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,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,27 +84,18 @@ 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 &&
|
||||||
else if (structure->structureType() == Screeps::STRUCTURE_EXTENSION)
|
dynamic_cast<Screeps::StructureSpawn *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
|
||||||
{
|
|
||||||
if (dynamic_cast<Screeps::StructureExtension *>(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_TOWER &&
|
||||||
else if (structure->structureType() == Screeps::STRUCTURE_TOWER)
|
dynamic_cast<Screeps::StructureSpawn *>(structure)->store().getFreeCapacity(Screeps::RESOURCE_ENERGY) > 0)
|
||||||
{
|
|
||||||
if (dynamic_cast<Screeps::StructureTower *>(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_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);
|
||||||
if (closestObj)
|
if (closestObj)
|
||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user