2 #include "../../buffs/all.qh"
3 #include "../../../lib/csqcmodel/interpolate.qh"
4 #include "../../../client/main.qh"
5 #include "../../../lib/csqcmodel/cl_model.qh"
10 REGISTER_NET_LINKED(ENT_CLIENT_LASER)
19 if(self.spawnflags & 2)
21 if(self.enemy.origin != self.mangle)
23 self.mangle = self.enemy.origin;
29 a = vectoangles(self.enemy.origin - self.origin);
40 if(self.angles != self.mangle)
42 self.mangle = self.angles;
46 if(self.origin != self.oldorigin)
49 self.oldorigin = self.origin;
53 void misc_laser_init()
56 self.enemy = find(world, targetname, self.target);
60 void misc_laser_think()
66 self.nextthink = time;
75 o = self.enemy.origin;
76 if (!(self.spawnflags & 2))
77 o = self.origin + normalize(o - self.origin) * 32768;
81 makevectors(self.mangle);
82 o = self.origin + v_forward * 32768;
85 if(self.dmg || self.enemy.target != "")
87 traceline(self.origin, o, MOVE_NORMAL, self);
90 hitloc = trace_endpos;
92 if(self.enemy.target != "") // DETECTOR laser
94 if(trace_ent.iscreature)
101 activator = self.enemy.pusher;
102 WITH(entity, self, self.enemy, SUB_UseTargets());
111 activator = self.enemy.pusher;
112 WITH(entity, self, self.enemy, SUB_UseTargets());
120 if(((self.spawnflags & 8) == 0) == (self.team != hitent.team))
122 if(hitent.takedamage)
123 Damage(hitent, self, self, ((self.dmg < 0) ? 100000 : (self.dmg * frametime)), DEATH_HURTTRIGGER.m_id, hitloc, '0 0 0');
127 bool laser_SendEntity(entity this, entity to, float fl)
129 WriteHeader(MSG_ENTITY, ENT_CLIENT_LASER);
130 fl = fl - (fl & 0xF0); // use that bit to indicate finite length laser
131 if(self.spawnflags & 2)
135 if(self.scale != 1 || self.modelscale != 1)
137 if(self.spawnflags & 4)
139 WriteByte(MSG_ENTITY, fl);
142 WriteCoord(MSG_ENTITY, self.origin_x);
143 WriteCoord(MSG_ENTITY, self.origin_y);
144 WriteCoord(MSG_ENTITY, self.origin_z);
148 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
149 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
150 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
152 WriteByte(MSG_ENTITY, self.alpha * 255.0);
155 WriteByte(MSG_ENTITY, bound(0, self.scale * 16.0, 255));
156 WriteByte(MSG_ENTITY, bound(0, self.modelscale * 16.0, 255));
158 if((fl & 0x80) || !(fl & 0x10)) // effect doesn't need sending if the laser is infinite and has collision testing turned off
159 WriteShort(MSG_ENTITY, self.cnt + 1);
165 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
166 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
167 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
171 WriteAngle(MSG_ENTITY, self.mangle_x);
172 WriteAngle(MSG_ENTITY, self.mangle_y);
176 WriteByte(MSG_ENTITY, self.state);
180 /*QUAKED spawnfunc_misc_laser (.5 .5 .5) ? START_ON DEST_IS_FIXED
181 Any object touching the beam will be hurt
184 spawnfunc_target_position where the laser ends
186 name of beam end effect to use
188 color of the beam (default: red)
190 damage per second (-1 for a laser that kills immediately)
194 self.state = !self.state;
201 if(self.spawnflags & 1)
207 spawnfunc(misc_laser)
211 if(self.mdl == "none")
215 self.cnt = _particleeffectnum(self.mdl);
218 self.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
224 self.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
231 if(self.colormod == '0 0 0')
233 self.colormod = '1 0 0';
234 if(self.message == "")
235 self.message = "saw the light";
236 if (self.message2 == "")
237 self.message2 = "was pushed into a laser by";
242 else if(self.modelscale < 0)
244 self.think = misc_laser_think;
245 self.nextthink = time;
246 InitializeEntity(self, misc_laser_init, INITPRIO_FINDTARGET);
248 self.mangle = self.angles;
250 Net_LinkEntity(self, false, 0, laser_SendEntity);
254 self.reset = laser_reset;
256 self.use = laser_use;
263 // a laser goes from origin in direction angles
264 // it has color 'colormod'
265 // and stops when something is in the way
267 class(Laser) .int cnt; // end effect
268 class(Laser) .vector colormod;
269 class(Laser) .int state; // on-off
270 class(Laser) .int count; // flags for the laser
271 class(Laser) .vector velocity;
272 class(Laser) .float alpha;
273 class(Laser) .float scale; // scaling factor of the thickness
274 class(Laser) .float modelscale; // scaling factor of the dlight
276 void Draw_Laser(entity this)
280 InterpolateOrigin_Do();
281 if(self.count & 0x80)
283 if(self.count & 0x10)
285 trace_endpos = self.velocity;
286 trace_dphitq3surfaceflags = 0;
289 traceline(self.origin, self.velocity, 0, self);
293 if(self.count & 0x10)
295 makevectors(self.angles);
296 trace_endpos = self.origin + v_forward * 1048576;
297 trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY;
301 makevectors(self.angles);
302 traceline(self.origin, self.origin + v_forward * 32768, 0, self);
303 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
304 trace_endpos = self.origin + v_forward * 1048576;
311 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, self.alpha, DRAWFLAG_NORMAL, view_origin);
315 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin);
318 if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
321 __pointparticles(self.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
322 if(self.colormod != '0 0 0' && self.modelscale != 0)
323 adddynamiclight(trace_endpos + trace_plane_normal * 1, self.modelscale, self.colormod * 5);
327 NET_HANDLE(ENT_CLIENT_LASER, bool isnew)
329 InterpolateOrigin_Undo();
331 // 30 bytes, or 13 bytes for just moving
333 self.count = (f & 0xF0);
335 if(self.count & 0x80)
336 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
338 self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
342 self.origin_x = ReadCoord();
343 self.origin_y = ReadCoord();
344 self.origin_z = ReadCoord();
345 setorigin(self, self.origin);
349 self.colormod_x = ReadByte() / 255.0;
350 self.colormod_y = ReadByte() / 255.0;
351 self.colormod_z = ReadByte() / 255.0;
353 self.alpha = ReadByte() / 255.0;
357 self.modelscale = 50;
360 self.scale *= ReadByte() / 16.0; // beam radius
361 self.modelscale *= ReadByte() / 16.0; // dlight radius
363 if((f & 0x80) || !(f & 0x10))
364 self.cnt = ReadShort() - 1; // effect number
372 self.velocity_x = ReadCoord();
373 self.velocity_y = ReadCoord();
374 self.velocity_z = ReadCoord();
378 self.angles_x = ReadAngle();
379 self.angles_y = ReadAngle();
383 self.state = ReadByte();
387 InterpolateOrigin_Note();
388 self.draw = Draw_Laser;