#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "Creeps/Builder.hpp" #include "Creeps/CreepBase.hpp" void DouwcoHivemind::Builder::depositEnergy() { auto constructionSite = getConstructionSiteTarget(); if (!constructionSite) return; if (isNearTo(constructionSite->pos(), 1)) { int resp = creep.build(*constructionSite); } else { moveToTarget(); } } std::unique_ptr DouwcoHivemind::Builder::getConstructionSiteTarget() { auto roomObj = getRoomObjectTarget(); if (!roomObj) { searchConstructionSite(); if(target_id.empty()) creep.move(rand()%5); return nullptr; } auto constructionSite = std::unique_ptr(dynamic_cast(roomObj.release())); if (!constructionSite) { searchConstructionSite(); return nullptr; } return std::move(constructionSite); } void DouwcoHivemind::Builder::searchConstructionSite() { int leastProgressLeft = INT16_MAX; Screeps::ConstructionSite *selectedConstructionSite; auto constructionSites = creep.room().find(Screeps::FIND_MY_CONSTRUCTION_SITES); for (auto &constructionSiteObject : constructionSites) { auto constructionSite = dynamic_cast(constructionSiteObject.get()); if (!constructionSite) continue; int progressLeft = constructionSite->progressTotal() - constructionSite->progress(); if(constructionSite->structureType() == Screeps::STRUCTURE_ROAD) progressLeft *= 100; if (progressLeft < leastProgressLeft) { leastProgressLeft = progressLeft; selectedConstructionSite = constructionSite; } } if (selectedConstructionSite) target_id = selectedConstructionSite->id(); else target_id.clear(); }