[Freeciv-Dev] (PR#2570) get_city_citizens
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients:; |
Subject: |
[Freeciv-Dev] (PR#2570) get_city_citizens |
From: |
"Jason Short via RT" <rt@xxxxxxxxxxxxxx> |
Date: |
Sat, 14 Dec 2002 01:19:43 -0800 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
The attached patch provides a client-common function
get_city_citizens(), which provides a list of citizens (citizen types)
of the citizens in the city. This allows the simplification of a lot of
GUI code and the removal of several hacks.
jason
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.12
diff -u -r1.12 citydlg_common.c
--- client/citydlg_common.c 2002/11/21 13:35:31 1.12
+++ client/citydlg_common.c 2002/12/14 09:13:13
@@ -255,3 +255,40 @@
my_snprintf(buf[3], column_size, "---");
}
}
+
+/**************************************************************************
+ Provide a list of all citizens in the city, in order. "index" should
+ be the happiness index (currently [0..4]; 4 = final happiness).
+ "citizens" should be an array large oenough to hold all citizens.
+**************************************************************************/
+void get_city_citizens(struct city *pcity, int index,
+ enum citizen_type *citizens)
+{
+ int i = 0, n;
+ assert(index >= 0 && index < 5);
+
+ for (n = 0; n < pcity->ppl_happy[index]; n++, i++) {
+ citizens[i] = CITIZEN_HAPPY;
+ }
+ for (n = 0; n < pcity->ppl_content[index]; n++, i++) {
+ citizens[i] = CITIZEN_CONTENT;
+ }
+ for (n = 0; n < pcity->ppl_unhappy[index]; n++, i++) {
+ citizens[i] = CITIZEN_UNHAPPY;
+ }
+ for (n = 0; n < pcity->ppl_angry[index]; n++, i++) {
+ 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;
+ }
+
+ assert(i == pcity->size);
+}
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.6
diff -u -r1.6 citydlg_common.h
--- client/citydlg_common.h 2002/12/13 19:15:11 1.6
+++ client/citydlg_common.h 2002/12/14 09:13:13
@@ -42,4 +42,7 @@
void get_city_dialog_production_row(char *buf[], size_t column_size, int id,
bool is_unit, struct city *pcity);
+void get_city_citizens(struct city *pcity, int index,
+ enum citizen_type *citizens);
+
#endif /* FC__CITYDLG_COMMON_H */
Index: client/gui-gtk/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/citydlg.c,v
retrieving revision 1.148
diff -u -r1.148 citydlg.c
--- client/gui-gtk/citydlg.c 2002/12/13 19:15:11 1.148
+++ client/gui-gtk/citydlg.c 2002/12/14 09:13:15
@@ -185,7 +185,6 @@
Impr_Type_id sell_id;
- int first_elvis, first_scientist, first_taxman;
int cwidth;
/* This is used only to avoid too many refreshes. */
@@ -1648,9 +1647,10 @@
*****************************************************************/
static void city_dialog_update_citizens(struct city_dialog *pdialog)
{
- int i, n;
+ int i;
struct city *pcity = pdialog->pcity;
int width;
+ enum citizen_type citizens[MAX_CITY_SIZE];
/* If there is not enough space we stack the icons. We draw from left to */
/* right. width is how far we go to the right for each drawn pixmap. The */
@@ -1668,51 +1668,14 @@
gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->citizen_pixmap), TRUE);
- i = 0; /* tracks the # of the citizen we are currently placing. */
- for (n = 0; n < pcity->ppl_happy[4]; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_HAPPY, i, pcity),
- i * width, 0, TRUE);
- }
+ get_city_citizens(pcity, 4, citizens);
- for (n = 0; n < pcity->ppl_content[4]; n++, i++) {
+ for (i = 0; i < pcity->size; i++) {
gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_CONTENT, i, pcity),
+ get_citizen_sprite(citizens[i], i, pcity),
i * width, 0, TRUE);
}
- for (n = 0; n < pcity->ppl_unhappy[4]; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_UNHAPPY, i, pcity),
- i * width, 0, TRUE);
- }
-
- for (n = 0; n < pcity->ppl_angry[4]; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_ANGRY, i, pcity),
- i * width, 0, TRUE);
- }
-
- pdialog->first_elvis = i;
- for (n = 0; n < pcity->ppl_elvis; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_ELVIS, i, pcity),
- i * width, 0, TRUE);
- }
-
- pdialog->first_scientist = i;
- for (n = 0; n < pcity->ppl_scientist; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_SCIENTIST, i, pcity),
- i * width, 0, TRUE);
- }
-
- pdialog->first_taxman = i;
- for (n = 0; n < pcity->ppl_taxman; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_TAXMAN, i, pcity),
- i * width, 0, TRUE);
- }
/* gtk_widget_set_sensitive(pdialog->citizen_pixmap,*/
/* !cma_is_city_under_agent(pcity, NULL));*/
}
@@ -2787,19 +2750,26 @@
struct packet_city_request packet;
int citnum;
enum specialist_type type;
+ enum citizen_type citizens[MAX_CITY_SIZE];
if (ev->x > (pcity->size - 1) * pdialog->cwidth + SMALL_TILE_WIDTH)
return; /* no citizen that far to the right */
citnum = MIN(pcity->size - 1, ev->x / pdialog->cwidth);
- if (citnum >= pdialog->first_taxman) {
- type = SP_TAXMAN;
- } else if (citnum >= pdialog->first_scientist) {
- type = SP_SCIENTIST;
- } else if (citnum >= pdialog->first_elvis) {
+ get_city_citizens(pcity, 4, citizens);
+
+ switch (citizens[citnum]) {
+ case CITIZEN_ELVIS:
type = SP_ELVIS;
- } else {
+ break;
+ case CITIZEN_SCIENTIST:
+ type = SP_SCIENTIST;
+ break;
+ case CITIZEN_TAXMAN:
+ type = SP_TAXMAN;
+ break;
+ default:
return;
}
Index: client/gui-gtk/happiness.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/happiness.c,v
retrieving revision 1.10
diff -u -r1.10 happiness.c
--- client/gui-gtk/happiness.c 2002/12/13 19:15:11 1.10
+++ client/gui-gtk/happiness.c 2002/12/14 09:13:15
@@ -159,13 +159,7 @@
static GdkPixmap *create_happiness_pixmap(struct city *pcity, int index)
{
int i;
- enum citizen_type citizen_type;
- int n1 = pcity->ppl_happy[index];
- int n2 = n1 + pcity->ppl_content[index];
- int n3 = n2 + pcity->ppl_unhappy[index];
- int n4 = n3 + pcity->ppl_angry[index];
- int n5 = n4 + pcity->ppl_elvis;
- int n6 = n5 + pcity->ppl_scientist;
+ enum citizen_type citizens[MAX_CITY_SIZE];
int num_citizens = pcity->size;
int pix_width = HAPPINESS_PIX_WIDTH * SMALL_TILE_WIDTH;
int offset = MIN(SMALL_TILE_WIDTH, pix_width / num_citizens);
@@ -174,24 +168,11 @@
GdkPixmap *happiness_pixmap = gdk_pixmap_new(root_window, true_pix_width,
SMALL_TILE_HEIGHT, -1);
- for (i = 0; i < num_citizens; i++) {
- if (i < n1)
- citizen_type = CITIZEN_HAPPY;
- else if (i < n2)
- citizen_type = CITIZEN_CONTENT;
- else if (i < n3)
- citizen_type = CITIZEN_UNHAPPY;
- else if (i < n4)
- citizen_type = CITIZEN_ANGRY;
- else if (i < n5)
- citizen_type = CITIZEN_ELVIS;
- else if (i < n6)
- citizen_type = CITIZEN_SCIENTIST;
- else
- citizen_type = CITIZEN_TAXMAN;
+ get_city_citizens(pcity, index, citizens);
+ for (i = 0; i < num_citizens; i++) {
gdk_draw_pixmap(happiness_pixmap, civ_gc,
- get_citizen_pixmap(citizen_type, i, pcity),
+ get_citizen_pixmap(citizens[i], i, pcity),
0, 0, i * offset, 0, SMALL_TILE_WIDTH,
SMALL_TILE_HEIGHT);
}
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.17
diff -u -r1.17 citydlg.c
--- client/gui-gtk-2.0/citydlg.c 2002/12/13 19:15:12 1.17
+++ client/gui-gtk-2.0/citydlg.c 2002/12/14 09:13:16
@@ -184,7 +184,6 @@
Impr_Type_id sell_id;
- int first_elvis, first_scientist, first_taxman;
int cwidth;
/* This is used only to avoid too many refreshes. */
@@ -1633,9 +1632,9 @@
*****************************************************************/
static void city_dialog_update_citizens(struct city_dialog *pdialog)
{
- int i, n;
+ int i, width;
struct city *pcity = pdialog->pcity;
- int width;
+ enum citizen_type citizens[MAX_CITY_SIZE];
/* If there is not enough space we stack the icons. We draw from left to */
/* right. width is how far we go to the right for each drawn pixmap. The */
@@ -1654,51 +1653,14 @@
gtk_pixcomm_freeze(GTK_PIXCOMM(pdialog->citizen_pixmap));
gtk_pixcomm_clear(GTK_PIXCOMM(pdialog->citizen_pixmap));
- i = 0; /* tracks the # of the citizen we are currently placing. */
- for (n = 0; n < pcity->ppl_happy[4]; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_HAPPY, i, pcity),
- i * width, 0);
- }
-
- for (n = 0; n < pcity->ppl_content[4]; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_CONTENT, i, pcity),
- i * width, 0);
- }
-
- for (n = 0; n < pcity->ppl_unhappy[4]; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_UNHAPPY, i, pcity),
- i * width, 0);
- }
-
- for (n = 0; n < pcity->ppl_angry[4]; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_ANGRY, i, pcity),
- i * width, 0);
- }
-
- pdialog->first_elvis = i;
- for (n = 0; n < pcity->ppl_elvis; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_ELVIS, i, pcity),
- i * width, 0);
- }
+ get_city_citizens(pcity, 4, citizens);
- pdialog->first_scientist = i;
- for (n = 0; n < pcity->ppl_scientist; n++, i++) {
+ for (i = 0; i < pcity->size; i++) {
gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_SCIENTIST, i, pcity),
+ get_citizen_sprite(citizens[i], i, pcity),
i * width, 0);
}
- pdialog->first_taxman = i;
- for (n = 0; n < pcity->ppl_taxman; n++, i++) {
- gtk_pixcomm_copyto(GTK_PIXCOMM(pdialog->citizen_pixmap),
- get_citizen_sprite(CITIZEN_TAXMAN, i, pcity),
- i * width, 0);
- }
gtk_pixcomm_thaw(GTK_PIXCOMM(pdialog->citizen_pixmap));
/* gtk_widget_set_sensitive(pdialog->citizen_pixmap,*/
@@ -2766,19 +2728,26 @@
struct packet_city_request packet;
int citnum;
enum specialist_type type;
+ enum citizen_type citizens[MAX_CITY_SIZE];
if (ev->x > (pcity->size - 1) * pdialog->cwidth + SMALL_TILE_WIDTH)
return; /* no citizen that far to the right */
citnum = MIN(pcity->size - 1, ev->x / pdialog->cwidth);
- if (citnum >= pdialog->first_taxman) {
- type = SP_TAXMAN;
- } else if (citnum >= pdialog->first_scientist) {
- type = SP_SCIENTIST;
- } else if (citnum >= pdialog->first_elvis) {
+ get_city_citizens(pcity, 4, citizens);
+
+ switch (citizens[citnum]) {
+ case CITIZEN_ELVIS:
type = SP_ELVIS;
- } else {
+ break;
+ case CITIZEN_SCIENTIST:
+ type = SP_SCIENTIST;
+ break;
+ case CITIZEN_TAXMAN:
+ type = SP_TAXMAN;
+ break;
+ default:
return;
}
Index: client/gui-gtk-2.0/happiness.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/happiness.c,v
retrieving revision 1.5
diff -u -r1.5 happiness.c
--- client/gui-gtk-2.0/happiness.c 2002/12/13 19:15:12 1.5
+++ client/gui-gtk-2.0/happiness.c 2002/12/14 09:13:16
@@ -146,13 +146,7 @@
static GdkPixmap *create_happiness_pixmap(struct city *pcity, int index)
{
int i;
- enum citizen_type citizen_type;
- int n1 = pcity->ppl_happy[index];
- int n2 = n1 + pcity->ppl_content[index];
- int n3 = n2 + pcity->ppl_unhappy[index];
- int n4 = n3 + pcity->ppl_angry[index];
- int n5 = n4 + pcity->ppl_elvis;
- int n6 = n5 + pcity->ppl_scientist;
+ enum citizen_type citizens[MAX_CITY_SIZE];
int num_citizens = pcity->size;
int pix_width = HAPPINESS_PIX_WIDTH * SMALL_TILE_WIDTH;
int offset = MIN(SMALL_TILE_WIDTH, pix_width / num_citizens);
@@ -161,24 +155,11 @@
GdkPixmap *happiness_pixmap = gdk_pixmap_new(root_window, true_pix_width,
SMALL_TILE_HEIGHT, -1);
- for (i = 0; i < num_citizens; i++) {
- if (i < n1)
- citizen_type = CITIZEN_HAPPY;
- else if (i < n2)
- citizen_type = CITIZEN_CONTENT;
- else if (i < n3)
- citizen_type = CITIZEN_UNHAPPY;
- else if (i < n4)
- citizen_type = CITIZEN_ANGRY;
- else if (i < n5)
- citizen_type = CITIZEN_ELVIS;
- else if (i < n6)
- citizen_type = CITIZEN_SCIENTIST;
- else
- citizen_type = CITIZEN_TAXMAN;
+ get_city_citizens(pcity, index, citizens);
+ for (i = 0; i < num_citizens; i++) {
gdk_draw_pixmap(happiness_pixmap, civ_gc,
- get_citizen_pixmap(citizen_type, i, pcity),
+ get_citizen_pixmap(citizens[i], i, pcity),
0, 0, i * offset, 0, SMALL_TILE_WIDTH,
SMALL_TILE_HEIGHT);
}
Index: client/gui-mui/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-mui/citydlg.c,v
retrieving revision 1.59
diff -u -r1.59 citydlg.c
--- client/gui-mui/citydlg.c 2002/12/13 19:15:12 1.59
+++ client/gui-mui/citydlg.c 2002/12/14 09:13:17
@@ -1114,19 +1114,22 @@
struct city_dialog *pdialog = msg->pdialog;
struct city *pcity = pdialog->pcity;
- switch (msg->type)
- {
- case 0:
+ switch (msg->type) {
+ case CITIZEN_ELVIS:
request_city_change_specialist(pcity, SP_ELVIS, SP_SCIENTIST);
break;
- case 1:
+ case CITIZEN_SCIENTIST:
request_city_change_specialist(pcity, SP_SCIENTIST, SP_TAXMAN);
break;
- default:
+ case CITIZEN_TAXMAN:
request_city_change_specialist(pcity, SP_TAXMAN, SP_ELVIS);
break;
+
+ default:
+ assert(FALSE);
+ break;
}
}
@@ -1934,8 +1937,9 @@
*****************************************************************/
static void city_dialog_update_citizens(struct city_dialog *pdialog)
{
- int n;
+ int i;
struct city *pcity = pdialog->pcity;
+ enum citizen_type citizens[MAX_CITY_SIZE];
DoMethod(pdialog->citizen_group, MUIM_Group_InitChange);
if (pdialog->citizen2_group)
@@ -1946,64 +1950,25 @@
pdialog->citizen2_group = HGroup, GroupSpacing(0), End;
- /* maybe add an i < NUM_CITIZENS_SHOWN check into every loop with own
counter i */
+ /* Get a list of the citizens. */
+ get_city_citizens(pcity, 4, citizens);
- for (n = 0; n < pcity->ppl_happy[4]; n++)
- {
- Object *o = MakeSprite(get_citizen_sprite(CITIZEN_HAPPY, n, pcity));
- if (o)
+ for (i = 0; i < pcity->size; i++) {
+ Object *o = MakeSprite(get_citizen_sprite(citizens[i], i, pcity));
+ if (o) {
DoMethod(pdialog->citizen2_group, OM_ADDMEMBER, o);
- }
- for (n = 0; n < pcity->ppl_content[4]; n++)
- {
- Object *o = MakeSprite(get_citizen_sprite(CITIZEN_CONTENT, n, pcity));
- if (o)
- DoMethod(pdialog->citizen2_group, OM_ADDMEMBER, o);
- }
-
-
- for (n = 0; n < pcity->ppl_unhappy[4]; n++)
- {
- Object *o = MakeSprite(get_citizen_sprite(CITIZEN_UNHAPPY, n, pcity));
- if (o)
- DoMethod(pdialog->citizen2_group, OM_ADDMEMBER, o);
- }
-
- for (n = 0; n < pcity->ppl_angry[4]; n++) {
- Object *o = MakeSprite(get_citizen_sprite(CITIZEN_ANGRY, n, pcity));
- if (o)
- DoMethod(pdialog->citizen2_group, OM_ADDMEMBER, o);
- }
-
- for (n = 0; n < pcity->ppl_elvis; n++)
- {
- Object *o = MakeSprite(get_citizen_sprite(CITIZEN_ELVIS, n, pcity));
- if (o)
- {
- DoMethod(pdialog->citizen2_group, OM_ADDMEMBER, o);
- DoMethod(o, MUIM_Notify, MUIA_Pressed, FALSE, o, 5, MUIM_CallHook,
&civstandard_hook, city_citizen, pdialog, 0);
- }
- }
-
- for (n = 0; n < pcity->ppl_scientist; n++)
- {
- Object *o = MakeSprite(get_citizen_sprite(CITIZEN_SCIENTIST, n, pcity));
- if (o)
- {
- DoMethod(pdialog->citizen2_group, OM_ADDMEMBER, o);
- DoMethod(o, MUIM_Notify, MUIA_Pressed, FALSE, o, 5, MUIM_CallHook,
&civstandard_hook, city_citizen, pdialog, 1);
- }
- }
-
- for (n = 0; n < pcity->ppl_taxman; n++)
- {
- Object *o = MakeSprite(get_citizen_sprite(CITIZEN_TAXMAN, n, pcity));
-
- if (o)
- {
- DoMethod(pdialog->citizen2_group, OM_ADDMEMBER, o);
- DoMethod(o, MUIM_Notify, MUIA_Pressed, FALSE, o, 5, MUIM_CallHook,
&civstandard_hook, city_citizen, pdialog, 2);
+ /* HACK: set sensitivity on widgets */
+ switch (citizens[i]) {
+ case CITIZEN_ELVIS:
+ case CITIZEN_SCIENTIST:
+ case CITIZEN_TAXMAN:
+ DoMethod(o, MUIM_Notify, MUIA_Pressed, FALSE, o, 5, MUIM_CallHook,
+ &civstandard_hook, city_citizen, pdialog, citizens[i]);
+ break;
+ default:
+ break;
+ }
}
}
@@ -2490,38 +2455,17 @@
for(i=0;i<5;i++)
{
int j;
- int n1 = pcity->ppl_happy[i];
- int n2 = n1 + pcity->ppl_content[i];
- int n3 = n2 + pcity->ppl_unhappy[i];
- int n4 = n3 + pcity->ppl_angry[i];
- int n5 = n4 + pcity->ppl_elvis;
- int n6 = n5 + pcity->ppl_scientist;
int num_citizens = pcity->size;
+ enum citizen_type citizens[MAX_CITY_SIZE];
DoMethod(pdialog->happiness_citizen_group[i],MUIM_Group_InitChange);
DisposeAllChilds(pdialog->happiness_citizen_group[i]);
- for (j = 0; j < num_citizens; j++) {
- int citizen_type;
- Object *obj;
- if (j < n1)
- citizen_type = CITIZEN_HAPPY;
- else if (j < n2)
- citizen_type = CITIZEN_CONTENT;
- else if (j < n3)
- citizen_type = CITIZEN_UNHAPPY;
- else if (j < n4) {
- citizen_type = CITIZEN_ANGRY;
- } else if (j < n5) {
- citizen_type = CITIZEN_ELVIS;
- } else if (j < n6) {
- citizen_type = CITIZEN_SCIENTIST;
- } else {
- citizen_type = CITIZEN_TAXMAN;
- }
+ get_city_citizens(pcity, i, citizens);
- if ((obj = MakeSprite(get_citizen_sprite(citizen_type, j, pcity))))
- {
+ for (j = 0; j < num_citizens; j++) {
+ obj = MakeSprite(get_citizen_sprite(citizens[j], j, pcity));
+ if (obj) {
DoMethod(pdialog->happiness_citizen_group[i], OM_ADDMEMBER, obj);
}
}
Index: client/gui-win32/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/citydlg.c,v
retrieving revision 1.40
diff -u -r1.40 citydlg.c
--- client/gui-win32/citydlg.c 2002/12/13 19:15:12 1.40
+++ client/gui-win32/citydlg.c 2002/12/14 09:13:17
@@ -611,52 +611,18 @@
RECT rc;
HBITMAP oldbit;
oldbit=SelectObject(citydlgdc,pdialog->citizen_bmp);
+ enum citizen_type citizens[MAX_CITY_SIZE];
+ get_city_citizens(pcity, 4, citizens);
- for(i=0, n=0; n<pcity->ppl_happy[4] && i<NUM_CITIZENS_SHOWN; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_HAPPY) {
- pdialog->citizen_type[i] = CITIZEN_HAPPY;
- draw_sprite(get_citizen_sprite(CITIZEN_HAPPY, i, pcity), citydlgdc,
- SMALL_TILE_WIDTH*i,0);
- }
- for(n=0; n<pcity->ppl_content[4] && i<NUM_CITIZENS_SHOWN; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_CONTENT) {
- pdialog->citizen_type[i] = CITIZEN_CONTENT;
- draw_sprite(get_citizen_sprite(CITIZEN_CONTENT, i, pcity), citydlgdc,
- SMALL_TILE_WIDTH*i,0);
- }
- for(n=0; n<pcity->ppl_unhappy[4] && i<NUM_CITIZENS_SHOWN; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_UNHAPPY) {
- pdialog->citizen_type[i] = CITIZEN_UNHAPPY;
- draw_sprite(get_citizen_sprite(CITIZEN_UNHAPPY, i, pcity), citydlgdc,
- SMALL_TILE_WIDTH*i,0);
- }
- for (n = 0; n < pcity->ppl_angry[4] && i < NUM_CITIZENS_SHOWN; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_ANGRY) {
- pdialog->citizen_type[i] = CITIZEN_ANGRY;
- draw_sprite(get_citizen_sprite(CITIZEN_ANGRY, i, pcity), citydlgdc,
+ for (i = 0; i < pcity->size && i < NUM_CITIZENS_SHOWN; i++) {
+ if (pdialog->citizen_type[i] != citizens[i]) {
+ pdialog->citizen_type[i] = citizens[i];
+ draw_sprite(get_citizen_sprite(citizens[i], i, pcity), citydlgdc,
SMALL_TILE_WIDTH * i, 0);
- }
- for(n=0; n<pcity->ppl_elvis && i<NUM_CITIZENS_SHOWN; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_ELVIS) {
- pdialog->citizen_type[i] = CITIZEN_ELVIS;
- draw_sprite(get_citizen_sprite(CITIZEN_ELVIS, i, pcity), citydlgdc,
- SMALL_TILE_WIDTH*i,0);
-
- }
- for(n=0; n<pcity->ppl_scientist && i<NUM_CITIZENS_SHOWN; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_SCIENTIST) {
- pdialog->citizen_type[i] = CITIZEN_SCIENTIST;
- draw_sprite(get_citizen_sprite(CITIZEN_SCIENTIST, i, pcity), citydlgdc,
- SMALL_TILE_WIDTH*i,0);
}
- for(n=0; n<pcity->ppl_taxman && i<NUM_CITIZENS_SHOWN; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_TAXMAN) {
- pdialog->citizen_type[i] = CITIZEN_TAXMAN;
- draw_sprite(get_citizen_sprite(CITIZEN_TAXMAN, i, pcity), citydlgdc,
- SMALL_TILE_WIDTH*i,0);
- }
-
+ }
+
if (i<NUM_CITIZENS_SHOWN) {
rc.left=i*SMALL_TILE_WIDTH;
rc.right=NUM_CITIZENS_SHOWN*SMALL_TILE_WIDTH;
@@ -669,7 +635,7 @@
}
for(; i<NUM_CITIZENS_SHOWN; i++) {
- pdialog->citizen_type[i]=-1;
+ pdialog->citizen_type[i] = CITIZEN_LAST;
}
BitBlt(hdc,pdialog->pop_x,pdialog->pop_y,
Index: client/gui-win32/happiness.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/happiness.c,v
retrieving revision 1.4
diff -u -r1.4 happiness.c
--- client/gui-win32/happiness.c 2002/12/13 19:15:12 1.4
+++ client/gui-win32/happiness.c 2002/12/14 09:13:17
@@ -392,13 +392,7 @@
HBITMAP old;
RECT rc;
int i;
- enum citizen_type citizen_type;
- int n1 = pcity->ppl_happy[index];
- int n2 = n1 + pcity->ppl_content[index];
- int n3 = n2 + pcity->ppl_unhappy[index];
- int n4 = n3 + pcity->ppl_angry[index];
- int n5 = n4 + pcity->ppl_elvis;
- int n6 = n5 + pcity->ppl_scientist;
+ enum citizen_type citizens[MAX_CITY_SIZE];
int num_citizens = pcity->size;
int pix_width = HAPPINESS_PIX_WIDTH * SMALL_TILE_WIDTH;
int offset = MIN(SMALL_TILE_WIDTH, pix_width / num_citizens);
@@ -410,24 +404,14 @@
rc.right=pix_width;
rc.bottom=SMALL_TILE_HEIGHT;
FillRect(hdc,&rc,(HBRUSH)GetClassLong(root_window,GCL_HBRBACKGROUND));
+
+ get_city_citizens(pcity, index, citizens);
+
for (i = 0; i < num_citizens; i++) {
- if (i < n1)
- citizen_type = CITIZEN_HAPPY;
- else if (i < n2)
- citizen_type = CITIZEN_CONTENT;
- else if (i < n3)
- citizen_type = CITIZEN_UNHAPPY;
- else if (i < n4)
- citizen_type = CITIZEN_ANGRY;
- else if (i < n5)
- citizen_type = CITIZEN_ELVIS;
- else if (i < n6)
- citizen_type = CITIZEN_SCIENTIST;
- else
- citizen_type = CITIZEN_TAXMAN;
- draw_sprite(get_citizen_sprite(citizen_type, i, pcity),
+ draw_sprite(get_citizen_sprite(citizens[i], i, pcity),
hdc, i * offset, 0);
}
+
SelectObject(hdc,old);
DeleteDC(hdc);
}
Index: client/gui-xaw/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/citydlg.c,v
retrieving revision 1.85
diff -u -r1.85 citydlg.c
--- client/gui-xaw/citydlg.c 2002/12/14 01:29:32 1.85
+++ client/gui-xaw/citydlg.c 2002/12/14 09:13:17
@@ -114,7 +114,6 @@
Impr_Type_id sell_id;
- enum citizen_type *citizen_type;
int support_unit_base;
int present_unit_base;
char improvlist_names[B_LAST+1][64];
@@ -931,8 +930,6 @@
pdialog->citizen_labels=
fc_malloc(pdialog->num_citizens_shown * sizeof(Widget));
- pdialog->citizen_type=
- fc_malloc(pdialog->num_citizens_shown * sizeof(*pdialog->citizen_type));
pdialog->support_unit_pixcomms=
fc_malloc(pdialog->num_units_shown * sizeof(Widget));
@@ -1050,11 +1047,6 @@
for(i=0; i<B_LAST+1; i++)
pdialog->improvlist_names_ptrs[i]=0;
- for (i = 0; i < pdialog->num_citizens_shown; i++) {
- /* Initialize to an invalid value to trigger an assert if it's used */
- pdialog->citizen_type[i] = CITIZEN_LAST;
- }
-
XtRealizeWidget(pdialog->shell);
refresh_city_dialog(pdialog->pcity);
@@ -1578,105 +1570,54 @@
*****************************************************************/
void city_dialog_update_citizens(struct city_dialog *pdialog)
{
- int i, n;
+ int i;
struct city *pcity=pdialog->pcity;
-
- i=0;
-
- for(n=0; n<pcity->ppl_happy[4] && i<pdialog->num_citizens_shown; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_HAPPY) {
- pdialog->citizen_type[i] = CITIZEN_HAPPY;
- xaw_set_bitmap(pdialog->citizen_labels[i],
- get_citizen_pixmap(CITIZEN_HAPPY, i, pcity));
- XtSetSensitive(pdialog->citizen_labels[i], FALSE);
- XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
- }
- if(n<pcity->ppl_happy[4]) goto city_dialog_update_citizens_overflow;
-
- for(n=0; n<pcity->ppl_content[4] && i<pdialog->num_citizens_shown; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_CONTENT) {
- pdialog->citizen_type[i] = CITIZEN_CONTENT;
- xaw_set_bitmap(pdialog->citizen_labels[i],
- get_citizen_pixmap(CITIZEN_CONTENT, i, pcity));
- XtSetSensitive(pdialog->citizen_labels[i], FALSE);
- XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
- }
- if(n<pcity->ppl_content[4]) goto city_dialog_update_citizens_overflow;
+ enum citizen_type citizens[MAX_CITY_SIZE];
- for(n=0; n<pcity->ppl_unhappy[4] && i<pdialog->num_citizens_shown; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_UNHAPPY) {
- pdialog->citizen_type[i] = CITIZEN_UNHAPPY;
- xaw_set_bitmap(pdialog->citizen_labels[i],
- get_citizen_pixmap(CITIZEN_UNHAPPY, i, pcity));
- XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
- XtSetSensitive(pdialog->citizen_labels[i], FALSE);
- }
- if(n<pcity->ppl_unhappy[4]) goto city_dialog_update_citizens_overflow;
+ get_city_citizens(pcity, 4, citizens);
- for (n = 0; n < pcity->ppl_angry[4] && i < pdialog->num_citizens_shown;
- n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_ANGRY) {
- pdialog->citizen_type[i] = CITIZEN_ANGRY;
- xaw_set_bitmap(pdialog->citizen_labels[i],
- get_citizen_pixmap(CITIZEN_ANGRY, i, pcity));
- XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
- XtSetSensitive(pdialog->citizen_labels[i], FALSE);
- }
- if (n < pcity->ppl_angry[4])
- goto city_dialog_update_citizens_overflow;
+ for (i = 0; i < pcity->size && i < pdialog->num_citizens_shown; i++) {
+ xaw_set_bitmap(pdialog->citizen_labels[i],
+ get_citizen_pixmap(citizens[i], i, pcity));
- for(n=0; n<pcity->ppl_elvis && i<pdialog->num_citizens_shown; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_ELVIS) {
- xaw_set_bitmap(pdialog->citizen_labels[i],
- get_citizen_pixmap(CITIZEN_ELVIS, i, pcity));
- pdialog->citizen_type[i] = CITIZEN_ELVIS;
- XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
- XtAddCallback(pdialog->citizen_labels[i], XtNcallback, elvis_callback,
- (XtPointer)pdialog);
+ /* HACK: set sensitivity/callbacks on the widget */
+ XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
+ switch (citizens[i]) {
+ case CITIZEN_ELVIS:
+ XtAddCallback(pdialog->citizen_labels[i], XtNcallback,
+ elvis_callback, (XtPointer)pdialog);
XtSetSensitive(pdialog->citizen_labels[i], TRUE);
- }
- if(n<pcity->ppl_elvis) goto city_dialog_update_citizens_overflow;
-
- for(n=0; n<pcity->ppl_scientist && i<pdialog->num_citizens_shown; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_SCIENTIST) {
- xaw_set_bitmap(pdialog->citizen_labels[i],
- get_citizen_pixmap(CITIZEN_SCIENTIST, i, pcity));
- pdialog->citizen_type[i] = CITIZEN_SCIENTIST;
- XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
- XtAddCallback(pdialog->citizen_labels[i], XtNcallback,
scientist_callback,
- (XtPointer)pdialog);
+ break;
+ case CITIZEN_SCIENTIST:
+ XtAddCallback(pdialog->citizen_labels[i], XtNcallback,
+ scientist_callback, (XtPointer)pdialog);
XtSetSensitive(pdialog->citizen_labels[i], TRUE);
- }
- if(n<pcity->ppl_scientist) goto city_dialog_update_citizens_overflow;
-
- for(n=0; n<pcity->ppl_taxman && i<pdialog->num_citizens_shown; n++, i++)
- if (pdialog->citizen_type[i] != CITIZEN_TAXMAN) {
- xaw_set_bitmap(pdialog->citizen_labels[i],
- get_citizen_pixmap(CITIZEN_TAXMAN, i, pcity));
- pdialog->citizen_type[i] = CITIZEN_TAXMAN;
- XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
+ break;
+ case CITIZEN_TAXMAN:
XtAddCallback(pdialog->citizen_labels[i], XtNcallback, taxman_callback,
(XtPointer)pdialog);
XtSetSensitive(pdialog->citizen_labels[i], TRUE);
+ break;
+ default:
+ XtSetSensitive(pdialog->citizen_labels[i], FALSE);
+ XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
+ break;
}
- if(n<pcity->ppl_taxman) goto city_dialog_update_citizens_overflow;
+ }
+
+ if (i >= pdialog->num_citizens_shown && i < pcity->size) {
+ i = pdialog->num_citizens_shown - 1;
+ xaw_set_bitmap(pdialog->citizen_labels[i], sprites.right_arrow->pixmap);
+ XtSetSensitive(pdialog->citizen_labels[i], FALSE);
+ XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
+ return;
+ }
for(; i<pdialog->num_citizens_shown; i++) {
xaw_set_bitmap(pdialog->citizen_labels[i], None);
XtSetSensitive(pdialog->citizen_labels[i], FALSE);
XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
}
-
- return;
-
-city_dialog_update_citizens_overflow:
-
- i=pdialog->num_citizens_shown-1;
- xaw_set_bitmap(pdialog->citizen_labels[i], sprites.right_arrow->pixmap);
- XtSetSensitive(pdialog->citizen_labels[i], FALSE);
- XtRemoveAllCallbacks(pdialog->citizen_labels[i], XtNcallback);
-
- return;
}
/****************************************************************
@@ -2528,7 +2469,6 @@
dialog_list_unlink(&dialog_list, pdialog);
free(pdialog->citizen_labels);
- free(pdialog->citizen_type);
free(pdialog->support_unit_pixcomms);
free(pdialog->present_unit_pixcomms);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#2570) get_city_citizens,
Jason Short via RT <=
|
|