Updated the supplier behavior to also use storage and implemented tower.
This commit is contained in:
@@ -6,68 +6,92 @@
|
||||
|
||||
void DouwcoHivemind::Spawn::loop() {
|
||||
// Only run every 500 ticks
|
||||
if (Screeps::Game.time() % 250 != 0)
|
||||
if (Screeps::Game.time() % 100 != 0)
|
||||
return;
|
||||
|
||||
// Get energy data
|
||||
int energyAvailable = spawn.room().energyAvailable();
|
||||
int energyCapacityAvailable = spawn.room().energyCapacityAvailable();
|
||||
|
||||
// Calculate needed creep roles
|
||||
int required_upgraders = 1;
|
||||
int required_suppliers = 1;
|
||||
int required_suppliers = 2;
|
||||
int required_maintainers =
|
||||
spawn.room().find(Screeps::FIND_STRUCTURES).size() <= 2 ? 0 : 1;
|
||||
;
|
||||
int required_builders =
|
||||
spawn.room().find(Screeps::FIND_MY_CONSTRUCTION_SITES).size() == 0 ? 0
|
||||
: 1;
|
||||
int required_miners = 1; //spawn.room().memory()["sourceContainers"].size();
|
||||
int required_miners = 1; // spawn.room().memory()["sourceContainers"].size();
|
||||
|
||||
// Count existing roles
|
||||
int existing_upgraders = 0;
|
||||
int existing_suppliers = 0;
|
||||
int existing_maintainers = 0;
|
||||
int existing_builders = 0;
|
||||
int existing_miners = 0;
|
||||
|
||||
for (auto &creep : Screeps::Game.creeps()) {
|
||||
CreepRole role = creep.second.memory()["role"];
|
||||
|
||||
if (role == CreepRole::SUPPLIER)
|
||||
required_suppliers--;
|
||||
existing_suppliers++;
|
||||
else if (role == CreepRole::UPGRADER)
|
||||
required_upgraders--;
|
||||
existing_upgraders++;
|
||||
else if (role == CreepRole::MAINTAINER)
|
||||
required_maintainers--;
|
||||
existing_maintainers++;
|
||||
else if (role == CreepRole::BUILDER)
|
||||
required_builders--;
|
||||
existing_builders++;
|
||||
else if (role == CreepRole::MINER)
|
||||
required_miners--;
|
||||
existing_miners++;
|
||||
}
|
||||
|
||||
// if (energyAvailable < energyCapacityAvailable && 3 <
|
||||
// Screeps::Game.creeps().size())
|
||||
// return;
|
||||
// Check if max energy used
|
||||
if (energyAvailable < energyCapacityAvailable && 0 < existing_suppliers)
|
||||
return;
|
||||
|
||||
// Set creep properties
|
||||
std::string name;
|
||||
JSON opts;
|
||||
if (required_upgraders > 0) {
|
||||
opts["memory"]["role"] = CreepRole::UPGRADER;
|
||||
name = "Upgrader: ";
|
||||
} else if (required_miners > 0) {
|
||||
opts["memory"]["role"] = CreepRole::MINER;
|
||||
CreepRole role = CreepRole::UNEMPLOYED;
|
||||
if (required_miners > existing_miners) {
|
||||
role = CreepRole::MINER;
|
||||
opts["memory"]["target_id"] =
|
||||
spawn.room().memory()["sourceContainers"][0]; // make logic for more
|
||||
name = "Miner: ";
|
||||
} else if (required_suppliers > 0) {
|
||||
opts["memory"]["role"] = CreepRole::SUPPLIER;
|
||||
} else if (required_suppliers > existing_suppliers) {
|
||||
role = CreepRole::SUPPLIER;
|
||||
name = "Supplier: ";
|
||||
} else if (required_builders > 0) {
|
||||
opts["memory"]["role"] = CreepRole::BUILDER;
|
||||
} else if (required_upgraders > existing_upgraders) {
|
||||
role = CreepRole::UPGRADER;
|
||||
name = "Upgrader: ";
|
||||
} else if (required_builders > existing_builders) {
|
||||
role = CreepRole::BUILDER;
|
||||
name = "Builder: ";
|
||||
} else if (required_maintainers > 0) {
|
||||
opts["memory"]["role"] = CreepRole::MAINTAINER;
|
||||
} else if (required_maintainers > existing_maintainers) {
|
||||
role = CreepRole::MAINTAINER;
|
||||
name = "Maintainer: ";
|
||||
} else
|
||||
return;
|
||||
|
||||
opts["memory"]["role"] = role;
|
||||
|
||||
// Build creep body
|
||||
std::vector<std::string> body;
|
||||
if (opts["memory"]["role"] == CreepRole::MINER) {
|
||||
if (role == CreepRole::MINER) {
|
||||
body.push_back("move");
|
||||
body.push_back("work");
|
||||
for (int i = 0; i < (energyAvailable - 150) / 100 && i < 5; i++) {
|
||||
body.push_back("work");
|
||||
}
|
||||
} else if (role == SUPPLIER) {
|
||||
body.push_back("move");
|
||||
body.push_back("work");
|
||||
body.push_back("carry");
|
||||
for (int i = 0; i < (energyAvailable - 200) / 100 && i * 50 < energyCapacityAvailable; i++) {
|
||||
body.push_back("move");
|
||||
body.push_back("carry");
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < energyAvailable / 200; i++) {
|
||||
body.push_back("work");
|
||||
@@ -76,5 +100,6 @@ void DouwcoHivemind::Spawn::loop() {
|
||||
}
|
||||
}
|
||||
|
||||
// Create creep
|
||||
spawn.spawnCreep(body, name + std::to_string(Screeps::Game.time()), opts);
|
||||
}
|
||||
Reference in New Issue
Block a user