Complete.Org: Mailing Lists: Archives: freeciv-dev: July 1999:
[Freeciv-Dev] [PATCH] Make Auto Setters transform too
Home

[Freeciv-Dev] [PATCH] Make Auto Setters transform too

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] [PATCH] Make Auto Setters transform too
From: Markus Linnala <maage@xxxxxxxxx>
Date: 05 Jul 1999 02:30:10 +0300
Reply-to: Markus Linnala <maage@xxxxxxxxx>

With this patch your autosettlers can and will also use
transform.

1999-07-05  Markus Linnala  <maage@xxxxxxxxx>

        * common/city.h: add transform field to struct ai_city

        * server/settlers.h: new function ai_calc_transform

        * server/settlers.c (ai_calc_transform): new function
        (auto_settler_findwork): use ai_calc_transform
        (initialize_infrastructure_cache): use ai_calc_transform

diff -u --ignore-space-change --recursive --new-file --exclude-from=.diffignore 
freeciv-cvs/common/city.h m/freeciv/common/city.h
--- freeciv-cvs/common/city.h   Sat Jun 12 15:03:27 1999
+++ m/freeciv/common/city.h     Sun Jul  4 18:43:36 1999
@@ -121,7 +119,7 @@
   struct ai_choice choice; /* to spend gold in the right place only */
   int downtown; /* distance from neighbours, for locating wonders wisely */
   int distance_to_wonder_city; /* wondercity will set this for us, avoiding 
paradox */
-  signed short int detox[5][5], mine[5][5], irrigate[5][5], road[5][5], 
railroad[5][5];
+  signed short int detox[5][5], mine[5][5], irrigate[5][5], road[5][5], 
railroad[5][5], transform[5][5];
 /* caching these so that CPU usage is O(cities) instead of O(cities^2) -- 
Syela */
   signed short int tile_value[5][5]; /* caching these will help too. */
   int settler_want; /* so we can contemplate with warmap fresh and decide 
later */
diff -u --ignore-space-change --recursive --new-file --exclude-from=.diffignore 
freeciv-cvs/server/settlers.c m/freeciv/server/settlers.c
--- freeciv-cvs/server/settlers.c       Thu Jun 24 14:55:21 1999
+++ m/freeciv/server/settlers.c Sun Jul  4 22:29:36 1999
@@ -542,6 +547,34 @@
   } else return(-1);
 }
 
+int ai_calc_transform(struct city *pcity, struct player *pplayer, int i, int j)
+{
+  int m, x = pcity->x + i - 2, y = pcity->y + j - 2;
+  struct tile *ptile = map_get_tile(x, y);
+
+  enum tile_terrain_type t = ptile->terrain;
+  struct tile_type *type = get_tile_type(t);
+  int s = ptile->special;
+  enum tile_terrain_type r = type->transform_result;
+  
+  if ((t == T_ARCTIC || t == T_DESERT || t == T_JUNGLE || t == T_SWAMP  || 
+       t == T_TUNDRA || t == T_MOUNTAINS) && r != T_LAST) {
+    ptile->terrain = r;
+
+    ;
+    if (get_tile_type(r)->mining_result != r) 
+      map_clear_special(x, y, S_MINE);
+
+    if (get_tile_type(r)->irrigation_result != r) 
+      map_clear_special(x, y, S_IRRIGATION);
+
+    m = city_tile_value(pcity, i, j, 0, 0);
+    ptile->terrain = t;
+    ptile->special = s;
+    return(m);
+  } else return(-1);
+}
+
 int road_bonus(int x, int y, int spc)
 {
   int m = 0, k;
@@ -833,6 +866,23 @@
          best_newv=newv; gx=x; gy=y; best_oldv=oldv;
         }
 
+       newv = pcity->ai.transform[i][j];
+        if (newv >= oldv) { /* worth evaluating */
+          b = MAX((newv - oldv)*64, MORT);
+          d = (map_transform_time(x, y) * 3 + mv_rate - 1) / mv_rate
+           + mv_turns;
+          a = amortize(b, d);
+          newv = ((a * b) / (MAX(1, b - a)))/64;
+        } else newv = 0;
+        if ((newv > best_newv || (newv == best_newv && oldv > best_oldv))
+           && ai_fuzzy(pplayer, 1)) {
+         freelog(LOG_DEBUG,
+                 "Replacing (%d, %d) = %d with (%d, %d) I=%d d=%d, b=%d",
+                 gx, gy, best_newv, x, y, newv, d, b);
+         best_act = ACTIVITY_TRANSFORM;
+         best_newv=newv; gx=x; gy=y; best_oldv=oldv;
+        }
+
        newv = pcity->ai.mine[i][j];
         if (newv >= oldv) {
           b = MAX((newv - oldv)<<6, MORT);
@@ -1162,6 +1212,7 @@
     pcity->ai.detox[i][j] = ai_calc_pollution(pcity, pplayer, i, j);
     pcity->ai.mine[i][j] = ai_calc_mine(pcity, pplayer, i, j);
     pcity->ai.irrigate[i][j] = ai_calc_irrigate(pcity, pplayer, i, j);
+    pcity->ai.transform[i][j] = ai_calc_transform(pcity, pplayer, i, j);
     pcity->ai.road[i][j] = ai_calc_road(pcity, pplayer, i, j);
 /* gonna handle road_bo dynamically for now since it can change
 as punits arrive at adjacent tiles and start laying road -- Syela */
diff -u --ignore-space-change --recursive --new-file --exclude-from=.diffignore 
freeciv-cvs/server/settlers.h m/freeciv/server/settlers.h
--- freeciv-cvs/server/settlers.h       Fri Jun 11 14:56:53 1999
+++ m/freeciv/server/settlers.h Sun Jul  4 18:48:10 1999
@@ -37,6 +37,7 @@
 int ai_calc_road(struct city *pcity, struct player *pplayer, int i, int j);
 int ai_calc_railroad(struct city *pcity, struct player *pplayer, int i, int j);
 int ai_calc_irrigate(struct city *pcity, struct player *pplayer, int i, int j);
+int ai_calc_transform(struct city *pcity, struct player *pplayer, int i, int 
j);
 int in_city_radius(int x, int y);
 int is_ok_city_spot(int x, int y); /* laughable, really. */
 int make_dy(int y1, int y2);

-- 
//Markus

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] [PATCH] Make Auto Setters transform too, Markus Linnala <=