Added small movments when waiting on new target preventing blocking a source.

This commit is contained in:
2026-06-17 01:04:10 +02:00
parent af440fd296
commit 2332978ab7
5 changed files with 17 additions and 13 deletions

View File

@@ -19,12 +19,12 @@
#include <Screeps/ConstructionSite.hpp>
#include "Creeps/Builder.hpp"
#include "Creeps/CreepBase.hpp"
void DouwcoHivemind::Builder::depositEnergy()
{
auto constructionSite = getConstructionSiteTarget();
if (!constructionSite)
return;
if (!constructionSite) return;
if (isNearTo(constructionSite->pos(), 1))
{
@@ -42,6 +42,7 @@ std::unique_ptr<Screeps::ConstructionSite> DouwcoHivemind::Builder::getConstruct
if (!roomObj)
{
searchConstructionSite();
if(target_id.empty()) creep.move(rand()%5);
return nullptr;
}

View File

@@ -3,6 +3,7 @@
#include <Screeps/Game.hpp>
#include <Screeps/Room.hpp>
#include <Screeps/RoomPosition.hpp>
#include <cstddef>
#include "Creeps/CreepBase.hpp"
@@ -19,6 +20,7 @@ DouwcoHivemind::CreepBase::CreepBase(Screeps::Creep crp) : creep(crp),
DouwcoHivemind::CreepBase::~CreepBase()
{
memory["role"] = role;
memory["target_id"] = target_id;
creep.setMemory(memory);
}
@@ -26,7 +28,7 @@ DouwcoHivemind::CreepBase::~CreepBase()
void DouwcoHivemind::CreepBase::moveToTarget(int dist)
{
// Is move required?
auto target = getRoomObjectTarget();
auto target = getRoomObjectTarget();
if (isNearTo(target->pos(), dist))
{
memory.erase("path");
@@ -127,11 +129,13 @@ void DouwcoHivemind::CreepBase::moveToTarget(int dist)
std::unique_ptr<Screeps::RoomObject> DouwcoHivemind::CreepBase::getRoomObjectTarget()
{
// Check if any target is present
if(target_id.empty()) return nullptr;
// Check if game can find target
auto roomObj = Screeps::Game.getObjectById(target_id);
if (!roomObj)
{
JS::console.log(creep.name() + ": Game can\'t find target id");
JS::console.log(creep.name() + ": Game can\'t find target id: " + target_id);
return nullptr;
}
return std::move(roomObj);

View File

@@ -16,13 +16,12 @@
#include <Screeps/Store.hpp>
#include "Creeps/Maintainer.hpp"
#include "Creeps/CreepBase.hpp"
void DouwcoHivemind::Maintainer::depositEnergy()
{
auto structure = getDamagedStructureTarget();
if (!structure)
return;
if (!structure) return;
if (isNearTo(structure->pos(), 1))
{
int resp = creep.repair(*structure);
@@ -39,6 +38,7 @@ std::unique_ptr<Screeps::Structure> DouwcoHivemind::Maintainer::getDamagedStruct
if (!roomObj)
{
searchDamagedStructure();
if(target_id.empty()) creep.move(rand()%5);
return nullptr;
}
@@ -82,8 +82,8 @@ void DouwcoHivemind::Maintainer::searchDamagedStructure()
}
}
if (selectedStructure)
if (selectedStructure && selectedStructure->hits() != selectedStructure->hitsMax())
target_id = selectedStructure->id();
else
else
target_id.clear();
}

View File

@@ -20,8 +20,7 @@
void DouwcoHivemind::Supplier::depositEnergy()
{
auto structure = getEnergyStructureTarget();
if (!structure)
return;
if (!structure) return;
if (isNearTo(structure->pos(), 1))
{
@@ -39,6 +38,7 @@ std::unique_ptr<Screeps::Structure> DouwcoHivemind::Supplier::getEnergyStructure
if (!roomObj)
{
searchEnergyStructure();
if(target_id.empty()) creep.move(rand()%5);
return nullptr;
}

View File

@@ -17,7 +17,6 @@ void DouwcoHivemind::Spawn::loop()
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;
for (auto &creep : Screeps::Game.creeps())
{
CreepRole role = creep.second.memory()["role"];
@@ -32,7 +31,7 @@ void DouwcoHivemind::Spawn::loop()
required_builders--;
}
if (energyAvailable < energyCapacityAvailable && required_suppliers < 2)
if (energyAvailable < energyCapacityAvailable && 3 < Screeps::Game.creeps().size())
return;
std::string name;
JSON opts;