Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] Re: (PR#11338) [Patch] can_transport()
Home

[Freeciv-Dev] Re: (PR#11338) [Patch] can_transport()

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#11338) [Patch] can_transport()
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Sun, 13 Mar 2005 08:37:40 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11338 >

Marko Lindqvist wrote:
> 
>   This one applies on top of #11336.

  Updated against CVS.


  - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiferry.c freeciv/ai/aiferry.c
--- freeciv/ai/aiferry.c        2005-03-13 12:38:42.609375000 +0200
+++ freeciv/ai/aiferry.c        2005-03-13 13:22:32.453125000 +0200
@@ -269,11 +269,11 @@
 
 /****************************************************************************
   Runs a few checks to determine if "boat" is a free boat that can carry
-  "cap" units of the same type as "punit" (the last one isn't implemented).
+  "cap" units of the same type as "punit".
 ****************************************************************************/
 static bool is_boat_free(struct unit *boat, struct unit *punit, int cap)
 {
-  /* - Only ground-unit transporters are consider.
+  /* - Only transporters capable of transporting this unit are eligible.
    * - Units with orders are skipped (the AI doesn't control units with
    *   orders).
    * - Only boats that we own are eligible.
@@ -281,7 +281,7 @@
    *   are eligible.
    * - Only boats with enough remaining capacity are eligible.
    */
-  return (is_ground_units_transport(boat)
+  return (can_unit_transport(boat, punit)
          && !unit_has_orders(boat)
          && boat->owner == punit->owner
          && (boat->ai.passenger == FERRY_AVAILABLE
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c   2005-03-13 12:38:43.000000000 +0200
+++ freeciv/common/movement.c   2005-03-13 13:31:26.703125000 +0200
@@ -34,6 +34,9 @@
 };
 
 
+static bool can_unit_type_transport(Unit_Type_id transporter,
+                                    Unit_Type_id transported);
+
 /****************************************************************************
   This function calculates the move rate of the unit, taking into 
   account the penalty for reduced hitpoints (affects sea and land 
@@ -446,3 +449,54 @@
 
   return MR_OK;
 }
+
+/**************************************************************************
+  Return true iff transporter has ability to transport transported.
+**************************************************************************/
+bool can_unit_transport(const struct unit *transporter,
+                        const struct unit *transported)
+{
+  return can_unit_type_transport(transporter->type, transported->type);
+}
+
+/**************************************************************************
+  Return TRUE iff transporter type has ability to transport transported type.
+**************************************************************************/
+static bool can_unit_type_transport(Unit_Type_id transporter,
+                                    Unit_Type_id transported)
+{
+  if (get_unit_type(transporter)->transport_capacity <= 0) {
+    return FALSE;
+  }
+
+  if (get_unit_type(transported)->move_type == LAND_MOVING) {
+    if ((unit_type_flag(transporter, F_CARRIER)
+         || unit_type_flag(transporter, F_MISSILE_CARRIER))) {
+      return FALSE;
+    }
+    return TRUE;
+  }
+
+  if (!unit_type_flag(transported, F_MISSILE)
+     && unit_type_flag(transporter, F_MISSILE_CARRIER)) {
+    return FALSE;
+  }
+
+  if (unit_type_flag(transported, F_MISSILE)) {
+    if (!unit_type_flag(transporter, F_MISSILE_CARRIER)
+        && !unit_type_flag(transporter, F_CARRIER)) {
+      return FALSE;
+    }
+  } else if ((get_unit_type(transported)->move_type == AIR_MOVING
+              || get_unit_type(transported)->move_type == HELI_MOVING)
+             && !unit_type_flag(transporter, F_CARRIER)) {
+    return FALSE;
+  }
+
+  if (get_unit_type(transported)->move_type == SEA_MOVING) {
+    /* No unit can transport sea units at the moment */
+    return FALSE;
+  }
+
+  return TRUE;
+}
diff -Nurd -X.diff_ignore freeciv/common/movement.h freeciv/common/movement.h
--- freeciv/common/movement.h   2005-03-13 12:38:43.031250000 +0200
+++ freeciv/common/movement.h   2005-03-13 13:31:09.921875000 +0200
@@ -48,5 +48,6 @@
                                             const struct tile *src_tile,
                                             const struct tile *dst_tile,
                                             bool igzoc);
+bool can_unit_transport(const struct unit *transporter, const struct unit 
*transported);
 
 #endif  /* FC__MOVEMENT_H */
diff -Nurd -X.diff_ignore freeciv/common/unit.c freeciv/common/unit.c
--- freeciv/common/unit.c       2005-03-13 12:38:43.031250000 +0200
+++ freeciv/common/unit.c       2005-03-13 13:22:32.484375000 +0200
@@ -257,18 +257,6 @@
 }
 
 /**************************************************************************
-  Return TRUE iff the unit is a transporter of air (including missile)
-  units.
-**************************************************************************/
-bool is_air_units_transport(const struct unit *punit)
-{
-  return (get_transporter_capacity(punit) > 0
-         && (unit_flag(punit, F_MISSILE_CARRIER)
-             || unit_flag(punit, F_CARRIER)));
-}
-
-
-/**************************************************************************
   Is the unit capable of attacking?
 **************************************************************************/
 bool is_attack_unit(const struct unit *punit)
@@ -594,19 +582,7 @@
   }
 
   /* Make sure this transporter can carry this type of unit. */
-  if (is_ground_unit(pcargo)) {
-    if (!is_ground_units_transport(ptrans)) {
-      return FALSE;
-    }
-  } else if (unit_flag(pcargo, F_MISSILE)) {
-    if (!is_air_units_transport(ptrans)) {
-      return FALSE;
-    }
-  } else if (is_air_unit(pcargo) || is_heli_unit(pcargo)) {
-    if (!unit_flag(ptrans, F_CARRIER)) {
-      return FALSE;
-    }
-  } else {
+  if(!can_unit_transport(ptrans, pcargo)) {
     return FALSE;
   }
 
diff -Nurd -X.diff_ignore freeciv/common/unit.h freeciv/common/unit.h
--- freeciv/common/unit.h       2005-03-13 12:38:43.046875000 +0200
+++ freeciv/common/unit.h       2005-03-13 13:22:32.500000000 +0200
@@ -279,7 +279,6 @@
                                     const struct player *pplayer);
 int get_transporter_capacity(const struct unit *punit);
 bool is_ground_units_transport(const struct unit *punit);
-bool is_air_units_transport(const struct unit *punit);
 int missile_carrier_capacity(const struct tile *ptile,
                             const struct player *pplayer,
                             bool count_units_with_extra_fuel);
diff -Nurd -X.diff_ignore freeciv/server/sanitycheck.c 
freeciv/server/sanitycheck.c
--- freeciv/server/sanitycheck.c        2005-03-13 12:38:43.171875000 +0200
+++ freeciv/server/sanitycheck.c        2005-03-13 13:22:32.515625000 +0200
@@ -375,18 +375,9 @@
       }
 
       /* Check for ground units in the ocean. */
-      if (!pcity
-         && is_ocean(map_get_terrain(ptile))
-         && is_ground_unit(punit)) {
-        SANITY_CHECK(punit->transported_by != -1);
-        SANITY_CHECK(!is_ground_unit(transporter));
-        SANITY_CHECK(is_ground_units_transport(transporter));
-      } else if (!pcity
-                 && !is_ocean(map_get_terrain(ptile))
-                && is_sailing_unit(punit)) {
+      if (!can_unit_exist_at_tile(punit, ptile)) {
         SANITY_CHECK(punit->transported_by != -1);
-        SANITY_CHECK(!is_sailing_unit(transporter));
-        SANITY_CHECK(FALSE); /* 
SANITY_CHECK(is_sailing_units_transport(transporter)); */
+        SANITY_CHECK(can_unit_transport(transporter, punit));
       }
 
       /* Check for over-full transports. */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#11338) [Patch] can_transport(), Marko Lindqvist <=