-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
graph.cpp
6344 lines (5492 loc) · 212 KB
/
graph.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
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
// Hyperbolic Rogue -- main graphics file
// Copyright (C) 2011-2019 Zeno Rogue, see 'hyper.cpp' for details
/** \file graph.cpp
* \brief Drawing cells, monsters, items, etc.
*/
#include "hyper.h"
namespace hr {
EX int last_firelimit;
EX int firelimit;
EX int inmirrorcount = 0;
/** wall optimization: do not draw things beyond walls */
EX bool wallopt;
EX bool in_wallopt() { return wallopt || racing::on; }
EX bool spatial_graphics;
EX bool wmspatial, wmescher, wmplain, wmblack, wmascii, wmascii3;
EX bool mmspatial, mmhigh, mmmon, mmitem;
EX int detaillevel = 0;
EX bool first_cell_to_draw = true;
EX bool zh_ascii = false;
EX bool in_perspective() {
return models::is_perspective(pconf.model);
}
EX bool in_perspective_v() {
return models::is_perspective(vpconf.model);
}
EX bool hide_player() {
return GDIM == 3 && playermoved && vid.yshift == 0 && vid.sspeed > -5 && in_perspective() && (first_cell_to_draw || elliptic) && (WDIM == 3 || vid.camera == 0) && !inmirrorcount
#if CAP_RACING
&& !(racing::on && !racing::use_standard_centering() && !racing::player_relative)
#endif
;
}
EX transmatrix ddspin180(cell *c, int dir) { return ddspin(c, dir, M_PI); }
EX transmatrix iddspin180(cell *c, int dir) { return iddspin(c, dir, M_PI); }
#if HDR
template<class T>
class span {
T *begin_ = nullptr;
T *end_ = nullptr;
public:
explicit span() = default;
explicit span(T *p, int n) : begin_(p), end_(p + n) {}
T *begin() const { return begin_; }
T *end() const { return end_; }
};
template<class Map, class Key>
hr::span<const shiftmatrix> span_at(const Map& map, const Key& key) {
auto it = map.find(key);
return (it == map.end()) ? hr::span<const shiftmatrix>() : hr::span<const shiftmatrix>(it->second.data(), it->second.size());
}
#endif
EX hookset<bool(int sym, int uni)> hooks_handleKey;
EX hookset<bool(cell *c, const shiftmatrix& V)> hooks_drawcell;
EX purehookset hooks_frame, hooks_markers;
EX ld animation_factor = 1;
EX int animation_lcm = 0;
EX ld ptick(int period, ld phase IS(0)) {
if(animation_lcm) animation_lcm = animation_lcm * (period / gcd(animation_lcm, period));
return (ticks * animation_factor * vid.ispeed) / period + phase * TAU;
}
EX ld fractick(int period, ld phase IS(0)) {
ld t = ptick(period, phase) / TAU;
t -= floor(t);
if(t<0) t++;
return t;
}
EX ld sintick(int period, ld phase IS(0)) {
return sin(ptick(period, phase));
}
EX transmatrix spintick(int period, ld phase IS(0)) {
return spin(ptick(period, phase));
}
#define WOLNIEJ 1
#define BTOFF 0x404040
#define BTON 0xC0C000
// #define PANDORA
int colorbar;
EX bool inHighQual; // taking high quality screenshot
EX bool auraNOGL; // aura without GL
//
int axestate;
EX int ticks;
EX int frameid;
EX bool camelotcheat;
EX bool nomap;
EX eItem orbToTarget;
EX eMonster monsterToSummon;
EX int sightrange_bonus = 0;
EX string mouseovers;
EX int darken = 0;
struct fallanim {
int t_mon, t_floor, pid;
eWall walltype;
eMonster m;
fallanim() { t_floor = 0; t_mon = 0; pid = 0; walltype = waNone; }
};
map<cell*, fallanim> fallanims;
EX bool doHighlight() {
return mmhigh;
}
int dlit;
ld spina(cell *c, int dir) {
return TAU * dir / c->type;
}
/** @brief used to alternate colors depending on distance to something. In chessboard-patterned geometries, automatically a third step.
* In some cases, we want to avoid a number of colors in the table -- set @param subtract to the number of such colors.
*/
EX color_t get_color_auto3(int f, const colortable& ctab, int subtract IS(0)) {
int size = ctab.size() - subtract;
if(size < 1) return 0;
if(geosupport_chessboard() && size == 2) {
f = gmod(f, 3);
if(f == 1)
return gradient(ctab[0], ctab[1], 0, 1, 2);
return ctab[f/2];
}
else
return ctab[gmod(f, size)];
}
color_t fc(int ph, color_t col, int z) {
if(items[itOrbFire]) col = darkena(firecolor(ph), 0, 0xFF);
if(items[itOrbAether]) col = (col &~0XFF) | (col&0xFF) / 2;
for(cell *pc: player_positions())
if(items[itOrbFish] && isWatery(pc) && z != 3) return watercolor(ph);
if(invismove)
col =
shmup::on ?
(col &~0XFF) | (int((col&0xFF) * .25))
: (col &~0XFF) | (int((col&0xFF) * (100+100*sintick(500)))/200);
return col;
}
EX int lightat, safetyat;
EX void drawLightning() { lightat = ticks; }
EX void drawSafety() { safetyat = ticks; }
EX void drawShield(const shiftmatrix& V, eItem it) {
#if CAP_CURVE
float ds = ptick(300);
color_t col = iinf[it].color;
if(it == itOrbShield && items[itOrbTime] && !orbused[it])
col = (col & 0xFEFEFE) / 2;
if(sphere && cwt.at->land == laHalloween && !wmblack && !wmascii)
col = 0;
double d = it == itOrbShield ? cgi.hexf : cgi.hexf - .1;
int mt = sphere ? 7 : 5;
#if MAXMDIM >= 4
if(GDIM == 3)
queueball(V * lzpush(cgi.GROIN1), cgi.human_height / 2, darkena(col, 0, 0xFF), itOrbShield);
#else
if(1) ;
#endif
else {
for(ld a=0; a<=cgi.S84*mt+1e-6; a+=pow(.5, vid.linequality))
curvepoint(xspinpush0(a * cgi.S_step, d + sin(ds + 90._deg*a/mt)*.1));
queuecurve(V, darkena(col, 0, 0xFF), 0x8080808, PPR::LINE);
}
#endif
}
void drawSpeed(const shiftmatrix& V, ld scale=1) {
#if CAP_CURVE
ld ds = ptick(10);
color_t col = darkena(iinf[itOrbSpeed].color, 0, 0xFF);
#if MAXMDIM >= 4
if(GDIM == 3) queueball(V * lzpush(cgi.GROIN1), cgi.human_height * 0.55, col, itOrbSpeed);
else
#endif
for(int b=0; b<cgi.S84; b+=cgi.S14) {
PRING(a)
curvepoint(xspinpush0((ds+b+a) * cgi.S_step, cgi.hexf*a/cgi.S84*scale));
queuecurve(V, col, 0x8080808, PPR::LINE);
}
#endif
}
void drawSafety(const shiftmatrix& V, int ct) {
if(inHighQual) return;
#if CAP_QUEUE
ld ds = ptick(50);
color_t col = darkena(iinf[itOrbSafety].color, 0, 0xFF);
#if MAXMDIM >= 4
if(GDIM == 3) {
queueball(V * lzpush(cgi.GROIN1), 2*cgi.hexf, col, itOrbSafety);
return;
}
#endif
for(int a=0; a<ct; a++)
queueline(V*xspinpush0((ds+a*cgi.S84/ct) * cgi.S_step, 2*cgi.hexf), V*xspinpush0((ds+(a+(ct-1)/2)*cgi.S84/ct) * cgi.S_step, 2*cgi.hexf), col, vid.linequality);
#endif
}
void drawFlash(const shiftmatrix& V) {
#if CAP_CURVE
float ds = ptick(300);
color_t col = darkena(iinf[itOrbFlash].color, 0, 0xFF);
col &= ~1;
for(int u=0; u<5; u++) {
ld rad = cgi.hexf * (2.5 + .5 * sin(ds+u*.3));
#if MAXMDIM >= 4
if(GDIM == 3) {
queueball(V * lzpush(cgi.GROIN1), rad, col, itOrbFlash);
}
#else
if(1) ;
#endif
else {
PRING(a) curvepoint(xspinpush0(a * cgi.S_step, rad));
queuecurve(V, col, 0x8080808, PPR::LINE);
}
}
#endif
}
EX ld cheilevel(ld v) {
return cgi.FLOOR + (cgi.HEAD - cgi.FLOOR) * v;
}
EX transmatrix chei(const transmatrix V, int a, int b) {
#if MAXMDIM >= 4
if(GDIM == 2) return V;
return V * lzpush(cheilevel((a+.5) / b));
#else
return V;
#endif
}
EX shiftmatrix chei(const shiftmatrix V, int a, int b) {
#if MAXMDIM >= 4
if(GDIM == 2) return V;
return V * lzpush(cheilevel((a+.5) / b));
#else
return V;
#endif
}
void drawLove(const shiftmatrix& V, int hdir) {
#if CAP_CURVE
float ds = ptick(300);
color_t col = darkena(iinf[itOrbLove].color, 0, 0xFF);
col &= ~1;
for(int u=0; u<5; u++) {
shiftmatrix V1 = chei(V, u, 5);
PRING(a) {
double d = (1 + cos(a * cgi.S_step)) / 2;
double z = a; if(z>cgi.S42) z = cgi.S84-z;
if(z <= 10) d += (10-z) * (10-z) * (10-z) / 3000.;
ld rad = cgi.hexf * (2.5 + .5 * sin(ds+u*.3)) * d;
curvepoint(xspinpush0((cgi.S42+hdir+a-1) * cgi.S_step, rad));
}
queuecurve(V1, col, 0x8080808, PPR::LINE);
}
#endif
}
void drawWinter(const shiftmatrix& V, ld hdir, color_t col) {
#if CAP_QUEUE
float ds = ptick(300);
col = darkena(col, 0, 0xFF);
for(int u=0; u<20; u++) {
ld rad = sin(ds+u * TAU / 20) * M_PI / S7;
shiftmatrix V1 = chei(V, u, 20);
queueline(V1*xspinpush0(M_PI+hdir+rad, cgi.hexf*.5), V1*xspinpush0(M_PI+hdir+rad, cgi.hexf*3), col, 2 + vid.linequality);
}
#endif
}
void drawLightning(const shiftmatrix& V) {
#if CAP_QUEUE
float ds = ptick(600);
color_t col = darkena(iinf[itOrbLightning].color, 0, 0xFF);
for(int u=0; u<20; u++) {
ld leng, rad;
if(vid.flasheffects) {
leng = 0.5 / (0.1 + (rand() % 100) / 100.0);
rad = rand() % 1000;
}
else {
if(u % 5) leng = 1.25 + sintick(200, ld(u) * 1.25) * 0.25;
else leng = 2 + sintick(200, ld(u) * 1.25);
rad = (u + ds) * TAU / 20;
}
shiftmatrix V1 = chei(V, u, 20);
queueline(V1*xspinpush0(rad, cgi.hexf*0.3), V1*xspinpush0(rad, cgi.hexf*leng), col, 2 + vid.linequality);
}
#endif
}
void drawCurse(const shiftmatrix& V, eItem it) {
#if CAP_QUEUE
float ds = ptick(450) + (it * 5.5); // Extra offset so both Gluttony and Repulsion are easily visible
color_t col = darkena(iinf[it].color, 0, 0xFF);
for(int u=0; u<20; u++) {
ld leng, rad;
if(vid.flasheffects) {
leng = 0.6 + 0.3 * randd();
rad = rand() % 1000;
}
else {
leng = 0.85 + sintick(150, ld(u) * 1.25) * 0.15;
rad = (u + ds) * TAU / 20;
}
shiftmatrix V1 = chei(V, u, 20);
queueline(V1*xspinpush0(rad, cgi.hexf*0.3), V1*xspinpush0(rad, cgi.hexf*leng), col, 2 + vid.linequality);
}
#endif
}
#define UNTRANS (GDIM == 3 ? 0x000000FF : 0)
EX transmatrix lpispin() {
return spin180();
}
EX void drawPlayerEffects(const shiftmatrix& V, const shiftmatrix& Vparam, cell *c, eMonster m) {
bool onplayer = m == moPlayer;
if(!onplayer && !items[itOrbEmpathy]) return;
if(items[itOrbShield] > (shmup::on ? 0 : ORBBASE)) drawShield(V, itOrbShield);
if(items[itOrbShell] > (shmup::on ? 0 : ORBBASE)) drawShield(V, itOrbShell);
if(items[itOrbSpeed]) drawSpeed(V);
if(items[itCurseGluttony]) drawCurse(V, itCurseGluttony);
if(items[itCurseRepulsion]) drawCurse(V, itCurseRepulsion);
if(onplayer && (items[itOrbSword] || items[itOrbSword2])) {
using namespace sword;
if(shmup::on && SWORDDIM == 2) {
#if CAP_SHAPES
if(items[itOrbSword])
queuepoly(V*spin(shmup::pc[multi::cpid]->swordangle), (peace::on ? cgi.shMagicShovel : cgi.shMagicSword), darkena(iinf[itOrbSword].color, 0, 0xC0 + 0x30 * sintick(200)));
if(items[itOrbSword2])
queuepoly(V*spin(shmup::pc[multi::cpid]->swordangle+M_PI), (peace::on ? cgi.shMagicShovel : cgi.shMagicSword), darkena(iinf[itOrbSword2].color, 0, 0xC0 + 0x30 * sintick(200)));
#endif
}
else if(SWORDDIM == 3) {
#if CAP_SHAPES
shiftmatrix Vsword =
shmup::on ? V * shmup::swordmatrix[multi::cpid] * cspin90(2, 0)
: Vparam * rgpushxto0(inverse_shift(gmatrix[c], tC0(V))) * sword::dir[multi::cpid].T;
if(items[itOrbSword])
queuepoly(Vsword * cspin(1,2, ticks / 150.), (peace::on ? cgi.shMagicShovel : cgi.shMagicSword), darkena(iinf[itOrbSword].color, 0, 0xC0 + 0x30 * sintick(200)));
if(items[itOrbSword2])
queuepoly(Vsword * lpispin() * cspin(1,2, ticks / 150.), (peace::on ? cgi.shMagicShovel : cgi.shMagicSword), darkena(iinf[itOrbSword2].color, 0, 0xC0 + 0x30 * sintick(200)));
#endif
}
else {
int& ang = sword::dir[multi::cpid].angle;
ang %= sword::sword_angles;
#if CAP_QUEUE || CAP_SHAPES
shiftmatrix Vnow = Vparam * rgpushxto0(inverse_shift(Vparam, tC0(V))) * ddspin180(c,0);
#endif
int adj = 1 - ((sword_angles/cwt.at->type)&1);
#if CAP_QUEUE
if(!euclid && !mhybrid) for(int a=0; a<sword_angles; a++) {
if(a == ang && items[itOrbSword]) continue;
if((a+sword_angles/2)%sword_angles == ang && items[itOrbSword2]) continue;
bool longer = sword::pos2(cwt.at, a-1) != sword::pos2(cwt.at, a+1);
if(sword_angles > 48 && !longer) continue;
color_t col = darkena(0xC0C0C0, 0, 0xFF);
ld l0 = PURE ? 0.6 * cgi.scalefactor : longer ? 0.36 : 0.4;
ld l1 = PURE ? 0.7 * cgi.scalefactor : longer ? 0.44 : 0.42;
#if MAXMDIM >= 4
hyperpoint h0 = GDIM == 3 ? xpush(l0) * lzpush(cgi.FLOOR - cgi.human_height/50) * C0 : xpush0(l0);
hyperpoint h1 = GDIM == 3 ? xpush(l1) * lzpush(cgi.FLOOR - cgi.human_height/50) * C0 : xpush0(l1);
#else
hyperpoint h0 = xpush0(l0);
hyperpoint h1 = xpush0(l1);
#endif
shiftmatrix T = Vnow*spin((sword_angles + (-adj-2*a)) * M_PI / sword_angles);
queueline(T*h0, T*h1, col, 1, PPR::SUPERLINE);
}
#endif
#if CAP_SHAPES
if(items[itOrbSword])
queuepoly(Vnow*spin(M_PI+(-adj-2*ang)*M_PI/sword_angles), (peace::on ? cgi.shMagicShovel : cgi.shMagicSword), darkena(iinf[itOrbSword].color, 0, 0x80 + 0x70 * sintick(200)));
if(items[itOrbSword2])
queuepoly(Vnow*spin((-adj-2*ang)*M_PI/sword_angles), (peace::on ? cgi.shMagicShovel : cgi.shMagicSword), darkena(iinf[itOrbSword2].color, 0, 0x80 + 0x70 * sintick(200)));
#endif
}
}
if(onplayer && items[itOrbSafety]) drawSafety(V, c->type);
if(onplayer && items[itOrbFlash]) drawFlash(V);
if(onplayer && items[itOrbLove]) drawLove(V, 0); // displaydir(c, cwt.spin));
if(items[itOrbWinter])
drawWinter(V, 0, iinf[itOrbWinter].color); // displaydir(c, cwt.spin));
if(items[itOrbFire])
drawWinter(V, 0, iinf[itOrbFire].color); // displaydir(c, cwt.spin));
if(items[itCurseWater])
drawWinter(V, 0, iinf[itCurseWater].color); // displaydir(c, cwt.spin));
if(onplayer && items[itOrbLightning]) drawLightning(V);
if(safetyat > 0) {
int tim = ticks - safetyat;
if(tim > 2500) safetyat = 0;
for(int u=tim; u<=2500; u++) {
if((u-tim)%250) continue;
ld rad = cgi.hexf * u / 250;
color_t col = darkena(iinf[itOrbSafety].color, 0, 0xFF);
PRING(a)
curvepoint(xspinpush0(a * cgi.S_step, rad));
queuecurve(V, col, 0, PPR::LINE);
}
}
}
void drawStunStars(const shiftmatrix& V, int t) {
#if CAP_SHAPES
for(int i=0; i<3*t; i++) {
shiftmatrix V2 = V * spin(TAU * i / (3*t) + ptick(200));
#if MAXMDIM >= 4
if(GDIM == 3) V2 = V2 * lzpush(cgi.HEAD);
#endif
queuepolyat(V2, cgi.shFlailBall, 0xFFFFFFFF, PPR::STUNSTARS);
}
#endif
}
EX namespace tortoise {
// small is 0 or 2
void draw(const shiftmatrix& V, int bits, int small, int stuntime) {
#if CAP_SHAPES
color_t eyecolor = getBit(bits, tfEyeHue) ? 0xFF0000 : 0xC0C0C0;
color_t shellcolor = getBit(bits, tfShellHue) ? 0x00C040 : 0xA06000;
color_t scutecolor = getBit(bits, tfScuteHue) ? 0x00C040 : 0xA06000;
color_t skincolor = getBit(bits, tfSkinHue) ? 0x00C040 : 0xA06000;
if(getBit(bits, tfShellSat)) shellcolor = gradient(shellcolor, 0xB0B0B0, 0, .5, 1);
if(getBit(bits, tfScuteSat)) scutecolor = gradient(scutecolor, 0xB0B0B0, 0, .5, 1);
if(getBit(bits, tfSkinSat)) skincolor = gradient(skincolor, 0xB0B0B0, 0, .5, 1);
if(getBit(bits, tfShellDark)) shellcolor = gradient(shellcolor, 0, 0, .5, 1);
if(getBit(bits, tfSkinDark)) skincolor = gradient(skincolor, 0, 0, .5, 1);
if(bits < 0) {
skincolor = 0xC00060;
shellcolor = 0xFF00FF;
scutecolor = 0x6000C0;
eyecolor = 0xFFFFFF;
}
for(int i=0; i<12; i++) {
color_t col =
i == 0 ? shellcolor:
i < 8 ? scutecolor :
skincolor;
int b = getBit(bits, i);
int d = darkena(col, 0, 0xFF);
if(i >= 1 && i <= 7) if(b) { d = darkena(col, 1, 0xFF); b = 0; }
if(i >= 8 && i <= 11 && stuntime >= 3) continue;
queuepoly(V, cgi.shTortoise[i][b+small], d);
if((i >= 5 && i <= 7) || (i >= 9 && i <= 10))
queuepoly(V * lmirror(), cgi.shTortoise[i][b+small], d);
if(i == 8) {
for(int k=0; k<stuntime; k++) {
eyecolor &= 0xFEFEFE;
eyecolor >>= 1;
}
queuepoly(V, cgi.shTortoise[12][b+small], darkena(eyecolor, 0, 0xFF));
queuepoly(V * lmirror(), cgi.shTortoise[12][b+small], darkena(eyecolor, 0, 0xFF));
}
}
#endif
}
EX int getMatchColor(int bits) {
int mcol = 1;
double d = tortoise::getScent(bits);
if(d > 0) mcol = 0xFFFFFF;
else if(d < 0) mcol = 0;
int dd = 0xFF * (atan(fabs(d)/2) / 90._deg);
return gradient(0x487830, mcol, 0, dd, 0xFF);
}
EX }
double footfun(double d) {
d -= floor(d);
return
d < .25 ? d :
d < .75 ? .5-d :
d-1;
}
EX bool ivoryz;
/** Change the level of V. Takes ivoryz and all geometries into account */
EX transmatrix at_smart_lof(const transmatrix& V, ld lev) {
if(!mmspatial) return V;
if(ivoryz) return mzscale(V, lev);
return orthogonal_move_fol(V, lev);
}
EX shiftmatrix at_smart_lof(const shiftmatrix& V, ld lev) { return shiftless(at_smart_lof(V.T, lev), V.shift); }
void animallegs(const shiftmatrix& V, eMonster mo, color_t col, double footphase) {
#if CAP_SHAPES
footphase /= SCALE;
bool dog = mo == moRunDog;
bool bug = mo == moBug0 || mo == moMetalBeast;
if(bug) footphase *= 2.5;
double rightfoot = footfun(footphase / .4 / 2) / 4 * 2;
double leftfoot = footfun(footphase / .4 / 2 - (bug ? .5 : dog ? .1 : .25)) / 4 * 2;
if(bug) rightfoot /= 2.5, leftfoot /= 2.5;
rightfoot *= SCALE;
leftfoot *= SCALE;
if(!footphase) rightfoot = leftfoot = 0;
hpcshape* sh[6][4] = {
{&cgi.shDogFrontPaw, &cgi.shDogRearPaw, &cgi.shDogFrontLeg, &cgi.shDogRearLeg},
{&cgi.shWolfFrontPaw, &cgi.shWolfRearPaw, &cgi.shWolfFrontLeg, &cgi.shWolfRearLeg},
{&cgi.shReptileFrontFoot, &cgi.shReptileRearFoot, &cgi.shReptileFrontLeg, &cgi.shReptileRearLeg},
{&cgi.shBugLeg, NULL, NULL, NULL},
{&cgi.shTrylobiteFrontClaw, &cgi.shTrylobiteRearClaw, &cgi.shTrylobiteFrontLeg, &cgi.shTrylobiteRearLeg},
{&cgi.shBullFrontHoof, &cgi.shBullRearHoof, &cgi.shBullFrontHoof, &cgi.shBullRearHoof},
};
hpcshape **x = sh[mo == moRagingBull ? 5 : mo == moBug0 ? 3 : mo == moMetalBeast ? 4 : mo == moRunDog ? 0 : mo == moReptile ? 2 : 1];
#if MAXMDIM >= 4
if(GDIM == 3 && !(embedded_plane && gproduct)) {
if(x[0]) queuepolyat(V * front_leg_move * cspin(0, 2, rightfoot / leg_length) * front_leg_move_inverse, *x[0], col, PPR::MONSTER_FOOT);
if(x[0]) queuepolyat(V * lmirror() * front_leg_move * cspin(0, 2, leftfoot / leg_length) * front_leg_move_inverse, *x[0], col, PPR::MONSTER_FOOT);
if(x[1]) queuepolyat(V * rear_leg_move * cspin(0, 2, -rightfoot / leg_length) * rear_leg_move_inverse, *x[1], col, PPR::MONSTER_FOOT);
if(x[1]) queuepolyat(V * lmirror() * rear_leg_move * cspin(0, 2, -leftfoot / leg_length) * rear_leg_move_inverse, *x[1], col, PPR::MONSTER_FOOT);
return;
}
#endif
const shiftmatrix VL = at_smart_lof(V, cgi.ALEG0);
const shiftmatrix VAML = at_smart_lof(V, cgi.ALEG);
if(x[0]) queuepolyat(VL * lxpush(rightfoot), *x[0], col, PPR::MONSTER_FOOT);
if(x[0]) queuepolyat(VL * lmirror() * lxpush(leftfoot), *x[0], col, PPR::MONSTER_FOOT);
if(x[1]) queuepolyat(VL * lxpush(-rightfoot), *x[1], col, PPR::MONSTER_FOOT);
if(x[1]) queuepolyat(VL * lmirror() * lxpush(-leftfoot), *x[1], col, PPR::MONSTER_FOOT);
if(x[2]) queuepolyat(VAML * lxpush(rightfoot/2), *x[2], col, PPR::MONSTER_FOOT);
if(x[2]) queuepolyat(VAML * lmirror() * lxpush(leftfoot/2), *x[2], col, PPR::MONSTER_FOOT);
if(x[3]) queuepolyat(VAML * lxpush(-rightfoot/2), *x[3], col, PPR::MONSTER_FOOT);
if(x[3]) queuepolyat(VAML * lmirror() * lxpush(-leftfoot/2), *x[3], col, PPR::MONSTER_FOOT);
#endif
}
EX bool noshadow;
#if CAP_SHAPES
EX void ShadowV(const shiftmatrix& V, const hpcshape& bp, PPR prio IS(PPR::MONSTER_SHADOW)) {
if(WDIM == 2 && GDIM == 3 && bp.shs != bp.she) {
if(noshadow) return;
auto& p = queuepolyat(V, bp, 0x18, PPR::TRANSPARENT_SHADOW);
p.outline = 0;
p.subprio = -100;
p.offset = bp.shs;
p.cnt = bp.she - bp.shs;
p.flags &=~ POLY_TRIANGLES;
p.tinf = NULL;
return;
}
if(mmspatial) {
if(model_needs_depth() || noshadow)
return; // shadows break the depth testing
dynamicval<color_t> p(poly_outline, OUTLINE_TRANS);
queuepolyat(V, bp, SHADOW_MON, prio);
}
}
#endif
#if CAP_SHAPES
transmatrix otherbodyparts(const shiftmatrix& V, color_t col, eMonster who, double footphase) {
#define VFOOT ((GDIM == 2 || mhybrid) ? V : at_smart_lof(V, cgi.LEG0))
#define VLEG at_smart_lof(V, cgi.LEG)
#define VGROIN at_smart_lof(V, cgi.GROIN)
#define VBODY at_smart_lof(V, cgi.BODY)
#define VBODY1 at_smart_lof(V, cgi.BODY1)
#define VBODY2 at_smart_lof(V, cgi.BODY2)
#define VBODY3 at_smart_lof(V, cgi.BODY3)
#define VNECK at_smart_lof(V, cgi.NECK)
#define VHEAD at_smart_lof(V, cgi.HEAD)
#define VHEAD1 at_smart_lof(V, cgi.HEAD1)
#define VHEAD2 at_smart_lof(V, cgi.HEAD2)
#define VHEAD3 at_smart_lof(V, cgi.HEAD3)
#define VALEGS V
#define VABODY at_smart_lof(V, cgi.ABODY)
#define VAHEAD at_smart_lof(V, cgi.AHEAD)
#define VFISH V
#define VBIRD ((GDIM == 3 || (where && bird_disruption(where))) ? (WDIM == 2 ? at_smart_lof(V, cgi.BIRD) : V) : at_smart_lof(V, cgi.BIRD + .05 * sintick(1000, static_cast<int>(reinterpret_cast<size_t>(where))/1000.)))
#define VGHOST at_smart_lof(V, cgi.GHOST)
#define VSLIMEEYE orthogonal_move_fol(V, cgi.FLATEYE)
// if(!mmspatial && !footphase && who != moSkeleton) return;
footphase /= SCALE;
double rightfoot = footfun(footphase / .4 / 2.5) / 4 * 2.5 * SCALE;
const double wobble = -1;
// todo
if(detaillevel >= 2 && GDIM == 2) {
shiftmatrix VL = at_smart_lof(V, cgi.LEG1);
queuepoly(VL * xpush(rightfoot*3/4), cgi.shHumanLeg, col);
queuepoly(VL * lmirror() * xpush(-rightfoot*3/4), cgi.shHumanLeg, col);
}
if(GDIM == 2) {
shiftmatrix VL = at_smart_lof(V, cgi.LEG);
queuepoly(VL * xpush(rightfoot/2), cgi.shHumanLeg, col);
queuepoly(VL * lmirror() * xpush(-rightfoot/2), cgi.shHumanLeg, col);
}
if(detaillevel >= 2 && GDIM == 2) {
shiftmatrix VL = at_smart_lof(V, cgi.LEG3);
queuepoly(VL * xpush(rightfoot/4), cgi.shHumanLeg, col);
queuepoly(VL * lmirror() * xpush(-rightfoot/4), cgi.shHumanLeg, col);
}
shiftmatrix Tright, Tleft;
if(GDIM == 2 || mhybrid || cgi.emb->is_euc_in_product()) {
Tright = VFOOT * xpush(rightfoot);
Tleft = VFOOT * lmirror() * xpush(-rightfoot);
}
#if MAXMDIM >= 4
else {
shiftmatrix V1 = V;
if(WDIM == 2) V1 = V1 * lzpush(cgi.GROIN);
int zdir = cgi.emb->is_euc_in_nil() ? 1 : 2;
Tright = V1 * cspin(0, zdir, rightfoot/ leg_length);
Tleft = V1 * lmirror() * cspin(zdir, 0, rightfoot / leg_length);
Tright = V1; Tleft = V1 * lmirror();
if(WDIM == 2) Tleft = Tleft * lzpush(-cgi.GROIN), Tright = Tright * lzpush(-cgi.GROIN);
}
#endif
if(who == moWaterElemental && GDIM == 2) {
double fishtail = footfun(footphase / .4) / 4 * 1.5;
queuepoly(VFOOT * xpush(fishtail), cgi.shFishTail, watercolor(100));
}
else if(who == moSkeleton) {
queuepoly(Tright, cgi.shSkeletalFoot, col);
queuepoly(Tleft, cgi.shSkeletalFoot, col);
return spin(rightfoot * wobble);
}
else if(isTroll(who) || who == moMonkey || who == moYeti || who == moRatling || who == moRatlingAvenger || who == moGoblin) {
queuepoly(Tright, cgi.shYetiFoot, col);
queuepoly(Tleft, cgi.shYetiFoot, col);
}
else {
queuepoly(Tright, cgi.shHumanFoot, col);
queuepoly(Tleft, cgi.shHumanFoot, col);
}
if(GDIM == 3 || !mmspatial) return spin(rightfoot * wobble);
if(detaillevel >= 2 && who != moZombie)
queuepoly(at_smart_lof(V, cgi.NECK1), cgi.shHumanNeck, col);
if(detaillevel >= 1) {
queuepoly(VGROIN, cgi.shHumanGroin, col);
if(who != moZombie) queuepoly(VNECK, cgi.shHumanNeck, col);
}
if(detaillevel >= 2) {
queuepoly(at_smart_lof(V, cgi.GROIN1), cgi.shHumanGroin, col);
if(who != moZombie) queuepoly(at_smart_lof(V, cgi.NECK3), cgi.shHumanNeck, col);
}
return spin(rightfoot * wobble);
}
#endif
EX bool drawstar(cell *c) {
for(int t=0; t<c->type; t++)
if(c->move(t) && c->move(t)->wall != waSulphur && c->move(t)->wall != waSulphurC &&
c->move(t)->wall != waBarrier)
return false;
return true;
}
EX bool drawing_usershape_on(cell *c, mapeditor::eShapegroup sg) {
#if CAP_EDIT
return c && c == mapeditor::drawcell && mapeditor::drawcellShapeGroup() == sg;
#else
return false;
#endif
}
EX color_t kind_outline(eItem it) {
int k = itemclass(it);
if(k == IC_TREASURE)
return OUTLINE_TREASURE;
else if(k == IC_ORB)
return OUTLINE_ORB;
else
return OUTLINE_OTHER;
}
/** should objects fly slightly up and down in product/twisted product geometries */
EX bool bobbing = true;
EX shiftmatrix face_the_player(const shiftmatrix V) {
if(GDIM == 2) return V;
if(mproduct) return bobbing ? orthogonal_move(V, cos(ptick(750)) * cgi.plevel / 16) : V;
if(mhybrid) return bobbing ? V * zpush(cos(ptick(750)) * cgi.plevel / 16) : V;
transmatrix dummy; /* used only in prod anyways */
if(embedded_plane && !cgi.emb->is_same_in_same()) return V;
if(nonisotropic) return shiftless(spin_towards(unshift(V), dummy, C0, 2, 0));
#if CAP_VR
if(vrhr::enabled) {
shiftpoint h = tC0(V);
hyperpoint uh = unshift(h);
return shiftless(cspin90(1, 2) * rspintox(cspin90(2, 1) * uh) * xpush(hdist0(uh)) * cspin90(0, 2) * spin270());
}
#endif
return rgpushxto0(tC0(V));
}
EX hpcshape& orbshape(eOrbshape s) {
if(vid.orbmode == 0) return cgi.shRing;
switch(s) {
case osLove: return cgi.shLoveRing;
case osRanged: return cgi.shTargetRing;
case osOffensive: return cgi.shSawRing;
case osDirectional: return vid.orbmode == 2 ? cgi.shSawRing : cgi.shSpearRing;
case osFriend: return cgi.shPeaceRing;
case osUtility: return cgi.shGearRing;
case osPowerUtility: return cgi.shPowerGearRing;
case osWarping: return cgi.shHeptaRing;
case osFrog: return cgi.shFrogRing;
case osProtective: return cgi.shProtectiveRing;
case osTerraform: return cgi.shTerraRing;
case osMovement: return cgi.shMoveRing;
default: return cgi.shRing;
}
}
void queue_ring(const shiftmatrix& V, hpcshape& sh, color_t col, PPR p) {
queuepolyat(V, sh, col, p).outline = 0;
auto& p1 = queuepolyat(V, sh, col, p);
p1.cnt = cgi.orb_inner_ring;
p1.color = 0;
auto& p2 = queuepolyat(V, sh, col, p);
p2.color = 0;
p2.offset += cgi.orb_inner_ring;
p2.cnt -= cgi.orb_inner_ring + 1;
}
EX color_t orb_auxiliary_color(eItem it) {
if(it == itOrbFire) return firecolor(200);
if(it == itOrbWater) return 0x000060;
if(it == itOrbFriend || it == itOrbDiscord) return 0xC0C0C0;
if(it == itOrbFrog) return 0xFF0000;
if(it == itOrbImpact) return 0xFF0000;
if(it == itOrbPhasing) return 0xFF0000;
if(it == itOrbDash) return 0xFF0000;
if(it == itOrbFreedom) return 0xC0FF00;
if(it == itOrbPlague) return 0x409040;
if(it == itOrbChaos) return 0xFF00FF;
if(it == itOrbAir) return 0xFFFFFF;
if(it == itOrbUndeath) return minf[moFriendlyGhost].color;
if(it == itOrbRecall) return 0x101010;
if(it == itOrbLife) return 0x90B090;
if(it == itOrbSlaying) return 0xFF0000;
if(it == itOrbSide1) return 0x307080;
if(it == itOrbDigging) return 0x606060;
if(it == itOrbEnergy) return 0xFFFF80;
return iinf[it].color;
}
EX color_t orb_inner_color(eItem it) {
if(it == itOrbWater) return 0x0070C0;
if(it == itOrbEnergy) return 0x8B4513;
// if(it == itOrbDash) return 0xFF0000;
if(it == itOrbSide1) return 0x00FF00;
// if(it == itOrbPhasing) return 0xFF0000;
if(it == itOrbDigging) return 0x00FF00;
if(it == itOrbLife) return 0x306000;
return iinf[it].color;
}
EX void draw_ascii(const shiftmatrix& V, const string& s, color_t col, ld size, ld size2) {
int id = isize(ptds);
if(WDIM == 2 && GDIM == 3)
queuestrn(V * lzpush(cgi.FLOOR - cgi.scalefactor * size / 4), size * mapfontscale / 100, s, darkenedby(col, darken), 0);
else
queuestrn(V, size2 * mapfontscale / 100, s, darkenedby(col, darken), GDIM == 3 ? 0 : 2);
while(id < isize(ptds)) ptds[id++]->prio = PPR::MONSTER_BODY;
}
EX void draw_ascii(const shiftmatrix& V, char glyph, color_t col, ld size) {
draw_ascii(V, s0 + glyph, col, size, 1);
}
EX void draw_ascii_or_zh(const shiftmatrix& V, char glyph, const string& name, color_t col, ld size, ld zh_size) {
#if CAP_TRANS
if(zh_ascii) {
auto p = XLAT1_acc(name, 8);
if(p) {
string chinese = p;
chinese.resize(utfsize(chinese[0]));
dynamicval<fontdata*> df(cfont, cfont_chinese);
draw_ascii(V, chinese, col, size, zh_size);
return;
}
}
#endif
draw_ascii(V, glyph, col, size);
}
EX void queue_goal_text(shiftpoint P1, ld sizemul, const string& s, color_t color) {
#if CAP_VR
if(vrhr::enabled) {
auto e = inverse_exp(P1);
e = e * 3 / hypot_d(GDIM, e);
auto T = face_the_player(shiftless(rgpushxto0(direct_exp(e))));
queuestrn(T, sizemul * mapfontscale / 100, s, color);
return;
}
#endif
queuestr(P1, vid.fsize * sizemul, s, color);
}
EX bool mark_compass(cell *c, shiftpoint& P1) {
cell *c1 = c ? findcompass(c) : NULL;
if(!c1) return false;
shiftmatrix P = ggmatrix(c1);
P1 = tC0(P);
if(isPlayerOn(c)) {
queue_goal_text(P1, 2, "X", 0x10100 * int(128 + 100 * sintick(150)));
// queuestr(V, 1, its(compassDist(c)), 0x10101 * int(128 - 100 * sin(ticks / 150.)), 1);
queue_goal_text(P1, 1, its(-compassDist(c)), 0x10101 * int(128 - 100 * sintick(150)));
addauraspecial(P1, 0xFF0000, 0);
addradar(P, 'X', iinf[itCompass].color, 0xFF, true);
}
return true;
}
EX bool drawItemType(eItem it, cell *c, const shiftmatrix& V, color_t icol, int pticks, bool hidden) {
if(!it) return false;
char xch = iinf[it].glyph;
#if MAXMDIM >= 4
if(c && GDIM == 3)
addradar(V, xch, icol, kind_outline(it));
#endif
if(WDIM == 3 && c == centerover && in_perspective() && hdist0(tC0(V)) < cgi.orbsize * 0.25) return false;
if(!mmitem || !CAP_SHAPES) {
draw_ascii_or_zh(V, iinf[it].glyph, iinf[it].name, icol, 1, 0.5);
return true;
}
#if CAP_SHAPES
auto sinptick = [c, pticks] (int period) { return c ? sintick(period) : sin(animation_factor * vid.ispeed * pticks / period);};
auto spinptick = [c, pticks] (int period, ld phase) { return c ? spintick(period, phase) : spin((animation_factor * vid.ispeed * pticks) / period + phase * TAU); };
int ct6 = c ? ctof(c) : 1;
hpcshape *xsh =
(it == itPirate || it == itKraken) ? &cgi.shPirateX :
(it == itBuggy || it == itBuggy2) ? &cgi.shPirateX :
it == itHolyGrail ? &cgi.shGrail :
isElementalShard(it) ? &cgi.shElementalShard :
(it == itBombEgg || it == itTrollEgg || it == itCursed) ? &cgi.shEgg :
(it == itFrog || it == itWhirlpool) ? &cgi.shDisk :
it == itHunting ? &cgi.shTriangle :
(it == itDodeca || it == itDice) ? &cgi.shDodeca :
xch == '*' ? &cgi.shGem[ct6] :
xch == '(' ? &cgi.shKnife :
it == itShard ? &cgi.shMFloor.b[0] :
it == itTreat ? &cgi.shTreat :
it == itSlime ? &cgi.shEgg :
xch == '%' ? &cgi.shDaisy : xch == '$' ? &cgi.shStar : xch == ';' ? &cgi.shTriangle :
xch == '!' ? &cgi.shTriangle : it == itBone ? &cgi.shNecro : it == itStatue ? &cgi.shStatue :
among(it, itIvory, itEclectic) ? &cgi.shFigurine :
xch == '?' ? &cgi.shBookCover :
it == itKey ? &cgi.shKey :
it == itRevolver ? &cgi.shGun :
NULL;
if(c && doHighlight())
poly_outline = kind_outline(it);
shiftmatrix Vit = V;
if(embedded_plane && c && it != itBabyTortoise) Vit = orthogonal_move_fol(V, cgi.STUFF);
if(c && mproduct)
Vit = orthogonal_move(Vit, sin(ptick(750)) * cgi.plevel / 4);
else if(c && sl2 && !embedded_plane)
Vit = Vit * zpush(sin(ptick(750)) * cgi.plevel / 4);
else
if(GDIM == 3 && c && it != itBabyTortoise) Vit = face_the_player(Vit);
// V * cspin(0, 2, ptick(618, 0));
#if CAP_SHAPES
if(mapeditor::drawUserShape(Vit, mapeditor::sgItem, it, darkena(icol, 0, 0xFF), c)) return true;
#endif
if(c && history::includeHistory && history::infindhistory.count(c)) poly_outline = OUTLINE_DEAD;
else if(it == itSavedPrincess) {
drawMonsterType(moPrincess, c, V, icol, 0, icol);
return true;
}
else if(it == itStrongWind) {
queuepoly(Vit * spinptick(750, 0), cgi.shFan, darkena(icol, 0, 255));
}
else if(it == itFatigue) {
queuepoly(Vit * spinptick(750, 0), cgi.shFan, darkena(icol, 0, 255));
}
else if(it == itWarning) {
queuepoly(Vit * spinptick(750, 0), cgi.shTriangle, darkena(icol, 0, 255));
}
else if(it == itCrossbow) {
queuepoly(Vit, cgi.shCrossbowIcon, getcs().bowcolor);
queuepoly(Vit, cgi.shCrossbowstringIcon, getcs().bowcolor2);
}
else if(it == itBabyTortoise) {
int bits = c ? tortoise::babymap[c] : tortoise::last;