From 8d47bc105919083ad4d58a32895cefef48a5e68a Mon Sep 17 00:00:00 2001 From: XenoAmess Date: Fri, 9 Sep 2022 01:14:39 +0800 Subject: [PATCH] change from suicide to recycle. --- src/prototype_creep.js | 5 ++--- src/prototype_creep_clean.js | 3 +-- src/prototype_creep_move.js | 2 +- src/prototype_creep_routing.js | 2 +- src/prototype_room_controller.js | 2 +- src/role_carry.js | 7 +++---- src/role_claimer.js | 2 +- src/role_extractor.js | 2 +- src/role_mineral.js | 4 ++-- src/role_quester.js | 6 +++--- src/role_signer.js | 2 +- src/role_sourcer.js | 5 ++--- src/role_watcher.js | 2 +- 13 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/prototype_creep.js b/src/prototype_creep.js index 276a3f4a4..6930eab8f 100644 --- a/src/prototype_creep.js +++ b/src/prototype_creep.js @@ -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; @@ -117,7 +116,7 @@ Creep.prototype.handle = function() { try { if (!this.unit()) { this.log('Unknown role suiciding'); - this.suicide(); + Creep.recycleCreep(this); return; } diff --git a/src/prototype_creep_clean.js b/src/prototype_creep_clean.js index 63d3a125f..f0ea5e6a4 100644 --- a/src/prototype_creep_clean.js +++ b/src/prototype_creep_clean.js @@ -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); }; diff --git a/src/prototype_creep_move.js b/src/prototype_creep_move.js index fc90ca298..798b9919b 100644 --- a/src/prototype_creep_move.js +++ b/src/prototype_creep_move.js @@ -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; } }; diff --git a/src/prototype_creep_routing.js b/src/prototype_creep_routing.js index 5ec77fa23..d7d1cc9fb 100644 --- a/src/prototype_creep_routing.js +++ b/src/prototype_creep_routing.js @@ -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) { diff --git a/src/prototype_room_controller.js b/src/prototype_room_controller.js index 981125b5e..ffba801eb 100644 --- a/src/prototype_room_controller.js +++ b/src/prototype_room_controller.js @@ -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)); }; diff --git a/src/role_carry.js b/src/role_carry.js index f472cf091..26ccfe70d 100644 --- a/src/role_carry.js +++ b/src/role_carry.js @@ -55,7 +55,7 @@ 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; } @@ -63,7 +63,7 @@ function checkHelperEmptyStorage(creep) { 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); } } } @@ -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; diff --git a/src/role_claimer.js b/src/role_claimer.js index 3034b6e8d..a6b05f4b5 100644 --- a/src/role_claimer.js +++ b/src/role_claimer.js @@ -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; }; diff --git a/src/role_extractor.js b/src/role_extractor.js index 552613991..dd492a6de 100644 --- a/src/role_extractor.js +++ b/src/role_extractor.js @@ -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); diff --git a/src/role_mineral.js b/src/role_mineral.js index 9d5068a95..01aae9f44 100644 --- a/src/role_mineral.js +++ b/src/role_mineral.js @@ -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; diff --git a/src/role_quester.js b/src/role_quester.js index afdc95797..4fa053fed 100644 --- a/src/role_quester.js +++ b/src/role_quester.js @@ -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) { @@ -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) { @@ -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') { diff --git a/src/role_signer.js b/src/role_signer.js index 54a287e5e..93b72353a 100644 --- a/src/role_signer.js +++ b/src/role_signer.js @@ -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 { diff --git a/src/role_sourcer.js b/src/role_sourcer.js index ee70819e2..f4446bd68 100644 --- a/src/role_sourcer.js +++ b/src/role_sourcer.js @@ -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; } diff --git a/src/role_watcher.js b/src/role_watcher.js index aca6217b8..75c58cfd9 100644 --- a/src/role_watcher.js +++ b/src/role_watcher.js @@ -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);