1 .float dphitcontentsmask;
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
11 .float absolute; // 1 = count per second is absolute, 2 = only spawn at toggle
12 .vector movedir; // trace direction
14 void Draw_PointParticles()
21 sz = self.maxs - self.mins;
23 if(self.absolute == 2)
26 n = self.just_toggled ? self.impulse : 0;
28 n = self.impulse * drawframetime;
32 n *= self.impulse * drawframetime;
40 for(i = random(); i <= n && fail <= 64*n; ++i)
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))
48 if(self.movedir != '0 0 0')
50 traceline(p, p + normalize(self.movedir) * 4096, 0, world);
52 pointparticles(self.cnt, p, trace_plane_normal * vlen(self.movedir) + self.velocity + randomvec() * self.waterlevel, self.count);
56 pointparticles(self.cnt, p, self.velocity + randomvec() * self.waterlevel, self.count);
61 sound(self, CH_AMBIENT, self.noise, VOL_BASE * self.volume, self.atten);
63 self.just_toggled = 0;
65 else if(self.absolute)
74 void Ent_PointParticles_Remove()
77 strunzone(self.noise);
78 self.noise = string_null;
80 strunzone(self.bgmscript);
81 self.bgmscript = string_null;
84 void Ent_PointParticles()
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;
98 self.origin_x = ReadCoord();
99 self.origin_y = ReadCoord();
100 self.origin_z = ReadCoord();
104 self.modelindex = ReadShort();
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();
119 self.maxs_x = ReadCoord();
120 self.maxs_y = ReadCoord();
121 self.maxs_z = ReadCoord();
126 self.mins = self.maxs = '0 0 0';
129 self.cnt = ReadShort(); // effect number
133 self.velocity = decompressShortVector(ReadShort());
134 self.movedir = decompressShortVector(ReadShort());
138 self.velocity = self.movedir = '0 0 0';
142 self.waterlevel = ReadShort() / 16.0;
143 self.count = ReadByte() / 16.0;
151 strunzone(self.noise);
153 strunzone(self.bgmscript);
154 self.noise = strzone(ReadString());
157 self.atten = ReadByte() / 64.0;
158 self.volume = ReadByte() / 255.0;
160 self.bgmscript = strzone(ReadString());
161 if(self.bgmscript != "")
163 self.bgmscriptattack = ReadByte() / 64.0;
164 self.bgmscriptdecay = ReadByte() / 64.0;
165 self.bgmscriptsustain = ReadByte() / 255.0;
166 self.bgmscriptrelease = ReadByte() / 64.0;
168 BGMScript_InitEntity(self);
173 self.absolute = (self.impulse >= 0);
176 v = self.maxs - self.mins;
177 self.impulse *= -v_x * v_y * v_z / 262144; // relative: particles per 64^3 cube
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;
191 .float glow_color; // palette index
194 te_particlerain(self.origin + self.mins, self.origin + self.maxs, self.velocity, floor(self.count * drawframetime + random()), self.glow_color);
199 te_particlesnow(self.origin + self.mins, self.origin + self.maxs, self.velocity, floor(self.count * drawframetime + random()), self.glow_color);
202 void Ent_RainOrSnow()
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
215 self.mins = -0.5 * self.maxs;
216 self.maxs = 0.5 * self.maxs;
217 self.origin = self.origin - self.mins;
219 setorigin(self, self.origin);
220 setsize(self, self.mins, self.maxs);
221 self.solid = SOLID_NOT;
223 self.draw = Draw_Rain;
225 self.draw = Draw_Snow;
228 void Net_ReadVortexBeamParticle()
230 vector shotorg, endpos;
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;
236 pointparticles(particleeffectnum("nex_muzzleflash"), shotorg, normalize(endpos - shotorg) * 1000, 1);
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;
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);
245 WarpZone_TrailParticles_WithMultiplier(world, particleeffectnum("nex_beam"), shotorg, endpos, 1, PARTICLES_USEALPHA | PARTICLES_USEFADE);
250 .float sw_spread_max;
251 .float sw_spread_min;
254 void Draw_Shockwave()
256 float a = bound(0, (0.5 - ((time - self.sw_time) / 0.4)), 0.5);
258 if(!a) { remove(self); }
260 vector deviation, angle;
262 vector sw_color = getcsqcplayercolor(self.sv_entnum); // GetTeamRGB(GetPlayerColor(self.sv_entnum));
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';
267 float new_max_dist, new_min_dist;
269 vector shotdir = normalize(self.sw_endpos - self.sw_shotorg);
270 vectorvectors(shotdir);
271 vector right = v_right;
274 float counter, dist_before_normal = 200, shots = 20;
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));
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);
282 for(counter = 0; counter < shots; ++counter)
284 // perfect circle effect lines
286 makevectors('0 360 0' * (0.75 + (counter - 0.5) / shots));
287 angle_y = v_forward_x;
288 angle_z = v_forward_y;
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);
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);
307 first_min_end = new_min_end;
308 first_max_end = new_max_end;
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);
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);
327 prev_min_end = new_min_end;
328 prev_max_end = new_max_end;
330 if((counter + 1) == shots)
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);
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);
348 void Net_ReadShockwaveParticle()
352 shockwave.draw = Draw_Shockwave;
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();
357 shockwave.sw_spread_max = ReadByte();
358 shockwave.sw_spread_min = ReadByte();
360 shockwave.sv_entnum = ReadByte();
362 shockwave.sw_time = time;
367 .float beam_thickness;
368 .float beam_traileffect;
369 .float beam_hiteffect;
370 .float beam_muzzleflash;
371 //.string beam_muzzlemodel;
372 //.vector beam_muzzlecolor; // todo: should we just use beam_color?
375 .float beam_usevieworigin;
376 .float beam_initialized;
377 .float beam_maxangle;
379 .float beam_returnspeed;
380 .float beam_tightness;
381 .vector beam_shotorigin;
385 InterpolateOrigin_Do();
387 // origin = beam starting origin
388 // v_angle = wanted/aim direction
389 // angles = current direction of beam
392 vector wantdir; //= view_forward;
393 vector beamdir; //= self.beam_dir;
395 if(self.beam_usevieworigin)
397 // find where we are aiming
398 makevectors(view_angles);
400 // decide upon start position
401 if(self.beam_usevieworigin == 2)
402 { start_pos = view_origin; }
404 { start_pos = self.origin; }
406 // trace forward with an estimation
407 WarpZone_TraceLine(start_pos, start_pos + view_forward * self.beam_range, MOVE_NOMONSTERS, self);
409 // untransform in case our trace went through a warpzone
414 vector shothitpos = WarpZone_UnTransformOrigin(WarpZone_trace_transform, trace_endpos); // warpzone support
419 // un-adjust trueaim if shotend is too close
420 if(vlen(shothitpos - view_origin) < g_trueaim_minrange)
421 shothitpos = view_origin + (view_forward * g_trueaim_minrange);
423 // move shot origin to the actual gun muzzle origin
424 vector origin_offset = view_forward * self.beam_shotorigin_x + view_right * -self.beam_shotorigin_y + view_up * self.beam_shotorigin_z;
425 start_pos = start_pos + origin_offset;
427 // calculate the aim direction now
428 wantdir = normalize(shothitpos - start_pos);
430 if(!self.beam_initialized)
432 self.beam_dir = wantdir;
433 self.beam_initialized = TRUE;
436 if(self.beam_dir != wantdir)
438 float angle = ceil(vlen(wantdir - self.beam_dir) * RAD2DEG);
440 if(angle && (angle > self.beam_maxangle))
442 // if the angle is greater than maxangle, force the blendfactor to make this the maximum factor
443 anglelimit = min(self.beam_maxangle / angle, 1);
447 // the radius is not too far yet, no worries :D
451 // calculate how much we're going to move the end of the beam to the want position
452 float blendfactor = bound(0, anglelimit * (1 - (self.beam_returnspeed * frametime)), 1);
453 self.beam_dir = normalize((wantdir * (1 - blendfactor)) + (self.beam_dir * blendfactor));
456 // finally, set the beam direction which the rest of the code will refer to
457 beamdir = self.beam_dir;
461 // set the values from the provided info from the networked entity
462 start_pos = self.origin;
463 wantdir = self.v_angle;
464 beamdir = self.angles;
467 setorigin(self, start_pos);
469 vector beam_endpos_estimate = (start_pos + (beamdir * self.beam_range));
471 float segments = 20; // todo: calculate this in a similar way to server does
472 float maxthickness = self.beam_thickness;
474 vector thickdir = normalize(cross(beamdir, view_origin - start_pos));
476 vector last_origin = start_pos;
478 float lastthickness = 0;
480 vector last_top = start_pos + (thickdir * lastthickness);
481 vector last_bottom = start_pos - (thickdir * lastthickness);
483 vector hitorigin = start_pos;
486 _len = vlen(self.origin - self.move_origin);
487 _dir = normalize(self.move_origin - self.origin);
489 if(self.total_damages < time)
491 boxparticles(self.traileffect, self, self.origin, self.origin + _dir * -64, _dir * -_len , _dir * -_len, 1, PARTICLES_USEALPHA);
492 boxparticles(self.lip, self, self.move_origin, self.move_origin + _dir * -64, _dir * -200 , _dir * -200, 1, PARTICLES_USEALPHA);
493 self.total_damages = time + 0.1;
499 for(i = 1; i <= segments; ++i)
501 // calculate this on every segment to ensure that we always reach the full length of the attack
502 float segmentblend = bound(0, (i/segments) + self.beam_tightness, 1);
503 float segmentdist = vlen(beam_endpos_estimate - last_origin) * (i/segments);
505 vector new_dir = normalize( (wantdir * (1 - segmentblend)) + (normalize(beam_endpos_estimate - last_origin) * segmentblend) );
506 vector new_origin = last_origin + (new_dir * segmentdist);
516 if(trace_fraction != 1)
518 // calculate our own hit origin as trace_endpos tends to jump around annoyingly (to player origin?)
519 hitorigin = last_origin + (new_dir * segmentdist * trace_fraction);
523 hitorigin = new_origin;
527 float falloff = ExponentialFalloff(
528 WEP_CVAR(arc, beam_falloff_mindist),
529 WEP_CVAR(arc, beam_falloff_maxdist),
530 WEP_CVAR(arc, beam_falloff_halflifedist),
531 vlen(WarpZone_UnTransformOrigin(WarpZone_trace_transform, hitorigin) - start_pos)
537 vector top = hitorigin + (thickdir * self.beam_thickness);
538 vector bottom = hitorigin - (thickdir * self.beam_thickness);
540 R_BeginPolygon(self.beam_image, DRAWFLAG_NORMAL); // DRAWFLAG_ADDITIVE
541 R_PolygonVertex(top, '0 0.5 0' + ('0 0.5 0' * (self.beam_thickness / maxthickness)), self.beam_color, self.beam_alpha);
542 R_PolygonVertex(last_top, '0 0.5 0' + ('0 0.5 0' * (lastthickness / maxthickness)), self.beam_color, self.beam_alpha);
543 R_PolygonVertex(last_bottom, '0 0.5 0' * (1 - (lastthickness / maxthickness)), self.beam_color, self.beam_alpha);
544 R_PolygonVertex(bottom, '0 0.5 0' * (1 - (self.beam_thickness / maxthickness)), self.beam_color, self.beam_alpha);
547 // check if we're going to proceed with drawing
548 if(trace_fraction != 1)
550 // we're done with drawing this frame
555 // continue onto the next segment
556 last_origin = new_origin;
558 last_bottom = bottom;
559 lastthickness = self.beam_thickness;
563 if(self.beam_hiteffect)
565 pointparticles(self.beam_hiteffect, hitorigin, beamdir * -1, frametime * 2);
567 if(self.beam_muzzleflash)
569 pointparticles(self.beam_muzzleflash, start_pos + wantdir * 20, wantdir * 1000, frametime * 0.1);
573 void Remove_ArcBeam(void)
575 sound(self, CH_SHOTS_SINGLE, "misc/null.wav", VOL_BASE, ATTEN_NORM);
578 void Ent_ReadArcBeam(float isnew)
580 float sf = ReadByte();
582 // self.iflags = IFLAG_ORIGIN | IFLAG_ANGLES | IFLAG_V_ANGLE; // why doesn't this work?
583 self.iflags = IFLAG_ORIGIN;
585 InterpolateOrigin_Undo();
587 if(sf & 1) // settings information
589 self.beam_maxangle = ReadShort();
590 self.beam_range = ReadCoord();
591 self.beam_returnspeed = ReadShort();
592 self.beam_tightness = (ReadByte() / 10);
595 if(sf & 2) // starting location
597 self.origin_x = ReadCoord();
598 self.origin_y = ReadCoord();
599 self.origin_z = ReadCoord();
600 setorigin(self, self.origin);
601 self.beam_usevieworigin = 0;
603 else // infer the location from player location
605 if(autocvar_chase_active) // use player origin so that third person display still works
607 self.beam_usevieworigin = 1;
608 self.origin = getplayerorigin(player_localnum) + ('0 0 1' * getstati(STAT_VIEWHEIGHT));
610 else // use view origin
612 self.beam_usevieworigin = 2;
613 self.origin = view_origin; // note that this is only necessary for the sound to be properly located
615 setorigin(self, self.origin);
618 if(sf & 4) // want/aim direction
620 self.v_angle_x = ReadCoord();
621 self.v_angle_y = ReadCoord();
622 self.v_angle_z = ReadCoord();
625 if(sf & 8) // beam direction
627 self.angles_x = ReadCoord();
628 self.angles_y = ReadCoord();
629 self.angles_z = ReadCoord();
632 if(sf & 16) // beam type
634 self.beam_type = ReadByte();
635 switch(self.beam_type)
639 self.beam_color = '-1 -1 1';
640 self.beam_alpha = 0.5;
641 self.beam_thickness = 8;
642 self.beam_traileffect = FALSE;
643 self.beam_hiteffect = particleeffectnum("electro_lightning");
644 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
645 //self.beam_muzzlemodel = "models/uziflash.md3";
646 //self.beam_muzzlecolor = '-1 -1 1';
647 self.beam_image = "particles/lgbeam";
650 case ARC_BT_WALL: // grenadelauncher_muzzleflash healray_muzzleflash
652 self.beam_color = '0.5 0.5 1';
653 self.beam_alpha = 0.5;
654 self.beam_thickness = 8;
655 self.beam_traileffect = FALSE;
656 self.beam_hiteffect = particleeffectnum("electro_lightning");
657 self.beam_muzzleflash = FALSE; // particleeffectnum("grenadelauncher_muzzleflash");
658 //self.beam_muzzlemodel = "models/uziflash.md3";
659 //self.beam_muzzlecolor = '-1 -1 1';
660 self.beam_image = "particles/lgbeam";
665 self.beam_color = '0 1 0';
666 self.beam_alpha = 0.5;
667 self.beam_thickness = 8;
668 self.beam_traileffect = FALSE;
669 self.beam_hiteffect = particleeffectnum("healray_impact");
670 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
671 //self.beam_muzzlemodel = "models/uziflash.md3";
672 //self.beam_muzzlecolor = '-1 -1 1';
673 self.beam_image = "particles/lgbeam";
678 self.beam_color = '1 0 1';
679 self.beam_alpha = 0.5;
680 self.beam_thickness = 8;
681 self.beam_traileffect = FALSE;
682 self.beam_hiteffect = particleeffectnum("electro_lightning");
683 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
684 //self.beam_muzzlemodel = "models/uziflash.md3";
685 //self.beam_muzzlecolor = '-1 -1 1';
686 self.beam_image = "particles/lgbeam";
689 case ARC_BT_BURST_MISS:
691 self.beam_color = '-1 -1 1';
692 self.beam_alpha = 0.5;
693 self.beam_thickness = 14;
694 self.beam_traileffect = FALSE;
695 self.beam_hiteffect = particleeffectnum("electro_lightning");
696 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
697 //self.beam_muzzlemodel = "models/uziflash.md3";
698 //self.beam_muzzlecolor = '-1 -1 1';
699 self.beam_image = "particles/lgbeam";
702 case ARC_BT_BURST_WALL:
704 self.beam_color = '0.5 0.5 1';
705 self.beam_alpha = 0.5;
706 self.beam_thickness = 14;
707 self.beam_traileffect = FALSE;
708 self.beam_hiteffect = particleeffectnum("electro_lightning");
709 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
710 //self.beam_muzzlemodel = "models/uziflash.md3";
711 //self.beam_muzzlecolor = '-1 -1 1';
712 self.beam_image = "particles/lgbeam";
715 case ARC_BT_BURST_HEAL:
717 self.beam_color = '0 1 0';
718 self.beam_alpha = 0.5;
719 self.beam_thickness = 14;
720 self.beam_traileffect = FALSE;
721 self.beam_hiteffect = particleeffectnum("electro_lightning");
722 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
723 //self.beam_muzzlemodel = "models/uziflash.md3";
724 //self.beam_muzzlecolor = '-1 -1 1';
725 self.beam_image = "particles/lgbeam";
728 case ARC_BT_BURST_HIT:
730 self.beam_color = '1 0 1';
731 self.beam_alpha = 0.5;
732 self.beam_thickness = 14;
733 self.beam_traileffect = FALSE;
734 self.beam_hiteffect = particleeffectnum("electro_lightning");
735 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
736 //self.beam_muzzlemodel = "models/uziflash.md3";
737 //self.beam_muzzlecolor = '-1 -1 1';
738 self.beam_image = "particles/lgbeam";
742 // shouldn't be possible, but lets make it colorful if it does :D
745 self.beam_color = randomvec();
747 self.beam_thickness = 8;
748 self.beam_traileffect = FALSE;
749 self.beam_hiteffect = FALSE;
750 self.beam_muzzleflash = FALSE; //particleeffectnum("nex_muzzleflash");
751 //self.beam_muzzlemodel = "models/uziflash.md3";
752 //self.beam_muzzlecolor = '-1 -1 1';
753 self.beam_image = "particles/lgbeam";
759 InterpolateOrigin_Note();
763 // calculate shot origin offset from gun alignment
764 float gunalign = autocvar_cl_gunalign;
765 if(gunalign != 1 && gunalign != 2 && gunalign != 4)
766 gunalign = 3; // default value
769 self.beam_shotorigin = arc_shotorigin[gunalign];
771 // set other main attributes of the beam
772 self.draw = Draw_ArcBeam;
773 self.entremove = Remove_ArcBeam;
774 sound(self, CH_SHOTS_SINGLE, "weapons/lgbeam_fly.wav", VOL_BASE, ATTEN_NORM);
779 "Ent_ReadArcBeam(%d): sf = %d, start = %s, want = %s, dir = %s, type = %d\n",
782 vtos(self.beam_start),