From b3282a959ac9b9dd0b3b55cf17dc7da71d46a426 Mon Sep 17 00:00:00 2001 From: Sveinung Kvilhaugsvik Date: Tue, 23 Mar 2021 03:06:53 +0100 Subject: [PATCH] Simplify away unit_move_igzoc(). The functinon unit_move_igzoc() is only used to move barbarians out of the hut tile. The unit that entered the hut is located at that tile. Eliminate conditions that can prevent the barbariann from moving out and move the new function to barbarian.c. See osdn #41834 --- server/barbarian.c | 24 +++++++++++- server/unithand.c | 91 ---------------------------------------------- server/unithand.h | 1 - 3 files changed, 22 insertions(+), 94 deletions(-) diff --git a/server/barbarian.c b/server/barbarian.c index f527acfcab..7f0e878a1f 100644 --- a/server/barbarian.c +++ b/server/barbarian.c @@ -242,6 +242,26 @@ static int random_unchecked_direction(int possibilities, const bool *checked) return j; } +/**********************************************************************//** + Move to the tile pdesttile. +**************************************************************************/ +static void unit_move_pay(struct unit *punit, struct tile *pdesttile) +{ + int move_cost = map_move_cost_unit(&(wld.map), punit, pdesttile); + + unit_move(punit, pdesttile, move_cost, + /* Don't override "Transport Embark" */ + NULL, FALSE, + /* Don't override "Conquer City" */ + FALSE, + /* Don't override "Conquer Extras" */ + FALSE, + /* Don't override "Enter Hut" */ + FALSE, + /* Don't override "Frighten Hut" */ + FALSE); +} + /**********************************************************************//** Unleash barbarians means give barbarian player some units and move them out of the hut, unless there's no place to go. @@ -341,7 +361,7 @@ bool unleash_barbarians(struct tile *ptile) if (unit_can_move_to_tile(&(wld.map), punit2, dir_tiles[rdir], TRUE, FALSE)) { /* Move */ - (void) unit_move_igzoc(punit2, dir_tiles[rdir]); + (void) unit_move_pay(punit2, dir_tiles[rdir]); log_debug("Moved barbarian unit from (%d, %d) to (%d, %d)", TILE_XY(ptile), TILE_XY(dir_tiles[rdir])); dest_found = TRUE; @@ -421,7 +441,7 @@ bool unleash_barbarians(struct tile *ptile) if (unit_can_move_to_tile(&(wld.map), punit2, dir_tiles[rdir], TRUE, FALSE)) { /* Move */ - (void) unit_move_igzoc(punit2, dir_tiles[rdir]); + (void) unit_move_pay(punit2, dir_tiles[rdir]); dest_found = TRUE; } diff --git a/server/unithand.c b/server/unithand.c index 998a7e605e..731ec2b48e 100644 --- a/server/unithand.c +++ b/server/unithand.c @@ -5071,97 +5071,6 @@ bool unit_move_handling(struct unit *punit, struct tile *pdesttile, } } -/**********************************************************************//** - Will try to move to/attack the tile dest_x,dest_y. Returns TRUE if this - was done, FALSE if it wasn't for some reason. Even if this returns TRUE, - the unit may have died upon arrival to new tile. - - igzoc means ignore ZOC rules - not necessary for igzoc units etc, but - done in some special cases (moving barbarians out of initial hut). -**************************************************************************/ -bool unit_move_igzoc(struct unit *punit, struct tile *pdesttile) -{ - struct player *pplayer = unit_owner(punit); - - /*** Phase 1: Basic checks ***/ - - /* this occurs often during lag, and to the AI due to some quirks -- Syela */ - if (!is_tiles_adjacent(unit_tile(punit), pdesttile)) { - log_debug("tiles not adjacent in move request"); - return FALSE; - } - - if (punit->moves_left <= 0) { - notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server, - _("This unit has no moves left.")); - return FALSE; - } - - if (!unit_can_do_action_now(punit)) { - return FALSE; - } - - /*** Phase 2: OK now move the unit ***/ - - /* We cannot move a transport into a tile that holds - * units or cities not allied with all of our cargo. */ - if (get_transporter_capacity(punit) > 0) { - unit_list_iterate(unit_tile(punit)->units, pcargo) { - if (unit_contained_in(pcargo, punit) - && (is_non_allied_unit_tile(pdesttile, unit_owner(pcargo)) - || is_non_allied_city_tile(pdesttile, - unit_owner(pcargo)))) { - notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server, - _("A transported unit is not allied to all " - "units or city on target tile.")); - return FALSE; - } - } unit_list_iterate_end; - } - - { - const struct action *blocking_action; - - /* Can't move if an action that block moves is legal */ - if ((blocking_action = action_is_blocked_by( - action_by_number(ACTION_UNIT_MOVE), punit, pdesttile, - tile_city(pdesttile), NULL))) { - notify_player(pplayer, unit_tile(punit), E_BAD_COMMAND, ftc_server, - /* TRANS: Freight ... Recycle Unit ... Help Wonder ... */ - _("Your %s can't do %s when %s is legal."), - unit_name_translation(punit), - _("regular unit move"), - action_name_translation(blocking_action)); - return FALSE; - } - } - - if (can_unit_move_to_tile_with_notify(punit, pdesttile, TRUE, - NULL, FALSE) - /* Don't override "Transport Embark" */ - && can_unit_exist_at_tile(&(wld.map), punit, pdesttile) - /* Don't override "Transport Disembark" or "Transport Disembark 2" */ - && !unit_transported(punit)) { - int move_cost = map_move_cost_unit(&(wld.map), punit, pdesttile); - - unit_move(punit, pdesttile, move_cost, - /* Don't override "Transport Embark" */ - NULL, FALSE, - /* Don't override "Conquer City" */ - FALSE, - /* Don't override "Conquer Extras" */ - FALSE, - /* Don't override "Enter Hut" */ - FALSE, - /* Don't override "Frighten Hut" */ - FALSE); - - return TRUE; - } else { - return FALSE; - } -} - /**********************************************************************//** Help build the current production in a city. diff --git a/server/unithand.h b/server/unithand.h index 12bd3d12c3..7bbe300736 100644 --- a/server/unithand.h +++ b/server/unithand.h @@ -29,7 +29,6 @@ void unit_change_homecity_handling(struct unit *punit, struct city *new_pcity, bool unit_move_handling(struct unit *punit, struct tile *pdesttile, bool move_diplomat_city); -bool unit_move_igzoc(struct unit *punit, struct tile *pdesttile); void unit_do_action(struct player *pplayer, const int actor_id, -- 2.20.1