Skip to content

Commit 94e4c06

Browse files
author
zGeneral
committed
PR review #1
1 parent cfc2ae5 commit 94e4c06

7 files changed

Lines changed: 123 additions & 153 deletions

File tree

.vs/ProjectSettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"CurrentProjectSetting": null
3+
}

.vs/VSWorkspaceState.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ExpandedNodes": [
3+
""
4+
],
5+
"PreviewInSolutionExplorer": false
6+
}

.vs/slnx.sqlite

124 KB
Binary file not shown.
Lines changed: 67 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
import {Colony, ColonyMemory, getAllColonies} from '../../Colony';
1+
import {getAllColonies} from '../../Colony';
2+
import {OvermindConsole} from '../../console/Console'; // temp for testing
23
import {log} from '../../console/log';
34
import {ClaimingOverlord} from '../../overlords/colonization/claimer';
4-
import {RoomPoisonerOverlord} from '../../overlords/offense/roomPoisoner';
5-
import {StationaryScoutOverlord} from '../../overlords/scouting/stationary';
5+
import {RoomPoisonerOverlord} from '../../overlords/colonization/roomPoisoner';
66
import {profile} from '../../profiler/decorator';
77
import {Cartographer, ROOMTYPE_CONTROLLER} from '../../utilities/Cartographer';
88
import {printRoomName} from '../../utilities/utils';
99
import {MY_USERNAME} from '../../~settings';
1010
import {DirectiveOutpostDefense} from '../defense/outpostDefense';
1111
import {Directive} from '../Directive';
12-
import {DirectiveControllerAttack} from './controllerAttack';
12+
import {DirectiveControllerAttack} from '../offense/controllerAttack';
13+
1314

1415
export const RUN_TIMER = 25;
1516

