@@ -74,13 +74,11 @@ static TilePosition getBuildLocation(final UnitType type, final TilePosition des
7474 desiredPosition = pTargRegion .getCenter ().toTilePosition ();
7575 }
7676 // Find the best position
77- int bestDistance ;
78- int fallbackDistance ;
79- TilePosition bestPosition ;
80- TilePosition fallbackPosition ;
77+ int bestDistance = 999999 ;
78+ int fallbackDistance = 999999 ;
79+ TilePosition bestPosition = TilePosition . None ;
80+ TilePosition fallbackPosition = TilePosition . None ;
8181
82- bestDistance = fallbackDistance = 999999 ;
83- bestPosition = fallbackPosition = TilePosition .None ;
8482 for (int passCount = 0 ; passCount < (pTargRegion != null ? 2 : 1 ); ++passCount ) {
8583 for (int y = 0 ; y < MAX_RANGE ; ++y ) {
8684 for (int x = 0 ; x < MAX_RANGE ; ++x ) {
@@ -90,7 +88,7 @@ static TilePosition getBuildLocation(final UnitType type, final TilePosition des
9088 }
9189 final TilePosition currentPosition = new TilePosition (x , y ).add (centerPosition );
9290 //Broodwar->getGroundDistance( desiredPosition, currentPosition );
93- final int currentDistance = desiredPosition .toPosition (). getApproxDistance (currentPosition . toPosition () );
91+ final int currentDistance = desiredPosition .getApproxDistance (currentPosition );
9492 if (currentDistance < bestDistance ) {
9593 if (currentDistance <= maxRange ) {
9694 bestDistance = currentDistance ;
@@ -101,21 +99,21 @@ static TilePosition getBuildLocation(final UnitType type, final TilePosition des
10199 }
102100 }
103101 }
104- // Break pass if position is found
105- if (bestPosition != TilePosition .None ) {
106- break ;
107- }
102+ }
103+ // Break pass if position is found
104+ if (!bestPosition .equals (TilePosition .None )) {
105+ break ;
106+ }
108107
109- // Break if an alternative position was found
110- if (fallbackPosition != TilePosition .None ) {
111- bestPosition = fallbackPosition ;
112- break ;
113- }
108+ // Break if an alternative position was found
109+ if (! fallbackPosition . equals ( TilePosition .None ) ) {
110+ bestPosition = fallbackPosition ;
111+ break ;
112+ }
114113
115- // If we were really targetting a region, and couldn't find a position above
116- if (pTargRegion != null ) { // Then fallback to the default build position
117- desiredPosition = centerPosition ;
118- }
114+ // If we were really targetting a region, and couldn't find a position above
115+ if (pTargRegion != null ) { // Then fallback to the default build position
116+ desiredPosition = centerPosition ;
119117 }
120118 }
121119
@@ -195,7 +193,7 @@ private static void AssignBuildableLocations(final PlacementReserve reserve, fin
195193 }
196194
197195 private static void RemoveDisconnected (final PlacementReserve reserve , final TilePosition desiredPosition , final Game game ) {
198- final TilePosition start = desiredPosition .subtract (new TilePosition (MAX_RANGE , MAX_RANGE )) .divide (2 );
196+ final TilePosition start = desiredPosition .subtract (new TilePosition (MAX_RANGE , MAX_RANGE ).divide (2 ) );
199197
200198 // Assign 0 to all locations that aren't connected
201199 reserve .iterate ((pr , x , y ) -> {
@@ -206,7 +204,7 @@ private static void RemoveDisconnected(final PlacementReserve reserve, final Til
206204 }
207205
208206 private static void ReserveGroundHeight (final PlacementReserve reserve , final TilePosition desiredPosition , final Game game ) {
209- final TilePosition start = desiredPosition .subtract (new TilePosition (MAX_RANGE , MAX_RANGE )) .divide (2 );
207+ final TilePosition start = desiredPosition .subtract (new TilePosition (MAX_RANGE , MAX_RANGE ).divide (2 ) );
210208
211209 // Exclude locations with a different ground height, but restore a backup in case there are no more build locations
212210 reserve .backup ();
@@ -447,11 +445,15 @@ boolean hasValidSpace() {
447445 }
448446
449447 void backup () {
450- System .arraycopy (data , 0 , save , 0 , data .length );
448+ for (int i = 0 ; i < MAX_RANGE ; i ++) {
449+ System .arraycopy (data [i ], 0 , save [i ], 0 , MAX_RANGE );
450+ }
451451 }
452452
453453 void restore () {
454- System .arraycopy (save , 0 , data , 0 , save .length );
454+ for (int i = 0 ; i < MAX_RANGE ; i ++) {
455+ System .arraycopy (save [i ], 0 , data [i ], 0 , MAX_RANGE );
456+ }
455457 }
456458
457459 void restoreIfInvalid () {
0 commit comments