]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/particles.qc
More cleanup and comments
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / particles.qc
1 .float dphitcontentsmask;
2
3 .float cnt; // effect number
4 .vector velocity; // particle velocity
5 .float waterlevel; // direction jitter
6 .float count; // count multiplier
7 .float impulse; // density
8 .string noise; // sound
9 .float atten;
10 .float volume;
11 .float absolute; // 1 = count per second is absolute, 2 = only spawn at toggle
12 .vector movedir; // trace direction
13
14 void Draw_PointParticles()
15 {
16         float n, i, fail;
17         vector p;
18         vector sz;
19         vector o;
20         o = self.origin;
21         sz = self.maxs - self.mins;
22         n = BGMScript(self);
23         if(self.absolute == 2)
24         {
25                 if(n >= 0)
26                         n = self.just_toggled ? self.impulse : 0;
27                 else
28                         n = self.impulse * drawframetime;
29         }
30         else
31         {
32                 n *= self.impulse * drawframetime;
33                 if(self.just_toggled)
34                         if(n < 1)
35                                 n = 1;
36         }
37         if(n == 0)
38                 return;
39         fail = 0;
40         for(i = random(); i <= n && fail <= 64*n; ++i)
41         {
42                 p = o + self.mins;
43                 p_x += random() * sz_x;
44                 p_y += random() * sz_y;
45                 p_z += random() * sz_z;
46                 if(WarpZoneLib_BoxTouchesBrush(p, p, self, world))
47                 {
48                         if(self.movedir != '0 0 0')
49                         {
50                                 traceline(p, p + normalize(self.movedir) * 4096, 0, world);
51                                 p = trace_endpos;
52                                 pointparticles(self.cnt, p, trace_plane_normal * vlen(self.movedir) + self.velocity + randomvec() * self.waterlevel, self.count);
53                         }
54                         else
55                         {
56                                 pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count);
57                         }
58                         if(self.noise != "")
59                         {
60                                 setorigin(self, p);
61                                 sound(self, CH_AMBIENT, self.noise, VOL_BASE * self.volume, self.atten);
62                         }
63                         self.just_toggled = 0;
64                 }
65                 else if(self.absolute)
66                 {
67                         ++fail;
68                         --i;
69                 }
70         }
71         setorigin(self, o);
72 }
73
74 void Ent_PointParticles_Remove()
75 {
76         if(self.noise)
77                 strunzone(self.noise);
78         self.noise = string_null;
79         if(self.bgmscript)
80                 strunzone(self.bgmscript);
81         self.bgmscript = string_null;
82 }
83
84 void Ent_PointParticles()
85 {
86         float f, i;
87         vector v;
88         f = ReadByte();
89         if(f & 2)
90         {
91                 i = ReadCoord(); // density (<0: point, >0: volume)
92                 if(i && !self.impulse && self.cnt) // self.cnt check is so it only happens if the ent already existed
93                         self.just_toggled = 1;
94                 self.impulse = i;
95         }
96         if(f & 4)
97         {
98                 self.origin_x = ReadCoord();
99                 self.origin_y = ReadCoord();
100                 self.origin_z = ReadCoord();
101         }
102         if(f & 1)
103         {
104                 self.modelindex = ReadShort();
105                 if(f & 0x80)
106                 {
107                         if(self.modelindex)
108                         {
109                                 self.mins_x = ReadCoord();
110                                 self.mins_y = ReadCoord();
111                                 self.mins_z = ReadCoord();
112                                 self.maxs_x = ReadCoord();
113                                 self.maxs_y = ReadCoord();
114                                 self.maxs_z = ReadCoord();
115                         }
116                         else
117                         {
118                                 self.mins    = '0 0 0';
119                                 self.maxs_x = ReadCoord();
120                                 self.maxs_y = ReadCoord();
121                                 self.maxs_z = ReadCoord();
122                         }
123                 }
124                 else
125                 {
126                         self.mins = self.maxs = '0 0 0';
127                 }
128
129                 self.cnt = ReadShort(); // effect number
130
131                 if(f & 0x20)
132                 {
133                         self.velocity = decompressShortVector(ReadShort());
134                         self.movedir = decompressShortVector(ReadShort());
135                 }
136                 else
137                 {
138                         self.velocity = self.movedir = '0 0 0';
139                 }
140                 if(f & 0x40)
141                 {
142                         self.waterlevel = ReadShort() / 16.0;
143                         self.count = ReadByte() / 16.0;
144                 }
145                 else
146                 {
147                         self.waterlevel = 0;
148                         self.count = 1;
149                 }
150                 if(self.noise)
151                         strunzone(self.noise);
152                 if(self.bgmscript)
153                         strunzone(self.bgmscript);
154                 self.noise = strzone(ReadString());
155                 if(self.noise != "")
156                 {
157                         self.atten = ReadByte() / 64.0;
158                         self.volume = ReadByte() / 255.0;
159                 }
160                 self.bgmscript = strzone(ReadString());
161                 if(self.bgmscript != "")
162                 {
163                         self.bgmscriptattack = ReadByte() / 64.0;
164                         self.bgmscriptdecay = ReadByte() / 64.0;
165                         self.bgmscriptsustain = ReadByte() / 255.0;
166                         self.bgmscriptrelease = ReadByte() / 64.0;
167                 }
168                 BGMScript_InitEntity(self);
169         }
170
171         if(f & 2)
172         {
173                 self.absolute = (self.impulse >= 0);
174                 if(!self.absolute)
175                 {
176                         v = self.maxs - self.mins;
177                         self.impulse *= -v_x * v_y * v_z / 262144; // relative: particles per 64^3 cube
178                 }
179         }
180
181         if(f & 0x10)
182                 self.absolute = 2;
183
184         setorigin(self, self.origin);
185         setsize(self, self.mins, self.maxs);
186         self.solid = SOLID_NOT;
187         self.draw = Draw_PointParticles;
188         self.entremove = Ent_PointParticles_Remove;
189 }
190
191 .float glow_color; // palette index
192 void Draw_Rain()
193 {
194     te_particlerain(self.origin + self.mins, self.origin + self.maxs, self.velocity, floor(self.count * drawframetime + random()), self.glow_color);
195 }
196
197 void Draw_Snow()
198 {
199     te_particlesnow(self.origin + self.mins, self.origin + self.maxs, self.velocity, floor(self.count * drawframetime + random()), self.glow_color);
200 }
201
202 void Ent_RainOrSnow()
203 {
204         self.impulse = ReadByte(); // Rain, Snow, or Whatever
205         self.origin_x = ReadCoord();
206         self.origin_y = ReadCoord();
207         self.origin_z = ReadCoord();
208         self.maxs_x = ReadCoord();
209         self.maxs_y = ReadCoord();
210         self.maxs_z = ReadCoord();
211         self.velocity = decompressShortVector(ReadShort());
212         self.count = ReadShort() * 10;
213         self.glow_color = ReadByte(); // color
214
215         self.mins    = -0.5 * self.maxs;
216         self.maxs    =  0.5 * self.maxs;
217         self.origin  = self.origin - self.mins;
218
219         setorigin(self, self.origin);
220         setsize(self, self.mins, self.maxs);
221         self.solid = SOLID_NOT;
222         if(self.impulse)
223                 self.draw = Draw_Rain;
224         else
225                 self.draw = Draw_Snow;
226 }
227
228 void Net_ReadVortexBeamParticle()
229 {
230         vector shotorg, endpos;
231         float charge;
232         shotorg_x = ReadCoord(); shotorg_y = ReadCoord(); shotorg_z = ReadCoord();
233         endpos_x = ReadCoord(); endpos_y = ReadCoord(); endpos_z = ReadCoord();
234         charge = ReadByte() / 255.0;
235
236         pointparticles(particleeffectnum("nex_muzzleflash"), shotorg, normalize(endpos - shotorg) * 1000, 1);
237
238         //draw either the old v2.3 beam or the new beam
239         charge = sqrt(charge); // divide evenly among trail spacing and alpha
240         particles_alphamin = particles_alphamax = particles_fade = charge;
241
242         if (autocvar_cl_particles_oldnexbeam && (getstati(STAT_ALLOW_OLDNEXBEAM) || isdemo()))
243                 WarpZone_TrailParticles_WithMultiplier(world, particleeffectnum("TE_TEI_G3"), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
244         else
245                 WarpZone_TrailParticles_WithMultiplier(world, particleeffectnum("nex_beam"), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
246 }
247
248 .vector sw_shotorg;
249 .vector sw_endpos;
250 .float sw_spread_max;
251 .float sw_spread_min;
252 .float sw_time;
253
254 void Draw_Shockwave()
255 {
256         float a = bound(0, (0.5 - ((time - self.sw_time) / 0.4)), 0.5);
257
258         if(!a) { remove(self); }
259         
260         vector deviation, angle;
261
262         vector sw_color = getcsqcplayercolor(self.sv_entnum); // GetTeamRGB(GetPlayerColor(self.sv_entnum));
263
264         vector first_min_end = '0 0 0', prev_min_end = '0 0 0', new_min_end = '0 0 0';
265         vector first_max_end = '0 0 0', prev_max_end = '0 0 0', new_max_end = '0 0 0';
266
267         float new_max_dist, new_min_dist;
268         
269         vector shotdir = normalize(self.sw_endpos - self.sw_shotorg);
270         vectorvectors(shotdir);
271         vector right = v_right;
272         vector up = v_up;
273         
274         float counter, dist_before_normal = 200, shots = 20;
275         
276         vector min_end = ((self.sw_shotorg + (shotdir * dist_before_normal)) + (up * self.sw_spread_min));
277         vector max_end = (self.sw_endpos + (up * self.sw_spread_max));
278         
279         float spread_to_min = vlen(normalize(min_end - self.sw_shotorg) - shotdir);
280         float spread_to_max = vlen(normalize(max_end - min_end) - shotdir);
281         
282         for(counter = 0; counter < shots; ++counter)
283         {
284                 // perfect circle effect lines
285                 angle = '0 0 0';
286                 makevectors('0 360 0' * (0.75 + (counter - 0.5) / shots));
287                 angle_y = v_forward_x;
288                 angle_z = v_forward_y;
289
290                 // first do the spread_to_min effect
291                 deviation = angle * spread_to_min;
292                 deviation = ((shotdir + (right * deviation_y) + (up * deviation_z)));
293                 new_min_dist = dist_before_normal;
294                 new_min_end = (self.sw_shotorg + (deviation * new_min_dist));
295                 //te_lightning2(world, new_min_end, self.sw_shotorg);
296
297                 // then calculate spread_to_max effect
298                 deviation = angle * spread_to_max;
299                 deviation = ((shotdir + (right * deviation_y) + (up * deviation_z)));
300                 new_max_dist = vlen(new_min_end - self.sw_endpos);
301                 new_max_end = (new_min_end + (deviation * new_max_dist));
302                 //te_lightning2(world, new_end, prev_min_end);
303                 
304
305                 if(counter == 0)
306                 {
307                         first_min_end = new_min_end;
308                         first_max_end = new_max_end;
309                 }
310
311                 if(counter >= 1)
312                 {
313                         R_BeginPolygon("", DRAWFLAG_NORMAL);
314                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
315                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
316                         R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
317                         R_EndPolygon();
318
319                         R_BeginPolygon("", DRAWFLAG_NORMAL);
320                         R_PolygonVertex(new_min_end, '0 0 0', sw_color, a);
321                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
322                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
323                         R_PolygonVertex(new_max_end, '0 0 0', sw_color, a);
324                         R_EndPolygon();
325                 }
326
327                 prev_min_end = new_min_end;
328                 prev_max_end = new_max_end;
329
330                 if((counter + 1) == shots)
331                 {
332                         R_BeginPolygon("", DRAWFLAG_NORMAL);
333                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
334                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
335                         R_PolygonVertex(self.sw_shotorg, '0 0 0', sw_color, a);
336                         R_EndPolygon();
337
338                         R_BeginPolygon("", DRAWFLAG_NORMAL);
339                         R_PolygonVertex(first_min_end, '0 0 0', sw_color, a);
340                         R_PolygonVertex(prev_min_end, '0 0 0', sw_color, a);
341                         R_PolygonVertex(prev_max_end, '0 0 0', sw_color, a);
342                         R_PolygonVertex(first_max_end, '0 0 0', sw_color, a);
343                         R_EndPolygon();
344                 }
345         }
346 }
347
348 void Net_ReadShockwaveParticle()
349 {
350         entity shockwave;
351         shockwave = spawn();
352         shockwave.draw = Draw_Shockwave;
353         
354         shockwave.sw_shotorg_x = ReadCoord(); shockwave.sw_shotorg_y = ReadCoord(); shockwave.sw_shotorg_z = ReadCoord();
355         shockwave.sw_endpos_x  = ReadCoord(); shockwave.sw_endpos_y  = ReadCoord(); shockwave.sw_endpos_z  = ReadCoord();
356         
357         shockwave.sw_spread_max = ReadByte();
358         shockwave.sw_spread_min = ReadByte();
359
360         shockwave.sv_entnum = ReadByte();
361
362         shockwave.sw_time = time;
363 }
364
365 .vector beam_color;
366 .float beam_alpha;
367 .float beam_thickness;
368 .float beam_traileffect;
369 .float beam_hiteffect;
370 .float beam_muzzleflash;
371 .string beam_image;
372
373 .entity beam_muzzleentity;
374
375 .float beam_usevieworigin;
376 .float beam_initialized;
377 .float beam_maxangle;
378 .float beam_range;
379 .float beam_returnspeed;
380 .float beam_tightness;
381 .vector beam_shotorigin;
382 .vector beam_dir;
383 void Draw_ArcBeam()
384 {
385         InterpolateOrigin_Do();
386
387         // origin = beam starting origin
388         // v_angle = wanted/aim direction
389         // angles = current direction of beam
390
391         vector start_pos;
392         vector wantdir; //= view_forward;
393         vector beamdir; //= self.beam_dir;
394
395         float segments;
396         if(self.beam_usevieworigin)
397         {
398                 // WEAPONTODO:
399                 // Currently we have to replicate nearly the same method of figuring
400                 // out the shotdir that the server does... Ideally in the future we
401                 // should be able to acquire this from a generalized function built
402                 // into a weapon system for client code. 
403
404                 // find where we are aiming
405                 makevectors(view_angles);
406
407                 // decide upon start position
408                 if(self.beam_usevieworigin == 2)
409                         { start_pos = view_origin; }
410                 else
411                         { start_pos = self.origin; }
412
413                 // trace forward with an estimation
414                 WarpZone_TraceLine(start_pos, start_pos + view_forward * self.beam_range, MOVE_NOMONSTERS, self);
415
416                 // untransform in case our trace went through a warpzone
417                 vector vf, vr, vu;
418                 vf = view_forward;
419                 vr = view_right;
420                 vu = view_up;
421                 vector shothitpos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos); // warpzone support
422                 view_forward = vf;
423                 view_right = vr;
424                 view_up = vu;
425
426                 // un-adjust trueaim if shotend is too close
427                 if(vlen(shothitpos - view_origin) < g_trueaim_minrange)
428                         shothitpos = view_origin + (view_forward * g_trueaim_minrange);
429
430                 // move shot origin to the actual gun muzzle origin
431                 vector origin_offset = view_forward * self.beam_shotorigin_x + view_right * -self.beam_shotorigin_y + view_up * self.beam_shotorigin_z;
432                 start_pos = start_pos + origin_offset;
433
434                 // calculate the aim direction now
435                 wantdir = normalize(shothitpos - start_pos);
436
437                 if(!self.beam_initialized)
438                 {
439                         self.beam_dir = wantdir;
440                         self.beam_initialized = TRUE;
441                 }
442
443                 // WEAPONTODO: Calculate segments dyanmically similarly to the server code
444                 segments = 20;
445                 if(self.beam_dir != wantdir)
446                 {
447                         float angle = ceil(vlen(wantdir - self.beam_dir) * RAD2DEG);
448                         float anglelimit;
449                         if(angle && (angle > self.beam_maxangle))
450                         {
451                                 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
452                                 anglelimit = min(self.beam_maxangle / angle, 1);
453                         }
454                         else
455                         {
456                                 // the radius is not too far yet, no worries :D
457                                 anglelimit = 1;
458                         }
459
460                         // calculate how much we're going to move the end of the beam to the want position
461                         float blendfactor = bound(0, anglelimit * (1 - (self.beam_returnspeed * frametime)), 1);
462                         self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
463
464                         // WEAPONTODO (server and client):
465                         // blendfactor never actually becomes 0 in this situation, which is a problem
466                         // regarding precision... this means that self.beam_dir and w_shotdir approach
467                         // eachother, however they never actually become the same value with this method.
468
469                         // Perhaps we should do some form of rounding/snapping?
470
471                         // printf("blendfactor = %f\n", blendfactor);
472
473                         #if 0
474                         // calculate how many segments are needed
475                         float max_allowed_segments;
476
477                         if(WEP_CVAR(arc, beam_distancepersegment))
478                                 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))));
479                         else
480                                 max_allowed_segments = ARC_MAX_SEGMENTS;
481
482                         if(WEP_CVAR(arc, beam_degreespersegment))
483                         {
484                                 segments = min( max(1, ( min(angle, WEP_CVAR(arc, beam_maxangle)) / WEP_CVAR(arc, beam_degreespersegment) ) ), max_allowed_segments );
485                         }
486                         else
487                         {
488                                 segments = 1;
489                         }
490                         #endif
491                 }
492                 #if 0
493                 else
494                 {
495                         segments = 1;
496                 }
497                 #endif
498
499                 // set the beam direction which the rest of the code will refer to
500                 beamdir = self.beam_dir;
501
502                 // finally, set self.angles to the proper direction so that muzzle attachment points in proper direction
503                 self.angles = fixedvectoangles2(view_forward, view_up);
504         }
505         else
506         {
507                 // set the values from the provided info from the networked entity
508                 start_pos = self.origin;
509                 wantdir = self.v_angle;
510                 beamdir = self.angles;
511
512                 // WEAPONTODO: Calculate segments dyanmically similarly to the server code
513                 segments = 20;
514                 #if 0
515                 if(beamdir != wantdir)
516                 {
517                         // calculate how many segments are needed
518                         float max_allowed_segments;
519
520                         if(WEP_CVAR(arc, beam_distancepersegment))
521                                 max_allowed_segments = min(ARC_MAX_SEGMENTS, 1 + (vlen(w_shotdir / WEP_CVAR(arc, beam_distancepersegment))));
522                         else
523                                 max_allowed_segments = ARC_MAX_SEGMENTS;
524
525                         if(WEP_CVAR(arc, beam_degreespersegment))
526                         {
527                                 segments = min( max(1, ( min(angle, WEP_CVAR(arc, beam_maxangle)) / WEP_CVAR(arc, beam_degreespersegment) ) ), max_allowed_segments );
528                         }
529                         else
530                         {
531                                 segments = 1;
532                         }
533                 }
534                 else
535                 {
536                         segments = 1;
537                 }
538                 #endif
539         }
540
541         setorigin(self, start_pos);
542         self.beam_muzzleentity.angles_z = random() * 360; // WEAPONTODO: use avelocity instead?
543
544         vector beam_endpos_estimate = (start_pos + (beamdir * self.beam_range));
545
546         float maxthickness = self.beam_thickness;
547
548         vector thickdir = normalize(cross(beamdir, view_origin - start_pos));
549
550         vector last_origin = start_pos;
551
552         float lastthickness = 0;
553
554         vector last_top = start_pos + (thickdir * lastthickness);
555         vector last_bottom = start_pos - (thickdir * lastthickness);
556
557         vector hitorigin = start_pos;
558
559         float i;
560         for(i = 1; i <= segments; ++i)
561         {
562                 // WEAPONTODO (server and client):
563                 // Segment blend and distance should probably really be calculated in a better way,
564                 // however I am not sure how to do it properly. There are a few things I have tried,
565                 // but most of them do not work properly due to my lack of understanding regarding
566                 // the mathematics behind them.
567
568                 // Ideally, we should calculate the positions along a perfect curve
569                 // between wantdir and self.beam_dir with an option for depth of arc
570
571                 // Another issue is that (on the client code) we must separate the
572                 // curve into multiple rendered curves when handling warpzones.
573                 
574                 // I can handle this by detecting it for each segment, however that
575                 // is a fairly inefficient method in comparison to having a curved line
576                 // drawing function similar to Draw_CylindricLine that accepts
577                 // top and bottom origins as input, this way there would be no
578                 // overlapping edges when connecting the curved pieces.
579
580                 // WEAPONTODO (client):
581                 // In order to do nice fading and pointing on the starting segment, we must always
582                 // have that drawn as a separate triangle... However, that is difficult to do when
583                 // keeping in mind the above problems and also optimizing the amount of segments
584                 // drawn on screen at any given time. (Automatic beam quality scaling, essentially)
585
586                 // calculate this on every segment to ensure that we always reach the full length of the attack
587                 float segmentblend = bound(0, (i/segments) + self.beam_tightness, 1);
588                 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
589
590                 vector new_dir = normalize( (wantdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend) );
591                 vector new_origin = last_origin + (new_dir * segmentdist);
592
593                 WarpZone_TraceLine(
594                         last_origin,
595                         new_origin,
596                         MOVE_NORMAL,
597                         self
598                 );
599
600                 // draw segment
601                 if(trace_fraction != 1)
602                 {
603                         // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
604                         hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
605                 }
606                 else
607                 {
608                         hitorigin = new_origin;
609                 }
610
611                 #if 0
612                 float falloff = ExponentialFalloff(
613                         WEP_CVAR(arc, beam_falloff_mindist),
614                         WEP_CVAR(arc, beam_falloff_maxdist),
615                         WEP_CVAR(arc, beam_falloff_halflifedist),
616                         vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - start_pos)
617                 );
618                 #else
619                 //float falloff = 1;
620                 #endif
621
622                 vector top    = hitorigin + (thickdir * self.beam_thickness);
623                 vector bottom = hitorigin - (thickdir * self.beam_thickness);
624
625                 R_BeginPolygon(self.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
626                 R_PolygonVertex(top,          '0 0.5 0' + ('0 0.5 0' * (self.beam_thickness / maxthickness)),  self.beam_color,  self.beam_alpha);
627                 R_PolygonVertex(last_top,     '0 0.5 0' + ('0 0.5 0' * (lastthickness / maxthickness)),        self.beam_color,  self.beam_alpha);
628                 R_PolygonVertex(last_bottom,  '0 0.5 0' * (1 - (lastthickness / maxthickness)),                self.beam_color,  self.beam_alpha);
629                 R_PolygonVertex(bottom,       '0 0.5 0' * (1 - (self.beam_thickness / maxthickness)),          self.beam_color,  self.beam_alpha);
630                 R_EndPolygon();
631
632                 // check if we're going to proceed with drawing
633                 if(trace_fraction != 1)
634                 {
635                         // we're done with drawing this frame
636                         break;
637                 }
638                 else
639                 {
640                         // continue onto the next segment
641                         last_origin = new_origin;
642                         last_top = top;
643                         last_bottom = bottom;
644                         lastthickness = self.beam_thickness;
645                 }
646         }
647
648         if(self.beam_hiteffect)
649         {
650                 pointparticles(self.beam_hiteffect, hitorigin, beamdir * -1, frametime * 2);
651         }
652         if(self.beam_muzzleflash)
653         {
654                 pointparticles(self.beam_muzzleflash, start_pos + wantdir * 20, wantdir * 1000, frametime * 0.1);
655         }
656 }
657
658 void Remove_ArcBeam(void)
659 {
660         remove(self.beam_muzzleentity);
661         sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
662 }
663
664 void Ent_ReadArcBeam(float isnew)
665 {
666         float sf = ReadByte();
667         entity flash;
668
669         // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
670         self.iflags = IFLAG_ORIGIN;
671
672         InterpolateOrigin_Undo();
673
674         if(isnew)
675         {
676                 // calculate shot origin offset from gun alignment
677                 float gunalign = autocvar_cl_gunalign;
678                 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
679                         gunalign = 3; // default value
680                 --gunalign;
681
682                 self.beam_shotorigin = arc_shotorigin[gunalign];
683
684                 // set other main attributes of the beam
685                 self.draw = Draw_ArcBeam;
686                 self.entremove = Remove_ArcBeam;
687                 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
688
689                 flash = spawn();
690                 flash.owner = self;
691                 flash.effects = EF_ADDITIVE | EF_FULLBRIGHT;
692                 flash.drawmask = MASK_NORMAL;
693                 flash.solid = SOLID_NOT;
694                 setattachment(flash, self, "");
695                 setorigin(flash, '0 0 0');
696
697                 self.beam_muzzleentity = flash;
698         }
699         else
700         {
701                 flash = self.beam_muzzleentity;
702         }
703
704         if(sf & 1) // settings information
705         {
706                 self.beam_maxangle = ReadShort();
707                 self.beam_range = ReadCoord();
708                 self.beam_returnspeed = ReadShort();
709                 self.beam_tightness = (ReadByte() / 10);
710
711                 if(ReadByte())
712                 {
713                         if(autocvar_chase_active)
714                                 { self.beam_usevieworigin = 1; }
715                         else // use view origin
716                                 { self.beam_usevieworigin = 2; }
717                 }
718                 else
719                 {
720                         self.beam_usevieworigin = 0;
721                 }
722         }
723
724         if(sf & 2) // starting location
725         {
726                 self.origin_x = ReadCoord();
727                 self.origin_y = ReadCoord();
728                 self.origin_z = ReadCoord();
729         }
730         else if(self.beam_usevieworigin) // infer the location from player location
731         {
732                 if(self.beam_usevieworigin == 2)
733                 {
734                         // use view origin
735                         self.origin = view_origin;
736                 }
737                 else
738                 {
739                         // use player origin so that third person display still works
740                         self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
741                 }
742         }
743
744         setorigin(self, self.origin);
745
746         if(sf & 4) // want/aim direction
747         {
748                 self.v_angle_x = ReadCoord();
749                 self.v_angle_y = ReadCoord();
750                 self.v_angle_z = ReadCoord();
751         }
752
753         if(sf & 8) // beam direction
754         {
755                 self.angles_x = ReadCoord();
756                 self.angles_y = ReadCoord();
757                 self.angles_z = ReadCoord();
758         }
759
760         if(sf & 16) // beam type
761         {
762                 self.beam_type = ReadByte();
763                 switch(self.beam_type)
764                 {
765                         case ARC_BT_MISS:
766                         {
767                                 self.beam_color = '-1 -1 1';
768                                 self.beam_alpha = 0.5;
769                                 self.beam_thickness = 8;
770                                 self.beam_traileffect = FALSE;
771                                 self.beam_hiteffect = particleeffectnum("electro_lightning");
772                                 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
773                                 self.beam_image = "particles/lgbeam";
774                                 setmodel(flash, "models/flash.md3");
775                                 flash.alpha = self.beam_alpha;
776                                 flash.colormod = self.beam_color;
777                                 flash.scale = 0.5;
778                                 break;
779                         }
780                         case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
781                         {
782                                 self.beam_color = '0.5 0.5 1';
783                                 self.beam_alpha = 0.5;
784                                 self.beam_thickness = 8;
785                                 self.beam_traileffect = FALSE;
786                                 self.beam_hiteffect = particleeffectnum("electro_lightning"); 
787                                 self.beam_muzzleflash = FALSE; // particleeffectnum("grenadelauncher_muzzleflash");
788                                 self.beam_image = "particles/lgbeam";
789                                 setmodel(flash, "models/flash.md3");
790                                 flash.alpha = self.beam_alpha;
791                                 flash.colormod = self.beam_color;
792                                 flash.scale = 0.5;
793                                 break;
794                         }
795                         case ARC_BT_HEAL:
796                         {
797                                 self.beam_color = '0 1 0';
798                                 self.beam_alpha = 0.5;
799                                 self.beam_thickness = 8;
800                                 self.beam_traileffect = FALSE;
801                                 self.beam_hiteffect = particleeffectnum("healray_impact"); 
802                                 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
803                                 self.beam_image = "particles/lgbeam";
804                                 setmodel(flash, "models/flash.md3");
805                                 flash.alpha = self.beam_alpha;
806                                 flash.colormod = self.beam_color;
807                                 flash.scale = 0.5;
808                                 break;
809                         }
810                         case ARC_BT_HIT:
811                         {
812                                 self.beam_color = '1 0 1';
813                                 self.beam_alpha = 0.5;
814                                 self.beam_thickness = 8;
815                                 self.beam_traileffect = FALSE;
816                                 self.beam_hiteffect = particleeffectnum("electro_lightning"); 
817                                 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
818                                 self.beam_image = "particles/lgbeam";
819                                 setmodel(flash, "models/flash.md3");
820                                 flash.alpha = self.beam_alpha;
821                                 flash.colormod = self.beam_color;
822                                 flash.scale = 0.5;
823                                 break;
824                         }
825                         case ARC_BT_BURST_MISS:
826                         {
827                                 self.beam_color = '-1 -1 1';
828                                 self.beam_alpha = 0.5;
829                                 self.beam_thickness = 14;
830                                 self.beam_traileffect = FALSE;
831                                 self.beam_hiteffect = particleeffectnum("electro_lightning"); 
832                                 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
833                                 self.beam_image = "particles/lgbeam";
834                                 setmodel(flash, "models/flash.md3");
835                                 flash.alpha = self.beam_alpha;
836                                 flash.colormod = self.beam_color;
837                                 flash.scale = 0.5;
838                                 break;
839                         }
840                         case ARC_BT_BURST_WALL:
841                         {
842                                 self.beam_color = '0.5 0.5 1';
843                                 self.beam_alpha = 0.5;
844                                 self.beam_thickness = 14;
845                                 self.beam_traileffect = FALSE;
846                                 self.beam_hiteffect = particleeffectnum("electro_lightning"); 
847                                 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
848                                 self.beam_image = "particles/lgbeam";
849                                 setmodel(flash, "models/flash.md3");
850                                 flash.alpha = self.beam_alpha;
851                                 flash.colormod = self.beam_color;
852                                 flash.scale = 0.5;
853                                 break;
854                         }
855                         case ARC_BT_BURST_HEAL:
856                         {
857                                 self.beam_color = '0 1 0';
858                                 self.beam_alpha = 0.5;
859                                 self.beam_thickness = 14;
860                                 self.beam_traileffect = FALSE;
861                                 self.beam_hiteffect = particleeffectnum("electro_lightning"); 
862                                 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
863                                 self.beam_image = "particles/lgbeam";
864                                 setmodel(flash, "models/flash.md3");
865                                 flash.alpha = self.beam_alpha;
866                                 flash.colormod = self.beam_color;
867                                 flash.scale = 0.5;
868                                 break;
869                         }
870                         case ARC_BT_BURST_HIT:
871                         {
872                                 self.beam_color = '1 0 1';
873                                 self.beam_alpha = 0.5;
874                                 self.beam_thickness = 14;
875                                 self.beam_traileffect = FALSE;
876                                 self.beam_hiteffect = particleeffectnum("electro_lightning"); 
877                                 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
878                                 self.beam_image = "particles/lgbeam";
879                                 setmodel(flash, "models/flash.md3");
880                                 flash.alpha = self.beam_alpha;
881                                 flash.colormod = self.beam_color;
882                                 flash.scale = 0.5;
883                                 break;
884                         }
885
886                         // shouldn't be possible, but lets make it colorful if it does :D
887                         default:
888                         {
889                                 self.beam_color = randomvec();
890                                 self.beam_alpha = 1;
891                                 self.beam_thickness = 8;
892                                 self.beam_traileffect = FALSE;
893                                 self.beam_hiteffect = FALSE; 
894                                 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
895                                 self.beam_image = "particles/lgbeam";
896                                 setmodel(flash, "models/flash.md3");
897                                 flash.alpha = self.beam_alpha;
898                                 flash.colormod = self.beam_color;
899                                 flash.scale = 0.5;
900                                 break;
901                         }
902                 }
903         }
904
905         InterpolateOrigin_Note();
906
907         #if 0
908         printf(
909                 "Ent_ReadArcBeam(%d): sf = %d, start = %s, want = %s, dir = %s, type = %d\n",
910                 isnew,
911                 sf,
912                 vtos(self.beam_start),
913                 vtos(self.v_angle),
914                 vtos(self.angles),
915                 self.beam_type
916         );
917         #endif
918 }
919