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