Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8856) specialists and the CM interface
Home

[Freeciv-Dev] (PR#8856) specialists and the CM interface

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8856) specialists and the CM interface
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 27 May 2004 19:18:12 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=8856 >

This patch changes the CM interface to use a specialists array instead 
of a variable for each specialist.

The CM internals are not changed.  A few of the users are simplified.

jason

? diff
? ferries
? flags
? data/flags
Index: client/agents/cma_core.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v
retrieving revision 1.52
diff -u -r1.52 cma_core.c
--- client/agents/cma_core.c    27 May 2004 22:14:18 -0000      1.52
+++ client/agents/cma_core.c    28 May 2004 02:15:47 -0000
@@ -117,9 +117,9 @@
 {
   T(disorder);
   T(happy);
-  T(entertainers);
-  T(scientists);
-  T(taxmen);
+  T(specialists[SP_ELVIS]);
+  T(specialists[SP_SCIENTIST]);
+  T(specialists[SP_TAXMAN]);
 
   T(production[FOOD]);
   T(production[SHIELD]);
@@ -225,8 +225,8 @@
 
   freelog(LOG_NORMAL,
          "print_result:  people: W/E/S/T %d/%d/%d/%d",
-         worker, result->entertainers, result->scientists,
-         result->taxmen);
+         worker, result->specialists[SP_ELVIS],
+         result->specialists[SP_SCIENTIST], result->specialists[SP_TAXMAN]);
 
   for (i = 0; i < NUM_STATS; i++) {
     freelog(LOG_NORMAL,
@@ -269,7 +269,7 @@
 static void get_current_as_result(struct city *pcity,
                                  struct cm_result *result)
 {
-  int worker = 0;
+  int worker = 0, i;
 
   memset(result->worker_positions_used, 0,
         sizeof(result->worker_positions_used));
@@ -282,12 +282,13 @@
     }
   } my_city_map_iterate_end;
 
-  result->entertainers = pcity->specialists[SP_ELVIS];
-  result->scientists = pcity->specialists[SP_SCIENTIST];
-  result->taxmen = pcity->specialists[SP_TAXMAN];
+  for (i = 0; i < SP_COUNT; i++) {
+    result->specialists[i] = pcity->specialists[i];
+  }
 
-  assert(worker + result->entertainers + result->scientists +
-        result->taxmen == pcity->size);
+  assert(worker + result->specialists[SP_ELVIS]
+        + result->specialists[SP_SCIENTIST]
+        + result->specialists[SP_TAXMAN] == pcity->size);
 
   result->found_a_valid = TRUE;
 
@@ -330,7 +331,7 @@
 static bool apply_result_on_server(struct city *pcity,
                                   const struct cm_result *const result)
 {
-  int first_request_id = 0, last_request_id = 0, i, worker;
+  int first_request_id = 0, last_request_id = 0, i, sp, worker;
   struct cm_result current_state;
   bool success;
 
@@ -352,8 +353,9 @@
   /* Do checks */
   worker = count_worker(pcity, result);
   if (pcity->size !=
-      (worker + result->entertainers + result->scientists +
-       result->taxmen)) {
+      (worker + result->specialists[SP_ELVIS]
+       + result->specialists[SP_SCIENTIST]
+       + result->specialists[SP_TAXMAN])) {
     print_city(pcity);
     print_result(pcity, result);
     assert(0);
@@ -370,26 +372,22 @@
     }
   } my_city_map_iterate_end;
 
-  /* Change surplus scientists to entertainers */
-  for (i = 0; i < pcity->specialists[SP_SCIENTIST] - result->scientists;
-       i++) {
-    last_request_id = city_change_specialist(pcity, SP_SCIENTIST, SP_ELVIS);
-    if (first_request_id == 0) {
-      first_request_id = last_request_id;
-    }
-  }
-
-  /* Change surplus taxmen to entertainers */
-  for (i = 0; i < pcity->specialists[SP_TAXMAN] - result->taxmen; i++) {
-    last_request_id = city_change_specialist(pcity, SP_TAXMAN, SP_ELVIS);
-    if (first_request_id == 0) {
-      first_request_id = last_request_id;
+  /* Change the excess non-elvis specialists to elvises. */
+  assert(SP_ELVIS == 0);
+  for (sp = 1; sp < SP_COUNT; sp++) {
+    for (i = 0; i < pcity->specialists[sp] - result->specialists[sp]; i++) {
+      last_request_id = city_change_specialist(pcity, sp, SP_ELVIS);
+      if (first_request_id == 0) {
+       first_request_id = last_request_id;
+      }
     }
   }
 
   /* now all surplus people are enterainers */
 
   /* Set workers */
+  /* FIXME: This code assumes that any toggled worker will turn into an
+   * elvis! */
   my_city_map_iterate(pcity, x, y) {
     if (result->worker_positions_used[x][y] &&
        pcity->city_map[x][y] != C_TILE_WORKER) {
@@ -401,20 +399,15 @@
     }
   } my_city_map_iterate_end;
 
-  /* Set scientists. */
-  for (i = 0; i < result->scientists - pcity->specialists[SP_SCIENTIST];
-       i++) {
-    last_request_id = city_change_specialist(pcity, SP_ELVIS, SP_SCIENTIST);
-    if (first_request_id == 0) {
-      first_request_id = last_request_id;
-    }
-  }
-
-  /* Set taxmen. */
-  for (i = 0; i < result->taxmen - pcity->specialists[SP_TAXMAN]; i++) {
-    last_request_id = city_change_specialist(pcity, SP_ELVIS, SP_TAXMAN);
-    if (first_request_id == 0) {
-      first_request_id = last_request_id;
+  /* Set all specialists except SP_ELVIS (all the unchanged ones remain
+   * as elvises). */
+  assert(SP_ELVIS == 0);
+  for (sp = 1; sp < SP_COUNT; sp++) {
+    for (i = 0; i < result->specialists[sp] - pcity->specialists[sp]; i++) {
+      last_request_id = city_change_specialist(pcity, SP_ELVIS, sp);
+      if (first_request_id == 0) {
+       first_request_id = last_request_id;
+      }
     }
   }
 
Index: client/agents/cma_fec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_fec.c,v
retrieving revision 1.19
diff -u -r1.19 cma_fec.c
--- client/agents/cma_fec.c     5 May 2004 20:39:15 -0000       1.19
+++ client/agents/cma_fec.c     28 May 2004 02:15:47 -0000
@@ -361,9 +361,13 @@
 
     my_snprintf(buf[6], BUFFER_SIZE, "%d/%d/%d/%d%s",
                pcity->size -
-               (result->entertainers + result->scientists +
-                result->taxmen), result->entertainers, result->scientists,
-               result->taxmen, result->happy ? _(" happy") : "");
+               (result->specialists[SP_ELVIS]
+                + result->specialists[SP_SCIENTIST]
+                + result->specialists[SP_TAXMAN]),
+               result->specialists[SP_ELVIS],
+               result->specialists[SP_SCIENTIST],
+               result->specialists[SP_TAXMAN],
+               result->happy ? _(" happy") : "");
 
     my_snprintf(buf[7], BUFFER_SIZE, "%s",
                get_city_growth_string(pcity, result->surplus[FOOD]));
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.21
diff -u -r1.21 cm.c
--- common/aicore/cm.c  27 May 2004 22:14:19 -0000      1.21
+++ common/aicore/cm.c  28 May 2004 02:15:47 -0000
@@ -326,7 +326,8 @@
   int i;
 
   if (!parameter->allow_specialists
-      && (result->entertainers + result->scientists + result->taxmen) >
+      && (result->specialists[SP_ELVIS] + result->specialists[SP_SCIENTIST]
+         + result->specialists[SP_TAXMAN]) >
       MAX(0,cache3.pcity->size - cache3.fields_available_total)) {
     return FALSE;
   }
@@ -423,8 +424,9 @@
 
   freelog(LOG_NORMAL,
          "print_result:  people: W/E/S/T %d/%d/%d/%d",
-         worker, result->entertainers, result->scientists,
-         result->taxmen);
+         worker, result->specialists[SP_ELVIS],
+         result->specialists[SP_SCIENTIST],
+         result->specialists[SP_TAXMAN]);
 
   for (i = 0; i < NUM_STATS; i++) {
     freelog(LOG_NORMAL,
@@ -528,7 +530,8 @@
    * unhappy_city_check.
    */
   if (!result->disorder) {
-    p = get_secondary_stat(result->production[TRADE], result->scientists,
+    p = get_secondary_stat(result->production[TRADE],
+                          result->specialists[SP_SCIENTIST],
                           SP_SCIENTIST);
     if (!p->is_valid) {
       p->production = result->production[SCIENCE];
@@ -545,7 +548,8 @@
    * unhappy_city_check.
    */
   if (!result->disorder) {
-    p = get_secondary_stat(result->production[TRADE], result->taxmen,
+    p = get_secondary_stat(result->production[TRADE],
+                          result->specialists[SP_TAXMAN],
                           SP_TAXMAN);
     if (!p->is_valid && !result->disorder) {
       p->production = result->production[GOLD];
@@ -557,7 +561,8 @@
     }
   }
 
-  p = get_secondary_stat(result->production[TRADE], result->entertainers,
+  p = get_secondary_stat(result->production[TRADE],
+                        result->specialists[SP_ELVIS],
                         SP_ELVIS);
   if (!p->is_valid) {
     p->production = result->production[LUXURY];
@@ -616,8 +621,9 @@
 
   /* Do checks */
   if (pcity->size !=
-      (worker + result->entertainers + result->scientists +
-       result->taxmen)) {
+      (worker + result->specialists[SP_ELVIS]
+       + result->specialists[SP_SCIENTIST]
+       + result->specialists[SP_TAXMAN])) {
     print_city(pcity);
     print_result(pcity, result);
     assert(0);
@@ -639,9 +645,9 @@
     }
   } my_city_map_iterate_end;
 
-  pcity->specialists[SP_ELVIS] = result->entertainers;
-  pcity->specialists[SP_SCIENTIST] = result->scientists;
-  pcity->specialists[SP_TAXMAN] = result->taxmen;
+  pcity->specialists[SP_ELVIS] = result->specialists[SP_ELVIS];
+  pcity->specialists[SP_SCIENTIST] = result->specialists[SP_SCIENTIST];
+  pcity->specialists[SP_TAXMAN] = result->specialists[SP_TAXMAN];
 
   /* Do a local recalculation of the city */
   generic_city_refresh(pcity, FALSE, NULL);
@@ -653,8 +659,8 @@
 
   freelog(LOG_DEBUG, "xyz: w=%d e=%d s=%d t=%d trade=%d "
          "sci=%d lux=%d tax=%d dis=%s happy=%s",
-         count_worker(pcity, result), result->entertainers,
-         result->scientists, result->taxmen,
+         count_worker(pcity, result), result->specialists[SP_ELVIS],
+         result->specialists[SP_SCIENTIST], result->specialists[SP_TAXMAN],
          result->production[TRADE],
          result->production[SCIENCE],
          result->production[LUXURY],
@@ -817,15 +823,15 @@
        (base_combination->worker_positions[x][y] == C_TILE_WORKER);
   } my_city_map_iterate_end;
 
-  result->scientists = scientists;
-  result->taxmen = taxmen;
-  result->entertainers =
+  result->specialists[SP_SCIENTIST] = scientists;
+  result->specialists[SP_TAXMAN] = taxmen;
+  result->specialists[SP_ELVIS] =
       pcity->size - (base_combination->worker + scientists + taxmen);
 
   freelog(LOG_DEBUG,
          "fill_out_result(city='%s'(%d), entrt.s=%d, scien.s=%d, taxmen=%d)",
-         pcity->name, pcity->id, result->entertainers,
-         result->scientists, result->taxmen);
+         pcity->name, pcity->id, result->specialists[SP_ELVIS],
+         result->specialists[SP_SCIENTIST], result->specialists[SP_TAXMAN]);
 
   /* try to fill result from cache2 */
   if (!base_combination->all_entertainer.found_a_valid) {
@@ -847,7 +853,8 @@
       result->surplus[i] = base_combination->all_entertainer.surplus[i];
     }
 
-    p = get_secondary_stat(result->production[TRADE], result->scientists,
+    p = get_secondary_stat(result->production[TRADE],
+                          result->specialists[SP_SCIENTIST],
                           SP_SCIENTIST);
     if (!p->is_valid) {
       got_all = FALSE;
@@ -856,7 +863,8 @@
       result->surplus[SCIENCE] = p->surplus;
     }
 
-    p = get_secondary_stat(result->production[TRADE], result->taxmen,
+    p = get_secondary_stat(result->production[TRADE],
+                          result->specialists[SP_TAXMAN],
                           SP_TAXMAN);
     if (!p->is_valid) {
       got_all = FALSE;
@@ -865,7 +873,8 @@
       result->surplus[GOLD] = p->surplus;
     }
 
-    p = get_secondary_stat(result->production[TRADE], result->entertainers,
+    p = get_secondary_stat(result->production[TRADE],
+                          result->specialists[SP_ELVIS],
                           SP_ELVIS);
     if (!p->is_valid) {
       got_all = FALSE;
Index: common/aicore/cm.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.h,v
retrieving revision 1.4
diff -u -r1.4 cm.h
--- common/aicore/cm.h  13 Nov 2003 20:11:31 -0000      1.4
+++ common/aicore/cm.h  28 May 2004 02:15:47 -0000
@@ -57,7 +57,7 @@
   int surplus[NUM_STATS];
 
   bool worker_positions_used[CITY_MAP_SIZE][CITY_MAP_SIZE];
-  int entertainers, scientists, taxmen;
+  int specialists[SP_COUNT];
 };
 
 /*
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.247
diff -u -r1.247 cityturn.c
--- server/cityturn.c   27 May 2004 22:14:19 -0000      1.247
+++ server/cityturn.c   28 May 2004 02:15:48 -0000
@@ -151,6 +151,7 @@
   struct cm_parameter cmp;
   struct cm_result cmr;
   struct player *pplayer = city_owner(pcity);
+  int i;
 
   /* HACK: make sure everything is up-to-date before continuing.  This may
    * result in recursive calls to auto_arrange_workers, but it's better
@@ -256,9 +257,9 @@
       server_set_worker_city(pcity, x, y);
     }
   } city_map_checked_iterate_end;
-  pcity->specialists[SP_ELVIS] = cmr.entertainers;
-  pcity->specialists[SP_SCIENTIST] = cmr.scientists;
-  pcity->specialists[SP_TAXMAN] = cmr.taxmen;
+  for (i = 0; i < SP_COUNT; i++) {
+    pcity->specialists[i] = cmr.specialists[i];
+  }
 
   sanity_check_city(pcity);
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8856) specialists and the CM interface, Jason Short <=