[Freeciv-Dev] (PR#8795) change specialists into an array
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8795 >
The next step toward configurable specialists is to remove of the
explicit references to types of specialists.
This patch takes a step or two in that direction. The ppl_elvis,
ppl_scientist, ppl_taxman fields of the city structure and city packet
are replaced with an array. The specialist enum is used to index into
this array.
In most places ppl_elvis is just replaced by specialists[SP_ELVIS].
However in a few places the explicit mention can easily be removed. For
instance instead of
ppl_elvis = ppl_scientist = ppl_taxman = 0;
it's easy to use a loop.
I also introduced a SP_DEFAULT (== SP_ELVIS) value. When an arbitrary
type of specialist must be made it should be SP_DEFAULT. Eventually
this value should be read from the ruleset.
I fixed what I believe to be a bug, replacing SP_TAXMAN with SP_DEFAULT
in one location.
Maybe this patch does too much? It would be easy enough to make a
simpler (but just as large) patch that left out SP_DEFAULT and didn't
change the logic anywhere. The packet code could be changed at the same
time, or left for later. Then we could go through and fix individual
places on a case-by-case basis.
gui-sdl does make a few references to the citizens. I didn't fix this.
I suspect that this is an error and gui-sdl should be using a
citydlg_common function instead.
-jason
? eff
? flags
? data/flags
Index: ai/advdomestic.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/advdomestic.c,v
retrieving revision 1.107
diff -u -r1.107 advdomestic.c
--- ai/advdomestic.c 19 May 2004 14:40:15 -0000 1.107
+++ ai/advdomestic.c 21 May 2004 20:20:24 -0000
@@ -212,7 +212,7 @@
/* How much one rebeling citizen counts - 16 is debatable value */
#define SADVAL 16
/* Number of elvises in the city */
- int elvis = pcity->ppl_elvis;
+ int elvis = pcity->specialists[SP_ELVIS];
/* Raw number of unhappy people */
int sad = pcity->ppl_unhappy[0];
/* Final number of content people */
@@ -247,8 +247,8 @@
while (happy > 0) { happy--; value += SADVAL; }
freelog(LOG_DEBUG, "%s: %d elvis %d sad %d content %d size %d val",
- pcity->name, pcity->ppl_elvis, pcity->ppl_unhappy[4],
- pcity->ppl_content[4], pcity->size, value);
+ pcity->name, pcity->specialists[SP_ELVIS],
+ pcity->ppl_unhappy[4], pcity->ppl_content[4], pcity->size, value);
return value;
#undef SADVAL
@@ -426,7 +426,8 @@
sci = 0;
}
- est_food = 2 * pcity->ppl_scientist + 2 * pcity->ppl_taxman
+ est_food = 2 * pcity->specialists[SP_SCIENTIST]
+ + 2 * pcity->specialists[SP_TAXMAN]
+ pcity->food_surplus;
prod =
(pcity->shield_prod * SHIELD_WEIGHTING * 100) / city_shield_bonus(pcity);
@@ -444,7 +445,8 @@
grana = food_weighting(grana + 1);
hunger = 1;
j = (pcity->size * 2) + settler_eats(pcity) - pcity->food_prod;
- if (j >= 0 && pcity->ppl_scientist <= 0 && pcity->ppl_taxman <= 0)
+ if (j >= 0 && pcity->specialists[SP_SCIENTIST] <= 0
+ && pcity->specialists[SP_TAXMAN] <= 0)
hunger += j+1;
/* rationale: barracks effectively doubles prod if building military units */
@@ -529,7 +531,7 @@
case B_MARKETPLACE:
case B_BANK:
case B_STOCK:
- values[id] = (tax + 3*pcity->ppl_taxman + pcity->ppl_elvis*wwtv)/2;
+ values[id] = (tax + 3*pcity->specialists[SP_TAXMAN] +
pcity->specialists[SP_ELVIS]*wwtv)/2;
break;
case B_SUPERHIGHWAYS:
values[id] = road_trade(pcity) * t;
@@ -952,8 +954,8 @@
/* Food surplus assuming that workers and elvii are already accounted for
* and properly balanced. */
int est_food = pcity->food_surplus
- + 2 * pcity->ppl_scientist
- + 2 * pcity->ppl_taxman;
+ + 2 * pcity->specialists[SP_SCIENTIST]
+ + 2 * pcity->specialists[SP_TAXMAN];
init_choice(choice);
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.151
diff -u -r1.151 aicity.c
--- ai/aicity.c 19 May 2004 14:40:15 -0000 1.151
+++ ai/aicity.c 21 May 2004 20:20:25 -0000
@@ -671,7 +671,7 @@
is_valid = map_to_city_map(&city_map_x, &city_map_y, acity, x, y);
assert(is_valid);
server_remove_worker_city(acity, city_map_x, city_map_y);
- acity->ppl_elvis++;
+ acity->specialists[SP_DEFAULT]++;
if (!city_list_find_id(&minilist, acity->id)) {
city_list_insert(&minilist, acity);
}
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.33
diff -u -r1.33 citydlg_common.c
--- client/citydlg_common.c 12 May 2004 03:21:00 -0000 1.33
+++ client/citydlg_common.c 21 May 2004 20:20:25 -0000
@@ -374,7 +374,7 @@
void get_city_citizen_types(struct city *pcity, int index,
enum citizen_type *citizens)
{
- int i = 0, n;
+ int i = 0, sp, n;
assert(index >= 0 && index < 5);
for (n = 0; n < pcity->ppl_happy[index]; n++, i++) {
@@ -390,14 +390,10 @@
citizens[i] = CITIZEN_ANGRY;
}
- for (n = 0; n < pcity->ppl_elvis; n++, i++) {
- citizens[i] = CITIZEN_ELVIS;
- }
- for (n = 0; n < pcity->ppl_scientist; n++, i++) {
- citizens[i] = CITIZEN_SCIENTIST;
- }
- for (n = 0; n < pcity->ppl_taxman; n++, i++) {
- citizens[i] = CITIZEN_TAXMAN;
+ for (sp = SP_FIRST; sp <= SP_LAST; sp++) {
+ for (n = 0; n < pcity->specialists[sp]; n++, i++) {
+ citizens[i] = sp;
+ }
}
assert(i == pcity->size);
Index: client/cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.32
diff -u -r1.32 cityrepdata.c
--- client/cityrepdata.c 25 Feb 2004 20:09:50 -0000 1.32
+++ client/cityrepdata.c 21 May 2004 20:20:25 -0000
@@ -116,30 +116,30 @@
{
static char buf[32];
my_snprintf(buf, sizeof(buf), "%d/%d/%d",
- pcity->ppl_elvis,
- pcity->ppl_scientist,
- pcity->ppl_taxman);
+ pcity->specialists[SP_ELVIS],
+ pcity->specialists[SP_SCIENTIST],
+ pcity->specialists[SP_TAXMAN]);
return buf;
}
static char *cr_entry_entertainers(struct city *pcity)
{
static char buf[8];
- my_snprintf(buf, sizeof(buf), "%2d", pcity->ppl_elvis);
+ my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[SP_ELVIS]);
return buf;
}
static char *cr_entry_scientists(struct city *pcity)
{
static char buf[8];
- my_snprintf(buf, sizeof(buf), "%2d", pcity->ppl_scientist);
+ my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[SP_SCIENTIST]);
return buf;
}
static char *cr_entry_taxmen(struct city *pcity)
{
static char buf[8];
- my_snprintf(buf, sizeof(buf), "%2d", pcity->ppl_taxman);
+ my_snprintf(buf, sizeof(buf), "%2d", pcity->specialists[SP_TAXMAN]);
return buf;
}
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.369
diff -u -r1.369 packhand.c
--- client/packhand.c 21 May 2004 19:03:43 -0000 1.369
+++ client/packhand.c 21 May 2004 20:20:26 -0000
@@ -435,9 +435,10 @@
pcity->ppl_unhappy[i]=packet->ppl_unhappy[i];
pcity->ppl_angry[i] = packet->ppl_angry[i];
}
- pcity->ppl_elvis=packet->ppl_elvis;
- pcity->ppl_scientist=packet->ppl_scientist;
- pcity->ppl_taxman=packet->ppl_taxman;
+ assert(SP_FIRST == 0);
+ for (i = SP_FIRST; i <= SP_LAST; i++) {
+ pcity->specialists[i] = packet->specialists[i];
+ }
pcity->city_options=packet->city_options;
@@ -708,9 +709,9 @@
int i;
int x, y;
- pcity->ppl_elvis = 0;
- pcity->ppl_scientist = 0;
- pcity->ppl_taxman = 0;
+ for (i = SP_FIRST; i <= SP_LAST; i++) {
+ pcity->specialists[i] = 0;
+ }
for (i = 0; i < NUM_TRADEROUTES; i++) {
pcity->trade[i]=0;
pcity->trade_value[i] = 0;
Index: client/agents/cma_core.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_core.c,v
retrieving revision 1.51
diff -u -r1.51 cma_core.c
--- client/agents/cma_core.c 28 Nov 2003 17:37:19 -0000 1.51
+++ client/agents/cma_core.c 21 May 2004 20:20:26 -0000
@@ -158,8 +158,8 @@
pcity->name, pcity->id);
freelog(LOG_NORMAL,
" size=%d, entertainers=%d, scientists=%d, taxmen=%d",
- pcity->size, pcity->ppl_elvis, pcity->ppl_scientist,
- pcity->ppl_taxman);
+ pcity->size, pcity->specialists[SP_ELVIS],
+ pcity->specialists[SP_SCIENTIST], pcity->specialists[SP_TAXMAN]);
freelog(LOG_NORMAL, " workers at:");
my_city_map_iterate(pcity, x, y) {
if (pcity->city_map[x][y] == C_TILE_WORKER) {
@@ -281,9 +281,9 @@
}
} my_city_map_iterate_end;
- result->entertainers = pcity->ppl_elvis;
- result->scientists = pcity->ppl_scientist;
- result->taxmen = pcity->ppl_taxman;
+ result->entertainers = pcity->specialists[SP_ELVIS];
+ result->scientists = pcity->specialists[SP_SCIENTIST];
+ result->taxmen = pcity->specialists[SP_TAXMAN];
assert(worker + result->entertainers + result->scientists +
result->taxmen == pcity->size);
@@ -370,7 +370,8 @@
} my_city_map_iterate_end;
/* Change surplus scientists to entertainers */
- for (i = 0; i < pcity->ppl_scientist - result->scientists; i++) {
+ 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;
@@ -378,7 +379,7 @@
}
/* Change surplus taxmen to entertainers */
- for (i = 0; i < pcity->ppl_taxman - result->taxmen; i++) {
+ 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;
@@ -400,7 +401,8 @@
} my_city_map_iterate_end;
/* Set scientists. */
- for (i = 0; i < result->scientists - pcity->ppl_scientist; i++) {
+ 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;
@@ -408,7 +410,7 @@
}
/* Set taxmen. */
- for (i = 0; i < result->taxmen - pcity->ppl_taxman; i++) {
+ 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;
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.211
diff -u -r1.211 city.c
--- common/city.c 21 May 2004 19:03:43 -0000 1.211
+++ common/city.c 21 May 2004 20:20:26 -0000
@@ -1821,10 +1821,13 @@
pcity->tax_total = tax;
pcity->luxury_total = lux;
- pcity->luxury_total += (pcity->ppl_elvis * game.rgame.base_elvis);
- pcity->science_total += (pcity->ppl_scientist * game.rgame.base_scientist);
- pcity->tax_total += (pcity->ppl_taxman * game.rgame.base_taxman)
- + get_city_tithes_bonus(pcity);
+ pcity->luxury_total
+ += (pcity->specialists[SP_ELVIS] * game.rgame.base_elvis);
+ pcity->science_total
+ += (pcity->specialists[SP_SCIENTIST] * game.rgame.base_scientist);
+ pcity->tax_total
+ += ((pcity->specialists[SP_TAXMAN] * game.rgame.base_taxman)
+ + get_city_tithes_bonus(pcity));
}
/**************************************************************************
@@ -2416,7 +2419,12 @@
**************************************************************************/
int city_specialists(struct city *pcity)
{
- return (pcity->ppl_elvis + pcity->ppl_scientist + pcity->ppl_taxman);
+ int count = 0, i;
+
+ for (i = SP_FIRST; i <= SP_LAST; i++) {
+ count += pcity->specialists[i];
+ }
+ return count;
}
/**************************************************************************
@@ -2566,8 +2574,14 @@
pcity->y = y;
sz_strlcpy(pcity->name, name);
pcity->size = 1;
- pcity->ppl_elvis = 1;
- pcity->ppl_scientist = pcity->ppl_taxman=0;
+ for (i = SP_FIRST; i <= SP_LAST; i++) {
+ if (i == SP_DEFAULT) {
+ /* The initial citizens aren't workers; they have to go somewhere. */
+ pcity->specialists[i] = pcity->size;
+ } else {
+ pcity->specialists[i] = 0;
+ }
+ }
pcity->ppl_happy[4] = 0;
pcity->ppl_content[4] = 1;
pcity->ppl_unhappy[4] = 0;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.143
diff -u -r1.143 city.h
--- common/city.h 20 May 2004 21:38:53 -0000 1.143
+++ common/city.h 21 May 2004 20:20:26 -0000
@@ -25,9 +25,13 @@
TYPE_UNIT, TYPE_NORMAL_IMPROVEMENT, TYPE_WONDER
};
+/* Changing these breaks network and savegame compatability. */
enum specialist_type {
- SP_ELVIS, SP_SCIENTIST, SP_TAXMAN
+ SP_ELVIS, SP_SCIENTIST, SP_TAXMAN, SP_COUNT
};
+#define SP_FIRST SP_ELVIS
+#define SP_LAST SP_TAXMAN
+#define SP_DEFAULT SP_ELVIS
enum city_tile_type {
C_TILE_EMPTY, C_TILE_WORKER, C_TILE_UNAVAILABLE
@@ -231,7 +235,7 @@
int ppl_happy[5], ppl_content[5], ppl_unhappy[5], ppl_angry[5];
/* Specialists */
- int ppl_elvis, ppl_scientist, ppl_taxman;
+ int specialists[SP_COUNT];
/* trade routes */
int trade[NUM_TRADEROUTES], trade_value[NUM_TRADEROUTES];
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.23
diff -u -r1.23 packets.def
--- common/packets.def 21 May 2004 19:03:43 -0000 1.23
+++ common/packets.def 21 May 2004 20:20:37 -0000
@@ -381,7 +381,7 @@
UINT8 ppl_happy[5], ppl_content[5], ppl_unhappy[5], ppl_angry[5];
- UINT8 ppl_elvis, ppl_scientist, ppl_taxman;
+ UINT8 specialists[SP_COUNT];
UINT16 food_prod, shield_prod, trade_prod;
SINT16 food_surplus, shield_surplus, tile_trade;
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.20
diff -u -r1.20 cm.c
--- common/aicore/cm.c 26 Feb 2004 04:05:10 -0000 1.20
+++ common/aicore/cm.c 21 May 2004 20:20:38 -0000
@@ -356,8 +356,8 @@
pcity->name, pcity->id);
freelog(LOG_NORMAL,
" size=%d, entertainers=%d, scientists=%d, taxmen=%d",
- pcity->size, pcity->ppl_elvis, pcity->ppl_scientist,
- pcity->ppl_taxman);
+ pcity->size, pcity->specialists[SP_ELVIS],
+ pcity->specialists[SP_SCIENTIST], pcity->specialists[SP_TAXMAN]);
freelog(LOG_NORMAL, " workers at:");
my_city_map_iterate(pcity, x, y) {
if (pcity->city_map[x][y] == C_TILE_WORKER) {
@@ -638,9 +638,9 @@
}
} my_city_map_iterate_end;
- pcity->ppl_elvis = result->entertainers;
- pcity->ppl_scientist = result->scientists;
- pcity->ppl_taxman = result->taxmen;
+ pcity->specialists[SP_ELVIS] = result->entertainers;
+ pcity->specialists[SP_SCIENTIST] = result->scientists;
+ pcity->specialists[SP_TAXMAN] = result->taxmen;
/* Do a local recalculation of the city */
generic_city_refresh(pcity, FALSE, NULL);
Index: server/cityhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityhand.c,v
retrieving revision 1.128
diff -u -r1.128 cityhand.c
--- server/cityhand.c 21 May 2004 19:03:44 -0000 1.128
+++ server/cityhand.c 21 May 2004 20:20:38 -0000
@@ -72,37 +72,18 @@
return;
}
- if ((to == SP_ELVIS && pcity->size < game.rgame.min_size_elvis)
+ if (to < SP_FIRST || to > SP_LAST || from < SP_FIRST || from > SP_LAST
+ || pcity->specialists[from] <= 0
+ || (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->ppl_elvis == 0)
- || (from == SP_TAXMAN && pcity->ppl_taxman == 0)
- || (from == SP_SCIENTIST && pcity->ppl_scientist == 0)
- || (to != SP_ELVIS && to != SP_TAXMAN && to != SP_SCIENTIST)
- || (from != SP_ELVIS && from != SP_TAXMAN && from != SP_SCIENTIST)) {
+ || (to == SP_SCIENTIST
+ && pcity->size < game.rgame.min_size_scientist)) {
freelog(LOG_ERROR, "Error in specialist change request from client.");
return;
}
- if (from == SP_ELVIS) {
- pcity->ppl_elvis--;
- } else if (from == SP_TAXMAN) {
- pcity->ppl_taxman--;
- } else if (from == SP_SCIENTIST) {
- pcity->ppl_scientist--;
- }
- switch (to) {
- case SP_TAXMAN:
- pcity->ppl_taxman++;
- break;
- case SP_SCIENTIST:
- pcity->ppl_scientist++;
- break;
- case SP_ELVIS:
- default:
- pcity->ppl_elvis++;
- break;
- }
+ pcity->specialists[from]--;
+ pcity->specialists[to]++;
sanity_check_city(pcity);
city_refresh(pcity);
@@ -127,7 +108,7 @@
}
if (is_worker_here(pcity, worker_x, worker_y)) {
server_remove_worker_city(pcity, worker_x, worker_y);
- pcity->ppl_elvis++;
+ pcity->specialists[SP_DEFAULT]++;
city_refresh(pcity);
sync_cities();
} else {
@@ -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->ppl_elvis > 0)
- pcity->ppl_elvis--;
- else if (pcity->ppl_scientist > 0)
- pcity->ppl_scientist--;
- else
- pcity->ppl_taxman--;
+ for (i = SP_FIRST; i <= SP_LAST; i++) {
+ if (pcity->specialists[i] > 0) {
+ pcity->specialists[i]--;
+ break;
+ }
+ }
+ assert(i <= SP_LAST);
sanity_check_city(pcity);
city_refresh(pcity);
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.258
diff -u -r1.258 citytools.c
--- server/citytools.c 11 May 2004 17:59:34 -0000 1.258
+++ server/citytools.c 21 May 2004 20:20:39 -0000
@@ -1687,9 +1687,10 @@
packet->ppl_unhappy[i]=pcity->ppl_unhappy[i];
packet->ppl_angry[i]=pcity->ppl_angry[i];
}
- packet->ppl_elvis=pcity->ppl_elvis;
- packet->ppl_scientist=pcity->ppl_scientist;
- packet->ppl_taxman=pcity->ppl_taxman;
+ assert(SP_FIRST == 0);
+ for (i = SP_FIRST; i <= SP_LAST; i++) {
+ packet->specialists[i] = pcity->specialists[i];
+ }
for (i = 0; i < NUM_TRADEROUTES; i++) {
packet->trade[i]=pcity->trade[i];
packet->trade_value[i]=pcity->trade_value[i];
@@ -2148,7 +2149,7 @@
case C_TILE_WORKER:
if (!is_available) {
server_set_tile_city(pcity, city_x, city_y, C_TILE_UNAVAILABLE);
- pcity->ppl_elvis++; /* keep city sanity */
+ pcity->specialists[SP_DEFAULT]++; /* keep city sanity */
auto_arrange_workers(pcity); /* will place the displaced */
city_refresh(pcity);
send_city_info(NULL, pcity);
Index: server/cityturn.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/cityturn.c,v
retrieving revision 1.246
diff -u -r1.246 cityturn.c
--- server/cityturn.c 21 Apr 2004 18:28:28 -0000 1.246
+++ server/cityturn.c 21 May 2004 20:20:39 -0000
@@ -256,9 +256,9 @@
server_set_worker_city(pcity, x, y);
}
} city_map_checked_iterate_end;
- pcity->ppl_elvis = cmr.entertainers;
- pcity->ppl_scientist = cmr.scientists;
- pcity->ppl_taxman = cmr.taxmen;
+ pcity->specialists[SP_ELVIS] = cmr.entertainers;
+ pcity->specialists[SP_SCIENTIST] = cmr.scientists;
+ pcity->specialists[SP_TAXMAN] = cmr.taxmen;
sanity_check_city(pcity);
@@ -401,13 +401,15 @@
/* First try to kill off the specialists */
while (pop_loss > 0 && city_specialists(pcity) > 0) {
- if (pcity->ppl_taxman > 0) {
- pcity->ppl_taxman--;
- } else if (pcity->ppl_scientist > 0) {
- pcity->ppl_scientist--;
- } else {
- assert(pcity->ppl_elvis > 0);
- pcity->ppl_elvis--;
+ int i;
+
+ /* Specialists are killed off starting with the last type. This
+ * preserves old behavior which would kill off scientists before
+ * elvises, etc. */
+ for (i = SP_LAST; i >= SP_FIRST; i--) {
+ if (pcity->specialists[i] > 0) {
+ pcity->specialists[i]--;
+ }
}
pop_loss--;
}
@@ -504,18 +506,18 @@
have_square = TRUE;
}
} city_map_iterate_end;
- if (((pcity->food_surplus >= 2) || !have_square) && pcity->size >= 5 &&
+ if (((pcity->food_surplus >= 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->ppl_scientist++;
+ pcity->specialists[SP_SCIENTIST]++;
} else { /* now pcity->city_options & (1<<CITYO_NEW_TAXMAN) is true */
- pcity->ppl_taxman++;
+ pcity->specialists[SP_TAXMAN]++;
}
} else {
- pcity->ppl_taxman++; /* or else city is !sane */
+ pcity->specialists[SP_DEFAULT]++; /* or else city is !sane */
auto_arrange_workers(pcity);
}
Index: server/sanitycheck.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/sanitycheck.c,v
retrieving revision 1.40
diff -u -r1.40 sanitycheck.c
--- server/sanitycheck.c 25 Jan 2004 08:04:53 -0000 1.40
+++ server/sanitycheck.c 21 May 2004 20:20:39 -0000
@@ -228,8 +228,9 @@
} city_map_iterate_end;
if (workers + city_specialists(pcity) != pcity->size + 1) {
die("%s is illegal (size%d w%d e%d t%d s%d) in %s line %d",
- pcity->name, pcity->size, workers, pcity->ppl_elvis,
- pcity->ppl_taxman, pcity->ppl_scientist, file, line);
+ pcity->name, pcity->size, workers, pcity->specialists[SP_ELVIS],
+ pcity->specialists[SP_TAXMAN], pcity->specialists[SP_SCIENTIST],
+ file, line);
}
}
Index: server/savegame.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/savegame.c,v
retrieving revision 1.152
diff -u -r1.152 savegame.c
--- server/savegame.c 19 May 2004 20:11:17 -0000 1.152
+++ server/savegame.c 21 May 2004 20:20:40 -0000
@@ -933,11 +933,12 @@
pcity->steal=secfile_lookup_int(file, "player%d.c%d.steal", plrno, i);
- pcity->ppl_elvis=secfile_lookup_int(file, "player%d.c%d.nelvis", plrno, i);
- pcity->ppl_scientist=secfile_lookup_int(file,
- "player%d.c%d.nscientist", plrno, i);
- pcity->ppl_taxman=secfile_lookup_int(file, "player%d.c%d.ntaxman",
- plrno, i);
+ pcity->specialists[SP_ELVIS]
+ = secfile_lookup_int(file, "player%d.c%d.nelvis", plrno, i);
+ pcity->specialists[SP_SCIENTIST]
+ = secfile_lookup_int(file, "player%d.c%d.nscientist", plrno, i);
+ pcity->specialists[SP_TAXMAN]
+ = secfile_lookup_int(file, "player%d.c%d.ntaxman", plrno, i);
for (j = 0; j < NUM_TRADEROUTES; j++)
pcity->trade[j]=secfile_lookup_int(file, "player%d.c%d.traderoute%d",
@@ -1045,7 +1046,7 @@
/* oops, inconsistent savegame; minimal fix: */
freelog(LOG_VERBOSE, "Inconsistent worked for %s (%d,%d), "
"converting to elvis", pcity->name, x, y);
- pcity->ppl_elvis++;
+ pcity->specialists[SP_DEFAULT]++;
set_worker_city(pcity, x, y, C_TILE_UNAVAILABLE);
} else {
set_worker_city(pcity, x, y, C_TILE_WORKER);
@@ -1685,10 +1686,13 @@
plrno, i);
secfile_insert_int(file, pcity->size, "player%d.c%d.size", plrno, i);
secfile_insert_int(file, pcity->steal, "player%d.c%d.steal", plrno, i);
- secfile_insert_int(file, pcity->ppl_elvis, "player%d.c%d.nelvis", plrno,
i);
- secfile_insert_int(file, pcity->ppl_scientist, "player%d.c%d.nscientist",
+ secfile_insert_int(file, pcity->specialists[SP_ELVIS],
+ "player%d.c%d.nelvis", plrno, i);
+ secfile_insert_int(file, pcity->specialists[SP_SCIENTIST],
+ "player%d.c%d.nscientist",
plrno, i);
- secfile_insert_int(file, pcity->ppl_taxman, "player%d.c%d.ntaxman", plrno,
i);
+ secfile_insert_int(file, pcity->specialists[SP_TAXMAN],
+ "player%d.c%d.ntaxman", plrno, i);
for (j = 0; j < NUM_TRADEROUTES; j++)
secfile_insert_int(file, pcity->trade[j], "player%d.c%d.traderoute%d",
@@ -1934,7 +1938,7 @@
int map_x, map_y;
bool is_real;
- pcity->ppl_elvis++;
+ pcity->specialists[SP_DEFAULT]++;
set_worker_city(pcity, x, y, C_TILE_UNAVAILABLE);
freelog(LOG_DEBUG, "Worked tile was unavailable!");
Index: server/score.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/score.c,v
retrieving revision 1.4
diff -u -r1.4 score.c
--- server/score.c 24 Oct 2003 00:23:33 -0000 1.4
+++ server/score.c 21 May 2004 20:20:40 -0000
@@ -412,9 +412,9 @@
pplayer->score.content += pcity->ppl_content[4];
pplayer->score.unhappy += pcity->ppl_unhappy[4];
pplayer->score.angry += pcity->ppl_angry[4];
- pplayer->score.taxmen += pcity->ppl_taxman;
- pplayer->score.scientists += pcity->ppl_scientist;
- pplayer->score.elvis += pcity->ppl_elvis;
+ pplayer->score.taxmen += pcity->specialists[SP_TAXMAN];
+ pplayer->score.scientists += pcity->specialists[SP_SCIENTIST];
+ pplayer->score.elvis += pcity->specialists[SP_ELVIS];
pplayer->score.population += city_population(pcity);
pplayer->score.cities++;
pplayer->score.pollution += pcity->pollution;
Index: server/unithand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/unithand.c,v
retrieving revision 1.298
diff -u -r1.298 unithand.c
--- server/unithand.c 13 May 2004 16:38:19 -0000 1.298
+++ server/unithand.c 21 May 2004 20:20:40 -0000
@@ -479,7 +479,7 @@
assert(unit_pop_value(punit->type) > 0);
pcity->size += unit_pop_value(punit->type);
/* Make the new people something, otherwise city fails the checks */
- pcity->ppl_taxman += unit_pop_value(punit->type);
+ pcity->specialists[SP_DEFAULT] += unit_pop_value(punit->type);
auto_arrange_workers(pcity);
wipe_unit(punit);
send_city_info(NULL, pcity);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8795) change specialists into an array,
Jason Short <=
|
|