2 #include "../../../client/_all.qh"
3 #include "../../buffs/all.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 WITH(entity, self, self.enemy, SUB_UseTargets());
110 activator = self.enemy.pusher;
111 WITH(entity, self, self.enemy, SUB_UseTargets());
119 if(((self.spawnflags & 8) == 0) == (self.team != hitent.team))
121 if(hitent.takedamage)
122 Damage(hitent, self, self, ((self.dmg < 0) ? 100000 : (self.dmg * frametime)), DEATH_HURTTRIGGER, hitloc, '0 0 0');
126 float laser_SendEntity(entity to, float fl)
128 WriteByte(MSG_ENTITY, ENT_CLIENT_LASER);
129 fl = fl - (fl & 0xF0); // use that bit to indicate finite length laser
130 if(self.spawnflags & 2)
134 if(self.scale != 1 || self.modelscale != 1)
136 if(self.spawnflags & 4)
138 WriteByte(MSG_ENTITY, fl);
141 WriteCoord(MSG_ENTITY, self.origin_x);
142 WriteCoord(MSG_ENTITY, self.origin_y);
143 WriteCoord(MSG_ENTITY, self.origin_z);
147 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
148 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
149 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
151 WriteByte(MSG_ENTITY, self.alpha * 255.0);
154 WriteByte(MSG_ENTITY, bound(0, self.scale * 16.0, 255));
155 WriteByte(MSG_ENTITY, bound(0, self.modelscale * 16.0, 255));
157 if((fl & 0x80) || !(fl & 0x10)) // effect doesn't need sending if the laser is infinite and has collision testing turned off
158 WriteShort(MSG_ENTITY, self.cnt + 1);
164 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
165 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
166 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
170 WriteAngle(MSG_ENTITY, self.mangle_x);
171 WriteAngle(MSG_ENTITY, self.mangle_y);
175 WriteByte(MSG_ENTITY, self.state);
179 /*QUAKED spawnfunc_misc_laser (.5 .5 .5) ? START_ON DEST_IS_FIXED
180 Any object touching the beam will be hurt
183 spawnfunc_target_position where the laser ends
185 name of beam end effect to use
187 color of the beam (default: red)
189 damage per second (-1 for a laser that kills immediately)
193 self.state = !self.state;
200 if(self.spawnflags & 1)
206 spawnfunc(misc_laser)
210 if(self.mdl == "none")
214 self.cnt = _particleeffectnum(self.mdl);
217 self.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
223 self.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
230 if(self.colormod == '0 0 0')
232 self.colormod = '1 0 0';
233 if(self.message == "")
234 self.message = "saw the light";
235 if (self.message2 == "")
236 self.message2 = "was pushed into a laser by";
241 else if(self.modelscale < 0)
243 self.think = misc_laser_think;
244 self.nextthink = time;
245 InitializeEntity(self, misc_laser_init, INITPRIO_FINDTARGET);
247 self.mangle = self.angles;
249 Net_LinkEntity(self, false, 0, laser_SendEntity);
253 self.reset = laser_reset;
255 self.use = laser_use;
262 // a laser goes from origin in direction angles
263 // it has color 'colormod'
264 // and stops when something is in the way
266 class(Laser) .int cnt; // end effect
267 class(Laser) .vector colormod;
268 class(Laser) .int state; // on-off
269 class(Laser) .int count; // flags for the laser
270 class(Laser) .vector velocity;
271 class(Laser) .float alpha;
272 class(Laser) .float scale; // scaling factor of the thickness
273 class(Laser) .float modelscale; // scaling factor of the dlight
279 InterpolateOrigin_Do();
280 if(self.count & 0x80)
282 if(self.count & 0x10)
284 trace_endpos = self.velocity;
285 trace_dphitq3surfaceflags = 0;
288 traceline(self.origin, self.velocity, 0, self);
292 if(self.count & 0x10)
294 makevectors(self.angles);
295 trace_endpos = self.origin + v_forward * 1048576;
296 trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY;
300 makevectors(self.angles);
301 traceline(self.origin, self.origin + v_forward * 32768, 0, self);
302 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
303 trace_endpos = self.origin + v_forward * 1048576;
310 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, self.alpha, DRAWFLAG_NORMAL, view_origin);
314 Draw_CylindricLine(self.origin, trace_endpos, self.scale, "particles/laserbeam", 0, time * 3, self.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin);
317 if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
320 pointparticles(self.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
321 if(self.colormod != '0 0 0' && self.modelscale != 0)
322 adddynamiclight(trace_endpos + trace_plane_normal * 1, self.modelscale, self.colormod * 5);
328 InterpolateOrigin_Undo();
330 // 30 bytes, or 13 bytes for just moving
332 self.count = (f & 0xF0);
334 if(self.count & 0x80)
335 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
337 self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
341 self.origin_x = ReadCoord();
342 self.origin_y = ReadCoord();
343 self.origin_z = ReadCoord();
344 setorigin(self, self.origin);
348 self.colormod_x = ReadByte() / 255.0;
349 self.colormod_y = ReadByte() / 255.0;
350 self.colormod_z = ReadByte() / 255.0;
352 self.alpha = ReadByte() / 255.0;
356 self.modelscale = 50;
359 self.scale *= ReadByte() / 16.0; // beam radius
360 self.modelscale *= ReadByte() / 16.0; // dlight radius
362 if((f & 0x80) || !(f & 0x10))
363 self.cnt = ReadShort() - 1; // effect number
371 self.velocity_x = ReadCoord();
372 self.velocity_y = ReadCoord();
373 self.velocity_z = ReadCoord();
377 self.angles_x = ReadAngle();
378 self.angles_y = ReadAngle();
382 self.state = ReadByte();
383 InterpolateOrigin_Note();
384 self.draw = Draw_Laser;