52 lines
1.5 KiB
C++
52 lines
1.5 KiB
C++
#ifndef DOUWCO_HIVEMIND_CREEP_HPP
|
|
#define DOUWCO_HIVEMIND_CREEP_HPP
|
|
|
|
#include <Screeps/Creep.hpp>
|
|
#include <Screeps/ReturnTypes.hpp>
|
|
#include "Tools/JsonTool.hpp"
|
|
#include "Tools/PathTool.hpp"
|
|
|
|
namespace DouwcoHivemind
|
|
{
|
|
enum CreepRole
|
|
{
|
|
UNEMPLOYED,
|
|
HARVESTER
|
|
};
|
|
class Creep
|
|
{
|
|
public:
|
|
CreepRole role;
|
|
std::string target_id;
|
|
std::vector<Screeps::PathStep> path;
|
|
|
|
protected:
|
|
Screeps::Creep creep;
|
|
JSON memory;
|
|
|
|
public:
|
|
Creep(Screeps::Creep crp) : creep(crp),
|
|
memory(crp.memory())
|
|
{
|
|
role = memory.contains("role") ? static_cast<CreepRole>(memory["role"]) : CreepRole::UNEMPLOYED;
|
|
target_id = memory.contains("target_id") ? static_cast<std::string>(memory["target_id"]) : std::string();
|
|
path = memory.contains("path") ? unflattenPathSteps(jsonToVector<int>(memory["path"])) : std::vector<Screeps::PathStep>();
|
|
}
|
|
virtual ~Creep()
|
|
{
|
|
memory["target_id"] = target_id;
|
|
memory["path"] = vectorToJson(flattenPathSteps(path));
|
|
creep.setMemory(memory);
|
|
}
|
|
|
|
virtual void loop() {}
|
|
bool isNearTo(const Screeps::RoomPosition &pos, int dist);
|
|
|
|
protected:
|
|
void moveToTarget(int dist = 1);
|
|
std::unique_ptr<Screeps::RoomObject> getRoomObjectTarget();
|
|
bool isNearTo(const Screeps::RoomPosition &pos1, const Screeps::RoomPosition &pos2, int dist);
|
|
};
|
|
}
|
|
|
|
#endif // DOUWCO_HIVEMIND_CREEP_HPP
|