Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2002:
[Freeciv-Dev] New AI cleanups
Home

[Freeciv-Dev] New AI cleanups

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Mike Kaufman <kaufman@xxxxxxxxxxxxxxxxxxxxxx>, freeciv-dev@xxxxxxxxxxx
Cc: bugs@xxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] New AI cleanups
From: Raahul Kumar <raahul_da_man@xxxxxxxxx>
Date: Sat, 23 Mar 2002 03:57:33 -0800 (PST)

The following diffs are included as a replacement for Aicleanup Version 3.
No save games are different, and this was done against March 20 CVS. The
changes only touch aiunit.c which has not been effected by any changes to the
AI according to the changelog.

The patches are:

Unit move turns 2
Fix Sea Moves

Unit move turns was a result of a discussion between Raimar and myself.
Greg(GB) improved the comments, and Raimar actually coded it. I'm just
responsible for the comments and the update to current CVS.

Fix Sea moves is a minor cleanup on my part to use SINGLE_MOVE where it should
be used.Don't bother reading the comment, read the diff. 

If anyone wishes to know, yes, I will send in IGTER cleanups next.


__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards®
http://movies.yahoo.com/
diff -ruN -Xdiff_ignore /home/rkumar/sound/freeciv-cvs/ai/aiunit.c 
/home/rkumar/sound/freeciv/ai/aiunit.c
--- /home/rkumar/sound/freeciv-cvs/ai/aiunit.c  Sat Mar 23 21:03:15 2002
+++ /home/rkumar/sound/freeciv/ai/aiunit.c      Sat Mar 23 21:13:00 2002
@@ -132,31 +132,83 @@
   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;
-  }
+/**********************************************************************
+ 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
 
-  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);
-}
+ 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.*/
+
+    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);
+    exit(1);
+    move_time = -1;
+  }
+  return move_time;
+ }
+ 
 /**************************************************************************
   is there any hope of reaching this tile without violating ZOC? 
 **************************************************************************/
diff -ruN -Xdiff_ignore /home/rkumar/sound/freeciv-cvs/ai/aiunit.c 
/home/rkumar/sound/freeciv/ai/aiunit.c
--- /home/rkumar/sound/freeciv-cvs/ai/aiunit.c  Sat Mar 23 21:03:15 2002
+++ /home/rkumar/sound/freeciv/ai/aiunit.c      Sat Mar 23 21:29:03 2002
@@ -1529,8 +1529,8 @@
   if (ferryboat) really_generate_warmap(map_get_city(ferryboat->x, 
ferryboat->y),
                        ferryboat, SEA_MOVING);
 
-  if (ferryboat) boatspeed = (unit_flag(ferryboat, F_TRIREME) ? 6 : 12);
-  else boatspeed = (get_invention(pplayer, game.rtech.nav) != TECH_KNOWN ? 6 : 
12);
+  if (ferryboat) boatspeed = (unit_flag(ferryboat, F_TRIREME) ? 2 * 
SINGLE_MOVE : 4 * SINGLE_MOVE);
+  else boatspeed = (get_invention(pplayer, game.rtech.nav) != TECH_KNOWN ? 2 * 
SINGLE_MOVE : 4 * SINGLE_MOVE);
 
   if (is_ground_unit(punit) && punit->id == 0 &&
       is_terrain_near_tile(punit->x, punit->y, T_OCEAN)) harborcity++;
diff -ruN -Xdiff_ignore /home/rkumar/sound/freeciv-cvs/diffcommand 
/home/rkumar/sound/freeciv/diffcommand
--- /home/rkumar/sound/freeciv-cvs/diffcommand  Wed Dec 31 19:00:00 1969
+++ /home/rkumar/sound/freeciv/diffcommand      Sat Mar 23 21:33:19 2002
@@ -0,0 +1 @@
+ diff -ruN -Xdiff_ignore ~/sound/freeciv-cvs ~/sound/freeciv 
>/tmp/fix_sea_moves.diff

[Prev in Thread] Current Thread [Next in Thread]