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