Introduced Builder Creep & Bug fixes
Fixed an issue where the role map was not getting the unique role name and therefore no role could be looked up. Added the BUILD_SPAWNS state to the SetupOverlord where it should create a builder and start building the other spawns. The create_spawns() function is not fully implemented yet though and the code to decide where to place the spawn is missing.main
parent
732e8270b9
commit
f5b1ff2931
@ -0,0 +1,84 @@
|
|||||||
|
const { sum } = require("lodash");
|
||||||
|
|
||||||
|
const ROLE_IDENT = "Build";
|
||||||
|
|
||||||
|
var roleBuilder = {
|
||||||
|
|
||||||
|
ROLE_IDENT: ROLE_IDENT,
|
||||||
|
|
||||||
|
minimum_parts: [WORK, MOVE, CARRY],
|
||||||
|
recommended_parts: [WORK, MOVE, CARRY, CARRY],
|
||||||
|
min_cost: sum([BODYPART_COST["work"], BODYPART_COST["move"], BODYPART_COST["carry"]]),
|
||||||
|
rec_cost: sum([BODYPART_COST["work"], BODYPART_COST["move"], BODYPART_COST["carry"], BODYPART_COST["carry"]]),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Orders the given spawn to create a creep fitting for this role according to the recommended_parts and if impossible use minimum_parts instead
|
||||||
|
* @param {spawn} spawn
|
||||||
|
* @param {string} postfix string to postfix to the creep
|
||||||
|
* @param {string} owner_id strind id of who shall be entered as owner of the new creep
|
||||||
|
*
|
||||||
|
* @return {string} name of the new creep
|
||||||
|
*/
|
||||||
|
spawn: function(spawn, postfix, owner_id) {
|
||||||
|
let creep_name = "builder-"+postfix;
|
||||||
|
if (spawn.spawnCreep(this.recommended_parts, creep_name, {dryRun: true}) === OK) {
|
||||||
|
console.log("roleBuilder: Spawn "+spawn.name+" is creating "+creep_name+" with recommended parts ...");
|
||||||
|
spawn.spawnCreep(this.recommended_parts, creep_name, {memory: {"owner": owner_id, "role": ROLE_IDENT}});
|
||||||
|
}
|
||||||
|
else if (spawn.spawnCreep(this.minimum_parts, creep_name, {dryRun: true}) === OK) {
|
||||||
|
console.log("roleBuilder: Spawn "+spawn.name+" is creating "+creep_name+" with minimum parts ...");
|
||||||
|
spawn.spawnCreep(this.minimum_parts, creep_name, {memory: {"owner": owner_id, "role": ROLE_IDENT}});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log("roleBuilder: Spawn \""+spawn.name+"\" couldn't afford a Builder! D: Result: ", spawn.spawnCreep(this.minimum_parts, creep_name, {dryRun: true}));
|
||||||
|
throw "Not enough energy!";
|
||||||
|
}
|
||||||
|
|
||||||
|
Memory.creeps[creep_name].destination_spot = {
|
||||||
|
id: null,
|
||||||
|
structure_pos: null,
|
||||||
|
goto_pos: null,
|
||||||
|
};
|
||||||
|
Memory.creeps[creep_name].source_spot = {
|
||||||
|
id: null,
|
||||||
|
structure_pos: null,
|
||||||
|
goto_pos: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
return creep_name;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the creep has all the parts necessary to work its role
|
||||||
|
* @param {Creep} creep
|
||||||
|
* @return bool that indicates if the creep can fullfill its role
|
||||||
|
*/
|
||||||
|
can_work: function(creep) {
|
||||||
|
if (creep.getActiveBodyparts(MOVE) >= 1 && creep.getActiveBodyparts(WORK) >= 1 && creep.getActiveBodyparts(CARRY) >= 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the creep has been set to this role. This does not include a check of their body parts.
|
||||||
|
* @param {Creep} creep
|
||||||
|
*/
|
||||||
|
is_builder: function(creep) {
|
||||||
|
if (creep.memory.role === ROLE_IDENT) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the creeps logic as a builder
|
||||||
|
* @param {Creep} creep
|
||||||
|
*/
|
||||||
|
run: function(creep) {
|
||||||
|
console.log("roleBuilder ["+creep.name+"] run(): running ...");
|
||||||
|
},
|
||||||
|
|
||||||
|
};
|
@ -1,10 +1,15 @@
|
|||||||
var harvester_obj = require('creeps_harvester');
|
var harvester_obj = require('creeps_harvester');
|
||||||
|
var builder_obj = require('creeps_builder');
|
||||||
|
|
||||||
/** Dictionary to map creep roles to their identifier and an object reference */
|
/** Dictionary to map creep roles to their identifier and an object reference */
|
||||||
var roles = {
|
var roles = {
|
||||||
harvester: {
|
harvester: {
|
||||||
ident: "Harv",
|
ident: harvester_obj.ROLE_IDENT,
|
||||||
obj: harvester_obj
|
obj: harvester_obj,
|
||||||
|
},
|
||||||
|
builder: {
|
||||||
|
ident: builder_obj.ROLE_IDENT,
|
||||||
|
obj: builder_obj,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue