Added small movments when waiting on new target preventing blocking a source.
This commit is contained in:
@@ -19,12 +19,12 @@
|
|||||||
#include <Screeps/ConstructionSite.hpp>
|
#include <Screeps/ConstructionSite.hpp>
|
||||||
|
|
||||||
#include "Creeps/Builder.hpp"
|
#include "Creeps/Builder.hpp"
|
||||||
|
#include "Creeps/CreepBase.hpp"
|
||||||
|
|
||||||
void DouwcoHivemind::Builder::depositEnergy()
|
void DouwcoHivemind::Builder::depositEnergy()
|
||||||
{
|
{
|
||||||
auto constructionSite = getConstructionSiteTarget();
|
auto constructionSite = getConstructionSiteTarget();
|
||||||
if (!constructionSite)
|
if (!constructionSite) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (isNearTo(constructionSite->pos(), 1))
|
if (isNearTo(constructionSite->pos(), 1))
|
||||||
{
|
{
|
||||||
@@ -42,6 +42,7 @@ std::unique_ptr<Screeps::ConstructionSite> DouwcoHivemind::Builder::getConstruct
|
|||||||
if (!roomObj)
|
if (!roomObj)
|
||||||
{
|
{
|
||||||
searchConstructionSite();
|
searchConstructionSite();
|
||||||
|
if(target_id.empty()) creep.move(rand()%5);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <Screeps/Game.hpp>
|
#include <Screeps/Game.hpp>
|
||||||
#include <Screeps/Room.hpp>
|
#include <Screeps/Room.hpp>
|
||||||
#include <Screeps/RoomPosition.hpp>
|
#include <Screeps/RoomPosition.hpp>
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
#include "Creeps/CreepBase.hpp"
|
#include "Creeps/CreepBase.hpp"
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ DouwcoHivemind::CreepBase::CreepBase(Screeps::Creep crp) : creep(crp),
|
|||||||
|
|
||||||
DouwcoHivemind::CreepBase::~CreepBase()
|
DouwcoHivemind::CreepBase::~CreepBase()
|
||||||
{
|
{
|
||||||
|
memory["role"] = role;
|
||||||
memory["target_id"] = target_id;
|
memory["target_id"] = target_id;
|
||||||
creep.setMemory(memory);
|
creep.setMemory(memory);
|
||||||
}
|
}
|
||||||
@@ -26,7 +28,7 @@ DouwcoHivemind::CreepBase::~CreepBase()
|
|||||||
void DouwcoHivemind::CreepBase::moveToTarget(int dist)
|
void DouwcoHivemind::CreepBase::moveToTarget(int dist)
|
||||||
{
|
{
|
||||||
// Is move required?
|
// Is move required?
|
||||||
auto target = getRoomObjectTarget();
|
auto target = getRoomObjectTarget();
|
||||||
if (isNearTo(target->pos(), dist))
|
if (isNearTo(target->pos(), dist))
|
||||||
{
|
{
|
||||||
memory.erase("path");
|
memory.erase("path");
|
||||||
@@ -127,11 +129,13 @@ void DouwcoHivemind::CreepBase::moveToTarget(int dist)
|
|||||||
|
|
||||||
std::unique_ptr<Screeps::RoomObject> DouwcoHivemind::CreepBase::getRoomObjectTarget()
|
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
|
// Check if game can find target
|
||||||
auto roomObj = Screeps::Game.getObjectById(target_id);
|
auto roomObj = Screeps::Game.getObjectById(target_id);
|
||||||
if (!roomObj)
|
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 nullptr;
|
||||||
}
|
}
|
||||||
return std::move(roomObj);
|
return std::move(roomObj);
|
||||||
|
|||||||
@@ -16,13 +16,12 @@
|
|||||||
#include <Screeps/Store.hpp>
|
#include <Screeps/Store.hpp>
|
||||||
|
|
||||||
#include "Creeps/Maintainer.hpp"
|
#include "Creeps/Maintainer.hpp"
|
||||||
|
#include "Creeps/CreepBase.hpp"
|
||||||
|
|
||||||
void DouwcoHivemind::Maintainer::depositEnergy()
|
void DouwcoHivemind::Maintainer::depositEnergy()
|
||||||
{
|
{
|
||||||
auto structure = getDamagedStructureTarget();
|
auto structure = getDamagedStructureTarget();
|
||||||
if (!structure)
|
if (!structure) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (isNearTo(structure->pos(), 1))
|
if (isNearTo(structure->pos(), 1))
|
||||||
{
|
{
|
||||||
int resp = creep.repair(*structure);
|
int resp = creep.repair(*structure);
|
||||||
@@ -39,6 +38,7 @@ std::unique_ptr<Screeps::Structure> DouwcoHivemind::Maintainer::getDamagedStruct
|
|||||||
if (!roomObj)
|
if (!roomObj)
|
||||||
{
|
{
|
||||||
searchDamagedStructure();
|
searchDamagedStructure();
|
||||||
|
if(target_id.empty()) creep.move(rand()%5);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,8 +82,8 @@ void DouwcoHivemind::Maintainer::searchDamagedStructure()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedStructure)
|
if (selectedStructure && selectedStructure->hits() != selectedStructure->hitsMax())
|
||||||
target_id = selectedStructure->id();
|
target_id = selectedStructure->id();
|
||||||
else
|
else
|
||||||
target_id.clear();
|
target_id.clear();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,8 +20,7 @@
|
|||||||
void DouwcoHivemind::Supplier::depositEnergy()
|
void DouwcoHivemind::Supplier::depositEnergy()
|
||||||
{
|
{
|
||||||
auto structure = getEnergyStructureTarget();
|
auto structure = getEnergyStructureTarget();
|
||||||
if (!structure)
|
if (!structure) return;
|
||||||
return;
|
|
||||||
|
|
||||||
if (isNearTo(structure->pos(), 1))
|
if (isNearTo(structure->pos(), 1))
|
||||||
{
|
{
|
||||||
@@ -39,6 +38,7 @@ std::unique_ptr<Screeps::Structure> DouwcoHivemind::Supplier::getEnergyStructure
|
|||||||
if (!roomObj)
|
if (!roomObj)
|
||||||
{
|
{
|
||||||
searchEnergyStructure();
|
searchEnergyStructure();
|
||||||
|
if(target_id.empty()) creep.move(rand()%5);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ void DouwcoHivemind::Spawn::loop()
|
|||||||
int required_suppliers = 1;
|
int required_suppliers = 1;
|
||||||
int required_maintainers = spawn.room().find(Screeps::FIND_MY_STRUCTURES).size() <= 2 ? 0 : 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;
|
int required_builders = spawn.room().find(Screeps::FIND_MY_CONSTRUCTION_SITES).size() == 0 ? 0 : 1;
|
||||||
|
|
||||||
for (auto &creep : Screeps::Game.creeps())
|
for (auto &creep : Screeps::Game.creeps())
|
||||||
{
|
{
|
||||||
CreepRole role = creep.second.memory()["role"];
|
CreepRole role = creep.second.memory()["role"];
|
||||||
@@ -32,7 +31,7 @@ void DouwcoHivemind::Spawn::loop()
|
|||||||
required_builders--;
|
required_builders--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (energyAvailable < energyCapacityAvailable && required_suppliers < 2)
|
if (energyAvailable < energyCapacityAvailable && 3 < Screeps::Game.creeps().size())
|
||||||
return;
|
return;
|
||||||
std::string name;
|
std::string name;
|
||||||
JSON opts;
|
JSON opts;
|
||||||
|
|||||||
Reference in New Issue
Block a user