From 75fc1b90e8caff4c6795b4dd1afb876fe7e4fd2f Mon Sep 17 00:00:00 2001 From: Ben Bartlett Date: Fri, 1 Feb 2019 10:23:09 -0800 Subject: [PATCH] tweaks to safemode, invasionDefense triggers --- src/Overseer.ts | 10 +++++++++- src/roomPlanner/BarrierPlanner.ts | 13 ++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Overseer.ts b/src/Overseer.ts index e6e37920e..112a0e265 100644 --- a/src/Overseer.ts +++ b/src/Overseer.ts @@ -196,9 +196,17 @@ export class Overseer implements IOverseer { private handleColonyInvasions(colony: Colony) { // Defend against invasions in owned rooms if (colony.room && colony.level >= DirectiveInvasionDefense.requiredRCL) { + + // See if invasion is big enough to warrant creep defenses let effectiveInvaderCount = _.sum(_.map(colony.room.hostiles, invader => invader.boosts.length > 0 ? 2 : 1)); - if (effectiveInvaderCount >= 3 || colony.room.dangerousPlayerHostiles.length > 0) { + let needsDefending = effectiveInvaderCount >= 3 || colony.room.dangerousPlayerHostiles.length > 0; + + // Place defensive directive after hostiles have been present for a long enough time + let safetyData = colony.room.memory.safety; + let invasionIsPersistent = safetyData && safetyData.unsafeFor > 20; + + if (needsDefending && invasionIsPersistent) { DirectiveInvasionDefense.createIfNotPresent(colony.controller.pos, 'room'); } } diff --git a/src/roomPlanner/BarrierPlanner.ts b/src/roomPlanner/BarrierPlanner.ts index 41aab4722..81ff6d663 100644 --- a/src/roomPlanner/BarrierPlanner.ts +++ b/src/roomPlanner/BarrierPlanner.ts @@ -133,11 +133,22 @@ export class BarrierPlanner { private buildMissingRamparts(): void { // Max buildings that can be placed each tick let count = RoomPlanner.settings.maxSitesPerColony - this.colony.constructionSites.length; + // Build missing ramparts - let barrierPositions = []; + let barrierPositions: RoomPosition[] = []; for (let coord of _.keys(this.memory.barrierLookup)) { barrierPositions.push(derefCoords(coord, this.colony.name)); } + + // Add critical structures to barrier lookup + let criticalStructures: Structure[] = _.compact([...this.colony.towers, + ...this.colony.spawns, + this.colony.storage!, + this.colony.terminal!]); + for (let structure of criticalStructures) { + barrierPositions.push(structure.pos); + } + for (let pos of barrierPositions) { if (count > 0 && RoomPlanner.canBuild(STRUCTURE_RAMPART, pos) && this.barrierShouldBeHere(pos)) { let ret = pos.createConstructionSite(STRUCTURE_RAMPART);