Minor bug fixes
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
2
dist/app_loader.js
vendored
2
dist/app_loader.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/app_module.wasm
vendored
BIN
dist/app_module.wasm
vendored
Binary file not shown.
@@ -20,8 +20,8 @@
|
||||
|
||||
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;
|
||||
memory = creep->memory();
|
||||
}
|
||||
@@ -48,10 +48,13 @@ void DouwcoHivemind::HarvesterRole::setupMemory()
|
||||
EM_ASM({ console.log('Setup harvesting'); });
|
||||
memory["harvesting"] = false;
|
||||
}
|
||||
if (!memory.contains("target"))
|
||||
if (!memory.contains("target") || memory["target"].empty())
|
||||
{
|
||||
EM_ASM({ console.log('Setup target'); });
|
||||
memory["target"] = "";
|
||||
if (memory["harvesting"])
|
||||
searchSource();
|
||||
else
|
||||
searchEnergyDeposit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,26 +84,17 @@ void DouwcoHivemind::HarvesterRole::searchEnergyDeposit()
|
||||
if (!structure)
|
||||
continue;
|
||||
|
||||
if (structure->structureType() == Screeps::STRUCTURE_SPAWN)
|
||||
{
|
||||
if (dynamic_cast<Screeps::StructureSpawn *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
|
||||
filtered.emplace_back(std::move(structureObject));
|
||||
}
|
||||
else if (structure->structureType() == Screeps::STRUCTURE_EXTENSION)
|
||||
{
|
||||
if (dynamic_cast<Screeps::StructureExtension *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
|
||||
filtered.emplace_back(std::move(structureObject));
|
||||
}
|
||||
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)
|
||||
{
|
||||
if (structure->structureType() == Screeps::STRUCTURE_SPAWN &&
|
||||
dynamic_cast<Screeps::StructureSpawn *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
|
||||
filtered.emplace_back(std::move(structureObject));
|
||||
else if (structure->structureType() == Screeps::STRUCTURE_EXTENSION &&
|
||||
dynamic_cast<Screeps::StructureSpawn *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
|
||||
filtered.emplace_back(std::move(structureObject));
|
||||
else if (structure->structureType() == Screeps::STRUCTURE_TOWER &&
|
||||
dynamic_cast<Screeps::StructureSpawn *>(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));
|
||||
}
|
||||
}
|
||||
|
||||
auto closestObj = creep->pos().findClosestByPath(filtered);
|
||||
@@ -110,7 +104,7 @@ void DouwcoHivemind::HarvesterRole::searchEnergyDeposit()
|
||||
memory["target"] = closest ? closest->id() : "";
|
||||
}
|
||||
else
|
||||
memory["target"] = "";
|
||||
memory["target"].clear();
|
||||
}
|
||||
|
||||
void DouwcoHivemind::HarvesterRole::searchSource()
|
||||
@@ -128,7 +122,7 @@ void DouwcoHivemind::HarvesterRole::searchSource()
|
||||
}
|
||||
else
|
||||
{
|
||||
memory["target"] = "";
|
||||
memory["target"].clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,16 +10,15 @@
|
||||
|
||||
void DouwcoHivemind::Spawn::process()
|
||||
{
|
||||
int creepcount = structure->room().find(Screeps::FIND_MY_CREEPS, nullptr).size();
|
||||
EM_ASM({ console.log('creepcount: ' + $0); }, creepcount);
|
||||
if (creepcount >= 10) return;
|
||||
int creepcount = structure->room().find(Screeps::FIND_MY_CREEPS).size();
|
||||
if (creepcount > 10) return;
|
||||
|
||||
JSON opts;
|
||||
opts["memory"]["role"] = DouwcoHivemind::ROLE_HARVESTER;
|
||||
|
||||
int resp = structure->spawnCreep(
|
||||
{"work", "carry", "move"},
|
||||
"harvester" + std::to_string(creepcount + 1),
|
||||
"harvester" + std::to_string(Screeps::Game.time()),
|
||||
opts
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user