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

[Freeciv-Dev] Unit move rate 2 (PR#1344)

[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 2 (PR#1344)
From: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Date: Mon, 25 Mar 2002 04:00:53 -0800 (PST)

Due to Per's comments on my use of exit(1) instead of exit(EXIT_FAILURE).
If you can think of a better freelog error message, feel free to replace my
existing one, and make formatting changes(no changes to actual code).

Improvements as a result of this patch:

More readable than existing code
Removal of struct player *pplayer, substitution of val with move_rate.
Changing return type from int to static int.
Insertion of debug messages and exit if things go wrong. 




__________________________________________________
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 21:21:24 2002
@@ -34,31 +34,59 @@
 
 
 /***************************************************************
-...
+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);
+    freelog(LOG_ERROR, "This unit has an illegal move type 
%s",unit_type(punit)->move_type); 
+    exit(EXIT_FAILURE);
+    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

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