diff --git a/src/game/creeps.js b/src/game/creeps.js index 07fb0147..53587f9e 100644 --- a/src/game/creeps.js +++ b/src/game/creeps.js @@ -985,6 +985,18 @@ exports.make = function(_runtimeData, _intents, _register, _globals) { return C.OK; }); + Creep.prototype.notifiesWhenAttacked = register.wrapFn(function() { + + if(!this.my) { + return C.ERR_NOT_OWNER; + } + if(this.spawning) { + return C.ERR_BUSY; + } + + return !!data(this.id).notifyWhenAttacked; + }); + Creep.prototype.notifyWhenAttacked = register.wrapFn(function(enabled) { if(!this.my) { diff --git a/src/game/power-creeps.js b/src/game/power-creeps.js index dcabece5..0adae683 100644 --- a/src/game/power-creeps.js +++ b/src/game/power-creeps.js @@ -372,6 +372,18 @@ exports.make = function(_runtimeData, _intents, _register, _globals) { return C.OK; }); + PowerCreep.prototype.notifiesWhenAttacked = register.wrapFn(function() { + + if(!this.room) { + return C.ERR_BUSY; + } + if(!this.my) { + return C.ERR_NOT_OWNER; + } + + return !!data(this.id).notifyWhenAttacked; + }); + PowerCreep.prototype.notifyWhenAttacked = register.wrapFn(function(enabled) { if(!this.room) { diff --git a/src/game/structures.js b/src/game/structures.js index 3432c42c..9b174a19 100644 --- a/src/game/structures.js +++ b/src/game/structures.js @@ -86,6 +86,18 @@ exports.make = function(_runtimeData, _intents, _register, _globals) { return C.OK; }); + Structure.prototype.notifiesWhenAttacked = register.wrapFn(function() { + + if(!this.room) { + return C.ERR_INVALID_TARGET; + } + if(this.my === false || (this.room.controller && this.room.controller.owner && !this.room.controller.my)) { + return C.ERR_NOT_OWNER; + } + + return !!data(this.id).notifyWhenAttacked; + }); + Structure.prototype.notifyWhenAttacked = register.wrapFn(function(enabled) { if(!this.room) { return C.ERR_INVALID_TARGET; @@ -1089,6 +1101,8 @@ exports.make = function(_runtimeData, _intents, _register, _globals) { } } + const notifyWhenAttacked = options.notifyWhenAttacked === undefined ? true : !!options.notifyWhenAttacked; + if(!this.my) { return C.ERR_NOT_OWNER; } @@ -1212,11 +1226,20 @@ exports.make = function(_runtimeData, _intents, _register, _globals) { } }); - intents.set(this.id, 'createCreep', {name, body, energyStructures, directions}); + intents.set(this.id, 'createCreep', {name, body, energyStructures, directions, notifyWhenAttacked}); return C.OK; }); + StructureSpawn.prototype.notifiesWhenAttacked = register.wrapFn(function() { + + if(!this.my) { + return C.ERR_NOT_OWNER; + } + + return !!data(this.id).notifyWhenAttacked; + }); + StructureSpawn.prototype.notifyWhenAttacked = register.wrapFn(function(enabled) { if(!this.my) { diff --git a/src/processor/intents/spawns/create-creep.js b/src/processor/intents/spawns/create-creep.js index 08ea6025..5411843b 100644 --- a/src/processor/intents/spawns/create-creep.js +++ b/src/processor/intents/spawns/create-creep.js @@ -33,6 +33,8 @@ module.exports = function(spawn, intent, scope) { } } + const notifyWhenAttacked = intent.notifyWhenAttacked === undefined ? true : !!intent.notifyWhenAttacked; + intent.body = intent.body.slice(0, C.MAX_CREEP_SIZE); var cost = utils.calcCreepCost(intent.body); @@ -90,7 +92,7 @@ module.exports = function(spawn, intent, scope) { hitsMax: body.length * 100, spawning: true, fatigue: 0, - notifyWhenAttacked: true + notifyWhenAttacked, }; if(spawn.tutorial) {