Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2004:
[Freeciv-Dev] (PR#7230) patrolling tririemes may sink
Home

[Freeciv-Dev] (PR#7230) patrolling tririemes may sink

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jshort@xxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#7230) patrolling tririemes may sink
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 26 Jan 2004 10:03:28 -0800
Reply-to: rt@xxxxxxxxxxx

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

> [i-freeciv-lists@xxxxxxxxxxxxx - Mon Jan 26 09:34:55 2004]:
> 
> On Sun, Jan 25, 2004 at 11:29:48PM -0800, Jason Short wrote:
> >
> > <URL: http://rt.freeciv.org/Ticket/Display.html?id=7230 >
> >
> > > [i-freeciv-lists@xxxxxxxxxxxxx - Mon Jan 12 15:35:43 2004]:
> >
> > > > The simplest solution would be to guarantee that the unit always
> had the
> > > > same number of MP at start and end of the route.  This is
> accomplished
> > > >   if the unit starts with less-than-full MP
> > > >     wait at the beginning of the route
> > > >   else if the unit ends with less-than-full MP
> > > >     wait at the end of the route
> > > > this is guaranteed correct but isn't optimal.
> > >
> > > I think this solution is acceptable. Especially since the purpose
> of
> > > patrol if not to go from A to B in the fastest way but to survey
> the
> > > area.
> >
> > Perhaps this solution isn't as simple as it seems.  Since it's
> > distinctly less than optimal, it should only be used for units that
> have
> > danger positions.  But how are we to know which units those are?
> 
> This is easy: iff is_pos_dangerous (from struct pf_parameter) != NULL.

OK, here's a patch.

I really don't like this implementation.  I'd much rather do it right.

jason

Index: client/goto.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v
retrieving revision 1.66
diff -u -r1.66 goto.c
--- client/goto.c       2004/01/20 21:52:06     1.66
+++ client/goto.c       2004/01/26 18:02:26
@@ -405,6 +405,11 @@
 
   fill_client_goto_parameter(punit, &goto_map.template);
 
+  if (hover_state == HOVER_PATROL) {
+    /* HACK */
+    goto_map.template.moves_left_initially = unit_type(punit)->move_rate;
+  }
+
   add_part();
   is_active = TRUE;
 }
@@ -486,10 +491,12 @@
   Send a path as a goto or patrol route to the server.
 **************************************************************************/
 static void send_path_orders(struct unit *punit, struct pf_path *path,
+                            enum unit_orders first_order,
+                            enum unit_orders last_order,
                             bool repeat, bool vigilant)
 {
   struct packet_unit_orders p;
-  int i, old_x, old_y;
+  int i, j = 0, old_x, old_y;
 
   p.unit_id = punit->id;
   p.repeat = repeat;
@@ -506,21 +513,28 @@
   freelog(PACKET_LOG_LEVEL, "  Repeat: %d.  Vigilant: %d.  Length: %d",
          p.repeat, p.vigilant, p.length);
 
+  if (first_order != ORDER_LAST) {
+    p.orders[0] = first_order;
+    p.dir[0] = -1;
+    j++;
+    p.length++;
+  }
+
   /* If the path has n positions it takes n-1 steps. */
-  for (i = 0; i < path->length - 1; i++) {
+  for (i = 0; i < path->length - 1; i++, j++) {
     int new_x = path->positions[i + 1].x;
     int new_y = path->positions[i + 1].y;
 
     if (same_pos(new_x, new_y, old_x, old_y)) {
-      p.orders[i] = ORDER_FINISH_TURN;
-      p.dir[i] = -1;
+      p.orders[j] = ORDER_FINISH_TURN;
+      p.dir[j] = -1;
       freelog(PACKET_LOG_LEVEL, "  packet[%d] = wait: %d,%d",
-             i, old_x, old_y);
+             j, old_x, old_y);
     } else {
-      p.orders[i] = ORDER_MOVE;
-      p.dir[i] = get_direction_for_step(old_x, old_y, new_x, new_y);
+      p.orders[j] = ORDER_MOVE;
+      p.dir[j] = get_direction_for_step(old_x, old_y, new_x, new_y);
       freelog(PACKET_LOG_LEVEL, "  packet[%d] = move %s: %d,%d => %d,%d",
-             i, dir_get_name(p.dir[i]), old_x, old_y, new_x, new_y);
+             j, dir_get_name(p.dir[j]), old_x, old_y, new_x, new_y);
     }
     old_x = new_x;
     old_y = new_y;
@@ -537,7 +551,7 @@
 **************************************************************************/
 void send_goto_path(struct unit *punit, struct pf_path *path)
 {
-  send_path_orders(punit, path, FALSE, FALSE);
+  send_path_orders(punit, path, ORDER_LAST, ORDER_LAST, FALSE, FALSE);
 }
 
 /**************************************************************************
@@ -550,6 +564,7 @@
   struct pf_path *path = NULL, *return_path;
   struct pf_parameter parameter = goto_map.template;
   struct pf_map *map;
+  enum unit_orders first_order = ORDER_LAST, last_order = ORDER_LAST;
 
   assert(is_active);
   assert(punit->id == goto_map.unit_id);
@@ -572,8 +587,16 @@
 
   pf_destroy_map(map);
   pf_destroy_path(return_path);
+
+  if (parameter.is_pos_dangerous) {
+    if (goto_map.parts[0].start_moves_left == punit->moves_left) {
+      last_order = ORDER_FINISH_TURN;
+    } else {
+      first_order = ORDER_FINISH_TURN;
+    }
+  }
 
-  send_path_orders(punit, path, TRUE, TRUE);
+  send_path_orders(punit, path, first_order, last_order, TRUE, TRUE);
 
   pf_destroy_path(path);
 }

[Prev in Thread] Current Thread [Next in Thread]