Skip to content

Commit

Permalink
Autoworkers: Fix assert failure because of recursive displacement
Browse files Browse the repository at this point in the history
Reported by alain_bkr

See osdn #47992

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
  • Loading branch information
cazfi committed May 12, 2023
1 parent dc2a4b9 commit 77a6634
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/advisors/autoworkers.c
Original file line number Diff line number Diff line change
Expand Up @@ -925,15 +925,21 @@ void auto_settler_findwork(struct player *pplayer,
struct pf_path *path = NULL;
struct city *taskcity;

/* time it will take worker to complete its given task */
/* Time it will take worker to complete its given task */
int completion_time = 0;

if (recursion > unit_list_size(pplayer->units)) {
fc_assert(recursion <= unit_list_size(pplayer->units));
/* Terminate what might be an inifite recursion of two units
* displacing each other, but leave enough space for
* finite recursion. */
if (recursion > 5
&& recursion > unit_list_size(pplayer->units) * 1.5) {
log_warn("Workers displacing each other recursing too much.");

adv_unit_new_task(punit, AUT_NONE, NULL);
set_unit_activity(punit, ACTIVITY_IDLE);
send_unit_info(NULL, punit);
return; /* avoid further recursion. */

return; /* Avoid further recursion. */
}

CHECK_UNIT(punit);
Expand Down

0 comments on commit 77a6634

Please sign in to comment.