Minor bug fixes

This commit is contained in:
douwe
2025-08-13 21:08:26 +02:00
parent 9a1682a857
commit 257cf85695
9 changed files with 24 additions and 31 deletions

Binary file not shown.

Binary file not shown.

2
app.js

File diff suppressed because one or more lines are too long

BIN
app.wasm

Binary file not shown.

2
dist/app_loader.js vendored

File diff suppressed because one or more lines are too long

BIN
dist/app_module.wasm vendored

Binary file not shown.

View File

@@ -20,7 +20,7 @@
bool isNearTo(const Screeps::RoomPosition &pos1, const Screeps::RoomPosition &pos2); bool isNearTo(const Screeps::RoomPosition &pos1, const Screeps::RoomPosition &pos2);
DouwcoHivemind::HarvesterRole::HarvesterRole(Screeps::Creep* creep_pntr) DouwcoHivemind::HarvesterRole::HarvesterRole(Screeps::Creep *creep_pntr)
{ {
creep = creep_pntr; creep = creep_pntr;
memory = creep->memory(); memory = creep->memory();
@@ -48,10 +48,13 @@ void DouwcoHivemind::HarvesterRole::setupMemory()
EM_ASM({ console.log('Setup harvesting'); }); EM_ASM({ console.log('Setup harvesting'); });
memory["harvesting"] = false; memory["harvesting"] = false;
} }
if (!memory.contains("target")) if (!memory.contains("target") || memory["target"].empty())
{ {
EM_ASM({ console.log('Setup target'); }); EM_ASM({ console.log('Setup target'); });
memory["target"] = ""; if (memory["harvesting"])
searchSource();
else
searchEnergyDeposit();
} }
} }
@@ -81,26 +84,17 @@ void DouwcoHivemind::HarvesterRole::searchEnergyDeposit()
if (!structure) if (!structure)
continue; continue;
if (structure->structureType() == Screeps::STRUCTURE_SPAWN) if (structure->structureType() == Screeps::STRUCTURE_SPAWN &&
{ dynamic_cast<Screeps::StructureSpawn *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
if (dynamic_cast<Screeps::StructureSpawn *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0) filtered.emplace_back(std::move(structureObject));
filtered.emplace_back(std::move(structureObject)); else if (structure->structureType() == Screeps::STRUCTURE_EXTENSION &&
} dynamic_cast<Screeps::StructureSpawn *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
else if (structure->structureType() == Screeps::STRUCTURE_EXTENSION) filtered.emplace_back(std::move(structureObject));
{ else if (structure->structureType() == Screeps::STRUCTURE_TOWER &&
if (dynamic_cast<Screeps::StructureExtension *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0) dynamic_cast<Screeps::StructureSpawn *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
filtered.emplace_back(std::move(structureObject)); filtered.emplace_back(std::move(structureObject));
} else if (structure->structureType() == Screeps::STRUCTURE_CONTROLLER)
else if (structure->structureType() == Screeps::STRUCTURE_TOWER)
{
if (dynamic_cast<Screeps::StructureTower *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
filtered.emplace_back(std::move(structureObject));
}
else if (structure->structureType() == Screeps::STRUCTURE_CONTROLLER)
{
filtered.emplace_back(std::move(structureObject)); filtered.emplace_back(std::move(structureObject));
}
} }
auto closestObj = creep->pos().findClosestByPath(filtered); auto closestObj = creep->pos().findClosestByPath(filtered);
@@ -110,7 +104,7 @@ void DouwcoHivemind::HarvesterRole::searchEnergyDeposit()
memory["target"] = closest ? closest->id() : ""; memory["target"] = closest ? closest->id() : "";
} }
else else
memory["target"] = ""; memory["target"].clear();
} }
void DouwcoHivemind::HarvesterRole::searchSource() void DouwcoHivemind::HarvesterRole::searchSource()
@@ -128,7 +122,7 @@ void DouwcoHivemind::HarvesterRole::searchSource()
} }
else else
{ {
memory["target"] = ""; memory["target"].clear();
} }
} }

View File

@@ -10,16 +10,15 @@
void DouwcoHivemind::Spawn::process() void DouwcoHivemind::Spawn::process()
{ {
int creepcount = structure->room().find(Screeps::FIND_MY_CREEPS, nullptr).size(); int creepcount = structure->room().find(Screeps::FIND_MY_CREEPS).size();
EM_ASM({ console.log('creepcount: ' + $0); }, creepcount); if (creepcount > 10) return;
if (creepcount >= 10) return;
JSON opts; JSON opts;
opts["memory"]["role"] = DouwcoHivemind::ROLE_HARVESTER; opts["memory"]["role"] = DouwcoHivemind::ROLE_HARVESTER;
int resp = structure->spawnCreep( int resp = structure->spawnCreep(
{"work", "carry", "move"}, {"work", "carry", "move"},
"harvester" + std::to_string(creepcount + 1), "harvester" + std::to_string(Screeps::Game.time()),
opts opts
); );
} }