From c3eac54e2f75cdfd07996026a168c4f02e55e97d Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sun, 25 Dec 2022 19:09:31 +0200 Subject: [PATCH 37/37] Execute unit orders after actual TC activities, and AI start Anonymously requested See osdn #46363 Signed-off-by: Marko Lindqvist --- server/srv_main.c | 26 ++++++++++++++++++++------ server/unittools.c | 20 +++++++++----------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/server/srv_main.c b/server/srv_main.c index a85a976f7c..d0e8e1226e 100644 --- a/server/srv_main.c +++ b/server/srv_main.c @@ -1220,7 +1220,7 @@ static void begin_phase(bool is_new_phase) /* Must be the first thing as it is needed for lots of functions below! */ phase_players_iterate(pplayer) { - /* human players also need this for building advice */ + /* Human players also need this for building advice */ adv_data_phase_init(pplayer, is_new_phase); CALL_PLR_AI_FUNC(phase_begin, pplayer, pplayer, is_new_phase); } phase_players_iterate_end; @@ -1280,8 +1280,6 @@ static void begin_phase(bool is_new_phase) /* Removed */ continue; } - random_movements(pplayer); - execute_unit_orders(pplayer); flush_packets(); } phase_players_iterate_end; @@ -1308,7 +1306,7 @@ static void begin_phase(bool is_new_phase) send_player_cities(pplayer); } phase_players_iterate_end; - flush_packets(); /* to curb major city spam */ + flush_packets(); /* To curb major city spam */ conn_list_do_unbuffer(game.est_connections); alive_phase_players_iterate(pplayer) { @@ -1324,8 +1322,24 @@ static void begin_phase(bool is_new_phase) } } phase_players_iterate_end; + /* Spend random movement move points before any controlled actions */ + phase_players_iterate(pplayer) { + random_movements(pplayer); + } phase_players_iterate_end; + log_debug("Aistartturn"); ai_start_phase(); + + flush_packets(); + phase_players_iterate(pplayer) { + unit_list_iterate_safe(pplayer->units, punit) { + if (punit->activity == ACTIVITY_EXPLORE) { + do_explore(punit); + } + } unit_list_iterate_safe_end; + execute_unit_orders(pplayer); + flush_packets(); + } phase_players_iterate_end; } else { phase_players_iterate(pplayer) { if (is_ai(pplayer)) { @@ -1354,14 +1368,14 @@ static void begin_phase(bool is_new_phase) } /**********************************************************************//** - End a phase of movement. This handles all end-of-phase actions + End a phase of movement. This handles all end-of-phase actions for one or more players. **************************************************************************/ static void end_phase(void) { log_debug("Endphase"); - /* + /* * This empties the client Messages window; put this before * everything else below, since otherwise any messages from the * following parts get wiped out before the user gets a chance to diff --git a/server/unittools.c b/server/unittools.c index dab4a68553..36d359b5cf 100644 --- a/server/unittools.c +++ b/server/unittools.c @@ -868,9 +868,7 @@ void unit_activities_cancel_all_illegal_area(const struct tile *ptile) } /**********************************************************************//** - Progress settlers in their current tasks, - and units that is pillaging. - also move units that is on a goto. + Progress settlers in their current tasks, and units that is pillaging. Restore unit move points (information needed for settler tasks) **************************************************************************/ static void update_unit_activity(struct unit *punit) @@ -880,7 +878,7 @@ static void update_unit_activity(struct unit *punit) enum unit_activity activity = punit->activity; struct tile *ptile = unit_tile(punit); const struct unit_type *act_utype = unit_type_get(punit); - + switch (activity) { case ACTIVITY_IDLE: case ACTIVITY_EXPLORE: @@ -888,7 +886,7 @@ static void update_unit_activity(struct unit *punit) case ACTIVITY_SENTRY: case ACTIVITY_GOTO: case ACTIVITY_LAST: - /* We don't need the activity_count for the above */ + /* We don't need the activity_count for the above */ break; case ACTIVITY_FORTIFYING: @@ -919,6 +917,10 @@ static void update_unit_activity(struct unit *punit) unit_restore_movepoints(pplayer, punit); switch (activity) { + case ACTIVITY_EXPLORE: + /* Not accumulating activity - will be handled more like movement + * after the TC */ + fc__fallthrough; case ACTIVITY_IDLE: case ACTIVITY_FORTIFIED: case ACTIVITY_SENTRY: @@ -929,12 +931,8 @@ static void update_unit_activity(struct unit *punit) /* No default, ensure all handled */ break; - case ACTIVITY_EXPLORE: - do_explore(punit); - return; - case ACTIVITY_PILLAGE: - if (total_activity_done(ptile, ACTIVITY_PILLAGE, + if (total_activity_done(ptile, ACTIVITY_PILLAGE, punit->activity_target)) { destroy_extra(ptile, punit->activity_target); unit_activity_done = TRUE; @@ -2578,7 +2576,7 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet) } /**********************************************************************//** - Package a unit_info packet. This packet contains basically all + Package a unit_info packet. This packet contains basically all information about a unit. **************************************************************************/ void package_unit(struct unit *punit, struct packet_unit_info *packet) -- 2.35.1