From 41e1edfef66a493bb61bb36b9084dd26f92684a9 Mon Sep 17 00:00:00 2001 From: Etienne Samson Date: Wed, 8 Apr 2026 13:48:53 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Add=20energyStructures=20option?= =?UTF-8?q?=20to=20Spawn.renewCreep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game/structures.js | 12 ++++++++---- src/processor/intents/spawns/renew-creep.js | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/game/structures.js b/src/game/structures.js index 3432c42c..1459d56b 100644 --- a/src/game/structures.js +++ b/src/game/structures.js @@ -1234,8 +1234,10 @@ exports.make = function(_runtimeData, _intents, _register, _globals) { return C.OK; }); - StructureSpawn.prototype.renewCreep = register.wrapFn(function(target) { - + StructureSpawn.prototype.renewCreep = register.wrapFn(function(target, options = {}) { + if (!_.isObject(options)) { + return C.ERR_INVALID_ARGS; + } if(this.spawning) { return C.ERR_BUSY; } @@ -1252,7 +1254,9 @@ exports.make = function(_runtimeData, _intents, _register, _globals) { if(!target.pos.isNearTo(this.pos)) { return C.ERR_NOT_IN_RANGE; } - if(this.room.energyAvailable < Math.ceil(C.SPAWN_RENEW_RATIO * utils.calcCreepCost(target.body) / C.CREEP_SPAWN_TIME / target.body.length)) { + let energyStructures = options.energyStructures && _.uniq(_.map(options.energyStructures, 'id')); + let energyAvailable = energyStructures ? calcEnergyAvailable(runtimeData.roomObjects, energyStructures) : this.room.energyAvailable; + if(energyAvailable < Math.ceil(C.SPAWN_RENEW_RATIO * utils.calcCreepCost(target.body) / C.CREEP_SPAWN_TIME / target.body.length)) { return C.ERR_NOT_ENOUGH_ENERGY; } if(target.ticksToLive + Math.floor(C.SPAWN_RENEW_RATIO * C.CREEP_LIFE_TIME / C.CREEP_SPAWN_TIME / target.body.length) > C.CREEP_LIFE_TIME) { @@ -1262,7 +1266,7 @@ exports.make = function(_runtimeData, _intents, _register, _globals) { register.deprecated('Using `StructureSpawn.renewCreep` on a boosted creep is deprecated and will throw an error soon. Please remove boosts using `StructureLab.unboostCreep` before renewing.'); } - intents.set(this.id, 'renewCreep', {id: target.id}); + intents.set(this.id, 'renewCreep', {id: target.id, energyStructures}); return C.OK; }); diff --git a/src/processor/intents/spawns/renew-creep.js b/src/processor/intents/spawns/renew-creep.js index 6818f76a..ef63cebd 100644 --- a/src/processor/intents/spawns/renew-creep.js +++ b/src/processor/intents/spawns/renew-creep.js @@ -31,7 +31,7 @@ module.exports = function(object, intent, scope) { } var cost = Math.ceil(C.SPAWN_RENEW_RATIO * utils.calcCreepCost(target.body) / C.CREEP_SPAWN_TIME / target.body.length); - var result = require('./_charge-energy')(object, cost, undefined, scope); + var result = require('./_charge-energy')(object, cost, intent.energyStructures, scope); if(!result) { return;