@@ -256,9 +256,6 @@ public void Tick(Actor self)
256
256
//Units that the ai already knows about. Any unit not on this list needs to be given a role.
257
257
List < Actor > activeUnits = new List < Actor > ( ) ;
258
258
259
- //This is purely to identify production buildings that don't have a rally point set.
260
- List < Actor > activeProductionBuildings = new List < Actor > ( ) ;
261
-
262
259
bool IsHumanPlayer ( Player p ) { return ! p . IsBot && ! p . NonCombatant ; }
263
260
264
261
bool HasHumanPlayers ( )
@@ -288,7 +285,6 @@ void AssignRolesToIdleUnits(Actor self)
288
285
activeUnits . RemoveAll ( a => a . Destroyed ) ;
289
286
unitsHangingAroundTheBase . RemoveAll ( a => a . Destroyed ) ;
290
287
attackForce . RemoveAll ( a => a . Destroyed ) ;
291
- activeProductionBuildings . RemoveAll ( a => a . Destroyed ) ;
292
288
293
289
// don't select harvesters.
294
290
var newUnits = self . World . Queries . OwnedBy [ p ]
@@ -318,34 +314,41 @@ void AssignRolesToIdleUnits(Actor self)
318
314
319
315
unitsHangingAroundTheBase . Clear ( ) ;
320
316
}
317
+ }
318
+
319
+ bool IsRallyPointValid ( int2 x )
320
+ {
321
+ return world . IsCellBuildable ( x , false ) ;
321
322
}
322
323
323
324
void SetRallyPointsForNewProductionBuildings ( Actor self )
324
- {
325
- var newProdBuildings = self . World . Queries . OwnedBy [ p ]
326
- . Where ( a => ( a . TraitOrDefault < RallyPoint > ( ) != null
327
- && ! activeProductionBuildings . Contains ( a )
328
- ) ) . ToArray ( ) ;
325
+ {
326
+ var buildings = self . World . Queries . OwnedBy [ p ] . WithTrait < RallyPoint > ( )
327
+ . Where ( rp => ! IsRallyPointValid ( rp . Trait . rallyPoint ) ) . ToArray ( ) ;
328
+
329
+ if ( buildings . Length > 0 )
330
+ BotDebug ( "Bot {0} needs to find rallypoints for {1} buildings." ,
331
+ p . PlayerName , buildings . Length ) ;
332
+
329
333
330
- foreach ( var a in newProdBuildings )
334
+ foreach ( var a in buildings )
331
335
{
332
- activeProductionBuildings . Add ( a ) ;
333
- int2 newRallyPoint = ChooseRallyLocationNear ( a . Location ) ;
334
- newRallyPoint . X += 4 ;
335
- newRallyPoint . Y += 4 ;
336
- world . IssueOrder ( new Order ( "SetRallyPoint" , a , false ) { TargetLocation = newRallyPoint } ) ;
336
+ int2 newRallyPoint = ChooseRallyLocationNear ( a . Actor . Location ) ;
337
+ world . IssueOrder ( new Order ( "SetRallyPoint" , a . Actor , false ) { TargetLocation = newRallyPoint } ) ;
337
338
}
338
339
}
339
340
340
341
//won't work for shipyards...
341
342
int2 ChooseRallyLocationNear ( int2 startPos )
342
- {
343
- Random r = new Random ( ) ;
344
- foreach ( var t in world . FindTilesInCircle ( startPos , 8 ) )
345
- if ( world . IsCellBuildable ( t , false ) && t != startPos && r . Next ( 64 ) == 0 )
346
- return t ;
347
-
348
- return startPos ; // i don't know where to put it.
343
+ {
344
+ var possibleRallyPoints = world . FindTilesInCircle ( startPos , 8 ) . Where ( x => world . IsCellBuildable ( x , false ) ) . ToArray ( ) ;
345
+ if ( possibleRallyPoints . Length == 0 )
346
+ {
347
+ Game . Debug ( "Bot Bug: No possible rallypoint near {0}" , startPos ) ;
348
+ return startPos ;
349
+ }
350
+
351
+ return possibleRallyPoints . Random ( random ) ;
349
352
}
350
353
351
354
int2 ? ChooseDestinationNear ( Actor a , int2 desiredMoveTarget )
0 commit comments