Author: sveinung Date: Wed Dec 23 15:57:25 2015 New Revision: 31164 URL: http://svn.gna.org/viewcvs/freeciv?rev=31164&view=rev Log: Move unit_do_disband_trad() to the default AI.
The function unit_do_disband_trad() is only used by the default AI. Move it. See patch #6715 Modified: trunk/ai/default/aicity.c trunk/server/unittools.c trunk/server/unittools.h Modified: trunk/ai/default/aicity.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aicity.c?rev=31164&r1=31163&r2=31164&view=diff ============================================================================== --- trunk/ai/default/aicity.c (original) +++ trunk/ai/default/aicity.c Wed Dec 23 15:57:25 2015 @@ -447,6 +447,79 @@ } } } unit_list_iterate_end; +} + +/************************************************************************** + Try to disband punit in the traditional way. + + Try to disband the specified unit. Match the old behavior in what kind + of disbanding is tried and who benefits from it. +**************************************************************************/ +static void unit_do_disband_trad(struct player *owner, struct unit *punit, + const enum action_requester requester) +{ + const int punit_id_stored = punit->id; + + fc_assert_ret(owner == unit_owner(punit)); + + /* Help Wonder gives 100% of the shields used to produce the unit to the + * city where it is located. */ + if (unit_can_do_action(punit, ACTION_HELP_WONDER)) { + struct city *tgt_city; + + /* Only a city at the same tile as the unit can benefit. */ + tgt_city = tile_city(unit_tile(punit)); + + if (tgt_city + && is_action_enabled_unit_on_city(ACTION_HELP_WONDER, + punit, tgt_city)) { + if (unit_perform_action(owner, punit->id, tgt_city->id, + 0, NULL, ACTION_HELP_WONDER, requester)) { + /* No shields wasted. The unit did Help Wonder. */ + return; + } + } + } + + if (!unit_alive(punit_id_stored)) { + /* The unit is gone. Maybe it was killed in Lua? */ + return; + } + + /* Disbanding a unit inside a city gives it 50% of the shields used to + * produce the unit. */ + if (unit_can_do_action(punit, ACTION_RECYCLE_UNIT)) { + struct city *tgt_city; + + /* Only a city at the same tile as the unit can benefit. */ + tgt_city = tile_city(unit_tile(punit)); + + if (tgt_city + && is_action_enabled_unit_on_city(ACTION_RECYCLE_UNIT, + punit, tgt_city)) { + if (unit_perform_action(owner, punit->id, tgt_city->id, + 0, NULL, ACTION_RECYCLE_UNIT, requester)) { + /* The unit did Recycle Unit. 50% of the shields wasted. */ + return; + } + } + } + + if (!unit_alive(punit_id_stored)) { + /* The unit is gone. Maybe it was killed in Lua? */ + return; + } + + /* Try to disband even if all shields will be wasted. */ + if (unit_can_do_action(punit, ACTION_DISBAND_UNIT)) { + if (is_action_enabled_unit_on_self(ACTION_DISBAND_UNIT, punit)) { + if (unit_perform_action(owner, punit->id, punit->id, + 0, NULL, ACTION_DISBAND_UNIT, requester)) { + /* All shields wasted. The unit did Disband Unit. */ + return; + } + } + } } /************************************************************************** Modified: trunk/server/unittools.c URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=31164&r1=31163&r2=31164&view=diff ============================================================================== --- trunk/server/unittools.c (original) +++ trunk/server/unittools.c Wed Dec 23 15:57:25 2015 @@ -3803,79 +3803,6 @@ } /************************************************************************** - Try to disband punit in the traditional way. - - Try to disband the specified unit. Match the old behavior in what kind - of disbanding is tried and who benefits from it. -**************************************************************************/ -void unit_do_disband_trad(struct player *owner, struct unit *punit, - const enum action_requester requester) -{ - const int punit_id_stored = punit->id; - - fc_assert_ret(owner == unit_owner(punit)); - - /* Help Wonder gives 100% of the shields used to produce the unit to the - * city where it is located. */ - if (unit_can_do_action(punit, ACTION_HELP_WONDER)) { - struct city *tgt_city; - - /* Only a city at the same tile as the unit can benefit. */ - tgt_city = tile_city(unit_tile(punit)); - - if (tgt_city - && is_action_enabled_unit_on_city(ACTION_HELP_WONDER, - punit, tgt_city)) { - if (unit_perform_action(owner, punit->id, tgt_city->id, - 0, NULL, ACTION_HELP_WONDER, requester)) { - /* No shields wasted. The unit did Help Wonder. */ - return; - } - } - } - - if (!unit_alive(punit_id_stored)) { - /* The unit is gone. Maybe it was killed in Lua? */ - return; - } - - /* Disbanding a unit inside a city gives it 50% of the shields used to - * produce the unit. */ - if (unit_can_do_action(punit, ACTION_RECYCLE_UNIT)) { - struct city *tgt_city; - - /* Only a city at the same tile as the unit can benefit. */ - tgt_city = tile_city(unit_tile(punit)); - - if (tgt_city - && is_action_enabled_unit_on_city(ACTION_RECYCLE_UNIT, - punit, tgt_city)) { - if (unit_perform_action(owner, punit->id, tgt_city->id, - 0, NULL, ACTION_RECYCLE_UNIT, requester)) { - /* The unit did Recycle Unit. 50% of the shields wasted. */ - return; - } - } - } - - if (!unit_alive(punit_id_stored)) { - /* The unit is gone. Maybe it was killed in Lua? */ - return; - } - - /* Try to disband even if all shields will be wasted. */ - if (unit_can_do_action(punit, ACTION_DISBAND_UNIT)) { - if (is_action_enabled_unit_on_self(ACTION_DISBAND_UNIT, punit)) { - if (unit_perform_action(owner, punit->id, punit->id, - 0, NULL, ACTION_DISBAND_UNIT, requester)) { - /* All shields wasted. The unit did Disband Unit. */ - return; - } - } - } -} - -/************************************************************************** Maybe cancel the goto if there is an enemy in the way **************************************************************************/ static bool maybe_cancel_goto_due_to_enemy(struct unit *punit, Modified: trunk/server/unittools.h URL: http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.h?rev=31164&r1=31163&r2=31164&view=diff ============================================================================== --- trunk/server/unittools.h (original) +++ trunk/server/unittools.h Wed Dec 23 15:57:25 2015 @@ -154,8 +154,6 @@ void unit_transport_load_send(struct unit *punit, struct unit *ptrans); void unit_transport_unload_send(struct unit *punit); bool unit_move(struct unit *punit, struct tile *ptile, int move_cost); -void unit_do_disband_trad(struct player *owner, struct unit *punit, - const enum action_requester requester); bool execute_orders(struct unit *punit, const bool fresh); bool unit_can_do_action_now(const struct unit *punit); _______________________________________________ Freeciv-commits mailing list Freeciv-commits@gna.org https://mail.gna.org/listinfo/freeciv-commits