Author: mir3x
Date: Sat Jan  2 01:39:56 2016
New Revision: 31299

URL: http://svn.gna.org/viewcvs/freeciv?rev=31299&view=rev
Log:
Added function tile_before_end_path(struct unit *punit, struct tile *ptile)
to find tile before end path for unit going to given ptile.
(eg. if unit attacked city it will stay on that tile)

See patch #6742


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=31299&r1=31298&r2=31299&view=diff
==============================================================================
--- branches/S2_6/client/goto.c (original)
+++ branches/S2_6/client/goto.c Sat Jan  2 01:39:56 2016
@@ -1701,3 +1701,32 @@
 
   return path;
 }
+
+/**************************************************************************
+  Finds penultimate tile on path for given unit going to ptile
+***************************************************************************/
+struct tile *tile_before_end_path(struct unit *punit, struct tile *ptile)
+{
+  struct pf_parameter parameter;
+  struct pf_map *pfm;
+  struct tile *dtile;
+  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);
+  if (path == NULL) {
+    return NULL;
+  }
+  if (path->length < 2) {
+    dtile = NULL;
+  } else {
+    dtile = path->positions[path->length - 2].tile;
+  }
+  pf_map_destroy(pfm);
+
+  return dtile;
+}

Modified: branches/S2_6/client/goto.h
URL: 
http://svn.gna.org/viewcvs/freeciv/branches/S2_6/client/goto.h?rev=31299&r1=31298&r2=31299&view=diff
==============================================================================
--- branches/S2_6/client/goto.h (original)
+++ branches/S2_6/client/goto.h Sat Jan  2 01:39:56 2016
@@ -59,6 +59,7 @@
                         struct extra_type *tgt);
 
 struct pf_path *path_to_nearest_allied_city(struct unit *punit);
+struct tile *tile_before_end_path(struct unit *punit, struct tile *ptile);
 
 #ifdef __cplusplus
 }


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

Reply via email to