From 22d298fe4027819f459cc8e7509b573030d6ecb1 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 28 Jan 2023 20:50:23 +0200 Subject: [PATCH 30/30] Separate unit moving from unit_move_data() to new unit_move_by_data() See osdn #46614 Signed-off-by: Marko Lindqvist --- server/unittools.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/server/unittools.c b/server/unittools.c index 31ae5ac776..140887573c 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -3725,14 +3725,6 @@ static struct unit_move_data *unit_move_data(struct unit *punit, { struct unit_move_data *pdata; struct player *powner = unit_owner(punit); - const v_radius_t radius_sq = - V_RADIUS(get_unit_vision_at(punit, pdesttile, V_MAIN), - get_unit_vision_at(punit, pdesttile, V_INVIS), - get_unit_vision_at(punit, pdesttile, V_SUBSURFACE)); - struct vision *new_vision; -#ifndef FREECIV_NDEBUG - bool success; -#endif if (punit->server.moving) { /* Recursive moving (probably due to a script). */ @@ -3756,10 +3748,27 @@ static struct unit_move_data *unit_move_data(struct unit *punit, BV_CLR_ALL(pdata->can_see_move); pdata->old_vision = punit->server.vision; + return pdata; +} + +/**********************************************************************//** + Move the unit using move_data. +**************************************************************************/ +static void unit_move_by_data(struct unit_move_data *pdata, + struct tile *psrctile, struct tile *pdesttile) +{ + struct vision *new_vision; + struct unit *punit = pdata->punit; + const v_radius_t radius_sq = + V_RADIUS(get_unit_vision_at(punit, pdesttile, V_MAIN), + get_unit_vision_at(punit, pdesttile, V_INVIS), + get_unit_vision_at(punit, pdesttile, V_SUBSURFACE)); + /* Remove unit from the source tile. */ fc_assert(unit_tile(punit) == psrctile); + #ifndef FREECIV_NDEBUG - success = + bool success = #endif unit_list_remove(psrctile->units, punit); fc_assert(success); @@ -3785,12 +3794,10 @@ static struct unit_move_data *unit_move_data(struct unit *punit, * move */ /* Enhance vision if unit steps into a fortress */ - new_vision = vision_new(powner, pdesttile); + new_vision = vision_new(pdata->powner, pdesttile); punit->server.vision = new_vision; vision_change_sight(new_vision, radius_sq); ASSERT_VISION(new_vision); - - return pdata; } /**********************************************************************//** @@ -3942,7 +3949,11 @@ bool unit_move(struct unit *punit, struct tile *pdesttile, int move_cost, } } players_iterate_end; } + unit_move_data_list_iterate(plist, pmove_data) { + + unit_move_by_data(pmove_data, psrctile, pdesttile); + if (adj && pmove_data == pdata) { /* If positions are adjacent, we have already handled 'punit'. See * above. */ -- 2.39.0