85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
#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"
|
|
#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<Screeps::ConstructionSite> DouwcoHivemind::Builder::getConstructionSiteTarget()
|
|
{
|
|
auto roomObj = getRoomObjectTarget();
|
|
if (!roomObj)
|
|
{
|
|
searchConstructionSite();
|
|
if(target_id.empty()) creep.move(rand()%5);
|
|
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();
|
|
}
|