]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/effects/qc/lightningarc.qc
Merge branch 'master' into matthiaskrgr/nadecountdown_nopicmip
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / effects / qc / lightningarc.qc
1 #include "lightningarc.qh"
2
3 REGISTER_NET_TEMP(TE_CSQC_ARC)
4
5 #if defined(SVQC)
6
7         void te_csqc_lightningarc(vector from, vector to)
8         {
9                 WriteHeader(MSG_BROADCAST, TE_CSQC_ARC);
10
11                 WriteCoord(MSG_BROADCAST, from.x);
12                 WriteCoord(MSG_BROADCAST, from.y);
13                 WriteCoord(MSG_BROADCAST, from.z);
14                 WriteCoord(MSG_BROADCAST, to.x);
15                 WriteCoord(MSG_BROADCAST, to.y);
16                 WriteCoord(MSG_BROADCAST, to.z);
17         }
18
19 #elif defined(CSQC)
20
21 /*
22 .vector fx_start;
23 .vector fx_end;
24 .float  fx_with;
25 .string fx_texture;
26 .float  fx_lifetime;
27
28 void b_draw()
29 {
30     //Draw_CylindricLine(this.fx_start, this.fx_end, this.fx_with, this.fx_texture, 0, time * 3, '1 1 1', 0.7, DRAWFLAG_ADDITIVE, view_origin);
31     Draw_CylindricLine(this.fx_start, this.fx_end, this.fx_with, this.fx_texture, (this.fx_with/256), 0, '1 1 1', 1, DRAWFLAG_ADDITIVE, view_origin);
32
33 }
34 void b_make(vector s,vector e, string t,float l,float z)
35 {
36     entity b;
37     b = spawn();
38     b.fx_texture = t;
39     b.fx_start = s;
40     b.fx_end = e;
41     b.fx_with = z;
42     b.think = SUB_Remove;
43     b.nextthink = time + l;
44     b.draw = b_draw;
45
46     //b.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP;
47 }
48 */
49
50         void cl_effects_lightningarc(vector from, vector to, float seglength, float drifts, float drifte,
51         float branchfactor, float branchfactor_add)
52         {
53                 float length = vlen(from - to);
54                 if (length < 1) return;
55
56                 // Use at most 16 te_lightning1 segments, as these eat up beam list segments.
57                 // TODO: Change this to R_BeginPolygon code, then we no longer have this limit.
58                 int steps = min(16, floor(length / seglength));
59                 if (steps < 1)
60                 {
61                         te_lightning1(NULL, from, to);
62                         return;
63                 }
64
65                 float steplength = length / steps;
66                 vector direction  = normalize(to - from);
67                 vector pos_l = from;
68                 if (length > seglength)
69                 {
70                         for (int i = 1; i < steps; i += 1)
71                         {
72                                 float drift = drifts * (1 - (i / steps)) + drifte * (i / steps);
73                                 vector dirnew = normalize(direction * (1 - drift) + randomvec() * drift);
74                                 vector pos = pos_l +  dirnew * steplength;
75                                 te_lightning1(NULL, pos_l, pos);
76                                 // WTF endless recursion if branchfactor is 1.0 (possibly due to adding branchfactor_add). FIXME
77                                 // if(random() < branchfactor)
78                                 //     cl_effects_lightningarc(pos, pos + (dirnew * length * 0.25),seglength,drifts,drifte,min(branchfactor + branchfactor_add,1),branchfactor_add);
79
80                                 pos_l = pos;
81                         }
82                         te_lightning1(NULL, pos_l, to);
83                 }
84                 else
85                 {
86                         te_lightning1(NULL, from, to);
87                 }
88         }
89
90         NET_HANDLE(TE_CSQC_ARC, bool isNew)
91         {
92                 vector from;
93                 from.x = ReadCoord();
94                 from.y = ReadCoord();
95                 from.z = ReadCoord();
96                 vector to;
97                 to.x = ReadCoord();
98                 to.y = ReadCoord();
99                 to.z = ReadCoord();
100                 return = true;
101
102                 if (autocvar_cl_effects_lightningarc_simple)
103                 {
104                         te_lightning1(NULL, from, to);
105                 }
106                 else
107                 {
108                         float seglength        = autocvar_cl_effects_lightningarc_segmentlength;
109                         float drifts           = autocvar_cl_effects_lightningarc_drift_start;
110                         float drifte           = autocvar_cl_effects_lightningarc_drift_end;
111                         float branchfactor     = autocvar_cl_effects_lightningarc_branchfactor_start;
112                         float branchfactor_add = autocvar_cl_effects_lightningarc_branchfactor_add;
113
114                         cl_effects_lightningarc(from, to, seglength, drifts, drifte, branchfactor, branchfactor_add);
115                 }
116         }
117
118 #endif