-
Notifications
You must be signed in to change notification settings - Fork 976
Expand file tree
/
Copy pathautomap.cpp
More file actions
1975 lines (1745 loc) · 85.4 KB
/
automap.cpp
File metadata and controls
1975 lines (1745 loc) · 85.4 KB
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
/**
* @file automap.cpp
*
* Implementation of the in-game map overlay.
*/
#include "automap.h"
#include <algorithm>
#include <cstdint>
#include <fmt/format.h>
#include "control/control.hpp"
#include "engine/load_file.hpp"
#include "engine/palette.h"
#include "engine/render/automap_render.hpp"
#include "engine/render/primitive_render.hpp"
#include "levels/gendung.h"
#include "levels/setmaps.h"
#include "options.h"
#include "player.h"
#include "utils/attributes.h"
#include "utils/enum_traits.h"
#include "utils/is_of.hpp"
#include "utils/language.h"
#include "utils/ui_fwd.h"
#include "utils/utf8.hpp"
#ifdef _DEBUG
#include "debug.h"
#include "lighting.h"
#endif
namespace devilution {
namespace {
Point Automap;
enum MapColors : uint8_t {
/** color used to draw the player's arrow */
MapColorsPlayer1 = (PAL8_ORANGE + 1),
MapColorsPlayer2 = (PAL8_YELLOW + 1),
MapColorsPlayer3 = (PAL8_RED + 1),
MapColorsPlayer4 = (PAL8_BLUE + 1),
/** color for bright map lines (doors, stairs etc.) */
MapColorsBright = PAL8_YELLOW,
/** color for dim map lines/dots */
MapColorsDim = (PAL16_YELLOW + 8),
/** color for items on automap */
MapColorsItem = (PAL8_BLUE + 1),
/** color for activated pentragram on automap */
MapColorsPentagramOpen = (PAL8_RED + 2),
/** color for cave lava on automap */
MapColorsLava = (PAL8_ORANGE + 2),
/** color for cave water on automap */
MapColorsWater = (PAL8_BLUE + 2),
/** color for hive acid on automap */
MapColorsAcid = (PAL8_YELLOW + 4),
};
struct AutomapTile {
/** The general shape of the tile */
enum class Types : uint8_t {
None,
Diamond,
Vertical,
Horizontal,
Cross,
FenceVertical,
FenceHorizontal,
Corner,
CaveHorizontalCross,
CaveVerticalCross,
CaveHorizontal,
CaveVertical,
CaveCross,
Bridge,
River,
RiverCornerEast,
RiverCornerNorth,
RiverCornerSouth,
RiverCornerWest,
RiverForkIn,
RiverForkOut,
RiverLeftIn,
RiverLeftOut,
RiverRightIn,
RiverRightOut,
CaveHorizontalWoodCross,
CaveVerticalWoodCross,
CaveLeftCorner,
CaveRightCorner,
CaveBottomCorner,
CaveHorizontalWood,
CaveVerticalWood,
CaveWoodCross,
CaveRightWoodCross,
CaveLeftWoodCross,
HorizontalLavaThin,
VerticalLavaThin,
BendSouthLavaThin,
BendWestLavaThin,
BendEastLavaThin,
BendNorthLavaThin,
VerticalWallLava,
HorizontalWallLava,
SELava,
SWLava,
NELava,
NWLava,
SLava,
WLava,
ELava,
NLava,
Lava,
CaveHorizontalWallLava,
CaveVerticalWallLava,
HorizontalBridgeLava,
VerticalBridgeLava,
VerticalDiamond,
HorizontalDiamond,
PentagramClosed,
PentagramOpen,
};
Types type;
/** Additional details about the given tile */
enum class Flags : uint8_t {
// clang-format off
VerticalDoor = 1 << 0,
HorizontalDoor = 1 << 1,
VerticalArch = 1 << 2,
HorizontalArch = 1 << 3,
VerticalGrate = 1 << 4,
HorizontalGrate = 1 << 5,
VerticalPassage = VerticalDoor | VerticalArch | VerticalGrate,
HorizontalPassage = HorizontalDoor | HorizontalArch | HorizontalGrate,
Dirt = 1 << 6,
Stairs = 1 << 7,
// clang-format on
};
Flags flags = {};
[[nodiscard]] DVL_ALWAYS_INLINE constexpr bool hasFlag(Flags test) const
{
return (static_cast<uint8_t>(flags) & static_cast<uint8_t>(test)) != 0;
}
template <typename... Args>
[[nodiscard]] DVL_ALWAYS_INLINE constexpr bool hasAnyFlag(Flags flag, Args... testFlags)
{
return (static_cast<uint8_t>(this->flags)
& (static_cast<uint8_t>(flag) | ... | static_cast<uint8_t>(testFlags)))
!= 0;
}
};
/**
* Maps from tile_id to automap type.
*/
std::array<AutomapTile, 256> AutomapTypeTiles;
/**
* @brief Draw a diamond on top tile.
*/
void DrawDiamond(const Surface &out, Point center, uint8_t color)
{
DrawMapLineNE(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileUp), AmLine(AmLineLength::FullTile), color);
DrawMapLineSE(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileUp), AmLine(AmLineLength::FullTile), color);
DrawMapLineSE(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileUp), AmLine(AmLineLength::FullTile), color);
DrawMapLineNE(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::None), AmLine(AmLineLength::FullTile), color);
}
/**
* @brief Draws a bright diamond and a line, orientation depending on the tileset.
*/
void DrawMapVerticalDoor(const Surface &out, Point center, AutomapTile neTile, uint8_t colorBright, uint8_t colorDim)
{
AmWidthOffset lWidthOffset;
AmHeightOffset lHeightOffset;
AmWidthOffset dWidthOffset;
AmHeightOffset dHeightOffset;
AmLineLength length;
switch (leveltype) {
case DTYPE_CATHEDRAL:
case DTYPE_CRYPT:
lWidthOffset = AmWidthOffset::QuarterTileLeft;
lHeightOffset = AmHeightOffset::QuarterTileUp;
dWidthOffset = AmWidthOffset::HalfTileLeft;
dHeightOffset = AmHeightOffset::HalfTileDown;
length = AmLineLength::HalfTile;
break;
case DTYPE_CATACOMBS:
lWidthOffset = AmWidthOffset::ThreeQuartersTileLeft;
lHeightOffset = AmHeightOffset::QuarterTileDown;
dWidthOffset = AmWidthOffset::None;
dHeightOffset = AmHeightOffset::None;
length = AmLineLength::FullTile;
break;
case DTYPE_CAVES:
lWidthOffset = AmWidthOffset::QuarterTileLeft;
lHeightOffset = AmHeightOffset::ThreeQuartersTileDown;
dWidthOffset = AmWidthOffset::HalfTileRight;
dHeightOffset = AmHeightOffset::HalfTileDown;
length = AmLineLength::FullTile;
break;
default:
app_fatal("Invalid leveltype");
}
if (!(neTile.hasFlag(AutomapTile::Flags::VerticalPassage) && leveltype == DTYPE_CATHEDRAL))
DrawMapLineNE(out, center + AmOffset(lWidthOffset, lHeightOffset), AmLine(length), colorDim);
DrawDiamond(out, center + AmOffset(dWidthOffset, dHeightOffset), colorBright);
}
/**
* @brief Draws a bright diamond and a line, orientation depending on the tileset.
*/
void DrawMapHorizontalDoor(const Surface &out, Point center, AutomapTile nwTile, uint8_t colorBright, uint8_t colorDim)
{
AmWidthOffset lWidthOffset;
AmHeightOffset lHeightOffset;
AmWidthOffset dWidthOffset;
AmHeightOffset dHeightOffset;
AmLineLength length;
switch (leveltype) {
case DTYPE_CATHEDRAL:
case DTYPE_CRYPT:
lWidthOffset = AmWidthOffset::None;
lHeightOffset = AmHeightOffset::HalfTileUp;
dWidthOffset = AmWidthOffset::HalfTileRight;
dHeightOffset = AmHeightOffset::HalfTileDown;
length = AmLineLength::HalfTile;
break;
case DTYPE_CATACOMBS:
lWidthOffset = AmWidthOffset::QuarterTileRight;
lHeightOffset = AmHeightOffset::QuarterTileUp;
dWidthOffset = AmWidthOffset::None;
dHeightOffset = AmHeightOffset::None;
length = AmLineLength::FullTile;
break;
case DTYPE_CAVES:
lWidthOffset = AmWidthOffset::QuarterTileLeft;
lHeightOffset = AmHeightOffset::QuarterTileDown;
dWidthOffset = AmWidthOffset::HalfTileLeft;
dHeightOffset = AmHeightOffset::HalfTileDown;
length = AmLineLength::FullTile;
break;
break;
default:
app_fatal("Invalid leveltype");
}
if (!(nwTile.hasFlag(AutomapTile::Flags::HorizontalPassage) && leveltype == DTYPE_CATHEDRAL))
DrawMapLineSE(out, center + AmOffset(lWidthOffset, lHeightOffset), AmLine(length), colorDim);
DrawDiamond(out, center + AmOffset(dWidthOffset, dHeightOffset), colorBright);
}
/**
* @brief Draw 16 individual pixels equally spaced apart, used to communicate OOB area to the player.
*/
void DrawDirt(const Surface &out, Point center, AutomapTile nwTile, AutomapTile neTile, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), color);
// Prevent the top dirt pixel from appearing inside arch diamonds
if (!nwTile.hasAnyFlag(AutomapTile::Flags::HorizontalArch, AutomapTile::Flags::HorizontalGrate)
&& !neTile.hasAnyFlag(AutomapTile::Flags::VerticalArch, AutomapTile::Flags::VerticalGrate))
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileUp), color);
SetMapPixel(out, center, color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), color);
}
void DrawBridge(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center, color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), color);
}
void DrawRiverRightIn(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center, color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), color);
}
void DrawRiverCornerSouth(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), color);
}
void DrawRiverCornerNorth(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color);
}
void DrawRiverLeftOut(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center, color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), color);
}
void DrawRiverLeftIn(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileUp), color);
SetMapPixel(out, center, color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color);
}
void DrawRiverCornerWest(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None), color);
}
void DrawRiverCornerEast(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), color);
}
void DrawRiverRightOut(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center, color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), color);
}
void DrawRiver(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center, color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), color);
}
void DrawRiverForkIn(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::FullTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileUp), color);
SetMapPixel(out, center, color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), color);
}
void DrawRiverForkOut(const Surface &out, Point center, uint8_t color)
{
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileLeft, AmHeightOffset::QuarterTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color);
}
template <Direction TDir1, Direction TDir2>
void DrawLavaRiver(const Surface &out, Point center, uint8_t color, bool hasBridge)
{
// First row (y = 0)
if constexpr (IsAnyOf(Direction::NorthWest, TDir1, TDir2)) {
if (!(hasBridge && IsAnyOf(TDir1, Direction::NorthWest))) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileUp), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None), color);
}
}
// Second row (y = 1)
if constexpr (IsAnyOf(Direction::NorthEast, TDir1, TDir2)) {
if (!(hasBridge && IsAnyOf(Direction::NorthEast, TDir1, TDir2)))
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color);
}
if constexpr (IsAnyOf(Direction::NorthWest, TDir1, TDir2) || IsAnyOf(Direction::NorthEast, TDir1, TDir2)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::None), color);
}
if constexpr (IsAnyOf(Direction::SouthWest, TDir1, TDir2) || IsAnyOf(Direction::NorthWest, TDir1, TDir2)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown), color);
}
if constexpr (IsAnyOf(Direction::SouthWest, TDir1, TDir2)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), color);
}
// Third row (y = 2)
if constexpr (IsAnyOf(Direction::NorthEast, TDir1, TDir2)) {
if (!(hasBridge && IsAnyOf(Direction::NorthEast, TDir1, TDir2)))
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color);
}
if constexpr (IsAnyOf(Direction::NorthEast, TDir1, TDir2) || IsAnyOf(Direction::SouthEast, TDir1, TDir2)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color);
}
if constexpr (IsAnyOf(Direction::SouthWest, TDir1, TDir2) || IsAnyOf(Direction::SouthEast, TDir1, TDir2)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), color);
}
if constexpr (IsAnyOf(Direction::SouthWest, TDir1, TDir2)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), color);
}
// Fourth row (y = 3)
if constexpr (IsAnyOf(Direction::SouthEast, TDir1, TDir2)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color);
}
}
template <Direction TDir>
void DrawLava(const Surface &out, Point center, uint8_t color)
{
if constexpr (IsAnyOf(TDir, Direction::NorthWest, Direction::North, Direction::NorthEast, Direction::NoDirection)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileUp), color); // north corner
}
if constexpr (IsNoneOf(TDir, Direction::South, Direction::SouthEast, Direction::East)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileUp), color); // northwest edge
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None), color); // northwest edge
}
if constexpr (IsAnyOf(TDir, Direction::SouthWest, Direction::West, Direction::NorthWest, Direction::NoDirection)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileLeft, AmHeightOffset::QuarterTileDown), color); // west corner
}
if constexpr (IsAnyOf(TDir, Direction::South, Direction::SouthWest, Direction::West, Direction::NorthWest, Direction::SouthEast, Direction::NoDirection)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), color); // southwest edge
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), color); // southwest edge
}
if constexpr (IsAnyOf(TDir, Direction::South, Direction::SouthWest, Direction::SouthEast, Direction::NoDirection)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), color); // south corner
}
if constexpr (IsAnyOf(TDir, Direction::South, Direction::SouthWest, Direction::NorthEast, Direction::East, Direction::SouthEast, Direction::NoDirection)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), color); // southeast edge
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), color); // southeast edge
}
if constexpr (IsAnyOf(TDir, Direction::NorthEast, Direction::East, Direction::SouthEast, Direction::NoDirection)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), color); // east corner
}
if constexpr (IsNoneOf(TDir, Direction::South, Direction::SouthWest, Direction::West)) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileUp), color); // northeast edge
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), color); // northeast edge
}
if constexpr (TDir != Direction::South) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::None), color); // north center
}
if constexpr (TDir != Direction::East) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown), color); // west center
}
if constexpr (TDir != Direction::West) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::QuarterTileDown), color); // east center
}
if constexpr (TDir != Direction::North) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), color); // south center
}
}
/**
* @brief Draw 4 south-east facing lines, used to communicate trigger locations to the player.
*/
void DrawStairs(const Surface &out, Point center, uint8_t color)
{
constexpr int NumStairSteps = 4;
const Displacement offset = AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::QuarterTileDown);
AmWidthOffset w = AmWidthOffset::QuarterTileLeft;
AmHeightOffset h = AmHeightOffset::QuarterTileUp;
if (IsAnyOf(leveltype, DTYPE_CATACOMBS, DTYPE_HELL)) {
w = AmWidthOffset::QuarterTileLeft;
h = AmHeightOffset::ThreeQuartersTileUp;
}
// Initial point based on the 'center' position.
Point p = center + AmOffset(w, h);
for (int i = 0; i < NumStairSteps; ++i) {
DrawMapLineSE(out, p, AmLine(AmLineLength::DoubleTile), color);
p += offset;
}
}
/**
* @brief Redraws the bright line of the door diamond that gets overwritten by later drawn lines.
*/
void FixHorizontalDoor(const Surface &out, Point center, AutomapTile nwTile, uint8_t colorBright)
{
if (leveltype != DTYPE_CATACOMBS && nwTile.hasFlag(AutomapTile::Flags::HorizontalDoor)) {
DrawMapLineNE(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileUp), AmLine(AmLineLength::FullTile), colorBright);
}
}
/**
* @brief Redraws the bright line of the door diamond that gets overwritten by later drawn lines.
*/
void FixVerticalDoor(const Surface &out, Point center, AutomapTile neTile, uint8_t colorBright)
{
if (leveltype != DTYPE_CATACOMBS && neTile.hasFlag(AutomapTile::Flags::VerticalDoor)) {
DrawMapLineSE(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileUp), AmLine(AmLineLength::FullTile), colorBright);
}
}
/**
* @brief Draw half-tile length lines to connect walls to any walls to the north-west and/or north-east
*/
void DrawWallConnections(const Surface &out, Point center, AutomapTile tile, AutomapTile nwTile, AutomapTile neTile, uint8_t colorBright, uint8_t colorDim)
{
if (tile.hasFlag(AutomapTile::Flags::HorizontalDoor) && nwTile.hasFlag(AutomapTile::Flags::HorizontalDoor)) {
// fix missing lower half of the line connecting door pairs in Lazarus' level
DrawMapLineSE(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileUp), AmLine(AmLineLength::HalfTile), colorDim);
}
if (IsAnyOf(nwTile.type, AutomapTile::Types::HorizontalWallLava, AutomapTile::Types::Horizontal, AutomapTile::Types::HorizontalDiamond, AutomapTile::Types::FenceHorizontal, AutomapTile::Types::Cross, AutomapTile::Types::CaveVerticalWoodCross, AutomapTile::Types::CaveRightCorner)) {
DrawMapLineSE(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileUp), AmLine(AmLineLength::HalfTile), colorDim);
FixHorizontalDoor(out, center, nwTile, colorBright);
}
if (IsAnyOf(neTile.type, AutomapTile::Types::VerticalWallLava, AutomapTile::Types::Vertical, AutomapTile::Types::VerticalDiamond, AutomapTile::Types::FenceVertical, AutomapTile::Types::Cross, AutomapTile::Types::CaveHorizontalWoodCross, AutomapTile::Types::CaveLeftCorner)) {
DrawMapLineNE(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileUp), AmLine(AmLineLength::HalfTile), colorDim);
FixVerticalDoor(out, center, neTile, colorBright);
}
}
/**
* @brief Draws a dotted line to represent a wall grate.
*/
void DrawMapVerticalGrate(const Surface &out, Point center, uint8_t colorDim)
{
const Point pos1 = center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None) + AmOffset(AmWidthOffset::EighthTileRight, AmHeightOffset::EighthTileUp);
const Point pos2 = center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None);
const Point pos3 = center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::None) + AmOffset(AmWidthOffset::EighthTileLeft, AmHeightOffset::EighthTileDown);
SetMapPixel(out, pos1 + Displacement { 0, 1 }, 0);
SetMapPixel(out, pos2 + Displacement { 0, 1 }, 0);
SetMapPixel(out, pos3 + Displacement { 0, 1 }, 0);
SetMapPixel(out, pos1, colorDim);
SetMapPixel(out, pos2, colorDim);
SetMapPixel(out, pos3, colorDim);
}
/**
* @brief Draws a dotted line to represent a wall grate.
*/
void DrawMapHorizontalGrate(const Surface &out, Point center, uint8_t colorDim)
{
const Point pos1 = center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None) + AmOffset(AmWidthOffset::EighthTileLeft, AmHeightOffset::EighthTileUp);
const Point pos2 = center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None);
const Point pos3 = center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None) + AmOffset(AmWidthOffset::EighthTileRight, AmHeightOffset::EighthTileDown);
SetMapPixel(out, pos1 + Displacement { 0, 1 }, 0);
SetMapPixel(out, pos2 + Displacement { 0, 1 }, 0);
SetMapPixel(out, pos3 + Displacement { 0, 1 }, 0);
SetMapPixel(out, pos1, colorDim);
SetMapPixel(out, pos2, colorDim);
SetMapPixel(out, pos3, colorDim);
}
/**
* Left-facing obstacle
*/
void DrawHorizontal(const Surface &out, Point center, AutomapTile tile, AutomapTile nwTile, AutomapTile neTile, AutomapTile seTile, uint8_t colorBright, uint8_t colorDim)
{
AmWidthOffset w = AmWidthOffset::None;
AmHeightOffset h = AmHeightOffset::HalfTileUp;
AmLineLength l = AmLineLength::FullAndHalfTile;
// Draw a diamond in the top tile
if (neTile.hasAnyFlag(AutomapTile::Flags::VerticalArch, AutomapTile::Flags::VerticalGrate) // NE tile has an arch, so add a diamond for visual consistency
|| nwTile.hasAnyFlag(AutomapTile::Flags::HorizontalArch, AutomapTile::Flags::HorizontalGrate) // NW tile has an arch, so add a diamond for visual consistency
|| tile.hasAnyFlag(AutomapTile::Flags::VerticalArch, AutomapTile::Flags::HorizontalArch, AutomapTile::Flags::VerticalGrate, AutomapTile::Flags::HorizontalGrate) // Current tile has an arch, add a diamond
|| tile.type == AutomapTile::Types::HorizontalDiamond) { // wall ending in hell that should end with a diamond
w = AmWidthOffset::QuarterTileRight;
h = AmHeightOffset::QuarterTileUp;
l = AmLineLength::FullTile; // shorten line to avoid overdraw
DrawDiamond(out, center, colorDim);
FixHorizontalDoor(out, center, nwTile, colorBright);
FixVerticalDoor(out, center, neTile, colorBright);
}
// Shorten line to avoid overdraw
if (IsAnyOf(leveltype, DTYPE_CAVES, DTYPE_NEST)
&& IsAnyOf(tile.type, AutomapTile::Types::CaveVerticalCross, AutomapTile::Types::CaveVerticalWoodCross)
&& !(IsAnyOf(seTile.type, AutomapTile::Types::Horizontal, AutomapTile::Types::CaveVerticalCross, AutomapTile::Types::CaveVerticalWoodCross, AutomapTile::Types::Corner))) {
l = AmLineLength::FullTile;
}
// Draw the wall line if the wall is solid
if (!tile.hasFlag(AutomapTile::Flags::HorizontalPassage)) {
DrawMapLineSE(out, center + AmOffset(w, h), AmLine(l), colorDim);
return;
}
// Draw door or grate
if (tile.hasFlag(AutomapTile::Flags::HorizontalDoor)) {
DrawMapHorizontalDoor(out, center, nwTile, colorBright, colorDim);
} else if (tile.hasFlag(AutomapTile::Flags::HorizontalGrate)) {
DrawMapHorizontalGrate(out, center, colorDim);
}
}
/**
* Right-facing obstacle
*/
void DrawVertical(const Surface &out, Point center, AutomapTile tile, AutomapTile nwTile, AutomapTile neTile, AutomapTile swTile, uint8_t colorBright, uint8_t colorDim)
{
AmWidthOffset w = AmWidthOffset::ThreeQuartersTileLeft;
AmHeightOffset h = AmHeightOffset::QuarterTileDown;
AmLineLength l = AmLineLength::FullAndHalfTile;
// Draw a diamond in the top tile
if (neTile.hasAnyFlag(AutomapTile::Flags::VerticalArch, AutomapTile::Flags::VerticalGrate) // NE tile has an arch, so add a diamond for visual consistency
|| nwTile.hasAnyFlag(AutomapTile::Flags::HorizontalArch, AutomapTile::Flags::HorizontalGrate) // NW tile has an arch, so add a diamond for visual consistency
|| tile.hasAnyFlag(AutomapTile::Flags::VerticalArch, AutomapTile::Flags::HorizontalArch, AutomapTile::Flags::VerticalGrate, AutomapTile::Flags::HorizontalGrate) // Current tile has an arch, add a diamond
|| tile.type == AutomapTile::Types::VerticalDiamond) { // wall ending in hell that should end with a diamond
l = AmLineLength::FullTile; // shorten line to avoid overdraw
DrawDiamond(out, center, colorDim);
FixVerticalDoor(out, center, nwTile, colorBright);
FixVerticalDoor(out, center, neTile, colorBright);
}
// Shorten line to avoid overdraw and adjust offset to match
if (IsAnyOf(leveltype, DTYPE_CAVES, DTYPE_NEST)
&& IsAnyOf(tile.type, AutomapTile::Types::CaveHorizontalCross, AutomapTile::Types::CaveHorizontalWoodCross)
&& !(IsAnyOf(swTile.type, AutomapTile::Types::Vertical, AutomapTile::Types::CaveHorizontalCross, AutomapTile::Types::CaveHorizontalWoodCross, AutomapTile::Types::Corner))) {
w = AmWidthOffset::HalfTileLeft;
h = AmHeightOffset::None;
l = AmLineLength::FullTile;
}
// Draw the wall line if the wall is solid
if (!tile.hasFlag(AutomapTile::Flags::VerticalPassage)) {
DrawMapLineNE(out, center + AmOffset(w, h), AmLine(l), colorDim);
return;
}
// Draw door or grate
if (tile.hasFlag(AutomapTile::Flags::VerticalDoor)) {
DrawMapVerticalDoor(out, center, neTile, colorBright, colorDim);
} else if (tile.hasFlag(AutomapTile::Flags::VerticalGrate)) {
DrawMapVerticalGrate(out, center, colorDim);
}
}
/**
* @brief Draw half-tile length lines to connect walls to any walls to the south-west and/or south-east
* (For caves the horizontal/vertical flags are swapped)
*/
void DrawCaveWallConnections(const Surface &out, Point center, AutomapTile sTile, AutomapTile swTile, AutomapTile seTile, uint8_t colorDim)
{
if (IsAnyOf(swTile.type, AutomapTile::Types::CaveVerticalWallLava, AutomapTile::Types::CaveVertical, AutomapTile::Types::CaveVerticalWood, AutomapTile::Types::CaveCross, AutomapTile::Types::CaveWoodCross, AutomapTile::Types::CaveRightWoodCross, AutomapTile::Types::CaveLeftWoodCross, AutomapTile::Types::CaveRightCorner)) {
DrawMapLineNE(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), AmLine(AmLineLength::HalfTile), colorDim);
}
if (IsAnyOf(seTile.type, AutomapTile::Types::CaveHorizontalWallLava, AutomapTile::Types::CaveHorizontal, AutomapTile::Types::CaveHorizontalWood, AutomapTile::Types::CaveCross, AutomapTile::Types::CaveWoodCross, AutomapTile::Types::CaveRightWoodCross, AutomapTile::Types::CaveLeftWoodCross, AutomapTile::Types::CaveLeftCorner)) {
DrawMapLineSE(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown), AmLine(AmLineLength::HalfTile), colorDim);
}
}
void DrawCaveHorizontalDirt(const Surface &out, Point center, AutomapTile tile, AutomapTile swTile, uint8_t colorDim)
{
if (swTile.hasFlag(AutomapTile::Flags::Dirt) || (leveltype != DTYPE_TOWN && IsNoneOf(tile.type, AutomapTile::Types::CaveHorizontalWood, AutomapTile::Types::CaveHorizontalWoodCross, AutomapTile::Types::CaveWoodCross, AutomapTile::Types::CaveLeftWoodCross))) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileLeft, AmHeightOffset::QuarterTileDown), colorDim);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileLeft, AmHeightOffset::HalfTileDown), colorDim);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileLeft, AmHeightOffset::ThreeQuartersTileDown), colorDim);
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), colorDim);
}
}
/**
* For caves the horizontal/vertical flags are swapped
*/
void DrawCaveHorizontal(const Surface &out, Point center, AutomapTile tile, AutomapTile nwTile, AutomapTile swTile, uint8_t colorBright, uint8_t colorDim)
{
if (tile.hasFlag(AutomapTile::Flags::VerticalDoor)) {
DrawMapHorizontalDoor(out, center, nwTile, colorBright, colorDim);
} else {
AmWidthOffset w;
AmHeightOffset h;
AmLineLength l;
if (IsAnyOf(tile.type, AutomapTile::Types::CaveHorizontalCross, AutomapTile::Types::CaveHorizontalWoodCross)) {
w = AmWidthOffset::HalfTileLeft;
h = AmHeightOffset::None;
l = AmLineLength::FullTile;
} else {
w = AmWidthOffset::ThreeQuartersTileLeft;
h = AmHeightOffset::QuarterTileUp;
l = AmLineLength::FullAndHalfTile;
}
DrawCaveHorizontalDirt(out, center, tile, swTile, colorDim);
DrawMapLineSE(out, center + AmOffset(w, h), AmLine(l), colorDim);
}
}
void DrawCaveVerticalDirt(const Surface &out, Point center, AutomapTile tile, AutomapTile seTile, uint8_t colorDim)
{
if (seTile.hasFlag(AutomapTile::Flags::Dirt) || (leveltype != DTYPE_TOWN && IsNoneOf(tile.type, AutomapTile::Types::CaveVerticalWood, AutomapTile::Types::CaveVerticalWoodCross, AutomapTile::Types::CaveWoodCross, AutomapTile::Types::CaveRightWoodCross))) {
SetMapPixel(out, center + AmOffset(AmWidthOffset::None, AmHeightOffset::FullTileDown), colorDim);
SetMapPixel(out, center + AmOffset(AmWidthOffset::QuarterTileRight, AmHeightOffset::ThreeQuartersTileDown), colorDim);
SetMapPixel(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::HalfTileDown), colorDim);
SetMapPixel(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileRight, AmHeightOffset::QuarterTileDown), colorDim);
}
}
/**
* For caves the horizontal/vertical flags are swapped
*/
void DrawCaveVertical(const Surface &out, Point center, AutomapTile tile, AutomapTile neTile, AutomapTile seTile, uint8_t colorBright, uint8_t colorDim)
{
if (tile.hasFlag(AutomapTile::Flags::HorizontalDoor)) {
DrawMapVerticalDoor(out, center, neTile, colorBright, colorDim);
} else {
AmLineLength l;
if (IsAnyOf(tile.type, AutomapTile::Types::CaveVerticalCross, AutomapTile::Types::CaveVerticalWoodCross)) {
l = AmLineLength::FullTile;
} else {
l = AmLineLength::FullAndHalfTile;
}
DrawCaveVerticalDirt(out, center, tile, seTile, colorDim);
DrawMapLineNE(out, { center + AmOffset(AmWidthOffset::None, AmHeightOffset::HalfTileDown) }, AmLine(l), colorDim);
}
}
void DrawCaveLeftCorner(const Surface &out, Point center, uint8_t colorDim)
{
DrawMapLineSE(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileLeft, AmHeightOffset::QuarterTileUp), AmLine(AmLineLength::HalfTile), colorDim);
DrawMapLineNE(out, center + AmOffset(AmWidthOffset::ThreeQuartersTileLeft, AmHeightOffset::QuarterTileDown), AmLine(AmLineLength::HalfTile), colorDim);
}
void DrawCaveRightCorner(const Surface &out, Point center, uint8_t colorDim)
{
DrawMapLineSE(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), AmLine(AmLineLength::HalfTile), colorDim);
DrawMapLineNE(out, center + AmOffset(AmWidthOffset::HalfTileRight, AmHeightOffset::None), AmLine(AmLineLength::HalfTile), colorDim);
}
void DrawMapEllipse(const Surface &out, Point from, int radius, uint8_t colorIndex)
{
const int a = radius;
const int b = radius / 2;
int x = 0;
int y = b;
// Offset ellipse so the center of the ellipse is the center of our megatile on the x plane
from.x -= radius;
// Initial point
SetMapPixel(out, { from.x, from.y + b }, colorIndex);
SetMapPixel(out, { from.x, from.y - b }, colorIndex);
// Initialize the parameters
int p1 = (b * b) - (a * a * b) + (a * a) / 4;
// Region 1
while ((b * b * x) < (a * a * y)) {
x++;
if (p1 < 0) {
p1 += (2 * b * b * x) + (b * b);
} else {
y--;
p1 += (2 * b * b * x) - (2 * a * a * y) + (b * b);
}
SetMapPixel(out, { from.x + x, from.y + y }, colorIndex);
SetMapPixel(out, { from.x - x, from.y + y }, colorIndex);
SetMapPixel(out, { from.x + x, from.y - y }, colorIndex);
SetMapPixel(out, { from.x - x, from.y - y }, colorIndex);
}
// Initialize the second parameter for Region 2
int p2 = (b * b * ((x + 1) * (x + 1))) + (a * a * ((y - 1) * (y - 1))) - (a * a * b * b);
// Region 2
while (y > 0) {
y--;
if (p2 > 0) {
p2 += (-2 * a * a * y) + (a * a);
} else {
x++;
p2 += (2 * b * b * x) - (2 * a * a * y) + (a * a);
}
SetMapPixel(out, { from.x + x, from.y + y }, colorIndex);
SetMapPixel(out, { from.x - x, from.y + y }, colorIndex);
SetMapPixel(out, { from.x + x, from.y - y }, colorIndex);
SetMapPixel(out, { from.x - x, from.y - y }, colorIndex);
}
}
void DrawMapStar(const Surface &out, Point from, int radius, uint8_t color)
{
const int scaleFactor = 128;
Point anchors[5];
// Offset star so the center of the star is the center of our megatile on the x plane
from.x -= radius;
anchors[0] = { from.x - (121 * radius / scaleFactor), from.y + (19 * radius / scaleFactor) }; // Left Point
anchors[1] = { from.x + (121 * radius / scaleFactor), from.y + (19 * radius / scaleFactor) }; // Right Point
anchors[2] = { from.x, from.y + (64 * radius / scaleFactor) }; // Bottom Point
anchors[3] = { from.x - (75 * radius / scaleFactor), from.y - (51 * radius / scaleFactor) }; // Top Left Point
anchors[4] = { from.x + (75 * radius / scaleFactor), from.y - (51 * radius / scaleFactor) }; // Top Right Point
// Draw lines between the anchors to form a star
DrawMapFreeLine(out, anchors[3], anchors[1], color); // Connect Top Left -> Right
DrawMapFreeLine(out, anchors[1], anchors[0], color); // Connect Right -> Left
DrawMapFreeLine(out, anchors[0], anchors[4], color); // Connect Left -> Top Right
DrawMapFreeLine(out, anchors[4], anchors[2], color); // Connect Top Right -> Bottom
DrawMapFreeLine(out, anchors[2], anchors[3], color); // Connect Bottom -> Top Left
}
/**
* @brief Check if a given tile has the provided AutomapTile flag
*/
bool HasAutomapFlag(Point position, AutomapTile::Flags type)
{
if (position.x < 0 || position.x >= DMAXX || position.y < 0 || position.y >= DMAXX) {
return false;
}
return AutomapTypeTiles[dungeon[position.x][position.y]].hasFlag(type);
}
/**
* @brief Returns the automap shape at the given coordinate.
*/
AutomapTile GetAutomapTileType(Point position)
{
if (position.x < 0 || position.x >= DMAXX || position.y < 0 || position.y >= DMAXX) {
return {};
}
AutomapTile tile = AutomapTypeTiles[dungeon[position.x][position.y]];
if (tile.type == AutomapTile::Types::Corner) {
if (HasAutomapFlag({ position.x - 1, position.y }, AutomapTile::Flags::HorizontalArch)) {
if (HasAutomapFlag({ position.x, position.y - 1 }, AutomapTile::Flags::VerticalArch)) {
tile.type = AutomapTile::Types::Diamond;
}
}
}
return tile;
}
/**
* @brief Returns the automap shape at the given coordinate.
*/
AutomapTile GetAutomapTypeView(Point map)
{
if (map.x == -1 && map.y >= 0 && map.y < DMAXY && AutomapView[0][map.y] != MAP_EXP_NONE) {
if (HasAutomapFlag({ 0, map.y + 1 }, AutomapTile::Flags::Dirt) && HasAutomapFlag({ 0, map.y }, AutomapTile::Flags::Dirt) && HasAutomapFlag({ 0, map.y - 1 }, AutomapTile::Flags::Dirt)) {
return {};
}
return { AutomapTile::Types::None, AutomapTile::Flags::Dirt };
}
if (map.y == -1 && map.x >= 0 && map.x < DMAXY && AutomapView[map.x][0] != MAP_EXP_NONE) {
if (HasAutomapFlag({ map.x + 1, 0 }, AutomapTile::Flags::Dirt) && HasAutomapFlag({ map.x, 0 }, AutomapTile::Flags::Dirt) && HasAutomapFlag({ map.x - 1, 0 }, AutomapTile::Flags::Dirt)) {
return {};
}
return { AutomapTile::Types::None, AutomapTile::Flags::Dirt };
}
if (map.x < 0 || map.x >= DMAXX) {
return {};
}
if (map.y < 0 || map.y >= DMAXX) {
return {};
}
if (AutomapView[map.x][map.y] == MAP_EXP_NONE) {
return {};
}
return GetAutomapTileType(map);
}
/**
* @brief Renders the given automap shape at the specified screen coordinates.
*/
void DrawAutomapTile(const Surface &out, Point center, Point map)
{
uint8_t colorBright = MapColorsBright;
uint8_t colorDim = MapColorsDim;
const MapExplorationType explorationType = static_cast<MapExplorationType>(AutomapView[std::clamp(map.x, 0, DMAXX - 1)][std::clamp(map.y, 0, DMAXY - 1)]);
switch (explorationType) {
case MAP_EXP_SHRINE:
colorDim = PAL16_GRAY + 11;
colorBright = PAL16_GRAY + 3;
break;
case MAP_EXP_OTHERS:
colorDim = PAL16_BEIGE + 10;
colorBright = PAL16_BEIGE + 2;
break;
case MAP_EXP_SELF:
case MAP_EXP_NONE:
case MAP_EXP_OLD:
break;
}