Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2004:
[Freeciv-Dev] (PR#10276) Goto bug
Home

[Freeciv-Dev] (PR#10276) Goto bug

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: mstefek@xxxxxxxxx
Subject: [Freeciv-Dev] (PR#10276) Goto bug
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 11 Oct 2004 15:11:01 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10276 >

Here is a patch.

- ORDER_FINISH_TURN is replaced with ORDER_FULL_MP.  This will cause a
wait ONLY if the unit's MP are not full.

- ORDER_MOVE is changed so that the move is "forced".  If the move is
attempted one turn and fails, it will be postponed to the next turn. 
(This doesn't count failing from ZOC or units in the way, just if the
unit runs out of MP on a rand-move attempt.)  It may be that later we'll
want to make this behavior optional.

This should solve the reported problems.  However I haven't tested it.

There is one remaining problem.  It is explained in the patch and will
be extraordinarily hard to fix.

jason

? newtiles
? common/stDTUTIV
Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.74
diff -u -r1.74 goto.c
--- client/goto.c       29 Sep 2004 02:24:19 -0000      1.74
+++ client/goto.c       11 Oct 2004 17:27:36 -0000
@@ -814,7 +814,7 @@
     struct tile *new_tile = path->positions[i + 1].tile;
 
     if (same_pos(new_tile, old_tile)) {
-      p.orders[i] = ORDER_FINISH_TURN;
+      p.orders[i] = ORDER_FULL_MP;
       p.dir[i] = -1;
       freelog(PACKET_LOG_LEVEL, "  packet[%d] = wait: %d,%d",
              i, TILE_XY(old_tile));
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.126
diff -u -r1.126 unit.h
--- common/unit.h       29 Sep 2004 02:24:23 -0000      1.126
+++ common/unit.h       11 Oct 2004 17:27:37 -0000
@@ -36,7 +36,7 @@
 
 /* Changing this enum will break savegame and network compatability. */
 enum unit_orders {
-  ORDER_MOVE, ORDER_FINISH_TURN, ORDER_ACTIVITY,
+  ORDER_MOVE, ORDER_FULL_MP, ORDER_ACTIVITY,
   ORDER_LAST
 };
 
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.198
diff -u -r1.198 savegame.c
--- server/savegame.c   11 Oct 2004 16:37:08 -0000      1.198
+++ server/savegame.c   11 Oct 2004 17:27:39 -0000
@@ -264,7 +264,7 @@
     return ORDER_MOVE;
   case 'w':
   case 'W':
-    return ORDER_FINISH_TURN;
+    return ORDER_FULL_MP;
   case 'a':
   case 'A':
     return ORDER_ACTIVITY;
@@ -282,7 +282,7 @@
   switch (order) {
   case ORDER_MOVE:
     return 'm';
-  case ORDER_FINISH_TURN:
+  case ORDER_FULL_MP:
     return 'w';
   case ORDER_ACTIVITY:
     return 'a';
@@ -2651,7 +2651,7 @@
        case ORDER_ACTIVITY:
          act_buf[j] = activity2char(punit->orders.list[j].activity);
          break;
-       case ORDER_FINISH_TURN:
+       case ORDER_FULL_MP:
        case ORDER_LAST:
          break;
        }
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.308
diff -u -r1.308 unithand.c
--- server/unithand.c   1 Oct 2004 17:53:02 -0000       1.308
+++ server/unithand.c   11 Oct 2004 17:27:39 -0000
@@ -1611,7 +1611,7 @@
        return;
       }
       break;
-    case ORDER_FINISH_TURN:
+    case ORDER_FULL_MP:
       break;
     default:
       /* An invalid order.  This is handled in execute_orders. */
Index: server/unittools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unittools.c,v
retrieving revision 1.306
diff -u -r1.306 unittools.c
--- server/unittools.c  29 Sep 2004 02:24:24 -0000      1.306
+++ server/unittools.c  11 Oct 2004 17:27:40 -0000
@@ -2938,10 +2938,15 @@
     punit->orders.index++;
 
     switch (order.order) {
-    case ORDER_FINISH_TURN:
-      punit->done_moving = TRUE;
-      freelog(LOG_DEBUG, "  waiting this turn");
-      send_unit_info(NULL, punit);
+    case ORDER_FULL_MP:
+      if (punit->moves_left != unit_move_rate(punit)) {
+       /* If the unit doesn't have full MP then it just waits until the
+        * next turn.  We assume that the next turn it will have full MP
+        * (there's no check for that). */
+       punit->done_moving = TRUE;
+       freelog(LOG_DEBUG, "  waiting this turn");
+       send_unit_info(NULL, punit);
+      }
       break;
     case ORDER_ACTIVITY:
       activity = order.activity;
@@ -3004,6 +3009,23 @@
        return TRUE;
       }
 
+      if (!res && punit->moves_left == 0) {
+       /* Movement failed (not enough MP).  Keep this move around for
+        * next turn. */
+       freelog(LOG_DEBUG, "  orders move failed (out of MP).");
+       if (unit_has_orders(punit)) {
+         /* FIXME: If this was the last move, the orders will already have
+          * been freed.  This is a problem, but very hard to fix.  The
+          * way things work now the orders have to be freed before the
+          * last move is done for things like caravan popups to work (see
+          * free_unit_orders above).  So we can't wait until here to
+          * free the orders without extensive changes elsewhere. */
+         punit->orders.index--;
+       }
+       send_unit_info(NULL, punit);
+       return TRUE;
+      }
+
       break;
     case ORDER_LAST:
       cancel_orders(punit, "  client sent invalid order!");

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#10276) Goto bug, Jason Short <=