Freeciv-3.3
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 "modpack.h"
50#include "movement.h"
51#include "nation.h"
52#include "player.h"
53#include "road.h"
54#include "specialist.h"
55#include "unit.h"
56#include "unitlist.h"
57
58/* client/include */
59#include "dialogs_g.h"
60#include "graphics_g.h"
61#include "gui_main_g.h"
62#include "mapview_g.h" /* For update_map_canvas_visible */
63#include "menu_g.h"
64#include "themes_g.h"
65
66/* client */
67#include "citydlg_common.h" /* For generate_citydlg_dimensions() */
68#include "client_main.h"
69#include "climap.h" /* For client_tile_get_known() */
70#include "colors_common.h"
71#include "control.h" /* For fill_xxx */
72#include "editor.h"
73#include "goto.h"
74#include "gui_properties.h"
75#include "helpdata.h"
76#include "options.h" /* For fill_xxx */
77#include "svgflag.h"
78#include "themes_common.h"
79
80#include "tilespec.h"
81
82#define TILESPEC_CAPSTR "+Freeciv-3.3-tilespec duplicates_ok"
83/*
84 * Tilespec capabilities acceptable to this program:
85 *
86 * +Freeciv-3.2-tilespec
87 * - basic format for Freeciv versions 3.2.x; required
88 *
89 * +Freeciv-tilespec-3.2-Devel-YYYY.MMM.DD
90 * - tilespec of the development version at the given date
91 *
92 * duplicates_ok
93 * - we can handle existence of duplicate tags (lattermost tag which
94 * appears is used; tilesets which have duplicates should specify
95 * "duplicates_ok")
96 */
97
98#define SPEC_CAPSTR "+Freeciv-3.3-spec"
99/*
100 * Individual spec file capabilities acceptable to this program:
101 *
102 * +Freeciv-3.2-spec
103 * - basic format for Freeciv versions 3.2.x; required
104 */
105
106#define TILESPEC_SUFFIX ".tilespec"
107#define TILE_SECTION_PREFIX "tile_"
108
109/* This the way directional indices are now encoded: */
110#define MAX_INDEX_CARDINAL 64
111#define MAX_INDEX_HALF 16
112#define MAX_INDEX_VALID 256
113
114#define NUM_TILES_HP_BAR 11
115#define NUM_TILES_DIGITS 10
116#define MAX_NUM_UPKEEP_SPRITES 10
117
118#define SPECENUM_NAME extrastyle_id
119#define SPECENUM_VALUE0 ESTYLE_ROAD_ALL_SEPARATE
120#define SPECENUM_VALUE0NAME "RoadAllSeparate"
121#define SPECENUM_VALUE1 ESTYLE_ROAD_PARITY_COMBINED
122#define SPECENUM_VALUE1NAME "RoadParityCombined"
123#define SPECENUM_VALUE2 ESTYLE_ROAD_ALL_COMBINED
124#define SPECENUM_VALUE2NAME "RoadAllCombined"
125#define SPECENUM_VALUE3 ESTYLE_RIVER
126#define SPECENUM_VALUE3NAME "River"
127#define SPECENUM_VALUE4 ESTYLE_SINGLE1
128#define SPECENUM_VALUE4NAME "Single1"
129#define SPECENUM_VALUE5 ESTYLE_SINGLE2
130#define SPECENUM_VALUE5NAME "Single2"
131#define SPECENUM_VALUE6 ESTYLE_3LAYER
132#define SPECENUM_VALUE6NAME "3Layer"
133#define SPECENUM_VALUE7 ESTYLE_CARDINALS
134#define SPECENUM_VALUE7NAME "Cardinals"
135#define SPECENUM_COUNT ESTYLE_COUNT
136#include "specenum_gen.h"
137
138/* This could be moved to common/map.h if there's more use for it. */
142static const char direction4letters[4] = "udrl";
143/* This must correspond to enum edge_type. */
144static const char edge_name[EDGE_COUNT][3] = {"ns", "we", "ud", "lr"};
145
146static const int DIR4_TO_DIR8[4] =
148
155
157 CELL_WHOLE, /* Entire tile */
158 CELL_CORNER /* Corner of tile */
160
167
168struct anim {
170 int time;
172 struct sprite **sprites;
174};
175
177 bool init;
178
179 char *name;
180
181 int num_layers; /* 1 thru MAX_NUM_LAYERS. */
182#define MAX_NUM_LAYERS 3
183
187
188#define MAX_NUM_MATCH_WITH 8
191 int match_indices; /* 0 = no match_type, 1 = no match_with */
192
194
197 struct sprite **cells;
198
199 /* List of those sprites in 'cells' that are allocated by some other
200 * means than load_sprite() and thus are not freed by unload_all_sprites(). */
203
205
206 int blending; /* layer, 0 = none */
208 struct sprite *blend[4]; /* indexed by a direction4 */
209};
210
212 struct sprite *sprite;
213};
214
222
228
230 /* Each citizen type has up to MAX_NUM_CITIZEN_SPRITES different
231 * sprites, as defined by the tileset. */
232 int count;
234};
235
240
245
247 struct sprite
249 *treaty_thumb[2], /* 0=disagree, 1=agree */
250 *arrow[ARROW_LAST], /* 0=right arrow, 1=plus, 2=minus */
251
253
255
256 /* The panel sprites for showing tax % allocations. */
258 *dither_tile; /* Only used for isometric view */
259
260 struct {
261 struct sprite
266
270
271 struct {
272 struct anim *icon[U_LAST][ACTIVITY_LAST];
275
278
281
283 struct {
284 int hot_x, hot_y;
285 struct sprite *frame[NUM_CURSOR_FRAMES];
287 struct {
289 struct sprite *nuke;
291 struct {
294 struct anim
297 struct sprite
299 *vet_lev[MAX_VET_LEVELS],
305 *go_to, /* goto is a C keyword :-) */
316 *battlegroup[MAX_NUM_BATTLEGROUPS],
320 struct {
321 struct sprite
325 struct {
326 struct sprite
329 *size_tens[NUM_TILES_DIGITS],
330 *size_hundreds[NUM_TILES_DIGITS],
331 *tile_foodnum[NUM_TILES_DIGITS],
332 *tile_shieldnum[NUM_TILES_DIGITS],
333 *tile_tradenum[NUM_TILES_DIGITS];
334 struct city_sprite
339 struct sprite_vector worked_tile_overlay;
340 struct sprite_vector unworked_tile_overlay;
344 struct {
345 struct {
347 struct sprite *turns[NUM_TILES_DIGITS];
348 struct sprite *turns_tens[NUM_TILES_DIGITS];
349 struct sprite *turns_hundreds[NUM_TILES_DIGITS];
353 struct {
357 struct {
358 struct sprite
361 *darkness[MAX_INDEX_CARDINAL]; /* First unused */
362 } tx; /* Terrain extra */
363 struct {
364 struct sprite
368 union {
369 struct anim *single;
370 struct anim *cardinals[MAX_INDEX_CARDINAL];
371 struct {
372 struct anim
376 } bmf;
377 struct {
378 struct anim
379 /* For extrastyles ESTYLE_ROAD_ALL_SEPARATE and ESTYLE_ROAD_PARITY_COMBINED */
381 *corner[8]; /* Indexed by direction; only non-cardinal dirs used. */
382 union {
383 /* For ESTYLE_ROAD_ALL_SEPARATE */
384 struct anim *dir[8]; /* All entries used */
385 /* ESTYLE_ROAD_PARITY_COMBINED */
386 struct {
387 struct anim
388 *even[MAX_INDEX_HALF], /* First unused */
389 *odd[MAX_INDEX_HALF]; /* First unused */
390 } combo;
391 /* ESTYLE_ALL_SEPARATE */
392 struct anim *total[MAX_INDEX_VALID];
393 struct river_sprites rivers;
394 } ru;
396 } u;
398 struct {
399 struct sprite
402 *worked[EDGE_COUNT],
405 *selected[EDGE_COUNT],
406 *coastline[EDGE_COUNT],
407 *borders[EDGE_COUNT][2];
409 struct {
410 struct sprite_vector overlays;
412 struct {
413 struct sprite *color; /* Generic background color */
414 struct sprite *graphic; /* Generic background graphic */
416 struct {
417 struct sprite *grid_borders[EDGE_COUNT][2];
418 struct sprite *color;
421
423};
424
425struct specfile {
426 struct sprite *big_sprite;
427 char *file_name;
428};
429
430#define SPECLIST_TAG specfile
431#define SPECLIST_TYPE struct specfile
432#include "speclist.h"
433
434#define specfile_list_iterate(list, pitem) \
435 TYPED_LIST_ITERATE(struct specfile, list, pitem)
436#define specfile_list_iterate_end LIST_ITERATE_END
437
438/*
439 * Information about an individual sprite. All fields except 'sprite' are
440 * filled at the time of the scan of the specfile. 'Sprite' is
441 * set/cleared on demand in load_sprite()/unload_sprite().
442 */
443struct small_sprite {
444 int ref_count;
445
446 /* The sprite is in this file. */
447 char *file;
448
449 /* Or, the sprite is in this file at the location. */
450 struct specfile *sf;
451 int x, y, width, height;
452
453 /* A little more (optional) data. */
454 int hot_x, hot_y;
455
456 struct sprite *sprite;
457};
458
459/* 'struct small_sprite_list' and related functions. */
460#define SPECLIST_TAG small_sprite
461#define SPECLIST_TYPE struct small_sprite
462#include "speclist.h"
463#define small_sprite_list_iterate(list, pitem) \
464 TYPED_LIST_ITERATE(struct small_sprite, list, pitem)
465#define small_sprite_list_iterate_end LIST_ITERATE_END
466
467/* 'struct sprite_hash' and related functions. */
468#define SPECHASH_TAG sprite
469#define SPECHASH_ASTR_KEY_TYPE
470#define SPECHASH_IDATA_TYPE struct small_sprite *
471#include "spechash.h"
472#define sprite_hash_iterate(hash, tag_name, sprite) \
473 TYPED_HASH_ITERATE(const char *, struct small_sprite *, \
474 hash, tag_name, sprite)
475#define sprite_hash_iterate_end HASH_ITERATE_END
476
477/* 'struct anim_hash' and related functions. */
478#define SPECHASH_TAG anim
479#define SPECHASH_ASTR_KEY_TYPE
480#define SPECHASH_IDATA_TYPE struct anim *
481#include "spechash.h"
482#define anim_hash_iterate(hash, tag_name, sprite) \
483 TYPED_HASH_ITERATE(const char *, struct anim *, \
484 hash, tag_name, anim)
485#define anim_hash_iterate_end HASH_ITERATE_END
486
487/* 'struct drawing_hash' and related functions. */
488static void drawing_data_destroy(struct drawing_data *draw);
489
490#define SPECHASH_TAG drawing
491#define SPECHASH_CSTR_KEY_TYPE
492#define SPECHASH_IDATA_TYPE struct drawing_data *
493#define SPECHASH_IDATA_FREE drawing_data_destroy
494#include "spechash.h"
495
496#define SPECHASH_TAG estyle
497#define SPECHASH_ASTR_KEY_TYPE
498#define SPECHASH_ENUM_DATA_TYPE extrastyle_id
499#include "spechash.h"
500
501struct tileset {
502 char name[512];
506
507 char *summary;
509 float scale;
510
512
514
518
523
526
528
530
532
535
541
554
555#define NUM_CORNER_DIRS 4
556#define TILES_PER_CORNER 4
560
565
568
569 /* This hash table maps tilespec tags to struct small_sprites. */
571
572 /* This hash table maps terrain graphic strings to drawing data. */
574
576
578
580
582
584
586
589};
590
593
595
596static bool tileset_update = FALSE;
597
598static int global_anim_time = 0;
599
600static struct tileset *tileset_read_toplevel(const char *tileset_name,
601 bool verbose, int topology_id,
602 float scale);
603
604static int fill_unit_type_sprite_array(const struct tileset *t,
605 struct drawn_sprite *sprs,
606 const struct unit_type *putype,
607 enum unit_activity activity,
608 enum direction8 facing);
609static int fill_unit_sprite_array(const struct tileset *t,
610 struct drawn_sprite *sprs,
611 const struct unit *punit,
612 int stack, bool backdrop);
613static bool load_river_sprites(struct tileset *t,
614 struct river_sprites *store, const char *tag_pfx);
615
616static void tileset_setup_base(struct tileset *t,
617 const struct extra_type *pextra,
618 const char *tag);
619static void tileset_setup_road(struct tileset *t,
620 struct extra_type *pextra,
621 const char *tag);
622
623static bool is_extra_drawing_enabled(struct extra_type *pextra);
624
625static int fill_basic_road_sprite_array(const struct tileset *t,
626 struct drawn_sprite *sprs,
627 const struct extra_type *pextra);
628static int fill_basic_base_sprite_array(const struct tileset *t,
629 struct drawn_sprite *sprs,
630 const struct extra_type *pextra);
631
632static void tileset_player_free(struct tileset *t, int plrid);
633
634static void tileset_setup_specialist_type(struct tileset *t,
635 struct citizen_set *set,
637 const char *tag_group,
638 const char *set_name,
639 bool required);
641static void tileset_setup_citizen_types(struct tileset *t,
642 struct citizen_set *set,
643 const char *tag_group,
644 const char *set_name,
645 bool required);
646
647/************************************************************************/
650void tileset_error(enum log_level level, const char *tset_name,
651 const char *format, ...)
652{
653 char buf[2048];
654 va_list args;
655
656 va_start(args, format);
657 fc_vsnprintf(buf, sizeof(buf), format, args);
658 va_end(args);
659
660 log_base(level, "%s", buf);
661
662 if (level <= LOG_NORMAL) {
664
665 if (level == LOG_FATAL) {
667 }
668 }
669}
670
671/************************************************************************/
674static struct drawing_data *drawing_data_new(void)
675{
676 struct drawing_data *draw = fc_calloc(1, sizeof(*draw));
677
678 draw->name = NULL;
679
680 return draw;
681}
682
683/************************************************************************/
687{
688 int i;
689
691
692 if (draw->name != NULL) {
693 free(draw->name);
694 }
695 for (i = 0; i < 4; i++) {
696 if (draw->blend[i]) {
697 free_sprite(draw->blend[i]);
698 }
699 }
700 for (i = 0; i < draw->num_layers; i++) {
701 int vec_size = sprite_vector_size(&draw->layer[i].allocated);
702 int j;
703
704 for (j = 0; j < vec_size; j++) {
705 free_sprite(draw->layer[i].allocated.p[j]);
706 }
707
708 sprite_vector_free(&draw->layer[i].base);
709 sprite_vector_free(&draw->layer[i].allocated);
710 free(draw->layer[i].cells);
711 }
712 free(draw);
713}
714
715/************************************************************************/
718struct tileset *get_tileset(void)
719{
720 if (unscaled_tileset != NULL) {
721 return unscaled_tileset;
722 } else {
723 return tileset;
724 }
725}
726
727/************************************************************************/
730const char *tileset_basename(const struct tileset *t)
731{
732 return t->name;
733}
734
735/************************************************************************/
738bool tileset_is_isometric(const struct tileset *t)
739{
740 return t->type == TS_ISOMETRIC;
741}
742
743/************************************************************************/
747int tileset_hex_width(const struct tileset *t)
748{
749 return t->hex_width;
750}
751
752/************************************************************************/
756int tileset_hex_height(const struct tileset *t)
757{
758 return t->hex_height;
759}
760
761/************************************************************************/
779int tileset_tile_width(const struct tileset *t)
780{
781 return t->normal_tile_width;
782}
783
784/************************************************************************/
791int tileset_tile_height(const struct tileset *t)
792{
793 return t->normal_tile_height;
794}
795
796/************************************************************************/
803{
804 return t->full_tile_width;
805}
806
807/************************************************************************/
816{
817 return t->full_tile_height;
818}
819
820/************************************************************************/
823int tileset_unit_width(const struct tileset *t)
824{
825 return t->unit_tile_width;
826}
827
828/************************************************************************/
831int tileset_unit_height(const struct tileset *t)
832{
833 return t->unit_tile_height;
834}
835
836/************************************************************************/
839static int calculate_max_upkeep_height(const struct tileset *t)
840{
841 int i;
842 int max = 0;
843
844 for (i = 0; i < MAX_NUM_UPKEEP_SPRITES; i++) {
845 if (t->sprites.upkeep.unhappy[i] != NULL) {
846 int width, height;
847
848 /* TODO: We want only height, getting the width might waste CPU
849 * depending on gui-specific implementation. */
851
852 max = MAX(max, height);
853 }
854 }
855
857 for (i = 0; i < MAX_NUM_UPKEEP_SPRITES; i++) {
858 if (t->sprites.upkeep.output[o][i] != NULL) {
859 int width, height;
860
861 /* TODO: We want only height, getting the width might waste CPU
862 * depending on gui-specific implementation. */
864
865 max = MAX(max, height);
866 }
867 }
869
870 return max;
871}
872
873/************************************************************************/
876static int tileset_upkeep_height(const struct tileset *t)
877{
878 /* Return cached value */
879 return t->max_upkeep_height;
880}
881
882/************************************************************************/
892
893/************************************************************************/
904
905/************************************************************************/
909{
910 return t->unit_upkeep_offset_y;
911}
912
913/************************************************************************/
918{
920}
921
922/************************************************************************/
928{
929 return t->small_sprite_width;
930}
931
932/************************************************************************/
937{
938 return t->citybar_offset_y;
939}
940
941/************************************************************************/
946{
947 return t->tilelabel_offset_y;
948}
949
950/************************************************************************/
953float tileset_scale(const struct tileset *t)
954{
955 return tileset->scale;
956}
957
958/************************************************************************/
964{
965 return t->small_sprite_height;
966}
967
968/************************************************************************/
973const char *tileset_main_intro_filename(const struct tileset *t)
974{
975 return t->main_intro_filename;
976}
977
978/************************************************************************/
982{
983 return t->sprites.city.worked_tile_overlay.size;
984}
985
986/************************************************************************/
990{
991 return FOG_AUTO == t->fogstyle;
992}
993
994/************************************************************************/
997static struct tileset *tileset_new(void)
998{
999 struct tileset *t = fc_calloc(1, sizeof(*t));
1000
1003
1004 return t;
1005}
1006
1007/************************************************************************/
1011static const char *dir_get_tileset_name(enum direction8 dir)
1012{
1013 switch (dir) {
1014 case DIR8_NORTH:
1015 return "n";
1016 case DIR8_NORTHEAST:
1017 return "ne";
1018 case DIR8_EAST:
1019 return "e";
1020 case DIR8_SOUTHEAST:
1021 return "se";
1022 case DIR8_SOUTH:
1023 return "s";
1024 case DIR8_SOUTHWEST:
1025 return "sw";
1026 case DIR8_WEST:
1027 return "w";
1028 case DIR8_NORTHWEST:
1029 return "nw";
1030 }
1031 log_error("Wrong direction8 variant: %d.", dir);
1032 return "";
1033}
1034
1035/************************************************************************/
1038static enum direction8 dir_by_tileset_name(const char *str)
1039{
1040 enum direction8 dir;
1041
1042 for (dir = direction8_begin();
1043 dir != direction8_end();
1044 dir = direction8_next(dir)) {
1045 if (strcmp(dir_get_tileset_name(dir), str) == 0) {
1046 return dir;
1047 }
1048 }
1049
1050 return direction8_invalid();
1051}
1052
1053/************************************************************************/
1056static bool is_valid_tileset_dir(const struct tileset *t,
1057 enum direction8 dir)
1058{
1059 if (t->hex_width > 0) {
1060 return dir != DIR8_NORTHEAST && dir != DIR8_SOUTHWEST;
1061 } else if (t->hex_height > 0) {
1062 return dir != DIR8_NORTHWEST && dir != DIR8_SOUTHEAST;
1063 } else {
1064 return TRUE;
1065 }
1066}
1067
1068/************************************************************************/
1074static bool is_cardinal_tileset_dir(const struct tileset *t,
1075 enum direction8 dir)
1076{
1077 if (t->hex_width > 0 || t->hex_height > 0) {
1078 return is_valid_tileset_dir(t, dir);
1079 } else {
1080 return (dir == DIR8_NORTH || dir == DIR8_EAST
1081 || dir == DIR8_SOUTH || dir == DIR8_WEST);
1082 }
1083}
1084
1085/************************************************************************/
1090{
1091 int idx;
1092
1093 if ((actual_topology & TF_HEX)
1094 && (actual_topology & TF_ISO)) {
1095 idx = TS_TOPO_ISOHEX;
1096 } else if (actual_topology & TF_ISO) {
1097 idx = TS_TOPO_SQUARE;
1098 } else if (actual_topology & TF_HEX) {
1099 idx = TS_TOPO_HEX;
1100 } else {
1101 idx = TS_TOPO_SQUARE;
1102 }
1103
1104 return idx;
1105}
1106
1107/************************************************************************/
1112{
1113 switch (idx) {
1114 case TS_TOPO_SQUARE:
1115 return TF_ISO;
1116 case TS_TOPO_HEX:
1117 return TF_HEX;
1118 case TS_TOPO_ISOHEX:
1119 return TF_HEX | TF_ISO;
1120 }
1121
1122 return 0;
1123}
1124
1126 struct strvec *list;
1127 int topo;
1128};
1129
1130/************************************************************************/
1133static void ts_list_cb(const char *modpack_name, const char *filename,
1134 void *data)
1135{
1136 struct ts_list_data *tsdata = (struct ts_list_data *)data;
1137 const char *target = modpack_tileset_target(modpack_name);
1138 struct tileset *t = tileset_read_toplevel(target,
1139 FALSE, tsdata->topo, 1.0f);
1140
1141 if (t != nullptr) {
1142 strvec_append(tsdata->list, target);
1143 tileset_free(t);
1144 }
1145}
1146
1147/************************************************************************/
1150const struct strvec *get_tileset_list(const struct option *poption)
1151{
1152 static struct strvec *tilesets[3] = { nullptr, nullptr, nullptr };
1153 int topo = option_get_cb_data(poption);
1154 int idx;
1155
1156 idx = ts_topology_index(topo);
1157
1158 fc_assert_ret_val(idx < ARRAY_SIZE(tilesets), nullptr);
1159
1160 if (tilesets[idx] == nullptr) {
1161 struct ts_list_data data;
1162
1163 /* Note: this means you must restart the client after installing a new
1164 tileset. */
1165 tilesets[idx] = strvec_new();
1166 data.list = tilesets[idx];
1167 data.topo = topo;
1169 }
1170
1171 return tilesets[idx];
1172}
1173
1174/************************************************************************/
1181static char *tilespec_fullname(const char *tileset_name)
1182{
1183 if (tileset_name) {
1185 const char *dname;
1186
1187 fc_snprintf(fname, sizeof(fname),
1188 "%s%s", tileset_name, TILESPEC_SUFFIX);
1189
1191
1192 if (dname) {
1193 return fc_strdup(dname);
1194 }
1195 }
1196
1197 return NULL;
1198}
1199
1200/************************************************************************/
1206 const char *which,
1207 const char *us_capstr,
1208 const char *filename,
1209 bool verbose)
1210{
1211 enum log_level level = verbose ? LOG_ERROR : LOG_DEBUG;
1212
1213 const char *file_capstr = secfile_lookup_str(file, "%s.options", which);
1214
1215 if (NULL == file_capstr) {
1216 log_base(level, "\"%s\": %s file doesn't have a capability string",
1217 filename, which);
1218 return FALSE;
1219 }
1221 log_base(level, "\"%s\": %s file appears incompatible:",
1222 filename, which);
1223 log_base(level, " datafile options: %s", file_capstr);
1224 log_base(level, " supported options: %s", us_capstr);
1225 return FALSE;
1226 }
1228 log_base(level, "\"%s\": %s file requires option(s) "
1229 "that client doesn't support:", filename, which);
1230 log_base(level, " datafile options: %s", file_capstr);
1231 log_base(level, " supported options: %s", us_capstr);
1232 return FALSE;
1233 }
1234
1235 return TRUE;
1236}
1237
1238/************************************************************************/
1243static void tileset_free_toplevel(struct tileset *t)
1244{
1245 int i, j;
1246
1247 if (t->main_intro_filename) {
1250 }
1251
1252 if (t->preferred_themes) {
1253 for (i = 0; i < t->num_preferred_themes; i++) {
1254 free(t->preferred_themes[i]);
1255 }
1258 }
1259 t->num_preferred_themes = 0;
1260
1261 if (t->tile_hash) {
1263 t->tile_hash = NULL; /* Helpful for sanity. */
1264 }
1265 if (t->estyle_hash) {
1267 t->estyle_hash = NULL;
1268 }
1269 for (i = 0; i < ESTYLE_COUNT; i++) {
1270 if (t->style_lists[i] != NULL) {
1272 t->style_lists[i] = NULL;
1273 }
1274 }
1275
1276 if (t->flagged_bases_list != NULL) {
1279 }
1280
1281 for (i = 0; i < MAX_NUM_LAYERS; i++) {
1282 struct tileset_layer *tslp = &t->layers[i];
1283
1284 if (tslp->match_types) {
1285 for (j = 0; j < tslp->match_count; j++) {
1286 free(tslp->match_types[j]);
1287 }
1288 free(tslp->match_types);
1289 tslp->match_types = NULL;
1290 }
1291 }
1292
1293 if (t->color_system) {
1295 t->color_system = NULL;
1296 }
1297
1298 if (t->summary != NULL) {
1299 free(t->summary);
1300 t->summary = NULL;
1301 }
1302 if (t->description != NULL) {
1303 free(t->description);
1304 t->description = NULL;
1305 }
1306 if (t->for_ruleset != NULL) {
1307 free(t->for_ruleset);
1308 t->for_ruleset = NULL;
1309 }
1310}
1311
1312/************************************************************************/
1315void tileset_free(struct tileset *t)
1316{
1317 int i;
1318
1321 for (i = 0; i < ARRAY_SIZE(t->sprites.player); i++) {
1323 }
1326 free(t);
1327}
1328
1329/************************************************************************/
1332static void ts_cb(const char *modpack_name, const char *filename, void *data)
1333{
1334 int topo_id = *((int *)data);
1335 struct tileset *t = tileset_read_toplevel(modpack_tileset_target(modpack_name),
1336 FALSE, topo_id, 1.0f);
1337
1338 if (t != nullptr) {
1339 if (tileset == nullptr) {
1340 tileset = t;
1341 } else if (t->priority > tileset->priority
1342 || (topo_id >= 0
1345 tileset = t;
1346 } else {
1347 tileset_free(t);
1348 }
1349 }
1350}
1351
1352/************************************************************************/
1360bool tilespec_try_read(const char *tileset_name, bool verbose, int topo_id,
1361 bool global_default)
1362{
1363 bool original;
1364
1365 if (tileset_name == nullptr
1367 topo_id, 1.0f))) {
1368 original = FALSE;
1370
1371 if (tileset == nullptr) {
1372 if (global_default) {
1373 tileset_error(LOG_FATAL, nullptr, _("No usable default tileset found, aborting!"));
1374 }
1375
1376 return FALSE;
1377 }
1378
1379 log_verbose("Trying tileset \"%s\".", tileset->name);
1380 } else {
1381 original = TRUE;
1382 }
1384
1385 if (global_default) {
1387 }
1388
1389 return original;
1390}
1391
1392/************************************************************************/
1406 bool game_fully_initialized, float scale)
1407{
1408 int id;
1409 struct tile *center_tile;
1410 enum client_states state = client_state();
1412 char tileset_name[strlen(name) + 1], old_name[strlen(tileset->name) + 1];
1413 bool new_tileset_in_use;
1414 int ts_topo;
1415
1416 /* Make local copies since these values may be freed down below */
1418 sz_strlcpy(old_name, tileset->name);
1419
1420 log_normal(_("Loading tileset \"%s\"."), tileset_name);
1421
1422 /* Step 0: Record old data.
1423 *
1424 * We record the current mapcanvas center, etc.
1425 */
1427
1428 /* Step 1: Cleanup.
1429 *
1430 * Free old tileset or keep it in memory if we are loading the same
1431 * tileset with scaling and old one was not scaled.
1432 */
1433
1434 if (strcmp(tileset_name, old_name) == 0 && tileset->scale == 1.0f
1435 && scale != 1.0f) {
1436 if (unscaled_tileset) {
1438 }
1440 } else {
1442 }
1443
1444 /* Step 2: Read.
1445 *
1446 * We read in the new tileset. This should be pretty straightforward.
1447 */
1449 if (tileset != NULL) {
1451 } else {
1453
1454 if (!(tileset = tileset_read_toplevel(old_name, FALSE, -1, scale))) {
1455 log_fatal("Failed to re-read the currently loaded tileset.");
1457 }
1458 }
1462 }
1463
1467 } /* else we'll get round to it on PACKET_RULESET_GAME */
1468 players_iterate(pplayer) {
1469 tileset_player_init(tileset, pplayer);
1471 boot_help_texts(); /* "About Current Tileset" */
1472 }
1473
1474 /* Step 3: Setup
1475 *
1476 * This is a seriously sticky problem. On startup, we build a hash
1477 * from all the sprite data. Then, when we connect to a server, the
1478 * server sends us ruleset data a piece at a time and we use this data
1479 * to assemble the sprite structures. But if we change while connected
1480 * we have to reassemble all of these. This should just involve
1481 * calling tilespec_setup_*** on everything. But how do we tell what
1482 * "everything" is?
1483 *
1484 * The below code just does things straightforwardly, by setting up
1485 * each possible sprite again. Hopefully it catches everything, and
1486 * doesn't mess up too badly if we change tilesets while not connected
1487 * to a server.
1488 */
1489 if (!game.client.ruleset_ready) {
1490 /* The ruleset data is not sent until this point. */
1491 return new_tileset_in_use;
1492 }
1493
1495 == TOPO_INCOMP_HARD) {
1497 _("Map topology (%s) and tileset (%s) incompatible."),
1499 }
1500
1501 terrain_type_iterate(pterrain) {
1507 governments_iterate(gov) {
1510 extra_type_iterate(pextra) {
1513 nations_iterate(pnation) {
1516 improvement_iterate(pimprove) {
1525
1528 * sizeof(tileset->sprites.style_citizen_sets.sets[0]));
1529
1530 for (id = 0; id < game.control.num_city_styles; id++) {
1532 }
1533
1534 if (state < C_S_RUNNING) {
1535 /* Below redraws do not apply before this. */
1536 return new_tileset_in_use;
1537 }
1538
1539 /* Step 4: Draw.
1540 *
1541 * Do any necessary redraws.
1542 */
1545 can_slide = FALSE;
1547 /* update_map_canvas_visible forces a full redraw. Otherwise with fast
1548 * drawing we might not get one. Of course this is slower. */
1550 can_slide = TRUE;
1551
1552 return new_tileset_in_use;
1553}
1554
1555/************************************************************************/
1560{
1561 const char *tileset_name;
1562 enum client_states state = client_state();
1563
1564 if (state == C_S_RUNNING || state == C_S_OVER) {
1566
1567 /* Also iso map topology counts as 'square' tileset topology */
1568 if (opt != (wld.map.topology_id & (TF_ISO | TF_HEX))
1569 && (opt != 0 || ((wld.map.topology_id & TF_HEX) == TF_HEX))) {
1570 /* Changed option was not for current topology */
1571 return;
1572 }
1573 }
1574
1576
1577 fc_assert_ret(NULL != tileset_name && tileset_name[0] != '\0');
1580
1581 /* As it's going to be 'current' tileset, make it global default if
1582 * options saved. */
1584
1586 menus_init();
1587}
1588
1589/************************************************************************/
1596{
1598 tilespec_reread(tname, TRUE, 1.0f);
1600 menus_init();
1601}
1602
1603/************************************************************************/
1607static struct sprite *load_gfx_file(const char *gfx_filename, bool svgflag)
1608{
1609 const char **gfx_fileexts, *gfx_fileext;
1610 struct sprite *s;
1611
1612 if (svgflag) {
1614 } else {
1616 }
1617
1618 /* Try out all supported file extensions to find one that works. */
1619 while ((gfx_fileext = *gfx_fileexts++)) {
1620 const char *real_full_name;
1621 char full_name[strlen(gfx_filename) + strlen(".")
1622 + strlen(gfx_fileext) + 1];
1623
1626 log_debug("trying to load gfx file \"%s\".", real_full_name);
1628 svgflag && !strcmp("svg", gfx_fileext));
1629 if (s) {
1630 return s;
1631 }
1632 }
1633 }
1634
1635 log_error("Could not load gfx file \"%s\".", gfx_filename);
1636
1637 return NULL;
1638}
1639
1640/************************************************************************/
1643static void ensure_big_sprite(struct specfile *sf, const char *tset_name)
1644{
1645 struct section_file *file;
1646 const char *gfx_filename;
1647
1648 if (sf->big_sprite) {
1649 /* Looks like it's already loaded. */
1650 return;
1651 }
1652
1653 /* Otherwise load it. The big sprite will sometimes be freed and will have
1654 * to be reloaded, but most of the time it's just loaded once, the small
1655 * sprites are extracted, and then it's freed. */
1656 if (!(file = secfile_load(sf->file_name, TRUE))) {
1658 _("Could not open '%s':\n%s"), sf->file_name, secfile_error());
1659 }
1660
1661 if (!check_tilespec_capabilities(file, "spec",
1662 SPEC_CAPSTR, sf->file_name, TRUE)) {
1664 _("Specfile %s has incompatible capabilities"), sf->file_name);
1665 }
1666
1667 gfx_filename = secfile_lookup_str(file, "file.gfx");
1668
1670
1671 if (!sf->big_sprite) {
1673 _("Could not load gfx file for the spec file \"%s\"."),
1674 sf->file_name);
1675 }
1676 secfile_destroy(file);
1677}
1678
1679/************************************************************************/
1684static void scan_specfile(struct tileset *t, struct specfile *sf,
1685 bool duplicates_ok)
1686{
1687 struct section_file *file;
1688 struct section_list *sections;
1689 int i;
1690
1691 if (!(file = secfile_load(sf->file_name, TRUE))) {
1693 _("Could not open '%s':\n%s"), sf->file_name, secfile_error());
1694 }
1695 if (!check_tilespec_capabilities(file, "spec",
1696 SPEC_CAPSTR, sf->file_name, TRUE)) {
1698 _("Specfile %s has incompatible capabilities"), sf->file_name);
1699 }
1700
1701 /* Currently unused */
1702 secfile_entry_ignore(file, "info.artists");
1703
1704 /* Not used here */
1705 secfile_entry_ignore(file, "file.gfx");
1706
1707 if ((sections = secfile_sections_by_name_prefix(file, "grid_"))) {
1708 section_list_iterate(sections, psection) {
1709 int j, k;
1710 int x_top_left, y_top_left, dx, dy;
1711 int pixel_border_x;
1712 int pixel_border_y;
1713 const char *sec_name = section_name(psection);
1714
1715 pixel_border_x = secfile_lookup_int_default(file, 0, "%s.pixel_border",
1716 sec_name);
1717 pixel_border_y = secfile_lookup_int_default(file, pixel_border_x, "%s.pixel_border_y",
1718 sec_name);
1719 pixel_border_x = secfile_lookup_int_default(file, pixel_border_x, "%s.pixel_border_x",
1720 sec_name);
1721 if (!secfile_lookup_int(file, &x_top_left, "%s.x_top_left", sec_name)
1722 || !secfile_lookup_int(file, &y_top_left,
1723 "%s.y_top_left", sec_name)
1724 || !secfile_lookup_int(file, &dx, "%s.dx", sec_name)
1725 || !secfile_lookup_int(file, &dy, "%s.dy", sec_name)) {
1726 log_error("%s grid \"%s\" invalid: %s",
1728 continue;
1729 }
1730
1731 j = -1;
1732 while (NULL != secfile_entry_lookup(file, "%s.tiles%d.tag",
1733 sec_name, ++j)) {
1734 struct small_sprite *ss;
1735 int row, column;
1736 int xr, yb;
1737 const char **tags;
1738 size_t num_tags;
1739 int hot_x, hot_y;
1740
1741 if (!secfile_lookup_int(file, &row, "%s.tiles%d.row", sec_name, j)
1742 || !secfile_lookup_int(file, &column, "%s.tiles%d.column",
1743 sec_name, j)
1744 || !(tags = secfile_lookup_str_vec(file, &num_tags,
1745 "%s.tiles%d.tag",
1746 sec_name, j))) {
1747 log_error("%s small sprite \"%s.tiles%d\" invalid: %s",
1749 continue;
1750 }
1751 hot_x = secfile_lookup_int_default(file, 0, "%s.tiles%d.hot_x",
1752 sec_name, j);
1753 hot_y = secfile_lookup_int_default(file, 0, "%s.tiles%d.hot_y",
1754 sec_name, j);
1755
1756 /* There must be at least 1 because of the while(): */
1757 fc_assert_action(num_tags > 0, continue);
1758
1759 xr = x_top_left + (dx + pixel_border_x) * column;
1760 yb = y_top_left + (dy + pixel_border_y) * row;
1761
1762 ss = fc_malloc(sizeof(*ss));
1763 ss->ref_count = 0;
1764 ss->file = NULL;
1765 ss->x = xr;
1766 ss->y = yb;
1767 ss->width = dx;
1768 ss->height = dy;
1769 ss->sf = sf;
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 has 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
1789 free(tags);
1790 tags = NULL;
1791 }
1793 section_list_destroy(sections);
1794 }
1795
1796 /* Load "extra" sprites. Each sprite is one file. */
1797 i = -1;
1798 while (NULL != secfile_entry_lookup(file, "extra.sprites%d.tag", ++i)) {
1799 struct small_sprite *ss;
1800 const char **tags;
1801 const char *filename;
1802 size_t num_tags, k;
1803 int hot_x, hot_y;
1804
1805 if (!(tags = secfile_lookup_str_vec(file, &num_tags,
1806 "extra.sprites%d.tag", i))
1807 || !(filename = secfile_lookup_str(file,
1808 "extra.sprites%d.file", i))) {
1809 log_error("%s extra sprite \"extra.sprites%d\" invalid: %s",
1811 continue;
1812 }
1813 hot_x = secfile_lookup_int_default(file, 0, "extra.sprites%d.hot_x", i);
1814 hot_y = secfile_lookup_int_default(file, 0, "extra.sprites%d.hot_y", i);
1815
1816 ss = fc_malloc(sizeof(*ss));
1817 ss->ref_count = 0;
1818 ss->file = fc_strdup(filename);
1819 ss->sf = NULL;
1820 ss->sprite = NULL;
1821 ss->hot_x = hot_x;
1822 ss->hot_y = hot_y;
1823
1825
1826 if (!duplicates_ok) {
1827 for (k = 0; k < num_tags; k++) {
1828 if (!sprite_hash_insert(t->sprite_hash, tags[k], ss)) {
1829 log_error("warning: %s already have a sprite for \"%s\".",
1830 tileset_name_get(t), tags[k]);
1831 }
1832 }
1833 } else {
1834 for (k = 0; k < num_tags; k++) {
1835 (void) sprite_hash_replace(t->sprite_hash, tags[k], ss);
1836 }
1837 }
1838 free(tags);
1839 }
1840
1843}
1844
1845/************************************************************************/
1849static char *tilespec_gfx_filename(const char *gfx_filename,
1850 const char *tset_name)
1851{
1852 const char *gfx_current_fileext;
1853 const char **gfx_fileexts = gfx_fileextensions();
1854
1855 while ((gfx_current_fileext = *gfx_fileexts++)) {
1856 const char *real_full_name;
1857 char *full_name =
1860
1862
1864 free(full_name);
1865 if (real_full_name) {
1866 return fc_strdup(real_full_name);
1867 }
1868 }
1869
1871 _("Couldn't find a supported gfx file extension for \"%s\"."),
1872 gfx_filename);
1873
1874 return NULL;
1875}
1876
1877/************************************************************************/
1880static bool tileset_scan_single_list(struct tileset *t,
1881 const char *spec_filenames[],
1882 int num_spec_files, bool verbose,
1883 bool duplicates_ok)
1884{
1885 int i;
1886
1887 for (i = 0; i < num_spec_files; i++) {
1888 struct specfile *sf = fc_malloc(sizeof(*sf));
1889 const char *dname;
1890
1891 log_debug("spec file %s", spec_filenames[i]);
1892
1893 sf->big_sprite = NULL;
1895 if (!dname) {
1896 if (verbose) {
1897 log_error("Can't find spec file \"%s\".", spec_filenames[i]);
1898 }
1899
1900 return FALSE;
1901 }
1902 sf->file_name = fc_strdup(dname);
1904
1906 }
1907
1908 return TRUE;
1909}
1910
1911/************************************************************************/
1914static int check_sprite_type(const char *sprite_type, const char *tile_section)
1915{
1916 if (fc_strcasecmp(sprite_type, "corner") == 0) {
1917 return CELL_CORNER;
1918 }
1919 if (fc_strcasecmp(sprite_type, "single") == 0) {
1920 return CELL_WHOLE;
1921 }
1922 if (fc_strcasecmp(sprite_type, "whole") == 0) {
1923 return CELL_WHOLE;
1924 }
1925 log_error("[%s] unknown sprite_type \"%s\".", tile_section, sprite_type);
1926 return CELL_WHOLE;
1927}
1928
1929/************************************************************************/
1935static struct tileset *tileset_read_toplevel(const char *tileset_name,
1936 bool verbose, int topology_id,
1937 float scale)
1938{
1939 struct section_file *file;
1940 char *fname;
1941 const char *c;
1942 int i;
1943 size_t num_spec_files[SFILE_LAST];
1944 const char **spec_filenames[SFILE_LAST];
1945 size_t num_layers;
1946 const char **layer_order;
1947 size_t num_preferred_themes;
1948 struct section_list *sections = NULL;
1949 const char *file_capstr;
1950 bool duplicates_ok, is_hex;
1951 enum direction8 dir;
1952 struct tileset *t = NULL;
1953 const char *extraname;
1954 const char *tstr;
1955 int topo;
1956 bool svg;
1958 const char *type_name;
1959 bool vsup;
1960
1962
1963 if (fname == NULL) {
1964 if (verbose) {
1965 log_error("Can't find tileset \"%s\".", tileset_name);
1966 }
1967
1968 return NULL;
1969 }
1970 log_verbose("tilespec file is \"%s\".", fname);
1971
1972 if (!(file = secfile_load(fname, TRUE))) {
1973 log_error("Could not open '%s':\n%s", fname, secfile_error());
1974 free(fname);
1975 return NULL;
1976 }
1977
1978 if (!check_tilespec_capabilities(file, "tilespec",
1979 TILESPEC_CAPSTR, fname, verbose)) {
1980 secfile_destroy(file);
1981 free(fname);
1982 return NULL;
1983 }
1984
1985 t = tileset_new();
1986 t->scale = scale;
1987 file_capstr = secfile_lookup_str(file, "%s.options", "tilespec");
1989 && has_capabilities("+duplicates_ok", file_capstr));
1990
1991 tstr = secfile_lookup_str(file, "tilespec.name");
1992 /* Tileset name found */
1994 tstr = secfile_lookup_str_default(file, "", "tilespec.version");
1995 if (tstr[0] != '\0') {
1996 /* Tileset version found */
1997 sz_strlcpy(t->version, tstr);
1998 } else {
1999 /* No version information */
2000 t->version[0] = '\0';
2001 }
2002
2003 tstr = secfile_lookup_str_default(file, "", "tilespec.summary");
2004 if (tstr[0] != '\0') {
2005 int len;
2006
2007 /* Tileset summary found */
2008 len = strlen(tstr);
2009 t->summary = fc_malloc(len + 1);
2010 fc_strlcpy(t->summary, tstr, len + 1);
2011 } else {
2012 /* No summary */
2013 if (t->summary != NULL) {
2014 free(t->summary);
2015 t->summary = NULL;
2016 }
2017 }
2018
2019 tstr = secfile_lookup_str_default(file, "", "tilespec.description");
2020 if (tstr[0] != '\0') {
2021 int len;
2022
2023 /* Tileset description found */
2024 len = strlen(tstr);
2025 t->description = fc_malloc(len + 1);
2026 fc_strlcpy(t->description, tstr, len + 1);
2027 } else {
2028 /* No description */
2029 if (t->description != NULL) {
2030 free(t->description);
2031 t->description = NULL;
2032 }
2033 }
2034
2035 tstr = secfile_lookup_str_default(file, NULL, "tilespec.for_ruleset");
2036 if (tstr != NULL) {
2038 } else {
2039 t->for_ruleset = NULL;
2040 }
2041
2043 if (!secfile_lookup_int(file, &t->priority, "tilespec.priority")
2044 || !secfile_lookup_bool(file, &is_hex, "tilespec.is_hex")) {
2045 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2046 goto ON_ERROR;
2047 }
2048
2049 tstr = secfile_lookup_str(file, "tilespec.type");
2050 if (tstr == NULL) {
2051 log_error("Tileset \"%s\": no tileset type", t->name);
2052 goto ON_ERROR;
2053 }
2054
2056 if (!ts_type_is_valid(t->type)) {
2057 log_error("Tileset \"%s\": unknown tileset type \"%s\"", t->name, tstr);
2058 goto ON_ERROR;
2059 }
2060
2061 if (t->type == TS_ISOMETRIC) {
2062 topo = TF_ISO;
2063 } else {
2064 topo = 0;
2065 }
2066
2067 /* Read hex-tileset information. */
2068 t->hex_width = t->hex_height = 0;
2069 if (is_hex) {
2070 int hex_side;
2071
2072 if (!secfile_lookup_int(file, &hex_side, "tilespec.hex_side")) {
2073 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2074 goto ON_ERROR;
2075 }
2076 hex_side = hex_side * t->scale;
2077 if (t->type == TS_ISOMETRIC) {
2078 t->hex_width = hex_side;
2079 } else {
2080 t->hex_height = hex_side;
2081 }
2082
2083 topo |= TF_HEX;
2084
2085 /* Hex tilesets are drawn the same as isometric. */
2086 /* FIXME: There will be other legal values to be used with hex
2087 * tileset in the future, and this would just overwrite it. */
2088 t->type = TS_ISOMETRIC;
2089 }
2090
2091 if (topology_id >= 0) {
2092 if (((topology_id & TF_HEX) && topology_id != (topo & (TF_ISO | TF_HEX)))
2093 || (!(topology_id & TF_HEX) && (topo & TF_HEX))) {
2094 /* Not of requested topology */
2095 goto ON_ERROR;
2096 }
2097 }
2098
2099 t->ts_topo_idx = ts_topology_index(topo);
2100
2101 /* Needed for older compilers to not give "used uninitialized" warning */
2102 vsup = FALSE;
2103
2104 switch (t->type) {
2105 case TS_ISOMETRIC:
2107 break;
2108 case TS_OVERHEAD:
2110 break;
2111 }
2112
2113 if (!vsup) {
2114 /* TRANS: "Overhead" or "Isometric" */
2115 log_normal(_("Client does not support %s tilesets."),
2116 _(ts_type_name(t->type)));
2117 log_normal(_("Using default tileset instead."));
2119 goto ON_ERROR;
2120 }
2121
2123
2124 /* Create arrays of valid and cardinal tileset dirs. These depend
2125 * entirely on the tileset, not the topology. They are also in clockwise
2126 * rotational ordering. */
2128 dir = DIR8_NORTH;
2129 do {
2130 if (is_valid_tileset_dir(t, dir)) {
2133 }
2134 if (is_cardinal_tileset_dir(t, dir)) {
2137 }
2138
2139 dir = dir_cw(dir);
2140 } while (dir != DIR8_NORTH);
2141
2142 fc_assert(t->num_valid_tileset_dirs % 2 == 0); /* Assumed elsewhere. */
2145
2147 "tilespec.normal_tile_width")
2149 "tilespec.normal_tile_height")) {
2150 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2151 goto ON_ERROR;
2152 }
2154 /* Adjust width to be multiple of 8 */
2155 if (scale != 1.0f) {
2156 i = t->normal_tile_width;
2157 while (i % 8 != 0) {
2158 i++;
2159 }
2160 t->scale = (t->scale * i) / t->normal_tile_width;
2161 t->normal_tile_width = i;
2162 }
2164 if (t->type == TS_ISOMETRIC) {
2166 if (tileset_hex_height(t) > 0) {
2168 } else {
2169 t->full_tile_height = 3 * t->normal_tile_height / 2;
2170 }
2171 } else {
2174 }
2176 = secfile_lookup_int_default(file, t->full_tile_width, "tilespec.unit_width");
2178 = secfile_lookup_int_default(file, t->full_tile_height, "tilespec.unit_height");
2180 "tilespec.small_tile_width")
2182 "tilespec.small_tile_height")) {
2183 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2184 goto ON_ERROR;
2185 }
2186 if (t->unit_tile_width != t->full_tile_width && t->scale != 1.0f) {
2188 }
2189 if (t->unit_tile_height != t->full_tile_height && t->scale != 1.0f) {
2191 }
2194 log_verbose("tile sizes %dx%d, %d%d unit, %d%d small",
2198
2199 tstr = secfile_lookup_str(file, "tilespec.fog_style");
2200 if (tstr == NULL) {
2201 log_error("Tileset \"%s\": no fog_style", t->name);
2202 goto ON_ERROR;
2203 }
2204
2206 if (!fog_style_is_valid(t->fogstyle)) {
2207 log_error("Tileset \"%s\": unknown fog_style \"%s\"", t->name, tstr);
2208 goto ON_ERROR;
2209 }
2210
2211 tstr = secfile_lookup_str(file, "tilespec.darkness_style");
2212 if (tstr == NULL) {
2213 log_error("Tileset \"%s\": no darkness_style", t->name);
2214 goto ON_ERROR;
2215 }
2216
2219 log_error("Tileset \"%s\": unknown darkness_style \"%s\"", t->name, tstr);
2220 goto ON_ERROR;
2221 }
2222
2224 && (t->type == TS_OVERHEAD || t->hex_width > 0 || t->hex_height > 0)) {
2225 log_error("Invalid darkness style set in tileset \"%s\".", t->name);
2226 goto ON_ERROR;
2227 }
2228
2230 "tilespec.unit_flag_offset_x")
2232 "tilespec.unit_flag_offset_y")
2234 "tilespec.city_flag_offset_x")
2236 "tilespec.city_flag_offset_y")
2237 || !secfile_lookup_int(file, &t->unit_offset_x,
2238 "tilespec.unit_offset_x")
2239 || !secfile_lookup_int(file, &t->unit_offset_y,
2240 "tilespec.unit_offset_y")
2242 "tilespec.activity_offset_x")
2244 "tilespec.activity_offset_y")
2245 || !secfile_lookup_int(file, &t->select_offset_x,
2246 "tilespec.select_offset_x")
2247 || !secfile_lookup_int(file, &t->select_offset_y,
2248 "tilespec.select_offset_y")
2250 "tilespec.stack_size_offset_x")
2252 "tilespec.stack_size_offset_y")
2253 || !secfile_lookup_int(file, &t->city_offset_x,
2254 "tilespec.city_offset_x")
2255 || !secfile_lookup_int(file, &t->city_offset_y,
2256 "tilespec.city_offset_y")
2258 "tilespec.city_size_offset_x")
2260 "tilespec.city_size_offset_y")
2262 "tilespec.citybar_offset_y")
2264 "tilespec.tilelabel_offset_y")
2266 "tilespec.occupied_offset_x")
2268 "tilespec.occupied_offset_y")) {
2269 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2270 goto ON_ERROR;
2271 }
2272
2274 "tilespec.unit_upkeep_offset_y");
2276 "tilespec.unit_upkeep_small_offset_y");
2277 t->svg_height = secfile_lookup_int_default(file, 44, "tilespec.svg_height");
2278 t->default_time_per_frame = secfile_lookup_int_default(file, 3, "tilespec.time_per_frame");
2279
2290 t->unit_offset_x = t->scale * t->unit_offset_x;
2291 t->unit_offset_y = t->scale * t->unit_offset_y;
2294 t->city_offset_x = t->scale * t->city_offset_x;
2295 t->city_offset_y = t->scale * t->city_offset_y;
2300 t->svg_height *= t->scale;
2301
2302 if (t->scale != 1.0f
2305 }
2306 if (t->scale != 1.0f
2309 }
2310
2312 "tilespec.unit_default_orientation");
2313 if (!c) {
2314 /* This is valid, but tileset must specify icon for every unit */
2316 } else {
2317 dir = dir_by_tileset_name(c);
2318
2319 if (!direction8_is_valid(dir)) {
2321 _("Unknown unit_default_orientation \"%s\""), c);
2322 goto ON_ERROR;
2323 } else {
2324 /* Default orientation is allowed to not be a valid one for the
2325 * tileset */
2326 t->unit_default_orientation = dir;
2327 }
2328 }
2329
2330 c = secfile_lookup_str(file, "tilespec.main_intro_file");
2332 log_debug("intro file %s", t->main_intro_filename);
2333
2334 /* Layer order */
2335 num_layers = 0;
2336 layer_order = secfile_lookup_str_vec(file, &num_layers,
2337 "tilespec.layer_order");
2338 if (layer_order != NULL) {
2339 for (i = 0; i < num_layers; i++) {
2340 int j;
2343
2344 /* Check for wrong layer names. */
2345 if (!mapview_layer_is_valid(layer)) {
2346 log_error("layer_order: Invalid layer \"%s\" in %s",
2348 goto ON_ERROR;
2349 }
2350 /* Check for duplicates. */
2351 for (j = 0; j < i; j++) {
2352 if (t->layer_order[j] == layer) {
2353 log_error("layer_order: Duplicate layer \"%s\" in %s",
2355 goto ON_ERROR;
2356 }
2357 }
2358 t->layer_order[i] = layer;
2359 }
2360
2361 /* Now check that all layers are present. Doing it now allows for a more
2362 * comprehensive error message. */
2363 for (i = 0; i < LAYER_COUNT; i++) {
2364 int j;
2365 bool found = FALSE;
2366
2367 for (j = 0; j < num_layers; j++) {
2368 if (i == t->layer_order[j]) {
2369 found = TRUE;
2370 break;
2371 }
2372 }
2373 if (!found) {
2374 log_error("layer_order: Missing layer \"%s\" in %s",
2376 goto ON_ERROR;
2377 }
2378 }
2379
2381 } else {
2382 /* There is no layer_order tag in the specfile -> use the default */
2383 for (i = 0; i < LAYER_COUNT; i++) {
2384 t->layer_order[i] = i;
2385 }
2386 }
2387
2388 /* Terrain layer info. */
2389 for (i = 0; i < MAX_NUM_LAYERS; i++) {
2390 struct tileset_layer *tslp = &t->layers[i];
2391 int j, k;
2392
2393 tslp->match_types =
2394 (char **) secfile_lookup_str_vec(file, &tslp->match_count,
2395 "layer%d.match_types", i);
2396 for (j = 0; j < tslp->match_count; j++) {
2397 tslp->match_types[j] = fc_strdup(tslp->match_types[j]);
2398
2399 for (k = 0; k < j; k++) {
2400 if (tslp->match_types[k][0] == tslp->match_types[j][0]) {
2402 _("[layer%d] match_types: \"%s\" initial "
2403 "('%c') is not unique."),
2404 i, tslp->match_types[j], tslp->match_types[j][0]);
2405 /* FIXME: Returns NULL. */
2406 }
2407 }
2408 }
2409 }
2410
2411 /* Tile drawing info. */
2413 if (NULL == sections || 0 == section_list_size(sections)) {
2415 _("No [%s] sections present."),
2417 goto ON_ERROR;
2418 }
2419
2420 fc_assert(t->tile_hash == NULL);
2422
2423 section_list_iterate(sections, psection) {
2424 const char *sec_name = section_name(psection);
2426 const char *sprite_type;
2427 int l;
2428 const char *terrain_name;
2429
2430 terrain_name = secfile_lookup_str(file, "%s.tag", sec_name);
2431
2432 if (terrain_name != NULL) {
2433 draw->name = fc_strdup(terrain_name);
2434 } else {
2435 tileset_error(LOG_ERROR, _("No terrain tag given in section [%s] in %s."),
2438 goto ON_ERROR;
2439 }
2440
2441 draw->blending = secfile_lookup_int_default(file, 0, "%s.blend_layer",
2442 sec_name);
2443 draw->blending = CLIP(0, draw->blending, MAX_NUM_LAYERS);
2444
2445 draw->is_reversed = secfile_lookup_bool_default(file, FALSE,
2446 "%s.is_reversed",
2447 sec_name);
2448 draw->num_layers = secfile_lookup_int_default(file, 0, "%s.num_layers",
2449 sec_name);
2450 draw->num_layers = CLIP(1, draw->num_layers, MAX_NUM_LAYERS);
2451
2452 for (l = 0; l < draw->num_layers; l++) {
2453 struct drawing_layer *dlp = &draw->layer[l];
2454 struct tileset_layer *tslp = &t->layers[l];
2455 const char *match_type;
2456 const char **match_with;
2457 size_t count;
2458
2459 dlp->is_tall
2460 = secfile_lookup_bool_default(file, FALSE, "%s.layer%d_is_tall",
2461 sec_name, l);
2462 dlp->offset_x
2463 = secfile_lookup_int_default(file, 0, "%s.layer%d_offset_x",
2464 sec_name, l);
2465 dlp->offset_y
2466 = secfile_lookup_int_default(file, 0, "%s.layer%d_offset_y",
2467 sec_name, l);
2468 dlp->offset_x = ceil(t->scale * dlp->offset_x);
2469 dlp->offset_y = ceil(t->scale * dlp->offset_y);
2470
2472 "%s.layer%d_match_type",
2473 sec_name, l);
2474 if (match_type) {
2475 int j;
2476
2477 /* Determine our match_type. */
2478 for (j = 0; j < tslp->match_count; j++) {
2479 if (fc_strcasecmp(tslp->match_types[j], match_type) == 0) {
2480 break;
2481 }
2482 }
2483 if (j >= tslp->match_count) {
2484 log_error("[%s] invalid match_type \"%s\" in %s.",
2486 } else {
2487 dlp->match_index[dlp->match_indices++] = j;
2488 }
2489 }
2490
2491 match_with = secfile_lookup_str_vec(file, &count,
2492 "%s.layer%d_match_with",
2493 sec_name, l);
2494 if (match_with) {
2495 int j, k;
2496
2497 if (count > MAX_NUM_MATCH_WITH) {
2498 log_error("[%s] match_with has too many types (%d, max %d) in %s",
2499 sec_name, (int) count, MAX_NUM_MATCH_WITH,
2500 tileset_name_get(t));
2501 count = MAX_NUM_MATCH_WITH;
2502 }
2503
2504 if (1 < dlp->match_indices) {
2505 log_error("[%s] previous match_with ignored in %s.",
2507 dlp->match_indices = 1;
2508 } else if (1 > dlp->match_indices) {
2509 log_error("[%s] missing match_type, using \"%s\" in %s.",
2510 sec_name, tslp->match_types[0], tileset_name_get(t));
2511 dlp->match_index[0] = 0;
2512 dlp->match_indices = 1;
2513 }
2514
2515 for (k = 0; k < count; k++) {
2516 for (j = 0; j < tslp->match_count; j++) {
2517 if (fc_strcasecmp(tslp->match_types[j], match_with[k]) == 0) {
2518 break;
2519 }
2520 }
2521 if (j >= tslp->match_count) {
2522 log_error("[%s] layer%d_match_with: invalid \"%s\".",
2523 sec_name, l, match_with[k]);
2524 } else if (1 < count) {
2525 int m;
2526
2527 for (m = 0; m < dlp->match_indices; m++) {
2528 if (dlp->match_index[m] == j) {
2529 log_error("[%s] layer%d_match_with: duplicate \"%s\" in %s.",
2531 break;
2532 }
2533 }
2534 if (m >= dlp->match_indices) {
2535 dlp->match_index[dlp->match_indices++] = j;
2536 }
2537 } else {
2538 dlp->match_index[dlp->match_indices++] = j;
2539 }
2540 }
2542 match_with = NULL;
2543 }
2544
2545 /* Check match_indices */
2546 switch (dlp->match_indices) {
2547 case 0:
2548 case 1:
2549 dlp->match_style = MATCH_NONE;
2550 break;
2551 case 2:
2552 if (dlp->match_index[0] == dlp->match_index[1] ) {
2553 dlp->match_style = MATCH_SAME;
2554 } else {
2555 dlp->match_style = MATCH_PAIR;
2556 }
2557 break;
2558 default:
2559 dlp->match_style = MATCH_FULL;
2560 break;
2561 };
2562
2564 = secfile_lookup_str_default(file, "whole", "%s.layer%d_sprite_type",
2565 sec_name, l);
2566 dlp->sprite_type = check_sprite_type(sprite_type, sec_name);
2567
2568 switch (dlp->sprite_type) {
2569 case CELL_WHOLE:
2570 /* OK, no problem */
2571 break;
2572 case CELL_CORNER:
2573 if (dlp->is_tall
2574 || dlp->offset_x > 0
2575 || dlp->offset_y > 0) {
2576 log_error("[%s] layer %d: you cannot have tall terrain or\n"
2577 "a sprite offset with a cell-based drawing method in %s.",
2579 dlp->is_tall = FALSE;
2580 dlp->offset_x = dlp->offset_y = 0;
2581 }
2582 break;
2583 };
2584 }
2585
2586 if (!drawing_hash_insert(t->tile_hash, draw->name, draw)) {
2587 log_error("warning: multiple tile sections containing terrain tag \"%s\" in %s.",
2588 draw->name, tileset_name_get(t));
2589 goto ON_ERROR;
2590 }
2592 section_list_destroy(sections);
2593 sections = NULL;
2594
2596
2597 for (i = 0; i < ESTYLE_COUNT; i++) {
2599 }
2601
2602 for (i = 0; (extraname = secfile_lookup_str_default(file, NULL,
2603 "extras.styles%d.name",
2604 i)); i++) {
2605 const char *style_name;
2606 enum extrastyle_id style;
2607
2608 style_name = secfile_lookup_str_default(file, "Single1",
2609 "extras.styles%d.style", i);
2611 if (!extrastyle_id_is_valid(style)) {
2612 log_error("Unknown extra style \"%s\" for extra \"%s\" in %s.",
2614 goto ON_ERROR;
2615 }
2616
2617 if (!estyle_hash_insert(t->estyle_hash, extraname, style)) {
2618 log_error("warning: duplicate extrastyle entry [%s] in %s.",
2620 goto ON_ERROR;
2621 }
2622 }
2623
2625
2628 "tilespec.files");
2629
2630 if (svg) {
2632 type_name = "svg";
2633
2634 /* Avoid "unused entry" warning about the other list */
2635 secfile_entry_ignore_by_path(file, "tilespec.files_pixel");
2636 } else {
2638 type_name = "pixel";
2639
2640 /* Avoid "unused entry" warning about the other list */
2641 secfile_entry_ignore_by_path(file, "tilespec.files_svg");
2642 }
2643
2646 "tilespec.files_%s", type_name);
2649 log_error("No tile graphics files specified in \"%s\" for %s mode.",
2650 type_name, fname);
2651 goto ON_ERROR;
2652 }
2653
2654 fc_assert(t->sprite_hash == nullptr);
2656
2657 fc_assert(t->anim_hash == nullptr);
2658 t->anim_hash = anim_hash_new();
2659
2662 verbose, duplicates_ok)) {
2663 goto ON_ERROR;
2664 }
2665
2668 verbose, duplicates_ok)) {
2669 goto ON_ERROR;
2670 }
2671
2674
2676
2678 = (char **) secfile_lookup_str_vec(file, &num_preferred_themes,
2679 "tilespec.preferred_themes");
2680 t->num_preferred_themes = num_preferred_themes;
2681 for (i = 0; i < t->num_preferred_themes; i++) {
2683 }
2684
2686 secfile_destroy(file);
2687 log_verbose("Finished reading \"%s\".", fname);
2688 free(fname);
2689
2690 return t;
2691
2692ON_ERROR:
2693 secfile_destroy(file);
2694 free(fname);
2695 tileset_free(t);
2696
2697 if (NULL != sections) {
2698 section_list_destroy(sections);
2699 }
2700
2701 return NULL;
2702}
2703
2704/************************************************************************/
2707static const char *citizen_rule_name(enum citizen_category citizen)
2708{
2709 /* These strings are used in reading the tileset. Do not
2710 * translate. */
2711 switch (citizen) {
2712 case CITIZEN_HAPPY:
2713 return "happy";
2714 case CITIZEN_CONTENT:
2715 return "content";
2716 case CITIZEN_UNHAPPY:
2717 return "unhappy";
2718 case CITIZEN_ANGRY:
2719 return "angry";
2720 default:
2721 break;
2722 }
2723 log_error("Unknown citizen type: %d.", (int) citizen);
2724 return NULL;
2725}
2726
2727/************************************************************************/
2732static const char *cardinal_index_str(const struct tileset *t, int idx)
2733{
2734 static char c[64];
2735 int i;
2736
2737 c[0] = '\0';
2738 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
2739 int value = (idx >> i) & 1;
2740
2741 cat_snprintf(c, sizeof(c), "%s%d",
2743 }
2744
2745 return c;
2746}
2747
2748/************************************************************************/
2752static char *valid_index_str(const struct tileset *t, int idx)
2753{
2754 static char c[64];
2755 int i;
2756
2757 c[0] = '\0';
2758 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
2759 int value = (idx >> i) & 1;
2760
2761 cat_snprintf(c, sizeof(c), "%s%d",
2763 }
2764
2765 return c;
2766}
2767
2768/************************************************************************/
2775static struct anim *anim_new(int frames, int time_per_frame)
2776{
2777 struct anim *ret = fc_malloc(sizeof(struct anim));
2778
2779 ret->frames = frames;
2780 ret->time = -1;
2781 ret->time_per_frame = time_per_frame;
2782 ret->sprites = fc_malloc(frames * sizeof(struct sprite *));
2783 ret->show_always = FALSE;
2784
2785 return ret;
2786}
2787
2788/************************************************************************/
2793static void anim_free(struct anim *a)
2794{
2795 if (a != nullptr) {
2796 free(a->sprites);
2797 free(a);
2798 }
2799}
2800
2801/************************************************************************/
2808static struct sprite *load_sprite(struct tileset *t, const char *tag_name,
2809 bool scale, bool smooth, bool svgflag)
2810{
2811 struct small_sprite *ss;
2812 float sprite_scale = 1.0f;
2813
2814 log_debug("load_sprite(tag='%s')", tag_name);
2815 /* Lookup information about where the sprite is found. */
2817 return NULL;
2818 }
2819
2820 fc_assert(ss->ref_count >= 0);
2821
2822 if (!ss->sprite) {
2823 /* If the sprite hasn't been loaded already, then load it. */
2824 fc_assert(ss->ref_count == 0);
2825
2826 if (ss->file) {
2827 int w, h;
2828 struct sprite *s;
2829
2830 if (scale) {
2831 s = load_gfx_file(ss->file, svgflag);
2832
2833 if (s != NULL) {
2834 get_sprite_dimensions(s, &w, &h);
2835 ss->sprite = crop_sprite(s, 0, 0, w,
2836 h, NULL, -1, -1, t->scale, smooth);
2837 free_sprite(s);
2838 }
2839 } else {
2840 ss->sprite = load_gfx_file(ss->file, svgflag);
2841 }
2842
2843 if (!ss->sprite) {
2845 _("Couldn't load gfx file \"%s\" for sprite '%s'."),
2846 ss->file, tag_name);
2847 }
2848 } else {
2849 int sf_w, sf_h;
2850
2852 get_sprite_dimensions(ss->sf->big_sprite, &sf_w, &sf_h);
2853 if (ss->x < 0 || ss->x + ss->width > sf_w
2854 || ss->y < 0 || ss->y + ss->height > sf_h) {
2856 _("Sprite '%s' in file \"%s\" isn't within the image!"),
2857 tag_name, ss->sf->file_name);
2858 return NULL;
2859 }
2860 if (scale) {
2861 sprite_scale = t->scale;
2862 }
2863 ss->sprite = crop_sprite(ss->sf->big_sprite, ss->x, ss->y, ss->width,
2864 ss->height, NULL, -1, -1, sprite_scale,
2865 smooth);
2866 }
2867 }
2868
2869 /* Track the reference count so we know when to free the sprite. */
2870 ss->ref_count++;
2871
2872 return ss->sprite;
2873}
2874
2875/************************************************************************/
2878static struct sprite *create_plr_sprite(struct color *pcolor)
2879{
2880 struct sprite *sprite;
2881
2883
2886
2887 return sprite;
2888}
2889
2890/************************************************************************/
2894static void unload_sprite(struct tileset *t, const char *tag_name)
2895{
2896 struct small_sprite *ss;
2897
2900 fc_assert_ret(ss->ref_count >= 1);
2901 fc_assert_ret(ss->sprite);
2902
2903 ss->ref_count--;
2904
2905 if (ss->ref_count == 0) {
2906 /* Nobody's using the sprite anymore, so we should free it. We know
2907 * where to find it if we need it again. */
2908 log_debug("freeing sprite '%s'.", tag_name);
2909 free_sprite(ss->sprite);
2910 ss->sprite = NULL;
2911 }
2912}
2913
2914/************************************************************************/
2918static bool sprite_exists(const struct tileset *t, const char *tag_name)
2919{
2920 /* Lookup information about where the sprite is found. */
2922}
2923
2924/* Not very safe, but convenient: */
2925#define SET_SPRITE(field, tag) \
2926 do { \
2927 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2928 if (t->sprites.field == NULL) { \
2929 tileset_error(LOG_FATAL, tileset_name_get(t), \
2930 _("Sprite for tag '%s' missing."), tag); \
2931 } \
2932 } while (FALSE)
2933
2934
2935#define SET_SPRITE_NOTSMOOTH(field, tag) \
2936 do { \
2937 t->sprites.field = load_sprite(t, tag, TRUE, FALSE, FALSE); \
2938 if (t->sprites.field == NULL) { \
2939 tileset_error(LOG_FATAL, tileset_name_get(t), \
2940 _("Sprite for tag '%s' missing."), tag); \
2941 } \
2942 } while (FALSE)
2943
2944#define SET_SPRITE_UNSCALED(field, tag) \
2945 do { \
2946 t->sprites.field = load_sprite(t, tag, FALSE, FALSE, FALSE); \
2947 if (t->sprites.field == NULL) { \
2948 tileset_error(LOG_FATAL, tileset_name_get(t), \
2949 _("Sprite for tag '%s' missing."), tag); \
2950 } \
2951 } while (FALSE)
2952
2953/* Sets sprites.field to tag or (if tag isn't available) to alt */
2954#define SET_SPRITE_ALT(field, tag, alt) \
2955 do { \
2956 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2957 if (!t->sprites.field) { \
2958 t->sprites.field = load_sprite(t, alt, TRUE, TRUE, FALSE); \
2959 } \
2960 if (t->sprites.field == NULL) { \
2961 tileset_error(LOG_FATAL, tileset_name_get(t), \
2962 _("Sprite for tags '%s' and alternate '%s' are " \
2963 "both missing."), tag, alt); \
2964 } \
2965 } while (FALSE)
2966
2967/* Sets sprites.field to tag or (if tag isn't available) to deprecated alt */
2968#define SET_SPRITE_DEPR_ALT(field, tag, alt, ver) \
2969 do { \
2970 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2971 if (!t->sprites.field) { \
2972 t->sprites.field = load_sprite(t, alt, TRUE, TRUE, FALSE); \
2973 if (t->sprites.field != NULL) { \
2974 log_deprecation(_("%s: Using tag \"%s\" deprecated by \"%s\" in %s"), \
2975 tileset_name_get(t), alt, tag, ver); \
2976 } \
2977 } \
2978 if (t->sprites.field == NULL) { \
2979 tileset_error(LOG_FATAL, tileset_name_get(t), \
2980 _("Sprite for tags '%s' and alternate '%s' are " \
2981 "both missing."), tag, alt); \
2982 } \
2983 } while (FALSE)
2984
2985/* Sets sprites.field to tag, or nullptr if not available */
2986#define SET_SPRITE_OPT(field, tag) \
2987 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE)
2988
2989#define SET_SPRITE_ALT_OPT(field, tag, alt) \
2990 do { \
2991 t->sprites.field = tiles_lookup_sprite_tag_alt(t, LOG_VERBOSE, tag, alt, \
2992 NULL, "sprite", #field, \
2993 TRUE); \
2994 } while (FALSE)
2995
2996#define SET_ANIM(field, tag) \
2997 do { \
2998 t->sprites.field = anim_load(t, tag, 0); \
2999 if (t->sprites.field == nullptr) { \
3000 tileset_error(LOG_FATAL, tileset_name_get(t), \
3001 _("Animation for tag '%s' missing."), tag); \
3002 } \
3003 } while (FALSE)
3004
3005/* Sets sprites.field to tag, or nullptr if not available */
3006#define SET_ANIM_OPT(field, tag) \
3007 t->sprites.field = anim_load(t, tag, 0)
3008
3009/************************************************************************/
3017static struct anim *anim_load(struct tileset *t, const char *tag,
3018 int time_per_frame)
3019{
3020 int frames = 0;
3021 char buf[1500];
3022 struct anim *ret;
3023 int i;
3024
3025 do {
3026 fc_snprintf(buf, sizeof(buf), "%s:%d", tag, frames++);
3027 } while (sprite_exists(t, buf));
3028
3029 if (--frames == 0) {
3030 if (sprite_exists(t, tag)) {
3031 log_deprecation(_("No animation \"%s\", but there's a single "
3032 "sprite by such a tag. Should it be an animation?"),
3033 tag);
3034 }
3035
3036 return nullptr;
3037 }
3038
3039 if (time_per_frame <= 0) {
3041 }
3042
3044
3045 for (i = 0; i < frames; i++) {
3046 fc_snprintf(buf, sizeof(buf), "%s:%d", tag, i);
3047 ret->sprites[i] = load_sprite(t, buf, TRUE, TRUE, FALSE);
3048 if (ret->sprites[i] == nullptr) {
3050 _("Animation sprite for tag '%s' missing."), buf);
3051 }
3052 }
3053
3054 anim_hash_insert(t->anim_hash, tag, ret);
3055
3056 return ret;
3057}
3058
3059/************************************************************************/
3064static void anim_advance_time(struct anim *a)
3065{
3066 a->time++;
3067}
3068
3069/************************************************************************/
3075static struct sprite *anim_get_current_frame(struct anim *a)
3076{
3077 int time;
3078
3080 return a->sprites[0];
3081 }
3082
3083 if (a->time >= 0) {
3084 time = a->time;
3085 } else {
3086 time = global_anim_time;
3087 }
3088
3089 return a->sprites[(time / a->time_per_frame) % a->frames];
3090}
3091
3092/************************************************************************/
3101
3102/************************************************************************/
3106 struct citizen_set *set,
3108 const char *tag_group,
3109 const char *set_name,
3110 bool required)
3111{
3112 /* Load the specialist sprite graphics. */
3113 char buffer[512];
3114 int j;
3115 struct specialist *spe = specialist_by_number(id);
3116 const char *tag = spe->graphic_str;
3117 const char *graphic_alt = spe->graphic_alt;
3118
3119 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
3120 /* Try tag name + index number */
3121 if (tag_group != NULL) {
3122 fc_snprintf(buffer, sizeof(buffer), "%s.%s_%d", tag_group, tag, j);
3123 } else {
3124 fc_snprintf(buffer, sizeof(buffer), "%s_%d", tag, j);
3125 }
3126 set->specialist[id].sprite[j] = load_sprite(t, buffer,
3127 FALSE, FALSE, FALSE);
3128
3129 /* Break if no more index specific sprites are defined */
3130 if (!set->specialist[id].sprite[j]) {
3131 break;
3132 }
3133 }
3134
3135 if (j == 0) {
3136 /* Try non-indexed */
3137 set->specialist[id].sprite[j] = load_sprite(t, tag,
3138 FALSE, FALSE, FALSE);
3139
3140 if (set->specialist[id].sprite[j]) {
3141 j = 1;
3142 }
3143 }
3144
3145 if (j == 0) {
3146 /* Try the alt tag */
3147 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
3148 /* Try alt tag name + index number */
3149 if (tag_group != NULL) {
3150 fc_snprintf(buffer, sizeof(buffer), "%s.%s_%d", tag_group, graphic_alt, j);
3151 } else {
3152 fc_snprintf(buffer, sizeof(buffer), "%s_%d", graphic_alt, j);
3153 }
3154 set->specialist[id].sprite[j] = load_sprite(t, buffer,
3155 FALSE, FALSE, FALSE);
3156
3157 /* Break if no more index specific sprites are defined */
3158 if (!set->specialist[id].sprite[j]) {
3159 break;
3160 }
3161 }
3162 }
3163
3164 if (j == 0) {
3165 /* Try alt tag non-indexed */
3167 FALSE, FALSE, FALSE);
3168
3169 if (set->specialist[id].sprite[j]) {
3170 j = 1;
3171 }
3172 }
3173
3174 set->specialist[id].count = j;
3175
3176 /* Still nothing? Give up. */
3177 if (j == 0 && required) {
3178 /* TRANS: First %s is a graphics tag of the specialist, second one
3179 * is a citizen set name; 'citizen_graphic' from styles.ruleset */
3181 _("No graphics for specialist \"%s\" in %s."),
3182 tag, set_name);
3183 }
3184}
3185
3186/************************************************************************/
3190{
3192 "default set", TRUE);
3193}
3194
3195/************************************************************************/
3199 struct citizen_set *set,
3200 const char *tag_group,
3201 const char *set_name,
3202 bool required)
3203{
3204 int i, j;
3205 char buffer[512];
3206
3207 /* Load the citizen sprite graphics, no specialist. */
3208 for (i = 0; i < CITIZEN_LAST; i++) {
3209 const char *name = citizen_rule_name(i);
3210
3211 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
3212 if (tag_group != NULL) {
3213 fc_snprintf(buffer, sizeof(buffer), "citizen.%s.%s_%d", tag_group, name, j);
3214 } else {
3215 fc_snprintf(buffer, sizeof(buffer), "citizen.%s_%d", name, j);
3216 }
3217 set->citizen[i].sprite[j] = load_sprite(t, buffer, FALSE, FALSE, FALSE);
3218 if (!set->citizen[i].sprite[j]) {
3219 break;
3220 }
3221 }
3222 set->citizen[i].count = j;
3223 if (j == 0 && required) {
3224 /* TRANS: First %s is type of the citizen ("happy" ... "angry"), second one
3225 * is a citizen set name; 'citizen_graphic' from styles.ruleset */
3227 _("No graphics for citizen \"%s\" in %s."),
3228 name, set_name);
3229 }
3230 }
3231}
3232
3233/************************************************************************/
3239static struct sprite *get_city_sprite(const struct city_sprite *city_sprite,
3240 const struct city *pcity)
3241{
3242 /* Get style and match the best tile based on city size */
3243 int style = style_of_city(pcity);
3244 int num_thresholds;
3246 int img_index;
3247
3249
3252
3253 if (num_thresholds == 0) {
3254 return NULL;
3255 }
3256
3257 /* Get the sprite with the index defined by the effects. */
3258 img_index = pcity->client.city_image;
3259 if (img_index == -100) {
3260 /* Server doesn't know right value as this is from old savegame.
3261 * Guess here based on *client* side information as was done in
3262 * versions where information was not saved to savegame - this should
3263 * give us right answer of what city looked like by the time it was
3264 * put under FoW. */
3266 }
3268
3269 return thresholds[img_index].sprite;
3270}
3271
3272/************************************************************************/
3275static int load_city_thresholds_sprites(struct tileset *t, const char *tag,
3276 char *graphic, char *graphic_alt,
3278{
3279 char buffer[128];
3280 char *gfx_in_use = graphic;
3281 int num_thresholds = 0;
3282 struct sprite *sprite;
3283 int size;
3284
3285 *thresholds = NULL;
3286
3287 for (size = 0; size < MAX_CITY_SIZE; size++) {
3288 fc_snprintf(buffer, sizeof(buffer), "%s_%s_%d",
3289 gfx_in_use, tag, size);
3290 if ((sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE))) {
3293 (*thresholds)[num_thresholds - 1].sprite = sprite;
3294 } else if (size == 0) {
3295 if (gfx_in_use == graphic) {
3296 /* Try again with graphic_alt. */
3297 size--;
3298 gfx_in_use = graphic_alt;
3299 } else {
3300 /* Don't load any others if the 0 element isn't there. */
3301 break;
3302 }
3303 }
3304 }
3305
3306 return num_thresholds;
3307}
3308
3309/************************************************************************/
3316static struct city_sprite *load_city_sprite(struct tileset *t,
3317 const char *tag)
3318{
3319 struct city_sprite *city_sprite = fc_malloc(sizeof(*city_sprite));
3320 int style;
3321
3322 /* Store number of styles we have allocated memory for.
3323 * game.control.num_city_styles might change if client disconnects from
3324 * server and connects new one. */
3327 * sizeof(*city_sprite->styles));
3328
3329 for (style = 0; style < city_sprite->num_styles; style++) {
3331 load_city_thresholds_sprites(t, tag, city_styles[style].graphic,
3332 city_styles[style].graphic_alt,
3334 }
3335
3336 return city_sprite;
3337}
3338
3339/************************************************************************/
3345{
3346 int style;
3347
3348 if (!city_sprite) {
3349 return;
3350 }
3351 for (style = 0; style < city_sprite->num_styles; style++) {
3352 if (city_sprite->styles[style].land_thresholds) {
3354 }
3355 }
3358}
3359
3360/************************************************************************/
3365{
3366 char buffer[512], buffer2[512];
3367 const int W = t->normal_tile_width, H = t->normal_tile_height;
3368 int i, j, f;
3369
3371
3372 SET_SPRITE_UNSCALED(treaty_thumb[0], "treaty.disagree_thumb_down");
3373 SET_SPRITE_UNSCALED(treaty_thumb[1], "treaty.agree_thumb_up");
3374
3375 for (j = 0; j < INDICATOR_COUNT; j++) {
3376 const char *names[] = {"science_bulb", "warming_sun", "cooling_flake"};
3377
3378 for (i = 0; i < NUM_TILES_PROGRESS; i++) {
3379 fc_snprintf(buffer, sizeof(buffer), "s.%s_%d", names[j], i);
3380 SET_SPRITE_UNSCALED(indicator[j][i], buffer);
3381 }
3382 }
3383
3384 SET_SPRITE(arrow[ARROW_RIGHT], "s.right_arrow");
3385 SET_SPRITE(arrow[ARROW_PLUS], "s.plus");
3386 SET_SPRITE(arrow[ARROW_MINUS], "s.minus");
3387 if (t->type == TS_ISOMETRIC) {
3388 SET_SPRITE(dither_tile, "t.dither_tile");
3389 }
3390
3392 SET_SPRITE_NOTSMOOTH(mask.tile, "mask.tile");
3393 } else {
3394 SET_SPRITE(mask.tile, "mask.tile");
3395 }
3396 SET_SPRITE(mask.worked_tile, "mask.worked_tile");
3397 SET_SPRITE(mask.unworked_tile, "mask.unworked_tile");
3398
3399 SET_SPRITE_UNSCALED(tax_luxury, "s.tax_luxury");
3400 SET_SPRITE_UNSCALED(tax_science, "s.tax_science");
3401 SET_SPRITE_UNSCALED(tax_gold, "s.tax_gold");
3402
3404
3405 for (i = 0; i < SPACESHIP_COUNT; i++) {
3406 const char *names[SPACESHIP_COUNT]
3407 = {"solar_panels", "life_support", "habitation",
3408 "structural", "fuel", "propulsion", "exhaust"};
3409
3410 fc_snprintf(buffer, sizeof(buffer), "spaceship.%s", names[i]);
3411 SET_SPRITE(spaceship[i], buffer);
3412 }
3413
3414 for (i = 0; i < CURSOR_LAST; i++) {
3415 const char *names[CURSOR_LAST] =
3416 {"goto", "patrol", "paradrop", "teleport", "nuke", "select",
3417 "invalid", "attack", "edit_paint", "edit_add", "wait"};
3418
3419 for (f = 0; f < NUM_CURSOR_FRAMES; f++) {
3420 struct small_sprite *ss;
3421
3422 fc_assert(ARRAY_SIZE(names) == CURSOR_LAST);
3423 fc_snprintf(buffer, sizeof(buffer), "cursor.%s%d", names[i], f);
3424 SET_SPRITE(cursor[i].frame[f], buffer);
3425
3426 if (sprite_hash_lookup(t->sprite_hash, buffer, &ss)) {
3427 t->sprites.cursor[i].hot_x = ss->hot_x;
3428 t->sprites.cursor[i].hot_y = ss->hot_y;
3429 }
3430 }
3431 }
3432
3433 for (i = 0; i < ICON_COUNT; i++) {
3434 const char *names[ICON_COUNT] = {"freeciv", "citydlg"};
3435
3436 fc_snprintf(buffer, sizeof(buffer), "icon.%s", names[i]);
3437 SET_SPRITE(icon[i], buffer);
3438 }
3439
3440 for (i = 0; i < E_COUNT; i++) {
3441 const char *tag = get_event_tag(i);
3442
3443 SET_SPRITE(events[i], tag);
3444 }
3445
3446 SET_SPRITE(explode.nuke, "explode.nuke");
3447
3449 for (i = 0; ; i++) {
3450 struct sprite *sprite;
3451
3452 fc_snprintf(buffer, sizeof(buffer), "explode.unit_%d", i);
3453 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3454 if (!sprite) {
3455 break;
3456 }
3458 }
3459
3460 SET_SPRITE(unit.auto_attack, "unit.auto_attack");
3461 /* TODO: Drop backward compatibility with "unit.auto_settler" tag. */
3462 SET_SPRITE_DEPR_ALT(unit.auto_worker, "unit.auto_worker", "unit.auto_settler", "3.3");
3463 SET_SPRITE(unit.auto_explore, "unit.auto_explore");
3464 SET_SPRITE(unit.fortified, "unit.fortified");
3465 SET_SPRITE(unit.fortifying, "unit.fortifying");
3466 SET_SPRITE(unit.go_to, "unit.goto");
3467 SET_SPRITE(unit.cultivate, "unit.cultivate");
3468 SET_SPRITE(unit.plant, "unit.plant");
3469 SET_SPRITE(unit.pillage, "unit.pillage");
3470 SET_SPRITE(unit.sentry, "unit.sentry");
3471 SET_SPRITE(unit.convert, "unit.convert");
3472 t->sprites.unit.stack = fc_malloc(sizeof(struct sprite *));
3473 t->sprites.unit.num_stack_sprites = 1;
3474 SET_SPRITE(unit.stack[0], "unit.stack");
3475 t->sprites.unit.no_more_stack_sprites = FALSE;
3476 SET_SPRITE(unit.loaded, "unit.loaded");
3477 SET_SPRITE(unit.transform, "unit.transform");
3478 SET_SPRITE(unit.connect, "unit.connect");
3479 SET_SPRITE(unit.patrol, "unit.patrol");
3480 for (i = 0; i < MAX_NUM_BATTLEGROUPS; i++) {
3481 fc_snprintf(buffer, sizeof(buffer), "unit.battlegroup_%d", i);
3482 fc_snprintf(buffer2, sizeof(buffer2), "city.size_%d", i + 1);
3485 }
3486 SET_SPRITE(unit.lowfuel, "unit.lowfuel");
3487 SET_SPRITE(unit.tired, "unit.tired");
3488
3489 t->sprites.unit.action_decision_want = anim_load(t, "unit.action_decision_want",
3490 0);
3491
3492 for (i = 0; i < NUM_TILES_HP_BAR; i++) {
3493 fc_snprintf(buffer, sizeof(buffer), "unit.hp_%d", i*10);
3494 SET_SPRITE(unit.hp_bar[i], buffer);
3495 }
3496
3497 for (i = 0; i < MAX_VET_LEVELS; i++) {
3498 /* Veteran level sprites are optional. For instance "green" units
3499 * usually have no special graphic. */
3500 fc_snprintf(buffer, sizeof(buffer), "unit.vet_%d", i);
3501 t->sprites.unit.vet_lev[i] = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3502 }
3503
3504 t->sprites.unit.select = anim_load(t, "unit.select", 1);
3505 if (t->sprites.unit.select != nullptr) {
3506 t->sprites.unit.select->show_always = TRUE;
3507 t->sprites.unit.select->time = 0; /* Not using global anim time */
3508 }
3509
3510 SET_SPRITE(citybar.shields, "citybar.shields");
3511 SET_SPRITE(citybar.food, "citybar.food");
3512 SET_SPRITE(citybar.trade, "citybar.trade");
3513 SET_SPRITE(citybar.occupied, "citybar.occupied");
3514 SET_SPRITE(citybar.background, "citybar.background");
3516 for (i = 0; ; i++) {
3517 struct sprite *sprite;
3518
3519 fc_snprintf(buffer, sizeof(buffer), "citybar.occupancy_%d", i);
3520 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3521 if (!sprite) {
3522 break;
3523 }
3525 }
3526 if (t->sprites.citybar.occupancy.size < 2) {
3528 _("Missing necessary citybar.occupancy_N sprites."));
3529 }
3530
3531#define SET_EDITOR_SPRITE(x) SET_SPRITE(editor.x, "editor." #x)
3532 SET_EDITOR_SPRITE(erase);
3533 SET_EDITOR_SPRITE(brush);
3534 SET_EDITOR_SPRITE(copy);
3535 SET_EDITOR_SPRITE(paste);
3536 SET_EDITOR_SPRITE(copypaste);
3539 SET_EDITOR_SPRITE(terrain_resource);
3540 SET_EDITOR_SPRITE(terrain_special);
3544 SET_EDITOR_SPRITE(territory);
3545 SET_EDITOR_SPRITE(properties);
3547 SET_EDITOR_SPRITE(military_base);
3548#undef SET_EDITOR_SPRITE
3549
3550 SET_SPRITE(city.disorder, "city.disorder");
3551
3552 /* Fallbacks for goto path turn numbers:
3553 * path.step_%d, path.exhausted_mp_%d
3554 * --> path.turns_%d
3555 * --> city.size_%d */
3556#define SET_GOTO_TURN_SPRITE(state, state_name, factor, factor_name) \
3557 fc_snprintf(buffer, sizeof(buffer), "path." state_name "_%d" #factor, i); \
3558 SET_SPRITE_OPT(path.s[state].turns ## factor_name [i], buffer); \
3559 if (t->sprites.path.s[state].turns ## factor_name [i] == NULL) { \
3560 t->sprites.path.s[state].turns ## factor_name [i] = \
3561 t->sprites.path.s[GTS_MP_LEFT].turns ## factor_name [i]; \
3562 }
3563
3564 for (i = 0; i < NUM_TILES_DIGITS; i++) {
3565 fc_snprintf(buffer, sizeof(buffer), "city.size_%d", i);
3566 SET_SPRITE(city.size[i], buffer);
3567 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d", i);
3568 SET_SPRITE_ALT(path.s[GTS_MP_LEFT].turns[i], buffer2, buffer);
3570 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp",,);
3571
3572 fc_snprintf(buffer, sizeof(buffer), "city.size_%d0", i);
3573 SET_SPRITE(city.size_tens[i], buffer);
3574 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d0", i);
3575 SET_SPRITE_ALT(path.s[GTS_MP_LEFT].turns_tens[i], buffer2, buffer);
3577 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp", 0, _tens);
3578
3579 fc_snprintf(buffer, sizeof(buffer), "city.size_%d00", i);
3580 SET_SPRITE_OPT(city.size_hundreds[i], buffer);
3581 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d00", i);
3582 SET_SPRITE_ALT_OPT(path.s[GTS_MP_LEFT].turns_hundreds[i], buffer2,
3583 buffer);
3585 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp", 00, _hundreds);
3586
3587 fc_snprintf(buffer, sizeof(buffer), "city.t_food_%d", i);
3588 SET_SPRITE(city.tile_foodnum[i], buffer);
3589 fc_snprintf(buffer, sizeof(buffer), "city.t_shields_%d", i);
3590 SET_SPRITE(city.tile_shieldnum[i], buffer);
3591 fc_snprintf(buffer, sizeof(buffer), "city.t_trade_%d", i);
3592 SET_SPRITE(city.tile_tradenum[i], buffer);
3593 }
3594#undef SET_GOTO_TURN_SPRITE
3595
3596 /* Must have at least one upkeep sprite per output type (and unhappy) */
3597 /* The rest are optional; we copy the previous sprite for unspecified ones */
3598 fc_strlcpy(buffer, "upkeep.unhappy", sizeof(buffer));
3599 SET_SPRITE(upkeep.unhappy[0], buffer);
3600 for (i = 1; i < MAX_NUM_UPKEEP_SPRITES; i++) {
3601 fc_snprintf(buffer2, sizeof(buffer2), "upkeep.unhappy%d", i+1);
3602 if (sprite_exists(t, buffer2)) {
3603 SET_SPRITE(upkeep.unhappy[i], buffer2);
3604 fc_strlcpy(buffer, buffer2, sizeof(buffer));
3605 } else {
3606 SET_SPRITE(upkeep.unhappy[i], buffer);
3607 }
3608 }
3610 fc_snprintf(buffer, sizeof(buffer),
3611 "upkeep.%s", get_output_identifier(o));
3612 SET_SPRITE_OPT(upkeep.output[o][0], buffer);
3613 for (i = 1; i < MAX_NUM_UPKEEP_SPRITES; i++) {
3614 fc_snprintf(buffer2, sizeof(buffer2),
3615 "upkeep.%s%d", get_output_identifier(o), i+1);
3616 if (sprite_exists(t, buffer2)) {
3617 SET_SPRITE(upkeep.output[o][i], buffer2);
3618 fc_strlcpy(buffer, buffer2, sizeof(buffer));
3619 } else {
3620 /* Optional, as maybe the upkeep 1 sprite didn't exist either */
3621 SET_SPRITE_OPT(upkeep.output[o][i], buffer);
3622 }
3623 }
3625
3627
3628 SET_SPRITE(user.attention, "user.attention");
3629 SET_SPRITE(user.infratile, "user.infratile");
3630
3631 SET_SPRITE_OPT(path.s[GTS_MP_LEFT].specific, "path.normal");
3632 SET_SPRITE_OPT(path.s[GTS_EXHAUSTED_MP].specific, "path.exhausted_mp");
3633 SET_SPRITE_OPT(path.s[GTS_TURN_STEP].specific, "path.step");
3634 SET_SPRITE(path.waypoint, "path.waypoint");
3635
3636 SET_SPRITE_NOTSMOOTH(tx.fog, "tx.fog");
3637
3639 for (i = 0; ; i++) {
3640 struct sprite *sprite;
3641
3642 fc_snprintf(buffer, sizeof(buffer), "colors.overlay_%d", i);
3643 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3644 if (!sprite) {
3645 break;
3646 }
3648 }
3649 if (i == 0) {
3651 _("Missing overlay-color sprite colors.overlay_0."));
3652 }
3653
3654 /* Chop up and build the overlay graphics. */
3659 for (i = 0; i < sprite_vector_size(&t->sprites.colors.overlays); i++) {
3660 struct sprite *color, *color_mask;
3661 struct sprite *worked, *unworked;
3662
3664 color_mask = crop_sprite(color, 0, 0, W, H, t->sprites.mask.tile, 0, 0,
3665 1.0f, FALSE);
3666 worked = crop_sprite(color_mask, 0, 0, W, H,
3667 t->sprites.mask.worked_tile, 0, 0, 1.0f, FALSE);
3668 unworked = crop_sprite(color_mask, 0, 0, W, H,
3669 t->sprites.mask.unworked_tile, 0, 0, 1.0f, FALSE);
3671 t->sprites.city.worked_tile_overlay.p[i] = worked;
3673 }
3674
3675
3676 {
3677 SET_SPRITE(grid.unavailable, "grid.unavailable");
3678 SET_SPRITE_OPT(grid.nonnative, "grid.nonnative");
3679
3680 for (i = 0; i < EDGE_COUNT; i++) {
3681 int be;
3682
3683 if (i == EDGE_UD && t->hex_width == 0) {
3684 continue;
3685 } else if (i == EDGE_LR && t->hex_height == 0) {
3686 continue;
3687 }
3688
3689 fc_snprintf(buffer, sizeof(buffer), "grid.main.%s", edge_name[i]);
3690 SET_SPRITE(grid.main[i], buffer);
3691
3692 fc_snprintf(buffer, sizeof(buffer), "grid.city.%s", edge_name[i]);
3693 SET_SPRITE(grid.city[i], buffer);
3694
3695 fc_snprintf(buffer, sizeof(buffer), "grid.worked.%s", edge_name[i]);
3696 SET_SPRITE(grid.worked[i], buffer);
3697
3698 fc_snprintf(buffer, sizeof(buffer), "grid.selected.%s", edge_name[i]);
3699 SET_SPRITE(grid.selected[i], buffer);
3700
3701 fc_snprintf(buffer, sizeof(buffer), "grid.coastline.%s", edge_name[i]);
3702 SET_SPRITE(grid.coastline[i], buffer);
3703
3704 for (be = 0; be < 2; be++) {
3705 fc_snprintf(buffer, sizeof(buffer), "grid.borders.%c",
3706 edge_name[i][be]);
3707 SET_SPRITE(grid.borders[i][be], buffer);
3708 }
3709 }
3710 }
3711
3712 switch (t->darkness_style) {
3713 case DARKNESS_NONE:
3714 /* Nothing. */
3715 break;
3716 case DARKNESS_ISORECT:
3717 {
3718 /* Isometric: take a single tx.darkness tile and split it into 4. */
3719 struct sprite *darkness = load_sprite(t, "tx.darkness",
3720 TRUE, FALSE, FALSE);
3721 const int ntw = t->normal_tile_width, nth = t->normal_tile_height;
3722 int offsets[4][2] = {{ntw / 2, 0}, {0, nth / 2}, {ntw / 2, nth / 2}, {0, 0}};
3723
3724 if (!darkness) {
3726 _("Sprite tx.darkness missing."));
3727 }
3728 for (i = 0; i < 4; i++) {
3729 t->sprites.tx.darkness[i] = crop_sprite(darkness, offsets[i][0],
3730 offsets[i][1], ntw / 2,
3731 nth / 2, NULL, 0, 0, 1.0f,
3732 FALSE);
3733 }
3734 }
3735 break;
3737 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
3738 enum direction8 dir = t->cardinal_tileset_dirs[i];
3739
3740 fc_snprintf(buffer, sizeof(buffer), "tx.darkness_%s",
3742 SET_SPRITE_NOTSMOOTH(tx.darkness[i], buffer);
3743 }
3744 break;
3745 case DARKNESS_CARD_FULL:
3746 for (i = 1; i < t->num_index_cardinal; i++) {
3747 fc_snprintf(buffer, sizeof(buffer), "tx.darkness_%s",
3748 cardinal_index_str(t, i));
3749 SET_SPRITE_NOTSMOOTH(tx.darkness[i], buffer);
3750 }
3751 break;
3752 case DARKNESS_CORNER:
3754 81 * sizeof(*t->sprites.tx.fullfog));
3755 for (i = 0; i < 81; i++) {
3756 /* Unknown, fog, known. */
3757 char ids[] = {'u', 'f', 'k'};
3758 char buf[512] = "t.fog";
3759 int values[4], vi, k = i;
3760
3761 for (vi = 0; vi < 4; vi++) {
3762 values[vi] = k % 3;
3763 k /= 3;
3764
3765 cat_snprintf(buf, sizeof(buf), "_%c", ids[values[vi]]);
3766 }
3767 fc_assert(k == 0);
3768
3770 }
3771 break;
3772 };
3773
3774 /* No other place to initialize these variables */
3777}
3778
3779/************************************************************************/
3782static bool load_river_sprites(struct tileset *t,
3783 struct river_sprites *store, const char *tag_pfx)
3784{
3785 int i;
3786 char buffer[512];
3787
3788 for (i = 0; i < t->num_index_cardinal; i++) {
3789 fc_snprintf(buffer, sizeof(buffer), "%s_s_%s",
3791 store->spec[i] = anim_load(t, buffer, 0);
3792 if (store->spec[i] == nullptr) {
3793 return FALSE;
3794 }
3795 }
3796
3797 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
3798 fc_snprintf(buffer, sizeof(buffer), "%s_outlet_%s",
3800 store->outlet[i] = anim_load(t, buffer, 0);
3801 if (store->outlet[i] == nullptr) {
3802 log_error("Missing \"%s\" for \"%s\".", buffer, tag_pfx);
3803 return FALSE;
3804 }
3805 }
3806
3807 return TRUE;
3808}
3809
3810/************************************************************************/
3817{
3819 if (sf->big_sprite) {
3820 free_sprite(sf->big_sprite);
3821 sf->big_sprite = NULL;
3822 }
3824}
3825
3826/************************************************************************/
3837
3838/************************************************************************/
3844 enum log_level level,
3845 const char *tag, const char *alt,
3846 const char *alt2,
3847 const char *what, const char *name,
3848 bool scale)
3849{
3850 struct sprite *sp;
3851
3852 /* (Should get sprite_hash before connection) */
3854 "attempt to lookup for %s \"%s\" before "
3855 "sprite_hash setup", what, name);
3856
3857 sp = load_sprite(t, tag, scale, TRUE, FALSE);
3858 if (sp) return sp;
3859
3860 sp = load_sprite(t, alt, scale, TRUE, FALSE);
3861 if (sp) {
3862 log_verbose("Using alternate graphic \"%s\" "
3863 "(instead of \"%s\") for %s \"%s\".",
3864 alt, tag, what, name);
3865 return sp;
3866 }
3867
3868 if (alt2 != NULL) {
3869 sp = load_sprite(t, alt2, scale, TRUE, FALSE);
3870 if (sp) {
3871 log_verbose("Using second alternate graphic \"%s\" "
3872 "(instead of \"%s\" or \"%s\") for %s \"%s\".",
3873 alt2, tag, alt, what, name);
3874 return sp;
3875 }
3876 }
3877
3879 _("Don't have graphics tags \"%s\" or \"%s\" for %s \"%s\"."),
3880 tag, alt, what, name);
3881
3882 return NULL;
3883}
3884
3885/************************************************************************/
3890 int uidx,
3891 const char *base_str,
3892 enum direction8 dir,
3893 enum unit_activity activity,
3894 bool has_icon)
3895{
3896 enum direction8 loaddir = dir;
3897 char buf[2048];
3898 const char *act_name = unit_activity_name(activity);
3899
3900 if (act_name == nullptr) {
3901 /* gcc-9 thinks this is possible. */
3902 return FALSE;
3903 }
3904
3905 /*
3906 * There may be more orientations available in this tileset than are
3907 * needed, if an oriented unit set has been reused between tilesets.
3908 *
3909 * Don't bother loading unused ones, unless they might be used by
3910 * unit_default_orientation (logic here mirrors get_unittype_sprite()).
3911 */
3912 if (!(dir == t->unit_default_orientation && !has_icon)
3913 && !is_valid_tileset_dir(t, dir)) {
3914 /* Instead we copy a nearby valid dir's sprite, so we're not caught
3915 * out in case this tileset is used with an incompatible topology,
3916 * although it'll be ugly. */
3917 do {
3919 /* This loop _should_ terminate... */
3921 } while (!is_valid_tileset_dir(t, loaddir));
3922 }
3923
3924 fc_snprintf(buf, sizeof(buf), "%s_%s_%s", base_str,
3926
3927 /* We don't use _alt graphics here, as that could lead to loading
3928 * real icon gfx, but alternative orientation gfx. Tileset author
3929 * probably meant icon gfx to be used as fallback for all orientations */
3930 t->sprites.units.facing[uidx][dir][activity] = anim_load(t, buf, 0);
3931
3932 if (activity == ACTIVITY_IDLE
3933 && t->sprites.units.facing[uidx][dir][activity] == nullptr) {
3934 /* Backward compatibility: Set Idle sprite from tag with no activity defined. */
3935 fc_snprintf(buf, sizeof(buf), "%s_%s", base_str,
3937
3938 t->sprites.units.facing[uidx][dir][activity] = anim_load(t, buf, 0);
3939 }
3940
3941 if (t->sprites.units.facing[uidx][dir][activity] != nullptr) {
3942 return TRUE;
3943 }
3944
3945 return FALSE;
3946}
3947
3948/************************************************************************/
3952 int uidx,
3953 const char *tag)
3954{
3956
3957 activity_type_iterate(activity) {
3958 char buffer[2048];
3959
3960 fc_snprintf(buffer, sizeof(buffer), "%s_%s",
3961 tag, unit_activity_name(activity));
3962 t->sprites.units.icon[uidx][activity] = anim_load(t, buffer, 0);
3963
3964 if (activity == ACTIVITY_IDLE
3965 && t->sprites.units.icon[uidx][activity] == nullptr) {
3966 /* Backward compatibility: Set Idle sprite from tag with no activity defined. */
3967 t->sprites.units.icon[uidx][activity] = anim_load(t, tag, 0);
3968 }
3970
3971 has_icon = t->sprites.units.icon[uidx][ACTIVITY_IDLE] != nullptr;
3972
3973#define LOAD_FACING_SPRITE(dir) \
3974 if (!tileset_setup_unit_direction(t, uidx, tag, dir, activity, has_icon)) { \
3975 facing_sprites[activity] = FALSE; \
3976 }
3977
3978 activity_type_iterate(activity) {
3979 facing_sprites[activity] = TRUE;
3980
3989
3991
3993 /* Neither icon gfx or orientation sprites */
3994 return FALSE;
3995 }
3996
3997 return TRUE;
3998
3999#undef LOAD_FACING_SPRITE
4000}
4001
4002/************************************************************************/
4007{
4008 int uidx = utype_index(ut);
4009
4010 if (!tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_str)
4011 && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt)
4012 && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt2)) {
4014 _("Missing %s unit sprites for tags \"%s\" and alternatives "
4015 "\"%s\" and \"%s\"."),
4016 utype_rule_name(ut), ut->graphic_str,
4017 ut->graphic_alt, ut->graphic_alt2);
4018 }
4019
4020 if (!t->sprites.units.icon[uidx][ACTIVITY_IDLE]) {
4023 _("Unit type %s has no unoriented sprites and "
4024 "tileset has no unit_default_orientation."),
4026 } else {
4027 /* We're guaranteed to have an oriented sprite corresponding to
4028 * unit_default_orientation, because tileset_setup_unit_type_from_tag()
4029 * checked for this. */
4031 != nullptr);
4032 }
4033 }
4034}
4035
4036/************************************************************************/
4041 struct impr_type *pimprove)
4042{
4043 t->sprites.building[improvement_index(pimprove)]
4045 pimprove->graphic_alt, pimprove->graphic_alt2,
4046 "improvement",
4047 improvement_rule_name(pimprove), FALSE);
4048
4049 /* Should maybe do something if NULL, eg generic default? */
4050}
4051
4052/************************************************************************/
4057 struct advance *padvance)
4058{
4059 if (valid_advance(padvance)) {
4062 padvance->graphic_alt, NULL, "technology",
4064
4065 /* Should maybe do something if NULL, eg generic default? */
4066 } else {
4068 }
4069}
4070
4071/************************************************************************/
4076 struct extra_type *pextra)
4077{
4078 const int id = extra_index(pextra);
4079 enum extrastyle_id extrastyle;
4080
4081 if (!fc_strcasecmp(pextra->graphic_str, "none")) {
4082 /* Extra without graphics */
4084 } else {
4085 const char *tag;
4086
4087 tag = pextra->graphic_str;
4088 if (!estyle_hash_lookup(t->estyle_hash, tag, &extrastyle)) {
4089 tag = pextra->graphic_alt;
4090 if (!estyle_hash_lookup(t->estyle_hash, tag, &extrastyle)) {
4092 _("No extra style for \"%s\" or \"%s\"."),
4093 pextra->graphic_str,
4094 pextra->graphic_alt);
4095 } else {
4096 log_verbose("Using alternate graphic \"%s\" "
4097 "(instead of \"%s\") for extra \"%s\".",
4098 pextra->graphic_alt, pextra->graphic_str,
4099 extra_rule_name(pextra));
4100 }
4101 }
4102
4103 t->sprites.extras[id].extrastyle = extrastyle;
4104
4105 extra_type_list_append(t->style_lists[extrastyle], pextra);
4106
4107 if (extra_has_flag(pextra, EF_SHOW_FLAG)) {
4109 }
4110
4111 switch (extrastyle) {
4112 case ESTYLE_3LAYER:
4113 tileset_setup_base(t, pextra, tag);
4114 break;
4115
4119 case ESTYLE_RIVER:
4120 tileset_setup_road(t, pextra, tag);
4121 break;
4122
4123 case ESTYLE_SINGLE1:
4124 case ESTYLE_SINGLE2:
4125 SET_ANIM(extras[id].u.single, tag);
4126 break;
4127
4128 case ESTYLE_CARDINALS:
4129 {
4130 int i;
4131 char buffer[512];
4132
4133 /* We use direction-specific irrigation and farmland graphics, if they
4134 * are available. If not, we just fall back to the basic irrigation
4135 * graphics. */
4136 for (i = 0; i < t->num_index_cardinal; i++) {
4137 fc_snprintf(buffer, sizeof(buffer), "%s_%s",
4138 tag, cardinal_index_str(t, i));
4139 t->sprites.extras[id].u.cardinals[i] = anim_load(t, buffer, 0);
4140 if (t->sprites.extras[id].u.cardinals[i] == nullptr) {
4141 t->sprites.extras[id].u.cardinals[i] = anim_load(t, tag, 0);
4142 }
4143 if (t->sprites.extras[id].u.cardinals[i] == nullptr) {
4145 _("No cardinal-style graphics \"%s*\" for "
4146 "extra \"%s\""),
4147 tag, extra_rule_name(pextra));
4148 }
4149 }
4150 }
4151 break;
4152 case ESTYLE_COUNT:
4153 break;
4154 }
4155 }
4156
4157 if (!fc_strcasecmp(pextra->activity_gfx, "none")) {
4159 } else {
4161 TRUE, TRUE, FALSE);
4162 if (t->sprites.extras[id].activity == NULL) {
4164 TRUE, TRUE, FALSE);
4165 }
4166 if (t->sprites.extras[id].activity == NULL) {
4168 TRUE, TRUE, FALSE);
4169 }
4170 if (t->sprites.extras[id].activity == NULL) {
4172 _("Missing %s building activity sprite for tags \"%s\" and alternatives \"%s\" and \"%s\"."),
4173 extra_rule_name(pextra), pextra->activity_gfx,
4174 pextra->act_gfx_alt, pextra->act_gfx_alt2);
4175 }
4176 }
4177
4178 if (!fc_strcasecmp(pextra->rmact_gfx, "none")) {
4179 t->sprites.extras[id].rmact = NULL;
4180 } else {
4181 t->sprites.extras[id].rmact = load_sprite(t, pextra->rmact_gfx,
4182 TRUE, TRUE, FALSE);
4183 if (t->sprites.extras[id].rmact == NULL) {
4185 TRUE, TRUE, FALSE);
4186 if (t->sprites.extras[id].rmact == NULL) {
4188 TRUE, TRUE, FALSE);
4189 if (t->sprites.extras[id].rmact == NULL) {
4191 _("Missing %s removal activity sprite for tags \"%s\" "
4192 "and alternatives \"%s\" and \"%s\"."),
4193 extra_rule_name(pextra), pextra->rmact_gfx,
4194 pextra->rmact_gfx_alt, pextra->rmact_gfx_alt2);
4195 }
4196 }
4197 }
4198 }
4199}
4200
4201/************************************************************************/
4205static void tileset_setup_road(struct tileset *t,
4206 struct extra_type *pextra,
4207 const char *tag)
4208{
4209 char full_tag_name[MAX_LEN_NAME + sizeof("_isolated")];
4210 const int id = extra_index(pextra);
4211 int i;
4212 enum extrastyle_id extrastyle = t->sprites.extras[id].extrastyle;
4213
4214 /* Isolated road graphics are used by ESTYLE_ROAD_ALL_SEPARATE and
4215 ESTYLE_ROAD_PARITY_COMBINED. */
4216 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4217 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4219 "%s_isolated", tag);
4220
4221 SET_ANIM(extras[id].u.road.isolated, full_tag_name);
4222 }
4223
4224 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
4225 /* ESTYLE_ROAD_ALL_SEPARATE has just 8 additional sprites for each
4226 * road type: one going off in each direction. */
4227 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4228 enum direction8 dir = t->valid_tileset_dirs[i];
4229 const char *dir_name = dir_get_tileset_name(dir);
4230
4232 "%s_%s", tag, dir_name);
4233
4234 SET_ANIM(extras[id].u.road.ru.dir[i], full_tag_name);
4235 }
4236 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4237 int num_index = 1 << (t->num_valid_tileset_dirs / 2), j;
4238
4239 /* ESTYLE_ROAD_PARITY_COMBINED has 32 additional sprites for each road
4240 * type: 16 each for cardinal and diagonal directions. Each set
4241 * of 16 provides a NSEW-indexed sprite to provide connectors for
4242 * all rails in the cardinal/diagonal directions. The 0 entry is
4243 * unused (the "isolated" sprite is used instead). */
4244
4245 for (i = 1; i < num_index; i++) {
4246 char c[64] = "", d[64] = "";
4247
4248 for (j = 0; j < t->num_valid_tileset_dirs / 2; j++) {
4249 int value = (i >> j) & 1;
4250
4251 cat_snprintf(c, sizeof(c), "%s%d",
4253 value);
4254 cat_snprintf(d, sizeof(d), "%s%d",
4256 value);
4257 }
4258
4260 "%s_c_%s", tag, c);
4261
4262 SET_ANIM(extras[id].u.road.ru.combo.even[i], full_tag_name);
4263
4265 "%s_d_%s", tag, d);
4266
4267 SET_ANIM(extras[id].u.road.ru.combo.odd[i], full_tag_name);
4268 }
4269 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
4270 /* ESTYLE_ROAD_ALL_COMBINED includes 256 sprites, one for every possibility.
4271 * Just go around clockwise, with all combinations. */
4272 for (i = 0; i < t->num_index_valid; i++) {
4273 char *idx_str = valid_index_str(t, i);
4274
4276 "%s_%s", tag, idx_str);
4277
4278 SET_ANIM(extras[id].u.road.ru.total[i], full_tag_name);
4279 }
4280 } else if (extrastyle == ESTYLE_RIVER) {
4281 if (!load_river_sprites(t, &t->sprites.extras[id].u.road.ru.rivers, tag)) {
4283 _("No river-style graphics \"%s*\" for extra \"%s\""),
4284 tag, extra_rule_name(pextra));
4285 }
4286 } else {
4288 }
4289
4290 /* Corner road graphics are used by ESTYLE_ROAD_ALL_SEPARATE,
4291 * ESTYLE_ROAD_PARITY_COMBINED and ESTYLE_ROAD_ALL_COMBINED. */
4292 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4293 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED
4294 || extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
4295 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4296 enum direction8 dir = t->valid_tileset_dirs[i];
4297
4298 if (!is_cardinal_tileset_dir(t, dir)) {
4299 const char *dtn = dir_get_tileset_name(dir);
4300
4302 "%s_c_%s", pextra->graphic_str, dtn);
4303
4304 SET_ANIM_OPT(extras[id].u.road.corner[dir], full_tag_name);
4305 }
4306 }
4307 }
4308}
4309
4310/************************************************************************/
4314static void tileset_setup_base(struct tileset *t,
4315 const struct extra_type *pextra,
4316 const char *tag)
4317{
4318 char full_tag_name[MAX_LEN_NAME + sizeof("_fg")];
4319 const int id = extra_index(pextra);
4320
4321 fc_assert_ret(id >= 0 && id < extra_count());
4322
4324 strcat(full_tag_name, "_bg");
4326
4328 strcat(full_tag_name, "_mg");
4330
4332 strcat(full_tag_name, "_fg");
4334
4335 if (t->sprites.extras[id].u.bmf.background == nullptr
4336 && t->sprites.extras[id].u.bmf.middleground == nullptr
4337 && t->sprites.extras[id].u.bmf.foreground == nullptr) {
4338 /* There was an extra style definition but no matching graphics */
4340 _("No graphics with tag \"%s_bg/mg/fg\" for extra \"%s\""),
4341 tag, extra_rule_name(pextra));
4342 }
4343}
4344
4345/************************************************************************/
4350 const struct terrain *pterrain)
4351{
4352 struct drawing_data *draw;
4353 struct sprite *sprite;
4354 char buffer[MAX_LEN_NAME + 20];
4355 int i, l;
4356
4357 if (!drawing_hash_lookup(t->tile_hash, pterrain->graphic_str, &draw)
4358 && !drawing_hash_lookup(t->tile_hash, pterrain->graphic_alt, &draw)
4359 && !drawing_hash_lookup(t->tile_hash, pterrain->graphic_alt2, &draw)) {
4361 _("Terrain \"%s\": no graphic tile \"%s\", \"%s\", or \"%s\"."),
4362 terrain_rule_name(pterrain), pterrain->graphic_str,
4363 pterrain->graphic_alt, pterrain->graphic_alt2);
4364 }
4365
4366 if (draw->init) {
4367 t->sprites.drawing[terrain_index(pterrain)] = draw;
4368 return;
4369 }
4370
4371 /* Set up each layer of the drawing. */
4372 for (l = 0; l < draw->num_layers; l++) {
4373 struct drawing_layer *dlp = &draw->layer[l];
4374 struct tileset_layer *tslp = &t->layers[l];
4375 sprite_vector_init(&dlp->base);
4376 sprite_vector_init(&dlp->allocated);
4377
4378 switch (dlp->sprite_type) {
4379 case CELL_WHOLE:
4380 switch (dlp->match_style) {
4381 case MATCH_NONE:
4382 /* Load whole sprites for this tile. */
4383 for (i = 0; ; i++) {
4384 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s%d",
4385 l, draw->name, i + 1);
4386 sprite = load_sprite(t, buffer, TRUE, FALSE, FALSE);
4387 if (!sprite) {
4388 break;
4389 }
4390 sprite_vector_reserve(&dlp->base, i + 1);
4391 dlp->base.p[i] = sprite;
4392 }
4393 /* Check for base sprite, allowing missing sprites above base */
4394 if (0 == i && 0 == l) {
4395 /* TRANS: 'base' means 'base of terrain gfx', not 'military base' */
4397 _("Missing base sprite for tag \"%s\"."), buffer);
4398 }
4399 break;
4400 case MATCH_SAME:
4401 /* Load 16 cardinally-matched sprites. */
4402 for (i = 0; i < t->num_index_cardinal; i++) {
4403 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_%s",
4404 l, draw->name, cardinal_index_str(t, i));
4405 dlp->match[i]
4406 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4407 NULL, "matched terrain",
4408 terrain_rule_name(pterrain), TRUE);
4409 }
4410 break;
4411 case MATCH_PAIR:
4412 case MATCH_FULL:
4413 fc_assert(FALSE); /* Not yet defined */
4414 break;
4415 };
4416 break;
4417 case CELL_CORNER:
4418 {
4419 const int count = dlp->match_indices;
4420 int number = NUM_CORNER_DIRS;
4421
4422 switch (dlp->match_style) {
4423 case MATCH_NONE:
4424 /* Do nothing */
4425 break;
4426 case MATCH_PAIR:
4427 case MATCH_SAME:
4428 /* N directions (NSEW) * 3 dimensions of matching */
4429 fc_assert(count == 2);
4430 number = NUM_CORNER_DIRS * 2 * 2 * 2;
4431 break;
4432 case MATCH_FULL:
4433 default:
4434 /* N directions (NSEW) * 3 dimensions of matching */
4435 /* could use exp() or expi() here? */
4436 number = NUM_CORNER_DIRS * count * count * count;
4437 break;
4438 };
4439
4440 dlp->cells
4441 = fc_calloc(number, sizeof(*dlp->cells));
4442
4443 for (i = 0; i < number; i++) {
4444 enum direction4 dir = i % NUM_CORNER_DIRS;
4445 int value = i / NUM_CORNER_DIRS;
4446
4447 switch (dlp->match_style) {
4448 case MATCH_NONE:
4449 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c",
4450 l, draw->name, direction4letters[dir]);
4451 dlp->cells[i]
4452 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4453 NULL, "cell terrain",
4454 terrain_rule_name(pterrain), TRUE);
4455 break;
4456 case MATCH_SAME:
4457 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c%d%d%d",
4458 l, draw->name, direction4letters[dir],
4459 (value) & 1, (value >> 1) & 1, (value >> 2) & 1);
4460 dlp->cells[i]
4461 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4462 NULL, "same cell terrain",
4463 terrain_rule_name(pterrain), TRUE);
4464 break;
4465 case MATCH_PAIR:
4466 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c_%c_%c_%c",
4467 l, draw->name, direction4letters[dir],
4468 tslp->match_types[dlp->match_index[(value) & 1]][0],
4469 tslp->match_types[dlp->match_index[(value >> 1) & 1]][0],
4470 tslp->match_types[dlp->match_index[(value >> 2) & 1]][0]);
4471 dlp->cells[i]
4472 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4473 NULL, "cell pair terrain",
4474 terrain_rule_name(pterrain), TRUE);
4475 break;
4476 case MATCH_FULL:
4477 {
4478 int this = dlp->match_index[0];
4479 int n, s, e, w;
4480 int v1, v2, v3;
4481
4482 v1 = dlp->match_index[value % count];
4483 value /= count;
4484 v2 = dlp->match_index[value % count];
4485 value /= count;
4486 v3 = dlp->match_index[value % count];
4487
4488 fc_assert(v1 < count && v2 < count && v3 < count);
4489
4490 /* Assume merged cells. This should be a separate option. */
4491 switch (dir) {
4492 case DIR4_NORTH:
4493 s = this;
4494 w = v1;
4495 n = v2;
4496 e = v3;
4497 break;
4498 case DIR4_EAST:
4499 w = this;
4500 n = v1;
4501 e = v2;
4502 s = v3;
4503 break;
4504 case DIR4_SOUTH:
4505 n = this;
4506 e = v1;
4507 s = v2;
4508 w = v3;
4509 break;
4510 case DIR4_WEST:
4511 default: /* Avoid warnings */
4512 e = this;
4513 s = v1;
4514 w = v2;
4515 n = v3;
4516 break;
4517 };
4518
4519 /* Use first character of match_types,
4520 * already checked for uniqueness. */
4521 fc_snprintf(buffer, sizeof(buffer),
4522 "t.l%d.cellgroup_%c_%c_%c_%c", l,
4523 tslp->match_types[n][0], tslp->match_types[e][0],
4524 tslp->match_types[s][0], tslp->match_types[w][0]);
4525 sprite = load_sprite(t, buffer, TRUE, FALSE, FALSE);
4526
4527 if (sprite) {
4528 /* Crop the sprite to separate this cell. */
4529 int vec_size = sprite_vector_size(&dlp->allocated);
4530
4531 const int W = t->normal_tile_width;
4532 const int H = t->normal_tile_height;
4533 int x[4] = {W / 4, W / 4, 0, W / 2};
4534 int y[4] = {H / 2, 0, H / 4, H / 4};
4535 int xo[4] = {0, 0, -W / 2, W / 2};
4536 int yo[4] = {H / 2, -H / 2, 0, 0};
4537
4538 sprite = crop_sprite(sprite, x[dir], y[dir], W / 2, H / 2,
4539 t->sprites.mask.tile, xo[dir], yo[dir], 1.0f,
4540 FALSE);
4541 /* We allocated new sprite with crop_sprite. Store its
4542 * address so we can free it. */
4543 sprite_vector_reserve(&dlp->allocated, vec_size + 1);
4544 dlp->allocated.p[vec_size] = sprite;
4545 } else {
4546 log_error("Terrain graphics sprite for tag \"%s\" missing.", buffer);
4547 }
4548
4549 dlp->cells[i] = sprite;
4550 }
4551 break;
4552 };
4553 }
4554 }
4555 break;
4556 };
4557 }
4558
4559 /* Try an optional special name */
4560 fc_snprintf(buffer, sizeof(buffer), "t.blend.%s", draw->name);
4561 draw->blender
4563 NULL, "blend terrain",
4564 terrain_rule_name(pterrain), TRUE);
4565
4566 if (draw->blending > 0) {
4567 const int bl = draw->blending - 1;
4568
4569 if (NULL == draw->blender) {
4570 int li = 0;
4571
4572 /* Try an already loaded base */
4573 while (NULL == draw->blender
4574 && li < draw->blending
4575 && 0 < draw->layer[li].base.size) {
4576 draw->blender = draw->layer[li++].base.p[0];
4577 }
4578 }
4579
4580 if (NULL == draw->blender) {
4581 /* Try an unloaded base name */
4582 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s1", bl, draw->name);
4583 draw->blender
4584 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4585 NULL, "base (blend) terrain",
4586 terrain_rule_name(pterrain), TRUE);
4587 }
4588 }
4589
4590 if (NULL != draw->blender) {
4591 /* Set up blending sprites. This only works in iso-view! */
4592 const int W = t->normal_tile_width;
4593 const int H = t->normal_tile_height;
4594 const int offsets[4][2] = {
4595 {W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}
4596 };
4597 enum direction4 dir = 0;
4598
4599 for (; dir < 4; dir++) {
4600 draw->blend[dir] = crop_sprite(draw->blender, offsets[dir][0],
4601 offsets[dir][1], W / 2, H / 2,
4602 t->sprites.dither_tile, 0, 0, 1.0f,
4603 FALSE);
4604 }
4605 }
4606
4607 draw->init = TRUE;
4608 t->sprites.drawing[terrain_index(pterrain)] = draw;
4609}
4610
4611/************************************************************************/
4616 struct government *gov)
4617{
4620 gov->graphic_alt, NULL, "government",
4622
4623 /* Should probably do something if NULL, eg generic default? */
4624}
4625
4626/************************************************************************/
4631 struct nation_type *nation)
4632{
4633 char *tags[] = {nation->flag_graphic_str,
4634 nation->flag_graphic_alt,
4635 "unknown", NULL};
4636 int i;
4637 struct sprite *flag = NULL, *shield = NULL;
4638 char buf[1024];
4640
4641 for (i = 0; tags[i] && !flag; i++) {
4642 fc_snprintf(buf, sizeof(buf), "f.%s", tags[i]);
4643 flag = load_sprite(t, buf, TRUE, TRUE, svgflag);
4644 }
4645 for (i = 0; tags[i] && !shield; i++) {
4646 fc_snprintf(buf, sizeof(buf), "f.shield.%s", tags[i]);
4647 shield = load_sprite(t, buf, TRUE, TRUE, svgflag);
4648 }
4649 if (!flag || !shield) {
4650 /* Should never get here because of the f.unknown fallback. */
4652 _("Nation %s: no national flag."), nation_rule_name(nation));
4653 }
4654
4656 t->sprites.nation_flag.p[nation_index(nation)] = flag;
4657
4659 t->sprites.nation_shield.p[nation_index(nation)] = shield;
4660}
4661
4662/************************************************************************/
4665struct sprite *get_city_flag_sprite(const struct tileset *t,
4666 const struct city *pcity)
4667{
4669}
4670
4671/************************************************************************/
4674static struct sprite *get_unit_nation_flag_sprite(const struct tileset *t,
4675 const struct unit *punit)
4676{
4677 struct nation_type *pnation = nation_of_unit(punit);
4678
4680 return t->sprites.nation_shield.p[nation_index(pnation)];
4681 } else {
4682 return t->sprites.nation_flag.p[nation_index(pnation)];
4683 }
4684}
4685
4686#define FULL_TILE_X_OFFSET ((t->normal_tile_width - t->full_tile_width) / 2)
4687#define FULL_TILE_Y_OFFSET (t->normal_tile_height - t->full_tile_height)
4688
4689#define ADD_SPRITE_SIZE(s, draw_fog, x_offset, y_offset, w_in, h_in) \
4690 (fc_assert(s != NULL), \
4691 sprs->sprite = s, \
4692 sprs->foggable = (draw_fog && t->fogstyle == FOG_AUTO), \
4693 sprs->offset_x = x_offset, \
4694 sprs->offset_y = y_offset, \
4695 sprs->w = w_in, \
4696 sprs->h = h_in, \
4697 sprs++)
4698#define ADD_SPRITE(s, draw_fog, x_offset, y_offset) \
4699 ADD_SPRITE_SIZE(s, draw_fog, x_offset, y_offset, 0, 0)
4700#define ADD_SPRITE_SIMPLE(s) ADD_SPRITE(s, TRUE, 0, 0)
4701#define ADD_SPRITE_FULL(s) \
4702 ADD_SPRITE(s, TRUE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET)
4703
4704#define ADD_ANIM_SPRITE(s, draw_fog, x_offset, y_offset) \
4705 ADD_SPRITE(anim_get_current_frame(s), draw_fog, x_offset, y_offset)
4706#define ADD_ANIM_SPRITE_SIMPLE(s) \
4707 ADD_SPRITE(anim_get_current_frame(s), TRUE, 0, 0)
4708#define ADD_ANIM_FULL(s) \
4709 ADD_SPRITE(anim_get_current_frame(s), TRUE, \
4710 FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET)
4711
4712#define ADD_FRAME0_SIMPLE(s) ADD_SPRITE_SIMPLE(s->sprites[0])
4713#define ADD_FRAME0_FULL(s) \
4714 ADD_SPRITE_FULL(s->sprites[0])
4715
4716/************************************************************************/
4723static void build_tile_data(const struct tile *ptile,
4724 struct terrain *pterrain,
4725 struct terrain **tterrain_near,
4727{
4728 enum direction8 dir;
4729
4730 /* Loop over all adjacent tiles. We should have an iterator for this. */
4731 for (dir = 0; dir < 8; dir++) {
4732 struct tile *tile1 = mapstep(&(wld.map), ptile, dir);
4733
4736
4737 if (NULL != terrain1) {
4738 tterrain_near[dir] = terrain1;
4740 continue;
4741 }
4742 log_error("build_tile_data() tile (%d,%d) has no terrain!",
4743 TILE_XY(tile1));
4744 }
4745 /* At the edges of the (known) map, pretend the same terrain continued
4746 * past the edge of the map. */
4747 tterrain_near[dir] = pterrain;
4749 }
4750}
4751
4752/************************************************************************/
4755static int fill_unit_type_sprite_array(const struct tileset *t,
4756 struct drawn_sprite *sprs,
4757 const struct unit_type *putype,
4758 enum unit_activity activity,
4759 enum direction8 facing)
4760{
4761 struct drawn_sprite *save_sprs = sprs;
4762 struct sprite *uspr = get_unittype_sprite(t, putype, activity, facing);
4763
4767
4768 return sprs - save_sprs;
4769}
4770
4771/************************************************************************/
4774static int fill_unit_sprite_array(const struct tileset *t,
4775 struct drawn_sprite *sprs,
4776 const struct unit *punit,
4777 int stack, bool backdrop)
4778{
4779 struct drawn_sprite *save_sprs = sprs;
4780 int ihp;
4781 const struct unit_type *ptype = unit_type_get(punit);
4782
4783 if (backdrop) {
4789 }
4790 } else {
4791 /* Taken care of in the LAYER_BACKGROUND. */
4792 }
4793 }
4794
4795 /* Add the sprite for the unit type. */
4798
4799 if (t->sprites.unit.loaded && unit_transported(punit)) {
4800 ADD_SPRITE_FULL(t->sprites.unit.loaded);
4801 }
4802
4803 if (punit->activity != ACTIVITY_IDLE) {
4804 struct sprite *s = NULL;
4805
4806 switch (punit->activity) {
4807 case ACTIVITY_MINE:
4808 if (punit->activity_target == NULL) {
4809 s = t->sprites.unit.plant;
4810 } else {
4812 }
4813 break;
4814 case ACTIVITY_PLANT:
4815 s = t->sprites.unit.plant;
4816 break;
4817 case ACTIVITY_IRRIGATE:
4818 if (punit->activity_target == NULL) {
4819 s = t->sprites.unit.cultivate;
4820 } else {
4822 }
4823 break;
4824 case ACTIVITY_CULTIVATE:
4825 s = t->sprites.unit.cultivate;
4826 break;
4827 case ACTIVITY_CLEAN:
4829 break;
4830 case ACTIVITY_PILLAGE:
4832 if (s == NULL) {
4833 s = t->sprites.unit.pillage;
4834 }
4835 break;
4836 case ACTIVITY_EXPLORE:
4837 /* Drawn below as the server side agent. */
4838 break;
4839 case ACTIVITY_FORTIFIED:
4840 s = t->sprites.unit.fortified;
4841 break;
4843 s = t->sprites.unit.fortifying;
4844 break;
4845 case ACTIVITY_SENTRY:
4846 s = t->sprites.unit.sentry;
4847 break;
4848 case ACTIVITY_GOTO:
4849 s = t->sprites.unit.go_to;
4850 break;
4851 case ACTIVITY_TRANSFORM:
4852 s = t->sprites.unit.transform;
4853 break;
4854 case ACTIVITY_BASE:
4855 case ACTIVITY_GEN_ROAD:
4857 break;
4858 case ACTIVITY_CONVERT:
4859 s = t->sprites.unit.convert;
4860 break;
4861 default:
4862 break;
4863 }
4864
4865 if (s != NULL) {
4868 }
4869 }
4870
4871 {
4872 struct sprite *s = NULL;
4873 int offset_x = 0;
4874 int offset_y = 0;
4875
4876 switch (punit->ssa_controller) {
4877 case SSA_NONE:
4878 break;
4879 case SSA_AUTOWORKER:
4880 s = t->sprites.unit.auto_worker;
4881 break;
4882 case SSA_AUTOEXPLORE:
4883 s = t->sprites.unit.auto_explore;
4884 /* Specified as an activity in the tileset. */
4887 break;
4888 default:
4889 s = t->sprites.unit.auto_attack;
4890 break;
4891 }
4892
4893 if (s != NULL) {
4894 ADD_SPRITE(s, TRUE,
4897 }
4898 }
4899
4900 if (unit_has_orders(punit)) {
4901 if (punit->orders.repeat) {
4902 ADD_SPRITE_FULL(t->sprites.unit.patrol);
4903 } else if (punit->activity != ACTIVITY_IDLE) {
4904 ADD_SPRITE_SIMPLE(t->sprites.unit.connect);
4905 } else {
4906 ADD_SPRITE(t->sprites.unit.go_to, TRUE,
4909 }
4910 }
4911
4912 if (t->sprites.unit.action_decision_want != nullptr
4914 ADD_ANIM_SPRITE(t->sprites.unit.action_decision_want, TRUE,
4917 }
4918
4920 ADD_SPRITE_FULL(t->sprites.unit.battlegroup[punit->battlegroup]);
4921 }
4922
4923 if (t->sprites.unit.lowfuel
4924 && utype_fuel(ptype)
4925 && punit->fuel == 1
4926 && punit->moves_left <= 2 * SINGLE_MOVE) {
4927 /* Show a low-fuel graphic if the plane has 2 or fewer moves left. */
4928 ADD_SPRITE_FULL(t->sprites.unit.lowfuel);
4929 }
4930 if (t->sprites.unit.tired
4932 && ptype->move_rate > 0) {
4933 /* Show a "tired" graphic if the unit has fewer than one move
4934 * remaining, except for units for which it's full movement. */
4935 ADD_SPRITE_FULL(t->sprites.unit.tired);
4936 }
4937
4938 if (stack == 1 && punit->client.occupied) {
4939 ADD_SPRITE_FULL(t->sprites.unit.stack[0]);
4940 } else if (stack > 1) {
4942 && t->sprites.unit.num_stack_sprites >= stack) {
4943 ADD_SPRITE(t->sprites.unit.stack[stack - 1], FALSE,
4945 } else {
4946 ADD_SPRITE_FULL(t->sprites.unit.stack[0]);
4947 }
4948 }
4949
4950 if (t->sprites.unit.vet_lev[punit->veteran]) {
4952 }
4953
4954 ihp = ((NUM_TILES_HP_BAR-1)*punit->hp) / ptype->hp;
4955 ihp = CLIP(0, ihp, NUM_TILES_HP_BAR-1);
4956 ADD_SPRITE_FULL(t->sprites.unit.hp_bar[ihp]);
4957
4958 return sprs - save_sprs;
4959}
4960
4961/************************************************************************/
4964static int fill_road_corner_sprites(const struct tileset *t,
4965 const struct extra_type *pextra,
4966 struct drawn_sprite *sprs,
4967 bool road, bool *road_near,
4968 bool hider, bool *hider_near)
4969{
4970 struct drawn_sprite *saved_sprs = sprs;
4971 int i;
4972 int extra_idx = extra_index(pextra);
4973
4974 if (is_cardinal_only_road(pextra)) {
4975 return 0;
4976 }
4977
4978 /* Roads going diagonally adjacent to this tile need to be
4979 * partly drawn on this tile. */
4980
4981 /* Draw the corner sprite if:
4982 * - There is a diagonal road (not rail!) between two adjacent tiles.
4983 * - There is no diagonal road (not rail!) that intersects this road.
4984 * The logic is simple: roads are drawn underneath railrods, but are
4985 * not always covered by them (even in the corners!). But if a railroad
4986 * connects two tiles, only the railroad (no road) is drawn between
4987 * those tiles.
4988 */
4989 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4990 enum direction8 dir = t->valid_tileset_dirs[i];
4991
4992 if (!is_cardinal_tileset_dir(t, dir)) {
4993 /* Draw corner sprites for this non-cardinal direction. */
4994 int cw = (i + 1) % t->num_valid_tileset_dirs;
4995 int ccw
4997 enum direction8 cwdir = t->valid_tileset_dirs[cw];
4999
5000 if (t->sprites.extras[extra_idx].u.road.corner[dir]
5002 && !(hider_near[cwdir] && hider_near[ccwdir]))
5003 && !(road && road_near[dir] && !(hider && hider_near[dir]))) {
5005 }
5006 }
5007 }
5008
5009 return sprs - saved_sprs;
5010}
5011
5012/************************************************************************/
5015static int fill_road_sprite_array(const struct tileset *t,
5016 const struct extra_type *pextra,
5017 struct drawn_sprite *sprs,
5020 struct terrain *tterrain_near[8],
5021 const struct city *pcity)
5022{
5023 struct drawn_sprite *saved_sprs = sprs;
5024 bool road, road_near[8], hider, hider_near[8];
5025 bool land_near[8], hland_near[8];
5026 bool draw_road[8], draw_single_road;
5027 enum direction8 dir;
5028 int extra_idx = -1;
5029 bool cl = FALSE;
5030 enum extrastyle_id extrastyle;
5031 const struct road_type *proad = extra_road_get(pextra);
5032
5033 extra_idx = extra_index(pextra);
5034
5035 extrastyle = t->sprites.extras[extra_idx].extrastyle;
5036
5037 if (extra_has_flag(pextra, EF_CONNECT_LAND)) {
5038 cl = TRUE;
5039 } else {
5040 int i;
5041
5042 for (i = 0; i < 8; i++) {
5043 land_near[i] = FALSE;
5044 }
5045 }
5046
5047 /* Fill some data arrays. rail_near and road_near store whether road/rail
5048 * is present in the given direction. draw_rail and draw_road store
5049 * whether road/rail is to be drawn in that direction. draw_single_road
5050 * and draw_single_rail store whether we need an isolated road/rail to be
5051 * drawn. */
5053
5054 hider = FALSE;
5057 hider = TRUE;
5058 break;
5059 }
5061
5062 if (road && (!pcity || !gui_options.draw_cities) && !hider) {
5064 } else {
5066 }
5067
5068 for (dir = 0; dir < 8; dir++) {
5069 bool roads_exist;
5070
5071 /* Check if there is adjacent road/rail. */
5072 if (!is_cardinal_only_road(pextra)
5073 || is_cardinal_tileset_dir(t, dir)) {
5074 road_near[dir] = FALSE;
5075 extra_type_list_iterate(proad->integrators, iextra) {
5077 road_near[dir] = TRUE;
5078 break;
5079 }
5081 if (cl) {
5082 land_near[dir] = (tterrain_near[dir] != T_UNKNOWN
5084 }
5085 } else {
5086 road_near[dir] = FALSE;
5087 land_near[dir] = FALSE;
5088 }
5089
5090 /* Draw rail/road if there is a connection from this tile to the
5091 * adjacent tile. But don't draw road if there is also a rail
5092 * connection. */
5093 roads_exist = road && (road_near[dir] || land_near[dir]);
5094 draw_road[dir] = roads_exist;
5095 hider_near[dir] = FALSE;
5096 hland_near[dir] = tterrain_near[dir] != T_UNKNOWN
5099 bool hider_dir = FALSE;
5100 bool land_dir = FALSE;
5101
5103 || is_cardinal_tileset_dir(t, dir)) {
5105 hider_near[dir] = TRUE;
5106 hider_dir = TRUE;
5107 }
5108 if (hland_near[dir]
5111 land_dir = TRUE;
5112 }
5113 if (hider_dir || land_dir) {
5115 draw_road[dir] = FALSE;
5116 }
5117 }
5118 }
5120
5121 /* Don't draw an isolated road/rail if there's any connection.
5122 * draw_single_road would be true in the first place only if start tile has road,
5123 * so it will have road connection with any adjacent road tile. We check from real
5124 * existence of road (road_near[dir]) and not from whether road gets drawn (draw_road[dir])
5125 * as latter can be FALSE when road is simply hidden by another one, and we don't want to
5126 * draw single road in that case either. */
5127 if (draw_single_road && road_near[dir]) {
5129 }
5130 }
5131
5132 /* Draw road corners */
5133 sprs
5135
5136 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
5137 /* With ESTYLE_ROAD_ALL_SEPARATE, we simply draw one road for every connection.
5138 * This means we only need a few sprites, but a lot of drawing is
5139 * necessary and it generally doesn't look very good. */
5140 int i;
5141
5142 /* First draw roads under rails. */
5143 if (road) {
5144 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
5145 if (draw_road[t->valid_tileset_dirs[i]]) {
5147 }
5148 }
5149 }
5150 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
5151 /* With ESTYLE_ROAD_PARITY_COMBINED, we draw one sprite for cardinal
5152 * road connections, one sprite for diagonal road connections.
5153 * This means we need about 4x more sprites than in style 0, but up to
5154 * 4x less drawing is needed. The drawing quality may also be
5155 * improved. */
5156
5157 /* First draw roads under rails. */
5158 if (road) {
5159 int road_even_tileno = 0, road_odd_tileno = 0, i;
5160
5161 for (i = 0; i < t->num_valid_tileset_dirs / 2; i++) {
5162 enum direction8 even = t->valid_tileset_dirs[2 * i];
5163 enum direction8 odd = t->valid_tileset_dirs[2 * i + 1];
5164
5165 if (draw_road[even]) {
5166 road_even_tileno |= 1 << i;
5167 }
5168 if (draw_road[odd]) {
5169 road_odd_tileno |= 1 << i;
5170 }
5171 }
5172
5173 /* Draw the cardinal/even roads first. */
5174 if (road_even_tileno != 0) {
5176 }
5177 if (road_odd_tileno != 0) {
5179 }
5180 }
5181 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
5182 /* RSTYLE_ALL_COMBINED is a very simple method that lets us simply retrieve
5183 * entire finished tiles, with a bitwise index of the presence of
5184 * roads in each direction. */
5185
5186 /* Draw roads first */
5187 if (road) {
5188 int road_tileno = 0, i;
5189
5190 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
5192
5193 if (draw_road[vdir]) {
5194 road_tileno |= 1 << i;
5195 }
5196 }
5197
5198 if (road_tileno != 0 || draw_single_road) {
5200 }
5201 }
5202 } else {
5204 }
5205
5206 /* Draw isolated rail/road separately (ESTYLE_ROAD_ALL_SEPARATE and
5207 ESTYLE_ROAD_PARITY_COMBINED only). */
5208 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
5209 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
5210 if (draw_single_road) {
5212 }
5213 }
5214
5215 return sprs - saved_sprs;
5216}
5217
5218/************************************************************************/
5227static int get_irrigation_index(const struct tileset *t,
5228 struct extra_type *pextra,
5230{
5231 int tileno = 0, i;
5232
5233 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5234 enum direction8 dir = t->cardinal_tileset_dirs[i];
5235
5236 if (BV_ISSET(textras_near[dir], extra_index(pextra))) {
5237 tileno |= 1 << i;
5238 }
5239 }
5240
5241 return tileno;
5242}
5243
5244/************************************************************************/
5247static int fill_irrigation_sprite_array(const struct tileset *t,
5248 struct drawn_sprite *sprs,
5251 const struct city *pcity)
5252{
5253 struct drawn_sprite *saved_sprs = sprs;
5254
5255 /* We don't draw the irrigation if there's a city (it just gets overdrawn
5256 * anyway, and ends up looking bad). */
5257 if (!(pcity && gui_options.draw_cities)) {
5259 if (is_extra_drawing_enabled(pextra)) {
5260 int eidx = extra_index(pextra);
5261
5262 if (BV_ISSET(textras, eidx)) {
5263 bool hidden = FALSE;
5264
5265 extra_type_list_iterate(pextra->hiders, phider) {
5267 hidden = TRUE;
5268 break;
5269 }
5271
5272 if (!hidden) {
5273 int idx = get_irrigation_index(t, pextra, textras_near);
5274
5276 }
5277 }
5278 }
5280 }
5281
5282 return sprs - saved_sprs;
5283}
5284
5285/************************************************************************/
5289static int fill_city_overlays_sprite_array(const struct tileset *t,
5290 struct drawn_sprite *sprs,
5291 const struct tile *ptile,
5292 const struct city *citymode)
5293{
5294 const struct city *pcity;
5295 const struct city *pwork;
5296 struct unit *psettler;
5297 struct drawn_sprite *saved_sprs = sprs;
5298 int city_x, city_y;
5299 const int NUM_CITY_COLORS = t->sprites.city.worked_tile_overlay.size;
5300
5301 if (NULL == ptile || TILE_UNKNOWN == client_tile_get_known(ptile)) {
5302 return 0;
5303 }
5304 pwork = tile_worked(ptile);
5305
5306 if (citymode) {
5307 pcity = citymode;
5308 } else {
5310 }
5311
5312 /* Below code does not work if pcity is invisible.
5313 * Make sure it is not. */
5314 fc_assert_ret_val(pcity == NULL || pcity->tile != NULL, 0);
5315 if (pcity && !pcity->tile) {
5316 pcity = NULL;
5317 }
5318
5319 if (pcity && city_base_to_city_map(&city_x, &city_y, pcity, ptile)) {
5320 /* FIXME: check elsewhere for valid tile (instead of above) */
5321
5322 if (!citymode && pcity->client.colored) {
5323 /* Add citymap overlay for a city. */
5325
5326 if (NULL != pwork && pwork == pcity) {
5328 } else if (city_can_work_tile(pcity, ptile)) {
5330 }
5331 } else if (NULL != pwork && pwork == pcity
5333
5334 /* Add on the tile output sprites.
5335 * NOTE: To show correct output on end of turn
5336 * base_city_celebrating() must be used instead of city_celebrating()
5337 * mirroring the behavior of the server that does so in
5338 * city_tile_cache_update(). */
5340 int food = city_tile_output(pcity, ptile, celebrating, O_FOOD);
5341 int shields = city_tile_output(pcity, ptile, celebrating, O_SHIELD);
5342 int trade = city_tile_output(pcity, ptile, celebrating, O_TRADE);
5343
5344 const int ox = t->type == TS_ISOMETRIC ? t->normal_tile_width / 3 : 0;
5345 const int oy = t->type == TS_ISOMETRIC ? -t->normal_tile_height / 3 : 0;
5346
5347 food = CLIP(0, food / game.info.granularity, NUM_TILES_DIGITS - 1);
5348 shields = CLIP(0, shields / game.info.granularity, NUM_TILES_DIGITS - 1);
5349 trade = CLIP(0, trade / game.info.granularity, NUM_TILES_DIGITS - 1);
5350
5352 ADD_SPRITE(t->sprites.city.tile_shieldnum[shields], TRUE, ox, oy);
5354 }
5355 } else if (psettler && psettler->client.colored) {
5356 /* Add citymap overlay for a unit. */
5357 int idx = psettler->client.color_index % NUM_CITY_COLORS;
5358
5360 }
5361
5362 return sprs - saved_sprs;
5363}
5364
5365/************************************************************************/
5369static int fill_terrain_sprite_blending(const struct tileset *t,
5370 struct drawn_sprite *sprs,
5371 const struct tile *ptile,
5372 const struct terrain *pterrain,
5373 struct terrain **tterrain_near)
5374{
5375 struct drawn_sprite *saved_sprs = sprs;
5376 const int W = t->normal_tile_width, H = t->normal_tile_height;
5377 const int offsets[4][2] = {
5378 {W/2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}
5379 };
5380 enum direction4 dir = 0;
5381
5382 /*
5383 * We want to mark unknown tiles so that an unreal tile will be
5384 * given the same marking as our current tile - that way we won't
5385 * get the "unknown" dither along the edge of the map.
5386 */
5387 for (; dir < 4; dir++) {
5388 struct tile *tile1 = mapstep(&(wld.map), ptile, DIR4_TO_DIR8[dir]);
5389 struct terrain *other;
5390
5391 if (!tile1
5393 || pterrain == (other = tterrain_near[DIR4_TO_DIR8[dir]])
5394 || (0 == t->sprites.drawing[terrain_index(other)]->blending
5395 && NULL == t->sprites.drawing[terrain_index(other)]->blender)) {
5396 continue;
5397 }
5398
5400 offsets[dir][0], offsets[dir][1]);
5401 }
5402
5403 return sprs - saved_sprs;
5404}
5405
5406/************************************************************************/
5409static int fill_fog_sprite_array(const struct tileset *t,
5410 struct drawn_sprite *sprs,
5411 const struct tile *ptile,
5412 const struct tile_edge *pedge,
5413 const struct tile_corner *pcorner)
5414{
5415 struct drawn_sprite *saved_sprs = sprs;
5416
5418 && NULL != ptile
5420 /* With FOG_AUTO, fog is done this way. */
5422 }
5423
5426 int i, tileno = 0;
5427
5428 for (i = 3; i >= 0; i--) {
5429 const int unknown = 0, fogged = 1, known = 2;
5430 int value = -1;
5431
5432 if (!pcorner->tile[i]) {
5433 value = fogged;
5434 } else {
5435 switch (client_tile_get_known(pcorner->tile[i])) {
5436 case TILE_KNOWN_SEEN:
5437 value = known;
5438 break;
5439 case TILE_KNOWN_UNSEEN:
5440 value = fogged;
5441 break;
5442 case TILE_UNKNOWN:
5443 value = unknown;
5444 break;
5445 }
5446 }
5447 fc_assert(value >= 0 && value < 3);
5448
5449 tileno = tileno * 3 + value;
5450 }
5451
5452 if (t->sprites.tx.fullfog[tileno]) {
5454 }
5455 }
5456
5457 return sprs - saved_sprs;
5458}
5459
5460/************************************************************************/
5464 struct drawn_sprite *sprs,
5465 int l, /* layer_num */
5466 const struct tile *ptile,
5467 const struct terrain *pterrain,
5468 struct terrain **tterrain_near,
5469 struct drawing_data *draw)
5470{
5471 struct drawn_sprite *saved_sprs = sprs;
5472 struct drawing_layer *dlp = &draw->layer[l];
5473 int this = dlp->match_index[0];
5474 int that = dlp->match_index[1];
5475 int ox = dlp->offset_x;
5476 int oy = dlp->offset_y;
5477 int i;
5478
5479#define MATCH(dir) \
5480 (t->sprites.drawing[terrain_index(tterrain_near[(dir)])]->num_layers > l \
5481 ? t->sprites.drawing[terrain_index(tterrain_near[(dir)])]->layer[l].match_index[0] \
5482 : -1)
5483
5484 switch (dlp->sprite_type) {
5485 case CELL_WHOLE:
5486 {
5487 switch (dlp->match_style) {
5488 case MATCH_NONE:
5489 {
5490 int count = sprite_vector_size(&dlp->base);
5491
5492 if (count > 0) {
5493 /* Pseudo-random reproducible algorithm to pick a sprite. Use modulo
5494 * to limit the number to a handleable size [0..32000). */
5495 count = fc_randomly(tile_index(ptile) % 32000, count);
5496
5497 if (dlp->is_tall) {
5500 }
5501 ADD_SPRITE(dlp->base.p[count], TRUE, ox, oy);
5502 }
5503 break;
5504 }
5505 case MATCH_SAME:
5506 {
5507 int tileno = 0;
5508
5509 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5510 enum direction8 dir = t->cardinal_tileset_dirs[i];
5511
5512 if (MATCH(dir) == this) {
5513 tileno |= 1 << i;
5514 }
5515 }
5516
5517 if (dlp->is_tall) {
5520 }
5521 ADD_SPRITE(dlp->match[tileno], TRUE, ox, oy);
5522 break;
5523 }
5524 case MATCH_PAIR:
5525 case MATCH_FULL:
5526 fc_assert(FALSE); /* Not yet defined */
5527 break;
5528 };
5529 break;
5530 }
5531 case CELL_CORNER:
5532 {
5533 /* Divide the tile up into four rectangular cells. Each of these
5534 * cells covers one corner, and each is adjacent to 3 different
5535 * tiles. For each cell we pick a sprite based upon the adjacent
5536 * terrains at each of those tiles. Thus, we have 8 different sprites
5537 * for each of the 4 cells (32 sprites total).
5538 *
5539 * These arrays correspond to the direction4 ordering. */
5540 const int W = t->normal_tile_width;
5541 const int H = t->normal_tile_height;
5542 const int iso_offsets[4][2] = {
5543 {W / 4, 0}, {W / 4, H / 2}, {W / 2, H / 4}, {0, H / 4}
5544 };
5545 const int noniso_offsets[4][2] = {
5546 {0, 0}, {W / 2, H / 2}, {W / 2, 0}, {0, H / 2}
5547 };
5548
5549 /* Put corner cells */
5550 for (i = 0; i < NUM_CORNER_DIRS; i++) {
5551 const int count = dlp->match_indices;
5552 int array_index = 0;
5553 enum direction8 dir = dir_ccw(DIR4_TO_DIR8[i]);
5554 int x = (t->type == TS_ISOMETRIC ? iso_offsets[i][0] : noniso_offsets[i][0]);
5555 int y = (t->type == TS_ISOMETRIC ? iso_offsets[i][1] : noniso_offsets[i][1]);
5556 int m[3] = {MATCH(dir_ccw(dir)), MATCH(dir), MATCH(dir_cw(dir))};
5557 struct sprite *s;
5558
5559 /* Synthesize 4 dimensional array? */
5560 switch (dlp->match_style) {
5561 case MATCH_NONE:
5562 /* We have no need for matching, just plug the piece in place. */
5563 break;
5564 case MATCH_SAME:
5565 array_index = array_index * 2 + (m[2] != this);
5566 array_index = array_index * 2 + (m[1] != this);
5567 array_index = array_index * 2 + (m[0] != this);
5568 break;
5569 case MATCH_PAIR:
5570 array_index = array_index * 2 + (m[2] == that);
5571 array_index = array_index * 2 + (m[1] == that);
5572 array_index = array_index * 2 + (m[0] == that);
5573 break;
5574 case MATCH_FULL:
5575 default:
5576 if (count > 0) {
5577 int n[3];
5578 int j;
5579
5580 for (j = 0; j < 3; j++) {
5581 int k;
5582
5583 for (k = 0; k < count; k++) {
5584 n[j] = k; /* Default to last entry */
5585 if (m[j] == dlp->match_index[k]) {
5586 break;
5587 }
5588 }
5589 }
5590 array_index = array_index * count + n[2];
5591 array_index = array_index * count + n[1];
5592 array_index = array_index * count + n[0];
5593 }
5594 break;
5595 };
5596
5598
5599 s = dlp->cells[array_index];
5600 if (s) {
5601 ADD_SPRITE(s, TRUE, x, y);
5602 }
5603 }
5604 break;
5605 }
5606 };
5607#undef MATCH
5608
5609 return sprs - saved_sprs;
5610}
5611
5612/************************************************************************/
5617 struct drawn_sprite *sprs,
5618 const struct tile *ptile,
5619 struct terrain **tterrain_near)
5620{
5621 struct drawn_sprite *saved_sprs = sprs;
5622 int i, tileno;
5623 struct tile *adjc_tile;
5624
5625#define UNKNOWN(dir) \
5626 ((adjc_tile = mapstep(&(wld.map), ptile, (dir))) \
5627 && client_tile_get_known(adjc_tile) == TILE_UNKNOWN)
5628
5629 switch (t->darkness_style) {
5630 case DARKNESS_NONE:
5631 break;
5632 case DARKNESS_ISORECT:
5633 for (i = 0; i < 4; i++) {
5634 const int W = t->normal_tile_width, H = t->normal_tile_height;
5635 int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
5636
5637 if (UNKNOWN(DIR4_TO_DIR8[i])) {
5639 offsets[i][0], offsets[i][1]);
5640 }
5641 }
5642 break;
5644 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5645 if (UNKNOWN(t->cardinal_tileset_dirs[i])) {
5647 }
5648 }
5649 break;
5650 case DARKNESS_CARD_FULL:
5651 /* We're looking to find the INDEX_NSEW for the directions that
5652 * are unknown. We want to mark unknown tiles so that an unreal
5653 * tile will be given the same marking as our current tile - that
5654 * way we won't get the "unknown" dither along the edge of the
5655 * map. */
5656 tileno = 0;
5657 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5658 if (UNKNOWN(t->cardinal_tileset_dirs[i])) {
5659 tileno |= 1 << i;
5660 }
5661 }
5662
5663 if (tileno != 0) {
5665 }
5666 break;
5667 case DARKNESS_CORNER:
5668 /* Handled separately. */
5669 break;
5670 };
5671#undef UNKNOWN
5672
5673 return sprs - saved_sprs;
5674}
5675
5676/************************************************************************/
5681 struct drawn_sprite *sprs,
5682 int layer_num,
5683 const struct tile *ptile,
5684 const struct terrain *pterrain,
5685 struct terrain **tterrain_near)
5686{
5687 struct sprite *sprite;
5688 struct drawn_sprite *saved_sprs = sprs;
5689 struct drawing_data *draw = t->sprites.drawing[terrain_index(pterrain)];
5690 const int l = (draw->is_reversed
5691 ? (draw->num_layers - layer_num - 1) : layer_num);
5692
5694
5695 /* Skip the normal drawing process. */
5696 /* FIXME: this should avoid calling load_sprite since it's slow and
5697 * increases the refcount without limit. */
5698 if (ptile->spec_sprite && (sprite = load_sprite(t, ptile->spec_sprite,
5699 TRUE, FALSE, FALSE))) {
5700 if (l == 0) {
5702 return 1;
5703 } else {
5704 return 0;
5705 }
5706 }
5707
5709 sprs += fill_terrain_sprite_array(t, sprs, l, ptile, pterrain, tterrain_near, draw);
5710
5711 if ((l + 1) == draw->blending) {
5712 sprs += fill_terrain_sprite_blending(t, sprs, ptile, pterrain, tterrain_near);
5713 }
5714 }
5715
5716 return sprs - saved_sprs;
5717}
5718
5719/************************************************************************/
5726{
5727 /* Display an outline for city-builder type units if they are selected,
5728 * and on a tile where a city can be built.
5729 * But suppress the outline if the unit has orders (likely it is in
5730 * transit to somewhere else and this will just slow down redraws). */
5737}
5738
5739/************************************************************************/
5742static int fill_grid_sprite_array(const struct tileset *t,
5743 struct drawn_sprite *sprs,
5744 const struct tile *ptile,
5745 const struct tile_edge *pedge,
5746 const struct tile_corner *pcorner,
5747 const struct unit *punit,
5748 const struct city *pcity,
5749 const struct city *citymode)
5750{
5751 struct drawn_sprite *saved_sprs = sprs;
5752
5753 if (pedge) {
5754 bool known[NUM_EDGE_TILES], city[NUM_EDGE_TILES];
5755 bool unit[NUM_EDGE_TILES], worked[NUM_EDGE_TILES];
5756 int i;
5757 struct unit_list *pfocus_units = get_units_in_focus();
5758
5759 for (i = 0; i < NUM_EDGE_TILES; i++) {
5760 int dummy_x, dummy_y;
5761 const struct tile *tile = pedge->tile[i];
5762 struct player *powner = tile ? tile_owner(tile) : NULL;
5763
5765 unit[i] = FALSE;
5766 if (tile && !citymode) {
5769 struct tile *utile = unit_tile(pfocus_unit);
5770 int radius = game.info.init_city_radius_sq
5772 NULL,
5773 &(const struct req_context) {
5774 .player = unit_owner(pfocus_unit),
5775 .tile = utile,
5776 },
5777 NULL,
5779 );
5780
5781 if (city_tile_to_city_map(&dummy_x, &dummy_y, radius,
5782 utile, tile)) {
5783 unit[i] = TRUE;
5784 break;
5785 }
5786 }
5788 }
5789 worked[i] = FALSE;
5790
5791 city[i] = (tile
5792 && (NULL == powner || NULL == client.conn.playing
5793 || powner == client.conn.playing)
5795 if (city[i]) {
5796 if (citymode) {
5797 /* In citymode, we only draw worked tiles for this city - other
5798 * tiles may be marked as unavailable. */
5799 worked[i] = (tile_worked(tile) == citymode);
5800 } else {
5801 worked[i] = (NULL != tile_worked(tile));
5802 }
5803 }
5804 }
5805
5806 if (mapdeco_is_highlight_set(pedge->tile[0])
5807 || mapdeco_is_highlight_set(pedge->tile[1])) {
5810 && pedge->tile[0] && pedge->tile[1]
5811 && known[0] && known[1]
5812 && (is_ocean_tile(pedge->tile[0])
5813 ^ is_ocean_tile(pedge->tile[1]))) {
5815 } else {
5817 if (worked[0] || worked[1]) {
5819 } else if (city[0] || city[1]) {
5821 } else if (known[0] || known[1]) {
5823 }
5824 }
5826 if (XOR(city[0], city[1])) {
5828 }
5829 if (XOR(unit[0], unit[1])) {
5831 }
5832 }
5833 }
5834
5837 && known[0]
5838 && known[1]) {
5839 struct player *owner0 = tile_owner(pedge->tile[0]);
5840 struct player *owner1 = tile_owner(pedge->tile[1]);
5841
5842 if (owner0 != owner1) {
5843 if (owner0) {
5844 int plrid = player_index(owner0);
5846 [pedge->type][0]);
5847 }
5848 if (owner1) {
5849 int plrid = player_index(owner1);
5851 [pedge->type][1]);
5852 }
5853 }
5854 }
5855 } else if (NULL != ptile && TILE_UNKNOWN != client_tile_get_known(ptile)) {
5856 int cx, cy;
5857
5858 if (citymode
5859 /* Test to ensure valid coordinates? */
5860 && city_base_to_city_map(&cx, &cy, citymode, ptile)
5861 && !client_city_can_work_tile(citymode, ptile)) {
5863 }
5864
5866 bool native = TRUE;
5867 struct unit_list *pfocus_units = get_units_in_focus();
5868
5870 if (!is_native_tile(unit_type_get(pfocus), ptile)) {
5871 native = FALSE;
5872 break;
5873 }
5875
5876 if (!native) {
5877 if (t->sprites.grid.nonnative != NULL) {
5879 } else {
5881 }
5882 }
5883 }
5884 }
5885
5886 return sprs - saved_sprs;
5887}
5888
5889/************************************************************************/
5892static int fill_goto_sprite_array(const struct tileset *t,
5893 struct drawn_sprite *sprs,
5894 const struct tile *ptile,
5895 const struct tile_edge *pedge,
5896 const struct tile_corner *pcorner)
5897{
5898 struct drawn_sprite *saved_sprs = sprs;
5899 struct sprite *sprite;
5900 bool warn = FALSE;
5901 enum goto_tile_state state;
5902 int length;
5903 bool waypoint;
5904
5905 if (goto_tile_state(ptile, &state, &length, &waypoint)) {
5906 if (length >= 0) {
5907 fc_assert(state >= 0);
5908 fc_assert(state < ARRAY_SIZE(t->sprites.path.s));
5909
5910 sprite = t->sprites.path.s[state].specific;
5911 if (sprite != NULL) {
5912 ADD_SPRITE(sprite, FALSE, 0, 0);
5913 }
5914
5915 sprite = t->sprites.path.s[state].turns[length % 10];
5917 if (length >= 10) {
5918 sprite = t->sprites.path.s[state].turns_tens[(length / 10) % 10];
5920 if (length >= 100) {
5921 sprite = t->sprites.path.s[state].turns_hundreds[(length / 100)
5922 % 10];
5923
5924 if (sprite != NULL) {
5926 if (length >= 1000) {
5927 warn = TRUE;
5928 }
5929 } else {
5930 warn = TRUE;
5931 }
5932 }
5933 }
5934 }
5935
5936 if (waypoint) {
5938 }
5939
5940 if (warn) {
5941 /* Warn only once by tileset. */
5942 static char last_reported[256] = "";
5943
5944 if (0 != strcmp(last_reported, t->name)) {
5945 log_normal(_("Tileset \"%s\" doesn't support long goto paths, "
5946 "such as %d. Path not displayed as expected."),
5947 t->name, length);
5949 }
5950 }
5951 }
5952
5953 return sprs - saved_sprs;
5954}
5955
5956/************************************************************************/
5960static bool is_extra_drawing_enabled(struct extra_type *pextra)
5961{
5962 bool no_disable = TRUE; /* Draw if matches no cause */
5963
5964 if (is_extra_caused_by(pextra, EC_IRRIGATION)) {
5966 return TRUE;
5967 }
5968 no_disable = FALSE;
5969 }
5970 if (is_extra_caused_by(pextra, EC_POLLUTION)
5971 || is_extra_caused_by(pextra, EC_FALLOUT)) {
5973 return TRUE;
5974 }
5975 no_disable = FALSE;
5976 }
5977 if (is_extra_caused_by(pextra, EC_MINE)) {
5978 if (gui_options.draw_mines) {
5979 return TRUE;
5980 }
5981 no_disable = FALSE;
5982 }
5983 if (is_extra_caused_by(pextra, EC_RESOURCE)) {
5985 return TRUE;
5986 }
5987 no_disable = FALSE;
5988 }
5989 if (is_extra_removed_by(pextra, ERM_ENTER)) {
5990 if (gui_options.draw_huts) {
5991 return TRUE;
5992 }
5993 no_disable = FALSE;
5994 }
5995 if (is_extra_caused_by(pextra, EC_BASE)) {
5997 return TRUE;
5998 }
5999 no_disable = FALSE;
6000 }
6001 if (is_extra_caused_by(pextra, EC_ROAD)) {
6002 if (gui_options.draw_paths) {
6003 return TRUE;
6004 }
6005 no_disable = FALSE;
6006 }
6007
6008 return no_disable;
6009}
6010
6011/************************************************************************/
6028 struct drawn_sprite *sprs, enum mapview_layer layer,
6029 const struct tile *ptile,
6030 const struct tile_edge *pedge,
6031 const struct tile_corner *pcorner,
6032 const struct unit *punit, const struct city *pcity,
6033 const struct city *citymode,
6034 const struct unit_type *putype)
6035{
6036 int tileno, dir;
6039 struct terrain *tterrain_near[8];
6040 struct terrain *pterrain = nullptr;
6041 struct drawn_sprite *save_sprs = sprs;
6042 struct player *owner = nullptr;
6043 /* Unit drawing is disabled when the view options are turned off,
6044 * but only where we're drawing on the mapview. */
6045 bool do_draw_unit = (punit != nullptr && (gui_options.draw_units
6046 || ptile == nullptr
6048 && unit_is_in_focus(punit))));
6049 bool flagless = (do_draw_unit
6052 && ((do_draw_unit && !flagless)
6053 || (pcity != nullptr && gui_options.draw_cities)
6054 || (ptile != nullptr && !gui_options.draw_terrain)));
6055
6056 if (citymode) {
6057 int count = 0, i, cx, cy;
6058 const struct tile *const *tiles = nullptr;
6059 bool valid = FALSE;
6060
6061 if (ptile) {
6062 tiles = &ptile;
6063 count = 1;
6064 } else if (pcorner) {
6065 tiles = pcorner->tile;
6066 count = NUM_CORNER_TILES;
6067 } else if (pedge) {
6068 tiles = pedge->tile;
6069 count = NUM_EDGE_TILES;
6070 }
6071
6072 for (i = 0; i < count; i++) {
6073 if (tiles[i] && city_base_to_city_map(&cx, &cy, citymode, tiles[i])) {
6074 valid = TRUE;
6075 break;
6076 }
6077 }
6078 if (!valid) {
6079 return 0;
6080 }
6081 }
6082
6083 if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) {
6084 textras = *tile_extras(ptile);
6085 pterrain = tile_terrain(ptile);
6086
6087 if (NULL != pterrain) {
6088 if (layer == LAYER_TERRAIN1
6089 || layer == LAYER_TERRAIN2
6090 || layer == LAYER_TERRAIN3
6091 || layer == LAYER_WATER
6092 || layer == LAYER_ROADS) {
6093 build_tile_data(ptile, pterrain, tterrain_near, textras_near);
6094 }
6095 } else {
6096 log_error("fill_sprite_array() tile (%d,%d) has no terrain!",
6097 TILE_XY(ptile));
6098 }
6099 } else {
6101 }
6102
6103 switch (layer) {
6104 case LAYER_BACKGROUND:
6105 /* Set up background color. */
6107 if (do_draw_unit && !flagless) {
6109 } else if (pcity != nullptr && gui_options.draw_cities) {
6111 }
6112 }
6113 if (owner != nullptr) {
6115 } else if (ptile != nullptr && !gui_options.draw_terrain) {
6117 }
6118 break;
6119
6120 case LAYER_TERRAIN1:
6121 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
6122 sprs += fill_terrain_sprite_layer(t, sprs, 0, ptile, pterrain, tterrain_near);
6123 }
6124 break;
6125
6126 case LAYER_DARKNESS:
6127 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
6129 }
6130 break;
6131
6132 case LAYER_TERRAIN2:
6133 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
6134 sprs += fill_terrain_sprite_layer(t, sprs, 1, ptile, pterrain, tterrain_near);
6135 }
6136 break;
6137
6138 case LAYER_TERRAIN3:
6139 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
6141 sprs += fill_terrain_sprite_layer(t, sprs, 2, ptile, pterrain, tterrain_near);
6142 }
6143 break;
6144
6145 case LAYER_WATER:
6146 if (NULL != pterrain) {
6148 && terrain_type_terrain_class(pterrain) == TC_OCEAN) {
6149 for (dir = 0; dir < t->num_cardinal_tileset_dirs; dir++) {
6150 int didx = t->cardinal_tileset_dirs[dir];
6151
6154 int idx = extra_index(priver);
6155
6156 if (BV_ISSET(textras_near[didx], idx)) {
6158 }
6159 }
6161 }
6162 }
6163
6165 pcity);
6166
6170 int idx = extra_index(priver);
6171
6172 if (BV_ISSET(textras, idx)) {
6173 int i;
6174
6175 /* Draw rivers on top of irrigation. */
6176 tileno = 0;
6177 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
6179
6181 tileno |= 1 << i;
6182 } else {
6184
6185 if (proad != NULL) {
6186 extra_type_list_iterate(proad->integrators, iextra) {
6188 tileno |= 1 << i;
6189 }
6191 }
6192 }
6193 }
6194
6196 }
6197 }
6199 }
6200 }
6201 break;
6202
6203 case LAYER_ROADS:
6204 if (NULL != pterrain) {
6206 if (is_extra_drawing_enabled(pextra)) {
6207 sprs += fill_road_sprite_array(t, pextra, sprs,
6210 }
6213 if (is_extra_drawing_enabled(pextra)) {
6214 sprs += fill_road_sprite_array(t, pextra, sprs,
6217 }
6220 if (is_extra_drawing_enabled(pextra)) {
6221 sprs += fill_road_sprite_array(t, pextra, sprs,
6224 }
6226 }
6227 break;
6228
6229 case LAYER_SPECIAL1:
6230 if (NULL != pterrain) {
6231 if (ptile) {
6233 if (tile_has_extra(ptile, pextra)
6234 && is_extra_drawing_enabled(pextra)
6235 && t->sprites.extras[extra_index(pextra)].u.bmf.background != nullptr) {
6236 bool hidden = FALSE;
6237
6238 extra_type_list_iterate(pextra->hiders, phider) {
6240 hidden = TRUE;
6241 break;
6242 }
6244
6245 if (!hidden) {
6247 }
6248 }
6250 }
6251
6253 if (BV_ISSET(textras, extra_index(pextra))
6254 && is_extra_drawing_enabled(pextra)) {
6255 bool hidden = FALSE;
6256
6257 extra_type_list_iterate(pextra->hiders, phider) {
6259 hidden = TRUE;
6260 break;
6261 }
6263
6264 if (!hidden) {
6266 }
6267 }
6269 }
6270 break;
6271
6272 case LAYER_GRID1:
6273 if (t->type == TS_ISOMETRIC) {
6275 punit, pcity, citymode);
6276 }
6277 break;
6278
6279 case LAYER_CITY1:
6280 /* City. Some city sprites are drawn later. */
6281 if (pcity && gui_options.draw_cities) {
6283 struct sprite *spr = get_city_flag_sprite(t, pcity);
6284 struct area_rect flag_rect;
6285
6287
6291 flag_rect.w, flag_rect.h);
6292 }
6293 /* For iso-view the city.wall graphics include the full city, whereas
6294 * for non-iso view they are an overlay on top of the base city
6295 * graphic. */
6296 if (t->type == TS_OVERHEAD || pcity->client.walls <= 0) {
6300 }
6301 if (t->type == TS_ISOMETRIC && pcity->client.walls > 0) {
6302 struct city_sprite *cspr = t->sprites.city.wall[pcity->client.walls - 1];
6303 struct sprite *spr = NULL;
6304
6305 if (cspr != NULL) {
6307 }
6308 if (spr == NULL) {
6310 if (cspr != NULL) {
6312 }
6313 }
6314
6315 if (spr != NULL) {
6319 }
6320 }
6325 }
6326 if (t->type == TS_OVERHEAD && pcity->client.walls > 0) {
6327 struct city_sprite *cspr = t->sprites.city.wall[pcity->client.walls - 1];
6328 struct sprite *spr = NULL;
6329
6330 if (cspr != NULL) {
6332 }
6333 if (spr == NULL) {
6335 if (cspr != NULL) {
6337 }
6338 }
6339
6340 if (spr != NULL) {
6342 }
6343 }
6344 if (pcity->client.unhappy) {
6346 }
6347 }
6348 break;
6349
6350 case LAYER_SPECIAL2:
6351 if (NULL != pterrain) {
6352 if (ptile) {
6354 if (tile_has_extra(ptile, pextra)
6355 && is_extra_drawing_enabled(pextra)
6356 && t->sprites.extras[extra_index(pextra)].u.bmf.middleground != nullptr) {
6357 bool hidden = FALSE;
6358
6359 extra_type_list_iterate(pextra->hiders, phider) {
6361 hidden = TRUE;
6362 break;
6363 }
6365
6366 if (!hidden) {
6368 }
6369 }
6371 }
6372
6374 if (BV_ISSET(textras, extra_index(pextra))
6375 && is_extra_drawing_enabled(pextra)) {
6376 bool hidden = FALSE;
6377
6378 extra_type_list_iterate(pextra->hiders, phider) {
6380 hidden = TRUE;
6381 break;
6382 }
6384
6385 if (!hidden) {
6387 }
6388 }
6390 }
6391 break;
6392
6393 case LAYER_UNIT:
6394 case LAYER_FOCUS_UNIT:
6395 if (do_draw_unit && XOR(layer == LAYER_UNIT, unit_is_in_focus(punit))) {
6396 int stack_count = ptile ? unit_list_size(ptile->units) : 0;
6397 bool backdrop = !pcity;
6398
6399 if (ptile && unit_is_in_focus(punit)
6400 && t->sprites.unit.select != nullptr) {
6401 /* Special case for drawing the selection rectangle. The blinking
6402 * unit is handled separately, inside get_drawable_unit(). */
6403 ADD_ANIM_SPRITE(t->sprites.unit.select, TRUE,
6405 }
6406
6407 /* Load more stack number sprites if needed. no_more_stack_sprites guard
6408 * that we don't retry over and over again for every stack,
6409 * when it's not working. */
6410 if (t->sprites.unit.num_stack_sprites < stack_count
6411 && !t->sprites.unit.no_more_stack_sprites) {
6412 t->sprites.unit.stack = fc_realloc(t->sprites.unit.stack,
6413 stack_count * sizeof(struct sprite *));
6414
6415 while (t->sprites.unit.num_stack_sprites < stack_count
6416 && !t->sprites.unit.no_more_stack_sprites) {
6417 struct sprite *spr = load_gfxnumber(t->sprites.unit.num_stack_sprites + 1);
6418
6419 if (spr != NULL) {
6420 t->sprites.unit.stack[t->sprites.unit.num_stack_sprites++] = spr;
6421 } else {
6422 t->sprites.unit.no_more_stack_sprites = TRUE;
6423 t->sprites.unit.stack = fc_realloc(t->sprites.unit.stack,
6424 t->sprites.unit.num_stack_sprites * sizeof(struct sprite *));
6425 }
6426 }
6427 }
6428
6430 } else if (putype != NULL && layer == LAYER_UNIT) {
6431 /* Only the sprite for the unit type. */
6432 /* FIXME: Shouldn't this still get activity and orientation of
6433 * the actual unit? */
6436 }
6437 break;
6438
6439 case LAYER_SPECIAL3:
6440 if (NULL != pterrain) {
6441 if (ptile) {
6442 bool show_flag = FALSE;
6443 struct player *eowner = extra_owner(ptile);
6444
6446 if (is_extra_drawing_enabled(pextra)
6447 && tile_has_extra(ptile, pextra)
6448 && t->sprites.extras[extra_index(pextra)].u.bmf.foreground != nullptr) {
6449 bool hidden = FALSE;
6450
6451 extra_type_list_iterate(pextra->hiders, phider) {
6453 hidden = TRUE;
6454 break;
6455 }
6457
6458 if (!hidden) {
6459 if (t->sprites.extras[extra_index(pextra)].u.bmf.foreground != nullptr) {
6461 }
6462 }
6463 }
6465
6466 /* Show base flag. Not part of previous iteration as
6467 * "extras of ESTYLE_3_LAYER" != "bases" */
6468 if (eowner != NULL) {
6470 if (tile_has_extra(ptile, pextra)) {
6471 bool hidden = FALSE;
6472
6473 extra_type_list_iterate(pextra->hiders, phider) {
6475 hidden = TRUE;
6476 break;
6477 }
6479
6480 if (!hidden) {
6481 show_flag = TRUE;
6482 }
6483 }
6485
6486 if (show_flag) {
6490 }
6491 }
6492 }
6493 }
6494 break;
6495
6496 case LAYER_FOG:
6498 break;
6499
6500 case LAYER_CITY2:
6501 /* City size. Drawing this under fog makes it hard to read. */
6503 bool warn = FALSE;
6504 unsigned int size = city_size_get(pcity);
6505
6509 if (10 <= size) {
6511 % 10], FALSE,
6514 if (100 <= size) {
6515 struct sprite *sprite =
6516 t->sprites.city.size_hundreds[(size / 100) % 10];
6517
6518 if (NULL != sprite) {
6522 } else {
6523 warn = TRUE;
6524 }
6525 if (1000 <= size) {
6526 warn = TRUE;
6527 }
6528 }
6529 }
6530
6531 if (warn) {
6532 /* Warn only once by tileset. */
6533 static char last_reported[256] = "";
6534
6535 if (0 != strcmp(last_reported, t->name)) {
6536 log_normal(_("Tileset \"%s\" doesn't support big cities size, "
6537 "such as %d. Size not displayed as expected."),
6538 t->name, size);
6540 }
6541 }
6542 }
6543 break;
6544
6545 case LAYER_GRID2:
6546 if (t->type == TS_OVERHEAD) {
6548 punit, pcity, citymode);
6549 }
6550 break;
6551
6552 case LAYER_OVERLAYS:
6554 if (mapdeco_is_crosshair_set(ptile)) {
6556 }
6557 break;
6558
6559 case LAYER_CITYBAR:
6560 case LAYER_TILELABEL:
6561 /* Nothing. This is just a placeholder. */
6562 break;
6563
6564 case LAYER_GOTO:
6565 if (ptile && goto_is_active()) {
6567 }
6568 break;
6569
6570 case LAYER_WORKERTASK:
6571 if (citymode != NULL && ptile != NULL) {
6573 if (ptask->ptile == ptile) {
6574 switch (ptask->act) {
6575 case ACTIVITY_MINE:
6576 if (ptask->tgt == NULL) {
6577 ADD_SPRITE(t->sprites.unit.plant,
6580 } else {
6584 }
6585 break;
6586 case ACTIVITY_PLANT:
6587 ADD_SPRITE(t->sprites.unit.plant,
6590 break;
6591 case ACTIVITY_IRRIGATE:
6592 if (ptask->tgt == NULL) {
6593 ADD_SPRITE(t->sprites.unit.cultivate,
6596 } else {
6600 }
6601 break;
6602 case ACTIVITY_CULTIVATE:
6603 ADD_SPRITE(t->sprites.unit.cultivate,
6606 break;
6607 case ACTIVITY_GEN_ROAD:
6608 if (ptask->tgt != NULL) {
6612 }
6613 break;
6614 case ACTIVITY_TRANSFORM:
6615 ADD_SPRITE(t->sprites.unit.transform,
6618 break;
6619 case ACTIVITY_CLEAN:
6620 if (ptask->tgt != NULL) {
6624 }
6625 break;
6626 default:
6627 break;
6628 }
6629 }
6631 }
6632 break;
6633
6634 case LAYER_EDITOR:
6635 if (ptile && editor_is_active()) {
6636 if (editor_tile_is_selected(ptile)) {
6639 }
6640
6641 if (NULL != map_startpos_get(ptile)) {
6642 /* FIXME: Use a more representative sprite. */
6644 }
6645 }
6646 break;
6647
6648 case LAYER_INFRAWORK:
6649 if (ptile != NULL) {
6650 if (ptile->placing != NULL) {
6651 const int id = extra_index(ptile->placing);
6652
6653 if (t->sprites.extras[id].activity != NULL) {
6657 }
6658 }
6659 if (client_infratile() == ptile) {
6661 }
6662 }
6663 break;
6664
6665 case LAYER_COUNT:
6667 break;
6668 }
6669
6670 return sprs - save_sprs;
6671}
6672
6673/************************************************************************/
6677void tileset_setup_city_tiles(struct tileset *t, int style)
6678{
6679 const char *style_name = city_style_rule_name(style);
6680
6681 if (style == game.control.num_city_styles - 1) {
6682 int i;
6683
6684 /* Free old sprites */
6686
6687 for (i = 0; i < NUM_WALL_TYPES; i++) {
6689 t->sprites.city.wall[i] = NULL;
6690 }
6693
6695
6696 t->sprites.city.tile = load_city_sprite(t, "city");
6697
6698 for (i = 0; i < NUM_WALL_TYPES; i++) {
6699 char buffer[256];
6700
6701 fc_snprintf(buffer, sizeof(buffer), "bldg_%d", i);
6702 t->sprites.city.wall[i] = load_city_sprite(t, buffer);
6703 }
6704 t->sprites.city.single_wall = load_city_sprite(t, "wall");
6705
6706 t->sprites.city.occupied = load_city_sprite(t, "occupied");
6707 }
6708
6710 &t->sprites.style_citizen_sets.sets[style],
6711 city_styles[style].citizens_graphic,
6712 style_name, FALSE);
6715 &t->sprites.style_citizen_sets.sets[style],
6716 sp,
6717 city_styles[style].citizens_graphic,
6718 style_name, FALSE);
6720
6721 if (style == game.control.num_city_styles - 1) {
6722 for (style = 0; style < game.control.num_city_styles; style++) {
6723 if (t->sprites.city.tile->styles[style].land_num_thresholds == 0) {
6725 _("City style \"%s\": no city graphics."),
6726 city_style_rule_name(style));
6727 }
6728 if (t->sprites.city.occupied->styles[style].land_num_thresholds == 0) {
6730 _("City style \"%s\": no occupied graphics."),
6731 city_style_rule_name(style));
6732 }
6733 }
6734 }
6735}
6736
6737/************************************************************************/
6743{
6744 if (t->sprites.unit.select != nullptr) {
6745 return 0.1;
6746 } else {
6747 return 0.5;
6748 }
6749}
6750
6751/************************************************************************/
6756{
6757 if (t->sprites.unit.select != nullptr) {
6758 t->sprites.unit.select->time = 0;
6759 } else {
6761 }
6762}
6763
6764/************************************************************************/
6768{
6770}
6771
6772/************************************************************************/
6777{
6778 if (t->sprites.unit.select != nullptr) {
6779 anim_advance_time(t->sprites.unit.select);
6780 } else {
6782 }
6783}
6784
6785/************************************************************************/
6795
6796/************************************************************************/
6799struct unit *get_drawable_unit(const struct tileset *t,
6800 struct tile *ptile,
6801 const struct city *citymode)
6802{
6803 struct unit *punit = find_visible_unit(ptile);
6804
6805 if (punit == NULL) {
6806 return NULL;
6807 }
6808
6810 return NULL;
6811 }
6812
6814 || t->sprites.unit.select != nullptr || focus_unit_state) {
6815 return punit;
6816 } else {
6817 return NULL;
6818 }
6819}
6820
6821/************************************************************************/
6825static void unload_all_sprites(struct tileset *t)
6826{
6827 if (t->sprite_hash != nullptr) {
6829 while (ss->ref_count > 0) {
6831 }
6833 }
6834}
6835
6836/************************************************************************/
6839static void free_all_anims(struct tileset *t)
6840{
6841 if (t->anim_hash != nullptr) {
6842 anim_hash_iterate(t->anim_hash, tag, anim) {
6843 (void)tag;
6844 anim_free(anim);
6846 }
6847}
6848
6849/************************************************************************/
6853{
6854 int i;
6855
6856 log_debug("tileset_free_tiles()");
6857
6859
6861 t->sprites.city.tile = NULL;
6862
6863 for (i = 0; i < NUM_WALL_TYPES; i++) {
6865 t->sprites.city.wall[i] = NULL;
6866 }
6869
6872
6873 if (t->sprite_hash) {
6875 t->sprite_hash = NULL;
6876 }
6877
6878 if (t->sprites.style_citizen_sets.sets != NULL) {
6881 }
6882
6885 if (ss->file) {
6886 free(ss->file);
6887 }
6888 fc_assert(ss->sprite == NULL);
6889 free(ss);
6891
6894 free(sf->file_name);
6895 if (sf->big_sprite) {
6896 free_sprite(sf->big_sprite);
6897 sf->big_sprite = NULL;
6898 }
6899 free(sf);
6901
6906
6911
6912 if (t->sprites.tx.fullfog) {
6913 free(t->sprites.tx.fullfog);
6914 t->sprites.tx.fullfog = NULL;
6915 }
6916
6922
6923 /* Index 0 is 'occupied' or 'default' stack sprite */
6924 for (i = 1; i < t->sprites.unit.num_stack_sprites - 1; i++) {
6925 free_sprite(t->sprites.unit.stack[i]);
6926 }
6927 t->sprites.unit.num_stack_sprites = 0;
6928 if (t->sprites.unit.stack != NULL) {
6929 free(t->sprites.unit.stack);
6930 t->sprites.unit.stack = NULL;
6931 }
6932
6933 free_all_anims(t);
6934 t->sprites.unit.select = nullptr;
6935 t->sprites.unit.action_decision_want = nullptr;
6936
6937 if (t->anim_hash) {
6939 t->anim_hash = nullptr;
6940 }
6941
6943}
6944
6945/************************************************************************/
6948struct sprite *get_spaceship_sprite(const struct tileset *t,
6949 enum spaceship_part part)
6950{
6951 return t->sprites.spaceship[part];
6952}
6953
6954/************************************************************************/
6957static inline const struct citizen_graphic *
6960{
6961 fc_assert_ret_val(set != NULL, NULL);
6962
6963 if (type < CITIZEN_SPECIALIST) {
6965 return &set->citizen[type];
6966 } else {
6968 return &set->specialist[type - CITIZEN_SPECIALIST];
6969 }
6970}
6971
6972/************************************************************************/
6979struct sprite *get_citizen_sprite(const struct tileset *t,
6981 int citizen_index,
6982 const struct city *pcity)
6983{
6984 const struct citizen_graphic *graphic = NULL;
6986
6987 if (pcity != NULL) {
6988 int style = style_of_city(pcity);
6989
6991
6993 type);
6994
6995 gfx_index += pcity->client.first_citizen_index;
6996 }
6997
6998 if (graphic == NULL || graphic->count == 0) {
6999 /* Fall back to default sprites */
7001 }
7002
7003 if (graphic->count == 0) {
7004 return NULL;
7005 }
7006
7007 return graphic->sprite[gfx_index % graphic->count];
7008}
7009
7010/************************************************************************/
7013struct sprite *get_nation_flag_sprite(const struct tileset *t,
7014 const struct nation_type *pnation)
7015{
7016 return t->sprites.nation_flag.p[nation_index(pnation)];
7017}
7018
7019/************************************************************************/
7023 const struct nation_type *pnation)
7024{
7025 return t->sprites.nation_shield.p[nation_index(pnation)];
7026}
7027
7028/************************************************************************/
7031struct sprite *get_tech_sprite(const struct tileset *t, Tech_type_id tech)
7032{
7033 fc_assert_ret_val(0 <= tech && tech < advance_count(), NULL);
7034 return t->sprites.tech[tech];
7035}
7036
7037/************************************************************************/
7040struct sprite *get_building_sprite(const struct tileset *t,
7041 const struct impr_type *pimprove)
7042{
7043 fc_assert_ret_val(NULL != pimprove, NULL);
7044 return t->sprites.building[improvement_index(pimprove)];
7045}
7046
7047/************************************************************************/
7050struct sprite *get_government_sprite(const struct tileset *t,
7051 const struct government *gov)
7052{
7053 fc_assert_ret_val(NULL != gov, NULL);
7054 return t->sprites.government[government_index(gov)];
7055}
7056
7057/************************************************************************/
7062struct sprite *get_unittype_sprite(const struct tileset *t,
7063 const struct unit_type *punittype,
7064 enum unit_activity activity,
7065 enum direction8 facing)
7066{
7067 int uidx = utype_index(punittype);
7068 bool icon = !direction8_is_valid(facing);
7069
7070 if (activity >= ACTIVITY_LAST) {
7071 activity = ACTIVITY_IDLE;
7072 }
7073
7075
7076 if (!direction8_is_valid(facing) || !is_valid_dir(facing)) {
7077 facing = t->unit_default_orientation;
7078 /* May not have been specified, but it only matters if we don't
7079 * turn out to have an icon sprite */
7080 }
7081
7082 if (t->sprites.units.icon[uidx][activity] != nullptr
7083 && (icon || t->sprites.units.facing[uidx][facing][activity] == nullptr)) {
7084 /* Has icon sprite, and we prefer to (or must) use it */
7085 if (icon) {
7086 return t->sprites.units.icon[uidx][activity]->sprites[0];
7087 } else {
7088 return anim_get_current_frame(t->sprites.units.icon[uidx][activity]);
7089 }
7090 } else if (t->sprites.units.icon[uidx][ACTIVITY_IDLE] != nullptr
7091 && (icon
7092 || t->sprites.units.facing[uidx][facing][ACTIVITY_IDLE] == nullptr)) {
7093 /* Has icon sprite, and we prefer to (or must) use it */
7094 if (icon) {
7095 return t->sprites.units.icon[uidx][ACTIVITY_IDLE]->sprites[0];
7096 } else {
7098 }
7099 } else {
7100 /* We should have a valid orientation by now. Failure to have either
7101 * an icon sprite or default orientation should have been caught at
7102 * tileset load. */
7103 fc_assert_ret_val(direction8_is_valid(facing), nullptr);
7104
7105 if (t->sprites.units.facing[uidx][facing][activity] == nullptr) {
7107 }
7108
7109 return anim_get_current_frame(t->sprites.units.facing[uidx][facing][activity]);
7110 }
7111}
7112
7113/************************************************************************/
7116struct sprite *get_sample_city_sprite(const struct tileset *t,
7117 int style_idx)
7118{
7119 int num_thresholds =
7120 t->sprites.city.tile->styles[style_idx].land_num_thresholds;
7121
7122 if (num_thresholds == 0) {
7123 return NULL;
7124 } else {
7125 return (t->sprites.city.tile->styles[style_idx]
7126 .land_thresholds[num_thresholds - 1].sprite);
7127 }
7128}
7129
7130/************************************************************************/
7133struct sprite *get_arrow_sprite(const struct tileset *t,
7134 enum arrow_type arrow)
7135{
7136 fc_assert_ret_val(arrow >= 0 && arrow < ARROW_LAST, NULL);
7137
7138 return t->sprites.arrow[arrow];
7139}
7140
7141/************************************************************************/
7145{
7146 switch (otype) {
7147 case O_SCIENCE:
7148 return t->sprites.tax_science;
7149 case O_GOLD:
7150 return t->sprites.tax_gold;
7151 case O_LUXURY:
7152 return t->sprites.tax_luxury;
7153 case O_TRADE:
7154 case O_FOOD:
7155 case O_SHIELD:
7156 case O_LAST:
7157 break;
7158 }
7159 return NULL;
7160}
7161
7162/************************************************************************/
7165struct sprite *get_event_sprite(const struct tileset *t, enum event_type event)
7166{
7167 return t->sprites.events[event];
7168}
7169
7170/************************************************************************/
7174struct sprite *get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
7175{
7176 return t->sprites.treaty_thumb[on_off ? 1 : 0];
7177}
7178
7179/************************************************************************/
7184 tileset *t)
7185{
7186 return &t->sprites.explode.unit;
7187}
7188
7189/************************************************************************/
7195{
7196 return t->sprites.explode.nuke;
7197}
7198
7199/************************************************************************/
7202const struct citybar_sprites *get_citybar_sprites(const struct tileset *t)
7203{
7205 return &t->sprites.citybar;
7206 } else {
7207 return NULL;
7208 }
7209}
7210
7211/************************************************************************/
7214const struct editor_sprites *get_editor_sprites(const struct tileset *t)
7215{
7216 return &t->sprites.editor;
7217}
7218
7219/************************************************************************/
7225struct sprite *get_cursor_sprite(const struct tileset *t,
7226 enum cursor_type cursor,
7227 int *hot_x, int *hot_y, int frame)
7228{
7229 *hot_x = t->sprites.cursor[cursor].hot_x;
7230 *hot_y = t->sprites.cursor[cursor].hot_y;
7231
7232 return t->sprites.cursor[cursor].frame[frame];
7233}
7234
7235/************************************************************************/
7244struct sprite *get_icon_sprite(const struct tileset *t, enum icon_type icon)
7245{
7246 return t->sprites.icon[icon];
7247}
7248
7249/************************************************************************/
7256{
7257 return t->sprites.user.attention;
7258}
7259
7260/************************************************************************/
7264struct sprite *get_indicator_sprite(const struct tileset *t,
7265 enum indicator_type indicator,
7266 int idx)
7267{
7268 idx = CLIP(0, idx, NUM_TILES_PROGRESS - 1);
7269
7270 fc_assert_ret_val(indicator >= 0 && indicator < INDICATOR_COUNT, NULL);
7271
7272 return t->sprites.indicator[indicator][idx];
7273}
7274
7275/************************************************************************/
7282 const struct unit *punit,
7283 int happy_cost)
7284{
7285 const int unhappy = CLIP(0, happy_cost, MAX_NUM_UPKEEP_SPRITES+1);
7286
7287 if (unhappy > 0) {
7288 return t->sprites.upkeep.unhappy[unhappy - 1];
7289 } else {
7290 return NULL;
7291 }
7292}
7293
7294/************************************************************************/
7300struct sprite *get_unit_upkeep_sprite(const struct tileset *t,
7302 const struct unit *punit,
7303 const int *upkeep_cost)
7304{
7305 const int upkeep = CLIP(0, upkeep_cost[otype], MAX_NUM_UPKEEP_SPRITES + 1);
7306
7307 if (upkeep > 0) {
7308 return t->sprites.upkeep.output[otype][upkeep - 1];
7309 } else {
7310 return NULL;
7311 }
7312}
7313
7314/************************************************************************/
7318struct sprite *get_basic_fog_sprite(const struct tileset *t)
7319{
7320 return t->sprites.tx.fog;
7321}
7322
7323/************************************************************************/
7326struct color_system *get_color_system(const struct tileset *t)
7327{
7328 return t->color_system;
7329}
7330
7331/************************************************************************/
7335{
7336 char *default_theme_name = NULL;
7337 size_t default_theme_name_sz = 0;
7338 int i;
7339
7340 switch (get_gui_type()) {
7341 case GUI_GTK3_22:
7344 break;
7345 case GUI_GTK4:
7348 break;
7349 case GUI_SDL2:
7352 break;
7353 case GUI_SDL3:
7356 break;
7357 case GUI_STUB:
7358 case GUI_QT:
7359 case GUI_SDL:
7360 case GUI_WEB:
7361 case GUI_GTK2:
7362 case GUI_GTK3:
7363 break;
7364 }
7365
7367 /* Theme is not supported by this client. */
7368 return;
7369 }
7370
7371 for (i = 0; i < t->num_preferred_themes; i++) {
7374 log_debug("trying theme \"%s\".", t->preferred_themes[i]);
7375 if (load_theme(t->preferred_themes[i])) {
7378 return;
7379 }
7380 }
7381 }
7382 }
7383 log_verbose("The tileset doesn't specify preferred themes or none of its "
7384 "preferred themes can be used. Using system default.");
7386}
7387
7388/************************************************************************/
7391void tileset_init(struct tileset *t)
7392{
7393 int wi;
7394
7395 /* We currently have no city sprites loaded. */
7396 t->sprites.city.tile = NULL;
7397
7398 for (wi = 0; wi < NUM_WALL_TYPES; wi++) {
7399 t->sprites.city.wall[wi] = NULL;
7400 }
7402
7404
7405 t->sprites.background.color = NULL;
7406 t->sprites.background.graphic = NULL;
7407
7408 player_slots_iterate(pslot) {
7409 int edge, j, id = player_slot_index(pslot);
7410
7411 for (edge = 0; edge < EDGE_COUNT; edge++) {
7412 for (j = 0; j < 2; j++) {
7414 }
7415 }
7416
7417 t->sprites.player[id].color = NULL;
7420
7421 t->max_upkeep_height = 0;
7422}
7423
7424/************************************************************************/
7433 struct drawn_sprite *sprs,
7434 int layer,
7435 struct terrain *pterrain)
7436{
7437 struct drawn_sprite *save_sprs = sprs;
7438 struct drawing_data *draw = t->sprites.drawing[terrain_index(pterrain)];
7439
7440 struct terrain *tterrain_near[8];
7442
7443 struct tile dummy_tile; /* :( */
7444
7445 int i;
7446
7447
7448 memset(&dummy_tile, 0, sizeof(struct tile));
7449
7450 for (i = 0; i < 8; i++) {
7451 tterrain_near[i] = pterrain;
7453 }
7454
7455 i = draw->is_reversed ? draw->num_layers - layer - 1 : layer;
7457 pterrain, tterrain_near, draw);
7458
7459 return sprs - save_sprs;
7460}
7461
7462/************************************************************************/
7466 struct drawn_sprite *sprs,
7467 const struct extra_type *pextra)
7468{
7469 int idx = extra_index(pextra);
7470 struct drawn_sprite *saved_sprs = sprs;
7471
7472 switch (t->sprites.extras[idx].extrastyle) {
7473 case ESTYLE_SINGLE1:
7474 case ESTYLE_SINGLE2:
7476 break;
7477 case ESTYLE_CARDINALS:
7479 break;
7483 case ESTYLE_RIVER:
7484 return fill_basic_road_sprite_array(t, sprs, pextra);
7485 case ESTYLE_3LAYER:
7486 return fill_basic_base_sprite_array(t, sprs, pextra);
7487 case ESTYLE_COUNT:
7489 break;
7490 }
7491
7492 return sprs - saved_sprs;
7493}
7494
7495/************************************************************************/
7501 struct drawn_sprite *sprs,
7502 const struct extra_type *pextra)
7503{
7504 struct drawn_sprite *saved_sprs = sprs;
7505 int idx;
7506 int i;
7507 enum extrastyle_id extrastyle;
7508
7509 if (!t || !sprs || !pextra) {
7510 return 0;
7511 }
7512
7513 idx = extra_index(pextra);
7514
7515 if (!(0 <= idx && idx < game.control.num_extra_types)) {
7516 return 0;
7517 }
7518
7519 extrastyle = t->sprites.extras[idx].extrastyle;
7520
7521 if (extrastyle == ESTYLE_RIVER) {
7523 } else {
7524 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
7525 if (!t->valid_tileset_dirs[i]) {
7526 continue;
7527 }
7528 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
7530 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
7531 if ((i % 2) == 0) {
7532 ADD_FRAME0_SIMPLE(t->sprites.extras[idx].u.road.ru.combo.even[1 << (i / 2)]);
7533 }
7534 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
7535 ADD_FRAME0_SIMPLE(t->sprites.extras[idx].u.road.ru.total[1 << i]);
7536 }
7537 }
7538 }
7539
7540 return sprs - saved_sprs;
7541}
7542
7543/************************************************************************/
7549 struct drawn_sprite *sprs,
7550 const struct extra_type *pextra)
7551{
7552 struct drawn_sprite *saved_sprs = sprs;
7553 int idx;
7554
7555 if (!t || !sprs || !pextra) {
7556 return 0;
7557 }
7558
7559 idx = extra_index(pextra);
7560
7561 if (!(0 <= idx && idx < game.control.num_extra_types)) {
7562 return 0;
7563 }
7564
7565#define ADD_FRAME0_IF_NOT_NULL(x) do {\
7566 if ((x) != nullptr) {\
7567 ADD_FRAME0_FULL(x);\
7568 }\
7569} while (FALSE)
7570
7571 /* Corresponds to LAYER_SPECIAL{1,2,3} order. */
7575
7576#undef ADD_FRAME0_IF_NOT_NULL
7577
7578 return sprs - saved_sprs;
7579}
7580
7581/************************************************************************/
7584enum mapview_layer tileset_get_layer(const struct tileset *t, int n)
7585{
7587
7588 return t->layer_order[n];
7589}
7590
7591/************************************************************************/
7595 enum layer_category cat)
7596{
7597 switch (layer) {
7598 case LAYER_BACKGROUND:
7599 case LAYER_TERRAIN1:
7600 case LAYER_DARKNESS:
7601 case LAYER_TERRAIN2:
7602 case LAYER_TERRAIN3:
7603 case LAYER_WATER:
7604 case LAYER_ROADS:
7605 case LAYER_SPECIAL1:
7606 case LAYER_SPECIAL2:
7607 case LAYER_SPECIAL3:
7609 case LAYER_CITY1:
7610 case LAYER_CITY2:
7611 return cat == LAYER_CATEGORY_CITY;
7612 case LAYER_UNIT:
7613 case LAYER_FOCUS_UNIT:
7614 return cat == LAYER_CATEGORY_UNIT;
7615 case LAYER_GRID1:
7616 case LAYER_FOG:
7617 case LAYER_GRID2:
7618 case LAYER_OVERLAYS:
7619 case LAYER_TILELABEL:
7620 case LAYER_CITYBAR:
7621 case LAYER_GOTO:
7622 case LAYER_WORKERTASK:
7623 case LAYER_EDITOR:
7624 case LAYER_INFRAWORK:
7625 return FALSE;
7626 case LAYER_COUNT:
7627 break; /* and fail below */
7628 }
7629
7630 fc_assert_msg(FALSE, "Unknown layer category: %d", cat);
7631 return FALSE;
7632}
7633
7634/************************************************************************/
7637void tileset_player_init(struct tileset *t, struct player *pplayer)
7638{
7639 int plrid, i, j;
7640 struct sprite *color;
7641
7642 fc_assert_ret(pplayer != NULL);
7643
7644 plrid = player_index(pplayer);
7645 fc_assert_ret(plrid >= 0);
7647
7648 /* Free all data before recreating it. */
7650
7651 if (player_has_color(pplayer)) {
7653 = create_plr_sprite(get_player_color(t, pplayer));
7654 } else {
7655 /* XXX: if player hasn't been assigned a color, perhaps there's no
7656 * point proceeding with an arbitrary color; this should only happen
7657 * in pregame. Probably blank sprites would be better. */
7658
7659 fc_assert_ret(t->sprites.background.color != NULL);
7660
7661 color = t->sprites.background.color;
7662 }
7663
7665 = crop_sprite(color, 0, 0,
7667 t->sprites.mask.tile, 0, 0, t->scale, FALSE);
7668
7669 for (i = 0; i < EDGE_COUNT; i++) {
7670 for (j = 0; j < 2; j++) {
7671 struct sprite *s;
7672
7673 if (color && t->sprites.grid.borders[i][j]) {
7674 s = crop_sprite(color, 0, 0,
7676 t->sprites.grid.borders[i][j], 0, 0, 1.0f, FALSE);
7677 } else {
7678 s = t->sprites.grid.borders[i][j];
7679 }
7680 t->sprites.player[plrid].grid_borders[i][j] = s;
7681 }
7682 }
7683}
7684
7685/************************************************************************/
7688static void tileset_player_free(struct tileset *t, int plrid)
7689{
7690 int i, j;
7691
7692 fc_assert_ret(plrid >= 0);
7694
7695 if (t->sprites.player[plrid].color) {
7698 }
7699 if (t->sprites.player[plrid].background) {
7702 }
7703
7704 for (i = 0; i < EDGE_COUNT; i++) {
7705 for (j = 0; j < 2; j++) {
7706 if (t->sprites.player[plrid].grid_borders[i][j]) {
7709 }
7710 }
7711 }
7712}
7713
7714/************************************************************************/
7718{
7719 /* Free all data before recreating it. */
7721
7722 /* Generate background color */
7723 t->sprites.background.color
7725
7726 /* Chop up and build the background graphics. */
7727 t->sprites.background.graphic
7728 = crop_sprite(t->sprites.background.color, 0, 0,
7730 t->sprites.mask.tile, 0, 0, t->scale, FALSE);
7731}
7732
7733/************************************************************************/
7737{
7738 if (t->sprites.background.color) {
7739 free_sprite(t->sprites.background.color);
7740 t->sprites.background.color = NULL;
7741 }
7742
7743 if (t->sprites.background.graphic) {
7744 free_sprite(t->sprites.background.graphic);
7745 t->sprites.background.graphic = NULL;
7746 }
7747}
7748
7749/************************************************************************/
7753{
7754 int i;
7755
7756 for (i = 0; i < ESTYLE_COUNT; i++) {
7757 if (t->style_lists[i] != NULL) {
7760 }
7761 }
7762
7763 if (t->flagged_bases_list != NULL) {
7766 }
7767
7768 if (t->sprites.style_citizen_sets.sets != NULL) {
7770 }
7771
7774 * sizeof(t->sprites.style_citizen_sets.sets[0]));
7775}
7776
7777/************************************************************************/
7781{
7782 return !tileset_update;
7783}
7784
7785/************************************************************************/
7788const char *tileset_name_get(struct tileset *t)
7789{
7790 return t->given_name;
7791}
7792
7793/************************************************************************/
7796const char *tileset_version(struct tileset *t)
7797{
7798 return t->version;
7799}
7800
7801/************************************************************************/
7804const char *tileset_summary(struct tileset *t)
7805{
7806 return t->summary;
7807}
7808
7809/************************************************************************/
7812const char *tileset_description(struct tileset *t)
7813{
7814 return t->description;
7815}
7816
7817/************************************************************************/
7821{
7822 return t->for_ruleset;
7823}
7824
7825/************************************************************************/
7829{
7830 return t->ts_topo_idx;
7831}
7832
7833/************************************************************************/
7837{
7838 return t->svg_height;
7839}
7840
7841/************************************************************************/
7844struct sprite *load_popup_sprite(const char *tag)
7845{
7846 return load_sprite(tileset, tag, TRUE, TRUE, FALSE);
7847}
7848
7849/************************************************************************/
7852void unload_popup_sprite(const char *tag)
7853{
7854 unload_sprite(tileset, tag);
7855}
#define str
Definition astring.c:76
#define n
Definition astring.c:77
#define BV_CLR_ALL(bv)
Definition bitvector.h:103
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
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:88
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:566
citizen_category
Definition city.h:264
@ CITIZEN_LAST
Definition city.h:269
@ CITIZEN_SPECIALIST
Definition city.h:270
@ CITIZEN_ANGRY
Definition city.h:268
@ CITIZEN_HAPPY
Definition city.h:265
@ CITIZEN_CONTENT
Definition city.h:266
@ CITIZEN_UNHAPPY
Definition city.h:267
#define output_type_iterate(output)
Definition city.h:842
#define city_owner(_pcity_)
Definition city.h:560
#define MAX_CITY_SIZE
Definition city.h:103
#define output_type_iterate_end
Definition city.h:848
void generate_citydlg_dimensions(void)
struct civclient client
enum client_states client_state(void)
#define client_player()
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
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:76
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:834
#define log_deprecation(message,...)
static void road(QVariant data1, QVariant data2)
Definition dialogs.cpp:3311
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:73
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 struct unit struct city * pcity
Definition dialogs_g.h:77
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_city_bonus(const struct city *pcity, enum effect_type effect_type)
Definition effects.c:842
int get_target_bonus_effects(struct effect_list *plist, const struct req_context *context, const struct req_context *other_context, enum effect_type effect_type)
Definition effects.c:744
enum event_type event
Definition events.c:81
static struct @25 events[]
const char * get_event_tag(enum event_type event)
Definition events.c:276
char * tag_name
Definition events.c:77
struct player * extra_owner(const struct tile *ptile)
Definition extras.c:1128
bool extra_has_flag(const struct extra_type *pextra, enum extra_flag_id flag)
Definition extras.c:875
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:329
#define MAX_NUM_ITEMS
Definition fc_types.h:40
int Tech_type_id
Definition fc_types.h:237
#define SP_MAX
Definition fc_types.h:268
int Specialist_type_id
Definition fc_types.h:235
#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:67
@ O_SHIELD
Definition fc_types.h:102
@ O_FOOD
Definition fc_types.h:102
@ O_TRADE
Definition fc_types.h:102
@ O_SCIENCE
Definition fc_types.h:102
@ O_LUXURY
Definition fc_types.h:102
@ O_GOLD
Definition fc_types.h:102
@ O_LAST
Definition fc_types.h:102
@ BORDERS_DISABLED
Definition fc_types.h:744
enum output_type_id Output_type_id
Definition fc_types.h:238
#define _(String)
Definition fcintl.h:67
struct civ_game game
Definition game.c:61
struct world wld
Definition game.c:62
bool goto_is_active(void)
Definition goto.c:1070
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
void show_tileset_error(bool fatal, const char *tset_name, const char *msg)
Definition dialogs.c:1540
void tileset_type_set(enum ts_type type)
Definition graphics.c:53
enum gui_type get_gui_type(void)
Definition gui_main.c:2046
void dirty_all(void)
Definition mapview.c:456
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
struct client_properties gui_properties
void boot_help_texts(void)
Definition helpdata.c:768
const char * improvement_rule_name(const struct impr_type *pimprove)
Impr_type_id improvement_index(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define B_LAST
Definition improvement.h:42
const char * name
Definition inputfile.c:127
#define fc_assert_msg(condition, message,...)
Definition log.h:182
#define fc_assert_ret(condition)
Definition log.h:192
#define log_verbose(message,...)
Definition log.h:110
#define fc_assert(condition)
Definition log.h:177
#define fc_assert_ret_val(condition, val)
Definition log.h:195
#define log_fatal(message,...)
Definition log.h:101
#define fc_assert_action(condition, action)
Definition log.h:188
#define log_debug(message,...)
Definition log.h:116
#define log_normal(message,...)
Definition log.h:108
#define log_base(level, message,...)
Definition log.h:95
log_level
Definition log.h:29
@ LOG_ERROR
Definition log.h:31
@ LOG_DEBUG
Definition log.h:35
@ LOG_NORMAL
Definition log.h:33
@ LOG_FATAL
Definition log.h:30
@ LOG_VERBOSE
Definition log.h:34
#define log_error(message,...)
Definition log.h:104
#define fc_assert_ret_val_msg(condition, val, message,...)
Definition log.h:209
struct startpos * map_startpos_get(const struct tile *ptile)
Definition map.c:2047
enum direction8 dir_ccw(enum direction8 dir)
Definition map.c:1353
bool is_valid_dir(enum direction8 dir)
Definition map.c:1410
enum direction8 dir_cw(enum direction8 dir)
Definition map.c:1324
struct tile * mapstep(const struct civ_map *nmap, const struct tile *ptile, enum direction8 dir)
Definition map.c:384
static int img_index(const int x, const int y, const struct img *pimg)
Definition mapimg.c:1999
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 view mapview
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)
void update_map_canvas(int canvas_x, int canvas_y, int width, int height)
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)
const char * modpack_tileset_target(const char *name)
Definition modpack.c:329
void modpack_tileset_cache_iterate(mrc_cb cb, void *data)
Definition modpack.c:360
bool is_native_tile(const struct unit_type *punittype, const struct tile *ptile)
Definition movement.c:362
#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:6640
const char * option_str_get(const struct option *poption)
Definition options.c:904
int option_get_cb_data(const struct option *poption)
Definition options.c:798
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:542
#define players_iterate(_pplayer)
Definition player.h:537
#define player_slots_iterate(_pslot)
Definition player.h:528
#define player_slots_iterate_end
Definition player.h:532
#define fc_randomly(_seed, _size)
Definition rand.h:73
struct section_file * secfile_load(const char *filename, bool allow_duplicates)
Definition registry.c:51
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:489
struct setting_list * level[OLEVELS_NUM]
Definition settings.c:190
const char * fileinfoname(const struct strvec *dirs, const char *filename)
Definition shared.c:1094
const struct strvec * get_data_dirs(void)
Definition shared.c:886
#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
int main(int argc, char *argv[])
static bool wall(char *str, bool check)
Definition stdinhand.c:1925
void strvec_append(struct strvec *psv, const char *string)
struct strvec * strvec_new(void)
struct sprite ** sprites
Definition tilespec.c:172
int time
Definition tilespec.c:170
bool show_always
Definition tilespec.c:173
int time_per_frame
Definition tilespec.c:171
int frames
Definition tilespec.c:169
struct sprite * sprite[MAX_NUM_CITIZEN_SPRITES]
Definition tilespec.c:233
struct citizen_graphic citizen[CITIZEN_LAST]
Definition tilespec.c:237
struct citizen_graphic specialist[SP_MAX]
Definition tilespec.c:238
struct city_sprite::@233 * styles
struct city_style_threshold * land_thresholds
Definition tilespec.c:218
int land_num_thresholds
Definition tilespec.c:217
int num_styles
Definition tilespec.c:220
struct sprite * sprite
Definition tilespec.c:212
Definition city.h:317
citizens size
Definition city.h:329
struct sprite_vector occupancy
Definition tilespec.h:337
struct civ_game::@32::@35 client
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
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:401
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:388
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:341
char gui_gtk3_22_default_theme_name[512]
Definition options.h:301
bool solid_color_behind_units
Definition options.h:149
struct client_properties::@203 views
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:190
enum match_style match_style
Definition tilespec.c:189
enum sprite_type sprite_type
Definition tilespec.c:193
struct sprite_vector allocated
Definition tilespec.c:201
struct sprite * match[MAX_INDEX_CARDINAL]
Definition tilespec.c:196
struct sprite_vector base
Definition tilespec.c:195
struct sprite ** cells
Definition tilespec.c:197
bool is_reversed
Definition tilespec.c:204
struct sprite * blend[4]
Definition tilespec.c:208
struct drawing_data::drawing_layer layer[MAX_NUM_LAYERS]
struct sprite * blender
Definition tilespec.c:207
char * name
Definition tilespec.c:179
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 anim * dir[8]
Definition tilespec.c:384
struct sprite * graphic
Definition tilespec.c:414
struct named_sprites::@234 mask
struct sprite * tax_gold
Definition tilespec.c:257
struct sprite * government[G_LAST]
Definition tilespec.c:269
struct anim * total[MAX_INDEX_VALID]
Definition tilespec.c:392
struct sprite_vector nation_shield
Definition tilespec.c:277
struct citizen_set default_citizens
Definition tilespec.c:279
struct named_sprites::@235 units
struct sprite * loaded
Definition tilespec.c:311
struct sprite * output[O_LAST][MAX_NUM_UPKEEP_SPRITES]
Definition tilespec.c:323
struct sprite ** stack
Definition tilespec.c:310
struct anim * foreground
Definition tilespec.c:372
struct sprite * infratile
Definition tilespec.c:355
struct anim * corner[8]
Definition tilespec.c:381
struct sprite * background
Definition tilespec.c:419
struct sprite * frame[NUM_CURSOR_FRAMES]
Definition tilespec.c:285
struct named_sprites::@236 cursor[CURSOR_LAST]
struct sprite * patrol
Definition tilespec.c:314
struct sprite * spaceship[SPACESHIP_COUNT]
Definition tilespec.c:282
struct sprite * rmact
Definition tilespec.c:366
struct sprite * selected[EDGE_COUNT]
Definition tilespec.c:405
int num_stack_sprites
Definition tilespec.c:292
struct anim * facing[U_LAST][DIR8_MAGIC_MAX][ACTIVITY_LAST]
Definition tilespec.c:273
struct sprite * transform
Definition tilespec.c:312
struct sprite * tile_shieldnum[NUM_TILES_DIGITS]
Definition tilespec.c:332
struct sprite ** fullfog
Definition tilespec.c:360
struct sprite_vector unworked_tile_overlay
Definition tilespec.c:340
enum extrastyle_id extrastyle
Definition tilespec.c:367
struct sprite * tile_foodnum[NUM_TILES_DIGITS]
Definition tilespec.c:331
struct sprite * turns[NUM_TILES_DIGITS]
Definition tilespec.c:347
struct sprite_vector nation_flag
Definition tilespec.c:276
struct named_sprites::@237 explode
struct named_sprites::@248 player[MAX_NUM_PLAYER_SLOTS]
struct named_sprites::@243 tx
struct sprite * nonnative
Definition tilespec.c:404
struct sprite * plant
Definition tilespec.c:307
bool no_more_stack_sprites
Definition tilespec.c:293
struct named_sprites::@241::@249 s[GTS_COUNT]
struct city_sprite * single_wall
Definition tilespec.c:336
struct sprite * indicator[INDICATOR_COUNT][NUM_TILES_PROGRESS]
Definition tilespec.c:247
struct sprite * borders[EDGE_COUNT][2]
Definition tilespec.c:407
struct sprite * size_tens[NUM_TILES_DIGITS]
Definition tilespec.c:329
struct city_sprite * tile
Definition tilespec.c:334
union named_sprites::@244::@250 u
struct sprite * disorder
Definition tilespec.c:326
struct sprite * tile_tradenum[NUM_TILES_DIGITS]
Definition tilespec.c:333
struct sprite * unworked_tile
Definition tilespec.c:264
struct sprite * waypoint
Definition tilespec.c:351
struct sprite * pillage
Definition tilespec.c:308
struct sprite * fortified
Definition tilespec.c:303
struct sprite * dither_tile
Definition tilespec.c:258
struct sprite * coastline[EDGE_COUNT]
Definition tilespec.c:406
union named_sprites::@244::@250::@252::@253 ru
struct sprite * tired
Definition tilespec.c:318
struct style_citizen_set style_citizen_sets
Definition tilespec.c:280
struct named_sprites::@246 colors
struct sprite * treaty_thumb[2]
Definition tilespec.c:249
struct sprite * sentry
Definition tilespec.c:309
struct named_sprites::@239 upkeep
struct sprite * tax_luxury
Definition tilespec.c:257
struct sprite_vector unit
Definition tilespec.c:288
struct sprite * building[B_LAST]
Definition tilespec.c:268
struct sprite * turns_hundreds[NUM_TILES_DIGITS]
Definition tilespec.c:349
struct anim * isolated
Definition tilespec.c:378
struct sprite * unhappy[MAX_NUM_UPKEEP_SPRITES]
Definition tilespec.c:321
struct sprite_vector worked_tile_overlay
Definition tilespec.c:339
struct sprite * darkness[MAX_INDEX_CARDINAL]
Definition tilespec.c:361
struct named_sprites::@240 city
struct sprite * tax_science
Definition tilespec.c:257
struct named_sprites::@242 user
struct named_sprites::@245 grid
struct anim * select
Definition tilespec.c:294
struct sprite * specific
Definition tilespec.c:346
struct sprite * color
Definition tilespec.c:413
struct sprite * unavailable
Definition tilespec.c:403
struct sprite * worked_tile
Definition tilespec.c:263
struct river_sprites rivers
Definition tilespec.c:393
struct drawing_data * drawing[MAX_NUM_ITEMS]
Definition tilespec.c:422
struct sprite * go_to
Definition tilespec.c:305
struct citybar_sprites citybar
Definition tilespec.c:342
struct sprite * auto_explore
Definition tilespec.c:302
struct sprite * turns_tens[NUM_TILES_DIGITS]
Definition tilespec.c:348
struct sprite * tech[A_LAST]
Definition tilespec.c:267
struct sprite * nuke
Definition tilespec.c:289
struct named_sprites::@244::@250::@252::@253::@254 combo
struct anim * action_decision_want
Definition tilespec.c:296
struct sprite * convert
Definition tilespec.c:315
struct sprite * worked[EDGE_COUNT]
Definition tilespec.c:402
struct sprite_vector overlays
Definition tilespec.c:410
struct editor_sprites editor
Definition tilespec.c:343
struct named_sprites::@244::@250::@252 road
struct sprite * size_hundreds[NUM_TILES_DIGITS]
Definition tilespec.c:330
struct sprite * activity
Definition tilespec.c:364
struct anim * single
Definition tilespec.c:369
struct anim * odd[MAX_INDEX_HALF]
Definition tilespec.c:389
struct sprite * size[NUM_TILES_DIGITS]
Definition tilespec.c:328
struct sprite * fortifying
Definition tilespec.c:304
struct sprite * main[EDGE_COUNT]
Definition tilespec.c:399
struct sprite * events[E_COUNT]
Definition tilespec.c:254
struct sprite * auto_attack
Definition tilespec.c:300
struct sprite * icon[ICON_COUNT]
Definition tilespec.c:252
struct anim * even[MAX_INDEX_HALF]
Definition tilespec.c:387
struct city_sprite * wall[NUM_WALL_TYPES]
Definition tilespec.c:337
struct anim * middleground
Definition tilespec.c:374
struct anim * background
Definition tilespec.c:375
struct named_sprites::@241 path
struct sprite * connect
Definition tilespec.c:313
struct sprite * fog
Definition tilespec.c:358
struct named_sprites::@244::@250::@251 bmf
struct sprite * arrow[ARROW_LAST]
Definition tilespec.c:250
struct named_sprites::@244 extras[MAX_EXTRA_TYPES]
struct sprite * grid_borders[EDGE_COUNT][2]
Definition tilespec.c:417
struct anim * cardinals[MAX_INDEX_CARDINAL]
Definition tilespec.c:370
struct sprite * attention
Definition tilespec.c:354
struct city_sprite * occupied
Definition tilespec.c:338
struct sprite * tile
Definition tilespec.c:261
struct sprite * cultivate
Definition tilespec.c:306
struct sprite * auto_worker
Definition tilespec.c:301
struct sprite * lowfuel
Definition tilespec.c:317
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 anim * outlet[MAX_INDEX_CARDINAL]
Definition tilespec.c:226
struct anim * spec[MAX_INDEX_CARDINAL]
Definition tilespec.c:224
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:40
struct citizen_set * sets
Definition tilespec.c:242
char graphic_alt2[MAX_LEN_NAME]
Definition terrain.h:82
char graphic_alt[MAX_LEN_NAME]
Definition terrain.h:81
char graphic_str[MAX_LEN_NAME]
Definition terrain.h:80
Definition tile.h:50
char * spec_sprite
Definition tile.h:67
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:503
int num_cardinal_tileset_dirs
Definition tilespec.c:557
int occupied_offset_x
Definition tilespec.c:550
int stack_size_offset_y
Definition tilespec.c:549
struct named_sprites sprites
Definition tilespec.c:579
int ts_topo_idx
Definition tilespec.c:517
int hex_height
Definition tilespec.c:516
enum fog_style fogstyle
Definition tilespec.c:533
int normal_tile_height
Definition tilespec.c:519
int unit_tile_width
Definition tilespec.c:521
int city_offset_y
Definition tilespec.c:539
char * main_intro_filename
Definition tilespec.c:529
enum ts_type type
Definition tilespec.c:515
int city_size_offset_x
Definition tilespec.c:540
int num_preferred_themes
Definition tilespec.c:587
char version[MAX_LEN_NAME]
Definition tilespec.c:504
int default_time_per_frame
Definition tilespec.c:527
int full_tile_height
Definition tilespec.c:520
int small_sprite_width
Definition tilespec.c:522
char ** preferred_themes
Definition tilespec.c:588
struct extra_type_list * flagged_bases_list
Definition tilespec.c:585
enum darkness_style darkness_style
Definition tilespec.c:534
int activity_offset_x
Definition tilespec.c:544
int citybar_offset_y
Definition tilespec.c:542
int normal_tile_width
Definition tilespec.c:519
float scale
Definition tilespec.c:509
int svg_height
Definition tilespec.c:525
int unit_tile_height
Definition tilespec.c:521
int hex_width
Definition tilespec.c:516
int select_offset_y
Definition tilespec.c:547
int city_flag_offset_x
Definition tilespec.c:537
int unit_flag_offset_x
Definition tilespec.c:536
int occupied_offset_y
Definition tilespec.c:551
char * description
Definition tilespec.c:508
int max_upkeep_height
Definition tilespec.c:524
int unit_flag_offset_y
Definition tilespec.c:536
int unit_upkeep_offset_y
Definition tilespec.c:552
struct estyle_hash * estyle_hash
Definition tilespec.c:575
char * for_ruleset
Definition tilespec.c:511
int activity_offset_y
Definition tilespec.c:545
int num_index_valid
Definition tilespec.c:558
int select_offset_x
Definition tilespec.c:546
int num_index_cardinal
Definition tilespec.c:558
int full_tile_width
Definition tilespec.c:520
struct small_sprite_list * small_sprites
Definition tilespec.c:567
struct extra_type_list * style_lists[ESTYLE_COUNT]
Definition tilespec.c:583
enum direction8 unit_default_orientation
Definition tilespec.c:531
struct tileset::tileset_layer layers[MAX_NUM_LAYERS]
int small_sprite_height
Definition tilespec.c:522
int city_size_offset_y
Definition tilespec.c:540
struct sprite_hash * sprite_hash
Definition tilespec.c:570
int unit_upkeep_small_offset_y
Definition tilespec.c:553
int unit_offset_x
Definition tilespec.c:538
int unit_offset_y
Definition tilespec.c:538
enum mapview_layer layer_order[LAYER_COUNT]
Definition tilespec.c:513
int city_offset_x
Definition tilespec.c:539
struct anim_hash * anim_hash
Definition tilespec.c:577
int priority
Definition tilespec.c:505
enum direction8 cardinal_tileset_dirs[8]
Definition tilespec.c:559
enum direction8 valid_tileset_dirs[8]
Definition tilespec.c:559
struct color_system * color_system
Definition tilespec.c:581
char * summary
Definition tilespec.c:507
char name[512]
Definition tilespec.c:502
int city_flag_offset_y
Definition tilespec.c:537
struct drawing_hash * tile_hash
Definition tilespec.c:573
int num_valid_tileset_dirs
Definition tilespec.c:557
int stack_size_offset_x
Definition tilespec.c:548
struct specfile_list * specfiles
Definition tilespec.c:566
int tilelabel_offset_y
Definition tilespec.c:543
struct strvec * list
Definition tilespec.c:1126
Definition unit.h:139
bool occupied
Definition unit.h:221
int battlegroup
Definition unit.h:193
enum unit_activity activity
Definition unit.h:158
int moves_left
Definition unit.h:151
struct unit::@83 orders
int hp
Definition unit.h:152
int fuel
Definition unit.h:154
bool colored
Definition unit.h:224
enum direction8 facing
Definition unit.h:143
struct tile * tile
Definition unit.h:141
struct unit::@84::@86 client
struct extra_type * activity_target
Definition unit.h:166
bool repeat
Definition unit.h:198
int color_index
Definition unit.h:225
int veteran
Definition unit.h:153
enum server_side_agent ssa_controller
Definition unit.h:174
int store_width
int store_height
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:960
size_t fc_strlcpy(char *dest, const char *src, size_t n)
Definition support.c:777
int fc_strcasecmp(const char *str0, const char *str1)
Definition support.c:186
int cat_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:986
int fc_vsnprintf(char *str, size_t n, const char *format, va_list ap)
Definition support.c:886
#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
void get_flag_dimensions(struct sprite *flag, struct area_rect *rect, int svg_height)
Definition svgflag.c:123
#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:309
Tech_type_id advance_index(const struct advance *padvance)
Definition tech.c:89
static Tech_type_id advance_count(void)
Definition tech.h:165
#define advance_iterate(_p)
Definition tech.h:271
#define advance_iterate_end
Definition tech.h:272
#define A_LAST
Definition tech.h:45
Terrain_type_id terrain_index(const struct terrain *pterrain)
Definition terrain.c:137
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:246
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
Definition terrain.c:581
#define terrain_type_iterate(_p)
Definition terrain.h:267
#define T_UNKNOWN
Definition terrain.h:62
#define is_ocean_tile(ptile)
Definition terrain.h:197
#define terrain_type_iterate_end
Definition terrain.h:273
#define tile_index(_pt_)
Definition tile.h:89
#define tile_worked(_tile)
Definition tile.h:119
@ 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:115
#define TILE_XY(ptile)
Definition tile.h:43
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:125
#define tile_has_extra(ptile, pextra)
Definition tile.h:152
#define tile_owner(_tile)
Definition tile.h:97
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:4755
void advance_global_anim_state(void)
Definition tilespec.c:6788
struct sprite * get_government_sprite(const struct tileset *t, const struct government *gov)
Definition tilespec.c:7050
void tileset_load_tiles(struct tileset *t)
Definition tilespec.c:3832
struct sprite * get_nuke_explode_sprite(const struct tileset *t)
Definition tilespec.c:7194
#define sprite_hash_iterate(hash, tag_name, sprite)
Definition tilespec.c:472
int tileset_hex_width(const struct tileset *t)
Definition tilespec.c:747
struct sprite * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
Definition tilespec.c:7040
#define SET_SPRITE_DEPR_ALT(field, tag, alt, ver)
Definition tilespec.c:2968
int tileset_unit_width(const struct tileset *t)
Definition tilespec.c:823
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:5892
struct unit * get_drawable_unit(const struct tileset *t, struct tile *ptile, const struct city *citymode)
Definition tilespec.c:6799
static int check_sprite_type(const char *sprite_type, const char *tile_section)
Definition tilespec.c:1914
struct sprite * get_attention_crosshair_sprite(const struct tileset *t)
Definition tilespec.c:7255
int tileset_unit_height(const struct tileset *t)
Definition tilespec.c:831
static struct tileset * tileset_new(void)
Definition tilespec.c:997
#define MAX_INDEX_VALID
Definition tilespec.c:112
void tileset_setup_unit_type(struct tileset *t, struct unit_type *ut)
Definition tilespec.c:4006
static void free_all_anims(struct tileset *t)
Definition tilespec.c:6839
static bool check_tilespec_capabilities(struct section_file *file, const char *which, const char *us_capstr, const char *filename, bool verbose)
Definition tilespec.c:1205
int tileset_small_sprite_width(const struct tileset *t)
Definition tilespec.c:927
static struct sprite * load_gfx_file(const char *gfx_filename, bool svgflag)
Definition tilespec.c:1607
#define specfile_list_iterate_end
Definition tilespec.c:436
static struct sprite * create_plr_sprite(struct color *pcolor)
Definition tilespec.c:2878
int tileset_svg_flag_height(struct tileset *t)
Definition tilespec.c:7836
#define SPEC_CAPSTR
Definition tilespec.c:98
static struct sprite * get_unit_nation_flag_sprite(const struct tileset *t, const struct unit *punit)
Definition tilespec.c:4674
direction4
Definition tilespec.c:139
@ DIR4_EAST
Definition tilespec.c:140
@ DIR4_NORTH
Definition tilespec.c:140
@ DIR4_SOUTH
Definition tilespec.c:140
@ DIR4_WEST
Definition tilespec.c:140
struct tileset * get_tileset(void)
Definition tilespec.c:718
#define MAX_NUM_MATCH_WITH
Definition tilespec.c:188
static struct sprite * get_city_sprite(const struct city_sprite *city_sprite, const struct city *pcity)
Definition tilespec.c:3239
void tileset_setup_government(struct tileset *t, struct government *gov)
Definition tilespec.c:4615
#define sprite_hash_iterate_end
Definition tilespec.c:475
struct sprite * get_city_flag_sprite(const struct tileset *t, const struct city *pcity)
Definition tilespec.c:4665
void tileset_setup_specialist_type_default_set(struct tileset *t, Specialist_type_id id)
Definition tilespec.c:3095
static bool is_valid_tileset_dir(const struct tileset *t, enum direction8 dir)
Definition tilespec.c:1056
struct sprite * get_basic_fog_sprite(const struct tileset *t)
Definition tilespec.c:7318
static enum direction8 dir_by_tileset_name(const char *str)
Definition tilespec.c:1038
#define ADD_SPRITE_SIMPLE(s)
Definition tilespec.c:4700
static int fill_basic_road_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7500
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:4774
int tileset_full_tile_height(const struct tileset *t)
Definition tilespec.c:815
bool tilespec_try_read(const char *tileset_name, bool verbose, int topo_id, bool global_default)
Definition tilespec.c:1360
static bool tileset_setup_unit_type_from_tag(struct tileset *t, int uidx, const char *tag)
Definition tilespec.c:3951
struct tileset * unscaled_tileset
Definition tilespec.c:592
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:5247
int fill_basic_extra_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7465
#define specfile_list_iterate(list, pitem)
Definition tilespec.c:434
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:7300
const char * tileset_main_intro_filename(const struct tileset *t)
Definition tilespec.c:973
void tileset_setup_tile_type(struct tileset *t, const struct terrain *pterrain)
Definition tilespec.c:4349
static const char direction4letters[4]
Definition tilespec.c:142
void tileset_player_init(struct tileset *t, struct player *pplayer)
Definition tilespec.c:7637
const struct strvec * get_tileset_list(const struct option *poption)
Definition tilespec.c:1150
int tileset_unit_layout_offset_y(const struct tileset *t)
Definition tilespec.c:908
int tileset_citybar_offset_y(const struct tileset *t)
Definition tilespec.c:936
#define MAX_NUM_UPKEEP_SPRITES
Definition tilespec.c:116
static void anim_free(struct anim *a)
Definition tilespec.c:2793
struct sprite * get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
Definition tilespec.c:7174
bool unit_drawn_with_city_outline(const struct unit *punit, bool check_focus)
Definition tilespec.c:5725
#define MAX_INDEX_HALF
Definition tilespec.c:111
double get_focus_unit_toggle_timeout(const struct tileset *t)
Definition tilespec.c:6742
#define SET_SPRITE_ALT_OPT(field, tag, alt)
Definition tilespec.c:2989
static int calculate_max_upkeep_height(const struct tileset *t)
Definition tilespec.c:839
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:5409
#define TILE_SECTION_PREFIX
Definition tilespec.c:107
static struct city_sprite * load_city_sprite(struct tileset *t, const char *tag)
Definition tilespec.c:3316
static char * valid_index_str(const struct tileset *t, int idx)
Definition tilespec.c:2752
void tileset_free_tiles(struct tileset *t)
Definition tilespec.c:6852
#define ADD_ANIM_FULL(s)
Definition tilespec.c:4708
void tileset_setup_impr_type(struct tileset *t, struct impr_type *pimprove)
Definition tilespec.c:4040
static struct tileset * tileset_read_toplevel(const char *tileset_name, bool verbose, int topology_id, float scale)
Definition tilespec.c:1935
static bool sprite_exists(const struct tileset *t, const char *tag_name)
Definition tilespec.c:2918
const struct sprite_vector * get_unit_explode_animation(const struct tileset *t)
Definition tilespec.c:7183
#define TILESPEC_CAPSTR
Definition tilespec.c:82
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:3275
struct sprite * load_popup_sprite(const char *tag)
Definition tilespec.c:7844
static void unload_all_sprites(struct tileset *t)
Definition tilespec.c:6825
static const char * dir_get_tileset_name(enum direction8 dir)
Definition tilespec.c:1011
#define SET_SPRITE_UNSCALED(field, tag)
Definition tilespec.c:2944
void tileset_background_init(struct tileset *t)
Definition tilespec.c:7717
void tileset_setup_tech_type(struct tileset *t, struct advance *padvance)
Definition tilespec.c:4056
static const int DIR4_TO_DIR8[4]
Definition tilespec.c:146
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:5680
static void unload_sprite(struct tileset *t, const char *tag_name)
Definition tilespec.c:2894
static void drawing_data_destroy(struct drawing_data *draw)
Definition tilespec.c:686
static int fill_terrain_sprite_darkness(struct tileset *t, struct drawn_sprite *sprs, const struct tile *ptile, struct terrain **tterrain_near)
Definition tilespec.c:5616
#define small_sprite_list_iterate_end
Definition tilespec.c:465
static struct drawing_data * drawing_data_new(void)
Definition tilespec.c:674
static void build_tile_data(const struct tile *ptile, struct terrain *pterrain, struct terrain **tterrain_near, bv_extras *textras_near)
Definition tilespec.c:4723
static void tileset_player_free(struct tileset *t, int plrid)
Definition tilespec.c:7688
float tileset_scale(const struct tileset *t)
Definition tilespec.c:953
#define UNKNOWN(dir)
int tileset_unit_with_small_upkeep_height(const struct tileset *t)
Definition tilespec.c:897
bool tileset_layer_in_category(enum mapview_layer layer, enum layer_category cat)
Definition tilespec.c:7594
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:5742
match_style
Definition tilespec.c:149
@ MATCH_SAME
Definition tilespec.c:151
@ MATCH_FULL
Definition tilespec.c:153
@ MATCH_PAIR
Definition tilespec.c:152
@ MATCH_NONE
Definition tilespec.c:150
#define small_sprite_list_iterate(list, pitem)
Definition tilespec.c:463
static void ts_cb(const char *modpack_name, const char *filename, void *data)
Definition tilespec.c:1332
int tileset_num_city_colors(const struct tileset *t)
Definition tilespec.c:981
int index_ts_topology(int idx)
Definition tilespec.c:1111
#define NUM_TILES_HP_BAR
Definition tilespec.c:114
#define anim_hash_iterate(hash, tag_name, sprite)
Definition tilespec.c:482
#define TILESPEC_SUFFIX
Definition tilespec.c:106
bool tileset_is_isometric(const struct tileset *t)
Definition tilespec.c:738
bool tileset_use_hard_coded_fog(const struct tileset *t)
Definition tilespec.c:989
void tileset_use_preferred_theme(const struct tileset *t)
Definition tilespec.c:7334
#define FULL_TILE_X_OFFSET
Definition tilespec.c:4686
sprite_type
Definition tilespec.c:156
@ CELL_CORNER
Definition tilespec.c:158
@ CELL_WHOLE
Definition tilespec.c:157
static int global_anim_time
Definition tilespec.c:598
void tileset_setup_city_tiles(struct tileset *t, int style)
Definition tilespec.c:6677
struct sprite * get_nation_shield_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:7022
const char * tileset_description(struct tileset *t)
Definition tilespec.c:7812
#define SET_GOTO_TURN_SPRITE(state, state_name, factor, factor_name)
#define SET_ANIM_OPT(field, tag)
Definition tilespec.c:3006
void tileset_background_free(struct tileset *t)
Definition tilespec.c:7736
#define MAX_NUM_LAYERS
Definition tilespec.c:182
int tileset_unit_layout_small_offset_y(const struct tileset *t)
Definition tilespec.c:917
struct sprite * get_event_sprite(const struct tileset *t, enum event_type event)
Definition tilespec.c:7165
void toggle_focus_unit_state(struct tileset *t)
Definition tilespec.c:6776
#define ADD_FRAME0_IF_NOT_NULL(x)
void tilespec_reread_frozen_refresh(const char *tname)
Definition tilespec.c:1595
int tileset_small_sprite_height(const struct tileset *t)
Definition tilespec.c:963
void tileset_free(struct tileset *t)
Definition tilespec.c:1315
static const char * cardinal_index_str(const struct tileset *t, int idx)
Definition tilespec.c:2732
#define NUM_TILES_DIGITS
Definition tilespec.c:115
void focus_unit_in_combat(struct tileset *t)
Definition tilespec.c:6767
static int tileset_upkeep_height(const struct tileset *t)
Definition tilespec.c:876
const char * tileset_summary(struct tileset *t)
Definition tilespec.c:7804
struct sprite * get_icon_sprite(const struct tileset *t, enum icon_type icon)
Definition tilespec.c:7244
static void ensure_big_sprite(struct specfile *sf, const char *tset_name)
Definition tilespec.c:1643
#define ADD_ANIM_SPRITE(s, draw_fog, x_offset, y_offset)
Definition tilespec.c:4704
static bool tileset_update
Definition tilespec.c:596
#define FULL_TILE_Y_OFFSET
Definition tilespec.c:4687
struct sprite * get_indicator_sprite(const struct tileset *t, enum indicator_type indicator, int idx)
Definition tilespec.c:7264
struct sprite * get_sample_city_sprite(const struct tileset *t, int style_idx)
Definition tilespec.c:7116
#define ADD_SPRITE_FULL(s)
Definition tilespec.c:4701
void tileset_setup_extra(struct tileset *t, struct extra_type *pextra)
Definition tilespec.c:4075
static void anim_advance_time(struct anim *a)
Definition tilespec.c:3064
void tileset_init(struct tileset *t)
Definition tilespec.c:7391
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:5289
static char * tilespec_gfx_filename(const char *gfx_filename, const char *tset_name)
Definition tilespec.c:1849
const char * tileset_basename(const struct tileset *t)
Definition tilespec.c:730
int fill_basic_terrain_layer_sprite_array(struct tileset *t, struct drawn_sprite *sprs, int layer, struct terrain *pterrain)
Definition tilespec.c:7432
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:791
#define LOAD_FACING_SPRITE(dir)
#define SET_SPRITE_NOTSMOOTH(field, tag)
Definition tilespec.c:2935
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:4964
static bool is_extra_drawing_enabled(struct extra_type *pextra)
Definition tilespec.c:5960
struct sprite * get_spaceship_sprite(const struct tileset *t, enum spaceship_part part)
Definition tilespec.c:6948
int tileset_unit_with_upkeep_height(const struct tileset *t)
Definition tilespec.c:885
static void tileset_free_toplevel(struct tileset *t)
Definition tilespec.c:1243
static struct sprite * load_sprite(struct tileset *t, const char *tag_name, bool scale, bool smooth, bool svgflag)
Definition tilespec.c:2808
struct sprite * get_cursor_sprite(const struct tileset *t, enum cursor_type cursor, int *hot_x, int *hot_y, int frame)
Definition tilespec.c:7225
static const char edge_name[EDGE_COUNT][3]
Definition tilespec.c:144
struct color_system * get_color_system(const struct tileset *t)
Definition tilespec.c:7326
int tileset_hex_height(const struct tileset *t)
Definition tilespec.c:756
void reset_focus_unit_state(struct tileset *t)
Definition tilespec.c:6755
static const char * citizen_rule_name(enum citizen_category citizen)
Definition tilespec.c:2707
static void tileset_setup_citizen_types_default_set(struct tileset *t)
Definition tilespec.c:3189
bool tileset_is_fully_loaded(void)
Definition tilespec.c:7780
static struct sprite * anim_get_current_frame(struct anim *a)
Definition tilespec.c:3075
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:5369
#define ADD_ANIM_SPRITE_SIMPLE(s)
Definition tilespec.c:4706
const struct citybar_sprites * get_citybar_sprites(const struct tileset *t)
Definition tilespec.c:7202
static bool is_cardinal_tileset_dir(const struct tileset *t, enum direction8 dir)
Definition tilespec.c:1074
void unload_popup_sprite(const char *tag)
Definition tilespec.c:7852
#define SET_SPRITE(field, tag)
Definition tilespec.c:2925
static void tileset_lookup_sprite_tags(struct tileset *t)
Definition tilespec.c:3364
struct sprite * get_arrow_sprite(const struct tileset *t, enum arrow_type arrow)
Definition tilespec.c:7133
struct sprite * get_unit_unhappy_sprite(const struct tileset *t, const struct unit *punit, int happy_cost)
Definition tilespec.c:7281
#define NUM_CORNER_DIRS
Definition tilespec.c:555
static int fill_basic_base_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7548
static void tileset_setup_base(struct tileset *t, const struct extra_type *pextra, const char *tag)
Definition tilespec.c:4314
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:5015
void finish_loading_sprites(struct tileset *t)
Definition tilespec.c:3816
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:1880
#define anim_hash_iterate_end
Definition tilespec.c:485
static struct anim * anim_new(int frames, int time_per_frame)
Definition tilespec.c:2775
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:3843
#define SET_EDITOR_SPRITE(x)
#define SET_SPRITE_ALT(field, tag, alt)
Definition tilespec.c:2954
#define SET_SPRITE_OPT(field, tag)
Definition tilespec.c:2986
void tilespec_reread_callback(struct option *poption)
Definition tilespec.c:1559
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:3105
static bool load_river_sprites(struct tileset *t, struct river_sprites *store, const char *tag_pfx)
Definition tilespec.c:3782
const char * tileset_name_get(struct tileset *t)
Definition tilespec.c:7788
static char * tilespec_fullname(const char *tileset_name)
Definition tilespec.c:1181
static const struct citizen_graphic * get_citizen_graphic(const struct citizen_set *set, enum citizen_category type)
Definition tilespec.c:6958
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:6027
#define ADD_SPRITE(s, draw_fog, x_offset, y_offset)
Definition tilespec.c:4698
int tileset_full_tile_width(const struct tileset *t)
Definition tilespec.c:802
static struct anim * anim_load(struct tileset *t, const char *tag, int time_per_frame)
Definition tilespec.c:3017
struct sprite * get_tax_sprite(const struct tileset *t, Output_type_id otype)
Definition tilespec.c:7144
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:3889
struct sprite * get_citizen_sprite(const struct tileset *t, enum citizen_category type, int citizen_index, const struct city *pcity)
Definition tilespec.c:6979
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:5463
const char * tileset_version(struct tileset *t)
Definition tilespec.c:7796
static bool focus_unit_state
Definition tilespec.c:594
static void free_city_sprite(struct city_sprite *city_sprite)
Definition tilespec.c:3344
static int ts_topology_index(int actual_topology)
Definition tilespec.c:1089
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:7062
char * tileset_what_ruleset(struct tileset *t)
Definition tilespec.c:7820
static void ts_list_cb(const char *modpack_name, const char *filename, void *data)
Definition tilespec.c:1133
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:7013
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:779
int tileset_tilelabel_offset_y(const struct tileset *t)
Definition tilespec.c:945
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:3198
static void tileset_setup_road(struct tileset *t, struct extra_type *pextra, const char *tag)
Definition tilespec.c:4205
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:7031
#define MATCH(dir)
static int get_irrigation_index(const struct tileset *t, struct extra_type *pextra, bv_extras *textras_near)
Definition tilespec.c:5227
#define ADD_FRAME0_SIMPLE(s)
Definition tilespec.c:4712
#define MAX_INDEX_CARDINAL
Definition tilespec.c:110
#define ADD_SPRITE_SIZE(s, draw_fog, x_offset, y_offset, w_in, h_in)
Definition tilespec.c:4689
void tileset_error(enum log_level level, const char *tset_name, const char *format,...)
Definition tilespec.c:650
const struct editor_sprites * get_editor_sprites(const struct tileset *t)
Definition tilespec.c:7214
int tileset_topo_index(struct tileset *t)
Definition tilespec.c:7828
bool tilespec_reread(const char *new_tileset_name, bool game_fully_initialized, float scale)
Definition tilespec.c:1405
spec_file_types
Definition tilespec.c:161
@ SFILE_COMMON
Definition tilespec.c:162
@ SFILE_PIXEL
Definition tilespec.c:164
@ SFILE_LAST
Definition tilespec.c:165
@ SFILE_SVG
Definition tilespec.c:163
void tileset_setup_nation_flag(struct tileset *t, struct nation_type *nation)
Definition tilespec.c:4630
void tileset_ruleset_reset(struct tileset *t)
Definition tilespec.c:7752
#define SET_ANIM(field, tag)
Definition tilespec.c:2996
static void scan_specfile(struct tileset *t, struct specfile *sf, bool duplicates_ok)
Definition tilespec.c:1684
enum mapview_layer tileset_get_layer(const struct tileset *t, int n)
Definition tilespec.c:7584
#define NUM_EDGE_TILES
Definition tilespec.h:99
#define NUM_CURSOR_FRAMES
Definition tilespec.h:304
indicator_type
Definition tilespec.h:306
@ INDICATOR_COUNT
Definition tilespec.h:310
arrow_type
Definition tilespec.h:200
@ ARROW_LAST
Definition tilespec.h:204
@ ARROW_MINUS
Definition tilespec.h:203
@ ARROW_RIGHT
Definition tilespec.h:201
@ ARROW_PLUS
Definition tilespec.h:202
#define TS_TOPO_ISOHEX
Definition tilespec.h:456
#define TERRAIN_LAYER_COUNT
Definition tilespec.h:174
#define sprite_vector_iterate_end
Definition tilespec.h:46
#define NUM_CORNER_TILES
Definition tilespec.h:106
#define NUM_TILES_PROGRESS
Definition tilespec.h:196
#define MAX_NUM_CITIZEN_SPRITES
Definition tilespec.h:198
#define TS_TOPO_HEX
Definition tilespec.h:455
#define TS_TOPO_SQUARE
Definition tilespec.h:454
layer_category
Definition tilespec.h:190
@ LAYER_CATEGORY_TILE
Definition tilespec.h:192
@ LAYER_CATEGORY_CITY
Definition tilespec.h:191
@ LAYER_CATEGORY_UNIT
Definition tilespec.h:193
icon_type
Definition tilespec.h:313
@ ICON_COUNT
Definition tilespec.h:316
@ EDGE_UD
Definition tilespec.h:93
@ EDGE_LR
Definition tilespec.h:94
@ EDGE_COUNT
Definition tilespec.h:95
spaceship_part
Definition tilespec.h:319
@ SPACESHIP_COUNT
Definition tilespec.h:327
#define NUM_WALL_TYPES
Definition tilespec.h:360
#define sprite_vector_iterate(sprite_vec, psprite)
Definition tilespec.h:44
cursor_type
Definition tilespec.h:288
@ CURSOR_LAST
Definition tilespec.h:300
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c:2744
bool unit_transported(const struct unit *pcargo)
Definition unit.c:2528
bool is_flagless_to_player(const struct unit *punit, const struct player *pplayer)
Definition unit.c:381
bool unit_has_orders(const struct unit *punit)
Definition unit.c:220
#define unit_tile(_pu)
Definition unit.h:406
#define BATTLEGROUP_NONE
Definition unit.h:192
#define unit_owner(_pu)
Definition unit.h:405
#define activity_type_iterate(_act_)
Definition unit.h:286
#define activity_type_iterate_end
Definition unit.h:291
#define MAX_NUM_BATTLEGROUPS
Definition unit.h:191
#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:1582
Unit_type_id utype_index(const struct unit_type *punittype)
Definition unittype.c:91
#define utype_fuel(ptype)
Definition unittype.h:844
#define unit_type_iterate(_p)
Definition unittype.h:860
#define U_LAST
Definition unittype.h:40
#define unit_type_iterate_end
Definition unittype.h:867
#define worker_task_list_iterate(tasklist, ptask)
Definition workertask.h:33
#define worker_task_list_iterate_end
Definition workertask.h:35