diff --git a/douwco_hivemind/include/Engine.hpp b/douwco_hivemind/include/Engine.hpp index 0e1620f..b0ffd67 100644 --- a/douwco_hivemind/include/Engine.hpp +++ b/douwco_hivemind/include/Engine.hpp @@ -1,6 +1,8 @@ #ifndef DOUWCO_HIVEMIND_ENGINE_HPP #define DOUWCO_HIVEMIND_ENGINE_HPP +#include +#include #include #include "Creeps/CreepBase.hpp" @@ -9,10 +11,10 @@ namespace DouwcoHivemind { class Engine { -private: - std::vector> rooms; - std::vector> creeps; - std::vector> structures; +public: + std::map> Rooms; + std::map> Creeps; + std::map> Structures; public: // Readout data from screeps API into C++ vectors @@ -30,6 +32,6 @@ private: // Clear dead screep memory void clearDeadCreepMemory(); }; -} +} // namespace DouwcoHivemind #endif // DOUWCO_HIVEMIND_ENGINE_HPP \ No newline at end of file diff --git a/douwco_hivemind/src/Creeps/Builder.cpp b/douwco_hivemind/src/Creeps/Builder.cpp index 0833a67..ad8d7b2 100644 --- a/douwco_hivemind/src/Creeps/Builder.cpp +++ b/douwco_hivemind/src/Creeps/Builder.cpp @@ -57,7 +57,7 @@ std::unique_ptr DouwcoHivemind::Builder::getConstruct void DouwcoHivemind::Builder::searchConstructionSite() { - int leastProgressLeft = INT16_MAX; + int leastProgressLeft = INT32_MAX; Screeps::ConstructionSite *selectedConstructionSite; auto constructionSites = creep.room().find(Screeps::FIND_MY_CONSTRUCTION_SITES); for (auto &constructionSiteObject : constructionSites) @@ -68,7 +68,7 @@ void DouwcoHivemind::Builder::searchConstructionSite() int progressLeft = constructionSite->progressTotal() - constructionSite->progress(); - if(constructionSite->structureType() == Screeps::STRUCTURE_ROAD) progressLeft *= 100; + if(constructionSite->structureType() == Screeps::STRUCTURE_ROAD) progressLeft *= 10; if (progressLeft < leastProgressLeft) { leastProgressLeft = progressLeft; diff --git a/douwco_hivemind/src/Engine.cpp b/douwco_hivemind/src/Engine.cpp index edf01c8..30baf9a 100644 --- a/douwco_hivemind/src/Engine.cpp +++ b/douwco_hivemind/src/Engine.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "Engine.hpp" @@ -10,7 +11,6 @@ #include "Creeps/Miner.hpp" #include "Creeps/Supplier.hpp" #include "Creeps/Upgrader.hpp" -#include "Creeps/Miner.hpp" #include "Screeps/Constants.hpp" #include "Screeps/StructureSpawn.hpp" @@ -18,23 +18,26 @@ #include "Structures/Tower.hpp" DouwcoHivemind::Engine::Engine() { + JS::console.log(std::string("Reading out owned rooms")); ReadOutRooms(); + JS::console.log(std::string("Reading out creeps")); ReadOutCreeps(); + JS::console.log(std::string("Reading out structures")); ReadOutStructures(); } void DouwcoHivemind::Engine::loop() { JS::console.log(std::string("Iterating over rooms")); - for (auto &room : rooms) - room->loop(); + for (auto &room : Rooms) + room.second->loop(); JS::console.log(std::string("Iterating over creeps")); - for (auto &creep : creeps) - creep->loop(); + for (auto &creep : Creeps) + creep.second->loop(); JS::console.log(std::string("Iterating over structures")); - for (auto &structure : structures) - structure->loop(); + for (auto &structure : Structures) + structure.second->loop(); if (Screeps::Game.time() % 100 == 0) { clearDeadCreepMemory(); @@ -42,42 +45,45 @@ void DouwcoHivemind::Engine::loop() { } void DouwcoHivemind::Engine::ReadOutRooms() { - JS::console.log(std::string("Reading out owned rooms")); auto src_rooms = Screeps::Game.rooms(); for (auto &room : src_rooms) { - if(!room.second.controller().value().my()) continue; - rooms.push_back(std::make_unique(room.second)); + if (!room.second.controller().value().my()) + continue; + Rooms.emplace(room.first, std::make_unique(room.second)); } } void DouwcoHivemind::Engine::ReadOutCreeps() { - JS::console.log(std::string("Reading out creeps")); auto src_creeps = Screeps::Game.creeps(); for (auto &creep : src_creeps) { CreepRole role = creep.second.memory()["role"]; if (role == CreepRole::SUPPLIER) - creeps.push_back(std::make_unique(creep.second)); + Creeps.emplace(creep.first, std::make_unique(creep.second)); else if (role == CreepRole::UPGRADER) - creeps.push_back(std::make_unique(creep.second)); + Creeps.emplace(creep.first, std::make_unique(creep.second)); else if (role == CreepRole::BUILDER) - creeps.push_back(std::make_unique(creep.second)); + Creeps.emplace(creep.first, std::make_unique(creep.second)); else if (role == CreepRole::MAINTAINER) - creeps.push_back(std::make_unique(creep.second)); + Creeps.emplace(creep.first, std::make_unique(creep.second)); else if (role == CreepRole::MINER) - creeps.push_back(std::make_unique(creep.second)); + Creeps.emplace(creep.first, std::make_unique(creep.second)); } } void DouwcoHivemind::Engine::ReadOutStructures() { - JS::console.log(std::string("Reading out structures")); - auto structures_src =Screeps::Game.structures(); + auto structures_src = Screeps::Game.structures(); for (auto &structure : structures_src) { std::string structureType = structure.second.structureType(); - if(structureType == Screeps::STRUCTURE_TOWER){ - structures.push_back(std::make_unique(static_cast(structure.second))); - } - else if(structureType == Screeps::STRUCTURE_SPAWN){ - structures.push_back(std::make_unique(static_cast(structure.second))); + if (structureType == Screeps::STRUCTURE_TOWER) { + Structures.emplace( + structure.first, + std::make_unique( + static_cast(structure.second))); + } else if (structureType == Screeps::STRUCTURE_SPAWN) { + Structures.emplace( + structure.first, + std::make_unique( + static_cast(structure.second))); } } } diff --git a/douwco_hivemind/src/Structures/Spawn.cpp b/douwco_hivemind/src/Structures/Spawn.cpp index 3745f6c..bbc2efb 100644 --- a/douwco_hivemind/src/Structures/Spawn.cpp +++ b/douwco_hivemind/src/Structures/Spawn.cpp @@ -3,13 +3,10 @@ #include #include "Creeps/CreepBase.hpp" +#include "Engine.hpp" #include "Structures/Spawn.hpp" void DouwcoHivemind::Spawn::loop() { - // Only run every 500 ticks - if (Screeps::Game.time() % 100 != 0) - return; - // Get energy data int energyAvailable = spawn.room().energyAvailable(); int energyCapacityAvailable = spawn.room().energyCapacityAvailable(); diff --git a/screepsxx b/screepsxx index 0eca2f2..c6e4baf 160000 --- a/screepsxx +++ b/screepsxx @@ -1 +1 @@ -Subproject commit 0eca2f2867dfab810eedec5ae76efea87592abac +Subproject commit c6e4bafaa3a20199d2e79dc28ca9acde63ebf84d