Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] Unit move turns 3 (PR#1345)
Home

[Freeciv-Dev] Unit move turns 3 (PR#1345)

[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 turns 3 (PR#1345)
From: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Date: Mon, 25 Mar 2002 04:08:02 -0800 (PST)

This is the final version of unit move turns. Necessary because of my foolish
use of exit(1) as Per pointed out. Written by Raimar, additional comments by
GB, and minor changes by me.

Advantages

More readable
Error messages and debugging tools
Removal of a variable and more consistent use of move_rate.

__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/
diff -ruN -Xdiff_ignore /home/rkumar/tmp/cvs-freeciv/ai/aiunit.c 
/home/rkumar/tmp/freeciv/ai/aiunit.c
--- /home/rkumar/tmp/cvs-freeciv/ai/aiunit.c    Sun Mar 24 18:15:01 2002
+++ /home/rkumar/tmp/freeciv/ai/aiunit.c        Mon Mar 25 21:08:38 2002
@@ -147,30 +147,91 @@
   return FALSE;
 }
 
-/********************************************************************** 
-  ...
-***********************************************************************/
-static int unit_move_turns(struct unit *punit, int x, int y)
-{
-  int m, d;
-  m = unit_type(punit)->move_rate;
-  if (unit_flag(punit, F_IGTER)) m *= SINGLE_MOVE;
-  if(is_sailing_unit(punit)) {
-    struct player *pplayer = unit_owner(punit);
-    if (player_owns_active_wonder(pplayer, B_LIGHTHOUSE)) 
-      m += SINGLE_MOVE;
-    if (player_owns_active_wonder(pplayer, B_MAGELLAN))
-      m += (improvement_variant(B_MAGELLAN)==1) ? SINGLE_MOVE : 2 * 
SINGLE_MOVE;
-    m += num_known_tech_with_flag(pplayer, TF_BOAT_FAST) * SINGLE_MOVE;
-  }
 
-  if (unit_type(punit)->move_type == LAND_MOVING)
-    d = warmap.cost[x][y] / m;
-  else if (unit_type(punit)->move_type == SEA_MOVING)
-    d = warmap.seacost[x][y] / m;
-  else d = real_map_distance(punit->x, punit->y, x, y) * SINGLE_MOVE / m;
-  return(d);
-}
+/**********************************************************************
+ Precondition: A warmap must already be generated for the punit
+
+ Returns the minimal amount of turns required to reach the given
+ destination position. The actual turn at which the unit will
+ reach the given point depends on the movement points it has remaining.
+
+ For example: Unit has a move rate of 3, path cost is 5, unit has 2
+ move points left
+
+ path1 costs: first tile = 3, second tile = 2
+
+
+ turn 0: points=2, unit has to wait
+ turn 1: points=3, unit can move, points=0, has to wait
+ turn 2: points=3, unit can move, points=1
+
+ path2 costs: first tile=2, second tile=3
+
+
+ turn 0: points=2, unit can move, points=0, has to wait
+ turn 1: points=3, unit can move, points=0
+ 
+
+ In spite of the path costs being the same, these two units will arrive
+ at different times. This function also does not take into account ZOC.
+ 
+ Note: even if a unit has only fractional move points left, there is
+ still a possibility it could cross the tile.
+
+**************************************************************************/
+
+ static int unit_move_turns(struct unit *punit, int x, int y)
+ {
+
+  int move_time, move_rate = unit_type(punit)->move_rate;
+
+  switch (unit_type(punit)->move_type) {
+  case LAND_MOVING:
+ 
+/***************************************************************************** 
+ FIXME: IGTER units should have their move rates multiplied by igter_speedup
+ Note: actually, igter units should never have their move rates multiplied.
+ The correct behaviour is to have every tile they cross cost 1/3 of a movement
+ point. ---RK
+******************************************************************************/
+
+    if (unit_flag(punit, F_IGTER)) {
+      move_rate *= 3;
+    }
+    move_time = warmap.cost[x][y] / move_rate;
+    break;
+
+  case SEA_MOVING:
+  
+    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;
+     }
+     
+    move_time = warmap.seacost[x][y] / move_rate;
+    break;
+
+  case HELI_MOVING:
+  case AIR_MOVING:
+     move_time = real_map_distance(punit->x, punit->y, x,y) * SINGLE_MOVE / 
move_rate;
+     break;
+
+  default:
+    assert(0);
+    freelog(LOG_ERROR, "This unit has an illegal move type 
%s",unit_type(punit)->move_type);
+    exit(EXIT_FAILURE);
+    move_time = -1;
+  }
+  return move_time;
+ }
 
 /**************************************************************************
   is there any hope of reaching this tile without violating ZOC? 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Unit move turns 3 (PR#1345), Raahul Kumar <=