diff --git a/src/roleHandlers/harvester.handler.ts b/src/roleHandlers/harvester.handler.ts index 60f1561..f67d75a 100644 --- a/src/roleHandlers/harvester.handler.ts +++ b/src/roleHandlers/harvester.handler.ts @@ -24,11 +24,7 @@ class HarvesterHandler extends RoleHandler { } private static validateCreepMemory(creep: Creep, state: GameState) { - if (!creep.memory.destination) { - return; // No destination set, nothing to validate - } - - if (creep.memory.destination.type === "source" && !!creep.memory.previousDestination && creep.memory.previousDestination.type === "source") { + if (!!creep.memory.previousDestination && creep.memory.previousDestination.type === "source") { setSpotStatus( state.sourcesStates[creep.memory.previousDestination.id].spots, creep.memory.previousDestination.sourceSpot, @@ -37,6 +33,10 @@ class HarvesterHandler extends RoleHandler { delete creep.memory.previousDestination; } + if (!creep.memory.destination) { + return; // No destination set, nothing to validate + } + if (creep.memory.destination.type === "source" && !creep.store.getFreeCapacity(RESOURCE_ENERGY)) { creep.memory.previousDestination = creep.memory.destination; creep.memory.destination = { diff --git a/src/roleHandlers/upgrader.handler.ts b/src/roleHandlers/upgrader.handler.ts index 69db62f..99470b7 100644 --- a/src/roleHandlers/upgrader.handler.ts +++ b/src/roleHandlers/upgrader.handler.ts @@ -24,11 +24,7 @@ class UpgraderHandler extends RoleHandler { } private static validateCreepMemory(creep: Creep, state: GameState) { - if (!creep.memory.destination) { - return; // No destination set, nothing to validate - } - - if (creep.memory.destination.type === "source" && !!creep.memory.previousDestination && creep.memory.previousDestination.type === "source") { + if (!!creep.memory.previousDestination && creep.memory.previousDestination.type === "source") { setSpotStatus( state.sourcesStates[creep.memory.previousDestination.id].spots, creep.memory.previousDestination.sourceSpot, @@ -37,6 +33,10 @@ class UpgraderHandler extends RoleHandler { delete creep.memory.previousDestination; } + if (!creep.memory.destination) { + return; // No destination set, nothing to validate + } + if (creep.memory.destination.type === "source" && !creep.store.getFreeCapacity(RESOURCE_ENERGY)) { creep.memory.previousDestination = creep.memory.destination;