Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] Re: (PR#11338) [Patch] can_unit_transport()
Home

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

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#11338) [Patch] can_unit_transport()
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Sat, 18 Dec 2004 05:00:53 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Vasco Alexandre da Silva Costa wrote:
> 
> This patch isn't in the One True Bracing style. Please indent according to
> CodingStyle.

  Sorry, I mixed (once again) styles between different projects. 
Attached patch is in freeciv style.

  I have not run any regression tests since first version I posted, but 
changes I have made since are more of style issues than code changes anyway.


  - ML

diff -Nurd -X.diff_ignore freeciv/ai/aiferry.c freeciv/ai/aiferry.c
--- freeciv/ai/aiferry.c        2004-12-18 14:29:05.453125000 +0200
+++ freeciv/ai/aiferry.c        2004-12-18 14:43:54.078125000 +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   2004-12-18 14:29:05.703125000 +0200
+++ freeciv/common/movement.c   2004-12-18 14:46:37.000000000 +0200
@@ -33,6 +33,9 @@
   "Land", "Sea", "Heli", "Air"
 };
 
+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 
@@ -426,3 +429,53 @@
 
   return MR_OK;
 }
+
+/**************************************************************************
+  Return true iff transporter has ability to transport transported.
+**************************************************************************/
+bool can_unit_transport(struct unit *transporter, 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   2004-12-18 14:29:05.703125000 +0200
+++ freeciv/common/movement.h   2004-12-18 14:43:54.109375000 +0200
@@ -46,5 +46,6 @@
                                             const struct tile *src_tile,
                                             const struct tile *dst_tile,
                                             bool igzoc);
+bool can_unit_transport(struct unit *transporter, struct unit *transported);
 
 #endif  /* FC__MOVEMENT_H */
diff -Nurd -X.diff_ignore freeciv/common/unit.c freeciv/common/unit.c
--- freeciv/common/unit.c       2004-12-18 14:29:05.718750000 +0200
+++ freeciv/common/unit.c       2004-12-18 14:43:54.109375000 +0200
@@ -248,16 +248,6 @@
 }
 
 /**************************************************************************
-...
-**************************************************************************/
-bool is_air_units_transport(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(struct unit *punit)
@@ -569,19 +559,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       2004-12-18 14:29:05.734375000 +0200
+++ freeciv/common/unit.h       2004-12-18 14:43:54.125000000 +0200
@@ -273,7 +273,6 @@
                                     struct player *pplayer);
 int get_transporter_capacity(struct unit *punit);
 bool is_ground_units_transport(struct unit *punit);
-bool is_air_units_transport(struct unit *punit);
 int missile_carrier_capacity(const struct tile *ptile,
                             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        2004-12-18 14:29:05.859375000 +0200
+++ freeciv/server/sanitycheck.c        2004-12-18 14:43:54.140625000 +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]