2 #include "../../buffs/all.qh"
3 #include "../../../lib/csqcmodel/interpolate.qh"
4 #include "../../../client/main.qh"
5 #include "../../../lib/csqcmodel/cl_model.qh"
17 if(self.spawnflags & 2)
19 if(self.enemy.origin != self.mangle)
21 self.mangle = self.enemy.origin;
27 a = vectoangles(self.enemy.origin - self.origin);
38 if(self.angles != self.mangle)
40 self.mangle = self.angles;
44 if(self.origin != self.oldorigin)
47 self.oldorigin = self.origin;
51 void misc_laser_init()
54 self.enemy = find(world, targetname, self.target);
58 void misc_laser_think()
64 self.nextthink = time;
73 o = self.enemy.origin;
74 if (!(self.spawnflags & 2))
75 o = self.origin + normalize(o - self.origin) * 32768;
79 makevectors(self.mangle);
80 o = self.origin + v_forward * 32768;
83 if(self.dmg || self.enemy.target != "")
85 traceline(self.origin, o, MOVE_NORMAL, self);
88 hitloc = trace_endpos;
90 if(self.enemy.target != "") // DETECTOR laser
92 if(trace_ent.iscreature)
99 activator = self.enemy.pusher;
100 WITH(entity, self, self.enemy, SUB_UseTargets());
109 activator = self.enemy.pusher;
110 WITH(entity, self, self.enemy, SUB_UseTargets());
118 if(((self.spawnflags & 8) == 0) == (self.team != hitent.team))
120 if(hitent.takedamage)
121 Damage(hitent, self, self, ((self.dmg < 0) ? 100000 : (self.dmg * frametime)), DEATH_HURTTRIGGER.m_id, hitloc, '0 0 0');
125 bool laser_SendEntity(entity this, entity to, float fl)
127 WriteHeader(MSG_ENTITY, ENT_CLIENT_LASER);
128 fl = fl - (fl & 0xF0); // use that bit to indicate finite length laser
129 if(self.spawnflags & 2)
133 if(self.scale != 1 || self.modelscale != 1)
135 if(self.spawnflags & 4)
137 WriteByte(MSG_ENTITY, fl);
140 WriteCoord(MSG_ENTITY, self.origin_x);
141 WriteCoord(MSG_ENTITY, self.origin_y);
142 WriteCoord(MSG_ENTITY, self.origin_z);
146 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
147 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
148 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
150 WriteByte(MSG_ENTITY, self.alpha * 255.0);
153 WriteByte(MSG_ENTITY, bound(0, self.scale * 16.0, 255));
154 WriteByte(MSG_ENTITY, bound(0, self.modelscale * 16.0, 255));
156 if((fl & 0x80) || !(fl & 0x10)) // effect doesn't need sending if the laser is infinite and has collision testing turned off
157 WriteShort(MSG_ENTITY, self.cnt + 1);
163 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
164 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
165 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
169 WriteAngle(MSG_ENTITY, self.mangle_x);
170 WriteAngle(MSG_ENTITY, self.mangle_y);
174 WriteByte(MSG_ENTITY, self.state);
178 /*QUAKED spawnfunc_misc_laser (.5 .5 .5) ? START_ON DEST_IS_FIXED
179 Any object touching the beam will be hurt
182 spawnfunc_target_position where the laser ends
184 name of beam end effect to use
186 color of the beam (default: red)
188 damage per second (-1 for a laser that kills immediately)
192 self.state = !self.state;
199 if(self.spawnflags & 1)
205 spawnfunc(misc_laser)
209 if(self.mdl == "none")
213 self.cnt = _particleeffectnum(self.mdl);
216 self.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
222 self.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
229 if(self.colormod == '0 0 0')
231 self.colormod = '1 0 0';
232 if(self.message == "")
233 self.message = "saw the light";
234 if (self.message2 == "")
235 self.message2 = "was pushed into a laser by";
240 else if(self.modelscale < 0)
242 self.think = misc_laser_think;
243 self.nextthink = time;
244 InitializeEntity(self, misc_laser_init, INITPRIO_FINDTARGET);
246 self.mangle = self.angles;
248 Net_LinkEntity(self, false, 0, laser_SendEntity);
252 self.reset = laser_reset;
254 self.use = laser_use;
261 // a laser goes from origin in direction angles
262 // it has color 'colormod'
263 // and stops when something is in the way
265 class(Laser) .int cnt; // end effect
266 class(Laser) .vector colormod;
267 class(Laser) .int state; // on-off
268 class(Laser) .int count; // flags for the laser
269 class(Laser) .vector velocity;
270 class(Laser) .float alpha;
271 class(Laser) .float scale; // scaling factor of the thickness
272 class(Laser) .float modelscale; // scaling factor of the dlight
274 void Draw_Laser(entity this)
278 InterpolateOrigin_Do();
279 if(self.count & 0x80)
281 if(self.count & 0x10)
283 trace_endpos = self.velocity;
284 trace_dphitq3surfaceflags = 0;
287 traceline(self.origin, self.velocity, 0, self);
291 if(self.count & 0x10)
293 makevectors(self.angles);
294 trace_endpos = self.origin + v_forward * 1048576;
295 trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY;
299 makevectors(self.angles);
300 traceline(self.origin, self.origin + v_forward * 32768, 0, self);
301 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
302 trace_endpos = self.origin + v_forward * 1048576;
309 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, self.alpha, DRAWFLAG_NORMAL, view_origin);
313 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin);
316 if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
319 __pointparticles(self.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
320 if(self.colormod != '0 0 0' && self.modelscale != 0)
321 adddynamiclight(trace_endpos + trace_plane_normal * 1, self.modelscale, self.colormod * 5);
327 InterpolateOrigin_Undo();
329 // 30 bytes, or 13 bytes for just moving
331 self.count = (f & 0xF0);
333 if(self.count & 0x80)
334 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
336 self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
340 self.origin_x = ReadCoord();
341 self.origin_y = ReadCoord();
342 self.origin_z = ReadCoord();
343 setorigin(self, self.origin);
347 self.colormod_x = ReadByte() / 255.0;
348 self.colormod_y = ReadByte() / 255.0;
349 self.colormod_z = ReadByte() / 255.0;
351 self.alpha = ReadByte() / 255.0;
355 self.modelscale = 50;
358 self.scale *= ReadByte() / 16.0; // beam radius
359 self.modelscale *= ReadByte() / 16.0; // dlight radius
361 if((f & 0x80) || !(f & 0x10))
362 self.cnt = ReadShort() - 1; // effect number
370 self.velocity_x = ReadCoord();
371 self.velocity_y = ReadCoord();
372 self.velocity_z = ReadCoord();
376 self.angles_x = ReadAngle();
377 self.angles_y = ReadAngle();
381 self.state = ReadByte();
382 InterpolateOrigin_Note();
383 self.draw = Draw_Laser;