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