-
Notifications
You must be signed in to change notification settings - Fork 6
/
c_tile.cpp
785 lines (739 loc) · 26.1 KB
/
c_tile.cpp
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
#include "c_tile.h"
#include "UserConfig.h"
#include "s_map_block.h"
#include "console.h"
#include "TileSet.h"
int get_border_offset_sixteen(unsigned char in)
{
if((in&(2|8|32|128)) == (2|8|32|128))
return 15;
else if((in&(2|8|128)) == (2|8|128))
return 14;
else if((in&(2|32|128)) == (2|32|128))
return 13;
else if((in&(8|32|128)) == (8|32|128))
return 12;
else if((in&(2|8|32)) == (2|8|32))
return 11;
else if((in&(2|128)) == (2|128))
return 10;
else if((in&(32|128)) == (32|128))
return 9;
else if((in&(8|32)) == (8|32))
return 8;
else if((in&(2|8)) == (2|8))
return 7;
else if((in&(8|32)) == (8|32))
return 6;
else if((in&(2|32)) == (2|32))
return 5;
else if((in&128) == 128)
return 4;
else if((in&32) == 32)
return 3;
else if((in&8) == 8)
return 2;
else if((in&2) == 2)
return 1;
else if(in == 0)
return 0;
return -1;
}
int get_border_offset_path(unsigned char in)
{
if((in&(2|8|32|128)) == (2|8|32|128))
return 10;
else if((in&(2|8|128)) == (2|8|128))
return 9;
else if((in&(2|32|128)) == (2|32|128))
return 8;
else if((in&(8|32|128)) == (8|32|128))
return 7;
else if((in&(2|8|32)) == (2|8|32))
return 6;
else if((in&(2|128)) == (2|128))
return 5;
else if((in&(32|128)) == (32|128))
return 4;
else if((in&(8|32)) == (8|32))
return 3;
else if((in&(2|8)) == (2|8))
return 2;
else if((in&(8|32)) == (8|32))
return 1;
else if((in&(2|32)) == (2|32))
return 0;
else if((in&2) == 2)
return 0;
else if((in&8) == 8)
return 1;
else if((in&32) == 32)
return 0;
else if((in&128) == 128)
return 1;
return -1;
}
int get_border_offset_six(unsigned char in)
{
if((in&(2|32)) == (2|32))
return 0;
else if((in&(8|128)) == (8|128))
return 1;
else if((in&(8|32)) == (8|32))
return 2;
else if((in&(32|128)) == (32|128))
return 3;
else if((in&(2|8)) == (2|8))
return 4;
else if((in&(2|128)) == (2|128))
return 5;
else if((in&2) == 2)
return 0;
else if((in&8) == 8)
return 1;
else if((in&32) == 32)
return 0;
else if((in&128) == 128)
return 1;
return -1;
}
int get_border_offset_four(unsigned char in)
{
if(((in&2) == 2) && !((in&32) == 32))
return 3;
else if(((in&8) == 8) && !((in&128) == 128))
return 0;
else if(((in&32) == 32) && !((in&2) == 2))
return 1;
else if(((in&128) == 128) && !((in&8) == 8))
return 2;
return -1;
}
int get_border_offset_pair(unsigned char in)
{
if((in&(2|32)) == (2|32))
return 0;
else if((in&(8|128)) == (8|128))
return 1;
else if((in&2) == 2)
return 0;
else if((in&8) == 8)
return 1;
else if((in&32) == 32)
return 0;
else if((in&128) == 128)
return 1;
return -1;
}
ALLEGRO_COLOR mix_colors( ALLEGRO_COLOR lhs, ALLEGRO_COLOR rhs)
{
lhs.a *= rhs.a;
lhs.r *= rhs.r;
lhs.g *= rhs.g;
lhs.b *= rhs.b;
return lhs;
}
void draw_sprite(TileSet * tileset, s_sprite sprite, s_map_block * block, float x, float y, int shrink, bool flip = 0, int offset = 0, bool shiftup = false)
{
if(offset < 0)
return;
int target_width = al_get_bitmap_width(al_get_target_bitmap());
int target_height = al_get_bitmap_height(al_get_target_bitmap());
if((x + sprite.origin_x > target_width) || (y + sprite.origin_y > target_height) ||
((x + sprite.origin_x + sprite.width) < 0) || ((y + sprite.origin_y + (sprite.height - shrink)) < 0))return;
int flags = 0;
if(flip)
flags = ALLEGRO_FLIP_HORIZONTAL;
ALLEGRO_COLOR color;
switch(sprite.color_by)
{
case COLOR_NONE:
color = block->light;
break;
case COLOR_INI:
color = mix_colors(sprite.color, block->light);
break;
case COLOR_BIOME:
color = mix_colors(block->biome_color, block->light);
break;
case COLOR_COMBINED:
color = mix_colors(block->combined_color, block->light);
break;
case COLOR_STRUCTURE:
color = mix_colors(block->structure_color, block->light);
break;
case COLOR_TRADE:
color = mix_colors(block->trade_color, block->light);
break;
case COLOR_PALETTE:
switch(sprite.color_source)
{
case SOURCE_ELEV:
color = mix_colors(tileset->get_palette_color(sprite.palette_number, block->height), block->light);
break;
case SOURCE_DEPTH:
color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->water_height-block->height), block->light);
break;
case SOURCE_TEMPERATURE:
color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_TEMPERATURE]), block->light);
break;
case SOURCE_RAINFALL:
color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_RAINFALL]), block->light);
break;
case SOURCE_DRAINAGE:
color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_DRAINAGE]), block->light);
break;
case SOURCE_SAVAGERY:
color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_SAVAGERY]), block->light);
break;
case SOURCE_VOLCANISM:
color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_VOLCANISM]), block->light);
break;
case SOURCE_EVIL:
color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_EVIL]), block->light);
break;
case SOURCE_SALINITY:
color = mix_colors(tileset->get_palette_color(sprite.palette_number,block->levels[SOURCE_SALINITY]), block->light);
break;
default:
color = block->light;
}
break;
default:
color = block->light;
break;
}
al_draw_tinted_bitmap_region(
imagelist.get_image(sprite.index),
color,
sprite.x + (sprite.width * offset),
sprite.y + ((!shiftup)*shrink),
sprite.width,
sprite.height - shrink,
x + sprite.origin_x,
y + sprite.origin_y,
flags);
}
e_color_by get_color_selector(const char * text)
{
if(strcmp(text, "none") == 0)
return COLOR_NONE;
if(strcmp(text, "html") == 0)
return COLOR_INI;
if(strcmp(text, "biome_map") == 0)
return COLOR_BIOME;
if(strcmp(text, "combined_biome_map") == 0)
return COLOR_COMBINED;
if(strcmp(text, "trade_map") == 0)
return COLOR_TRADE;
if(strcmp(text, "structure_map") == 0)
return COLOR_STRUCTURE;
if(strcmp(text, "palette") == 0)
return COLOR_PALETTE;
return COLOR_NONE;
}
e_color_source get_color_source(const char * text)
{
if(strcmp(text, "elevation") == 0)
return SOURCE_ELEV;
if(strcmp(text, "water_depth") == 0)
return SOURCE_DEPTH;
if(strcmp(text, "temperature") == 0)
return SOURCE_TEMPERATURE;
if(strcmp(text, "rainfall") == 0)
return SOURCE_RAINFALL;
if(strcmp(text, "drainage") == 0)
return SOURCE_DRAINAGE;
if(strcmp(text, "savagery") == 0)
return SOURCE_SAVAGERY;
if(strcmp(text, "volcanism") == 0)
return SOURCE_VOLCANISM;
if(strcmp(text, "evil") == 0)
return SOURCE_EVIL;
if(strcmp(text, "salinity") == 0)
return SOURCE_SALINITY;
return SOURCE_ELEV;
}
terrain_type get_terrain_type(const char * text)
{
if(strcmp(text, "any") == 0)
return TERRAIN_ANY;
if(strcmp(text, "none") == 0)
return TERRAIN_NONE;
if(strcmp(text, "mountain") == 0)
return TERRAIN_MOUNTAIN;
if(strcmp(text, "temperate_freshwater_lake") == 0)
return TERRAIN_LAKE_TEMP_FRESH;
if(strcmp(text, "temperate_brackish_lake") == 0)
return TERRAIN_LAKE_TEMP_BRACK;
if(strcmp(text, "temperate_saltwater_lake") == 0)
return TERRAIN_LAKE_TEMP_SALT;
if(strcmp(text, "tropical_freshwater_lake") == 0)
return TERRAIN_LAKE_TROP_FRESH;
if(strcmp(text, "tropical_brackish_lake") == 0)
return TERRAIN_LAKE_TROP_BRACK;
if(strcmp(text, "tropical_saltwater_lake") == 0)
return TERRAIN_LAKE_TROP_SALT;
if(strcmp(text, "arctic_ocean") == 0)
return TERRAIN_OCEAN_ARCT;
if(strcmp(text, "tropical_ocean") == 0)
return TERRAIN_OCEAN_TROP;
if(strcmp(text, "temperate_ocean") == 0)
return TERRAIN_OCEAN_TEMP;
if(strcmp(text, "glacier") == 0)
return TERRAIN_GLACIER;
if(strcmp(text, "tundra") == 0)
return TERRAIN_TUNDRA;
if(strcmp(text, "temperate_freshwater_swamp") == 0)
return TERRAIN_SWAMP_TEMP_FRESH;
if(strcmp(text, "temperate_saltwater_swamp") == 0)
return TERRAIN_SWAMP_TEMP_SALT;
if(strcmp(text, "temperate_freshwater_marsh") == 0)
return TERRAIN_MARSH_TEMP_FRESH;
if(strcmp(text, "temperate_saltwater_marsh") == 0)
return TERRAIN_MARSH_TEMP_SALT;
if(strcmp(text, "tropical_freshwater_swamp") == 0)
return TERRAIN_SWAMP_TROP_FRESH;
if(strcmp(text, "tropical_saltwater_swamp") == 0)
return TERRAIN_SWAMP_TROP_SALT;
if(strcmp(text, "mangrove_swamp") == 0)
return TERRAIN_SWAMP_MANGROVE;
if(strcmp(text, "tropical_freshwater_marsh") == 0)
return TERRAIN_MARSH_TROP_FRESH;
if(strcmp(text, "tropical_saltwater_marsh") == 0)
return TERRAIN_MARSH_TROP_SALT;
if(strcmp(text, "taiga_forest") == 0)
return TERRAIN_FOREST_TAIGA;
if(strcmp(text, "temperate_conifer_forest") == 0)
return TERRAIN_FOREST_TEMP_FIR;
if(strcmp(text, "temperate_broadleaf_forest") == 0)
return TERRAIN_FOREST_TEMP_BROAD;
if(strcmp(text, "tropical_conifer_forest") == 0)
return TERRAIN_FOREST_TROP_FIR;
if(strcmp(text, "tropical_dry_broadleaf_forest") == 0)
return TERRAIN_FOREST_TROP_BROAD_DRY;
if(strcmp(text, "tropical_moist_broadleaf_forest") == 0)
return TERRAIN_FOREST_TROP_BROAD_MOIST;
if(strcmp(text, "temperate_grassland") == 0)
return TERRAIN_GRASS_TEMP;
if(strcmp(text, "temperate_savanna") == 0)
return TERRAIN_SAV_TEMP;
if(strcmp(text, "temperate_shrubland") == 0)
return TERRAIN_SHRUB_TEMP;
if(strcmp(text, "tropical_grassland") == 0)
return TERRAIN_GRASS_TROP;
if(strcmp(text, "tropical_savanna") == 0)
return TERRAIN_SAV_TROP;
if(strcmp(text, "tropical_shrubland") == 0)
return TERRAIN_SHRUB_TROP;
if(strcmp(text, "badland_desert") == 0)
return TERRAIN_DESERT_BAD;
if(strcmp(text, "sand_desert") == 0)
return TERRAIN_DESERT_SAND;
if(strcmp(text, "rock_desert") == 0)
return TERRAIN_DESERT_ROCK;
if(strcmp(text, "tall_mountain") == 0)
return TERRAIN_MOUNTAIN_TALL;
if(strcmp(text, "temperate_beach") == 0)
return TERRAIN_BEACH_TEMP;
if(strcmp(text, "tropical_beach") == 0)
return TERRAIN_BEACH_TROP;
if(strcmp(text, "arctic_beach") == 0)
return TERRAIN_BEACH_ARCT;
return TERRAIN_ANY;
}
structure_type get_structure_type(const char * text)
{
if(strcmp(text, "any") == 0)
return STRUCTURE_ANY;
if(strcmp(text, "none") == 0)
return STRUCTURE_NONE;
if(strcmp(text, "castle") == 0)
return STRUCTURE_CASTLE;
if(strcmp(text, "village") == 0)
return STRUCTURE_VILLAGE;
if(strcmp(text, "crops_1") == 0)
return STRUCTURE_CROPS1;
if(strcmp(text, "crops_2") == 0)
return STRUCTURE_CROPS2;
if(strcmp(text, "crops_3") == 0)
return STRUCTURE_CROPS3;
if(strcmp(text, "pasture") == 0)
return STRUCTURE_PASTURE;
if(strcmp(text, "meadow") == 0)
return STRUCTURE_MEADOW;
if(strcmp(text, "woodland") == 0)
return STRUCTURE_WOODLAND;
if(strcmp(text, "orchard") == 0)
return STRUCTURE_ORCHARD;
if(strcmp(text, "tunnel") == 0)
return STRUCTURE_TUNNEL;
if(strcmp(text, "stone_bridge") == 0)
return STRUCTURE_BRIDGE_STONE;
if(strcmp(text, "other_bridge") == 0)
return STRUCTURE_BRIDGE_OTHER;
if(strcmp(text, "stone_road") == 0)
return STRUCTURE_ROAD_STONE;
if(strcmp(text, "other_road") == 0)
return STRUCTURE_ROAD_OTHER;
if(strcmp(text, "stone_wall") == 0)
return STRUCTURE_WALL_STONE;
if(strcmp(text, "other_wall") == 0)
return STRUCTURE_WALL_OTHER;
if(strcmp(text, "river") == 0)
return STRUCTURE_RIVER;
if(strcmp(text, "brook") == 0)
return STRUCTURE_BROOK;
return STRUCTURE_NONE;
}
e_offset_type get_offset_type(const char * text)
{
if(!text)
return OFFSET_NONE;
if(strcmp(text, "none") == 0)
return OFFSET_NONE;
if(strcmp(text, "path") == 0)
return OFFSET_PATH;
if(strcmp(text, "pair") == 0)
return OFFSET_PAIR;
if(strcmp(text, "six") == 0)
return OFFSET_SIX;
if(strcmp(text, "sixteen") == 0)
return OFFSET_SIXTEEN;
if(strcmp(text, "four") == 0)
return OFFSET_FOUR;
if(strcmp(text, "random") == 0)
return OFFSET_RANDOM;
return OFFSET_NONE;
}
int get_offset(e_offset_type type, char borders, s_map_block * block, unsigned char amount)
{
switch(type)
{
case OFFSET_NONE:
case OFFSET_COUNT:
break;
case OFFSET_SIXTEEN:
return get_border_offset_sixteen(borders);
case OFFSET_PATH:
return get_border_offset_path(borders);
case OFFSET_PAIR:
return get_border_offset_pair(borders);
case OFFSET_SIX:
return get_border_offset_six(borders);
case OFFSET_FOUR:
return get_border_offset_four(borders);
case OFFSET_RANDOM:
int off = amount*block->random;
if(off >= amount)
off=0;
return off;
}
return 0;
}
s_sprite::s_sprite(void)
{
x = 0;
y = 0;
width = 0;
height = 0;
index = -1;
origin_x = 0;
origin_y = 0;
column_height = 0;
color_by=COLOR_NONE;
color_source=SOURCE_ELEV;
palette_number=0;
offset_type = OFFSET_NONE;
offset_amount = 0;
border_terrain = TERRAIN_ANY;
border_structure = STRUCTURE_ANY;
}
c_tile::c_tile(void)
{
height_max = 999;
height_min = -999;
special_terrain = TERRAIN_ANY;
structure = STRUCTURE_NONE;
priority = 0;
}
c_tile::~c_tile(void)
{
}
void c_tile::draw(float x, float y, int height, int bottom, int surface, s_map_block * block, TileSet * tileset, bool flip, e_layer drawlayer)
{
switch (drawlayer)
{
case LAYER_BASE:
//Draw ocean layer first.
if(height < surface)
{
for(unsigned int i = 0; i < intermediate_sprites.size(); i++)
{
int num_sections = (surface - height) / intermediate_sprites.at(i).column_height;
int bottom_section_height = (surface - height) % intermediate_sprites.at(i).column_height;
int offset = get_offset(
intermediate_sprites.at(i).offset_type,
block->structure==STRUCTURE_NONE?
(block->terrain_borders[intermediate_sprites.at(i).border_terrain?intermediate_sprites.at(i).border_terrain:block->terrain])
:block->structure_borders[intermediate_sprites.at(i).border_structure?intermediate_sprites.at(i).border_structure:block->structure],
block,
intermediate_sprites.at(i).offset_amount);
if(bottom_section_height)
{
draw_sprite(
tileset,
intermediate_sprites.at(i),
block,
x,
y - surface + (num_sections * intermediate_sprites.at(i).column_height),
intermediate_sprites.at(i).column_height - bottom_section_height,
flip,
offset,
true);
}
for( int sec = 0; sec < num_sections; sec++)
{
draw_sprite(
tileset,
intermediate_sprites.at(i),
block,
x,
y - surface + (sec * intermediate_sprites.at(i).column_height),
0,
flip,
offset);
}
}
}
//next comes the bottom layers
if ((height-bottom) <= 0)
{
for(unsigned int i = 0; i < top_sprites.size(); i++)
{
int offset = get_offset(
top_sprites.at(i).offset_type,
block->structure==STRUCTURE_NONE?
(block->terrain_borders[top_sprites.at(i).border_terrain?top_sprites.at(i).border_terrain:block->terrain])
:block->structure_borders[top_sprites.at(i).border_structure?top_sprites.at(i).border_structure:block->structure],
block,
top_sprites.at(i).offset_amount);
draw_sprite(
tileset,
top_sprites.at(i),
block,
x,
y - height,
0,
flip,
offset);
}
}
else
{
for(unsigned int i = 0; i < bottom_sprites.size(); i++)
{
int num_sections = (height - bottom) / bottom_sprites.at(i).column_height;
int bottom_section_height = (height - bottom) % bottom_sprites.at(i).column_height;
int offset = get_offset(
bottom_sprites.at(i).offset_type,
block->structure==STRUCTURE_NONE?
(block->terrain_borders[bottom_sprites.at(i).border_terrain?bottom_sprites.at(i).border_terrain:block->terrain])
:block->structure_borders[bottom_sprites.at(i).border_structure?bottom_sprites.at(i).border_structure:block->structure],
block,
bottom_sprites.at(i).offset_amount);
if(bottom_section_height)
{
draw_sprite(
tileset,
bottom_sprites.at(i),
block,
x,
y - height + (num_sections * bottom_sprites.at(i).column_height),
bottom_sprites.at(i).column_height - bottom_section_height,
flip,
offset);
}
for( int sec = 0; sec < num_sections; sec++)
{
draw_sprite(
tileset,
bottom_sprites.at(i),
block,
x,
y - height + (sec * bottom_sprites.at(i).column_height),
0,
flip,
offset);
}
}
for(unsigned int i = 0; i < top_sprites.size(); i++)
{
int offset = get_offset(
top_sprites.at(i).offset_type,
block->structure==STRUCTURE_NONE?
(block->terrain_borders[top_sprites.at(i).border_terrain?top_sprites.at(i).border_terrain:block->terrain])
:block->structure_borders[top_sprites.at(i).border_structure?top_sprites.at(i).border_structure:block->structure],
block,
top_sprites.at(i).offset_amount);
draw_sprite(
tileset,
top_sprites.at(i),
block,
x,
y - height,
0,
flip,
offset);
}
}
for(unsigned int i = 0; i < surface_sprites.size(); i++)
{
int offset = get_offset(
surface_sprites.at(i).offset_type,
block->structure==STRUCTURE_NONE?
(block->terrain_borders[surface_sprites.at(i).border_terrain?surface_sprites.at(i).border_terrain:block->terrain])
:block->structure_borders[surface_sprites.at(i).border_structure?surface_sprites.at(i).border_structure:block->structure],
block,
surface_sprites.at(i).offset_amount);
draw_sprite(
tileset,
surface_sprites.at(i),
block,
x,
y-surface,
0,
flip,
offset);
}
break;
case LAYER_OBJECT:
for(unsigned int i = 0; i < object_sprites.size(); i++)
{
int offset = get_offset(
object_sprites.at(i).offset_type,
block->structure==STRUCTURE_NONE?
(block->terrain_borders[object_sprites.at(i).border_terrain?object_sprites.at(i).border_terrain:block->terrain])
:block->structure_borders[object_sprites.at(i).border_structure?object_sprites.at(i).border_structure:block->structure],
block,
object_sprites.at(i).offset_amount);
draw_sprite(
tileset,
object_sprites.at(i),
block,
x,
y-surface,
0,
flip,
offset);
}
break;
}
}
void c_tile::load_ini(ALLEGRO_PATH * path)
{
ALLEGRO_CONFIG * config = 0;
const char * thepath = al_path_cstr(path, ALLEGRO_NATIVE_PATH_SEP);
log_printf("Loading tile at: %s\n", thepath);
config = al_load_config_file(thepath);
if(!config)
{
DisplayErr("Cannot load tile: %s\n", thepath);
exit(1);
}
char buffer[256];
height_max = get_config_int(config, "SPRITE", "height_max", 280);
height_min = get_config_int(config, "SPRITE", "height_min", 0);
priority = get_config_int(config, "SPRITE", "priority", 0);
const char * terra = al_get_config_value(config, "SPRITE", "special_terrain");
if(terra)
special_terrain = get_terrain_type(terra);
const char * cons = al_get_config_value(config, "SPRITE", "special_object");
if(cons)
structure = get_structure_type(cons);
s_sprite temp;
size_t cap_layers = get_config_int(config, "SPRITE", "cap_layers");
for(size_t i = 0; i < cap_layers; i++)
{
sprintf(buffer, "CAP_IMAGE_%d", int(i));
temp = get_from_ini(config, buffer, path);
if(temp.index >= 0)
top_sprites.push_back(temp);
}
size_t column_layers = get_config_int(config, "SPRITE", "column_layers");
for(size_t i = 0; i < column_layers; i++)
{
sprintf(buffer, "COLUMN_IMAGE_%d", int(i));
temp = get_from_ini(config, buffer, path);
if(temp.index >= 0)
bottom_sprites.push_back(temp);
}
size_t surface_layers = get_config_int(config, "SPRITE", "surface_layers");
for(size_t i = 0; i < surface_layers; i++)
{
sprintf(buffer, "SURFACE_IMAGE_%d", int(i));
temp = get_from_ini(config, buffer, path);
if(temp.index >= 0)
surface_sprites.push_back(temp);
}
size_t intermediate_layers = get_config_int(config, "SPRITE", "intermediate_layers");
for(size_t i = 0; i < intermediate_layers; i++)
{
sprintf(buffer, "INTERMEDIATE_IMAGE_%d", int(i));
temp = get_from_ini(config, buffer, path);
if(temp.index >= 0)
intermediate_sprites.push_back(temp);
}
size_t object_layers = get_config_int(config, "SPRITE", "object_layers");
for(size_t i = 0; i < object_layers; i++)
{
sprintf(buffer, "OBJECT_IMAGE_%d", int(i));
temp = get_from_ini(config, buffer, path);
if(temp.index >= 0)
object_sprites.push_back(temp);
}
}
s_sprite c_tile::get_from_ini(ALLEGRO_CONFIG *config, const char * section, ALLEGRO_PATH * base_path)
{
s_sprite temp;
const char * buffer_file = al_get_config_value(config, section, "image_file");
if(!buffer_file)
{
temp.index = -1;
return temp;
}
ALLEGRO_PATH * imagepath = al_create_path(buffer_file);
al_rebase_path(base_path, imagepath);
temp.index = imagelist.load_image(al_path_cstr(imagepath, ALLEGRO_NATIVE_PATH_SEP));
temp.x = get_config_int(config, section, "x");
temp.y = get_config_int(config, section, "y");
temp.width = get_config_int(config, section, "width");
temp.height = get_config_int(config, section, "height");
temp.origin_x = get_config_int(config, section, "origin_x");
temp.origin_y = get_config_int(config, section, "origin_y");
temp.origin_x = 0 - temp.origin_x;
temp.origin_y = 0 - temp.origin_y;
temp.palette_number = get_config_int(config, section, "palette_index");
temp.column_height = get_config_int(config, section, "column_height");
const char * color_selection = al_get_config_value(config, section, "color_source");
if(color_selection)
temp.color_by = get_color_selector(color_selection);
const char * pal_source = al_get_config_value(config, section, "palette_source");
if(pal_source)
temp.color_source = get_color_source(pal_source);
const char * color = al_get_config_value(config, section, "color_html");
if(color)
temp.color = color_html(color);
const char * off = al_get_config_value(config, section, "offset_type");
if(off)
temp.offset_type = get_offset_type(off);
const char * neigh = al_get_config_value(config, section, "border_terrain");
if(neigh)
temp.border_terrain = get_terrain_type(neigh);
const char * neighbobj = al_get_config_value(config, section, "border_structure");
if(neighbobj)
temp.border_structure = get_structure_type(neighbobj);
temp.offset_amount = get_config_int(config, section, "offset_amount");
al_destroy_path(imagepath);
return temp;
}