Freeciv-3.2
Loading...
Searching...
No Matches
tilespec.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14/***********************************************************************
15 Functions for handling the tilespec files which describe
16 the files and contents of tilesets.
17 original author: David Pfitzner <dwp@mso.anu.edu.au>
18***********************************************************************/
19
20#ifdef HAVE_CONFIG_H
21#include <fc_config.h>
22#endif
23
24#include <stdio.h>
25#include <stdlib.h> /* exit */
26#include <stdarg.h>
27#include <string.h>
28
29/* utility */
30#include "astring.h"
31#include "bitvector.h"
32#include "capability.h"
33#include "deprecations.h"
34#include "fcintl.h"
35#include "log.h"
36#include "mem.h"
37#include "rand.h"
38#include "registry.h"
39#include "shared.h"
40#include "string_vector.h"
41#include "support.h"
42
43/* common */
44#include "base.h"
45#include "effects.h"
46#include "game.h" /* game.control.num_city_styles */
47#include "government.h"
48#include "map.h"
49#include "movement.h"
50#include "nation.h"
51#include "player.h"
52#include "road.h"
53#include "specialist.h"
54#include "unit.h"
55#include "unitlist.h"
56
57/* client/include */
58#include "dialogs_g.h"
59#include "graphics_g.h"
60#include "gui_main_g.h"
61#include "mapview_g.h" /* For update_map_canvas_visible */
62#include "menu_g.h"
63#include "themes_g.h"
64
65/* client */
66#include "citydlg_common.h" /* For generate_citydlg_dimensions() */
67#include "client_main.h"
68#include "climap.h" /* For client_tile_get_known() */
69#include "colors_common.h"
70#include "control.h" /* For fill_xxx */
71#include "editor.h"
72#include "goto.h"
73#include "helpdata.h"
74#include "options.h" /* For fill_xxx */
75#include "svgflag.h"
76#include "themes_common.h"
77
78#include "tilespec.h"
79
80#define TILESPEC_CAPSTR "+Freeciv-3.2-tilespec duplicates_ok"
81/*
82 * Tilespec capabilities acceptable to this program:
83 *
84 * +Freeciv-3.2-tilespec
85 * - basic format for Freeciv versions 3.2.x; required
86 *
87 * +Freeciv-tilespec-3.2-Devel-YYYY.MMM.DD
88 * - tilespec of the development version at the given date
89 *
90 * duplicates_ok
91 * - we can handle existence of duplicate tags (lattermost tag which
92 * appears is used; tilesets which have duplicates should specify
93 * "duplicates_ok")
94 */
95
96#define SPEC_CAPSTR "+Freeciv-3.2-spec"
97/*
98 * Individual spec file capabilities acceptable to this program:
99 *
100 * +Freeciv-3.2-spec
101 * - basic format for Freeciv versions 3.2.x; required
102 */
103
104#define TILESPEC_SUFFIX ".tilespec"
105#define TILE_SECTION_PREFIX "tile_"
106
107/* This the way directional indices are now encoded: */
108#define MAX_INDEX_CARDINAL 64
109#define MAX_INDEX_HALF 16
110#define MAX_INDEX_VALID 256
111
112#define NUM_TILES_HP_BAR 11
113#define NUM_TILES_DIGITS 10
114#define NUM_TILES_SELECT 4
115#define MAX_NUM_UPKEEP_SPRITES 10
116
117#define SPECENUM_NAME extrastyle_id
118#define SPECENUM_VALUE0 ESTYLE_ROAD_ALL_SEPARATE
119#define SPECENUM_VALUE0NAME "RoadAllSeparate"
120#define SPECENUM_VALUE1 ESTYLE_ROAD_PARITY_COMBINED
121#define SPECENUM_VALUE1NAME "RoadParityCombined"
122#define SPECENUM_VALUE2 ESTYLE_ROAD_ALL_COMBINED
123#define SPECENUM_VALUE2NAME "RoadAllCombined"
124#define SPECENUM_VALUE3 ESTYLE_RIVER
125#define SPECENUM_VALUE3NAME "River"
126#define SPECENUM_VALUE4 ESTYLE_SINGLE1
127#define SPECENUM_VALUE4NAME "Single1"
128#define SPECENUM_VALUE5 ESTYLE_SINGLE2
129#define SPECENUM_VALUE5NAME "Single2"
130#define SPECENUM_VALUE6 ESTYLE_3LAYER
131#define SPECENUM_VALUE6NAME "3Layer"
132#define SPECENUM_VALUE7 ESTYLE_CARDINALS
133#define SPECENUM_VALUE7NAME "Cardinals"
134#define SPECENUM_COUNT ESTYLE_COUNT
135#include "specenum_gen.h"
136
137/* This could be moved to common/map.h if there's more use for it. */
141static const char direction4letters[4] = "udrl";
142/* This must correspond to enum edge_type. */
143static const char edge_name[EDGE_COUNT][3] = {"ns", "we", "ud", "lr"};
144
145static const int DIR4_TO_DIR8[4] =
147
154
156 CELL_WHOLE, /* Entire tile */
157 CELL_CORNER /* Corner of tile */
159
166
168 bool init;
169
170 char *name;
171
172 int num_layers; /* 1 thru MAX_NUM_LAYERS. */
173#define MAX_NUM_LAYERS 3
174
178
179#define MAX_NUM_MATCH_WITH 8
182 int match_indices; /* 0 = no match_type, 1 = no match_with */
183
185
188 struct sprite **cells;
189
190 /* List of those sprites in 'cells' that are allocated by some other
191 * means than load_sprite() and thus are not freed by unload_all_sprites(). */
194
196
197 int blending; /* layer, 0 = none */
199 struct sprite *blend[4]; /* indexed by a direction4 */
200};
201
203 struct sprite *sprite;
204};
205
213
219
221 /* Each citizen type has up to MAX_NUM_CITIZEN_SPRITES different
222 * sprites, as defined by the tileset. */
223 int count;
225};
226
231
236
238 struct sprite
240 *treaty_thumb[2], /* 0=disagree, 1=agree */
241 *arrow[ARROW_LAST], /* 0=right arrow, 1=plus, 2=minus */
242
244
246
247 /* The panel sprites for showing tax % allocations. */
249 *dither_tile; /* Only used for isometric view */
250
251 struct {
252 struct sprite
257
261
262 struct {
263 struct sprite *icon[U_LAST][ACTIVITY_LAST];
266
269
272
274 struct {
275 int hot_x, hot_y;
276 struct sprite *frame[NUM_CURSOR_FRAMES];
278 struct {
280 struct sprite *nuke;
282 struct {
285 struct sprite
287 *vet_lev[MAX_VET_LEVELS],
294 *go_to, /* goto is a C keyword :-) */
305 *battlegroup[MAX_NUM_BATTLEGROUPS],
310 struct {
311 struct sprite
315 struct {
316 struct sprite
319 *size_tens[NUM_TILES_DIGITS],
320 *size_hundreds[NUM_TILES_DIGITS],
321 *tile_foodnum[NUM_TILES_DIGITS],
322 *tile_shieldnum[NUM_TILES_DIGITS],
323 *tile_tradenum[NUM_TILES_DIGITS];
324 struct city_sprite
329 struct sprite_vector worked_tile_overlay;
330 struct sprite_vector unworked_tile_overlay;
334 struct {
335 struct {
337 struct sprite *turns[NUM_TILES_DIGITS];
338 struct sprite *turns_tens[NUM_TILES_DIGITS];
339 struct sprite *turns_hundreds[NUM_TILES_DIGITS];
343 struct {
347 struct {
348 struct sprite
351 *darkness[MAX_INDEX_CARDINAL]; /* First unused */
352 } tx; /* Terrain extra */
353 struct {
354 struct sprite
358 union {
359 struct sprite *single;
360 struct sprite *cardinals[MAX_INDEX_CARDINAL];
361 struct {
362 struct sprite
366 } bmf;
367 struct {
368 struct sprite
369 /* For extrastyles ESTYLE_ROAD_ALL_SEPARATE and ESTYLE_ROAD_PARITY_COMBINED */
371 *corner[8]; /* Indexed by direction; only non-cardinal dirs used. */
372 union {
373 /* For ESTYLE_ROAD_ALL_SEPARATE */
374 struct sprite *dir[8]; /* All entries used */
375 /* ESTYLE_ROAD_PARITY_COMBINED */
376 struct {
377 struct sprite
378 *even[MAX_INDEX_HALF], /* First unused */
379 *odd[MAX_INDEX_HALF]; /* First unused */
380 } combo;
381 /* ESTYLE_ALL_SEPARATE */
382 struct sprite *total[MAX_INDEX_VALID];
383 struct river_sprites rivers;
384 } ru;
386 } u;
388 struct {
389 struct sprite
392 *worked[EDGE_COUNT],
395 *selected[EDGE_COUNT],
396 *coastline[EDGE_COUNT],
397 *borders[EDGE_COUNT][2];
399 struct {
400 struct sprite_vector overlays;
402 struct {
403 struct sprite *color; /* Generic background color */
404 struct sprite *graphic; /* Generic background graphic */
406 struct {
407 struct sprite *grid_borders[EDGE_COUNT][2];
408 struct sprite *color;
409 struct sprite *background;
411
413};
414
415struct specfile {
416 struct sprite *big_sprite;
417 char *file_name;
418};
419
420#define SPECLIST_TAG specfile
421#define SPECLIST_TYPE struct specfile
422#include "speclist.h"
423
424#define specfile_list_iterate(list, pitem) \
425 TYPED_LIST_ITERATE(struct specfile, list, pitem)
426#define specfile_list_iterate_end LIST_ITERATE_END
427
428/*
429 * Information about an individual sprite. All fields except 'sprite' are
430 * filled at the time of the scan of the specfile. 'Sprite' is
431 * set/cleared on demand in load_sprite()/unload_sprite().
432 */
433struct small_sprite {
434 int ref_count;
435
436 /* The sprite is in this file. */
437 char *file;
438
439 /* Or, the sprite is in this file at the location. */
440 struct specfile *sf;
441 int x, y, width, height;
442
443 /* A little more (optional) data. */
444 int hot_x, hot_y;
445
446 struct sprite *sprite;
447};
448
449/* 'struct small_sprite_list' and related functions. */
450#define SPECLIST_TAG small_sprite
451#define SPECLIST_TYPE struct small_sprite
452#include "speclist.h"
453#define small_sprite_list_iterate(list, pitem) \
454 TYPED_LIST_ITERATE(struct small_sprite, list, pitem)
455#define small_sprite_list_iterate_end LIST_ITERATE_END
456
457/* 'struct sprite_hash' and related functions. */
458#define SPECHASH_TAG sprite
459#define SPECHASH_ASTR_KEY_TYPE
460#define SPECHASH_IDATA_TYPE struct small_sprite *
461#include "spechash.h"
462#define sprite_hash_iterate(hash, tag_name, sprite) \
463 TYPED_HASH_ITERATE(const char *, struct small_sprite *, \
464 hash, tag_name, sprite)
465#define sprite_hash_iterate_end HASH_ITERATE_END
466
467/* 'struct drawing_hash' and related functions. */
468static void drawing_data_destroy(struct drawing_data *draw);
469
470#define SPECHASH_TAG drawing
471#define SPECHASH_CSTR_KEY_TYPE
472#define SPECHASH_IDATA_TYPE struct drawing_data *
473#define SPECHASH_IDATA_FREE drawing_data_destroy
474#include "spechash.h"
475
476#define SPECHASH_TAG estyle
477#define SPECHASH_ASTR_KEY_TYPE
478#define SPECHASH_ENUM_DATA_TYPE extrastyle_id
479#include "spechash.h"
480
481struct tileset {
482 char name[512];
486
487 char *summary;
489 float scale;
490
492
494
498
503
506
508
510
513
519
532
533#define NUM_CORNER_DIRS 4
534#define TILES_PER_CORNER 4
538
543
546
547 /* This hash table maps tilespec tags to struct small_sprites. */
549
550 /* This hash table maps terrain graphic strings to drawing data. */
552
554
556
558
560
562
565};
566
569
571
572static bool tileset_update = FALSE;
573
574static struct tileset *tileset_read_toplevel(const char *tileset_name,
575 bool verbose, int topology_id,
576 float scale);
577
578static int fill_unit_type_sprite_array(const struct tileset *t,
579 struct drawn_sprite *sprs,
580 const struct unit_type *putype,
581 enum unit_activity activity,
582 enum direction8 facing);
583static int fill_unit_sprite_array(const struct tileset *t,
584 struct drawn_sprite *sprs,
585 const struct unit *punit,
586 int stack, bool backdrop);
587static bool load_river_sprites(struct tileset *t,
588 struct river_sprites *store, const char *tag_pfx);
589
590static void tileset_setup_base(struct tileset *t,
591 const struct extra_type *pextra,
592 const char *tag);
593static void tileset_setup_road(struct tileset *t,
594 struct extra_type *pextra,
595 const char *tag);
596
597static bool is_extra_drawing_enabled(struct extra_type *pextra);
598
599static int fill_basic_road_sprite_array(const struct tileset *t,
600 struct drawn_sprite *sprs,
601 const struct extra_type *pextra);
602static int fill_basic_base_sprite_array(const struct tileset *t,
603 struct drawn_sprite *sprs,
604 const struct extra_type *pextra);
605
606static void tileset_player_free(struct tileset *t, int plrid);
607
608static void tileset_setup_specialist_type(struct tileset *t,
609 struct citizen_set *set,
611 const char *tag_group,
612 const char *set_name,
613 bool required);
615static void tileset_setup_citizen_types(struct tileset *t,
616 struct citizen_set *set,
617 const char *tag_group,
618 const char *set_name,
619 bool required);
620
621/************************************************************************/
624void tileset_error(enum log_level level, const char *tset_name,
625 const char *format, ...)
626{
627 char buf[2048];
628 va_list args;
629
630 va_start(args, format);
631 fc_vsnprintf(buf, sizeof(buf), format, args);
632 va_end(args);
633
634 log_base(level, "%s", buf);
635
636 if (level <= LOG_NORMAL) {
638
639 if (level == LOG_FATAL) {
641 }
642 }
643}
644
645/************************************************************************/
648static struct drawing_data *drawing_data_new(void)
649{
650 struct drawing_data *draw = fc_calloc(1, sizeof(*draw));
651
652 draw->name = NULL;
653
654 return draw;
655}
656
657/************************************************************************/
661{
662 int i;
663
665
666 if (draw->name != NULL) {
667 free(draw->name);
668 }
669 for (i = 0; i < 4; i++) {
670 if (draw->blend[i]) {
671 free_sprite(draw->blend[i]);
672 }
673 }
674 for (i = 0; i < draw->num_layers; i++) {
675 int vec_size = sprite_vector_size(&draw->layer[i].allocated);
676 int j;
677
678 for (j = 0; j < vec_size; j++) {
679 free_sprite(draw->layer[i].allocated.p[j]);
680 }
681
682 sprite_vector_free(&draw->layer[i].base);
683 sprite_vector_free(&draw->layer[i].allocated);
684 free(draw->layer[i].cells);
685 }
686 free(draw);
687}
688
689/************************************************************************/
692struct tileset *get_tileset(void)
693{
694 if (unscaled_tileset != NULL) {
695 return unscaled_tileset;
696 } else {
697 return tileset;
698 }
699}
700
701/************************************************************************/
704const char *tileset_basename(const struct tileset *t)
705{
706 return t->name;
707}
708
709/************************************************************************/
712bool tileset_is_isometric(const struct tileset *t)
713{
714 return t->type == TS_ISOMETRIC;
715}
716
717/************************************************************************/
721int tileset_hex_width(const struct tileset *t)
722{
723 return t->hex_width;
724}
725
726/************************************************************************/
730int tileset_hex_height(const struct tileset *t)
731{
732 return t->hex_height;
733}
734
735/************************************************************************/
753int tileset_tile_width(const struct tileset *t)
754{
755 return t->normal_tile_width;
756}
757
758/************************************************************************/
765int tileset_tile_height(const struct tileset *t)
766{
767 return t->normal_tile_height;
768}
769
770/************************************************************************/
777{
778 return t->full_tile_width;
779}
780
781/************************************************************************/
790{
791 return t->full_tile_height;
792}
793
794/************************************************************************/
797int tileset_unit_width(const struct tileset *t)
798{
799 return t->unit_tile_width;
800}
801
802/************************************************************************/
805int tileset_unit_height(const struct tileset *t)
806{
807 return t->unit_tile_height;
808}
809
810/************************************************************************/
813static int calculate_max_upkeep_height(const struct tileset *t)
814{
815 int i;
816 int max = 0;
817
818 for (i = 0; i < MAX_NUM_UPKEEP_SPRITES; i++) {
819 if (t->sprites.upkeep.unhappy[i] != NULL) {
820 int width, height;
821
822 /* TODO: We want only height, getting the width might waste CPU
823 * depending on gui-specific implementation. */
825
826 max = MAX(max, height);
827 }
828 }
829
831 for (i = 0; i < MAX_NUM_UPKEEP_SPRITES; i++) {
832 if (t->sprites.upkeep.output[o][i] != NULL) {
833 int width, height;
834
835 /* TODO: We want only height, getting the width might waste CPU
836 * depending on gui-specific implementation. */
838
839 max = MAX(max, height);
840 }
841 }
843
844 return max;
845}
846
847/************************************************************************/
850static int tileset_upkeep_height(const struct tileset *t)
851{
852 /* Return cached value */
853 return t->max_upkeep_height;
854}
855
856/************************************************************************/
866
867/************************************************************************/
878
879/************************************************************************/
883{
884 return t->unit_upkeep_offset_y;
885}
886
887/************************************************************************/
892{
894}
895
896/************************************************************************/
902{
903 return t->small_sprite_width;
904}
905
906/************************************************************************/
911{
912 return t->citybar_offset_y;
913}
914
915/************************************************************************/
920{
921 return t->tilelabel_offset_y;
922}
923
924/************************************************************************/
927float tileset_scale(const struct tileset *t)
928{
929 return tileset->scale;
930}
931
932/************************************************************************/
938{
939 return t->small_sprite_height;
940}
941
942/************************************************************************/
947const char *tileset_main_intro_filename(const struct tileset *t)
948{
949 return t->main_intro_filename;
950}
951
952/************************************************************************/
956{
957 return t->sprites.city.worked_tile_overlay.size;
958}
959
960/************************************************************************/
964{
965 return FOG_AUTO == t->fogstyle;
966}
967
968/************************************************************************/
971static struct tileset *tileset_new(void)
972{
973 struct tileset *t = fc_calloc(1, sizeof(*t));
974
977
978 return t;
979}
980
981/************************************************************************/
985static const char *dir_get_tileset_name(enum direction8 dir)
986{
987 switch (dir) {
988 case DIR8_NORTH:
989 return "n";
990 case DIR8_NORTHEAST:
991 return "ne";
992 case DIR8_EAST:
993 return "e";
994 case DIR8_SOUTHEAST:
995 return "se";
996 case DIR8_SOUTH:
997 return "s";
998 case DIR8_SOUTHWEST:
999 return "sw";
1000 case DIR8_WEST:
1001 return "w";
1002 case DIR8_NORTHWEST:
1003 return "nw";
1004 }
1005 log_error("Wrong direction8 variant: %d.", dir);
1006 return "";
1007}
1008
1009/************************************************************************/
1012static enum direction8 dir_by_tileset_name(const char *str)
1013{
1014 enum direction8 dir;
1015
1016 for (dir = direction8_begin();
1017 dir != direction8_end();
1018 dir = direction8_next(dir)) {
1019 if (strcmp(dir_get_tileset_name(dir), str) == 0) {
1020 return dir;
1021 }
1022 }
1023
1024 return direction8_invalid();
1025}
1026
1027/************************************************************************/
1030static bool is_valid_tileset_dir(const struct tileset *t,
1031 enum direction8 dir)
1032{
1033 if (t->hex_width > 0) {
1034 return dir != DIR8_NORTHEAST && dir != DIR8_SOUTHWEST;
1035 } else if (t->hex_height > 0) {
1036 return dir != DIR8_NORTHWEST && dir != DIR8_SOUTHEAST;
1037 } else {
1038 return TRUE;
1039 }
1040}
1041
1042/************************************************************************/
1048static bool is_cardinal_tileset_dir(const struct tileset *t,
1049 enum direction8 dir)
1050{
1051 if (t->hex_width > 0 || t->hex_height > 0) {
1052 return is_valid_tileset_dir(t, dir);
1053 } else {
1054 return (dir == DIR8_NORTH || dir == DIR8_EAST
1055 || dir == DIR8_SOUTH || dir == DIR8_WEST);
1056 }
1057}
1058
1059/************************************************************************/
1064{
1065 int idx;
1066
1067 if ((actual_topology & TF_HEX)
1068 && (actual_topology & TF_ISO)) {
1069 idx = TS_TOPO_ISOHEX;
1070 } else if (actual_topology & TF_ISO) {
1071 idx = TS_TOPO_SQUARE;
1072 } else if (actual_topology & TF_HEX) {
1073 idx = TS_TOPO_HEX;
1074 } else {
1075 idx = TS_TOPO_SQUARE;
1076 }
1077
1078 return idx;
1079}
1080
1081/************************************************************************/
1086{
1087 switch (idx) {
1088 case TS_TOPO_SQUARE:
1089 return TF_ISO;
1090 case TS_TOPO_HEX:
1091 return TF_HEX;
1092 case TS_TOPO_ISOHEX:
1093 return TF_HEX | TF_ISO;
1094 }
1095
1096 return 0;
1097}
1098
1099/************************************************************************/
1103const struct strvec *get_tileset_list(const struct option *poption)
1104{
1105 static struct strvec *tilesets[3] = { NULL, NULL, NULL };
1107 int idx;
1108
1109 idx = ts_topology_index(topo);
1110
1112
1113 if (tilesets[idx] == NULL) {
1114 /* Note: this means you must restart the client after installing a new
1115 tileset. */
1117
1118 tilesets[idx] = strvec_new();
1119 strvec_iterate(list, file) {
1120 struct tileset *t = tileset_read_toplevel(file, FALSE, topo, 1.0f);
1121
1122 if (t) {
1123 strvec_append(tilesets[idx], file);
1124 tileset_free(t);
1125 }
1128 }
1129
1130 return tilesets[idx];
1131}
1132
1133/************************************************************************/
1140static char *tilespec_fullname(const char *tileset_name)
1141{
1142 if (tileset_name) {
1144 const char *dname;
1145
1146 fc_snprintf(fname, sizeof(fname),
1147 "%s%s", tileset_name, TILESPEC_SUFFIX);
1148
1150
1151 if (dname) {
1152 return fc_strdup(dname);
1153 }
1154 }
1155
1156 return NULL;
1157}
1158
1159/************************************************************************/
1165 const char *which,
1166 const char *us_capstr,
1167 const char *filename,
1168 bool verbose)
1169{
1170 enum log_level level = verbose ? LOG_ERROR : LOG_DEBUG;
1171
1172 const char *file_capstr = secfile_lookup_str(file, "%s.options", which);
1173
1174 if (NULL == file_capstr) {
1175 log_base(level, "\"%s\": %s file doesn't have a capability string",
1176 filename, which);
1177 return FALSE;
1178 }
1180 log_base(level, "\"%s\": %s file appears incompatible:",
1181 filename, which);
1182 log_base(level, " datafile options: %s", file_capstr);
1183 log_base(level, " supported options: %s", us_capstr);
1184 return FALSE;
1185 }
1187 log_base(level, "\"%s\": %s file requires option(s) "
1188 "that client doesn't support:", filename, which);
1189 log_base(level, " datafile options: %s", file_capstr);
1190 log_base(level, " supported options: %s", us_capstr);
1191 return FALSE;
1192 }
1193
1194 return TRUE;
1195}
1196
1197/************************************************************************/
1202static void tileset_free_toplevel(struct tileset *t)
1203{
1204 int i, j;
1205
1206 if (t->main_intro_filename) {
1209 }
1210
1211 if (t->preferred_themes) {
1212 for (i = 0; i < t->num_preferred_themes; i++) {
1213 free(t->preferred_themes[i]);
1214 }
1217 }
1218 t->num_preferred_themes = 0;
1219
1220 if (t->tile_hash) {
1222 t->tile_hash = NULL; /* Helpful for sanity. */
1223 }
1224 if (t->estyle_hash) {
1226 t->estyle_hash = NULL;
1227 }
1228 for (i = 0; i < ESTYLE_COUNT; i++) {
1229 if (t->style_lists[i] != NULL) {
1231 t->style_lists[i] = NULL;
1232 }
1233 }
1234
1235 if (t->flagged_bases_list != NULL) {
1238 }
1239
1240 for (i = 0; i < MAX_NUM_LAYERS; i++) {
1241 struct tileset_layer *tslp = &t->layers[i];
1242
1243 if (tslp->match_types) {
1244 for (j = 0; j < tslp->match_count; j++) {
1245 free(tslp->match_types[j]);
1246 }
1247 free(tslp->match_types);
1248 tslp->match_types = NULL;
1249 }
1250 }
1251
1252 if (t->color_system) {
1254 t->color_system = NULL;
1255 }
1256
1257 if (t->summary != NULL) {
1258 free(t->summary);
1259 t->summary = NULL;
1260 }
1261 if (t->description != NULL) {
1262 free(t->description);
1263 t->description = NULL;
1264 }
1265 if (t->for_ruleset != NULL) {
1266 free(t->for_ruleset);
1267 t->for_ruleset = NULL;
1268 }
1269}
1270
1271/************************************************************************/
1274void tileset_free(struct tileset *t)
1275{
1276 int i;
1277
1280 for (i = 0; i < ARRAY_SIZE(t->sprites.player); i++) {
1282 }
1285 free(t);
1286}
1287
1288/************************************************************************/
1296bool tilespec_try_read(const char *tileset_name, bool verbose, int topo_id,
1297 bool global_default)
1298{
1299 bool original;
1300
1301 if (tileset_name == NULL
1303 topo_id, 1.0f))) {
1305
1306 original = FALSE;
1307 strvec_iterate(list, file) {
1308 struct tileset *t = tileset_read_toplevel(file, FALSE, topo_id, 1.0f);
1309
1310 if (t) {
1311 if (!tileset) {
1312 tileset = t;
1313 } else if (t->priority > tileset->priority
1314 || (topo_id >= 0
1317 tileset = t;
1318 } else {
1319 tileset_free(t);
1320 }
1321 }
1324
1325 if (tileset == NULL) {
1326 tileset_error(LOG_FATAL, NULL, _("No usable default tileset found, aborting!"));
1327 }
1328
1329 log_verbose("Trying tileset \"%s\".", tileset->name);
1330 } else {
1331 original = TRUE;
1332 }
1334
1335 if (global_default) {
1337 }
1338
1339 return original;
1340}
1341
1342/************************************************************************/
1356 bool game_fully_initialized, float scale)
1357{
1358 int id;
1359 struct tile *center_tile;
1360 enum client_states state = client_state();
1362 char tileset_name[strlen(name) + 1], old_name[strlen(tileset->name) + 1];
1363 bool new_tileset_in_use;
1364 int ts_topo;
1365
1366 /* Make local copies since these values may be freed down below */
1368 sz_strlcpy(old_name, tileset->name);
1369
1370 log_normal(_("Loading tileset \"%s\"."), tileset_name);
1371
1372 /* Step 0: Record old data.
1373 *
1374 * We record the current mapcanvas center, etc.
1375 */
1377
1378 /* Step 1: Cleanup.
1379 *
1380 * Free old tileset or keep it in memory if we are loading the same
1381 * tileset with scaling and old one was not scaled.
1382 */
1383
1384 if (strcmp(tileset_name, old_name) == 0 && tileset->scale == 1.0f
1385 && scale != 1.0f) {
1386 if (unscaled_tileset) {
1388 }
1390 } else {
1392 }
1393
1394 /* Step 2: Read.
1395 *
1396 * We read in the new tileset. This should be pretty straightforward.
1397 */
1399 if (tileset != NULL) {
1401 } else {
1403
1404 if (!(tileset = tileset_read_toplevel(old_name, FALSE, -1, scale))) {
1405 log_fatal("Failed to re-read the currently loaded tileset.");
1407 }
1408 }
1412 }
1413
1417 } /* else we'll get round to it on PACKET_RULESET_GAME */
1418 players_iterate(pplayer) {
1419 tileset_player_init(tileset, pplayer);
1421 boot_help_texts(); /* "About Current Tileset" */
1422 }
1423
1424 /* Step 3: Setup
1425 *
1426 * This is a seriously sticky problem. On startup, we build a hash
1427 * from all the sprite data. Then, when we connect to a server, the
1428 * server sends us ruleset data a piece at a time and we use this data
1429 * to assemble the sprite structures. But if we change while connected
1430 * we have to reassemble all of these. This should just involve
1431 * calling tilespec_setup_*** on everything. But how do we tell what
1432 * "everything" is?
1433 *
1434 * The below code just does things straightforwardly, by setting up
1435 * each possible sprite again. Hopefully it catches everything, and
1436 * doesn't mess up too badly if we change tilesets while not connected
1437 * to a server.
1438 */
1439 if (!game.client.ruleset_ready) {
1440 /* The ruleset data is not sent until this point. */
1441 return new_tileset_in_use;
1442 }
1443
1445 == TOPO_INCOMP_HARD) {
1447 _("Map topology (%s) and tileset (%s) incompatible."),
1449 }
1450
1451 terrain_type_iterate(pterrain) {
1457 governments_iterate(gov) {
1460 extra_type_iterate(pextra) {
1463 nations_iterate(pnation) {
1466 improvement_iterate(pimprove) {
1475
1478 * sizeof(tileset->sprites.style_citizen_sets.sets[0]));
1479
1480 for (id = 0; id < game.control.num_city_styles; id++) {
1482 }
1483
1484 if (state < C_S_RUNNING) {
1485 /* Below redraws do not apply before this. */
1486 return new_tileset_in_use;
1487 }
1488
1489 /* Step 4: Draw.
1490 *
1491 * Do any necessary redraws.
1492 */
1495 can_slide = FALSE;
1497 /* update_map_canvas_visible forces a full redraw. Otherwise with fast
1498 * drawing we might not get one. Of course this is slower. */
1500 can_slide = TRUE;
1501
1502 return new_tileset_in_use;
1503}
1504
1505/************************************************************************/
1510{
1511 const char *tileset_name;
1512 enum client_states state = client_state();
1513
1514 if (state == C_S_RUNNING || state == C_S_OVER) {
1516
1517 /* Also iso map topology counts as 'square' tileset topology */
1518 if (opt != (wld.map.topology_id & (TF_ISO | TF_HEX))
1519 && (opt != 0 || ((wld.map.topology_id & TF_HEX) == TF_HEX))) {
1520 /* Changed option was not for current topology */
1521 return;
1522 }
1523 }
1524
1526
1527 fc_assert_ret(NULL != tileset_name && tileset_name[0] != '\0');
1530
1531 /* As it's going to be 'current' tileset, make it global default if
1532 * options saved. */
1534
1536 menus_init();
1537}
1538
1539/************************************************************************/
1546{
1548 tilespec_reread(tname, TRUE, 1.0f);
1550 menus_init();
1551}
1552
1553/************************************************************************/
1557static struct sprite *load_gfx_file(const char *gfx_filename, bool svgflag)
1558{
1559 const char **gfx_fileexts, *gfx_fileext;
1560 struct sprite *s;
1561
1562 if (svgflag) {
1564 } else {
1566 }
1567
1568 /* Try out all supported file extensions to find one that works. */
1569 while ((gfx_fileext = *gfx_fileexts++)) {
1570 const char *real_full_name;
1571 char full_name[strlen(gfx_filename) + strlen(".")
1572 + strlen(gfx_fileext) + 1];
1573
1576 log_debug("trying to load gfx file \"%s\".", real_full_name);
1578 svgflag && !strcmp("svg", gfx_fileext));
1579 if (s) {
1580 return s;
1581 }
1582 }
1583 }
1584
1585 log_error("Could not load gfx file \"%s\".", gfx_filename);
1586
1587 return NULL;
1588}
1589
1590/************************************************************************/
1593static void ensure_big_sprite(struct specfile *sf, const char *tset_name)
1594{
1595 struct section_file *file;
1596 const char *gfx_filename;
1597
1598 if (sf->big_sprite) {
1599 /* Looks like it's already loaded. */
1600 return;
1601 }
1602
1603 /* Otherwise load it. The big sprite will sometimes be freed and will have
1604 * to be reloaded, but most of the time it's just loaded once, the small
1605 * sprites are extracted, and then it's freed. */
1606 if (!(file = secfile_load(sf->file_name, TRUE))) {
1608 _("Could not open '%s':\n%s"), sf->file_name, secfile_error());
1609 }
1610
1611 if (!check_tilespec_capabilities(file, "spec",
1612 SPEC_CAPSTR, sf->file_name, TRUE)) {
1614 _("Specfile %s has incompatible capabilities"), sf->file_name);
1615 }
1616
1617 gfx_filename = secfile_lookup_str(file, "file.gfx");
1618
1620
1621 if (!sf->big_sprite) {
1623 _("Could not load gfx file for the spec file \"%s\"."),
1624 sf->file_name);
1625 }
1626 secfile_destroy(file);
1627}
1628
1629/************************************************************************/
1634static void scan_specfile(struct tileset *t, struct specfile *sf,
1635 bool duplicates_ok)
1636{
1637 struct section_file *file;
1638 struct section_list *sections;
1639 int i;
1640
1641 if (!(file = secfile_load(sf->file_name, TRUE))) {
1643 _("Could not open '%s':\n%s"), sf->file_name, secfile_error());
1644 }
1645 if (!check_tilespec_capabilities(file, "spec",
1646 SPEC_CAPSTR, sf->file_name, TRUE)) {
1648 _("Specfile %s has incompatible capabilities"), sf->file_name);
1649 }
1650
1651 /* Currently unused */
1652 secfile_entry_ignore(file, "info.artists");
1653
1654 /* Not used here */
1655 secfile_entry_ignore(file, "file.gfx");
1656
1657 if ((sections = secfile_sections_by_name_prefix(file, "grid_"))) {
1658 section_list_iterate(sections, psection) {
1659 int j, k;
1660 int x_top_left, y_top_left, dx, dy;
1661 int pixel_border_x;
1662 int pixel_border_y;
1663 const char *sec_name = section_name(psection);
1664
1665 pixel_border_x = secfile_lookup_int_default(file, 0, "%s.pixel_border",
1666 sec_name);
1667 pixel_border_y = secfile_lookup_int_default(file, pixel_border_x, "%s.pixel_border_y",
1668 sec_name);
1669 pixel_border_x = secfile_lookup_int_default(file, pixel_border_x, "%s.pixel_border_x",
1670 sec_name);
1671 if (!secfile_lookup_int(file, &x_top_left, "%s.x_top_left", sec_name)
1672 || !secfile_lookup_int(file, &y_top_left,
1673 "%s.y_top_left", sec_name)
1674 || !secfile_lookup_int(file, &dx, "%s.dx", sec_name)
1675 || !secfile_lookup_int(file, &dy, "%s.dy", sec_name)) {
1676 log_error("%s grid \"%s\" invalid: %s",
1678 continue;
1679 }
1680
1681 j = -1;
1682 while (NULL != secfile_entry_lookup(file, "%s.tiles%d.tag",
1683 sec_name, ++j)) {
1684 struct small_sprite *ss;
1685 int row, column;
1686 int xr, yb;
1687 const char **tags;
1688 size_t num_tags;
1689 int hot_x, hot_y;
1690
1691 if (!secfile_lookup_int(file, &row, "%s.tiles%d.row", sec_name, j)
1692 || !secfile_lookup_int(file, &column, "%s.tiles%d.column",
1693 sec_name, j)
1694 || !(tags = secfile_lookup_str_vec(file, &num_tags,
1695 "%s.tiles%d.tag",
1696 sec_name, j))) {
1697 log_error("%s small sprite \"%s.tiles%d\" invalid: %s",
1699 continue;
1700 }
1701 hot_x = secfile_lookup_int_default(file, 0, "%s.tiles%d.hot_x",
1702 sec_name, j);
1703 hot_y = secfile_lookup_int_default(file, 0, "%s.tiles%d.hot_y",
1704 sec_name, j);
1705
1706 /* There must be at least 1 because of the while(): */
1707 fc_assert_action(num_tags > 0, continue);
1708
1709 xr = x_top_left + (dx + pixel_border_x) * column;
1710 yb = y_top_left + (dy + pixel_border_y) * row;
1711
1712 ss = fc_malloc(sizeof(*ss));
1713 ss->ref_count = 0;
1714 ss->file = NULL;
1715 ss->x = xr;
1716 ss->y = yb;
1717 ss->width = dx;
1718 ss->height = dy;
1719 ss->sf = sf;
1720 ss->sprite = NULL;
1721 ss->hot_x = hot_x;
1722 ss->hot_y = hot_y;
1723
1725
1726 if (!duplicates_ok) {
1727 for (k = 0; k < num_tags; k++) {
1728 if (!sprite_hash_insert(t->sprite_hash, tags[k], ss)) {
1729 log_error("warning: %s already has a sprite for \"%s\".",
1730 tileset_name_get(t), tags[k]);
1731 }
1732 }
1733 } else {
1734 for (k = 0; k < num_tags; k++) {
1735 (void) sprite_hash_replace(t->sprite_hash, tags[k], ss);
1736 }
1737 }
1738
1739 free(tags);
1740 tags = NULL;
1741 }
1743 section_list_destroy(sections);
1744 }
1745
1746 /* Load "extra" sprites. Each sprite is one file. */
1747 i = -1;
1748 while (NULL != secfile_entry_lookup(file, "extra.sprites%d.tag", ++i)) {
1749 struct small_sprite *ss;
1750 const char **tags;
1751 const char *filename;
1752 size_t num_tags, k;
1753 int hot_x, hot_y;
1754
1755 if (!(tags = secfile_lookup_str_vec(file, &num_tags,
1756 "extra.sprites%d.tag", i))
1757 || !(filename = secfile_lookup_str(file,
1758 "extra.sprites%d.file", i))) {
1759 log_error("%s extra sprite \"extra.sprites%d\" invalid: %s",
1761 continue;
1762 }
1763 hot_x = secfile_lookup_int_default(file, 0, "extra.sprites%d.hot_x", i);
1764 hot_y = secfile_lookup_int_default(file, 0, "extra.sprites%d.hot_y", i);
1765
1766 ss = fc_malloc(sizeof(*ss));
1767 ss->ref_count = 0;
1768 ss->file = fc_strdup(filename);
1769 ss->sf = NULL;
1770 ss->sprite = NULL;
1771 ss->hot_x = hot_x;
1772 ss->hot_y = hot_y;
1773
1775
1776 if (!duplicates_ok) {
1777 for (k = 0; k < num_tags; k++) {
1778 if (!sprite_hash_insert(t->sprite_hash, tags[k], ss)) {
1779 log_error("warning: %s already have a sprite for \"%s\".",
1780 tileset_name_get(t), tags[k]);
1781 }
1782 }
1783 } else {
1784 for (k = 0; k < num_tags; k++) {
1785 (void) sprite_hash_replace(t->sprite_hash, tags[k], ss);
1786 }
1787 }
1788 free(tags);
1789 }
1790
1793}
1794
1795/************************************************************************/
1799static char *tilespec_gfx_filename(const char *gfx_filename,
1800 const char *tset_name)
1801{
1802 const char *gfx_current_fileext;
1803 const char **gfx_fileexts = gfx_fileextensions();
1804
1805 while ((gfx_current_fileext = *gfx_fileexts++)) {
1806 const char *real_full_name;
1807 char *full_name =
1810
1812
1814 free(full_name);
1815 if (real_full_name) {
1816 return fc_strdup(real_full_name);
1817 }
1818 }
1819
1821 _("Couldn't find a supported gfx file extension for \"%s\"."),
1822 gfx_filename);
1823
1824 return NULL;
1825}
1826
1827/************************************************************************/
1830static bool tileset_scan_single_list(struct tileset *t,
1831 const char *spec_filenames[],
1832 int num_spec_files, bool verbose,
1833 bool duplicates_ok)
1834{
1835 int i;
1836
1837 for (i = 0; i < num_spec_files; i++) {
1838 struct specfile *sf = fc_malloc(sizeof(*sf));
1839 const char *dname;
1840
1841 log_debug("spec file %s", spec_filenames[i]);
1842
1843 sf->big_sprite = NULL;
1845 if (!dname) {
1846 if (verbose) {
1847 log_error("Can't find spec file \"%s\".", spec_filenames[i]);
1848 }
1849
1850 return FALSE;
1851 }
1852 sf->file_name = fc_strdup(dname);
1854
1856 }
1857
1858 return TRUE;
1859}
1860
1861/************************************************************************/
1864static int check_sprite_type(const char *sprite_type, const char *tile_section)
1865{
1866 if (fc_strcasecmp(sprite_type, "corner") == 0) {
1867 return CELL_CORNER;
1868 }
1869 if (fc_strcasecmp(sprite_type, "single") == 0) {
1870 return CELL_WHOLE;
1871 }
1872 if (fc_strcasecmp(sprite_type, "whole") == 0) {
1873 return CELL_WHOLE;
1874 }
1875 log_error("[%s] unknown sprite_type \"%s\".", tile_section, sprite_type);
1876 return CELL_WHOLE;
1877}
1878
1879/************************************************************************/
1885static struct tileset *tileset_read_toplevel(const char *tileset_name,
1886 bool verbose, int topology_id,
1887 float scale)
1888{
1889 struct section_file *file;
1890 char *fname;
1891 const char *c;
1892 int i;
1893 size_t num_spec_files[SFILE_LAST];
1894 const char **spec_filenames[SFILE_LAST];
1895 size_t num_layers;
1896 const char **layer_order;
1897 size_t num_preferred_themes;
1898 struct section_list *sections = NULL;
1899 const char *file_capstr;
1900 bool duplicates_ok, is_hex;
1901 enum direction8 dir;
1902 struct tileset *t = NULL;
1903 const char *extraname;
1904 const char *tstr;
1905 int topo;
1906 bool svg;
1908 const char *type_name;
1909
1911
1912 if (fname == NULL) {
1913 if (verbose) {
1914 log_error("Can't find tileset \"%s\".", tileset_name);
1915 }
1916
1917 return NULL;
1918 }
1919 log_verbose("tilespec file is \"%s\".", fname);
1920
1921 if (!(file = secfile_load(fname, TRUE))) {
1922 log_error("Could not open '%s':\n%s", fname, secfile_error());
1923 free(fname);
1924 return NULL;
1925 }
1926
1927 if (!check_tilespec_capabilities(file, "tilespec",
1928 TILESPEC_CAPSTR, fname, verbose)) {
1929 secfile_destroy(file);
1930 free(fname);
1931 return NULL;
1932 }
1933
1934 t = tileset_new();
1935 t->scale = scale;
1936 file_capstr = secfile_lookup_str(file, "%s.options", "tilespec");
1938 && has_capabilities("+duplicates_ok", file_capstr));
1939
1940 tstr = secfile_lookup_str(file, "tilespec.name");
1941 /* Tileset name found */
1943 tstr = secfile_lookup_str_default(file, "", "tilespec.version");
1944 if (tstr[0] != '\0') {
1945 /* Tileset version found */
1946 sz_strlcpy(t->version, tstr);
1947 } else {
1948 /* No version information */
1949 t->version[0] = '\0';
1950 }
1951
1952 tstr = secfile_lookup_str_default(file, "", "tilespec.summary");
1953 if (tstr[0] != '\0') {
1954 int len;
1955
1956 /* Tileset summary found */
1957 len = strlen(tstr);
1958 t->summary = fc_malloc(len + 1);
1959 fc_strlcpy(t->summary, tstr, len + 1);
1960 } else {
1961 /* No summary */
1962 if (t->summary != NULL) {
1963 free(t->summary);
1964 t->summary = NULL;
1965 }
1966 }
1967
1968 tstr = secfile_lookup_str_default(file, "", "tilespec.description");
1969 if (tstr[0] != '\0') {
1970 int len;
1971
1972 /* Tileset description found */
1973 len = strlen(tstr);
1974 t->description = fc_malloc(len + 1);
1975 fc_strlcpy(t->description, tstr, len + 1);
1976 } else {
1977 /* No description */
1978 if (t->description != NULL) {
1979 free(t->description);
1980 t->description = NULL;
1981 }
1982 }
1983
1984 tstr = secfile_lookup_str_default(file, NULL, "tilespec.for_ruleset");
1985 if (tstr != NULL) {
1987 } else {
1988 t->for_ruleset = NULL;
1989 }
1990
1992 if (!secfile_lookup_int(file, &t->priority, "tilespec.priority")
1993 || !secfile_lookup_bool(file, &is_hex, "tilespec.is_hex")) {
1994 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
1995 goto ON_ERROR;
1996 }
1997
1998 tstr = secfile_lookup_str(file, "tilespec.type");
1999 if (tstr == NULL) {
2000 log_error("Tileset \"%s\": no tileset type", t->name);
2001 goto ON_ERROR;
2002 }
2003
2005 if (!ts_type_is_valid(t->type)) {
2006 log_error("Tileset \"%s\": unknown tileset type \"%s\"", t->name, tstr);
2007 goto ON_ERROR;
2008 }
2009
2010 if (t->type == TS_ISOMETRIC) {
2011 topo = TF_ISO;
2012 } else {
2013 topo = 0;
2014 }
2015
2016 /* Read hex-tileset information. */
2017 t->hex_width = t->hex_height = 0;
2018 if (is_hex) {
2019 int hex_side;
2020
2021 if (!secfile_lookup_int(file, &hex_side, "tilespec.hex_side")) {
2022 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2023 goto ON_ERROR;
2024 }
2025 hex_side = hex_side * t->scale;
2026 if (t->type == TS_ISOMETRIC) {
2027 t->hex_width = hex_side;
2028 } else {
2029 t->hex_height = hex_side;
2030 }
2031
2032 topo |= TF_HEX;
2033
2034 /* Hex tilesets are drawn the same as isometric. */
2035 /* FIXME: There will be other legal values to be used with hex
2036 * tileset in the future, and this would just overwrite it. */
2037 t->type = TS_ISOMETRIC;
2038 }
2039
2040 if (topology_id >= 0) {
2041 if (((topology_id & TF_HEX) && topology_id != (topo & (TF_ISO | TF_HEX)))
2042 || (!(topology_id & TF_HEX) && (topo & TF_HEX))) {
2043 /* Not of requested topology */
2044 goto ON_ERROR;
2045 }
2046 }
2047
2049
2050 if (!is_view_supported(t->type)) {
2051 /* TRANS: "Overhead" or "Isometric" */
2052 log_normal(_("Client does not support %s tilesets."),
2053 _(ts_type_name(t->type)));
2054 log_normal(_("Using default tileset instead."));
2056 goto ON_ERROR;
2057 }
2058
2060
2061 /* Create arrays of valid and cardinal tileset dirs. These depend
2062 * entirely on the tileset, not the topology. They are also in clockwise
2063 * rotational ordering. */
2065 dir = DIR8_NORTH;
2066 do {
2067 if (is_valid_tileset_dir(t, dir)) {
2070 }
2071 if (is_cardinal_tileset_dir(t, dir)) {
2074 }
2075
2076 dir = dir_cw(dir);
2077 } while (dir != DIR8_NORTH);
2078
2079 fc_assert(t->num_valid_tileset_dirs % 2 == 0); /* Assumed elsewhere. */
2082
2084 "tilespec.normal_tile_width")
2086 "tilespec.normal_tile_height")) {
2087 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2088 goto ON_ERROR;
2089 }
2091 /* Adjust width to be multiple of 8 */
2092 if (scale != 1.0f) {
2093 i = t->normal_tile_width;
2094 while (i % 8 != 0) {
2095 i++;
2096 }
2097 t->scale = (t->scale * i) / t->normal_tile_width;
2098 t->normal_tile_width = i;
2099 }
2101 if (t->type == TS_ISOMETRIC) {
2103 if (tileset_hex_height(t) > 0) {
2105 } else {
2106 t->full_tile_height = 3 * t->normal_tile_height / 2;
2107 }
2108 } else {
2111 }
2113 = secfile_lookup_int_default(file, t->full_tile_width, "tilespec.unit_width");
2115 = secfile_lookup_int_default(file, t->full_tile_height, "tilespec.unit_height");
2117 "tilespec.small_tile_width")
2119 "tilespec.small_tile_height")) {
2120 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2121 goto ON_ERROR;
2122 }
2123 if (t->unit_tile_width != t->full_tile_width && t->scale != 1.0f) {
2125 }
2126 if (t->unit_tile_height != t->full_tile_height && t->scale != 1.0f) {
2128 }
2131 log_verbose("tile sizes %dx%d, %d%d unit, %d%d small",
2135
2136 tstr = secfile_lookup_str(file, "tilespec.fog_style");
2137 if (tstr == NULL) {
2138 log_error("Tileset \"%s\": no fog_style", t->name);
2139 goto ON_ERROR;
2140 }
2141
2143 if (!fog_style_is_valid(t->fogstyle)) {
2144 log_error("Tileset \"%s\": unknown fog_style \"%s\"", t->name, tstr);
2145 goto ON_ERROR;
2146 }
2147
2148 tstr = secfile_lookup_str(file, "tilespec.darkness_style");
2149 if (tstr == NULL) {
2150 log_error("Tileset \"%s\": no darkness_style", t->name);
2151 goto ON_ERROR;
2152 }
2153
2156 log_error("Tileset \"%s\": unknown darkness_style \"%s\"", t->name, tstr);
2157 goto ON_ERROR;
2158 }
2159
2161 && (t->type == TS_OVERHEAD || t->hex_width > 0 || t->hex_height > 0)) {
2162 log_error("Invalid darkness style set in tileset \"%s\".", t->name);
2163 goto ON_ERROR;
2164 }
2165
2167 "tilespec.unit_flag_offset_x")
2169 "tilespec.unit_flag_offset_y")
2171 "tilespec.city_flag_offset_x")
2173 "tilespec.city_flag_offset_y")
2174 || !secfile_lookup_int(file, &t->unit_offset_x,
2175 "tilespec.unit_offset_x")
2176 || !secfile_lookup_int(file, &t->unit_offset_y,
2177 "tilespec.unit_offset_y")
2179 "tilespec.activity_offset_x")
2181 "tilespec.activity_offset_y")
2182 || !secfile_lookup_int(file, &t->select_offset_x,
2183 "tilespec.select_offset_x")
2184 || !secfile_lookup_int(file, &t->select_offset_y,
2185 "tilespec.select_offset_y")
2187 "tilespec.stack_size_offset_x")
2189 "tilespec.stack_size_offset_y")
2190 || !secfile_lookup_int(file, &t->city_offset_x,
2191 "tilespec.city_offset_x")
2192 || !secfile_lookup_int(file, &t->city_offset_y,
2193 "tilespec.city_offset_y")
2195 "tilespec.city_size_offset_x")
2197 "tilespec.city_size_offset_y")
2199 "tilespec.citybar_offset_y")
2201 "tilespec.tilelabel_offset_y")
2203 "tilespec.occupied_offset_x")
2205 "tilespec.occupied_offset_y")) {
2206 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2207 goto ON_ERROR;
2208 }
2209
2211 "tilespec.unit_upkeep_offset_y");
2213 "tilespec.unit_upkeep_small_offset_y");
2214 t->svg_height = secfile_lookup_int_default(file, 44, "tilespec.svg_height");
2215
2226 t->unit_offset_x = t->scale * t->unit_offset_x;
2227 t->unit_offset_y = t->scale * t->unit_offset_y;
2230 t->city_offset_x = t->scale * t->city_offset_x;
2231 t->city_offset_y = t->scale * t->city_offset_y;
2236 t->svg_height *= t->scale;
2237
2238 if (t->scale != 1.0f
2241 }
2242 if (t->scale != 1.0f
2245 }
2246
2248 "tilespec.unit_default_orientation");
2249 if (!c) {
2250 /* This is valid, but tileset must specify icon for every unit */
2252 } else {
2253 dir = dir_by_tileset_name(c);
2254
2255 if (!direction8_is_valid(dir)) {
2257 _("Unknown unit_default_orientation \"%s\""), c);
2258 goto ON_ERROR;
2259 } else {
2260 /* Default orientation is allowed to not be a valid one for the
2261 * tileset */
2262 t->unit_default_orientation = dir;
2263 }
2264 }
2265
2266 c = secfile_lookup_str(file, "tilespec.main_intro_file");
2268 log_debug("intro file %s", t->main_intro_filename);
2269
2270 /* Layer order */
2271 num_layers = 0;
2272 layer_order = secfile_lookup_str_vec(file, &num_layers,
2273 "tilespec.layer_order");
2274 if (layer_order != NULL) {
2275 for (i = 0; i < num_layers; i++) {
2276 int j;
2279
2280 /* Check for wrong layer names. */
2281 if (!mapview_layer_is_valid(layer)) {
2282 log_error("layer_order: Invalid layer \"%s\" in %s",
2284 goto ON_ERROR;
2285 }
2286 /* Check for duplicates. */
2287 for (j = 0; j < i; j++) {
2288 if (t->layer_order[j] == layer) {
2289 log_error("layer_order: Duplicate layer \"%s\" in %s",
2291 goto ON_ERROR;
2292 }
2293 }
2294 t->layer_order[i] = layer;
2295 }
2296
2297 /* Now check that all layers are present. Doing it now allows for a more
2298 * comprehensive error message. */
2299 for (i = 0; i < LAYER_COUNT; i++) {
2300 int j;
2301 bool found = FALSE;
2302
2303 for (j = 0; j < num_layers; j++) {
2304 if (i == t->layer_order[j]) {
2305 found = TRUE;
2306 break;
2307 }
2308 }
2309 if (!found) {
2310 log_error("layer_order: Missing layer \"%s\" in %s",
2312 goto ON_ERROR;
2313 }
2314 }
2315
2317 } else {
2318 /* There is no layer_order tag in the specfile -> use the default */
2319 for (i = 0; i < LAYER_COUNT; i++) {
2320 t->layer_order[i] = i;
2321 }
2322 }
2323
2324 /* Terrain layer info. */
2325 for (i = 0; i < MAX_NUM_LAYERS; i++) {
2326 struct tileset_layer *tslp = &t->layers[i];
2327 int j, k;
2328
2329 tslp->match_types =
2330 (char **) secfile_lookup_str_vec(file, &tslp->match_count,
2331 "layer%d.match_types", i);
2332 for (j = 0; j < tslp->match_count; j++) {
2333 tslp->match_types[j] = fc_strdup(tslp->match_types[j]);
2334
2335 for (k = 0; k < j; k++) {
2336 if (tslp->match_types[k][0] == tslp->match_types[j][0]) {
2338 _("[layer%d] match_types: \"%s\" initial "
2339 "('%c') is not unique."),
2340 i, tslp->match_types[j], tslp->match_types[j][0]);
2341 /* FIXME: Returns NULL. */
2342 }
2343 }
2344 }
2345 }
2346
2347 /* Tile drawing info. */
2349 if (NULL == sections || 0 == section_list_size(sections)) {
2351 _("No [%s] sections present."),
2353 goto ON_ERROR;
2354 }
2355
2356 fc_assert(t->tile_hash == NULL);
2358
2359 section_list_iterate(sections, psection) {
2360 const char *sec_name = section_name(psection);
2362 const char *sprite_type;
2363 int l;
2364 const char *terrain_name;
2365
2366 terrain_name = secfile_lookup_str(file, "%s.tag", sec_name);
2367
2368 if (terrain_name != NULL) {
2369 draw->name = fc_strdup(terrain_name);
2370 } else {
2371 tileset_error(LOG_ERROR, _("No terrain tag given in section [%s] in %s."),
2374 goto ON_ERROR;
2375 }
2376
2377 draw->blending = secfile_lookup_int_default(file, 0, "%s.blend_layer",
2378 sec_name);
2379 draw->blending = CLIP(0, draw->blending, MAX_NUM_LAYERS);
2380
2381 draw->is_reversed = secfile_lookup_bool_default(file, FALSE,
2382 "%s.is_reversed",
2383 sec_name);
2384 draw->num_layers = secfile_lookup_int_default(file, 0, "%s.num_layers",
2385 sec_name);
2386 draw->num_layers = CLIP(1, draw->num_layers, MAX_NUM_LAYERS);
2387
2388 for (l = 0; l < draw->num_layers; l++) {
2389 struct drawing_layer *dlp = &draw->layer[l];
2390 struct tileset_layer *tslp = &t->layers[l];
2391 const char *match_type;
2392 const char **match_with;
2393 size_t count;
2394
2395 dlp->is_tall
2396 = secfile_lookup_bool_default(file, FALSE, "%s.layer%d_is_tall",
2397 sec_name, l);
2398 dlp->offset_x
2399 = secfile_lookup_int_default(file, 0, "%s.layer%d_offset_x",
2400 sec_name, l);
2401 dlp->offset_y
2402 = secfile_lookup_int_default(file, 0, "%s.layer%d_offset_y",
2403 sec_name, l);
2404 dlp->offset_x = ceil(t->scale * dlp->offset_x);
2405 dlp->offset_y = ceil(t->scale * dlp->offset_y);
2406
2408 "%s.layer%d_match_type",
2409 sec_name, l);
2410 if (match_type) {
2411 int j;
2412
2413 /* Determine our match_type. */
2414 for (j = 0; j < tslp->match_count; j++) {
2415 if (fc_strcasecmp(tslp->match_types[j], match_type) == 0) {
2416 break;
2417 }
2418 }
2419 if (j >= tslp->match_count) {
2420 log_error("[%s] invalid match_type \"%s\" in %s.",
2422 } else {
2423 dlp->match_index[dlp->match_indices++] = j;
2424 }
2425 }
2426
2427 match_with = secfile_lookup_str_vec(file, &count,
2428 "%s.layer%d_match_with",
2429 sec_name, l);
2430 if (match_with) {
2431 int j, k;
2432
2433 if (count > MAX_NUM_MATCH_WITH) {
2434 log_error("[%s] match_with has too many types (%d, max %d) in %s",
2435 sec_name, (int) count, MAX_NUM_MATCH_WITH,
2436 tileset_name_get(t));
2437 count = MAX_NUM_MATCH_WITH;
2438 }
2439
2440 if (1 < dlp->match_indices) {
2441 log_error("[%s] previous match_with ignored in %s.",
2443 dlp->match_indices = 1;
2444 } else if (1 > dlp->match_indices) {
2445 log_error("[%s] missing match_type, using \"%s\" in %s.",
2446 sec_name, tslp->match_types[0], tileset_name_get(t));
2447 dlp->match_index[0] = 0;
2448 dlp->match_indices = 1;
2449 }
2450
2451 for (k = 0; k < count; k++) {
2452 for (j = 0; j < tslp->match_count; j++) {
2453 if (fc_strcasecmp(tslp->match_types[j], match_with[k]) == 0) {
2454 break;
2455 }
2456 }
2457 if (j >= tslp->match_count) {
2458 log_error("[%s] layer%d_match_with: invalid \"%s\".",
2459 sec_name, l, match_with[k]);
2460 } else if (1 < count) {
2461 int m;
2462
2463 for (m = 0; m < dlp->match_indices; m++) {
2464 if (dlp->match_index[m] == j) {
2465 log_error("[%s] layer%d_match_with: duplicate \"%s\" in %s.",
2467 break;
2468 }
2469 }
2470 if (m >= dlp->match_indices) {
2471 dlp->match_index[dlp->match_indices++] = j;
2472 }
2473 } else {
2474 dlp->match_index[dlp->match_indices++] = j;
2475 }
2476 }
2478 match_with = NULL;
2479 }
2480
2481 /* Check match_indices */
2482 switch (dlp->match_indices) {
2483 case 0:
2484 case 1:
2485 dlp->match_style = MATCH_NONE;
2486 break;
2487 case 2:
2488 if (dlp->match_index[0] == dlp->match_index[1] ) {
2489 dlp->match_style = MATCH_SAME;
2490 } else {
2491 dlp->match_style = MATCH_PAIR;
2492 }
2493 break;
2494 default:
2495 dlp->match_style = MATCH_FULL;
2496 break;
2497 };
2498
2500 = secfile_lookup_str_default(file, "whole", "%s.layer%d_sprite_type",
2501 sec_name, l);
2502 dlp->sprite_type = check_sprite_type(sprite_type, sec_name);
2503
2504 switch (dlp->sprite_type) {
2505 case CELL_WHOLE:
2506 /* OK, no problem */
2507 break;
2508 case CELL_CORNER:
2509 if (dlp->is_tall
2510 || dlp->offset_x > 0
2511 || dlp->offset_y > 0) {
2512 log_error("[%s] layer %d: you cannot have tall terrain or\n"
2513 "a sprite offset with a cell-based drawing method in %s.",
2515 dlp->is_tall = FALSE;
2516 dlp->offset_x = dlp->offset_y = 0;
2517 }
2518 break;
2519 };
2520 }
2521
2522 if (!drawing_hash_insert(t->tile_hash, draw->name, draw)) {
2523 log_error("warning: multiple tile sections containing terrain tag \"%s\" in %s.",
2524 draw->name, tileset_name_get(t));
2525 goto ON_ERROR;
2526 }
2528 section_list_destroy(sections);
2529 sections = NULL;
2530
2532
2533 for (i = 0; i < ESTYLE_COUNT; i++) {
2535 }
2537
2538 for (i = 0; (extraname = secfile_lookup_str_default(file, NULL,
2539 "extras.styles%d.name",
2540 i)); i++) {
2541 const char *style_name;
2542 enum extrastyle_id style;
2543
2544 style_name = secfile_lookup_str_default(file, "Single1",
2545 "extras.styles%d.style", i);
2547 if (!extrastyle_id_is_valid(style)) {
2548 log_error("Unknown extra style \"%s\" for extra \"%s\" in %s.",
2550 goto ON_ERROR;
2551 }
2552
2553 if (!estyle_hash_insert(t->estyle_hash, extraname, style)) {
2554 log_error("warning: duplicate extrastyle entry [%s] in %s.",
2556 goto ON_ERROR;
2557 }
2558 }
2559
2561
2564 "tilespec.files");
2565
2566 if (svg) {
2568 type_name = "svg";
2569
2570 /* Avoid "unused entry" warning about the other list */
2571 secfile_entry_ignore_by_path(file, "tilespec.files_pixel");
2572 } else {
2574 type_name = "pixel";
2575
2576 /* Avoid "unused entry" warning about the other list */
2577 secfile_entry_ignore_by_path(file, "tilespec.files_svg");
2578 }
2579
2582 "tilespec.files_%s", type_name);
2585 log_error("No tile graphics files specified in \"%s\" for %s mode.",
2586 type_name, fname);
2587 goto ON_ERROR;
2588 }
2589
2590 fc_assert(t->sprite_hash == NULL);
2592
2595 verbose, duplicates_ok)) {
2596 goto ON_ERROR;
2597 }
2598
2601 verbose, duplicates_ok)) {
2602 goto ON_ERROR;
2603 }
2604
2607
2609
2610 /* FIXME: remove this hack. */
2611 t->preferred_themes =
2612 (char **) secfile_lookup_str_vec(file, &num_preferred_themes,
2613 "tilespec.preferred_themes");
2614 if (num_preferred_themes <= 0) {
2615 t->preferred_themes =
2616 (char **) secfile_lookup_str_vec(file, &num_preferred_themes,
2617 "tilespec.prefered_themes");
2618 if (num_preferred_themes > 0) {
2619 log_deprecation("Entry tilespec.prefered_themes in tilespec."
2620 " Use correct spelling tilespec.preferred_themes instead");
2621 }
2622 }
2623 t->num_preferred_themes = num_preferred_themes;
2624 for (i = 0; i < t->num_preferred_themes; i++) {
2626 }
2627
2629 secfile_destroy(file);
2630 log_verbose("finished reading \"%s\".", fname);
2631 free(fname);
2632
2633 return t;
2634
2635ON_ERROR:
2636 secfile_destroy(file);
2637 free(fname);
2638 tileset_free(t);
2639
2640 if (NULL != sections) {
2641 section_list_destroy(sections);
2642 }
2643
2644 return NULL;
2645}
2646
2647/************************************************************************/
2650static const char *citizen_rule_name(enum citizen_category citizen)
2651{
2652 /* These strings are used in reading the tileset. Do not
2653 * translate. */
2654 switch (citizen) {
2655 case CITIZEN_HAPPY:
2656 return "happy";
2657 case CITIZEN_CONTENT:
2658 return "content";
2659 case CITIZEN_UNHAPPY:
2660 return "unhappy";
2661 case CITIZEN_ANGRY:
2662 return "angry";
2663 default:
2664 break;
2665 }
2666 log_error("Unknown citizen type: %d.", (int) citizen);
2667 return NULL;
2668}
2669
2670/************************************************************************/
2675static const char *cardinal_index_str(const struct tileset *t, int idx)
2676{
2677 static char c[64];
2678 int i;
2679
2680 c[0] = '\0';
2681 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
2682 int value = (idx >> i) & 1;
2683
2684 cat_snprintf(c, sizeof(c), "%s%d",
2686 }
2687
2688 return c;
2689}
2690
2691/************************************************************************/
2695static char *valid_index_str(const struct tileset *t, int idx)
2696{
2697 static char c[64];
2698 int i;
2699
2700 c[0] = '\0';
2701 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
2702 int value = (idx >> i) & 1;
2703
2704 cat_snprintf(c, sizeof(c), "%s%d",
2706 }
2707
2708 return c;
2709}
2710
2711/************************************************************************/
2718static struct sprite *load_sprite(struct tileset *t, const char *tag_name,
2719 bool scale, bool smooth, bool svgflag)
2720{
2721 struct small_sprite *ss;
2722 float sprite_scale = 1.0f;
2723
2724 log_debug("load_sprite(tag='%s')", tag_name);
2725 /* Lookup information about where the sprite is found. */
2727 return NULL;
2728 }
2729
2730 fc_assert(ss->ref_count >= 0);
2731
2732 if (!ss->sprite) {
2733 /* If the sprite hasn't been loaded already, then load it. */
2734 fc_assert(ss->ref_count == 0);
2735
2736 if (ss->file) {
2737 int w, h;
2738 struct sprite *s;
2739
2740 if (scale) {
2741 s = load_gfx_file(ss->file, svgflag);
2742
2743 if (s != NULL) {
2744 get_sprite_dimensions(s, &w, &h);
2745 ss->sprite = crop_sprite(s, 0, 0, w,
2746 h, NULL, -1, -1, t->scale, smooth);
2747 free_sprite(s);
2748 }
2749 } else {
2750 ss->sprite = load_gfx_file(ss->file, svgflag);
2751 }
2752
2753 if (!ss->sprite) {
2755 _("Couldn't load gfx file \"%s\" for sprite '%s'."),
2756 ss->file, tag_name);
2757 }
2758 } else {
2759 int sf_w, sf_h;
2760
2762 get_sprite_dimensions(ss->sf->big_sprite, &sf_w, &sf_h);
2763 if (ss->x < 0 || ss->x + ss->width > sf_w
2764 || ss->y < 0 || ss->y + ss->height > sf_h) {
2766 _("Sprite '%s' in file \"%s\" isn't within the image!"),
2767 tag_name, ss->sf->file_name);
2768 return NULL;
2769 }
2770 if (scale) {
2771 sprite_scale = t->scale;
2772 }
2773 ss->sprite = crop_sprite(ss->sf->big_sprite, ss->x, ss->y, ss->width,
2774 ss->height, NULL, -1, -1, sprite_scale,
2775 smooth);
2776 }
2777 }
2778
2779 /* Track the reference count so we know when to free the sprite. */
2780 ss->ref_count++;
2781
2782 return ss->sprite;
2783}
2784
2785/************************************************************************/
2788static struct sprite *create_plr_sprite(struct color *pcolor)
2789{
2790 struct sprite *sprite;
2791
2793
2796
2797 return sprite;
2798}
2799
2800/************************************************************************/
2804static void unload_sprite(struct tileset *t, const char *tag_name)
2805{
2806 struct small_sprite *ss;
2807
2810 fc_assert_ret(ss->ref_count >= 1);
2811 fc_assert_ret(ss->sprite);
2812
2813 ss->ref_count--;
2814
2815 if (ss->ref_count == 0) {
2816 /* Nobody's using the sprite anymore, so we should free it. We know
2817 * where to find it if we need it again. */
2818 log_debug("freeing sprite '%s'.", tag_name);
2819 free_sprite(ss->sprite);
2820 ss->sprite = NULL;
2821 }
2822}
2823
2824/************************************************************************/
2828static bool sprite_exists(const struct tileset *t, const char *tag_name)
2829{
2830 /* Lookup information about where the sprite is found. */
2832}
2833
2834/* Not very safe, but convenient: */
2835#define SET_SPRITE(field, tag) \
2836 do { \
2837 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2838 if (t->sprites.field == NULL) { \
2839 tileset_error(LOG_FATAL, tileset_name_get(t), \
2840 _("Sprite for tag '%s' missing."), tag); \
2841 } \
2842 } while (FALSE)
2843
2844
2845#define SET_SPRITE_NOTSMOOTH(field, tag) \
2846 do { \
2847 t->sprites.field = load_sprite(t, tag, TRUE, FALSE, FALSE); \
2848 if (t->sprites.field == NULL) { \
2849 tileset_error(LOG_FATAL, tileset_name_get(t), \
2850 _("Sprite for tag '%s' missing."), tag); \
2851 } \
2852 } while (FALSE)
2853
2854#define SET_SPRITE_UNSCALED(field, tag) \
2855 do { \
2856 t->sprites.field = load_sprite(t, tag, FALSE, FALSE, FALSE); \
2857 if (t->sprites.field == NULL) { \
2858 tileset_error(LOG_FATAL, tileset_name_get(t), \
2859 _("Sprite for tag '%s' missing."), tag); \
2860 } \
2861 } while (FALSE)
2862
2863/* Sets sprites.field to tag or (if tag isn't available) to alt */
2864#define SET_SPRITE_ALT(field, tag, alt) \
2865 do { \
2866 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2867 if (!t->sprites.field) { \
2868 t->sprites.field = load_sprite(t, alt, TRUE, TRUE, FALSE); \
2869 } \
2870 if (t->sprites.field == NULL) { \
2871 tileset_error(LOG_FATAL, tileset_name_get(t), \
2872 _("Sprite for tags '%s' and alternate '%s' are " \
2873 "both missing."), tag, alt); \
2874 } \
2875 } while (FALSE)
2876
2877/* Sets sprites.field to tag, or NULL if not available */
2878#define SET_SPRITE_OPT(field, tag) \
2879 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE)
2880
2881#define SET_SPRITE_ALT_OPT(field, tag, alt) \
2882 do { \
2883 t->sprites.field = tiles_lookup_sprite_tag_alt(t, LOG_VERBOSE, tag, alt, \
2884 NULL, "sprite", #field, \
2885 TRUE); \
2886 } while (FALSE)
2887
2888/************************************************************************/
2897
2898/************************************************************************/
2902 struct citizen_set *set,
2904 const char *tag_group,
2905 const char *set_name,
2906 bool required)
2907{
2908 /* Load the specialist sprite graphics. */
2909 char buffer[512];
2910 int j;
2911 struct specialist *spe = specialist_by_number(id);
2912 const char *tag = spe->graphic_str;
2913 const char *graphic_alt = spe->graphic_alt;
2914
2915 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
2916 /* Try tag name + index number */
2917 if (tag_group != NULL) {
2918 fc_snprintf(buffer, sizeof(buffer), "%s.%s_%d", tag_group, tag, j);
2919 } else {
2920 fc_snprintf(buffer, sizeof(buffer), "%s_%d", tag, j);
2921 }
2922 set->specialist[id].sprite[j] = load_sprite(t, buffer,
2923 FALSE, FALSE, FALSE);
2924
2925 /* Break if no more index specific sprites are defined */
2926 if (!set->specialist[id].sprite[j]) {
2927 break;
2928 }
2929 }
2930
2931 if (j == 0) {
2932 /* Try non-indexed */
2933 set->specialist[id].sprite[j] = load_sprite(t, tag,
2934 FALSE, FALSE, FALSE);
2935
2936 if (set->specialist[id].sprite[j]) {
2937 j = 1;
2938 }
2939 }
2940
2941 if (j == 0) {
2942 /* Try the alt tag */
2943 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
2944 /* Try alt tag name + index number */
2945 if (tag_group != NULL) {
2946 fc_snprintf(buffer, sizeof(buffer), "%s.%s_%d", tag_group, graphic_alt, j);
2947 } else {
2948 fc_snprintf(buffer, sizeof(buffer), "%s_%d", graphic_alt, j);
2949 }
2950 set->specialist[id].sprite[j] = load_sprite(t, buffer,
2951 FALSE, FALSE, FALSE);
2952
2953 /* Break if no more index specific sprites are defined */
2954 if (!set->specialist[id].sprite[j]) {
2955 break;
2956 }
2957 }
2958 }
2959
2960 if (j == 0) {
2961 /* Try alt tag non-indexed */
2963 FALSE, FALSE, FALSE);
2964
2965 if (set->specialist[id].sprite[j]) {
2966 j = 1;
2967 }
2968 }
2969
2970 set->specialist[id].count = j;
2971
2972 /* Still nothing? Give up. */
2973 if (j == 0 && required) {
2974 /* TRANS: First %s is a graphics tag of the specialist, second one
2975 * is a citizen set name; 'citizen_graphic' from styles.ruleset */
2977 _("No graphics for specialist \"%s\" in %s."),
2978 tag, set_name);
2979 }
2980}
2981
2982/************************************************************************/
2986{
2988 "default set", TRUE);
2989}
2990
2991/************************************************************************/
2995 struct citizen_set *set,
2996 const char *tag_group,
2997 const char *set_name,
2998 bool required)
2999{
3000 int i, j;
3001 char buffer[512];
3002
3003 /* Load the citizen sprite graphics, no specialist. */
3004 for (i = 0; i < CITIZEN_LAST; i++) {
3005 const char *name = citizen_rule_name(i);
3006
3007 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
3008 if (tag_group != NULL) {
3009 fc_snprintf(buffer, sizeof(buffer), "citizen.%s.%s_%d", tag_group, name, j);
3010 } else {
3011 fc_snprintf(buffer, sizeof(buffer), "citizen.%s_%d", name, j);
3012 }
3013 set->citizen[i].sprite[j] = load_sprite(t, buffer, FALSE, FALSE, FALSE);
3014 if (!set->citizen[i].sprite[j]) {
3015 break;
3016 }
3017 }
3018 set->citizen[i].count = j;
3019 if (j == 0 && required) {
3020 /* TRANS: First %s is type of the citizen ("happy" ... "angry"), second one
3021 * is a citizen set name; 'citizen_graphic' from styles.ruleset */
3023 _("No graphics for citizen \"%s\" in %s."),
3024 name, set_name);
3025 }
3026 }
3027}
3028
3029/************************************************************************/
3035static struct sprite *get_city_sprite(const struct city_sprite *city_sprite,
3036 const struct city *pcity)
3037{
3038 /* Get style and match the best tile based on city size */
3039 int style = style_of_city(pcity);
3040 int num_thresholds;
3042 int img_index;
3043
3045
3048
3049 if (num_thresholds == 0) {
3050 return NULL;
3051 }
3052
3053 /* Get the sprite with the index defined by the effects. */
3054 img_index = pcity->client.city_image;
3055 if (img_index == -100) {
3056 /* Server doesn't know right value as this is from old savegame.
3057 * Guess here based on *client* side information as was done in
3058 * versions where information was not saved to savegame - this should
3059 * give us right answer of what city looked like by the time it was
3060 * put under FoW. */
3062 }
3064
3065 return thresholds[img_index].sprite;
3066}
3067
3068/************************************************************************/
3071static int load_city_thresholds_sprites(struct tileset *t, const char *tag,
3072 char *graphic, char *graphic_alt,
3074{
3075 char buffer[128];
3076 char *gfx_in_use = graphic;
3077 int num_thresholds = 0;
3078 struct sprite *sprite;
3079 int size;
3080
3081 *thresholds = NULL;
3082
3083 for (size = 0; size < MAX_CITY_SIZE; size++) {
3084 fc_snprintf(buffer, sizeof(buffer), "%s_%s_%d",
3085 gfx_in_use, tag, size);
3086 if ((sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE))) {
3089 (*thresholds)[num_thresholds - 1].sprite = sprite;
3090 } else if (size == 0) {
3091 if (gfx_in_use == graphic) {
3092 /* Try again with graphic_alt. */
3093 size--;
3094 gfx_in_use = graphic_alt;
3095 } else {
3096 /* Don't load any others if the 0 element isn't there. */
3097 break;
3098 }
3099 }
3100 }
3101
3102 return num_thresholds;
3103}
3104
3105/************************************************************************/
3112static struct city_sprite *load_city_sprite(struct tileset *t,
3113 const char *tag)
3114{
3115 struct city_sprite *city_sprite = fc_malloc(sizeof(*city_sprite));
3116 int style;
3117
3118 /* Store number of styles we have allocated memory for.
3119 * game.control.num_city_styles might change if client disconnects from
3120 * server and connects new one. */
3123 * sizeof(*city_sprite->styles));
3124
3125 for (style = 0; style < city_sprite->num_styles; style++) {
3127 load_city_thresholds_sprites(t, tag, city_styles[style].graphic,
3128 city_styles[style].graphic_alt,
3130 }
3131
3132 return city_sprite;
3133}
3134
3135/************************************************************************/
3141{
3142 int style;
3143
3144 if (!city_sprite) {
3145 return;
3146 }
3147 for (style = 0; style < city_sprite->num_styles; style++) {
3148 if (city_sprite->styles[style].land_thresholds) {
3150 }
3151 }
3154}
3155
3156/************************************************************************/
3161{
3162 char buffer[512], buffer2[512];
3163 const int W = t->normal_tile_width, H = t->normal_tile_height;
3164 int i, j, f;
3165
3167
3168 SET_SPRITE_UNSCALED(treaty_thumb[0], "treaty.disagree_thumb_down");
3169 SET_SPRITE_UNSCALED(treaty_thumb[1], "treaty.agree_thumb_up");
3170
3171 for (j = 0; j < INDICATOR_COUNT; j++) {
3172 const char *names[] = {"science_bulb", "warming_sun", "cooling_flake"};
3173
3174 for (i = 0; i < NUM_TILES_PROGRESS; i++) {
3175 fc_snprintf(buffer, sizeof(buffer), "s.%s_%d", names[j], i);
3176 SET_SPRITE_UNSCALED(indicator[j][i], buffer);
3177 }
3178 }
3179
3180 SET_SPRITE(arrow[ARROW_RIGHT], "s.right_arrow");
3181 SET_SPRITE(arrow[ARROW_PLUS], "s.plus");
3182 SET_SPRITE(arrow[ARROW_MINUS], "s.minus");
3183 if (t->type == TS_ISOMETRIC) {
3184 SET_SPRITE(dither_tile, "t.dither_tile");
3185 }
3186
3188 SET_SPRITE_NOTSMOOTH(mask.tile, "mask.tile");
3189 } else {
3190 SET_SPRITE(mask.tile, "mask.tile");
3191 }
3192 SET_SPRITE(mask.worked_tile, "mask.worked_tile");
3193 SET_SPRITE(mask.unworked_tile, "mask.unworked_tile");
3194
3195 SET_SPRITE_UNSCALED(tax_luxury, "s.tax_luxury");
3196 SET_SPRITE_UNSCALED(tax_science, "s.tax_science");
3197 SET_SPRITE_UNSCALED(tax_gold, "s.tax_gold");
3198
3200
3201 for (i = 0; i < SPACESHIP_COUNT; i++) {
3202 const char *names[SPACESHIP_COUNT]
3203 = {"solar_panels", "life_support", "habitation",
3204 "structural", "fuel", "propulsion", "exhaust"};
3205
3206 fc_snprintf(buffer, sizeof(buffer), "spaceship.%s", names[i]);
3207 SET_SPRITE(spaceship[i], buffer);
3208 }
3209
3210 for (i = 0; i < CURSOR_LAST; i++) {
3211 const char *names[CURSOR_LAST] =
3212 {"goto", "patrol", "paradrop", "teleport", "nuke", "select",
3213 "invalid", "attack", "edit_paint", "edit_add", "wait"};
3214
3215 for (f = 0; f < NUM_CURSOR_FRAMES; f++) {
3216 struct small_sprite *ss;
3217
3218 fc_assert(ARRAY_SIZE(names) == CURSOR_LAST);
3219 fc_snprintf(buffer, sizeof(buffer), "cursor.%s%d", names[i], f);
3220 SET_SPRITE(cursor[i].frame[f], buffer);
3221
3222 if (sprite_hash_lookup(t->sprite_hash, buffer, &ss)) {
3223 t->sprites.cursor[i].hot_x = ss->hot_x;
3224 t->sprites.cursor[i].hot_y = ss->hot_y;
3225 }
3226 }
3227 }
3228
3229 for (i = 0; i < ICON_COUNT; i++) {
3230 const char *names[ICON_COUNT] = {"freeciv", "citydlg"};
3231
3232 fc_snprintf(buffer, sizeof(buffer), "icon.%s", names[i]);
3233 SET_SPRITE(icon[i], buffer);
3234 }
3235
3236 for (i = 0; i < E_COUNT; i++) {
3237 const char *tag = get_event_tag(i);
3238
3239 SET_SPRITE(events[i], tag);
3240 }
3241
3242 SET_SPRITE(explode.nuke, "explode.nuke");
3243
3245 for (i = 0; ; i++) {
3246 struct sprite *sprite;
3247
3248 fc_snprintf(buffer, sizeof(buffer), "explode.unit_%d", i);
3249 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3250 if (!sprite) {
3251 break;
3252 }
3254 }
3255
3256 SET_SPRITE(unit.auto_attack, "unit.auto_attack");
3257 SET_SPRITE(unit.auto_settler, "unit.auto_settler");
3258 SET_SPRITE(unit.auto_explore, "unit.auto_explore");
3259 SET_SPRITE(unit.fortified, "unit.fortified");
3260 SET_SPRITE(unit.fortifying, "unit.fortifying");
3261 SET_SPRITE(unit.go_to, "unit.goto");
3262 SET_SPRITE(unit.cultivate, "unit.cultivate");
3263 SET_SPRITE(unit.plant, "unit.plant");
3264 SET_SPRITE(unit.pillage, "unit.pillage");
3265 SET_SPRITE(unit.sentry, "unit.sentry");
3266 SET_SPRITE(unit.convert, "unit.convert");
3267 t->sprites.unit.stack = fc_malloc(sizeof(struct sprite *));
3268 t->sprites.unit.num_stack_sprites = 1;
3269 SET_SPRITE(unit.stack[0], "unit.stack");
3270 t->sprites.unit.no_more_stack_sprites = FALSE;
3271 SET_SPRITE(unit.loaded, "unit.loaded");
3272 SET_SPRITE(unit.transform, "unit.transform");
3273 SET_SPRITE(unit.connect, "unit.connect");
3274 SET_SPRITE(unit.patrol, "unit.patrol");
3275 for (i = 0; i < MAX_NUM_BATTLEGROUPS; i++) {
3276 fc_snprintf(buffer, sizeof(buffer), "unit.battlegroup_%d", i);
3277 fc_snprintf(buffer2, sizeof(buffer2), "city.size_%d", i + 1);
3280 }
3281 SET_SPRITE(unit.lowfuel, "unit.lowfuel");
3282 SET_SPRITE(unit.tired, "unit.tired");
3283
3284 SET_SPRITE_OPT(unit.action_decision_want, "unit.action_decision_want");
3285
3286 for (i = 0; i < NUM_TILES_HP_BAR; i++) {
3287 fc_snprintf(buffer, sizeof(buffer), "unit.hp_%d", i*10);
3288 SET_SPRITE(unit.hp_bar[i], buffer);
3289 }
3290
3291 for (i = 0; i < MAX_VET_LEVELS; i++) {
3292 /* Veteran level sprites are optional. For instance "green" units
3293 * usually have no special graphic. */
3294 fc_snprintf(buffer, sizeof(buffer), "unit.vet_%d", i);
3295 t->sprites.unit.vet_lev[i] = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3296 }
3297
3298 t->sprites.unit.select[0] = NULL;
3299 if (sprite_exists(t, "unit.select0")) {
3300 for (i = 0; i < NUM_TILES_SELECT; i++) {
3301 fc_snprintf(buffer, sizeof(buffer), "unit.select%d", i);
3302 SET_SPRITE(unit.select[i], buffer);
3303 }
3304 }
3305
3306 SET_SPRITE(citybar.shields, "citybar.shields");
3307 SET_SPRITE(citybar.food, "citybar.food");
3308 SET_SPRITE(citybar.trade, "citybar.trade");
3309 SET_SPRITE(citybar.occupied, "citybar.occupied");
3310 SET_SPRITE(citybar.background, "citybar.background");
3312 for (i = 0; ; i++) {
3313 struct sprite *sprite;
3314
3315 fc_snprintf(buffer, sizeof(buffer), "citybar.occupancy_%d", i);
3316 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3317 if (!sprite) {
3318 break;
3319 }
3321 }
3322 if (t->sprites.citybar.occupancy.size < 2) {
3324 _("Missing necessary citybar.occupancy_N sprites."));
3325 }
3326
3327#define SET_EDITOR_SPRITE(x) SET_SPRITE(editor.x, "editor." #x)
3328 SET_EDITOR_SPRITE(erase);
3329 SET_EDITOR_SPRITE(brush);
3330 SET_EDITOR_SPRITE(copy);
3331 SET_EDITOR_SPRITE(paste);
3332 SET_EDITOR_SPRITE(copypaste);
3335 SET_EDITOR_SPRITE(terrain_resource);
3336 SET_EDITOR_SPRITE(terrain_special);
3340 SET_EDITOR_SPRITE(territory);
3341 SET_EDITOR_SPRITE(properties);
3343 SET_EDITOR_SPRITE(military_base);
3344#undef SET_EDITOR_SPRITE
3345
3346 SET_SPRITE(city.disorder, "city.disorder");
3347
3348 /* Fallbacks for goto path turn numbers:
3349 * path.step_%d, path.exhausted_mp_%d
3350 * --> path.turns_%d
3351 * --> city.size_%d */
3352#define SET_GOTO_TURN_SPRITE(state, state_name, factor, factor_name) \
3353 fc_snprintf(buffer, sizeof(buffer), "path." state_name "_%d" #factor, i); \
3354 SET_SPRITE_OPT(path.s[state].turns ## factor_name [i], buffer); \
3355 if (t->sprites.path.s[state].turns ## factor_name [i] == NULL) { \
3356 t->sprites.path.s[state].turns ## factor_name [i] = \
3357 t->sprites.path.s[GTS_MP_LEFT].turns ## factor_name [i]; \
3358 }
3359
3360 for (i = 0; i < NUM_TILES_DIGITS; i++) {
3361 fc_snprintf(buffer, sizeof(buffer), "city.size_%d", i);
3362 SET_SPRITE(city.size[i], buffer);
3363 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d", i);
3364 SET_SPRITE_ALT(path.s[GTS_MP_LEFT].turns[i], buffer2, buffer);
3366 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp",,);
3367
3368 fc_snprintf(buffer, sizeof(buffer), "city.size_%d0", i);
3369 SET_SPRITE(city.size_tens[i], buffer);
3370 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d0", i);
3371 SET_SPRITE_ALT(path.s[GTS_MP_LEFT].turns_tens[i], buffer2, buffer);
3373 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp", 0, _tens);
3374
3375 fc_snprintf(buffer, sizeof(buffer), "city.size_%d00", i);
3376 SET_SPRITE_OPT(city.size_hundreds[i], buffer);
3377 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d00", i);
3378 SET_SPRITE_ALT_OPT(path.s[GTS_MP_LEFT].turns_hundreds[i], buffer2,
3379 buffer);
3381 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp", 00, _hundreds);
3382
3383 fc_snprintf(buffer, sizeof(buffer), "city.t_food_%d", i);
3384 SET_SPRITE(city.tile_foodnum[i], buffer);
3385 fc_snprintf(buffer, sizeof(buffer), "city.t_shields_%d", i);
3386 SET_SPRITE(city.tile_shieldnum[i], buffer);
3387 fc_snprintf(buffer, sizeof(buffer), "city.t_trade_%d", i);
3388 SET_SPRITE(city.tile_tradenum[i], buffer);
3389 }
3390#undef SET_GOTO_TURN_SPRITE
3391
3392 /* Must have at least one upkeep sprite per output type (and unhappy) */
3393 /* The rest are optional; we copy the previous sprite for unspecified ones */
3394 fc_strlcpy(buffer, "upkeep.unhappy", sizeof(buffer));
3395 SET_SPRITE(upkeep.unhappy[0], buffer);
3396 for (i = 1; i < MAX_NUM_UPKEEP_SPRITES; i++) {
3397 fc_snprintf(buffer2, sizeof(buffer2), "upkeep.unhappy%d", i+1);
3398 if (sprite_exists(t, buffer2)) {
3399 SET_SPRITE(upkeep.unhappy[i], buffer2);
3400 fc_strlcpy(buffer, buffer2, sizeof(buffer));
3401 } else {
3402 SET_SPRITE(upkeep.unhappy[i], buffer);
3403 }
3404 }
3406 fc_snprintf(buffer, sizeof(buffer),
3407 "upkeep.%s", get_output_identifier(o));
3408 SET_SPRITE_OPT(upkeep.output[o][0], buffer);
3409 for (i = 1; i < MAX_NUM_UPKEEP_SPRITES; i++) {
3410 fc_snprintf(buffer2, sizeof(buffer2),
3411 "upkeep.%s%d", get_output_identifier(o), i+1);
3412 if (sprite_exists(t, buffer2)) {
3413 SET_SPRITE(upkeep.output[o][i], buffer2);
3414 fc_strlcpy(buffer, buffer2, sizeof(buffer));
3415 } else {
3416 /* Optional, as maybe the upkeep 1 sprite didn't exist either */
3417 SET_SPRITE_OPT(upkeep.output[o][i], buffer);
3418 }
3419 }
3421
3423
3424 SET_SPRITE(user.attention, "user.attention");
3425 SET_SPRITE(user.infratile, "user.infratile");
3426
3427 SET_SPRITE_OPT(path.s[GTS_MP_LEFT].specific, "path.normal");
3428 SET_SPRITE_OPT(path.s[GTS_EXHAUSTED_MP].specific, "path.exhausted_mp");
3429 SET_SPRITE_OPT(path.s[GTS_TURN_STEP].specific, "path.step");
3430 SET_SPRITE(path.waypoint, "path.waypoint");
3431
3432 SET_SPRITE_NOTSMOOTH(tx.fog, "tx.fog");
3433
3435 for (i = 0; ; i++) {
3436 struct sprite *sprite;
3437
3438 fc_snprintf(buffer, sizeof(buffer), "colors.overlay_%d", i);
3439 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3440 if (!sprite) {
3441 break;
3442 }
3444 }
3445 if (i == 0) {
3447 _("Missing overlay-color sprite colors.overlay_0."));
3448 }
3449
3450 /* Chop up and build the overlay graphics. */
3455 for (i = 0; i < sprite_vector_size(&t->sprites.colors.overlays); i++) {
3456 struct sprite *color, *color_mask;
3457 struct sprite *worked, *unworked;
3458
3460 color_mask = crop_sprite(color, 0, 0, W, H, t->sprites.mask.tile, 0, 0,
3461 1.0f, FALSE);
3462 worked = crop_sprite(color_mask, 0, 0, W, H,
3463 t->sprites.mask.worked_tile, 0, 0, 1.0f, FALSE);
3464 unworked = crop_sprite(color_mask, 0, 0, W, H,
3465 t->sprites.mask.unworked_tile, 0, 0, 1.0f, FALSE);
3467 t->sprites.city.worked_tile_overlay.p[i] = worked;
3469 }
3470
3471
3472 {
3473 SET_SPRITE(grid.unavailable, "grid.unavailable");
3474 SET_SPRITE_OPT(grid.nonnative, "grid.nonnative");
3475
3476 for (i = 0; i < EDGE_COUNT; i++) {
3477 int be;
3478
3479 if (i == EDGE_UD && t->hex_width == 0) {
3480 continue;
3481 } else if (i == EDGE_LR && t->hex_height == 0) {
3482 continue;
3483 }
3484
3485 fc_snprintf(buffer, sizeof(buffer), "grid.main.%s", edge_name[i]);
3486 SET_SPRITE(grid.main[i], buffer);
3487
3488 fc_snprintf(buffer, sizeof(buffer), "grid.city.%s", edge_name[i]);
3489 SET_SPRITE(grid.city[i], buffer);
3490
3491 fc_snprintf(buffer, sizeof(buffer), "grid.worked.%s", edge_name[i]);
3492 SET_SPRITE(grid.worked[i], buffer);
3493
3494 fc_snprintf(buffer, sizeof(buffer), "grid.selected.%s", edge_name[i]);
3495 SET_SPRITE(grid.selected[i], buffer);
3496
3497 fc_snprintf(buffer, sizeof(buffer), "grid.coastline.%s", edge_name[i]);
3498 SET_SPRITE(grid.coastline[i], buffer);
3499
3500 for (be = 0; be < 2; be++) {
3501 fc_snprintf(buffer, sizeof(buffer), "grid.borders.%c",
3502 edge_name[i][be]);
3503 SET_SPRITE(grid.borders[i][be], buffer);
3504 }
3505 }
3506 }
3507
3508 switch (t->darkness_style) {
3509 case DARKNESS_NONE:
3510 /* Nothing. */
3511 break;
3512 case DARKNESS_ISORECT:
3513 {
3514 /* Isometric: take a single tx.darkness tile and split it into 4. */
3515 struct sprite *darkness = load_sprite(t, "tx.darkness",
3516 TRUE, FALSE, FALSE);
3517 const int ntw = t->normal_tile_width, nth = t->normal_tile_height;
3518 int offsets[4][2] = {{ntw / 2, 0}, {0, nth / 2}, {ntw / 2, nth / 2}, {0, 0}};
3519
3520 if (!darkness) {
3522 _("Sprite tx.darkness missing."));
3523 }
3524 for (i = 0; i < 4; i++) {
3525 t->sprites.tx.darkness[i] = crop_sprite(darkness, offsets[i][0],
3526 offsets[i][1], ntw / 2,
3527 nth / 2, NULL, 0, 0, 1.0f,
3528 FALSE);
3529 }
3530 }
3531 break;
3533 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
3534 enum direction8 dir = t->cardinal_tileset_dirs[i];
3535
3536 fc_snprintf(buffer, sizeof(buffer), "tx.darkness_%s",
3538 SET_SPRITE_NOTSMOOTH(tx.darkness[i], buffer);
3539 }
3540 break;
3541 case DARKNESS_CARD_FULL:
3542 for (i = 1; i < t->num_index_cardinal; i++) {
3543 fc_snprintf(buffer, sizeof(buffer), "tx.darkness_%s",
3544 cardinal_index_str(t, i));
3545 SET_SPRITE_NOTSMOOTH(tx.darkness[i], buffer);
3546 }
3547 break;
3548 case DARKNESS_CORNER:
3550 81 * sizeof(*t->sprites.tx.fullfog));
3551 for (i = 0; i < 81; i++) {
3552 /* Unknown, fog, known. */
3553 char ids[] = {'u', 'f', 'k'};
3554 char buf[512] = "t.fog";
3555 int values[4], vi, k = i;
3556
3557 for (vi = 0; vi < 4; vi++) {
3558 values[vi] = k % 3;
3559 k /= 3;
3560
3561 cat_snprintf(buf, sizeof(buf), "_%c", ids[values[vi]]);
3562 }
3563 fc_assert(k == 0);
3564
3566 }
3567 break;
3568 };
3569
3570 /* no other place to initialize these variables */
3573}
3574
3575/************************************************************************/
3578static bool load_river_sprites(struct tileset *t,
3579 struct river_sprites *store, const char *tag_pfx)
3580{
3581 int i;
3582 char buffer[512];
3583
3584 for (i = 0; i < t->num_index_cardinal; i++) {
3585 fc_snprintf(buffer, sizeof(buffer), "%s_s_%s",
3587 store->spec[i] = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3588 if (store->spec[i] == NULL) {
3589 return FALSE;
3590 }
3591 }
3592
3593 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
3594 fc_snprintf(buffer, sizeof(buffer), "%s_outlet_%s",
3596 store->outlet[i] = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3597 if (store->outlet[i] == NULL) {
3598 log_error("Missing \"%s\" for \"%s\".", buffer, tag_pfx);
3599 return FALSE;
3600 }
3601 }
3602
3603 return TRUE;
3604}
3605
3606/************************************************************************/
3613{
3615 if (sf->big_sprite) {
3616 free_sprite(sf->big_sprite);
3617 sf->big_sprite = NULL;
3618 }
3620}
3621
3622/************************************************************************/
3633
3634/************************************************************************/
3640 enum log_level level,
3641 const char *tag, const char *alt,
3642 const char *alt2,
3643 const char *what, const char *name,
3644 bool scale)
3645{
3646 struct sprite *sp;
3647
3648 /* (Should get sprite_hash before connection) */
3650 "attempt to lookup for %s \"%s\" before "
3651 "sprite_hash setup", what, name);
3652
3653 sp = load_sprite(t, tag, scale, TRUE, FALSE);
3654 if (sp) return sp;
3655
3656 sp = load_sprite(t, alt, scale, TRUE, FALSE);
3657 if (sp) {
3658 log_verbose("Using alternate graphic \"%s\" "
3659 "(instead of \"%s\") for %s \"%s\".",
3660 alt, tag, what, name);
3661 return sp;
3662 }
3663
3664 if (alt2 != NULL) {
3665 sp = load_sprite(t, alt2, scale, TRUE, FALSE);
3666 if (sp) {
3667 log_verbose("Using second alternate graphic \"%s\" "
3668 "(instead of \"%s\" or \"%s\") for %s \"%s\".",
3669 alt2, tag, alt, what, name);
3670 return sp;
3671 }
3672 }
3673
3675 _("Don't have graphics tags \"%s\" or \"%s\" for %s \"%s\"."),
3676 tag, alt, what, name);
3677
3678 return NULL;
3679}
3680
3681/************************************************************************/
3686 int uidx,
3687 const char *base_str,
3688 enum direction8 dir,
3689 enum unit_activity activity,
3690 bool has_icon)
3691{
3692 enum direction8 loaddir = dir;
3693 char buf[2048];
3694 const char *act_name = unit_activity_name(activity);
3695
3696 if (act_name == NULL) {
3697 /* gcc-9 thinks this is possible. */
3698 return FALSE;
3699 }
3700
3701 /*
3702 * There may be more orientations available in this tileset than are
3703 * needed, if an oriented unit set has been reused between tilesets.
3704 *
3705 * Don't bother loading unused ones, unless they might be used by
3706 * unit_default_orientation (logic here mirrors get_unittype_sprite()).
3707 */
3708 if (!(dir == t->unit_default_orientation && !has_icon)
3709 && !is_valid_tileset_dir(t, dir)) {
3710 /* Instead we copy a nearby valid dir's sprite, so we're not caught
3711 * out in case this tileset is used with an incompatible topology,
3712 * although it'll be ugly. */
3713 do {
3715 /* This loop _should_ terminate... */
3717 } while (!is_valid_tileset_dir(t, loaddir));
3718 }
3719
3720 fc_snprintf(buf, sizeof(buf), "%s_%s_%s", base_str,
3722
3723 /* We don't use _alt graphics here, as that could lead to loading
3724 * real icon gfx, but alternative orientation gfx. Tileset author
3725 * probably meant icon gfx to be used as fallback for all orientations */
3726 t->sprites.units.facing[uidx][dir][activity] = load_sprite(t, buf,
3727 TRUE, TRUE, FALSE);
3728
3729 if (activity == ACTIVITY_IDLE
3730 && t->sprites.units.facing[uidx][dir][activity] == NULL) {
3731 /* Backward compatibility: Set Idle sprite from tag with no activity defined. */
3732 fc_snprintf(buf, sizeof(buf), "%s_%s", base_str,
3734
3735 t->sprites.units.facing[uidx][dir][activity] = load_sprite(t, buf,
3736 TRUE, TRUE, FALSE);
3737 }
3738
3739 if (t->sprites.units.facing[uidx][dir][activity] != NULL) {
3740 return TRUE;
3741 }
3742
3743 return FALSE;
3744}
3745
3746/************************************************************************/
3750 int uidx,
3751 const char *tag)
3752{
3754
3755 activity_type_iterate(activity) {
3756 char buffer[2048];
3757
3758 fc_snprintf(buffer, sizeof(buffer), "%s_%s",
3759 tag, unit_activity_name(activity));
3760 t->sprites.units.icon[uidx][activity] = load_sprite(t, buffer,
3761 TRUE, TRUE, FALSE);
3762
3763 if (activity == ACTIVITY_IDLE
3764 && t->sprites.units.icon[uidx][activity] == NULL) {
3765 /* Backward compatibility: Set Idle sprite from tag with no activity defined. */
3766 t->sprites.units.icon[uidx][activity] = load_sprite(t, tag,
3767 TRUE, TRUE, FALSE);
3768 }
3770
3772
3773#define LOAD_FACING_SPRITE(dir) \
3774 if (!tileset_setup_unit_direction(t, uidx, tag, dir, activity, has_icon)) { \
3775 facing_sprites[activity] = FALSE; \
3776 }
3777
3778 activity_type_iterate(activity) {
3779 facing_sprites[activity] = TRUE;
3780
3789
3791
3793 /* Neither icon gfx or orientation sprites */
3794 return FALSE;
3795 }
3796
3797 return TRUE;
3798
3799#undef LOAD_FACING_SPRITE
3800}
3801
3802/************************************************************************/
3807{
3808 int uidx = utype_index(ut);
3809
3810 if (!tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_str)
3811 && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt)
3812 && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt2)) {
3814 _("Missing %s unit sprite for tags \"%s\" and alternatives "
3815 "\"%s\" and \"%s\"."),
3816 utype_rule_name(ut), ut->graphic_str,
3817 ut->graphic_alt, ut->graphic_alt2);
3818 }
3819
3820 if (!t->sprites.units.icon[uidx][ACTIVITY_IDLE]) {
3823 _("Unit type %s has no unoriented sprite and "
3824 "tileset has no unit_default_orientation."),
3826 } else {
3827 /* We're guaranteed to have an oriented sprite corresponding to
3828 * unit_default_orientation, because tileset_setup_unit_type_from_tag()
3829 * checked for this. */
3831 != NULL);
3832 }
3833 }
3834}
3835
3836/************************************************************************/
3841 struct impr_type *pimprove)
3842{
3843 t->sprites.building[improvement_index(pimprove)]
3845 pimprove->graphic_alt, pimprove->graphic_alt2,
3846 "improvement",
3847 improvement_rule_name(pimprove), FALSE);
3848
3849 /* Should maybe do something if NULL, eg generic default? */
3850}
3851
3852/************************************************************************/
3857 struct advance *padvance)
3858{
3859 if (valid_advance(padvance)) {
3862 padvance->graphic_alt, NULL, "technology",
3864
3865 /* Should maybe do something if NULL, eg generic default? */
3866 } else {
3868 }
3869}
3870
3871/************************************************************************/
3876 struct extra_type *pextra)
3877{
3878 const int id = extra_index(pextra);
3879 enum extrastyle_id extrastyle;
3880
3881 if (!fc_strcasecmp(pextra->graphic_str, "none")) {
3882 /* Extra without graphics */
3884 } else {
3885 const char *tag;
3886
3887 tag = pextra->graphic_str;
3888 if (!estyle_hash_lookup(t->estyle_hash, tag, &extrastyle)) {
3889 tag = pextra->graphic_alt;
3890 if (!estyle_hash_lookup(t->estyle_hash, tag, &extrastyle)) {
3892 _("No extra style for \"%s\" or \"%s\"."),
3893 pextra->graphic_str,
3894 pextra->graphic_alt);
3895 } else {
3896 log_verbose("Using alternate graphic \"%s\" "
3897 "(instead of \"%s\") for extra \"%s\".",
3898 pextra->graphic_alt, pextra->graphic_str,
3899 extra_rule_name(pextra));
3900 }
3901 }
3902
3903 t->sprites.extras[id].extrastyle = extrastyle;
3904
3905 extra_type_list_append(t->style_lists[extrastyle], pextra);
3906
3907 if (extra_has_flag(pextra, EF_SHOW_FLAG)) {
3909 }
3910
3911 switch (extrastyle) {
3912 case ESTYLE_3LAYER:
3913 tileset_setup_base(t, pextra, tag);
3914 break;
3915
3919 case ESTYLE_RIVER:
3920 tileset_setup_road(t, pextra, tag);
3921 break;
3922
3923 case ESTYLE_SINGLE1:
3924 case ESTYLE_SINGLE2:
3925 SET_SPRITE(extras[id].u.single, tag);
3926 break;
3927
3928 case ESTYLE_CARDINALS:
3929 {
3930 int i;
3931 char buffer[512];
3932
3933 /* We use direction-specific irrigation and farmland graphics, if they
3934 * are available. If not, we just fall back to the basic irrigation
3935 * graphics. */
3936 for (i = 0; i < t->num_index_cardinal; i++) {
3937 fc_snprintf(buffer, sizeof(buffer), "%s_%s",
3938 tag, cardinal_index_str(t, i));
3939 t->sprites.extras[id].u.cardinals[i] = load_sprite(t, buffer,
3940 TRUE, TRUE, FALSE);
3941 if (!t->sprites.extras[id].u.cardinals[i]) {
3942 t->sprites.extras[id].u.cardinals[i] = load_sprite(t, tag,
3943 TRUE, TRUE, FALSE);
3944 }
3945 if (!t->sprites.extras[id].u.cardinals[i]) {
3947 _("No cardinal-style graphics \"%s*\" for "
3948 "extra \"%s\""),
3949 tag, extra_rule_name(pextra));
3950 }
3951 }
3952 }
3953 break;
3954 case ESTYLE_COUNT:
3955 break;
3956 }
3957 }
3958
3959 if (!fc_strcasecmp(pextra->activity_gfx, "none")) {
3961 } else {
3963 TRUE, TRUE, FALSE);
3964 if (t->sprites.extras[id].activity == NULL) {
3966 TRUE, TRUE, FALSE);
3967 }
3968 if (t->sprites.extras[id].activity == NULL) {
3970 TRUE, TRUE, FALSE);
3971 }
3972 if (t->sprites.extras[id].activity == NULL) {
3974 _("Missing %s building activity sprite for tags \"%s\" and alternatives \"%s\" and \"%s\"."),
3975 extra_rule_name(pextra), pextra->activity_gfx,
3976 pextra->act_gfx_alt, pextra->act_gfx_alt2);
3977 }
3978 }
3979
3980 if (!fc_strcasecmp(pextra->rmact_gfx, "none")) {
3981 t->sprites.extras[id].rmact = NULL;
3982 } else {
3983 t->sprites.extras[id].rmact = load_sprite(t, pextra->rmact_gfx,
3984 TRUE, TRUE, FALSE);
3985 if (t->sprites.extras[id].rmact == NULL) {
3987 TRUE, TRUE, FALSE);
3988 if (t->sprites.extras[id].rmact == NULL) {
3990 TRUE, TRUE, FALSE);
3991 if (t->sprites.extras[id].rmact == NULL) {
3993 _("Missing %s removal activity sprite for tags \"%s\" "
3994 "and alternatives \"%s\" and \"%s\"."),
3995 extra_rule_name(pextra), pextra->rmact_gfx,
3996 pextra->rmact_gfx_alt, pextra->rmact_gfx_alt2);
3997 }
3998 }
3999 }
4000 }
4001}
4002
4003/************************************************************************/
4007static void tileset_setup_road(struct tileset *t,
4008 struct extra_type *pextra,
4009 const char *tag)
4010{
4011 char full_tag_name[MAX_LEN_NAME + sizeof("_isolated")];
4012 const int id = extra_index(pextra);
4013 int i;
4014 enum extrastyle_id extrastyle = t->sprites.extras[id].extrastyle;
4015
4016 /* Isolated road graphics are used by ESTYLE_ROAD_ALL_SEPARATE and
4017 ESTYLE_ROAD_PARITY_COMBINED. */
4018 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4019 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4021 "%s_isolated", tag);
4022
4023 SET_SPRITE(extras[id].u.road.isolated, full_tag_name);
4024 }
4025
4026 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
4027 /* ESTYLE_ROAD_ALL_SEPARATE has just 8 additional sprites for each
4028 * road type: one going off in each direction. */
4029 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4030 enum direction8 dir = t->valid_tileset_dirs[i];
4031 const char *dir_name = dir_get_tileset_name(dir);
4032
4034 "%s_%s", tag, dir_name);
4035
4036 SET_SPRITE(extras[id].u.road.ru.dir[i], full_tag_name);
4037 }
4038 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4039 int num_index = 1 << (t->num_valid_tileset_dirs / 2), j;
4040
4041 /* ESTYLE_ROAD_PARITY_COMBINED has 32 additional sprites for each road
4042 * type: 16 each for cardinal and diagonal directions. Each set
4043 * of 16 provides a NSEW-indexed sprite to provide connectors for
4044 * all rails in the cardinal/diagonal directions. The 0 entry is
4045 * unused (the "isolated" sprite is used instead). */
4046
4047 for (i = 1; i < num_index; i++) {
4048 char c[64] = "", d[64] = "";
4049
4050 for (j = 0; j < t->num_valid_tileset_dirs / 2; j++) {
4051 int value = (i >> j) & 1;
4052
4053 cat_snprintf(c, sizeof(c), "%s%d",
4055 value);
4056 cat_snprintf(d, sizeof(d), "%s%d",
4058 value);
4059 }
4060
4062 "%s_c_%s", tag, c);
4063
4064 SET_SPRITE(extras[id].u.road.ru.combo.even[i], full_tag_name);
4065
4067 "%s_d_%s", tag, d);
4068
4069 SET_SPRITE(extras[id].u.road.ru.combo.odd[i], full_tag_name);
4070 }
4071 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
4072 /* ESTYLE_ROAD_ALL_COMBINED includes 256 sprites, one for every possibility.
4073 * Just go around clockwise, with all combinations. */
4074 for (i = 0; i < t->num_index_valid; i++) {
4075 char *idx_str = valid_index_str(t, i);
4076
4078 "%s_%s", tag, idx_str);
4079
4080 SET_SPRITE(extras[id].u.road.ru.total[i], full_tag_name);
4081 }
4082 } else if (extrastyle == ESTYLE_RIVER) {
4083 if (!load_river_sprites(t, &t->sprites.extras[id].u.road.ru.rivers, tag)) {
4085 _("No river-style graphics \"%s*\" for extra \"%s\""),
4086 tag, extra_rule_name(pextra));
4087 }
4088 } else {
4090 }
4091
4092 /* Corner road graphics are used by ESTYLE_ROAD_ALL_SEPARATE,
4093 * ESTYLE_ROAD_PARITY_COMBINED and ESTYLE_ROAD_ALL_COMBINED. */
4094 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4095 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED
4096 || extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
4097 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4098 enum direction8 dir = t->valid_tileset_dirs[i];
4099
4100 if (!is_cardinal_tileset_dir(t, dir)) {
4101 const char *dtn = dir_get_tileset_name(dir);
4102
4104 "%s_c_%s", pextra->graphic_str, dtn);
4105
4106 SET_SPRITE_OPT(extras[id].u.road.corner[dir], full_tag_name);
4107 }
4108 }
4109 }
4110}
4111
4112/************************************************************************/
4116static void tileset_setup_base(struct tileset *t,
4117 const struct extra_type *pextra,
4118 const char *tag)
4119{
4120 char full_tag_name[MAX_LEN_NAME + sizeof("_fg")];
4121 const int id = extra_index(pextra);
4122
4123 fc_assert_ret(id >= 0 && id < extra_count());
4124
4126 strcat(full_tag_name, "_bg");
4128 TRUE, TRUE, FALSE);
4129
4131 strcat(full_tag_name, "_mg");
4133 TRUE, TRUE, FALSE);
4134
4136 strcat(full_tag_name, "_fg");
4138 TRUE, TRUE, FALSE);
4139
4140 if (t->sprites.extras[id].u.bmf.background == NULL
4141 && t->sprites.extras[id].u.bmf.middleground == NULL
4142 && t->sprites.extras[id].u.bmf.foreground == NULL) {
4143 /* There was an extra style definition but no matching graphics */
4145 _("No graphics with tag \"%s_bg/mg/fg\" for extra \"%s\""),
4146 tag, extra_rule_name(pextra));
4147 }
4148}
4149
4150/************************************************************************/
4155 const struct terrain *pterrain)
4156{
4157 struct drawing_data *draw;
4158 struct sprite *sprite;
4159 char buffer[MAX_LEN_NAME + 20];
4160 int i, l;
4161
4162 if (!drawing_hash_lookup(t->tile_hash, pterrain->graphic_str, &draw)
4163 && !drawing_hash_lookup(t->tile_hash, pterrain->graphic_alt, &draw)
4164 && !drawing_hash_lookup(t->tile_hash, pterrain->graphic_alt2, &draw)) {
4166 _("Terrain \"%s\": no graphic tile \"%s\", \"%s\", or \"%s\"."),
4167 terrain_rule_name(pterrain), pterrain->graphic_str,
4168 pterrain->graphic_alt, pterrain->graphic_alt2);
4169 }
4170
4171 if (draw->init) {
4172 t->sprites.drawing[terrain_index(pterrain)] = draw;
4173 return;
4174 }
4175
4176 /* Set up each layer of the drawing. */
4177 for (l = 0; l < draw->num_layers; l++) {
4178 struct drawing_layer *dlp = &draw->layer[l];
4179 struct tileset_layer *tslp = &t->layers[l];
4180 sprite_vector_init(&dlp->base);
4181 sprite_vector_init(&dlp->allocated);
4182
4183 switch (dlp->sprite_type) {
4184 case CELL_WHOLE:
4185 switch (dlp->match_style) {
4186 case MATCH_NONE:
4187 /* Load whole sprites for this tile. */
4188 for (i = 0; ; i++) {
4189 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s%d",
4190 l, draw->name, i + 1);
4191 sprite = load_sprite(t, buffer, TRUE, FALSE, FALSE);
4192 if (!sprite) {
4193 break;
4194 }
4195 sprite_vector_reserve(&dlp->base, i + 1);
4196 dlp->base.p[i] = sprite;
4197 }
4198 /* Check for base sprite, allowing missing sprites above base */
4199 if (0 == i && 0 == l) {
4200 /* TRANS: 'base' means 'base of terrain gfx', not 'military base' */
4202 _("Missing base sprite for tag \"%s\"."), buffer);
4203 }
4204 break;
4205 case MATCH_SAME:
4206 /* Load 16 cardinally-matched sprites. */
4207 for (i = 0; i < t->num_index_cardinal; i++) {
4208 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_%s",
4209 l, draw->name, cardinal_index_str(t, i));
4210 dlp->match[i]
4211 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4212 NULL, "matched terrain",
4213 terrain_rule_name(pterrain), TRUE);
4214 }
4215 break;
4216 case MATCH_PAIR:
4217 case MATCH_FULL:
4218 fc_assert(FALSE); /* Not yet defined */
4219 break;
4220 };
4221 break;
4222 case CELL_CORNER:
4223 {
4224 const int count = dlp->match_indices;
4225 int number = NUM_CORNER_DIRS;
4226
4227 switch (dlp->match_style) {
4228 case MATCH_NONE:
4229 /* Do nothing */
4230 break;
4231 case MATCH_PAIR:
4232 case MATCH_SAME:
4233 /* N directions (NSEW) * 3 dimensions of matching */
4234 fc_assert(count == 2);
4235 number = NUM_CORNER_DIRS * 2 * 2 * 2;
4236 break;
4237 case MATCH_FULL:
4238 default:
4239 /* N directions (NSEW) * 3 dimensions of matching */
4240 /* could use exp() or expi() here? */
4241 number = NUM_CORNER_DIRS * count * count * count;
4242 break;
4243 };
4244
4245 dlp->cells
4246 = fc_calloc(number, sizeof(*dlp->cells));
4247
4248 for (i = 0; i < number; i++) {
4249 enum direction4 dir = i % NUM_CORNER_DIRS;
4250 int value = i / NUM_CORNER_DIRS;
4251
4252 switch (dlp->match_style) {
4253 case MATCH_NONE:
4254 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c",
4255 l, draw->name, direction4letters[dir]);
4256 dlp->cells[i]
4257 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4258 NULL, "cell terrain",
4259 terrain_rule_name(pterrain), TRUE);
4260 break;
4261 case MATCH_SAME:
4262 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c%d%d%d",
4263 l, draw->name, direction4letters[dir],
4264 (value) & 1, (value >> 1) & 1, (value >> 2) & 1);
4265 dlp->cells[i]
4266 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4267 NULL, "same cell terrain",
4268 terrain_rule_name(pterrain), TRUE);
4269 break;
4270 case MATCH_PAIR:
4271 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c_%c_%c_%c",
4272 l, draw->name, direction4letters[dir],
4273 tslp->match_types[dlp->match_index[(value) & 1]][0],
4274 tslp->match_types[dlp->match_index[(value >> 1) & 1]][0],
4275 tslp->match_types[dlp->match_index[(value >> 2) & 1]][0]);
4276 dlp->cells[i]
4277 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4278 NULL, "cell pair terrain",
4279 terrain_rule_name(pterrain), TRUE);
4280 break;
4281 case MATCH_FULL:
4282 {
4283 int this = dlp->match_index[0];
4284 int n, s, e, w;
4285 int v1, v2, v3;
4286
4287 v1 = dlp->match_index[value % count];
4288 value /= count;
4289 v2 = dlp->match_index[value % count];
4290 value /= count;
4291 v3 = dlp->match_index[value % count];
4292
4293 fc_assert(v1 < count && v2 < count && v3 < count);
4294
4295 /* Assume merged cells. This should be a separate option. */
4296 switch (dir) {
4297 case DIR4_NORTH:
4298 s = this;
4299 w = v1;
4300 n = v2;
4301 e = v3;
4302 break;
4303 case DIR4_EAST:
4304 w = this;
4305 n = v1;
4306 e = v2;
4307 s = v3;
4308 break;
4309 case DIR4_SOUTH:
4310 n = this;
4311 e = v1;
4312 s = v2;
4313 w = v3;
4314 break;
4315 case DIR4_WEST:
4316 default: /* Avoid warnings */
4317 e = this;
4318 s = v1;
4319 w = v2;
4320 n = v3;
4321 break;
4322 };
4323
4324 /* Use first character of match_types,
4325 * already checked for uniqueness. */
4326 fc_snprintf(buffer, sizeof(buffer),
4327 "t.l%d.cellgroup_%c_%c_%c_%c", l,
4328 tslp->match_types[n][0], tslp->match_types[e][0],
4329 tslp->match_types[s][0], tslp->match_types[w][0]);
4330 sprite = load_sprite(t, buffer, TRUE, FALSE, FALSE);
4331
4332 if (sprite) {
4333 /* Crop the sprite to separate this cell. */
4334 int vec_size = sprite_vector_size(&dlp->allocated);
4335
4336 const int W = t->normal_tile_width;
4337 const int H = t->normal_tile_height;
4338 int x[4] = {W / 4, W / 4, 0, W / 2};
4339 int y[4] = {H / 2, 0, H / 4, H / 4};
4340 int xo[4] = {0, 0, -W / 2, W / 2};
4341 int yo[4] = {H / 2, -H / 2, 0, 0};
4342
4343 sprite = crop_sprite(sprite, x[dir], y[dir], W / 2, H / 2,
4344 t->sprites.mask.tile, xo[dir], yo[dir], 1.0f,
4345 FALSE);
4346 /* We allocated new sprite with crop_sprite. Store its
4347 * address so we can free it. */
4348 sprite_vector_reserve(&dlp->allocated, vec_size + 1);
4349 dlp->allocated.p[vec_size] = sprite;
4350 } else {
4351 log_error("Terrain graphics sprite for tag \"%s\" missing.", buffer);
4352 }
4353
4354 dlp->cells[i] = sprite;
4355 }
4356 break;
4357 };
4358 }
4359 }
4360 break;
4361 };
4362 }
4363
4364 /* Try an optional special name */
4365 fc_snprintf(buffer, sizeof(buffer), "t.blend.%s", draw->name);
4366 draw->blender
4368 NULL, "blend terrain",
4369 terrain_rule_name(pterrain), TRUE);
4370
4371 if (draw->blending > 0) {
4372 const int bl = draw->blending - 1;
4373
4374 if (NULL == draw->blender) {
4375 int li = 0;
4376
4377 /* Try an already loaded base */
4378 while (NULL == draw->blender
4379 && li < draw->blending
4380 && 0 < draw->layer[li].base.size) {
4381 draw->blender = draw->layer[li++].base.p[0];
4382 }
4383 }
4384
4385 if (NULL == draw->blender) {
4386 /* Try an unloaded base name */
4387 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s1", bl, draw->name);
4388 draw->blender
4389 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4390 NULL, "base (blend) terrain",
4391 terrain_rule_name(pterrain), TRUE);
4392 }
4393 }
4394
4395 if (NULL != draw->blender) {
4396 /* Set up blending sprites. This only works in iso-view! */
4397 const int W = t->normal_tile_width;
4398 const int H = t->normal_tile_height;
4399 const int offsets[4][2] = {
4400 {W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}
4401 };
4402 enum direction4 dir = 0;
4403
4404 for (; dir < 4; dir++) {
4405 draw->blend[dir] = crop_sprite(draw->blender, offsets[dir][0],
4406 offsets[dir][1], W / 2, H / 2,
4407 t->sprites.dither_tile, 0, 0, 1.0f,
4408 FALSE);
4409 }
4410 }
4411
4412 draw->init = TRUE;
4413 t->sprites.drawing[terrain_index(pterrain)] = draw;
4414}
4415
4416/************************************************************************/
4421 struct government *gov)
4422{
4425 gov->graphic_alt, NULL, "government",
4427
4428 /* Should probably do something if NULL, eg generic default? */
4429}
4430
4431/************************************************************************/
4436 struct nation_type *nation)
4437{
4438 char *tags[] = {nation->flag_graphic_str,
4439 nation->flag_graphic_alt,
4440 "unknown", NULL};
4441 int i;
4442 struct sprite *flag = NULL, *shield = NULL;
4443 char buf[1024];
4445
4446 for (i = 0; tags[i] && !flag; i++) {
4447 fc_snprintf(buf, sizeof(buf), "f.%s", tags[i]);
4448 flag = load_sprite(t, buf, TRUE, TRUE, svgflag);
4449 }
4450 for (i = 0; tags[i] && !shield; i++) {
4451 fc_snprintf(buf, sizeof(buf), "f.shield.%s", tags[i]);
4452 shield = load_sprite(t, buf, TRUE, TRUE, svgflag);
4453 }
4454 if (!flag || !shield) {
4455 /* Should never get here because of the f.unknown fallback. */
4457 _("Nation %s: no national flag."), nation_rule_name(nation));
4458 }
4459
4461 t->sprites.nation_flag.p[nation_index(nation)] = flag;
4462
4464 t->sprites.nation_shield.p[nation_index(nation)] = shield;
4465}
4466
4467/************************************************************************/
4470struct sprite *get_city_flag_sprite(const struct tileset *t,
4471 const struct city *pcity)
4472{
4473 return get_nation_flag_sprite(t, nation_of_city(pcity));
4474}
4475
4476/************************************************************************/
4479static struct sprite *get_unit_nation_flag_sprite(const struct tileset *t,
4480 const struct unit *punit)
4481{
4482 struct nation_type *pnation = nation_of_unit(punit);
4483
4485 return t->sprites.nation_shield.p[nation_index(pnation)];
4486 } else {
4487 return t->sprites.nation_flag.p[nation_index(pnation)];
4488 }
4489}
4490
4491#define FULL_TILE_X_OFFSET ((t->normal_tile_width - t->full_tile_width) / 2)
4492#define FULL_TILE_Y_OFFSET (t->normal_tile_height - t->full_tile_height)
4493
4494#define ADD_SPRITE(s, draw_fog, x_offset, y_offset) \
4495 (fc_assert(s != NULL), \
4496 sprs->sprite = s, \
4497 sprs->foggable = (draw_fog && t->fogstyle == FOG_AUTO), \
4498 sprs->offset_x = x_offset, \
4499 sprs->offset_y = y_offset, \
4500 sprs++)
4501#define ADD_SPRITE_SIMPLE(s) ADD_SPRITE(s, TRUE, 0, 0)
4502#define ADD_SPRITE_FULL(s) \
4503 ADD_SPRITE(s, TRUE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET)
4504
4505/************************************************************************/
4512static void build_tile_data(const struct tile *ptile,
4513 struct terrain *pterrain,
4514 struct terrain **tterrain_near,
4516{
4517 enum direction8 dir;
4518
4519 /* Loop over all adjacent tiles. We should have an iterator for this. */
4520 for (dir = 0; dir < 8; dir++) {
4521 struct tile *tile1 = mapstep(&(wld.map), ptile, dir);
4522
4525
4526 if (NULL != terrain1) {
4527 tterrain_near[dir] = terrain1;
4529 continue;
4530 }
4531 log_error("build_tile_data() tile (%d,%d) has no terrain!",
4532 TILE_XY(tile1));
4533 }
4534 /* At the edges of the (known) map, pretend the same terrain continued
4535 * past the edge of the map. */
4536 tterrain_near[dir] = pterrain;
4538 }
4539}
4540
4541/************************************************************************/
4544static int fill_unit_type_sprite_array(const struct tileset *t,
4545 struct drawn_sprite *sprs,
4546 const struct unit_type *putype,
4547 enum unit_activity activity,
4548 enum direction8 facing)
4549{
4550 struct drawn_sprite *save_sprs = sprs;
4551 struct sprite *uspr = get_unittype_sprite(t, putype, activity, facing);
4552
4556
4557 return sprs - save_sprs;
4558}
4559
4560/************************************************************************/
4563static int fill_unit_sprite_array(const struct tileset *t,
4564 struct drawn_sprite *sprs,
4565 const struct unit *punit,
4566 int stack, bool backdrop)
4567{
4568 struct drawn_sprite *save_sprs = sprs;
4569 int ihp;
4570 const struct unit_type *ptype = unit_type_get(punit);
4571
4572 if (backdrop) {
4577 } else {
4578 /* Taken care of in the LAYER_BACKGROUND. */
4579 }
4580 }
4581
4582 /* Add the sprite for the unit type. */
4585
4586 if (t->sprites.unit.loaded && unit_transported(punit)) {
4587 ADD_SPRITE_FULL(t->sprites.unit.loaded);
4588 }
4589
4590 if (punit->activity != ACTIVITY_IDLE) {
4591 struct sprite *s = NULL;
4592
4593 switch (punit->activity) {
4594 case ACTIVITY_MINE:
4595 if (punit->activity_target == NULL) {
4596 s = t->sprites.unit.plant;
4597 } else {
4599 }
4600 break;
4601 case ACTIVITY_PLANT:
4602 s = t->sprites.unit.plant;
4603 break;
4604 case ACTIVITY_IRRIGATE:
4605 if (punit->activity_target == NULL) {
4606 s = t->sprites.unit.cultivate;
4607 } else {
4609 }
4610 break;
4611 case ACTIVITY_CULTIVATE:
4612 s = t->sprites.unit.cultivate;
4613 break;
4614 case ACTIVITY_CLEAN:
4616 break;
4617 case ACTIVITY_PILLAGE:
4619 if (s == NULL) {
4620 s = t->sprites.unit.pillage;
4621 }
4622 break;
4623 case ACTIVITY_EXPLORE:
4624 /* Drawn below as the server side agent. */
4625 break;
4626 case ACTIVITY_FORTIFIED:
4627 s = t->sprites.unit.fortified;
4628 break;
4630 s = t->sprites.unit.fortifying;
4631 break;
4632 case ACTIVITY_SENTRY:
4633 s = t->sprites.unit.sentry;
4634 break;
4635 case ACTIVITY_GOTO:
4636 s = t->sprites.unit.go_to;
4637 break;
4638 case ACTIVITY_TRANSFORM:
4639 s = t->sprites.unit.transform;
4640 break;
4641 case ACTIVITY_BASE:
4642 case ACTIVITY_GEN_ROAD:
4644 break;
4645 case ACTIVITY_CONVERT:
4646 s = t->sprites.unit.convert;
4647 break;
4648 default:
4649 break;
4650 }
4651
4652 if (s != NULL) {
4655 }
4656 }
4657
4658 {
4659 struct sprite *s = NULL;
4660 int offset_x = 0;
4661 int offset_y = 0;
4662
4663 switch (punit->ssa_controller) {
4664 case SSA_NONE:
4665 break;
4666 case SSA_AUTOSETTLER:
4667 s = t->sprites.unit.auto_settler;
4668 break;
4669 case SSA_AUTOEXPLORE:
4670 s = t->sprites.unit.auto_explore;
4671 /* Specified as an activity in the tileset. */
4674 break;
4675 default:
4676 s = t->sprites.unit.auto_attack;
4677 break;
4678 }
4679
4680 if (s != NULL) {
4681 ADD_SPRITE(s, TRUE,
4684 }
4685 }
4686
4687 if (unit_has_orders(punit)) {
4688 if (punit->orders.repeat) {
4689 ADD_SPRITE_FULL(t->sprites.unit.patrol);
4690 } else if (punit->activity != ACTIVITY_IDLE) {
4691 ADD_SPRITE_SIMPLE(t->sprites.unit.connect);
4692 } else {
4693 ADD_SPRITE(t->sprites.unit.go_to, TRUE,
4696 }
4697 }
4698
4699 if (t->sprites.unit.action_decision_want != NULL
4701 ADD_SPRITE(t->sprites.unit.action_decision_want, TRUE,
4704 }
4705
4707 ADD_SPRITE_FULL(t->sprites.unit.battlegroup[punit->battlegroup]);
4708 }
4709
4710 if (t->sprites.unit.lowfuel
4711 && utype_fuel(ptype)
4712 && punit->fuel == 1
4713 && punit->moves_left <= 2 * SINGLE_MOVE) {
4714 /* Show a low-fuel graphic if the plane has 2 or fewer moves left. */
4715 ADD_SPRITE_FULL(t->sprites.unit.lowfuel);
4716 }
4717 if (t->sprites.unit.tired
4719 && ptype->move_rate > 0) {
4720 /* Show a "tired" graphic if the unit has fewer than one move
4721 * remaining, except for units for which it's full movement. */
4722 ADD_SPRITE_FULL(t->sprites.unit.tired);
4723 }
4724
4725 if (stack == 1 && punit->client.occupied) {
4726 ADD_SPRITE_FULL(t->sprites.unit.stack[0]);
4727 } else if (stack > 1) {
4729 && t->sprites.unit.num_stack_sprites >= stack) {
4730 ADD_SPRITE(t->sprites.unit.stack[stack - 1], FALSE,
4732 } else {
4733 ADD_SPRITE_FULL(t->sprites.unit.stack[0]);
4734 }
4735 }
4736
4737 if (t->sprites.unit.vet_lev[punit->veteran]) {
4739 }
4740
4741 ihp = ((NUM_TILES_HP_BAR-1)*punit->hp) / ptype->hp;
4742 ihp = CLIP(0, ihp, NUM_TILES_HP_BAR-1);
4743 ADD_SPRITE_FULL(t->sprites.unit.hp_bar[ihp]);
4744
4745 return sprs - save_sprs;
4746}
4747
4748/************************************************************************/
4751static int fill_road_corner_sprites(const struct tileset *t,
4752 const struct extra_type *pextra,
4753 struct drawn_sprite *sprs,
4754 bool road, bool *road_near,
4755 bool hider, bool *hider_near)
4756{
4757 struct drawn_sprite *saved_sprs = sprs;
4758 int i;
4759 int extra_idx = extra_index(pextra);
4760
4761 if (is_cardinal_only_road(pextra)) {
4762 return 0;
4763 }
4764
4765 /* Roads going diagonally adjacent to this tile need to be
4766 * partly drawn on this tile. */
4767
4768 /* Draw the corner sprite if:
4769 * - There is a diagonal road (not rail!) between two adjacent tiles.
4770 * - There is no diagonal road (not rail!) that intersects this road.
4771 * The logic is simple: roads are drawn underneath railrods, but are
4772 * not always covered by them (even in the corners!). But if a railroad
4773 * connects two tiles, only the railroad (no road) is drawn between
4774 * those tiles.
4775 */
4776 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4777 enum direction8 dir = t->valid_tileset_dirs[i];
4778
4779 if (!is_cardinal_tileset_dir(t, dir)) {
4780 /* Draw corner sprites for this non-cardinal direction. */
4781 int cw = (i + 1) % t->num_valid_tileset_dirs;
4782 int ccw
4784 enum direction8 cwdir = t->valid_tileset_dirs[cw];
4786
4787 if (t->sprites.extras[extra_idx].u.road.corner[dir]
4789 && !(hider_near[cwdir] && hider_near[ccwdir]))
4790 && !(road && road_near[dir] && !(hider && hider_near[dir]))) {
4792 }
4793 }
4794 }
4795
4796 return sprs - saved_sprs;
4797}
4798
4799/************************************************************************/
4802static int fill_road_sprite_array(const struct tileset *t,
4803 const struct extra_type *pextra,
4804 struct drawn_sprite *sprs,
4807 struct terrain *tterrain_near[8],
4808 const struct city *pcity)
4809{
4810 struct drawn_sprite *saved_sprs = sprs;
4811 bool road, road_near[8], hider, hider_near[8];
4812 bool land_near[8], hland_near[8];
4813 bool draw_road[8], draw_single_road;
4814 enum direction8 dir;
4815 int extra_idx = -1;
4816 bool cl = FALSE;
4817 enum extrastyle_id extrastyle;
4818 const struct road_type *proad = extra_road_get(pextra);
4819
4820 extra_idx = extra_index(pextra);
4821
4822 extrastyle = t->sprites.extras[extra_idx].extrastyle;
4823
4824 if (extra_has_flag(pextra, EF_CONNECT_LAND)) {
4825 cl = TRUE;
4826 } else {
4827 int i;
4828
4829 for (i = 0; i < 8; i++) {
4830 land_near[i] = FALSE;
4831 }
4832 }
4833
4834 /* Fill some data arrays. rail_near and road_near store whether road/rail
4835 * is present in the given direction. draw_rail and draw_road store
4836 * whether road/rail is to be drawn in that direction. draw_single_road
4837 * and draw_single_rail store whether we need an isolated road/rail to be
4838 * drawn. */
4840
4841 hider = FALSE;
4844 hider = TRUE;
4845 break;
4846 }
4848
4849 if (road && (!pcity || !gui_options.draw_cities) && !hider) {
4851 } else {
4853 }
4854
4855 for (dir = 0; dir < 8; dir++) {
4856 bool roads_exist;
4857
4858 /* Check if there is adjacent road/rail. */
4859 if (!is_cardinal_only_road(pextra)
4860 || is_cardinal_tileset_dir(t, dir)) {
4861 road_near[dir] = FALSE;
4862 extra_type_list_iterate(proad->integrators, iextra) {
4864 road_near[dir] = TRUE;
4865 break;
4866 }
4868 if (cl) {
4869 land_near[dir] = (tterrain_near[dir] != T_UNKNOWN
4871 }
4872 } else {
4873 road_near[dir] = FALSE;
4874 land_near[dir] = FALSE;
4875 }
4876
4877 /* Draw rail/road if there is a connection from this tile to the
4878 * adjacent tile. But don't draw road if there is also a rail
4879 * connection. */
4880 roads_exist = road && (road_near[dir] || land_near[dir]);
4881 draw_road[dir] = roads_exist;
4882 hider_near[dir] = FALSE;
4883 hland_near[dir] = tterrain_near[dir] != T_UNKNOWN
4886 bool hider_dir = FALSE;
4887 bool land_dir = FALSE;
4888
4890 || is_cardinal_tileset_dir(t, dir)) {
4892 hider_near[dir] = TRUE;
4893 hider_dir = TRUE;
4894 }
4895 if (hland_near[dir]
4898 land_dir = TRUE;
4899 }
4900 if (hider_dir || land_dir) {
4902 draw_road[dir] = FALSE;
4903 }
4904 }
4905 }
4907
4908 /* Don't draw an isolated road/rail if there's any connection.
4909 * draw_single_road would be true in the first place only if start tile has road,
4910 * so it will have road connection with any adjacent road tile. We check from real
4911 * existence of road (road_near[dir]) and not from whether road gets drawn (draw_road[dir])
4912 * as latter can be FALSE when road is simply hidden by another one, and we don't want to
4913 * draw single road in that case either. */
4914 if (draw_single_road && road_near[dir]) {
4916 }
4917 }
4918
4919 /* Draw road corners */
4920 sprs
4922
4923 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
4924 /* With ESTYLE_ROAD_ALL_SEPARATE, we simply draw one road for every connection.
4925 * This means we only need a few sprites, but a lot of drawing is
4926 * necessary and it generally doesn't look very good. */
4927 int i;
4928
4929 /* First draw roads under rails. */
4930 if (road) {
4931 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4932 if (draw_road[t->valid_tileset_dirs[i]]) {
4934 }
4935 }
4936 }
4937 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4938 /* With ESTYLE_ROAD_PARITY_COMBINED, we draw one sprite for cardinal
4939 * road connections, one sprite for diagonal road connections.
4940 * This means we need about 4x more sprites than in style 0, but up to
4941 * 4x less drawing is needed. The drawing quality may also be
4942 * improved. */
4943
4944 /* First draw roads under rails. */
4945 if (road) {
4946 int road_even_tileno = 0, road_odd_tileno = 0, i;
4947
4948 for (i = 0; i < t->num_valid_tileset_dirs / 2; i++) {
4949 enum direction8 even = t->valid_tileset_dirs[2 * i];
4950 enum direction8 odd = t->valid_tileset_dirs[2 * i + 1];
4951
4952 if (draw_road[even]) {
4953 road_even_tileno |= 1 << i;
4954 }
4955 if (draw_road[odd]) {
4956 road_odd_tileno |= 1 << i;
4957 }
4958 }
4959
4960 /* Draw the cardinal/even roads first. */
4961 if (road_even_tileno != 0) {
4963 }
4964 if (road_odd_tileno != 0) {
4966 }
4967 }
4968 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
4969 /* RSTYLE_ALL_COMBINED is a very simple method that lets us simply retrieve
4970 * entire finished tiles, with a bitwise index of the presence of
4971 * roads in each direction. */
4972
4973 /* Draw roads first */
4974 if (road) {
4975 int road_tileno = 0, i;
4976
4977 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4979
4980 if (draw_road[vdir]) {
4981 road_tileno |= 1 << i;
4982 }
4983 }
4984
4985 if (road_tileno != 0 || draw_single_road) {
4987 }
4988 }
4989 } else {
4991 }
4992
4993 /* Draw isolated rail/road separately (ESTYLE_ROAD_ALL_SEPARATE and
4994 ESTYLE_ROAD_PARITY_COMBINED only). */
4995 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4996 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4997 if (draw_single_road) {
4999 }
5000 }
5001
5002 return sprs - saved_sprs;
5003}
5004
5005/************************************************************************/
5014static int get_irrigation_index(const struct tileset *t,
5015 struct extra_type *pextra,
5017{
5018 int tileno = 0, i;
5019
5020 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5021 enum direction8 dir = t->cardinal_tileset_dirs[i];
5022
5023 if (BV_ISSET(textras_near[dir], extra_index(pextra))) {
5024 tileno |= 1 << i;
5025 }
5026 }
5027
5028 return tileno;
5029}
5030
5031/************************************************************************/
5034static int fill_irrigation_sprite_array(const struct tileset *t,
5035 struct drawn_sprite *sprs,
5038 const struct city *pcity)
5039{
5040 struct drawn_sprite *saved_sprs = sprs;
5041
5042 /* We don't draw the irrigation if there's a city (it just gets overdrawn
5043 * anyway, and ends up looking bad). */
5044 if (!(pcity && gui_options.draw_cities)) {
5046 if (is_extra_drawing_enabled(pextra)) {
5047 int eidx = extra_index(pextra);
5048
5049 if (BV_ISSET(textras, eidx)) {
5050 bool hidden = FALSE;
5051
5052 extra_type_list_iterate(pextra->hiders, phider) {
5054 hidden = TRUE;
5055 break;
5056 }
5058
5059 if (!hidden) {
5060 int idx = get_irrigation_index(t, pextra, textras_near);
5061
5063 }
5064 }
5065 }
5067 }
5068
5069 return sprs - saved_sprs;
5070}
5071
5072/************************************************************************/
5076static int fill_city_overlays_sprite_array(const struct tileset *t,
5077 struct drawn_sprite *sprs,
5078 const struct tile *ptile,
5079 const struct city *citymode)
5080{
5081 const struct city *pcity;
5082 const struct city *pwork;
5083 struct unit *psettler;
5084 struct drawn_sprite *saved_sprs = sprs;
5085 int city_x, city_y;
5086 const int NUM_CITY_COLORS = t->sprites.city.worked_tile_overlay.size;
5087
5088 if (NULL == ptile || TILE_UNKNOWN == client_tile_get_known(ptile)) {
5089 return 0;
5090 }
5091 pwork = tile_worked(ptile);
5092
5093 if (citymode) {
5094 pcity = citymode;
5095 } else {
5097 }
5098
5099 /* Below code does not work if pcity is invisible.
5100 * Make sure it is not. */
5101 fc_assert_ret_val(pcity == NULL || pcity->tile != NULL, 0);
5102 if (pcity && !pcity->tile) {
5103 pcity = NULL;
5104 }
5105
5106 if (pcity && city_base_to_city_map(&city_x, &city_y, pcity, ptile)) {
5107 /* FIXME: check elsewhere for valid tile (instead of above) */
5108
5109 if (!citymode && pcity->client.colored) {
5110 /* Add citymap overlay for a city. */
5111 int idx = pcity->client.color_index % NUM_CITY_COLORS;
5112
5113 if (NULL != pwork && pwork == pcity) {
5115 } else if (city_can_work_tile(pcity, ptile)) {
5117 }
5118 } else if (NULL != pwork && pwork == pcity
5120
5121 /* Add on the tile output sprites.
5122 * NOTE: To show correct output on end of turn
5123 * base_city_celebrating() must be used instead of city_celebrating()
5124 * mirroring the behavior of the server that does so in
5125 * city_tile_cache_update(). */
5126 bool celebrating = base_city_celebrating(pcity);
5127 int food = city_tile_output(pcity, ptile, celebrating, O_FOOD);
5128 int shields = city_tile_output(pcity, ptile, celebrating, O_SHIELD);
5129 int trade = city_tile_output(pcity, ptile, celebrating, O_TRADE);
5130
5131 const int ox = t->type == TS_ISOMETRIC ? t->normal_tile_width / 3 : 0;
5132 const int oy = t->type == TS_ISOMETRIC ? -t->normal_tile_height / 3 : 0;
5133
5134 food = CLIP(0, food / game.info.granularity, NUM_TILES_DIGITS - 1);
5135 shields = CLIP(0, shields / game.info.granularity, NUM_TILES_DIGITS - 1);
5136 trade = CLIP(0, trade / game.info.granularity, NUM_TILES_DIGITS - 1);
5137
5139 ADD_SPRITE(t->sprites.city.tile_shieldnum[shields], TRUE, ox, oy);
5141 }
5142 } else if (psettler && psettler->client.colored) {
5143 /* Add citymap overlay for a unit. */
5144 int idx = psettler->client.color_index % NUM_CITY_COLORS;
5145
5147 }
5148
5149 return sprs - saved_sprs;
5150}
5151
5152/************************************************************************/
5156static int fill_terrain_sprite_blending(const struct tileset *t,
5157 struct drawn_sprite *sprs,
5158 const struct tile *ptile,
5159 const struct terrain *pterrain,
5160 struct terrain **tterrain_near)
5161{
5162 struct drawn_sprite *saved_sprs = sprs;
5163 const int W = t->normal_tile_width, H = t->normal_tile_height;
5164 const int offsets[4][2] = {
5165 {W/2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}
5166 };
5167 enum direction4 dir = 0;
5168
5169 /*
5170 * We want to mark unknown tiles so that an unreal tile will be
5171 * given the same marking as our current tile - that way we won't
5172 * get the "unknown" dither along the edge of the map.
5173 */
5174 for (; dir < 4; dir++) {
5175 struct tile *tile1 = mapstep(&(wld.map), ptile, DIR4_TO_DIR8[dir]);
5176 struct terrain *other;
5177
5178 if (!tile1
5180 || pterrain == (other = tterrain_near[DIR4_TO_DIR8[dir]])
5181 || (0 == t->sprites.drawing[terrain_index(other)]->blending
5182 && NULL == t->sprites.drawing[terrain_index(other)]->blender)) {
5183 continue;
5184 }
5185
5187 offsets[dir][0], offsets[dir][1]);
5188 }
5189
5190 return sprs - saved_sprs;
5191}
5192
5193/************************************************************************/
5196static int fill_fog_sprite_array(const struct tileset *t,
5197 struct drawn_sprite *sprs,
5198 const struct tile *ptile,
5199 const struct tile_edge *pedge,
5200 const struct tile_corner *pcorner)
5201{
5202 struct drawn_sprite *saved_sprs = sprs;
5203
5205 && NULL != ptile
5207 /* With FOG_AUTO, fog is done this way. */
5209 }
5210
5213 int i, tileno = 0;
5214
5215 for (i = 3; i >= 0; i--) {
5216 const int unknown = 0, fogged = 1, known = 2;
5217 int value = -1;
5218
5219 if (!pcorner->tile[i]) {
5220 value = fogged;
5221 } else {
5222 switch (client_tile_get_known(pcorner->tile[i])) {
5223 case TILE_KNOWN_SEEN:
5224 value = known;
5225 break;
5226 case TILE_KNOWN_UNSEEN:
5227 value = fogged;
5228 break;
5229 case TILE_UNKNOWN:
5230 value = unknown;
5231 break;
5232 }
5233 }
5234 fc_assert(value >= 0 && value < 3);
5235
5236 tileno = tileno * 3 + value;
5237 }
5238
5239 if (t->sprites.tx.fullfog[tileno]) {
5241 }
5242 }
5243
5244 return sprs - saved_sprs;
5245}
5246
5247/************************************************************************/
5251 struct drawn_sprite *sprs,
5252 int l, /* layer_num */
5253 const struct tile *ptile,
5254 const struct terrain *pterrain,
5255 struct terrain **tterrain_near,
5256 struct drawing_data *draw)
5257{
5258 struct drawn_sprite *saved_sprs = sprs;
5259 struct drawing_layer *dlp = &draw->layer[l];
5260 int this = dlp->match_index[0];
5261 int that = dlp->match_index[1];
5262 int ox = dlp->offset_x;
5263 int oy = dlp->offset_y;
5264 int i;
5265
5266#define MATCH(dir) \
5267 (t->sprites.drawing[terrain_index(tterrain_near[(dir)])]->num_layers > l \
5268 ? t->sprites.drawing[terrain_index(tterrain_near[(dir)])]->layer[l].match_index[0] \
5269 : -1)
5270
5271 switch (dlp->sprite_type) {
5272 case CELL_WHOLE:
5273 {
5274 switch (dlp->match_style) {
5275 case MATCH_NONE:
5276 {
5277 int count = sprite_vector_size(&dlp->base);
5278
5279 if (count > 0) {
5280 /* Pseudo-random reproducible algorithm to pick a sprite. Use modulo
5281 * to limit the number to a handleable size [0..32000). */
5282 count = fc_randomly(tile_index(ptile) % 32000, count);
5283
5284 if (dlp->is_tall) {
5287 }
5288 ADD_SPRITE(dlp->base.p[count], TRUE, ox, oy);
5289 }
5290 break;
5291 }
5292 case MATCH_SAME:
5293 {
5294 int tileno = 0;
5295
5296 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5297 enum direction8 dir = t->cardinal_tileset_dirs[i];
5298
5299 if (MATCH(dir) == this) {
5300 tileno |= 1 << i;
5301 }
5302 }
5303
5304 if (dlp->is_tall) {
5307 }
5308 ADD_SPRITE(dlp->match[tileno], TRUE, ox, oy);
5309 break;
5310 }
5311 case MATCH_PAIR:
5312 case MATCH_FULL:
5313 fc_assert(FALSE); /* Not yet defined */
5314 break;
5315 };
5316 break;
5317 }
5318 case CELL_CORNER:
5319 {
5320 /* Divide the tile up into four rectangular cells. Each of these
5321 * cells covers one corner, and each is adjacent to 3 different
5322 * tiles. For each cell we pick a sprite based upon the adjacent
5323 * terrains at each of those tiles. Thus, we have 8 different sprites
5324 * for each of the 4 cells (32 sprites total).
5325 *
5326 * These arrays correspond to the direction4 ordering. */
5327 const int W = t->normal_tile_width;
5328 const int H = t->normal_tile_height;
5329 const int iso_offsets[4][2] = {
5330 {W / 4, 0}, {W / 4, H / 2}, {W / 2, H / 4}, {0, H / 4}
5331 };
5332 const int noniso_offsets[4][2] = {
5333 {0, 0}, {W / 2, H / 2}, {W / 2, 0}, {0, H / 2}
5334 };
5335
5336 /* Put corner cells */
5337 for (i = 0; i < NUM_CORNER_DIRS; i++) {
5338 const int count = dlp->match_indices;
5339 int array_index = 0;
5340 enum direction8 dir = dir_ccw(DIR4_TO_DIR8[i]);
5341 int x = (t->type == TS_ISOMETRIC ? iso_offsets[i][0] : noniso_offsets[i][0]);
5342 int y = (t->type == TS_ISOMETRIC ? iso_offsets[i][1] : noniso_offsets[i][1]);
5343 int m[3] = {MATCH(dir_ccw(dir)), MATCH(dir), MATCH(dir_cw(dir))};
5344 struct sprite *s;
5345
5346 /* Synthesize 4 dimensional array? */
5347 switch (dlp->match_style) {
5348 case MATCH_NONE:
5349 /* We have no need for matching, just plug the piece in place. */
5350 break;
5351 case MATCH_SAME:
5352 array_index = array_index * 2 + (m[2] != this);
5353 array_index = array_index * 2 + (m[1] != this);
5354 array_index = array_index * 2 + (m[0] != this);
5355 break;
5356 case MATCH_PAIR:
5357 array_index = array_index * 2 + (m[2] == that);
5358 array_index = array_index * 2 + (m[1] == that);
5359 array_index = array_index * 2 + (m[0] == that);
5360 break;
5361 case MATCH_FULL:
5362 default:
5363 if (count > 0) {
5364 int n[3];
5365 int j;
5366
5367 for (j = 0; j < 3; j++) {
5368 int k;
5369
5370 for (k = 0; k < count; k++) {
5371 n[j] = k; /* Default to last entry */
5372 if (m[j] == dlp->match_index[k]) {
5373 break;
5374 }
5375 }
5376 }
5377 array_index = array_index * count + n[2];
5378 array_index = array_index * count + n[1];
5379 array_index = array_index * count + n[0];
5380 }
5381 break;
5382 };
5383
5385
5386 s = dlp->cells[array_index];
5387 if (s) {
5388 ADD_SPRITE(s, TRUE, x, y);
5389 }
5390 }
5391 break;
5392 }
5393 };
5394#undef MATCH
5395
5396 return sprs - saved_sprs;
5397}
5398
5399/************************************************************************/
5404 struct drawn_sprite *sprs,
5405 const struct tile *ptile,
5406 struct terrain **tterrain_near)
5407{
5408 struct drawn_sprite *saved_sprs = sprs;
5409 int i, tileno;
5410 struct tile *adjc_tile;
5411
5412#define UNKNOWN(dir) \
5413 ((adjc_tile = mapstep(&(wld.map), ptile, (dir))) \
5414 && client_tile_get_known(adjc_tile) == TILE_UNKNOWN)
5415
5416 switch (t->darkness_style) {
5417 case DARKNESS_NONE:
5418 break;
5419 case DARKNESS_ISORECT:
5420 for (i = 0; i < 4; i++) {
5421 const int W = t->normal_tile_width, H = t->normal_tile_height;
5422 int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
5423
5424 if (UNKNOWN(DIR4_TO_DIR8[i])) {
5426 offsets[i][0], offsets[i][1]);
5427 }
5428 }
5429 break;
5431 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5432 if (UNKNOWN(t->cardinal_tileset_dirs[i])) {
5434 }
5435 }
5436 break;
5437 case DARKNESS_CARD_FULL:
5438 /* We're looking to find the INDEX_NSEW for the directions that
5439 * are unknown. We want to mark unknown tiles so that an unreal
5440 * tile will be given the same marking as our current tile - that
5441 * way we won't get the "unknown" dither along the edge of the
5442 * map. */
5443 tileno = 0;
5444 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5445 if (UNKNOWN(t->cardinal_tileset_dirs[i])) {
5446 tileno |= 1 << i;
5447 }
5448 }
5449
5450 if (tileno != 0) {
5452 }
5453 break;
5454 case DARKNESS_CORNER:
5455 /* Handled separately. */
5456 break;
5457 };
5458#undef UNKNOWN
5459
5460 return sprs - saved_sprs;
5461}
5462
5463/************************************************************************/
5468 struct drawn_sprite *sprs,
5469 int layer_num,
5470 const struct tile *ptile,
5471 const struct terrain *pterrain,
5472 struct terrain **tterrain_near)
5473{
5474 struct sprite *sprite;
5475 struct drawn_sprite *saved_sprs = sprs;
5476 struct drawing_data *draw = t->sprites.drawing[terrain_index(pterrain)];
5477 const int l = (draw->is_reversed
5478 ? (draw->num_layers - layer_num - 1) : layer_num);
5479
5481
5482 /* Skip the normal drawing process. */
5483 /* FIXME: this should avoid calling load_sprite since it's slow and
5484 * increases the refcount without limit. */
5485 if (ptile->spec_sprite && (sprite = load_sprite(t, ptile->spec_sprite,
5486 TRUE, FALSE, FALSE))) {
5487 if (l == 0) {
5489 return 1;
5490 } else {
5491 return 0;
5492 }
5493 }
5494
5496 sprs += fill_terrain_sprite_array(t, sprs, l, ptile, pterrain, tterrain_near, draw);
5497
5498 if ((l + 1) == draw->blending) {
5499 sprs += fill_terrain_sprite_blending(t, sprs, ptile, pterrain, tterrain_near);
5500 }
5501 }
5502
5503 return sprs - saved_sprs;
5504}
5505
5506/************************************************************************/
5513{
5514 /* Display an outline for city-builder type units if they are selected,
5515 * and on a tile where a city can be built.
5516 * But suppress the outline if the unit has orders (likely it is in
5517 * transit to somewhere else and this will just slow down redraws). */
5524}
5525
5526/************************************************************************/
5529static int fill_grid_sprite_array(const struct tileset *t,
5530 struct drawn_sprite *sprs,
5531 const struct tile *ptile,
5532 const struct tile_edge *pedge,
5533 const struct tile_corner *pcorner,
5534 const struct unit *punit,
5535 const struct city *pcity,
5536 const struct city *citymode)
5537{
5538 struct drawn_sprite *saved_sprs = sprs;
5539
5540 if (pedge) {
5541 bool known[NUM_EDGE_TILES], city[NUM_EDGE_TILES];
5542 bool unit[NUM_EDGE_TILES], worked[NUM_EDGE_TILES];
5543 int i;
5544 struct unit_list *pfocus_units = get_units_in_focus();
5545
5546 for (i = 0; i < NUM_EDGE_TILES; i++) {
5547 int dummy_x, dummy_y;
5548 const struct tile *tile = pedge->tile[i];
5549 struct player *powner = tile ? tile_owner(tile) : NULL;
5550
5552 unit[i] = FALSE;
5553 if (tile && !citymode) {
5556 struct tile *utile = unit_tile(pfocus_unit);
5557 int radius = game.info.init_city_radius_sq
5559 NULL,
5560 &(const struct req_context) {
5561 .player = unit_owner(pfocus_unit),
5562 .tile = utile,
5563 },
5564 NULL,
5566 );
5567
5568 if (city_tile_to_city_map(&dummy_x, &dummy_y, radius,
5569 utile, tile)) {
5570 unit[i] = TRUE;
5571 break;
5572 }
5573 }
5575 }
5576 worked[i] = FALSE;
5577
5578 city[i] = (tile
5579 && (NULL == powner || NULL == client.conn.playing
5580 || powner == client.conn.playing)
5582 if (city[i]) {
5583 if (citymode) {
5584 /* In citymode, we only draw worked tiles for this city - other
5585 * tiles may be marked as unavailable. */
5586 worked[i] = (tile_worked(tile) == citymode);
5587 } else {
5588 worked[i] = (NULL != tile_worked(tile));
5589 }
5590 }
5591 }
5592
5593 if (mapdeco_is_highlight_set(pedge->tile[0])
5594 || mapdeco_is_highlight_set(pedge->tile[1])) {
5597 && pedge->tile[0] && pedge->tile[1]
5598 && known[0] && known[1]
5599 && (is_ocean_tile(pedge->tile[0])
5600 ^ is_ocean_tile(pedge->tile[1]))) {
5602 } else {
5604 if (worked[0] || worked[1]) {
5606 } else if (city[0] || city[1]) {
5608 } else if (known[0] || known[1]) {
5610 }
5611 }
5613 if (XOR(city[0], city[1])) {
5615 }
5616 if (XOR(unit[0], unit[1])) {
5618 }
5619 }
5620 }
5621
5624 && known[0]
5625 && known[1]) {
5626 struct player *owner0 = tile_owner(pedge->tile[0]);
5627 struct player *owner1 = tile_owner(pedge->tile[1]);
5628
5629 if (owner0 != owner1) {
5630 if (owner0) {
5631 int plrid = player_index(owner0);
5633 [pedge->type][0]);
5634 }
5635 if (owner1) {
5636 int plrid = player_index(owner1);
5638 [pedge->type][1]);
5639 }
5640 }
5641 }
5642 } else if (NULL != ptile && TILE_UNKNOWN != client_tile_get_known(ptile)) {
5643 int cx, cy;
5644
5645 if (citymode
5646 /* Test to ensure valid coordinates? */
5647 && city_base_to_city_map(&cx, &cy, citymode, ptile)
5648 && !client_city_can_work_tile(citymode, ptile)) {
5650 }
5651
5653 bool native = TRUE;
5654 struct unit_list *pfocus_units = get_units_in_focus();
5655
5657 if (!is_native_tile(unit_type_get(pfocus), ptile)) {
5658 native = FALSE;
5659 break;
5660 }
5662
5663 if (!native) {
5664 if (t->sprites.grid.nonnative != NULL) {
5666 } else {
5668 }
5669 }
5670 }
5671 }
5672
5673 return sprs - saved_sprs;
5674}
5675
5676/************************************************************************/
5679static int fill_goto_sprite_array(const struct tileset *t,
5680 struct drawn_sprite *sprs,
5681 const struct tile *ptile,
5682 const struct tile_edge *pedge,
5683 const struct tile_corner *pcorner)
5684{
5685 struct drawn_sprite *saved_sprs = sprs;
5686 struct sprite *sprite;
5687 bool warn = FALSE;
5688 enum goto_tile_state state;
5689 int length;
5690 bool waypoint;
5691
5692 if (goto_tile_state(ptile, &state, &length, &waypoint)) {
5693 if (length >= 0) {
5694 fc_assert(state >= 0);
5695 fc_assert(state < ARRAY_SIZE(t->sprites.path.s));
5696
5697 sprite = t->sprites.path.s[state].specific;
5698 if (sprite != NULL) {
5699 ADD_SPRITE(sprite, FALSE, 0, 0);
5700 }
5701
5702 sprite = t->sprites.path.s[state].turns[length % 10];
5704 if (length >= 10) {
5705 sprite = t->sprites.path.s[state].turns_tens[(length / 10) % 10];
5707 if (length >= 100) {
5708 sprite = t->sprites.path.s[state].turns_hundreds[(length / 100)
5709 % 10];
5710
5711 if (sprite != NULL) {
5713 if (length >= 1000) {
5714 warn = TRUE;
5715 }
5716 } else {
5717 warn = TRUE;
5718 }
5719 }
5720 }
5721 }
5722
5723 if (waypoint) {
5725 }
5726
5727 if (warn) {
5728 /* Warn only once by tileset. */
5729 static char last_reported[256] = "";
5730
5731 if (0 != strcmp(last_reported, t->name)) {
5732 log_normal(_("Tileset \"%s\" doesn't support long goto paths, "
5733 "such as %d. Path not displayed as expected."),
5734 t->name, length);
5736 }
5737 }
5738 }
5739
5740 return sprs - saved_sprs;
5741}
5742
5743/************************************************************************/
5747static bool is_extra_drawing_enabled(struct extra_type *pextra)
5748{
5749 bool no_disable = TRUE; /* Draw if matches no cause */
5750
5751 if (is_extra_caused_by(pextra, EC_IRRIGATION)) {
5753 return TRUE;
5754 }
5755 no_disable = FALSE;
5756 }
5757 if (is_extra_caused_by(pextra, EC_POLLUTION)
5758 || is_extra_caused_by(pextra, EC_FALLOUT)) {
5760 return TRUE;
5761 }
5762 no_disable = FALSE;
5763 }
5764 if (is_extra_caused_by(pextra, EC_MINE)) {
5765 if (gui_options.draw_mines) {
5766 return TRUE;
5767 }
5768 no_disable = FALSE;
5769 }
5770 if (is_extra_caused_by(pextra, EC_RESOURCE)) {
5772 return TRUE;
5773 }
5774 no_disable = FALSE;
5775 }
5776 if (is_extra_removed_by(pextra, ERM_ENTER)) {
5777 if (gui_options.draw_huts) {
5778 return TRUE;
5779 }
5780 no_disable = FALSE;
5781 }
5782 if (is_extra_caused_by(pextra, EC_BASE)) {
5784 return TRUE;
5785 }
5786 no_disable = FALSE;
5787 }
5788 if (is_extra_caused_by(pextra, EC_ROAD)) {
5789 if (gui_options.draw_paths) {
5790 return TRUE;
5791 }
5792 no_disable = FALSE;
5793 }
5794
5795 return no_disable;
5796}
5797
5798/************************************************************************/
5815 struct drawn_sprite *sprs, enum mapview_layer layer,
5816 const struct tile *ptile,
5817 const struct tile_edge *pedge,
5818 const struct tile_corner *pcorner,
5819 const struct unit *punit, const struct city *pcity,
5820 const struct city *citymode,
5821 const struct unit_type *putype)
5822{
5823 int tileno, dir;
5826 struct terrain *tterrain_near[8];
5827 struct terrain *pterrain = NULL;
5828 struct drawn_sprite *save_sprs = sprs;
5829 struct player *owner = NULL;
5830 /* Unit drawing is disabled when the view options are turned off,
5831 * but only where we're drawing on the mapview. */
5832 bool do_draw_unit = (punit && (gui_options.draw_units || !ptile
5834 && unit_is_in_focus(punit))));
5836 && (do_draw_unit
5837 || (pcity && gui_options.draw_cities)
5838 || (ptile && !gui_options.draw_terrain)));
5839
5840 if (citymode) {
5841 int count = 0, i, cx, cy;
5842 const struct tile *const *tiles = NULL;
5843 bool valid = FALSE;
5844
5845 if (ptile) {
5846 tiles = &ptile;
5847 count = 1;
5848 } else if (pcorner) {
5849 tiles = pcorner->tile;
5850 count = NUM_CORNER_TILES;
5851 } else if (pedge) {
5852 tiles = pedge->tile;
5853 count = NUM_EDGE_TILES;
5854 }
5855
5856 for (i = 0; i < count; i++) {
5857 if (tiles[i] && city_base_to_city_map(&cx, &cy, citymode, tiles[i])) {
5858 valid = TRUE;
5859 break;
5860 }
5861 }
5862 if (!valid) {
5863 return 0;
5864 }
5865 }
5866
5867 if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) {
5868 textras = *tile_extras(ptile);
5869 pterrain = tile_terrain(ptile);
5870
5871 if (NULL != pterrain) {
5872 if (layer == LAYER_TERRAIN1
5873 || layer == LAYER_TERRAIN2
5874 || layer == LAYER_TERRAIN3
5875 || layer == LAYER_WATER
5876 || layer == LAYER_ROADS) {
5877 build_tile_data(ptile, pterrain, tterrain_near, textras_near);
5878 }
5879 } else {
5880 log_error("fill_sprite_array() tile (%d,%d) has no terrain!",
5881 TILE_XY(ptile));
5882 }
5883 } else {
5885 }
5886
5887 switch (layer) {
5888 case LAYER_BACKGROUND:
5889 /* Set up background color. */
5891 if (do_draw_unit) {
5893 } else if (pcity && gui_options.draw_cities) {
5894 owner = city_owner(pcity);
5895 }
5896 }
5897 if (owner) {
5899 } else if (ptile && !gui_options.draw_terrain) {
5901 }
5902 break;
5903
5904 case LAYER_TERRAIN1:
5905 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
5906 sprs += fill_terrain_sprite_layer(t, sprs, 0, ptile, pterrain, tterrain_near);
5907 }
5908 break;
5909
5910 case LAYER_DARKNESS:
5911 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
5913 }
5914 break;
5915
5916 case LAYER_TERRAIN2:
5917 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
5918 sprs += fill_terrain_sprite_layer(t, sprs, 1, ptile, pterrain, tterrain_near);
5919 }
5920 break;
5921
5922 case LAYER_TERRAIN3:
5923 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
5925 sprs += fill_terrain_sprite_layer(t, sprs, 2, ptile, pterrain, tterrain_near);
5926 }
5927 break;
5928
5929 case LAYER_WATER:
5930 if (NULL != pterrain) {
5932 && terrain_type_terrain_class(pterrain) == TC_OCEAN) {
5933 for (dir = 0; dir < t->num_cardinal_tileset_dirs; dir++) {
5934 int didx = t->cardinal_tileset_dirs[dir];
5935
5938 int idx = extra_index(priver);
5939
5940 if (BV_ISSET(textras_near[didx], idx)) {
5942 }
5943 }
5945 }
5946 }
5947
5949 pcity);
5950
5954 int idx = extra_index(priver);
5955
5956 if (BV_ISSET(textras, idx)) {
5957 int i;
5958
5959 /* Draw rivers on top of irrigation. */
5960 tileno = 0;
5961 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5963
5965 tileno |= 1 << i;
5966 } else {
5968
5969 if (proad != NULL) {
5970 extra_type_list_iterate(proad->integrators, iextra) {
5972 tileno |= 1 << i;
5973 }
5975 }
5976 }
5977 }
5978
5980 }
5981 }
5983 }
5984 }
5985 break;
5986
5987 case LAYER_ROADS:
5988 if (NULL != pterrain) {
5990 if (is_extra_drawing_enabled(pextra)) {
5991 sprs += fill_road_sprite_array(t, pextra, sprs,
5993 tterrain_near, pcity);
5994 }
5997 if (is_extra_drawing_enabled(pextra)) {
5998 sprs += fill_road_sprite_array(t, pextra, sprs,
6000 tterrain_near, pcity);
6001 }
6004 if (is_extra_drawing_enabled(pextra)) {
6005 sprs += fill_road_sprite_array(t, pextra, sprs,
6007 tterrain_near, pcity);
6008 }
6010 }
6011 break;
6012
6013 case LAYER_SPECIAL1:
6014 if (NULL != pterrain) {
6015 if (ptile) {
6017 if (tile_has_extra(ptile, pextra)
6018 && is_extra_drawing_enabled(pextra)
6019 && t->sprites.extras[extra_index(pextra)].u.bmf.background) {
6020 bool hidden = FALSE;
6021
6022 extra_type_list_iterate(pextra->hiders, phider) {
6024 hidden = TRUE;
6025 break;
6026 }
6028
6029 if (!hidden) {
6031 }
6032 }
6034 }
6035
6037 if (BV_ISSET(textras, extra_index(pextra))
6038 && is_extra_drawing_enabled(pextra)) {
6039 bool hidden = FALSE;
6040
6041 extra_type_list_iterate(pextra->hiders, phider) {
6043 hidden = TRUE;
6044 break;
6045 }
6047
6048 if (!hidden) {
6050 }
6051 }
6053 }
6054 break;
6055
6056 case LAYER_GRID1:
6057 if (t->type == TS_ISOMETRIC) {
6059 punit, pcity, citymode);
6060 }
6061 break;
6062
6063 case LAYER_CITY1:
6064 /* City. Some city sprites are drawn later. */
6065 if (pcity && gui_options.draw_cities) {
6070 }
6071 /* For iso-view the city.wall graphics include the full city, whereas
6072 * for non-iso view they are an overlay on top of the base city
6073 * graphic. */
6074 if (t->type == TS_OVERHEAD || pcity->client.walls <= 0) {
6078 }
6079 if (t->type == TS_ISOMETRIC && pcity->client.walls > 0) {
6080 struct city_sprite *cspr = t->sprites.city.wall[pcity->client.walls - 1];
6081 struct sprite *spr = NULL;
6082
6083 if (cspr != NULL) {
6084 spr = get_city_sprite(cspr, pcity);
6085 }
6086 if (spr == NULL) {
6088 if (cspr != NULL) {
6089 spr = get_city_sprite(cspr, pcity);
6090 }
6091 }
6092
6093 if (spr != NULL) {
6097 }
6098 }
6103 }
6104 if (t->type == TS_OVERHEAD && pcity->client.walls > 0) {
6105 struct city_sprite *cspr = t->sprites.city.wall[pcity->client.walls - 1];
6106 struct sprite *spr = NULL;
6107
6108 if (cspr != NULL) {
6109 spr = get_city_sprite(cspr, pcity);
6110 }
6111 if (spr == NULL) {
6113 if (cspr != NULL) {
6114 spr = get_city_sprite(cspr, pcity);
6115 }
6116 }
6117
6118 if (spr != NULL) {
6120 }
6121 }
6122 if (pcity->client.unhappy) {
6124 }
6125 }
6126 break;
6127
6128 case LAYER_SPECIAL2:
6129 if (NULL != pterrain) {
6130 if (ptile) {
6132 if (tile_has_extra(ptile, pextra)
6133 && is_extra_drawing_enabled(pextra)
6134 && t->sprites.extras[extra_index(pextra)].u.bmf.middleground) {
6135 bool hidden = FALSE;
6136
6137 extra_type_list_iterate(pextra->hiders, phider) {
6139 hidden = TRUE;
6140 break;
6141 }
6143
6144 if (!hidden) {
6146 }
6147 }
6149 }
6150
6152 if (BV_ISSET(textras, extra_index(pextra))
6153 && is_extra_drawing_enabled(pextra)) {
6154 bool hidden = FALSE;
6155
6156 extra_type_list_iterate(pextra->hiders, phider) {
6158 hidden = TRUE;
6159 break;
6160 }
6162
6163 if (!hidden) {
6165 }
6166 }
6168 }
6169 break;
6170
6171 case LAYER_UNIT:
6172 case LAYER_FOCUS_UNIT:
6173 if (do_draw_unit && XOR(layer == LAYER_UNIT, unit_is_in_focus(punit))) {
6174 int stack_count = ptile ? unit_list_size(ptile->units) : 0;
6175 bool backdrop = !pcity;
6176
6177 if (ptile && unit_is_in_focus(punit)
6178 && t->sprites.unit.select[0]) {
6179 /* Special case for drawing the selection rectangle. The blinking
6180 * unit is handled separately, inside get_drawable_unit(). */
6183 }
6184
6185 /* Load more stack number sprites if needed. no_more_stack_sprites guard
6186 * that we don't retry over and over again for every stack,
6187 * when it's not working. */
6188 if (t->sprites.unit.num_stack_sprites < stack_count
6189 && !t->sprites.unit.no_more_stack_sprites) {
6190 t->sprites.unit.stack = fc_realloc(t->sprites.unit.stack,
6191 stack_count * sizeof(struct sprite *));
6192
6193 while (t->sprites.unit.num_stack_sprites < stack_count
6194 && !t->sprites.unit.no_more_stack_sprites) {
6195 struct sprite *spr = load_gfxnumber(t->sprites.unit.num_stack_sprites + 1);
6196
6197 if (spr != NULL) {
6198 t->sprites.unit.stack[t->sprites.unit.num_stack_sprites++] = spr;
6199 } else {
6200 t->sprites.unit.no_more_stack_sprites = TRUE;
6201 t->sprites.unit.stack = fc_realloc(t->sprites.unit.stack,
6202 t->sprites.unit.num_stack_sprites * sizeof(struct sprite *));
6203 }
6204 }
6205 }
6206
6208 } else if (putype != NULL && layer == LAYER_UNIT) {
6209 /* Only the sprite for the unit type. */
6210 /* FIXME: Shouldn't this still get activity and orientation of
6211 * the actual unit? */
6214 }
6215 break;
6216
6217 case LAYER_SPECIAL3:
6218 if (NULL != pterrain) {
6219 if (ptile) {
6220 bool show_flag = FALSE;
6221 struct player *eowner = extra_owner(ptile);
6222
6224 if (is_extra_drawing_enabled(pextra)
6225 && tile_has_extra(ptile, pextra)
6226 && t->sprites.extras[extra_index(pextra)].u.bmf.foreground) {
6227 bool hidden = FALSE;
6228
6229 extra_type_list_iterate(pextra->hiders, phider) {
6231 hidden = TRUE;
6232 break;
6233 }
6235
6236 if (!hidden) {
6237 if (t->sprites.extras[extra_index(pextra)].u.bmf.foreground) {
6239 }
6240 }
6241 }
6243
6244 /* Show base flag. Not part of previous iteration as
6245 * "extras of ESTYLE_3_LAYER" != "bases" */
6246 if (eowner != NULL) {
6248 if (tile_has_extra(ptile, pextra)) {
6249 bool hidden = FALSE;
6250
6251 extra_type_list_iterate(pextra->hiders, phider) {
6253 hidden = TRUE;
6254 break;
6255 }
6257
6258 if (!hidden) {
6259 show_flag = TRUE;
6260 }
6261 }
6263
6264 if (show_flag) {
6268 }
6269 }
6270 }
6271 }
6272 break;
6273
6274 case LAYER_FOG:
6276 break;
6277
6278 case LAYER_CITY2:
6279 /* City size. Drawing this under fog makes it hard to read. */
6281 bool warn = FALSE;
6282 unsigned int size = city_size_get(pcity);
6283
6287 if (10 <= size) {
6289 % 10], FALSE,
6292 if (100 <= size) {
6293 struct sprite *sprite =
6294 t->sprites.city.size_hundreds[(size / 100) % 10];
6295
6296 if (NULL != sprite) {
6300 } else {
6301 warn = TRUE;
6302 }
6303 if (1000 <= size) {
6304 warn = TRUE;
6305 }
6306 }
6307 }
6308
6309 if (warn) {
6310 /* Warn only once by tileset. */
6311 static char last_reported[256] = "";
6312
6313 if (0 != strcmp(last_reported, t->name)) {
6314 log_normal(_("Tileset \"%s\" doesn't support big cities size, "
6315 "such as %d. Size not displayed as expected."),
6316 t->name, size);
6318 }
6319 }
6320 }
6321 break;
6322
6323 case LAYER_GRID2:
6324 if (t->type == TS_OVERHEAD) {
6326 punit, pcity, citymode);
6327 }
6328 break;
6329
6330 case LAYER_OVERLAYS:
6332 if (mapdeco_is_crosshair_set(ptile)) {
6334 }
6335 break;
6336
6337 case LAYER_CITYBAR:
6338 case LAYER_TILELABEL:
6339 /* Nothing. This is just a placeholder. */
6340 break;
6341
6342 case LAYER_GOTO:
6343 if (ptile && goto_is_active()) {
6345 }
6346 break;
6347
6348 case LAYER_WORKERTASK:
6349 if (citymode != NULL && ptile != NULL) {
6351 if (ptask->ptile == ptile) {
6352 switch (ptask->act) {
6353 case ACTIVITY_MINE:
6354 if (ptask->tgt == NULL) {
6355 ADD_SPRITE(t->sprites.unit.plant,
6358 } else {
6362 }
6363 break;
6364 case ACTIVITY_PLANT:
6365 ADD_SPRITE(t->sprites.unit.plant,
6368 break;
6369 case ACTIVITY_IRRIGATE:
6370 if (ptask->tgt == NULL) {
6371 ADD_SPRITE(t->sprites.unit.cultivate,
6374 } else {
6378 }
6379 break;
6380 case ACTIVITY_CULTIVATE:
6381 ADD_SPRITE(t->sprites.unit.cultivate,
6384 break;
6385 case ACTIVITY_GEN_ROAD:
6386 if (ptask->tgt != NULL) {
6390 }
6391 break;
6392 case ACTIVITY_TRANSFORM:
6393 ADD_SPRITE(t->sprites.unit.transform,
6396 break;
6397 case ACTIVITY_CLEAN:
6398 if (ptask->tgt != NULL) {
6402 }
6403 break;
6404 default:
6405 break;
6406 }
6407 }
6409 }
6410 break;
6411
6412 case LAYER_EDITOR:
6413 if (ptile && editor_is_active()) {
6414 if (editor_tile_is_selected(ptile)) {
6417 }
6418
6419 if (NULL != map_startpos_get(ptile)) {
6420 /* FIXME: Use a more representative sprite. */
6422 }
6423 }
6424 break;
6425
6426 case LAYER_INFRAWORK:
6427 if (ptile != NULL) {
6428 if (ptile->placing != NULL) {
6429 const int id = extra_index(ptile->placing);
6430
6431 if (t->sprites.extras[id].activity != NULL) {
6435 }
6436 }
6437 if (client_infratile() == ptile) {
6439 }
6440 }
6441 break;
6442
6443 case LAYER_COUNT:
6445 break;
6446 }
6447
6448 return sprs - save_sprs;
6449}
6450
6451/************************************************************************/
6455void tileset_setup_city_tiles(struct tileset *t, int style)
6456{
6457 const char *style_name = city_style_rule_name(style);
6458
6459 if (style == game.control.num_city_styles - 1) {
6460 int i;
6461
6462 /* Free old sprites */
6464
6465 for (i = 0; i < NUM_WALL_TYPES; i++) {
6467 t->sprites.city.wall[i] = NULL;
6468 }
6471
6473
6474 t->sprites.city.tile = load_city_sprite(t, "city");
6475
6476 for (i = 0; i < NUM_WALL_TYPES; i++) {
6477 char buffer[256];
6478
6479 fc_snprintf(buffer, sizeof(buffer), "bldg_%d", i);
6480 t->sprites.city.wall[i] = load_city_sprite(t, buffer);
6481 }
6482 t->sprites.city.single_wall = load_city_sprite(t, "wall");
6483
6484 t->sprites.city.occupied = load_city_sprite(t, "occupied");
6485 }
6486
6488 &t->sprites.style_citizen_sets.sets[style],
6489 city_styles[style].citizens_graphic,
6490 style_name, FALSE);
6493 &t->sprites.style_citizen_sets.sets[style],
6494 sp,
6495 city_styles[style].citizens_graphic,
6496 style_name, FALSE);
6498
6499 if (style == game.control.num_city_styles - 1) {
6500 for (style = 0; style < game.control.num_city_styles; style++) {
6501 if (t->sprites.city.tile->styles[style].land_num_thresholds == 0) {
6503 _("City style \"%s\": no city graphics."),
6504 city_style_rule_name(style));
6505 }
6506 if (t->sprites.city.occupied->styles[style].land_num_thresholds == 0) {
6508 _("City style \"%s\": no occupied graphics."),
6509 city_style_rule_name(style));
6510 }
6511 }
6512 }
6513}
6514
6515/************************************************************************/
6521{
6522 if (t->sprites.unit.select[0]) {
6523 return 0.1;
6524 } else {
6525 return 0.5;
6526 }
6527}
6528
6529/************************************************************************/
6534{
6535 focus_unit_state = 0;
6536}
6537
6538/************************************************************************/
6542{
6543 if (!t->sprites.unit.select[0]) {
6545 }
6546}
6547
6548/************************************************************************/
6553{
6555 if (t->sprites.unit.select[0]) {
6557 } else {
6558 focus_unit_state %= 2;
6559 }
6560}
6561
6562/************************************************************************/
6565struct unit *get_drawable_unit(const struct tileset *t,
6566 struct tile *ptile,
6567 const struct city *citymode)
6568{
6569 struct unit *punit = find_visible_unit(ptile);
6570
6571 if (punit == NULL) {
6572 return NULL;
6573 }
6574
6576 return NULL;
6577 }
6578
6580 || t->sprites.unit.select[0] || focus_unit_state == 0) {
6581 return punit;
6582 } else {
6583 return NULL;
6584 }
6585}
6586
6587/************************************************************************/
6591static void unload_all_sprites(struct tileset *t)
6592{
6593 if (t->sprite_hash) {
6595 while (ss->ref_count > 0) {
6597 }
6599 }
6600}
6601
6602/************************************************************************/
6606{
6607 int i;
6608
6609 log_debug("tileset_free_tiles()");
6610
6612
6614 t->sprites.city.tile = NULL;
6615
6616 for (i = 0; i < NUM_WALL_TYPES; i++) {
6618 t->sprites.city.wall[i] = NULL;
6619 }
6622
6625
6626 if (t->sprite_hash) {
6628 t->sprite_hash = NULL;
6629 }
6630
6631 if (t->sprites.style_citizen_sets.sets != NULL) {
6634 }
6635
6638 if (ss->file) {
6639 free(ss->file);
6640 }
6641 fc_assert(ss->sprite == NULL);
6642 free(ss);
6644
6647 free(sf->file_name);
6648 if (sf->big_sprite) {
6649 free_sprite(sf->big_sprite);
6650 sf->big_sprite = NULL;
6651 }
6652 free(sf);
6654
6659
6664
6665 if (t->sprites.tx.fullfog) {
6666 free(t->sprites.tx.fullfog);
6667 t->sprites.tx.fullfog = NULL;
6668 }
6669
6675
6676 /* Index 0 is 'occupied' or 'default' stack sprite */
6677 for (i = 1; i < t->sprites.unit.num_stack_sprites - 1; i++) {
6678 free_sprite(t->sprites.unit.stack[i]);
6679 }
6680 t->sprites.unit.num_stack_sprites = 0;
6681 if (t->sprites.unit.stack != NULL) {
6682 free(t->sprites.unit.stack);
6683 t->sprites.unit.stack = NULL;
6684 }
6685
6687}
6688
6689/************************************************************************/
6692struct sprite *get_spaceship_sprite(const struct tileset *t,
6693 enum spaceship_part part)
6694{
6695 return t->sprites.spaceship[part];
6696}
6697
6698/************************************************************************/
6701static inline const struct citizen_graphic *
6704{
6705 fc_assert_ret_val(set != NULL, NULL);
6706
6707 if (type < CITIZEN_SPECIALIST) {
6709 return &set->citizen[type];
6710 } else {
6712 return &set->specialist[type - CITIZEN_SPECIALIST];
6713 }
6714}
6715
6716/************************************************************************/
6723struct sprite *get_citizen_sprite(const struct tileset *t,
6725 int citizen_index,
6726 const struct city *pcity)
6727{
6728 const struct citizen_graphic *graphic = NULL;
6730
6731 if (pcity != NULL) {
6732 int style = style_of_city(pcity);
6733
6735
6737 type);
6738
6740 }
6741
6742 if (graphic == NULL || graphic->count == 0) {
6743 /* Fall back to default sprites */
6745 }
6746
6747 if (graphic->count == 0) {
6748 return NULL;
6749 }
6750
6751 return graphic->sprite[gfx_index % graphic->count];
6752}
6753
6754/************************************************************************/
6757struct sprite *get_nation_flag_sprite(const struct tileset *t,
6758 const struct nation_type *pnation)
6759{
6760 return t->sprites.nation_flag.p[nation_index(pnation)];
6761}
6762
6763/************************************************************************/
6767 const struct nation_type *pnation)
6768{
6769 return t->sprites.nation_shield.p[nation_index(pnation)];
6770}
6771
6772/************************************************************************/
6775struct sprite *get_tech_sprite(const struct tileset *t, Tech_type_id tech)
6776{
6777 fc_assert_ret_val(0 <= tech && tech < advance_count(), NULL);
6778 return t->sprites.tech[tech];
6779}
6780
6781/************************************************************************/
6784struct sprite *get_building_sprite(const struct tileset *t,
6785 const struct impr_type *pimprove)
6786{
6787 fc_assert_ret_val(NULL != pimprove, NULL);
6788 return t->sprites.building[improvement_index(pimprove)];
6789}
6790
6791/************************************************************************/
6794struct sprite *get_government_sprite(const struct tileset *t,
6795 const struct government *gov)
6796{
6797 fc_assert_ret_val(NULL != gov, NULL);
6798 return t->sprites.government[government_index(gov)];
6799}
6800
6801/************************************************************************/
6806struct sprite *get_unittype_sprite(const struct tileset *t,
6807 const struct unit_type *punittype,
6808 enum unit_activity activity,
6809 enum direction8 facing)
6810{
6811 int uidx = utype_index(punittype);
6812 bool icon = !direction8_is_valid(facing);
6813
6814 if (activity >= ACTIVITY_LAST) {
6815 activity = ACTIVITY_IDLE;
6816 }
6817
6819
6820 if (!direction8_is_valid(facing) || !is_valid_dir(facing)) {
6821 facing = t->unit_default_orientation;
6822 /* May not have been specified, but it only matters if we don't
6823 * turn out to have an icon sprite */
6824 }
6825
6826 if (t->sprites.units.icon[uidx][activity] != NULL
6827 && (icon || t->sprites.units.facing[uidx][facing][activity] == NULL)) {
6828 /* Has icon sprite, and we prefer to (or must) use it */
6829 return t->sprites.units.icon[uidx][activity];
6830 } else if (t->sprites.units.icon[uidx][ACTIVITY_IDLE] != NULL
6831 && (icon
6832 || t->sprites.units.facing[uidx][facing][ACTIVITY_IDLE] == NULL)) {
6833 /* Has icon sprite, and we prefer to (or must) use it */
6834 return t->sprites.units.icon[uidx][ACTIVITY_IDLE];
6835 } else {
6836 /* We should have a valid orientation by now. Failure to have either
6837 * an icon sprite or default orientation should have been caught at
6838 * tileset load. */
6840
6841 if (t->sprites.units.facing[uidx][facing][activity] == NULL) {
6842 return t->sprites.units.facing[uidx][facing][ACTIVITY_IDLE];
6843 }
6844
6845 return t->sprites.units.facing[uidx][facing][activity];
6846 }
6847}
6848
6849/************************************************************************/
6852struct sprite *get_sample_city_sprite(const struct tileset *t,
6853 int style_idx)
6854{
6855 int num_thresholds =
6856 t->sprites.city.tile->styles[style_idx].land_num_thresholds;
6857
6858 if (num_thresholds == 0) {
6859 return NULL;
6860 } else {
6861 return (t->sprites.city.tile->styles[style_idx]
6862 .land_thresholds[num_thresholds - 1].sprite);
6863 }
6864}
6865
6866/************************************************************************/
6869struct sprite *get_arrow_sprite(const struct tileset *t,
6870 enum arrow_type arrow)
6871{
6872 fc_assert_ret_val(arrow >= 0 && arrow < ARROW_LAST, NULL);
6873
6874 return t->sprites.arrow[arrow];
6875}
6876
6877/************************************************************************/
6881{
6882 switch (otype) {
6883 case O_SCIENCE:
6884 return t->sprites.tax_science;
6885 case O_GOLD:
6886 return t->sprites.tax_gold;
6887 case O_LUXURY:
6888 return t->sprites.tax_luxury;
6889 case O_TRADE:
6890 case O_FOOD:
6891 case O_SHIELD:
6892 case O_LAST:
6893 break;
6894 }
6895 return NULL;
6896}
6897
6898/************************************************************************/
6901struct sprite *get_event_sprite(const struct tileset *t, enum event_type event)
6902{
6903 return t->sprites.events[event];
6904}
6905
6906/************************************************************************/
6910struct sprite *get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
6911{
6912 return t->sprites.treaty_thumb[on_off ? 1 : 0];
6913}
6914
6915/************************************************************************/
6920 tileset *t)
6921{
6922 return &t->sprites.explode.unit;
6923}
6924
6925/************************************************************************/
6931{
6932 return t->sprites.explode.nuke;
6933}
6934
6935/************************************************************************/
6938const struct citybar_sprites *get_citybar_sprites(const struct tileset *t)
6939{
6941 return &t->sprites.citybar;
6942 } else {
6943 return NULL;
6944 }
6945}
6946
6947/************************************************************************/
6950const struct editor_sprites *get_editor_sprites(const struct tileset *t)
6951{
6952 return &t->sprites.editor;
6953}
6954
6955/************************************************************************/
6961struct sprite *get_cursor_sprite(const struct tileset *t,
6962 enum cursor_type cursor,
6963 int *hot_x, int *hot_y, int frame)
6964{
6965 *hot_x = t->sprites.cursor[cursor].hot_x;
6966 *hot_y = t->sprites.cursor[cursor].hot_y;
6967
6968 return t->sprites.cursor[cursor].frame[frame];
6969}
6970
6971/************************************************************************/
6980struct sprite *get_icon_sprite(const struct tileset *t, enum icon_type icon)
6981{
6982 return t->sprites.icon[icon];
6983}
6984
6985/************************************************************************/
6992{
6993 return t->sprites.user.attention;
6994}
6995
6996/************************************************************************/
7000struct sprite *get_indicator_sprite(const struct tileset *t,
7001 enum indicator_type indicator,
7002 int idx)
7003{
7004 idx = CLIP(0, idx, NUM_TILES_PROGRESS - 1);
7005
7006 fc_assert_ret_val(indicator >= 0 && indicator < INDICATOR_COUNT, NULL);
7007
7008 return t->sprites.indicator[indicator][idx];
7009}
7010
7011/************************************************************************/
7018 const struct unit *punit,
7019 int happy_cost)
7020{
7021 const int unhappy = CLIP(0, happy_cost, MAX_NUM_UPKEEP_SPRITES+1);
7022
7023 if (unhappy > 0) {
7024 return t->sprites.upkeep.unhappy[unhappy - 1];
7025 } else {
7026 return NULL;
7027 }
7028}
7029
7030/************************************************************************/
7036struct sprite *get_unit_upkeep_sprite(const struct tileset *t,
7038 const struct unit *punit,
7039 const int *upkeep_cost)
7040{
7041 const int upkeep = CLIP(0, upkeep_cost[otype], MAX_NUM_UPKEEP_SPRITES + 1);
7042
7043 if (upkeep > 0) {
7044 return t->sprites.upkeep.output[otype][upkeep - 1];
7045 } else {
7046 return NULL;
7047 }
7048}
7049
7050/************************************************************************/
7054struct sprite *get_basic_fog_sprite(const struct tileset *t)
7055{
7056 return t->sprites.tx.fog;
7057}
7058
7059/************************************************************************/
7062struct color_system *get_color_system(const struct tileset *t)
7063{
7064 return t->color_system;
7065}
7066
7067/************************************************************************/
7071{
7072 char *default_theme_name = NULL;
7073 size_t default_theme_name_sz = 0;
7074 int i;
7075
7076 switch (get_gui_type()) {
7077 case GUI_GTK3_22:
7080 break;
7081 case GUI_GTK4:
7084 break;
7085 case GUI_SDL2:
7088 break;
7089 case GUI_SDL3:
7092 break;
7093 case GUI_STUB:
7094 case GUI_QT:
7095 case GUI_SDL:
7096 case GUI_WEB:
7097 case GUI_GTK2:
7098 case GUI_GTK3:
7099 break;
7100 }
7101
7103 /* Theme is not supported by this client. */
7104 return;
7105 }
7106
7107 for (i = 0; i < t->num_preferred_themes; i++) {
7110 log_debug("trying theme \"%s\".", t->preferred_themes[i]);
7111 if (load_theme(t->preferred_themes[i])) {
7114 return;
7115 }
7116 }
7117 }
7118 }
7119 log_verbose("The tileset doesn't specify preferred themes or none of its "
7120 "preferred themes can be used. Using system default.");
7122}
7123
7124/************************************************************************/
7127void tileset_init(struct tileset *t)
7128{
7129 int wi;
7130
7131 /* We currently have no city sprites loaded. */
7132 t->sprites.city.tile = NULL;
7133
7134 for (wi = 0; wi < NUM_WALL_TYPES; wi++) {
7135 t->sprites.city.wall[wi] = NULL;
7136 }
7138
7140
7141 t->sprites.background.color = NULL;
7142 t->sprites.background.graphic = NULL;
7143
7144 player_slots_iterate(pslot) {
7145 int edge, j, id = player_slot_index(pslot);
7146
7147 for (edge = 0; edge < EDGE_COUNT; edge++) {
7148 for (j = 0; j < 2; j++) {
7150 }
7151 }
7152
7153 t->sprites.player[id].color = NULL;
7156
7157 t->max_upkeep_height = 0;
7158}
7159
7160/************************************************************************/
7169 struct drawn_sprite *sprs,
7170 int layer,
7171 struct terrain *pterrain)
7172{
7173 struct drawn_sprite *save_sprs = sprs;
7174 struct drawing_data *draw = t->sprites.drawing[terrain_index(pterrain)];
7175
7176 struct terrain *tterrain_near[8];
7178
7179 struct tile dummy_tile; /* :( */
7180
7181 int i;
7182
7183
7184 memset(&dummy_tile, 0, sizeof(struct tile));
7185
7186 for (i = 0; i < 8; i++) {
7187 tterrain_near[i] = pterrain;
7189 }
7190
7191 i = draw->is_reversed ? draw->num_layers - layer - 1 : layer;
7193 pterrain, tterrain_near, draw);
7194
7195 return sprs - save_sprs;
7196}
7197
7198/************************************************************************/
7202 struct drawn_sprite *sprs,
7203 const struct extra_type *pextra)
7204{
7205 int idx = extra_index(pextra);
7206 struct drawn_sprite *saved_sprs = sprs;
7207
7208 switch (t->sprites.extras[idx].extrastyle) {
7209 case ESTYLE_SINGLE1:
7210 case ESTYLE_SINGLE2:
7212 break;
7213 case ESTYLE_CARDINALS:
7215 break;
7219 case ESTYLE_RIVER:
7220 return fill_basic_road_sprite_array(t, sprs, pextra);
7221 case ESTYLE_3LAYER:
7222 return fill_basic_base_sprite_array(t, sprs, pextra);
7223 case ESTYLE_COUNT:
7225 break;
7226 }
7227
7228 return sprs - saved_sprs;
7229}
7230
7231/************************************************************************/
7237 struct drawn_sprite *sprs,
7238 const struct extra_type *pextra)
7239{
7240 struct drawn_sprite *saved_sprs = sprs;
7241 int idx;
7242 int i;
7243 enum extrastyle_id extrastyle;
7244
7245 if (!t || !sprs || !pextra) {
7246 return 0;
7247 }
7248
7249 idx = extra_index(pextra);
7250
7251 if (!(0 <= idx && idx < game.control.num_extra_types)) {
7252 return 0;
7253 }
7254
7255 extrastyle = t->sprites.extras[idx].extrastyle;
7256
7257 if (extrastyle == ESTYLE_RIVER) {
7259 } else {
7260 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
7261 if (!t->valid_tileset_dirs[i]) {
7262 continue;
7263 }
7264 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
7266 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
7267 if ((i % 2) == 0) {
7268 ADD_SPRITE_SIMPLE(t->sprites.extras[idx].u.road.ru.combo.even[1 << (i / 2)]);
7269 }
7270 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
7271 ADD_SPRITE_SIMPLE(t->sprites.extras[idx].u.road.ru.total[1 << i]);
7272 }
7273 }
7274 }
7275
7276 return sprs - saved_sprs;
7277}
7278
7279/************************************************************************/
7285 struct drawn_sprite *sprs,
7286 const struct extra_type *pextra)
7287{
7288 struct drawn_sprite *saved_sprs = sprs;
7289 int idx;
7290
7291 if (!t || !sprs || !pextra) {
7292 return 0;
7293 }
7294
7295 idx = extra_index(pextra);
7296
7297 if (!(0 <= idx && idx < game.control.num_extra_types)) {
7298 return 0;
7299 }
7300
7301#define ADD_SPRITE_IF_NOT_NULL(x) do {\
7302 if ((x) != NULL) {\
7303 ADD_SPRITE_FULL(x);\
7304 }\
7305} while (FALSE)
7306
7307 /* Corresponds to LAYER_SPECIAL{1,2,3} order. */
7311
7312#undef ADD_SPRITE_IF_NOT_NULL
7313
7314 return sprs - saved_sprs;
7315}
7316
7317/************************************************************************/
7320enum mapview_layer tileset_get_layer(const struct tileset *t, int n)
7321{
7323 return t->layer_order[n];
7324}
7325
7326/************************************************************************/
7330 enum layer_category cat)
7331{
7332 switch (layer) {
7333 case LAYER_BACKGROUND:
7334 case LAYER_TERRAIN1:
7335 case LAYER_DARKNESS:
7336 case LAYER_TERRAIN2:
7337 case LAYER_TERRAIN3:
7338 case LAYER_WATER:
7339 case LAYER_ROADS:
7340 case LAYER_SPECIAL1:
7341 case LAYER_SPECIAL2:
7342 case LAYER_SPECIAL3:
7344 case LAYER_CITY1:
7345 case LAYER_CITY2:
7346 return cat == LAYER_CATEGORY_CITY;
7347 case LAYER_UNIT:
7348 case LAYER_FOCUS_UNIT:
7349 return cat == LAYER_CATEGORY_UNIT;
7350 case LAYER_GRID1:
7351 case LAYER_FOG:
7352 case LAYER_GRID2:
7353 case LAYER_OVERLAYS:
7354 case LAYER_TILELABEL:
7355 case LAYER_CITYBAR:
7356 case LAYER_GOTO:
7357 case LAYER_WORKERTASK:
7358 case LAYER_EDITOR:
7359 case LAYER_INFRAWORK:
7360 return FALSE;
7361 case LAYER_COUNT:
7362 break; /* and fail below */
7363 }
7364
7365 fc_assert_msg(FALSE, "Unknown layer category: %d", cat);
7366 return FALSE;
7367}
7368
7369/************************************************************************/
7372void tileset_player_init(struct tileset *t, struct player *pplayer)
7373{
7374 int plrid, i, j;
7375 struct sprite *color;
7376
7377 fc_assert_ret(pplayer != NULL);
7378
7379 plrid = player_index(pplayer);
7380 fc_assert_ret(plrid >= 0);
7382
7383 /* Free all data before recreating it. */
7385
7386 if (player_has_color(pplayer)) {
7388 = create_plr_sprite(get_player_color(t, pplayer));
7389 } else {
7390 /* XXX: if player hasn't been assigned a color, perhaps there's no
7391 * point proceeding with an arbitrary color; this should only happen
7392 * in pregame. Probably blank sprites would be better. */
7393
7394 fc_assert_ret(t->sprites.background.color != NULL);
7395
7396 color = t->sprites.background.color;
7397 }
7398
7400 = crop_sprite(color, 0, 0,
7402 t->sprites.mask.tile, 0, 0, t->scale, FALSE);
7403
7404 for (i = 0; i < EDGE_COUNT; i++) {
7405 for (j = 0; j < 2; j++) {
7406 struct sprite *s;
7407
7408 if (color && t->sprites.grid.borders[i][j]) {
7409 s = crop_sprite(color, 0, 0,
7411 t->sprites.grid.borders[i][j], 0, 0, 1.0f, FALSE);
7412 } else {
7413 s = t->sprites.grid.borders[i][j];
7414 }
7415 t->sprites.player[plrid].grid_borders[i][j] = s;
7416 }
7417 }
7418}
7419
7420/************************************************************************/
7423static void tileset_player_free(struct tileset *t, int plrid)
7424{
7425 int i, j;
7426
7427 fc_assert_ret(plrid >= 0);
7429
7430 if (t->sprites.player[plrid].color) {
7433 }
7434 if (t->sprites.player[plrid].background) {
7437 }
7438
7439 for (i = 0; i < EDGE_COUNT; i++) {
7440 for (j = 0; j < 2; j++) {
7441 if (t->sprites.player[plrid].grid_borders[i][j]) {
7444 }
7445 }
7446 }
7447}
7448
7449/************************************************************************/
7453{
7454 /* Free all data before recreating it. */
7456
7457 /* Generate background color */
7458 t->sprites.background.color
7460
7461 /* Chop up and build the background graphics. */
7462 t->sprites.background.graphic
7463 = crop_sprite(t->sprites.background.color, 0, 0,
7465 t->sprites.mask.tile, 0, 0, t->scale, FALSE);
7466}
7467
7468/************************************************************************/
7472{
7473 if (t->sprites.background.color) {
7474 free_sprite(t->sprites.background.color);
7475 t->sprites.background.color = NULL;
7476 }
7477
7478 if (t->sprites.background.graphic) {
7479 free_sprite(t->sprites.background.graphic);
7480 t->sprites.background.graphic = NULL;
7481 }
7482}
7483
7484/************************************************************************/
7488{
7489 int i;
7490
7491 for (i = 0; i < ESTYLE_COUNT; i++) {
7492 if (t->style_lists[i] != NULL) {
7495 }
7496 }
7497
7498 if (t->flagged_bases_list != NULL) {
7501 }
7502
7503 if (t->sprites.style_citizen_sets.sets != NULL) {
7505 }
7506
7509 * sizeof(t->sprites.style_citizen_sets.sets[0]));
7510}
7511
7512/************************************************************************/
7516{
7517 return !tileset_update;
7518}
7519
7520/************************************************************************/
7523const char *tileset_name_get(struct tileset *t)
7524{
7525 return t->given_name;
7526}
7527
7528/************************************************************************/
7531const char *tileset_version(struct tileset *t)
7532{
7533 return t->version;
7534}
7535
7536/************************************************************************/
7539const char *tileset_summary(struct tileset *t)
7540{
7541 return t->summary;
7542}
7543
7544/************************************************************************/
7547const char *tileset_description(struct tileset *t)
7548{
7549 return t->description;
7550}
7551
7552/************************************************************************/
7556{
7557 return t->for_ruleset;
7558}
7559
7560/************************************************************************/
7564{
7565 return t->ts_topo_idx;
7566}
7567
7568/************************************************************************/
7572{
7573 return t->svg_height;
7574}
7575
7576/************************************************************************/
7579struct sprite *load_popup_sprite(const char *tag)
7580{
7581 return load_sprite(tileset, tag, TRUE, TRUE, FALSE);
7582}
7583
7584/************************************************************************/
7587void unload_popup_sprite(const char *tag)
7588{
7589 unload_sprite(tileset, tag);
7590}
#define str
Definition astring.c:76
#define n
Definition astring.c:77
#define BV_CLR_ALL(bv)
Definition bitvector.h:95
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
struct canvas int int struct sprite int int offset_y
Definition canvas_g.h:44
struct canvas int int struct sprite int offset_x
Definition canvas_g.h:44
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
bool has_capabilities(const char *us, const char *them)
Definition capability.c:86
bool base_city_celebrating(const struct city *pcity)
Definition city.c:1637
const char * city_style_rule_name(const int style)
Definition city.c:1765
const char * get_output_identifier(Output_type_id output)
Definition city.c:619
bool city_can_be_built_here(const struct civ_map *nmap, const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1487
bool city_base_to_city_map(int *city_map_x, int *city_map_y, const struct city *const pcity, const struct tile *map_tile)
Definition city.c:281
bool city_tile_to_city_map(int *city_map_x, int *city_map_y, const int city_radius_sq, const struct tile *city_center, const struct tile *map_tile)
Definition city.c:264
static const struct city struct citystyle * city_styles
Definition city.c:84
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1283
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1456
static citizens city_size_get(const struct city *pcity)
Definition city.h:569
citizen_category
Definition city.h:267
@ CITIZEN_LAST
Definition city.h:272
@ CITIZEN_SPECIALIST
Definition city.h:273
@ CITIZEN_ANGRY
Definition city.h:271
@ CITIZEN_HAPPY
Definition city.h:268
@ CITIZEN_CONTENT
Definition city.h:269
@ CITIZEN_UNHAPPY
Definition city.h:270
#define output_type_iterate(output)
Definition city.h:845
#define city_owner(_pcity_)
Definition city.h:563
#define MAX_CITY_SIZE
Definition city.h:106
#define output_type_iterate_end
Definition city.h:851
void generate_citydlg_dimensions(void)
int main(int argc, char *argv[])
Definition civserver.c:72
struct civclient client
enum client_states client_state(void)
client_states
Definition client_main.h:43
@ C_S_RUNNING
Definition client_main.h:47
@ C_S_OVER
Definition client_main.h:48
enum known_type client_tile_get_known(const struct tile *ptile)
Definition climap.c:36
bool client_city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition climap.c:133
static struct fc_sockaddr_list * list
Definition clinet.c:102
void color_system_free(struct color_system *colors)
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
struct color_system * color_system_read(struct section_file *file)
struct color * ensure_color(struct rgbcolor *rgb)
bool player_has_color(const struct player *pplayer)
char * incite_cost
Definition comments.c:75
bool unit_is_in_focus(const struct unit *punit)
Definition control.c:388
bool should_ask_server_for_actions(const struct unit *punit)
Definition control.c:339
struct unit_list * get_units_in_focus(void)
Definition control.c:177
struct unit * find_visible_unit(struct tile *ptile)
Definition control.c:822
#define log_deprecation(message,...)
static void road(QVariant data1, QVariant data2)
Definition dialogs.cpp:2919
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction show_tileset_error
Definition dialogs_g.h:85
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction bool const char * tset_name
Definition dialogs_g.h:86
int int id
Definition editgui_g.h:28
bool editor_is_active(void)
Definition editor.c:347
bool editor_tile_is_selected(const struct tile *ptile)
Definition editor.c:1118
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct player *other_player, enum effect_type effect_type)
Definition effects.c:748
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:846
enum event_type event
Definition events.c:81
const char * get_event_tag(enum event_type event)
Definition events.c:276
static struct @24 events[]
char * tag_name
Definition events.c:77
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1114
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:861
static struct extra_type extras[MAX_EXTRA_TYPES]
Definition extras.c:31
const char * extra_rule_name(const struct extra_type *pextra)
Definition extras.c:203
bool is_extra_removed_by(const struct extra_type *pextra, enum extra_rmcause rmcause)
Definition extras.c:353
int extra_count(void)
Definition extras.c:153
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_list_iterate(extralist, pextra)
Definition extras.h:165
#define extra_type_iterate_end
Definition extras.h:321
#define is_extra_caused_by(e, c)
Definition extras.h:203
#define extra_index(_e_)
Definition extras.h:183
#define extra_type_list_iterate_end
Definition extras.h:167
#define extra_road_get(_e_)
Definition extras.h:191
#define MAX_VET_LEVELS
Definition fc_types.h:49
#define DIR8_MAGIC_MAX
Definition fc_types.h:471
#define MAX_NUM_ITEMS
Definition fc_types.h:40
int Tech_type_id
Definition fc_types.h:377
#define SP_MAX
Definition fc_types.h:409
int Specialist_type_id
Definition fc_types.h:375
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
@ O_LAST
Definition fc_types.h:101
@ BORDERS_DISABLED
Definition fc_types.h:1037
enum output_type_id Output_type_id
Definition fc_types.h:378
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:62
struct world wld
Definition game.c:63
bool goto_is_active(void)
Definition goto.c:1059
goto_tile_state
Definition goto.h:25
@ GTS_EXHAUSTED_MP
Definition goto.h:28
@ GTS_MP_LEFT
Definition goto.h:27
@ GTS_TURN_STEP
Definition goto.h:26
@ GTS_COUNT
Definition goto.h:30
Government_type_id government_index(const struct government *pgovern)
Definition government.c:82
const char * government_rule_name(const struct government *pgovern)
Definition government.c:133
#define governments_iterate(NAME_pgov)
Definition government.h:124
#define G_LAST
Definition government.h:48
#define governments_iterate_end
Definition government.h:127
struct city * owner
Definition citydlg.c:226
bool is_view_supported(enum ts_type type)
Definition graphics.c:53
void tileset_type_set(enum ts_type type)
Definition graphics.c:67
enum gui_type get_gui_type(void)
Definition gui_main.c:2077
void tileset_changed(void)
Definition mapview.c:782
GType type
Definition repodlgs.c:1313
void free_sprite(struct sprite *s)
Definition sprite.c:278
struct sprite * create_sprite(int width, int height, struct color *pcolor)
Definition sprite.c:84
struct sprite * sprite_scale(struct sprite *src, int new_w, int new_h)
Definition sprite.c:291
struct sprite * load_gfxnumber(int num)
Definition sprite.c:526
struct sprite * load_gfxfile(const char *filename, bool svgflag)
Definition sprite.c:170
const char ** gfx_fileextensions(void)
Definition sprite.c:117
bool popup_theme_suggestion_dialog(const char *theme_name)
Definition theme_dlg.c:46
static bool load_theme
Definition theme_dlg.c:30
void gui_clear_theme(void)
Definition themes.c:72
void boot_help_texts(void)
Definition helpdata.c:768
const char * improvement_rule_name(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:181
#define fc_assert_ret(condition)
Definition log.h:191
#define log_verbose(message,...)
Definition log.h:109
#define fc_assert(condition)
Definition log.h:176
#define fc_assert_ret_val(condition, val)
Definition log.h:194
#define log_fatal(message,...)
Definition log.h:100
#define fc_assert_action(condition, action)
Definition log.h:187
#define log_debug(message,...)
Definition log.h:115
#define log_normal(message,...)
Definition log.h:107
#define log_base(level, message,...)
Definition log.h:94
log_level
Definition log.h:28
@ LOG_ERROR
Definition log.h:30
@ LOG_DEBUG
Definition log.h:34
@ LOG_NORMAL
Definition log.h:32
@ LOG_FATAL
Definition log.h:29
@ LOG_VERBOSE
Definition log.h:33
#define log_error(message,...)
Definition log.h:103
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:208
struct startpos * map_startpos_get(const struct tile *ptile)
Definition map.c:1883
enum direction8 dir_ccw(enum direction8 dir)
Definition map.c:1203
bool is_valid_dir(enum direction8 dir)
Definition map.c:1260
enum direction8 dir_cw(enum direction8 dir)
Definition map.c:1174
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:371
static int img_index(const int x, const int y, const struct img *pimg)
Definition mapimg.c:1996
struct city * find_city_or_settler_near_tile(const struct tile *ptile, struct unit **punit)
void update_map_canvas_visible(void)
enum topo_comp_lvl tileset_map_topo_compatible(int topology_id, struct tileset *tset, int *tset_topo)
struct tile * get_center_tile_mapcanvas(void)
bool mapdeco_is_highlight_set(const struct tile *ptile)
#define NUM_CITY_COLORS
void center_tile_mapcanvas(const struct tile *ptile)
const struct tile * center_tile
struct tile * client_infratile(void)
const char * describe_topology(int topo)
bool can_slide
bool mapdeco_is_crosshair_set(const struct tile *ptile)
@ TOPO_INCOMP_HARD
#define H(x, y, z)
Definition md5.c:92
#define fc_calloc(n, esz)
Definition mem.h:38
#define fc_strdup(str)
Definition mem.h:43
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_malloc(sz)
Definition mem.h:34
void menus_init(void)
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:363
#define SINGLE_MOVE
Definition movement.h:26
const char * nation_rule_name(const struct nation_type *pnation)
Definition nation.c:138
Nation_type_id nation_count(void)
Definition nation.c:507
struct nation_type * nation_of_unit(const struct unit *punit)
Definition nation.c:463
struct nation_type * nation_of_player(const struct player *pplayer)
Definition nation.c:444
struct nation_type * nation_of_city(const struct city *pcity)
Definition nation.c:454
Nation_type_id nation_index(const struct nation_type *pnation)
Definition nation.c:498
#define nations_iterate_end
Definition nation.h:336
#define nations_iterate(NAME_pnation)
Definition nation.h:333
void option_set_default_ts(struct tileset *t)
Definition options.c:6607
const char * option_str_get(const struct option *poption)
Definition options.c:897
int option_get_cb_data(const struct option *poption)
Definition options.c:791
struct client_options gui_options
Definition options.c:72
int len
Definition packhand.c:127
bool player_in_city_map(const struct player *pplayer, const struct tile *ptile)
Definition player.c:1249
int player_slot_index(const struct player_slot *pslot)
Definition player.c:426
int player_index(const struct player *pplayer)
Definition player.c:829
#define players_iterate_end
Definition player.h:537
#define players_iterate(_pplayer)
Definition player.h:532
#define player_slots_iterate(_pslot)
Definition player.h:523
#define player_slots_iterate_end
Definition player.h:527
#define fc_randomly(_seed, _size)
Definition rand.h:73
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
Definition registry.c:50
const char * secfile_error(void)
const char * section_name(const struct section *psection)
void secfile_destroy(struct section_file *secfile)
void secfile_check_unused(const struct section_file *secfile)
bool secfile_lookup_int(const struct section_file *secfile, int *ival, const char *path,...)
struct section_list * secfile_sections_by_name_prefix(const struct section_file *secfile, const char *prefix)
const char ** secfile_lookup_str_vec(const struct section_file *secfile, size_t *dim, const char *path,...)
struct entry * secfile_entry_lookup(const struct section_file *secfile, const char *path,...)
const char * secfile_lookup_str(const struct section_file *secfile, const char *path,...)
bool secfile_lookup_bool_default(const struct section_file *secfile, bool def, const char *path,...)
int secfile_lookup_int_default(const struct section_file *secfile, int def, const char *path,...)
const char * secfile_lookup_str_default(const struct section_file *secfile, const char *def, const char *path,...)
bool secfile_lookup_bool(const struct section_file *secfile, bool *bval, const char *path,...)
#define section_list_iterate(seclist, psection)
#define secfile_entry_ignore(_sfile_, _fmt_,...)
#define section_list_iterate_end
#define secfile_entry_ignore_by_path(_sfile_, _path_)
bool is_cardinal_only_road(const struct extra_type *pextra)
Definition road.c:483
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1101
struct strvec * fileinfolist(const struct strvec *dirs, const char *suffix)
Definition shared.c:1027
const struct strvec * get_data_dirs(void)
Definition shared.c:893
#define CLIP(lower, current, upper)
Definition shared.h:57
#define ARRAY_SIZE(x)
Definition shared.h:85
#define MAX(x, y)
Definition shared.h:54
#define XOR(p, q)
Definition shared.h:71
struct specialist * specialist_by_number(const Specialist_type_id id)
Definition specialist.c:100
#define specialist_type_iterate_end
Definition specialist.h:79
#define specialist_type_iterate(sp)
Definition specialist.h:73
size_t size
Definition specvec.h:72
struct sprite int int int int struct sprite * mask
Definition sprite_g.h:32
struct sprite int int y
Definition sprite_g.h:31
struct sprite int int int int struct sprite int int float scale
Definition sprite_g.h:33
struct sprite int x
Definition sprite_g.h:31
crop_sprite
Definition sprite_g.h:30
struct sprite int int int int struct sprite int int float bool smooth get_sprite_dimensions
Definition sprite_g.h:36
static bool wall(char *str, bool check)
Definition stdinhand.c:1927
void strvec_destroy(struct strvec *psv)
void strvec_append(struct strvec *psv, const char *string)
struct strvec * strvec_new(void)
#define strvec_iterate(psv, str)
#define strvec_iterate_end
struct sprite * sprite[MAX_NUM_CITIZEN_SPRITES]
Definition tilespec.c:224
struct citizen_graphic citizen[CITIZEN_LAST]
Definition tilespec.c:228
struct citizen_graphic specialist[SP_MAX]
Definition tilespec.c:229
struct city_style_threshold * land_thresholds
Definition tilespec.c:209
int land_num_thresholds
Definition tilespec.c:208
int num_styles
Definition tilespec.c:211
struct city_sprite::@230 * styles
struct sprite * sprite
Definition tilespec.c:203
Definition city.h:320
int color_index
Definition city.h:470
bool occupied
Definition city.h:460
int walls
Definition city.h:461
citizens size
Definition city.h:332
unsigned char first_citizen_index
Definition city.h:483
struct tile * tile
Definition city.h:322
int city_image
Definition city.h:464
bool colored
Definition city.h:469
bool unhappy
Definition city.h:463
struct city::@17::@20 client
struct sprite_vector occupancy
Definition tilespec.h:336
struct rgbcolor * plr_bg_color
Definition game.h:103
struct packet_ruleset_control control
Definition game.h:83
struct packet_game_info info
Definition game.h:89
bool ruleset_ready
Definition game.h:119
struct civ_game::@31::@34 client
int topology_id
Definition map_types.h:72
struct connection conn
Definition client_main.h:96
bool draw_native
Definition options.h:215
bool draw_specials
Definition options.h:207
bool draw_city_output
Definition options.h:194
char gui_sdl3_default_theme_name[512]
Definition options.h:393
bool draw_mines
Definition options.h:205
bool draw_borders
Definition options.h:214
bool draw_fortress_airbase
Definition options.h:206
bool draw_unit_stack_size
Definition options.h:218
bool draw_irrigation
Definition options.h:204
bool draw_terrain
Definition options.h:201
bool draw_units
Definition options.h:211
int default_topology
Definition options.h:123
bool draw_fog_of_war
Definition options.h:213
bool draw_unit_shields
Definition options.h:217
char gui_sdl2_default_theme_name[512]
Definition options.h:380
bool draw_cities
Definition options.h:210
bool draw_map_grid
Definition options.h:195
bool draw_focus_unit
Definition options.h:212
bool draw_paths
Definition options.h:203
bool draw_city_outlines
Definition options.h:193
bool draw_coastline
Definition options.h:202
bool draw_full_citybar
Definition options.h:216
bool draw_pollution
Definition options.h:209
char gui_gtk4_default_theme_name[512]
Definition options.h:337
char gui_gtk3_22_default_theme_name[512]
Definition options.h:301
bool solid_color_behind_units
Definition options.h:149
Definition colors.h:21
bool established
Definition connection.h:140
struct player * playing
Definition connection.h:151
int match_index[1+MAX_NUM_MATCH_WITH]
Definition tilespec.c:181
enum match_style match_style
Definition tilespec.c:180
enum sprite_type sprite_type
Definition tilespec.c:184
struct sprite_vector allocated
Definition tilespec.c:192
struct sprite * match[MAX_INDEX_CARDINAL]
Definition tilespec.c:187
struct sprite_vector base
Definition tilespec.c:186
struct sprite ** cells
Definition tilespec.c:188
bool is_reversed
Definition tilespec.c:195
struct sprite * blend[4]
Definition tilespec.c:199
struct drawing_data::drawing_layer layer[MAX_NUM_LAYERS]
struct sprite * blender
Definition tilespec.c:198
char * name
Definition tilespec.c:170
char rmact_gfx[MAX_LEN_NAME]
Definition extras.h:102
char act_gfx_alt[MAX_LEN_NAME]
Definition extras.h:100
struct extra_type_list * hiders
Definition extras.h:144
char rmact_gfx_alt[MAX_LEN_NAME]
Definition extras.h:103
struct road_type * road
Definition extras.h:155
char rmact_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:104
char graphic_alt[MAX_LEN_NAME]
Definition extras.h:98
char activity_gfx[MAX_LEN_NAME]
Definition extras.h:99
char act_gfx_alt2[MAX_LEN_NAME]
Definition extras.h:101
char graphic_str[MAX_LEN_NAME]
Definition extras.h:97
char graphic_alt[MAX_LEN_NAME]
Definition government.h:58
char graphic_str[MAX_LEN_NAME]
Definition government.h:57
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:55
char graphic_alt2[MAX_LEN_NAME]
Definition improvement.h:57
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:56
struct named_sprites::@239 user
struct sprite * graphic
Definition tilespec.c:404
struct sprite * tax_gold
Definition tilespec.c:248
struct named_sprites::@231 mask
struct sprite * government[G_LAST]
Definition tilespec.c:260
struct sprite_vector nation_shield
Definition tilespec.c:268
struct citizen_set default_citizens
Definition tilespec.c:270
struct sprite * loaded
Definition tilespec.c:300
struct sprite * even[MAX_INDEX_HALF]
Definition tilespec.c:377
struct sprite * output[O_LAST][MAX_NUM_UPKEEP_SPRITES]
Definition tilespec.c:313
struct sprite ** stack
Definition tilespec.c:299
struct sprite * infratile
Definition tilespec.c:345
struct sprite * background
Definition tilespec.c:362
struct sprite * frame[NUM_CURSOR_FRAMES]
Definition tilespec.c:276
struct sprite * patrol
Definition tilespec.c:303
struct sprite * spaceship[SPACESHIP_COUNT]
Definition tilespec.c:273
struct sprite * rmact
Definition tilespec.c:356
struct sprite * selected[EDGE_COUNT]
Definition tilespec.c:395
int num_stack_sprites
Definition tilespec.c:283
struct sprite * transform
Definition tilespec.c:301
struct sprite * tile_shieldnum[NUM_TILES_DIGITS]
Definition tilespec.c:322
struct sprite ** fullfog
Definition tilespec.c:350
struct sprite_vector unworked_tile_overlay
Definition tilespec.c:330
enum extrastyle_id extrastyle
Definition tilespec.c:357
struct sprite * tile_foodnum[NUM_TILES_DIGITS]
Definition tilespec.c:321
struct sprite * turns[NUM_TILES_DIGITS]
Definition tilespec.c:337
struct sprite_vector nation_flag
Definition tilespec.c:267
struct named_sprites::@245 player[MAX_NUM_PLAYER_SLOTS]
struct named_sprites::@241 extras[MAX_EXTRA_TYPES]
struct sprite * nonnative
Definition tilespec.c:394
struct sprite * plant
Definition tilespec.c:296
bool no_more_stack_sprites
Definition tilespec.c:284
struct city_sprite * single_wall
Definition tilespec.c:326
struct sprite * indicator[INDICATOR_COUNT][NUM_TILES_PROGRESS]
Definition tilespec.c:238
struct sprite * borders[EDGE_COUNT][2]
Definition tilespec.c:397
struct sprite * size_tens[NUM_TILES_DIGITS]
Definition tilespec.c:319
struct city_sprite * tile
Definition tilespec.c:324
struct sprite * disorder
Definition tilespec.c:316
struct sprite * tile_tradenum[NUM_TILES_DIGITS]
Definition tilespec.c:323
struct sprite * unworked_tile
Definition tilespec.c:255
struct named_sprites::@236 upkeep
struct sprite * waypoint
Definition tilespec.c:341
struct sprite * pillage
Definition tilespec.c:297
struct sprite * auto_settler
Definition tilespec.c:290
struct sprite * fortified
Definition tilespec.c:292
struct sprite * dither_tile
Definition tilespec.c:249
struct sprite * coastline[EDGE_COUNT]
Definition tilespec.c:396
struct named_sprites::@238::@246 s[GTS_COUNT]
struct sprite * tired
Definition tilespec.c:308
struct style_citizen_set style_citizen_sets
Definition tilespec.c:271
struct sprite * isolated
Definition tilespec.c:368
struct sprite * treaty_thumb[2]
Definition tilespec.c:240
struct named_sprites::@241::@247::@249 road
struct sprite * sentry
Definition tilespec.c:298
struct sprite * tax_luxury
Definition tilespec.c:248
struct sprite_vector unit
Definition tilespec.c:279
struct sprite * building[B_LAST]
Definition tilespec.c:259
struct sprite * turns_hundreds[NUM_TILES_DIGITS]
Definition tilespec.c:339
struct named_sprites::@233 cursor[CURSOR_LAST]
struct sprite * total[MAX_INDEX_VALID]
Definition tilespec.c:382
struct sprite * action_decision_want
Definition tilespec.c:306
struct named_sprites::@241::@247::@248 bmf
struct sprite * unhappy[MAX_NUM_UPKEEP_SPRITES]
Definition tilespec.c:311
struct sprite_vector worked_tile_overlay
Definition tilespec.c:329
struct named_sprites::@237 city
struct sprite * corner[8]
Definition tilespec.c:371
struct sprite * darkness[MAX_INDEX_CARDINAL]
Definition tilespec.c:351
struct sprite * tax_science
Definition tilespec.c:248
union named_sprites::@241::@247::@249::@250 ru
struct sprite * icon[ICON_COUNT]
Definition tilespec.c:243
struct named_sprites::@240 tx
struct sprite * specific
Definition tilespec.c:336
struct sprite * odd[MAX_INDEX_HALF]
Definition tilespec.c:379
struct named_sprites::@232 units
struct sprite * color
Definition tilespec.c:403
struct sprite * unavailable
Definition tilespec.c:393
struct sprite * worked_tile
Definition tilespec.c:254
struct river_sprites rivers
Definition tilespec.c:383
struct drawing_data * drawing[MAX_NUM_ITEMS]
Definition tilespec.c:412
struct sprite * go_to
Definition tilespec.c:294
struct sprite * middleground
Definition tilespec.c:364
struct sprite * foreground
Definition tilespec.c:365
struct citybar_sprites citybar
Definition tilespec.c:332
struct sprite * auto_explore
Definition tilespec.c:291
struct sprite * turns_tens[NUM_TILES_DIGITS]
Definition tilespec.c:338
struct sprite * tech[A_LAST]
Definition tilespec.c:258
struct sprite * nuke
Definition tilespec.c:280
struct named_sprites::@241::@247::@249::@250::@251 combo
struct sprite * convert
Definition tilespec.c:304
struct sprite * worked[EDGE_COUNT]
Definition tilespec.c:392
struct named_sprites::@234 explode
struct sprite_vector overlays
Definition tilespec.c:400
struct editor_sprites editor
Definition tilespec.c:333
struct named_sprites::@243 colors
struct sprite * size_hundreds[NUM_TILES_DIGITS]
Definition tilespec.c:320
struct sprite * activity
Definition tilespec.c:354
struct named_sprites::@242 grid
struct sprite * size[NUM_TILES_DIGITS]
Definition tilespec.c:318
struct sprite * cardinals[MAX_INDEX_CARDINAL]
Definition tilespec.c:360
struct sprite * fortifying
Definition tilespec.c:293
struct sprite * main[EDGE_COUNT]
Definition tilespec.c:389
struct sprite * events[E_COUNT]
Definition tilespec.c:245
struct sprite * auto_attack
Definition tilespec.c:289
union named_sprites::@241::@247 u
struct named_sprites::@238 path
struct city_sprite * wall[NUM_WALL_TYPES]
Definition tilespec.c:327
struct sprite * connect
Definition tilespec.c:302
struct sprite * fog
Definition tilespec.c:348
struct sprite * arrow[ARROW_LAST]
Definition tilespec.c:241
struct sprite * dir[8]
Definition tilespec.c:374
struct sprite * single
Definition tilespec.c:359
struct sprite * grid_borders[EDGE_COUNT][2]
Definition tilespec.c:407
struct sprite * facing[U_LAST][DIR8_MAGIC_MAX][ACTIVITY_LAST]
Definition tilespec.c:264
struct sprite * attention
Definition tilespec.c:344
struct city_sprite * occupied
Definition tilespec.c:328
struct sprite * tile
Definition tilespec.c:252
struct sprite * cultivate
Definition tilespec.c:295
struct sprite * lowfuel
Definition tilespec.c:307
char flag_graphic_str[MAX_LEN_NAME]
Definition nation.h:103
char flag_graphic_alt[MAX_LEN_NAME]
Definition nation.h:104
enum borders_mode borders
Definition goto.c:52
struct sprite * spec[MAX_INDEX_CARDINAL]
Definition tilespec.c:215
struct sprite * outlet[MAX_INDEX_CARDINAL]
Definition tilespec.c:217
struct sprite * sprite
Definition themespec.c:109
char * file
Definition themespec.c:100
struct specfile * sf
Definition themespec.c:103
char * file_name
Definition themespec.c:80
struct sprite * big_sprite
Definition themespec.c:79
char graphic_alt[MAX_LEN_NAME]
Definition specialist.h:36
Definition map.c:41
struct citizen_set * sets
Definition tilespec.c:233
char graphic_alt2[MAX_LEN_NAME]
Definition terrain.h:189
char graphic_alt[MAX_LEN_NAME]
Definition terrain.h:188
char graphic_str[MAX_LEN_NAME]
Definition terrain.h:187
Definition tile.h:50
char * spec_sprite
Definition tile.h:66
struct unit_list * units
Definition tile.h:58
struct extra_type * placing
Definition tile.h:61
struct city * worked
Definition tile.h:59
char given_name[MAX_LEN_NAME]
Definition tilespec.c:483
int num_cardinal_tileset_dirs
Definition tilespec.c:535
int occupied_offset_x
Definition tilespec.c:528
int stack_size_offset_y
Definition tilespec.c:527
struct named_sprites sprites
Definition tilespec.c:555
int ts_topo_idx
Definition tilespec.c:497
int hex_height
Definition tilespec.c:496
enum fog_style fogstyle
Definition tilespec.c:511
int normal_tile_height
Definition tilespec.c:499
int unit_tile_width
Definition tilespec.c:501
int city_offset_y
Definition tilespec.c:517
char * main_intro_filename
Definition tilespec.c:507
enum ts_type type
Definition tilespec.c:495
int city_size_offset_x
Definition tilespec.c:518
int num_preferred_themes
Definition tilespec.c:563
char version[MAX_LEN_NAME]
Definition tilespec.c:484
int full_tile_height
Definition tilespec.c:500
int small_sprite_width
Definition tilespec.c:502
char ** preferred_themes
Definition tilespec.c:564
struct extra_type_list * flagged_bases_list
Definition tilespec.c:561
enum darkness_style darkness_style
Definition tilespec.c:512
int activity_offset_x
Definition tilespec.c:522
int citybar_offset_y
Definition tilespec.c:520
int normal_tile_width
Definition tilespec.c:499
float scale
Definition tilespec.c:489
int svg_height
Definition tilespec.c:505
int unit_tile_height
Definition tilespec.c:501
int hex_width
Definition tilespec.c:496
int select_offset_y
Definition tilespec.c:525
int city_flag_offset_x
Definition tilespec.c:515
int unit_flag_offset_x
Definition tilespec.c:514
int occupied_offset_y
Definition tilespec.c:529
char * description
Definition tilespec.c:488
int max_upkeep_height
Definition tilespec.c:504
int unit_flag_offset_y
Definition tilespec.c:514
int unit_upkeep_offset_y
Definition tilespec.c:530
struct estyle_hash * estyle_hash
Definition tilespec.c:553
char * for_ruleset
Definition tilespec.c:491
int activity_offset_y
Definition tilespec.c:523
int num_index_valid
Definition tilespec.c:536
int select_offset_x
Definition tilespec.c:524
int num_index_cardinal
Definition tilespec.c:536
int full_tile_width
Definition tilespec.c:500
struct small_sprite_list * small_sprites
Definition tilespec.c:545
struct extra_type_list * style_lists[ESTYLE_COUNT]
Definition tilespec.c:559
enum direction8 unit_default_orientation
Definition tilespec.c:509
struct tileset::tileset_layer layers[MAX_NUM_LAYERS]
int small_sprite_height
Definition tilespec.c:502
int city_size_offset_y
Definition tilespec.c:518
struct sprite_hash * sprite_hash
Definition tilespec.c:548
int unit_upkeep_small_offset_y
Definition tilespec.c:531
int unit_offset_x
Definition tilespec.c:516
int unit_offset_y
Definition tilespec.c:516
enum mapview_layer layer_order[LAYER_COUNT]
Definition tilespec.c:493
int city_offset_x
Definition tilespec.c:517
int priority
Definition tilespec.c:485
enum direction8 cardinal_tileset_dirs[8]
Definition tilespec.c:537
enum direction8 valid_tileset_dirs[8]
Definition tilespec.c:537
struct color_system * color_system
Definition tilespec.c:557
char * summary
Definition tilespec.c:487
char name[512]
Definition tilespec.c:482
int city_flag_offset_y
Definition tilespec.c:515
struct drawing_hash * tile_hash
Definition tilespec.c:551
int num_valid_tileset_dirs
Definition tilespec.c:535
int stack_size_offset_x
Definition tilespec.c:526
struct specfile_list * specfiles
Definition tilespec.c:544
int tilelabel_offset_y
Definition tilespec.c:521
Definition unit.h:138
struct unit::@80 orders
bool occupied
Definition unit.h:219
enum action_decision action_decision_want
Definition unit.h:202
int battlegroup
Definition unit.h:191
enum unit_activity activity
Definition unit.h:157
int moves_left
Definition unit.h:150
struct unit::@81::@83 client
int hp
Definition unit.h:151
int fuel
Definition unit.h:153
enum direction8 facing
Definition unit.h:142
struct extra_type * activity_target
Definition unit.h:164
bool repeat
Definition unit.h:196
int veteran
Definition unit.h:152
enum server_side_agent ssa_controller
Definition unit.h:172
struct civ_map map
int style_of_city(const struct city *pcity)
Definition style.c:202
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:974
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:791
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:189
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:1000
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:900
#define sz_strlcpy(dest, src)
Definition support.h:195
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
const char ** ordered_gfx_fextensions(void)
Definition svgflag.c:53
#define is_svg_flag_enabled()
Definition svgflag.h:30
struct advance * valid_advance(struct advance *padvance)
Definition tech.c:152
const char * advance_rule_name(const struct advance *padvance)
Definition tech.c:299
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
static Tech_type_id advance_count(void)
Definition tech.h:170
#define advance_iterate(_p)
Definition tech.h:275
#define advance_iterate_end
Definition tech.h:276
#define A_LAST
Definition tech.h:45
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:138
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
Definition terrain.c:582
#define terrain_type_iterate(_p)
Definition terrain.h:373
#define T_UNKNOWN
Definition terrain.h:57
#define is_ocean_tile(ptile)
Definition terrain.h:303
#define terrain_type_iterate_end
Definition terrain.h:379
#define tile_index(_pt_)
Definition tile.h:88
#define tile_worked(_tile)
Definition tile.h:118
@ TILE_KNOWN_UNSEEN
Definition tile.h:37
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
#define tile_terrain(_tile)
Definition tile.h:114
#define TILE_XY(ptile)
Definition tile.h:43
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:124
#define tile_has_extra(ptile, pextra)
Definition tile.h:151
#define tile_owner(_tile)
Definition tile.h:96
static int fill_unit_type_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct unit_type *putype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:4544
struct sprite * get_government_sprite(const struct tileset *t, const struct government *gov)
Definition tilespec.c:6794
void tileset_load_tiles(struct tileset *t)
Definition tilespec.c:3628
struct sprite * get_nuke_explode_sprite(const struct tileset *t)
Definition tilespec.c:6930
#define sprite_hash_iterate(hash, tag_name, sprite)
Definition tilespec.c:462
int tileset_hex_width(const struct tileset *t)
Definition tilespec.c:721
struct sprite * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
Definition tilespec.c:6784
int tileset_unit_width(const struct tileset *t)
Definition tilespec.c:797
static int fill_goto_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner)
Definition tilespec.c:5679
#define NUM_TILES_SELECT
Definition tilespec.c:114
struct unit * get_drawable_unit(const struct tileset *t, struct tile *ptile, const struct city *citymode)
Definition tilespec.c:6565
static int check_sprite_type(const char *sprite_type, const char *tile_section)
Definition tilespec.c:1864
struct sprite * get_attention_crosshair_sprite(const struct tileset *t)
Definition tilespec.c:6991
int tileset_unit_height(const struct tileset *t)
Definition tilespec.c:805
static struct tileset * tileset_new(void)
Definition tilespec.c:971
#define MAX_INDEX_VALID
Definition tilespec.c:110
void tileset_setup_unit_type(struct tileset *t, struct unit_type *ut)
Definition tilespec.c:3806
static bool check_tilespec_capabilities(struct section_file *file, const char *which, const char *us_capstr, const char *filename, bool verbose)
Definition tilespec.c:1164
int tileset_small_sprite_width(const struct tileset *t)
Definition tilespec.c:901
static struct sprite * load_gfx_file(const char *gfx_filename, bool svgflag)
Definition tilespec.c:1557
#define specfile_list_iterate_end
Definition tilespec.c:426
static struct sprite * create_plr_sprite(struct color *pcolor)
Definition tilespec.c:2788
int tileset_svg_flag_height(struct tileset *t)
Definition tilespec.c:7571
#define SPEC_CAPSTR
Definition tilespec.c:96
static struct sprite * get_unit_nation_flag_sprite(const struct tileset *t, const struct unit *punit)
Definition tilespec.c:4479
direction4
Definition tilespec.c:138
@ DIR4_EAST
Definition tilespec.c:139
@ DIR4_NORTH
Definition tilespec.c:139
@ DIR4_SOUTH
Definition tilespec.c:139
@ DIR4_WEST
Definition tilespec.c:139
struct tileset * get_tileset(void)
Definition tilespec.c:692
#define MAX_NUM_MATCH_WITH
Definition tilespec.c:179
static struct sprite * get_city_sprite(const struct city_sprite *city_sprite, const struct city *pcity)
Definition tilespec.c:3035
void tileset_setup_government(struct tileset *t, struct government *gov)
Definition tilespec.c:4420
#define sprite_hash_iterate_end
Definition tilespec.c:465
struct sprite * get_city_flag_sprite(const struct tileset *t, const struct city *pcity)
Definition tilespec.c:4470
void tileset_setup_specialist_type_default_set(struct tileset *t, Specialist_type_id id)
Definition tilespec.c:2891
static bool is_valid_tileset_dir(const struct tileset *t, enum direction8 dir)
Definition tilespec.c:1030
struct sprite * get_basic_fog_sprite(const struct tileset *t)
Definition tilespec.c:7054
static enum direction8 dir_by_tileset_name(const char *str)
Definition tilespec.c:1012
#define ADD_SPRITE_SIMPLE(s)
Definition tilespec.c:4501
static int fill_basic_road_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7236
static int fill_unit_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct unit *punit, int stack, bool backdrop)
Definition tilespec.c:4563
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:789
bool tilespec_try_read(const char *tileset_name, bool verbose, int topo_id, bool global_default)
Definition tilespec.c:1296
static bool tileset_setup_unit_type_from_tag(struct tileset *t, int uidx, const char *tag)
Definition tilespec.c:3749
struct tileset * unscaled_tileset
Definition tilespec.c:568
static int fill_irrigation_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, bv_extras textras, bv_extras *textras_near, const struct city *pcity)
Definition tilespec.c:5034
int fill_basic_extra_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7201
#define specfile_list_iterate(list, pitem)
Definition tilespec.c:424
struct sprite * get_unit_upkeep_sprite(const struct tileset *t, Output_type_id otype, const struct unit *punit, const int *upkeep_cost)
Definition tilespec.c:7036
const char * tileset_main_intro_filename(const struct tileset *t)
Definition tilespec.c:947
void tileset_setup_tile_type(struct tileset *t, const struct terrain *pterrain)
Definition tilespec.c:4154
static const char direction4letters[4]
Definition tilespec.c:141
void tileset_player_init(struct tileset *t, struct player *pplayer)
Definition tilespec.c:7372
const struct strvec * get_tileset_list(const struct option *poption)
Definition tilespec.c:1103
int tileset_unit_layout_offset_y(const struct tileset *t)
Definition tilespec.c:882
int tileset_citybar_offset_y(const struct tileset *t)
Definition tilespec.c:910
#define MAX_NUM_UPKEEP_SPRITES
Definition tilespec.c:115
struct sprite * get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
Definition tilespec.c:6910
bool unit_drawn_with_city_outline(const struct unit *punit, bool check_focus)
Definition tilespec.c:5512
#define MAX_INDEX_HALF
Definition tilespec.c:109
double get_focus_unit_toggle_timeout(const struct tileset *t)
Definition tilespec.c:6520
#define SET_SPRITE_ALT_OPT(field, tag, alt)
Definition tilespec.c:2881
static int calculate_max_upkeep_height(const struct tileset *t)
Definition tilespec.c:813
static int fill_fog_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner)
Definition tilespec.c:5196
#define TILE_SECTION_PREFIX
Definition tilespec.c:105
static struct city_sprite * load_city_sprite(struct tileset *t, const char *tag)
Definition tilespec.c:3112
static char * valid_index_str(const struct tileset *t, int idx)
Definition tilespec.c:2695
void tileset_free_tiles(struct tileset *t)
Definition tilespec.c:6605
void tileset_setup_impr_type(struct tileset *t, struct impr_type *pimprove)
Definition tilespec.c:3840
static struct tileset * tileset_read_toplevel(const char *tileset_name, bool verbose, int topology_id, float scale)
Definition tilespec.c:1885
static bool sprite_exists(const struct tileset *t, const char *tag_name)
Definition tilespec.c:2828
const struct sprite_vector * get_unit_explode_animation(const struct tileset *t)
Definition tilespec.c:6919
#define TILESPEC_CAPSTR
Definition tilespec.c:80
static int load_city_thresholds_sprites(struct tileset *t, const char *tag, char *graphic, char *graphic_alt, struct city_style_threshold **thresholds)
Definition tilespec.c:3071
struct sprite * load_popup_sprite(const char *tag)
Definition tilespec.c:7579
static void unload_all_sprites(struct tileset *t)
Definition tilespec.c:6591
static const char * dir_get_tileset_name(enum direction8 dir)
Definition tilespec.c:985
#define SET_SPRITE_UNSCALED(field, tag)
Definition tilespec.c:2854
void tileset_background_init(struct tileset *t)
Definition tilespec.c:7452
void tileset_setup_tech_type(struct tileset *t, struct advance *padvance)
Definition tilespec.c:3856
static const int DIR4_TO_DIR8[4]
Definition tilespec.c:145
static int fill_terrain_sprite_layer(struct tileset *t, struct drawn_sprite *sprs, int layer_num, const struct tile *ptile, const struct terrain *pterrain, struct terrain **tterrain_near)
Definition tilespec.c:5467
static void unload_sprite(struct tileset *t, const char *tag_name)
Definition tilespec.c:2804
static void drawing_data_destroy(struct drawing_data *draw)
Definition tilespec.c:660
static int fill_terrain_sprite_darkness(struct tileset *t, struct drawn_sprite *sprs, const struct tile *ptile, struct terrain **tterrain_near)
Definition tilespec.c:5403
#define small_sprite_list_iterate_end
Definition tilespec.c:455
static struct drawing_data * drawing_data_new(void)
Definition tilespec.c:648
static void build_tile_data(const struct tile *ptile, struct terrain *pterrain, struct terrain **tterrain_near, bv_extras *textras_near)
Definition tilespec.c:4512
static void tileset_player_free(struct tileset *t, int plrid)
Definition tilespec.c:7423
float tileset_scale(const struct tileset *t)
Definition tilespec.c:927
#define UNKNOWN(dir)
int tileset_unit_with_small_upkeep_height(const struct tileset *t)
Definition tilespec.c:871
bool tileset_layer_in_category(enum mapview_layer layer, enum layer_category cat)
Definition tilespec.c:7329
static int fill_grid_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner, const struct unit *punit, const struct city *pcity, const struct city *citymode)
Definition tilespec.c:5529
match_style
Definition tilespec.c:148
@ MATCH_SAME
Definition tilespec.c:150
@ MATCH_FULL
Definition tilespec.c:152
@ MATCH_PAIR
Definition tilespec.c:151
@ MATCH_NONE
Definition tilespec.c:149
#define small_sprite_list_iterate(list, pitem)
Definition tilespec.c:453
int tileset_num_city_colors(const struct tileset *t)
Definition tilespec.c:955
int index_ts_topology(int idx)
Definition tilespec.c:1085
#define NUM_TILES_HP_BAR
Definition tilespec.c:112
#define TILESPEC_SUFFIX
Definition tilespec.c:104
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:712
bool tileset_use_hard_coded_fog(const struct tileset *t)
Definition tilespec.c:963
void tileset_use_preferred_theme(const struct tileset *t)
Definition tilespec.c:7070
#define FULL_TILE_X_OFFSET
Definition tilespec.c:4491
sprite_type
Definition tilespec.c:155
@ CELL_CORNER
Definition tilespec.c:157
@ CELL_WHOLE
Definition tilespec.c:156
void tileset_setup_city_tiles(struct tileset *t, int style)
Definition tilespec.c:6455
struct sprite * get_nation_shield_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6766
const char * tileset_description(struct tileset *t)
Definition tilespec.c:7547
#define SET_GOTO_TURN_SPRITE(state, state_name, factor, factor_name)
void tileset_background_free(struct tileset *t)
Definition tilespec.c:7471
#define MAX_NUM_LAYERS
Definition tilespec.c:173
int tileset_unit_layout_small_offset_y(const struct tileset *t)
Definition tilespec.c:891
struct sprite * get_event_sprite(const struct tileset *t, enum event_type event)
Definition tilespec.c:6901
void toggle_focus_unit_state(struct tileset *t)
Definition tilespec.c:6552
void tilespec_reread_frozen_refresh(const char *tname)
Definition tilespec.c:1545
int tileset_small_sprite_height(const struct tileset *t)
Definition tilespec.c:937
void tileset_free(struct tileset *t)
Definition tilespec.c:1274
static const char * cardinal_index_str(const struct tileset *t, int idx)
Definition tilespec.c:2675
#define NUM_TILES_DIGITS
Definition tilespec.c:113
void focus_unit_in_combat(struct tileset *t)
Definition tilespec.c:6541
static int tileset_upkeep_height(const struct tileset *t)
Definition tilespec.c:850
const char * tileset_summary(struct tileset *t)
Definition tilespec.c:7539
struct sprite * get_icon_sprite(const struct tileset *t, enum icon_type icon)
Definition tilespec.c:6980
static void ensure_big_sprite(struct specfile *sf, const char *tset_name)
Definition tilespec.c:1593
static bool tileset_update
Definition tilespec.c:572
#define FULL_TILE_Y_OFFSET
Definition tilespec.c:4492
struct sprite * get_indicator_sprite(const struct tileset *t, enum indicator_type indicator, int idx)
Definition tilespec.c:7000
struct sprite * get_sample_city_sprite(const struct tileset *t, int style_idx)
Definition tilespec.c:6852
#define ADD_SPRITE_FULL(s)
Definition tilespec.c:4502
void tileset_setup_extra(struct tileset *t, struct extra_type *pextra)
Definition tilespec.c:3875
int focus_unit_state
Definition tilespec.c:570
void tileset_init(struct tileset *t)
Definition tilespec.c:7127
static int fill_city_overlays_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct tile *ptile, const struct city *citymode)
Definition tilespec.c:5076
static char * tilespec_gfx_filename(const char *gfx_filename, const char *tset_name)
Definition tilespec.c:1799
const char * tileset_basename(const struct tileset *t)
Definition tilespec.c:704
int fill_basic_terrain_layer_sprite_array(struct tileset *t, struct drawn_sprite *sprs, int layer, struct terrain *pterrain)
Definition tilespec.c:7168
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:765
#define LOAD_FACING_SPRITE(dir)
#define SET_SPRITE_NOTSMOOTH(field, tag)
Definition tilespec.c:2845
static int fill_road_corner_sprites(const struct tileset *t, const struct extra_type *pextra, struct drawn_sprite *sprs, bool road, bool *road_near, bool hider, bool *hider_near)
Definition tilespec.c:4751
static bool is_extra_drawing_enabled(struct extra_type *pextra)
Definition tilespec.c:5747
struct sprite * get_spaceship_sprite(const struct tileset *t, enum spaceship_part part)
Definition tilespec.c:6692
int tileset_unit_with_upkeep_height(const struct tileset *t)
Definition tilespec.c:859
static void tileset_free_toplevel(struct tileset *t)
Definition tilespec.c:1202
static struct sprite * load_sprite(struct tileset *t, const char *tag_name, bool scale, bool smooth, bool svgflag)
Definition tilespec.c:2718
struct sprite * get_cursor_sprite(const struct tileset *t, enum cursor_type cursor, int *hot_x, int *hot_y, int frame)
Definition tilespec.c:6961
static const char edge_name[EDGE_COUNT][3]
Definition tilespec.c:143
struct color_system * get_color_system(const struct tileset *t)
Definition tilespec.c:7062
int tileset_hex_height(const struct tileset *t)
Definition tilespec.c:730
void reset_focus_unit_state(struct tileset *t)
Definition tilespec.c:6533
static const char * citizen_rule_name(enum citizen_category citizen)
Definition tilespec.c:2650
static void tileset_setup_citizen_types_default_set(struct tileset *t)
Definition tilespec.c:2985
bool tileset_is_fully_loaded(void)
Definition tilespec.c:7515
static int fill_terrain_sprite_blending(const struct tileset *t, struct drawn_sprite *sprs, const struct tile *ptile, const struct terrain *pterrain, struct terrain **tterrain_near)
Definition tilespec.c:5156
const struct citybar_sprites * get_citybar_sprites(const struct tileset *t)
Definition tilespec.c:6938
static bool is_cardinal_tileset_dir(const struct tileset *t, enum direction8 dir)
Definition tilespec.c:1048
void unload_popup_sprite(const char *tag)
Definition tilespec.c:7587
#define SET_SPRITE(field, tag)
Definition tilespec.c:2835
static void tileset_lookup_sprite_tags(struct tileset *t)
Definition tilespec.c:3160
struct sprite * get_arrow_sprite(const struct tileset *t, enum arrow_type arrow)
Definition tilespec.c:6869
struct sprite * get_unit_unhappy_sprite(const struct tileset *t, const struct unit *punit, int happy_cost)
Definition tilespec.c:7017
#define NUM_CORNER_DIRS
Definition tilespec.c:533
static int fill_basic_base_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7284
static void tileset_setup_base(struct tileset *t, const struct extra_type *pextra, const char *tag)
Definition tilespec.c:4116
static int fill_road_sprite_array(const struct tileset *t, const struct extra_type *pextra, struct drawn_sprite *sprs, bv_extras textras, bv_extras *textras_near, struct terrain *tterrain_near[8], const struct city *pcity)
Definition tilespec.c:4802
void finish_loading_sprites(struct tileset *t)
Definition tilespec.c:3612
static bool tileset_scan_single_list(struct tileset *t, const char *spec_filenames[], int num_spec_files, bool verbose, bool duplicates_ok)
Definition tilespec.c:1830
struct sprite * tiles_lookup_sprite_tag_alt(struct tileset *t, enum log_level level, const char *tag, const char *alt, const char *alt2, const char *what, const char *name, bool scale)
Definition tilespec.c:3639
#define SET_EDITOR_SPRITE(x)
#define SET_SPRITE_ALT(field, tag, alt)
Definition tilespec.c:2864
#define SET_SPRITE_OPT(field, tag)
Definition tilespec.c:2878
void tilespec_reread_callback(struct option *poption)
Definition tilespec.c:1509
static void tileset_setup_specialist_type(struct tileset *t, struct citizen_set *set, Specialist_type_id id, const char *tag_group, const char *set_name, bool required)
Definition tilespec.c:2901
static bool load_river_sprites(struct tileset *t, struct river_sprites *store, const char *tag_pfx)
Definition tilespec.c:3578
const char * tileset_name_get(struct tileset *t)
Definition tilespec.c:7523
static char * tilespec_fullname(const char *tileset_name)
Definition tilespec.c:1140
static const struct citizen_graphic * get_citizen_graphic(const struct citizen_set *set, enum citizen_category type)
Definition tilespec.c:6702
int fill_sprite_array(struct tileset *t, struct drawn_sprite *sprs, enum mapview_layer layer, const struct tile *ptile, const struct tile_edge *pedge, const struct tile_corner *pcorner, const struct unit *punit, const struct city *pcity, const struct city *citymode, const struct unit_type *putype)
Definition tilespec.c:5814
#define ADD_SPRITE(s, draw_fog, x_offset, y_offset)
Definition tilespec.c:4494
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:776
struct sprite * get_tax_sprite(const struct tileset *t, Output_type_id otype)
Definition tilespec.c:6880
static bool tileset_setup_unit_direction(struct tileset *t, int uidx, const char *base_str, enum direction8 dir, enum unit_activity activity, bool has_icon)
Definition tilespec.c:3685
struct sprite * get_citizen_sprite(const struct tileset *t, enum citizen_category type, int citizen_index, const struct city *pcity)
Definition tilespec.c:6723
static int fill_terrain_sprite_array(struct tileset *t, struct drawn_sprite *sprs, int l, const struct tile *ptile, const struct terrain *pterrain, struct terrain **tterrain_near, struct drawing_data *draw)
Definition tilespec.c:5250
const char * tileset_version(struct tileset *t)
Definition tilespec.c:7531
static void free_city_sprite(struct city_sprite *city_sprite)
Definition tilespec.c:3140
static int ts_topology_index(int actual_topology)
Definition tilespec.c:1063
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:6806
char * tileset_what_ruleset(struct tileset *t)
Definition tilespec.c:7555
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6757
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:753
int tileset_tilelabel_offset_y(const struct tileset *t)
Definition tilespec.c:919
static void tileset_setup_citizen_types(struct tileset *t, struct citizen_set *set, const char *tag_group, const char *set_name, bool required)
Definition tilespec.c:2994
static void tileset_setup_road(struct tileset *t, struct extra_type *pextra, const char *tag)
Definition tilespec.c:4007
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:6775
#define MATCH(dir)
static int get_irrigation_index(const struct tileset *t, struct extra_type *pextra, bv_extras *textras_near)
Definition tilespec.c:5014
#define MAX_INDEX_CARDINAL
Definition tilespec.c:108
void tileset_error(enum log_level level, const char *tset_name, const char *format,...)
Definition tilespec.c:624
const struct editor_sprites * get_editor_sprites(const struct tileset *t)
Definition tilespec.c:6950
int tileset_topo_index(struct tileset *t)
Definition tilespec.c:7563
bool tilespec_reread(const char *new_tileset_name, bool game_fully_initialized, float scale)
Definition tilespec.c:1355
spec_file_types
Definition tilespec.c:160
@ SFILE_COMMON
Definition tilespec.c:161
@ SFILE_PIXEL
Definition tilespec.c:163
@ SFILE_LAST
Definition tilespec.c:164
@ SFILE_SVG
Definition tilespec.c:162
void tileset_setup_nation_flag(struct tileset *t, struct nation_type *nation)
Definition tilespec.c:4435
void tileset_ruleset_reset(struct tileset *t)
Definition tilespec.c:7487
#define ADD_SPRITE_IF_NOT_NULL(x)
static void scan_specfile(struct tileset *t, struct specfile *sf, bool duplicates_ok)
Definition tilespec.c:1634
enum mapview_layer tileset_get_layer(const struct tileset *t, int n)
Definition tilespec.c:7320
#define NUM_EDGE_TILES
Definition tilespec.h:99
#define NUM_CURSOR_FRAMES
Definition tilespec.h:303
indicator_type
Definition tilespec.h:305
@ INDICATOR_COUNT
Definition tilespec.h:309
arrow_type
Definition tilespec.h:199
@ ARROW_LAST
Definition tilespec.h:203
@ ARROW_MINUS
Definition tilespec.h:202
@ ARROW_RIGHT
Definition tilespec.h:200
@ ARROW_PLUS
Definition tilespec.h:201
#define TS_TOPO_ISOHEX
Definition tilespec.h:455
#define TERRAIN_LAYER_COUNT
Definition tilespec.h:173
#define sprite_vector_iterate_end
Definition tilespec.h:46
#define NUM_CORNER_TILES
Definition tilespec.h:106
#define NUM_TILES_PROGRESS
Definition tilespec.h:195
#define MAX_NUM_CITIZEN_SPRITES
Definition tilespec.h:197
#define TS_TOPO_HEX
Definition tilespec.h:454
#define TS_TOPO_SQUARE
Definition tilespec.h:453
layer_category
Definition tilespec.h:189
@ LAYER_CATEGORY_TILE
Definition tilespec.h:191
@ LAYER_CATEGORY_CITY
Definition tilespec.h:190
@ LAYER_CATEGORY_UNIT
Definition tilespec.h:192
icon_type
Definition tilespec.h:312
@ ICON_COUNT
Definition tilespec.h:315
@ EDGE_UD
Definition tilespec.h:93
@ EDGE_LR
Definition tilespec.h:94
@ EDGE_COUNT
Definition tilespec.h:95
spaceship_part
Definition tilespec.h:318
@ SPACESHIP_COUNT
Definition tilespec.h:326
#define NUM_WALL_TYPES
Definition tilespec.h:359
#define sprite_vector_iterate(sprite_vec, psprite)
Definition tilespec.h:44
cursor_type
Definition tilespec.h:287
@ CURSOR_LAST
Definition tilespec.h:299
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2649
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2433
bool unit_has_orders(const struct unit *punit)
Definition unit.c:210
#define unit_tile(_pu)
Definition unit.h:397
#define BATTLEGROUP_NONE
Definition unit.h:190
#define unit_owner(_pu)
Definition unit.h:396
#define activity_type_iterate(_act_)
Definition unit.h:284
#define activity_type_iterate_end
Definition unit.h:289
#define MAX_NUM_BATTLEGROUPS
Definition unit.h:189
#define unit_list_iterate(unitlist, punit)
Definition unitlist.h:31
#define unit_list_iterate_end
Definition unitlist.h:33
const struct unit_type * unit_type_get(const struct unit *punit)
Definition unittype.c:123
const char * utype_rule_name(const struct unit_type *punittype)
Definition unittype.c:1578
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
#define utype_fuel(ptype)
Definition unittype.h:839
#define unit_type_iterate(_p)
Definition unittype.h:855
#define U_LAST
Definition unittype.h:40
#define unit_type_iterate_end
Definition unittype.h:862
#define worker_task_list_iterate(tasklist, ptask)
Definition workertask.h:33
#define worker_task_list_iterate_end
Definition workertask.h:35