]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/client/particles.qc
Add some additional functionality to beam type effect selection
[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 .float beam_usevieworigin;
366 .float beam_initialized;
367 .float beam_maxangle;
368 .float beam_range;
369 .float beam_returnspeed;
370 .vector beam_shotorigin;
371 .vector beam_dir;
372 void Draw_ArcBeam()
373 {
374         if(self.teleport_time)
375         if(time > self.teleport_time)
376         {
377                 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM); // safeguard
378                 self.teleport_time = 0;
379         }
380
381         InterpolateOrigin_Do();
382
383         // origin = beam starting origin
384         // v_angle = wanted/aim direction
385         // angles = current direction of beam
386
387         vector start_pos;
388         vector wantdir; //= view_forward;
389         vector beamdir; //= self.beam_dir;
390
391         if(self.beam_usevieworigin)
392         {
393                 // find where we are aiming
394                 makevectors(view_angles);
395
396                 // decide upon start position
397                 if(self.beam_usevieworigin == 2)
398                         { start_pos = view_origin; }
399                 else
400                         { start_pos = self.origin; }
401
402                 // trace forward with an estimation
403                 WarpZone_TraceLine(start_pos, start_pos + view_forward * self.beam_range, MOVE_NOMONSTERS, self);
404
405                 // untransform in case our trace went through a warpzone
406                 vector vf, vr, vu;
407                 vf = view_forward;
408                 vr = view_right;
409                 vu = view_up;
410                 vector shothitpos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos); // warpzone support
411                 view_forward = vf;
412                 view_right = vr;
413                 view_up = vu;
414
415                 // un-adjust trueaim if shotend is too close
416                 if(vlen(shothitpos - view_origin) < g_trueaim_minrange)
417                         shothitpos = view_origin + (view_forward * g_trueaim_minrange);
418
419                 // move shot origin to the actual gun muzzle origin
420                 vector origin_offset = view_forward * self.beam_shotorigin_x + view_right * -self.beam_shotorigin_y + view_up * self.beam_shotorigin_z;
421                 start_pos = start_pos + origin_offset;
422
423                 // calculate the aim direction now
424                 wantdir = normalize(shothitpos - start_pos);
425
426                 if(!self.beam_initialized)
427                 {
428                         self.beam_dir = wantdir;
429                         self.beam_initialized = TRUE;
430                 }
431
432                 if(self.beam_dir != wantdir)
433                 {
434                         float angle = ceil(vlen(wantdir - self.beam_dir) * RAD2DEG);
435                         float anglelimit;
436                         if(angle && (angle > self.beam_maxangle))
437                         {
438                                 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
439                                 anglelimit = min(self.beam_maxangle / angle, 1);
440                         }
441                         else
442                         {
443                                 // the radius is not too far yet, no worries :D
444                                 anglelimit = 1;
445                         }
446
447                         // calculate how much we're going to move the end of the beam to the want position
448                         float blendfactor = bound(0, anglelimit * (1 - (self.beam_returnspeed * frametime)), 1);
449                         self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
450                 }
451
452                 // finally, set the beam direction which the rest of the code will refer to
453                 beamdir = self.beam_dir;
454         }
455         else
456         {
457                 // set the values from the provided info from the networked entity
458                 start_pos = self.origin;
459                 wantdir = self.v_angle;
460                 beamdir = self.angles;
461         }
462
463         setorigin(self, start_pos);
464
465         vector beam_endpos_estimate = (start_pos + (beamdir * self.beam_range));
466
467         float segments = 20; // todo: calculate this in a similar way to server does
468         float maxthickness = 8;
469
470         // determine visual effects now
471         // todo: figure this out when reading the networked entity
472         // this way we don't have to check this EVERY frame
473         vector beamrgb;
474         float beamalpha;
475         float beamthickness;
476         float beamtraileffect;
477         float beamhiteffect;
478         float beammuzzleflash;
479         string beamimage = "particles/lgbeam";
480
481         //printf("beam type: %d\n", self.beam_type);
482
483         switch(self.beam_type)
484         {
485                 case ARC_BT_MISS:
486                 {
487                         beamrgb = '-1 -1 1';
488                         beamalpha = 0.5;
489                         beamthickness = 8;
490                         beamtraileffect = FALSE;
491                         beamhiteffect = particleeffectnum("electro_lightning");
492                         beammuzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
493                         break;
494                 }
495                 case ARC_BT_WALL:
496                 {
497                         beamrgb = '0.5 0.5 1';
498                         beamalpha = 0.5;
499                         beamthickness = 8;
500                         beamtraileffect = FALSE;
501                         beamhiteffect = particleeffectnum("electro_lightning"); 
502                         beammuzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
503                         break;
504                 }
505                 case ARC_BT_HEAL:
506                 {
507                         beamrgb = '0 1 0';
508                         beamalpha = 0.5;
509                         beamthickness = 8;
510                         beamtraileffect = FALSE;
511                         beamhiteffect = particleeffectnum("electro_lightning"); 
512                         beammuzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
513                         break;
514                 }
515                 case ARC_BT_HIT:
516                 {
517                         beamrgb = '1 0 1';
518                         beamalpha = 0.5;
519                         beamthickness = 8;
520                         beamtraileffect = FALSE;
521                         beamhiteffect = particleeffectnum("electro_lightning"); 
522                         beammuzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
523                         break;
524                 }
525                 case ARC_BT_BURST_MISS:
526                 {
527                         beamrgb = '-1 -1 1';
528                         beamalpha = 0.5;
529                         beamthickness = 14;
530                         beamtraileffect = FALSE;
531                         beamhiteffect = particleeffectnum("electro_lightning"); 
532                         beammuzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
533                         break;
534                 }
535                 case ARC_BT_BURST_WALL:
536                 {
537                         beamrgb = '0.5 0.5 1';
538                         beamalpha = 0.5;
539                         beamthickness = 14;
540                         beamtraileffect = FALSE;
541                         beamhiteffect = particleeffectnum("electro_lightning"); 
542                         beammuzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
543                         break;
544                 }
545                 case ARC_BT_BURST_HEAL:
546                 {
547                         beamrgb = '0 1 0';
548                         beamalpha = 0.5;
549                         beamthickness = 14;
550                         beamtraileffect = FALSE;
551                         beamhiteffect = particleeffectnum("electro_lightning"); 
552                         beammuzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
553                         break;
554                 }
555                 case ARC_BT_BURST_HIT:
556                 {
557                         beamrgb = '1 0 1';
558                         beamalpha = 0.5;
559                         beamthickness = 14;
560                         beamtraileffect = FALSE;
561                         beamhiteffect = particleeffectnum("electro_lightning"); 
562                         beammuzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
563                         break;
564                 }
565
566                 // shouldn't be possible, but lets make it colorful if it does :D
567                 default:
568                 {
569                         beamrgb = randomvec();
570                         beamalpha = 1;
571                         beamthickness = 8;
572                         beamtraileffect = FALSE;
573                         beamhiteffect = FALSE; 
574                         beammuzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
575                         break;
576                 }
577         }
578
579         vector thickdir = normalize(cross(beamdir, view_origin - start_pos));
580
581         vector last_origin = start_pos;
582
583         float lastthickness = 0;
584
585         vector last_top = start_pos + (thickdir * lastthickness);
586         vector last_bottom = start_pos - (thickdir * lastthickness);
587
588         vector hitorigin = start_pos;
589
590         float i;
591         for(i = 1; i <= segments; ++i)
592         {
593                 // calculate this on every segment to ensure that we always reach the full length of the attack
594                 float segmentblend = (i/segments);
595                 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
596
597                 vector new_dir = normalize( (wantdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend) );
598                 vector new_origin = last_origin + (new_dir * segmentdist);
599
600                 WarpZone_TraceLine(
601                         last_origin,
602                         new_origin,
603                         MOVE_NORMAL,
604                         self
605                 );
606
607                 // draw segment
608                 if(trace_fraction != 1)
609                 {
610                         // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
611                         hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
612                 }
613                 else
614                 {
615                         hitorigin = new_origin;
616                 }
617
618                 #if 0
619                 float falloff = ExponentialFalloff(
620                         WEP_CVAR(arc, beam_falloff_mindist),
621                         WEP_CVAR(arc, beam_falloff_maxdist),
622                         WEP_CVAR(arc, beam_falloff_halflifedist),
623                         vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - start_pos)
624                 );
625                 #else
626                 //float falloff = 1;
627                 #endif
628
629                 vector top    = hitorigin + (thickdir * beamthickness);
630                 vector bottom = hitorigin - (thickdir * beamthickness);
631
632                 R_BeginPolygon(beamimage, DRAWFLAG_NORMAL);
633                 R_PolygonVertex(top,         '0 0.5 0' + ('0 0.5 0' * (beamthickness / maxthickness)), beamrgb, beamalpha);
634                 R_PolygonVertex(last_top,    '0 0.5 0' + ('0 0.5 0' * (lastthickness / maxthickness)), beamrgb, beamalpha);
635                 R_PolygonVertex(last_bottom, '0 0.5 0' * (1 - (lastthickness / maxthickness)),         beamrgb, beamalpha);
636                 R_PolygonVertex(bottom,      '0 0.5 0' * (1 - (beamthickness / maxthickness)),         beamrgb, beamalpha);
637                 R_EndPolygon();
638
639                 // check if we're going to proceed with drawing
640                 if(trace_fraction != 1)
641                 {
642                         // we're done with drawing this frame
643                         break;
644                 }
645                 else
646                 {
647                         // continue onto the next segment
648                         last_origin = new_origin;
649                         last_top = top;
650                         last_bottom = bottom;
651                         lastthickness = beamthickness;
652                 }
653         }
654
655         if(beamhiteffect)
656         {
657                 pointparticles(beamhiteffect, hitorigin, beamdir * -1, frametime * 2);
658         }
659         if(beammuzzleflash)
660         {
661                 pointparticles(beammuzzleflash, start_pos, wantdir * 1000, frametime * 1);
662         }
663 }
664
665 void Remove_ArcBeam(void)
666 {
667         sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
668 }
669
670 void Ent_ReadArcBeam(float isnew)
671 {
672         float sf = ReadByte();
673
674         // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
675         self.iflags = IFLAG_ORIGIN;
676
677         InterpolateOrigin_Undo();
678
679         if(sf & 1) // settings information
680         {
681                 self.beam_maxangle = ReadShort();
682                 self.beam_range = ReadCoord();
683                 self.beam_returnspeed = ReadShort();
684         }
685
686         if(sf & 2) // starting location
687         {
688                 self.origin_x = ReadCoord();
689                 self.origin_y = ReadCoord();
690                 self.origin_z = ReadCoord();
691                 setorigin(self, self.origin);
692                 self.beam_usevieworigin = 0;
693                 //WriteCoord(MSG_ENTITY, WEP_CVAR(arc, beam_range));
694         }
695         else // infer the location from player location
696         {
697                 if(autocvar_chase_active) // use player origin so that third person display still works
698                 {
699                         self.beam_usevieworigin = 1;
700                         self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
701                 }
702                 else // use view origin
703                 {
704                         self.beam_usevieworigin = 2;
705                         self.origin = view_origin; // note that this is only necessary for the sound to be properly located
706                 }
707                 setorigin(self, self.origin);
708         }
709
710         if(sf & 4) // want/aim direction
711         {
712                 self.v_angle_x = ReadCoord();
713                 self.v_angle_y = ReadCoord();
714                 self.v_angle_z = ReadCoord();
715         }
716
717         if(sf & 8) // beam direction
718         {
719                 self.angles_x = ReadCoord();
720                 self.angles_y = ReadCoord();
721                 self.angles_z = ReadCoord();
722         }
723
724         if(sf & 16) // beam type
725         {
726                 self.beam_type = ReadByte();
727         }
728
729         InterpolateOrigin_Note();
730
731         if(isnew || !self.teleport_time)
732         {
733                 // calculate shot origin offset from gun alignment
734                 float gunalign = autocvar_cl_gunalign;
735                 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
736                         gunalign = 3; // default value
737                 --gunalign;
738
739                 self.beam_shotorigin = arc_shotorigin[gunalign];
740
741                 // set other main attributes of the beam
742                 self.draw = Draw_ArcBeam;
743                 self.entremove = Remove_ArcBeam;
744                 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
745         }
746
747         self.teleport_time = time + 10;
748
749         #if 0
750         printf(
751                 "Ent_ReadArcBeam(%d): sf = %d, start = %s, want = %s, dir = %s, type = %d\n",
752                 isnew,
753                 sf,
754                 vtos(self.beam_start),
755                 vtos(self.v_angle),
756                 vtos(self.angles),
757                 self.beam_type
758         );
759         #endif
760 }
761