Creeps extract memory completly
This commit is contained in:
@@ -2,19 +2,31 @@
|
||||
#define DOUWCO_HIVEMIND_CREEP_HPP
|
||||
|
||||
#include <Screeps/Creep.hpp>
|
||||
#include "Constants.hpp"
|
||||
|
||||
namespace DouwcoHivemind
|
||||
{
|
||||
class Creep
|
||||
{
|
||||
public:
|
||||
CreepRole role;
|
||||
|
||||
protected:
|
||||
Screeps::Creep creep;
|
||||
JSON memory;
|
||||
public:
|
||||
Creep(Screeps::Creep crp) : creep(crp), memory(crp.memory()){}
|
||||
~Creep(){ creep.setMemory(memory); }
|
||||
|
||||
virtual void loop(){}
|
||||
public:
|
||||
Creep(Screeps::Creep crp) : creep(crp),
|
||||
memory(crp.memory())
|
||||
{
|
||||
role = memory.contains("role") ? static_cast<CreepRole>(memory["role"]) : CreepRole::UNEMPLOYED;
|
||||
}
|
||||
|
||||
virtual ~Creep() {
|
||||
creep.setMemory(memory);
|
||||
}
|
||||
|
||||
virtual void loop() {}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,25 @@ namespace DouwcoHivemind
|
||||
{
|
||||
class HarvesterRole : public Creep
|
||||
{
|
||||
private:
|
||||
bool harvesting;
|
||||
std::string target_id;
|
||||
int taskCounter;
|
||||
|
||||
public:
|
||||
HarvesterRole(Screeps::Creep crp) : Creep(crp) {}
|
||||
~HarvesterRole() {}
|
||||
HarvesterRole(Screeps::Creep crp) : Creep(crp)
|
||||
{
|
||||
harvesting = memory.contains("harvesting") ? static_cast<bool>(memory["harvesting"]) : false;
|
||||
target_id = memory.contains("target_id") ? static_cast<std::string>(memory["target_id"]) : std::string();
|
||||
taskCounter = memory.contains("taskCounter") ? static_cast<int>(memory["taskCounter"]) : 0;
|
||||
}
|
||||
|
||||
~HarvesterRole() override
|
||||
{
|
||||
memory["harvesting"] = harvesting;
|
||||
memory["target_id"] = target_id;
|
||||
memory["taskCounter"] = taskCounter;
|
||||
}
|
||||
|
||||
void loop() override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user