(PR#10567) pubserver crash: ai-controlled unit has no goto destination

"Jason Short" <[email protected]> Mon, 15 Nov 2004 10:00:17 -0800
Newsgroups gmane.games.freeciv.ai
Message-ID <[email protected]>
<URL: http://rt.freeciv.org/Ticket/Display.html?id=10567 >

Now I can reproduce this bug!

Load the attached savegame.  The player is on ai-mode but you should
connect with a client.  Hit "turn done" and all the diplomats will be
given an ai role.  Then put one of the diplomats that is en route onto a
short goto.  Hit turn done again.  When the goto completes the goto_tile
will be cleared, leaving a unit that still has an AI role requiring a
goto tile but no longer has a goto tile.

In the long term we should things so that only the AI uses goto_tile. 
However this may be a bit tricky.  I think orders don't have to use
goto_tile anymore (this was needed when they were first written, but
since fixed).  However client-side air goto does need goto_tile.  Even
if orders are fixed it's possible that there will still be a crash if
client-side "server goto" is used.  As long as this value is used for
multiple things it will always be bug-prone.

In the short term I think we just need to get rid of the role when the
unit is given orders.  This patch should do this (AI people should make
sure this is the right way to do it).

jason
ai_role.diff (text/x-patch, 547 B)
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.310
diff -u -r1.310 unithand.c
--- server/unithand.c	10 Nov 2004 17:02:00 -0000	1.310
+++ server/unithand.c	15 Nov 2004 17:59:30 -0000
@@ -1628,6 +1628,10 @@
     return;
   }
 
+  if (punit->ai.ai_role != AIUNIT_NONE) {
+    ai_unit_new_role(punit, AIUNIT_NONE, NULL);
+  }
+
   punit->has_orders = TRUE;
   punit->orders.length = packet->length;
   punit->orders.index = 0;