2 #include <lib/csqcmodel/interpolate.qh>
3 #include <client/main.qh>
4 #include <lib/csqcmodel/cl_model.qh>
9 REGISTER_NET_LINKED(ENT_CLIENT_LASER)
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 WITHSELF(self.enemy, SUB_UseTargets());
110 activator = self.enemy.pusher;
111 WITHSELF(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.m_id, hitloc, '0 0 0');
126 bool laser_SendEntity(entity this, entity to, float fl)
128 WriteHeader(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;
198 void laser_reset(entity this)
200 if(this.spawnflags & 1)
206 spawnfunc(misc_laser)
210 if(this.mdl == "none")
214 this.cnt = _particleeffectnum(this.mdl);
215 if(this.cnt < 0 && this.dmg)
216 this.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
222 this.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
229 if(this.colormod == '0 0 0')
231 this.colormod = '1 0 0';
232 if(this.message == "") this.message = "saw the light";
233 if (this.message2 == "") this.message2 = "was pushed into a laser by";
234 if(!this.scale) this.scale = 1;
235 if(!this.modelscale) this.modelscale = 1;
236 else if(this.modelscale < 0) this.modelscale = 0;
237 this.think = misc_laser_think;
238 this.nextthink = time;
239 InitializeEntity(this, misc_laser_init, INITPRIO_FINDTARGET);
241 this.mangle = this.angles;
243 Net_LinkEntity(this, false, 0, laser_SendEntity);
247 this.reset = laser_reset;
249 this.use = laser_use;
256 // a laser goes from origin in direction angles
257 // it has color 'colormod'
258 // and stops when something is in the way
260 class(Laser) .int cnt; // end effect
261 class(Laser) .vector colormod;
262 class(Laser) .int state; // on-off
263 class(Laser) .int count; // flags for the laser
264 class(Laser) .vector velocity;
265 class(Laser) .float alpha;
266 class(Laser) .float scale; // scaling factor of the thickness
267 class(Laser) .float modelscale; // scaling factor of the dlight
269 void Draw_Laser(entity this)
273 InterpolateOrigin_Do(this);
274 if(this.count & 0x80)
276 if(this.count & 0x10)
278 trace_endpos = this.velocity;
279 trace_dphitq3surfaceflags = 0;
282 traceline(this.origin, this.velocity, 0, this);
286 if(this.count & 0x10)
288 makevectors(this.angles);
289 trace_endpos = this.origin + v_forward * 1048576;
290 trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY;
294 makevectors(this.angles);
295 traceline(this.origin, this.origin + v_forward * 32768, 0, this);
296 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
297 trace_endpos = this.origin + v_forward * 1048576;
304 Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.colormod, this.alpha, DRAWFLAG_NORMAL, view_origin);
308 Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin);
311 if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
314 __pointparticles(this.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
315 if(this.colormod != '0 0 0' && this.modelscale != 0)
316 adddynamiclight(trace_endpos + trace_plane_normal * 1, this.modelscale, this.colormod * 5);
320 NET_HANDLE(ENT_CLIENT_LASER, bool isnew)
322 InterpolateOrigin_Undo(self);
324 // 30 bytes, or 13 bytes for just moving
326 self.count = (f & 0xF0);
328 if(self.count & 0x80)
329 self.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
331 self.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
335 self.origin_x = ReadCoord();
336 self.origin_y = ReadCoord();
337 self.origin_z = ReadCoord();
338 setorigin(self, self.origin);
342 self.colormod_x = ReadByte() / 255.0;
343 self.colormod_y = ReadByte() / 255.0;
344 self.colormod_z = ReadByte() / 255.0;
346 self.alpha = ReadByte() / 255.0;
350 self.modelscale = 50;
353 self.scale *= ReadByte() / 16.0; // beam radius
354 self.modelscale *= ReadByte() / 16.0; // dlight radius
356 if((f & 0x80) || !(f & 0x10))
357 self.cnt = ReadShort() - 1; // effect number
365 self.velocity_x = ReadCoord();
366 self.velocity_y = ReadCoord();
367 self.velocity_z = ReadCoord();
371 self.angles_x = ReadAngle();
372 self.angles_y = ReadAngle();
376 self.state = ReadByte();
380 InterpolateOrigin_Note(this);
381 self.draw = Draw_Laser;