Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/console/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion src/declarations/memory.d.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,7 +28,8 @@ interface Memory {
operationMode: operationMode;
log: LoggerMemory;
enableVisuals: boolean;
};
resourceCollectionMode: resourceCollectionMode;
}
profiler?: any;
stats: any;
constructionSites: { [id: string]: number };
Expand Down
43 changes: 38 additions & 5 deletions src/directives/colony/clearRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";


/**
Expand All @@ -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() {
Expand All @@ -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;

Expand All @@ -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;
}
Expand All @@ -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);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions src/memory/Memory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class Mem {
operationMode: DEFAULT_OPERATION_MODE,
log : {},
enableVisuals: true,
resourceCollectionMode: 0,
});
if (!Memory.stats) {
Memory.stats = {};
Expand Down
2 changes: 1 addition & 1 deletion src/overlords/situational/hauler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down