[Freeciv-Dev] Re: (PR#9929) new function specialists_string
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients: ; |
Subject: |
[Freeciv-Dev] Re: (PR#9929) new function specialists_string |
From: |
"Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx> |
Date: |
Sat, 4 Sep 2004 12:00:38 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9929 >
Jason Short wrote:
> <URL: http://rt.freeciv.org/Ticket/Display.html?id=9929 >
>
>>[jdorje - Fri Sep 03 23:34:58 2004]:
>>
>>This patch adds a function specialists_string. It takes an array of
>>specialists (like in pcity->specialists or result->specialists) and
>>returns a slash-separated string containing the numbers. This is useful
>>for UI and debugging output.
>>
>>No doubt this function can be useful in more places. We'll see...
>
> And an updated patch.
...and the correct patch.
Index: client/cityrepdata.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/cityrepdata.c,v
retrieving revision 1.35
diff -u -r1.35 cityrepdata.c
--- client/cityrepdata.c 4 Sep 2004 18:39:38 -0000 1.35
+++ client/cityrepdata.c 4 Sep 2004 18:56:50 -0000
@@ -114,12 +114,7 @@
static const char *cr_entry_specialists(const struct city *pcity)
{
- static char buf[32];
- my_snprintf(buf, sizeof(buf), "%d/%d/%d",
- pcity->specialists[SP_ELVIS],
- pcity->specialists[SP_SCIENTIST],
- pcity->specialists[SP_TAXMAN]);
- return buf;
+ return specialists_string(pcity->specialists);
}
static const char *cr_entry_entertainers(const struct city *pcity)
Index: client/agents/cma_fec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/agents/cma_fec.c,v
retrieving revision 1.25
diff -u -r1.25 cma_fec.c
--- client/agents/cma_fec.c 4 Sep 2004 18:39:38 -0000 1.25
+++ client/agents/cma_fec.c 4 Sep 2004 18:56:50 -0000
@@ -337,14 +337,9 @@
my_snprintf(buf[j], BUFFER_SIZE, "%+3d", result->surplus[j]);
}
- my_snprintf(buf[6], BUFFER_SIZE, "%d/%d/%d/%d%s",
- pcity->size -
- (result->specialists[SP_ELVIS]
- + result->specialists[SP_SCIENTIST]
- + result->specialists[SP_TAXMAN]),
- result->specialists[SP_ELVIS],
- result->specialists[SP_SCIENTIST],
- result->specialists[SP_TAXMAN],
+ my_snprintf(buf[6], BUFFER_SIZE, "%d/%s%s",
+ pcity->size - cm_count_specialist(pcity, result),
+ specialists_string(result->specialists),
result->happy ? _(" happy") : "");
my_snprintf(buf[7], BUFFER_SIZE, "%s",
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.240
diff -u -r1.240 city.c
--- common/city.c 1 Sep 2004 19:45:19 -0000 1.240
+++ common/city.c 4 Sep 2004 18:56:51 -0000
@@ -2464,6 +2464,31 @@
}
/**************************************************************************
+ Return a string showing the number of specialists in the array.
+
+ For instance with a city with (0,3,1) specialists call
+
+ specialists_string(pcity->specialists);
+
+ and you'll get "0/3/1".
+**************************************************************************/
+const char *specialists_string(const int *specialists)
+{
+ size_t len = 0;
+ static char buf[5 * SP_COUNT];
+
+ specialist_type_iterate(sp) {
+ char *separator = (len == 0) ? "" : "/";
+
+ my_snprintf(buf + len, sizeof(buf) - len,
+ "%s%d", separator, specialists[sp]);
+ len += strlen(buf + len);
+ } specialist_type_iterate_end;
+
+ return buf;
+}
+
+/**************************************************************************
Return the power (pacifying effect) of temples in the city.
**************************************************************************/
int get_temple_power(const struct city *pcity)
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.158
diff -u -r1.158 city.h
--- common/city.h 3 Sep 2004 04:22:36 -0000 1.158
+++ common/city.h 4 Sep 2004 18:56:51 -0000
@@ -483,6 +483,7 @@
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 */
+const char *specialists_string(const int *specialists);
int get_temple_power(const struct city *pcity);
int get_cathedral_power(const struct city *pcity);
int get_colosseum_power(const struct city *pcity);
Index: common/aicore/cm.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/aicore/cm.c,v
retrieving revision 1.39
diff -u -r1.39 cm.c
--- common/aicore/cm.c 24 Jul 2004 03:43:35 -0000 1.39
+++ common/aicore/cm.c 4 Sep 2004 18:56:51 -0000
@@ -449,10 +449,8 @@
}
freelog(LOG_NORMAL,
- "print_result: people: W/E/S/T %d/%d/%d/%d",
- worker, result->specialists[SP_ELVIS],
- result->specialists[SP_SCIENTIST],
- result->specialists[SP_TAXMAN]);
+ "print_result: people: (workers/specialists) %d/%s",
+ worker, specialists_string(result->specialists));
for (i = 0; i < NUM_STATS; i++) {
freelog(LOG_NORMAL,
@@ -673,10 +671,10 @@
/* Restore */
memcpy(pcity, &backup, sizeof(struct city));
- freelog(LOG_DEBUG, "xyz: w=%d e=%d s=%d t=%d trade=%d "
+ freelog(LOG_DEBUG, "xyz: w=%d s=%s trade=%d "
"sci=%d lux=%d tax=%d dis=%s happy=%s",
- cm_count_worker(pcity, result), result->specialists[SP_ELVIS],
- result->specialists[SP_SCIENTIST], result->specialists[SP_TAXMAN],
+ cm_count_worker(pcity, result),
+ specialists_string(result->specialists),
result->surplus[TRADE],
result->surplus[SCIENCE],
result->surplus[LUXURY],
@@ -858,9 +856,8 @@
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->specialists[SP_ELVIS],
- result->specialists[SP_SCIENTIST], result->specialists[SP_TAXMAN]);
+ "fill_out_result(city='%s'(%d), specialists=%s)",
+ pcity->name, pcity->id, specialists_string(result->specialists));
/* try to fill result from cache2 */
if (!base_combination->all_entertainer.found_a_valid) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] Re: (PR#9929) new function specialists_string,
Jason Short <=
|
|