Restructured the source files.
This commit is contained in:
83
douwco_hivemind/src/Creeps/Builder.cpp
Normal file
83
douwco_hivemind/src/Creeps/Builder.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <vector>
|
||||
#include <optional>
|
||||
#include <emscripten.h>
|
||||
|
||||
#include <Screeps/Game.hpp>
|
||||
#include <Screeps/Creep.hpp>
|
||||
#include <Screeps/Source.hpp>
|
||||
#include <Screeps/Room.hpp>
|
||||
#include <Screeps/RoomPosition.hpp>
|
||||
#include <Screeps/RoomObject.hpp>
|
||||
#include <Screeps/Structure.hpp>
|
||||
#include <Screeps/StructureController.hpp>
|
||||
#include <Screeps/StructureSpawn.hpp>
|
||||
#include <Screeps/StructureExtension.hpp>
|
||||
#include <Screeps/StructureTower.hpp>
|
||||
#include <Screeps/Constants.hpp>
|
||||
#include <Screeps/Store.hpp>
|
||||
|
||||
#include <Screeps/ConstructionSite.hpp>
|
||||
|
||||
#include "Creeps/Builder.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<Screeps::ConstructionSite> DouwcoHivemind::Builder::getConstructionSiteTarget()
|
||||
{
|
||||
auto roomObj = getRoomObjectTarget();
|
||||
if (!roomObj)
|
||||
{
|
||||
searchConstructionSite();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto constructionSite = std::unique_ptr<Screeps::ConstructionSite>(dynamic_cast<Screeps::ConstructionSite *>(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<Screeps::ConstructionSite *>(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();
|
||||
}
|
||||
Reference in New Issue
Block a user