diff --git a/Traveler.js b/Traveler.js index 716b018..0c6a5d6 100644 --- a/Traveler.js +++ b/Traveler.js @@ -398,8 +398,9 @@ class Traveler { * @returns {any} */ static getStructureMatrix(room, freshMatrix) { - if (!this.structureMatrixCache[room.name] || (freshMatrix && Game.time !== this.structureMatrixTick)) { - this.structureMatrixTick = Game.time; + if (!this.structureMatrixTick) this.structureMatrixTick = {}; + if (!this.structureMatrixCache[room.name] || (freshMatrix && Game.time !== this.structureMatrixTick[room.name])) { + this.structureMatrixTick[room.name] = Game.time; let matrix = new PathFinder.CostMatrix(); this.structureMatrixCache[room.name] = Traveler.addStructuresToMatrix(room, matrix, 1); } @@ -411,8 +412,9 @@ class Traveler { * @returns {any} */ static getCreepMatrix(room) { - if (!this.creepMatrixCache[room.name] || Game.time !== this.creepMatrixTick) { - this.creepMatrixTick = Game.time; + if (!this.creepMatrixTick) this.creepMatrixTick = {}; + if (!this.creepMatrixCache[room.name] || Game.time !== this.creepMatrixTick[room.name]) { + this.creepMatrixTick[room.name] = Game.time; this.creepMatrixCache[room.name] = Traveler.addCreepsToMatrix(room, this.getStructureMatrix(room, true).clone()); } return this.creepMatrixCache[room.name]; diff --git a/Traveler.ts b/Traveler.ts index e2da125..065dd8b 100644 --- a/Traveler.ts +++ b/Traveler.ts @@ -7,8 +7,8 @@ export class Traveler { private static structureMatrixCache: {[roomName: string]: CostMatrix} = {}; private static creepMatrixCache: {[roomName: string]: CostMatrix} = {}; - private static creepMatrixTick: number; - private static structureMatrixTick: number; + private static creepMatrixTick: {[roomName: string]: number} = {}; + private static structureMatrixTick: {[roomName: string]: number} = {}; /** * move creep to destination @@ -458,8 +458,8 @@ export class Traveler { */ public static getStructureMatrix(room: Room, freshMatrix?: boolean): CostMatrix { - if (!this.structureMatrixCache[room.name] || (freshMatrix && Game.time !== this.structureMatrixTick)) { - this.structureMatrixTick = Game.time; + if (!this.structureMatrixCache[room.name] || (freshMatrix && Game.time !== this.structureMatrixTick[room.name])) { + this.structureMatrixTick[room.name] = Game.time; let matrix = new PathFinder.CostMatrix(); this.structureMatrixCache[room.name] = Traveler.addStructuresToMatrix(room, matrix, 1); } @@ -473,8 +473,8 @@ export class Traveler { */ public static getCreepMatrix(room: Room) { - if (!this.creepMatrixCache[room.name] || Game.time !== this.creepMatrixTick) { - this.creepMatrixTick = Game.time; + if (!this.creepMatrixCache[room.name] || Game.time !== this.creepMatrixTick[room.name]) { + this.creepMatrixTick[room.name] = Game.time; this.creepMatrixCache[room.name] = Traveler.addCreepsToMatrix(room, this.getStructureMatrix(room, true).clone()); }