From 08ec3954f4c4258a7892a1751e39bec632be5290 Mon Sep 17 00:00:00 2001 From: Alexander Scherer Date: Sun, 22 Nov 2020 13:34:05 +0100 Subject: [PATCH] :recycle: refactor deprecated isRoomAvailable function --- src/Overseer.ts | 11 +++++++++-- src/overlords/scouting/randomWalker.ts | 3 ++- src/strategy/ExpansionPlanner.ts | 4 ++-- src/utilities/utils.ts | 7 +++++++ 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Overseer.ts b/src/Overseer.ts index 68664c3b3..963c8a7e8 100644 --- a/src/Overseer.ts +++ b/src/Overseer.ts @@ -31,7 +31,14 @@ import { ROOMTYPE_SOURCEKEEPER } from './utilities/Cartographer'; import {p} from './utilities/random'; -import {canClaimAnotherRoom, getAllRooms, hasJustSpawned, minBy, onPublicServer} from './utilities/utils'; +import { + canClaimAnotherRoom, + getAllRooms, + hasJustSpawned, + isRoomAvailable, + minBy, + onPublicServer +} from './utilities/utils'; import {MUON, MY_USERNAME, USE_TRY_CATCH} from './~settings'; @@ -378,7 +385,7 @@ export class Overseer implements IOverseer { } const neighboringRooms = _.values(Game.map.describeExits(roomName)) as string[]; const isReachableFromColony = _.any(neighboringRooms, r => colony.roomNames.includes(r)); - return isReachableFromColony && Game.map.isRoomAvailable(roomName); + return isReachableFromColony && isRoomAvailable(roomName); }); } diff --git a/src/overlords/scouting/randomWalker.ts b/src/overlords/scouting/randomWalker.ts index 367255489..05daf6efa 100644 --- a/src/overlords/scouting/randomWalker.ts +++ b/src/overlords/scouting/randomWalker.ts @@ -3,6 +3,7 @@ import {Roles, Setups} from '../../creepSetups/setups'; import {OverlordPriority} from '../../priorities/priorities_overlords'; import {profile} from '../../profiler/decorator'; import {Tasks} from '../../tasks/Tasks'; +import {isRoomAvailable} from '../../utilities/utils'; import {Zerg} from '../../zerg/Zerg'; import {Overlord} from '../Overlord'; @@ -40,7 +41,7 @@ export class RandomWalkerScoutOverlord extends Overlord { // Pick a new room const neighboringRooms = _.values(Game.map.describeExits(scout.pos.roomName)) as string[]; const roomName = _.sample(neighboringRooms); - if (Game.map.isRoomAvailable(roomName)) { + if (isRoomAvailable(roomName)) { scout.task = Tasks.goToRoom(roomName); } } diff --git a/src/strategy/ExpansionPlanner.ts b/src/strategy/ExpansionPlanner.ts index 2b0ea4cc4..9fb8b8886 100644 --- a/src/strategy/ExpansionPlanner.ts +++ b/src/strategy/ExpansionPlanner.ts @@ -6,7 +6,7 @@ import {Autonomy, getAutonomyLevel, Mem} from '../memory/Memory'; import {Pathing} from '../movement/Pathing'; import {profile} from '../profiler/decorator'; import {Cartographer} from '../utilities/Cartographer'; -import {maxBy} from '../utilities/utils'; +import {isRoomAvailable, maxBy} from '../utilities/utils'; import {MAX_OWNED_ROOMS, SHARD3_MAX_OWNED_ROOMS} from '../~settings'; import {MIN_EXPANSION_DISTANCE} from './ExpansionEvaluator'; @@ -123,7 +123,7 @@ export class ExpansionPlanner implements IExpansionPlanner { } } // Update best choices - if (score > bestScore && Game.map.isRoomAvailable(roomName)) { + if (score > bestScore && isRoomAvailable(roomName)) { bestScore = score; bestRoom = roomName; } diff --git a/src/utilities/utils.ts b/src/utilities/utils.ts index 241913c3a..f8a2643e8 100644 --- a/src/utilities/utils.ts +++ b/src/utilities/utils.ts @@ -352,3 +352,10 @@ export function rotatedMatrix(matrix: T[][], clockwiseTurns: 0 | 1 | 2 | 3): export function cyclicListPermutation(list: T[], offset: number): T[] { return list.slice(offset).concat(list.slice(0, offset)); } + +export function isRoomAvailable(roomName: string) { + const roomStatus = Game.map.getRoomStatus(roomName); + const expiration = roomStatus.timestamp; + // TODO: cache result and only recheck after expiration + return roomStatus.status === 'normal'; +}