Complete.Org: Mailing Lists: Archives: freeciv-dev: June 2005:
[Freeciv-Dev] Re: (PR#13334) [Patch] Unit class structure with move para
Home

[Freeciv-Dev] Re: (PR#13334) [Patch] Unit class structure with move para

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] Re: (PR#13334) [Patch] Unit class structure with move parameters
From: "Marko Lindqvist" <marko.lindqvist@xxxxxxxxxxx>
Date: Sun, 26 Jun 2005 08:11:51 -0700
Reply-to: bugs@xxxxxxxxxxx

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


  Updated so that applies on top of #13341.


  - ML

diff -Nurd -X.diff_ignore freeciv/common/map.c freeciv/common/map.c
--- freeciv/common/map.c        2005-06-26 13:58:31.625000000 +0300
+++ freeciv/common/map.c        2005-06-26 15:33:51.750000000 +0300
@@ -629,6 +629,11 @@
                               const struct tile *t1, const struct tile *t2)
 {
   bool cardinal_move;
+  struct unit_class *class = NULL;
+
+  if(punit) {
+    class = get_unit_class(punit->type);
+  }
 
   if (game.info.slow_invasions
       && punit 
@@ -639,7 +644,8 @@
      * if "slowinvasions" server option is turned on. */
     return punit->moves_left;
   }
-  if (punit && !is_ground_unit(punit))
+  if (punit && (!class->move.terrain_affects
+                || !is_native_terrain(punit, t2->terrain)))
     return SINGLE_MOVE;
   if (tile_has_special(t1, S_RAILROAD) && tile_has_special(t2, S_RAILROAD))
     return MOVE_COST_RAIL;
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c   2005-06-26 15:32:54.078125000 +0300
+++ freeciv/common/movement.c   2005-06-26 15:33:13.093750000 +0300
@@ -44,17 +44,17 @@
   int move_rate = 0;
   int base_move_rate = unit_type(punit)->move_rate 
     + unit_type(punit)->veteran[punit->veteran].move_bonus;
+  struct unit_class *pclass = get_unit_class(punit->type);
 
-  switch (unit_type(punit)->move_type) {
-  case LAND_MOVING:
-    /* Scale the MP based on how many HP the unit has. */
-    move_rate = (base_move_rate * punit->hp) / unit_type(punit)->hp;
-    break;
+  move_rate = base_move_rate;
 
-  case SEA_MOVING:
-    /* Scale the MP based on how many MP the unit has. */
-    move_rate = (base_move_rate * punit->hp) / unit_type(punit)->hp;
+  if(pclass->move.damage_slows) {
+    /* Scale the MP based on how many HP the unit has. */
+    move_rate = (move_rate * punit->hp) / unit_type(punit)->hp;
+  }
 
+  /* TODO: These effects should not be hardcoded to unit class enumeration */
+  if(pclass->id == UCL_SEA) {
     /* Add on effects bonus (Magellan's Expedition, Lighthouse,
      * Nuclear Power). */
     move_rate += (get_unit_bonus(punit, EFT_SEA_MOVE)
@@ -65,17 +65,6 @@
     if (move_rate < 2 * SINGLE_MOVE) {
       move_rate = MIN(2 * SINGLE_MOVE, base_move_rate);
     }
-    break;
-
-  case HELI_MOVING:
-  case AIR_MOVING:
-    /* No modifiers for air or helicoptor units. */
-    move_rate = base_move_rate;
-    break;
-
-  default:
-    die("In %s:unit_move_rate: illegal move type %d",
-       __FILE__, unit_type(punit)->move_type);
   }
 
   /* Don't let any unit get less than 1 MP. */
diff -Nurd -X.diff_ignore freeciv/common/unittype.c freeciv/common/unittype.c
--- freeciv/common/unittype.c   2005-06-26 13:58:32.281250000 +0300
+++ freeciv/common/unittype.c   2005-06-26 15:33:13.093750000 +0300
@@ -64,6 +64,15 @@
   "Sea"
 };
 
+struct unit_class unit_classes[] = {
+  { UCL_AIR, { FALSE, FALSE }},
+  { UCL_HELICOPTER, { FALSE, FALSE }},
+  { UCL_LAND, { TRUE, TRUE }},
+  { UCL_MISSILE, { FALSE, FALSE }},
+  { UCL_NUCLEAR, { FALSE, FALSE }},
+  { UCL_SEA, { TRUE, TRUE }}
+};
+
 /**************************************************************************
   Return a pointer for the unit type struct for the given unit type id.
 **************************************************************************/
@@ -668,3 +677,11 @@
     unit_type_free(i);
   } unit_type_iterate_end;
 }
+
+/***************************************************************
+ Returns unit class structure
+***************************************************************/
+struct unit_class *get_unit_class(Unit_type_id type)
+{
+  return &unit_classes[get_unit_type(type)->class];
+}
diff -Nurd -X.diff_ignore freeciv/common/unittype.h freeciv/common/unittype.h
--- freeciv/common/unittype.h   2005-06-26 15:32:54.078125000 +0300
+++ freeciv/common/unittype.h   2005-06-26 15:33:13.109375000 +0300
@@ -47,6 +47,16 @@
   to hold full number of unit types.
 */
 
+struct move_params {
+  bool terrain_affects;
+  bool damage_slows;
+};
+
+struct unit_class {
+  Unit_Class_id id;
+  struct move_params move;
+};
+
 /* Unit "special effects" flags:
    Note this is now an enumerated type, and not power-of-two integers
    for bits, though unit_type.flags is still a bitfield, and code
@@ -218,6 +228,7 @@
 int unit_disband_shields(Unit_type_id id);
 int unit_pop_value(Unit_type_id id);
 
+struct unit_class *get_unit_class(Unit_type_id type);
 const char *unit_name(Unit_type_id id);
 const char *unit_name_orig(Unit_type_id id);
 const char *unit_class_name(Unit_Class_id id);

[Prev in Thread] Current Thread [Next in Thread]