diff --git a/src/console/Console.ts b/src/console/Console.ts index 3fa5c9e82..eaa47778d 100644 --- a/src/console/Console.ts +++ b/src/console/Console.ts @@ -26,6 +26,7 @@ export class OvermindConsole { global.setLogLevel = log.setLogLevel; global.suspendColony = this.suspendColony; global.unsuspendColony = this.unsuspendColony; + global.listSuspendedColonies = this.listSuspendedColonies; global.openRoomPlanner = this.openRoomPlanner; global.closeRoomPlanner = this.closeRoomPlanner; global.cancelRoomPlanner = this.cancelRoomPlanner; @@ -68,6 +69,7 @@ export class OvermindConsole { descr['setLogLevel(int)'] = 'set the logging level from 0 - 4'; descr['suspendColony(roomName)'] = 'suspend operations within a colony'; descr['unsuspendColony(roomName)'] = 'resume operations within a suspended colony'; + descr['listSuspendedColonies()'] = 'Prints all suspended colonies'; descr['openRoomPlanner(roomName)'] = 'open the room planner for a room'; descr['closeRoomPlanner(roomName)'] = 'close the room planner and save changes'; descr['cancelRoomPlanner(roomName)'] = 'close the room planner and discard changes'; @@ -250,6 +252,17 @@ export class OvermindConsole { } } + static listSuspendedColonies(): string { + let msg = 'Colonies currently suspended: \n'; + for (let i in Memory.colonies) { + let colonyMemory = Memory.colonies[i] as ColonyMemory | undefined; + if (colonyMemory && colonyMemory.suspend == true) { + msg += 'Colony ' + i + ' \n'; + } + } + return msg; + } + // Room planner control ============================================================================================ static openRoomPlanner(roomName: string): string { diff --git a/src/declarations/memory.d.ts b/src/declarations/memory.d.ts index 433e3a40d..75267b961 100644 --- a/src/declarations/memory.d.ts +++ b/src/declarations/memory.d.ts @@ -1,4 +1,11 @@ type operationMode = 'manual' | 'semiautomatic' | 'automatic'; +/** + * 0: Basic + * 1: Collect from enemy storage/terminal + * 2: Collect from all sources TBD + * 3: Collect all and mine walls for energy TBD + */ +type resourceCollectionMode = number; interface RawMemory { _parsed: any; @@ -21,7 +28,8 @@ interface Memory { operationMode: operationMode; log: LoggerMemory; enableVisuals: boolean; - }; + resourceCollectionMode: resourceCollectionMode; + } profiler?: any; stats: any; constructionSites: { [id: string]: number }; diff --git a/src/directives/colony/clearRoom.ts b/src/directives/colony/clearRoom.ts index c74dc013e..6758b0937 100644 --- a/src/directives/colony/clearRoom.ts +++ b/src/directives/colony/clearRoom.ts @@ -5,6 +5,9 @@ import {Cartographer, ROOMTYPE_CONTROLLER} from '../../utilities/Cartographer'; import {printRoomName} from '../../utilities/utils'; import {MY_USERNAME} from '../../~settings'; import {Directive} from '../Directive'; +import {DirectiveHaul} from "../resource/haul"; +import {Pathing} from "../../movement/Pathing"; +import {DirectiveDismantle} from "../targeting/dismantle"; /** @@ -26,9 +29,12 @@ export class DirectiveClearRoom extends Directive { // Remove if misplaced if (Cartographer.roomType(this.pos.roomName) != ROOMTYPE_CONTROLLER) { log.warning(`${this.print}: ${printRoomName(this.pos.roomName)} is not a controller room; ` + - `removing directive!`); + `removing directive!`); this.remove(true); } + if (Memory.settings.resourceCollectionMode && Memory.settings.resourceCollectionMode >= 1) { + this.memory.keepStorageStructures = true; + } } spawnMoarOverlords() { @@ -42,7 +48,7 @@ export class DirectiveClearRoom extends Directive { private removeAllStructures(): boolean { const keepStorageStructures = this.memory.keepStorageStructures !== undefined - ? this.memory.keepStorageStructures : true; + ? this.memory.keepStorageStructures : true; const keepRoads = this.memory.keepRoads !== undefined ? this.memory.keepRoads : true; const keepContainers = this.memory.keepContainers !== undefined ? this.memory.keepContainers : true; @@ -52,9 +58,14 @@ export class DirectiveClearRoom extends Directive { for (const s of allStructures) { if (s.structureType == STRUCTURE_CONTROLLER) continue; if (keepStorageStructures && - (s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL)) { + (s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL) && !s.isEmpty) { + // Create a collection flag + DirectiveHaul.createIfNotPresent(s.pos, 'pos'); continue; } + if (s.structureType == STRUCTURE_NUKER && s.energy > 50000) { + DirectiveHaul.createIfNotPresent(s.pos, 'pos'); + } if (keepRoads && s.structureType == STRUCTURE_ROAD) { continue; } @@ -79,9 +90,31 @@ export class DirectiveClearRoom extends Directive { if (this.room && this.room.my) { const done = this.removeAllStructures(); if (done) { - this.room.controller!.unclaim(); + let res = this.room.controller!.unclaim(); + // Clear up flags + for (let flag of this.room.flags) { + if (!DirectiveClearRoom.filter(flag) && !DirectiveHaul.filter(flag)) { + flag.remove(); + } + } log.notify(`Removing clearRoom directive in ${this.pos.roomName}: operation completed.`); - this.remove(); + if (res == OK) { + this.remove(); + } + } + // Clear path if controller is not reachable + } else if (this.room && this.room.creeps.length > 1) { + let currentlyDismantlingLocations = DirectiveDismantle.find(this.room.flags); + + if (currentlyDismantlingLocations.length == 0) { + let pathablePos = this.room.creeps[0] ? this.room.creeps[0].pos + : Pathing.findPathablePosition(this.room.name); + let blockingLocation = Pathing.findBlockingPos(pathablePos, this.room.controller!.pos, + _.filter(this.room.structures, s => !s.isWalkable)); + if (blockingLocation && !Directive.isPresent(blockingLocation, 'pos')) { + log.notify(`Adding dismantle directive for ${this.pos.roomName} to reach controller.`); + DirectiveDismantle.create(blockingLocation); + } } } diff --git a/src/memory/Memory.ts b/src/memory/Memory.ts index 35db27790..6f74b2750 100644 --- a/src/memory/Memory.ts +++ b/src/memory/Memory.ts @@ -199,6 +199,7 @@ export class Mem { operationMode: DEFAULT_OPERATION_MODE, log : {}, enableVisuals: true, + resourceCollectionMode: 0, }); if (!Memory.stats) { Memory.stats = {}; diff --git a/src/overlords/situational/hauler.ts b/src/overlords/situational/hauler.ts index 8164b270d..cb7758b1e 100644 --- a/src/overlords/situational/hauler.ts +++ b/src/overlords/situational/hauler.ts @@ -55,7 +55,7 @@ export class HaulingOverlord extends Overlord { // Pick up drops first if (this.directive.hasDrops) { const allDrops: Resource[] = _.flatten(_.values(this.directive.drops)); - const drop = allDrops[0]; + const drop = _.find(allDrops, drop => drop.resourceType != "energy") || allDrops[0]; if (drop) { hauler.task = Tasks.pickup(drop); return;