40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
#ifndef DOUWCO_HIVEMIND_PATH_TOOL_HPP
|
|
#define DOUWCO_HIVEMIND_PATH_TOOL_HPP
|
|
|
|
#include <vector>
|
|
#include <Screeps/Room.hpp>
|
|
|
|
namespace DouwcoHivemind
|
|
{
|
|
static std::vector<int> flattenPathSteps(const std::vector<Screeps::Room::PathStep> &pathSteps)
|
|
{
|
|
std::vector<int> flattened;
|
|
for (const auto &step : pathSteps)
|
|
{
|
|
flattened.push_back(step.x);
|
|
flattened.push_back(step.y);
|
|
flattened.push_back(step.dx);
|
|
flattened.push_back(step.dy);
|
|
flattened.push_back(step.direction);
|
|
}
|
|
return flattened;
|
|
}
|
|
|
|
static std::vector<Screeps::Room::PathStep> unflattenPathSteps(const std::vector<int> &flattened)
|
|
{
|
|
std::vector<Screeps::Room::PathStep> pathSteps;
|
|
for (size_t i = 0; i < flattened.size(); i += 5)
|
|
{
|
|
Screeps::Room::PathStep step;
|
|
step.x = flattened[i];
|
|
step.y = flattened[i+1];
|
|
step.dx = flattened[i+2];
|
|
step.dy = flattened[i+3];
|
|
step.direction = flattened[i+4];
|
|
pathSteps.emplace_back(step);
|
|
}
|
|
return pathSteps;
|
|
}
|
|
} // namespace Screeps
|
|
|
|
#endif // DOUWCO_HIVEMIND_PATH_TOOL_HPP
|