From c92e6fd5cbe862e6e5a38879177aee9811486442 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Wed, 10 Apr 2019 13:03:56 -0700 Subject: [PATCH 1/9] Adding simple collection during room clearing phase --- src/directives/colony/clearRoom.ts | 7 +++++-- src/utilities/utils.ts | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/directives/colony/clearRoom.ts b/src/directives/colony/clearRoom.ts index 82bbec80f..b0275ca05 100644 --- a/src/directives/colony/clearRoom.ts +++ b/src/directives/colony/clearRoom.ts @@ -4,7 +4,8 @@ import {ClaimingOverlord} from '../../overlords/colonization/claimer'; import {MY_USERNAME} from '../../~settings'; import {log} from '../../console/log'; import {Cartographer, ROOMTYPE_CONTROLLER} from '../../utilities/Cartographer'; -import {printRoomName} from '../../utilities/utils'; +import {hasContents, printRoomName} from '../../utilities/utils'; +import {DirectiveHaul} from "../resource/haul"; /** @@ -52,7 +53,9 @@ export class DirectiveClearRoom extends Directive { for (let 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) && hasContents(s.store)) { + // Create a collection flag + let result = s.pos.createFlag(undefined, DirectiveHaul.color, DirectiveHaul.secondaryColor); continue; } if (keepRoads && s.structureType == STRUCTURE_ROAD) { diff --git a/src/utilities/utils.ts b/src/utilities/utils.ts index 33b465b82..47341cd81 100644 --- a/src/utilities/utils.ts +++ b/src/utilities/utils.ts @@ -34,6 +34,15 @@ export function hasMinerals(store: { [resourceType: string]: number }): boolean return false; } +export function hasContents(store: { [resourceType: string]: number }): boolean { + for (let resourceType in store) { + if ((store[resourceType] || 0) > 0) { + return true; + } + } + return false; +} + /** * Obtain the username of the player */ From d7a86028f193dde97ebe79c307f93eb6ff6654c6 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Wed, 10 Apr 2019 14:39:56 -0700 Subject: [PATCH 2/9] Adding listSuspended command and adding more to clearRoom --- src/console/Console.ts | 12 ++++++++++++ src/declarations/memory.d.ts | 8 ++++++++ src/directives/colony/clearRoom.ts | 23 +++++++++++++++++++++++ src/memory/Memory.ts | 1 + 4 files changed, 44 insertions(+) diff --git a/src/console/Console.ts b/src/console/Console.ts index 7b5446dce..14a13c2b1 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; @@ -244,6 +245,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 270b52c4f..b0c2589fa 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,6 +28,7 @@ interface Memory { operationMode: operationMode; log: LoggerMemory; enableVisuals: boolean; + resourceCollectionMode: resourceCollectionMode; } profiler?: any; stats: any; diff --git a/src/directives/colony/clearRoom.ts b/src/directives/colony/clearRoom.ts index b0275ca05..076be1b85 100644 --- a/src/directives/colony/clearRoom.ts +++ b/src/directives/colony/clearRoom.ts @@ -6,6 +6,10 @@ import {log} from '../../console/log'; import {Cartographer, ROOMTYPE_CONTROLLER} from '../../utilities/Cartographer'; import {hasContents, printRoomName} from '../../utilities/utils'; import {DirectiveHaul} from "../resource/haul"; +import {WorkerOverlord} from "../../overlords/core/worker"; +import {Zerg} from "../../zerg/Zerg"; +import {Pathing} from "../../movement/Pathing"; +import {DirectiveDismantle} from "../targeting/dismantle"; /** @@ -30,6 +34,9 @@ export class DirectiveClearRoom extends Directive { `removing directive!`); this.remove(true); } + if (Memory.settings.resourceCollectionMode && Memory.settings.resourceCollectionMode >= 1) { + this.memory.keepStorageStructures = true; + } } spawnMoarOverlords() { @@ -86,6 +93,22 @@ export class DirectiveClearRoom extends Directive { log.notify(`Removing clearRoom directive in ${this.pos.roomName}: operation completed.`); this.remove(); } + // Clear path if controller is not reachable + } else if (this.room && this.room.creeps.length > 1) { + let currentlyDismantling = _.find(this.room.flags, function(flag) { + return (flag.color == DirectiveDismantle.color && flag.secondaryColor == DirectiveDismantle.secondaryColor) + }); + + if (!currentlyDismantling) { + 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 && blockingLocation.lookFor(LOOK_FLAGS).length <= 0) { + log.notify(`Adding dismantle directive for ${this.pos.roomName} to reach controller.`); + blockingLocation!.createFlag(undefined, DirectiveDismantle.color, DirectiveDismantle.secondaryColor); + } + } } // Remove if owned by other player diff --git a/src/memory/Memory.ts b/src/memory/Memory.ts index 67c9f751b..441806e6d 100644 --- a/src/memory/Memory.ts +++ b/src/memory/Memory.ts @@ -197,6 +197,7 @@ export class Mem { operationMode: DEFAULT_OPERATION_MODE, log : {}, enableVisuals: true, + resourceCollectionMode: 0, }); if (!Memory.stats) { Memory.stats = {}; From f49a075fd0d99acaad1e0f2bf1d5af480e1b7b27 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Wed, 8 May 2019 15:20:59 -0700 Subject: [PATCH 3/9] PR comments --- src/console/Console.ts | 1 + src/directives/colony/clearRoom.ts | 14 ++++++-------- src/utilities/utils.ts | 9 --------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/src/console/Console.ts b/src/console/Console.ts index 14a13c2b1..b32fb88cc 100644 --- a/src/console/Console.ts +++ b/src/console/Console.ts @@ -69,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'; diff --git a/src/directives/colony/clearRoom.ts b/src/directives/colony/clearRoom.ts index 076be1b85..2e7de2e52 100644 --- a/src/directives/colony/clearRoom.ts +++ b/src/directives/colony/clearRoom.ts @@ -60,9 +60,9 @@ export class DirectiveClearRoom extends Directive { for (let s of allStructures) { if (s.structureType == STRUCTURE_CONTROLLER) continue; if (keepStorageStructures && - (s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL) && hasContents(s.store)) { + (s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL) && ~s.isEmpty) { // Create a collection flag - let result = s.pos.createFlag(undefined, DirectiveHaul.color, DirectiveHaul.secondaryColor); + DirectiveHaul.create(s.pos); continue; } if (keepRoads && s.structureType == STRUCTURE_ROAD) { @@ -95,18 +95,16 @@ export class DirectiveClearRoom extends Directive { } // Clear path if controller is not reachable } else if (this.room && this.room.creeps.length > 1) { - let currentlyDismantling = _.find(this.room.flags, function(flag) { - return (flag.color == DirectiveDismantle.color && flag.secondaryColor == DirectiveDismantle.secondaryColor) - }); + let currentlyDismantlingLocations = DirectiveDismantle.find(this.room.flags); - if (!currentlyDismantling) { + 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 && blockingLocation.lookFor(LOOK_FLAGS).length <= 0) { + if (blockingLocation && !Directive.isPresent(blockingLocation, 'pos')) { log.notify(`Adding dismantle directive for ${this.pos.roomName} to reach controller.`); - blockingLocation!.createFlag(undefined, DirectiveDismantle.color, DirectiveDismantle.secondaryColor); + DirectiveDismantle.create(blockingLocation); } } } diff --git a/src/utilities/utils.ts b/src/utilities/utils.ts index 47341cd81..33b465b82 100644 --- a/src/utilities/utils.ts +++ b/src/utilities/utils.ts @@ -34,15 +34,6 @@ export function hasMinerals(store: { [resourceType: string]: number }): boolean return false; } -export function hasContents(store: { [resourceType: string]: number }): boolean { - for (let resourceType in store) { - if ((store[resourceType] || 0) > 0) { - return true; - } - } - return false; -} - /** * Obtain the username of the player */ From f3a5ac8a8f8f982b55f6c7448792b18ae2cfb198 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Tue, 21 May 2019 11:34:23 -0700 Subject: [PATCH 4/9] Removing bad imports --- src/directives/colony/clearRoom.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/directives/colony/clearRoom.ts b/src/directives/colony/clearRoom.ts index 2e7de2e52..318dad32a 100644 --- a/src/directives/colony/clearRoom.ts +++ b/src/directives/colony/clearRoom.ts @@ -4,10 +4,8 @@ import {ClaimingOverlord} from '../../overlords/colonization/claimer'; import {MY_USERNAME} from '../../~settings'; import {log} from '../../console/log'; import {Cartographer, ROOMTYPE_CONTROLLER} from '../../utilities/Cartographer'; -import {hasContents, printRoomName} from '../../utilities/utils'; +import {printRoomName} from '../../utilities/utils'; import {DirectiveHaul} from "../resource/haul"; -import {WorkerOverlord} from "../../overlords/core/worker"; -import {Zerg} from "../../zerg/Zerg"; import {Pathing} from "../../movement/Pathing"; import {DirectiveDismantle} from "../targeting/dismantle"; From 97f44dca9b332a6eb8d87f76ca36386093883236 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Sun, 26 May 2019 20:06:28 -0700 Subject: [PATCH 5/9] Adding nuker to hauling --- src/directives/colony/clearRoom.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/directives/colony/clearRoom.ts b/src/directives/colony/clearRoom.ts index 9fea647d1..f237db05b 100644 --- a/src/directives/colony/clearRoom.ts +++ b/src/directives/colony/clearRoom.ts @@ -63,6 +63,9 @@ export class DirectiveClearRoom extends Directive { DirectiveHaul.create(s.pos); continue; } + if (s.structureType == STRUCTURE_NUKER && s.energy > 50000) { + DirectiveHaul.create(s.pos); + } if (keepRoads && s.structureType == STRUCTURE_ROAD) { continue; } From c1d87981ac5ae7b775ee6d2d12a8773e973b97a7 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Sun, 26 May 2019 20:08:37 -0700 Subject: [PATCH 6/9] Fixing ! --- src/directives/colony/clearRoom.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/directives/colony/clearRoom.ts b/src/directives/colony/clearRoom.ts index f237db05b..0d6ec1848 100644 --- a/src/directives/colony/clearRoom.ts +++ b/src/directives/colony/clearRoom.ts @@ -58,7 +58,7 @@ 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.isEmpty) { + (s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL) && !s.isEmpty) { // Create a collection flag DirectiveHaul.create(s.pos); continue; From c3f0e33a1639b26546062f33578d5246ab0cf639 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Sun, 26 May 2019 20:22:47 -0700 Subject: [PATCH 7/9] Preventing removing directive if room not unclaimed and createIfPresent for hauling --- src/directives/colony/clearRoom.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/directives/colony/clearRoom.ts b/src/directives/colony/clearRoom.ts index 0d6ec1848..3db78368a 100644 --- a/src/directives/colony/clearRoom.ts +++ b/src/directives/colony/clearRoom.ts @@ -29,7 +29,7 @@ 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) { @@ -48,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; @@ -60,11 +60,11 @@ export class DirectiveClearRoom extends Directive { if (keepStorageStructures && (s.structureType == STRUCTURE_STORAGE || s.structureType == STRUCTURE_TERMINAL) && !s.isEmpty) { // Create a collection flag - DirectiveHaul.create(s.pos); + DirectiveHaul.createIfNotPresent(s.pos, 'pos'); continue; } if (s.structureType == STRUCTURE_NUKER && s.energy > 50000) { - DirectiveHaul.create(s.pos); + DirectiveHaul.createIfNotPresent(s.pos, 'pos'); } if (keepRoads && s.structureType == STRUCTURE_ROAD) { continue; @@ -90,11 +90,13 @@ 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(); 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 + // Clear path if controller is not reachable } else if (this.room && this.room.creeps.length > 1) { let currentlyDismantlingLocations = DirectiveDismantle.find(this.room.flags); From 14ac9bcdf2a6b536cb915d85cd3780f08ab4dc01 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Mon, 17 Jun 2019 18:10:21 -0700 Subject: [PATCH 8/9] Deletes all room flags before cleanup --- src/directives/colony/clearRoom.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/directives/colony/clearRoom.ts b/src/directives/colony/clearRoom.ts index 3db78368a..6758b0937 100644 --- a/src/directives/colony/clearRoom.ts +++ b/src/directives/colony/clearRoom.ts @@ -91,6 +91,12 @@ export class DirectiveClearRoom extends Directive { const done = this.removeAllStructures(); if (done) { 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.`); if (res == OK) { this.remove(); From a9b5e17bdf0c0c634251369d93ce22b0b12ffb06 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Mon, 24 Jun 2019 16:08:22 -0700 Subject: [PATCH 9/9] Collect non-energy first --- src/overlords/situational/hauler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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;