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