Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] Re: (PR#8882) city_can_use_specialist
Home

[Freeciv-Dev] Re: (PR#8882) city_can_use_specialist

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] Re: (PR#8882) city_can_use_specialist
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 31 May 2004 12:47:54 -0700
Reply-to: rt@xxxxxxxxxxx

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

Jason Short wrote:

> - citydlg_common.c didn't use it, but should have.  For instance with 
> the current code if you can support elvises and taxmen the citydlg does 
> not let you switch between them.  Instead it keeps trying to switch from 
> elvises to scientists which fails.  The replacement code loops over the 
> specialists in order, skipping past ones that aren't available.  And it 
> doesn't send a change packet to the server if there is no change 
> possible (currently if you click on an elvis, the client sends a 
> change-to-scientist packet to the server which the server discards - I 
> think).

Oops.  New patch attached.

jason

? ferries
? data/flags
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.34
diff -u -r1.34 citydlg_common.c
--- client/citydlg_common.c     27 May 2004 22:14:18 -0000      1.34
+++ client/citydlg_common.c     31 May 2004 19:47:08 -0000
@@ -420,21 +420,28 @@
   switch (citizens[citizen_index]) {
   case CITIZEN_ELVIS:
     from = SP_ELVIS;
-    to = SP_SCIENTIST;
     break;
   case CITIZEN_SCIENTIST:
     from = SP_SCIENTIST;
-    to = SP_TAXMAN;
     break;
   case CITIZEN_TAXMAN:
     from = SP_TAXMAN;
-    to = SP_ELVIS;
     break;
   default:
     return;
   }
 
-  city_change_specialist(pcity, from, to);
+  /* Loop through all specialists in order until we find a usable one
+   * (or run out of choices). */
+  to = from;
+  assert(to >= 0 && to < SP_COUNT);
+  do {
+    to = (to + 1) % SP_COUNT;
+  } while (to != from && !city_can_use_specialist(pcity, to));
+
+  if (from != to) {
+    city_change_specialist(pcity, from, to);
+  }
 }
     
 /**************************************************************************
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.214
diff -u -r1.214 city.c
--- common/city.c       31 May 2004 16:38:54 -0000      1.214
+++ common/city.c       31 May 2004 19:47:09 -0000
@@ -461,6 +461,14 @@
   return TRUE;
 }
 
+/****************************************************************************
+  Returns TRUE iff if the given city can use this kind of specialist.
+****************************************************************************/
+bool city_can_use_specialist(struct city *pcity,
+                            enum specialist_type type)
+{
+  return pcity->size >= game.rgame.specialists[type].min_size;
+}
 
 /**************************************************************************
  Returns how many thousand citizen live in this city.
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.144
diff -u -r1.144 city.h
--- common/city.h       27 May 2004 22:14:18 -0000      1.144
+++ common/city.h       31 May 2004 19:47:09 -0000
@@ -362,6 +362,7 @@
 bool can_build_unit(struct city *pcity, Unit_Type_id id);
 bool can_build_unit_direct(struct city *pcity, Unit_Type_id id);
 bool can_eventually_build_unit(struct city *pcity, Unit_Type_id id);
+bool city_can_use_specialist(struct city *pcity, enum specialist_type type);
 bool city_got_building(struct city *pcity,  Impr_Type_id id); 
 bool city_affected_by_wonder(struct city *pcity, Impr_Type_id id);
 bool city_got_effect(struct city *pcity, Impr_Type_id id);
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.22
diff -u -r1.22 cm.c
--- common/aicore/cm.c  29 May 2004 20:34:31 -0000      1.22
+++ common/aicore/cm.c  31 May 2004 19:47:09 -0000
@@ -302,21 +302,6 @@
 }
 
 /****************************************************************************
- Returns TRUE iff if the given city can use this kind of specialists.
-*****************************************************************************/
-static bool can_use_specialist(struct city *pcity,
-                              enum specialist_type specialist_type)
-{
-  if (specialist_type == SP_ELVIS) {
-    return TRUE;
-  }
-  if (pcity->size >= 5) {
-    return TRUE;
-  }
-  return FALSE;
-}
-
-/****************************************************************************
  Returns TRUE iff is the result has the required surplus and the city
  isn't in disorder and the city is happy if this is required.
 *****************************************************************************/
@@ -1258,13 +1243,13 @@
 
     int i, items;
 
-    if (can_use_specialist(pcity, SP_SCIENTIST)) {
+    if (city_can_use_specialist(pcity, SP_SCIENTIST)) {
       base_combination->max_scientists = specialists;
     } else {
       base_combination->max_scientists = 0;
     }
 
-    if (can_use_specialist(pcity, SP_TAXMAN)) {
+    if (city_can_use_specialist(pcity, SP_TAXMAN)) {
       base_combination->max_taxmen = specialists;
     } else {
       base_combination->max_taxmen = 0;
Index: server/cityhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v
retrieving revision 1.131
diff -u -r1.131 cityhand.c
--- server/cityhand.c   31 May 2004 16:38:55 -0000      1.131
+++ server/cityhand.c   31 May 2004 19:47:10 -0000
@@ -74,7 +74,7 @@
 
   if (to < 0 || to >= SP_COUNT
       || from < 0 || from >= SP_COUNT
-      || pcity->size < game.rgame.specialists[to].min_size
+      || !city_can_use_specialist(pcity, to)
       || pcity->specialists[from] == 0) {
     freelog(LOG_ERROR, "Error in specialist change request from client.");
     return;

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] Re: (PR#8882) city_can_use_specialist, Jason Short <=