-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoctis-1.cpp
4966 lines (4532 loc) · 147 KB
/
noctis-1.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
#include "defs.h"
#include "noctis-d.h"
#include "noctis-0.h"
#include "noctis-2.h"
// <temp> Temporary to make the code easier to mod later on
#define FLYING_LANDER 1
#define option_flying_lander 1
// </temp>
const double deg = M_PI / 180;
int opencapcount;
float refx, refy, refz;
float sp_x, sp_y, sp_z;
/* Funzioni e variabili globali di tracciamento e gestione
delle superfici planetarie, in poligonale (h! ce la far•?)
Si, ce l'ho fatta, ahem... dunque...
per tracciare in tempo utile una superficie di 40000 quadranti,
ovvero 80000 triangoli, su una matrice di 200x200 (un po' tantino
in effetti) ho applicato un procedimento di, boh...
"focalizzazione" diciamo. Pi— probabilmente pu• chiamarsi
"depth culling"... inclusi i riflessi, la funzione "fragment"
passa al vaglio 160.000 poligoni per fotogramma, disegnandone
comunque circa un decimo. E' importante ottimizzare quella,
quando si vuole ottimizzare qualcosa... */
char sctype; // tipo di scenario.
#define OCEAN 1
#define PLAINS 2
#define DESERT 3
#define ICY 4
float dsd1, dsd2; // distanza dal sole (pri/sec)
float nray1, nray2; // raggio del sole (pri/sec)
float latitude; // latitudine (0..90, 90=poli)
float exposure; // longitudine relativa al centro dell'area diurna.
float sun_x, sun_y, sun_z; // coordinate del "sole" locale.
int sh_delta; // shift del puntatore di confronto per lo shading.
// dati riguardanti il "sole" primario se ci si trova
// attorno a un sole secondario (sistemi multipli di classe 8)
char jumping;
char jetpack;
extern char blinkhudlights;
extern char blinkhudlights_stay;
int pri_crepzone;
int pri_nightzone;
int pri_sun_x_factor;
float pri_latitude, pri_exposure;
float pri_x, pri_y, pri_z;
char mirror = 0; // effetto specchio d'acqua (agisce su "fragment").
char waves_in = 0; // flag di presenza delle onde sui mari.
char waves_out = 0; // flag di produzione di onde sui mari.
long T_SCALE; // scala della texture, passata in H/V_MATRIXS.
float base_pp_temp;
float base_pp_pressure;
float hpoint (long px, long pz)
{ // Trova l'altezza di un punto sulla superficie.
// Per migliorare la risoluzione, usa un procedimento d'interpolazione
// bi-lineare, con 16384 gradazioni intermedie, tante quante le unit…
// logiche che compongono il lato di un quadrante; considera anche
// la divisione dei quadranti in due triangoli isosceli.
long cpos;
float h1, h2, h3, h4, icx, icz, py;
cpos = m200[pz>>14] + (px>>14);
h1 = - ((long)(p_surfacemap[cpos]) << 11);
h2 = - ((long)(p_surfacemap[cpos+1]) << 11);
h3 = - ((long)(p_surfacemap[cpos+201]) << 11);
h4 = - ((long)(p_surfacemap[cpos+200]) << 11);
icx = px & 16383;
icz = pz & 16383;
if (icx+icz<16384) {
py = h1 + (h2 - h1) * (icx * qid);
py += (h4 - h1) * (icz * qid);
}
else {
py = h3 + (h4 - h3) * ((16384-icx) * qid);
py += (h2 - h3) * ((16384-icz) * qid);
}
return (py);
}
/*
-----------------------------------------------------------------
Collezione di funzioni interdipendenti per il tracciamento degli
oggetti che si possono trovare sulla superficie dei vari pianeti.
-----------------------------------------------------------------
*/
char groundflares = 0; // tipo di tracciamento del suolo.
long mushscaling = 8191; // range variabilit… (in bitmask) "greenmush"
float treescaling = 4096; // scalatura alberi, di solito mushscaling/2
float treespreads = 0.75; // scalatura rami ad ogni ricorsione
float treepeaking = 1.25; // passa come "distance_from_perfection"
float branchwidth = 0.15; // larghezza dei rami rispetto alla lunghezza
float rootheight = 0.50; // altezza del tronco rispetto a "treescaling"
char rootshade = 0x00; // colore di base del tronco
char treeflares = 0x00; // tipo di tracciamento rami.
char leafflares = 0x00; // tipo di tracciamento foglie.
float rockscaling = 500; // dimensioni delle rocce.
float rockpeaking = 250; // altezza delle rocce.
int rockdensity = 15; // densit… gruppi di rocce (bitmask).
char quartz = 0; // traccia quarzi trasparenti, se impostato.
int detail_seed = 12345;
void greenmush (float x, float y, float z,
unsigned char mask_1, unsigned char mask_2,
long scaling, unsigned char colorgrade,
unsigned char colormask, char noseed)
{ // produce una serie di gruppi di minuscole sagome verdi, studiate per
// fornire l'impressione delle fronde degli alberi pi— distanti.
long correction;
int n1, m1, n2, m2;
correction = scaling >> 1;
x += correction;
y += correction;
z += correction;
if (!noseed)
fast_srand (((long)x>>14) + ((long)y>>14) + ((long)z>>14));
m1 = 1 + fast_random (mask_1);
for (n1 = 0; n1 < m1; n1++)
if (getcoords (x - fast_random (scaling),
y - fast_random (scaling),
z - fast_random (scaling))) {
m2 = 1 + fast_random (mask_2);
for (n2 = 0; n2 < m2; n2++) {
_DI = riga[_y_+fast_random(7)]+_x_+fast_random(7);
_CL = colorgrade + fast_random (colormask);
asm { les ax, adapted
mov es:[di+4], cl
mov es:[di+5], cl
mov es:[di+3], cl
mov es:[di+324], cl
mov es:[di-316], cl
mov es:[di-636], cl }
}
}
}
void build_fractal_tree (float x, float y, float z,
float scaling, float reduction, float globalwidth,
long layers, long divisions, float distance_from_perfection,
unsigned char rootcolormask, unsigned char leafcolormask,
float branchdetail, char isrootnode, char occurrence)
{ // funzione ricorsiva: eventualmente traccia l'intero albero pseudo-casuale,
// con una struttura multilivello, ma va usata con parsimonia perch‚ Š
// ovviamente una cosa piuttosto laboriosa in termini di tempo.
//
// serve qualche spiegazione per i parametri, che sono davvero tantini...
//
// P(x;y;z) - origine del tronco (punto medio della base del tronco)
// scaling - altezza del tronco (determina anche la lunghezza dei rami)
// reduction - coefficiente di riduzione della lunghezza dei rami,
// calcolata rispetto a quella del tronco livello per livello
// globalwidth - coefficiente che determina la larghezza dei rami,
// calcolata rispetto alla loro lunghezza
// layers - numero di processi ricorsivi di suddivisione del tronco
// una buona tattica per disegnare ciuffi d'erba Š porre
// questo parametro E il successivo entrambi a zero...
// divisions - maschera delle ramificazioni della cima di ogni ramo
// branchdetail- step di rotazione nel tracciamento dei rami
// (p.es. 120 traccia 360/120 = 3 poligoni per ramo)...
// il minimo livello di dettaglio Š 360, un poligono per ramo,
// 180 fa i rami piatti ma visibili da ogni lato,
// e infine 120 approssima piuttosto bene...
// isrootnode - chiamare la funzione con questo parametro impostato a 1
// per ottenere un albero normale, anche se si possono
// agevolmente disegnare dei cespugli semplicemente ponendo
// questo flag a zero, poich‚ un cespuglio pu• essere anche
// approssimato, in effetti, come un albero senza tronco
// occurrence - Š un contatore, va semplicemente posto a zero.
//
// rootcolormask Š il colore di base per il tronco e per i rami.
// leafcolormask Š il colore di base per le foglie.
//
// distance_from_perfection, infine, Š un coefficiente in gradi, che
// esprime di quanto i rami "figli" possono divaricarsi ad ogni ulteriore
// suddivisione dei rami "padri": in pratica, distance_from_perfection
// rappresenta l'irregolarit… generale dell'albero - ad esempio, per le
// latifoglie bisognerebbe impostare questo parametro ad un valore alto
// (diciamo all'incirca 1.25), mentre per qualcosa di pi— simile ad una
// conifera questo valore andrebbe abbassato all'incirca a 0.3 .. 0.4
// (ponendolo a zero si otterrebbero rami in una colonna verticale).
int subdivs;
char polycolor;
char pf = flares;
float x2, y2, z2;
float fx[4], fy[4], fz[4];
float widthscale1, widthscale2;
float b_angle, b_angle_delta, range, rotation, rlimit;
float rot2, rot3;
long hm, vm, lseed;
unsigned char huge *previoustexture;
widthscale1 = scaling * globalwidth;
widthscale2 = reduction * scaling * globalwidth;
if (isrootnode) {
subdivs = 1;
range = scaling * distance_from_perfection * 0.2;
}
else {
subdivs = 1 + fast_random (divisions);
range = scaling * distance_from_perfection * 0.5;
}
rlimit = 360 - branchdetail;
b_angle = 0;
if (subdivs) {
b_angle_delta = (float)(2*M_PI) / (float)subdivs;
b_angle = b_angle_delta * 0.5;
}
lseed = x + y + z + detail_seed;
while (subdivs) {
fast_srand (lseed);
lseed += 3;
//
if (layers) {
flares = treeflares;
hm = H_MATRIXS; vm = V_MATRIXS;
H_MATRIXS = 3; V_MATRIXS = 8;
change_txm_repeating_mode();
previoustexture = txtr;
x2 = x + cos(b_angle) * range;
z2 = z + sin(b_angle) * range;
if (isrootnode)
y2 = y - (fast_flandom() * rootheight + 0.1) * scaling;
else
y2 = y - (fast_flandom() + 0.25) * scaling * 0.25;
fy[0] = y;
fy[1] = y;
fy[2] = y2;
fy[3] = y2;
polycolor = 9 * occurrence;
for (rotation = 0; rotation <= rlimit; rotation += branchdetail) {
fx[0] = x + lft_cos[rotation ] * widthscale1;
fz[0] = z + lft_sin[rotation ] * widthscale1;
fx[1] = x + lft_cos[rotation + branchdetail] * widthscale1;
fz[1] = z + lft_sin[rotation + branchdetail] * widthscale1;
fx[2] = x2 + lft_cos[rotation + branchdetail] * widthscale2;
fz[2] = z2 + lft_sin[rotation + branchdetail] * widthscale2;
fx[3] = x2 + lft_cos[rotation ] * widthscale2;
fz[3] = z2 + lft_sin[rotation ] * widthscale2;
if (isrootnode) {
fy[0] = hpoint (fx[0], fz[0]);
fy[1] = hpoint (fx[1], fz[1]);
}
if (facing (fx, fy, fz))
polymap (fx, fy, fz, 4, polycolor + rootcolormask);
txtr += 48;
polycolor += 4;
}
H_MATRIXS = hm; V_MATRIXS = vm;
change_txm_repeating_mode();
txtr = previoustexture;
build_fractal_tree (x2, y2, z2, scaling * reduction, reduction,
globalwidth, layers - 1, divisions, distance_from_perfection,
rootcolormask, leafcolormask, branchdetail, 0, occurrence + 1);
}
else {
flares = leafflares;
hm = H_MATRIXS; vm = V_MATRIXS;
H_MATRIXS = 1; V_MATRIXS = 3;
change_txm_repeating_mode();
previoustexture = txtr;
x2 = x + fast_flandom() * range - fast_flandom() * range;
z2 = z + fast_flandom() * range - fast_flandom() * range;
fy[0] = y;
fy[1] = y;
fy[2] = y - fast_flandom() * scaling;
polycolor = fast_random (31);
rot2 = 0; rot3 = 0;
for (rotation = 0; rotation <= rlimit; rotation += branchdetail) {
rot2 = rotation + 72; if (rot2 > 359) rot2 -= 360;
rot3 = rotation + 36; if (rot3 > 359) rot3 -= 360;
fx[0] = x + lft_cos[rotation] * widthscale1;
fz[0] = z + lft_sin[rotation] * widthscale1;
fx[1] = x + lft_cos[rot2] * widthscale1;
fz[1] = z + lft_sin[rot2] * widthscale1;
fx[2] = x2 + lft_cos[rot3] * range + wdircos;
fz[2] = z2 + lft_sin[rot3] * range + wdirsin;
polymap (fx, fy, fz, 3, polycolor + leafcolormask);
greenmush (fx[2], fy[2], fz[2], 15, 3, 1023, 223, 31, 0);
polycolor += 2;
}
H_MATRIXS = hm; V_MATRIXS = vm;
change_txm_repeating_mode();
txtr = previoustexture;
}
//
subdivs--;
b_angle += b_angle_delta;
}
flares = pf;
}
#define FORCE_LAT 11
#define FORCE_CON 22
#define GIANT_TREE 333
void albero (float x, float y, float z, long depth)
{ // disegna alberi ove richiesti.
fast_srand (x+y+z+3);
int treetype = fast_random(511);
if (treetype == GIANT_TREE) {
if (depth > 11) {
greenmush (x, y - treescaling * 0.5, z, 07, 15, mushscaling, 223, 31, 0);
return;
}
if (depth > 07) {
build_fractal_tree (x, y, z,
2*treescaling, treespreads, 1.5*branchwidth,
3, 2, 1.5*treepeaking, rootshade, 0xC0, 120, 1, 0);
return;
}
if (depth > 04) {
build_fractal_tree (x, y, z,
2*treescaling, treespreads, 1.5*branchwidth,
4, 3, 1.5*treepeaking, rootshade, 0xC0, 120, 1, 0);
return;
}
build_fractal_tree (x, y, z,
2*treescaling, treespreads, 1.5*branchwidth,
4, 3, 1.5*treepeaking, rootshade, 0xC0, 72, 1, 0);
return;
}
if (depth > 20) {
greenmush (x, y - treescaling * 0.5, z, 03, 07, mushscaling, 223, 31, 0);
return;
}
if (depth > 10) {
greenmush (x, y - treescaling * 0.7, z, 07, 15, mushscaling, 223, 31, 0);
return;
}
if (depth > 03) {
greenmush (x, y - treescaling * 0.9, z, 15, 31, mushscaling, 223, 31, 0);
return;
}
treetype >>= 3;
if (treetype == FORCE_LAT) {
build_fractal_tree (x, y, z,
treescaling, treespreads, branchwidth,
2, 3, 2*treepeaking, 0x80, 0xC0, 120, 1, 0);
return;
}
if (treetype == FORCE_CON) {
build_fractal_tree (x, y, z,
treescaling, treespreads, branchwidth,
2, 2, 0.5*treepeaking, 0x80, 0x40, 120, 1, 0);
return;
}
build_fractal_tree (x, y, z,
treescaling, treespreads, branchwidth,
2, 2, treepeaking, rootshade, 0xC0, 120, 1, 0);
}
void cespuglio (float x, float y, float z, long depth)
{ // disegna un cespuglio.
// da 48 mt in poi: ammasso di foglie.
if (depth >= 3) {
greenmush (x, y, z, 7, 7, mushscaling, 209, 31, 0);
return;
}
switch (depth) {
case 2: // 32 -- 48 mt: visibili i ramoscelli pi— grandi.
build_fractal_tree (x, y, z, 3000, 0.75, 0.15, 1, 1, 1.5, 0x00, 0xC0, 180, 0, 0);
break;
case 1: // 16 -- 32 mt: visibili il 50% delle ramificazioni.
build_fractal_tree (x, y, z, 3000, 0.75, 0.15, 1, 2, 1.5, 0x00, 0xC0, 120, 0, 0);
break;
case 0: // 0 -- 16 mt: cespuglio completo.
build_fractal_tree (x, y, z, 3000, 0.75, 0.15, 1, 3, 1.5, 0x00, 0xC0, 120, 0, 0);
}
}
void ciuffo (float x, float y, float z, long depth)
{ // disegna un ciuffo d'erba.
// da 64 mt in poi, non Š visibile.
if (depth >= 4) return;
switch (depth) {
case 3: // 48 -- 64 mt: qualche macchietta.
greenmush (x, y, z, 3, 7, 1023, 216, 31, 0);
break;
case 2: // 32 -- 48 mt: visibile un filo d'erba.
build_fractal_tree (x, y, z, 1000, 1.00, 0.25, 0, 0, 1.0, 0x00, 0xC0, 120, 0, 0);
break;
case 1: // 16 -- 32 mt: visibili il 50% dei fili d'erba.
build_fractal_tree (x, y, z, 1000, 1.00, 0.25, 0, 7, 1.0, 0x00, 0xC0, 90, 0, 0);
break;
case 0: // 0 -- 16 mt: un ciuffo completo.
build_fractal_tree (x, y, z, 1000, 1.00, 0.25, 0, 7, 1.0, 0x00, 0xC0, 60, 0, 0);
}
}
void roccia (float x, float y, float z, long depth)
{ // disegna una pietra fatta sulla base di un tetraedo per risparmiare tempo.
float tx[4], ty[4], tz[4];
float px[3], pz[3];
float rs = rockscaling;
char rc[3], rcolor;
int cdown;
// da 160 mt in poi: nulla di visibile.
if (depth >= 8) return;
// questo significa che non devono mai essere visualizzate rocce.
if (!rockdensity) return;
fast_srand (detail_seed);
// e questo che IN questo quadrante non ci sono rocce.
cdown = fast_random (rockdensity);
if (!cdown) return;
// da 32 a 160 mt: solo un triangolino.
if (depth > 2) {
tx[0] = x; tx[1] = x; tx[2] = x + rockscaling - fast_flandom () * rockscaling;
tz[0] = z; tz[1] = z; tz[2] = z + rockscaling - fast_flandom () * rockscaling;
ty[0] = y - 100 - fast_flandom () * rockpeaking;
ty[1] = y - 100 - fast_flandom () * rockpeaking;
ty[2] = y - 100 - fast_flandom () * rockpeaking;
rcolor = fast_random (64 + 7);
if (facing (tx, ty, tz))
poly3d (tx, ty, tz, 3, rcolor);
return;
}
// da 16 a 32 mt: tre triagolini disposti a tetraedo, senza base.
// da 0 a 16 mt: con texture, e sassolini multipli se necessari.
rockscaling *= 5;
setfx (quartz);
rockrep:px[0] = x - fast_flandom () * rockscaling;
pz[0] = z - fast_flandom () * rockscaling;
px[1] = x;
pz[1] = z + fast_flandom () * rockscaling;
px[2] = x + fast_flandom () * rockscaling;
pz[2] = z - fast_flandom () * rockscaling;
rcolor = fast_random (64);
rc[0] = rcolor + fast_random( 7);
rc[1] = rcolor + fast_random(15);
rc[2] = rcolor + fast_random(31);
tx[2] = x; tz[2] = z;
ty[2] = hpoint (x, z) - 100 - fast_flandom () * rockpeaking;
tx[0] = px[0]; tx[1] = px[1];
tz[0] = pz[0]; tz[1] = pz[1];
ty[0] = hpoint (tx[0], tz[0]);
ty[1] = hpoint (tx[1], tz[1]);
if (!facing (tx, ty, tz)) {
if (depth < 2) {
tx[3] = tx[2]; ty[3] = ty[2]; tz[3] = tz[2];
polymap (tx, ty, tz, 4, rc[0]);
}
else
poly3d (tx, ty, tz, 3, rc[0]);
}
tx[0] = px[1]; tx[1] = px[2];
tz[0] = pz[1]; tz[1] = pz[2];
ty[0] = hpoint (tx[0], tz[0]);
ty[1] = hpoint (tx[1], tz[1]);
if (!facing (tx, ty, tz)) {
if (depth < 2) {
tx[3] = tx[2]; ty[3] = ty[2]; tz[3] = tz[2];
polymap (tx, ty, tz, 4, rc[1]);
}
else
poly3d (tx, ty, tz, 3, rc[1]);
}
tx[0] = px[2]; tx[1] = px[0];
tz[0] = pz[2]; tz[1] = pz[0];
ty[0] = hpoint (tx[0], tz[0]);
ty[1] = hpoint (tx[1], tz[1]);
if (!facing (tx, ty, tz)) {
if (depth < 2) {
tx[3] = tx[2]; ty[3] = ty[2]; tz[3] = tz[2];
polymap (tx, ty, tz, 4, rc[2]);
}
else
poly3d (tx, ty, tz, 3, rc[2]);
}
x = x + fast_flandom() * 1000 * cdown - fast_flandom () * 1000 * cdown;
z = z + fast_flandom() * 1000 * cdown - fast_flandom () * 1000 * cdown;
y = hpoint (x, z); rockscaling *= 0.5;
cdown--; if (cdown>0) goto rockrep;
rockscaling = rs;
resetfx ();
}
/*
-----------------------------------------------------------------
Collezione di funzioni per il tracciamento e l'animazione delle
forme di vita indigene dei pianeti abitabili.
-----------------------------------------------------------------
*/
#define LFS 100 // massimo numero di animali.
int animals = 0; // animali attualmente visibili.
char ani_type [LFS]; // tipologia
long ani_seed [LFS]; // seme pseudo per le modifiche alla forma.
float ani_scale[LFS]; // scala.
float ani_x [LFS]; // posizione (X)
float ani_quote[LFS]; // quota rispetto al suolo.
float ani_z [LFS]; // posizione (Z)
float ani_pitch[LFS]; // direzione in cui si spostano.
float ani_speed[LFS]; // velocit… attuale.
float tgt_quote[LFS]; // quota che vogliono raggiungere.
float tgt_speed[LFS]; // velocit… che vogliono raggiungere.
float tgt_pitch[LFS]; // direzione che vogliono acquisire.
char ani_lcount[LFS]; // contatempo di vicinanza.
unsigned ani_sqc[LFS]; // sub-quadrant coordinates (attuali).
char ani_mtype[LFS]; // tipo di movimento.
#define FELINE_LIKE 0
#define RABBIT_LIKE 1
#define KANGAROO_LIKE 2
#define BIRD 1 // definizione tipologia (per classi).
#define REPTIL 4
#define MAMMAL 5
// dati di definizione - classe uccelli - relativo PVfile: "birdy_ncc"
const int bird_wings_center_p = 1;
const int bird_wings_center_v = 0;
pvlist bird_wing1[3] = { { 0, 1,1,1,0 }, { 1, 1,1,1,0 }, {0xFFF,0,0,0,0} };
pvlist bird_wing2[3] = { { 2, 1,1,1,0 }, { 3, 1,1,1,0 }, {0xFFF,0,0,0,0} };
const int bird_legs_center_p = 18;
const int bird_legs_center_v = 1;
pvlist bird_legs[3] = { { 18, 0,0,1,0 }, { 19, 0,1,0,0 }, {0xFFF,0,0,0,0} };
// dati di definizione - classe mammiferi - relativo PVfile: "mammal_ncc"
pvlist mamm_ears[5] = {
{ 42, 0,1,0,0 },
{ 45, 0,0,1,0 },
{ 43, 1,0,0,0 },
{ 44, 0,0,1,0 },
{0xFFF,0,0,0,0}
};
const int mamm_wrap_center_p = 16;
const int mamm_wrap_center_v = 2;
pvlist mamm_reartoto[19] = {
{ 7, 0,0,1,1 },
{ 8, 1,1,1,1 },
{ 9, 1,1,1,1 },
{ 14, 1,1,1,1 },
{ 18, 0,1,1,0 },
{ 12, 1,1,1,1 },
{ 19, 1,0,0,1 },
{ 21, 0,0,1,1 },
{ 10, 1,1,1,1 },
{ 15, 1,1,1,1 },
{ 13, 1,1,1,1 },
{ 11, 1,1,1,1 },
{ 46, 1,1,1,1 },
{ 47, 1,1,1,1 },
{ 50, 1,1,1,1 },
{ 51, 1,1,1,1 },
{ 48, 1,1,1,0 },
{ 49, 1,1,1,0 },
{0xFFF,0,0,0,0}
};
pvlist mamm_legs[15] = {
{ 0, 1,1,1,1 }, // F-L
{ 2, 1,1,0,0 },
{ 22, 1,0,0,0 },
{ 1, 1,1,1,1 }, // F-R
{ 3, 1,1,0,0 },
{ 23, 0,1,0,0 },
{ 8, 0,0,1,1 }, // R-L
{ 10, 1,1,1,1 },
{ 14, 0,1,1,0 },
{ 15, 1,1,1,1 },
{ 12, 0,0,1,1 }, // R-R
{ 13, 1,1,1,1 },
{ 9, 0,0,1,1 },
{ 11, 1,1,1,1 },
{0xFFF,0,0,0,0}
};
const int mamm_tail_center_p = 46;
const int mamm_tail_center_v = 1;
pvlist mamm_tail[7] = {
{ 46, 1,1,1,1 },
{ 47, 1,1,1,1 },
{ 50, 1,1,1,1 },
{ 51, 1,1,1,1 },
{ 48, 1,1,1,0 },
{ 49, 1,1,1,0 },
{0xFFF,0,0,0,0}
};
/* Funzione di tracciamento ed animazione delle forme di vita animali. */
void live_animal (int n)
{
const double an_incl_prec = 50;
double incl;
float period;
int sqc_x, sqc_z;
long tick = 18 * secs;
float dx, dy, dz, ax, ay, ay2, az;
float update_ratio, tendence_to_stop; // mammals
char perform_depth_sort = 0;
char texture_skin_map = 0;
float animal_distance = 0;
float quote = tgt_quote[n];
float pitch = tgt_pitch[n];
float velocity = tgt_speed[n];
float reaction = 0.5 / ani_scale[n];
ax = ani_x[n]; az = ani_z[n];
ay = hpoint (ani_x[n], ani_z[n]) - ani_quote[n];
if (ani_lcount[n] < 0) {
dx = 1 / (float)(-ani_lcount[n]);
ani_x[n] += dx * (refx - ax);
ani_z[n] += dx * (refz - az);
ani_quote[n] -= dx * ani_quote[n];
if (ani_lcount[n] > -10) {
stick3d (ax, ay, az, pos_x, pos_y - 50, pos_z);
stick3d (ax, ay, az, pos_x - 50, pos_y - 50, pos_z);
stick3d (ax, ay, az, pos_x + 50, pos_y - 50, pos_z);
stick3d (ax, ay, az, pos_x, pos_y - 50, pos_z + 50);
stick3d (ax, ay, az, pos_x, pos_y - 50, pos_z - 50);
}
if (ani_lcount[n] < -1) {
step += 2 * ani_lcount[n];
ani_lcount[n]++;
}
goto inactive;
}
/* Comportamento in distanza. */
if (ani_type[n] == BIRD) {
if (quote >= 1500) {
velocity = 800;
fast_srand (n + (tick / 50));
pitch += 5 * fast_flandom() - 2.5;
quote += 1000 * fast_flandom() - 500;
goto end_far;
}
if (quote > 750) {
velocity = 400;
quote *= 0.5;
fast_srand (n + (tick / 15));
pitch += 10 * fast_flandom() - 5;
goto end_far;
}
if (quote > 250) {
velocity = 0;
quote = 0;
goto end_far;
}
fast_srand (n + (tick / 10));
if (quote < 50)
velocity = 0;
else {
velocity = 100 * fast_flandom();
pitch += 10 * fast_flandom() - 5;
}
if (fast_random(7) == 3)
quote = 1500 + 1000 * fast_flandom();
else
quote += 500 * fast_flandom() - 250;
}
if (ani_type[n] == MAMMAL) {
//stick3d (ax, ay, az, ax, ay - 50000, az);
fast_srand (n);
update_ratio = fast_random (31) + 3;
tendence_to_stop = fast_flandom () * 0.8;
fast_srand (n + tick / update_ratio);
if (fast_flandom() < tendence_to_stop) {
velocity = 0;
fast_srand (n + tick);
if (fast_flandom() < 0.1 * tendence_to_stop) {
pitch += 100 * fast_flandom();
pitch -= 100 * fast_flandom();
}
}
else {
fast_srand (n + tick / 18);
if (ani_mtype[n] == FELINE_LIKE) velocity = 350 + fast_flandom() * 350;
if (ani_mtype[n] == RABBIT_LIKE) velocity = 200 + fast_flandom() * 200;
if (ani_mtype[n] == KANGAROO_LIKE) velocity = 400 + fast_flandom() * 100;
fast_srand (n + (tick / 5));
dx = 300 * fast_flandom() - 5;
pitch += dx / velocity;
}
quote = 0;
}
end_far:
if (quote < 0) quote = 0;
tgt_speed[n] = velocity;
tgt_quote[n] = quote;
tgt_pitch[n] = pitch;
dx = velocity - ani_speed[n];
dy = quote - ani_quote[n];
dz = pitch - ani_pitch[n];
ani_speed[n] += 3 * reaction * dx;
ani_pitch[n] += 2 * reaction * dz;
ani_quote[n] += 1 * reaction * dy;
ani_x[n] -= ani_speed[n] * sin (deg * ani_pitch[n]);
ani_z[n] -= ani_speed[n] * cos (deg * ani_pitch[n]);
if (ani_x[n] < 0 || ani_x[n] > 3276800 || ani_z[n] < 0 || ani_z[n] > 3276800) {
ani_x[n] += ani_speed[n] * sin (deg * ani_pitch[n]);
ani_z[n] += ani_speed[n] * sin (deg * ani_pitch[n]);
ani_pitch[n] += 180;
}
inactive:
dx = ax - cam_x;
dy = ay - cam_y;
dz = az - cam_z;
animal_distance = sqrt (dx*dx + dy*dy + dz*dz);
if (animal_distance > 250000) {
ani_x[n] = pos_x + 100000 * fast_flandom() - 100000 * fast_flandom();
ani_z[n] = pos_z + 100000 * fast_flandom() - 100000 * fast_flandom();
if (ani_type[n] == BIRD)
ani_quote[n] = 25000 * fast_flandom();
else
ani_quote[n] = 0;
tgt_quote[n] = ani_quote[n];
}
sqc_x = ani_x[n] / 16384;
sqc_z = ani_z[n] / 16384;
if (sqc_x < 0) sqc_x = 0;
if (sqc_x > 199) sqc_x = 199;
if (sqc_z < 0) sqc_z = 0;
if (sqc_z > 199) sqc_z = 199;
ani_sqc[n] = m200[sqc_z] + sqc_x;
if (animal_distance > 150000) return;
if (animal_distance < 75000) perform_depth_sort = 1;
if (animal_distance < 12500) texture_skin_map = 1 + (n % 2);
/* Comportamento in vicinanza e tracciamento. */
// impostazione texture per forme di vita.
flares = 0;
txtr = p_background;
XSIZE = TEXTURE_XSIZE * 256;
YSIZE = TEXTURE_YSIZE * T_SCALE;
if (ani_type[n] == BIRD) {
// preparazione forma di base:
copypv (bird_result, bird_base);
modpv (bird_result, -1, -1, ani_scale[n], ani_scale[n], ani_scale[n], 0, 0, 0, NULL);
// modifiche alla forma di base:
if (ani_lcount[n] < 0) {
// bŠ, questo non Š pi— vivo:
// Š stato catturato e giace legato
// ad alcune cordicelle, mentre viene
// trascinato dietro al player...
dz = 180 / (float)ani_lcount[n];
goto bird_trace;
}
if (ani_quote[n] < 500) {
// si inclina all'indietro, prima di
// atterrare o decollare. Š normale.
dz = -0.1 * fabs (250 - ani_quote[n]);
}
else
dz = 0;
if (ay < 0 || sctype != OCEAN) {
if (ani_quote[n] < 50) {
// modello di comportamento:
// quando Š a terra. ali chiuse o semiaperte.
// non succede quando al posto della terraferma
// c'Š l'acqua...
dy = 1 - (ani_quote[n] * reaction); if (dy < 0) dy = 0;
modpv (bird_result, bird_wings_center_p, bird_wings_center_v, 1, 1, 1, 0, +45*dy, +75*dy, bird_wing1);
modpv (bird_result, bird_wings_center_p, bird_wings_center_v, 1, 1, 1, 0, -45*dy, -75*dy, bird_wing2);
goto bird_trace;
}
}
modpv (bird_result, bird_legs_center_p, bird_legs_center_v, 1, 1, 1, -75, 0, 0, bird_legs);
if (ani_scale[n] > 10) {
// modello di comportamento:
// in volo, grandi uccelli.
modpv (bird_result, bird_wings_center_p, bird_wings_center_v, 1, 1, 1,
0, 0, fabs(10 - (tick % 20)) * -4.5, bird_wing1);
modpv (bird_result, bird_wings_center_p, bird_wings_center_v, 1, 1, 1,
0, 0, fabs(10 - (tick % 20)) * +4.5, bird_wing2);
}
else {
// modello di comportamento:
// in volo, piccoli uccelli.
modpv (bird_result, bird_wings_center_p, bird_wings_center_v, 1, 1, 1,
0, 0, fabs(3 - (tick % 6)) * -15, bird_wing1);
modpv (bird_result, bird_wings_center_p, bird_wings_center_v, 1, 1, 1,
0, 0, fabs(3 - (tick % 6)) * +15, bird_wing2);
}
// visualizzazione:
bird_trace:
modpv (bird_result, bird_wings_center_p, bird_wings_center_v, 1, 1, 1,
dz, 0, 0, 0);
modpv (bird_result, bird_wings_center_p, bird_wings_center_v, 1, 1, 1,
0, ani_pitch[n], 0, 0);
drawpv (bird_result, texture_skin_map, 3, ax, ay
- 9 * ani_scale[n], az, perform_depth_sort);
// reazioni alla vicinanza.
// bŠ, gli uccelli tendono a scappare,
// a meno che non ci si avvicini ad essi
// con molta cautela. tuttavia, si possono
// catturare: concettualmente, Š semplice,
// dato che basta tender loro un agguato,
// e saltargli addosso da molto vicino.
// praticamente Š piuttosto difficile...
if (ani_lcount[n] >= 0) {
if (animal_distance < 5000 && step > 250)
tgt_quote[n] += 2500;
if (animal_distance < 3000 && step > 100)
tgt_quote[n] += 2000;
if (animal_distance < 1000) {
tgt_speed[n] = 500 * reaction;
tgt_quote[n] = 250 * reaction;
if (animal_distance < 500)
ani_lcount[n] = -25;
}
}
}
if (ani_type[n] == MAMMAL) {
// preparazione forma di base:
copypv (mamm_result, mamm_base);
modpv (mamm_result, -1, -1, ani_scale[n], ani_scale[n], ani_scale[n], 0, 0, 0, NULL);
if (ay > -10 && sctype == OCEAN) {
// nell'acqua...
// se alcuni ci si avventurano, bŠ,
// possono sempre nuotare...
modpv (mamm_result, -1, -1, 1, 0.7, 1, 0, 0, 0, NULL);
modpv (mamm_result, -1, -1, 1, 0.0, 1, 0, 0, 0, mamm_legs);
period = fabs (fsecs - 0.5);
modpv (mamm_result, -1, -1, 1, 1, 1, 15, 0, 50 * period, NULL);
}
else {
// Sulla terraferma...
if (ani_mtype[n] != FELINE_LIKE) {
modpv (mamm_result, -1, -1, 2, 2, 0.75, 0, 0, 0, mamm_reartoto);
modpv (mamm_result, -1, -1, 1, 1, 1, 60, 0, 0, NULL);
modpv (mamm_result, mamm_tail_center_p, mamm_tail_center_v, 1, 1, 1, -100, 0, 0, mamm_tail);
if (ani_mtype[n] != KANGAROO_LIKE)
modpv (mamm_result, -1, -1, 0.33, 0.33, 0.33, 0, 0, 0, NULL);
}
ay2 = hpoint (ax - an_incl_prec * sin (deg * ani_pitch[n]),
az - an_incl_prec * cos (deg * ani_pitch[n]))
- ani_quote[n];
incl = ay - ay2;
incl /= an_incl_prec;
if (incl < -1) incl = -1;
if (incl > +1) incl = +1;
incl = ((double)180 * atan(incl)) / M_PI;
modpv (mamm_result, mamm_wrap_center_p,
mamm_wrap_center_v, 1, 1, 1, incl, 0, 0, NULL);
if (ani_mtype[n] == FELINE_LIKE) ay -= ani_scale[n] * 16;
if (ani_mtype[n] == RABBIT_LIKE) ay -= ani_scale[n] * 48;
if (ani_mtype[n] == KANGAROO_LIKE) ay -= ani_scale[n] * 115;
if (ani_speed[n] < 50) {
// se sono fermi possono comunque
// scondinzolare, mentre pensano
// a cosa fare...
fast_srand (4*n);
if (fast_random(1)) {
period = fabs (fsecs - 0.5);
modpv (mamm_result, mamm_tail_center_p, mamm_tail_center_v,
1, 1, 1, 0, 240 * period - 60, 0, mamm_tail);
}
}
else {
// se corrono, si fa semplicemente
// un'animazione del tronco per dare
// l'idea che stiano appunto correndo.
if (ani_mtype[n] == FELINE_LIKE)
period = 45;
if (ani_mtype[n] == RABBIT_LIKE)
period = 60;
if (ani_mtype[n] == KANGAROO_LIKE)
period = 22;
period *= fabs (fsecs - 0.5);
period /= ani_scale[n];
if (ani_mtype[n] == FELINE_LIKE)
ay -= 35 * ani_scale[n] * period;
if (ani_mtype[n] == RABBIT_LIKE)
ay -= 50 * ani_scale[n] * period;
if (ani_mtype[n] == KANGAROO_LIKE)
ay -= 300 * ani_scale[n] * period;
modpv (mamm_result, mamm_wrap_center_p, mamm_wrap_center_v,
1, 1, 1, - 50 * period, 0, 0, NULL);
modpv (mamm_result, mamm_wrap_center_p, mamm_wrap_center_v,
1, 1, 1, 100 * period, 0, 0, mamm_reartoto);
}
}
modpv (mamm_result, mamm_wrap_center_p, mamm_wrap_center_v,
1, 1, 1, 0, ani_pitch[n] + 180, 0, NULL);
// visualizzazione:
mamm_trace:
drawpv (mamm_result, 1, 0, ax, ay, az, perform_depth_sort);
}
end_vicinity:
}
/*
-----------------------------------------------------------------
Collezione di funzioni interdipendenti per il tracciamento delle
superfici di base che compongono l'orografia dei territori.
Queste funzioni coordinano quelle che si occupano del
tracciamento degli oggetti in superficie.
-----------------------------------------------------------------
*/
#define bk_lines_to_horizon 120
#define culling_limit 50
void srf_detail (float x, float y, float z, long depth, char _class_)
{ // disegna un oggetto sulla superficie di un pianeta.
switch (_class_) {
case ROCKS: // rocce, sassi, massi, pietre, pietruzze etc...
roccia (x, y, z, depth);
break;