[Freeciv-Dev] (PR#10970) put terrain specials in 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=10970 >
This patch puts the terrain special data (data for S_SPECIAL_1 and
S_SPECIAL_2, loaded from the rulesets) into an array.
Some of the data was already in an array. From a comment in the code it
seems the only reason it wasn't all moved into an array is to avoid
changing too much code.
But this is a simple cleanup that will make some things easier.
jason
? diff
? vgcore.pid5770
? vgcore.pid7790
? utility/output
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.417
diff -u -r1.417 packhand.c
--- client/packhand.c 10 Nov 2004 17:01:58 -0000 1.417
+++ client/packhand.c 10 Nov 2004 18:42:28 -0000
@@ -2485,16 +2485,16 @@
t->food = p->food;
t->shield = p->shield;
t->trade = p->trade;
- sz_strlcpy(t->special_1_name_orig, p->special_1_name);
- t->special_1_name = t->special_1_name_orig;
- t->food_special_1 = p->food_special_1;
- t->shield_special_1 = p->shield_special_1;
- t->trade_special_1 = p->trade_special_1;
- sz_strlcpy(t->special_2_name_orig, p->special_2_name);
- t->special_2_name = t->special_2_name_orig;
- t->food_special_2 = p->food_special_2;
- t->shield_special_2 = p->shield_special_2;
- t->trade_special_2 = p->trade_special_2;
+ sz_strlcpy(t->special[0].name_orig, p->special_1_name);
+ t->special[0].name = t->special[0].name_orig;
+ t->special[0].food = p->food_special_1;
+ t->special[0].shield = p->shield_special_1;
+ t->special[0].trade = p->trade_special_1;
+ sz_strlcpy(t->special[1].name_orig, p->special_2_name);
+ t->special[1].name = t->special[1].name_orig;
+ t->special[1].food = p->food_special_2;
+ t->special[1].shield = p->shield_special_2;
+ t->special[1].trade = p->trade_special_2;
sz_strlcpy(t->special[0].graphic_str, p->graphic_str_special_1);
sz_strlcpy(t->special[0].graphic_alt, p->graphic_alt_special_1);
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.210
diff -u -r1.210 tilespec.c
--- client/tilespec.c 10 Nov 2004 17:01:58 -0000 1.210
+++ client/tilespec.c 10 Nov 2004 18:42:28 -0000
@@ -1773,8 +1773,9 @@
}
}
- for (i=0; i<2; i++) {
- const char *name = (i != 0) ? tt->special_2_name : tt->special_1_name;
+ for (i = 0; i < MAX_NUM_SPECIALS; i++) {
+ const char *name = tt->special[i].name;
+
if (name[0] != '\0') {
draw->special[i]
= lookup_sprite_tag_alt(tt->special[i].graphic_str,
Index: client/gui-gtk-2.0/helpdlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/helpdlg.c,v
retrieving revision 1.36
diff -u -r1.36 helpdlg.c
--- client/gui-gtk-2.0/helpdlg.c 10 Nov 2004 17:01:59 -0000 1.36
+++ client/gui-gtk-2.0/helpdlg.c 10 Nov 2004 18:42:28 -0000
@@ -998,28 +998,28 @@
tile_types[i].trade);
gtk_label_set_text(GTK_LABEL(help_tlabel[0][4]), buf);
- if (*(tile_types[i].special_1_name)) {
+ if (*(tile_types[i].special[0].name)) {
sprintf(buf, _("%s F/R/T:"),
- tile_types[i].special_1_name);
+ tile_types[i].special[0].name);
gtk_label_set_text(GTK_LABEL(help_tlabel[1][0]), buf);
sprintf(buf, "%d/%d/%d",
- tile_types[i].food_special_1,
- tile_types[i].shield_special_1,
- tile_types[i].trade_special_1);
+ tile_types[i].special[0].food,
+ tile_types[i].special[0].shield,
+ tile_types[i].special[0].trade);
gtk_label_set_text(GTK_LABEL(help_tlabel[1][1]), buf);
} else {
gtk_label_set_text(GTK_LABEL(help_tlabel[1][0]), "");
gtk_label_set_text(GTK_LABEL(help_tlabel[1][1]), "");
}
- if (*(tile_types[i].special_2_name)) {
+ if (*(tile_types[i].special[1].name)) {
sprintf(buf, _("%s F/R/T:"),
- tile_types[i].special_2_name);
+ tile_types[i].special[1].name);
gtk_label_set_text(GTK_LABEL(help_tlabel[1][3]), buf);
sprintf(buf, "%d/%d/%d",
- tile_types[i].food_special_2,
- tile_types[i].shield_special_2,
- tile_types[i].trade_special_2);
+ tile_types[i].special[1].food,
+ tile_types[i].special[1].shield,
+ tile_types[i].special[1].trade);
gtk_label_set_text(GTK_LABEL(help_tlabel[1][4]), buf);
} else {
gtk_label_set_text(GTK_LABEL(help_tlabel[1][3]), "");
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.253
diff -u -r1.253 city.c
--- common/city.c 10 Nov 2004 17:01:59 -0000 1.253
+++ common/city.c 10 Nov 2004 18:42:29 -0000
@@ -530,9 +530,9 @@
int s;
if (contains_special(spec_t, S_SPECIAL_1)) {
- s = get_tile_type(tile_t)->shield_special_1;
+ s = get_tile_type(tile_t)->special[0].shield;
} else if (contains_special(spec_t, S_SPECIAL_2)) {
- s = get_tile_type(tile_t)->shield_special_2;
+ s = get_tile_type(tile_t)->special[1].shield;
} else {
s = get_tile_type(tile_t)->shield;
}
@@ -635,9 +635,9 @@
int t;
if (contains_special(spec_t, S_SPECIAL_1)) {
- t = get_tile_type(tile_t)->trade_special_1;
+ t = get_tile_type(tile_t)->special[0].trade;
} else if (contains_special(spec_t, S_SPECIAL_2)) {
- t = get_tile_type(tile_t)->trade_special_2;
+ t = get_tile_type(tile_t)->special[1].trade;
} else {
t = get_tile_type(tile_t)->trade;
}
@@ -762,9 +762,9 @@
}
if (contains_special(tile.special, S_SPECIAL_1)) {
- f = type->food_special_1;
+ f = type->special[0].food;
} else if (contains_special(tile.special, S_SPECIAL_2)) {
- f = type->food_special_2;
+ f = type->special[1].food;
} else {
f = type->food;
}
Index: common/game.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/game.c,v
retrieving revision 1.189
diff -u -r1.189 game.c
--- common/game.c 10 Nov 2004 17:01:59 -0000 1.189
+++ common/game.c 10 Nov 2004 18:42:29 -0000
@@ -566,10 +566,10 @@
tthis->terrain_name = ((strcmp(tthis->terrain_name_orig, "") != 0)
? Q_(tthis->terrain_name_orig) : "");
- tthis->special_1_name = ((strcmp(tthis->special_1_name_orig, "") != 0)
- ? Q_(tthis->special_1_name_orig) : "");
- tthis->special_2_name = ((strcmp(tthis->special_2_name_orig, "") != 0)
- ? Q_(tthis->special_2_name_orig) : "");
+ tthis->special[0].name = ((strcmp(tthis->special[0].name_orig, "") != 0)
+ ? Q_(tthis->special[0].name_orig) : "");
+ tthis->special[1].name = ((strcmp(tthis->special[1].name_orig, "") != 0)
+ ? Q_(tthis->special[1].name_orig) : "");
} terrain_type_iterate_end;
government_iterate(tthis) {
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.202
diff -u -r1.202 map.c
--- common/map.c 18 Oct 2004 22:40:02 -0000 1.202
+++ common/map.c 10 Nov 2004 18:42:29 -0000
@@ -109,7 +109,7 @@
} else {
sz_strlcat(s, "/");
}
- sz_strlcat(s, tile_types[ptile->terrain].special_1_name);
+ sz_strlcat(s, tile_types[ptile->terrain].special[0].name);
}
if (tile_has_special(ptile, S_SPECIAL_2)) {
if (first) {
@@ -118,7 +118,7 @@
} else {
sz_strlcat(s, "/");
}
- sz_strlcat(s, tile_types[ptile->terrain].special_2_name);
+ sz_strlcat(s, tile_types[ptile->terrain].special[1].name);
}
if (!first) {
sz_strlcat(s, ")");
@@ -728,9 +728,9 @@
int get_tile_food_base(const struct tile *ptile)
{
if (tile_has_special(ptile, S_SPECIAL_1))
- return tile_types[ptile->terrain].food_special_1;
+ return tile_types[ptile->terrain].special[0].food;
else if (tile_has_special(ptile, S_SPECIAL_2))
- return tile_types[ptile->terrain].food_special_2;
+ return tile_types[ptile->terrain].special[1].food;
else
return tile_types[ptile->terrain].food;
}
@@ -741,9 +741,9 @@
int get_tile_shield_base(const struct tile *ptile)
{
if (tile_has_special(ptile, S_SPECIAL_1))
- return tile_types[ptile->terrain].shield_special_1;
+ return tile_types[ptile->terrain].special[0].shield;
else if(tile_has_special(ptile, S_SPECIAL_2))
- return tile_types[ptile->terrain].shield_special_2;
+ return tile_types[ptile->terrain].special[1].shield;
else
return tile_types[ptile->terrain].shield;
}
@@ -754,9 +754,9 @@
int get_tile_trade_base(const struct tile *ptile)
{
if (tile_has_special(ptile, S_SPECIAL_1))
- return tile_types[ptile->terrain].trade_special_1;
+ return tile_types[ptile->terrain].special[0].trade;
else if (tile_has_special(ptile, S_SPECIAL_2))
- return tile_types[ptile->terrain].trade_special_2;
+ return tile_types[ptile->terrain].special[1].trade;
else
return tile_types[ptile->terrain].trade;
}
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.224
diff -u -r1.224 map.h
--- common/map.h 10 Nov 2004 17:01:59 -0000 1.224
+++ common/map.h 10 Nov 2004 18:42:30 -0000
@@ -91,24 +91,14 @@
int shield;
int trade;
- const char *special_1_name; /* Translated string - doesn't need freeing. */
- char special_1_name_orig[MAX_LEN_NAME]; /* untranslated copy */
- int food_special_1;
- int shield_special_1;
- int trade_special_1;
-
- const char *special_2_name; /* Translated string - doesn't need freeing. */
- char special_2_name_orig[MAX_LEN_NAME]; /* untranslated copy */
- int food_special_2;
- int shield_special_2;
- int trade_special_2;
-
- /* I would put the above special data in this struct too,
- but don't want to make unnecessary changes right now --dwp */
+#define MAX_NUM_SPECIALS 2
struct {
+ const char *name; /* Translated string - doesn't need freeing. */
+ char name_orig[MAX_LEN_NAME];
+ int food, shield, trade;
char graphic_str[MAX_LEN_NAME];
char graphic_alt[MAX_LEN_NAME];
- } special[2];
+ } special[MAX_NUM_SPECIALS];
int road_trade_incr;
int road_time;
Index: manual/civmanual.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/manual/civmanual.c,v
retrieving revision 1.2
diff -u -r1.2 civmanual.c
--- manual/civmanual.c 8 Oct 2004 16:30:13 -0000 1.2
+++ manual/civmanual.c 10 Nov 2004 18:42:30 -0000
@@ -226,6 +226,7 @@
fprintf(doc, "</tr>\n");
terrain_type_iterate(id) {
struct tile_type *ptype = get_tile_type(id);
+ int s;
if (ptype->defense_bonus == 0) {
/* Must be a disabled piece of terrain */
@@ -238,19 +239,14 @@
fprintf(doc, "<td>%d / %d / %d</td>",
ptype->food, ptype->shield, ptype->trade);
- fprintf(doc, "<td>%s%s%s %s</td>", IMAGE_BEGIN,
- ptype->special[0].graphic_str, IMAGE_END,
- ptype->special_1_name);
- fprintf(doc, "<td>%d / %d / %d</td>",
- ptype->food_special_1, ptype->shield_special_1,
- ptype->trade_special_1);
-
- fprintf(doc, "<td>%s%s%s", IMAGE_BEGIN,
- ptype->special[1].graphic_str, IMAGE_END);
- fprintf(doc, " %s</td>", ptype->special_2_name);
- fprintf(doc, "<td>%d / %d / %d</td>",
- ptype->food_special_2, ptype->shield_special_2,
- ptype->trade_special_2);
+ for (s = 0; s < MAX_NUM_SPECIALS; s++) {
+ fprintf(doc, "<td>%s%s%s %s</td>", IMAGE_BEGIN,
+ ptype->special[s].graphic_str, IMAGE_END,
+ ptype->special[s].name);
+ fprintf(doc, "<td>%d / %d / %d</td>",
+ ptype->special[s].food, ptype->special[s].shield,
+ ptype->special[s].trade);
+ }
fprintf(doc, "<td>%d</td>\n", ptype->movement_cost);
fprintf(doc, "<td>%d0%%</td><td>%d</td><td>%d</td><td>%d</td>\n",
Index: server/ruleset.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/ruleset.c,v
retrieving revision 1.198
diff -u -r1.198 ruleset.c
--- server/ruleset.c 10 Nov 2004 17:02:00 -0000 1.198
+++ server/ruleset.c 10 Nov 2004 18:42:31 -0000
@@ -1607,7 +1607,7 @@
terrain_type_iterate(i) {
struct tile_type *t = &(tile_types[i]);
- char *s1_name, *s2_name, **slist;
+ char **slist;
sz_strlcpy(t->graphic_str,
secfile_lookup_str(file,"%s.graphic", sec[i]));
@@ -1638,26 +1638,23 @@
t->shield = secfile_lookup_int(file, "%s.shield", sec[i]);
t->trade = secfile_lookup_int(file, "%s.trade", sec[i]);
- s1_name = secfile_lookup_str(file, "%s.special_1_name", sec[i]);
- name_strlcpy(t->special_1_name_orig, s1_name);
- if (0 == strcmp(t->special_1_name_orig, "none")) {
- t->special_1_name_orig[0] = '\0';
- }
- t->special_1_name = t->special_1_name_orig;
- t->food_special_1 = secfile_lookup_int(file, "%s.food_special_1",
sec[i]);
- t->shield_special_1 = secfile_lookup_int(file, "%s.shield_special_1",
sec[i]);
- t->trade_special_1 = secfile_lookup_int(file, "%s.trade_special_1",
sec[i]);
-
- s2_name = secfile_lookup_str(file, "%s.special_2_name", sec[i]);
- name_strlcpy(t->special_2_name_orig, s2_name);
- if (0 == strcmp(t->special_2_name_orig, "none")) {
- t->special_2_name_orig[0] = '\0';
- }
- t->special_2_name = t->special_2_name_orig;
- t->food_special_2 = secfile_lookup_int(file, "%s.food_special_2",
sec[i]);
- t->shield_special_2 = secfile_lookup_int(file, "%s.shield_special_2",
sec[i]);
- t->trade_special_2 = secfile_lookup_int(file, "%s.trade_special_2",
sec[i]);
- for(j=0; j<2; j++) {
+ for (j = 0; j < MAX_NUM_SPECIALS; j++) {
+ char *name = secfile_lookup_str(file, "%s.special_%d_name",
+ sec[i], j + 1);
+
+ name_strlcpy(t->special[j].name_orig, name);
+ if (0 == strcmp(t->special[j].name_orig, "none")) {
+ t->special[j].name_orig[0] = '\0';
+ }
+ t->special[j].name = t->special[j].name_orig;
+ t->special[j].food = secfile_lookup_int(file, "%s.food_special_%d",
+ sec[i], j + 1);
+ t->special[j].shield = secfile_lookup_int(file,
+ "%s.shield_special_%d",
+ sec[i], j + 1);
+ t->special[j].trade = secfile_lookup_int(file, "%s.trade_special_%d",
+ sec[i], j + 1);
+
sz_strlcpy(t->special[j].graphic_str,
secfile_lookup_str(file,"%s.graphic_special_%d",
sec[i], j+1));
@@ -2961,15 +2958,15 @@
packet.shield = t->shield;
packet.trade = t->trade;
- sz_strlcpy(packet.special_1_name, t->special_1_name_orig);
- packet.food_special_1 = t->food_special_1;
- packet.shield_special_1 = t->shield_special_1;
- packet.trade_special_1 = t->trade_special_1;
-
- sz_strlcpy(packet.special_2_name, t->special_2_name_orig);
- packet.food_special_2 = t->food_special_2;
- packet.shield_special_2 = t->shield_special_2;
- packet.trade_special_2 = t->trade_special_2;
+ sz_strlcpy(packet.special_1_name, t->special[0].name_orig);
+ packet.food_special_1 = t->special[0].food;
+ packet.shield_special_1 = t->special[0].shield;
+ packet.trade_special_1 = t->special[0].trade;
+
+ sz_strlcpy(packet.special_2_name, t->special[1].name_orig);
+ packet.food_special_2 = t->special[1].food;
+ packet.shield_special_2 = t->special[1].shield;
+ packet.trade_special_2 = t->special[1].trade;
sz_strlcpy(packet.graphic_str_special_1, t->special[0].graphic_str);
sz_strlcpy(packet.graphic_alt_special_1, t->special[0].graphic_alt);
Index: server/generator/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/generator/mapgen.c,v
retrieving revision 1.15
diff -u -r1.15 mapgen.c
--- server/generator/mapgen.c 15 Oct 2004 09:39:06 -0000 1.15
+++ server/generator/mapgen.c 10 Nov 2004 18:42:31 -0000
@@ -1197,20 +1197,20 @@
if (!is_ocean(ttype)
&& !is_special_close(ptile)
&& myrand(1000) < prob) {
- if (tile_types[ttype].special_1_name[0] != '\0'
- && (tile_types[ttype].special_2_name[0] == '\0'
+ if (tile_types[ttype].special[0].name[0] != '\0'
+ && (tile_types[ttype].special[1].name[0] == '\0'
|| (myrand(100) < 50))) {
map_set_special(ptile, S_SPECIAL_1);
- } else if (tile_types[ttype].special_2_name[0] != '\0') {
+ } else if (tile_types[ttype].special[1].name[0] != '\0') {
map_set_special(ptile, S_SPECIAL_2);
}
} else if (is_ocean(ttype) && near_safe_tiles(ptile)
&& myrand(1000) < prob && !is_special_close(ptile)) {
- if (tile_types[ttype].special_1_name[0] != '\0'
- && (tile_types[ttype].special_2_name[0] == '\0'
+ if (tile_types[ttype].special[0].name[0] != '\0'
+ && (tile_types[ttype].special[1].name[0] == '\0'
|| (myrand(100) < 50))) {
map_set_special(ptile, S_SPECIAL_1);
- } else if (tile_types[ttype].special_2_name[0] != '\0') {
+ } else if (tile_types[ttype].special[1].name[0] != '\0') {
map_set_special(ptile, S_SPECIAL_2);
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#10970) put terrain specials in an array,
Jason Short <=
|
|