1- import { Colony , ColonyMemory , getAllColonies } from '../../Colony' ;
1+ import { getAllColonies } from '../../Colony' ;
2+ import { OvermindConsole } from '../../console/Console' ; // temp for testing
23import { log } from '../../console/log' ;
34import { 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' ;
66import { profile } from '../../profiler/decorator' ;
77import { Cartographer , ROOMTYPE_CONTROLLER } from '../../utilities/Cartographer' ;
88import { printRoomName } from '../../utilities/utils' ;
99import { MY_USERNAME } from '../../~settings' ;
1010import { DirectiveOutpostDefense } from '../defense/outpostDefense' ;
1111import { Directive } from '../Directive' ;
12- import { DirectiveControllerAttack } from './controllerAttack' ;
12+ import { DirectiveControllerAttack } from '../offense/controllerAttack' ;
13+
1314
1415export const RUN_TIMER = 25 ;
1516
@@ -18,16 +19,17 @@ export const RUN_TIMER = 25;
1819*/
1920@profile
2021export 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 ( ) ;
0 commit comments