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