Improved the spawn behaviour.

This commit is contained in:
2025-12-16 01:54:16 +01:00
parent 74d6e9e76d
commit 1596283841
10 changed files with 427 additions and 7 deletions

View File

@@ -1,5 +1,10 @@
#include <algorithm>
#include <Screeps/Game.hpp>
#include <Screeps/Room.hpp>
#include <Screeps/RoomObject.hpp>
#include <Screeps/Constants.hpp>
#include <Screeps/Structure.hpp>
#include "Creeps/CreepBase.hpp"
#include "Structures/Spawn.hpp"
@@ -10,13 +15,25 @@ void DouwcoHivemind::Spawn::loop()
if (Screeps::Game.time() % 50 != 0)
return;
int energyAvailable = spawn.room().energyAvailable();
int energyCapacityAvailable = spawn.room().energyCapacityAvailable();
auto room = spawn.room();
int energyAvailable = room.energyAvailable();
int energyCapacityAvailable = room.energyCapacityAvailable();
int constructionSiteCount = room.find(Screeps::FIND_MY_CONSTRUCTION_SITES).size();
auto structures = room.find(Screeps::FIND_STRUCTURES);
int repairableStructureCount, extensionCount;
for (auto& roomObj : structures)
{
auto structure = dynamic_cast<Screeps::Structure*>(roomObj.get());
std::string type = structure->structureType();
if (type == Screeps::STRUCTURE_CONTROLLER || type == Screeps::STRUCTURE_SPAWN) continue;
repairableStructureCount++;
if (type == Screeps::STRUCTURE_EXTENSION) extensionCount++;
}
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;
int required_suppliers = std::clamp(extensionCount/5, 1, 2);
int required_maintainers = std::clamp(repairableStructureCount, 0, 1);
int required_builders = std::clamp(constructionSiteCount, 0, 5);
int required_upgraders = std::clamp(5-required_builders-required_maintainers-required_suppliers, 1, 3);
for (auto &creep : Screeps::Game.creeps())
{
@@ -32,7 +49,7 @@ void DouwcoHivemind::Spawn::loop()
required_builders--;
}
if (energyAvailable < energyCapacityAvailable && required_suppliers < 2)
if (energyAvailable < energyCapacityAvailable && required_suppliers == 0)
return;
std::string name;
JSON opts;