@@ -18,16 +19,17 @@ export const RUN_TIMER = 25;
1819
*/
1920
@profile
2021
export class DirectivePoisonRoom extends Directive {
22+
2123
static directiveName = 'PoisonRoom';
22-
static color = COLOR_RED;
23-
static secondaryColor = COLOR_BROWN;
24+
static color = COLOR_PURPLE;
25+
static secondaryColor = COLOR_RED;
2426
static requiredRCL = 4;
25-
walkableSourcePosisions: RoomPosition[];
26-
walkableControllerPosisions: RoomPosition[];
27+
2728
overlords: {
2829
claim: ClaimingOverlord;
2930
roomPoisoner: RoomPoisonerOverlord;
3031
};
32+
3133
constructor(flag: Flag) {
3234
super(flag, colony => colony.level >= DirectivePoisonRoom.requiredRCL);
3335
// Remove if misplaced
@@ -45,35 +47,45 @@ export class DirectivePoisonRoom extends Directive {
4547
log.notify(`Removing poisonRoom directive in ${this.pos.roomName}: room already owned by another player.`);
4648
this.remove(true);
4749
}
48-
// Remove if not enough GCL
49-
if(getAllColonies().length == Game.gcl.level) {
50-
log.warning(`${this.print}: ${printRoomName(this.pos.roomName)} not enough GCL; ` +
51-
`for poison room, removing directive!`);
50+
}
51+
52+
get positionsToBlock(): RoomPosition[] {
53+
if (!this.room) {
54+
return [];
5255
}
56+
const thingsToBlock = _.compact([this.room.controller, ...this.room.sources]) as RoomObject[];
57+
return <RoomPosition[]><unknown>_(thingsToBlock).map(obj =>
58+
obj.pos).unique(pos => pos.name).filter(pos => pos.isWalkable);
59+
}
60+
61+
static canAutoPoison(room: Room): boolean {
62+
return (Memory.settings.autoPoison.enabled && getAllColonies().length == Game.gcl.level &&
63+
!!room && !!room.controller && room.controller.level == 0 && room.controller.reservation == undefined &&
64+
room.dangerousHostiles.length == 0 &&
65+
!room.isOutpost &&
66+
_.filter(Game.flags, flag =>
67+
flag.color == DirectivePoisonRoom.color &&
68+
flag.secondaryColor == DirectivePoisonRoom.secondaryColor).length < Memory.settings.autoPoison.concurrent &&
69+
(<RoomPosition[]><unknown>_(_.compact([room.controller, ...room.sources])).map(obj =>
70+
obj.pos).unique(pos => pos.name).filter(pos => pos.isWalkable)).length > 0);
5371
}
72+
5473
spawnMoarOverlords() {
5574
this.overlords.claim = new ClaimingOverlord(this);
5675
this.overlords.roomPoisoner = new RoomPoisonerOverlord(this);
5776
}
77+
5878
init() {
5979
this.alert(`Poisoning Room ${this.pos.roomName}`);
6080

61-
if(!(this.room && this.room.controller)) {
62-
return;
63-
}
64-
81+
// TODO: Muon to add suspension somewhere else after the merge
6582
// suspend room immediately once claimed to avoid default room actions
66-
if(this.room.controller.level == 1) {
67-
this.suspendColony(this.room.name);
83+
// this is temp for testing the directive
84+
if(this.room && this.room.controller && this.room.controller.level == 1) {
85+
OvermindConsole.suspendColony(this.room.name);
6886
}
6987

70-
if (Game.time % RUN_TIMER == 0 || this.room.constructionSites.length == 0) {
71-
// capture variables
72-
this.walkableSourcePosisions = _.filter(_.flatten(_.map(this.room.sources,
73-
s => s.pos.neighbors)),pos => pos.isWalkable(true));
74-
this.walkableControllerPosisions = _.filter(this.room.controller!.pos.neighbors,
75-
pos => pos.isWalkable(true));
76-
88+
if (this.room && this.room.controller && (Game.time % RUN_TIMER == 0 || this.room.constructionSites.length == 0)) {
7789
// reverse reservation if needed
7890
if(this.room.controller.reservation && this.room.controller.reservation.ticksToEnd > 500) {
7991
DirectiveControllerAttack.createIfNotPresent(this.room.controller.pos,'room');
@@ -85,70 +97,36 @@ export class DirectivePoisonRoom extends Directive {
8597
}
8698
}
8799
}
88-
private suspendColony(roomName: string): string {
89-
if (Overmind.colonies[roomName]) {
90-
const colonyMemory = Memory.colonies[roomName] as ColonyMemory | undefined;
91-
if (colonyMemory) {
92-
colonyMemory.suspend = true;
93-
Overmind.shouldBuild = true;
94-
return `Colony ${roomName} suspended.`;
95-
} else {
96-
return `No colony memory for ${roomName}!`;
97-
}
98-
} else {
99-
return `Colony ${roomName} is not a valid colony!`;
100-
}
101-
}
102100

103101
private poisonActions() {
104-
if(!(this.room && this.room.controller && this.room.controller.level == 2 &&
105-
this.walkableControllerPosisions && this.walkableControllerPosisions)) {
102+
if(!(this.room && this.room.controller && this.room.controller.level == 2 && this.positionsToBlock.length > 0)) {
106103
return;
107104
}
108105

109-
// Poison Controller First
110-
if(this.walkableControllerPosisions.length > 0) {
111-
_.first(this.walkableControllerPosisions).createConstructionSite(STRUCTURE_WALL);
112-
return;
113-
}
114-
115-
// Poison Sources Next
116-
// Trick: Csite are not walkable, wait for poisoner to carry energy before blocking Sources
117-
// Trick: Remove sources Csites if poisoner need to harvest, i.e carrying 0 energy
118-
if (this.overlords.roomPoisoner.roomPoisoners.length &&
119-
this.overlords.roomPoisoner.roomPoisoners[0].carry.energy > 0) {
120-
if(this.walkableSourcePosisions.length) {
121-
_.first(this.walkableSourcePosisions).createConstructionSite(STRUCTURE_WALL);
122-
}
123-
} else {
124-
_.forEach(this.room.constructionSites, csite => {csite.remove();} );
106+
// Poison blockPositions. One position at a time.
107+
if(this.positionsToBlock.length > 1) {
108+
_.first(this.positionsToBlock).createConstructionSite(STRUCTURE_WALL);
109+
} else { // do not block last position unless poisoner has energy
110+
if(this.overlords.roomPoisoner.roomPoisoners.length &&
111+
this.overlords.roomPoisoner.roomPoisoners[0].carry.energy > 0) {
112+
_.first(this.positionsToBlock).createConstructionSite(STRUCTURE_WALL);
113+
}
125114
}
126115

127116
}
128-
private isPoisoned(): boolean {
129-
let result = false;
130-
if (this.room && this.room.controller!.level > 1) {
131-
result = !!this.walkableSourcePosisions && !this.walkableSourcePosisions.length &&
132-
!!this.walkableControllerPosisions && !this.walkableControllerPosisions.length;
133-
return result;
134-
} else {
135-
return false;
136-
}
137-
}
138117

139118
private prePoisonActions(): void {
140119
if(!(this.room && this.room.controller && this.room.controller.my)) {
141120
return;
142121
}
143-
// kill claimer if room claimed, it can blocking csite creation
122+
// kill claimer if room claimed, it can block csite creation
144123
// it can also be used as a quick energy source from the tomb
145124
if (this.overlords.claim.claimers.length) {
146125
this.overlords.claim.claimers[0].suicide();
147126
}
148-
// remove any containers that can be next to sources
149-
if(this.room.containers.length) {
150-
_.forEach(this.room.containers, container => {container.destroy();});
151-
}
127+
// destroy all structures except for store structures
128+
this.clearRoom();
129+
152130
// remove any hostile consituction sites
153131
_.forEach(this.room.find(FIND_HOSTILE_CONSTRUCTION_SITES), csite => {csite.remove();});
154132
}
@@ -157,18 +135,29 @@ export class DirectivePoisonRoom extends Directive {
157135
if(!(this.room && this.room.controller)) {
158136
return;
159137
}
160-
// remove roads before unclaiming
161-
if(this.room.roads.length > 0) {
162-
_.forEach(this.room.roads, road => {road.destroy();} );
163-
}
164138
this.room.controller.unclaim();
165139
log.notify(`Removing poisonRoom directive in ${this.pos.roomName}: operation completed.`);
166140
this.remove();
167141
}
168142

143+
private clearRoom(): void {
144+
if (this.room) {
145+
const allStructures = this.room.find(FIND_STRUCTURES,{
146+
filter: (s: Structure) =>
147+
s.structureType != STRUCTURE_CONTROLLER &&
148+
s.structureType != STRUCTURE_STORAGE &&
149+
s.structureType != STRUCTURE_TERMINAL &&
150+
s.structureType != STRUCTURE_FACTORY &&
151+
s.structureType != STRUCTURE_LAB &&
152+
s.structureType != STRUCTURE_NUKER
153+
});
154+
_.forEach(allStructures,s => s.destroy());
155+
}
156+
}
157+
169158
run() {
170159
if (this.room && (Game.time % RUN_TIMER == 0 || this.room.constructionSites.length == 0 ) &&
171-
this.room.controller && this.room.controller.my) {
160+
this.room.controller && this.room.controller.my) {
172161

173162
// Preperations start at controller level 1
174163
if(this.room.controller.level == 1) {
@@ -177,7 +166,7 @@ export class DirectivePoisonRoom extends Directive {
177166
}
178167

179168
if(this.room.controller.level == 2) {
180-
if(this.isPoisoned()) {
169+
if(this.positionsToBlock.length == 0) {
181170
this.unclaimActions();
182171
} else {
183172
this.poisonActions();

src/directives/initializer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import {DirectiveColonize} from './colony/colonize';
55
import {DirectiveIncubate} from './colony/incubate';
66
import {DirectiveOutpost} from './colony/outpost';
77
import {DirectiveSKOutpost} from './colony/outpostSK';
8+
import {DirectivePoisonRoom} from './colony/poisonRoom';
89
import {DirectiveGuard} from './defense/guard';
910
import {DirectiveInvasionDefense} from './defense/invasionDefense';
1011
import {DirectiveOutpostDefense} from './defense/outpostDefense';
1112
import {Directive} from './Directive';
1213
import {DirectiveControllerAttack} from './offense/controllerAttack';
1314
import {DirectiveHarass} from './offense/harass';
1415
import {DirectivePairDestroy} from './offense/pairDestroy';
15-
import {DirectivePoisonRoom} from './offense/poisonRoom';
1616
import {DirectiveSwarmDestroy} from './offense/swarmDestroy';
1717
import {DirectiveBaseOperator} from './powerCreeps/baseOperator';
1818
import {DirectiveExtract} from './resource/extract';
@@ -53,6 +53,8 @@ export function DirectiveWrapper(flag: Flag): Directive | undefined {
5353
return new DirectiveColonize(flag);
5454
case COLOR_ORANGE:
5555
return new DirectiveClearRoom(flag);
56+
case COLOR_RED:
57+
return new DirectivePoisonRoom(flag);
5658
}
5759
break;
5860

@@ -67,8 +69,6 @@ export function DirectiveWrapper(flag: Flag): Directive | undefined {
6769
return new DirectiveControllerAttack(flag);
6870
case COLOR_WHITE:
6971
return new DirectiveHarass(flag);
70-
case COLOR_BROWN:
71-
return new DirectivePoisonRoom(flag);
7272
}
7373
break;
7474

src/intel/RoomIntel.ts

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import {getAllColonies} from '../Colony';
44
import {log} from '../console/log';
55
import {DirectiveOutpost} from '../directives/colony/outpost';
6-
import {DirectivePoisonRoom} from '../directives/offense/poisonRoom';
6+
import {DirectivePoisonRoom} from '../directives/colony/poisonRoom';
77
import {DirectivePowerMine} from '../directives/resource/powerMine';
88
import {DirectiveStronghold} from '../directives/situational/stronghold';
99
import {Segmenter} from '../memory/Segmenter';
@@ -458,46 +458,24 @@ export class RoomIntel {
458458
}
459459
}
460460
}
461+
461462
private static autoPoison(room: Room) {
462-
463-
if(!Memory.settings.autoPoison.enabled || !room || getAllColonies().length == Game.gcl.level) {
463+
if (!DirectivePoisonRoom.canAutoPoison(room)) {
464464
return;
465-
}
466-
467-
// poison X rooms at a time
468-
let count = 0;
469-
for (const colony of getAllColonies()) {
470-
if(Game.flags['POISON-'+colony.name]) {
471-
count++;
472-
}
473-
if (count >= Memory.settings.autoPoison.concurrent) {
474-
return;
475-
}
476-
}
477-
478-
if (!(room.controller && room.controller.level == 0 && room.controller.reservation == undefined
479-
&& !room.storage && !room.terminal // do not include rooms with storage/terminal, i might want to loot
480-
&& room.hostiles.length == 0)
481-
|| DirectiveOutpost.isPresent(room.controller.pos,'pos')) { // do not poison own outPost!
482-
return; // not a valid room to poison;
483465
}
484-
485-
const walkableControllerPositions = _.filter(room.controller.pos.neighbors, pos => pos.isWalkable(true));
486-
if (walkableControllerPositions.length == 0) {
487-
return; // already poisoned.
488-
}
489-
490-
const colonies = getAllColonies().filter(colony => colony.level > 6);
466+
const colonies = getAllColonies().filter(colony => colony.level > DirectivePoisonRoom.requiredRCL
467+
&& Game.map.getRoomLinearDistance(colony.name, room.name) <= Memory.settings.autoPoison.maxRange );
491468
for (const colony of colonies) {
492469
const route = Game.map.findRoute(colony.room, room);
493470
if (route != -2 && route.length <= Memory.settings.autoPoison.maxRange) {
494-
Game.notify(`FOUND ROOM TO POISON IN RANGE ${route.length}, POISONING ROOM ${room.name}`);
495-
DirectivePoisonRoom.createIfNotPresent(room.controller.pos, 'pos',{name: 'POISON-'+colony.room.name});
471+
Game.notify(`Found a room to poison in range ${route.length}, poisoning ${room.name}`);
472+
DirectivePoisonRoom.createIfNotPresent(room!.controller!.pos, 'pos',{name: 'poisonRoom-'+colony.room.name});
496473
Memory.settings.autoPoison.poisonedRooms.push(room.name);
497474
return;
498475
}
499476
}
500477
}
478+
501479
static run(): void {
502480
let alreadyComputedScore = false;
503481
// this.requestZoneData();

0 commit comments

Comments
 (0)