diff --git a/src/other/profilerRegister.ts b/src/other/profilerRegister.ts index 774c6aa8c..314ff8282 100644 --- a/src/other/profilerRegister.ts +++ b/src/other/profilerRegister.ts @@ -8,7 +8,6 @@ import { StatsManager } from 'international/stats' import { ConstructionManager } from 'room/construction/construction' import { RemotesManager } from 'room/commune/remotesManager' import { HaulRequestManager } from 'room/commune/haulRequestManager' -import { WorkRequestManager } from 'room/commune/workRequest' import { Quad } from 'room/creeps/roleManagers/antifa/quad' import { DynamicSquad } from 'room/creeps/roleManagers/antifa/dynamicSquad' import { Duo } from 'room/creeps/roleManagers/antifa/duo' @@ -116,6 +115,7 @@ import { RoomServices } from 'room/roomServices' import { HaulerNeedOps } from 'room/commune/haulerNeedOps' import { MyCreepServices } from 'room/creeps/myCreepServices' import { MyPowerCreepServices } from 'room/creeps/myPowerCreepServices' +import { WorkRequestOps } from 'room/commune/workRequest' export function profilerRegister() { // Classes @@ -162,7 +162,6 @@ export function profilerRegister() { profiler.registerClass(ConstructionManager, 'ConstructionManager') profiler.registerClass(RemotesManager, 'RemotesManager') profiler.registerClass(HaulRequestManager, 'HaulRequestManager') - profiler.registerClass(WorkRequestManager, 'WorkRequestManager') profiler.registerClass(EndTickCreepManager, 'EndTickCreepManager') profiler.registerClass(LinkManager, 'LinkManager') profiler.registerClass(DefenceProcs, 'DefenceProcs') @@ -193,6 +192,7 @@ export function profilerRegister() { profiler.registerClass(ObserverProcs, 'ObserverProcs') profiler.registerClass(PowerSpawnProcs, 'PowerSpawnProcs') profiler.registerClass(HaulerNeedOps, 'HaulerNeedOps') + profiler.registerClass(WorkRequestOps, "WorkRequestOps") // Creep classes diff --git a/src/room/commune/commune.ts b/src/room/commune/commune.ts index b21f70ba1..101e2407e 100644 --- a/src/room/commune/commune.ts +++ b/src/room/commune/commune.ts @@ -18,7 +18,6 @@ import './factory' import { LabManager } from './labs' import './links' import { RemotesManager } from './remotesManager' -import { WorkRequestManager } from './workRequest' import { CombatRequestManager } from './combatRequest' import { HaulRequestManager } from './haulRequestManager' import { packCoord, unpackPosAt } from 'other/codec' @@ -49,7 +48,6 @@ export class CommuneManager { remotesManager: RemotesManager - workRequestManager: WorkRequestManager combatRequestManager: CombatRequestManager haulRequestManager: HaulRequestManager @@ -90,7 +88,6 @@ export class CommuneManager { this.remotesManager = new RemotesManager(this) - this.workRequestManager = new WorkRequestManager(this) this.combatRequestManager = new CombatRequestManager(this) this.haulRequestManager = new HaulRequestManager(this) diff --git a/src/room/commune/communeOps.ts b/src/room/commune/communeOps.ts index c2a5125e2..3d6bdb7af 100644 --- a/src/room/commune/communeOps.ts +++ b/src/room/commune/communeOps.ts @@ -2,10 +2,12 @@ import { RoomUtils } from 'room/roomUtils' import { CommuneDataOps, communeData } from './communeData' import { CommuneUtils } from './communeUtils' import { + CombatRequestKeys, Result, RoomLogisticsRequestTypes, RoomMemoryKeys, RoomTypes, + WorkRequestKeys, creepRoles, haulerUpdateDefault, } from '../../constants/general' @@ -24,6 +26,7 @@ import { TowerProcs } from './towerProcs' import { HaulerNeedOps } from './haulerNeedOps' import { CommuneManager } from './commune' import { RoomOps } from 'room/roomOps' +import { WorkRequestOps } from './workRequest' /** * Minor processes for communes @@ -158,7 +161,7 @@ export class CommuneOps { TerminalProcs.preTickRun(room) communeManager.remotesManager.initRun() communeManager.haulRequestManager.preTickRun() - communeManager.workRequestManager.preTickRun() + WorkRequestOps.tryCreateWorkRequest(room) } private static preTickTest(room: Room) { @@ -184,7 +187,7 @@ export class CommuneOps { TerminalProcs.run(room) - communeManager.workRequestManager.run() + WorkRequestOps.manageWorkRequest(room) communeManager.combatRequestManager.run() communeManager.haulRequestManager.run() @@ -351,4 +354,43 @@ export class CommuneOps { remoteMemory[RoomMemoryKeys.type] = RoomTypes.neutral RoomNameUtils.cleanMemory(remoteName) } + + static stopWorkRequestResponse(room: Room, deleteCombat?: boolean) { + const roomMemory = Memory.rooms[room.name] + const request = Memory.workRequests[roomMemory[RoomMemoryKeys.workRequest]] + + if (deleteCombat) { + CommuneOps.deleteCombatForWorkRequest(room) + } + + delete request[WorkRequestKeys.responder] + delete roomMemory[RoomMemoryKeys.workRequest] + } + + static abandonWorkRequest(room: Room, abandonTime: number = 20000) { + const roomMemory = Memory.rooms[room.name] + + CommuneOps.deleteCombatForWorkRequest(room) + + delete Memory.workRequests[roomMemory[RoomMemoryKeys.workRequest]] + delete roomMemory[RoomMemoryKeys.workRequest] + } + + static deleteCombatForWorkRequest(room: Room) { + const workRequestName = Memory.rooms[room.name][RoomMemoryKeys.workRequest] + const combatRequest = Memory.combatRequests[workRequestName] + if (!combatRequest) return + + if (combatRequest[CombatRequestKeys.responder]) { + const combatRequestResponder = Game.rooms[combatRequest[CombatRequestKeys.responder]] + CommuneOps.deleteCombatRequest( + combatRequestResponder, + combatRequest[CombatRequestKeys.responder], + combatRequestResponder.memory[RoomMemoryKeys.combatRequests].indexOf(workRequestName), + ) + return + } + + delete Memory.combatRequests[workRequestName] + } } diff --git a/src/room/commune/workRequest.ts b/src/room/commune/workRequest.ts index 1b5649fab..2821f36ac 100644 --- a/src/room/commune/workRequest.ts +++ b/src/room/commune/workRequest.ts @@ -14,33 +14,25 @@ import { CommuneOps } from './communeOps' const checkRoomStatusInverval = randomIntRange(200, 500) -export class WorkRequestManager { - communeManager: CommuneManager +export class WorkRequestOps { + static tryCreateWorkRequest(room: Room) { - constructor(communeManager: CommuneManager) { - this.communeManager = communeManager - } + // create a workRequest if needed - preTickRun() { - const { room } = this.communeManager + if (room.roomManager.structures.spawn.length) return - // create a workRequest if needed + let request = Memory.workRequests[room.name] + if (request) { + request[WorkRequestKeys.priority] = 0 + return + } - if (room.roomManager.structures.spawn.length) return - - let request = Memory.workRequests[room.name] - if (request) { - request[WorkRequestKeys.priority] = 0 - return + request = Memory.workRequests[room.name] = { + [WorkRequestKeys.priority]: 0, + } } - request = Memory.workRequests[room.name] = { - [WorkRequestKeys.priority]: 0, - } - } - - run() { - const { room } = this.communeManager + static manageWorkRequest(room: Room) { const roomMemory = Memory.rooms[room.name] const requestName = roomMemory[RoomMemoryKeys.workRequest] @@ -55,7 +47,7 @@ export class WorkRequestManager { // if we have no spawn, stop if (!room.roomManager.structures.spawn.length) { - this.stopResponse(true) + CommuneOps.stopWorkRequestResponse(room, true) return } @@ -68,7 +60,7 @@ export class WorkRequestManager { ) { // Delete the request so long as the new type isn't ally - this.stopResponse(type !== RoomTypes.ally) + CommuneOps.stopWorkRequestResponse(room, type !== RoomTypes.ally) return } @@ -78,25 +70,25 @@ export class WorkRequestManager { Memory.rooms[room.name][RoomMemoryKeys.status] !== Memory.rooms[requestName][RoomMemoryKeys.status] ) { - this.delete(requestName, request) + CommuneOps.abandonWorkRequest(room) return } // If the request has been abandoned, have the commune abandon it too if (request[WorkRequestKeys.abandon] > 0) { - this.stopResponse() + CommuneOps.stopWorkRequestResponse(room) return } if (room.energyCapacityAvailable < 650) { - this.stopResponse() + CommuneOps.stopWorkRequestResponse(room) return } const requestRoom = Game.rooms[requestName] if (!requestRoom && Game.gcl.level === CollectiveManager.communes.size) { - this.stopResponse(true) + CommuneOps.stopWorkRequestResponse(room, true) return } @@ -111,7 +103,7 @@ export class WorkRequestManager { requestRoom.roomManager.structures.spawn.length && requestRoom.roomManager.structures.spawn.find(spawn => spawn.my) ) { - this.delete(requestName, request) + CommuneOps.abandonWorkRequest(room) return } @@ -121,7 +113,8 @@ export class WorkRequestManager { if (invaderCores.length) { // Abandon for the core's remaining existance plus the estimated reservation time - this.abandon( + CommuneOps.abandonWorkRequest( + room, invaderCores[0].effects[EFFECT_COLLAPSE_TIMER].ticksRemaining + CONTROLLER_RESERVE_MAX, ) return @@ -158,53 +151,5 @@ export class WorkRequestManager { if (request[WorkRequestKeys.minDamage] > 0 || request[WorkRequestKeys.minHeal] > 0) this.abandonRemote() } */ - } - - private stopResponse(deleteCombat?: boolean) { - const roomMemory = this.communeManager.room.memory - const request = Memory.workRequests[roomMemory[RoomMemoryKeys.workRequest]] - - if (deleteCombat) this.deleteCombat() - - delete request[WorkRequestKeys.responder] - delete roomMemory[RoomMemoryKeys.workRequest] - } - - private delete(requestName: string, request: WorkRequest) { - const roomMemory = this.communeManager.room.memory - - this.deleteCombat() - - delete Memory.workRequests[roomMemory[RoomMemoryKeys.workRequest]] - delete roomMemory[RoomMemoryKeys.workRequest] - } - - private abandon(abandonTime: number = 20000) { - const roomMemory = this.communeManager.room.memory - const request = Memory.workRequests[roomMemory[RoomMemoryKeys.workRequest]] - - this.deleteCombat() - - request[WorkRequestKeys.abandon] = abandonTime - delete request[WorkRequestKeys.responder] - delete roomMemory[RoomMemoryKeys.workRequest] - } - - private deleteCombat() { - const workRequestName = this.communeManager.room.memory[RoomMemoryKeys.workRequest] - const combatRequest = Memory.combatRequests[workRequestName] - if (!combatRequest) return - - if (combatRequest[CombatRequestKeys.responder]) { - const combatRequestResponder = Game.rooms[combatRequest[CombatRequestKeys.responder]] - CommuneOps.deleteCombatRequest( - combatRequestResponder, - combatRequest[CombatRequestKeys.responder], - combatRequestResponder.memory[RoomMemoryKeys.combatRequests].indexOf(workRequestName), - ) - return } - - delete Memory.combatRequests[workRequestName] - } }