Author: pepeto
Date: Sat Jul 19 11:14:09 2014
New Revision: 25618

URL: http://svn.gna.org/viewcvs/freeciv?rev=25618&view=rev
Log:
Really take in account embark/disembark restriction rules when moving. It was
resulting units standing on undesirable tiles. Remove confusing
unit_class_transporter_capacity(), and prefer transport_from_tile().

See gna bug #22299

Modified:
    trunk/ai/default/aiair.c
    trunk/common/movement.c
    trunk/common/movement.h
    trunk/common/unit.c
    trunk/server/unittools.c
    trunk/server/unittools.h

Modified: trunk/ai/default/aiair.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/ai/default/aiair.c?rev=25618&r1=25617&r2=25618&view=diff
==============================================================================
--- trunk/ai/default/aiair.c    (original)
+++ trunk/ai/default/aiair.c    Sat Jul 19 11:14:09 2014
@@ -61,7 +61,6 @@
                                          struct pf_path **path)
 {
   struct player *pplayer = unit_owner(punit);
-  const struct unit_type *punittype = unit_type(punit);
   struct pf_parameter parameter;
   struct pf_map *pfm;
 
@@ -75,7 +74,7 @@
       break;
     }
 
-    if (is_airunit_refuel_point(ptile, pplayer, punittype, FALSE)) {
+    if (is_airunit_refuel_point(ptile, pplayer, punit)) {
       if (path) {
         *path = pf_map_path(pfm, ptile);
       }
@@ -273,8 +272,7 @@
       break; /* Too far! */
     }
 
-    if (!is_airunit_refuel_point(ptile, pplayer,
-                                 unit_type(punit), FALSE)) {
+    if (!is_airunit_refuel_point(ptile, pplayer, punit)) {
       continue; /* Cannot refuel here. */
     }
 
@@ -346,8 +344,7 @@
         /* We are on a GOTO.  Check if it will get us anywhere */
         && NULL != punit->goto_tile
         && !same_pos(unit_tile(punit), punit->goto_tile)
-        && is_airunit_refuel_point(punit->goto_tile, 
-                                   pplayer, unit_type(punit), FALSE)) {
+        && is_airunit_refuel_point(punit->goto_tile, pplayer, punit)) {
       pfm = pf_map_new(&parameter);
       path = pf_map_path(pfm, punit->goto_tile);
       if (path) {

Modified: trunk/common/movement.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/movement.c?rev=25618&r1=25617&r2=25618&view=diff
==============================================================================
--- trunk/common/movement.c     (original)
+++ trunk/common/movement.c     Sat Jul 19 11:14:09 2014
@@ -570,8 +570,7 @@
 
   /* 5) */
   if (!(can_exist_at_tile(punittype, dst_tile)
-        || unit_class_transporter_capacity(dst_tile, puowner,
-                                           utype_class(punittype)) > 0)) {
+        || NULL != transport_from_tile(punit, dst_tile))) {
     return MR_NO_TRANSPORTER_CAPACITY;
   }
 
@@ -640,9 +639,7 @@
   if (!(is_native_move(utype_class(punittype), src_tile, dst_tile)
         /* Allow non-native moves into cities or boarding transport. */
         || pcity
-        || 0 < unit_class_transporter_capacity(dst_tile,
-                                               puowner,
-                                               utype_class(punittype)))) {
+        || NULL != transport_from_tile(punit, dst_tile))) {
     return MR_NON_NATIVE_MOVE;
   }
 
@@ -678,7 +675,8 @@
   Search transport suitable for given unit from tile. It has to have
   free space in it.
 **************************************************************************/
-struct unit *transport_from_tile(struct unit *punit, struct tile *ptile)
+struct unit *transport_from_tile(const struct unit *punit,
+                                 const struct tile *ptile)
 {
   unit_list_iterate(ptile->units, ptransport) {
     if (could_unit_load(punit, ptransport)) {
@@ -687,30 +685,6 @@
   } unit_list_iterate_end;
 
   return NULL;
-}
- 
-/**************************************************************************
- Returns the number of free spaces for units of given class.
- Can be 0.
-**************************************************************************/
-int unit_class_transporter_capacity(const struct tile *ptile,
-                                    const struct player *pplayer,
-                                    const struct unit_class *pclass)
-{
-  int availability = 0;
-
-  unit_list_iterate(ptile->units, punit) {
-    if (unit_owner(punit) == pplayer
-        || pplayers_allied(unit_owner(punit), pplayer)) {
-
-      if (can_unit_type_transport(unit_type(punit), pclass)) {
-        availability += get_transporter_capacity(punit);
-        availability -= get_transporter_occupancy(punit);
-      }
-    }
-  } unit_list_iterate_end;
-
-  return availability;
 }
 
 static int move_points_denomlen = 0;

Modified: trunk/common/movement.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/movement.h?rev=25618&r1=25617&r2=25618&view=diff
==============================================================================
--- trunk/common/movement.h     (original)
+++ trunk/common/movement.h     Sat Jul 19 11:14:09 2014
@@ -90,10 +90,8 @@
 bool can_unit_transport(const struct unit *transporter, const struct unit 
*transported);
 bool can_unit_type_transport(const struct unit_type *transporter,
                              const struct unit_class *transported);
-int unit_class_transporter_capacity(const struct tile *ptile,
-                                    const struct player *pplayer,
-                                    const struct unit_class *pclass);
-struct unit *transport_from_tile(struct unit *punit, struct tile *ptile);
+struct unit *transport_from_tile(const struct unit *punit,
+                                 const struct tile *ptile);
 
 void init_move_fragments(void);
 const char *move_points_text_full(int mp, bool reduce, const char *prefix,

Modified: trunk/common/unit.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/common/unit.c?rev=25618&r1=25617&r2=25618&view=diff
==============================================================================
--- trunk/common/unit.c (original)
+++ trunk/common/unit.c Sat Jul 19 11:14:09 2014
@@ -2026,9 +2026,8 @@
   }
 
   if (!can_type_transport_units_cargo(to_unittype, punit)) {
-    /* TODO: allow transported units to be reassigned.  Check for
-     * unit_class_transporter_capacity() here and make changes to
-     * upgrade_unit. */
+    /* TODO: allow transported units to be reassigned.  Check here
+     * and make changes to upgrade_unit. */
     return UU_NOT_ENOUGH_ROOM;
   }
 

Modified: trunk/server/unittools.c
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.c?rev=25618&r1=25617&r2=25618&view=diff
==============================================================================
--- trunk/server/unittools.c    (original)
+++ trunk/server/unittools.c    Sat Jul 19 11:14:09 2014
@@ -421,9 +421,7 @@
               break;
             }
 
-            if (is_airunit_refuel_point(ptile, pplayer,
-                                       unit_type(punit), FALSE)) {
-
+            if (is_airunit_refuel_point(ptile, pplayer, punit)) {
               struct pf_path *path;
               int id = punit->id;
 
@@ -1323,36 +1321,32 @@
 /**************************************************************************
   Can unit refuel on tile. Considers also carrier capacity on tile.
 **************************************************************************/
-bool is_airunit_refuel_point(struct tile *ptile, struct player *pplayer,
-                            const struct unit_type *type,
-                            bool unit_is_on_carrier)
-{
-  int cap;
-  struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
-
-  if (!is_non_allied_unit_tile(ptile, pplayer)) {
-    struct unit_class *pclass = utype_class(type);
-
-    if (is_allied_city_tile(ptile, pplayer)) {
-      return TRUE;
-    }
-
-    if (pclass->cache.refuel_bases != NULL) {
-      extra_type_list_iterate(pclass->cache.refuel_bases, pextra) {
-        if (BV_ISSET(plrtile->extras, extra_index(pextra))) {
-          return TRUE;
-        }
-      } extra_type_list_iterate_end;
-    }
-  }
-
-  cap = unit_class_transporter_capacity(ptile, pplayer, utype_class(type));
-
-  if (unit_is_on_carrier) {
-    cap++;
-  }
-
-  return cap > 0;
+bool is_airunit_refuel_point(const struct tile *ptile,
+                             const struct player *pplayer,
+                             const struct unit *punit)
+{
+  const struct unit_class *pclass;
+
+  if (NULL != is_non_allied_unit_tile(ptile, pplayer)) {
+    return FALSE;
+  }
+
+  if (NULL != is_allied_city_tile(ptile, pplayer)) {
+    return TRUE;
+  }
+
+  pclass = unit_class(punit);
+  if (NULL != pclass->cache.refuel_bases) {
+    const struct player_tile *plrtile = map_get_player_tile(ptile, pplayer);
+
+    extra_type_list_iterate(pclass->cache.refuel_bases, pextra) {
+      if (BV_ISSET(plrtile->extras, extra_index(pextra))) {
+        return TRUE;
+      }
+    } extra_type_list_iterate_end;
+  }
+
+  return (NULL != transport_from_tile(punit, ptile));
 }
 
 /**************************************************************************

Modified: trunk/server/unittools.h
URL: 
http://svn.gna.org/viewcvs/freeciv/trunk/server/unittools.h?rev=25618&r1=25617&r2=25618&view=diff
==============================================================================
--- trunk/server/unittools.h    (original)
+++ trunk/server/unittools.h    Sat Jul 19 11:14:09 2014
@@ -82,9 +82,9 @@
 
 /* move check related */
 bool is_unit_being_refueled(const struct unit *punit);
-bool is_airunit_refuel_point(struct tile *ptile, struct player *pplayer,
-                            const struct unit_type *punittype,
-                            bool unit_is_on_carrier);
+bool is_airunit_refuel_point(const struct tile *ptile,
+                             const struct player *pplayer,
+                             const struct unit *punit);
 
 /* turn update related */
 void player_restore_units(struct player *pplayer);


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

Reply via email to