[Freeciv-Dev] (PR#2549) enum citizen_type with citizens styles
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: |
undisclosed-recipients:; |
Subject: |
[Freeciv-Dev] (PR#2549) enum citizen_type with citizens styles |
From: |
"Rafa³ Bursig via RT" <rt@xxxxxxxxxxxxxx> |
Date: |
Wed, 11 Dec 2002 10:16:41 -0800 |
Reply-to: |
rt@xxxxxxxxxxxxxx |
This is citizens style patch integrated with new citizen_type enum and
get_citizen_sprite funct.
Is there any way to speed up get_city_style(...) funct. ( exp: use
player->city_style ) ?
Rafal
----------------------------------------------------------------------
Zwieksz swoje szanse na sukces o mozliwosci nowej, lepszej poczty...
Poczta PLUS i PREMIUM >>> http://link.interia.pl/f16a1
diff -r -u fc3/client/packhand.c fc2/client/packhand.c
--- fc3/client/packhand.c Wed Dec 11 16:35:14 2002
+++ fc2/client/packhand.c Wed Dec 11 14:08:36 2002
@@ -1677,6 +1679,7 @@
int i;
tilespec_free_city_tiles(game.styles_count);
+ citizens_styles_free(game.styles_count);
ruleset_data_free();
game.aqueduct_size = packet->aqueduct_size;
@@ -1708,6 +1711,7 @@
game.playable_nation_count = packet->playable_nation_count;
city_styles_alloc(packet->style_count);
+ citizens_styles_alloc(packet->style_count);
tilespec_alloc_city_tiles(game.styles_count);
for(i = 0; i < MAX_NUM_TEAMS; i++) {
@@ -2185,6 +2189,8 @@
sz_strlcpy(cs->name, packet->name);
sz_strlcpy(cs->graphic, packet->graphic);
sz_strlcpy(cs->graphic_alt, packet->graphic_alt);
+ sz_strlcpy(cs->citizens_graphic, packet->citizens_graphic);
+ sz_strlcpy(cs->citizens_graphic_alt, packet->citizens_graphic_alt);
tilespec_setup_city_tiles(id);
}
diff -r -u fc3/client/tilespec.c fc2/client/tilespec.c
--- fc3/client/tilespec.c Wed Dec 11 17:49:42 2002
+++ fc2/client/tilespec.c Wed Dec 11 16:33:55 2002
@@ -648,30 +658,7 @@
SET_SPRITE(dither_tile, "t.dither_tile");
SET_SPRITE(coast_color, "t.coast_color");
}
-
- /* Load the citizen sprite graphics. */
- for (i = 0; i < NUM_TILES_CITIZEN; i++) {
- my_snprintf(buffer, sizeof(buffer), "citizen.%s", get_citizen_name(i));
- sprites.citizen[i].sprite[0] = hash_lookup_data(sprite_hash, buffer);
- if (sprites.citizen[i].sprite[0]) {
- /* If this form exists, use it as the only sprite. This allows
- * backwards compatability with tilesets that use e.g.,
- * citizen.entertainer. */
- sprites.citizen[i].count = 1;
- continue;
- }
- for (j = 0; j < NUM_TILES_CITIZEN; j++) {
- my_snprintf(buffer, sizeof(buffer), "citizen.%s_%d",
- get_citizen_name(i), j);
- sprites.citizen[i].sprite[j] = hash_lookup_data(sprite_hash, buffer);
- if (!sprites.citizen[i].sprite[j]) {
- break;
- }
- }
- sprites.citizen[i].count = j;
- assert(j > 0);
- }
-
+
SET_SPRITE(spaceship.solar_panels, "spaceship.solar_panels");
SET_SPRITE(spaceship.life_support, "spaceship.life_support");
SET_SPRITE(spaceship.habitation, "spaceship.habitation");
@@ -1046,6 +1035,85 @@
}
/**********************************************************************
+ Set tile_type sprite values; should only happen after
+ tilespec_load_tiles().
+***********************************************************************/
+static void tilespec_setup_citizens_style(int style)
+{
+ char tag[64];
+ char alt[64];
+ char alt_buf[32] = ".";
+ int i , j;
+
+ if ( strcmp( "generic" , city_styles[style].citizens_graphic_alt ))
+ {
+ my_snprintf( alt_buf , sizeof(alt_buf) , ".%s_",
+ city_styles[style].citizens_graphic_alt );
+ }
+
+/* Load the citizen sprite graphics. */
+ for (i = 0; i < NUM_TILES_CITIZEN; i++) {
+
+ my_snprintf(tag, sizeof(tag), "citizen.%s_%s",
+ city_styles[style].citizens_graphic ,get_citizen_name(i));
+ my_snprintf(alt, sizeof(alt), "citizen%s%s", alt_buf ,get_citizen_name(i));
+ sprites.citizen[i].sprite[style][0] = lookup_sprite_tag_alt(tag, alt,
+ TRUE, "citizen", get_citizen_name(i) );
+ if (sprites.citizen[i].sprite[style][0]) {
+ /* If this form exists, use it as the only sprite. This allows
+ * backwards compatability with tilesets that use e.g.,
+ * citizen.entertainer. */
+ sprites.citizen[i].count[style] = 1;
+ continue;
+ }
+ for (j = 0; j < NUM_TILES_CITIZEN; j++) {
+ my_snprintf(tag, sizeof(tag), "citizen.%s_%s_%d",
+ city_styles[style].citizens_graphic ,get_citizen_name(i) , j );
+ my_snprintf(alt, sizeof(alt), "citizen%s%s_%d", alt_buf
,get_citizen_name(i), j);
+ sprites.citizen[i].sprite[style][j] = lookup_sprite_tag_alt(tag, alt,
+ TRUE, "citizen", get_citizen_name(i) );
+ if (!sprites.citizen[i].sprite[style][j]) {
+ break;
+ }
+ }
+ sprites.citizen[i].count[style] = j;
+ assert(j > 0);
+ }
+}
+
+/**********************************************************************
+ alloc memory for citizens style sprites
+***********************************************************************/
+void citizens_styles_alloc( int count )
+{
+ int type, style;
+ for (type = 0; type < NUM_TILES_CITIZEN; type++) {
+ sprites.citizen[type].count = fc_calloc( count , sizeof(int) );
+ sprites.citizen[type].sprite = fc_calloc( count , sizeof( struct Sprite **
) );
+ for ( style = 0; style < count; style++ ) {
+ /* MAX_NUM_CITIZEN_SPRITES should be defined in tilespec file */
+ sprites.citizen[type].sprite[style] =
+ fc_calloc( MAX_NUM_CITIZEN_SPRITES , sizeof( struct Sprite * ) );
+ }
+ }
+}
+
+void citizens_styles_free(int count)
+{
+ int type, style;
+ for (type = 0; type < NUM_TILES_CITIZEN; type++) {
+ for ( style = 0; style < count; style++ ) {
+ free( sprites.citizen[type].sprite[style] );
+ sprites.citizen[type].sprite[style] = NULL;
+ }
+ free( sprites.citizen[type].sprite );
+ sprites.citizen[type].sprite = NULL;
+ free( sprites.citizen[type].count );
+ sprites.citizen[type].count = NULL;
+ }
+}
+
+/**********************************************************************
...
***********************************************************************/
static struct Sprite *get_city_nation_flag_sprite(struct city *pcity)
@@ -1909,7 +1977,8 @@
void tilespec_setup_city_tiles(int style)
{
tilespec_setup_style_tile(style, city_styles[style].graphic);
-
+ tilespec_setup_citizens_style( style );
+
if (city_styles[style].tiles_num == 0) {
/* no tiles found, try alternate */
freelog(LOG_NORMAL, "No tiles for %s style, trying alternate %s style",
@@ -2128,7 +2197,9 @@
struct Sprite *get_citizen_sprite(enum citizen_type citizen,
int cnum, struct city *pcity)
{
+ int style;
assert(citizen >= 0 && citizen < NUM_TILES_CITIZEN);
- cnum %= sprites.citizen[citizen].count;
- return sprites.citizen[citizen].sprite[cnum];
+ style = get_city_style( pcity );
+ cnum %= sprites.citizen[citizen].count[style];
+ return sprites.citizen[citizen].sprite[style][cnum];
}
diff -r -u fc3/client/tilespec.h fc2/client/tilespec.h
--- fc3/client/tilespec.h Wed Dec 11 17:49:42 2002
+++ fc2/client/tilespec.h Wed Dec 11 13:57:39 2002
@@ -47,6 +48,8 @@
void tilespec_setup_city_tiles(int style);
void tilespec_alloc_city_tiles(int count);
void tilespec_free_city_tiles(int count);
+void citizens_styles_alloc( int count );
+void citizens_styles_free( int count );
/* Gfx support */
@@ -104,8 +107,8 @@
struct {
/* Each citizen type has up to MAX_NUM_CITIZEN_SPRITES different
* sprites, as defined by the tileset. */
- int count;
- struct Sprite *sprite[MAX_NUM_CITIZEN_SPRITES];
+ int *count;
+ struct Sprite ***sprite;
} citizen[NUM_TILES_CITIZEN];
struct {
struct Sprite
diff -r -u fc3/common/city.h fc2/common/city.h
--- fc3/common/city.h Sun Dec 8 19:57:19 2002
+++ fc2/common/city.h Tue Dec 10 01:53:57 2002
@@ -312,6 +312,8 @@
char name_orig[MAX_LEN_NAME]; /* untranslated */
char graphic[MAX_LEN_NAME];
char graphic_alt[MAX_LEN_NAME];
+ char citizens_graphic[MAX_LEN_NAME];
+ char citizens_graphic_alt[MAX_LEN_NAME];
int techreq; /* tech required to use a style */
int replaced_by; /* index to replacing style */
/* client side-only: */
diff -r -u fc3/common/packets.c fc2/common/packets.c
--- fc3/common/packets.c Wed Dec 11 16:35:14 2002
+++ fc2/common/packets.c Tue Dec 10 01:53:58 2002
@@ -2650,6 +2650,11 @@
dio_put_string(&dout, packet->graphic);
dio_put_string(&dout, packet->graphic_alt);
+ if (has_capability("delux", pc->capability)) {
+ dio_put_string(&dout, packet->citizens_graphic);
+ dio_put_string(&dout, packet->citizens_graphic_alt);
+ }
+
SEND_PACKET_END;
}
@@ -2668,7 +2673,16 @@
dio_get_string(&din, packet->name, MAX_LEN_NAME);
dio_get_string(&din, packet->graphic, MAX_LEN_NAME);
dio_get_string(&din, packet->graphic_alt, MAX_LEN_NAME);
-
+
+ if (has_capability("delux", pc->capability)) {
+ dio_get_string(&din, packet->citizens_graphic, MAX_LEN_NAME);
+ dio_get_string(&din, packet->citizens_graphic_alt, MAX_LEN_NAME);
+ } else {
+ /* This is probably necessary */
+ packet->citizens_graphic[0] = '\0';
+ my_snprintf( packet->citizens_graphic_alt , MAX_LEN_NAME , "generic" );
+ }
+
RECEIVE_PACKET_END(packet);
}
diff -r -u fc3/common/packets.h fc2/common/packets.h
--- fc3/common/packets.h Wed Dec 11 16:35:14 2002
+++ fc2/common/packets.h Tue Dec 10 01:53:58 2002
@@ -799,6 +799,8 @@
char name[MAX_LEN_NAME];
char graphic[MAX_LEN_NAME];
char graphic_alt[MAX_LEN_NAME];
+ char citizens_graphic[MAX_LEN_NAME];
+ char citizens_graphic_alt[MAX_LEN_NAME];
int techreq;
int replaced_by;
};
diff -r -u fc3/data/default/cities.ruleset fc2/data/default/cities.ruleset
--- fc3/data/default/cities.ruleset Mon Nov 18 20:46:25 2002
+++ fc2/data/default/cities.ruleset Tue Dec 10 01:53:58 2002
@@ -19,6 +19,8 @@
;
; graphic = group of tiles to use, see cities spec for
; more info on city tiles
+; citizens_graphic = group of citizens tiles to use, see citizens/small
+; spec for more info on citizens tiles
; tech = technology required for style to be used
; replaced_by = which style replaced this one
@@ -26,34 +28,53 @@
name = _("European")
graphic = "city.european"
graphic_alt = "-"
+citizens_graphic = "ancient"
+citizens_graphic_alt = "generic"
tech = "None"
-replaced_by = "Industrial"
+replaced_by = "Renaissance"
[citystyle_classical]
name = _("Classical")
graphic = "city.classical"
graphic_alt = "-"
+citizens_graphic = "ancient"
+citizens_graphic_alt = "generic"
tech = "None"
-replaced_by = "Industrial"
+replaced_by = "Renaissance"
[citystyle_tropical]
name = _("Tropical")
graphic = "city.tropical"
graphic_alt = "city.european"
+citizens_graphic = "ancient"
+citizens_graphic_alt = "generic"
tech = "None"
-replaced_by = "Industrial"
+replaced_by = "Renaissance"
[citystyle_asian]
name = _("Asian")
graphic = "city.asian"
graphic_alt = "city.classical"
+citizens_graphic = "ancient"
+citizens_graphic_alt = "generic"
tech = "None"
+replaced_by = "Renaissance"
+
+[citystyle_renaissance]
+name = _("Renaissance")
+graphic = "city.industrial"
+graphic_alt = "-"
+citizens_graphic = "renaissance"
+citizens_graphic_alt = "generic"
+tech = "University"
replaced_by = "Industrial"
[citystyle_industrial]
name = _("Industrial")
graphic = "city.industrial"
graphic_alt = "-"
+citizens_graphic = "industrial"
+citizens_graphic_alt = "generic"
tech = "Railroad"
replaced_by = "Modern"
@@ -61,6 +82,8 @@
name = _("Modern")
graphic = "city.modern"
graphic_alt = "-"
+citizens_graphic = "modern"
+citizens_graphic_alt = "generic"
tech = "Automobile"
replaced_by = "PostModern"
@@ -68,5 +91,7 @@
name = _("PostModern")
graphic = "city.postmodern"
graphic_alt = "-"
+citizens_graphic = "postmodern"
+citizens_graphic_alt = "generic"
tech = "Superconductors"
replaced_by = "-"
diff -r -u fc3/server/ruleset.c fc2/server/ruleset.c
--- fc3/server/ruleset.c Wed Dec 11 16:35:14 2002
+++ fc2/server/ruleset.c Tue Dec 10 01:53:58 2002
@@ -2242,6 +2242,10 @@
secfile_lookup_str(file, "%s.graphic", styles[i]));
sz_strlcpy(city_styles[i].graphic_alt,
secfile_lookup_str(file, "%s.graphic_alt", styles[i]));
+ sz_strlcpy(city_styles[i].citizens_graphic,
+ secfile_lookup_str(file, "%s.citizens_graphic", styles[i]));
+ sz_strlcpy(city_styles[i].citizens_graphic_alt,
+ secfile_lookup_str(file, "%s.citizens_graphic_alt", styles[i]));
city_styles[i].techreq = lookup_tech(file, styles[i], "tech", TRUE,
filename, city_styles[i].name);
@@ -2685,6 +2689,8 @@
sz_strlcpy(city_p.name, city_styles[k].name_orig);
sz_strlcpy(city_p.graphic, city_styles[k].graphic);
sz_strlcpy(city_p.graphic_alt, city_styles[k].graphic_alt);
+ sz_strlcpy(city_p.citizens_graphic, city_styles[k].citizens_graphic );
+ sz_strlcpy(city_p.citizens_graphic_alt,
city_styles[k].citizens_graphic_alt );
lsend_packet_ruleset_city(dest, &city_p);
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#2549) enum citizen_type with citizens styles,
Rafa³ Bursig via RT <=
|
|