[Freeciv-Dev] Re: (PR#11338) [Patch] can_unit_transport()
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11338 >
>
>> Function names are probably not final. What naming convention should
>>be used here?
>
> It should mention "unit" somewhere. Maybe can_unit_transport() or
> can_unit_transport_unit() or unit_can_transport_unit(). And the same for
> unittype.
can_unittype_transport_unittype() seemed too long so I use
can_unit[type]_transport().
- Updated against latest CVS
- Unrelated stuff removed
- can_unittype_transport() made static, for now (there probably will
be callers outside movement.c in the future)
- ML
diff -Nurd -X.diff_ignore freeciv/ai/aiferry.c freeciv/ai/aiferry.c
--- freeciv/ai/aiferry.c 2004-12-17 02:45:30.062500000 +0200
+++ freeciv/ai/aiferry.c 2004-12-17 02:45:40.140625000 +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-17 02:45:30.281250000 +0200
+++ freeciv/common/movement.c 2004-12-17 03:00:34.875000000 +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,63 @@
return MR_OK;
}
+
+/**************************************************************************
+ Whether '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);
+}
+
+/**************************************************************************
+ Whether 'transporter' of given 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;
+ }
+
+ /* No unit can transport sea units */
+ if (get_unit_type(transported)->move_type == SEA_MOVING)
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
diff -Nurd -X.diff_ignore freeciv/common/movement.h freeciv/common/movement.h
--- freeciv/common/movement.h 2004-12-17 02:45:30.296875000 +0200
+++ freeciv/common/movement.h 2004-12-17 02:45:40.140625000 +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-17 02:45:30.296875000 +0200
+++ freeciv/common/unit.c 2004-12-17 02:45:40.171875000 +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-17 02:45:30.312500000 +0200
+++ freeciv/common/unit.h 2004-12-17 02:45:40.171875000 +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-17 02:45:30.421875000 +0200
+++ freeciv/server/sanitycheck.c 2004-12-17 02:59:00.781250000 +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. */
|
|