#ifndef DOUWCO_HIVEMIND_CREEP_HPP #define DOUWCO_HIVEMIND_CREEP_HPP #include #include #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 path; protected: Screeps::Creep creep; JSON memory; public: Creep(Screeps::Creep crp) : creep(crp), memory(crp.memory()) { role = memory.contains("role") ? static_cast(memory["role"]) : CreepRole::UNEMPLOYED; target_id = memory.contains("target_id") ? static_cast(memory["target_id"]) : std::string(); path = memory.contains("path") ? unflattenPathSteps(jsonToVector(memory["path"])) : std::vector(); } 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 getRoomObjectTarget(); bool isNearTo(const Screeps::RoomPosition &pos1, const Screeps::RoomPosition &pos2, int dist); }; } #endif // DOUWCO_HIVEMIND_CREEP_HPP