Complete.Org: Mailing Lists: Archives: freeciv-dev: December 2004:
[Freeciv-Dev] (PR#11318) determine the "best" specialist at runtime
Home

[Freeciv-Dev] (PR#11318) determine the "best" specialist at runtime

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#11318) determine the "best" specialist at runtime
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 3 Dec 2004 02:29:42 -0800
Reply-to: rt@xxxxxxxxxxx

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

If a city has the CITYO_EINSTEIN or CITYO_TAXMAN option set then 
scientists or taxmen are set as new citizens when possible.  This patch 
just changes that slightly so that the best science/gold specialist is 
determined at runtime.

Eventually these two options should go away.  New citizens should be 
placed by a shortened CM algorithm that will place just 1 citizen at a 
time.  The placement can thus respect the parameters given by the player 
for the server-side city CM.

jason

? diff
? server/generator/characteristics.c
? server/generator/characteristics.h
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.266
diff -u -r1.266 city.c
--- common/city.c       3 Dec 2004 09:39:39 -0000       1.266
+++ common/city.c       3 Dec 2004 10:27:21 -0000
@@ -2327,6 +2327,29 @@
   return count;
 }
 
+/****************************************************************************
+  Return the "best" specialist available in the game.  This specialist will
+  have the most of the given type of output.  If pcity is given then only
+  specialists usable by pcity will be considered.
+****************************************************************************/
+Specialist_type_id best_specialist(Output_type_id otype,
+                                  const struct city *pcity)
+{
+  int best = DEFAULT_SPECIALIST;
+  int val = game.rgame.specialists[DEFAULT_SPECIALIST].bonus[otype];;
+
+  specialist_type_iterate(i) {
+    if (!pcity || city_can_use_specialist(pcity, i)) {
+      if (game.rgame.specialists[i].bonus[otype] > val) {
+       best = i;
+       val = game.rgame.specialists[i].bonus[otype];
+      }
+    }
+  } specialist_type_iterate_end;
+
+  return best;
+}
+
 /**************************************************************************
   Return a string showing the number of specialists in the array.
 
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.174
diff -u -r1.174 city.h
--- common/city.h       3 Dec 2004 09:39:40 -0000       1.174
+++ common/city.h       3 Dec 2004 10:27:22 -0000
@@ -506,6 +506,8 @@
 int city_corruption(const struct city *pcity, int trade);
 int city_waste(const struct city *pcity, int shields);
 int city_specialists(const struct city *pcity);                 /* 
elv+tax+scie */
+Specialist_type_id best_specialist(Output_type_id otype,
+                                  const struct city *pcity);
 const char *specialists_string(const int *specialists);
 int get_city_tax_bonus(const struct city *pcity);
 int get_city_luxury_bonus(const struct city *pcity);
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.276
diff -u -r1.276 cityturn.c
--- server/cityturn.c   30 Nov 2004 08:37:03 -0000      1.276
+++ server/cityturn.c   3 Dec 2004 10:27:22 -0000
@@ -458,6 +458,8 @@
   bool have_square;
   int savings_pct = granary_savings(pcity), new_food;
   bool rapture_grow = city_rapture_grow(pcity); /* check before size increase! 
*/
+  int best_sci = best_specialist(O_SCIENCE, pcity);
+  int best_tax = best_specialist(O_GOLD, pcity);
 
   if (!city_can_grow_to(pcity, pcity->size + 1)) { /* need improvement */
     if (get_current_construction_bonus(pcity, EFT_SIZE_ADJ) > 0) {
@@ -496,19 +498,14 @@
       have_square = TRUE;
     }
   } city_map_iterate_end;
-  if (((pcity->surplus[O_FOOD] >= 2) || !have_square)
-      && pcity->size >= 5
-      && (is_city_option_set(pcity, CITYO_NEW_EINSTEIN)
-         || is_city_option_set(pcity, CITYO_NEW_TAXMAN))) {
-
-    if (is_city_option_set(pcity, CITYO_NEW_EINSTEIN)) {
-      pcity->specialists[SP_SCIENTIST]++;
-    } else { /* now pcity->city_options & (1<<CITYO_NEW_TAXMAN) is true */
-      pcity->specialists[SP_TAXMAN]++;
-    }
-
+  if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
+      && is_city_option_set(pcity, CITYO_NEW_EINSTEIN)) {
+    pcity->specialists[best_sci]++;
+  } else if ((pcity->surplus[O_FOOD] >= 2 || !have_square)
+            && is_city_option_set(pcity, CITYO_NEW_TAXMAN)) {
+    pcity->specialists[best_tax]++;
   } else {
-    pcity->specialists[SP_TAXMAN]++; /* or else city is !sane */
+    pcity->specialists[DEFAULT_SPECIALIST]++; /* or else city is !sane */
     auto_arrange_workers(pcity);
   }
 

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#11318) determine the "best" specialist at runtime, Jason Short <=