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-tilespec-3.3-Devel-2024-Nov-16 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-spec-3.3-Devel-2023.Apr.05"
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 tileset_error(LOG_FATAL, nullptr, _("No usable default tileset found, aborting!"));
1373 }
1374
1375 log_verbose("Trying tileset \"%s\".", tileset->name);
1376 } else {
1377 original = TRUE;
1378 }
1380
1381 if (global_default) {
1383 }
1384
1385 return original;
1386}
1387
1388/************************************************************************/
1402 bool game_fully_initialized, float scale)
1403{
1404 int id;
1405 struct tile *center_tile;
1406 enum client_states state = client_state();
1408 char tileset_name[strlen(name) + 1], old_name[strlen(tileset->name) + 1];
1409 bool new_tileset_in_use;
1410 int ts_topo;
1411
1412 /* Make local copies since these values may be freed down below */
1414 sz_strlcpy(old_name, tileset->name);
1415
1416 log_normal(_("Loading tileset \"%s\"."), tileset_name);
1417
1418 /* Step 0: Record old data.
1419 *
1420 * We record the current mapcanvas center, etc.
1421 */
1423
1424 /* Step 1: Cleanup.
1425 *
1426 * Free old tileset or keep it in memory if we are loading the same
1427 * tileset with scaling and old one was not scaled.
1428 */
1429
1430 if (strcmp(tileset_name, old_name) == 0 && tileset->scale == 1.0f
1431 && scale != 1.0f) {
1432 if (unscaled_tileset) {
1434 }
1436 } else {
1438 }
1439
1440 /* Step 2: Read.
1441 *
1442 * We read in the new tileset. This should be pretty straightforward.
1443 */
1445 if (tileset != NULL) {
1447 } else {
1449
1450 if (!(tileset = tileset_read_toplevel(old_name, FALSE, -1, scale))) {
1451 log_fatal("Failed to re-read the currently loaded tileset.");
1453 }
1454 }
1458 }
1459
1463 } /* else we'll get round to it on PACKET_RULESET_GAME */
1464 players_iterate(pplayer) {
1465 tileset_player_init(tileset, pplayer);
1467 boot_help_texts(); /* "About Current Tileset" */
1468 }
1469
1470 /* Step 3: Setup
1471 *
1472 * This is a seriously sticky problem. On startup, we build a hash
1473 * from all the sprite data. Then, when we connect to a server, the
1474 * server sends us ruleset data a piece at a time and we use this data
1475 * to assemble the sprite structures. But if we change while connected
1476 * we have to reassemble all of these. This should just involve
1477 * calling tilespec_setup_*** on everything. But how do we tell what
1478 * "everything" is?
1479 *
1480 * The below code just does things straightforwardly, by setting up
1481 * each possible sprite again. Hopefully it catches everything, and
1482 * doesn't mess up too badly if we change tilesets while not connected
1483 * to a server.
1484 */
1485 if (!game.client.ruleset_ready) {
1486 /* The ruleset data is not sent until this point. */
1487 return new_tileset_in_use;
1488 }
1489
1491 == TOPO_INCOMP_HARD) {
1493 _("Map topology (%s) and tileset (%s) incompatible."),
1495 }
1496
1497 terrain_type_iterate(pterrain) {
1503 governments_iterate(gov) {
1506 extra_type_iterate(pextra) {
1509 nations_iterate(pnation) {
1512 improvement_iterate(pimprove) {
1521
1524 * sizeof(tileset->sprites.style_citizen_sets.sets[0]));
1525
1526 for (id = 0; id < game.control.num_city_styles; id++) {
1528 }
1529
1530 if (state < C_S_RUNNING) {
1531 /* Below redraws do not apply before this. */
1532 return new_tileset_in_use;
1533 }
1534
1535 /* Step 4: Draw.
1536 *
1537 * Do any necessary redraws.
1538 */
1541 can_slide = FALSE;
1543 /* update_map_canvas_visible forces a full redraw. Otherwise with fast
1544 * drawing we might not get one. Of course this is slower. */
1546 can_slide = TRUE;
1547
1548 return new_tileset_in_use;
1549}
1550
1551/************************************************************************/
1556{
1557 const char *tileset_name;
1558 enum client_states state = client_state();
1559
1560 if (state == C_S_RUNNING || state == C_S_OVER) {
1562
1563 /* Also iso map topology counts as 'square' tileset topology */
1564 if (opt != (wld.map.topology_id & (TF_ISO | TF_HEX))
1565 && (opt != 0 || ((wld.map.topology_id & TF_HEX) == TF_HEX))) {
1566 /* Changed option was not for current topology */
1567 return;
1568 }
1569 }
1570
1572
1573 fc_assert_ret(NULL != tileset_name && tileset_name[0] != '\0');
1576
1577 /* As it's going to be 'current' tileset, make it global default if
1578 * options saved. */
1580
1582 menus_init();
1583}
1584
1585/************************************************************************/
1592{
1594 tilespec_reread(tname, TRUE, 1.0f);
1596 menus_init();
1597}
1598
1599/************************************************************************/
1603static struct sprite *load_gfx_file(const char *gfx_filename, bool svgflag)
1604{
1605 const char **gfx_fileexts, *gfx_fileext;
1606 struct sprite *s;
1607
1608 if (svgflag) {
1610 } else {
1612 }
1613
1614 /* Try out all supported file extensions to find one that works. */
1615 while ((gfx_fileext = *gfx_fileexts++)) {
1616 const char *real_full_name;
1617 char full_name[strlen(gfx_filename) + strlen(".")
1618 + strlen(gfx_fileext) + 1];
1619
1622 log_debug("trying to load gfx file \"%s\".", real_full_name);
1624 svgflag && !strcmp("svg", gfx_fileext));
1625 if (s) {
1626 return s;
1627 }
1628 }
1629 }
1630
1631 log_error("Could not load gfx file \"%s\".", gfx_filename);
1632
1633 return NULL;
1634}
1635
1636/************************************************************************/
1639static void ensure_big_sprite(struct specfile *sf, const char *tset_name)
1640{
1641 struct section_file *file;
1642 const char *gfx_filename;
1643
1644 if (sf->big_sprite) {
1645 /* Looks like it's already loaded. */
1646 return;
1647 }
1648
1649 /* Otherwise load it. The big sprite will sometimes be freed and will have
1650 * to be reloaded, but most of the time it's just loaded once, the small
1651 * sprites are extracted, and then it's freed. */
1652 if (!(file = secfile_load(sf->file_name, TRUE))) {
1654 _("Could not open '%s':\n%s"), sf->file_name, secfile_error());
1655 }
1656
1657 if (!check_tilespec_capabilities(file, "spec",
1658 SPEC_CAPSTR, sf->file_name, TRUE)) {
1660 _("Specfile %s has incompatible capabilities"), sf->file_name);
1661 }
1662
1663 gfx_filename = secfile_lookup_str(file, "file.gfx");
1664
1666
1667 if (!sf->big_sprite) {
1669 _("Could not load gfx file for the spec file \"%s\"."),
1670 sf->file_name);
1671 }
1672 secfile_destroy(file);
1673}
1674
1675/************************************************************************/
1680static void scan_specfile(struct tileset *t, struct specfile *sf,
1681 bool duplicates_ok)
1682{
1683 struct section_file *file;
1684 struct section_list *sections;
1685 int i;
1686
1687 if (!(file = secfile_load(sf->file_name, TRUE))) {
1689 _("Could not open '%s':\n%s"), sf->file_name, secfile_error());
1690 }
1691 if (!check_tilespec_capabilities(file, "spec",
1692 SPEC_CAPSTR, sf->file_name, TRUE)) {
1694 _("Specfile %s has incompatible capabilities"), sf->file_name);
1695 }
1696
1697 /* Currently unused */
1698 secfile_entry_ignore(file, "info.artists");
1699
1700 /* Not used here */
1701 secfile_entry_ignore(file, "file.gfx");
1702
1703 if ((sections = secfile_sections_by_name_prefix(file, "grid_"))) {
1704 section_list_iterate(sections, psection) {
1705 int j, k;
1706 int x_top_left, y_top_left, dx, dy;
1707 int pixel_border_x;
1708 int pixel_border_y;
1709 const char *sec_name = section_name(psection);
1710
1711 pixel_border_x = secfile_lookup_int_default(file, 0, "%s.pixel_border",
1712 sec_name);
1713 pixel_border_y = secfile_lookup_int_default(file, pixel_border_x, "%s.pixel_border_y",
1714 sec_name);
1715 pixel_border_x = secfile_lookup_int_default(file, pixel_border_x, "%s.pixel_border_x",
1716 sec_name);
1717 if (!secfile_lookup_int(file, &x_top_left, "%s.x_top_left", sec_name)
1718 || !secfile_lookup_int(file, &y_top_left,
1719 "%s.y_top_left", sec_name)
1720 || !secfile_lookup_int(file, &dx, "%s.dx", sec_name)
1721 || !secfile_lookup_int(file, &dy, "%s.dy", sec_name)) {
1722 log_error("%s grid \"%s\" invalid: %s",
1724 continue;
1725 }
1726
1727 j = -1;
1728 while (NULL != secfile_entry_lookup(file, "%s.tiles%d.tag",
1729 sec_name, ++j)) {
1730 struct small_sprite *ss;
1731 int row, column;
1732 int xr, yb;
1733 const char **tags;
1734 size_t num_tags;
1735 int hot_x, hot_y;
1736
1737 if (!secfile_lookup_int(file, &row, "%s.tiles%d.row", sec_name, j)
1738 || !secfile_lookup_int(file, &column, "%s.tiles%d.column",
1739 sec_name, j)
1740 || !(tags = secfile_lookup_str_vec(file, &num_tags,
1741 "%s.tiles%d.tag",
1742 sec_name, j))) {
1743 log_error("%s small sprite \"%s.tiles%d\" invalid: %s",
1745 continue;
1746 }
1747 hot_x = secfile_lookup_int_default(file, 0, "%s.tiles%d.hot_x",
1748 sec_name, j);
1749 hot_y = secfile_lookup_int_default(file, 0, "%s.tiles%d.hot_y",
1750 sec_name, j);
1751
1752 /* There must be at least 1 because of the while(): */
1753 fc_assert_action(num_tags > 0, continue);
1754
1755 xr = x_top_left + (dx + pixel_border_x) * column;
1756 yb = y_top_left + (dy + pixel_border_y) * row;
1757
1758 ss = fc_malloc(sizeof(*ss));
1759 ss->ref_count = 0;
1760 ss->file = NULL;
1761 ss->x = xr;
1762 ss->y = yb;
1763 ss->width = dx;
1764 ss->height = dy;
1765 ss->sf = sf;
1766 ss->sprite = NULL;
1767 ss->hot_x = hot_x;
1768 ss->hot_y = hot_y;
1769
1771
1772 if (!duplicates_ok) {
1773 for (k = 0; k < num_tags; k++) {
1774 if (!sprite_hash_insert(t->sprite_hash, tags[k], ss)) {
1775 log_error("warning: %s already has a sprite for \"%s\".",
1776 tileset_name_get(t), tags[k]);
1777 }
1778 }
1779 } else {
1780 for (k = 0; k < num_tags; k++) {
1781 (void) sprite_hash_replace(t->sprite_hash, tags[k], ss);
1782 }
1783 }
1784
1785 free(tags);
1786 tags = NULL;
1787 }
1789 section_list_destroy(sections);
1790 }
1791
1792 /* Load "extra" sprites. Each sprite is one file. */
1793 i = -1;
1794 while (NULL != secfile_entry_lookup(file, "extra.sprites%d.tag", ++i)) {
1795 struct small_sprite *ss;
1796 const char **tags;
1797 const char *filename;
1798 size_t num_tags, k;
1799 int hot_x, hot_y;
1800
1801 if (!(tags = secfile_lookup_str_vec(file, &num_tags,
1802 "extra.sprites%d.tag", i))
1803 || !(filename = secfile_lookup_str(file,
1804 "extra.sprites%d.file", i))) {
1805 log_error("%s extra sprite \"extra.sprites%d\" invalid: %s",
1807 continue;
1808 }
1809 hot_x = secfile_lookup_int_default(file, 0, "extra.sprites%d.hot_x", i);
1810 hot_y = secfile_lookup_int_default(file, 0, "extra.sprites%d.hot_y", i);
1811
1812 ss = fc_malloc(sizeof(*ss));
1813 ss->ref_count = 0;
1814 ss->file = fc_strdup(filename);
1815 ss->sf = NULL;
1816 ss->sprite = NULL;
1817 ss->hot_x = hot_x;
1818 ss->hot_y = hot_y;
1819
1821
1822 if (!duplicates_ok) {
1823 for (k = 0; k < num_tags; k++) {
1824 if (!sprite_hash_insert(t->sprite_hash, tags[k], ss)) {
1825 log_error("warning: %s already have a sprite for \"%s\".",
1826 tileset_name_get(t), tags[k]);
1827 }
1828 }
1829 } else {
1830 for (k = 0; k < num_tags; k++) {
1831 (void) sprite_hash_replace(t->sprite_hash, tags[k], ss);
1832 }
1833 }
1834 free(tags);
1835 }
1836
1839}
1840
1841/************************************************************************/
1845static char *tilespec_gfx_filename(const char *gfx_filename,
1846 const char *tset_name)
1847{
1848 const char *gfx_current_fileext;
1849 const char **gfx_fileexts = gfx_fileextensions();
1850
1851 while ((gfx_current_fileext = *gfx_fileexts++)) {
1852 const char *real_full_name;
1853 char *full_name =
1856
1858
1860 free(full_name);
1861 if (real_full_name) {
1862 return fc_strdup(real_full_name);
1863 }
1864 }
1865
1867 _("Couldn't find a supported gfx file extension for \"%s\"."),
1868 gfx_filename);
1869
1870 return NULL;
1871}
1872
1873/************************************************************************/
1876static bool tileset_scan_single_list(struct tileset *t,
1877 const char *spec_filenames[],
1878 int num_spec_files, bool verbose,
1879 bool duplicates_ok)
1880{
1881 int i;
1882
1883 for (i = 0; i < num_spec_files; i++) {
1884 struct specfile *sf = fc_malloc(sizeof(*sf));
1885 const char *dname;
1886
1887 log_debug("spec file %s", spec_filenames[i]);
1888
1889 sf->big_sprite = NULL;
1891 if (!dname) {
1892 if (verbose) {
1893 log_error("Can't find spec file \"%s\".", spec_filenames[i]);
1894 }
1895
1896 return FALSE;
1897 }
1898 sf->file_name = fc_strdup(dname);
1900
1902 }
1903
1904 return TRUE;
1905}
1906
1907/************************************************************************/
1910static int check_sprite_type(const char *sprite_type, const char *tile_section)
1911{
1912 if (fc_strcasecmp(sprite_type, "corner") == 0) {
1913 return CELL_CORNER;
1914 }
1915 if (fc_strcasecmp(sprite_type, "single") == 0) {
1916 return CELL_WHOLE;
1917 }
1918 if (fc_strcasecmp(sprite_type, "whole") == 0) {
1919 return CELL_WHOLE;
1920 }
1921 log_error("[%s] unknown sprite_type \"%s\".", tile_section, sprite_type);
1922 return CELL_WHOLE;
1923}
1924
1925/************************************************************************/
1931static struct tileset *tileset_read_toplevel(const char *tileset_name,
1932 bool verbose, int topology_id,
1933 float scale)
1934{
1935 struct section_file *file;
1936 char *fname;
1937 const char *c;
1938 int i;
1939 size_t num_spec_files[SFILE_LAST];
1940 const char **spec_filenames[SFILE_LAST];
1941 size_t num_layers;
1942 const char **layer_order;
1943 size_t num_preferred_themes;
1944 struct section_list *sections = NULL;
1945 const char *file_capstr;
1946 bool duplicates_ok, is_hex;
1947 enum direction8 dir;
1948 struct tileset *t = NULL;
1949 const char *extraname;
1950 const char *tstr;
1951 int topo;
1952 bool svg;
1954 const char *type_name;
1955 bool vsup;
1956
1958
1959 if (fname == NULL) {
1960 if (verbose) {
1961 log_error("Can't find tileset \"%s\".", tileset_name);
1962 }
1963
1964 return NULL;
1965 }
1966 log_verbose("tilespec file is \"%s\".", fname);
1967
1968 if (!(file = secfile_load(fname, TRUE))) {
1969 log_error("Could not open '%s':\n%s", fname, secfile_error());
1970 free(fname);
1971 return NULL;
1972 }
1973
1974 if (!check_tilespec_capabilities(file, "tilespec",
1975 TILESPEC_CAPSTR, fname, verbose)) {
1976 secfile_destroy(file);
1977 free(fname);
1978 return NULL;
1979 }
1980
1981 t = tileset_new();
1982 t->scale = scale;
1983 file_capstr = secfile_lookup_str(file, "%s.options", "tilespec");
1985 && has_capabilities("+duplicates_ok", file_capstr));
1986
1987 tstr = secfile_lookup_str(file, "tilespec.name");
1988 /* Tileset name found */
1990 tstr = secfile_lookup_str_default(file, "", "tilespec.version");
1991 if (tstr[0] != '\0') {
1992 /* Tileset version found */
1993 sz_strlcpy(t->version, tstr);
1994 } else {
1995 /* No version information */
1996 t->version[0] = '\0';
1997 }
1998
1999 tstr = secfile_lookup_str_default(file, "", "tilespec.summary");
2000 if (tstr[0] != '\0') {
2001 int len;
2002
2003 /* Tileset summary found */
2004 len = strlen(tstr);
2005 t->summary = fc_malloc(len + 1);
2006 fc_strlcpy(t->summary, tstr, len + 1);
2007 } else {
2008 /* No summary */
2009 if (t->summary != NULL) {
2010 free(t->summary);
2011 t->summary = NULL;
2012 }
2013 }
2014
2015 tstr = secfile_lookup_str_default(file, "", "tilespec.description");
2016 if (tstr[0] != '\0') {
2017 int len;
2018
2019 /* Tileset description found */
2020 len = strlen(tstr);
2021 t->description = fc_malloc(len + 1);
2022 fc_strlcpy(t->description, tstr, len + 1);
2023 } else {
2024 /* No description */
2025 if (t->description != NULL) {
2026 free(t->description);
2027 t->description = NULL;
2028 }
2029 }
2030
2031 tstr = secfile_lookup_str_default(file, NULL, "tilespec.for_ruleset");
2032 if (tstr != NULL) {
2034 } else {
2035 t->for_ruleset = NULL;
2036 }
2037
2039 if (!secfile_lookup_int(file, &t->priority, "tilespec.priority")
2040 || !secfile_lookup_bool(file, &is_hex, "tilespec.is_hex")) {
2041 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2042 goto ON_ERROR;
2043 }
2044
2045 tstr = secfile_lookup_str(file, "tilespec.type");
2046 if (tstr == NULL) {
2047 log_error("Tileset \"%s\": no tileset type", t->name);
2048 goto ON_ERROR;
2049 }
2050
2052 if (!ts_type_is_valid(t->type)) {
2053 log_error("Tileset \"%s\": unknown tileset type \"%s\"", t->name, tstr);
2054 goto ON_ERROR;
2055 }
2056
2057 if (t->type == TS_ISOMETRIC) {
2058 topo = TF_ISO;
2059 } else {
2060 topo = 0;
2061 }
2062
2063 /* Read hex-tileset information. */
2064 t->hex_width = t->hex_height = 0;
2065 if (is_hex) {
2066 int hex_side;
2067
2068 if (!secfile_lookup_int(file, &hex_side, "tilespec.hex_side")) {
2069 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2070 goto ON_ERROR;
2071 }
2072 hex_side = hex_side * t->scale;
2073 if (t->type == TS_ISOMETRIC) {
2074 t->hex_width = hex_side;
2075 } else {
2076 t->hex_height = hex_side;
2077 }
2078
2079 topo |= TF_HEX;
2080
2081 /* Hex tilesets are drawn the same as isometric. */
2082 /* FIXME: There will be other legal values to be used with hex
2083 * tileset in the future, and this would just overwrite it. */
2084 t->type = TS_ISOMETRIC;
2085 }
2086
2087 if (topology_id >= 0) {
2088 if (((topology_id & TF_HEX) && topology_id != (topo & (TF_ISO | TF_HEX)))
2089 || (!(topology_id & TF_HEX) && (topo & TF_HEX))) {
2090 /* Not of requested topology */
2091 goto ON_ERROR;
2092 }
2093 }
2094
2095 t->ts_topo_idx = ts_topology_index(topo);
2096
2097 /* Needed for older compilers to not give "used uninitialized" warning */
2098 vsup = FALSE;
2099
2100 switch (t->type) {
2101 case TS_ISOMETRIC:
2103 break;
2104 case TS_OVERHEAD:
2106 break;
2107 }
2108
2109 if (!vsup) {
2110 /* TRANS: "Overhead" or "Isometric" */
2111 log_normal(_("Client does not support %s tilesets."),
2112 _(ts_type_name(t->type)));
2113 log_normal(_("Using default tileset instead."));
2115 goto ON_ERROR;
2116 }
2117
2119
2120 /* Create arrays of valid and cardinal tileset dirs. These depend
2121 * entirely on the tileset, not the topology. They are also in clockwise
2122 * rotational ordering. */
2124 dir = DIR8_NORTH;
2125 do {
2126 if (is_valid_tileset_dir(t, dir)) {
2129 }
2130 if (is_cardinal_tileset_dir(t, dir)) {
2133 }
2134
2135 dir = dir_cw(dir);
2136 } while (dir != DIR8_NORTH);
2137
2138 fc_assert(t->num_valid_tileset_dirs % 2 == 0); /* Assumed elsewhere. */
2141
2143 "tilespec.normal_tile_width")
2145 "tilespec.normal_tile_height")) {
2146 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2147 goto ON_ERROR;
2148 }
2150 /* Adjust width to be multiple of 8 */
2151 if (scale != 1.0f) {
2152 i = t->normal_tile_width;
2153 while (i % 8 != 0) {
2154 i++;
2155 }
2156 t->scale = (t->scale * i) / t->normal_tile_width;
2157 t->normal_tile_width = i;
2158 }
2160 if (t->type == TS_ISOMETRIC) {
2162 if (tileset_hex_height(t) > 0) {
2164 } else {
2165 t->full_tile_height = 3 * t->normal_tile_height / 2;
2166 }
2167 } else {
2170 }
2172 = secfile_lookup_int_default(file, t->full_tile_width, "tilespec.unit_width");
2174 = secfile_lookup_int_default(file, t->full_tile_height, "tilespec.unit_height");
2176 "tilespec.small_tile_width")
2178 "tilespec.small_tile_height")) {
2179 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2180 goto ON_ERROR;
2181 }
2182 if (t->unit_tile_width != t->full_tile_width && t->scale != 1.0f) {
2184 }
2185 if (t->unit_tile_height != t->full_tile_height && t->scale != 1.0f) {
2187 }
2190 log_verbose("tile sizes %dx%d, %d%d unit, %d%d small",
2194
2195 tstr = secfile_lookup_str(file, "tilespec.fog_style");
2196 if (tstr == NULL) {
2197 log_error("Tileset \"%s\": no fog_style", t->name);
2198 goto ON_ERROR;
2199 }
2200
2202 if (!fog_style_is_valid(t->fogstyle)) {
2203 log_error("Tileset \"%s\": unknown fog_style \"%s\"", t->name, tstr);
2204 goto ON_ERROR;
2205 }
2206
2207 tstr = secfile_lookup_str(file, "tilespec.darkness_style");
2208 if (tstr == NULL) {
2209 log_error("Tileset \"%s\": no darkness_style", t->name);
2210 goto ON_ERROR;
2211 }
2212
2215 log_error("Tileset \"%s\": unknown darkness_style \"%s\"", t->name, tstr);
2216 goto ON_ERROR;
2217 }
2218
2220 && (t->type == TS_OVERHEAD || t->hex_width > 0 || t->hex_height > 0)) {
2221 log_error("Invalid darkness style set in tileset \"%s\".", t->name);
2222 goto ON_ERROR;
2223 }
2224
2226 "tilespec.unit_flag_offset_x")
2228 "tilespec.unit_flag_offset_y")
2230 "tilespec.city_flag_offset_x")
2232 "tilespec.city_flag_offset_y")
2233 || !secfile_lookup_int(file, &t->unit_offset_x,
2234 "tilespec.unit_offset_x")
2235 || !secfile_lookup_int(file, &t->unit_offset_y,
2236 "tilespec.unit_offset_y")
2238 "tilespec.activity_offset_x")
2240 "tilespec.activity_offset_y")
2241 || !secfile_lookup_int(file, &t->select_offset_x,
2242 "tilespec.select_offset_x")
2243 || !secfile_lookup_int(file, &t->select_offset_y,
2244 "tilespec.select_offset_y")
2246 "tilespec.stack_size_offset_x")
2248 "tilespec.stack_size_offset_y")
2249 || !secfile_lookup_int(file, &t->city_offset_x,
2250 "tilespec.city_offset_x")
2251 || !secfile_lookup_int(file, &t->city_offset_y,
2252 "tilespec.city_offset_y")
2254 "tilespec.city_size_offset_x")
2256 "tilespec.city_size_offset_y")
2258 "tilespec.citybar_offset_y")
2260 "tilespec.tilelabel_offset_y")
2262 "tilespec.occupied_offset_x")
2264 "tilespec.occupied_offset_y")) {
2265 log_error("Tileset \"%s\" invalid: %s", t->name, secfile_error());
2266 goto ON_ERROR;
2267 }
2268
2270 "tilespec.unit_upkeep_offset_y");
2272 "tilespec.unit_upkeep_small_offset_y");
2273 t->svg_height = secfile_lookup_int_default(file, 44, "tilespec.svg_height");
2274 t->default_time_per_frame = secfile_lookup_int_default(file, 3, "tilespec.time_per_frame");
2275
2286 t->unit_offset_x = t->scale * t->unit_offset_x;
2287 t->unit_offset_y = t->scale * t->unit_offset_y;
2290 t->city_offset_x = t->scale * t->city_offset_x;
2291 t->city_offset_y = t->scale * t->city_offset_y;
2296 t->svg_height *= t->scale;
2297
2298 if (t->scale != 1.0f
2301 }
2302 if (t->scale != 1.0f
2305 }
2306
2308 "tilespec.unit_default_orientation");
2309 if (!c) {
2310 /* This is valid, but tileset must specify icon for every unit */
2312 } else {
2313 dir = dir_by_tileset_name(c);
2314
2315 if (!direction8_is_valid(dir)) {
2317 _("Unknown unit_default_orientation \"%s\""), c);
2318 goto ON_ERROR;
2319 } else {
2320 /* Default orientation is allowed to not be a valid one for the
2321 * tileset */
2322 t->unit_default_orientation = dir;
2323 }
2324 }
2325
2326 c = secfile_lookup_str(file, "tilespec.main_intro_file");
2328 log_debug("intro file %s", t->main_intro_filename);
2329
2330 /* Layer order */
2331 num_layers = 0;
2332 layer_order = secfile_lookup_str_vec(file, &num_layers,
2333 "tilespec.layer_order");
2334 if (layer_order != NULL) {
2335 for (i = 0; i < num_layers; i++) {
2336 int j;
2339
2340 /* Check for wrong layer names. */
2341 if (!mapview_layer_is_valid(layer)) {
2342 log_error("layer_order: Invalid layer \"%s\" in %s",
2344 goto ON_ERROR;
2345 }
2346 /* Check for duplicates. */
2347 for (j = 0; j < i; j++) {
2348 if (t->layer_order[j] == layer) {
2349 log_error("layer_order: Duplicate layer \"%s\" in %s",
2351 goto ON_ERROR;
2352 }
2353 }
2354 t->layer_order[i] = layer;
2355 }
2356
2357 /* Now check that all layers are present. Doing it now allows for a more
2358 * comprehensive error message. */
2359 for (i = 0; i < LAYER_COUNT; i++) {
2360 int j;
2361 bool found = FALSE;
2362
2363 for (j = 0; j < num_layers; j++) {
2364 if (i == t->layer_order[j]) {
2365 found = TRUE;
2366 break;
2367 }
2368 }
2369 if (!found) {
2370 log_error("layer_order: Missing layer \"%s\" in %s",
2372 goto ON_ERROR;
2373 }
2374 }
2375
2377 } else {
2378 /* There is no layer_order tag in the specfile -> use the default */
2379 for (i = 0; i < LAYER_COUNT; i++) {
2380 t->layer_order[i] = i;
2381 }
2382 }
2383
2384 /* Terrain layer info. */
2385 for (i = 0; i < MAX_NUM_LAYERS; i++) {
2386 struct tileset_layer *tslp = &t->layers[i];
2387 int j, k;
2388
2389 tslp->match_types =
2390 (char **) secfile_lookup_str_vec(file, &tslp->match_count,
2391 "layer%d.match_types", i);
2392 for (j = 0; j < tslp->match_count; j++) {
2393 tslp->match_types[j] = fc_strdup(tslp->match_types[j]);
2394
2395 for (k = 0; k < j; k++) {
2396 if (tslp->match_types[k][0] == tslp->match_types[j][0]) {
2398 _("[layer%d] match_types: \"%s\" initial "
2399 "('%c') is not unique."),
2400 i, tslp->match_types[j], tslp->match_types[j][0]);
2401 /* FIXME: Returns NULL. */
2402 }
2403 }
2404 }
2405 }
2406
2407 /* Tile drawing info. */
2409 if (NULL == sections || 0 == section_list_size(sections)) {
2411 _("No [%s] sections present."),
2413 goto ON_ERROR;
2414 }
2415
2416 fc_assert(t->tile_hash == NULL);
2418
2419 section_list_iterate(sections, psection) {
2420 const char *sec_name = section_name(psection);
2422 const char *sprite_type;
2423 int l;
2424 const char *terrain_name;
2425
2426 terrain_name = secfile_lookup_str(file, "%s.tag", sec_name);
2427
2428 if (terrain_name != NULL) {
2429 draw->name = fc_strdup(terrain_name);
2430 } else {
2431 tileset_error(LOG_ERROR, _("No terrain tag given in section [%s] in %s."),
2434 goto ON_ERROR;
2435 }
2436
2437 draw->blending = secfile_lookup_int_default(file, 0, "%s.blend_layer",
2438 sec_name);
2439 draw->blending = CLIP(0, draw->blending, MAX_NUM_LAYERS);
2440
2441 draw->is_reversed = secfile_lookup_bool_default(file, FALSE,
2442 "%s.is_reversed",
2443 sec_name);
2444 draw->num_layers = secfile_lookup_int_default(file, 0, "%s.num_layers",
2445 sec_name);
2446 draw->num_layers = CLIP(1, draw->num_layers, MAX_NUM_LAYERS);
2447
2448 for (l = 0; l < draw->num_layers; l++) {
2449 struct drawing_layer *dlp = &draw->layer[l];
2450 struct tileset_layer *tslp = &t->layers[l];
2451 const char *match_type;
2452 const char **match_with;
2453 size_t count;
2454
2455 dlp->is_tall
2456 = secfile_lookup_bool_default(file, FALSE, "%s.layer%d_is_tall",
2457 sec_name, l);
2458 dlp->offset_x
2459 = secfile_lookup_int_default(file, 0, "%s.layer%d_offset_x",
2460 sec_name, l);
2461 dlp->offset_y
2462 = secfile_lookup_int_default(file, 0, "%s.layer%d_offset_y",
2463 sec_name, l);
2464 dlp->offset_x = ceil(t->scale * dlp->offset_x);
2465 dlp->offset_y = ceil(t->scale * dlp->offset_y);
2466
2468 "%s.layer%d_match_type",
2469 sec_name, l);
2470 if (match_type) {
2471 int j;
2472
2473 /* Determine our match_type. */
2474 for (j = 0; j < tslp->match_count; j++) {
2475 if (fc_strcasecmp(tslp->match_types[j], match_type) == 0) {
2476 break;
2477 }
2478 }
2479 if (j >= tslp->match_count) {
2480 log_error("[%s] invalid match_type \"%s\" in %s.",
2482 } else {
2483 dlp->match_index[dlp->match_indices++] = j;
2484 }
2485 }
2486
2487 match_with = secfile_lookup_str_vec(file, &count,
2488 "%s.layer%d_match_with",
2489 sec_name, l);
2490 if (match_with) {
2491 int j, k;
2492
2493 if (count > MAX_NUM_MATCH_WITH) {
2494 log_error("[%s] match_with has too many types (%d, max %d) in %s",
2495 sec_name, (int) count, MAX_NUM_MATCH_WITH,
2496 tileset_name_get(t));
2497 count = MAX_NUM_MATCH_WITH;
2498 }
2499
2500 if (1 < dlp->match_indices) {
2501 log_error("[%s] previous match_with ignored in %s.",
2503 dlp->match_indices = 1;
2504 } else if (1 > dlp->match_indices) {
2505 log_error("[%s] missing match_type, using \"%s\" in %s.",
2506 sec_name, tslp->match_types[0], tileset_name_get(t));
2507 dlp->match_index[0] = 0;
2508 dlp->match_indices = 1;
2509 }
2510
2511 for (k = 0; k < count; k++) {
2512 for (j = 0; j < tslp->match_count; j++) {
2513 if (fc_strcasecmp(tslp->match_types[j], match_with[k]) == 0) {
2514 break;
2515 }
2516 }
2517 if (j >= tslp->match_count) {
2518 log_error("[%s] layer%d_match_with: invalid \"%s\".",
2519 sec_name, l, match_with[k]);
2520 } else if (1 < count) {
2521 int m;
2522
2523 for (m = 0; m < dlp->match_indices; m++) {
2524 if (dlp->match_index[m] == j) {
2525 log_error("[%s] layer%d_match_with: duplicate \"%s\" in %s.",
2527 break;
2528 }
2529 }
2530 if (m >= dlp->match_indices) {
2531 dlp->match_index[dlp->match_indices++] = j;
2532 }
2533 } else {
2534 dlp->match_index[dlp->match_indices++] = j;
2535 }
2536 }
2538 match_with = NULL;
2539 }
2540
2541 /* Check match_indices */
2542 switch (dlp->match_indices) {
2543 case 0:
2544 case 1:
2545 dlp->match_style = MATCH_NONE;
2546 break;
2547 case 2:
2548 if (dlp->match_index[0] == dlp->match_index[1] ) {
2549 dlp->match_style = MATCH_SAME;
2550 } else {
2551 dlp->match_style = MATCH_PAIR;
2552 }
2553 break;
2554 default:
2555 dlp->match_style = MATCH_FULL;
2556 break;
2557 };
2558
2560 = secfile_lookup_str_default(file, "whole", "%s.layer%d_sprite_type",
2561 sec_name, l);
2562 dlp->sprite_type = check_sprite_type(sprite_type, sec_name);
2563
2564 switch (dlp->sprite_type) {
2565 case CELL_WHOLE:
2566 /* OK, no problem */
2567 break;
2568 case CELL_CORNER:
2569 if (dlp->is_tall
2570 || dlp->offset_x > 0
2571 || dlp->offset_y > 0) {
2572 log_error("[%s] layer %d: you cannot have tall terrain or\n"
2573 "a sprite offset with a cell-based drawing method in %s.",
2575 dlp->is_tall = FALSE;
2576 dlp->offset_x = dlp->offset_y = 0;
2577 }
2578 break;
2579 };
2580 }
2581
2582 if (!drawing_hash_insert(t->tile_hash, draw->name, draw)) {
2583 log_error("warning: multiple tile sections containing terrain tag \"%s\" in %s.",
2584 draw->name, tileset_name_get(t));
2585 goto ON_ERROR;
2586 }
2588 section_list_destroy(sections);
2589 sections = NULL;
2590
2592
2593 for (i = 0; i < ESTYLE_COUNT; i++) {
2595 }
2597
2598 for (i = 0; (extraname = secfile_lookup_str_default(file, NULL,
2599 "extras.styles%d.name",
2600 i)); i++) {
2601 const char *style_name;
2602 enum extrastyle_id style;
2603
2604 style_name = secfile_lookup_str_default(file, "Single1",
2605 "extras.styles%d.style", i);
2607 if (!extrastyle_id_is_valid(style)) {
2608 log_error("Unknown extra style \"%s\" for extra \"%s\" in %s.",
2610 goto ON_ERROR;
2611 }
2612
2613 if (!estyle_hash_insert(t->estyle_hash, extraname, style)) {
2614 log_error("warning: duplicate extrastyle entry [%s] in %s.",
2616 goto ON_ERROR;
2617 }
2618 }
2619
2621
2624 "tilespec.files");
2625
2626 if (svg) {
2628 type_name = "svg";
2629
2630 /* Avoid "unused entry" warning about the other list */
2631 secfile_entry_ignore_by_path(file, "tilespec.files_pixel");
2632 } else {
2634 type_name = "pixel";
2635
2636 /* Avoid "unused entry" warning about the other list */
2637 secfile_entry_ignore_by_path(file, "tilespec.files_svg");
2638 }
2639
2642 "tilespec.files_%s", type_name);
2645 log_error("No tile graphics files specified in \"%s\" for %s mode.",
2646 type_name, fname);
2647 goto ON_ERROR;
2648 }
2649
2650 fc_assert(t->sprite_hash == nullptr);
2652
2653 fc_assert(t->anim_hash == nullptr);
2654 t->anim_hash = anim_hash_new();
2655
2658 verbose, duplicates_ok)) {
2659 goto ON_ERROR;
2660 }
2661
2664 verbose, duplicates_ok)) {
2665 goto ON_ERROR;
2666 }
2667
2670
2672
2674 = (char **) secfile_lookup_str_vec(file, &num_preferred_themes,
2675 "tilespec.preferred_themes");
2676 t->num_preferred_themes = num_preferred_themes;
2677 for (i = 0; i < t->num_preferred_themes; i++) {
2679 }
2680
2682 secfile_destroy(file);
2683 log_verbose("Finished reading \"%s\".", fname);
2684 free(fname);
2685
2686 return t;
2687
2688ON_ERROR:
2689 secfile_destroy(file);
2690 free(fname);
2691 tileset_free(t);
2692
2693 if (NULL != sections) {
2694 section_list_destroy(sections);
2695 }
2696
2697 return NULL;
2698}
2699
2700/************************************************************************/
2703static const char *citizen_rule_name(enum citizen_category citizen)
2704{
2705 /* These strings are used in reading the tileset. Do not
2706 * translate. */
2707 switch (citizen) {
2708 case CITIZEN_HAPPY:
2709 return "happy";
2710 case CITIZEN_CONTENT:
2711 return "content";
2712 case CITIZEN_UNHAPPY:
2713 return "unhappy";
2714 case CITIZEN_ANGRY:
2715 return "angry";
2716 default:
2717 break;
2718 }
2719 log_error("Unknown citizen type: %d.", (int) citizen);
2720 return NULL;
2721}
2722
2723/************************************************************************/
2728static const char *cardinal_index_str(const struct tileset *t, int idx)
2729{
2730 static char c[64];
2731 int i;
2732
2733 c[0] = '\0';
2734 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
2735 int value = (idx >> i) & 1;
2736
2737 cat_snprintf(c, sizeof(c), "%s%d",
2739 }
2740
2741 return c;
2742}
2743
2744/************************************************************************/
2748static char *valid_index_str(const struct tileset *t, int idx)
2749{
2750 static char c[64];
2751 int i;
2752
2753 c[0] = '\0';
2754 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
2755 int value = (idx >> i) & 1;
2756
2757 cat_snprintf(c, sizeof(c), "%s%d",
2759 }
2760
2761 return c;
2762}
2763
2764/************************************************************************/
2771static struct anim *anim_new(int frames, int time_per_frame)
2772{
2773 struct anim *ret = fc_malloc(sizeof(struct anim));
2774
2775 ret->frames = frames;
2776 ret->time = -1;
2777 ret->time_per_frame = time_per_frame;
2778 ret->sprites = fc_malloc(frames * sizeof(struct sprite *));
2779 ret->show_always = FALSE;
2780
2781 return ret;
2782}
2783
2784/************************************************************************/
2789static void anim_free(struct anim *a)
2790{
2791 if (a != nullptr) {
2792 free(a->sprites);
2793 free(a);
2794 }
2795}
2796
2797/************************************************************************/
2804static struct sprite *load_sprite(struct tileset *t, const char *tag_name,
2805 bool scale, bool smooth, bool svgflag)
2806{
2807 struct small_sprite *ss;
2808 float sprite_scale = 1.0f;
2809
2810 log_debug("load_sprite(tag='%s')", tag_name);
2811 /* Lookup information about where the sprite is found. */
2813 return NULL;
2814 }
2815
2816 fc_assert(ss->ref_count >= 0);
2817
2818 if (!ss->sprite) {
2819 /* If the sprite hasn't been loaded already, then load it. */
2820 fc_assert(ss->ref_count == 0);
2821
2822 if (ss->file) {
2823 int w, h;
2824 struct sprite *s;
2825
2826 if (scale) {
2827 s = load_gfx_file(ss->file, svgflag);
2828
2829 if (s != NULL) {
2830 get_sprite_dimensions(s, &w, &h);
2831 ss->sprite = crop_sprite(s, 0, 0, w,
2832 h, NULL, -1, -1, t->scale, smooth);
2833 free_sprite(s);
2834 }
2835 } else {
2836 ss->sprite = load_gfx_file(ss->file, svgflag);
2837 }
2838
2839 if (!ss->sprite) {
2841 _("Couldn't load gfx file \"%s\" for sprite '%s'."),
2842 ss->file, tag_name);
2843 }
2844 } else {
2845 int sf_w, sf_h;
2846
2848 get_sprite_dimensions(ss->sf->big_sprite, &sf_w, &sf_h);
2849 if (ss->x < 0 || ss->x + ss->width > sf_w
2850 || ss->y < 0 || ss->y + ss->height > sf_h) {
2852 _("Sprite '%s' in file \"%s\" isn't within the image!"),
2853 tag_name, ss->sf->file_name);
2854 return NULL;
2855 }
2856 if (scale) {
2857 sprite_scale = t->scale;
2858 }
2859 ss->sprite = crop_sprite(ss->sf->big_sprite, ss->x, ss->y, ss->width,
2860 ss->height, NULL, -1, -1, sprite_scale,
2861 smooth);
2862 }
2863 }
2864
2865 /* Track the reference count so we know when to free the sprite. */
2866 ss->ref_count++;
2867
2868 return ss->sprite;
2869}
2870
2871/************************************************************************/
2874static struct sprite *create_plr_sprite(struct color *pcolor)
2875{
2876 struct sprite *sprite;
2877
2879
2882
2883 return sprite;
2884}
2885
2886/************************************************************************/
2890static void unload_sprite(struct tileset *t, const char *tag_name)
2891{
2892 struct small_sprite *ss;
2893
2896 fc_assert_ret(ss->ref_count >= 1);
2897 fc_assert_ret(ss->sprite);
2898
2899 ss->ref_count--;
2900
2901 if (ss->ref_count == 0) {
2902 /* Nobody's using the sprite anymore, so we should free it. We know
2903 * where to find it if we need it again. */
2904 log_debug("freeing sprite '%s'.", tag_name);
2905 free_sprite(ss->sprite);
2906 ss->sprite = NULL;
2907 }
2908}
2909
2910/************************************************************************/
2914static bool sprite_exists(const struct tileset *t, const char *tag_name)
2915{
2916 /* Lookup information about where the sprite is found. */
2918}
2919
2920/* Not very safe, but convenient: */
2921#define SET_SPRITE(field, tag) \
2922 do { \
2923 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2924 if (t->sprites.field == NULL) { \
2925 tileset_error(LOG_FATAL, tileset_name_get(t), \
2926 _("Sprite for tag '%s' missing."), tag); \
2927 } \
2928 } while (FALSE)
2929
2930
2931#define SET_SPRITE_NOTSMOOTH(field, tag) \
2932 do { \
2933 t->sprites.field = load_sprite(t, tag, TRUE, FALSE, FALSE); \
2934 if (t->sprites.field == NULL) { \
2935 tileset_error(LOG_FATAL, tileset_name_get(t), \
2936 _("Sprite for tag '%s' missing."), tag); \
2937 } \
2938 } while (FALSE)
2939
2940#define SET_SPRITE_UNSCALED(field, tag) \
2941 do { \
2942 t->sprites.field = load_sprite(t, tag, FALSE, FALSE, FALSE); \
2943 if (t->sprites.field == NULL) { \
2944 tileset_error(LOG_FATAL, tileset_name_get(t), \
2945 _("Sprite for tag '%s' missing."), tag); \
2946 } \
2947 } while (FALSE)
2948
2949/* Sets sprites.field to tag or (if tag isn't available) to alt */
2950#define SET_SPRITE_ALT(field, tag, alt) \
2951 do { \
2952 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2953 if (!t->sprites.field) { \
2954 t->sprites.field = load_sprite(t, alt, TRUE, TRUE, FALSE); \
2955 } \
2956 if (t->sprites.field == NULL) { \
2957 tileset_error(LOG_FATAL, tileset_name_get(t), \
2958 _("Sprite for tags '%s' and alternate '%s' are " \
2959 "both missing."), tag, alt); \
2960 } \
2961 } while (FALSE)
2962
2963/* Sets sprites.field to tag or (if tag isn't available) to deprecated alt */
2964#define SET_SPRITE_DEPR_ALT(field, tag, alt, ver) \
2965 do { \
2966 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE); \
2967 if (!t->sprites.field) { \
2968 t->sprites.field = load_sprite(t, alt, TRUE, TRUE, FALSE); \
2969 if (t->sprites.field != NULL) { \
2970 log_deprecation(_("%s: Using tag \"%s\" deprecated by \"%s\" in %s"), \
2971 tileset_name_get(t), alt, tag, ver); \
2972 } \
2973 } \
2974 if (t->sprites.field == NULL) { \
2975 tileset_error(LOG_FATAL, tileset_name_get(t), \
2976 _("Sprite for tags '%s' and alternate '%s' are " \
2977 "both missing."), tag, alt); \
2978 } \
2979 } while (FALSE)
2980
2981/* Sets sprites.field to tag, or nullptr if not available */
2982#define SET_SPRITE_OPT(field, tag) \
2983 t->sprites.field = load_sprite(t, tag, TRUE, TRUE, FALSE)
2984
2985#define SET_SPRITE_ALT_OPT(field, tag, alt) \
2986 do { \
2987 t->sprites.field = tiles_lookup_sprite_tag_alt(t, LOG_VERBOSE, tag, alt, \
2988 NULL, "sprite", #field, \
2989 TRUE); \
2990 } while (FALSE)
2991
2992#define SET_ANIM(field, tag) \
2993 do { \
2994 t->sprites.field = anim_load(t, tag, 0); \
2995 if (t->sprites.field == nullptr) { \
2996 tileset_error(LOG_FATAL, tileset_name_get(t), \
2997 _("Animation for tag '%s' missing."), tag); \
2998 } \
2999 } while (FALSE)
3000
3001/* Sets sprites.field to tag, or nullptr if not available */
3002#define SET_ANIM_OPT(field, tag) \
3003 t->sprites.field = anim_load(t, tag, 0)
3004
3005/************************************************************************/
3013static struct anim *anim_load(struct tileset *t, const char *tag,
3014 int time_per_frame)
3015{
3016 int frames = 0;
3017 char buf[1500];
3018 struct anim *ret;
3019 int i;
3020
3021 do {
3022 fc_snprintf(buf, sizeof(buf), "%s:%d", tag, frames++);
3023 } while (sprite_exists(t, buf));
3024
3025 if (--frames == 0) {
3026 return nullptr;
3027 }
3028
3029 if (time_per_frame <= 0) {
3031 }
3032
3034
3035 for (i = 0; i < frames; i++) {
3036 fc_snprintf(buf, sizeof(buf), "%s:%d", tag, i);
3037 ret->sprites[i] = load_sprite(t, buf, TRUE, TRUE, FALSE);
3038 if (ret->sprites[i] == nullptr) {
3040 _("Animation sprite for tag '%s' missing."), buf);
3041 }
3042 }
3043
3044 anim_hash_insert(t->anim_hash, tag, ret);
3045
3046 return ret;
3047}
3048
3049/************************************************************************/
3054static void anim_advance_time(struct anim *a)
3055{
3056 a->time++;
3057}
3058
3059/************************************************************************/
3065static struct sprite *anim_get_current_frame(struct anim *a)
3066{
3067 int time;
3068
3070 return a->sprites[0];
3071 }
3072
3073 if (a->time >= 0) {
3074 time = a->time;
3075 } else {
3076 time = global_anim_time;
3077 }
3078
3079 return a->sprites[(time / a->time_per_frame) % a->frames];
3080}
3081
3082/************************************************************************/
3091
3092/************************************************************************/
3096 struct citizen_set *set,
3098 const char *tag_group,
3099 const char *set_name,
3100 bool required)
3101{
3102 /* Load the specialist sprite graphics. */
3103 char buffer[512];
3104 int j;
3105 struct specialist *spe = specialist_by_number(id);
3106 const char *tag = spe->graphic_str;
3107 const char *graphic_alt = spe->graphic_alt;
3108
3109 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
3110 /* Try tag name + index number */
3111 if (tag_group != NULL) {
3112 fc_snprintf(buffer, sizeof(buffer), "%s.%s_%d", tag_group, tag, j);
3113 } else {
3114 fc_snprintf(buffer, sizeof(buffer), "%s_%d", tag, j);
3115 }
3116 set->specialist[id].sprite[j] = load_sprite(t, buffer,
3117 FALSE, FALSE, FALSE);
3118
3119 /* Break if no more index specific sprites are defined */
3120 if (!set->specialist[id].sprite[j]) {
3121 break;
3122 }
3123 }
3124
3125 if (j == 0) {
3126 /* Try non-indexed */
3127 set->specialist[id].sprite[j] = load_sprite(t, tag,
3128 FALSE, FALSE, FALSE);
3129
3130 if (set->specialist[id].sprite[j]) {
3131 j = 1;
3132 }
3133 }
3134
3135 if (j == 0) {
3136 /* Try the alt tag */
3137 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
3138 /* Try alt tag name + index number */
3139 if (tag_group != NULL) {
3140 fc_snprintf(buffer, sizeof(buffer), "%s.%s_%d", tag_group, graphic_alt, j);
3141 } else {
3142 fc_snprintf(buffer, sizeof(buffer), "%s_%d", graphic_alt, j);
3143 }
3144 set->specialist[id].sprite[j] = load_sprite(t, buffer,
3145 FALSE, FALSE, FALSE);
3146
3147 /* Break if no more index specific sprites are defined */
3148 if (!set->specialist[id].sprite[j]) {
3149 break;
3150 }
3151 }
3152 }
3153
3154 if (j == 0) {
3155 /* Try alt tag non-indexed */
3157 FALSE, FALSE, FALSE);
3158
3159 if (set->specialist[id].sprite[j]) {
3160 j = 1;
3161 }
3162 }
3163
3164 set->specialist[id].count = j;
3165
3166 /* Still nothing? Give up. */
3167 if (j == 0 && required) {
3168 /* TRANS: First %s is a graphics tag of the specialist, second one
3169 * is a citizen set name; 'citizen_graphic' from styles.ruleset */
3171 _("No graphics for specialist \"%s\" in %s."),
3172 tag, set_name);
3173 }
3174}
3175
3176/************************************************************************/
3180{
3182 "default set", TRUE);
3183}
3184
3185/************************************************************************/
3189 struct citizen_set *set,
3190 const char *tag_group,
3191 const char *set_name,
3192 bool required)
3193{
3194 int i, j;
3195 char buffer[512];
3196
3197 /* Load the citizen sprite graphics, no specialist. */
3198 for (i = 0; i < CITIZEN_LAST; i++) {
3199 const char *name = citizen_rule_name(i);
3200
3201 for (j = 0; j < MAX_NUM_CITIZEN_SPRITES; j++) {
3202 if (tag_group != NULL) {
3203 fc_snprintf(buffer, sizeof(buffer), "citizen.%s.%s_%d", tag_group, name, j);
3204 } else {
3205 fc_snprintf(buffer, sizeof(buffer), "citizen.%s_%d", name, j);
3206 }
3207 set->citizen[i].sprite[j] = load_sprite(t, buffer, FALSE, FALSE, FALSE);
3208 if (!set->citizen[i].sprite[j]) {
3209 break;
3210 }
3211 }
3212 set->citizen[i].count = j;
3213 if (j == 0 && required) {
3214 /* TRANS: First %s is type of the citizen ("happy" ... "angry"), second one
3215 * is a citizen set name; 'citizen_graphic' from styles.ruleset */
3217 _("No graphics for citizen \"%s\" in %s."),
3218 name, set_name);
3219 }
3220 }
3221}
3222
3223/************************************************************************/
3229static struct sprite *get_city_sprite(const struct city_sprite *city_sprite,
3230 const struct city *pcity)
3231{
3232 /* Get style and match the best tile based on city size */
3233 int style = style_of_city(pcity);
3234 int num_thresholds;
3236 int img_index;
3237
3239
3242
3243 if (num_thresholds == 0) {
3244 return NULL;
3245 }
3246
3247 /* Get the sprite with the index defined by the effects. */
3248 img_index = pcity->client.city_image;
3249 if (img_index == -100) {
3250 /* Server doesn't know right value as this is from old savegame.
3251 * Guess here based on *client* side information as was done in
3252 * versions where information was not saved to savegame - this should
3253 * give us right answer of what city looked like by the time it was
3254 * put under FoW. */
3256 }
3258
3259 return thresholds[img_index].sprite;
3260}
3261
3262/************************************************************************/
3265static int load_city_thresholds_sprites(struct tileset *t, const char *tag,
3266 char *graphic, char *graphic_alt,
3268{
3269 char buffer[128];
3270 char *gfx_in_use = graphic;
3271 int num_thresholds = 0;
3272 struct sprite *sprite;
3273 int size;
3274
3275 *thresholds = NULL;
3276
3277 for (size = 0; size < MAX_CITY_SIZE; size++) {
3278 fc_snprintf(buffer, sizeof(buffer), "%s_%s_%d",
3279 gfx_in_use, tag, size);
3280 if ((sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE))) {
3283 (*thresholds)[num_thresholds - 1].sprite = sprite;
3284 } else if (size == 0) {
3285 if (gfx_in_use == graphic) {
3286 /* Try again with graphic_alt. */
3287 size--;
3288 gfx_in_use = graphic_alt;
3289 } else {
3290 /* Don't load any others if the 0 element isn't there. */
3291 break;
3292 }
3293 }
3294 }
3295
3296 return num_thresholds;
3297}
3298
3299/************************************************************************/
3306static struct city_sprite *load_city_sprite(struct tileset *t,
3307 const char *tag)
3308{
3309 struct city_sprite *city_sprite = fc_malloc(sizeof(*city_sprite));
3310 int style;
3311
3312 /* Store number of styles we have allocated memory for.
3313 * game.control.num_city_styles might change if client disconnects from
3314 * server and connects new one. */
3317 * sizeof(*city_sprite->styles));
3318
3319 for (style = 0; style < city_sprite->num_styles; style++) {
3321 load_city_thresholds_sprites(t, tag, city_styles[style].graphic,
3322 city_styles[style].graphic_alt,
3324 }
3325
3326 return city_sprite;
3327}
3328
3329/************************************************************************/
3335{
3336 int style;
3337
3338 if (!city_sprite) {
3339 return;
3340 }
3341 for (style = 0; style < city_sprite->num_styles; style++) {
3342 if (city_sprite->styles[style].land_thresholds) {
3344 }
3345 }
3348}
3349
3350/************************************************************************/
3355{
3356 char buffer[512], buffer2[512];
3357 const int W = t->normal_tile_width, H = t->normal_tile_height;
3358 int i, j, f;
3359
3361
3362 SET_SPRITE_UNSCALED(treaty_thumb[0], "treaty.disagree_thumb_down");
3363 SET_SPRITE_UNSCALED(treaty_thumb[1], "treaty.agree_thumb_up");
3364
3365 for (j = 0; j < INDICATOR_COUNT; j++) {
3366 const char *names[] = {"science_bulb", "warming_sun", "cooling_flake"};
3367
3368 for (i = 0; i < NUM_TILES_PROGRESS; i++) {
3369 fc_snprintf(buffer, sizeof(buffer), "s.%s_%d", names[j], i);
3370 SET_SPRITE_UNSCALED(indicator[j][i], buffer);
3371 }
3372 }
3373
3374 SET_SPRITE(arrow[ARROW_RIGHT], "s.right_arrow");
3375 SET_SPRITE(arrow[ARROW_PLUS], "s.plus");
3376 SET_SPRITE(arrow[ARROW_MINUS], "s.minus");
3377 if (t->type == TS_ISOMETRIC) {
3378 SET_SPRITE(dither_tile, "t.dither_tile");
3379 }
3380
3382 SET_SPRITE_NOTSMOOTH(mask.tile, "mask.tile");
3383 } else {
3384 SET_SPRITE(mask.tile, "mask.tile");
3385 }
3386 SET_SPRITE(mask.worked_tile, "mask.worked_tile");
3387 SET_SPRITE(mask.unworked_tile, "mask.unworked_tile");
3388
3389 SET_SPRITE_UNSCALED(tax_luxury, "s.tax_luxury");
3390 SET_SPRITE_UNSCALED(tax_science, "s.tax_science");
3391 SET_SPRITE_UNSCALED(tax_gold, "s.tax_gold");
3392
3394
3395 for (i = 0; i < SPACESHIP_COUNT; i++) {
3396 const char *names[SPACESHIP_COUNT]
3397 = {"solar_panels", "life_support", "habitation",
3398 "structural", "fuel", "propulsion", "exhaust"};
3399
3400 fc_snprintf(buffer, sizeof(buffer), "spaceship.%s", names[i]);
3401 SET_SPRITE(spaceship[i], buffer);
3402 }
3403
3404 for (i = 0; i < CURSOR_LAST; i++) {
3405 const char *names[CURSOR_LAST] =
3406 {"goto", "patrol", "paradrop", "teleport", "nuke", "select",
3407 "invalid", "attack", "edit_paint", "edit_add", "wait"};
3408
3409 for (f = 0; f < NUM_CURSOR_FRAMES; f++) {
3410 struct small_sprite *ss;
3411
3412 fc_assert(ARRAY_SIZE(names) == CURSOR_LAST);
3413 fc_snprintf(buffer, sizeof(buffer), "cursor.%s%d", names[i], f);
3414 SET_SPRITE(cursor[i].frame[f], buffer);
3415
3416 if (sprite_hash_lookup(t->sprite_hash, buffer, &ss)) {
3417 t->sprites.cursor[i].hot_x = ss->hot_x;
3418 t->sprites.cursor[i].hot_y = ss->hot_y;
3419 }
3420 }
3421 }
3422
3423 for (i = 0; i < ICON_COUNT; i++) {
3424 const char *names[ICON_COUNT] = {"freeciv", "citydlg"};
3425
3426 fc_snprintf(buffer, sizeof(buffer), "icon.%s", names[i]);
3427 SET_SPRITE(icon[i], buffer);
3428 }
3429
3430 for (i = 0; i < E_COUNT; i++) {
3431 const char *tag = get_event_tag(i);
3432
3433 SET_SPRITE(events[i], tag);
3434 }
3435
3436 SET_SPRITE(explode.nuke, "explode.nuke");
3437
3439 for (i = 0; ; i++) {
3440 struct sprite *sprite;
3441
3442 fc_snprintf(buffer, sizeof(buffer), "explode.unit_%d", i);
3443 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3444 if (!sprite) {
3445 break;
3446 }
3448 }
3449
3450 SET_SPRITE(unit.auto_attack, "unit.auto_attack");
3451 /* TODO: Drop backward compatibility with "unit.auto_settler" tag. */
3452 SET_SPRITE_DEPR_ALT(unit.auto_worker, "unit.auto_worker", "unit.auto_settler", "3.3");
3453 SET_SPRITE(unit.auto_explore, "unit.auto_explore");
3454 SET_SPRITE(unit.fortified, "unit.fortified");
3455 SET_SPRITE(unit.fortifying, "unit.fortifying");
3456 SET_SPRITE(unit.go_to, "unit.goto");
3457 SET_SPRITE(unit.cultivate, "unit.cultivate");
3458 SET_SPRITE(unit.plant, "unit.plant");
3459 SET_SPRITE(unit.pillage, "unit.pillage");
3460 SET_SPRITE(unit.sentry, "unit.sentry");
3461 SET_SPRITE(unit.convert, "unit.convert");
3462 t->sprites.unit.stack = fc_malloc(sizeof(struct sprite *));
3463 t->sprites.unit.num_stack_sprites = 1;
3464 SET_SPRITE(unit.stack[0], "unit.stack");
3465 t->sprites.unit.no_more_stack_sprites = FALSE;
3466 SET_SPRITE(unit.loaded, "unit.loaded");
3467 SET_SPRITE(unit.transform, "unit.transform");
3468 SET_SPRITE(unit.connect, "unit.connect");
3469 SET_SPRITE(unit.patrol, "unit.patrol");
3470 for (i = 0; i < MAX_NUM_BATTLEGROUPS; i++) {
3471 fc_snprintf(buffer, sizeof(buffer), "unit.battlegroup_%d", i);
3472 fc_snprintf(buffer2, sizeof(buffer2), "city.size_%d", i + 1);
3475 }
3476 SET_SPRITE(unit.lowfuel, "unit.lowfuel");
3477 SET_SPRITE(unit.tired, "unit.tired");
3478
3479 t->sprites.unit.action_decision_want = anim_load(t, "unit.action_decision_want",
3480 0);
3481
3482 for (i = 0; i < NUM_TILES_HP_BAR; i++) {
3483 fc_snprintf(buffer, sizeof(buffer), "unit.hp_%d", i*10);
3484 SET_SPRITE(unit.hp_bar[i], buffer);
3485 }
3486
3487 for (i = 0; i < MAX_VET_LEVELS; i++) {
3488 /* Veteran level sprites are optional. For instance "green" units
3489 * usually have no special graphic. */
3490 fc_snprintf(buffer, sizeof(buffer), "unit.vet_%d", i);
3491 t->sprites.unit.vet_lev[i] = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3492 }
3493
3494 t->sprites.unit.select = anim_load(t, "unit.select", 1);
3495 if (t->sprites.unit.select != nullptr) {
3496 t->sprites.unit.select->show_always = TRUE;
3497 t->sprites.unit.select->time = 0; /* Not using global anim time */
3498 }
3499
3500 SET_SPRITE(citybar.shields, "citybar.shields");
3501 SET_SPRITE(citybar.food, "citybar.food");
3502 SET_SPRITE(citybar.trade, "citybar.trade");
3503 SET_SPRITE(citybar.occupied, "citybar.occupied");
3504 SET_SPRITE(citybar.background, "citybar.background");
3506 for (i = 0; ; i++) {
3507 struct sprite *sprite;
3508
3509 fc_snprintf(buffer, sizeof(buffer), "citybar.occupancy_%d", i);
3510 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3511 if (!sprite) {
3512 break;
3513 }
3515 }
3516 if (t->sprites.citybar.occupancy.size < 2) {
3518 _("Missing necessary citybar.occupancy_N sprites."));
3519 }
3520
3521#define SET_EDITOR_SPRITE(x) SET_SPRITE(editor.x, "editor." #x)
3522 SET_EDITOR_SPRITE(erase);
3523 SET_EDITOR_SPRITE(brush);
3524 SET_EDITOR_SPRITE(copy);
3525 SET_EDITOR_SPRITE(paste);
3526 SET_EDITOR_SPRITE(copypaste);
3529 SET_EDITOR_SPRITE(terrain_resource);
3530 SET_EDITOR_SPRITE(terrain_special);
3534 SET_EDITOR_SPRITE(territory);
3535 SET_EDITOR_SPRITE(properties);
3537 SET_EDITOR_SPRITE(military_base);
3538#undef SET_EDITOR_SPRITE
3539
3540 SET_SPRITE(city.disorder, "city.disorder");
3541
3542 /* Fallbacks for goto path turn numbers:
3543 * path.step_%d, path.exhausted_mp_%d
3544 * --> path.turns_%d
3545 * --> city.size_%d */
3546#define SET_GOTO_TURN_SPRITE(state, state_name, factor, factor_name) \
3547 fc_snprintf(buffer, sizeof(buffer), "path." state_name "_%d" #factor, i); \
3548 SET_SPRITE_OPT(path.s[state].turns ## factor_name [i], buffer); \
3549 if (t->sprites.path.s[state].turns ## factor_name [i] == NULL) { \
3550 t->sprites.path.s[state].turns ## factor_name [i] = \
3551 t->sprites.path.s[GTS_MP_LEFT].turns ## factor_name [i]; \
3552 }
3553
3554 for (i = 0; i < NUM_TILES_DIGITS; i++) {
3555 fc_snprintf(buffer, sizeof(buffer), "city.size_%d", i);
3556 SET_SPRITE(city.size[i], buffer);
3557 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d", i);
3558 SET_SPRITE_ALT(path.s[GTS_MP_LEFT].turns[i], buffer2, buffer);
3560 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp",,);
3561
3562 fc_snprintf(buffer, sizeof(buffer), "city.size_%d0", i);
3563 SET_SPRITE(city.size_tens[i], buffer);
3564 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d0", i);
3565 SET_SPRITE_ALT(path.s[GTS_MP_LEFT].turns_tens[i], buffer2, buffer);
3567 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp", 0, _tens);
3568
3569 fc_snprintf(buffer, sizeof(buffer), "city.size_%d00", i);
3570 SET_SPRITE_OPT(city.size_hundreds[i], buffer);
3571 fc_snprintf(buffer2, sizeof(buffer2), "path.turns_%d00", i);
3572 SET_SPRITE_ALT_OPT(path.s[GTS_MP_LEFT].turns_hundreds[i], buffer2,
3573 buffer);
3575 SET_GOTO_TURN_SPRITE(GTS_EXHAUSTED_MP, "exhausted_mp", 00, _hundreds);
3576
3577 fc_snprintf(buffer, sizeof(buffer), "city.t_food_%d", i);
3578 SET_SPRITE(city.tile_foodnum[i], buffer);
3579 fc_snprintf(buffer, sizeof(buffer), "city.t_shields_%d", i);
3580 SET_SPRITE(city.tile_shieldnum[i], buffer);
3581 fc_snprintf(buffer, sizeof(buffer), "city.t_trade_%d", i);
3582 SET_SPRITE(city.tile_tradenum[i], buffer);
3583 }
3584#undef SET_GOTO_TURN_SPRITE
3585
3586 /* Must have at least one upkeep sprite per output type (and unhappy) */
3587 /* The rest are optional; we copy the previous sprite for unspecified ones */
3588 fc_strlcpy(buffer, "upkeep.unhappy", sizeof(buffer));
3589 SET_SPRITE(upkeep.unhappy[0], buffer);
3590 for (i = 1; i < MAX_NUM_UPKEEP_SPRITES; i++) {
3591 fc_snprintf(buffer2, sizeof(buffer2), "upkeep.unhappy%d", i+1);
3592 if (sprite_exists(t, buffer2)) {
3593 SET_SPRITE(upkeep.unhappy[i], buffer2);
3594 fc_strlcpy(buffer, buffer2, sizeof(buffer));
3595 } else {
3596 SET_SPRITE(upkeep.unhappy[i], buffer);
3597 }
3598 }
3600 fc_snprintf(buffer, sizeof(buffer),
3601 "upkeep.%s", get_output_identifier(o));
3602 SET_SPRITE_OPT(upkeep.output[o][0], buffer);
3603 for (i = 1; i < MAX_NUM_UPKEEP_SPRITES; i++) {
3604 fc_snprintf(buffer2, sizeof(buffer2),
3605 "upkeep.%s%d", get_output_identifier(o), i+1);
3606 if (sprite_exists(t, buffer2)) {
3607 SET_SPRITE(upkeep.output[o][i], buffer2);
3608 fc_strlcpy(buffer, buffer2, sizeof(buffer));
3609 } else {
3610 /* Optional, as maybe the upkeep 1 sprite didn't exist either */
3611 SET_SPRITE_OPT(upkeep.output[o][i], buffer);
3612 }
3613 }
3615
3617
3618 SET_SPRITE(user.attention, "user.attention");
3619 SET_SPRITE(user.infratile, "user.infratile");
3620
3621 SET_SPRITE_OPT(path.s[GTS_MP_LEFT].specific, "path.normal");
3622 SET_SPRITE_OPT(path.s[GTS_EXHAUSTED_MP].specific, "path.exhausted_mp");
3623 SET_SPRITE_OPT(path.s[GTS_TURN_STEP].specific, "path.step");
3624 SET_SPRITE(path.waypoint, "path.waypoint");
3625
3626 SET_SPRITE_NOTSMOOTH(tx.fog, "tx.fog");
3627
3629 for (i = 0; ; i++) {
3630 struct sprite *sprite;
3631
3632 fc_snprintf(buffer, sizeof(buffer), "colors.overlay_%d", i);
3633 sprite = load_sprite(t, buffer, TRUE, TRUE, FALSE);
3634 if (!sprite) {
3635 break;
3636 }
3638 }
3639 if (i == 0) {
3641 _("Missing overlay-color sprite colors.overlay_0."));
3642 }
3643
3644 /* Chop up and build the overlay graphics. */
3649 for (i = 0; i < sprite_vector_size(&t->sprites.colors.overlays); i++) {
3650 struct sprite *color, *color_mask;
3651 struct sprite *worked, *unworked;
3652
3654 color_mask = crop_sprite(color, 0, 0, W, H, t->sprites.mask.tile, 0, 0,
3655 1.0f, FALSE);
3656 worked = crop_sprite(color_mask, 0, 0, W, H,
3657 t->sprites.mask.worked_tile, 0, 0, 1.0f, FALSE);
3658 unworked = crop_sprite(color_mask, 0, 0, W, H,
3659 t->sprites.mask.unworked_tile, 0, 0, 1.0f, FALSE);
3661 t->sprites.city.worked_tile_overlay.p[i] = worked;
3663 }
3664
3665
3666 {
3667 SET_SPRITE(grid.unavailable, "grid.unavailable");
3668 SET_SPRITE_OPT(grid.nonnative, "grid.nonnative");
3669
3670 for (i = 0; i < EDGE_COUNT; i++) {
3671 int be;
3672
3673 if (i == EDGE_UD && t->hex_width == 0) {
3674 continue;
3675 } else if (i == EDGE_LR && t->hex_height == 0) {
3676 continue;
3677 }
3678
3679 fc_snprintf(buffer, sizeof(buffer), "grid.main.%s", edge_name[i]);
3680 SET_SPRITE(grid.main[i], buffer);
3681
3682 fc_snprintf(buffer, sizeof(buffer), "grid.city.%s", edge_name[i]);
3683 SET_SPRITE(grid.city[i], buffer);
3684
3685 fc_snprintf(buffer, sizeof(buffer), "grid.worked.%s", edge_name[i]);
3686 SET_SPRITE(grid.worked[i], buffer);
3687
3688 fc_snprintf(buffer, sizeof(buffer), "grid.selected.%s", edge_name[i]);
3689 SET_SPRITE(grid.selected[i], buffer);
3690
3691 fc_snprintf(buffer, sizeof(buffer), "grid.coastline.%s", edge_name[i]);
3692 SET_SPRITE(grid.coastline[i], buffer);
3693
3694 for (be = 0; be < 2; be++) {
3695 fc_snprintf(buffer, sizeof(buffer), "grid.borders.%c",
3696 edge_name[i][be]);
3697 SET_SPRITE(grid.borders[i][be], buffer);
3698 }
3699 }
3700 }
3701
3702 switch (t->darkness_style) {
3703 case DARKNESS_NONE:
3704 /* Nothing. */
3705 break;
3706 case DARKNESS_ISORECT:
3707 {
3708 /* Isometric: take a single tx.darkness tile and split it into 4. */
3709 struct sprite *darkness = load_sprite(t, "tx.darkness",
3710 TRUE, FALSE, FALSE);
3711 const int ntw = t->normal_tile_width, nth = t->normal_tile_height;
3712 int offsets[4][2] = {{ntw / 2, 0}, {0, nth / 2}, {ntw / 2, nth / 2}, {0, 0}};
3713
3714 if (!darkness) {
3716 _("Sprite tx.darkness missing."));
3717 }
3718 for (i = 0; i < 4; i++) {
3719 t->sprites.tx.darkness[i] = crop_sprite(darkness, offsets[i][0],
3720 offsets[i][1], ntw / 2,
3721 nth / 2, NULL, 0, 0, 1.0f,
3722 FALSE);
3723 }
3724 }
3725 break;
3727 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
3728 enum direction8 dir = t->cardinal_tileset_dirs[i];
3729
3730 fc_snprintf(buffer, sizeof(buffer), "tx.darkness_%s",
3732 SET_SPRITE_NOTSMOOTH(tx.darkness[i], buffer);
3733 }
3734 break;
3735 case DARKNESS_CARD_FULL:
3736 for (i = 1; i < t->num_index_cardinal; i++) {
3737 fc_snprintf(buffer, sizeof(buffer), "tx.darkness_%s",
3738 cardinal_index_str(t, i));
3739 SET_SPRITE_NOTSMOOTH(tx.darkness[i], buffer);
3740 }
3741 break;
3742 case DARKNESS_CORNER:
3744 81 * sizeof(*t->sprites.tx.fullfog));
3745 for (i = 0; i < 81; i++) {
3746 /* Unknown, fog, known. */
3747 char ids[] = {'u', 'f', 'k'};
3748 char buf[512] = "t.fog";
3749 int values[4], vi, k = i;
3750
3751 for (vi = 0; vi < 4; vi++) {
3752 values[vi] = k % 3;
3753 k /= 3;
3754
3755 cat_snprintf(buf, sizeof(buf), "_%c", ids[values[vi]]);
3756 }
3757 fc_assert(k == 0);
3758
3760 }
3761 break;
3762 };
3763
3764 /* No other place to initialize these variables */
3767}
3768
3769/************************************************************************/
3772static bool load_river_sprites(struct tileset *t,
3773 struct river_sprites *store, const char *tag_pfx)
3774{
3775 int i;
3776 char buffer[512];
3777
3778 for (i = 0; i < t->num_index_cardinal; i++) {
3779 fc_snprintf(buffer, sizeof(buffer), "%s_s_%s",
3781 store->spec[i] = anim_load(t, buffer, 0);
3782 if (store->spec[i] == nullptr) {
3783 return FALSE;
3784 }
3785 }
3786
3787 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
3788 fc_snprintf(buffer, sizeof(buffer), "%s_outlet_%s",
3790 store->outlet[i] = anim_load(t, buffer, 0);
3791 if (store->outlet[i] == nullptr) {
3792 log_error("Missing \"%s\" for \"%s\".", buffer, tag_pfx);
3793 return FALSE;
3794 }
3795 }
3796
3797 return TRUE;
3798}
3799
3800/************************************************************************/
3807{
3809 if (sf->big_sprite) {
3810 free_sprite(sf->big_sprite);
3811 sf->big_sprite = NULL;
3812 }
3814}
3815
3816/************************************************************************/
3827
3828/************************************************************************/
3834 enum log_level level,
3835 const char *tag, const char *alt,
3836 const char *alt2,
3837 const char *what, const char *name,
3838 bool scale)
3839{
3840 struct sprite *sp;
3841
3842 /* (Should get sprite_hash before connection) */
3844 "attempt to lookup for %s \"%s\" before "
3845 "sprite_hash setup", what, name);
3846
3847 sp = load_sprite(t, tag, scale, TRUE, FALSE);
3848 if (sp) return sp;
3849
3850 sp = load_sprite(t, alt, scale, TRUE, FALSE);
3851 if (sp) {
3852 log_verbose("Using alternate graphic \"%s\" "
3853 "(instead of \"%s\") for %s \"%s\".",
3854 alt, tag, what, name);
3855 return sp;
3856 }
3857
3858 if (alt2 != NULL) {
3859 sp = load_sprite(t, alt2, scale, TRUE, FALSE);
3860 if (sp) {
3861 log_verbose("Using second alternate graphic \"%s\" "
3862 "(instead of \"%s\" or \"%s\") for %s \"%s\".",
3863 alt2, tag, alt, what, name);
3864 return sp;
3865 }
3866 }
3867
3869 _("Don't have graphics tags \"%s\" or \"%s\" for %s \"%s\"."),
3870 tag, alt, what, name);
3871
3872 return NULL;
3873}
3874
3875/************************************************************************/
3880 int uidx,
3881 const char *base_str,
3882 enum direction8 dir,
3883 enum unit_activity activity,
3884 bool has_icon)
3885{
3886 enum direction8 loaddir = dir;
3887 char buf[2048];
3888 const char *act_name = unit_activity_name(activity);
3889
3890 if (act_name == nullptr) {
3891 /* gcc-9 thinks this is possible. */
3892 return FALSE;
3893 }
3894
3895 /*
3896 * There may be more orientations available in this tileset than are
3897 * needed, if an oriented unit set has been reused between tilesets.
3898 *
3899 * Don't bother loading unused ones, unless they might be used by
3900 * unit_default_orientation (logic here mirrors get_unittype_sprite()).
3901 */
3902 if (!(dir == t->unit_default_orientation && !has_icon)
3903 && !is_valid_tileset_dir(t, dir)) {
3904 /* Instead we copy a nearby valid dir's sprite, so we're not caught
3905 * out in case this tileset is used with an incompatible topology,
3906 * although it'll be ugly. */
3907 do {
3909 /* This loop _should_ terminate... */
3911 } while (!is_valid_tileset_dir(t, loaddir));
3912 }
3913
3914 fc_snprintf(buf, sizeof(buf), "%s_%s_%s", base_str,
3916
3917 /* We don't use _alt graphics here, as that could lead to loading
3918 * real icon gfx, but alternative orientation gfx. Tileset author
3919 * probably meant icon gfx to be used as fallback for all orientations */
3920 t->sprites.units.facing[uidx][dir][activity] = anim_load(t, buf, 0);
3921
3922 if (activity == ACTIVITY_IDLE
3923 && t->sprites.units.facing[uidx][dir][activity] == nullptr) {
3924 /* Backward compatibility: Set Idle sprite from tag with no activity defined. */
3925 fc_snprintf(buf, sizeof(buf), "%s_%s", base_str,
3927
3928 t->sprites.units.facing[uidx][dir][activity] = anim_load(t, buf, 0);
3929 }
3930
3931 if (t->sprites.units.facing[uidx][dir][activity] != nullptr) {
3932 return TRUE;
3933 }
3934
3935 return FALSE;
3936}
3937
3938/************************************************************************/
3942 int uidx,
3943 const char *tag)
3944{
3946
3947 activity_type_iterate(activity) {
3948 char buffer[2048];
3949
3950 fc_snprintf(buffer, sizeof(buffer), "%s_%s",
3951 tag, unit_activity_name(activity));
3952 t->sprites.units.icon[uidx][activity] = anim_load(t, buffer, 0);
3953
3954 if (activity == ACTIVITY_IDLE
3955 && t->sprites.units.icon[uidx][activity] == nullptr) {
3956 /* Backward compatibility: Set Idle sprite from tag with no activity defined. */
3957 t->sprites.units.icon[uidx][activity] = anim_load(t, tag, 0);
3958 }
3960
3961 has_icon = t->sprites.units.icon[uidx][ACTIVITY_IDLE] != nullptr;
3962
3963#define LOAD_FACING_SPRITE(dir) \
3964 if (!tileset_setup_unit_direction(t, uidx, tag, dir, activity, has_icon)) { \
3965 facing_sprites[activity] = FALSE; \
3966 }
3967
3968 activity_type_iterate(activity) {
3969 facing_sprites[activity] = TRUE;
3970
3979
3981
3983 /* Neither icon gfx or orientation sprites */
3984 return FALSE;
3985 }
3986
3987 return TRUE;
3988
3989#undef LOAD_FACING_SPRITE
3990}
3991
3992/************************************************************************/
3997{
3998 int uidx = utype_index(ut);
3999
4000 if (!tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_str)
4001 && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt)
4002 && !tileset_setup_unit_type_from_tag(t, uidx, ut->graphic_alt2)) {
4004 _("Missing %s unit sprites for tags \"%s\" and alternatives "
4005 "\"%s\" and \"%s\"."),
4006 utype_rule_name(ut), ut->graphic_str,
4007 ut->graphic_alt, ut->graphic_alt2);
4008 }
4009
4010 if (!t->sprites.units.icon[uidx][ACTIVITY_IDLE]) {
4013 _("Unit type %s has no unoriented sprites and "
4014 "tileset has no unit_default_orientation."),
4016 } else {
4017 /* We're guaranteed to have an oriented sprite corresponding to
4018 * unit_default_orientation, because tileset_setup_unit_type_from_tag()
4019 * checked for this. */
4021 != nullptr);
4022 }
4023 }
4024}
4025
4026/************************************************************************/
4031 struct impr_type *pimprove)
4032{
4033 t->sprites.building[improvement_index(pimprove)]
4035 pimprove->graphic_alt, pimprove->graphic_alt2,
4036 "improvement",
4037 improvement_rule_name(pimprove), FALSE);
4038
4039 /* Should maybe do something if NULL, eg generic default? */
4040}
4041
4042/************************************************************************/
4047 struct advance *padvance)
4048{
4049 if (valid_advance(padvance)) {
4052 padvance->graphic_alt, NULL, "technology",
4054
4055 /* Should maybe do something if NULL, eg generic default? */
4056 } else {
4058 }
4059}
4060
4061/************************************************************************/
4066 struct extra_type *pextra)
4067{
4068 const int id = extra_index(pextra);
4069 enum extrastyle_id extrastyle;
4070
4071 if (!fc_strcasecmp(pextra->graphic_str, "none")) {
4072 /* Extra without graphics */
4074 } else {
4075 const char *tag;
4076
4077 tag = pextra->graphic_str;
4078 if (!estyle_hash_lookup(t->estyle_hash, tag, &extrastyle)) {
4079 tag = pextra->graphic_alt;
4080 if (!estyle_hash_lookup(t->estyle_hash, tag, &extrastyle)) {
4082 _("No extra style for \"%s\" or \"%s\"."),
4083 pextra->graphic_str,
4084 pextra->graphic_alt);
4085 } else {
4086 log_verbose("Using alternate graphic \"%s\" "
4087 "(instead of \"%s\") for extra \"%s\".",
4088 pextra->graphic_alt, pextra->graphic_str,
4089 extra_rule_name(pextra));
4090 }
4091 }
4092
4093 t->sprites.extras[id].extrastyle = extrastyle;
4094
4095 extra_type_list_append(t->style_lists[extrastyle], pextra);
4096
4097 if (extra_has_flag(pextra, EF_SHOW_FLAG)) {
4099 }
4100
4101 switch (extrastyle) {
4102 case ESTYLE_3LAYER:
4103 tileset_setup_base(t, pextra, tag);
4104 break;
4105
4109 case ESTYLE_RIVER:
4110 tileset_setup_road(t, pextra, tag);
4111 break;
4112
4113 case ESTYLE_SINGLE1:
4114 case ESTYLE_SINGLE2:
4115 SET_ANIM(extras[id].u.single, tag);
4116 break;
4117
4118 case ESTYLE_CARDINALS:
4119 {
4120 int i;
4121 char buffer[512];
4122
4123 /* We use direction-specific irrigation and farmland graphics, if they
4124 * are available. If not, we just fall back to the basic irrigation
4125 * graphics. */
4126 for (i = 0; i < t->num_index_cardinal; i++) {
4127 fc_snprintf(buffer, sizeof(buffer), "%s_%s",
4128 tag, cardinal_index_str(t, i));
4129 t->sprites.extras[id].u.cardinals[i] = anim_load(t, buffer, 0);
4130 if (t->sprites.extras[id].u.cardinals[i] == nullptr) {
4131 t->sprites.extras[id].u.cardinals[i] = anim_load(t, tag, 0);
4132 }
4133 if (t->sprites.extras[id].u.cardinals[i] == nullptr) {
4135 _("No cardinal-style graphics \"%s*\" for "
4136 "extra \"%s\""),
4137 tag, extra_rule_name(pextra));
4138 }
4139 }
4140 }
4141 break;
4142 case ESTYLE_COUNT:
4143 break;
4144 }
4145 }
4146
4147 if (!fc_strcasecmp(pextra->activity_gfx, "none")) {
4149 } else {
4151 TRUE, TRUE, FALSE);
4152 if (t->sprites.extras[id].activity == NULL) {
4154 TRUE, TRUE, FALSE);
4155 }
4156 if (t->sprites.extras[id].activity == NULL) {
4158 TRUE, TRUE, FALSE);
4159 }
4160 if (t->sprites.extras[id].activity == NULL) {
4162 _("Missing %s building activity sprite for tags \"%s\" and alternatives \"%s\" and \"%s\"."),
4163 extra_rule_name(pextra), pextra->activity_gfx,
4164 pextra->act_gfx_alt, pextra->act_gfx_alt2);
4165 }
4166 }
4167
4168 if (!fc_strcasecmp(pextra->rmact_gfx, "none")) {
4169 t->sprites.extras[id].rmact = NULL;
4170 } else {
4171 t->sprites.extras[id].rmact = load_sprite(t, pextra->rmact_gfx,
4172 TRUE, TRUE, FALSE);
4173 if (t->sprites.extras[id].rmact == NULL) {
4175 TRUE, TRUE, FALSE);
4176 if (t->sprites.extras[id].rmact == NULL) {
4178 TRUE, TRUE, FALSE);
4179 if (t->sprites.extras[id].rmact == NULL) {
4181 _("Missing %s removal activity sprite for tags \"%s\" "
4182 "and alternatives \"%s\" and \"%s\"."),
4183 extra_rule_name(pextra), pextra->rmact_gfx,
4184 pextra->rmact_gfx_alt, pextra->rmact_gfx_alt2);
4185 }
4186 }
4187 }
4188 }
4189}
4190
4191/************************************************************************/
4195static void tileset_setup_road(struct tileset *t,
4196 struct extra_type *pextra,
4197 const char *tag)
4198{
4199 char full_tag_name[MAX_LEN_NAME + sizeof("_isolated")];
4200 const int id = extra_index(pextra);
4201 int i;
4202 enum extrastyle_id extrastyle = t->sprites.extras[id].extrastyle;
4203
4204 /* Isolated road graphics are used by ESTYLE_ROAD_ALL_SEPARATE and
4205 ESTYLE_ROAD_PARITY_COMBINED. */
4206 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4207 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4209 "%s_isolated", tag);
4210
4211 SET_ANIM(extras[id].u.road.isolated, full_tag_name);
4212 }
4213
4214 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
4215 /* ESTYLE_ROAD_ALL_SEPARATE has just 8 additional sprites for each
4216 * road type: one going off in each direction. */
4217 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4218 enum direction8 dir = t->valid_tileset_dirs[i];
4219 const char *dir_name = dir_get_tileset_name(dir);
4220
4222 "%s_%s", tag, dir_name);
4223
4224 SET_ANIM(extras[id].u.road.ru.dir[i], full_tag_name);
4225 }
4226 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
4227 int num_index = 1 << (t->num_valid_tileset_dirs / 2), j;
4228
4229 /* ESTYLE_ROAD_PARITY_COMBINED has 32 additional sprites for each road
4230 * type: 16 each for cardinal and diagonal directions. Each set
4231 * of 16 provides a NSEW-indexed sprite to provide connectors for
4232 * all rails in the cardinal/diagonal directions. The 0 entry is
4233 * unused (the "isolated" sprite is used instead). */
4234
4235 for (i = 1; i < num_index; i++) {
4236 char c[64] = "", d[64] = "";
4237
4238 for (j = 0; j < t->num_valid_tileset_dirs / 2; j++) {
4239 int value = (i >> j) & 1;
4240
4241 cat_snprintf(c, sizeof(c), "%s%d",
4243 value);
4244 cat_snprintf(d, sizeof(d), "%s%d",
4246 value);
4247 }
4248
4250 "%s_c_%s", tag, c);
4251
4252 SET_ANIM(extras[id].u.road.ru.combo.even[i], full_tag_name);
4253
4255 "%s_d_%s", tag, d);
4256
4257 SET_ANIM(extras[id].u.road.ru.combo.odd[i], full_tag_name);
4258 }
4259 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
4260 /* ESTYLE_ROAD_ALL_COMBINED includes 256 sprites, one for every possibility.
4261 * Just go around clockwise, with all combinations. */
4262 for (i = 0; i < t->num_index_valid; i++) {
4263 char *idx_str = valid_index_str(t, i);
4264
4266 "%s_%s", tag, idx_str);
4267
4268 SET_ANIM(extras[id].u.road.ru.total[i], full_tag_name);
4269 }
4270 } else if (extrastyle == ESTYLE_RIVER) {
4271 if (!load_river_sprites(t, &t->sprites.extras[id].u.road.ru.rivers, tag)) {
4273 _("No river-style graphics \"%s*\" for extra \"%s\""),
4274 tag, extra_rule_name(pextra));
4275 }
4276 } else {
4278 }
4279
4280 /* Corner road graphics are used by ESTYLE_ROAD_ALL_SEPARATE,
4281 * ESTYLE_ROAD_PARITY_COMBINED and ESTYLE_ROAD_ALL_COMBINED. */
4282 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
4283 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED
4284 || extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
4285 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4286 enum direction8 dir = t->valid_tileset_dirs[i];
4287
4288 if (!is_cardinal_tileset_dir(t, dir)) {
4289 const char *dtn = dir_get_tileset_name(dir);
4290
4292 "%s_c_%s", pextra->graphic_str, dtn);
4293
4294 SET_ANIM_OPT(extras[id].u.road.corner[dir], full_tag_name);
4295 }
4296 }
4297 }
4298}
4299
4300/************************************************************************/
4304static void tileset_setup_base(struct tileset *t,
4305 const struct extra_type *pextra,
4306 const char *tag)
4307{
4308 char full_tag_name[MAX_LEN_NAME + sizeof("_fg")];
4309 const int id = extra_index(pextra);
4310
4311 fc_assert_ret(id >= 0 && id < extra_count());
4312
4314 strcat(full_tag_name, "_bg");
4316
4318 strcat(full_tag_name, "_mg");
4320
4322 strcat(full_tag_name, "_fg");
4324
4325 if (t->sprites.extras[id].u.bmf.background == nullptr
4326 && t->sprites.extras[id].u.bmf.middleground == nullptr
4327 && t->sprites.extras[id].u.bmf.foreground == nullptr) {
4328 /* There was an extra style definition but no matching graphics */
4330 _("No graphics with tag \"%s_bg/mg/fg\" for extra \"%s\""),
4331 tag, extra_rule_name(pextra));
4332 }
4333}
4334
4335/************************************************************************/
4340 const struct terrain *pterrain)
4341{
4342 struct drawing_data *draw;
4343 struct sprite *sprite;
4344 char buffer[MAX_LEN_NAME + 20];
4345 int i, l;
4346
4347 if (!drawing_hash_lookup(t->tile_hash, pterrain->graphic_str, &draw)
4348 && !drawing_hash_lookup(t->tile_hash, pterrain->graphic_alt, &draw)
4349 && !drawing_hash_lookup(t->tile_hash, pterrain->graphic_alt2, &draw)) {
4351 _("Terrain \"%s\": no graphic tile \"%s\", \"%s\", or \"%s\"."),
4352 terrain_rule_name(pterrain), pterrain->graphic_str,
4353 pterrain->graphic_alt, pterrain->graphic_alt2);
4354 }
4355
4356 if (draw->init) {
4357 t->sprites.drawing[terrain_index(pterrain)] = draw;
4358 return;
4359 }
4360
4361 /* Set up each layer of the drawing. */
4362 for (l = 0; l < draw->num_layers; l++) {
4363 struct drawing_layer *dlp = &draw->layer[l];
4364 struct tileset_layer *tslp = &t->layers[l];
4365 sprite_vector_init(&dlp->base);
4366 sprite_vector_init(&dlp->allocated);
4367
4368 switch (dlp->sprite_type) {
4369 case CELL_WHOLE:
4370 switch (dlp->match_style) {
4371 case MATCH_NONE:
4372 /* Load whole sprites for this tile. */
4373 for (i = 0; ; i++) {
4374 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s%d",
4375 l, draw->name, i + 1);
4376 sprite = load_sprite(t, buffer, TRUE, FALSE, FALSE);
4377 if (!sprite) {
4378 break;
4379 }
4380 sprite_vector_reserve(&dlp->base, i + 1);
4381 dlp->base.p[i] = sprite;
4382 }
4383 /* Check for base sprite, allowing missing sprites above base */
4384 if (0 == i && 0 == l) {
4385 /* TRANS: 'base' means 'base of terrain gfx', not 'military base' */
4387 _("Missing base sprite for tag \"%s\"."), buffer);
4388 }
4389 break;
4390 case MATCH_SAME:
4391 /* Load 16 cardinally-matched sprites. */
4392 for (i = 0; i < t->num_index_cardinal; i++) {
4393 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_%s",
4394 l, draw->name, cardinal_index_str(t, i));
4395 dlp->match[i]
4396 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4397 NULL, "matched terrain",
4398 terrain_rule_name(pterrain), TRUE);
4399 }
4400 break;
4401 case MATCH_PAIR:
4402 case MATCH_FULL:
4403 fc_assert(FALSE); /* Not yet defined */
4404 break;
4405 };
4406 break;
4407 case CELL_CORNER:
4408 {
4409 const int count = dlp->match_indices;
4410 int number = NUM_CORNER_DIRS;
4411
4412 switch (dlp->match_style) {
4413 case MATCH_NONE:
4414 /* Do nothing */
4415 break;
4416 case MATCH_PAIR:
4417 case MATCH_SAME:
4418 /* N directions (NSEW) * 3 dimensions of matching */
4419 fc_assert(count == 2);
4420 number = NUM_CORNER_DIRS * 2 * 2 * 2;
4421 break;
4422 case MATCH_FULL:
4423 default:
4424 /* N directions (NSEW) * 3 dimensions of matching */
4425 /* could use exp() or expi() here? */
4426 number = NUM_CORNER_DIRS * count * count * count;
4427 break;
4428 };
4429
4430 dlp->cells
4431 = fc_calloc(number, sizeof(*dlp->cells));
4432
4433 for (i = 0; i < number; i++) {
4434 enum direction4 dir = i % NUM_CORNER_DIRS;
4435 int value = i / NUM_CORNER_DIRS;
4436
4437 switch (dlp->match_style) {
4438 case MATCH_NONE:
4439 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c",
4440 l, draw->name, direction4letters[dir]);
4441 dlp->cells[i]
4442 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4443 NULL, "cell terrain",
4444 terrain_rule_name(pterrain), TRUE);
4445 break;
4446 case MATCH_SAME:
4447 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c%d%d%d",
4448 l, draw->name, direction4letters[dir],
4449 (value) & 1, (value >> 1) & 1, (value >> 2) & 1);
4450 dlp->cells[i]
4451 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4452 NULL, "same cell terrain",
4453 terrain_rule_name(pterrain), TRUE);
4454 break;
4455 case MATCH_PAIR:
4456 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s_cell_%c_%c_%c_%c",
4457 l, draw->name, direction4letters[dir],
4458 tslp->match_types[dlp->match_index[(value) & 1]][0],
4459 tslp->match_types[dlp->match_index[(value >> 1) & 1]][0],
4460 tslp->match_types[dlp->match_index[(value >> 2) & 1]][0]);
4461 dlp->cells[i]
4462 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4463 NULL, "cell pair terrain",
4464 terrain_rule_name(pterrain), TRUE);
4465 break;
4466 case MATCH_FULL:
4467 {
4468 int this = dlp->match_index[0];
4469 int n, s, e, w;
4470 int v1, v2, v3;
4471
4472 v1 = dlp->match_index[value % count];
4473 value /= count;
4474 v2 = dlp->match_index[value % count];
4475 value /= count;
4476 v3 = dlp->match_index[value % count];
4477
4478 fc_assert(v1 < count && v2 < count && v3 < count);
4479
4480 /* Assume merged cells. This should be a separate option. */
4481 switch (dir) {
4482 case DIR4_NORTH:
4483 s = this;
4484 w = v1;
4485 n = v2;
4486 e = v3;
4487 break;
4488 case DIR4_EAST:
4489 w = this;
4490 n = v1;
4491 e = v2;
4492 s = v3;
4493 break;
4494 case DIR4_SOUTH:
4495 n = this;
4496 e = v1;
4497 s = v2;
4498 w = v3;
4499 break;
4500 case DIR4_WEST:
4501 default: /* Avoid warnings */
4502 e = this;
4503 s = v1;
4504 w = v2;
4505 n = v3;
4506 break;
4507 };
4508
4509 /* Use first character of match_types,
4510 * already checked for uniqueness. */
4511 fc_snprintf(buffer, sizeof(buffer),
4512 "t.l%d.cellgroup_%c_%c_%c_%c", l,
4513 tslp->match_types[n][0], tslp->match_types[e][0],
4514 tslp->match_types[s][0], tslp->match_types[w][0]);
4515 sprite = load_sprite(t, buffer, TRUE, FALSE, FALSE);
4516
4517 if (sprite) {
4518 /* Crop the sprite to separate this cell. */
4519 int vec_size = sprite_vector_size(&dlp->allocated);
4520
4521 const int W = t->normal_tile_width;
4522 const int H = t->normal_tile_height;
4523 int x[4] = {W / 4, W / 4, 0, W / 2};
4524 int y[4] = {H / 2, 0, H / 4, H / 4};
4525 int xo[4] = {0, 0, -W / 2, W / 2};
4526 int yo[4] = {H / 2, -H / 2, 0, 0};
4527
4528 sprite = crop_sprite(sprite, x[dir], y[dir], W / 2, H / 2,
4529 t->sprites.mask.tile, xo[dir], yo[dir], 1.0f,
4530 FALSE);
4531 /* We allocated new sprite with crop_sprite. Store its
4532 * address so we can free it. */
4533 sprite_vector_reserve(&dlp->allocated, vec_size + 1);
4534 dlp->allocated.p[vec_size] = sprite;
4535 } else {
4536 log_error("Terrain graphics sprite for tag \"%s\" missing.", buffer);
4537 }
4538
4539 dlp->cells[i] = sprite;
4540 }
4541 break;
4542 };
4543 }
4544 }
4545 break;
4546 };
4547 }
4548
4549 /* Try an optional special name */
4550 fc_snprintf(buffer, sizeof(buffer), "t.blend.%s", draw->name);
4551 draw->blender
4553 NULL, "blend terrain",
4554 terrain_rule_name(pterrain), TRUE);
4555
4556 if (draw->blending > 0) {
4557 const int bl = draw->blending - 1;
4558
4559 if (NULL == draw->blender) {
4560 int li = 0;
4561
4562 /* Try an already loaded base */
4563 while (NULL == draw->blender
4564 && li < draw->blending
4565 && 0 < draw->layer[li].base.size) {
4566 draw->blender = draw->layer[li++].base.p[0];
4567 }
4568 }
4569
4570 if (NULL == draw->blender) {
4571 /* Try an unloaded base name */
4572 fc_snprintf(buffer, sizeof(buffer), "t.l%d.%s1", bl, draw->name);
4573 draw->blender
4574 = tiles_lookup_sprite_tag_alt(t, LOG_FATAL, buffer, "",
4575 NULL, "base (blend) terrain",
4576 terrain_rule_name(pterrain), TRUE);
4577 }
4578 }
4579
4580 if (NULL != draw->blender) {
4581 /* Set up blending sprites. This only works in iso-view! */
4582 const int W = t->normal_tile_width;
4583 const int H = t->normal_tile_height;
4584 const int offsets[4][2] = {
4585 {W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}
4586 };
4587 enum direction4 dir = 0;
4588
4589 for (; dir < 4; dir++) {
4590 draw->blend[dir] = crop_sprite(draw->blender, offsets[dir][0],
4591 offsets[dir][1], W / 2, H / 2,
4592 t->sprites.dither_tile, 0, 0, 1.0f,
4593 FALSE);
4594 }
4595 }
4596
4597 draw->init = TRUE;
4598 t->sprites.drawing[terrain_index(pterrain)] = draw;
4599}
4600
4601/************************************************************************/
4606 struct government *gov)
4607{
4610 gov->graphic_alt, NULL, "government",
4612
4613 /* Should probably do something if NULL, eg generic default? */
4614}
4615
4616/************************************************************************/
4621 struct nation_type *nation)
4622{
4623 char *tags[] = {nation->flag_graphic_str,
4624 nation->flag_graphic_alt,
4625 "unknown", NULL};
4626 int i;
4627 struct sprite *flag = NULL, *shield = NULL;
4628 char buf[1024];
4630
4631 for (i = 0; tags[i] && !flag; i++) {
4632 fc_snprintf(buf, sizeof(buf), "f.%s", tags[i]);
4633 flag = load_sprite(t, buf, TRUE, TRUE, svgflag);
4634 }
4635 for (i = 0; tags[i] && !shield; i++) {
4636 fc_snprintf(buf, sizeof(buf), "f.shield.%s", tags[i]);
4637 shield = load_sprite(t, buf, TRUE, TRUE, svgflag);
4638 }
4639 if (!flag || !shield) {
4640 /* Should never get here because of the f.unknown fallback. */
4642 _("Nation %s: no national flag."), nation_rule_name(nation));
4643 }
4644
4646 t->sprites.nation_flag.p[nation_index(nation)] = flag;
4647
4649 t->sprites.nation_shield.p[nation_index(nation)] = shield;
4650}
4651
4652/************************************************************************/
4655struct sprite *get_city_flag_sprite(const struct tileset *t,
4656 const struct city *pcity)
4657{
4659}
4660
4661/************************************************************************/
4664static struct sprite *get_unit_nation_flag_sprite(const struct tileset *t,
4665 const struct unit *punit)
4666{
4667 struct nation_type *pnation = nation_of_unit(punit);
4668
4670 return t->sprites.nation_shield.p[nation_index(pnation)];
4671 } else {
4672 return t->sprites.nation_flag.p[nation_index(pnation)];
4673 }
4674}
4675
4676#define FULL_TILE_X_OFFSET ((t->normal_tile_width - t->full_tile_width) / 2)
4677#define FULL_TILE_Y_OFFSET (t->normal_tile_height - t->full_tile_height)
4678
4679#define ADD_SPRITE(s, draw_fog, x_offset, y_offset) \
4680 (fc_assert(s != NULL), \
4681 sprs->sprite = s, \
4682 sprs->foggable = (draw_fog && t->fogstyle == FOG_AUTO), \
4683 sprs->offset_x = x_offset, \
4684 sprs->offset_y = y_offset, \
4685 sprs++)
4686#define ADD_SPRITE_SIMPLE(s) ADD_SPRITE(s, TRUE, 0, 0)
4687#define ADD_SPRITE_FULL(s) \
4688 ADD_SPRITE(s, TRUE, FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET)
4689
4690#define ADD_ANIM_SPRITE(s, draw_fog, x_offset, y_offset) \
4691 ADD_SPRITE(anim_get_current_frame(s), draw_fog, x_offset, y_offset)
4692#define ADD_ANIM_SPRITE_SIMPLE(s) \
4693 ADD_SPRITE(anim_get_current_frame(s), TRUE, 0, 0)
4694#define ADD_ANIM_FULL(s) \
4695 ADD_SPRITE(anim_get_current_frame(s), TRUE, \
4696 FULL_TILE_X_OFFSET, FULL_TILE_Y_OFFSET)
4697
4698#define ADD_FRAME0_SIMPLE(s) ADD_SPRITE_SIMPLE(s->sprites[0])
4699#define ADD_FRAME0_FULL(s) \
4700 ADD_SPRITE_FULL(s->sprites[0])
4701
4702/************************************************************************/
4709static void build_tile_data(const struct tile *ptile,
4710 struct terrain *pterrain,
4711 struct terrain **tterrain_near,
4713{
4714 enum direction8 dir;
4715
4716 /* Loop over all adjacent tiles. We should have an iterator for this. */
4717 for (dir = 0; dir < 8; dir++) {
4718 struct tile *tile1 = mapstep(&(wld.map), ptile, dir);
4719
4722
4723 if (NULL != terrain1) {
4724 tterrain_near[dir] = terrain1;
4726 continue;
4727 }
4728 log_error("build_tile_data() tile (%d,%d) has no terrain!",
4729 TILE_XY(tile1));
4730 }
4731 /* At the edges of the (known) map, pretend the same terrain continued
4732 * past the edge of the map. */
4733 tterrain_near[dir] = pterrain;
4735 }
4736}
4737
4738/************************************************************************/
4741static int fill_unit_type_sprite_array(const struct tileset *t,
4742 struct drawn_sprite *sprs,
4743 const struct unit_type *putype,
4744 enum unit_activity activity,
4745 enum direction8 facing)
4746{
4747 struct drawn_sprite *save_sprs = sprs;
4748 struct sprite *uspr = get_unittype_sprite(t, putype, activity, facing);
4749
4753
4754 return sprs - save_sprs;
4755}
4756
4757/************************************************************************/
4760static int fill_unit_sprite_array(const struct tileset *t,
4761 struct drawn_sprite *sprs,
4762 const struct unit *punit,
4763 int stack, bool backdrop)
4764{
4765 struct drawn_sprite *save_sprs = sprs;
4766 int ihp;
4767 const struct unit_type *ptype = unit_type_get(punit);
4768
4769 if (backdrop) {
4775 }
4776 } else {
4777 /* Taken care of in the LAYER_BACKGROUND. */
4778 }
4779 }
4780
4781 /* Add the sprite for the unit type. */
4784
4785 if (t->sprites.unit.loaded && unit_transported(punit)) {
4786 ADD_SPRITE_FULL(t->sprites.unit.loaded);
4787 }
4788
4789 if (punit->activity != ACTIVITY_IDLE) {
4790 struct sprite *s = NULL;
4791
4792 switch (punit->activity) {
4793 case ACTIVITY_MINE:
4794 if (punit->activity_target == NULL) {
4795 s = t->sprites.unit.plant;
4796 } else {
4798 }
4799 break;
4800 case ACTIVITY_PLANT:
4801 s = t->sprites.unit.plant;
4802 break;
4803 case ACTIVITY_IRRIGATE:
4804 if (punit->activity_target == NULL) {
4805 s = t->sprites.unit.cultivate;
4806 } else {
4808 }
4809 break;
4810 case ACTIVITY_CULTIVATE:
4811 s = t->sprites.unit.cultivate;
4812 break;
4813 case ACTIVITY_CLEAN:
4815 break;
4816 case ACTIVITY_PILLAGE:
4818 if (s == NULL) {
4819 s = t->sprites.unit.pillage;
4820 }
4821 break;
4822 case ACTIVITY_EXPLORE:
4823 /* Drawn below as the server side agent. */
4824 break;
4825 case ACTIVITY_FORTIFIED:
4826 s = t->sprites.unit.fortified;
4827 break;
4829 s = t->sprites.unit.fortifying;
4830 break;
4831 case ACTIVITY_SENTRY:
4832 s = t->sprites.unit.sentry;
4833 break;
4834 case ACTIVITY_GOTO:
4835 s = t->sprites.unit.go_to;
4836 break;
4837 case ACTIVITY_TRANSFORM:
4838 s = t->sprites.unit.transform;
4839 break;
4840 case ACTIVITY_BASE:
4841 case ACTIVITY_GEN_ROAD:
4843 break;
4844 case ACTIVITY_CONVERT:
4845 s = t->sprites.unit.convert;
4846 break;
4847 default:
4848 break;
4849 }
4850
4851 if (s != NULL) {
4854 }
4855 }
4856
4857 {
4858 struct sprite *s = NULL;
4859 int offset_x = 0;
4860 int offset_y = 0;
4861
4862 switch (punit->ssa_controller) {
4863 case SSA_NONE:
4864 break;
4865 case SSA_AUTOWORKER:
4866 s = t->sprites.unit.auto_worker;
4867 break;
4868 case SSA_AUTOEXPLORE:
4869 s = t->sprites.unit.auto_explore;
4870 /* Specified as an activity in the tileset. */
4873 break;
4874 default:
4875 s = t->sprites.unit.auto_attack;
4876 break;
4877 }
4878
4879 if (s != NULL) {
4880 ADD_SPRITE(s, TRUE,
4883 }
4884 }
4885
4886 if (unit_has_orders(punit)) {
4887 if (punit->orders.repeat) {
4888 ADD_SPRITE_FULL(t->sprites.unit.patrol);
4889 } else if (punit->activity != ACTIVITY_IDLE) {
4890 ADD_SPRITE_SIMPLE(t->sprites.unit.connect);
4891 } else {
4892 ADD_SPRITE(t->sprites.unit.go_to, TRUE,
4895 }
4896 }
4897
4898 if (t->sprites.unit.action_decision_want != nullptr
4900 ADD_ANIM_SPRITE(t->sprites.unit.action_decision_want, TRUE,
4903 }
4904
4906 ADD_SPRITE_FULL(t->sprites.unit.battlegroup[punit->battlegroup]);
4907 }
4908
4909 if (t->sprites.unit.lowfuel
4910 && utype_fuel(ptype)
4911 && punit->fuel == 1
4912 && punit->moves_left <= 2 * SINGLE_MOVE) {
4913 /* Show a low-fuel graphic if the plane has 2 or fewer moves left. */
4914 ADD_SPRITE_FULL(t->sprites.unit.lowfuel);
4915 }
4916 if (t->sprites.unit.tired
4918 && ptype->move_rate > 0) {
4919 /* Show a "tired" graphic if the unit has fewer than one move
4920 * remaining, except for units for which it's full movement. */
4921 ADD_SPRITE_FULL(t->sprites.unit.tired);
4922 }
4923
4924 if (stack == 1 && punit->client.occupied) {
4925 ADD_SPRITE_FULL(t->sprites.unit.stack[0]);
4926 } else if (stack > 1) {
4928 && t->sprites.unit.num_stack_sprites >= stack) {
4929 ADD_SPRITE(t->sprites.unit.stack[stack - 1], FALSE,
4931 } else {
4932 ADD_SPRITE_FULL(t->sprites.unit.stack[0]);
4933 }
4934 }
4935
4936 if (t->sprites.unit.vet_lev[punit->veteran]) {
4938 }
4939
4940 ihp = ((NUM_TILES_HP_BAR-1)*punit->hp) / ptype->hp;
4941 ihp = CLIP(0, ihp, NUM_TILES_HP_BAR-1);
4942 ADD_SPRITE_FULL(t->sprites.unit.hp_bar[ihp]);
4943
4944 return sprs - save_sprs;
4945}
4946
4947/************************************************************************/
4950static int fill_road_corner_sprites(const struct tileset *t,
4951 const struct extra_type *pextra,
4952 struct drawn_sprite *sprs,
4953 bool road, bool *road_near,
4954 bool hider, bool *hider_near)
4955{
4956 struct drawn_sprite *saved_sprs = sprs;
4957 int i;
4958 int extra_idx = extra_index(pextra);
4959
4960 if (is_cardinal_only_road(pextra)) {
4961 return 0;
4962 }
4963
4964 /* Roads going diagonally adjacent to this tile need to be
4965 * partly drawn on this tile. */
4966
4967 /* Draw the corner sprite if:
4968 * - There is a diagonal road (not rail!) between two adjacent tiles.
4969 * - There is no diagonal road (not rail!) that intersects this road.
4970 * The logic is simple: roads are drawn underneath railrods, but are
4971 * not always covered by them (even in the corners!). But if a railroad
4972 * connects two tiles, only the railroad (no road) is drawn between
4973 * those tiles.
4974 */
4975 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
4976 enum direction8 dir = t->valid_tileset_dirs[i];
4977
4978 if (!is_cardinal_tileset_dir(t, dir)) {
4979 /* Draw corner sprites for this non-cardinal direction. */
4980 int cw = (i + 1) % t->num_valid_tileset_dirs;
4981 int ccw
4983 enum direction8 cwdir = t->valid_tileset_dirs[cw];
4985
4986 if (t->sprites.extras[extra_idx].u.road.corner[dir]
4988 && !(hider_near[cwdir] && hider_near[ccwdir]))
4989 && !(road && road_near[dir] && !(hider && hider_near[dir]))) {
4991 }
4992 }
4993 }
4994
4995 return sprs - saved_sprs;
4996}
4997
4998/************************************************************************/
5001static int fill_road_sprite_array(const struct tileset *t,
5002 const struct extra_type *pextra,
5003 struct drawn_sprite *sprs,
5006 struct terrain *tterrain_near[8],
5007 const struct city *pcity)
5008{
5009 struct drawn_sprite *saved_sprs = sprs;
5010 bool road, road_near[8], hider, hider_near[8];
5011 bool land_near[8], hland_near[8];
5012 bool draw_road[8], draw_single_road;
5013 enum direction8 dir;
5014 int extra_idx = -1;
5015 bool cl = FALSE;
5016 enum extrastyle_id extrastyle;
5017 const struct road_type *proad = extra_road_get(pextra);
5018
5019 extra_idx = extra_index(pextra);
5020
5021 extrastyle = t->sprites.extras[extra_idx].extrastyle;
5022
5023 if (extra_has_flag(pextra, EF_CONNECT_LAND)) {
5024 cl = TRUE;
5025 } else {
5026 int i;
5027
5028 for (i = 0; i < 8; i++) {
5029 land_near[i] = FALSE;
5030 }
5031 }
5032
5033 /* Fill some data arrays. rail_near and road_near store whether road/rail
5034 * is present in the given direction. draw_rail and draw_road store
5035 * whether road/rail is to be drawn in that direction. draw_single_road
5036 * and draw_single_rail store whether we need an isolated road/rail to be
5037 * drawn. */
5039
5040 hider = FALSE;
5043 hider = TRUE;
5044 break;
5045 }
5047
5048 if (road && (!pcity || !gui_options.draw_cities) && !hider) {
5050 } else {
5052 }
5053
5054 for (dir = 0; dir < 8; dir++) {
5055 bool roads_exist;
5056
5057 /* Check if there is adjacent road/rail. */
5058 if (!is_cardinal_only_road(pextra)
5059 || is_cardinal_tileset_dir(t, dir)) {
5060 road_near[dir] = FALSE;
5061 extra_type_list_iterate(proad->integrators, iextra) {
5063 road_near[dir] = TRUE;
5064 break;
5065 }
5067 if (cl) {
5068 land_near[dir] = (tterrain_near[dir] != T_UNKNOWN
5070 }
5071 } else {
5072 road_near[dir] = FALSE;
5073 land_near[dir] = FALSE;
5074 }
5075
5076 /* Draw rail/road if there is a connection from this tile to the
5077 * adjacent tile. But don't draw road if there is also a rail
5078 * connection. */
5079 roads_exist = road && (road_near[dir] || land_near[dir]);
5080 draw_road[dir] = roads_exist;
5081 hider_near[dir] = FALSE;
5082 hland_near[dir] = tterrain_near[dir] != T_UNKNOWN
5085 bool hider_dir = FALSE;
5086 bool land_dir = FALSE;
5087
5089 || is_cardinal_tileset_dir(t, dir)) {
5091 hider_near[dir] = TRUE;
5092 hider_dir = TRUE;
5093 }
5094 if (hland_near[dir]
5097 land_dir = TRUE;
5098 }
5099 if (hider_dir || land_dir) {
5101 draw_road[dir] = FALSE;
5102 }
5103 }
5104 }
5106
5107 /* Don't draw an isolated road/rail if there's any connection.
5108 * draw_single_road would be true in the first place only if start tile has road,
5109 * so it will have road connection with any adjacent road tile. We check from real
5110 * existence of road (road_near[dir]) and not from whether road gets drawn (draw_road[dir])
5111 * as latter can be FALSE when road is simply hidden by another one, and we don't want to
5112 * draw single road in that case either. */
5113 if (draw_single_road && road_near[dir]) {
5115 }
5116 }
5117
5118 /* Draw road corners */
5119 sprs
5121
5122 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
5123 /* With ESTYLE_ROAD_ALL_SEPARATE, we simply draw one road for every connection.
5124 * This means we only need a few sprites, but a lot of drawing is
5125 * necessary and it generally doesn't look very good. */
5126 int i;
5127
5128 /* First draw roads under rails. */
5129 if (road) {
5130 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
5131 if (draw_road[t->valid_tileset_dirs[i]]) {
5133 }
5134 }
5135 }
5136 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
5137 /* With ESTYLE_ROAD_PARITY_COMBINED, we draw one sprite for cardinal
5138 * road connections, one sprite for diagonal road connections.
5139 * This means we need about 4x more sprites than in style 0, but up to
5140 * 4x less drawing is needed. The drawing quality may also be
5141 * improved. */
5142
5143 /* First draw roads under rails. */
5144 if (road) {
5145 int road_even_tileno = 0, road_odd_tileno = 0, i;
5146
5147 for (i = 0; i < t->num_valid_tileset_dirs / 2; i++) {
5148 enum direction8 even = t->valid_tileset_dirs[2 * i];
5149 enum direction8 odd = t->valid_tileset_dirs[2 * i + 1];
5150
5151 if (draw_road[even]) {
5152 road_even_tileno |= 1 << i;
5153 }
5154 if (draw_road[odd]) {
5155 road_odd_tileno |= 1 << i;
5156 }
5157 }
5158
5159 /* Draw the cardinal/even roads first. */
5160 if (road_even_tileno != 0) {
5162 }
5163 if (road_odd_tileno != 0) {
5165 }
5166 }
5167 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
5168 /* RSTYLE_ALL_COMBINED is a very simple method that lets us simply retrieve
5169 * entire finished tiles, with a bitwise index of the presence of
5170 * roads in each direction. */
5171
5172 /* Draw roads first */
5173 if (road) {
5174 int road_tileno = 0, i;
5175
5176 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
5178
5179 if (draw_road[vdir]) {
5180 road_tileno |= 1 << i;
5181 }
5182 }
5183
5184 if (road_tileno != 0 || draw_single_road) {
5186 }
5187 }
5188 } else {
5190 }
5191
5192 /* Draw isolated rail/road separately (ESTYLE_ROAD_ALL_SEPARATE and
5193 ESTYLE_ROAD_PARITY_COMBINED only). */
5194 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE
5195 || extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
5196 if (draw_single_road) {
5198 }
5199 }
5200
5201 return sprs - saved_sprs;
5202}
5203
5204/************************************************************************/
5213static int get_irrigation_index(const struct tileset *t,
5214 struct extra_type *pextra,
5216{
5217 int tileno = 0, i;
5218
5219 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5220 enum direction8 dir = t->cardinal_tileset_dirs[i];
5221
5222 if (BV_ISSET(textras_near[dir], extra_index(pextra))) {
5223 tileno |= 1 << i;
5224 }
5225 }
5226
5227 return tileno;
5228}
5229
5230/************************************************************************/
5233static int fill_irrigation_sprite_array(const struct tileset *t,
5234 struct drawn_sprite *sprs,
5237 const struct city *pcity)
5238{
5239 struct drawn_sprite *saved_sprs = sprs;
5240
5241 /* We don't draw the irrigation if there's a city (it just gets overdrawn
5242 * anyway, and ends up looking bad). */
5243 if (!(pcity && gui_options.draw_cities)) {
5245 if (is_extra_drawing_enabled(pextra)) {
5246 int eidx = extra_index(pextra);
5247
5248 if (BV_ISSET(textras, eidx)) {
5249 bool hidden = FALSE;
5250
5251 extra_type_list_iterate(pextra->hiders, phider) {
5253 hidden = TRUE;
5254 break;
5255 }
5257
5258 if (!hidden) {
5259 int idx = get_irrigation_index(t, pextra, textras_near);
5260
5262 }
5263 }
5264 }
5266 }
5267
5268 return sprs - saved_sprs;
5269}
5270
5271/************************************************************************/
5275static int fill_city_overlays_sprite_array(const struct tileset *t,
5276 struct drawn_sprite *sprs,
5277 const struct tile *ptile,
5278 const struct city *citymode)
5279{
5280 const struct city *pcity;
5281 const struct city *pwork;
5282 struct unit *psettler;
5283 struct drawn_sprite *saved_sprs = sprs;
5284 int city_x, city_y;
5285 const int NUM_CITY_COLORS = t->sprites.city.worked_tile_overlay.size;
5286
5287 if (NULL == ptile || TILE_UNKNOWN == client_tile_get_known(ptile)) {
5288 return 0;
5289 }
5290 pwork = tile_worked(ptile);
5291
5292 if (citymode) {
5293 pcity = citymode;
5294 } else {
5296 }
5297
5298 /* Below code does not work if pcity is invisible.
5299 * Make sure it is not. */
5300 fc_assert_ret_val(pcity == NULL || pcity->tile != NULL, 0);
5301 if (pcity && !pcity->tile) {
5302 pcity = NULL;
5303 }
5304
5305 if (pcity && city_base_to_city_map(&city_x, &city_y, pcity, ptile)) {
5306 /* FIXME: check elsewhere for valid tile (instead of above) */
5307
5308 if (!citymode && pcity->client.colored) {
5309 /* Add citymap overlay for a city. */
5311
5312 if (NULL != pwork && pwork == pcity) {
5314 } else if (city_can_work_tile(pcity, ptile)) {
5316 }
5317 } else if (NULL != pwork && pwork == pcity
5319
5320 /* Add on the tile output sprites.
5321 * NOTE: To show correct output on end of turn
5322 * base_city_celebrating() must be used instead of city_celebrating()
5323 * mirroring the behavior of the server that does so in
5324 * city_tile_cache_update(). */
5326 int food = city_tile_output(pcity, ptile, celebrating, O_FOOD);
5327 int shields = city_tile_output(pcity, ptile, celebrating, O_SHIELD);
5328 int trade = city_tile_output(pcity, ptile, celebrating, O_TRADE);
5329
5330 const int ox = t->type == TS_ISOMETRIC ? t->normal_tile_width / 3 : 0;
5331 const int oy = t->type == TS_ISOMETRIC ? -t->normal_tile_height / 3 : 0;
5332
5333 food = CLIP(0, food / game.info.granularity, NUM_TILES_DIGITS - 1);
5334 shields = CLIP(0, shields / game.info.granularity, NUM_TILES_DIGITS - 1);
5335 trade = CLIP(0, trade / game.info.granularity, NUM_TILES_DIGITS - 1);
5336
5338 ADD_SPRITE(t->sprites.city.tile_shieldnum[shields], TRUE, ox, oy);
5340 }
5341 } else if (psettler && psettler->client.colored) {
5342 /* Add citymap overlay for a unit. */
5343 int idx = psettler->client.color_index % NUM_CITY_COLORS;
5344
5346 }
5347
5348 return sprs - saved_sprs;
5349}
5350
5351/************************************************************************/
5355static int fill_terrain_sprite_blending(const struct tileset *t,
5356 struct drawn_sprite *sprs,
5357 const struct tile *ptile,
5358 const struct terrain *pterrain,
5359 struct terrain **tterrain_near)
5360{
5361 struct drawn_sprite *saved_sprs = sprs;
5362 const int W = t->normal_tile_width, H = t->normal_tile_height;
5363 const int offsets[4][2] = {
5364 {W/2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}
5365 };
5366 enum direction4 dir = 0;
5367
5368 /*
5369 * We want to mark unknown tiles so that an unreal tile will be
5370 * given the same marking as our current tile - that way we won't
5371 * get the "unknown" dither along the edge of the map.
5372 */
5373 for (; dir < 4; dir++) {
5374 struct tile *tile1 = mapstep(&(wld.map), ptile, DIR4_TO_DIR8[dir]);
5375 struct terrain *other;
5376
5377 if (!tile1
5379 || pterrain == (other = tterrain_near[DIR4_TO_DIR8[dir]])
5380 || (0 == t->sprites.drawing[terrain_index(other)]->blending
5381 && NULL == t->sprites.drawing[terrain_index(other)]->blender)) {
5382 continue;
5383 }
5384
5386 offsets[dir][0], offsets[dir][1]);
5387 }
5388
5389 return sprs - saved_sprs;
5390}
5391
5392/************************************************************************/
5395static int fill_fog_sprite_array(const struct tileset *t,
5396 struct drawn_sprite *sprs,
5397 const struct tile *ptile,
5398 const struct tile_edge *pedge,
5399 const struct tile_corner *pcorner)
5400{
5401 struct drawn_sprite *saved_sprs = sprs;
5402
5404 && NULL != ptile
5406 /* With FOG_AUTO, fog is done this way. */
5408 }
5409
5412 int i, tileno = 0;
5413
5414 for (i = 3; i >= 0; i--) {
5415 const int unknown = 0, fogged = 1, known = 2;
5416 int value = -1;
5417
5418 if (!pcorner->tile[i]) {
5419 value = fogged;
5420 } else {
5421 switch (client_tile_get_known(pcorner->tile[i])) {
5422 case TILE_KNOWN_SEEN:
5423 value = known;
5424 break;
5425 case TILE_KNOWN_UNSEEN:
5426 value = fogged;
5427 break;
5428 case TILE_UNKNOWN:
5429 value = unknown;
5430 break;
5431 }
5432 }
5433 fc_assert(value >= 0 && value < 3);
5434
5435 tileno = tileno * 3 + value;
5436 }
5437
5438 if (t->sprites.tx.fullfog[tileno]) {
5440 }
5441 }
5442
5443 return sprs - saved_sprs;
5444}
5445
5446/************************************************************************/
5450 struct drawn_sprite *sprs,
5451 int l, /* layer_num */
5452 const struct tile *ptile,
5453 const struct terrain *pterrain,
5454 struct terrain **tterrain_near,
5455 struct drawing_data *draw)
5456{
5457 struct drawn_sprite *saved_sprs = sprs;
5458 struct drawing_layer *dlp = &draw->layer[l];
5459 int this = dlp->match_index[0];
5460 int that = dlp->match_index[1];
5461 int ox = dlp->offset_x;
5462 int oy = dlp->offset_y;
5463 int i;
5464
5465#define MATCH(dir) \
5466 (t->sprites.drawing[terrain_index(tterrain_near[(dir)])]->num_layers > l \
5467 ? t->sprites.drawing[terrain_index(tterrain_near[(dir)])]->layer[l].match_index[0] \
5468 : -1)
5469
5470 switch (dlp->sprite_type) {
5471 case CELL_WHOLE:
5472 {
5473 switch (dlp->match_style) {
5474 case MATCH_NONE:
5475 {
5476 int count = sprite_vector_size(&dlp->base);
5477
5478 if (count > 0) {
5479 /* Pseudo-random reproducible algorithm to pick a sprite. Use modulo
5480 * to limit the number to a handleable size [0..32000). */
5481 count = fc_randomly(tile_index(ptile) % 32000, count);
5482
5483 if (dlp->is_tall) {
5486 }
5487 ADD_SPRITE(dlp->base.p[count], TRUE, ox, oy);
5488 }
5489 break;
5490 }
5491 case MATCH_SAME:
5492 {
5493 int tileno = 0;
5494
5495 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5496 enum direction8 dir = t->cardinal_tileset_dirs[i];
5497
5498 if (MATCH(dir) == this) {
5499 tileno |= 1 << i;
5500 }
5501 }
5502
5503 if (dlp->is_tall) {
5506 }
5507 ADD_SPRITE(dlp->match[tileno], TRUE, ox, oy);
5508 break;
5509 }
5510 case MATCH_PAIR:
5511 case MATCH_FULL:
5512 fc_assert(FALSE); /* Not yet defined */
5513 break;
5514 };
5515 break;
5516 }
5517 case CELL_CORNER:
5518 {
5519 /* Divide the tile up into four rectangular cells. Each of these
5520 * cells covers one corner, and each is adjacent to 3 different
5521 * tiles. For each cell we pick a sprite based upon the adjacent
5522 * terrains at each of those tiles. Thus, we have 8 different sprites
5523 * for each of the 4 cells (32 sprites total).
5524 *
5525 * These arrays correspond to the direction4 ordering. */
5526 const int W = t->normal_tile_width;
5527 const int H = t->normal_tile_height;
5528 const int iso_offsets[4][2] = {
5529 {W / 4, 0}, {W / 4, H / 2}, {W / 2, H / 4}, {0, H / 4}
5530 };
5531 const int noniso_offsets[4][2] = {
5532 {0, 0}, {W / 2, H / 2}, {W / 2, 0}, {0, H / 2}
5533 };
5534
5535 /* Put corner cells */
5536 for (i = 0; i < NUM_CORNER_DIRS; i++) {
5537 const int count = dlp->match_indices;
5538 int array_index = 0;
5539 enum direction8 dir = dir_ccw(DIR4_TO_DIR8[i]);
5540 int x = (t->type == TS_ISOMETRIC ? iso_offsets[i][0] : noniso_offsets[i][0]);
5541 int y = (t->type == TS_ISOMETRIC ? iso_offsets[i][1] : noniso_offsets[i][1]);
5542 int m[3] = {MATCH(dir_ccw(dir)), MATCH(dir), MATCH(dir_cw(dir))};
5543 struct sprite *s;
5544
5545 /* Synthesize 4 dimensional array? */
5546 switch (dlp->match_style) {
5547 case MATCH_NONE:
5548 /* We have no need for matching, just plug the piece in place. */
5549 break;
5550 case MATCH_SAME:
5551 array_index = array_index * 2 + (m[2] != this);
5552 array_index = array_index * 2 + (m[1] != this);
5553 array_index = array_index * 2 + (m[0] != this);
5554 break;
5555 case MATCH_PAIR:
5556 array_index = array_index * 2 + (m[2] == that);
5557 array_index = array_index * 2 + (m[1] == that);
5558 array_index = array_index * 2 + (m[0] == that);
5559 break;
5560 case MATCH_FULL:
5561 default:
5562 if (count > 0) {
5563 int n[3];
5564 int j;
5565
5566 for (j = 0; j < 3; j++) {
5567 int k;
5568
5569 for (k = 0; k < count; k++) {
5570 n[j] = k; /* Default to last entry */
5571 if (m[j] == dlp->match_index[k]) {
5572 break;
5573 }
5574 }
5575 }
5576 array_index = array_index * count + n[2];
5577 array_index = array_index * count + n[1];
5578 array_index = array_index * count + n[0];
5579 }
5580 break;
5581 };
5582
5584
5585 s = dlp->cells[array_index];
5586 if (s) {
5587 ADD_SPRITE(s, TRUE, x, y);
5588 }
5589 }
5590 break;
5591 }
5592 };
5593#undef MATCH
5594
5595 return sprs - saved_sprs;
5596}
5597
5598/************************************************************************/
5603 struct drawn_sprite *sprs,
5604 const struct tile *ptile,
5605 struct terrain **tterrain_near)
5606{
5607 struct drawn_sprite *saved_sprs = sprs;
5608 int i, tileno;
5609 struct tile *adjc_tile;
5610
5611#define UNKNOWN(dir) \
5612 ((adjc_tile = mapstep(&(wld.map), ptile, (dir))) \
5613 && client_tile_get_known(adjc_tile) == TILE_UNKNOWN)
5614
5615 switch (t->darkness_style) {
5616 case DARKNESS_NONE:
5617 break;
5618 case DARKNESS_ISORECT:
5619 for (i = 0; i < 4; i++) {
5620 const int W = t->normal_tile_width, H = t->normal_tile_height;
5621 int offsets[4][2] = {{W / 2, 0}, {0, H / 2}, {W / 2, H / 2}, {0, 0}};
5622
5623 if (UNKNOWN(DIR4_TO_DIR8[i])) {
5625 offsets[i][0], offsets[i][1]);
5626 }
5627 }
5628 break;
5630 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5631 if (UNKNOWN(t->cardinal_tileset_dirs[i])) {
5633 }
5634 }
5635 break;
5636 case DARKNESS_CARD_FULL:
5637 /* We're looking to find the INDEX_NSEW for the directions that
5638 * are unknown. We want to mark unknown tiles so that an unreal
5639 * tile will be given the same marking as our current tile - that
5640 * way we won't get the "unknown" dither along the edge of the
5641 * map. */
5642 tileno = 0;
5643 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
5644 if (UNKNOWN(t->cardinal_tileset_dirs[i])) {
5645 tileno |= 1 << i;
5646 }
5647 }
5648
5649 if (tileno != 0) {
5651 }
5652 break;
5653 case DARKNESS_CORNER:
5654 /* Handled separately. */
5655 break;
5656 };
5657#undef UNKNOWN
5658
5659 return sprs - saved_sprs;
5660}
5661
5662/************************************************************************/
5667 struct drawn_sprite *sprs,
5668 int layer_num,
5669 const struct tile *ptile,
5670 const struct terrain *pterrain,
5671 struct terrain **tterrain_near)
5672{
5673 struct sprite *sprite;
5674 struct drawn_sprite *saved_sprs = sprs;
5675 struct drawing_data *draw = t->sprites.drawing[terrain_index(pterrain)];
5676 const int l = (draw->is_reversed
5677 ? (draw->num_layers - layer_num - 1) : layer_num);
5678
5680
5681 /* Skip the normal drawing process. */
5682 /* FIXME: this should avoid calling load_sprite since it's slow and
5683 * increases the refcount without limit. */
5684 if (ptile->spec_sprite && (sprite = load_sprite(t, ptile->spec_sprite,
5685 TRUE, FALSE, FALSE))) {
5686 if (l == 0) {
5688 return 1;
5689 } else {
5690 return 0;
5691 }
5692 }
5693
5695 sprs += fill_terrain_sprite_array(t, sprs, l, ptile, pterrain, tterrain_near, draw);
5696
5697 if ((l + 1) == draw->blending) {
5698 sprs += fill_terrain_sprite_blending(t, sprs, ptile, pterrain, tterrain_near);
5699 }
5700 }
5701
5702 return sprs - saved_sprs;
5703}
5704
5705/************************************************************************/
5712{
5713 /* Display an outline for city-builder type units if they are selected,
5714 * and on a tile where a city can be built.
5715 * But suppress the outline if the unit has orders (likely it is in
5716 * transit to somewhere else and this will just slow down redraws). */
5723}
5724
5725/************************************************************************/
5728static int fill_grid_sprite_array(const struct tileset *t,
5729 struct drawn_sprite *sprs,
5730 const struct tile *ptile,
5731 const struct tile_edge *pedge,
5732 const struct tile_corner *pcorner,
5733 const struct unit *punit,
5734 const struct city *pcity,
5735 const struct city *citymode)
5736{
5737 struct drawn_sprite *saved_sprs = sprs;
5738
5739 if (pedge) {
5740 bool known[NUM_EDGE_TILES], city[NUM_EDGE_TILES];
5741 bool unit[NUM_EDGE_TILES], worked[NUM_EDGE_TILES];
5742 int i;
5743 struct unit_list *pfocus_units = get_units_in_focus();
5744
5745 for (i = 0; i < NUM_EDGE_TILES; i++) {
5746 int dummy_x, dummy_y;
5747 const struct tile *tile = pedge->tile[i];
5748 struct player *powner = tile ? tile_owner(tile) : NULL;
5749
5751 unit[i] = FALSE;
5752 if (tile && !citymode) {
5755 struct tile *utile = unit_tile(pfocus_unit);
5756 int radius = game.info.init_city_radius_sq
5758 NULL,
5759 &(const struct req_context) {
5760 .player = unit_owner(pfocus_unit),
5761 .tile = utile,
5762 },
5763 NULL,
5765 );
5766
5767 if (city_tile_to_city_map(&dummy_x, &dummy_y, radius,
5768 utile, tile)) {
5769 unit[i] = TRUE;
5770 break;
5771 }
5772 }
5774 }
5775 worked[i] = FALSE;
5776
5777 city[i] = (tile
5778 && (NULL == powner || NULL == client.conn.playing
5779 || powner == client.conn.playing)
5781 if (city[i]) {
5782 if (citymode) {
5783 /* In citymode, we only draw worked tiles for this city - other
5784 * tiles may be marked as unavailable. */
5785 worked[i] = (tile_worked(tile) == citymode);
5786 } else {
5787 worked[i] = (NULL != tile_worked(tile));
5788 }
5789 }
5790 }
5791
5792 if (mapdeco_is_highlight_set(pedge->tile[0])
5793 || mapdeco_is_highlight_set(pedge->tile[1])) {
5796 && pedge->tile[0] && pedge->tile[1]
5797 && known[0] && known[1]
5798 && (is_ocean_tile(pedge->tile[0])
5799 ^ is_ocean_tile(pedge->tile[1]))) {
5801 } else {
5803 if (worked[0] || worked[1]) {
5805 } else if (city[0] || city[1]) {
5807 } else if (known[0] || known[1]) {
5809 }
5810 }
5812 if (XOR(city[0], city[1])) {
5814 }
5815 if (XOR(unit[0], unit[1])) {
5817 }
5818 }
5819 }
5820
5823 && known[0]
5824 && known[1]) {
5825 struct player *owner0 = tile_owner(pedge->tile[0]);
5826 struct player *owner1 = tile_owner(pedge->tile[1]);
5827
5828 if (owner0 != owner1) {
5829 if (owner0) {
5830 int plrid = player_index(owner0);
5832 [pedge->type][0]);
5833 }
5834 if (owner1) {
5835 int plrid = player_index(owner1);
5837 [pedge->type][1]);
5838 }
5839 }
5840 }
5841 } else if (NULL != ptile && TILE_UNKNOWN != client_tile_get_known(ptile)) {
5842 int cx, cy;
5843
5844 if (citymode
5845 /* Test to ensure valid coordinates? */
5846 && city_base_to_city_map(&cx, &cy, citymode, ptile)
5847 && !client_city_can_work_tile(citymode, ptile)) {
5849 }
5850
5852 bool native = TRUE;
5853 struct unit_list *pfocus_units = get_units_in_focus();
5854
5856 if (!is_native_tile(unit_type_get(pfocus), ptile)) {
5857 native = FALSE;
5858 break;
5859 }
5861
5862 if (!native) {
5863 if (t->sprites.grid.nonnative != NULL) {
5865 } else {
5867 }
5868 }
5869 }
5870 }
5871
5872 return sprs - saved_sprs;
5873}
5874
5875/************************************************************************/
5878static int fill_goto_sprite_array(const struct tileset *t,
5879 struct drawn_sprite *sprs,
5880 const struct tile *ptile,
5881 const struct tile_edge *pedge,
5882 const struct tile_corner *pcorner)
5883{
5884 struct drawn_sprite *saved_sprs = sprs;
5885 struct sprite *sprite;
5886 bool warn = FALSE;
5887 enum goto_tile_state state;
5888 int length;
5889 bool waypoint;
5890
5891 if (goto_tile_state(ptile, &state, &length, &waypoint)) {
5892 if (length >= 0) {
5893 fc_assert(state >= 0);
5894 fc_assert(state < ARRAY_SIZE(t->sprites.path.s));
5895
5896 sprite = t->sprites.path.s[state].specific;
5897 if (sprite != NULL) {
5898 ADD_SPRITE(sprite, FALSE, 0, 0);
5899 }
5900
5901 sprite = t->sprites.path.s[state].turns[length % 10];
5903 if (length >= 10) {
5904 sprite = t->sprites.path.s[state].turns_tens[(length / 10) % 10];
5906 if (length >= 100) {
5907 sprite = t->sprites.path.s[state].turns_hundreds[(length / 100)
5908 % 10];
5909
5910 if (sprite != NULL) {
5912 if (length >= 1000) {
5913 warn = TRUE;
5914 }
5915 } else {
5916 warn = TRUE;
5917 }
5918 }
5919 }
5920 }
5921
5922 if (waypoint) {
5924 }
5925
5926 if (warn) {
5927 /* Warn only once by tileset. */
5928 static char last_reported[256] = "";
5929
5930 if (0 != strcmp(last_reported, t->name)) {
5931 log_normal(_("Tileset \"%s\" doesn't support long goto paths, "
5932 "such as %d. Path not displayed as expected."),
5933 t->name, length);
5935 }
5936 }
5937 }
5938
5939 return sprs - saved_sprs;
5940}
5941
5942/************************************************************************/
5946static bool is_extra_drawing_enabled(struct extra_type *pextra)
5947{
5948 bool no_disable = TRUE; /* Draw if matches no cause */
5949
5950 if (is_extra_caused_by(pextra, EC_IRRIGATION)) {
5952 return TRUE;
5953 }
5954 no_disable = FALSE;
5955 }
5956 if (is_extra_caused_by(pextra, EC_POLLUTION)
5957 || is_extra_caused_by(pextra, EC_FALLOUT)) {
5959 return TRUE;
5960 }
5961 no_disable = FALSE;
5962 }
5963 if (is_extra_caused_by(pextra, EC_MINE)) {
5964 if (gui_options.draw_mines) {
5965 return TRUE;
5966 }
5967 no_disable = FALSE;
5968 }
5969 if (is_extra_caused_by(pextra, EC_RESOURCE)) {
5971 return TRUE;
5972 }
5973 no_disable = FALSE;
5974 }
5975 if (is_extra_removed_by(pextra, ERM_ENTER)) {
5976 if (gui_options.draw_huts) {
5977 return TRUE;
5978 }
5979 no_disable = FALSE;
5980 }
5981 if (is_extra_caused_by(pextra, EC_BASE)) {
5983 return TRUE;
5984 }
5985 no_disable = FALSE;
5986 }
5987 if (is_extra_caused_by(pextra, EC_ROAD)) {
5988 if (gui_options.draw_paths) {
5989 return TRUE;
5990 }
5991 no_disable = FALSE;
5992 }
5993
5994 return no_disable;
5995}
5996
5997/************************************************************************/
6014 struct drawn_sprite *sprs, enum mapview_layer layer,
6015 const struct tile *ptile,
6016 const struct tile_edge *pedge,
6017 const struct tile_corner *pcorner,
6018 const struct unit *punit, const struct city *pcity,
6019 const struct city *citymode,
6020 const struct unit_type *putype)
6021{
6022 int tileno, dir;
6025 struct terrain *tterrain_near[8];
6026 struct terrain *pterrain = nullptr;
6027 struct drawn_sprite *save_sprs = sprs;
6028 struct player *owner = nullptr;
6029 /* Unit drawing is disabled when the view options are turned off,
6030 * but only where we're drawing on the mapview. */
6031 bool do_draw_unit = (punit != nullptr && (gui_options.draw_units
6032 || ptile == nullptr
6034 && unit_is_in_focus(punit))));
6035 bool flagless = (do_draw_unit
6038 && ((do_draw_unit && !flagless)
6039 || (pcity != nullptr && gui_options.draw_cities)
6040 || (ptile != nullptr && !gui_options.draw_terrain)));
6041
6042 if (citymode) {
6043 int count = 0, i, cx, cy;
6044 const struct tile *const *tiles = nullptr;
6045 bool valid = FALSE;
6046
6047 if (ptile) {
6048 tiles = &ptile;
6049 count = 1;
6050 } else if (pcorner) {
6051 tiles = pcorner->tile;
6052 count = NUM_CORNER_TILES;
6053 } else if (pedge) {
6054 tiles = pedge->tile;
6055 count = NUM_EDGE_TILES;
6056 }
6057
6058 for (i = 0; i < count; i++) {
6059 if (tiles[i] && city_base_to_city_map(&cx, &cy, citymode, tiles[i])) {
6060 valid = TRUE;
6061 break;
6062 }
6063 }
6064 if (!valid) {
6065 return 0;
6066 }
6067 }
6068
6069 if (ptile && client_tile_get_known(ptile) != TILE_UNKNOWN) {
6070 textras = *tile_extras(ptile);
6071 pterrain = tile_terrain(ptile);
6072
6073 if (NULL != pterrain) {
6074 if (layer == LAYER_TERRAIN1
6075 || layer == LAYER_TERRAIN2
6076 || layer == LAYER_TERRAIN3
6077 || layer == LAYER_WATER
6078 || layer == LAYER_ROADS) {
6079 build_tile_data(ptile, pterrain, tterrain_near, textras_near);
6080 }
6081 } else {
6082 log_error("fill_sprite_array() tile (%d,%d) has no terrain!",
6083 TILE_XY(ptile));
6084 }
6085 } else {
6087 }
6088
6089 switch (layer) {
6090 case LAYER_BACKGROUND:
6091 /* Set up background color. */
6093 if (do_draw_unit && !flagless) {
6095 } else if (pcity != nullptr && gui_options.draw_cities) {
6097 }
6098 }
6099 if (owner != nullptr) {
6101 } else if (ptile != nullptr && !gui_options.draw_terrain) {
6103 }
6104 break;
6105
6106 case LAYER_TERRAIN1:
6107 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
6108 sprs += fill_terrain_sprite_layer(t, sprs, 0, ptile, pterrain, tterrain_near);
6109 }
6110 break;
6111
6112 case LAYER_DARKNESS:
6113 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
6115 }
6116 break;
6117
6118 case LAYER_TERRAIN2:
6119 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
6120 sprs += fill_terrain_sprite_layer(t, sprs, 1, ptile, pterrain, tterrain_near);
6121 }
6122 break;
6123
6124 case LAYER_TERRAIN3:
6125 if (NULL != pterrain && gui_options.draw_terrain && !solid_bg) {
6127 sprs += fill_terrain_sprite_layer(t, sprs, 2, ptile, pterrain, tterrain_near);
6128 }
6129 break;
6130
6131 case LAYER_WATER:
6132 if (NULL != pterrain) {
6134 && terrain_type_terrain_class(pterrain) == TC_OCEAN) {
6135 for (dir = 0; dir < t->num_cardinal_tileset_dirs; dir++) {
6136 int didx = t->cardinal_tileset_dirs[dir];
6137
6140 int idx = extra_index(priver);
6141
6142 if (BV_ISSET(textras_near[didx], idx)) {
6144 }
6145 }
6147 }
6148 }
6149
6151 pcity);
6152
6156 int idx = extra_index(priver);
6157
6158 if (BV_ISSET(textras, idx)) {
6159 int i;
6160
6161 /* Draw rivers on top of irrigation. */
6162 tileno = 0;
6163 for (i = 0; i < t->num_cardinal_tileset_dirs; i++) {
6165
6167 tileno |= 1 << i;
6168 } else {
6170
6171 if (proad != NULL) {
6172 extra_type_list_iterate(proad->integrators, iextra) {
6174 tileno |= 1 << i;
6175 }
6177 }
6178 }
6179 }
6180
6182 }
6183 }
6185 }
6186 }
6187 break;
6188
6189 case LAYER_ROADS:
6190 if (NULL != pterrain) {
6192 if (is_extra_drawing_enabled(pextra)) {
6193 sprs += fill_road_sprite_array(t, pextra, sprs,
6196 }
6199 if (is_extra_drawing_enabled(pextra)) {
6200 sprs += fill_road_sprite_array(t, pextra, sprs,
6203 }
6206 if (is_extra_drawing_enabled(pextra)) {
6207 sprs += fill_road_sprite_array(t, pextra, sprs,
6210 }
6212 }
6213 break;
6214
6215 case LAYER_SPECIAL1:
6216 if (NULL != pterrain) {
6217 if (ptile) {
6219 if (tile_has_extra(ptile, pextra)
6220 && is_extra_drawing_enabled(pextra)
6221 && t->sprites.extras[extra_index(pextra)].u.bmf.background != nullptr) {
6222 bool hidden = FALSE;
6223
6224 extra_type_list_iterate(pextra->hiders, phider) {
6226 hidden = TRUE;
6227 break;
6228 }
6230
6231 if (!hidden) {
6233 }
6234 }
6236 }
6237
6239 if (BV_ISSET(textras, extra_index(pextra))
6240 && is_extra_drawing_enabled(pextra)) {
6241 bool hidden = FALSE;
6242
6243 extra_type_list_iterate(pextra->hiders, phider) {
6245 hidden = TRUE;
6246 break;
6247 }
6249
6250 if (!hidden) {
6252 }
6253 }
6255 }
6256 break;
6257
6258 case LAYER_GRID1:
6259 if (t->type == TS_ISOMETRIC) {
6261 punit, pcity, citymode);
6262 }
6263 break;
6264
6265 case LAYER_CITY1:
6266 /* City. Some city sprites are drawn later. */
6267 if (pcity && gui_options.draw_cities) {
6272 }
6273 /* For iso-view the city.wall graphics include the full city, whereas
6274 * for non-iso view they are an overlay on top of the base city
6275 * graphic. */
6276 if (t->type == TS_OVERHEAD || pcity->client.walls <= 0) {
6280 }
6281 if (t->type == TS_ISOMETRIC && pcity->client.walls > 0) {
6282 struct city_sprite *cspr = t->sprites.city.wall[pcity->client.walls - 1];
6283 struct sprite *spr = NULL;
6284
6285 if (cspr != NULL) {
6287 }
6288 if (spr == NULL) {
6290 if (cspr != NULL) {
6292 }
6293 }
6294
6295 if (spr != NULL) {
6299 }
6300 }
6305 }
6306 if (t->type == TS_OVERHEAD && pcity->client.walls > 0) {
6307 struct city_sprite *cspr = t->sprites.city.wall[pcity->client.walls - 1];
6308 struct sprite *spr = NULL;
6309
6310 if (cspr != NULL) {
6312 }
6313 if (spr == NULL) {
6315 if (cspr != NULL) {
6317 }
6318 }
6319
6320 if (spr != NULL) {
6322 }
6323 }
6324 if (pcity->client.unhappy) {
6326 }
6327 }
6328 break;
6329
6330 case LAYER_SPECIAL2:
6331 if (NULL != pterrain) {
6332 if (ptile) {
6334 if (tile_has_extra(ptile, pextra)
6335 && is_extra_drawing_enabled(pextra)
6336 && t->sprites.extras[extra_index(pextra)].u.bmf.middleground != nullptr) {
6337 bool hidden = FALSE;
6338
6339 extra_type_list_iterate(pextra->hiders, phider) {
6341 hidden = TRUE;
6342 break;
6343 }
6345
6346 if (!hidden) {
6348 }
6349 }
6351 }
6352
6354 if (BV_ISSET(textras, extra_index(pextra))
6355 && is_extra_drawing_enabled(pextra)) {
6356 bool hidden = FALSE;
6357
6358 extra_type_list_iterate(pextra->hiders, phider) {
6360 hidden = TRUE;
6361 break;
6362 }
6364
6365 if (!hidden) {
6367 }
6368 }
6370 }
6371 break;
6372
6373 case LAYER_UNIT:
6374 case LAYER_FOCUS_UNIT:
6375 if (do_draw_unit && XOR(layer == LAYER_UNIT, unit_is_in_focus(punit))) {
6376 int stack_count = ptile ? unit_list_size(ptile->units) : 0;
6377 bool backdrop = !pcity;
6378
6379 if (ptile && unit_is_in_focus(punit)
6380 && t->sprites.unit.select != nullptr) {
6381 /* Special case for drawing the selection rectangle. The blinking
6382 * unit is handled separately, inside get_drawable_unit(). */
6383 ADD_ANIM_SPRITE(t->sprites.unit.select, TRUE,
6385 }
6386
6387 /* Load more stack number sprites if needed. no_more_stack_sprites guard
6388 * that we don't retry over and over again for every stack,
6389 * when it's not working. */
6390 if (t->sprites.unit.num_stack_sprites < stack_count
6391 && !t->sprites.unit.no_more_stack_sprites) {
6392 t->sprites.unit.stack = fc_realloc(t->sprites.unit.stack,
6393 stack_count * sizeof(struct sprite *));
6394
6395 while (t->sprites.unit.num_stack_sprites < stack_count
6396 && !t->sprites.unit.no_more_stack_sprites) {
6397 struct sprite *spr = load_gfxnumber(t->sprites.unit.num_stack_sprites + 1);
6398
6399 if (spr != NULL) {
6400 t->sprites.unit.stack[t->sprites.unit.num_stack_sprites++] = spr;
6401 } else {
6402 t->sprites.unit.no_more_stack_sprites = TRUE;
6403 t->sprites.unit.stack = fc_realloc(t->sprites.unit.stack,
6404 t->sprites.unit.num_stack_sprites * sizeof(struct sprite *));
6405 }
6406 }
6407 }
6408
6410 } else if (putype != NULL && layer == LAYER_UNIT) {
6411 /* Only the sprite for the unit type. */
6412 /* FIXME: Shouldn't this still get activity and orientation of
6413 * the actual unit? */
6416 }
6417 break;
6418
6419 case LAYER_SPECIAL3:
6420 if (NULL != pterrain) {
6421 if (ptile) {
6422 bool show_flag = FALSE;
6423 struct player *eowner = extra_owner(ptile);
6424
6426 if (is_extra_drawing_enabled(pextra)
6427 && tile_has_extra(ptile, pextra)
6428 && t->sprites.extras[extra_index(pextra)].u.bmf.foreground != nullptr) {
6429 bool hidden = FALSE;
6430
6431 extra_type_list_iterate(pextra->hiders, phider) {
6433 hidden = TRUE;
6434 break;
6435 }
6437
6438 if (!hidden) {
6439 if (t->sprites.extras[extra_index(pextra)].u.bmf.foreground != nullptr) {
6441 }
6442 }
6443 }
6445
6446 /* Show base flag. Not part of previous iteration as
6447 * "extras of ESTYLE_3_LAYER" != "bases" */
6448 if (eowner != NULL) {
6450 if (tile_has_extra(ptile, pextra)) {
6451 bool hidden = FALSE;
6452
6453 extra_type_list_iterate(pextra->hiders, phider) {
6455 hidden = TRUE;
6456 break;
6457 }
6459
6460 if (!hidden) {
6461 show_flag = TRUE;
6462 }
6463 }
6465
6466 if (show_flag) {
6470 }
6471 }
6472 }
6473 }
6474 break;
6475
6476 case LAYER_FOG:
6478 break;
6479
6480 case LAYER_CITY2:
6481 /* City size. Drawing this under fog makes it hard to read. */
6483 bool warn = FALSE;
6484 unsigned int size = city_size_get(pcity);
6485
6489 if (10 <= size) {
6491 % 10], FALSE,
6494 if (100 <= size) {
6495 struct sprite *sprite =
6496 t->sprites.city.size_hundreds[(size / 100) % 10];
6497
6498 if (NULL != sprite) {
6502 } else {
6503 warn = TRUE;
6504 }
6505 if (1000 <= size) {
6506 warn = TRUE;
6507 }
6508 }
6509 }
6510
6511 if (warn) {
6512 /* Warn only once by tileset. */
6513 static char last_reported[256] = "";
6514
6515 if (0 != strcmp(last_reported, t->name)) {
6516 log_normal(_("Tileset \"%s\" doesn't support big cities size, "
6517 "such as %d. Size not displayed as expected."),
6518 t->name, size);
6520 }
6521 }
6522 }
6523 break;
6524
6525 case LAYER_GRID2:
6526 if (t->type == TS_OVERHEAD) {
6528 punit, pcity, citymode);
6529 }
6530 break;
6531
6532 case LAYER_OVERLAYS:
6534 if (mapdeco_is_crosshair_set(ptile)) {
6536 }
6537 break;
6538
6539 case LAYER_CITYBAR:
6540 case LAYER_TILELABEL:
6541 /* Nothing. This is just a placeholder. */
6542 break;
6543
6544 case LAYER_GOTO:
6545 if (ptile && goto_is_active()) {
6547 }
6548 break;
6549
6550 case LAYER_WORKERTASK:
6551 if (citymode != NULL && ptile != NULL) {
6553 if (ptask->ptile == ptile) {
6554 switch (ptask->act) {
6555 case ACTIVITY_MINE:
6556 if (ptask->tgt == NULL) {
6557 ADD_SPRITE(t->sprites.unit.plant,
6560 } else {
6564 }
6565 break;
6566 case ACTIVITY_PLANT:
6567 ADD_SPRITE(t->sprites.unit.plant,
6570 break;
6571 case ACTIVITY_IRRIGATE:
6572 if (ptask->tgt == NULL) {
6573 ADD_SPRITE(t->sprites.unit.cultivate,
6576 } else {
6580 }
6581 break;
6582 case ACTIVITY_CULTIVATE:
6583 ADD_SPRITE(t->sprites.unit.cultivate,
6586 break;
6587 case ACTIVITY_GEN_ROAD:
6588 if (ptask->tgt != NULL) {
6592 }
6593 break;
6594 case ACTIVITY_TRANSFORM:
6595 ADD_SPRITE(t->sprites.unit.transform,
6598 break;
6599 case ACTIVITY_CLEAN:
6600 if (ptask->tgt != NULL) {
6604 }
6605 break;
6606 default:
6607 break;
6608 }
6609 }
6611 }
6612 break;
6613
6614 case LAYER_EDITOR:
6615 if (ptile && editor_is_active()) {
6616 if (editor_tile_is_selected(ptile)) {
6619 }
6620
6621 if (NULL != map_startpos_get(ptile)) {
6622 /* FIXME: Use a more representative sprite. */
6624 }
6625 }
6626 break;
6627
6628 case LAYER_INFRAWORK:
6629 if (ptile != NULL) {
6630 if (ptile->placing != NULL) {
6631 const int id = extra_index(ptile->placing);
6632
6633 if (t->sprites.extras[id].activity != NULL) {
6637 }
6638 }
6639 if (client_infratile() == ptile) {
6641 }
6642 }
6643 break;
6644
6645 case LAYER_COUNT:
6647 break;
6648 }
6649
6650 return sprs - save_sprs;
6651}
6652
6653/************************************************************************/
6657void tileset_setup_city_tiles(struct tileset *t, int style)
6658{
6659 const char *style_name = city_style_rule_name(style);
6660
6661 if (style == game.control.num_city_styles - 1) {
6662 int i;
6663
6664 /* Free old sprites */
6666
6667 for (i = 0; i < NUM_WALL_TYPES; i++) {
6669 t->sprites.city.wall[i] = NULL;
6670 }
6673
6675
6676 t->sprites.city.tile = load_city_sprite(t, "city");
6677
6678 for (i = 0; i < NUM_WALL_TYPES; i++) {
6679 char buffer[256];
6680
6681 fc_snprintf(buffer, sizeof(buffer), "bldg_%d", i);
6682 t->sprites.city.wall[i] = load_city_sprite(t, buffer);
6683 }
6684 t->sprites.city.single_wall = load_city_sprite(t, "wall");
6685
6686 t->sprites.city.occupied = load_city_sprite(t, "occupied");
6687 }
6688
6690 &t->sprites.style_citizen_sets.sets[style],
6691 city_styles[style].citizens_graphic,
6692 style_name, FALSE);
6695 &t->sprites.style_citizen_sets.sets[style],
6696 sp,
6697 city_styles[style].citizens_graphic,
6698 style_name, FALSE);
6700
6701 if (style == game.control.num_city_styles - 1) {
6702 for (style = 0; style < game.control.num_city_styles; style++) {
6703 if (t->sprites.city.tile->styles[style].land_num_thresholds == 0) {
6705 _("City style \"%s\": no city graphics."),
6706 city_style_rule_name(style));
6707 }
6708 if (t->sprites.city.occupied->styles[style].land_num_thresholds == 0) {
6710 _("City style \"%s\": no occupied graphics."),
6711 city_style_rule_name(style));
6712 }
6713 }
6714 }
6715}
6716
6717/************************************************************************/
6723{
6724 if (t->sprites.unit.select != nullptr) {
6725 return 0.1;
6726 } else {
6727 return 0.5;
6728 }
6729}
6730
6731/************************************************************************/
6736{
6737 if (t->sprites.unit.select != nullptr) {
6738 t->sprites.unit.select->time = 0;
6739 } else {
6741 }
6742}
6743
6744/************************************************************************/
6748{
6750}
6751
6752/************************************************************************/
6757{
6758 if (t->sprites.unit.select != nullptr) {
6759 anim_advance_time(t->sprites.unit.select);
6760 } else {
6762 }
6763}
6764
6765/************************************************************************/
6775
6776/************************************************************************/
6779struct unit *get_drawable_unit(const struct tileset *t,
6780 struct tile *ptile,
6781 const struct city *citymode)
6782{
6783 struct unit *punit = find_visible_unit(ptile);
6784
6785 if (punit == NULL) {
6786 return NULL;
6787 }
6788
6790 return NULL;
6791 }
6792
6794 || t->sprites.unit.select != nullptr || focus_unit_state) {
6795 return punit;
6796 } else {
6797 return NULL;
6798 }
6799}
6800
6801/************************************************************************/
6805static void unload_all_sprites(struct tileset *t)
6806{
6807 if (t->sprite_hash != nullptr) {
6809 while (ss->ref_count > 0) {
6811 }
6813 }
6814}
6815
6816/************************************************************************/
6819static void free_all_anims(struct tileset *t)
6820{
6821 if (t->anim_hash != nullptr) {
6822 anim_hash_iterate(t->anim_hash, tag, anim) {
6823 (void)tag;
6824 anim_free(anim);
6826 }
6827}
6828
6829/************************************************************************/
6833{
6834 int i;
6835
6836 log_debug("tileset_free_tiles()");
6837
6839
6841 t->sprites.city.tile = NULL;
6842
6843 for (i = 0; i < NUM_WALL_TYPES; i++) {
6845 t->sprites.city.wall[i] = NULL;
6846 }
6849
6852
6853 if (t->sprite_hash) {
6855 t->sprite_hash = NULL;
6856 }
6857
6858 if (t->sprites.style_citizen_sets.sets != NULL) {
6861 }
6862
6865 if (ss->file) {
6866 free(ss->file);
6867 }
6868 fc_assert(ss->sprite == NULL);
6869 free(ss);
6871
6874 free(sf->file_name);
6875 if (sf->big_sprite) {
6876 free_sprite(sf->big_sprite);
6877 sf->big_sprite = NULL;
6878 }
6879 free(sf);
6881
6886
6891
6892 if (t->sprites.tx.fullfog) {
6893 free(t->sprites.tx.fullfog);
6894 t->sprites.tx.fullfog = NULL;
6895 }
6896
6902
6903 /* Index 0 is 'occupied' or 'default' stack sprite */
6904 for (i = 1; i < t->sprites.unit.num_stack_sprites - 1; i++) {
6905 free_sprite(t->sprites.unit.stack[i]);
6906 }
6907 t->sprites.unit.num_stack_sprites = 0;
6908 if (t->sprites.unit.stack != NULL) {
6909 free(t->sprites.unit.stack);
6910 t->sprites.unit.stack = NULL;
6911 }
6912
6913 free_all_anims(t);
6914 t->sprites.unit.select = nullptr;
6915 t->sprites.unit.action_decision_want = nullptr;
6916
6917 if (t->anim_hash) {
6919 t->anim_hash = nullptr;
6920 }
6921
6923}
6924
6925/************************************************************************/
6928struct sprite *get_spaceship_sprite(const struct tileset *t,
6929 enum spaceship_part part)
6930{
6931 return t->sprites.spaceship[part];
6932}
6933
6934/************************************************************************/
6937static inline const struct citizen_graphic *
6940{
6941 fc_assert_ret_val(set != NULL, NULL);
6942
6943 if (type < CITIZEN_SPECIALIST) {
6945 return &set->citizen[type];
6946 } else {
6948 return &set->specialist[type - CITIZEN_SPECIALIST];
6949 }
6950}
6951
6952/************************************************************************/
6959struct sprite *get_citizen_sprite(const struct tileset *t,
6961 int citizen_index,
6962 const struct city *pcity)
6963{
6964 const struct citizen_graphic *graphic = NULL;
6966
6967 if (pcity != NULL) {
6968 int style = style_of_city(pcity);
6969
6971
6973 type);
6974
6975 gfx_index += pcity->client.first_citizen_index;
6976 }
6977
6978 if (graphic == NULL || graphic->count == 0) {
6979 /* Fall back to default sprites */
6981 }
6982
6983 if (graphic->count == 0) {
6984 return NULL;
6985 }
6986
6987 return graphic->sprite[gfx_index % graphic->count];
6988}
6989
6990/************************************************************************/
6993struct sprite *get_nation_flag_sprite(const struct tileset *t,
6994 const struct nation_type *pnation)
6995{
6996 return t->sprites.nation_flag.p[nation_index(pnation)];
6997}
6998
6999/************************************************************************/
7003 const struct nation_type *pnation)
7004{
7005 return t->sprites.nation_shield.p[nation_index(pnation)];
7006}
7007
7008/************************************************************************/
7011struct sprite *get_tech_sprite(const struct tileset *t, Tech_type_id tech)
7012{
7013 fc_assert_ret_val(0 <= tech && tech < advance_count(), NULL);
7014 return t->sprites.tech[tech];
7015}
7016
7017/************************************************************************/
7020struct sprite *get_building_sprite(const struct tileset *t,
7021 const struct impr_type *pimprove)
7022{
7023 fc_assert_ret_val(NULL != pimprove, NULL);
7024 return t->sprites.building[improvement_index(pimprove)];
7025}
7026
7027/************************************************************************/
7030struct sprite *get_government_sprite(const struct tileset *t,
7031 const struct government *gov)
7032{
7033 fc_assert_ret_val(NULL != gov, NULL);
7034 return t->sprites.government[government_index(gov)];
7035}
7036
7037/************************************************************************/
7042struct sprite *get_unittype_sprite(const struct tileset *t,
7043 const struct unit_type *punittype,
7044 enum unit_activity activity,
7045 enum direction8 facing)
7046{
7047 int uidx = utype_index(punittype);
7048 bool icon = !direction8_is_valid(facing);
7049
7050 if (activity >= ACTIVITY_LAST) {
7051 activity = ACTIVITY_IDLE;
7052 }
7053
7055
7056 if (!direction8_is_valid(facing) || !is_valid_dir(facing)) {
7057 facing = t->unit_default_orientation;
7058 /* May not have been specified, but it only matters if we don't
7059 * turn out to have an icon sprite */
7060 }
7061
7062 if (t->sprites.units.icon[uidx][activity] != nullptr
7063 && (icon || t->sprites.units.facing[uidx][facing][activity] == nullptr)) {
7064 /* Has icon sprite, and we prefer to (or must) use it */
7065 if (icon) {
7066 return t->sprites.units.icon[uidx][activity]->sprites[0];
7067 } else {
7068 return anim_get_current_frame(t->sprites.units.icon[uidx][activity]);
7069 }
7070 } else if (t->sprites.units.icon[uidx][ACTIVITY_IDLE] != nullptr
7071 && (icon
7072 || t->sprites.units.facing[uidx][facing][ACTIVITY_IDLE] == nullptr)) {
7073 /* Has icon sprite, and we prefer to (or must) use it */
7074 if (icon) {
7075 return t->sprites.units.icon[uidx][ACTIVITY_IDLE]->sprites[0];
7076 } else {
7078 }
7079 } else {
7080 /* We should have a valid orientation by now. Failure to have either
7081 * an icon sprite or default orientation should have been caught at
7082 * tileset load. */
7083 fc_assert_ret_val(direction8_is_valid(facing), nullptr);
7084
7085 if (t->sprites.units.facing[uidx][facing][activity] == nullptr) {
7087 }
7088
7089 return anim_get_current_frame(t->sprites.units.facing[uidx][facing][activity]);
7090 }
7091}
7092
7093/************************************************************************/
7096struct sprite *get_sample_city_sprite(const struct tileset *t,
7097 int style_idx)
7098{
7099 int num_thresholds =
7100 t->sprites.city.tile->styles[style_idx].land_num_thresholds;
7101
7102 if (num_thresholds == 0) {
7103 return NULL;
7104 } else {
7105 return (t->sprites.city.tile->styles[style_idx]
7106 .land_thresholds[num_thresholds - 1].sprite);
7107 }
7108}
7109
7110/************************************************************************/
7113struct sprite *get_arrow_sprite(const struct tileset *t,
7114 enum arrow_type arrow)
7115{
7116 fc_assert_ret_val(arrow >= 0 && arrow < ARROW_LAST, NULL);
7117
7118 return t->sprites.arrow[arrow];
7119}
7120
7121/************************************************************************/
7125{
7126 switch (otype) {
7127 case O_SCIENCE:
7128 return t->sprites.tax_science;
7129 case O_GOLD:
7130 return t->sprites.tax_gold;
7131 case O_LUXURY:
7132 return t->sprites.tax_luxury;
7133 case O_TRADE:
7134 case O_FOOD:
7135 case O_SHIELD:
7136 case O_LAST:
7137 break;
7138 }
7139 return NULL;
7140}
7141
7142/************************************************************************/
7145struct sprite *get_event_sprite(const struct tileset *t, enum event_type event)
7146{
7147 return t->sprites.events[event];
7148}
7149
7150/************************************************************************/
7154struct sprite *get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
7155{
7156 return t->sprites.treaty_thumb[on_off ? 1 : 0];
7157}
7158
7159/************************************************************************/
7164 tileset *t)
7165{
7166 return &t->sprites.explode.unit;
7167}
7168
7169/************************************************************************/
7175{
7176 return t->sprites.explode.nuke;
7177}
7178
7179/************************************************************************/
7182const struct citybar_sprites *get_citybar_sprites(const struct tileset *t)
7183{
7185 return &t->sprites.citybar;
7186 } else {
7187 return NULL;
7188 }
7189}
7190
7191/************************************************************************/
7194const struct editor_sprites *get_editor_sprites(const struct tileset *t)
7195{
7196 return &t->sprites.editor;
7197}
7198
7199/************************************************************************/
7205struct sprite *get_cursor_sprite(const struct tileset *t,
7206 enum cursor_type cursor,
7207 int *hot_x, int *hot_y, int frame)
7208{
7209 *hot_x = t->sprites.cursor[cursor].hot_x;
7210 *hot_y = t->sprites.cursor[cursor].hot_y;
7211
7212 return t->sprites.cursor[cursor].frame[frame];
7213}
7214
7215/************************************************************************/
7224struct sprite *get_icon_sprite(const struct tileset *t, enum icon_type icon)
7225{
7226 return t->sprites.icon[icon];
7227}
7228
7229/************************************************************************/
7236{
7237 return t->sprites.user.attention;
7238}
7239
7240/************************************************************************/
7244struct sprite *get_indicator_sprite(const struct tileset *t,
7245 enum indicator_type indicator,
7246 int idx)
7247{
7248 idx = CLIP(0, idx, NUM_TILES_PROGRESS - 1);
7249
7250 fc_assert_ret_val(indicator >= 0 && indicator < INDICATOR_COUNT, NULL);
7251
7252 return t->sprites.indicator[indicator][idx];
7253}
7254
7255/************************************************************************/
7262 const struct unit *punit,
7263 int happy_cost)
7264{
7265 const int unhappy = CLIP(0, happy_cost, MAX_NUM_UPKEEP_SPRITES+1);
7266
7267 if (unhappy > 0) {
7268 return t->sprites.upkeep.unhappy[unhappy - 1];
7269 } else {
7270 return NULL;
7271 }
7272}
7273
7274/************************************************************************/
7280struct sprite *get_unit_upkeep_sprite(const struct tileset *t,
7282 const struct unit *punit,
7283 const int *upkeep_cost)
7284{
7285 const int upkeep = CLIP(0, upkeep_cost[otype], MAX_NUM_UPKEEP_SPRITES + 1);
7286
7287 if (upkeep > 0) {
7288 return t->sprites.upkeep.output[otype][upkeep - 1];
7289 } else {
7290 return NULL;
7291 }
7292}
7293
7294/************************************************************************/
7298struct sprite *get_basic_fog_sprite(const struct tileset *t)
7299{
7300 return t->sprites.tx.fog;
7301}
7302
7303/************************************************************************/
7306struct color_system *get_color_system(const struct tileset *t)
7307{
7308 return t->color_system;
7309}
7310
7311/************************************************************************/
7315{
7316 char *default_theme_name = NULL;
7317 size_t default_theme_name_sz = 0;
7318 int i;
7319
7320 switch (get_gui_type()) {
7321 case GUI_GTK3_22:
7324 break;
7325 case GUI_GTK4:
7328 break;
7329 case GUI_GTK5:
7332 break;
7333 case GUI_SDL2:
7336 break;
7337 case GUI_SDL3:
7340 break;
7341 case GUI_STUB:
7342 case GUI_QT:
7343 case GUI_SDL:
7344 case GUI_WEB:
7345 case GUI_GTK2:
7346 case GUI_GTK3:
7347 break;
7348 }
7349
7351 /* Theme is not supported by this client. */
7352 return;
7353 }
7354
7355 for (i = 0; i < t->num_preferred_themes; i++) {
7358 log_debug("trying theme \"%s\".", t->preferred_themes[i]);
7359 if (load_theme(t->preferred_themes[i])) {
7362 return;
7363 }
7364 }
7365 }
7366 }
7367 log_verbose("The tileset doesn't specify preferred themes or none of its "
7368 "preferred themes can be used. Using system default.");
7370}
7371
7372/************************************************************************/
7375void tileset_init(struct tileset *t)
7376{
7377 int wi;
7378
7379 /* We currently have no city sprites loaded. */
7380 t->sprites.city.tile = NULL;
7381
7382 for (wi = 0; wi < NUM_WALL_TYPES; wi++) {
7383 t->sprites.city.wall[wi] = NULL;
7384 }
7386
7388
7389 t->sprites.background.color = NULL;
7390 t->sprites.background.graphic = NULL;
7391
7392 player_slots_iterate(pslot) {
7393 int edge, j, id = player_slot_index(pslot);
7394
7395 for (edge = 0; edge < EDGE_COUNT; edge++) {
7396 for (j = 0; j < 2; j++) {
7398 }
7399 }
7400
7401 t->sprites.player[id].color = NULL;
7404
7405 t->max_upkeep_height = 0;
7406}
7407
7408/************************************************************************/
7417 struct drawn_sprite *sprs,
7418 int layer,
7419 struct terrain *pterrain)
7420{
7421 struct drawn_sprite *save_sprs = sprs;
7422 struct drawing_data *draw = t->sprites.drawing[terrain_index(pterrain)];
7423
7424 struct terrain *tterrain_near[8];
7426
7427 struct tile dummy_tile; /* :( */
7428
7429 int i;
7430
7431
7432 memset(&dummy_tile, 0, sizeof(struct tile));
7433
7434 for (i = 0; i < 8; i++) {
7435 tterrain_near[i] = pterrain;
7437 }
7438
7439 i = draw->is_reversed ? draw->num_layers - layer - 1 : layer;
7441 pterrain, tterrain_near, draw);
7442
7443 return sprs - save_sprs;
7444}
7445
7446/************************************************************************/
7450 struct drawn_sprite *sprs,
7451 const struct extra_type *pextra)
7452{
7453 int idx = extra_index(pextra);
7454 struct drawn_sprite *saved_sprs = sprs;
7455
7456 switch (t->sprites.extras[idx].extrastyle) {
7457 case ESTYLE_SINGLE1:
7458 case ESTYLE_SINGLE2:
7460 break;
7461 case ESTYLE_CARDINALS:
7463 break;
7467 case ESTYLE_RIVER:
7468 return fill_basic_road_sprite_array(t, sprs, pextra);
7469 case ESTYLE_3LAYER:
7470 return fill_basic_base_sprite_array(t, sprs, pextra);
7471 case ESTYLE_COUNT:
7473 break;
7474 }
7475
7476 return sprs - saved_sprs;
7477}
7478
7479/************************************************************************/
7485 struct drawn_sprite *sprs,
7486 const struct extra_type *pextra)
7487{
7488 struct drawn_sprite *saved_sprs = sprs;
7489 int idx;
7490 int i;
7491 enum extrastyle_id extrastyle;
7492
7493 if (!t || !sprs || !pextra) {
7494 return 0;
7495 }
7496
7497 idx = extra_index(pextra);
7498
7499 if (!(0 <= idx && idx < game.control.num_extra_types)) {
7500 return 0;
7501 }
7502
7503 extrastyle = t->sprites.extras[idx].extrastyle;
7504
7505 if (extrastyle == ESTYLE_RIVER) {
7507 } else {
7508 for (i = 0; i < t->num_valid_tileset_dirs; i++) {
7509 if (!t->valid_tileset_dirs[i]) {
7510 continue;
7511 }
7512 if (extrastyle == ESTYLE_ROAD_ALL_SEPARATE) {
7514 } else if (extrastyle == ESTYLE_ROAD_PARITY_COMBINED) {
7515 if ((i % 2) == 0) {
7516 ADD_FRAME0_SIMPLE(t->sprites.extras[idx].u.road.ru.combo.even[1 << (i / 2)]);
7517 }
7518 } else if (extrastyle == ESTYLE_ROAD_ALL_COMBINED) {
7519 ADD_FRAME0_SIMPLE(t->sprites.extras[idx].u.road.ru.total[1 << i]);
7520 }
7521 }
7522 }
7523
7524 return sprs - saved_sprs;
7525}
7526
7527/************************************************************************/
7533 struct drawn_sprite *sprs,
7534 const struct extra_type *pextra)
7535{
7536 struct drawn_sprite *saved_sprs = sprs;
7537 int idx;
7538
7539 if (!t || !sprs || !pextra) {
7540 return 0;
7541 }
7542
7543 idx = extra_index(pextra);
7544
7545 if (!(0 <= idx && idx < game.control.num_extra_types)) {
7546 return 0;
7547 }
7548
7549#define ADD_FRAME0_IF_NOT_NULL(x) do {\
7550 if ((x) != nullptr) {\
7551 ADD_FRAME0_FULL(x);\
7552 }\
7553} while (FALSE)
7554
7555 /* Corresponds to LAYER_SPECIAL{1,2,3} order. */
7559
7560#undef ADD_FRAME0_IF_NOT_NULL
7561
7562 return sprs - saved_sprs;
7563}
7564
7565/************************************************************************/
7568enum mapview_layer tileset_get_layer(const struct tileset *t, int n)
7569{
7571
7572 return t->layer_order[n];
7573}
7574
7575/************************************************************************/
7579 enum layer_category cat)
7580{
7581 switch (layer) {
7582 case LAYER_BACKGROUND:
7583 case LAYER_TERRAIN1:
7584 case LAYER_DARKNESS:
7585 case LAYER_TERRAIN2:
7586 case LAYER_TERRAIN3:
7587 case LAYER_WATER:
7588 case LAYER_ROADS:
7589 case LAYER_SPECIAL1:
7590 case LAYER_SPECIAL2:
7591 case LAYER_SPECIAL3:
7593 case LAYER_CITY1:
7594 case LAYER_CITY2:
7595 return cat == LAYER_CATEGORY_CITY;
7596 case LAYER_UNIT:
7597 case LAYER_FOCUS_UNIT:
7598 return cat == LAYER_CATEGORY_UNIT;
7599 case LAYER_GRID1:
7600 case LAYER_FOG:
7601 case LAYER_GRID2:
7602 case LAYER_OVERLAYS:
7603 case LAYER_TILELABEL:
7604 case LAYER_CITYBAR:
7605 case LAYER_GOTO:
7606 case LAYER_WORKERTASK:
7607 case LAYER_EDITOR:
7608 case LAYER_INFRAWORK:
7609 return FALSE;
7610 case LAYER_COUNT:
7611 break; /* and fail below */
7612 }
7613
7614 fc_assert_msg(FALSE, "Unknown layer category: %d", cat);
7615 return FALSE;
7616}
7617
7618/************************************************************************/
7621void tileset_player_init(struct tileset *t, struct player *pplayer)
7622{
7623 int plrid, i, j;
7624 struct sprite *color;
7625
7626 fc_assert_ret(pplayer != NULL);
7627
7628 plrid = player_index(pplayer);
7629 fc_assert_ret(plrid >= 0);
7631
7632 /* Free all data before recreating it. */
7634
7635 if (player_has_color(pplayer)) {
7637 = create_plr_sprite(get_player_color(t, pplayer));
7638 } else {
7639 /* XXX: if player hasn't been assigned a color, perhaps there's no
7640 * point proceeding with an arbitrary color; this should only happen
7641 * in pregame. Probably blank sprites would be better. */
7642
7643 fc_assert_ret(t->sprites.background.color != NULL);
7644
7645 color = t->sprites.background.color;
7646 }
7647
7649 = crop_sprite(color, 0, 0,
7651 t->sprites.mask.tile, 0, 0, t->scale, FALSE);
7652
7653 for (i = 0; i < EDGE_COUNT; i++) {
7654 for (j = 0; j < 2; j++) {
7655 struct sprite *s;
7656
7657 if (color && t->sprites.grid.borders[i][j]) {
7658 s = crop_sprite(color, 0, 0,
7660 t->sprites.grid.borders[i][j], 0, 0, 1.0f, FALSE);
7661 } else {
7662 s = t->sprites.grid.borders[i][j];
7663 }
7664 t->sprites.player[plrid].grid_borders[i][j] = s;
7665 }
7666 }
7667}
7668
7669/************************************************************************/
7672static void tileset_player_free(struct tileset *t, int plrid)
7673{
7674 int i, j;
7675
7676 fc_assert_ret(plrid >= 0);
7678
7679 if (t->sprites.player[plrid].color) {
7682 }
7683 if (t->sprites.player[plrid].background) {
7686 }
7687
7688 for (i = 0; i < EDGE_COUNT; i++) {
7689 for (j = 0; j < 2; j++) {
7690 if (t->sprites.player[plrid].grid_borders[i][j]) {
7693 }
7694 }
7695 }
7696}
7697
7698/************************************************************************/
7702{
7703 /* Free all data before recreating it. */
7705
7706 /* Generate background color */
7707 t->sprites.background.color
7709
7710 /* Chop up and build the background graphics. */
7711 t->sprites.background.graphic
7712 = crop_sprite(t->sprites.background.color, 0, 0,
7714 t->sprites.mask.tile, 0, 0, t->scale, FALSE);
7715}
7716
7717/************************************************************************/
7721{
7722 if (t->sprites.background.color) {
7723 free_sprite(t->sprites.background.color);
7724 t->sprites.background.color = NULL;
7725 }
7726
7727 if (t->sprites.background.graphic) {
7728 free_sprite(t->sprites.background.graphic);
7729 t->sprites.background.graphic = NULL;
7730 }
7731}
7732
7733/************************************************************************/
7737{
7738 int i;
7739
7740 for (i = 0; i < ESTYLE_COUNT; i++) {
7741 if (t->style_lists[i] != NULL) {
7744 }
7745 }
7746
7747 if (t->flagged_bases_list != NULL) {
7750 }
7751
7752 if (t->sprites.style_citizen_sets.sets != NULL) {
7754 }
7755
7758 * sizeof(t->sprites.style_citizen_sets.sets[0]));
7759}
7760
7761/************************************************************************/
7765{
7766 return !tileset_update;
7767}
7768
7769/************************************************************************/
7772const char *tileset_name_get(struct tileset *t)
7773{
7774 return t->given_name;
7775}
7776
7777/************************************************************************/
7780const char *tileset_version(struct tileset *t)
7781{
7782 return t->version;
7783}
7784
7785/************************************************************************/
7788const char *tileset_summary(struct tileset *t)
7789{
7790 return t->summary;
7791}
7792
7793/************************************************************************/
7796const char *tileset_description(struct tileset *t)
7797{
7798 return t->description;
7799}
7800
7801/************************************************************************/
7805{
7806 return t->for_ruleset;
7807}
7808
7809/************************************************************************/
7813{
7814 return t->ts_topo_idx;
7815}
7816
7817/************************************************************************/
7821{
7822 return t->svg_height;
7823}
7824
7825/************************************************************************/
7828struct sprite *load_popup_sprite(const char *tag)
7829{
7830 return load_sprite(tileset, tag, TRUE, TRUE, FALSE);
7831}
7832
7833/************************************************************************/
7836void unload_popup_sprite(const char *tag)
7837{
7838 unload_sprite(tileset, tag);
7839}
#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:822
static void road(QVariant data1, QVariant data2)
Definition dialogs.cpp:2944
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
Definition dialogs_g.h:74
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
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:328
#define MAX_NUM_ITEMS
Definition fc_types.h:40
int Tech_type_id
Definition fc_types.h:236
#define SP_MAX
Definition fc_types.h:267
int Specialist_type_id
Definition fc_types.h:234
#define MAX_NUM_PLAYER_SLOTS
Definition fc_types.h:32
#define MAX_EXTRA_TYPES
Definition fc_types.h:50
#define MAX_LEN_NAME
Definition fc_types.h:66
@ O_SHIELD
Definition fc_types.h:101
@ O_FOOD
Definition fc_types.h:101
@ O_TRADE
Definition fc_types.h:101
@ O_SCIENCE
Definition fc_types.h:101
@ O_LUXURY
Definition fc_types.h:101
@ O_GOLD
Definition fc_types.h:101
@ O_LAST
Definition fc_types.h:101
@ BORDERS_DISABLED
Definition fc_types.h:745
enum output_type_id Output_type_id
Definition fc_types.h:237
#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:2078
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:2038
enum direction8 dir_ccw(enum direction8 dir)
Definition map.c:1344
bool is_valid_dir(enum direction8 dir)
Definition map.c:1401
enum direction8 dir_cw(enum direction8 dir)
Definition map.c:1315
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:6937
const char * option_str_get(const struct option *poption)
Definition options.c:944
int option_get_cb_data(const struct option *poption)
Definition options.c:838
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:1927
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_style_threshold * land_thresholds
Definition tilespec.c:218
struct city_sprite::@260 * styles
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:336
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:216
bool draw_specials
Definition options.h:208
bool draw_city_output
Definition options.h:195
char gui_sdl3_default_theme_name[512]
Definition options.h:442
bool draw_mines
Definition options.h:206
bool draw_borders
Definition options.h:215
bool draw_fortress_airbase
Definition options.h:207
bool draw_unit_stack_size
Definition options.h:219
bool draw_irrigation
Definition options.h:205
bool draw_terrain
Definition options.h:202
bool draw_units
Definition options.h:212
int default_topology
Definition options.h:123
bool draw_fog_of_war
Definition options.h:214
bool draw_unit_shields
Definition options.h:218
char gui_sdl2_default_theme_name[512]
Definition options.h:429
bool draw_cities
Definition options.h:211
bool draw_map_grid
Definition options.h:196
bool draw_focus_unit
Definition options.h:213
bool draw_paths
Definition options.h:204
bool draw_city_outlines
Definition options.h:194
bool draw_coastline
Definition options.h:203
bool draw_full_citybar
Definition options.h:217
bool draw_pollution
Definition options.h:210
char gui_gtk5_default_theme_name[512]
Definition options.h:382
char gui_gtk4_default_theme_name[512]
Definition options.h:342
char gui_gtk3_22_default_theme_name[512]
Definition options.h:302
bool solid_color_behind_units
Definition options.h:150
struct client_properties::@230 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 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 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 named_sprites::@272 grid
struct named_sprites::@268 path
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 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
struct named_sprites::@271::@277::@279::@280::@281 combo
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 named_sprites::@271 extras[MAX_EXTRA_TYPES]
struct sprite * turns[NUM_TILES_DIGITS]
Definition tilespec.c:347
struct sprite_vector nation_flag
Definition tilespec.c:276
struct sprite * nonnative
Definition tilespec.c:404
struct named_sprites::@275 player[MAX_NUM_PLAYER_SLOTS]
struct sprite * plant
Definition tilespec.c:307
bool no_more_stack_sprites
Definition tilespec.c:293
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::@271::@277 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 named_sprites::@268::@276 s[GTS_COUNT]
struct sprite * waypoint
Definition tilespec.c:351
struct sprite * pillage
Definition tilespec.c:308
struct named_sprites::@270 tx
struct sprite * fortified
Definition tilespec.c:303
struct sprite * dither_tile
Definition tilespec.c:258
struct sprite * coastline[EDGE_COUNT]
Definition tilespec.c:406
struct sprite * tired
Definition tilespec.c:318
struct style_citizen_set style_citizen_sets
Definition tilespec.c:280
struct sprite * treaty_thumb[2]
Definition tilespec.c:249
struct sprite * sentry
Definition tilespec.c:309
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 named_sprites::@271::@277::@279 road
struct sprite * darkness[MAX_INDEX_CARDINAL]
Definition tilespec.c:361
struct sprite * tax_science
Definition tilespec.c:257
struct named_sprites::@261 mask
struct anim * select
Definition tilespec.c:294
struct named_sprites::@271::@277::@278 bmf
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::@264 explode
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::@263 cursor[CURSOR_LAST]
struct sprite * size_hundreds[NUM_TILES_DIGITS]
Definition tilespec.c:330
struct sprite * activity
Definition tilespec.c:364
struct named_sprites::@262 units
struct anim * single
Definition tilespec.c:369
struct anim * odd[MAX_INDEX_HALF]
Definition tilespec.c:389
union named_sprites::@271::@277::@279::@280 ru
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 named_sprites::@266 upkeep
struct named_sprites::@273 colors
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 sprite * connect
Definition tilespec.c:313
struct sprite * fog
Definition tilespec.c:358
struct sprite * arrow[ARROW_LAST]
Definition tilespec.c:250
struct named_sprites::@269 user
struct sprite * grid_borders[EDGE_COUNT][2]
Definition tilespec.c:417
struct anim * cardinals[MAX_INDEX_CARDINAL]
Definition tilespec.c:370
struct named_sprites::@267 city
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:140
bool occupied
Definition unit.h:222
int battlegroup
Definition unit.h:194
enum unit_activity activity
Definition unit.h:159
int moves_left
Definition unit.h:152
struct unit::@83 orders
int hp
Definition unit.h:153
int fuel
Definition unit.h:155
bool colored
Definition unit.h:225
enum direction8 facing
Definition unit.h:144
struct tile * tile
Definition unit.h:142
struct unit::@84::@86 client
struct extra_type * activity_target
Definition unit.h:167
bool repeat
Definition unit.h:199
int color_index
Definition unit.h:226
int veteran
Definition unit.h:154
enum server_side_agent ssa_controller
Definition unit.h:175
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
#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:138
const char * terrain_rule_name(const struct terrain *pterrain)
Definition terrain.c:247
enum terrain_class terrain_type_terrain_class(const struct terrain *pterrain)
Definition terrain.c:582
#define terrain_type_iterate(_p)
Definition terrain.h:266
#define T_UNKNOWN
Definition terrain.h:62
#define is_ocean_tile(ptile)
Definition terrain.h:196
#define terrain_type_iterate_end
Definition terrain.h:272
#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:4741
void advance_global_anim_state(void)
Definition tilespec.c:6768
struct sprite * get_government_sprite(const struct tileset *t, const struct government *gov)
Definition tilespec.c:7030
void tileset_load_tiles(struct tileset *t)
Definition tilespec.c:3822
struct sprite * get_nuke_explode_sprite(const struct tileset *t)
Definition tilespec.c:7174
#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:7020
#define SET_SPRITE_DEPR_ALT(field, tag, alt, ver)
Definition tilespec.c:2964
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:5878
struct unit * get_drawable_unit(const struct tileset *t, struct tile *ptile, const struct city *citymode)
Definition tilespec.c:6779
static int check_sprite_type(const char *sprite_type, const char *tile_section)
Definition tilespec.c:1910
struct sprite * get_attention_crosshair_sprite(const struct tileset *t)
Definition tilespec.c:7235
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:3996
static void free_all_anims(struct tileset *t)
Definition tilespec.c:6819
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:1603
#define specfile_list_iterate_end
Definition tilespec.c:436
static struct sprite * create_plr_sprite(struct color *pcolor)
Definition tilespec.c:2874
int tileset_svg_flag_height(struct tileset *t)
Definition tilespec.c:7820
#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:4664
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:3229
void tileset_setup_government(struct tileset *t, struct government *gov)
Definition tilespec.c:4605
#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:4655
void tileset_setup_specialist_type_default_set(struct tileset *t, Specialist_type_id id)
Definition tilespec.c:3085
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:7298
static enum direction8 dir_by_tileset_name(const char *str)
Definition tilespec.c:1038
#define ADD_SPRITE_SIMPLE(s)
Definition tilespec.c:4686
static int fill_basic_road_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7484
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:4760
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:3941
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:5233
int fill_basic_extra_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7449
#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:7280
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:4339
static const char direction4letters[4]
Definition tilespec.c:142
void tileset_player_init(struct tileset *t, struct player *pplayer)
Definition tilespec.c:7621
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:2789
struct sprite * get_treaty_thumb_sprite(const struct tileset *t, bool on_off)
Definition tilespec.c:7154
bool unit_drawn_with_city_outline(const struct unit *punit, bool check_focus)
Definition tilespec.c:5711
#define MAX_INDEX_HALF
Definition tilespec.c:111
double get_focus_unit_toggle_timeout(const struct tileset *t)
Definition tilespec.c:6722
#define SET_SPRITE_ALT_OPT(field, tag, alt)
Definition tilespec.c:2985
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:5395
#define TILE_SECTION_PREFIX
Definition tilespec.c:107
static struct city_sprite * load_city_sprite(struct tileset *t, const char *tag)
Definition tilespec.c:3306
static char * valid_index_str(const struct tileset *t, int idx)
Definition tilespec.c:2748
void tileset_free_tiles(struct tileset *t)
Definition tilespec.c:6832
#define ADD_ANIM_FULL(s)
Definition tilespec.c:4694
void tileset_setup_impr_type(struct tileset *t, struct impr_type *pimprove)
Definition tilespec.c:4030
static struct tileset * tileset_read_toplevel(const char *tileset_name, bool verbose, int topology_id, float scale)
Definition tilespec.c:1931
static bool sprite_exists(const struct tileset *t, const char *tag_name)
Definition tilespec.c:2914
const struct sprite_vector * get_unit_explode_animation(const struct tileset *t)
Definition tilespec.c:7163
#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:3265
struct sprite * load_popup_sprite(const char *tag)
Definition tilespec.c:7828
static void unload_all_sprites(struct tileset *t)
Definition tilespec.c:6805
static const char * dir_get_tileset_name(enum direction8 dir)
Definition tilespec.c:1011
#define SET_SPRITE_UNSCALED(field, tag)
Definition tilespec.c:2940
void tileset_background_init(struct tileset *t)
Definition tilespec.c:7701
void tileset_setup_tech_type(struct tileset *t, struct advance *padvance)
Definition tilespec.c:4046
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:5666
static void unload_sprite(struct tileset *t, const char *tag_name)
Definition tilespec.c:2890
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:5602
#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:4709
static void tileset_player_free(struct tileset *t, int plrid)
Definition tilespec.c:7672
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:7578
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:5728
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:7314
#define FULL_TILE_X_OFFSET
Definition tilespec.c:4676
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:6657
struct sprite * get_nation_shield_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:7002
const char * tileset_description(struct tileset *t)
Definition tilespec.c:7796
#define SET_GOTO_TURN_SPRITE(state, state_name, factor, factor_name)
#define SET_ANIM_OPT(field, tag)
Definition tilespec.c:3002
void tileset_background_free(struct tileset *t)
Definition tilespec.c:7720
#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:7145
void toggle_focus_unit_state(struct tileset *t)
Definition tilespec.c:6756
#define ADD_FRAME0_IF_NOT_NULL(x)
void tilespec_reread_frozen_refresh(const char *tname)
Definition tilespec.c:1591
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:2728
#define NUM_TILES_DIGITS
Definition tilespec.c:115
void focus_unit_in_combat(struct tileset *t)
Definition tilespec.c:6747
static int tileset_upkeep_height(const struct tileset *t)
Definition tilespec.c:876
const char * tileset_summary(struct tileset *t)
Definition tilespec.c:7788
struct sprite * get_icon_sprite(const struct tileset *t, enum icon_type icon)
Definition tilespec.c:7224
static void ensure_big_sprite(struct specfile *sf, const char *tset_name)
Definition tilespec.c:1639
#define ADD_ANIM_SPRITE(s, draw_fog, x_offset, y_offset)
Definition tilespec.c:4690
static bool tileset_update
Definition tilespec.c:596
#define FULL_TILE_Y_OFFSET
Definition tilespec.c:4677
struct sprite * get_indicator_sprite(const struct tileset *t, enum indicator_type indicator, int idx)
Definition tilespec.c:7244
struct sprite * get_sample_city_sprite(const struct tileset *t, int style_idx)
Definition tilespec.c:7096
#define ADD_SPRITE_FULL(s)
Definition tilespec.c:4687
void tileset_setup_extra(struct tileset *t, struct extra_type *pextra)
Definition tilespec.c:4065
static void anim_advance_time(struct anim *a)
Definition tilespec.c:3054
void tileset_init(struct tileset *t)
Definition tilespec.c:7375
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:5275
static char * tilespec_gfx_filename(const char *gfx_filename, const char *tset_name)
Definition tilespec.c:1845
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:7416
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:2931
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:4950
static bool is_extra_drawing_enabled(struct extra_type *pextra)
Definition tilespec.c:5946
struct sprite * get_spaceship_sprite(const struct tileset *t, enum spaceship_part part)
Definition tilespec.c:6928
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:2804
struct sprite * get_cursor_sprite(const struct tileset *t, enum cursor_type cursor, int *hot_x, int *hot_y, int frame)
Definition tilespec.c:7205
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:7306
int tileset_hex_height(const struct tileset *t)
Definition tilespec.c:756
void reset_focus_unit_state(struct tileset *t)
Definition tilespec.c:6735
static const char * citizen_rule_name(enum citizen_category citizen)
Definition tilespec.c:2703
static void tileset_setup_citizen_types_default_set(struct tileset *t)
Definition tilespec.c:3179
bool tileset_is_fully_loaded(void)
Definition tilespec.c:7764
static struct sprite * anim_get_current_frame(struct anim *a)
Definition tilespec.c:3065
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:5355
#define ADD_ANIM_SPRITE_SIMPLE(s)
Definition tilespec.c:4692
const struct citybar_sprites * get_citybar_sprites(const struct tileset *t)
Definition tilespec.c:7182
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:7836
#define SET_SPRITE(field, tag)
Definition tilespec.c:2921
static void tileset_lookup_sprite_tags(struct tileset *t)
Definition tilespec.c:3354
struct sprite * get_arrow_sprite(const struct tileset *t, enum arrow_type arrow)
Definition tilespec.c:7113
struct sprite * get_unit_unhappy_sprite(const struct tileset *t, const struct unit *punit, int happy_cost)
Definition tilespec.c:7261
#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:7532
static void tileset_setup_base(struct tileset *t, const struct extra_type *pextra, const char *tag)
Definition tilespec.c:4304
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:5001
void finish_loading_sprites(struct tileset *t)
Definition tilespec.c:3806
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:1876
#define anim_hash_iterate_end
Definition tilespec.c:485
static struct anim * anim_new(int frames, int time_per_frame)
Definition tilespec.c:2771
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:3833
#define SET_EDITOR_SPRITE(x)
#define SET_SPRITE_ALT(field, tag, alt)
Definition tilespec.c:2950
#define SET_SPRITE_OPT(field, tag)
Definition tilespec.c:2982
void tilespec_reread_callback(struct option *poption)
Definition tilespec.c:1555
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:3095
static bool load_river_sprites(struct tileset *t, struct river_sprites *store, const char *tag_pfx)
Definition tilespec.c:3772
const char * tileset_name_get(struct tileset *t)
Definition tilespec.c:7772
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:6938
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:6013
#define ADD_SPRITE(s, draw_fog, x_offset, y_offset)
Definition tilespec.c:4679
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:3013
struct sprite * get_tax_sprite(const struct tileset *t, Output_type_id otype)
Definition tilespec.c:7124
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:3879
struct sprite * get_citizen_sprite(const struct tileset *t, enum citizen_category type, int citizen_index, const struct city *pcity)
Definition tilespec.c:6959
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:5449
const char * tileset_version(struct tileset *t)
Definition tilespec.c:7780
static bool focus_unit_state
Definition tilespec.c:594
static void free_city_sprite(struct city_sprite *city_sprite)
Definition tilespec.c:3334
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:7042
char * tileset_what_ruleset(struct tileset *t)
Definition tilespec.c:7804
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:6993
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:3188
static void tileset_setup_road(struct tileset *t, struct extra_type *pextra, const char *tag)
Definition tilespec.c:4195
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:7011
#define MATCH(dir)
static int get_irrigation_index(const struct tileset *t, struct extra_type *pextra, bv_extras *textras_near)
Definition tilespec.c:5213
#define ADD_FRAME0_SIMPLE(s)
Definition tilespec.c:4698
#define MAX_INDEX_CARDINAL
Definition tilespec.c:110
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:7194
int tileset_topo_index(struct tileset *t)
Definition tilespec.c:7812
bool tilespec_reread(const char *new_tileset_name, bool game_fully_initialized, float scale)
Definition tilespec.c:1401
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:4620
void tileset_ruleset_reset(struct tileset *t)
Definition tilespec.c:7736
#define SET_ANIM(field, tag)
Definition tilespec.c:2992
static void scan_specfile(struct tileset *t, struct specfile *sf, bool duplicates_ok)
Definition tilespec.c:1680
enum mapview_layer tileset_get_layer(const struct tileset *t, int n)
Definition tilespec.c:7568
#define NUM_EDGE_TILES
Definition tilespec.h:99
#define NUM_CURSOR_FRAMES
Definition tilespec.h:303
indicator_type
Definition tilespec.h:305
@ INDICATOR_COUNT
Definition tilespec.h:309
arrow_type
Definition tilespec.h:199
@ ARROW_LAST
Definition tilespec.h:203
@ ARROW_MINUS
Definition tilespec.h:202
@ ARROW_RIGHT
Definition tilespec.h:200
@ ARROW_PLUS
Definition tilespec.h:201
#define TS_TOPO_ISOHEX
Definition tilespec.h:455
#define TERRAIN_LAYER_COUNT
Definition tilespec.h:173
#define sprite_vector_iterate_end
Definition tilespec.h:46
#define NUM_CORNER_TILES
Definition tilespec.h:106
#define NUM_TILES_PROGRESS
Definition tilespec.h:195
#define MAX_NUM_CITIZEN_SPRITES
Definition tilespec.h:197
#define TS_TOPO_HEX
Definition tilespec.h:454
#define TS_TOPO_SQUARE
Definition tilespec.h:453
layer_category
Definition tilespec.h:189
@ LAYER_CATEGORY_TILE
Definition tilespec.h:191
@ LAYER_CATEGORY_CITY
Definition tilespec.h:190
@ LAYER_CATEGORY_UNIT
Definition tilespec.h:192
icon_type
Definition tilespec.h:312
@ ICON_COUNT
Definition tilespec.h:315
@ EDGE_UD
Definition tilespec.h:93
@ EDGE_LR
Definition tilespec.h:94
@ EDGE_COUNT
Definition tilespec.h:95
spaceship_part
Definition tilespec.h:318
@ SPACESHIP_COUNT
Definition tilespec.h:326
#define NUM_WALL_TYPES
Definition tilespec.h:359
#define sprite_vector_iterate(sprite_vec, psprite)
Definition tilespec.h:44
cursor_type
Definition tilespec.h:287
@ CURSOR_LAST
Definition tilespec.h:299
bool unit_is_cityfounder(const struct unit *punit)
Definition unit.c: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:407
#define BATTLEGROUP_NONE
Definition unit.h:193
#define unit_owner(_pu)
Definition unit.h:406
#define activity_type_iterate(_act_)
Definition unit.h:287
#define activity_type_iterate_end
Definition unit.h:292
#define MAX_NUM_BATTLEGROUPS
Definition unit.h:192
#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