added the maintainer and changed some naming.

This commit is contained in:
douwe
2025-08-26 16:34:49 +02:00
parent 0c693354e6
commit eea9e7d69f
24 changed files with 328 additions and 164 deletions

View File

@@ -1,10 +1,12 @@
#include <Screeps/Game.hpp>
#include <Screeps/Memory.hpp>
#include "Engine.hpp"
#include "Creeps/HarvesterSupplier.hpp"
#include "Creeps/HarvesterUpgrader.hpp"
#include "Creeps/HarvesterBuilder.hpp"
#include "Creeps/Supplier.hpp"
#include "Creeps/Upgrader.hpp"
#include "Creeps/Builder.hpp"
#include "Creeps/Maintainer.hpp"
#include "Structures/Spawn.hpp"
@@ -19,10 +21,15 @@ void DouwcoHivemind::Engine::loop()
JS::console.log(std::string("Iterating over creeps"));
for (auto &creep : creeps)
creep->loop();
JS::console.log(std::string("Iterating over structures"));
for (auto &structure : structures)
structure->loop();
if (Screeps::Game.time() % 1000 == 0)
{
clearDeadCreepMemory();
}
}
void DouwcoHivemind::Engine::ReadOutCreeps()
@@ -32,12 +39,14 @@ void DouwcoHivemind::Engine::ReadOutCreeps()
for (auto &creep : src_creeps)
{
CreepRole role = creep.second.memory()["role"];
if (role == CreepRole::HARVESTER_SUPPLIER)
creeps.push_back(std::make_unique<HarvesterSupplier>(creep.second));
else if (role == CreepRole::HARVESTER_UPGRADER)
creeps.push_back(std::make_unique<HarvesterUpgrader>(creep.second));
else if (role == CreepRole::HARVESTER_BUILDER)
creeps.push_back(std::make_unique<HarvesterBuilder>(creep.second));
if (role == CreepRole::SUPPLIER)
creeps.push_back(std::make_unique<Supplier>(creep.second));
else if (role == CreepRole::UPGRADER)
creeps.push_back(std::make_unique<Upgrader>(creep.second));
else if (role == CreepRole::BUILDER)
creeps.push_back(std::make_unique<Builder>(creep.second));
else if (role == CreepRole::MAINTAINER)
creeps.push_back(std::make_unique<Maintainer>(creep.second));
}
}
@@ -49,4 +58,31 @@ void DouwcoHivemind::Engine::ReadOutStructures()
{
structures.push_back(std::make_unique<Spawn>(spawn.second));
}
}
}
void DouwcoHivemind::Engine::clearDeadCreepMemory()
{
auto creepMemory = Screeps::Memory["creeps"];
auto creepsMap = Screeps::Game.creeps();
int iterator = 0;
for (auto [name, creep] : creepMemory.items())
{
// avoid cpu overload
iterator++;
if (iterator == 100)
break;
bool containsname = false;
for (auto creepObject : creepsMap)
{
if (creepObject.first == name)
{
containsname = true;
break;
}
}
if (!containsname)
creepMemory.erase(name);
}
Screeps::Memory.set("creeps", creepMemory);
}