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-tilespec-3.2-Devel-2022-Jun-21 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-spec-3.2-Devel-2023.Jan.01"
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
2794 if (tileset->scale == 1.0f) {
2795 sprite = create_sprite(128, 64, pcolor);
2796 } else {
2799 }
2800
2801 return sprite;
2802}
2803
2804/************************************************************************/
2808static void unload_sprite(struct tileset *t, const char *tag_name)
2809{
2810 struct small_sprite *ss;
2811
2814 fc_assert_ret(ss->ref_count >= 1);
2815 fc_assert_ret(ss->sprite);
2816
2817 ss->ref_count--;
2818
2819 if (ss->ref_count == 0) {
2820 /* Nobody's using the sprite anymore, so we should free it. We know
2821 * where to find it if we need it again. */
2822 log_debug("freeing sprite '%s'.", tag_name);
2823 free_sprite(ss->sprite);
2824 ss->sprite = NULL;
2825 }
2826}
2827
2828/************************************************************************/
2832static bool sprite_exists(const struct tileset *t, const char *tag_name)
2833{
2834 /* Lookup information about where the sprite is found. */
2836}
2837
2838/* Not very safe, but convenient: */
2839#define SET_SPRITE(field, tag) \
2840 do { \
2841 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2842 if (t->sprites.field == NULL) { \
2843 tileset_error(LOG_FATAL, tileset_name_get(t), \
2844 _("Sprite for tag '%s' missing."), tag); \
2845 } \
2846 } while (FALSE)
2847
2848
2849#define SET_SPRITE_NOTSMOOTH(field, tag) \
2850 do { \
2851 t->sprites.field = load_sprite(t, tag, TRUE, FALSE, FALSE); \
2852 if (t->sprites.field == NULL) { \
2853 tileset_error(LOG_FATAL, tileset_name_get(t), \
2854 _("Sprite for tag '%s' missing."), tag); \
2855 } \
2856 } while (FALSE)
2857
2858#define SET_SPRITE_UNSCALED(field, tag) \
2859 do { \
2860 t->sprites.field = load_sprite(t, tag, FALSE, FALSE, FALSE); \
2861 if (t->sprites.field == NULL) { \
2862 tileset_error(LOG_FATAL, tileset_name_get(t), \
2863 _("Sprite for tag '%s' missing."), tag); \
2864 } \
2865 } while (FALSE)
2866
2867/* Sets sprites.field to tag or (if tag isn't available) to alt */
2868#define SET_SPRITE_ALT(field, tag, alt) \
2869 do { \
2870 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2871 if (!t->sprites.field) { \
2872 t->sprites.field = load_sprite(t, alt, TRUE, TRUE, FALSE); \
2873 } \
2874 if (t->sprites.field == NULL) { \
2875 tileset_error(LOG_FATAL, tileset_name_get(t), \
2876 _("Sprite for tags '%s' and alternate '%s' are " \
2877 "both missing."), tag, alt); \
2878 } \
2879 } while (FALSE)
2880
2881/* Sets sprites.field to tag, or NULL if not available */
2882#define SET_SPRITE_OPT(field, tag) \
2883 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE)
2884
2885#define SET_SPRITE_ALT_OPT(field, tag, alt) \
2886 do { \
2887 t->sprites.field = tiles_lookup_sprite_tag_alt(t, LOG_VERBOSE, tag, alt, \
2888 NULL, "sprite", #field, \
2889 TRUE); \
2890 } while (FALSE)
2891
2892/************************************************************************/
2901
2902/************************************************************************/
2906 struct citizen_set *set,
2908 const char *tag_group,
2909 const char *set_name,
2910 bool required)
2911{
2912 /* Load the specialist sprite graphics. */
2913 char buffer[512];
2914 int j;
2915 struct specialist *spe = specialist_by_number(id);
2916 const char *tag = spe->graphic_str;
2917 const char *graphic_alt = spe->graphic_alt;
2918
2919 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
2920 /* Try tag name + index number */
2921 if (tag_group != NULL) {
2922 fc_snprintf(buffer, sizeof(buffer), "%s.%s_%d", tag_group, tag, j);
2923 } else {
2924 fc_snprintf(buffer, sizeof(buffer), "%s_%d", tag, j);
2925 }
2926 set->specialist[id].sprite[j] = load_sprite(t, buffer,
2927 FALSE, FALSE, FALSE);
2928
2929 /* Break if no more index specific sprites are defined */
2930 if (!set->specialist[id].sprite[j]) {
2931 break;
2932 }
2933 }
2934
2935 if (j == 0) {
2936 /* Try non-indexed */
2937 set->specialist[id].sprite[j] = load_sprite(t, tag,
2938 FALSE, FALSE, FALSE);
2939
2940 if (set->specialist[id].sprite[j]) {
2941 j = 1;
2942 }
2943 }
2944
2945 if (j == 0) {
2946 /* Try the alt tag */
2947 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
2948 /* Try alt tag name + index number */
2949 if (tag_group != NULL) {
2950 fc_snprintf(buffer, sizeof(buffer), "%s.%s_%d", tag_group, graphic_alt, j);
2951 } else {
2952 fc_snprintf(buffer, sizeof(buffer), "%s_%d", graphic_alt, j);
2953 }
2954 set->specialist[id].sprite[j] = load_sprite(t, buffer,
2955 FALSE, FALSE, FALSE);
2956
2957 /* Break if no more index specific sprites are defined */
2958 if (!set->specialist[id].sprite[j]) {
2959 break;
2960 }
2961 }
2962 }
2963
2964 if (j == 0) {
2965 /* Try alt tag non-indexed */
2967 FALSE, FALSE, FALSE);
2968
2969 if (set->specialist[id].sprite[j]) {
2970 j = 1;
2971 }
2972 }
2973
2974 set->specialist[id].count = j;
2975
2976 /* Still nothing? Give up. */
2977 if (j == 0 && required) {
2978 /* TRANS: First %s is a graphics tag of the specialist, second one
2979 * is a citizen set name; 'citizen_graphic' from styles.ruleset */
2981 _("No graphics for specialist \"%s\" in %s."),
2982 tag, set_name);
2983 }
2984}
2985
2986/************************************************************************/
2990{
2992 "default set", TRUE);
2993}
2994
2995/************************************************************************/
2999 struct citizen_set *set,
3000 const char *tag_group,
3001 const char *set_name,
3002 bool required)
3003{
3004 int i, j;
3005 char buffer[512];
3006
3007 /* Load the citizen sprite graphics, no specialist. */
3008 for (i = 0; i < CITIZEN_LAST; i++) {
3009 const char *name = citizen_rule_name(i);
3010
3011 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
3012 if (tag_group != NULL) {
3013 fc_snprintf(buffer, sizeof(buffer), "citizen.%s.%s_%d", tag_group, name, j);
3014 } else {
3015 fc_snprintf(buffer, sizeof(buffer), "citizen.%s_%d", name, j);
3016 }
3017 set->citizen[i].sprite[j] = load_sprite(t, buffer, FALSE, FALSE, FALSE);
3018 if (!set->citizen[i].sprite[j]) {
3019 break;
3020 }
3021 }
3022 set->citizen[i].count = j;
3023 if (j == 0 && required) {
3024 /* TRANS: First %s is type of the citizen ("happy" ... "angry"), second one
3025 * is a citizen set name; 'citizen_graphic' from styles.ruleset */
3027 _("No graphics for citizen \"%s\" in %s."),
3028 name, set_name);
3029 }
3030 }
3031}
3032
3033/************************************************************************/
3039static struct sprite *get_city_sprite(const struct city_sprite *city_sprite,
3040 const struct city *pcity)
3041{
3042 /* Get style and match the best tile based on city size */
3043 int style = style_of_city(pcity);
3044 int num_thresholds;
3046 int img_index;
3047
3049
3052
3053 if (num_thresholds == 0) {
3054 return NULL;
3055 }
3056
3057 /* Get the sprite with the index defined by the effects. */
3058 img_index = pcity->client.city_image;
3059 if (img_index == -100) {
3060 /* Server doesn't know right value as this is from old savegame.
3061 * Guess here based on *client* side information as was done in
3062 * versions where information was not saved to savegame - this should
3063 * give us right answer of what city looked like by the time it was
3064 * put under FoW. */
3066 }
3068
3069 return thresholds[img_index].sprite;
3070}
3071
3072/************************************************************************/
3075static int load_city_thresholds_sprites(struct tileset *t, const char *tag,
3076 char *graphic, char *graphic_alt,
3078{
3079 char buffer[128];
3080 char *gfx_in_use = graphic;
3081 int num_thresholds = 0;
3082 struct sprite *sprite;
3083 int size;
3084
3085 *thresholds = NULL;
3086
3087 for (size = 0; size < MAX_CITY_SIZE; size++) {
3088 fc_snprintf(buffer, sizeof(buffer), "%s_%s_%d",
3089 gfx_in_use, tag, size);
3090 if ((sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE))) {
3093 (*thresholds)[num_thresholds - 1].sprite = sprite;
3094 } else if (size == 0) {
3095 if (gfx_in_use == graphic) {
3096 /* Try again with graphic_alt. */
3097 size--;
3098 gfx_in_use = graphic_alt;
3099 } else {
3100 /* Don't load any others if the 0 element isn't there. */
3101 break;
3102 }
3103 }
3104 }
3105
3106 return num_thresholds;
3107}
3108
3109/************************************************************************/
3116static struct city_sprite *load_city_sprite(struct tileset *t,
3117 const char *tag)
3118{
3119 struct city_sprite *city_sprite = fc_malloc(sizeof(*city_sprite));
3120 int style;
3121
3122 /* Store number of styles we have allocated memory for.
3123 * game.control.num_city_styles might change if client disconnects from
3124 * server and connects new one. */
3127 * sizeof(*city_sprite->styles));
3128
3129 for (style = 0; style < city_sprite->num_styles; style++) {
3131 load_city_thresholds_sprites(t, tag, city_styles[style].graphic,
3132 city_styles[style].graphic_alt,
3134 }
3135
3136 return city_sprite;
3137}
3138
3139/************************************************************************/
3145{
3146 int style;
3147
3148 if (!city_sprite) {
3149 return;
3150 }
3151 for (style = 0; style < city_sprite->num_styles; style++) {
3152 if (city_sprite->styles[style].land_thresholds) {
3154 }
3155 }
3158}
3159
3160/************************************************************************/
3165{
3166 char buffer[512], buffer2[512];
3167 const int W = t->normal_tile_width, H = t->normal_tile_height;
3168 int i, j, f;
3169
3171
3172 SET_SPRITE_UNSCALED(treaty_thumb[0], "treaty.disagree_thumb_down");
3173 SET_SPRITE_UNSCALED(treaty_thumb[1], "treaty.agree_thumb_up");
3174
3175 for (j = 0; j < INDICATOR_COUNT; j++) {
3176 const char *names[] = {"science_bulb", "warming_sun", "cooling_flake"};
3177
3178 for (i = 0; i < NUM_TILES_PROGRESS; i++) {
3179 fc_snprintf(buffer, sizeof(buffer), "s.%s_%d", names[j], i);
3180 SET_SPRITE_UNSCALED(indicator[j][i], buffer);
3181 }
3182 }
3183
3184 SET_SPRITE(arrow[ARROW_RIGHT], "s.right_arrow");
3185 SET_SPRITE(arrow[ARROW_PLUS], "s.plus");
3186 SET_SPRITE(arrow[ARROW_MINUS], "s.minus");
3187 if (t->type == TS_ISOMETRIC) {
3188 SET_SPRITE(dither_tile, "t.dither_tile");
3189 }
3190
3192 SET_SPRITE_NOTSMOOTH(mask.tile, "mask.tile");
3193 } else {
3194 SET_SPRITE(mask.tile, "mask.tile");
3195 }
3196 SET_SPRITE(mask.worked_tile, "mask.worked_tile");
3197 SET_SPRITE(mask.unworked_tile, "mask.unworked_tile");
3198
3199 SET_SPRITE_UNSCALED(tax_luxury, "s.tax_luxury");
3200 SET_SPRITE_UNSCALED(tax_science, "s.tax_science");
3201 SET_SPRITE_UNSCALED(tax_gold, "s.tax_gold");
3202
3204
3205 for (i = 0; i < SPACESHIP_COUNT; i++) {
3206 const char *names[SPACESHIP_COUNT]
3207 = {"solar_panels", "life_support", "habitation",
3208 "structural", "fuel", "propulsion", "exhaust"};
3209
3210 fc_snprintf(buffer, sizeof(buffer), "spaceship.%s", names[i]);
3211 SET_SPRITE(spaceship[i], buffer);
3212 }
3213
3214 for (i = 0; i < CURSOR_LAST; i++) {
3215 const char *names[CURSOR_LAST] =
3216 {"goto", "patrol", "paradrop", "teleport", "nuke", "select",
3217 "invalid", "attack", "edit_paint", "edit_add", "wait"};
3218
3219 for (f = 0; f < NUM_CURSOR_FRAMES; f++) {
3220 struct small_sprite *ss;
3221
3222 fc_assert(ARRAY_SIZE(names) == CURSOR_LAST);
3223 fc_snprintf(buffer, sizeof(buffer), "cursor.%s%d", names[i], f);
3224 SET_SPRITE(cursor[i].frame[f], buffer);
3225
3226 if (sprite_hash_lookup(t->sprite_hash, buffer, &ss)) {
3227 t->sprites.cursor[i].hot_x = ss->hot_x;
3228 t->sprites.cursor[i].hot_y = ss->hot_y;
3229 }
3230 }
3231 }
3232
3233 for (i = 0; i < ICON_COUNT; i++) {
3234 const char *names[ICON_COUNT] = {"freeciv", "citydlg"};
3235
3236 fc_snprintf(buffer, sizeof(buffer), "icon.%s", names[i]);
3237 SET_SPRITE(icon[i], buffer);
3238 }
3239
3240 for (i = 0; i < E_COUNT; i++) {
3241 const char *tag = get_event_tag(i);
3242
3243 SET_SPRITE(events[i], tag);
3244 }
3245
3246 SET_SPRITE(explode.nuke, "explode.nuke");
3247
3249 for (i = 0; ; i++) {
3250 struct sprite *sprite;
3251
3252 fc_snprintf(buffer, sizeof(buffer), "explode.unit_%d", i);
3253 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3254 if (!sprite) {
3255 break;
3256 }
3258 }
3259
3260 SET_SPRITE(unit.auto_attack, "unit.auto_attack");
3261 SET_SPRITE(unit.auto_settler, "unit.auto_settler");
3262 SET_SPRITE(unit.auto_explore, "unit.auto_explore");
3263 SET_SPRITE(unit.fortified, "unit.fortified");
3264 SET_SPRITE(unit.fortifying, "unit.fortifying");
3265 SET_SPRITE(unit.go_to, "unit.goto");
3266 SET_SPRITE(unit.cultivate, "unit.cultivate");
3267 SET_SPRITE(unit.plant, "unit.plant");
3268 SET_SPRITE(unit.pillage, "unit.pillage");
3269 SET_SPRITE(unit.sentry, "unit.sentry");
3270 SET_SPRITE(unit.convert, "unit.convert");
3271 t->sprites.unit.stack = fc_malloc(sizeof(struct sprite *));
3272 t->sprites.unit.num_stack_sprites = 1;
3273 SET_SPRITE(unit.stack[0], "unit.stack");
3274 t->sprites.unit.no_more_stack_sprites = FALSE;
3275 SET_SPRITE(unit.loaded, "unit.loaded");
3276 SET_SPRITE(unit.transform, "unit.transform");
3277 SET_SPRITE(unit.connect, "unit.connect");
3278 SET_SPRITE(unit.patrol, "unit.patrol");
3279 for (i = 0; i < MAX_NUM_BATTLEGROUPS; i++) {
3280 fc_snprintf(buffer, sizeof(buffer), "unit.battlegroup_%d", i);
3281 fc_snprintf(buffer2, sizeof(buffer2), "city.size_%d", i + 1);
3284 }
3285 SET_SPRITE(unit.lowfuel, "unit.lowfuel");
3286 SET_SPRITE(unit.tired, "unit.tired");
3287
3288 SET_SPRITE_OPT(unit.action_decision_want, "unit.action_decision_want");
3289
3290 for (i = 0; i < NUM_TILES_HP_BAR; i++) {
3291 fc_snprintf(buffer, sizeof(buffer), "unit.hp_%d", i*10);
3292 SET_SPRITE(unit.hp_bar[i], buffer);
3293 }
3294
3295 for (i = 0; i < MAX_VET_LEVELS; i++) {
3296 /* Veteran level sprites are optional. For instance "green" units
3297 * usually have no special graphic. */
3298 fc_snprintf(buffer, sizeof(buffer), "unit.vet_%d", i);
3299 t->sprites.unit.vet_lev[i] = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3300 }
3301
3302 t->sprites.unit.select[0] = NULL;
3303 if (sprite_exists(t, "unit.select0")) {
3304 for (i = 0; i < NUM_TILES_SELECT; i++) {
3305 fc_snprintf(buffer, sizeof(buffer), "unit.select%d", i);
3306 SET_SPRITE(unit.select[i], buffer);
3307 }
3308 }
3309
3310 SET_SPRITE(citybar.shields, "citybar.shields");
3311 SET_SPRITE(citybar.food, "citybar.food");
3312 SET_SPRITE(citybar.trade, "citybar.trade");
3313 SET_SPRITE(citybar.occupied, "citybar.occupied");
3314 SET_SPRITE(citybar.background, "citybar.background");
3316 for (i = 0; ; i++) {
3317 struct sprite *sprite;
3318
3319 fc_snprintf(buffer, sizeof(buffer), "citybar.occupancy_%d", i);
3320 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3321 if (!sprite) {
3322 break;
3323 }
3325 }
3326 if (t->sprites.citybar.occupancy.size < 2) {
3328 _("Missing necessary citybar.occupancy_N sprites."));
3329 }
3330
3331#define SET_EDITOR_SPRITE(x) SET_SPRITE(editor.x, "editor." #x)
3332 SET_EDITOR_SPRITE(erase);
3333 SET_EDITOR_SPRITE(brush);
3334 SET_EDITOR_SPRITE(copy);
3335 SET_EDITOR_SPRITE(paste);
3336 SET_EDITOR_SPRITE(copypaste);
3339 SET_EDITOR_SPRITE(terrain_resource);
3340 SET_EDITOR_SPRITE(terrain_special);
3344 SET_EDITOR_SPRITE(territory);
3345 SET_EDITOR_SPRITE(properties);
3347 SET_EDITOR_SPRITE(military_base);
3348#undef SET_EDITOR_SPRITE
3349
3350 SET_SPRITE(city.disorder, "city.disorder");
3351
3352 /* Fallbacks for goto path turn numbers:
3353 * path.step_%d, path.exhausted_mp_%d
3354 * --> path.turns_%d
3355 * --> city.size_%d */
3356#define SET_GOTO_TURN_SPRITE(state, state_name, factor, factor_name) \
3357 fc_snprintf(buffer, sizeof(buffer), "path." state_name "_%d" #factor, i); \
3358 SET_SPRITE_OPT(path.s[state].turns ## factor_name [i], buffer); \
3359 if (t->sprites.path.s[state].turns ## factor_name [i] == NULL) { \
3360 t->sprites.path.s[state].turns ## factor_name [i] = \
3361 t->sprites.path.s[GTS_MP_LEFT].turns ## factor_name [i]; \
3362 }
3363
3364 for (i = 0; i < NUM_TILES_DIGITS; i++) {
3365 fc_snprintf(buffer, sizeof(buffer), "city.size_%d", i);
3366 SET_SPRITE(city.size[i], buffer);
3367 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d", i);
3368 SET_SPRITE_ALT(path.s[GTS_MP_LEFT].turns[i], buffer2, buffer);
3370 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp",,);
3371
3372 fc_snprintf(buffer, sizeof(buffer), "city.size_%d0", i);
3373 SET_SPRITE(city.size_tens[i], buffer);
3374 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d0", i);
3375 SET_SPRITE_ALT(path.s[GTS_MP_LEFT].turns_tens[i], buffer2, buffer);
3377 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp", 0, _tens);
3378
3379 fc_snprintf(buffer, sizeof(buffer), "city.size_%d00", i);
3380 SET_SPRITE_OPT(city.size_hundreds[i], buffer);
3381 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d00", i);
3382 SET_SPRITE_ALT_OPT(path.s[GTS_MP_LEFT].turns_hundreds[i], buffer2,
3383 buffer);
3385 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp", 00, _hundreds);
3386
3387 fc_snprintf(buffer, sizeof(buffer), "city.t_food_%d", i);
3388 SET_SPRITE(city.tile_foodnum[i], buffer);
3389 fc_snprintf(buffer, sizeof(buffer), "city.t_shields_%d", i);
3390 SET_SPRITE(city.tile_shieldnum[i], buffer);
3391 fc_snprintf(buffer, sizeof(buffer), "city.t_trade_%d", i);
3392 SET_SPRITE(city.tile_tradenum[i], buffer);
3393 }
3394#undef SET_GOTO_TURN_SPRITE
3395
3396 /* Must have at least one upkeep sprite per output type (and unhappy) */
3397 /* The rest are optional; we copy the previous sprite for unspecified ones */
3398 fc_strlcpy(buffer, "upkeep.unhappy", sizeof(buffer));
3399 SET_SPRITE(upkeep.unhappy[0], buffer);
3400 for (i = 1; i < MAX_NUM_UPKEEP_SPRITES; i++) {
3401 fc_snprintf(buffer2, sizeof(buffer2), "upkeep.unhappy%d", i+1);
3402 if (sprite_exists(t, buffer2)) {
3403 SET_SPRITE(upkeep.unhappy[i], buffer2);
3404 fc_strlcpy(buffer, buffer2, sizeof(buffer));
3405 } else {
3406 SET_SPRITE(upkeep.unhappy[i], buffer);
3407 }
3408 }
3410 fc_snprintf(buffer, sizeof(buffer),
3411 "upkeep.%s", get_output_identifier(o));
3412 SET_SPRITE_OPT(upkeep.output[o][0], buffer);
3413 for (i = 1; i < MAX_NUM_UPKEEP_SPRITES; i++) {
3414 fc_snprintf(buffer2, sizeof(buffer2),
3415 "upkeep.%s%d", get_output_identifier(o), i+1);
3416 if (sprite_exists(t, buffer2)) {
3417 SET_SPRITE(upkeep.output[o][i], buffer2);
3418 fc_strlcpy(buffer, buffer2, sizeof(buffer));
3419 } else {
3420 /* Optional, as maybe the upkeep 1 sprite didn't exist either */
3421 SET_SPRITE_OPT(upkeep.output[o][i], buffer);
3422 }
3423 }
3425
3427
3428 SET_SPRITE(user.attention, "user.attention");
3429 SET_SPRITE(user.infratile, "user.infratile");
3430
3431 SET_SPRITE_OPT(path.s[GTS_MP_LEFT].specific, "path.normal");
3432 SET_SPRITE_OPT(path.s[GTS_EXHAUSTED_MP].specific, "path.exhausted_mp");
3433 SET_SPRITE_OPT(path.s[GTS_TURN_STEP].specific, "path.step");
3434 SET_SPRITE(path.waypoint, "path.waypoint");
3435
3436 SET_SPRITE_NOTSMOOTH(tx.fog, "tx.fog");
3437
3439 for (i = 0; ; i++) {
3440 struct sprite *sprite;
3441
3442 fc_snprintf(buffer, sizeof(buffer), "colors.overlay_%d", i);
3443 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3444 if (!sprite) {
3445 break;
3446 }
3448 }
3449 if (i == 0) {
3451 _("Missing overlay-color sprite colors.overlay_0."));
3452 }
3453
3454 /* Chop up and build the overlay graphics. */
3459 for (i = 0; i < sprite_vector_size(&t->sprites.colors.overlays); i++) {
3460 struct sprite *color, *color_mask;
3461 struct sprite *worked, *unworked;
3462
3464 color_mask = crop_sprite(color, 0, 0, W, H, t->sprites.mask.tile, 0, 0,
3465 1.0f, FALSE);
3466 worked = crop_sprite(color_mask, 0, 0, W, H,
3467 t->sprites.mask.worked_tile, 0, 0, 1.0f, FALSE);
3468 unworked = crop_sprite(color_mask, 0, 0, W, H,
3469 t->sprites.mask.unworked_tile, 0, 0, 1.0f, FALSE);
3471 t->sprites.city.worked_tile_overlay.p[i] = worked;
3473 }
3474
3475
3476 {
3477 SET_SPRITE(grid.unavailable, "grid.unavailable");
3478 SET_SPRITE_OPT(grid.nonnative, "grid.nonnative");
3479
3480 for (i = 0; i < EDGE_COUNT; i++) {
3481 int be;
3482
3483 if (i == EDGE_UD && t->hex_width == 0) {
3484 continue;
3485 } else if (i == EDGE_LR && t->hex_height == 0) {
3486 continue;
3487 }
3488
3489 fc_snprintf(buffer, sizeof(buffer), "grid.main.%s", edge_name[i]);
3490 SET_SPRITE(grid.main[i], buffer);
3491
3492 fc_snprintf(buffer, sizeof(buffer), "grid.city.%s", edge_name[i]);
3493 SET_SPRITE(grid.city[i], buffer);
3494
3495 fc_snprintf(buffer, sizeof(buffer), "grid.worked.%s", edge_name[i]);
3496 SET_SPRITE(grid.worked[i], buffer);
3497
3498 fc_snprintf(buffer, sizeof(buffer), "grid.selected.%s", edge_name[i]);
3499 SET_SPRITE(grid.selected[i], buffer);
3500
3501 fc_snprintf(buffer, sizeof(buffer), "grid.coastline.%s", edge_name[i]);
3502 SET_SPRITE(grid.coastline[i], buffer);
3503
3504 for (be = 0; be < 2; be++) {
3505 fc_snprintf(buffer, sizeof(buffer), "grid.borders.%c",
3506 edge_name[i][be]);
3507 SET_SPRITE(grid.borders[i][be], buffer);
3508 }
3509 }
3510 }
3511
3512 switch (t->darkness_style) {
3513 case DARKNESS_NONE:
3514 /* Nothing. */
3515 break;
3516 case DARKNESS_ISORECT:
3517 {
3518 /* Isometric: take a single tx.darkness tile and split it into 4. */
3519 struct sprite *darkness = load_sprite(t, "tx.darkness",
3520 TRUE, FALSE, FALSE);
3521 const int ntw = t->normal_tile_width, nth = t->normal_tile_height;
3522 int offsets[4][2] = {{ntw / 2, 0}, {0, nth / 2}, {ntw / 2, nth / 2}, {0, 0}};
3523
3524 if (!darkness) {
3526 _("Sprite tx.darkness missing."));
3527 }
3528 for (i = 0; i < 4; i++) {
3529 t->sprites.tx.darkness[i] = crop_sprite(darkness, offsets[i][0],
3530 offsets[i][1], ntw / 2,
3531 nth / 2, NULL, 0, 0, 1.0f,
3532 FALSE);
3533 }
3534 }
3535 break;
3537 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
3538 enum direction8 dir = t->cardinal_tileset_dirs[i];
3539
3540 fc_snprintf(buffer, sizeof(buffer), "tx.darkness_%s",
3542 SET_SPRITE_NOTSMOOTH(tx.darkness[i], buffer);
3543 }
3544 break;
3545 case DARKNESS_CARD_FULL:
3546 for (i = 1; i < t->num_index_cardinal; i++) {
3547 fc_snprintf(buffer, sizeof(buffer), "tx.darkness_%s",
3548 cardinal_index_str(t, i));
3549 SET_SPRITE_NOTSMOOTH(tx.darkness[i], buffer);
3550 }
3551 break;
3552 case DARKNESS_CORNER:
3554 81 * sizeof(*t->sprites.tx.fullfog));
3555 for (i = 0; i < 81; i++) {
3556 /* Unknown, fog, known. */
3557 char ids[] = {'u', 'f', 'k'};
3558 char buf[512] = "t.fog";
3559 int values[4], vi, k = i;
3560
3561 for (vi = 0; vi < 4; vi++) {
3562 values[vi] = k % 3;
3563 k /= 3;
3564
3565 cat_snprintf(buf, sizeof(buf), "_%c", ids[values[vi]]);
3566 }
3567 fc_assert(k == 0);
3568
3570 }
3571 break;
3572 };
3573
3574 /* no other place to initialize these variables */
3577}
3578
3579/************************************************************************/
3582static bool load_river_sprites(struct tileset *t,
3583 struct river_sprites *store, const char *tag_pfx)
3584{
3585 int i;
3586 char buffer[512];
3587
3588 for (i = 0; i < t->num_index_cardinal; i++) {
3589 fc_snprintf(buffer, sizeof(buffer), "%s_s_%s",
3591 store->spec[i] = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3592 if (store->spec[i] == NULL) {
3593 return FALSE;
3594 }
3595 }
3596
3597 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
3598 fc_snprintf(buffer, sizeof(buffer), "%s_outlet_%s",
3600 store->outlet[i] = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3601 if (store->outlet[i] == NULL) {
3602 log_error("Missing \"%s\" for \"%s\".", buffer, tag_pfx);
3603 return FALSE;
3604 }
3605 }
3606
3607 return TRUE;
3608}
3609
3610/************************************************************************/
3617{
3619 if (sf->big_sprite) {
3620 free_sprite(sf->big_sprite);
3621 sf->big_sprite = NULL;
3622 }
3624}
3625
3626/************************************************************************/
3637
3638/************************************************************************/
3644 enum log_level level,
3645 const char *tag, const char *alt,
3646 const char *alt2,
3647 const char *what, const char *name,
3648 bool scale)
3649{
3650 struct sprite *sp;
3651
3652 /* (Should get sprite_hash before connection) */
3654 "attempt to lookup for %s \"%s\" before "
3655 "sprite_hash setup", what, name);
3656
3657 sp = load_sprite(t, tag, scale, TRUE, FALSE);
3658 if (sp) return sp;
3659
3660 sp = load_sprite(t, alt, scale, TRUE, FALSE);
3661 if (sp) {
3662 log_verbose("Using alternate graphic \"%s\" "
3663 "(instead of \"%s\") for %s \"%s\".",
3664 alt, tag, what, name);
3665 return sp;
3666 }
3667
3668 if (alt2 != NULL) {
3669 sp = load_sprite(t, alt2, scale, TRUE, FALSE);
3670 if (sp) {
3671 log_verbose("Using second alternate graphic \"%s\" "
3672 "(instead of \"%s\" or \"%s\") for %s \"%s\".",
3673 alt2, tag, alt, what, name);
3674 return sp;
3675 }
3676 }
3677
3679 _("Don't have graphics tags \"%s\" or \"%s\" for %s \"%s\"."),
3680 tag, alt, what, name);
3681
3682 return NULL;
3683}
3684
3685/************************************************************************/
3690 int uidx,
3691 const char *base_str,
3692 enum direction8 dir,
3693 enum unit_activity activity,
3694 bool has_icon)
3695{
3696 enum direction8 loaddir = dir;
3697 char buf[2048];
3698 const char *act_name = unit_activity_name(activity);
3699
3700 if (act_name == NULL) {
3701 /* gcc-9 thinks this is possible. */
3702 return FALSE;
3703 }
3704
3705 /*
3706 * There may be more orientations available in this tileset than are
3707 * needed, if an oriented unit set has been reused between tilesets.
3708 *
3709 * Don't bother loading unused ones, unless they might be used by
3710 * unit_default_orientation (logic here mirrors get_unittype_sprite()).
3711 */
3712 if (!(dir == t->unit_default_orientation && !has_icon)
3713 && !is_valid_tileset_dir(t, dir)) {
3714 /* Instead we copy a nearby valid dir's sprite, so we're not caught
3715 * out in case this tileset is used with an incompatible topology,
3716 * although it'll be ugly. */
3717 do {
3719 /* This loop _should_ terminate... */
3721 } while (!is_valid_tileset_dir(t, loaddir));
3722 }
3723
3724 fc_snprintf(buf, sizeof(buf), "%s_%s_%s", base_str,
3726
3727 /* We don't use _alt graphics here, as that could lead to loading
3728 * real icon gfx, but alternative orientation gfx. Tileset author
3729 * probably meant icon gfx to be used as fallback for all orientations */
3730 t->sprites.units.facing[uidx][dir][activity] = load_sprite(t, buf,
3731 TRUE, TRUE, FALSE);
3732
3733 if (activity == ACTIVITY_IDLE
3734 && t->sprites.units.facing[uidx][dir][activity] == NULL) {
3735 /* Backward compatibility: Set Idle sprite from tag with no activity defined. */
3736 fc_snprintf(buf, sizeof(buf), "%s_%s", base_str,
3738
3739 t->sprites.units.facing[uidx][dir][activity] = load_sprite(t, buf,
3740 TRUE, TRUE, FALSE);
3741 }
3742
3743 if (t->sprites.units.facing[uidx][dir][activity] != NULL) {
3744 return TRUE;
3745 }
3746
3747 return FALSE;
3748}
3749
3750/************************************************************************/
3754 int uidx,
3755 const char *tag)
3756{
3758
3759 activity_type_iterate(activity) {
3760 char buffer[2048];
3761
3762 fc_snprintf(buffer, sizeof(buffer), "%s_%s",
3763 tag, unit_activity_name(activity));
3764 t->sprites.units.icon[uidx][activity] = load_sprite(t, buffer,
3765 TRUE, TRUE, FALSE);
3766
3767 if (activity == ACTIVITY_IDLE
3768 && t->sprites.units.icon[uidx][activity] == NULL) {
3769 /* Backward compatibility: Set Idle sprite from tag with no activity defined. */
3770 t->sprites.units.icon[uidx][activity] = load_sprite(t, tag,
3771 TRUE, TRUE, FALSE);
3772 }
3774
3776
3777#define LOAD_FACING_SPRITE(dir) \
3778 if (!tileset_setup_unit_direction(t, uidx, tag, dir, activity, has_icon)) { \
3779 facing_sprites[activity] = FALSE; \
3780 }
3781
3782 activity_type_iterate(activity) {
3783 facing_sprites[activity] = TRUE;
3784
3793
3795
3797 /* Neither icon gfx or orientation sprites */
3798 return FALSE;
3799 }
3800
3801 return TRUE;
3802
3803#undef LOAD_FACING_SPRITE
3804}
3805
3806/************************************************************************/
3811{
3812 int uidx = utype_index(ut);
3813
3814 if (!tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_str)
3815 && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt)
3816 && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt2)) {
3818 _("Missing %s unit sprite for tags \"%s\" and alternatives "
3819 "\"%s\" and \"%s\"."),
3820 utype_rule_name(ut), ut->graphic_str,
3821 ut->graphic_alt, ut->graphic_alt2);
3822 }
3823
3824 if (!t->sprites.units.icon[uidx][ACTIVITY_IDLE]) {
3827 _("Unit type %s has no unoriented sprite and "
3828 "tileset has no unit_default_orientation."),
3830 } else {
3831 /* We're guaranteed to have an oriented sprite corresponding to
3832 * unit_default_orientation, because tileset_setup_unit_type_from_tag()
3833 * checked for this. */
3835 != NULL);
3836 }
3837 }
3838}
3839
3840/************************************************************************/
3845 struct impr_type *pimprove)
3846{
3847 t->sprites.building[improvement_index(pimprove)]
3849 pimprove->graphic_alt, pimprove->graphic_alt2,
3850 "improvement",
3851 improvement_rule_name(pimprove), FALSE);
3852
3853 /* Should maybe do something if NULL, eg generic default? */
3854}
3855
3856/************************************************************************/
3861 struct advance *padvance)
3862{
3863 if (valid_advance(padvance)) {
3866 padvance->graphic_alt, NULL, "technology",
3868
3869 /* Should maybe do something if NULL, eg generic default? */
3870 } else {
3872 }
3873}
3874
3875/************************************************************************/
3880 struct extra_type *pextra)
3881{
3882 const int id = extra_index(pextra);
3883 enum extrastyle_id extrastyle;
3884
3885 if (!fc_strcasecmp(pextra->graphic_str, "none")) {
3886 /* Extra without graphics */
3888 } else {
3889 const char *tag;
3890
3891 tag = pextra->graphic_str;
3892 if (!estyle_hash_lookup(t->estyle_hash, tag, &extrastyle)) {
3893 tag = pextra->graphic_alt;
3894 if (!estyle_hash_lookup(t->estyle_hash, tag, &extrastyle)) {
3896 _("No extra style for \"%s\" or \"%s\"."),
3897 pextra->graphic_str,
3898 pextra->graphic_alt);
3899 } else {
3900 log_verbose("Using alternate graphic \"%s\" "
3901 "(instead of \"%s\") for extra \"%s\".",
3902 pextra->graphic_alt, pextra->graphic_str,
3903 extra_rule_name(pextra));
3904 }
3905 }
3906
3907 t->sprites.extras[id].extrastyle = extrastyle;
3908
3909 extra_type_list_append(t->style_lists[extrastyle], pextra);
3910
3911 if (extra_has_flag(pextra, EF_SHOW_FLAG)) {
3913 }
3914
3915 switch (extrastyle) {
3916 case ESTYLE_3LAYER:
3917 tileset_setup_base(t, pextra, tag);
3918 break;
3919
3923 case ESTYLE_RIVER:
3924 tileset_setup_road(t, pextra, tag);
3925 break;
3926
3927 case ESTYLE_SINGLE1:
3928 case ESTYLE_SINGLE2:
3929 SET_SPRITE(extras[id].u.single, tag);
3930 break;
3931
3932 case ESTYLE_CARDINALS:
3933 {
3934 int i;
3935 char buffer[512];
3936
3937 /* We use direction-specific irrigation and farmland graphics, if they
3938 * are available. If not, we just fall back to the basic irrigation
3939 * graphics. */
3940 for (i = 0; i < t->num_index_cardinal; i++) {
3941 fc_snprintf(buffer, sizeof(buffer), "%s_%s",
3942 tag, cardinal_index_str(t, i));
3943 t->sprites.extras[id].u.cardinals[i] = load_sprite(t, buffer,
3944 TRUE, TRUE, FALSE);
3945 if (!t->sprites.extras[id].u.cardinals[i]) {
3946 t->sprites.extras[id].u.cardinals[i] = load_sprite(t, tag,
3947 TRUE, TRUE, FALSE);
3948 }
3949 if (!t->sprites.extras[id].u.cardinals[i]) {
3951 _("No cardinal-style graphics \"%s*\" for "
3952 "extra \"%s\""),
3953 tag, extra_rule_name(pextra));
3954 }
3955 }
3956 }
3957 break;
3958 case ESTYLE_COUNT:
3959 break;
3960 }
3961 }
3962
3963 if (!fc_strcasecmp(pextra->activity_gfx, "none")) {
3965 } else {
3967 TRUE, TRUE, FALSE);
3968 if (t->sprites.extras[id].activity == NULL) {
3970 TRUE, TRUE, FALSE);
3971 }
3972 if (t->sprites.extras[id].activity == NULL) {
3974 TRUE, TRUE, FALSE);
3975 }
3976 if (t->sprites.extras[id].activity == NULL) {
3978 _("Missing %s building activity sprite for tags \"%s\" and alternatives \"%s\" and \"%s\"."),
3979 extra_rule_name(pextra), pextra->activity_gfx,
3980 pextra->act_gfx_alt, pextra->act_gfx_alt2);
3981 }
3982 }
3983
3984 if (!fc_strcasecmp(pextra->rmact_gfx, "none")) {
3985 t->sprites.extras[id].rmact = NULL;
3986 } else {
3987 t->sprites.extras[id].rmact = load_sprite(t, pextra->rmact_gfx,
3988 TRUE, TRUE, FALSE);
3989 if (t->sprites.extras[id].rmact == NULL) {
3991 TRUE, TRUE, FALSE);
3992 if (t->sprites.extras[id].rmact == NULL) {
3994 TRUE, TRUE, FALSE);
3995 if (t->sprites.extras[id].rmact == NULL) {
3997 _("Missing %s removal activity sprite for tags \"%s\" "
3998 "and alternatives \"%s\" and \"%s\"."),
3999 extra_rule_name(pextra), pextra->rmact_gfx,
4000 pextra->rmact_gfx_alt, pextra->rmact_gfx_alt2);
4001 }
4002 }
4003 }
4004 }
4005}
4006
4007/************************************************************************/
4011static void tileset_setup_road(struct tileset *t,
4012 struct extra_type *pextra,
4013 const char *tag)
4014{
4015 char full_tag_name[MAX_LEN_NAME + strlen("_isolated")];
4016 const int id = extra_index(pextra);
4017 int i;
4018 enum extrastyle_id extrastyle = t->sprites.extras[id].extrastyle;
4019
4020 /* Isolated road graphics are used by ESTYLE_ROAD_ALL_SEPARATE and
4021 ESTYLE_ROAD_PARITY_COMBINED. */
4022 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4023 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4025 "%s_isolated", tag);
4026
4027 SET_SPRITE(extras[id].u.road.isolated, full_tag_name);
4028 }
4029
4030 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
4031 /* ESTYLE_ROAD_ALL_SEPARATE has just 8 additional sprites for each
4032 * road type: one going off in each direction. */
4033 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4034 enum direction8 dir = t->valid_tileset_dirs[i];
4035 const char *dir_name = dir_get_tileset_name(dir);
4036
4038 "%s_%s", tag, dir_name);
4039
4040 SET_SPRITE(extras[id].u.road.ru.dir[i], full_tag_name);
4041 }
4042 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4043 int num_index = 1 << (t->num_valid_tileset_dirs / 2), j;
4044
4045 /* ESTYLE_ROAD_PARITY_COMBINED has 32 additional sprites for each road
4046 * type: 16 each for cardinal and diagonal directions. Each set
4047 * of 16 provides a NSEW-indexed sprite to provide connectors for
4048 * all rails in the cardinal/diagonal directions. The 0 entry is
4049 * unused (the "isolated" sprite is used instead). */
4050
4051 for (i = 1; i < num_index; i++) {
4052 char c[64] = "", d[64] = "";
4053
4054 for (j = 0; j < t->num_valid_tileset_dirs / 2; j++) {
4055 int value = (i >> j) & 1;
4056
4057 cat_snprintf(c, sizeof(c), "%s%d",
4059 value);
4060 cat_snprintf(d, sizeof(d), "%s%d",
4062 value);
4063 }
4064
4066 "%s_c_%s", tag, c);
4067
4068 SET_SPRITE(extras[id].u.road.ru.combo.even[i], full_tag_name);
4069
4071 "%s_d_%s", tag, d);
4072
4073 SET_SPRITE(extras[id].u.road.ru.combo.odd[i], full_tag_name);
4074 }
4075 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
4076 /* ESTYLE_ROAD_ALL_COMBINED includes 256 sprites, one for every possibility.
4077 * Just go around clockwise, with all combinations. */
4078 for (i = 0; i < t->num_index_valid; i++) {
4079 char *idx_str = valid_index_str(t, i);
4080
4082 "%s_%s", tag, idx_str);
4083
4084 SET_SPRITE(extras[id].u.road.ru.total[i], full_tag_name);
4085 }
4086 } else if (extrastyle == ESTYLE_RIVER) {
4087 if (!load_river_sprites(t, &t->sprites.extras[id].u.road.ru.rivers, tag)) {
4089 _("No river-style graphics \"%s*\" for extra \"%s\""),
4090 tag, extra_rule_name(pextra));
4091 }
4092 } else {
4094 }
4095
4096 /* Corner road graphics are used by ESTYLE_ROAD_ALL_SEPARATE and
4097 * ESTYLE_ROAD_PARITY_COMBINED. */
4098 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4099 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4100 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4101 enum direction8 dir = t->valid_tileset_dirs[i];
4102
4103 if (!is_cardinal_tileset_dir(t, dir)) {
4104 const char *dtn = dir_get_tileset_name(dir);
4105
4107 "%s_c_%s", pextra->graphic_str, dtn);
4108
4109 SET_SPRITE_OPT(extras[id].u.road.corner[dir], full_tag_name);
4110 }
4111 }
4112 }
4113}
4114
4115/************************************************************************/
4119static void tileset_setup_base(struct tileset *t,
4120 const struct extra_type *pextra,
4121 const char *tag)
4122{
4123 char full_tag_name[MAX_LEN_NAME + strlen("_fg")];
4124 const int id = extra_index(pextra);
4125
4126 fc_assert_ret(id >= 0 && id < extra_count());
4127
4129 strcat(full_tag_name, "_bg");
4131 TRUE, TRUE, FALSE);
4132
4134 strcat(full_tag_name, "_mg");
4136 TRUE, TRUE, FALSE);
4137
4139 strcat(full_tag_name, "_fg");
4141 TRUE, TRUE, FALSE);
4142
4143 if (t->sprites.extras[id].u.bmf.background == NULL
4144 && t->sprites.extras[id].u.bmf.middleground == NULL
4145 && t->sprites.extras[id].u.bmf.foreground == NULL) {
4146 /* There was an extra style definition but no matching graphics */
4148 _("No graphics with tag \"%s_bg/mg/fg\" for extra \"%s\""),
4149 tag, extra_rule_name(pextra));
4150 }
4151}
4152
4153/************************************************************************/
4158 const struct terrain *pterrain)
4159{
4160 struct drawing_data *draw;
4161 struct sprite *sprite;
4162 char buffer[MAX_LEN_NAME + 20];
4163 int i, l;
4164
4165 if (!drawing_hash_lookup(t->tile_hash, pterrain->graphic_str, &draw)
4166 && !drawing_hash_lookup(t->tile_hash, pterrain->graphic_alt, &draw)
4167 && !drawing_hash_lookup(t->tile_hash, pterrain->graphic_alt2, &draw)) {
4169 _("Terrain \"%s\": no graphic tile \"%s\", \"%s\", or \"%s\"."),
4170 terrain_rule_name(pterrain), pterrain->graphic_str,
4171 pterrain->graphic_alt, pterrain->graphic_alt2);
4172 }
4173
4174 if (draw->init) {
4175 t->sprites.drawing[terrain_index(pterrain)] = draw;
4176 return;
4177 }
4178
4179 /* Set up each layer of the drawing. */
4180 for (l = 0; l < draw->num_layers; l++) {
4181 struct drawing_layer *dlp = &draw->layer[l];
4182 struct tileset_layer *tslp = &t->layers[l];
4183 sprite_vector_init(&dlp->base);
4184 sprite_vector_init(&dlp->allocated);
4185
4186 switch (dlp->sprite_type) {
4187 case CELL_WHOLE:
4188 switch (dlp->match_style) {
4189 case MATCH_NONE:
4190 /* Load whole sprites for this tile. */
4191 for (i = 0; ; i++) {
4192 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s%d",
4193 l, draw->name, i + 1);
4194 sprite = load_sprite(t, buffer, TRUE, FALSE, FALSE);
4195 if (!sprite) {
4196 break;
4197 }
4198 sprite_vector_reserve(&dlp->base, i + 1);
4199 dlp->base.p[i] = sprite;
4200 }
4201 /* Check for base sprite, allowing missing sprites above base */
4202 if (0 == i && 0 == l) {
4203 /* TRANS: 'base' means 'base of terrain gfx', not 'military base' */
4205 _("Missing base sprite for tag \"%s\"."), buffer);
4206 }
4207 break;
4208 case MATCH_SAME:
4209 /* Load 16 cardinally-matched sprites. */
4210 for (i = 0; i < t->num_index_cardinal; i++) {
4211 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_%s",
4212 l, draw->name, cardinal_index_str(t, i));
4213 dlp->match[i]
4214 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4215 NULL, "matched terrain",
4216 terrain_rule_name(pterrain), TRUE);
4217 }
4218 break;
4219 case MATCH_PAIR:
4220 case MATCH_FULL:
4221 fc_assert(FALSE); /* Not yet defined */
4222 break;
4223 };
4224 break;
4225 case CELL_CORNER:
4226 {
4227 const int count = dlp->match_indices;
4228 int number = NUM_CORNER_DIRS;
4229
4230 switch (dlp->match_style) {
4231 case MATCH_NONE:
4232 /* Do nothing */
4233 break;
4234 case MATCH_PAIR:
4235 case MATCH_SAME:
4236 /* N directions (NSEW) * 3 dimensions of matching */
4237 fc_assert(count == 2);
4238 number = NUM_CORNER_DIRS * 2 * 2 * 2;
4239 break;
4240 case MATCH_FULL:
4241 default:
4242 /* N directions (NSEW) * 3 dimensions of matching */
4243 /* could use exp() or expi() here? */
4244 number = NUM_CORNER_DIRS * count * count * count;
4245 break;
4246 };
4247
4248 dlp->cells
4249 = fc_calloc(number, sizeof(*dlp->cells));
4250
4251 for (i = 0; i < number; i++) {
4252 enum direction4 dir = i % NUM_CORNER_DIRS;
4253 int value = i / NUM_CORNER_DIRS;
4254
4255 switch (dlp->match_style) {
4256 case MATCH_NONE:
4257 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c",
4258 l, draw->name, direction4letters[dir]);
4259 dlp->cells[i]
4260 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4261 NULL, "cell terrain",
4262 terrain_rule_name(pterrain), TRUE);
4263 break;
4264 case MATCH_SAME:
4265 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c%d%d%d",
4266 l, draw->name, direction4letters[dir],
4267 (value) & 1, (value >> 1) & 1, (value >> 2) & 1);
4268 dlp->cells[i]
4269 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4270 NULL, "same cell terrain",
4271 terrain_rule_name(pterrain), TRUE);
4272 break;
4273 case MATCH_PAIR:
4274 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c_%c_%c_%c",
4275 l, draw->name, direction4letters[dir],
4276 tslp->match_types[dlp->match_index[(value) & 1]][0],
4277 tslp->match_types[dlp->match_index[(value >> 1) & 1]][0],
4278 tslp->match_types[dlp->match_index[(value >> 2) & 1]][0]);
4279 dlp->cells[i]
4280 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4281 NULL, "cell pair terrain",
4282 terrain_rule_name(pterrain), TRUE);
4283 break;
4284 case MATCH_FULL:
4285 {
4286 int this = dlp->match_index[0];
4287 int n, s, e, w;
4288 int v1, v2, v3;
4289
4290 v1 = dlp->match_index[value % count];
4291 value /= count;
4292 v2 = dlp->match_index[value % count];
4293 value /= count;
4294 v3 = dlp->match_index[value % count];
4295
4296 fc_assert(v1 < count && v2 < count && v3 < count);
4297
4298 /* Assume merged cells. This should be a separate option. */
4299 switch (dir) {
4300 case DIR4_NORTH:
4301 s = this;
4302 w = v1;
4303 n = v2;
4304 e = v3;
4305 break;
4306 case DIR4_EAST:
4307 w = this;
4308 n = v1;
4309 e = v2;
4310 s = v3;
4311 break;
4312 case DIR4_SOUTH:
4313 n = this;
4314 e = v1;
4315 s = v2;
4316 w = v3;
4317 break;
4318 case DIR4_WEST:
4319 default: /* Avoid warnings */
4320 e = this;
4321 s = v1;
4322 w = v2;
4323 n = v3;
4324 break;
4325 };
4326
4327 /* Use first character of match_types,
4328 * already checked for uniqueness. */
4329 fc_snprintf(buffer, sizeof(buffer),
4330 "t.l%d.cellgroup_%c_%c_%c_%c", l,
4331 tslp->match_types[n][0], tslp->match_types[e][0],
4332 tslp->match_types[s][0], tslp->match_types[w][0]);
4333 sprite = load_sprite(t, buffer, TRUE, FALSE, FALSE);
4334
4335 if (sprite) {
4336 /* Crop the sprite to separate this cell. */
4337 int vec_size = sprite_vector_size(&dlp->allocated);
4338
4339 const int W = t->normal_tile_width;
4340 const int H = t->normal_tile_height;
4341 int x[4] = {W / 4, W / 4, 0, W / 2};
4342 int y[4] = {H / 2, 0, H / 4, H / 4};
4343 int xo[4] = {0, 0, -W / 2, W / 2};
4344 int yo[4] = {H / 2, -H / 2, 0, 0};
4345
4346 sprite = crop_sprite(sprite, x[dir], y[dir], W / 2, H / 2,
4347 t->sprites.mask.tile, xo[dir], yo[dir], 1.0f,
4348 FALSE);
4349 /* We allocated new sprite with crop_sprite. Store its
4350 * address so we can free it. */
4351 sprite_vector_reserve(&dlp->allocated, vec_size + 1);
4352 dlp->allocated.p[vec_size] = sprite;
4353 } else {
4354 log_error("Terrain graphics sprite for tag \"%s\" missing.", buffer);
4355 }
4356
4357 dlp->cells[i] = sprite;
4358 }
4359 break;
4360 };
4361 }
4362 }
4363 break;
4364 };
4365 }
4366
4367 /* Try an optional special name */
4368 fc_snprintf(buffer, sizeof(buffer), "t.blend.%s", draw->name);
4369 draw->blender
4371 NULL, "blend terrain",
4372 terrain_rule_name(pterrain), TRUE);
4373
4374 if (draw->blending > 0) {
4375 const int bl = draw->blending - 1;
4376
4377 if (NULL == draw->blender) {
4378 int li = 0;
4379
4380 /* Try an already loaded base */
4381 while (NULL == draw->blender
4382 && li < draw->blending
4383 && 0 < draw->layer[li].base.size) {
4384 draw->blender = draw->layer[li++].base.p[0];
4385 }
4386 }
4387
4388 if (NULL == draw->blender) {
4389 /* Try an unloaded base name */
4390 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s1", bl, draw->name);
4391 draw->blender
4392 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4393 NULL, "base (blend) terrain",
4394 terrain_rule_name(pterrain), TRUE);
4395 }
4396 }
4397
4398 if (NULL != draw->blender) {
4399 /* Set up blending sprites. This only works in iso-view! */
4400 const int W = t->normal_tile_width;
4401 const int H = t->normal_tile_height;
4402 const int offsets[4][2] = {
4403 {W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}
4404 };
4405 enum direction4 dir = 0;
4406
4407 for (; dir < 4; dir++) {
4408 draw->blend[dir] = crop_sprite(draw->blender, offsets[dir][0],
4409 offsets[dir][1], W / 2, H / 2,
4410 t->sprites.dither_tile, 0, 0, 1.0f,
4411 FALSE);
4412 }
4413 }
4414
4415 draw->init = TRUE;
4416 t->sprites.drawing[terrain_index(pterrain)] = draw;
4417}
4418
4419/************************************************************************/
4424 struct government *gov)
4425{
4428 gov->graphic_alt, NULL, "government",
4430
4431 /* Should probably do something if NULL, eg generic default? */
4432}
4433
4434/************************************************************************/
4439 struct nation_type *nation)
4440{
4441 char *tags[] = {nation->flag_graphic_str,
4442 nation->flag_graphic_alt,
4443 "unknown", NULL};
4444 int i;
4445 struct sprite *flag = NULL, *shield = NULL;
4446 char buf[1024];
4448
4449 for (i = 0; tags[i] && !flag; i++) {
4450 fc_snprintf(buf, sizeof(buf), "f.%s", tags[i]);
4451 flag = load_sprite(t, buf, TRUE, TRUE, svgflag);
4452 }
4453 for (i = 0; tags[i] && !shield; i++) {
4454 fc_snprintf(buf, sizeof(buf), "f.shield.%s", tags[i]);
4455 shield = load_sprite(t, buf, TRUE, TRUE, svgflag);
4456 }
4457 if (!flag || !shield) {
4458 /* Should never get here because of the f.unknown fallback. */
4460 _("Nation %s: no national flag."), nation_rule_name(nation));
4461 }
4462
4464 t->sprites.nation_flag.p[nation_index(nation)] = flag;
4465
4467 t->sprites.nation_shield.p[nation_index(nation)] = shield;
4468}
4469
4470/************************************************************************/
4473struct sprite *get_city_flag_sprite(const struct tileset *t,
4474 const struct city *pcity)
4475{
4476 return get_nation_flag_sprite(t, nation_of_city(pcity));
4477}
4478
4479/************************************************************************/
4482static struct sprite *get_unit_nation_flag_sprite(const struct tileset *t,
4483 const struct unit *punit)
4484{
4485 struct nation_type *pnation = nation_of_unit(punit);
4486
4488 return t->sprites.nation_shield.p[nation_index(pnation)];
4489 } else {
4490 return t->sprites.nation_flag.p[nation_index(pnation)];
4491 }
4492}
4493
4494#define FULL_TILE_X_OFFSET ((t->normal_tile_width - t->full_tile_width) / 2)
4495#define FULL_TILE_Y_OFFSET (t->normal_tile_height - t->full_tile_height)
4496
4497#define ADD_SPRITE(s, draw_fog, x_offset, y_offset) \
4498 (fc_assert(s != NULL), \
4499 sprs->sprite = s, \
4500 sprs->foggable = (draw_fog && t->fogstyle == FOG_AUTO), \
4501 sprs->offset_x = x_offset, \
4502 sprs->offset_y = y_offset, \
4503 sprs++)
4504#define ADD_SPRITE_SIMPLE(s) ADD_SPRITE(s, TRUE, 0, 0)
4505#define ADD_SPRITE_FULL(s) \
4506 ADD_SPRITE(s, TRUE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET)
4507
4508/************************************************************************/
4515static void build_tile_data(const struct tile *ptile,
4516 struct terrain *pterrain,
4517 struct terrain **tterrain_near,
4519{
4520 enum direction8 dir;
4521
4522 /* Loop over all adjacent tiles. We should have an iterator for this. */
4523 for (dir = 0; dir < 8; dir++) {
4524 struct tile *tile1 = mapstep(&(wld.map), ptile, dir);
4525
4528
4529 if (NULL != terrain1) {
4530 tterrain_near[dir] = terrain1;
4532 continue;
4533 }
4534 log_error("build_tile_data() tile (%d,%d) has no terrain!",
4535 TILE_XY(tile1));
4536 }
4537 /* At the edges of the (known) map, pretend the same terrain continued
4538 * past the edge of the map. */
4539 tterrain_near[dir] = pterrain;
4541 }
4542}
4543
4544/************************************************************************/
4547static int fill_unit_type_sprite_array(const struct tileset *t,
4548 struct drawn_sprite *sprs,
4549 const struct unit_type *putype,
4550 enum unit_activity activity,
4551 enum direction8 facing)
4552{
4553 struct drawn_sprite *save_sprs = sprs;
4554 struct sprite *uspr = get_unittype_sprite(t, putype, activity, facing);
4555
4559
4560 return sprs - save_sprs;
4561}
4562
4563/************************************************************************/
4566static int fill_unit_sprite_array(const struct tileset *t,
4567 struct drawn_sprite *sprs,
4568 const struct unit *punit,
4569 int stack, bool backdrop)
4570{
4571 struct drawn_sprite *save_sprs = sprs;
4572 int ihp;
4573 const struct unit_type *ptype = unit_type_get(punit);
4574
4575 if (backdrop) {
4580 } else {
4581 /* Taken care of in the LAYER_BACKGROUND. */
4582 }
4583 }
4584
4585 /* Add the sprite for the unit type. */
4588
4589 if (t->sprites.unit.loaded && unit_transported(punit)) {
4590 ADD_SPRITE_FULL(t->sprites.unit.loaded);
4591 }
4592
4593 if (punit->activity != ACTIVITY_IDLE) {
4594 struct sprite *s = NULL;
4595
4596 switch (punit->activity) {
4597 case ACTIVITY_MINE:
4598 if (punit->activity_target == NULL) {
4599 s = t->sprites.unit.plant;
4600 } else {
4602 }
4603 break;
4604 case ACTIVITY_PLANT:
4605 s = t->sprites.unit.plant;
4606 break;
4607 case ACTIVITY_IRRIGATE:
4608 if (punit->activity_target == NULL) {
4609 s = t->sprites.unit.cultivate;
4610 } else {
4612 }
4613 break;
4614 case ACTIVITY_CULTIVATE:
4615 s = t->sprites.unit.cultivate;
4616 break;
4617 case ACTIVITY_CLEAN:
4619 break;
4620 case ACTIVITY_PILLAGE:
4622 if (s == NULL) {
4623 s = t->sprites.unit.pillage;
4624 }
4625 break;
4626 case ACTIVITY_EXPLORE:
4627 /* Drawn below as the server side agent. */
4628 break;
4629 case ACTIVITY_FORTIFIED:
4630 s = t->sprites.unit.fortified;
4631 break;
4633 s = t->sprites.unit.fortifying;
4634 break;
4635 case ACTIVITY_SENTRY:
4636 s = t->sprites.unit.sentry;
4637 break;
4638 case ACTIVITY_GOTO:
4639 s = t->sprites.unit.go_to;
4640 break;
4641 case ACTIVITY_TRANSFORM:
4642 s = t->sprites.unit.transform;
4643 break;
4644 case ACTIVITY_BASE:
4645 case ACTIVITY_GEN_ROAD:
4647 break;
4648 case ACTIVITY_CONVERT:
4649 s = t->sprites.unit.convert;
4650 break;
4651 default:
4652 break;
4653 }
4654
4655 if (s != NULL) {
4658 }
4659 }
4660
4661 {
4662 struct sprite *s = NULL;
4663 int offset_x = 0;
4664 int offset_y = 0;
4665
4666 switch (punit->ssa_controller) {
4667 case SSA_NONE:
4668 break;
4669 case SSA_AUTOSETTLER:
4670 s = t->sprites.unit.auto_settler;
4671 break;
4672 case SSA_AUTOEXPLORE:
4673 s = t->sprites.unit.auto_explore;
4674 /* Specified as an activity in the tileset. */
4677 break;
4678 default:
4679 s = t->sprites.unit.auto_attack;
4680 break;
4681 }
4682
4683 if (s != NULL) {
4684 ADD_SPRITE(s, TRUE,
4687 }
4688 }
4689
4690 if (unit_has_orders(punit)) {
4691 if (punit->orders.repeat) {
4692 ADD_SPRITE_FULL(t->sprites.unit.patrol);
4693 } else if (punit->activity != ACTIVITY_IDLE) {
4694 ADD_SPRITE_SIMPLE(t->sprites.unit.connect);
4695 } else {
4696 ADD_SPRITE(t->sprites.unit.go_to, TRUE,
4699 }
4700 }
4701
4702 if (t->sprites.unit.action_decision_want != NULL
4704 ADD_SPRITE(t->sprites.unit.action_decision_want, TRUE,
4707 }
4708
4710 ADD_SPRITE_FULL(t->sprites.unit.battlegroup[punit->battlegroup]);
4711 }
4712
4713 if (t->sprites.unit.lowfuel
4714 && utype_fuel(ptype)
4715 && punit->fuel == 1
4716 && punit->moves_left <= 2 * SINGLE_MOVE) {
4717 /* Show a low-fuel graphic if the plane has 2 or fewer moves left. */
4718 ADD_SPRITE_FULL(t->sprites.unit.lowfuel);
4719 }
4720 if (t->sprites.unit.tired
4722 && ptype->move_rate > 0) {
4723 /* Show a "tired" graphic if the unit has fewer than one move
4724 * remaining, except for units for which it's full movement. */
4725 ADD_SPRITE_FULL(t->sprites.unit.tired);
4726 }
4727
4728 if (stack == 1 && punit->client.occupied) {
4729 ADD_SPRITE_FULL(t->sprites.unit.stack[0]);
4730 } else if (stack > 1) {
4732 && t->sprites.unit.num_stack_sprites >= stack) {
4733 ADD_SPRITE(t->sprites.unit.stack[stack - 1], FALSE,
4735 } else {
4736 ADD_SPRITE_FULL(t->sprites.unit.stack[0]);
4737 }
4738 }
4739
4740 if (t->sprites.unit.vet_lev[punit->veteran]) {
4742 }
4743
4744 ihp = ((NUM_TILES_HP_BAR-1)*punit->hp) / ptype->hp;
4745 ihp = CLIP(0, ihp, NUM_TILES_HP_BAR-1);
4746 ADD_SPRITE_FULL(t->sprites.unit.hp_bar[ihp]);
4747
4748 return sprs - save_sprs;
4749}
4750
4751/************************************************************************/
4754static int fill_road_corner_sprites(const struct tileset *t,
4755 const struct extra_type *pextra,
4756 struct drawn_sprite *sprs,
4757 bool road, bool *road_near,
4758 bool hider, bool *hider_near)
4759{
4760 struct drawn_sprite *saved_sprs = sprs;
4761 int i;
4762 int extra_idx = extra_index(pextra);
4763
4764 if (is_cardinal_only_road(pextra)) {
4765 return 0;
4766 }
4767
4768 /* Roads going diagonally adjacent to this tile need to be
4769 * partly drawn on this tile. */
4770
4771 /* Draw the corner sprite if:
4772 * - There is a diagonal road (not rail!) between two adjacent tiles.
4773 * - There is no diagonal road (not rail!) that intersects this road.
4774 * The logic is simple: roads are drawn underneath railrods, but are
4775 * not always covered by them (even in the corners!). But if a railroad
4776 * connects two tiles, only the railroad (no road) is drawn between
4777 * those tiles.
4778 */
4779 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4780 enum direction8 dir = t->valid_tileset_dirs[i];
4781
4782 if (!is_cardinal_tileset_dir(t, dir)) {
4783 /* Draw corner sprites for this non-cardinal direction. */
4784 int cw = (i + 1) % t->num_valid_tileset_dirs;
4785 int ccw
4787 enum direction8 cwdir = t->valid_tileset_dirs[cw];
4789
4790 if (t->sprites.extras[extra_idx].u.road.corner[dir]
4792 && !(hider_near[cwdir] && hider_near[ccwdir]))
4793 && !(road && road_near[dir] && !(hider && hider_near[dir]))) {
4795 }
4796 }
4797 }
4798
4799 return sprs - saved_sprs;
4800}
4801
4802/************************************************************************/
4805static int fill_road_sprite_array(const struct tileset *t,
4806 const struct extra_type *pextra,
4807 struct drawn_sprite *sprs,
4810 struct terrain *tterrain_near[8],
4811 const struct city *pcity)
4812{
4813 struct drawn_sprite *saved_sprs = sprs;
4814 bool road, road_near[8], hider, hider_near[8];
4815 bool land_near[8], hland_near[8];
4816 bool draw_road[8], draw_single_road;
4817 enum direction8 dir;
4818 int extra_idx = -1;
4819 bool cl = FALSE;
4820 enum extrastyle_id extrastyle;
4821 const struct road_type *proad = extra_road_get(pextra);
4822
4823 extra_idx = extra_index(pextra);
4824
4825 extrastyle = t->sprites.extras[extra_idx].extrastyle;
4826
4827 if (extra_has_flag(pextra, EF_CONNECT_LAND)) {
4828 cl = TRUE;
4829 } else {
4830 int i;
4831
4832 for (i = 0; i < 8; i++) {
4833 land_near[i] = FALSE;
4834 }
4835 }
4836
4837 /* Fill some data arrays. rail_near and road_near store whether road/rail
4838 * is present in the given direction. draw_rail and draw_road store
4839 * whether road/rail is to be drawn in that direction. draw_single_road
4840 * and draw_single_rail store whether we need an isolated road/rail to be
4841 * drawn. */
4843
4844 hider = FALSE;
4847 hider = TRUE;
4848 break;
4849 }
4851
4852 if (road && (!pcity || !gui_options.draw_cities) && !hider) {
4854 } else {
4856 }
4857
4858 for (dir = 0; dir < 8; dir++) {
4859 bool roads_exist;
4860
4861 /* Check if there is adjacent road/rail. */
4862 if (!is_cardinal_only_road(pextra)
4863 || is_cardinal_tileset_dir(t, dir)) {
4864 road_near[dir] = FALSE;
4865 extra_type_list_iterate(proad->integrators, iextra) {
4867 road_near[dir] = TRUE;
4868 break;
4869 }
4871 if (cl) {
4872 land_near[dir] = (tterrain_near[dir] != T_UNKNOWN
4874 }
4875 } else {
4876 road_near[dir] = FALSE;
4877 land_near[dir] = FALSE;
4878 }
4879
4880 /* Draw rail/road if there is a connection from this tile to the
4881 * adjacent tile. But don't draw road if there is also a rail
4882 * connection. */
4883 roads_exist = road && (road_near[dir] || land_near[dir]);
4884 draw_road[dir] = roads_exist;
4885 hider_near[dir] = FALSE;
4886 hland_near[dir] = tterrain_near[dir] != T_UNKNOWN
4889 bool hider_dir = FALSE;
4890 bool land_dir = FALSE;
4891
4893 || is_cardinal_tileset_dir(t, dir)) {
4895 hider_near[dir] = TRUE;
4896 hider_dir = TRUE;
4897 }
4898 if (hland_near[dir]
4901 land_dir = TRUE;
4902 }
4903 if (hider_dir || land_dir) {
4905 draw_road[dir] = FALSE;
4906 }
4907 }
4908 }
4910
4911 /* Don't draw an isolated road/rail if there's any connection.
4912 * draw_single_road would be true in the first place only if start tile has road,
4913 * so it will have road connection with any adjacent road tile. We check from real
4914 * existence of road (road_near[dir]) and not from whether road gets drawn (draw_road[dir])
4915 * as latter can be FALSE when road is simply hidden by another one, and we don't want to
4916 * draw single road in that case either. */
4917 if (draw_single_road && road_near[dir]) {
4919 }
4920 }
4921
4922 /* Draw road corners */
4923 sprs
4925
4926 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
4927 /* With ESTYLE_ROAD_ALL_SEPARATE, we simply draw one road for every connection.
4928 * This means we only need a few sprites, but a lot of drawing is
4929 * necessary and it generally doesn't look very good. */
4930 int i;
4931
4932 /* First draw roads under rails. */
4933 if (road) {
4934 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4935 if (draw_road[t->valid_tileset_dirs[i]]) {
4937 }
4938 }
4939 }
4940 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4941 /* With ESTYLE_ROAD_PARITY_COMBINED, we draw one sprite for cardinal
4942 * road connections, one sprite for diagonal road connections.
4943 * This means we need about 4x more sprites than in style 0, but up to
4944 * 4x less drawing is needed. The drawing quality may also be
4945 * improved. */
4946
4947 /* First draw roads under rails. */
4948 if (road) {
4949 int road_even_tileno = 0, road_odd_tileno = 0, i;
4950
4951 for (i = 0; i < t->num_valid_tileset_dirs / 2; i++) {
4952 enum direction8 even = t->valid_tileset_dirs[2 * i];
4953 enum direction8 odd = t->valid_tileset_dirs[2 * i + 1];
4954
4955 if (draw_road[even]) {
4956 road_even_tileno |= 1 << i;
4957 }
4958 if (draw_road[odd]) {
4959 road_odd_tileno |= 1 << i;
4960 }
4961 }
4962
4963 /* Draw the cardinal/even roads first. */
4964 if (road_even_tileno != 0) {
4966 }
4967 if (road_odd_tileno != 0) {
4969 }
4970 }
4971 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
4972 /* RSTYLE_ALL_COMBINED is a very simple method that lets us simply retrieve
4973 * entire finished tiles, with a bitwise index of the presence of
4974 * roads in each direction. */
4975
4976 /* Draw roads first */
4977 if (road) {
4978 int road_tileno = 0, i;
4979
4980 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4982
4983 if (draw_road[vdir]) {
4984 road_tileno |= 1 << i;
4985 }
4986 }
4987
4988 if (road_tileno != 0 || draw_single_road) {
4990 }
4991 }
4992 } else {
4994 }
4995
4996 /* Draw isolated rail/road separately (ESTYLE_ROAD_ALL_SEPARATE and
4997 ESTYLE_ROAD_PARITY_COMBINED only). */
4998 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4999 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
5000 if (draw_single_road) {
5002 }
5003 }
5004
5005 return sprs - saved_sprs;
5006}
5007
5008/************************************************************************/
5017static int get_irrigation_index(const struct tileset *t,
5018 struct extra_type *pextra,
5020{
5021 int tileno = 0, i;
5022
5023 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5024 enum direction8 dir = t->cardinal_tileset_dirs[i];
5025
5026 if (BV_ISSET(textras_near[dir], extra_index(pextra))) {
5027 tileno |= 1 << i;
5028 }
5029 }
5030
5031 return tileno;
5032}
5033
5034/************************************************************************/
5037static int fill_irrigation_sprite_array(const struct tileset *t,
5038 struct drawn_sprite *sprs,
5041 const struct city *pcity)
5042{
5043 struct drawn_sprite *saved_sprs = sprs;
5044
5045 /* We don't draw the irrigation if there's a city (it just gets overdrawn
5046 * anyway, and ends up looking bad). */
5047 if (!(pcity && gui_options.draw_cities)) {
5049 if (is_extra_drawing_enabled(pextra)) {
5050 int eidx = extra_index(pextra);
5051
5052 if (BV_ISSET(textras, eidx)) {
5053 bool hidden = FALSE;
5054
5055 extra_type_list_iterate(pextra->hiders, phider) {
5057 hidden = TRUE;
5058 break;
5059 }
5061
5062 if (!hidden) {
5063 int idx = get_irrigation_index(t, pextra, textras_near);
5064
5066 }
5067 }
5068 }
5070 }
5071
5072 return sprs - saved_sprs;
5073}
5074
5075/************************************************************************/
5079static int fill_city_overlays_sprite_array(const struct tileset *t,
5080 struct drawn_sprite *sprs,
5081 const struct tile *ptile,
5082 const struct city *citymode)
5083{
5084 const struct city *pcity;
5085 const struct city *pwork;
5086 struct unit *psettler;
5087 struct drawn_sprite *saved_sprs = sprs;
5088 int city_x, city_y;
5089 const int NUM_CITY_COLORS = t->sprites.city.worked_tile_overlay.size;
5090
5091 if (NULL == ptile || TILE_UNKNOWN == client_tile_get_known(ptile)) {
5092 return 0;
5093 }
5094 pwork = tile_worked(ptile);
5095
5096 if (citymode) {
5097 pcity = citymode;
5098 } else {
5100 }
5101
5102 /* Below code does not work if pcity is invisible.
5103 * Make sure it is not. */
5104 fc_assert_ret_val(pcity == NULL || pcity->tile != NULL, 0);
5105 if (pcity && !pcity->tile) {
5106 pcity = NULL;
5107 }
5108
5109 if (pcity && city_base_to_city_map(&city_x, &city_y, pcity, ptile)) {
5110 /* FIXME: check elsewhere for valid tile (instead of above) */
5111
5112 if (!citymode && pcity->client.colored) {
5113 /* Add citymap overlay for a city. */
5114 int idx = pcity->client.color_index % NUM_CITY_COLORS;
5115
5116 if (NULL != pwork && pwork == pcity) {
5118 } else if (city_can_work_tile(pcity, ptile)) {
5120 }
5121 } else if (NULL != pwork && pwork == pcity
5123
5124 /* Add on the tile output sprites.
5125 * NOTE: To show correct output on end of turn
5126 * base_city_celebrating() must be used instead of city_celebrating()
5127 * mirroring the behavior of the server that does so in
5128 * city_tile_cache_update(). */
5129 bool celebrating = base_city_celebrating(pcity);
5130 int food = city_tile_output(pcity, ptile, celebrating, O_FOOD);
5131 int shields = city_tile_output(pcity, ptile, celebrating, O_SHIELD);
5132 int trade = city_tile_output(pcity, ptile, celebrating, O_TRADE);
5133
5134 const int ox = t->type == TS_ISOMETRIC ? t->normal_tile_width / 3 : 0;
5135 const int oy = t->type == TS_ISOMETRIC ? -t->normal_tile_height / 3 : 0;
5136
5137 food = CLIP(0, food / game.info.granularity, NUM_TILES_DIGITS - 1);
5138 shields = CLIP(0, shields / game.info.granularity, NUM_TILES_DIGITS - 1);
5139 trade = CLIP(0, trade / game.info.granularity, NUM_TILES_DIGITS - 1);
5140
5142 ADD_SPRITE(t->sprites.city.tile_shieldnum[shields], TRUE, ox, oy);
5144 }
5145 } else if (psettler && psettler->client.colored) {
5146 /* Add citymap overlay for a unit. */
5147 int idx = psettler->client.color_index % NUM_CITY_COLORS;
5148
5150 }
5151
5152 return sprs - saved_sprs;
5153}
5154
5155/************************************************************************/
5159static int fill_terrain_sprite_blending(const struct tileset *t,
5160 struct drawn_sprite *sprs,
5161 const struct tile *ptile,
5162 const struct terrain *pterrain,
5163 struct terrain **tterrain_near)
5164{
5165 struct drawn_sprite *saved_sprs = sprs;
5166 const int W = t->normal_tile_width, H = t->normal_tile_height;
5167 const int offsets[4][2] = {
5168 {W/2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}
5169 };
5170 enum direction4 dir = 0;
5171
5172 /*
5173 * We want to mark unknown tiles so that an unreal tile will be
5174 * given the same marking as our current tile - that way we won't
5175 * get the "unknown" dither along the edge of the map.
5176 */
5177 for (; dir < 4; dir++) {
5178 struct tile *tile1 = mapstep(&(wld.map), ptile, DIR4_TO_DIR8[dir]);
5179 struct terrain *other;
5180
5181 if (!tile1
5183 || pterrain == (other = tterrain_near[DIR4_TO_DIR8[dir]])
5184 || (0 == t->sprites.drawing[terrain_index(other)]->blending
5185 && NULL == t->sprites.drawing[terrain_index(other)]->blender)) {
5186 continue;
5187 }
5188
5190 offsets[dir][0], offsets[dir][1]);
5191 }
5192
5193 return sprs - saved_sprs;
5194}
5195
5196/************************************************************************/
5199static int fill_fog_sprite_array(const struct tileset *t,
5200 struct drawn_sprite *sprs,
5201 const struct tile *ptile,
5202 const struct tile_edge *pedge,
5203 const struct tile_corner *pcorner)
5204{
5205 struct drawn_sprite *saved_sprs = sprs;
5206
5208 && NULL != ptile
5210 /* With FOG_AUTO, fog is done this way. */
5212 }
5213
5216 int i, tileno = 0;
5217
5218 for (i = 3; i >= 0; i--) {
5219 const int unknown = 0, fogged = 1, known = 2;
5220 int value = -1;
5221
5222 if (!pcorner->tile[i]) {
5223 value = fogged;
5224 } else {
5225 switch (client_tile_get_known(pcorner->tile[i])) {
5226 case TILE_KNOWN_SEEN:
5227 value = known;
5228 break;
5229 case TILE_KNOWN_UNSEEN:
5230 value = fogged;
5231 break;
5232 case TILE_UNKNOWN:
5233 value = unknown;
5234 break;
5235 }
5236 }
5237 fc_assert(value >= 0 && value < 3);
5238
5239 tileno = tileno * 3 + value;
5240 }
5241
5242 if (t->sprites.tx.fullfog[tileno]) {
5244 }
5245 }
5246
5247 return sprs - saved_sprs;
5248}
5249
5250/************************************************************************/
5254 struct drawn_sprite *sprs,
5255 int l, /* layer_num */
5256 const struct tile *ptile,
5257 const struct terrain *pterrain,
5258 struct terrain **tterrain_near,
5259 struct drawing_data *draw)
5260{
5261 struct drawn_sprite *saved_sprs = sprs;
5262 struct drawing_layer *dlp = &draw->layer[l];
5263 int this = dlp->match_index[0];
5264 int that = dlp->match_index[1];
5265 int ox = dlp->offset_x;
5266 int oy = dlp->offset_y;
5267 int i;
5268
5269#define MATCH(dir) \
5270 (t->sprites.drawing[terrain_index(tterrain_near[(dir)])]->num_layers > l \
5271 ? t->sprites.drawing[terrain_index(tterrain_near[(dir)])]->layer[l].match_index[0] \
5272 : -1)
5273
5274 switch (dlp->sprite_type) {
5275 case CELL_WHOLE:
5276 {
5277 switch (dlp->match_style) {
5278 case MATCH_NONE:
5279 {
5280 int count = sprite_vector_size(&dlp->base);
5281
5282 if (count > 0) {
5283 /* Pseudo-random reproducable algorithm to pick a sprite. Use modulo
5284 * to limit the number to a handleable size [0..32000). */
5285 count = fc_randomly(tile_index(ptile) % 32000, count);
5286
5287 if (dlp->is_tall) {
5290 }
5291 ADD_SPRITE(dlp->base.p[count], TRUE, ox, oy);
5292 }
5293 break;
5294 }
5295 case MATCH_SAME:
5296 {
5297 int tileno = 0;
5298
5299 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5300 enum direction8 dir = t->cardinal_tileset_dirs[i];
5301
5302 if (MATCH(dir) == this) {
5303 tileno |= 1 << i;
5304 }
5305 }
5306
5307 if (dlp->is_tall) {
5310 }
5311 ADD_SPRITE(dlp->match[tileno], TRUE, ox, oy);
5312 break;
5313 }
5314 case MATCH_PAIR:
5315 case MATCH_FULL:
5316 fc_assert(FALSE); /* Not yet defined */
5317 break;
5318 };
5319 break;
5320 }
5321 case CELL_CORNER:
5322 {
5323 /* Divide the tile up into four rectangular cells. Each of these
5324 * cells covers one corner, and each is adjacent to 3 different
5325 * tiles. For each cell we pick a sprite based upon the adjacent
5326 * terrains at each of those tiles. Thus, we have 8 different sprites
5327 * for each of the 4 cells (32 sprites total).
5328 *
5329 * These arrays correspond to the direction4 ordering. */
5330 const int W = t->normal_tile_width;
5331 const int H = t->normal_tile_height;
5332 const int iso_offsets[4][2] = {
5333 {W / 4, 0}, {W / 4, H / 2}, {W / 2, H / 4}, {0, H / 4}
5334 };
5335 const int noniso_offsets[4][2] = {
5336 {0, 0}, {W / 2, H / 2}, {W / 2, 0}, {0, H / 2}
5337 };
5338
5339 /* Put corner cells */
5340 for (i = 0; i < NUM_CORNER_DIRS; i++) {
5341 const int count = dlp->match_indices;
5342 int array_index = 0;
5343 enum direction8 dir = dir_ccw(DIR4_TO_DIR8[i]);
5344 int x = (t->type == TS_ISOMETRIC ? iso_offsets[i][0] : noniso_offsets[i][0]);
5345 int y = (t->type == TS_ISOMETRIC ? iso_offsets[i][1] : noniso_offsets[i][1]);
5346 int m[3] = {MATCH(dir_ccw(dir)), MATCH(dir), MATCH(dir_cw(dir))};
5347 struct sprite *s;
5348
5349 /* Synthesize 4 dimensional array? */
5350 switch (dlp->match_style) {
5351 case MATCH_NONE:
5352 /* We have no need for matching, just plug the piece in place. */
5353 break;
5354 case MATCH_SAME:
5355 array_index = array_index * 2 + (m[2] != this);
5356 array_index = array_index * 2 + (m[1] != this);
5357 array_index = array_index * 2 + (m[0] != this);
5358 break;
5359 case MATCH_PAIR:
5360 array_index = array_index * 2 + (m[2] == that);
5361 array_index = array_index * 2 + (m[1] == that);
5362 array_index = array_index * 2 + (m[0] == that);
5363 break;
5364 case MATCH_FULL:
5365 default:
5366 if (count > 0) {
5367 int n[3];
5368 int j;
5369
5370 for (j = 0; j < 3; j++) {
5371 int k;
5372
5373 for (k = 0; k < count; k++) {
5374 n[j] = k; /* Default to last entry */
5375 if (m[j] == dlp->match_index[k]) {
5376 break;
5377 }
5378 }
5379 }
5380 array_index = array_index * count + n[2];
5381 array_index = array_index * count + n[1];
5382 array_index = array_index * count + n[0];
5383 }
5384 break;
5385 };
5386
5388
5389 s = dlp->cells[array_index];
5390 if (s) {
5391 ADD_SPRITE(s, TRUE, x, y);
5392 }
5393 }
5394 break;
5395 }
5396 };
5397#undef MATCH
5398
5399 return sprs - saved_sprs;
5400}
5401
5402/************************************************************************/
5407 struct drawn_sprite *sprs,
5408 const struct tile *ptile,
5409 struct terrain **tterrain_near)
5410{
5411 struct drawn_sprite *saved_sprs = sprs;
5412 int i, tileno;
5413 struct tile *adjc_tile;
5414
5415#define UNKNOWN(dir) \
5416 ((adjc_tile = mapstep(&(wld.map), ptile, (dir))) \
5417 && client_tile_get_known(adjc_tile) == TILE_UNKNOWN)
5418
5419 switch (t->darkness_style) {
5420 case DARKNESS_NONE:
5421 break;
5422 case DARKNESS_ISORECT:
5423 for (i = 0; i < 4; i++) {
5424 const int W = t->normal_tile_width, H = t->normal_tile_height;
5425 int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
5426
5427 if (UNKNOWN(DIR4_TO_DIR8[i])) {
5429 offsets[i][0], offsets[i][1]);
5430 }
5431 }
5432 break;
5434 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5435 if (UNKNOWN(t->cardinal_tileset_dirs[i])) {
5437 }
5438 }
5439 break;
5440 case DARKNESS_CARD_FULL:
5441 /* We're looking to find the INDEX_NSEW for the directions that
5442 * are unknown. We want to mark unknown tiles so that an unreal
5443 * tile will be given the same marking as our current tile - that
5444 * way we won't get the "unknown" dither along the edge of the
5445 * map. */
5446 tileno = 0;
5447 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5448 if (UNKNOWN(t->cardinal_tileset_dirs[i])) {
5449 tileno |= 1 << i;
5450 }
5451 }
5452
5453 if (tileno != 0) {
5455 }
5456 break;
5457 case DARKNESS_CORNER:
5458 /* Handled separately. */
5459 break;
5460 };
5461#undef UNKNOWN
5462
5463 return sprs - saved_sprs;
5464}
5465
5466/************************************************************************/
5471 struct drawn_sprite *sprs,
5472 int layer_num,
5473 const struct tile *ptile,
5474 const struct terrain *pterrain,
5475 struct terrain **tterrain_near)
5476{
5477 struct sprite *sprite;
5478 struct drawn_sprite *saved_sprs = sprs;
5479 struct drawing_data *draw = t->sprites.drawing[terrain_index(pterrain)];
5480 const int l = (draw->is_reversed
5481 ? (draw->num_layers - layer_num - 1) : layer_num);
5482
5484
5485 /* Skip the normal drawing process. */
5486 /* FIXME: this should avoid calling load_sprite since it's slow and
5487 * increases the refcount without limit. */
5488 if (ptile->spec_sprite && (sprite = load_sprite(t, ptile->spec_sprite,
5489 TRUE, FALSE, FALSE))) {
5490 if (l == 0) {
5492 return 1;
5493 } else {
5494 return 0;
5495 }
5496 }
5497
5499 sprs += fill_terrain_sprite_array(t, sprs, l, ptile, pterrain, tterrain_near, draw);
5500
5501 if ((l + 1) == draw->blending) {
5502 sprs += fill_terrain_sprite_blending(t, sprs, ptile, pterrain, tterrain_near);
5503 }
5504 }
5505
5506 return sprs - saved_sprs;
5507}
5508
5509/************************************************************************/
5516{
5517 /* Display an outline for city-builder type units if they are selected,
5518 * and on a tile where a city can be built.
5519 * But suppress the outline if the unit has orders (likely it is in
5520 * transit to somewhere else and this will just slow down redraws). */
5527}
5528
5529/************************************************************************/
5532static int fill_grid_sprite_array(const struct tileset *t,
5533 struct drawn_sprite *sprs,
5534 const struct tile *ptile,
5535 const struct tile_edge *pedge,
5536 const struct tile_corner *pcorner,
5537 const struct unit *punit,
5538 const struct city *pcity,
5539 const struct city *citymode)
5540{
5541 struct drawn_sprite *saved_sprs = sprs;
5542
5543 if (pedge) {
5544 bool known[NUM_EDGE_TILES], city[NUM_EDGE_TILES];
5545 bool unit[NUM_EDGE_TILES], worked[NUM_EDGE_TILES];
5546 int i;
5547 struct unit_list *pfocus_units = get_units_in_focus();
5548
5549 for (i = 0; i < NUM_EDGE_TILES; i++) {
5550 int dummy_x, dummy_y;
5551 const struct tile *tile = pedge->tile[i];
5552 struct player *powner = tile ? tile_owner(tile) : NULL;
5553
5555 unit[i] = FALSE;
5556 if (tile && !citymode) {
5559 struct tile *utile = unit_tile(pfocus_unit);
5560 int radius = game.info.init_city_radius_sq
5562 NULL,
5563 &(const struct req_context) {
5564 .player = unit_owner(pfocus_unit),
5565 .tile = utile,
5566 },
5567 NULL,
5569 );
5570
5571 if (city_tile_to_city_map(&dummy_x, &dummy_y, radius,
5572 utile, tile)) {
5573 unit[i] = TRUE;
5574 break;
5575 }
5576 }
5578 }
5579 worked[i] = FALSE;
5580
5581 city[i] = (tile
5582 && (NULL == powner || NULL == client.conn.playing
5583 || powner == client.conn.playing)
5585 if (city[i]) {
5586 if (citymode) {
5587 /* In citymode, we only draw worked tiles for this city - other
5588 * tiles may be marked as unavailable. */
5589 worked[i] = (tile_worked(tile) == citymode);
5590 } else {
5591 worked[i] = (NULL != tile_worked(tile));
5592 }
5593 }
5594 }
5595
5596 if (mapdeco_is_highlight_set(pedge->tile[0])
5597 || mapdeco_is_highlight_set(pedge->tile[1])) {
5600 && pedge->tile[0] && pedge->tile[1]
5601 && known[0] && known[1]
5602 && (is_ocean_tile(pedge->tile[0])
5603 ^ is_ocean_tile(pedge->tile[1]))) {
5605 } else {
5607 if (worked[0] || worked[1]) {
5609 } else if (city[0] || city[1]) {
5611 } else if (known[0] || known[1]) {
5613 }
5614 }
5616 if (XOR(city[0], city[1])) {
5618 }
5619 if (XOR(unit[0], unit[1])) {
5621 }
5622 }
5623 }
5624
5627 && known[0]
5628 && known[1]) {
5629 struct player *owner0 = tile_owner(pedge->tile[0]);
5630 struct player *owner1 = tile_owner(pedge->tile[1]);
5631
5632 if (owner0 != owner1) {
5633 if (owner0) {
5634 int plrid = player_index(owner0);
5636 [pedge->type][0]);
5637 }
5638 if (owner1) {
5639 int plrid = player_index(owner1);
5641 [pedge->type][1]);
5642 }
5643 }
5644 }
5645 } else if (NULL != ptile && TILE_UNKNOWN != client_tile_get_known(ptile)) {
5646 int cx, cy;
5647
5648 if (citymode
5649 /* Test to ensure valid coordinates? */
5650 && city_base_to_city_map(&cx, &cy, citymode, ptile)
5651 && !client_city_can_work_tile(citymode, ptile)) {
5653 }
5654
5656 bool native = TRUE;
5657 struct unit_list *pfocus_units = get_units_in_focus();
5658
5660 if (!is_native_tile(unit_type_get(pfocus), ptile)) {
5661 native = FALSE;
5662 break;
5663 }
5665
5666 if (!native) {
5667 if (t->sprites.grid.nonnative != NULL) {
5669 } else {
5671 }
5672 }
5673 }
5674 }
5675
5676 return sprs - saved_sprs;
5677}
5678
5679/************************************************************************/
5682static int fill_goto_sprite_array(const struct tileset *t,
5683 struct drawn_sprite *sprs,
5684 const struct tile *ptile,
5685 const struct tile_edge *pedge,
5686 const struct tile_corner *pcorner)
5687{
5688 struct drawn_sprite *saved_sprs = sprs;
5689 struct sprite *sprite;
5690 bool warn = FALSE;
5691 enum goto_tile_state state;
5692 int length;
5693 bool waypoint;
5694
5695 if (goto_tile_state(ptile, &state, &length, &waypoint)) {
5696 if (length >= 0) {
5697 fc_assert(state >= 0);
5698 fc_assert(state < ARRAY_SIZE(t->sprites.path.s));
5699
5700 sprite = t->sprites.path.s[state].specific;
5701 if (sprite != NULL) {
5702 ADD_SPRITE(sprite, FALSE, 0, 0);
5703 }
5704
5705 sprite = t->sprites.path.s[state].turns[length % 10];
5707 if (length >= 10) {
5708 sprite = t->sprites.path.s[state].turns_tens[(length / 10) % 10];
5710 if (length >= 100) {
5711 sprite = t->sprites.path.s[state].turns_hundreds[(length / 100)
5712 % 10];
5713
5714 if (sprite != NULL) {
5716 if (length >= 1000) {
5717 warn = TRUE;
5718 }
5719 } else {
5720 warn = TRUE;
5721 }
5722 }
5723 }
5724 }
5725
5726 if (waypoint) {
5728 }
5729
5730 if (warn) {
5731 /* Warn only once by tileset. */
5732 static char last_reported[256] = "";
5733
5734 if (0 != strcmp(last_reported, t->name)) {
5735 log_normal(_("Tileset \"%s\" doesn't support long goto paths, "
5736 "such as %d. Path not displayed as expected."),
5737 t->name, length);
5739 }
5740 }
5741 }
5742
5743 return sprs - saved_sprs;
5744}
5745
5746/************************************************************************/
5750static bool is_extra_drawing_enabled(struct extra_type *pextra)
5751{
5752 bool no_disable = TRUE; /* Draw if matches no cause */
5753
5754 if (is_extra_caused_by(pextra, EC_IRRIGATION)) {
5756 return TRUE;
5757 }
5758 no_disable = FALSE;
5759 }
5760 if (is_extra_caused_by(pextra, EC_POLLUTION)
5761 || is_extra_caused_by(pextra, EC_FALLOUT)) {
5763 return TRUE;
5764 }
5765 no_disable = FALSE;
5766 }
5767 if (is_extra_caused_by(pextra, EC_MINE)) {
5768 if (gui_options.draw_mines) {
5769 return TRUE;
5770 }
5771 no_disable = FALSE;
5772 }
5773 if (is_extra_caused_by(pextra, EC_RESOURCE)) {
5775 return TRUE;
5776 }
5777 no_disable = FALSE;
5778 }
5779 if (is_extra_removed_by(pextra, ERM_ENTER)) {
5780 if (gui_options.draw_huts) {
5781 return TRUE;
5782 }
5783 no_disable = FALSE;
5784 }
5785 if (is_extra_caused_by(pextra, EC_BASE)) {
5787 return TRUE;
5788 }
5789 no_disable = FALSE;
5790 }
5791 if (is_extra_caused_by(pextra, EC_ROAD)) {
5792 if (gui_options.draw_paths) {
5793 return TRUE;
5794 }
5795 no_disable = FALSE;
5796 }
5797
5798 return no_disable;
5799}
5800
5801/************************************************************************/
5818 struct drawn_sprite *sprs, enum mapview_layer layer,
5819 const struct tile *ptile,
5820 const struct tile_edge *pedge,
5821 const struct tile_corner *pcorner,
5822 const struct unit *punit, const struct city *pcity,
5823 const struct city *citymode,
5824 const struct unit_type *putype)
5825{
5826 int tileno, dir;
5829 struct terrain *tterrain_near[8];
5830 struct terrain *pterrain = NULL;
5831 struct drawn_sprite *save_sprs = sprs;
5832 struct player *owner = NULL;
5833 /* Unit drawing is disabled when the view options are turned off,
5834 * but only where we're drawing on the mapview. */
5835 bool do_draw_unit = (punit && (gui_options.draw_units || !ptile
5837 && unit_is_in_focus(punit))));
5839 && (do_draw_unit
5840 || (pcity && gui_options.draw_cities)
5841 || (ptile && !gui_options.draw_terrain)));
5842
5843 if (citymode) {
5844 int count = 0, i, cx, cy;
5845 const struct tile *const *tiles = NULL;
5846 bool valid = FALSE;
5847
5848 if (ptile) {
5849 tiles = &ptile;
5850 count = 1;
5851 } else if (pcorner) {
5852 tiles = pcorner->tile;
5853 count = NUM_CORNER_TILES;
5854 } else if (pedge) {
5855 tiles = pedge->tile;
5856 count = NUM_EDGE_TILES;
5857 }
5858
5859 for (i = 0; i < count; i++) {
5860 if (tiles[i] && city_base_to_city_map(&cx, &cy, citymode, tiles[i])) {
5861 valid = TRUE;
5862 break;
5863 }
5864 }
5865 if (!valid) {
5866 return 0;
5867 }
5868 }
5869
5870 if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) {
5871 textras = *tile_extras(ptile);
5872 pterrain = tile_terrain(ptile);
5873
5874 if (NULL != pterrain) {
5875 if (layer == LAYER_TERRAIN1
5876 || layer == LAYER_TERRAIN2
5877 || layer == LAYER_TERRAIN3
5878 || layer == LAYER_WATER
5879 || layer == LAYER_ROADS) {
5880 build_tile_data(ptile, pterrain, tterrain_near, textras_near);
5881 }
5882 } else {
5883 log_error("fill_sprite_array() tile (%d,%d) has no terrain!",
5884 TILE_XY(ptile));
5885 }
5886 } else {
5888 }
5889
5890 switch (layer) {
5891 case LAYER_BACKGROUND:
5892 /* Set up background color. */
5894 if (do_draw_unit) {
5896 } else if (pcity && gui_options.draw_cities) {
5897 owner = city_owner(pcity);
5898 }
5899 }
5900 if (owner) {
5902 } else if (ptile && !gui_options.draw_terrain) {
5904 }
5905 break;
5906
5907 case LAYER_TERRAIN1:
5908 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
5909 sprs += fill_terrain_sprite_layer(t, sprs, 0, ptile, pterrain, tterrain_near);
5910 }
5911 break;
5912
5913 case LAYER_DARKNESS:
5914 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
5916 }
5917 break;
5918
5919 case LAYER_TERRAIN2:
5920 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
5921 sprs += fill_terrain_sprite_layer(t, sprs, 1, ptile, pterrain, tterrain_near);
5922 }
5923 break;
5924
5925 case LAYER_TERRAIN3:
5926 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
5928 sprs += fill_terrain_sprite_layer(t, sprs, 2, ptile, pterrain, tterrain_near);
5929 }
5930 break;
5931
5932 case LAYER_WATER:
5933 if (NULL != pterrain) {
5935 && terrain_type_terrain_class(pterrain) == TC_OCEAN) {
5936 for (dir = 0; dir < t->num_cardinal_tileset_dirs; dir++) {
5937 int didx = t->cardinal_tileset_dirs[dir];
5938
5941 int idx = extra_index(priver);
5942
5943 if (BV_ISSET(textras_near[didx], idx)) {
5945 }
5946 }
5948 }
5949 }
5950
5952 pcity);
5953
5957 int idx = extra_index(priver);
5958
5959 if (BV_ISSET(textras, idx)) {
5960 int i;
5961
5962 /* Draw rivers on top of irrigation. */
5963 tileno = 0;
5964 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5966
5968 tileno |= 1 << i;
5969 } else {
5971
5972 if (proad != NULL) {
5973 extra_type_list_iterate(proad->integrators, iextra) {
5975 tileno |= 1 << i;
5976 }
5978 }
5979 }
5980 }
5981
5983 }
5984 }
5986 }
5987 }
5988 break;
5989
5990 case LAYER_ROADS:
5991 if (NULL != pterrain) {
5993 if (is_extra_drawing_enabled(pextra)) {
5994 sprs += fill_road_sprite_array(t, pextra, sprs,
5996 tterrain_near, pcity);
5997 }
6000 if (is_extra_drawing_enabled(pextra)) {
6001 sprs += fill_road_sprite_array(t, pextra, sprs,
6003 tterrain_near, pcity);
6004 }
6007 if (is_extra_drawing_enabled(pextra)) {
6008 sprs += fill_road_sprite_array(t, pextra, sprs,
6010 tterrain_near, pcity);
6011 }
6013 }
6014 break;
6015
6016 case LAYER_SPECIAL1:
6017 if (NULL != pterrain) {
6018 if (ptile) {
6020 if (tile_has_extra(ptile, pextra)
6021 && is_extra_drawing_enabled(pextra)
6022 && t->sprites.extras[extra_index(pextra)].u.bmf.background) {
6023 bool hidden = FALSE;
6024
6025 extra_type_list_iterate(pextra->hiders, phider) {
6027 hidden = TRUE;
6028 break;
6029 }
6031
6032 if (!hidden) {
6034 }
6035 }
6037 }
6038
6040 if (BV_ISSET(textras, extra_index(pextra))
6041 && is_extra_drawing_enabled(pextra)) {
6042 bool hidden = FALSE;
6043
6044 extra_type_list_iterate(pextra->hiders, phider) {
6046 hidden = TRUE;
6047 break;
6048 }
6050
6051 if (!hidden) {
6053 }
6054 }
6056 }
6057 break;
6058
6059 case LAYER_GRID1:
6060 if (t->type == TS_ISOMETRIC) {
6062 punit, pcity, citymode);
6063 }
6064 break;
6065
6066 case LAYER_CITY1:
6067 /* City. Some city sprites are drawn later. */
6068 if (pcity && gui_options.draw_cities) {
6073 }
6074 /* For iso-view the city.wall graphics include the full city, whereas
6075 * for non-iso view they are an overlay on top of the base city
6076 * graphic. */
6077 if (t->type == TS_OVERHEAD || pcity->client.walls <= 0) {
6081 }
6082 if (t->type == TS_ISOMETRIC && pcity->client.walls > 0) {
6083 struct city_sprite *cspr = t->sprites.city.wall[pcity->client.walls - 1];
6084 struct sprite *spr = NULL;
6085
6086 if (cspr != NULL) {
6087 spr = get_city_sprite(cspr, pcity);
6088 }
6089 if (spr == NULL) {
6091 if (cspr != NULL) {
6092 spr = get_city_sprite(cspr, pcity);
6093 }
6094 }
6095
6096 if (spr != NULL) {
6100 }
6101 }
6106 }
6107 if (t->type == TS_OVERHEAD && pcity->client.walls > 0) {
6108 struct city_sprite *cspr = t->sprites.city.wall[pcity->client.walls - 1];
6109 struct sprite *spr = NULL;
6110
6111 if (cspr != NULL) {
6112 spr = get_city_sprite(cspr, pcity);
6113 }
6114 if (spr == NULL) {
6116 if (cspr != NULL) {
6117 spr = get_city_sprite(cspr, pcity);
6118 }
6119 }
6120
6121 if (spr != NULL) {
6123 }
6124 }
6125 if (pcity->client.unhappy) {
6127 }
6128 }
6129 break;
6130
6131 case LAYER_SPECIAL2:
6132 if (NULL != pterrain) {
6133 if (ptile) {
6135 if (tile_has_extra(ptile, pextra)
6136 && is_extra_drawing_enabled(pextra)
6137 && t->sprites.extras[extra_index(pextra)].u.bmf.middleground) {
6138 bool hidden = FALSE;
6139
6140 extra_type_list_iterate(pextra->hiders, phider) {
6142 hidden = TRUE;
6143 break;
6144 }
6146
6147 if (!hidden) {
6149 }
6150 }
6152 }
6153
6155 if (BV_ISSET(textras, extra_index(pextra))
6156 && is_extra_drawing_enabled(pextra)) {
6157 bool hidden = FALSE;
6158
6159 extra_type_list_iterate(pextra->hiders, phider) {
6161 hidden = TRUE;
6162 break;
6163 }
6165
6166 if (!hidden) {
6168 }
6169 }
6171 }
6172 break;
6173
6174 case LAYER_UNIT:
6175 case LAYER_FOCUS_UNIT:
6176 if (do_draw_unit && XOR(layer == LAYER_UNIT, unit_is_in_focus(punit))) {
6177 int stack_count = ptile ? unit_list_size(ptile->units) : 0;
6178 bool backdrop = !pcity;
6179
6180 if (ptile && unit_is_in_focus(punit)
6181 && t->sprites.unit.select[0]) {
6182 /* Special case for drawing the selection rectangle. The blinking
6183 * unit is handled separately, inside get_drawable_unit(). */
6186 }
6187
6188 /* Load more stack number sprites if needed. no_more_stack_sprites guard
6189 * that we don't retry over and over again for every stack,
6190 * when it's not working. */
6191 if (t->sprites.unit.num_stack_sprites < stack_count
6192 && !t->sprites.unit.no_more_stack_sprites) {
6193 t->sprites.unit.stack = fc_realloc(t->sprites.unit.stack,
6194 stack_count * sizeof(struct sprite *));
6195
6196 while (t->sprites.unit.num_stack_sprites < stack_count
6197 && !t->sprites.unit.no_more_stack_sprites) {
6198 struct sprite *spr = load_gfxnumber(t->sprites.unit.num_stack_sprites + 1);
6199
6200 if (spr != NULL) {
6201 t->sprites.unit.stack[t->sprites.unit.num_stack_sprites++] = spr;
6202 } else {
6203 t->sprites.unit.no_more_stack_sprites = TRUE;
6204 t->sprites.unit.stack = fc_realloc(t->sprites.unit.stack,
6205 t->sprites.unit.num_stack_sprites * sizeof(struct sprite *));
6206 }
6207 }
6208 }
6209
6211 } else if (putype != NULL && layer == LAYER_UNIT) {
6212 /* Only the sprite for the unit type. */
6213 /* FIXME: Shouldn't this still get activity and orientation of
6214 * the actual unit? */
6217 }
6218 break;
6219
6220 case LAYER_SPECIAL3:
6221 if (NULL != pterrain) {
6222 if (ptile) {
6223 bool show_flag = FALSE;
6224 struct player *eowner = extra_owner(ptile);
6225
6227 if (is_extra_drawing_enabled(pextra)
6228 && tile_has_extra(ptile, pextra)
6229 && t->sprites.extras[extra_index(pextra)].u.bmf.foreground) {
6230 bool hidden = FALSE;
6231
6232 extra_type_list_iterate(pextra->hiders, phider) {
6234 hidden = TRUE;
6235 break;
6236 }
6238
6239 if (!hidden) {
6240 if (t->sprites.extras[extra_index(pextra)].u.bmf.foreground) {
6242 }
6243 }
6244 }
6246
6247 /* Show base flag. Not part of previous iteration as
6248 * "extras of ESTYLE_3_LAYER" != "bases" */
6249 if (eowner != NULL) {
6251 if (tile_has_extra(ptile, pextra)) {
6252 bool hidden = FALSE;
6253
6254 extra_type_list_iterate(pextra->hiders, phider) {
6256 hidden = TRUE;
6257 break;
6258 }
6260
6261 if (!hidden) {
6262 show_flag = TRUE;
6263 }
6264 }
6266
6267 if (show_flag) {
6271 }
6272 }
6273 }
6274 }
6275 break;
6276
6277 case LAYER_FOG:
6279 break;
6280
6281 case LAYER_CITY2:
6282 /* City size. Drawing this under fog makes it hard to read. */
6284 bool warn = FALSE;
6285 unsigned int size = city_size_get(pcity);
6286
6290 if (10 <= size) {
6292 % 10], FALSE,
6295 if (100 <= size) {
6296 struct sprite *sprite =
6297 t->sprites.city.size_hundreds[(size / 100) % 10];
6298
6299 if (NULL != sprite) {
6303 } else {
6304 warn = TRUE;
6305 }
6306 if (1000 <= size) {
6307 warn = TRUE;
6308 }
6309 }
6310 }
6311
6312 if (warn) {
6313 /* Warn only once by tileset. */
6314 static char last_reported[256] = "";
6315
6316 if (0 != strcmp(last_reported, t->name)) {
6317 log_normal(_("Tileset \"%s\" doesn't support big cities size, "
6318 "such as %d. Size not displayed as expected."),
6319 t->name, size);
6321 }
6322 }
6323 }
6324 break;
6325
6326 case LAYER_GRID2:
6327 if (t->type == TS_OVERHEAD) {
6329 punit, pcity, citymode);
6330 }
6331 break;
6332
6333 case LAYER_OVERLAYS:
6335 if (mapdeco_is_crosshair_set(ptile)) {
6337 }
6338 break;
6339
6340 case LAYER_CITYBAR:
6341 case LAYER_TILELABEL:
6342 /* Nothing. This is just a placeholder. */
6343 break;
6344
6345 case LAYER_GOTO:
6346 if (ptile && goto_is_active()) {
6348 }
6349 break;
6350
6351 case LAYER_WORKERTASK:
6352 if (citymode != NULL && ptile != NULL) {
6354 if (ptask->ptile == ptile) {
6355 switch (ptask->act) {
6356 case ACTIVITY_MINE:
6357 if (ptask->tgt == NULL) {
6358 ADD_SPRITE(t->sprites.unit.plant,
6361 } else {
6365 }
6366 break;
6367 case ACTIVITY_PLANT:
6368 ADD_SPRITE(t->sprites.unit.plant,
6371 break;
6372 case ACTIVITY_IRRIGATE:
6373 if (ptask->tgt == NULL) {
6374 ADD_SPRITE(t->sprites.unit.cultivate,
6377 } else {
6381 }
6382 break;
6383 case ACTIVITY_CULTIVATE:
6384 ADD_SPRITE(t->sprites.unit.cultivate,
6387 break;
6388 case ACTIVITY_GEN_ROAD:
6389 if (ptask->tgt != NULL) {
6393 }
6394 break;
6395 case ACTIVITY_TRANSFORM:
6396 ADD_SPRITE(t->sprites.unit.transform,
6399 break;
6400 case ACTIVITY_CLEAN:
6401 if (ptask->tgt != NULL) {
6405 }
6406 break;
6407 default:
6408 break;
6409 }
6410 }
6412 }
6413 break;
6414
6415 case LAYER_EDITOR:
6416 if (ptile && editor_is_active()) {
6417 if (editor_tile_is_selected(ptile)) {
6420 }
6421
6422 if (NULL != map_startpos_get(ptile)) {
6423 /* FIXME: Use a more representative sprite. */
6425 }
6426 }
6427 break;
6428
6429 case LAYER_INFRAWORK:
6430 if (ptile != NULL) {
6431 if (ptile->placing != NULL) {
6432 const int id = extra_index(ptile->placing);
6433
6434 if (t->sprites.extras[id].activity != NULL) {
6438 }
6439 }
6440 if (client_infratile() == ptile) {
6442 }
6443 }
6444 break;
6445
6446 case LAYER_COUNT:
6448 break;
6449 }
6450
6451 return sprs - save_sprs;
6452}
6453
6454/************************************************************************/
6458void tileset_setup_city_tiles(struct tileset *t, int style)
6459{
6460 const char *style_name = city_style_rule_name(style);
6461
6462 if (style == game.control.num_city_styles - 1) {
6463 int i;
6464
6465 /* Free old sprites */
6467
6468 for (i = 0; i < NUM_WALL_TYPES; i++) {
6470 t->sprites.city.wall[i] = NULL;
6471 }
6474
6476
6477 t->sprites.city.tile = load_city_sprite(t, "city");
6478
6479 for (i = 0; i < NUM_WALL_TYPES; i++) {
6480 char buffer[256];
6481
6482 fc_snprintf(buffer, sizeof(buffer), "bldg_%d", i);
6483 t->sprites.city.wall[i] = load_city_sprite(t, buffer);
6484 }
6485 t->sprites.city.single_wall = load_city_sprite(t, "wall");
6486
6487 t->sprites.city.occupied = load_city_sprite(t, "occupied");
6488 }
6489
6491 &t->sprites.style_citizen_sets.sets[style],
6492 city_styles[style].citizens_graphic,
6493 style_name, FALSE);
6496 &t->sprites.style_citizen_sets.sets[style],
6497 sp,
6498 city_styles[style].citizens_graphic,
6499 style_name, FALSE);
6501
6502 if (style == game.control.num_city_styles - 1) {
6503 for (style = 0; style < game.control.num_city_styles; style++) {
6504 if (t->sprites.city.tile->styles[style].land_num_thresholds == 0) {
6506 _("City style \"%s\": no city graphics."),
6507 city_style_rule_name(style));
6508 }
6509 if (t->sprites.city.occupied->styles[style].land_num_thresholds == 0) {
6511 _("City style \"%s\": no occupied graphics."),
6512 city_style_rule_name(style));
6513 }
6514 }
6515 }
6516}
6517
6518/************************************************************************/
6524{
6525 if (t->sprites.unit.select[0]) {
6526 return 0.1;
6527 } else {
6528 return 0.5;
6529 }
6530}
6531
6532/************************************************************************/
6537{
6538 focus_unit_state = 0;
6539}
6540
6541/************************************************************************/
6545{
6546 if (!t->sprites.unit.select[0]) {
6548 }
6549}
6550
6551/************************************************************************/
6556{
6558 if (t->sprites.unit.select[0]) {
6560 } else {
6561 focus_unit_state %= 2;
6562 }
6563}
6564
6565/************************************************************************/
6568struct unit *get_drawable_unit(const struct tileset *t,
6569 struct tile *ptile,
6570 const struct city *citymode)
6571{
6572 struct unit *punit = find_visible_unit(ptile);
6573
6574 if (punit == NULL) {
6575 return NULL;
6576 }
6577
6579 return NULL;
6580 }
6581
6583 || t->sprites.unit.select[0] || focus_unit_state == 0) {
6584 return punit;
6585 } else {
6586 return NULL;
6587 }
6588}
6589
6590/************************************************************************/
6594static void unload_all_sprites(struct tileset *t)
6595{
6596 if (t->sprite_hash) {
6598 while (ss->ref_count > 0) {
6600 }
6602 }
6603}
6604
6605/************************************************************************/
6609{
6610 int i;
6611
6612 log_debug("tileset_free_tiles()");
6613
6615
6617 t->sprites.city.tile = NULL;
6618
6619 for (i = 0; i < NUM_WALL_TYPES; i++) {
6621 t->sprites.city.wall[i] = NULL;
6622 }
6625
6628
6629 if (t->sprite_hash) {
6631 t->sprite_hash = NULL;
6632 }
6633
6634 if (t->sprites.style_citizen_sets.sets != NULL) {
6637 }
6638
6641 if (ss->file) {
6642 free(ss->file);
6643 }
6644 fc_assert(ss->sprite == NULL);
6645 free(ss);
6647
6650 free(sf->file_name);
6651 if (sf->big_sprite) {
6652 free_sprite(sf->big_sprite);
6653 sf->big_sprite = NULL;
6654 }
6655 free(sf);
6657
6662
6667
6668 if (t->sprites.tx.fullfog) {
6669 free(t->sprites.tx.fullfog);
6670 t->sprites.tx.fullfog = NULL;
6671 }
6672
6678
6679 /* Index 0 is 'occupied' or 'default' stack sprite */
6680 for (i = 1; i < t->sprites.unit.num_stack_sprites - 1; i++) {
6681 free_sprite(t->sprites.unit.stack[i]);
6682 }
6683 t->sprites.unit.num_stack_sprites = 0;
6684 if (t->sprites.unit.stack != NULL) {
6685 free(t->sprites.unit.stack);
6686 t->sprites.unit.stack = NULL;
6687 }
6688
6690}
6691
6692/************************************************************************/
6695struct sprite *get_spaceship_sprite(const struct tileset *t,
6696 enum spaceship_part part)
6697{
6698 return t->sprites.spaceship[part];
6699}
6700
6701/************************************************************************/
6704static inline const struct citizen_graphic *
6707{
6708 fc_assert_ret_val(set != NULL, NULL);
6709
6710 if (type < CITIZEN_SPECIALIST) {
6712 return &set->citizen[type];
6713 } else {
6715 return &set->specialist[type - CITIZEN_SPECIALIST];
6716 }
6717}
6718
6719/************************************************************************/
6726struct sprite *get_citizen_sprite(const struct tileset *t,
6728 int citizen_index,
6729 const struct city *pcity)
6730{
6731 const struct citizen_graphic *graphic = NULL;
6733
6734 if (pcity != NULL) {
6735 int style = style_of_city(pcity);
6736
6738
6740 type);
6741
6743 }
6744
6745 if (graphic == NULL || graphic->count == 0) {
6746 /* Fall back to default sprites */
6748 }
6749
6750 if (graphic->count == 0) {
6751 return NULL;
6752 }
6753
6754 return graphic->sprite[gfx_index % graphic->count];
6755}
6756
6757/************************************************************************/
6760struct sprite *get_nation_flag_sprite(const struct tileset *t,
6761 const struct nation_type *pnation)
6762{
6763 return t->sprites.nation_flag.p[nation_index(pnation)];
6764}
6765
6766/************************************************************************/
6770 const struct nation_type *pnation)
6771{
6772 return t->sprites.nation_shield.p[nation_index(pnation)];
6773}
6774
6775/************************************************************************/
6778struct sprite *get_tech_sprite(const struct tileset *t, Tech_type_id tech)
6779{
6780 fc_assert_ret_val(0 <= tech && tech < advance_count(), NULL);
6781 return t->sprites.tech[tech];
6782}
6783
6784/************************************************************************/
6787struct sprite *get_building_sprite(const struct tileset *t,
6788 const struct impr_type *pimprove)
6789{
6790 fc_assert_ret_val(NULL != pimprove, NULL);
6791 return t->sprites.building[improvement_index(pimprove)];
6792}
6793
6794/************************************************************************/
6797struct sprite *get_government_sprite(const struct tileset *t,
6798 const struct government *gov)
6799{
6800 fc_assert_ret_val(NULL != gov, NULL);
6801 return t->sprites.government[government_index(gov)];
6802}
6803
6804/************************************************************************/
6809struct sprite *get_unittype_sprite(const struct tileset *t,
6810 const struct unit_type *punittype,
6811 enum unit_activity activity,
6812 enum direction8 facing)
6813{
6814 int uidx = utype_index(punittype);
6815 bool icon = !direction8_is_valid(facing);
6816
6817 if (activity >= ACTIVITY_LAST) {
6818 activity = ACTIVITY_IDLE;
6819 }
6820
6822
6823 if (!direction8_is_valid(facing) || !is_valid_dir(facing)) {
6824 facing = t->unit_default_orientation;
6825 /* May not have been specified, but it only matters if we don't
6826 * turn out to have an icon sprite */
6827 }
6828
6829 if (t->sprites.units.icon[uidx][activity] != NULL
6830 && (icon || t->sprites.units.facing[uidx][facing][activity] == NULL)) {
6831 /* Has icon sprite, and we prefer to (or must) use it */
6832 return t->sprites.units.icon[uidx][activity];
6833 } else if (t->sprites.units.icon[uidx][ACTIVITY_IDLE] != NULL
6834 && (icon
6835 || t->sprites.units.facing[uidx][facing][ACTIVITY_IDLE] == NULL)) {
6836 /* Has icon sprite, and we prefer to (or must) use it */
6837 return t->sprites.units.icon[uidx][ACTIVITY_IDLE];
6838 } else {
6839 /* We should have a valid orientation by now. Failure to have either
6840 * an icon sprite or default orientation should have been caught at
6841 * tileset load. */
6843
6844 if (t->sprites.units.facing[uidx][facing][activity] == NULL) {
6845 return t->sprites.units.facing[uidx][facing][ACTIVITY_IDLE];
6846 }
6847
6848 return t->sprites.units.facing[uidx][facing][activity];
6849 }
6850}
6851
6852/************************************************************************/
6855struct sprite *get_sample_city_sprite(const struct tileset *t,
6856 int style_idx)
6857{
6858 int num_thresholds =
6859 t->sprites.city.tile->styles[style_idx].land_num_thresholds;
6860
6861 if (num_thresholds == 0) {
6862 return NULL;
6863 } else {
6864 return (t->sprites.city.tile->styles[style_idx]
6865 .land_thresholds[num_thresholds - 1].sprite);
6866 }
6867}
6868
6869/************************************************************************/
6872struct sprite *get_arrow_sprite(const struct tileset *t,
6873 enum arrow_type arrow)
6874{
6875 fc_assert_ret_val(arrow >= 0 && arrow < ARROW_LAST, NULL);
6876
6877 return t->sprites.arrow[arrow];
6878}
6879
6880/************************************************************************/
6884{
6885 switch (otype) {
6886 case O_SCIENCE:
6887 return t->sprites.tax_science;
6888 case O_GOLD:
6889 return t->sprites.tax_gold;
6890 case O_LUXURY:
6891 return t->sprites.tax_luxury;
6892 case O_TRADE:
6893 case O_FOOD:
6894 case O_SHIELD:
6895 case O_LAST:
6896 break;
6897 }
6898 return NULL;
6899}
6900
6901/************************************************************************/
6904struct sprite *get_event_sprite(const struct tileset *t, enum event_type event)
6905{
6906 return t->sprites.events[event];
6907}
6908
6909/************************************************************************/
6913struct sprite *get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
6914{
6915 return t->sprites.treaty_thumb[on_off ? 1 : 0];
6916}
6917
6918/************************************************************************/
6923 tileset *t)
6924{
6925 return &t->sprites.explode.unit;
6926}
6927
6928/************************************************************************/
6934{
6935 return t->sprites.explode.nuke;
6936}
6937
6938/************************************************************************/
6941const struct citybar_sprites *get_citybar_sprites(const struct tileset *t)
6942{
6944 return &t->sprites.citybar;
6945 } else {
6946 return NULL;
6947 }
6948}
6949
6950/************************************************************************/
6953const struct editor_sprites *get_editor_sprites(const struct tileset *t)
6954{
6955 return &t->sprites.editor;
6956}
6957
6958/************************************************************************/
6964struct sprite *get_cursor_sprite(const struct tileset *t,
6965 enum cursor_type cursor,
6966 int *hot_x, int *hot_y, int frame)
6967{
6968 *hot_x = t->sprites.cursor[cursor].hot_x;
6969 *hot_y = t->sprites.cursor[cursor].hot_y;
6970
6971 return t->sprites.cursor[cursor].frame[frame];
6972}
6973
6974/************************************************************************/
6983struct sprite *get_icon_sprite(const struct tileset *t, enum icon_type icon)
6984{
6985 return t->sprites.icon[icon];
6986}
6987
6988/************************************************************************/
6995{
6996 return t->sprites.user.attention;
6997}
6998
6999/************************************************************************/
7003struct sprite *get_indicator_sprite(const struct tileset *t,
7004 enum indicator_type indicator,
7005 int idx)
7006{
7007 idx = CLIP(0, idx, NUM_TILES_PROGRESS - 1);
7008
7009 fc_assert_ret_val(indicator >= 0 && indicator < INDICATOR_COUNT, NULL);
7010
7011 return t->sprites.indicator[indicator][idx];
7012}
7013
7014/************************************************************************/
7021 const struct unit *punit,
7022 int happy_cost)
7023{
7024 const int unhappy = CLIP(0, happy_cost, MAX_NUM_UPKEEP_SPRITES+1);
7025
7026 if (unhappy > 0) {
7027 return t->sprites.upkeep.unhappy[unhappy - 1];
7028 } else {
7029 return NULL;
7030 }
7031}
7032
7033/************************************************************************/
7039struct sprite *get_unit_upkeep_sprite(const struct tileset *t,
7041 const struct unit *punit,
7042 const int *upkeep_cost)
7043{
7044 const int upkeep = CLIP(0, upkeep_cost[otype], MAX_NUM_UPKEEP_SPRITES + 1);
7045
7046 if (upkeep > 0) {
7047 return t->sprites.upkeep.output[otype][upkeep - 1];
7048 } else {
7049 return NULL;
7050 }
7051}
7052
7053/************************************************************************/
7057struct sprite *get_basic_fog_sprite(const struct tileset *t)
7058{
7059 return t->sprites.tx.fog;
7060}
7061
7062/************************************************************************/
7065struct color_system *get_color_system(const struct tileset *t)
7066{
7067 return t->color_system;
7068}
7069
7070/************************************************************************/
7074{
7075 char *default_theme_name = NULL;
7076 size_t default_theme_name_sz = 0;
7077 int i;
7078
7079 switch (get_gui_type()) {
7080 case GUI_GTK3_22:
7083 break;
7084 case GUI_GTK4:
7087 break;
7088 case GUI_SDL2:
7091 break;
7092 case GUI_SDL3:
7095 break;
7096 case GUI_STUB:
7097 case GUI_QT:
7098 case GUI_SDL:
7099 case GUI_WEB:
7100 case GUI_GTK2:
7101 case GUI_GTK3:
7102 break;
7103 }
7104
7106 /* Theme is not supported by this client. */
7107 return;
7108 }
7109
7110 for (i = 0; i < t->num_preferred_themes; i++) {
7113 log_debug("trying theme \"%s\".", t->preferred_themes[i]);
7114 if (load_theme(t->preferred_themes[i])) {
7117 return;
7118 }
7119 }
7120 }
7121 }
7122 log_verbose("The tileset doesn't specify preferred themes or none of its "
7123 "preferred themes can be used. Using system default.");
7125}
7126
7127/************************************************************************/
7130void tileset_init(struct tileset *t)
7131{
7132 int wi;
7133
7134 /* We currently have no city sprites loaded. */
7135 t->sprites.city.tile = NULL;
7136
7137 for (wi = 0; wi < NUM_WALL_TYPES; wi++) {
7138 t->sprites.city.wall[wi] = NULL;
7139 }
7141
7143
7144 t->sprites.background.color = NULL;
7145 t->sprites.background.graphic = NULL;
7146
7147 player_slots_iterate(pslot) {
7148 int edge, j, id = player_slot_index(pslot);
7149
7150 for (edge = 0; edge < EDGE_COUNT; edge++) {
7151 for (j = 0; j < 2; j++) {
7153 }
7154 }
7155
7156 t->sprites.player[id].color = NULL;
7159
7160 t->max_upkeep_height = 0;
7161}
7162
7163/************************************************************************/
7172 struct drawn_sprite *sprs,
7173 int layer,
7174 struct terrain *pterrain)
7175{
7176 struct drawn_sprite *save_sprs = sprs;
7177 struct drawing_data *draw = t->sprites.drawing[terrain_index(pterrain)];
7178
7179 struct terrain *tterrain_near[8];
7181
7182 struct tile dummy_tile; /* :( */
7183
7184 int i;
7185
7186
7187 memset(&dummy_tile, 0, sizeof(struct tile));
7188
7189 for (i = 0; i < 8; i++) {
7190 tterrain_near[i] = pterrain;
7192 }
7193
7194 i = draw->is_reversed ? draw->num_layers - layer - 1 : layer;
7196 pterrain, tterrain_near, draw);
7197
7198 return sprs - save_sprs;
7199}
7200
7201/************************************************************************/
7205 struct drawn_sprite *sprs,
7206 const struct extra_type *pextra)
7207{
7208 int idx = extra_index(pextra);
7209 struct drawn_sprite *saved_sprs = sprs;
7210
7211 switch (t->sprites.extras[idx].extrastyle) {
7212 case ESTYLE_SINGLE1:
7213 case ESTYLE_SINGLE2:
7215 break;
7216 case ESTYLE_CARDINALS:
7218 break;
7222 case ESTYLE_RIVER:
7223 return fill_basic_road_sprite_array(t, sprs, pextra);
7224 case ESTYLE_3LAYER:
7225 return fill_basic_base_sprite_array(t, sprs, pextra);
7226 case ESTYLE_COUNT:
7228 break;
7229 }
7230
7231 return sprs - saved_sprs;
7232}
7233
7234/************************************************************************/
7240 struct drawn_sprite *sprs,
7241 const struct extra_type *pextra)
7242{
7243 struct drawn_sprite *saved_sprs = sprs;
7244 int idx;
7245 int i;
7246 enum extrastyle_id extrastyle;
7247
7248 if (!t || !sprs || !pextra) {
7249 return 0;
7250 }
7251
7252 idx = extra_index(pextra);
7253
7254 if (!(0 <= idx && idx < game.control.num_extra_types)) {
7255 return 0;
7256 }
7257
7258 extrastyle = t->sprites.extras[idx].extrastyle;
7259
7260 if (extrastyle == ESTYLE_RIVER) {
7262 } else {
7263 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
7264 if (!t->valid_tileset_dirs[i]) {
7265 continue;
7266 }
7267 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
7269 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
7270 if ((i % 2) == 0) {
7271 ADD_SPRITE_SIMPLE(t->sprites.extras[idx].u.road.ru.combo.even[1 << (i / 2)]);
7272 }
7273 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
7274 ADD_SPRITE_SIMPLE(t->sprites.extras[idx].u.road.ru.total[1 << i]);
7275 }
7276 }
7277 }
7278
7279 return sprs - saved_sprs;
7280}
7281
7282/************************************************************************/
7288 struct drawn_sprite *sprs,
7289 const struct extra_type *pextra)
7290{
7291 struct drawn_sprite *saved_sprs = sprs;
7292 int idx;
7293
7294 if (!t || !sprs || !pextra) {
7295 return 0;
7296 }
7297
7298 idx = extra_index(pextra);
7299
7300 if (!(0 <= idx && idx < game.control.num_extra_types)) {
7301 return 0;
7302 }
7303
7304#define ADD_SPRITE_IF_NOT_NULL(x) do {\
7305 if ((x) != NULL) {\
7306 ADD_SPRITE_FULL(x);\
7307 }\
7308} while (FALSE)
7309
7310 /* Corresponds to LAYER_SPECIAL{1,2,3} order. */
7314
7315#undef ADD_SPRITE_IF_NOT_NULL
7316
7317 return sprs - saved_sprs;
7318}
7319
7320/************************************************************************/
7323enum mapview_layer tileset_get_layer(const struct tileset *t, int n)
7324{
7326 return t->layer_order[n];
7327}
7328
7329/************************************************************************/
7333 enum layer_category cat)
7334{
7335 switch (layer) {
7336 case LAYER_BACKGROUND:
7337 case LAYER_TERRAIN1:
7338 case LAYER_DARKNESS:
7339 case LAYER_TERRAIN2:
7340 case LAYER_TERRAIN3:
7341 case LAYER_WATER:
7342 case LAYER_ROADS:
7343 case LAYER_SPECIAL1:
7344 case LAYER_SPECIAL2:
7345 case LAYER_SPECIAL3:
7347 case LAYER_CITY1:
7348 case LAYER_CITY2:
7349 return cat == LAYER_CATEGORY_CITY;
7350 case LAYER_UNIT:
7351 case LAYER_FOCUS_UNIT:
7352 return cat == LAYER_CATEGORY_UNIT;
7353 case LAYER_GRID1:
7354 case LAYER_FOG:
7355 case LAYER_GRID2:
7356 case LAYER_OVERLAYS:
7357 case LAYER_TILELABEL:
7358 case LAYER_CITYBAR:
7359 case LAYER_GOTO:
7360 case LAYER_WORKERTASK:
7361 case LAYER_EDITOR:
7362 case LAYER_INFRAWORK:
7363 return FALSE;
7364 case LAYER_COUNT:
7365 break; /* and fail below */
7366 }
7367
7368 fc_assert_msg(FALSE, "Unknown layer category: %d", cat);
7369 return FALSE;
7370}
7371
7372/************************************************************************/
7375void tileset_player_init(struct tileset *t, struct player *pplayer)
7376{
7377 int plrid, i, j;
7378 struct sprite *color;
7379
7380 fc_assert_ret(pplayer != NULL);
7381
7382 plrid = player_index(pplayer);
7383 fc_assert_ret(plrid >= 0);
7385
7386 /* Free all data before recreating it. */
7388
7389 if (player_has_color(pplayer)) {
7391 = create_plr_sprite(get_player_color(t, pplayer));
7392 } else {
7393 /* XXX: if player hasn't been assigned a color, perhaps there's no
7394 * point proceeding with an arbitrary color; this should only happen
7395 * in pregame. Probably blank sprites would be better. */
7396
7397 fc_assert_ret(t->sprites.background.color != NULL);
7398
7399 color = t->sprites.background.color;
7400 }
7401
7403 = crop_sprite(color, 0, 0,
7405 t->sprites.mask.tile, 0, 0, t->scale, FALSE);
7406
7407 for (i = 0; i < EDGE_COUNT; i++) {
7408 for (j = 0; j < 2; j++) {
7409 struct sprite *s;
7410
7411 if (color && t->sprites.grid.borders[i][j]) {
7412 s = crop_sprite(color, 0, 0,
7414 t->sprites.grid.borders[i][j], 0, 0, 1.0f, FALSE);
7415 } else {
7416 s = t->sprites.grid.borders[i][j];
7417 }
7418 t->sprites.player[plrid].grid_borders[i][j] = s;
7419 }
7420 }
7421}
7422
7423/************************************************************************/
7426static void tileset_player_free(struct tileset *t, int plrid)
7427{
7428 int i, j;
7429
7430 fc_assert_ret(plrid >= 0);
7432
7433 if (t->sprites.player[plrid].color) {
7436 }
7437 if (t->sprites.player[plrid].background) {
7440 }
7441
7442 for (i = 0; i < EDGE_COUNT; i++) {
7443 for (j = 0; j < 2; j++) {
7444 if (t->sprites.player[plrid].grid_borders[i][j]) {
7447 }
7448 }
7449 }
7450}
7451
7452/************************************************************************/
7456{
7457 /* Free all data before recreating it. */
7459
7460 /* Generate background color */
7461 t->sprites.background.color
7463
7464 /* Chop up and build the background graphics. */
7465 t->sprites.background.graphic
7466 = crop_sprite(t->sprites.background.color, 0, 0,
7468 t->sprites.mask.tile, 0, 0, t->scale, FALSE);
7469}
7470
7471/************************************************************************/
7475{
7476 if (t->sprites.background.color) {
7477 free_sprite(t->sprites.background.color);
7478 t->sprites.background.color = NULL;
7479 }
7480
7481 if (t->sprites.background.graphic) {
7482 free_sprite(t->sprites.background.graphic);
7483 t->sprites.background.graphic = NULL;
7484 }
7485}
7486
7487/************************************************************************/
7491{
7492 int i;
7493
7494 for (i = 0; i < ESTYLE_COUNT; i++) {
7495 if (t->style_lists[i] != NULL) {
7498 }
7499 }
7500
7501 if (t->flagged_bases_list != NULL) {
7504 }
7505
7506 if (t->sprites.style_citizen_sets.sets != NULL) {
7508 }
7509
7512 * sizeof(t->sprites.style_citizen_sets.sets[0]));
7513}
7514
7515/************************************************************************/
7519{
7520 return !tileset_update;
7521}
7522
7523/************************************************************************/
7526const char *tileset_name_get(struct tileset *t)
7527{
7528 return t->given_name;
7529}
7530
7531/************************************************************************/
7534const char *tileset_version(struct tileset *t)
7535{
7536 return t->version;
7537}
7538
7539/************************************************************************/
7542const char *tileset_summary(struct tileset *t)
7543{
7544 return t->summary;
7545}
7546
7547/************************************************************************/
7550const char *tileset_description(struct tileset *t)
7551{
7552 return t->description;
7553}
7554
7555/************************************************************************/
7559{
7560 return t->for_ruleset;
7561}
7562
7563/************************************************************************/
7567{
7568 return t->ts_topo_idx;
7569}
7570
7571/************************************************************************/
7575{
7576 return t->svg_height;
7577}
#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:1629
bool city_can_be_built_here(const struct tile *ptile, const struct unit *punit, bool hut_test)
Definition city.c:1478
const char * city_style_rule_name(const int style)
Definition city.c:1757
const char * get_output_identifier(Output_type_id output)
Definition city.c:618
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:280
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:263
static const struct city struct citystyle * city_styles
Definition city.c:83
int city_tile_output(const struct city *pcity, const struct tile *ptile, bool is_celebrating, Output_type_id otype)
Definition city.c:1274
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
Definition city.c:1447
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:833
#define city_owner(_pcity_)
Definition city.h:563
#define MAX_CITY_SIZE
Definition city.h:106
#define output_type_iterate_end
Definition city.h:839
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:74
bool unit_is_in_focus(const struct unit *punit)
Definition control.c:383
bool should_ask_server_for_actions(const struct unit *punit)
Definition control.c:334
struct unit_list * get_units_in_focus(void)
Definition control.c:177
struct unit * find_visible_unit(struct tile *ptile)
Definition control.c:804
#define log_deprecation(message,...)
static void road(QVariant data1, QVariant data2)
Definition dialogs.cpp:2910
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:346
bool editor_tile_is_selected(const struct tile *ptile)
Definition editor.c:1117
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:474
#define MAX_NUM_ITEMS
Definition fc_types.h:40
int Tech_type_id
Definition fc_types.h:380
#define SP_MAX
Definition fc_types.h:412
int Specialist_type_id
Definition fc_types.h:378
#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:1038
enum output_type_id Output_type_id
Definition fc_types.h:381
#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:120
#define G_LAST
Definition government.h:48
#define governments_iterate_end
Definition government.h:123
struct city * owner
Definition citydlg.c:220
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:2099
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:710
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:331
#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:6551
const char * option_str_get(const struct option *poption)
Definition options.c:892
int option_get_cb_data(const struct option *poption)
Definition options.c:786
struct client_options gui_options
Definition options.c:71
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:1929
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
struct city_sprite::@228 * styles
int land_num_thresholds
Definition tilespec.c:208
int num_styles
Definition tilespec.c:211
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:117
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:57
char graphic_str[MAX_LEN_NAME]
Definition government.h:56
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::@245::@247::@248::@249 combo
struct sprite * graphic
Definition tilespec.c:404
struct sprite * tax_gold
Definition tilespec.c:248
struct sprite * government[G_LAST]
Definition tilespec.c:260
union named_sprites::@239::@245 u
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 named_sprites::@239 extras[MAX_EXTRA_TYPES]
struct named_sprites::@239::@245::@247 road
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 named_sprites::@239::@245::@246 bmf
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::@238 tx
struct sprite * nonnative
Definition tilespec.c:394
struct sprite * plant
Definition tilespec.c:296
bool no_more_stack_sprites
Definition tilespec.c:284
struct named_sprites::@229 mask
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 named_sprites::@232 explode
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 path
struct named_sprites::@240 grid
struct sprite * waypoint
Definition tilespec.c:341
struct sprite * pillage
Definition tilespec.c:297
struct named_sprites::@241 colors
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 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 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 sprite * total[MAX_INDEX_VALID]
Definition tilespec.c:382
struct sprite * action_decision_want
Definition tilespec.c:306
struct sprite * unhappy[MAX_NUM_UPKEEP_SPRITES]
Definition tilespec.c:311
struct named_sprites::@231 cursor[CURSOR_LAST]
struct sprite_vector worked_tile_overlay
Definition tilespec.c:329
struct sprite * corner[8]
Definition tilespec.c:371
struct sprite * darkness[MAX_INDEX_CARDINAL]
Definition tilespec.c:351
struct named_sprites::@235 city
struct sprite * tax_science
Definition tilespec.c:248
struct sprite * icon[ICON_COUNT]
Definition tilespec.c:243
struct sprite * specific
Definition tilespec.c:336
struct sprite * odd[MAX_INDEX_HALF]
Definition tilespec.c:379
struct named_sprites::@236::@244 s[GTS_COUNT]
struct sprite * color
Definition tilespec.c:403
union named_sprites::@239::@245::@247::@248 ru
struct sprite * unavailable
Definition tilespec.c:393
struct sprite * worked_tile
Definition tilespec.c:254
struct river_sprites rivers
Definition tilespec.c:383
struct named_sprites::@234 upkeep
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 sprite * convert
Definition tilespec.c:304
struct sprite * worked[EDGE_COUNT]
Definition tilespec.c:392
struct sprite_vector overlays
Definition tilespec.c:400
struct named_sprites::@243 player[MAX_NUM_PLAYER_SLOTS]
struct editor_sprites editor
Definition tilespec.c:333
struct sprite * size_hundreds[NUM_TILES_DIGITS]
Definition tilespec.c:320
struct sprite * activity
Definition tilespec.c:354
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
struct named_sprites::@230 units
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 named_sprites::@237 user
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:189
#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:114
@ 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:110
#define TILE_XY(ptile)
Definition tile.h:43
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:120
#define tile_has_extra(ptile, pextra)
Definition tile.h:147
#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:4547
struct sprite * get_government_sprite(const struct tileset *t, const struct government *gov)
Definition tilespec.c:6797
void tileset_load_tiles(struct tileset *t)
Definition tilespec.c:3632
struct sprite * get_nuke_explode_sprite(const struct tileset *t)
Definition tilespec.c:6933
#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:6787
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:5682
#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:6568
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:6994
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:3810
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:7574
#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:4482
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:3039
void tileset_setup_government(struct tileset *t, struct government *gov)
Definition tilespec.c:4423
#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:4473
void tileset_setup_specialist_type_default_set(struct tileset *t, Specialist_type_id id)
Definition tilespec.c:2895
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:7057
static enum direction8 dir_by_tileset_name(const char *str)
Definition tilespec.c:1012
#define ADD_SPRITE_SIMPLE(s)
Definition tilespec.c:4504
static int fill_basic_road_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7239
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:4566
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:3753
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:5037
int fill_basic_extra_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7204
#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:7039
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:4157
static const char direction4letters[4]
Definition tilespec.c:141
void tileset_player_init(struct tileset *t, struct player *pplayer)
Definition tilespec.c:7375
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:6913
bool unit_drawn_with_city_outline(const struct unit *punit, bool check_focus)
Definition tilespec.c:5515
#define MAX_INDEX_HALF
Definition tilespec.c:109
double get_focus_unit_toggle_timeout(const struct tileset *t)
Definition tilespec.c:6523
#define SET_SPRITE_ALT_OPT(field, tag, alt)
Definition tilespec.c:2885
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:5199
#define TILE_SECTION_PREFIX
Definition tilespec.c:105
static struct city_sprite * load_city_sprite(struct tileset *t, const char *tag)
Definition tilespec.c:3116
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:6608
void tileset_setup_impr_type(struct tileset *t, struct impr_type *pimprove)
Definition tilespec.c:3844
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:2832
const struct sprite_vector * get_unit_explode_animation(const struct tileset *t)
Definition tilespec.c:6922
#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:3075
static void unload_all_sprites(struct tileset *t)
Definition tilespec.c:6594
static const char * dir_get_tileset_name(enum direction8 dir)
Definition tilespec.c:985
#define SET_SPRITE_UNSCALED(field, tag)
Definition tilespec.c:2858
void tileset_background_init(struct tileset *t)
Definition tilespec.c:7455
void tileset_setup_tech_type(struct tileset *t, struct advance *padvance)
Definition tilespec.c:3860
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:5470
static void unload_sprite(struct tileset *t, const char *tag_name)
Definition tilespec.c:2808
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:5406
#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:4515
static void tileset_player_free(struct tileset *t, int plrid)
Definition tilespec.c:7426
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:7332
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:5532
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:7073
#define FULL_TILE_X_OFFSET
Definition tilespec.c:4494
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:6458
struct sprite * get_nation_shield_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6769
const char * tileset_description(struct tileset *t)
Definition tilespec.c:7550
#define SET_GOTO_TURN_SPRITE(state, state_name, factor, factor_name)
void tileset_background_free(struct tileset *t)
Definition tilespec.c:7474
#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:6904
void toggle_focus_unit_state(struct tileset *t)
Definition tilespec.c:6555
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:6544
static int tileset_upkeep_height(const struct tileset *t)
Definition tilespec.c:850
const char * tileset_summary(struct tileset *t)
Definition tilespec.c:7542
struct sprite * get_icon_sprite(const struct tileset *t, enum icon_type icon)
Definition tilespec.c:6983
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:4495
struct sprite * get_indicator_sprite(const struct tileset *t, enum indicator_type indicator, int idx)
Definition tilespec.c:7003
struct sprite * get_sample_city_sprite(const struct tileset *t, int style_idx)
Definition tilespec.c:6855
#define ADD_SPRITE_FULL(s)
Definition tilespec.c:4505
void tileset_setup_extra(struct tileset *t, struct extra_type *pextra)
Definition tilespec.c:3879
int focus_unit_state
Definition tilespec.c:570
void tileset_init(struct tileset *t)
Definition tilespec.c:7130
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:5079
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:7171
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:2849
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:4754
static bool is_extra_drawing_enabled(struct extra_type *pextra)
Definition tilespec.c:5750
struct sprite * get_spaceship_sprite(const struct tileset *t, enum spaceship_part part)
Definition tilespec.c:6695
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:6964
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:7065
int tileset_hex_height(const struct tileset *t)
Definition tilespec.c:730
void reset_focus_unit_state(struct tileset *t)
Definition tilespec.c:6536
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:2989
bool tileset_is_fully_loaded(void)
Definition tilespec.c:7518
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:5159
const struct citybar_sprites * get_citybar_sprites(const struct tileset *t)
Definition tilespec.c:6941
static bool is_cardinal_tileset_dir(const struct tileset *t, enum direction8 dir)
Definition tilespec.c:1048
#define SET_SPRITE(field, tag)
Definition tilespec.c:2839
static void tileset_lookup_sprite_tags(struct tileset *t)
Definition tilespec.c:3164
struct sprite * get_arrow_sprite(const struct tileset *t, enum arrow_type arrow)
Definition tilespec.c:6872
struct sprite * get_unit_unhappy_sprite(const struct tileset *t, const struct unit *punit, int happy_cost)
Definition tilespec.c:7020
#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:7287
static void tileset_setup_base(struct tileset *t, const struct extra_type *pextra, const char *tag)
Definition tilespec.c:4119
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:4805
void finish_loading_sprites(struct tileset *t)
Definition tilespec.c:3616
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:3643
#define SET_EDITOR_SPRITE(x)
#define SET_SPRITE_ALT(field, tag, alt)
Definition tilespec.c:2868
#define SET_SPRITE_OPT(field, tag)
Definition tilespec.c:2882
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:2905
static bool load_river_sprites(struct tileset *t, struct river_sprites *store, const char *tag_pfx)
Definition tilespec.c:3582
const char * tileset_name_get(struct tileset *t)
Definition tilespec.c:7526
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:6705
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:5817
#define ADD_SPRITE(s, draw_fog, x_offset, y_offset)
Definition tilespec.c:4497
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:6883
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:3689
struct sprite * get_citizen_sprite(const struct tileset *t, enum citizen_category type, int citizen_index, const struct city *pcity)
Definition tilespec.c:6726
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:5253
const char * tileset_version(struct tileset *t)
Definition tilespec.c:7534
static void free_city_sprite(struct city_sprite *city_sprite)
Definition tilespec.c:3144
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:6809
char * tileset_what_ruleset(struct tileset *t)
Definition tilespec.c:7558
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:6760
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:2998
static void tileset_setup_road(struct tileset *t, struct extra_type *pextra, const char *tag)
Definition tilespec.c:4011
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:6778
#define MATCH(dir)
static int get_irrigation_index(const struct tileset *t, struct extra_type *pextra, bv_extras *textras_near)
Definition tilespec.c:5017
#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:6953
int tileset_topo_index(struct tileset *t)
Definition tilespec.c:7566
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:4438
void tileset_ruleset_reset(struct tileset *t)
Definition tilespec.c:7490
#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:7323
#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:2637
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2421
bool unit_has_orders(const struct unit *punit)
Definition unit.c:205
#define unit_tile(_pu)
Definition unit.h:390
#define BATTLEGROUP_NONE
Definition unit.h:190
#define unit_owner(_pu)
Definition unit.h:389
#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:836
#define unit_type_iterate(_p)
Definition unittype.h:852
#define U_LAST
Definition unittype.h:40
#define unit_type_iterate_end
Definition unittype.h:859
#define worker_task_list_iterate(tasklist, ptask)
Definition workertask.h:33
#define worker_task_list_iterate_end
Definition workertask.h:35