<URL: http://bugs.freeciv.org/Ticket/Display.html?id=39792 >

OK, I've merged the tickets, they are failing in the same place.

An assert is supposed to be added by developers to detect impossible 
conditions.  In this case, it looks like a piece of debugging 
accidentally left in -- it wasn't in the original 2003 patch (PR#2631).

In unithand.c handle_unit_change_activity():

    /* Exploring is handled here explicitly, since the player expects to
     * see an immediate response from setting a unit to auto-explore.
     * Handling it deeper in the code leads to some tricky recursive loops -
     * see PR#2631. */
    if (punit->moves_left > 0 && activity == ACTIVITY_EXPLORE) {
      int id = punit->id;
      bool more_to_explore = ai_manage_explorer(punit);

      if ((punit = game_find_unit_by_number(id))) {
        assert(punit->activity == ACTIVITY_EXPLORE);
        if (!more_to_explore) {
          set_unit_activity(punit, ACTIVITY_IDLE);
          punit->ai.control = FALSE;
        send_unit_info(NULL, punit);


Similar code also exists in unittools.c update_unit_activity(), but 
*properly* tests the condition without assert() -- note the comment 
that it shouldn't change, so this is a known problem:

  if (activity == ACTIVITY_EXPLORE) {
    bool more_to_explore = ai_manage_explorer(punit);

    if (!player_find_unit_by_id(pplayer, id)) {
      /* Died */

    /* ai_manage_explorer isn't supposed to change the activity but we
     * don't count on this. */
    if (punit->activity != ACTIVITY_EXPLORE || !more_to_explore) {
      handle_unit_activity_request(punit, ACTIVITY_IDLE);

      /* FIXME: When the ai_manage_explorer call changes the activity from
       * EXPLORE to IDLE, then for some reason the ai.control value gets
       * set.  We reset it here.  See PR#12931. */
      punit->ai.control = FALSE;
    send_unit_info(NULL, punit);


Both have a slightly bizarre side check for the unit's surprise death.  
This could be better handled by redefining the return for 
ai_manage_explorer(), which "knows" whether the unit dies....

Freeciv-dev mailing list

Reply via email to