-
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathgraph.cpp
More file actions
2113 lines (1749 loc) · 60.6 KB
/
graph.cpp
File metadata and controls
2113 lines (1749 loc) · 60.6 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
// 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); }
EX transmatrix lpispin() {
return spin180();
}
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;
#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 nomap;
EX eItem orbToTarget;
EX eMonster monsterToSummon;
EX int sightrange_bonus = 0;
EX string mouseovers;
EX int darken = 0;
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)];
}
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
}
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); }
EX color_t kind_outline(eItem it) {
switch(itemclass(it)) {
case IC_TREASURE:
return OUTLINE_TREASURE;
case IC_ORB:
return OUTLINE_ORB;
default:
return OUTLINE_OTHER;
}
}
/** should objects fly slightly up and down in product/twisted product geometries */
EX bool bobbing = true;
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);
}
// push down the queue after q-th element, `down` absolute units down,
// based on cell c and transmatrix V
// do change the zoom factor? do change the priorities?
EX int cellcolor(cell *c) {
if(isPlayerOn(c) || isFriendly(c)) return OUTLINE_FRIEND;
if(noHighlight(c->monst)) return OUTLINE_NONE;
if(c->monst) return OUTLINE_ENEMY;
if(c->wall == waMirror) return c->land == laMirror ? OUTLINE_TREASURE : OUTLINE_ORB;
if(c->item && !itemHiddenFromSight(c))
return kind_outline(c->item);
return OUTLINE_NONE;
}
#define AURA 180
array<array<int,4>,AURA+1> aurac;
int haveaura_cached;
/** 0 = no aura, 1 = standard aura, 2 = Joukowsky aura */
EX int haveaura() {
if(!(vid.aurastr>0 && !svg::in && (auraNOGL || vid.usingGL))) return 0;
if(vrhr::active()) return 0;
if(sphere && mdAzimuthalEqui()) return 0;
if(among(pmodel, mdJoukowsky, mdJoukowskyInverted) && hyperbolic && pconf.model_transition < 1)
return 2;
if(among(pmodel, mdFisheye, mdFisheye2)) return 1;
return pmodel == mdDisk && (!sphere || pconf.alpha > 10) && !euclid;
}
vector<pair<int, int> > auraspecials;
int auramemo;
EX void clearaura() {
haveaura_cached = haveaura();
if(!haveaura_cached) return;
for(int a=0; a<AURA; a++) for(int b=0; b<4; b++)
aurac[a][b] = 0;
auraspecials.clear();
auramemo = 128 * 128 / vid.aurastr;
}
void apply_joukowsky_aura(shiftpoint& h) {
if(haveaura_cached == 2) {
hyperpoint ret;
applymodel(h, ret);
h.h = ret;
}
if(nonisotropic) {
h.h = lp_apply(inverse_exp(h, pfNO_DISTANCE));
}
}
EX void addauraspecial(shiftpoint h, color_t col, int dir) {
if(!haveaura_cached) return;
apply_joukowsky_aura(h);
int r = int(2*AURA + dir + atan2(h[1], h[0]) * AURA / TAU) % AURA;
auraspecials.emplace_back(r, col);
}
EX void addaura(shiftpoint h, color_t col, int fd) {
if(!haveaura_cached) return;
apply_joukowsky_aura(h);
int r = gmod(atan2(h[1], h[0]) * AURA / TAU, AURA);
aurac[r][3] += auramemo << fd;
col = darkened(col);
aurac[r][0] += (col>>16)&255;
aurac[r][1] += (col>>8)&255;
aurac[r][2] += (col>>0)&255;
}
void sumaura(int v) {
int auc[AURA];
for(int t=0; t<AURA; t++) auc[t] = aurac[t][v];
int val = 0;
if(vid.aurasmoothen < 1) vid.aurasmoothen = 1;
if(vid.aurasmoothen > AURA) vid.aurasmoothen = AURA;
int SMO = vid.aurasmoothen;
for(int t=0; t<SMO; t++) val += auc[t];
for(int t=0; t<AURA; t++) {
int tt = (t + SMO/2) % AURA;
aurac[tt][v] = val;
val -= auc[t];
val += auc[(t+SMO) % AURA];
}
aurac[AURA][v] = aurac[0][v];
}
#if CAP_GL
vector<glhr::colored_vertex> auravertices;
#endif
EX debugflag debug_graph = {"graph"};
EX debugflag debug_aura = {"graph_aura"};
EX void drawaura() {
indenter_finish(debug_aura, "drawaura");
if(!haveaura()) return;
if(vid.stereo_mode) return;
double rad = current_display->radius;
if(sphere && !mdAzimuthalEqui()) rad /= sqrt(pconf.alpha*pconf.alpha - 1);
if(hyperbolic && pmodel == mdFisheye) {
ld h = 1;
h /= pconf.fisheye_param;
ld nrad = h / sqrt(2 + h*h);
rad *= nrad;
}
for(int v=0; v<4; v++) sumaura(v);
for(auto& p: auraspecials) {
int r = p.first;
aurac[r][3] = auramemo;
for(int k=0; k<3; k++) aurac[r][k] = (p.second >> (16-8*k)) & 255;
}
#if CAP_SDL || CAP_GL
ld bak[3];
bak[0] = ((backcolor>>16)&255)/255.;
bak[1] = ((backcolor>>8)&255)/255.;
bak[2] = ((backcolor>>0)&255)/255.;
#endif
#if CAP_SDL
if(!vid.usingGL) {
SDL_LockSurface(s);
for(int y=0; y<vid.yres; y++)
for(int x=0; x<vid.xres; x++) {
ld hx = (x * 1. - current_display->xcenter) / rad;
ld hy = (y * 1. - current_display->ycenter) / rad / pconf.stretch;
if(!models::camera_straight) camrotate(hx, hy);
ld fac = sqrt(hx*hx+hy*hy);
if(fac < 1) continue;
ld dd = log((fac - .99999) / .00001);
ld cmul = 1 - dd/10.;
if(cmul>1) cmul=1;
if(cmul<0) cmul=0;
ld alpha = AURA * atan2(hx,hy) / TAU;
if(alpha<0) alpha += AURA;
if(alpha >= AURA) alpha -= AURA;
int rm = int(alpha);
ld fr = alpha-rm;
if(rm<0 || rm >= AURA) continue;
color_t& p = qpixel(s, x, y);
for(int c=0; c<3; c++) {
ld c1 = aurac[rm][2-c] / (aurac[rm][3]+.1);
ld c2 = aurac[rm+1][2-c] / (aurac[rm+1][3]+.1);
const ld one = 1;
part(p, c) = int(255 * min(one, bak[2-c] + cmul * ((c1 + fr * (c2-c1) - bak[2-c]))));
}
}
SDL_UnlockSurface(s);
return;
}
#endif
#if CAP_GL
float cx[AURA+1][11][5];
double facs[11] = {1, 1.01, 1.02, 1.04, 1.08, 1.70, 1.95, 1.5, 2, 6, 10};
double cmul[11] = {1, .8, .7, .6, .5, .16, .12, .08, .07, .06, 0};
double d2[11] = {0, 2, 4, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10};
for(int d=0; d<11; d++) {
double dd = d2[d];
cmul[d] = (1- dd/10.);
facs[d] = .99999 + .00001 * exp(dd);
}
facs[10] = 10;
cmul[1] = cmul[0];
bool inversion = pconf.alpha <= -1 || pmodel == mdJoukowsky;
bool joukowsky = among(pmodel, mdJoukowskyInverted, mdJoukowsky) && hyperbolic && pconf.model_transition < 1;
for(int r=0; r<=AURA; r++) for(int z=0; z<11; z++) {
float rr = (TAU * r) / AURA;
float rad0 = inversion ? rad / facs[z] : rad * facs[z];
int rm = r % AURA;
ld c = cos(rr);
ld s = sin(rr);
if(joukowsky) {
hyperpoint v(c, s, 0, 1);
if(inversion)
models::ori_to_scr(v);
else
models::scr_to_ori(v);
ld c1 = v[0], s1 = v[1];
ld& mt = pconf.model_transition;
ld mt2 = 1 - mt;
ld m = sqrt(c1*c1 + s1*s1 / mt2 / mt2);
m *= 2;
if(inversion) rad0 /= m;
else rad0 *= m;
}
ld x = rad0 * c;
ld y = rad0 * s;
if(!models::camera_straight) {
hyperpoint p = hyperpoint(x, y, rad0, 1);
p = rot_inverse(pconf.cam()) * p;
x = p[0] * rad0 / p[2];
y = p[1] * rad0 / p[2];
}
cx[r][z][0] = x;
cx[r][z][1] = y * pconf.stretch;
for(int u=0; u<3; u++)
cx[r][z][u+2] = bak[u] + (aurac[rm][u] / (aurac[rm][3]+.1) - bak[u]) * cmul[z];
}
auravertices.clear();
for(int r=0; r<AURA; r++) for(int z=0;z<10;z++) {
for(int c=0; c<6; c++) {
int br = (c == 1 || c == 3 || c == 5) ? r+1 : r;
int bz = (c == 2 || c == 4 || c == 5) ? z+1 : z;
auravertices.emplace_back(
cx[br][bz][0], cx[br][bz][1], cx[br][bz][2], cx[br][bz][3], cx[br][bz][4]
);
}
}
glflush();
current_display->next_shader_flags = GF_VARCOLOR;
dynamicval<eModel> m(pmodel, mdPixel);
current_display->set_all(0, 0);
glhr::id_modelview();
glhr::prepare(auravertices);
glhr::set_depthtest(false);
glDrawArrays(GL_TRIANGLES, 0, isize(auravertices));
#endif
}
// int fnt[100][7];
bool bugsNearby(cell *c, int dist = 2) {
if(!(havewhat&HF_BUG)) return false;
if(isBug(c)) return true;
if(dist) for(int t=0; t<c->type; t++) if(c->move(t) && bugsNearby(c->move(t), dist-1)) return true;
return false;
}
EX int celldistAltPlus(cell *c) { return 1000000 + celldistAlt(c); }
EX bool drawstaratvec(double dx, double dy) {
return dx*dx+dy*dy > .05;
}
ld wavefun(ld x) {
return sin(x);
/* x /= TAU;
x -= (int) x;
if(x > .5) return (x-.5) * 2;
else return 0; */
}
// does the current geometry allow nice duals
EX bool has_nice_dual() {
#if CAP_IRR
if(IRREGULAR) return irr::bitruncations_performed > 0;
#endif
#if CAP_ARCM
if(arcm::in()) return geosupport_football() >= 2;
#endif
if(bt::in()) return false;
if(BITRUNCATED) return true;
if(a4) return false;
if((S7 & 1) == 0) return true;
if(PURE) return false;
#if CAP_GP
return (gp::param.first + gp::param.second * 2) % 3 == 0;
#else
return false;
#endif
}
// does the current geometry allow nice duals
EX bool is_nice_dual(cell *c) {
return c->land == laDual && has_nice_dual();
}
EX bool use_swapped_duals() {
return (euclid && !a4) || GOLDBERG;
}
EX bool openorsafe(cell *c) {
#if CAP_COMPLEX2
return c->wall == waMineOpen || mine::marked_safe(c);
#else
return false;
#endif
}
#define Dark(x) darkena(x,0,0xFF)
EX color_t stdgridcolor = 0x202020FF;
EX int gridcolor(cell *c1, cell *c2) {
if(cmode & sm::DRAW && !mapeditor::drawing_tool) return Dark(forecolor);
if(!c2)
return 0x202020 >> darken;
int rd1 = rosedist(c1), rd2 = rosedist(c2);
if(rd1 != rd2) {
int r = rd1+rd2;
if(r == 1) return Dark(0x802020);
if(r == 3) return Dark(0xC02020);
if(r == 2) return Dark(0xF02020);
}
if((get_spatial_info(c1).deep<SIDE::SHALLOW) != (get_spatial_info(c2).deep<SIDE::SHALLOW) && c1->land != laAsteroids && c2->land != laAsteroids)
return Dark(0x808080);
if(c1->land == laAlchemist && c2->land == laAlchemist && c1->wall != c2->wall && !c1->item && !c2->item)
return Dark(0xC020C0);
if((c1->land == laWhirlpool || c2->land == laWhirlpool) && (celldistAlt(c1) != celldistAlt(c2)))
return Dark(0x2020A0);
if(c1->land == laMinefield && c2->land == laMinefield && (openorsafe(c1) != openorsafe(c2)))
return Dark(0xA0A0A0);
if(!darken) return stdgridcolor;
return Dark(0x202020);
}
#if CAP_SHAPES
EX void pushdown(cell *c, int& q, const shiftmatrix &V, double down, bool rezoom, bool repriority) {
#if MAXMDIM >= 4
if(GDIM == 3) {
for(int i=q; i<isize(ptds); i++) {
auto pp = ptds[q++]->as_poly();
if(!pp) continue;
auto& ptd = *pp;
ptd.V = ptd.V * lzpush(+down);
}
return;
}
#endif
// since we might be changing priorities, we have to make sure that we are sorting correctly
if(down > 0 && repriority) {
int qq = q+1;
while(qq < isize(ptds))
if(qq > q && ptds[qq]->prio < ptds[qq-1]->prio) {
swap(ptds[qq], ptds[qq-1]);
qq--;
}
else qq++;
}
while(q < isize(ptds)) {
auto pp = ptds[q++]->as_poly();
if(!pp) continue;
auto& ptd = *pp;
double z2;
double z = zlevel(tC0(ptd.V.T));
double lev = geom3::factor_to_lev(z);
double nlev = lev - down;
double xyscale = rezoom ? geom3::scale_at_lev(lev) / geom3::scale_at_lev(nlev) : 1;
z2 = geom3::lev_to_factor(nlev);
double zscale = z2 / z;
// xyscale = xyscale + (zscale-xyscale) * (1+sin(ticks / 1000.0)) / 2;
ptd.V.T = xyzscale( V.T, xyscale*zscale, zscale)
* z_inverse(V.T) * unshift(ptd.V, V.shift);
if(!repriority) ;
else if(nlev < -vid.lake_bottom-1e-3) {
ptd.prio = PPR::DEEP_FALLANIM;
if(c->wall != waChasm)
ptd.color = 0; // disappear!
}
else if(nlev < -vid.lake_top-1e-3)
ptd.prio = PPR::SHALLOW_FALLANIM;
else if(nlev < 0)
ptd.prio = PPR::FLOOR_FALLANIM;
}
}
#endif
bool allemptynear(cell *c) {
if(c->wall) return false;
forCellEx(c2, c) if(c2->wall) return false;
return true;
}
EX bool bright;
EX int canvasdark;
// how much to darken
EX int getfd(cell *c) {
if(bright) return 0;
if(among(c->land, laAlchemist, laHell, laVariant, laEclectic) && WDIM == 2 && GDIM == 3) return 0;
switch(c->land) {
case laCanvas:
return min(2,max(0,canvasdark));
case laRedRock:
case laReptile:
return 0;
case laSnakeNest:
return realred(c->wall) ? 0 : 1;
case laTerracotta:
case laMercuryRiver:
return (c->wall == waMercury && wmspatial) ? 0 : 1;
case laKraken:
case laDocks:
case laBurial:
case laIvoryTower:
case laDungeon:
case laMountain:
case laEndorian:
case laCaribbean:
case laWhirlwind:
case laRose:
case laWarpSea:
case laTortoise:
case laDragon:
case laHalloween:
case laHunting:
case laOcean:
case laLivefjord:
case laWhirlpool:
case laAlchemist:
case laIce:
case laGraveyard:
case laBlizzard:
case laRlyeh:
case laTemple:
case laWineyard:
case laDeadCaves:
case laPalace:
case laCA:
case laDual:
case laBrownian:
return 1;
case laVariant:
if(isWateryOrBoat(c)) return 1;
return 2;
case laTrollheim:
default:
return 2;
}
}
EX bool just_gmatrix;
EX int colorhash(color_t i) {
return (i * 0x471211 + i*i*0x124159 + i*i*i*0x982165) & 0xFFFFFF;
}
EX ld mousedist(shiftmatrix T) {
if(GDIM == 2) return hdist(mouseh, tC0(T));
shiftpoint T1 = orthogonal_move_fol(T, cgi.FLOOR) * tile_center();
hyperpoint h1;
applymodel(T1, h1);
if(mouseaim_sensitivity) return sqhypot_d(2, h1) + (point_behind(T1) ? 1e10 : 0);
h1 = h1 - point2((mousex - current_display->xcenter) / current_display->radius, (mousey - current_display->ycenter) / current_display->radius);
return sqhypot_d(2, h1) + (point_behind(T1) ? 1e10 : 0);
}
EX vector<vector<hyperpoint>> clipping_plane_sets;
EX int noclipped;
EX bool frustum_culling = true;
EX ld threshold, xyz_threshold;
EX bool clip_checked = false;
EX bool other_stereo_mode() {
return vid.stereo_mode != sOFF;
}
EX void make_clipping_planes() {
#if MAXMDIM >= 4
clip_checked = false;
if(!frustum_culling || PIU(sphere) || experimental || other_stereo_mode() || gproduct || embedded_plane) return;
if(WDIM == 3 && pmodel == mdPerspective && !nonisotropic && !in_s2xe())
threshold = sin_auto(cgi.corner_bonus), xyz_threshold = 0, clip_checked = true;
else if(pmodel == mdGeodesic && sn::in())
threshold = .6, xyz_threshold = 3, clip_checked = true;
else if(pmodel == mdGeodesic && nil)
threshold = 2, xyz_threshold = 3, clip_checked = true;
else return;
clipping_plane_sets.clear();
auto add_clipping_plane_txy = [] (transmatrix T, const transmatrix& nlp, ld x1, ld y1, ld x2, ld y2) {
ld z1 = 1, z2 = 1;
hyperpoint sx = point3(y1 * z2 - y2 * z1, z1 * x2 - z2 * x1, x1 * y2 - x2 * y1);
sx /= hypot_d(3, sx);
sx[3] = 0;
sx = T * sx;
if(nisot::local_perspective_used) sx = ortho_inverse(nlp) * sx;
clipping_plane_sets.back().push_back(sx);
};
#if CAP_VR
auto add_clipping_plane_proj = [&] (transmatrix T, const transmatrix& nlp, const transmatrix& iproj, ld x1, ld y1, ld x2, ld y2) {
hyperpoint h1 = iproj * point31(x1, y1, .5);
hyperpoint h2 = iproj * point31(x2, y2, .5);
h1 /= h1[2]; h2 /= h2[2];
add_clipping_plane_txy(T, nlp, h1[0], h1[1], h2[0], h2[1]);
};
#endif
auto clipping_planes_screen = [&] (const transmatrix& T, const transmatrix& nlp) {
ld tx = current_display->tanfov;
ld ty = tx * current_display->ysize / current_display->xsize;
clipping_plane_sets.push_back({});
add_clipping_plane_txy(T, nlp, +tx, +ty, -tx, +ty);
add_clipping_plane_txy(T, nlp, -tx, +ty, -tx, -ty);
add_clipping_plane_txy(T, nlp, -tx, -ty, +tx, -ty);
add_clipping_plane_txy(T, nlp, +tx, -ty, +tx, +ty);
};
bool stdview = true;
#if CAP_VR
if(vrhr::active()) {
for(auto p: vrhr::frusta) {
if(p.screen)
clipping_planes_screen(inverse(p.pre), p.nlp);
else {
auto iproj = inverse(p.proj);
auto ipre = inverse(p.pre);
clipping_plane_sets.push_back({});
add_clipping_plane_proj(ipre, p.nlp, iproj, 1, 1, 0, 1);
add_clipping_plane_proj(ipre, p.nlp, iproj, 0, 1, 0, 0);
add_clipping_plane_proj(ipre, p.nlp, iproj, 0, 0, 1, 0);
add_clipping_plane_proj(ipre, p.nlp, iproj, 1, 0, 1, 1);
}
stdview = false;
}
}
#endif
if(stdview) clipping_planes_screen(Id, NLP);
#endif
}
EX bool clipped_by(const hyperpoint& H, const vector<hyperpoint>& v) {
for(auto& cpoint: v) if((H|cpoint) < -threshold) return true;
return false;
}
EX bool clipped_by(const hyperpoint& H, const vector<vector<hyperpoint>>& vv) {
for(auto& cps: vv) if(!clipped_by(H, cps)) return false;
return true;
}
bool celldrawer::cell_clipped() {
if(!clip_checked) return false;
hyperpoint H = unshift(tC0(V));
if(xyz_threshold && abs(H[0]) <= xyz_threshold && abs(H[1]) <= xyz_threshold && abs(H[2]) <= xyz_threshold) {
noclipped++;
return false;
}
if(clipped_by(H, clipping_plane_sets)) {
drawcell_in_radar();
return true;
}
noclipped++;
return false;
}
EX ld precise_width = .5;
int grid_depth = 0;
EX bool fat_edges = false;
EX bool gridbelow;
EX void gridline(const shiftmatrix& V1, const hyperpoint h1, const shiftmatrix& V2, const hyperpoint h2, color_t col, int prec) {
transmatrix U2 = unshift(V2, V1.shift);
int c1 = safe_classify_ideals(h1);
int c2 = safe_classify_ideals(h2);
ld d = (c1 <= 0 || c2 <= 0) ? 99 : hdist(V1.T*h1, U2*h2);
#if MAXMDIM >= 4
if(GDIM == 3 && fat_edges) {
if(nonisotropic) {
auto nV1 = V1 * rgpushxto0(h1);
hyperpoint U2 = inverse_shift(nV1, V2*rgpushxto0(h2)) * C0;
auto& p = cgi.get_pipe_noniso(U2, vid.linewidth, ePipeEnd::ball);
queuepoly(nV1, p, col);
return;
}
shiftmatrix T = V1 * rgpushxto0(h1);
transmatrix S = rspintox(inverse_shift(T, V2) * h2);
transmatrix U = rspintoc(inverse_shift(T*S, shiftless(C0)), 2, 1);
auto& p = queuepoly(T * S * U, cgi.get_pipe_iso(d, vid.linewidth, ePipeEnd::ball), col);
p.intester = xpush0(d/2);
return;
}
#endif
while(d > precise_width && d < 100 && grid_depth < 10) {
if(V1.shift != V2.shift || !eqmatrix(V1.T, V2.T, 1e-6)) { gridline(V1, h1, V1, inverse_shift(V1, V2) * h2, col, prec); return; }
hyperpoint h;
if(c1 <= 0 && c2 <= 0) {
h = closest_to_zero(h1, h2);
if(safe_classify_ideals(h) <= 0) return;
h = normalize(h);
}
else if(c2 <= 0) {
dynamicval<int> dw(grid_depth, 99);
for(ld a=0; a<ideal_limit; a+=precise_width)
gridline(V1, towards_inf(h1, h2, a), V1, towards_inf(h1, h2, a+precise_width), col, prec);
return;
}
else if(c1 <= 0) {
dynamicval<int> dw(grid_depth, 99);
for(ld a=0; a<ideal_limit; a+=precise_width)
gridline(V1, towards_inf(h2, h1, a), V1, towards_inf(h2, h1, a+precise_width), col, prec);
return;
}
else h = midz(h1, h2);
grid_depth++;
gridline(V1, h1, V1, h, col, prec);
gridline(V1, h, V1, h2, col, prec);
grid_depth--;
return;
}
#if MAXMDIM >= 4
if(WDIM == 2 && GDIM == 3) {
ld eps = cgi.human_height/100;
queueline(V1*orthogonal_move(h1,cgi.FLOOR+eps), V2*orthogonal_move(h2,cgi.FLOOR+eps), col, prec);
queueline(V1*orthogonal_move(h1,cgi.WALL-eps), V2*orthogonal_move(h2,cgi.WALL-eps), col, prec);
}
else
#endif
queueline(V1*h1, V2*h2, col, prec, gridbelow ? PPR::FLOORd : PPR::LINE);
}
EX void gridline(const shiftmatrix& V, const hyperpoint h1, const hyperpoint h2, color_t col, int prec) {
gridline(V, h1, V, h2, col, prec);
}
EX void set_detail_level(const shiftmatrix& V) {
ld dist0 = hdist0(tC0(V)) - 1e-6;
if(vid.use_smart_range) detaillevel = 2;
else if(dist0 < vid.highdetail) detaillevel = 2;
else if(dist0 < vid.middetail) detaillevel = 1;
else detaillevel = 0;
if((cmode & sm::NUMBER) && (dialog::editingDetail())) {
color_t col =
dist0 < vid.highdetail ? 0xFF80FF80 :
dist0 >= vid.middetail ? 0xFFFF8080 :
0XFFFFFF80;
queuepoly(V, cgi.shHeptaMarker, darkena(col & 0xFFFFFF, 0, 0xFF));
}
}
#if CAP_QUEUE
EX void queuecircleat1(cell *c, const shiftmatrix& V, double rad, color_t col) {
if(WDIM == 3) {
dynamicval<color_t> p(poly_outline, col);
int ofs = currentmap->wall_offset(c);
for(int i=0; i<c->type; i++) {
queuepolyat(V, cgi.shWireframe3D[ofs + i], 0, PPR::SUPERLINE);
}
return;
}
if(spatial_graphics || GDIM == 3) {
vector<hyperpoint> corners(c->type+1);
for(int i=0; i<c->type; i++) corners[i] = get_corner_position(c, i, 3 / rad);
corners[c->type] = corners[0];
for(int i=0; i<c->type; i++) {
queueline(V * orthogonal_move_fol(corners[i], cgi.FLOOR), V * orthogonal_move_fol(corners[i+1], cgi.FLOOR), col, 2, PPR::SUPERLINE);
queueline(V * orthogonal_move_fol(corners[i], cgi.WALL), V * orthogonal_move_fol(corners[i+1], cgi.WALL), col, 2, PPR::SUPERLINE);
queueline(V * orthogonal_move_fol(corners[i], cgi.FLOOR), V * orthogonal_move_fol(corners[i], cgi.WALL), col, 2, PPR::SUPERLINE);
}
return;
}
#if CAP_SHAPES
if(vid.stereo_mode || sphere) {
dynamicval<color_t> p(poly_outline, col);
queuepolyat(V * spintick(100), cgi.shGem[1], 0, PPR::LINE);
return;
}
#endif
queuecircle(V, rad, col);
if(!wmspatial) return;
auto si = get_spatial_info(c);
if(si.top == SIDE::WALL)
queuecircle(orthogonal_move_fol(V, cgi.WALL), rad, col);
if(si.top == SIDE::RED1)
queuecircle(orthogonal_move_fol(V, cgi.RED[1]), rad, col);
if(si.top == SIDE::RED2)
queuecircle(orthogonal_move_fol(V, cgi.RED[2]), rad, col);
if(si.top == SIDE::RED3)
queuecircle(orthogonal_move_fol(V, cgi.RED[3]), rad, col);
if(si.top <= SIDE::WATERLEVEL)
queuecircle(orthogonal_move_fol(V, cgi.WATERLEVEL), rad, col);
}
EX void queuecircleat(cell *c, double rad, color_t col) {
if(!c) return;
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, c))
queuecircleat1(c, V, rad, col);
}
#endif
#if ISMOBILE
#define MOBON (clicked)
#else
#define MOBON true
#endif
EX cell *forwardcell() {
#if CAP_VR
if(vrhr::active()) {
return vrhr::forward_cell;
}
#endif
movedir md = vectodir(move_destination_vec(6));
cellwalker xc = cwt + md.d + wstep;
return xc.at;
}
EX bool draw_centerover = true;
EX bool should_draw_mouse_cursor() {
if(!mousing || inHighQual) return false;
if(outofmap(mouseh.h)) return false;
if(rug::rugged && !rug::renderonce) return true;
return false;
}
EX void drawMarkers() {
shmup::draw_collision_debug();
if(!(cmode & sm::NORMAL)) return;
if(should_draw_mouse_cursor()) {
for(int i: player_indices()) {
queueline(ggmatrix(playerpos(i)) * (WDIM == 2 && GDIM == 3 ? zpush0(cgi.WALL) : C0), mouseh, 0xFF00FF, grid_prec() + 1);
}
}
callhooks(hooks_markers);
#if CAP_SHAPES
viewmat();
#endif
#if CAP_QUEUE
for(cell *c1: crush_now)
queuecircleat(c1, .8, darkena(minf[moCrusher].color, 0, 0xFF));
#endif
if(!inHighQual) {
bool ok = !ISPANDORA || mousepressed;
ignore(ok);
#if CAP_QUEUE
if(haveMount())
for (const shiftmatrix& V : hr::span_at(current_display->all_drawn_copies, dragon::target)) {
queuestr(V, mapfontscale/100, "X",
gradient(0, iinf[itOrbDomination].color, -1, sintick(dragon::whichturn == turncount ? 75 : 150), 1));
}
#endif
/* for(int i=0; i<12; i++) if(c->type == 5 && c->master == &dodecahedron[i])
queuestr(xc, yc, sc, 4*vid.fsize, s0+('A'+i), iinf[itOrbDomination].color); */
if(1) {
using namespace yendor;
if(yii < isize(yi) && !yi[yii].found) {
cell *keycell = NULL;
int last_i = 0;
for(int i=0; i<YDIST; i++)
if(yi[yii].path[i]->cpdist <= get_sightrange_ambush()) {
keycell = yi[yii].path[i]; last_i = i;
}
if(keycell) {
for(int i = last_i+1; i<YDIST; i++) {
cell *c = yi[yii].path[i];
if(inscreenrange(c))
keycell = c;