-
Notifications
You must be signed in to change notification settings - Fork 0
Structures: Extensions
The Controller upgrade gives access to some new structures: walls, ramparts, and extensions. We’ll discuss walls and ramparts in the next Tutorial section, for now let’s talk about extensions.
Extensions are required to build larger creeps. A creep with only one body part of one type works poorly. Giving it several WORKs will make him work proportionally faster.
However, such a creep will be costly and a lone spawn can only contain 300 energy units. To build creeps costing over 300 energy units you need spawn extensions.
The second Controller level has 5 extensions available for you to build. This number increases with each new level.
You can place extensions at any spot in your room, and a spawn can use them regardless of the distance
Let’s create a new creep whose purpose is to build structures. This process will be similar to the previous Tutorial sections. But this time let’s set the memory for the new creep right in the method Spawn.createCreep by passing it as the third function argument.
Spawn a creep with the body [WORK,CARRY,MOVE], the name Builder1, and {role:'builder'} as its memory.
`Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Builder1', { role: 'builder' } );'
Our new creep won’t move until we define the behavior for the role builder.
As before, let’s move this role into a separate module role.builder. The building is carried out by applying the method Creep.build to the construction sites searchable by Room.find(FIND_CONSTRUCTION_SITES). The structure requires energy which your creep can harvest on its own.
To avoid having the creep run back and forth too often but make it deplete the cargo, let’s complicate our logic by creating a new Boolean variable creep.memory.building which will tell the creep when to switch tasks.
Create the module role.builder with a behavior logic for a new creep.
var roleBuilder = {
/** @param {Creep} creep **/
run: function(creep) {
if(creep.memory.building && creep.carry.energy == 0) {
creep.memory.building = false;
}
if(!creep.memory.building && creep.carry.energy == creep.carryCapacity) {
creep.memory.building = true;
}
if(creep.memory.building) {
var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
if(targets.length) {
if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(targets[0]);
}
}
}
else {
var sources = creep.room.find(FIND_SOURCES);
if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) {
creep.moveTo(sources[0]);
}
}
}
};
module.exports = roleBuilder;