2 #include "../../../client/_all.qh"
3 #include "../../buffs.qh"
4 #include "../../../csqcmodellib/interpolate.qh"
5 #include "../../../client/main.qh"
6 #include "../../../csqcmodellib/cl_model.qh"
18 if(self.spawnflags & 2)
20 if(self.enemy.origin != self.mangle)
22 self.mangle = self.enemy.origin;
28 a = vectoangles(self.enemy.origin - self.origin);
39 if(self.angles != self.mangle)
41 self.mangle = self.angles;
45 if(self.origin != self.oldorigin)
48 self.oldorigin = self.origin;
52 void misc_laser_init()
55 self.enemy = find(world, targetname, self.target);
59 void misc_laser_think()
65 self.nextthink = time;
74 o = self.enemy.origin;
75 if (!(self.spawnflags & 2))
76 o = self.origin + normalize(o - self.origin) * 32768;
80 makevectors(self.mangle);
81 o = self.origin + v_forward * 32768;
84 if(self.dmg || self.enemy.target != "")
86 traceline(self.origin, o, MOVE_NORMAL, self);
89 hitloc = trace_endpos;
91 if(self.enemy.target != "") // DETECTOR laser
93 if(trace_ent.iscreature)
100 activator = self.enemy.pusher;
101 SELFCALL(self.enemy, SUB_UseTargets());
111 activator = self.enemy.pusher;
112 SELFCALL(self.enemy, SUB_UseTargets());
121 if(((self.spawnflags & 8) == 0) == (self.team != hitent.team))
123 if(hitent.takedamage)
124 Damage(hitent, self, self, ((self.dmg < 0) ? 100000 : (self.dmg * frametime)), DEATH_HURTTRIGGER, hitloc, '0 0 0');
128 float laser_SendEntity(entity to, float fl)
130 WriteByte(MSG_ENTITY, ENT_CLIENT_LASER);
131 fl = fl - (fl & 0xF0); // use that bit to indicate finite length laser
132 if(self.spawnflags & 2)
136 if(self.scale != 1 || self.modelscale != 1)
138 if(self.spawnflags & 4)
140 WriteByte(MSG_ENTITY, fl);
143 WriteCoord(MSG_ENTITY, self.origin_x);
144 WriteCoord(MSG_ENTITY, self.origin_y);
145 WriteCoord(MSG_ENTITY, self.origin_z);
149 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
150 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
151 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
153 WriteByte(MSG_ENTITY, self.alpha * 255.0);
156 WriteByte(MSG_ENTITY, bound(0, self.scale * 16.0, 255));
157 WriteByte(MSG_ENTITY, bound(0, self.modelscale * 16.0, 255));
159 if((fl & 0x80) || !(fl & 0x10)) // effect doesn't need sending if the laser is infinite and has collision testing turned off
160 WriteShort(MSG_ENTITY, self.cnt + 1);
166 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
167 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
168 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
172 WriteAngle(MSG_ENTITY, self.mangle_x);
173 WriteAngle(MSG_ENTITY, self.mangle_y);
177 WriteByte(MSG_ENTITY, self.state);
181 /*QUAKED spawnfunc_misc_laser (.5 .5 .5) ? START_ON DEST_IS_FIXED
182 Any object touching the beam will be hurt
185 spawnfunc_target_position where the laser ends
187 name of beam end effect to use
189 color of the beam (default: red)
191 damage per second (-1 for a laser that kills immediately)
195 self.state = !self.state;
202 if(self.spawnflags & 1)
208 void spawnfunc_misc_laser()
212 if(self.mdl == "none")
216 self.cnt = _particleeffectnum(self.mdl);
219 self.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
225 self.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
232 if(self.colormod == '0 0 0')
234 self.colormod = '1 0 0';
235 if(self.message == "")
236 self.message = "saw the light";
237 if (self.message2 == "")
238 self.message2 = "was pushed into a laser by";
243 else if(self.modelscale < 0)
245 self.think = misc_laser_think;
246 self.nextthink = time;
247 InitializeEntity(self, misc_laser_init, INITPRIO_FINDTARGET);
249 self.mangle = self.angles;
251 Net_LinkEntity(self, false, 0, laser_SendEntity);
255 self.reset = laser_reset;
257 self.use = laser_use;
264 // a laser goes from origin in direction angles
265 // it has color 'colormod'
266 // and stops when something is in the way
268 class(Laser) .int cnt; // end effect
269 class(Laser) .vector colormod;
270 class(Laser) .int state; // on-off
271 class(Laser) .int count; // flags for the laser
272 class(Laser) .vector velocity;
273 class(Laser) .float alpha;
274 class(Laser) .float scale; // scaling factor of the thickness
275 class(Laser) .float modelscale; // scaling factor of the dlight
281 InterpolateOrigin_Do();
282 if(self.count & 0x80)
284 if(self.count & 0x10)
286 trace_endpos = self.velocity;
287 trace_dphitq3surfaceflags = 0;
290 traceline(self.origin, self.velocity, 0, self);
294 if(self.count & 0x10)
296 makevectors(self.angles);
297 trace_endpos = self.origin + v_forward * 1048576;
298 trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY;
302 makevectors(self.angles);
303 traceline(self.origin, self.origin + v_forward * 32768, 0, self);
304 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
305 trace_endpos = self.origin + v_forward * 1048576;
312 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, self.alpha, DRAWFLAG_NORMAL, view_origin);
316 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin);
319 if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
322 pointparticles(self.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
323 if(self.colormod != '0 0 0' && self.modelscale != 0)
324 adddynamiclight(trace_endpos + trace_plane_normal * 1, self.modelscale, self.colormod * 5);
330 InterpolateOrigin_Undo();
332 // 30 bytes, or 13 bytes for just moving
334 self.count = (f & 0xF0);
336 if(self.count & 0x80)
337 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
339 self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
343 self.origin_x = ReadCoord();
344 self.origin_y = ReadCoord();
345 self.origin_z = ReadCoord();
346 setorigin(self, self.origin);
350 self.colormod_x = ReadByte() / 255.0;
351 self.colormod_y = ReadByte() / 255.0;
352 self.colormod_z = ReadByte() / 255.0;
354 self.alpha = ReadByte() / 255.0;
358 self.modelscale = 50;
361 self.scale *= ReadByte() / 16.0; // beam radius
362 self.modelscale *= ReadByte() / 16.0; // dlight radius
364 if((f & 0x80) || !(f & 0x10))
365 self.cnt = ReadShort() - 1; // effect number
373 self.velocity_x = ReadCoord();
374 self.velocity_y = ReadCoord();
375 self.velocity_z = ReadCoord();
379 self.angles_x = ReadAngle();
380 self.angles_y = ReadAngle();
384 self.state = ReadByte();
385 InterpolateOrigin_Note();
386 self.draw = Draw_Laser;