Skip to content

Commit

Permalink
change from suicide to recycle.
Browse files Browse the repository at this point in the history
  • Loading branch information
XenoAmess committed Sep 9, 2022
1 parent fc4768f commit 8d47bc1
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 24 deletions.
5 changes: 2 additions & 3 deletions src/prototype_creep.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ Creep.prototype.checkForHandle = function() {
const role = this.memory.role;
if (!role) {
this.log('Creep role not defined for: ' + this.id + ' ' + this.name.split('-')[0].replace(/[0-9]/g, ''));
this.memory.killed = true;
this.suicide();
Creep.recycleCreep(this);
return false;
}
return true;
Expand All @@ -117,7 +116,7 @@ Creep.prototype.handle = function() {
try {
if (!this.unit()) {
this.log('Unknown role suiciding');
this.suicide();
Creep.recycleCreep(this);
return;
}

Expand Down
3 changes: 1 addition & 2 deletions src/prototype_creep_clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ Creep.prototype.cleanSetTargetId = function() {
}
}
this.memory.targetReached = true;
this.memory.killed = true;
this.log('Nothing found, suicide');
this.suicide();
Creep.recycleCreep(this);
// return Creep.recycleCreep(this);
};
2 changes: 1 addition & 1 deletion src/prototype_creep_move.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Creep.prototype.moveCreepCheckRoleAndTarget = function(creep, direction) {
if (role === 'upgrader' &&
(targetRole === 'universal' || targetRole === 'sourcer' || targetRole === 'upgrader')) {
this.log('config_creep_move suicide ' + targetRole);
creep.suicide();
Creep.recycleCreep(creep);
return true;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/prototype_creep_routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Creep.prototype.followPath = function(action) {
path = this.prepareRoutingMemory();
} catch (e) {
this.log(`Suiciding, cannot prepare routing ${e} ${e.stack}`);
this.suicide();
Creep.recycleCreep(this);
return true;
}
if (!path) {
Expand Down
2 changes: 1 addition & 1 deletion src/prototype_room_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,5 @@ Room.prototype.clearRoom = function() {
_.each(constructionSites, (cs) => cs.remove());

const creeps = this.findMyCreeps();
_.each(creeps, (cs) => cs.suicide());
_.each(creeps, (cs) => Creep.recycleCreep(cs));
};
7 changes: 3 additions & 4 deletions src/role_carry.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ function checkHelperEmptyStorage(creep) {
if (creep.room.name === creep.memory.routing.targetRoom) {
const targetStructure = Game.getObjectById(creep.memory.routing.targetId);
if (targetStructure === null) {
creep.suicide();
Creep.recycleCreep(creep);
return;
}

if (targetStructure.structureType === STRUCTURE_STORAGE) {
creep.say('storage');
if (targetStructure.store.energy === 0) {
creep.log('Suiciding the storage I should get the energy from is empty');
creep.suicide();
Creep.recycleCreep(creep);
}
}
}
Expand Down Expand Up @@ -399,8 +399,7 @@ roles.carry.action = function(creep) {
// End of path, can't harvest, suicide (otherwise the sourcer gets stuck)
if (!reverse && creep.body.filter((part) => part.type === WORK).length === 0) {
// creep.log('Suiciding because end of path, no energy, do not want to get in the way of the sourcer (better recycle?)');
creep.memory.killed = true;
creep.suicide();
Creep.recycleCreep(creep);
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion src/role_claimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ roles.claimer.action = function(creep) {
const returnCode = creep.claimController(creep.room.controller);
if (returnCode === OK) {
creep.creepLog('New claimer, in room, claimed');
creep.suicide();
Creep.recycleCreep(creep);
}
return true;
};
2 changes: 1 addition & 1 deletion src/role_extractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function getMineral(creep) {

roles.extractor.action = function(creep) {
if (!creep.room.terminal) {
creep.suicide();
Creep.recycleCreep(creep);
return true;
}
const mineral = getMineral(creep);
Expand Down
4 changes: 2 additions & 2 deletions src/role_mineral.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ function transfer(creep, target, resource) {
*/
function checkForSuicide(creep) {
if (!creep.room.terminal) {
creep.suicide();
Creep.recycleCreep(creep);
return true;
}
if (creep.ticksToLive < 50 && _.sum(creep.carry) === 0) {
// early suicide to not waste minerals
creep.suicide();
Creep.recycleCreep(creep);
return true;
}
return false;
Expand Down
6 changes: 3 additions & 3 deletions src/role_quester.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ roles.quester.settings = {
roles.quester.questLost = function(creep, quest, reason, value) {
creep.log(`Quest lost cs: ${value} ${JSON.stringify(quest)}`);
delete Memory.quests[creep.memory.level];
creep.suicide();
Creep.recycleCreep(creep);
};

roles.quester.questWon = function(creep, quest) {
Expand All @@ -33,7 +33,7 @@ roles.quester.questWon = function(creep, quest) {
};
creep.room.terminal.send(RESOURCE_ENERGY, 100, quest.player.room, JSON.stringify(response));
delete Memory.quests[creep.memory.level];
creep.suicide();
Creep.recycleCreep(creep);
};

roles.quester.handleBuildConstructionSite = function(creep, quest) {
Expand Down Expand Up @@ -67,7 +67,7 @@ roles.quester.action = function(creep) {
const quest = Memory.quests[creep.memory.level];
if (!quest) {
creep.log(`Quest ${creep.memory.level} not found, suiciding`);
creep.suicide();
Creep.recycleCreep(creep);
return;
}
if (quest.quest === 'buildcs') {
Expand Down
2 changes: 1 addition & 1 deletion src/role_signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ roles.signer.action = function(creep) {
// creep.memory.routing = creep.memory.nextTarget.routing;
// creep.memory.nextTarget = creep.memory.nextTarget.nextTarget;
// } else {
creep.suicide();
Creep.recycleCreep(creep);
// }
return true;
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/role_sourcer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,14 @@ function harvest(creep) {

if (returnCode === ERR_NOT_OWNER) {
creep.log('Suiciding, someone else reserved the controller');
creep.memory.killed = true;
creep.suicide();
Creep.recycleCreep(creep);
return false;
}

if (returnCode === ERR_NO_BODYPART) {
creep.room.checkRoleToSpawn('defender', 2, undefined, creep.room.name);
creep.respawnMe();
creep.suicide();
Creep.recycleCreep(creep);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/role_watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ roles.watcher.action = function(creep) {
});
if (creepOfRole.length > 1) {
creepOfRole = _.sortBy(creepOfRole, (c) => c.ticksToLive);
creepOfRole[0].suicide();
creepOfRole[0].recycleCreep();
}
} else {
creep.moveToMy(pos, near);
Expand Down

0 comments on commit 8d47bc1

Please sign in to comment.