Restructured the source files.
This commit is contained in:
74
douwco_hivemind/src/Structures/Spawn.cpp
Normal file
74
douwco_hivemind/src/Structures/Spawn.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <Screeps/Game.hpp>
|
||||
#include <Screeps/Room.hpp>
|
||||
|
||||
#include "Creeps/CreepBase.hpp"
|
||||
#include "Structures/Spawn.hpp"
|
||||
|
||||
void DouwcoHivemind::Spawn::loop()
|
||||
{
|
||||
// Only run every 50 ticks
|
||||
if (Screeps::Game.time() % 50 != 0)
|
||||
return;
|
||||
|
||||
int energyAvailable = spawn.room().energyAvailable();
|
||||
int energyCapacityAvailable = spawn.room().energyCapacityAvailable();
|
||||
|
||||
int required_upgraders = 1;
|
||||
int required_suppliers = 1;
|
||||
int required_maintainers = spawn.room().find(Screeps::FIND_MY_STRUCTURES).size() <= 2 ? 0 : 1;;
|
||||
int required_builders = spawn.room().find(Screeps::FIND_MY_CONSTRUCTION_SITES).size() == 0 ? 0 : 1;
|
||||
|
||||
for (auto &creep : Screeps::Game.creeps())
|
||||
{
|
||||
CreepRole role = creep.second.memory()["role"];
|
||||
|
||||
if (role == CreepRole::SUPPLIER)
|
||||
required_suppliers--;
|
||||
else if (role == CreepRole::UPGRADER)
|
||||
required_upgraders--;
|
||||
else if (role == CreepRole::MAINTAINER)
|
||||
required_maintainers--;
|
||||
else if (role == CreepRole::BUILDER)
|
||||
required_builders--;
|
||||
}
|
||||
|
||||
if (energyAvailable < energyCapacityAvailable && required_suppliers < 2)
|
||||
return;
|
||||
std::string name;
|
||||
JSON opts;
|
||||
if (required_suppliers > 0)
|
||||
{
|
||||
opts["memory"]["role"] = CreepRole::SUPPLIER;
|
||||
name = "Supplier: ";
|
||||
}
|
||||
else if (required_upgraders > 0)
|
||||
{
|
||||
opts["memory"]["role"] = CreepRole::UPGRADER;
|
||||
name = "Upgrader: ";
|
||||
}
|
||||
else if (required_builders > 0)
|
||||
{
|
||||
opts["memory"]["role"] = CreepRole::BUILDER;
|
||||
name = "Builder: ";
|
||||
}
|
||||
else if (required_maintainers > 0)
|
||||
{
|
||||
opts["memory"]["role"] = CreepRole::MAINTAINER;
|
||||
name = "Maintainer: ";
|
||||
}
|
||||
else
|
||||
return;
|
||||
|
||||
std::vector<std::string> body;
|
||||
for (int i = 0; i < energyAvailable / 200; i++)
|
||||
{
|
||||
body.push_back("work");
|
||||
body.push_back("carry");
|
||||
body.push_back("move");
|
||||
}
|
||||
|
||||
spawn.spawnCreep(
|
||||
body,
|
||||
name + std::to_string(Screeps::Game.time()),
|
||||
opts);
|
||||
}
|
||||
Reference in New Issue
Block a user