2 #include "../../../dpdefs/csprogsdefs.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()
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)
103 activator = self.pusher;
116 activator = self.pusher;
126 if(((self.spawnflags & 8) == 0) == (self.team != hitent.team))
128 if(hitent.takedamage)
129 Damage(hitent, self, self, ((self.dmg < 0) ? 100000 : (self.dmg * frametime)), DEATH_HURTTRIGGER, hitloc, '0 0 0');
133 float laser_SendEntity(entity to, float fl)
135 WriteByte(MSG_ENTITY, ENT_CLIENT_LASER);
136 fl = fl - (fl & 0xF0); // use that bit to indicate finite length laser
137 if(self.spawnflags & 2)
141 if(self.scale != 1 || self.modelscale != 1)
143 if(self.spawnflags & 4)
145 WriteByte(MSG_ENTITY, fl);
148 WriteCoord(MSG_ENTITY, self.origin_x);
149 WriteCoord(MSG_ENTITY, self.origin_y);
150 WriteCoord(MSG_ENTITY, self.origin_z);
154 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
155 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
156 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
158 WriteByte(MSG_ENTITY, self.alpha * 255.0);
161 WriteByte(MSG_ENTITY, bound(0, self.scale * 16.0, 255));
162 WriteByte(MSG_ENTITY, bound(0, self.modelscale * 16.0, 255));
164 if((fl & 0x80) || !(fl & 0x10)) // effect doesn't need sending if the laser is infinite and has collision testing turned off
165 WriteShort(MSG_ENTITY, self.cnt + 1);
171 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
172 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
173 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
177 WriteAngle(MSG_ENTITY, self.mangle_x);
178 WriteAngle(MSG_ENTITY, self.mangle_y);
182 WriteByte(MSG_ENTITY, self.state);
186 /*QUAKED spawnfunc_misc_laser (.5 .5 .5) ? START_ON DEST_IS_FIXED
187 Any object touching the beam will be hurt
190 spawnfunc_target_position where the laser ends
192 name of beam end effect to use
194 color of the beam (default: red)
196 damage per second (-1 for a laser that kills immediately)
200 self.state = !self.state;
207 if(self.spawnflags & 1)
213 void spawnfunc_misc_laser()
217 if(self.mdl == "none")
221 self.cnt = particleeffectnum(self.mdl);
224 self.cnt = particleeffectnum("laser_deadly");
230 self.cnt = particleeffectnum("laser_deadly");
237 if(self.colormod == '0 0 0')
239 self.colormod = '1 0 0';
240 if(self.message == "")
241 self.message = "saw the light";
242 if (self.message2 == "")
243 self.message2 = "was pushed into a laser by";
248 else if(self.modelscale < 0)
250 self.think = misc_laser_think;
251 self.nextthink = time;
252 InitializeEntity(self, misc_laser_init, INITPRIO_FINDTARGET);
254 self.mangle = self.angles;
256 Net_LinkEntity(self, false, 0, laser_SendEntity);
260 self.reset = laser_reset;
262 self.use = laser_use;
269 // a laser goes from origin in direction angles
270 // it has color 'colormod'
271 // and stops when something is in the way
272 .int cnt; // end effect
274 .int state; // on-off
275 .int count; // flags for the laser
278 .float scale; // scaling factor of the thickness
279 .float modelscale; // scaling factor of the dlight
285 InterpolateOrigin_Do();
286 if(self.count & 0x80)
288 if(self.count & 0x10)
290 trace_endpos = self.velocity;
291 trace_dphitq3surfaceflags = 0;
294 traceline(self.origin, self.velocity, 0, self);
298 if(self.count & 0x10)
300 makevectors(self.angles);
301 trace_endpos = self.origin + v_forward * 1048576;
302 trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY;
306 makevectors(self.angles);
307 traceline(self.origin, self.origin + v_forward * 32768, 0, self);
308 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
309 trace_endpos = self.origin + v_forward * 1048576;
316 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, self.alpha, DRAWFLAG_NORMAL, view_origin);
320 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin);
323 if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
326 pointparticles(self.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
327 if(self.colormod != '0 0 0' && self.modelscale != 0)
328 adddynamiclight(trace_endpos + trace_plane_normal * 1, self.modelscale, self.colormod * 5);
334 InterpolateOrigin_Undo();
336 // 30 bytes, or 13 bytes for just moving
338 self.count = (f & 0xF0);
340 if(self.count & 0x80)
341 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
343 self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
347 self.origin_x = ReadCoord();
348 self.origin_y = ReadCoord();
349 self.origin_z = ReadCoord();
350 setorigin(self, self.origin);
354 self.colormod_x = ReadByte() / 255.0;
355 self.colormod_y = ReadByte() / 255.0;
356 self.colormod_z = ReadByte() / 255.0;
358 self.alpha = ReadByte() / 255.0;
362 self.modelscale = 50;
365 self.scale *= ReadByte() / 16.0; // beam radius
366 self.modelscale *= ReadByte() / 16.0; // dlight radius
368 if((f & 0x80) || !(f & 0x10))
369 self.cnt = ReadShort() - 1; // effect number
377 self.velocity_x = ReadCoord();
378 self.velocity_y = ReadCoord();
379 self.velocity_z = ReadCoord();
383 self.angles_x = ReadAngle();
384 self.angles_y = ReadAngle();
388 self.state = ReadByte();
389 InterpolateOrigin_Note();
390 self.draw = Draw_Laser;