From b51aa6d604928371c82cce3e1c5d22e48a4cb06e Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Wed, 1 Nov 2023 21:50:14 +0200 Subject: [PATCH 21/21] Set activity launching action from orders to unit struct See osdn #48930 Signed-off-by: Marko Lindqvist --- common/unit.h | 3 ++- server/savegame/savegame2.c | 2 +- server/savegame/savegame3.c | 6 +++++- server/unittools.c | 17 ++++++++--------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/common/unit.h b/common/unit.h index 8631364e34..af7f425c48 100644 --- a/common/unit.h +++ b/common/unit.h @@ -97,7 +97,8 @@ struct unit_order { * 'action'. See action_target_kind and action_sub_target_kind */ int target; int sub_target; - /* Only valid for ORDER_PERFORM_ACTION */ + /* Only valid for ORDER_PERFORM_ACTION and ORDER_ACTIVITY + * TODO: Drop ORDER_ACTIVITY, always have activities as result of actions. */ int action; /* Valid for ORDER_MOVE and ORDER_ACTION_MOVE. */ enum direction8 dir; diff --git a/server/savegame/savegame2.c b/server/savegame/savegame2.c index b2a8283274..0f9c22fea4 100644 --- a/server/savegame/savegame2.c +++ b/server/savegame/savegame2.c @@ -4732,7 +4732,7 @@ static bool sg_load_player_unit(struct loaddata *loading, order->action = sg_order_to_action(order->order, punit, punit->goto_tile); if (order->action != ACTION_NONE) { - /* The order was converted by order_to_action */ + /* The order was converted by sg_order_to_action() */ order->order = ORDER_PERFORM_ACTION; } diff --git a/server/savegame/savegame3.c b/server/savegame/savegame3.c index a9289f7eb9..36f4dea321 100644 --- a/server/savegame/savegame3.c +++ b/server/savegame/savegame3.c @@ -5807,6 +5807,8 @@ static void sg_save_player_cities(struct savedata *saving, sub_targets[j] = pcity->rally_point.orders[j].sub_target; activities[j] = activity2char(pcity->rally_point.orders[j].activity); + actions[j] + = pcity->rally_point.orders[j].action; break; case ORDER_PERFORM_ACTION: actions[j] = pcity->rally_point.orders[j].action; @@ -6379,7 +6381,8 @@ static bool sg_load_player_unit(struct loaddata *loading, || (order->order == ORDER_PERFORM_ACTION && !action_id_exists(order->action)) || (order->order == ORDER_ACTIVITY - && order->activity == ACTIVITY_LAST)) { + && (order->activity == ACTIVITY_LAST + || !action_id_exists(order->action)))) { /* An invalid order. Just drop the orders for this unit. */ free(punit->orders.list); punit->orders.list = NULL; @@ -6751,6 +6754,7 @@ static void sg_save_player_units(struct savedata *saving, case ORDER_ACTIVITY: sub_tgt_vec[j] = punit->orders.list[j].sub_target; act_buf[j] = activity2char(punit->orders.list[j].activity); + action_buf[j] = punit->orders.list[j].action; break; case ORDER_PERFORM_ACTION: action_buf[j] = punit->orders.list[j].action; diff --git a/server/unittools.c b/server/unittools.c index 65fdfe0dfd..22ab809a2f 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -4369,17 +4369,17 @@ static inline bool player_is_watching(struct unit *punit, const bool fresh) } /**********************************************************************//** - Executes a unit's orders stored in punit->orders. The unit is put on idle + Executes a unit's orders stored in punit->orders. The unit is put on idle if an action fails or if "patrol" is set and an enemy unit is encountered. - The return value will be TRUE if the unit lives, FALSE otherwise. (This - function used to return a goto_result enumeration, declared in gotohand.h. - But this enumeration was never checked by the caller and just lead to - confusion. All the caller really needs to know is if the unit lived or - died; everything else is handled internally within execute_orders.) + The return value will be TRUE if the unit lives, FALSE otherwise. + (This function used to return a goto_result enumeration, declared + in gotohand.h. But this enumeration was never checked by the caller and + just lead to confusion. All the caller really needs to know is if the unit + lived or died; everything else is handled internally within execute_orders.) If the orders are repeating the loop starts over at the beginning once it - completes. To avoid infinite loops on railroad we stop for this + completes. To avoid infinite loops on railroad we stop for this turn when the unit is back where it started, even if it have moves left. A unit will attack under orders only on its final action. @@ -4510,8 +4510,7 @@ bool execute_orders(struct unit *punit, const bool fresh) if (can_unit_do_activity(nmap, punit, activity)) { punit->done_moving = TRUE; - /* FIXME: Have actions also with orders */ - set_unit_activity(punit, activity, activity_default_action(activity)); + set_unit_activity(punit, activity, order.action); send_unit_info(NULL, punit); break; -- 2.42.0