/
tilespec.c
6951 lines (6036 loc) · 231 KB
/
tilespec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***********************************************************************
Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
/***********************************************************************
Functions for handling the tilespec files which describe
the files and contents of tilesets.
original author: David Pfitzner <dwp@mso.anu.edu.au>
***********************************************************************/
#ifdef HAVE_CONFIG_H
#include <fc_config.h>
#endif
#include <stdio.h>
#include <stdlib.h> /* exit */
#include <stdarg.h>
#include <string.h>
/* utility */
#include "astring.h"
#include "bitvector.h"
#include "capability.h"
#include "deprecations.h"
#include "fcintl.h"
#include "log.h"
#include "mem.h"
#include "rand.h"
#include "registry.h"
#include "shared.h"
#include "string_vector.h"
#include "support.h"
/* common */
#include "base.h"
#include "effects.h"
#include "game.h" /* game.control.styles_count */
#include "government.h"
#include "map.h"
#include "movement.h"
#include "nation.h"
#include "player.h"
#include "road.h"
#include "specialist.h"
#include "unit.h"
#include "unitlist.h"
/* client/include */
#include "dialogs_g.h"
#include "graphics_g.h"
#include "gui_main_g.h"
#include "mapview_g.h" /* for update_map_canvas_visible */
#include "menu_g.h"
#include "themes_g.h"
/* client */
#include "citydlg_common.h" /* for generate_citydlg_dimensions() */
#include "client_main.h"
#include "climap.h" /* for client_tile_get_known() */
#include "colors_common.h"
#include "control.h" /* for fill_xxx */
#include "editor.h"
#include "goto.h"
#include "helpdata.h"
#include "options.h" /* for fill_xxx */
#include "themes_common.h"
#include "tilespec.h"
#define TILESPEC_CAPSTR "+Freeciv-2.6-tilespec duplicates_ok"
/*
* Tilespec capabilities acceptable to this program:
*
* +Freeciv-2.6-tilespec
* - basic format for Freeciv versions 2.6.x; required
*
* +Freeciv-tilespec-Devel-YYYY.MMM.DD
* - tilespec of the development version at the given date
*
* duplicates_ok
* - we can handle existence of duplicate tags (lattermost tag which
* appears is used; tilesets which have duplicates should specify
* "duplicates_ok")
*/
#define SPEC_CAPSTR "+Freeciv-2.6-spec"
/*
* Individual spec file capabilities acceptable to this program:
*
* +Freeciv-2.6-spec
* - basic format for Freeciv versions 2.6.x; required
*/
#define TILESPEC_SUFFIX ".tilespec"
#define TILE_SECTION_PREFIX "tile_"
/* This the way directional indices are now encoded: */
#define MAX_INDEX_CARDINAL 64
#define MAX_INDEX_HALF 16
#define MAX_INDEX_VALID 256
#define NUM_TILES_HP_BAR 11
#define NUM_TILES_DIGITS 10
#define NUM_TILES_SELECT 4
#define MAX_NUM_UPKEEP_SPRITES 10
#define SPECENUM_NAME extrastyle_id
#define SPECENUM_VALUE0 ESTYLE_ROAD_ALL_SEPARATE
#define SPECENUM_VALUE0NAME "RoadAllSeparate"
#define SPECENUM_VALUE1 ESTYLE_ROAD_PARITY_COMBINED
#define SPECENUM_VALUE1NAME "RoadParityCombined"
#define SPECENUM_VALUE2 ESTYLE_ROAD_ALL_COMBINED
#define SPECENUM_VALUE2NAME "RoadAllCombined"
#define SPECENUM_VALUE3 ESTYLE_RIVER
#define SPECENUM_VALUE3NAME "River"
#define SPECENUM_VALUE4 ESTYLE_SINGLE1
#define SPECENUM_VALUE4NAME "Single1"
#define SPECENUM_VALUE5 ESTYLE_SINGLE2
#define SPECENUM_VALUE5NAME "Single2"
#define SPECENUM_VALUE6 ESTYLE_3LAYER
#define SPECENUM_VALUE6NAME "3Layer"
#define SPECENUM_VALUE7 ESTYLE_CARDINALS
#define SPECENUM_VALUE7NAME "Cardinals"
#define SPECENUM_COUNT ESTYLE_COUNT
#include "specenum_gen.h"
/* This could be moved to common/map.h if there's more use for it. */
enum direction4 {
DIR4_NORTH = 0, DIR4_SOUTH, DIR4_EAST, DIR4_WEST
};
static const char direction4letters[4] = "udrl";
/* This must correspond to enum edge_type. */
static const char edge_name[EDGE_COUNT][3] = {"ns", "we", "ud", "lr"};
static const int DIR4_TO_DIR8[4] =
{ DIR8_NORTH, DIR8_SOUTH, DIR8_EAST, DIR8_WEST };
enum match_style {
MATCH_NONE,
MATCH_SAME, /* "boolean" match */
MATCH_PAIR,
MATCH_FULL
};
enum sprite_type {
CELL_WHOLE, /* entire tile */
CELL_CORNER /* corner of tile */
};
struct drawing_data {
bool init;
char *name;
int num_layers; /* 1 thru MAX_NUM_LAYERS. */
#define MAX_NUM_LAYERS 3
struct drawing_layer {
bool is_tall;
int offset_x, offset_y;
#define MAX_NUM_MATCH_WITH 8
enum match_style match_style;
int match_index[1 + MAX_NUM_MATCH_WITH];
int match_indices; /* 0 = no match_type, 1 = no match_with */
enum sprite_type sprite_type;
struct sprite_vector base;
struct sprite *match[MAX_INDEX_CARDINAL];
struct sprite **cells;
/* List of those sprites in 'cells' that are allocated by some other
* means than load_sprite() and thus are not freed by unload_all_sprites(). */
struct sprite_vector allocated;
} layer[MAX_NUM_LAYERS];
bool is_reversed;
int blending; /* layer, 0 = none */
struct sprite *blender;
struct sprite *blend[4]; /* indexed by a direction4 */
};
struct city_style_threshold {
struct sprite *sprite;
};
struct city_sprite {
struct {
int land_num_thresholds;
struct city_style_threshold *land_thresholds;
} *styles;
int num_styles;
};
struct river_sprites {
struct sprite
*spec[MAX_INDEX_CARDINAL],
*outlet[MAX_INDEX_CARDINAL];
};
struct named_sprites {
struct sprite
*indicator[INDICATOR_COUNT][NUM_TILES_PROGRESS],
*treaty_thumb[2], /* 0=disagree, 1=agree */
*arrow[ARROW_LAST], /* 0=right arrow, 1=plus, 2=minus */
*icon[ICON_COUNT],
*events[E_COUNT],
/* The panel sprites for showing tax % allocations. */
*tax_luxury, *tax_science, *tax_gold,
*dither_tile; /* only used for isometric view */
struct {
struct sprite
*tile,
*worked_tile,
*unworked_tile;
} mask;
struct sprite *tech[A_LAST];
struct sprite *building[B_LAST];
struct sprite *government[G_LAST];
struct {
struct sprite *icon[U_LAST];
struct sprite *facing[U_LAST][DIR8_MAGIC_MAX];
unsigned int default_dir_seed[U_LAST];
} units;
struct sprite *resource[MAX_NUM_RESOURCES];
struct sprite_vector nation_flag;
struct sprite_vector nation_shield;
struct citizen_graphic {
/* Each citizen type has up to MAX_NUM_CITIZEN_SPRITES different
* sprites, as defined by the tileset. */
int count;
struct sprite *sprite[MAX_NUM_CITIZEN_SPRITES];
} citizen[CITIZEN_LAST], specialist[SP_MAX];
struct sprite *spaceship[SPACESHIP_COUNT];
struct {
int hot_x, hot_y;
struct sprite *frame[NUM_CURSOR_FRAMES];
} cursor[CURSOR_LAST];
struct {
struct sprite_vector unit;
struct sprite *nuke;
} explode;
struct {
struct sprite
*hp_bar[NUM_TILES_HP_BAR],
*vet_lev[MAX_VET_LEVELS],
*select[NUM_TILES_SELECT],
*auto_attack,
*auto_settler,
*auto_explore,
*fortified,
*fortifying,
*go_to, /* goto is a C keyword :-) */
*irrigate,
*plant,
*pillage,
*sentry,
*stack,
*loaded,
*transform,
*connect,
*patrol,
*convert,
*battlegroup[MAX_NUM_BATTLEGROUPS],
*lowfuel,
*tired;
} unit;
struct {
struct sprite
*unhappy[MAX_NUM_UPKEEP_SPRITES],
*output[O_LAST][MAX_NUM_UPKEEP_SPRITES];
} upkeep;
struct {
struct sprite
*disorder,
*size[NUM_TILES_DIGITS],
*size_tens[NUM_TILES_DIGITS],
*size_hundreds[NUM_TILES_DIGITS],
*tile_foodnum[NUM_TILES_DIGITS],
*tile_shieldnum[NUM_TILES_DIGITS],
*tile_tradenum[NUM_TILES_DIGITS];
struct city_sprite
*tile,
*single_wall,
*wall[NUM_WALL_TYPES],
*occupied;
struct sprite_vector worked_tile_overlay;
struct sprite_vector unworked_tile_overlay;
} city;
struct citybar_sprites citybar;
struct editor_sprites editor;
struct {
struct {
struct sprite *specific;
struct sprite *turns[NUM_TILES_DIGITS];
struct sprite *turns_tens[NUM_TILES_DIGITS];
struct sprite *turns_hundreds[NUM_TILES_DIGITS];
} s[GTS_COUNT];
struct sprite *waypoint;
} path;
struct {
struct sprite *attention;
} user;
struct {
struct sprite
*fog,
**fullfog,
*darkness[MAX_INDEX_CARDINAL]; /* first unused */
} tx; /* terrain extra */
struct {
struct sprite
*activity,
*rmact;
enum extrastyle_id extrastyle;
union {
struct sprite *single;
struct sprite *cardinals[MAX_INDEX_CARDINAL];
struct {
struct sprite
*background,
*middleground,
*foreground;
} bmf;
struct {
struct sprite
/* for extrastyles ESTYLE_ROAD_ALL_SEPARATE and ESTYLE_ROAD_PARITY_COMBINED */
*isolated,
*corner[8]; /* Indexed by direction; only non-cardinal dirs used. */
union {
/* for ESTYLE_ROAD_ALL_SEPARATE */
struct sprite *dir[8]; /* all entries used */
/* ESTYLE_ROAD_PARITY_COMBINED */
struct {
struct sprite
*even[MAX_INDEX_HALF], /* first unused */
*odd[MAX_INDEX_HALF]; /* first unused */
} combo;
/* ESTYLE_ALL_SEPARATE */
struct sprite *total[MAX_INDEX_VALID];
struct river_sprites rivers;
} ru;
} road;
} u;
} extras[MAX_EXTRA_TYPES];
struct {
struct sprite
*main[EDGE_COUNT],
*city[EDGE_COUNT],
*worked[EDGE_COUNT],
*unavailable,
*nonnative,
*selected[EDGE_COUNT],
*coastline[EDGE_COUNT],
*borders[EDGE_COUNT][2];
} grid;
struct {
struct sprite_vector overlays;
} colors;
struct {
struct sprite *color; /* Generic background color */
struct sprite *graphic; /* Generic background graphic */
} background;
struct {
struct sprite *grid_borders[EDGE_COUNT][2];
struct sprite *color;
struct sprite *background;
} player[MAX_NUM_PLAYER_SLOTS];
struct drawing_data *drawing[MAX_NUM_ITEMS];
};
struct specfile {
struct sprite *big_sprite;
char *file_name;
};
#define SPECLIST_TAG specfile
#define SPECLIST_TYPE struct specfile
#include "speclist.h"
#define specfile_list_iterate(list, pitem) \
TYPED_LIST_ITERATE(struct specfile, list, pitem)
#define specfile_list_iterate_end LIST_ITERATE_END
/*
* Information about an individual sprite. All fields except 'sprite' are
* filled at the time of the scan of the specfile. 'Sprite' is
* set/cleared on demand in load_sprite/unload_sprite.
*/
struct small_sprite {
int ref_count;
/* The sprite is in this file. */
char *file;
/* Or, the sprite is in this file at the location. */
struct specfile *sf;
int x, y, width, height;
/* A little more (optional) data. */
int hot_x, hot_y;
struct sprite *sprite;
};
/* 'struct small_sprite_list' and related functions. */
#define SPECLIST_TAG small_sprite
#define SPECLIST_TYPE struct small_sprite
#include "speclist.h"
#define small_sprite_list_iterate(list, pitem) \
TYPED_LIST_ITERATE(struct small_sprite, list, pitem)
#define small_sprite_list_iterate_end LIST_ITERATE_END
/* 'struct sprite_hash' and related functions. */
#define SPECHASH_TAG sprite
#define SPECHASH_ASTR_KEY_TYPE
#define SPECHASH_IDATA_TYPE struct small_sprite *
#include "spechash.h"
#define sprite_hash_iterate(hash, tag_name, sprite) \
TYPED_HASH_ITERATE(const char *, struct small_sprite *, \
hash, tag_name, sprite)
#define sprite_hash_iterate_end HASH_ITERATE_END
/* 'struct drawing_hash' and related functions. */
static void drawing_data_destroy(struct drawing_data *draw);
#define SPECHASH_TAG drawing
#define SPECHASH_CSTR_KEY_TYPE
#define SPECHASH_IDATA_TYPE struct drawing_data *
#define SPECHASH_IDATA_FREE drawing_data_destroy
#include "spechash.h"
#define SPECHASH_TAG estyle
#define SPECHASH_ASTR_KEY_TYPE
#define SPECHASH_ENUM_DATA_TYPE extrastyle_id
#include "spechash.h"
struct tileset {
char name[512];
char given_name[MAX_LEN_NAME];
char version[MAX_LEN_NAME];
int priority;
char *summary;
char *description;
float scale;
enum ts_type type;
int hex_width, hex_height;
int ts_topo_idx;
int normal_tile_width, normal_tile_height;
int full_tile_width, full_tile_height;
int unit_tile_width, unit_tile_height;
int small_sprite_width, small_sprite_height;
int max_upkeep_height;
char *main_intro_filename;
char *minimap_intro_filename;
int city_names_font_size, city_productions_font_size;
enum fog_style fogstyle;
enum darkness_style darkness_style;
int darkness_layer;
int unit_flag_offset_x, unit_flag_offset_y;
int city_flag_offset_x, city_flag_offset_y;
int unit_offset_x, unit_offset_y;
int city_offset_x, city_offset_y;
int citybar_offset_y;
int tilelabel_offset_y;
int activity_offset_x;
int activity_offset_y;
int occupied_offset_x;
int occupied_offset_y;
int unit_upkeep_offset_y;
int unit_upkeep_small_offset_y;
#define NUM_CORNER_DIRS 4
#define TILES_PER_CORNER 4
int num_valid_tileset_dirs, num_cardinal_tileset_dirs;
int num_index_valid, num_index_cardinal;
enum direction8 valid_tileset_dirs[8], cardinal_tileset_dirs[8];
struct tileset_layer {
char **match_types;
size_t match_count;
} layers[MAX_NUM_LAYERS];
struct specfile_list *specfiles;
struct small_sprite_list *small_sprites;
/* This hash table maps tilespec tags to struct small_sprites. */
struct sprite_hash *sprite_hash;
/* This hash table maps terrain graphic strings to drawing data. */
struct drawing_hash *tile_hash;
struct estyle_hash *estyle_hash;
struct named_sprites sprites;
struct color_system *color_system;
struct extra_type_list *style_lists[ESTYLE_COUNT];
struct extra_type_list *flagged_bases_list;
int num_preferred_themes;
char** preferred_themes;
};
struct tileset *tileset;
struct tileset *unscaled_tileset = NULL;
int focus_unit_state = 0;
static bool tileset_update = FALSE;
static int fill_unit_type_sprite_array(const struct tileset *t,
struct drawn_sprite *sprs,
const struct unit_type *putype,
enum direction8 facing);
static int fill_unit_sprite_array(const struct tileset *t,
struct drawn_sprite *sprs,
const struct unit *punit,
bool stack, bool backdrop);
static bool load_river_sprites(struct tileset *t,
struct river_sprites *store, const char *tag_pfx);
static void tileset_setup_base(struct tileset *t,
const struct extra_type *pextra);
static void tileset_setup_road(struct tileset *t,
struct extra_type *pextra);
static bool is_extra_drawing_enabled(struct extra_type *pextra);
static int fill_basic_road_sprite_array(const struct tileset *t,
struct drawn_sprite *sprs,
const struct extra_type *pextra);
static int fill_basic_base_sprite_array(const struct tileset *t,
struct drawn_sprite *sprs,
const struct extra_type *pextra);
static void tileset_player_free(struct tileset *t, int plrid);
/****************************************************************************
Called when ever there's problem in ruleset/tileset compatibility
****************************************************************************/
void tileset_error(enum log_level level, const char *format, ...)
{
char buf[2048];
va_list args;
va_start(args, format);
fc_vsnprintf(buf, sizeof(buf), format, args);
va_end(args);
log_base(level, "%s", buf);
if (level <= LOG_NORMAL) {
show_tileset_error(buf);
}
if (level == LOG_FATAL) {
exit(EXIT_FAILURE);
}
}
/****************************************************************************
Create a new drawing data.
****************************************************************************/
static struct drawing_data *drawing_data_new(void)
{
struct drawing_data *draw = fc_calloc(1, sizeof(*draw));
draw->name = NULL;
return draw;
}
/****************************************************************************
Free a drawing data.
****************************************************************************/
static void drawing_data_destroy(struct drawing_data *draw)
{
int i;
fc_assert_ret(NULL != draw);
if (draw->name != NULL) {
free(draw->name);
}
for (i = 0; i < 4; i++) {
if (draw->blend[i]) {
free_sprite(draw->blend[i]);
}
}
for (i = 0; i < draw->num_layers; i++) {
int vec_size = sprite_vector_size(&draw->layer[i].allocated);
int j;
for (j = 0; j < vec_size; j++) {
free_sprite(draw->layer[i].allocated.p[j]);
}
sprite_vector_free(&draw->layer[i].base);
sprite_vector_free(&draw->layer[i].allocated);
free(draw->layer[i].cells);
}
free(draw);
}
/****************************************************************************
Return unscaled tileset if it exists, or default otherwise
****************************************************************************/
struct tileset *get_tileset(void)
{
if (unscaled_tileset != NULL) {
return unscaled_tileset;
} else {
return tileset;
}
}
/****************************************************************************
Return the name of the given tileset.
****************************************************************************/
const char *tileset_basename(const struct tileset *t)
{
return t->name;
}
/****************************************************************************
Return whether the current tileset is isometric.
****************************************************************************/
bool tileset_is_isometric(const struct tileset *t)
{
return t->type == TS_ISOMETRIC;
}
/****************************************************************************
Return the hex_width of the current tileset. For iso-hex tilesets this
value will be > 0 and is_isometric will be set.
****************************************************************************/
int tileset_hex_width(const struct tileset *t)
{
return t->hex_width;
}
/****************************************************************************
Return the hex_height of the current tileset. For hex tilesets this
value will be > 0 and is_isometric will be set.
****************************************************************************/
int tileset_hex_height(const struct tileset *t)
{
return t->hex_height;
}
/****************************************************************************
Return the tile width of the current tileset. This is the tesselation
width of the tiled plane. This means it's the width of the bounding box
of the basic map tile.
For best results:
- The value should be even (or a multiple of 4 in iso-view).
- In iso-view, the width should be twice the height (to give a
perspective of 30 degrees above the horizon).
- In non-iso-view, width and height should be equal (overhead
perspective).
- In hex or iso-hex view, remember this is the tesselation vector.
hex_width and hex_height then give the size of the side of the
hexagon. Calculating the dimensions of a "regular" hexagon or
iso-hexagon may be tricky.
However these requirements are not absolute and callers should not
depend on them (although some do).
****************************************************************************/
int tileset_tile_width(const struct tileset *t)
{
return t->normal_tile_width;
}
/****************************************************************************
Return the tile height of the current tileset. This is the tesselation
height of the tiled plane. This means it's the height of the bounding box
of the basic map tile.
See also tileset_tile_width.
****************************************************************************/
int tileset_tile_height(const struct tileset *t)
{
return t->normal_tile_height;
}
/****************************************************************************
Return the full tile width of the current tileset. This is the maximum
width that any mapview sprite will have.
Note: currently this is always equal to the tile width.
****************************************************************************/
int tileset_full_tile_width(const struct tileset *t)
{
return t->full_tile_width;
}
/****************************************************************************
Return the full tile height of the current tileset. This is the maximum
height that any mapview sprite will have. This may be greater than the
tile width in which case the extra area is above the "normal" tile.
Some callers assume the full height is 50% larger than the height in
iso-view, and equal in non-iso view.
****************************************************************************/
int tileset_full_tile_height(const struct tileset *t)
{
return t->full_tile_height;
}
/****************************************************************************
Return the unit tile width of the current tileset.
****************************************************************************/
int tileset_unit_width(const struct tileset *t)
{
return t->unit_tile_width;
}
/****************************************************************************
Return the unit tile height of the current tileset.
****************************************************************************/
int tileset_unit_height(const struct tileset *t)
{
return t->unit_tile_height;
}
/****************************************************************************
Calculate the height of a unit upkeep icons.
****************************************************************************/
static int calculate_max_upkeep_height(const struct tileset *t)
{
int i;
int max = 0;
for (i = 0; i < MAX_NUM_UPKEEP_SPRITES; i++) {
if (t->sprites.upkeep.unhappy[i] != NULL) {
int width, height;
/* TODO: We want only height, getting the width might waste CPU
* depending on gui-specific implementation. */
get_sprite_dimensions(t->sprites.upkeep.unhappy[i], &width, &height);
max = MAX(max, height);
}
}
output_type_iterate(o) {
for (i = 0; i < MAX_NUM_UPKEEP_SPRITES; i++) {
if (t->sprites.upkeep.output[o][i] != NULL) {
int width, height;
/* TODO: We want only height, getting the width might waste CPU
* depending on gui-specific implementation. */
get_sprite_dimensions(t->sprites.upkeep.output[o][i], &width, &height);
max = MAX(max, height);
}
}
} output_type_iterate_end;
return max;
}
/****************************************************************************
Get the height of a unit upkeep icons.
****************************************************************************/
static int tileset_upkeep_height(const struct tileset *t)
{
/* Return cached value */
return t->max_upkeep_height;
}
/****************************************************************************
Suitable canvas height for a unit icon that includes upkeep sprites.
****************************************************************************/
int tileset_unit_with_upkeep_height(const struct tileset *t)
{
int uk_bottom = tileset_unit_layout_offset_y(tileset) + tileset_upkeep_height(tileset);
int u_bottom = tileset_unit_height(tileset);
return MAX(uk_bottom, u_bottom);
}
/****************************************************************************
Suitable canvas height for a unit icon that includes upkeep sprites,
using small space layout.
****************************************************************************/
int tileset_unit_with_small_upkeep_height(const struct tileset *t)
{
return tileset_unit_layout_small_offset_y(tileset) + tileset_upkeep_height(tileset);
}
/****************************************************************************
Offset to layout extra unit sprites, such as upkeep.
****************************************************************************/
int tileset_unit_layout_offset_y(const struct tileset *t)
{
return t->unit_upkeep_offset_y;
}
/****************************************************************************
Offset to layout extra unit sprites, such as upkeep, requesting small
space layout.
****************************************************************************/
int tileset_unit_layout_small_offset_y(const struct tileset *t)
{
return t->unit_upkeep_small_offset_y;
}
/****************************************************************************
Return the small sprite width of the current tileset. The small sprites
are used for various theme graphics (e.g., citymap citizens/specialists
as well as panel indicator icons).
****************************************************************************/
int tileset_small_sprite_width(const struct tileset *t)
{
return t->small_sprite_width;
}
/****************************************************************************
Return the offset from the origin of the city tile at which to place the
city bar text.
****************************************************************************/
int tileset_citybar_offset_y(const struct tileset *t)
{
return t->citybar_offset_y;
}
/****************************************************************************
Return the offset from the origin of the tile at which to place the
label text.
****************************************************************************/
int tileset_tilelabel_offset_y(const struct tileset *t)
{
return t->tilelabel_offset_y;
}
/****************************************************************************
Returns tileset scale
****************************************************************************/
float tileset_scale(const struct tileset *t)
{
return tileset->scale;
}
/****************************************************************************
Return the small sprite height of the current tileset. The small sprites
are used for various theme graphics (e.g., citymap citizens/specialists
as well as panel indicator icons).
****************************************************************************/
int tileset_small_sprite_height(const struct tileset *t)
{
return t->small_sprite_height;
}
/****************************************************************************
Return the path within the data directories where the main intro graphics
file can be found. (It is left up to the GUI code to load and unload this
file.)
****************************************************************************/
const char *tileset_main_intro_filename(const struct tileset *t)
{
return t->main_intro_filename;
}
/****************************************************************************
Return the path within the data directories where the mini intro graphics
file can be found. (It is left up to the GUI code to load and unload this
file.)
****************************************************************************/
const char *tileset_mini_intro_filename(const struct tileset *t)
{
return t->minimap_intro_filename;
}
/****************************************************************************
Return the number of possible colors for city overlays.
****************************************************************************/
int tileset_num_city_colors(const struct tileset *t)
{
return t->sprites.city.worked_tile_overlay.size;
}
/****************************************************************************
Return TRUE if the client will use the code to generate the fog.
****************************************************************************/
bool tileset_use_hard_coded_fog(const struct tileset *t)
{
return FOG_AUTO == t->fogstyle;
}
/**************************************************************************
Initialize.
**************************************************************************/
static struct tileset *tileset_new(void)
{
struct tileset *t = fc_calloc(1, sizeof(*t));
t->specfiles = specfile_list_new();
t->small_sprites = small_sprite_list_new();
return t;
}
/**************************************************************************
Return the tileset name of the direction. This is similar to
dir_get_name but you shouldn't change this or all tilesets will break.
**************************************************************************/
static const char *dir_get_tileset_name(enum direction8 dir)
{
switch (dir) {
case DIR8_NORTH:
return "n";
case DIR8_NORTHEAST:
return "ne";
case DIR8_EAST:
return "e";
case DIR8_SOUTHEAST:
return "se";
case DIR8_SOUTH:
return "s";
case DIR8_SOUTHWEST:
return "sw";
case DIR8_WEST:
return "w";
case DIR8_NORTHWEST:
return "nw";
}
log_error("Wrong direction8 variant: %d.", dir);
return "";
}
/****************************************************************************
Return TRUE iff the dir is valid in this tileset.
****************************************************************************/
static bool is_valid_tileset_dir(const struct tileset *t,
enum direction8 dir)
{
if (t->hex_width > 0) {
return dir != DIR8_NORTHEAST && dir != DIR8_SOUTHWEST;
} else if (t->hex_height > 0) {
return dir != DIR8_NORTHWEST && dir != DIR8_SOUTHEAST;
} else {
return TRUE;
}
}
/****************************************************************************
Return TRUE iff the dir is cardinal in this tileset.
"Cardinal", in this sense, means that a tile will share a border with
another tile in the direction rather than sharing just a single vertex.
****************************************************************************/
static bool is_cardinal_tileset_dir(const struct tileset *t,
enum direction8 dir)
{
if (t->hex_width > 0 || t->hex_height > 0) {
return is_valid_tileset_dir(t, dir);
} else {
return (dir == DIR8_NORTH || dir == DIR8_EAST
|| dir == DIR8_SOUTH || dir == DIR8_WEST);
}
}
/**********************************************************************
Convert properties of the actual topology to an index of different
tileset topology types.
***********************************************************************/
static int ts_topology_index(int actual_topology)