Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Unit move rate cleanup (PR#1343)
Home

[Freeciv-Dev] Unit move rate cleanup (PR#1343)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] Unit move rate cleanup (PR#1343)
From: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Date: Sun, 24 Mar 2002 19:47:04 -0800 (PST)

This patch was made against March 22 CVS. No save games should be different.

This cleans up unit move rate by getting rid of struct player *pplayer and
replacing val with move_rate. I've also made it return a static int, and
introduced an assert and -1 return value for errors.


This is part of my long term project to use the same variable names throughout
the code instead of the exciting array of options we currently have for the
same thing!

I've also used a case statement and made it slightly more readable. Enjoy.

__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/
diff -ruN -Xdiff_ignore /home/rkumar/tmp/cvs-freeciv/common/unit.c 
/home/rkumar/tmp/freeciv/common/unit.c
--- /home/rkumar/tmp/cvs-freeciv/common/unit.c  Sun Mar 24 18:15:02 2002
+++ /home/rkumar/tmp/freeciv/common/unit.c      Mon Mar 25 13:05:08 2002
@@ -34,31 +34,58 @@
 
 
 /***************************************************************
-...
+Unit move rate calculates the move rate of the unit taking into 
+account the penalty for reduced hitpoints(affects sea and land units 
+only) and the effects of wonders for sea units. --RK
 ***************************************************************/
-int unit_move_rate(struct unit *punit)
+
+static int unit_move_rate(struct unit *punit)
 {
-  int val;
-  struct player *pplayer = unit_owner(punit);
-  
-  val = unit_type(punit)->move_rate;
-  if (!is_air_unit(punit) && !is_heli_unit(punit)) 
-    val = (val * punit->hp) / unit_type(punit)->hp;
-  if(is_sailing_unit(punit)) {
-    if(player_owns_active_wonder(pplayer, B_LIGHTHOUSE)) 
-      val+=SINGLE_MOVE;
-    if(player_owns_active_wonder(pplayer, B_MAGELLAN)) 
-      val += (improvement_variant(B_MAGELLAN)==1) ? SINGLE_MOVE : 2 * 
SINGLE_MOVE;
-    val += num_known_tech_with_flag(pplayer, TF_BOAT_FAST) * SINGLE_MOVE;
-    if (val < 2 * SINGLE_MOVE)
-      val = 2 * SINGLE_MOVE;
+
+ int move_rate = unit_type(punit)->move_rate;
+
+ switch (unit_type(punit)->move_type) {
+ case LAND_MOVING:
+   move_rate = (move_rate * punit->hp) / unit_type(punit)->hp;
+   break;
+   
+ case SEA_MOVING:
+   move_rate = (move_rate * punit->hp) / unit_type(punit)->hp;
+   
+   if (player_owns_active_wonder(unit_owner(punit), B_LIGHTHOUSE)) {
+      move_rate += SINGLE_MOVE;
+   }
+   
+   if (player_owns_active_wonder(unit_owner(punit), B_MAGELLAN)) {
+   move_rate += (improvement_variant(B_MAGELLAN) == 1) ?
+   SINGLE_MOVE : 2 * SINGLE_MOVE;
+   }
+   
+   if (player_knows_techs_with_flag(unit_owner(punit), TF_BOAT_FAST)) {
+   move_rate += SINGLE_MOVE;
+   }
+   
+   if (move_rate < 2 * SINGLE_MOVE) {
+   move_rate = 2 * SINGLE_MOVE; 
+   }
+   break;
+
+  case HELI_MOVING:
+  case AIR_MOVING:
+   break;
+
+  default:
+    assert(0);
+    exit(1);
+    move_rate = -1;
   }
-  if (val < SINGLE_MOVE
+  
+  if (move_rate < SINGLE_MOVE
       && unit_type(punit)->move_rate > 0) {
-    val = SINGLE_MOVE;
+      move_rate = SINGLE_MOVE;
   }
-  return val;
-}
+  return move_rate;
+ }
 
 /**************************************************************************
 bribe unit
diff -ruN -Xdiff_ignore /home/rkumar/tmp/cvs-freeciv/diffcommand 
/home/rkumar/tmp/freeciv/diffcommand
--- /home/rkumar/tmp/cvs-freeciv/diffcommand    Wed Dec 31 19:00:00 1969
+++ /home/rkumar/tmp/freeciv/diffcommand        Mon Mar 25 12:56:55 2002
@@ -0,0 +1 @@
+ diff -ruN -Xdiff_ignore ~/tmp/cvs-freeciv ~/tmp/freeciv 
>/tmp/unit_move_rate.diff

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Unit move rate cleanup (PR#1343), Raahul Kumar <=