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