Complete.Org: Mailing Lists: Archives: freeciv-dev: May 2004:
[Freeciv-Dev] (PR#8854) remove some specialist references
Home

[Freeciv-Dev] (PR#8854) remove some specialist references

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#8854) remove some specialist references
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 27 May 2004 17:52:49 -0700
Reply-to: rt@xxxxxxxxxxx

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

This patch removes some references to the specialist enum values.

These are the "easy" cases, where all the other infrastructure is in 
place and it's easier to use a loop than direct references.

jason

? convert.sh
? diff
? ferries
? flags
? output
? test.log
? client/output
? data/flags
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.371
diff -u -r1.371 packhand.c
--- client/packhand.c   27 May 2004 22:14:18 -0000      1.371
+++ client/packhand.c   28 May 2004 00:50:04 -0000
@@ -435,9 +435,9 @@
     pcity->ppl_unhappy[i] = packet->ppl_unhappy[i];
     pcity->ppl_angry[i] = packet->ppl_angry[i];
   }
-  pcity->specialists[SP_ELVIS] = packet->specialists[SP_ELVIS];
-  pcity->specialists[SP_SCIENTIST] = packet->specialists[SP_SCIENTIST];
-  pcity->specialists[SP_TAXMAN] = packet->specialists[SP_TAXMAN];
+  for (i = 0; i < SP_COUNT; i++) {
+    pcity->specialists[i] = packet->specialists[i];
+  }
 
   pcity->city_options = packet->city_options;
 
@@ -711,9 +711,9 @@
     int i;
     int x, y;
 
-    pcity->specialists[SP_ELVIS] = 0;
-    pcity->specialists[SP_SCIENTIST] = 0;
-    pcity->specialists[SP_TAXMAN] = 0;
+    for (i = 0; i < SP_COUNT; i++) {
+      pcity->specialists[i] = 0;
+    }
     for (i = 0; i < NUM_TRADEROUTES; i++) {
       pcity->trade[i] = 0;
       pcity->trade_value[i] = 0;
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.212
diff -u -r1.212 city.c
--- common/city.c       27 May 2004 22:14:18 -0000      1.212
+++ common/city.c       28 May 2004 00:50:05 -0000
@@ -2419,9 +2419,13 @@
 **************************************************************************/
 int city_specialists(struct city *pcity)
 {
-  return (pcity->specialists[SP_ELVIS]
-         + pcity->specialists[SP_SCIENTIST]
-         + pcity->specialists[SP_TAXMAN]);
+  int count = 0, i;
+
+  for (i = 0; i < SP_COUNT; i++) {
+    count += pcity->specialists[i];
+  }
+
+  return count;
 }
 
 /**************************************************************************
@@ -2571,8 +2575,10 @@
   pcity->y = y;
   sz_strlcpy(pcity->name, name);
   pcity->size = 1;
+  for (i = 0; i < SP_COUNT; i++) {
+    pcity->specialists[i] = 0;
+  }
   pcity->specialists[SP_ELVIS] = 1;
-  pcity->specialists[SP_SCIENTIST] = pcity->specialists[SP_TAXMAN] = 0;
   pcity->ppl_happy[4] = 0;
   pcity->ppl_content[4] = 1;
   pcity->ppl_unhappy[4] = 0;
Index: server/cityhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v
retrieving revision 1.129
diff -u -r1.129 cityhand.c
--- server/cityhand.c   27 May 2004 22:14:19 -0000      1.129
+++ server/cityhand.c   28 May 2004 00:50:05 -0000
@@ -72,37 +72,18 @@
     return;
   }
 
-  if ((to == SP_ELVIS && pcity->size < game.rgame.min_size_elvis)
+  if (to < 0 || to >= SP_COUNT
+      || from < 0 || from >= SP_COUNT
+      || (to == SP_ELVIS && pcity->size < game.rgame.min_size_elvis)
       || (to == SP_TAXMAN && pcity->size < game.rgame.min_size_taxman)
       || (to == SP_SCIENTIST && pcity->size < game.rgame.min_size_scientist)
-      || (from == SP_ELVIS && pcity->specialists[SP_ELVIS] == 0)
-      || (from == SP_TAXMAN && pcity->specialists[SP_TAXMAN] == 0)
-      || (from == SP_SCIENTIST && pcity->specialists[SP_SCIENTIST] == 0)
-      || (to != SP_ELVIS && to != SP_TAXMAN && to != SP_SCIENTIST)
-      || (from != SP_ELVIS && from != SP_TAXMAN && from != SP_SCIENTIST)) {
+      || pcity->specialists[from] == 0) {
     freelog(LOG_ERROR, "Error in specialist change request from client.");
     return;
   }
 
-  if (from == SP_ELVIS) {
-    pcity->specialists[SP_ELVIS]--;
-  } else if (from == SP_TAXMAN) {
-    pcity->specialists[SP_TAXMAN]--;
-  } else if (from == SP_SCIENTIST) {
-    pcity->specialists[SP_SCIENTIST]--;
-  }
-  switch (to) {
-  case SP_TAXMAN:
-    pcity->specialists[SP_TAXMAN]++;
-    break;
-  case SP_SCIENTIST:
-    pcity->specialists[SP_SCIENTIST]++;
-    break;
-  case SP_ELVIS:
-  default:
-    pcity->specialists[SP_ELVIS]++;
-    break;
-  }
+  pcity->specialists[from]--;
+  pcity->specialists[to]++;
 
   sanity_check_city(pcity);
   city_refresh(pcity);
@@ -144,6 +125,7 @@
                             int worker_x, int worker_y)
 {
   struct city *pcity = player_find_city_by_id(pplayer, city_id);
+  int i;
 
   if (!is_valid_city_coords(worker_x, worker_y)) {
     freelog(LOG_ERROR, "invalid city coords %d,%d in package",
@@ -167,12 +149,13 @@
 
   server_set_worker_city(pcity, worker_x, worker_y);
 
-  if (pcity->specialists[SP_ELVIS] > 0) 
-    pcity->specialists[SP_ELVIS]--;
-  else if (pcity->specialists[SP_SCIENTIST] > 0) 
-    pcity->specialists[SP_SCIENTIST]--;
-  else 
-    pcity->specialists[SP_TAXMAN]--;
+  for (i = 0; i < SP_COUNT; i++) {
+    if (pcity->specialists[i] > 0) {
+      pcity->specialists[i]--;
+      break;
+    }
+  }
+  assert(i < SP_COUNT);
 
   sanity_check_city(pcity);
   city_refresh(pcity);
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 00:50:06 -0000
@@ -401,15 +401,14 @@
 
   /* First try to kill off the specialists */
   while (pop_loss > 0 && city_specialists(pcity) > 0) {
-    if (pcity->specialists[SP_TAXMAN] > 0) {
-      pcity->specialists[SP_TAXMAN]--;
-    } else if (pcity->specialists[SP_SCIENTIST] > 0) {
-      pcity->specialists[SP_SCIENTIST]--;
-    } else {
-      assert(pcity->specialists[SP_ELVIS] > 0);
-      pcity->specialists[SP_ELVIS]--; 
+    /* This loop could be more efficient. */
+    for (i = SP_COUNT - 1; i >= 0; i--) {
+      if (pcity->specialists[i] > 0) {
+       pcity->specialists[i]--;
+       pop_loss--;
+       break;
+      }
     }
-    pop_loss--;
   }
 
   /* we consumed all the pop_loss in specialists */

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#8854) remove some specialist references, Jason Short <=