[Freeciv-Dev] (PR#13334) [Patch] Unit class sutrcuture with move paramet
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=13334 >
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.
In this version sea units gain advantage from roads when moving from
city to (adjacent) city. I will fix that to next version.
This applies on top of #13136.
- ML
diff -Nurd -X.diff_ignore freeciv/common/map.c freeciv/common/map.c
--- freeciv/common/map.c 2005-06-25 17:38:07.781250000 +0300
+++ freeciv/common/map.c 2005-06-25 20:43:54.781250000 +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,7 @@
* if "slowinvasions" server option is turned on. */
return punit->moves_left;
}
- if (punit && !is_ground_unit(punit))
+ if (punit && !class->move.terrain_affects)
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-25 17:38:07.812500000 +0300
+++ freeciv/common/movement.c 2005-06-25 20:50:44.468750000 +0300
@@ -48,17 +48,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)
@@ -69,17 +69,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-25 17:38:08.562500000 +0300
+++ freeciv/common/unittype.c 2005-06-25 20:43:54.796875000 +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-25 20:44:24.312500000 +0300
+++ freeciv/common/unittype.h 2005-06-25 20:43:54.796875000 +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] |
- [Freeciv-Dev] (PR#13334) [Patch] Unit class sutrcuture with move parameters,
Marko Lindqvist <=
|
|