Author: sveinung
Date: Wed Dec 30 13:29:32 2015
New Revision: 31265

URL: http://svn.gna.org/viewcvs/freeciv?rev=31265&view=rev
Log:
client goto: add send_attack_tile().

Add the new function send_attack_tile(). It orders a unit to try to reach a
specified tile. The unit will act against anything in its path (because
it uses the ORDER_ACTION_MOVE order for all moves). The tile must be
reachable the same turn. Dangers and refuel points are ignored.

Patch by mir3x <mir3x>

See patch #6741

Modified:
    branches/S2_6/client/goto.c
    branches/S2_6/client/goto.h

Modified: branches/S2_6/client/goto.c
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/goto.c?rev=31265&r1=31264&r2=31265&view=diff
==============================================================================
--- branches/S2_6/client/goto.c (original)
+++ branches/S2_6/client/goto.c Wed Dec 30 13:29:32 2015
@@ -1343,8 +1343,9 @@
   Send a path as a goto or patrol route to the server.
 **************************************************************************/
 static void send_path_orders(struct unit *punit, struct pf_path *path,
-                            bool repeat, bool vigilant,
-                            struct unit_order *final_order)
+                             bool repeat, bool vigilant,
+                             enum unit_orders orders,
+                             struct unit_order *final_order)
 {
   struct packet_unit_orders p;
   int i;
@@ -1386,7 +1387,7 @@
       p.target[i] = EXTRA_NONE;
       log_goto_packet("  packet[%d] = wait: %d,%d", i, TILE_XY(old_tile));
     } else {
-      p.orders[i] = ORDER_MOVE;
+      p.orders[i] = orders;
       p.dir[i] = get_direction_for_step(old_tile, new_tile);
       p.activity[i] = ACTIVITY_LAST;
       p.target[i] = EXTRA_NONE;
@@ -1440,7 +1441,7 @@
 void send_goto_path(struct unit *punit, struct pf_path *path,
                    struct unit_order *final_order)
 {
-  send_path_orders(punit, path, FALSE, FALSE, final_order);
+  send_path_orders(punit, path, FALSE, FALSE, ORDER_MOVE, final_order);
 }
 
 /****************************************************************************
@@ -1467,6 +1468,32 @@
   }
 }
 
+/****************************************************************************
+  Send orders for the unit to move it to the arbitrary tile and attack
+  everything it approaches. Returns FALSE if no path is found.
+****************************************************************************/
+bool send_attack_tile(struct unit *punit, struct tile *ptile)
+{
+  struct pf_parameter parameter;
+  struct pf_map *pfm;
+  struct pf_path *path;
+
+  goto_fill_parameter_base(&parameter, punit);
+  parameter.move_rate = 0;
+  parameter.is_pos_dangerous = NULL;
+  parameter.get_moves_left_req = NULL;
+  pfm = pf_map_new(&parameter);
+  path = pf_map_path(pfm, ptile);
+  pf_map_destroy(pfm);
+
+  if (path) {
+   send_path_orders(punit, path, false, false, ORDER_ACTION_MOVE, NULL);
+   pf_path_destroy(path);
+   return TRUE;
+  }
+  return FALSE;
+}
+
 /**************************************************************************
   Send the current patrol route (i.e., the one generated via HOVER_STATE)
   to the server.
@@ -1489,7 +1516,7 @@
     }
     path = pf_path_concat(path, goto_map->patrol.return_path);
 
-    send_path_orders(punit, path, TRUE, TRUE, NULL);
+    send_path_orders(punit, path, TRUE, TRUE, ORDER_MOVE, NULL);
 
     pf_path_destroy(path);
   } goto_map_unit_iterate_end;

Modified: branches/S2_6/client/goto.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/goto.h?rev=31265&r1=31264&r2=31265&view=diff
==============================================================================
--- branches/S2_6/client/goto.h (original)
+++ branches/S2_6/client/goto.h Wed Dec 30 13:29:32 2015
@@ -52,6 +52,7 @@
 void send_goto_path(struct unit *punit, struct pf_path *path,
                    struct unit_order *last_order);
 bool send_goto_tile(struct unit *punit, struct tile *ptile);
+bool send_attack_tile(struct unit *punit, struct tile *ptile);
 void send_patrol_route(void);
 void send_goto_route(void);
 void send_connect_route(enum unit_activity activity,


_______________________________________________
Freeciv-commits mailing list
Freeciv-commits@gna.org
https://mail.gna.org/listinfo/freeciv-commits

Reply via email to