From 4d392db1e49abcd9fe65d5c75df52a6edadc1e79 Mon Sep 17 00:00:00 2001 From: Pranav Date: Thu, 3 Mar 2022 16:51:12 +0100 Subject: [PATCH] Bounce units to tiles where it can just exist if it cant "survive" in any of the available tiles. Fixes #931 --- server/unittools.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/server/unittools.cpp b/server/unittools.cpp index 16c501049c..deed7f6448 100644 --- a/server/unittools.cpp +++ b/server/unittools.cpp @@ -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)];