Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2005:
[Freeciv-Dev] (PR#11763) is_free_worked_tile function
Home

[Freeciv-Dev] (PR#11763) is_free_worked_tile function

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11763) is_free_worked_tile function
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 1 Jan 2005 22:02:12 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11763 >

This patch changes many/most of the callers of is_city_center to use a 
new function is_free_worked_tile.  The two functions are identical so no 
behavior is changed for the moment.

This is a step toward removing the free city center and/or removing tile 
working completely.  It's a very small step though.

It shows some problems: namely the places where is_city_center is still 
used.

1.  In city.c.  The min city center productions still apply to the city 
center only.  Is this the correct thing to do?  Probably.

2.  In aisettler.c.  The settler map (or whatever it's called) cannot 
handle calculating data for the city center, because the city center is 
hackishly overloaded to hold other data.  I don't know what to do about 
this, and it will become a problem if the city center is no longer given 
free.

The name is a bit questionable.  It could be is_free_city_tile or 
is_free_worked_city_tile.  I don't want is_free_city_center as was 
previously suggested, because this really has little to do with the city 
center.

-jason

? gmon.out
? ngrep
? ngrep2
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.188
diff -u -r1.188 aicity.c
--- ai/aicity.c 24 Dec 2004 16:20:22 -0000      1.188
+++ ai/aicity.c 2 Jan 2005 05:43:09 -0000
@@ -1106,8 +1106,8 @@
               pcity->name, acity->name, ptile->x, ptile->y);
       is_valid = map_to_city_map(&city_map_x, &city_map_y, acity, ptile);
       assert(is_valid);
-      if (!is_valid || is_city_center(city_map_x, city_map_y)) {
-        /* can't stop working city center */
+      if (!is_valid || is_free_worked_tile(city_map_x, city_map_y)) {
+       /* Can't remove a worker here. */
         continue;
       }
       server_remove_worker_city(acity, city_map_x, city_map_y);
Index: client/agents/cma_core.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v
retrieving revision 1.69
diff -u -r1.69 cma_core.c
--- client/agents/cma_core.c    15 Dec 2004 00:15:12 -0000      1.69
+++ client/agents/cma_core.c    2 Jan 2005 05:43:09 -0000
@@ -80,7 +80,7 @@
 
 #define my_city_map_iterate(pcity, cx, cy) {                           \
   city_map_checked_iterate(pcity->tile, cx, cy, _ptile) { \
-    if(!is_city_center(cx, cy)) {
+    if (!is_free_worked_tile(cx, cy)) {
 
 #define my_city_map_iterate_end \
     }                                \
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.190
diff -u -r1.190 city.h
--- common/city.h       1 Jan 2005 22:47:14 -0000       1.190
+++ common/city.h       2 Jan 2005 05:43:10 -0000
@@ -358,6 +358,9 @@
 }
 
 
+static inline bool is_city_center(int city_x, int city_y);
+static inline bool is_free_worked_tile(int city_x, int city_y);
+
 /* output type functions */
 
 const char *get_output_identifier(Output_type_id output);
@@ -551,4 +554,13 @@
   return CITY_MAP_RADIUS == city_x && CITY_MAP_RADIUS == city_y;
 }
 
+/**************************************************************************
+  Return TRUE iff the given city coordinate pair can be worked for free by
+  a city.
+**************************************************************************/
+static inline bool is_free_worked_tile(int city_x, int city_y)
+{
+  return is_city_center(city_x, city_y);
+}
+
 #endif  /* FC__CITY_H */
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.56
diff -u -r1.56 cm.c
--- common/aicore/cm.c  1 Jan 2005 22:47:14 -0000       1.56
+++ common/aicore/cm.c  2 Jan 2005 05:43:12 -0000
@@ -632,7 +632,7 @@
    * the city center). */
   memset(&pcity->specialists, 0, sizeof(pcity->specialists));
   city_map_iterate(x, y) {
-    if (is_city_center(x, y)) {
+    if (is_free_worked_tile(x, y)) {
       continue;
     }
     if (pcity->city_map[x][y] == C_TILE_WORKER) {
@@ -1113,7 +1113,7 @@
     if (pcity->city_map[x][y] == C_TILE_UNAVAILABLE) {
       continue;
     }
-    if (!is_city_center(x, y)) {
+    if (!is_free_worked_tile(x, y)) {
       compute_tile_production(pcity, x, y, &type); /* clobbers type */
       tile_type_lattice_add(lattice, &type, x, y); /* copy type if needed */
     }
@@ -1885,7 +1885,7 @@
   int count = 0;
 
   city_map_iterate(x, y) {
-    if(result->worker_positions_used[x][y] && !is_city_center(x, y)) {
+    if (result->worker_positions_used[x][y] && !is_free_worked_tile(x, y)) {
       count++;
     }
   } city_map_iterate_end;
@@ -2106,7 +2106,7 @@
     for (x = 0; x < CITY_MAP_SIZE; x++) {
       if (!is_valid_city_coords(x, y)) {
         line[x] = '-';
-      } else if (is_city_center(x, y)) {
+      } else if (is_free_worked_tile(x, y)) {
         line[x] = 'c';
       } else if (result->worker_positions_used[x][y]) {
         line[x] = 'w';
Index: server/cityhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v
retrieving revision 1.139
diff -u -r1.139 cityhand.c
--- server/cityhand.c   21 Dec 2004 04:18:54 -0000      1.139
+++ server/cityhand.c   2 Jan 2005 05:43:12 -0000
@@ -99,7 +99,7 @@
   if (!pcity) {
     return;
   }
-  if (is_city_center(worker_x, worker_y)) {
+  if (is_free_worked_tile(worker_x, worker_y)) {
     auto_arrange_workers(pcity);
     sync_cities();
     return;
@@ -135,7 +135,7 @@
     return;
   }
 
-  if (is_city_center(worker_x, worker_y)) {
+  if (is_free_worked_tile(worker_x, worker_y)) {
     auto_arrange_workers(pcity);
     sync_cities();
     return;
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.296
diff -u -r1.296 citytools.c
--- server/citytools.c  21 Dec 2004 04:18:54 -0000      1.296
+++ server/citytools.c  2 Jan 2005 05:43:13 -0000
@@ -1847,7 +1847,7 @@
   }
   
   if (is_enemy_unit_tile(ptile, city_owner(pcity))
-      && !is_city_center(city_x, city_y)) {
+      && !is_free_worked_tile(city_x, city_y)) {
     return FALSE;
   }
 
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.290
diff -u -r1.290 cityturn.c
--- server/cityturn.c   21 Dec 2004 22:57:36 -0000      1.290
+++ server/cityturn.c   2 Jan 2005 05:43:13 -0000
@@ -158,12 +158,12 @@
   /* Now apply results */
   city_map_checked_iterate(pcity->tile, x, y, ptile) {
     if (pcity->city_map[x][y] == C_TILE_WORKER
-        && !is_city_center(x, y)
+        && !is_free_worked_tile(x, y)
         && !cmr->worker_positions_used[x][y]) {
       server_remove_worker_city(pcity, x, y);
     }
     if (pcity->city_map[x][y] != C_TILE_WORKER
-        && !is_city_center(x, y)
+        && !is_free_worked_tile(x, y)
         && cmr->worker_positions_used[x][y]) {
       server_set_worker_city(pcity, x, y);
     }
@@ -451,7 +451,7 @@
     /* Take it out on workers */
     city_map_iterate(x, y) {
       if (get_worker_city(pcity, x, y) == C_TILE_WORKER
-          && !is_city_center(x, y) && pop_loss > 0) {
+          && !is_free_worked_tile(x, y) && pop_loss > 0) {
         server_remove_worker_city(pcity, x, y);
         pop_loss--;
       }
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.216
diff -u -r1.216 settlers.c
--- server/settlers.c   19 Dec 2004 19:44:40 -0000      1.216
+++ server/settlers.c   2 Jan 2005 05:43:13 -0000
@@ -1206,7 +1206,7 @@
   int best = 0;
 
   city_map_iterate(x, y) {
-    if (is_city_center(x, y) 
+    if (is_free_worked_tile(x, y) 
        || get_worker_city(pcity, x, y) == C_TILE_WORKER 
        || get_worker_city(pcity, x, y) == C_TILE_EMPTY) {
       int tmp = city_tile_value(pcity, x, y, 0, 0);

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11763) is_free_worked_tile function, Jason Short <=