Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Unit_move_rate 3 (PR#1347)
Home

[Freeciv-Dev] Unit_move_rate 3 (PR#1347)

[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 3 (PR#1347)
From: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Date: Mon, 25 Mar 2002 19:00:46 -0800 (PST)

Author:                 Raahul
Patch Name:             unit_move_rate3.diff
Dependencies:           This patch has no dependencies on other patches.
Supercedes:             All earlier versions .
CVS version:            diffed against March 22
Compile intruction:     The usual ./configure, make, make install
Savegames:              Not tested, should be no difference.
Compiles successfully:  Yes

The changes made are:

Removal of 

struct player *pplayer = unit_owner(punit);
and replacement of int val with int move_rate.

Use of a case statement to replace the barely readable if statements,
and insertion of debugging messages using LOG_FATAL.

More progress being made towards the goal of using the same variable names
throughtout the code. This is in contrast to the current situation where we
have the same thing (punit->move_rate) named move_rate and val.

Thanks to Per for his formatting and debugging comments and Greg for spotting
the compile error.


__________________________________________________
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      Tue Mar 26 12:57:56 2002
@@ -34,30 +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)
 {
-  int val;
-  struct player *pplayer = unit_owner(punit);
+
+ 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;
   
-  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;
+  if (player_owns_active_wonder(unit_owner(punit), B_LIGHTHOUSE)) {
+      move_rate += SINGLE_MOVE;
   }
-  if (val < SINGLE_MOVE
-      && unit_type(punit)->move_rate > 0) {
-    val = SINGLE_MOVE;
+   
+  if (player_owns_active_wonder(unit_owner(punit), B_MAGELLAN)) {
+      move_rate += (improvement_variant(B_MAGELLAN) == 1) ?
+      SINGLE_MOVE : 2 * SINGLE_MOVE;
   }
-  return val;
+   
+  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_FATAL, "In common/unit.c: function unit_move_rate");
+   freelog(LOG_FATAL, "Illegal move type %s",unit_type(punit)->move_type);
+   exit(EXIT_FAILURE);
+   move_rate = -1;
+ }
+  
+ if (move_rate < SINGLE_MOVE
+     && unit_type(punit)->move_rate > 0) {
+     move_rate = SINGLE_MOVE;
+ }
+ return move_rate;
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Unit_move_rate 3 (PR#1347), Raahul Kumar <=