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: Tue, 28 Jun 2005 15:49:46 -0700
Reply-to: bugs@xxxxxxxxxxx

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

Marko Lindqvist wrote:
> 
>   This patch introduces unit_class structure and populates it with 
> couple of movement related parameters.
>   - terrain_affects: move rate is subject to terrain and terrain 
> improvement effects. True to all but flying units.
>   - damage_slows: move rate gets lower when unit is damaged. True to all 
> but flying units.

  Fixed bug in F_IGTER units entering ships.


  - ML

diff -Nurd -X.diff_ignore freeciv/common/map.c freeciv/common/map.c
--- freeciv/common/map.c        2005-06-28 23:10:04.500000000 +0300
+++ freeciv/common/map.c        2005-06-29 01:19:16.984375000 +0300
@@ -14,7 +14,6 @@
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
-
 #include <assert.h>
 #include <string.h>            /* strlen */
 
@@ -629,6 +628,13 @@
                               const struct tile *t1, const struct tile *t2)
 {
   bool cardinal_move;
+  struct unit_class *pclass = NULL;
+  bool native = TRUE;
+
+  if (punit) {
+    pclass = get_unit_class(punit->type);
+    native = is_native_terrain(punit, t2->terrain);
+  }
 
   if (game.info.slow_invasions
       && punit 
@@ -639,15 +645,28 @@
      * if "slowinvasions" server option is turned on. */
     return punit->moves_left;
   }
-  if (punit && !is_ground_unit(punit))
+
+  if (punit && !pclass->move.terrain_affects) {
     return SINGLE_MOVE;
-  if (tile_has_special(t1, S_RAILROAD) && tile_has_special(t2, S_RAILROAD))
+  }
+
+  /* Railroad check has to be before F_IGTER check so that F_IGTER
+   * units are not penalized. F_IGTER affects also entering and
+   * leaving ships, so F_IGTER check has to be before native terrain
+   * check. We want to give railroad bonus only to native units. */
+  if (tile_has_special(t1, S_RAILROAD) && tile_has_special(t2, S_RAILROAD)
+      && native) {
     return MOVE_COST_RAIL;
-/* return (unit_move_rate(punit)/RAIL_MAX) */
-  if (punit && unit_flag(punit, F_IGTER))
+  }
+  if (punit && unit_flag(punit, F_IGTER)) {
     return SINGLE_MOVE/3;
-  if (tile_has_special(t1, S_ROAD) && tile_has_special(t2, S_ROAD))
+  }
+  if (!native) {
+    return SINGLE_MOVE;
+  }
+  if (tile_has_special(t1, S_ROAD) && tile_has_special(t2, S_ROAD)) {
     return MOVE_COST_ROAD;
+  }
 
   if (tile_has_special(t1, S_RIVER) && tile_has_special(t2, S_RIVER)) {
     cardinal_move = is_move_cardinal(t1, t2);
diff -Nurd -X.diff_ignore freeciv/common/movement.c freeciv/common/movement.c
--- freeciv/common/movement.c   2005-06-28 23:10:04.531250000 +0300
+++ freeciv/common/movement.c   2005-06-29 00:53:33.640625000 +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-28 23:10:06.734375000 +0300
+++ freeciv/common/unittype.c   2005-06-29 01:18:45.609375000 +0300
@@ -64,6 +64,15 @@
   "Nuclear",
 };
 
+struct unit_class unit_classes[] = {
+  { UCL_MISSILE,    { FALSE, FALSE }},
+  { UCL_LAND,       { TRUE,  TRUE  }},
+  { UCL_SEA,        { TRUE,  TRUE  }},
+  { UCL_HELICOPTER, { FALSE, FALSE }},
+  { UCL_AIR,        { FALSE, FALSE }},
+  { UCL_NUCLEAR,    { FALSE, FALSE }}
+};
+
 /**************************************************************************
   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-28 23:10:06.765625000 +0300
+++ freeciv/common/unittype.h   2005-06-29 00:53:33.640625000 +0300
@@ -47,6 +47,16 @@
   to hold full number of unit types.
 */
 
+struct move_params {
+  bool terrain_affects; /* Move rate is subject to terrain and improvement 
effects */
+  bool damage_slows;    /* Damaged unit is slowed down */
+};
+
+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]