Skip to content

Commit

Permalink
Bounce units to tiles where it can just exist if it cant "survive" in…
Browse files Browse the repository at this point in the history
… any of the available tiles.

Fixes #931
  • Loading branch information
psampathkumar authored and lmoureaux committed Apr 11, 2022
1 parent f31e358 commit 4d392db
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions server/unittools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,28 @@ void bounce_unit(struct unit *punit, bool verbose)
}
square_iterate_end;

if (count == 0) {
/* If no place unit can survive try the same with tiles the unit can just
* exist inspite of losing health or fuel*/
square_iterate(&(wld.map), punit_tile, DIST, ptile)
{
if (count >= ARRAY_SIZE(tiles)) {
break;
}

if (ptile == punit_tile) {
continue;
}

if (can_unit_exist_at_tile(&(wld.map), punit, ptile)
&& !is_non_allied_city_tile(ptile, pplayer)
&& !is_non_allied_unit_tile(ptile, pplayer)) {
tiles[count++] = ptile;
}
}
square_iterate_end;
}

if (count > 0) {
struct tile *ptile = tiles[fc_rand(count)];

Expand Down

0 comments on commit 4d392db

Please sign in to comment.