From ccc89d32e1d081a2ab325125ff10159d40edf205 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Tue, 14 May 2019 01:02:38 -0700 Subject: [PATCH 1/5] Adding a harass directive to annoy remote mines --- src/directives/initializer.ts | 3 + src/directives/offense/harass.ts | 83 ++++++++++++++++++++++++++ src/overlords/offense/harass.ts | 66 ++++++++++++++++++++ src/priorities/priorities_overlords.ts | 3 +- 4 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 src/directives/offense/harass.ts create mode 100644 src/overlords/offense/harass.ts diff --git a/src/directives/initializer.ts b/src/directives/initializer.ts index 081a081bd..8565d94bd 100644 --- a/src/directives/initializer.ts +++ b/src/directives/initializer.ts @@ -25,6 +25,7 @@ import {DirectiveTargetSiege} from './targeting/siegeTarget'; import {DirectiveTerminalEmergencyState} from './terminalState/terminalState_emergency'; import {DirectiveTerminalEvacuateState} from './terminalState/terminalState_evacuate'; import {DirectiveTerminalRebuildState} from './terminalState/terminalState_rebuild'; +import {DirectiveHarass} from "./offense/harass"; /** * This is the initializer for directives, which maps flags by their color code to the corresponding directive @@ -58,6 +59,8 @@ export function DirectiveWrapper(flag: Flag): Directive | undefined { return new DirectivePairDestroy(flag); case COLOR_PURPLE: return new DirectiveControllerAttack(flag); + case COLOR_WHITE: + return new DirectiveHarass(flag); } break; diff --git a/src/directives/offense/harass.ts b/src/directives/offense/harass.ts new file mode 100644 index 000000000..44366079e --- /dev/null +++ b/src/directives/offense/harass.ts @@ -0,0 +1,83 @@ +import {RoomIntel} from '../../intel/RoomIntel'; +import {profile} from '../../profiler/decorator'; +import {Directive} from '../Directive'; +import {HarassOverlord} from "../../overlords/offense/harass"; +import {log, Log} from "../../console/log"; +import {MY_USERNAME} from "../../~settings"; + +interface DirectiveHarassMemory extends FlagMemory { + enhanced?: boolean; + targetPlayer?: string; + roomsToHarass: string[]; +} + +/** + * Harass Directive that wanders through enemy rooms killing stuff + * Placed on an enemy room, it will harass all of it's remotes periodically + */ +@profile +export class DirectiveHarass extends Directive { + + static directiveName = 'harass'; + static color = COLOR_RED; + static secondaryColor = COLOR_WHITE; + + memory: DirectiveHarassMemory; + + constructor(flag: Flag) { + super(flag); + this.memory.targetPlayer = RoomIntel.roomOwnedBy(flag.pos.roomName); + if (this.memory.targetPlayer == MY_USERNAME) { + log.error(`Ahhhhhh harassing self in room ${flag.pos.roomName}`); + this.remove(); + } + if (this.memory.targetPlayer) { + this.memory.roomsToHarass = this.findNearbyReservedRooms(flag.pos.roomName, this.memory.targetPlayer); + } + } + + spawnMoarOverlords() { + // For now, just spawn from RCL 5+ rooms + this.overlords.harassOverlord = new HarassOverlord(this, this.memory.enhanced); + } + + init(): void { + // if + // if (!this.memory.roomsToHarass && this.memory.targetPlayer) + + + } + + /** + * Finds the rooms to harass + * + * @param roomName + * @param playerName + */ + findNearbyReservedRooms(roomName: string, playerName: string): string[] { + if (!this.memory.targetPlayer) { + log.error(`Unable to find which player to harass in room ${roomName}`); + return []; + } + let reservedByTargetPlayer: string[] = []; + let adjacentRooms = _.values(Game.map.describeExits(roomName)) as string[]; + adjacentRooms.forEach(room => { + if (RoomIntel.roomReservedBy(room) == playerName) { + reservedByTargetPlayer.push(room); + // This will double add rooms next to owned rooms, making it more likely to harass them + (_.values(Game.map.describeExits(room)) as string[]).forEach(room => { + if (RoomIntel.roomReservedBy(room) == playerName) { + reservedByTargetPlayer.push(room); + } + }) + } + }); + Game.notify(`Looking for nearby rooms to harass, found ${reservedByTargetPlayer}`); + return reservedByTargetPlayer; + } + + run(): void { + // Probably something modifying frequency of harassment + + } +} diff --git a/src/overlords/offense/harass.ts b/src/overlords/offense/harass.ts new file mode 100644 index 000000000..a20124a2a --- /dev/null +++ b/src/overlords/offense/harass.ts @@ -0,0 +1,66 @@ +import {CreepSetup} from '../../creepSetups/CreepSetup'; +import {CombatSetups, Roles} from '../../creepSetups/setups'; +import {DirectiveInvasionDefense} from '../../directives/defense/invasionDefense'; +import {CombatIntel} from '../../intel/CombatIntel'; +import {OverlordPriority} from '../../priorities/priorities_overlords'; +import {profile} from '../../profiler/decorator'; +import {boostResources} from '../../resources/map_resources'; +import {CombatZerg} from '../../zerg/CombatZerg'; +import {CombatOverlord} from '../CombatOverlord'; +import {DirectiveHarass} from "../../directives/offense/harass"; + +/** + * Spawns ranged harassers to stop mining for an enemy room + */ +@profile +export class HarassOverlord extends CombatOverlord { + + hydralisks: CombatZerg[]; + room: Room; + nextTarget: string; + directive: DirectiveHarass; + + + static settings = { + retreatHitsPercent : 0.85, + reengageHitsPercent: 0.95, + }; + + constructor(directive: DirectiveHarass, + boosted = false, + priority = OverlordPriority.offense.harass) { + super(directive, 'harass', priority, 1); + this.directive = directive; + this.hydralisks = this.combatZerg(Roles.ranged, { + boostWishlist: boosted ? [boostResources.ranged_attack[3], boostResources.heal[3], boostResources.move[3]] + : undefined + }); + } + + private handleHarass(hydralisk: CombatZerg): void { + if (this.nextTarget && this.room.name != this.nextTarget) { + hydralisk.goToRoom(this.nextTarget); + } else if (hydralisk.room.dangerousPlayerHostiles.length > 2) { + // Time to move on + this.moveToNearbyRoom(hydralisk, hydralisk.room.name); + } + hydralisk.autoCombat(this.room.name); + // Clean up infra then move on to another room + } + + moveToNearbyRoom(hydralisk: CombatZerg, currentRoom: string) { + this.nextTarget = _.sample(this.directive.memory.roomsToHarass); + hydralisk.goToRoom(this.nextTarget); + } + + init() { + this.reassignIdleCreeps(Roles.ranged); + const setup = CombatSetups.hydralisks.default; + this.wishlist(1, setup); + } + + run() { + console.log(`Matt: Running directive harass in ${this.room.print}`); + this.autoRun(this.hydralisks, hydralisk => this.handleHarass(hydralisk)); + } +} diff --git a/src/priorities/priorities_overlords.ts b/src/priorities/priorities_overlords.ts index bef3ab436..1ed197744 100644 --- a/src/priorities/priorities_overlords.ts +++ b/src/priorities/priorities_overlords.ts @@ -22,7 +22,8 @@ export let OverlordPriority = { destroy : 300, healPoint : 301, siege : 302, - controllerAttack: 399 + controllerAttack: 399, + harass : 571, }, colonization: { // Colonizing new rooms From 7d4132488258d897d4803dd820fc6c0e13c0cd05 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Tue, 14 May 2019 11:12:14 -0700 Subject: [PATCH 2/5] Fixing some movement bugs, still need to properly flee --- src/overlords/offense/harass.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/overlords/offense/harass.ts b/src/overlords/offense/harass.ts index a20124a2a..bc59ccad6 100644 --- a/src/overlords/offense/harass.ts +++ b/src/overlords/offense/harass.ts @@ -38,19 +38,30 @@ export class HarassOverlord extends CombatOverlord { } private handleHarass(hydralisk: CombatZerg): void { - if (this.nextTarget && this.room.name != this.nextTarget) { + console.log(`Matt: hydralisk harassment in ${hydralisk.print}`); + //this.moveToNearbyRoom(hydralisk, hydralisk.room.name); + if (!this.nextTarget) { + this.moveToNearbyRoom(hydralisk, hydralisk.room.name); + } + if (this.nextTarget && this.directive.pos.roomName != this.nextTarget) { hydralisk.goToRoom(this.nextTarget); } else if (hydralisk.room.dangerousPlayerHostiles.length > 2) { // Time to move on this.moveToNearbyRoom(hydralisk, hydralisk.room.name); } - hydralisk.autoCombat(this.room.name); - // Clean up infra then move on to another room + hydralisk.autoCombat(this.nextTarget || hydralisk.room.name); + // Clean up construction sites then move on to another room } moveToNearbyRoom(hydralisk: CombatZerg, currentRoom: string) { this.nextTarget = _.sample(this.directive.memory.roomsToHarass); - hydralisk.goToRoom(this.nextTarget); + if (this.nextTarget) { + console.log(`Selecting new target of ${this.nextTarget} for ${hydralisk.print}`); + hydralisk.say(`Tgt ${this.nextTarget}`); + hydralisk.goToRoom(this.nextTarget); + } else { + console.log(`Tried to select new harass target from ${currentRoom} but failed for ${this.directive.print} with list ${this.directive.memory.roomsToHarass}`); + } } init() { @@ -60,7 +71,7 @@ export class HarassOverlord extends CombatOverlord { } run() { - console.log(`Matt: Running directive harass in ${this.room.print}`); + console.log(`Matt: Running directive harass in ${this.directive.print}`); this.autoRun(this.hydralisks, hydralisk => this.handleHarass(hydralisk)); } } From e7d5dc59f8e44803608ff51addc2ec7170ff68f9 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Tue, 14 May 2019 12:54:26 -0700 Subject: [PATCH 3/5] More stuff --- src/overlords/offense/harass.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/overlords/offense/harass.ts b/src/overlords/offense/harass.ts index bc59ccad6..13a7250c2 100644 --- a/src/overlords/offense/harass.ts +++ b/src/overlords/offense/harass.ts @@ -17,7 +17,7 @@ export class HarassOverlord extends CombatOverlord { hydralisks: CombatZerg[]; room: Room; - nextTarget: string; + targetRemoteToHarass: string; directive: DirectiveHarass; @@ -39,26 +39,27 @@ export class HarassOverlord extends CombatOverlord { private handleHarass(hydralisk: CombatZerg): void { console.log(`Matt: hydralisk harassment in ${hydralisk.print}`); - //this.moveToNearbyRoom(hydralisk, hydralisk.room.name); - if (!this.nextTarget) { - this.moveToNearbyRoom(hydralisk, hydralisk.room.name); + hydralisk.autoCombat(this.targetRemoteToHarass || hydralisk.room.name); + + //this.chooseRemoteToHarass(hydralisk, hydralisk.room.name); + if (!this.targetRemoteToHarass) { + this.chooseRemoteToHarass(hydralisk, hydralisk.room.name); } - if (this.nextTarget && this.directive.pos.roomName != this.nextTarget) { - hydralisk.goToRoom(this.nextTarget); + if (this.targetRemoteToHarass && hydralisk.room.name != this.targetRemoteToHarass) { + hydralisk.goToRoom(this.targetRemoteToHarass); } else if (hydralisk.room.dangerousPlayerHostiles.length > 2) { // Time to move on - this.moveToNearbyRoom(hydralisk, hydralisk.room.name); + this.chooseRemoteToHarass(hydralisk, hydralisk.room.name); } - hydralisk.autoCombat(this.nextTarget || hydralisk.room.name); // Clean up construction sites then move on to another room } - moveToNearbyRoom(hydralisk: CombatZerg, currentRoom: string) { - this.nextTarget = _.sample(this.directive.memory.roomsToHarass); - if (this.nextTarget) { - console.log(`Selecting new target of ${this.nextTarget} for ${hydralisk.print}`); - hydralisk.say(`Tgt ${this.nextTarget}`); - hydralisk.goToRoom(this.nextTarget); + chooseRemoteToHarass(hydralisk: CombatZerg, currentRoom: string) { + this.targetRemoteToHarass = _.sample(this.directive.memory.roomsToHarass); + if (this.targetRemoteToHarass) { + console.log(`Selecting new target of ${this.targetRemoteToHarass} for ${hydralisk.print}`); + hydralisk.say(`Tgt ${this.targetRemoteToHarass}`); + hydralisk.goToRoom(this.targetRemoteToHarass); } else { console.log(`Tried to select new harass target from ${currentRoom} but failed for ${this.directive.print} with list ${this.directive.memory.roomsToHarass}`); } From 11ab43eb82f95530feee8833185fc6f8a5ed3a15 Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Wed, 15 May 2019 15:08:11 -0700 Subject: [PATCH 4/5] Improving harass logging --- src/overlords/offense/harass.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/overlords/offense/harass.ts b/src/overlords/offense/harass.ts index 13a7250c2..448f5990e 100644 --- a/src/overlords/offense/harass.ts +++ b/src/overlords/offense/harass.ts @@ -8,6 +8,7 @@ import {boostResources} from '../../resources/map_resources'; import {CombatZerg} from '../../zerg/CombatZerg'; import {CombatOverlord} from '../CombatOverlord'; import {DirectiveHarass} from "../../directives/offense/harass"; +import {log} from "../../console/log"; /** * Spawns ranged harassers to stop mining for an enemy room @@ -38,7 +39,6 @@ export class HarassOverlord extends CombatOverlord { } private handleHarass(hydralisk: CombatZerg): void { - console.log(`Matt: hydralisk harassment in ${hydralisk.print}`); hydralisk.autoCombat(this.targetRemoteToHarass || hydralisk.room.name); //this.chooseRemoteToHarass(hydralisk, hydralisk.room.name); @@ -55,13 +55,13 @@ export class HarassOverlord extends CombatOverlord { } chooseRemoteToHarass(hydralisk: CombatZerg, currentRoom: string) { - this.targetRemoteToHarass = _.sample(this.directive.memory.roomsToHarass); - if (this.targetRemoteToHarass) { - console.log(`Selecting new target of ${this.targetRemoteToHarass} for ${hydralisk.print}`); + let nextRoom = this.directive.memory.roomsToHarass.shift(); + if (nextRoom) { + this.directive.memory.roomsToHarass.push(nextRoom); + this.targetRemoteToHarass = nextRoom; + log.debug(`Selecting new target of ${this.targetRemoteToHarass} for ${hydralisk.print} from ${this.directive.memory.roomsToHarass}`); hydralisk.say(`Tgt ${this.targetRemoteToHarass}`); hydralisk.goToRoom(this.targetRemoteToHarass); - } else { - console.log(`Tried to select new harass target from ${currentRoom} but failed for ${this.directive.print} with list ${this.directive.memory.roomsToHarass}`); } } @@ -72,7 +72,6 @@ export class HarassOverlord extends CombatOverlord { } run() { - console.log(`Matt: Running directive harass in ${this.directive.print}`); this.autoRun(this.hydralisks, hydralisk => this.handleHarass(hydralisk)); } } From 9d17bbc5cef99b330af8d76930683a9aa88bc60c Mon Sep 17 00:00:00 2001 From: Matthew Roy Date: Wed, 15 May 2019 15:18:48 -0700 Subject: [PATCH 5/5] Fixing harass NPE --- src/directives/offense/harass.ts | 7 +++++++ src/overlords/offense/harass.ts | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/directives/offense/harass.ts b/src/directives/offense/harass.ts index 44366079e..4fc6732b2 100644 --- a/src/directives/offense/harass.ts +++ b/src/directives/offense/harass.ts @@ -48,6 +48,13 @@ export class DirectiveHarass extends Directive { } + findNearbyReservedRoomsForHarassment() { + if (this.memory.targetPlayer) { + return this.findNearbyReservedRooms(this.flag.pos.roomName, this.memory.targetPlayer); + } + return []; + } + /** * Finds the rooms to harass * diff --git a/src/overlords/offense/harass.ts b/src/overlords/offense/harass.ts index 448f5990e..8fb8fc87d 100644 --- a/src/overlords/offense/harass.ts +++ b/src/overlords/offense/harass.ts @@ -55,6 +55,9 @@ export class HarassOverlord extends CombatOverlord { } chooseRemoteToHarass(hydralisk: CombatZerg, currentRoom: string) { + if (!this.directive.memory.roomsToHarass || this.directive.memory.roomsToHarass.length == 0) { + this.directive.memory.roomsToHarass = this.directive.findNearbyReservedRoomsForHarassment(); + } let nextRoom = this.directive.memory.roomsToHarass.shift(); if (nextRoom) { this.directive.memory.roomsToHarass.push(nextRoom);