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)
13 void misc_laser_aim(entity this)
18 if(this.spawnflags & 2)
20 if(this.enemy.origin != this.mangle)
22 this.mangle = this.enemy.origin;
28 a = vectoangles(this.enemy.origin - this.origin);
39 if(this.angles != this.mangle)
41 this.mangle = this.angles;
45 if(this.origin != this.oldorigin)
48 this.oldorigin = this.origin;
52 void misc_laser_init(entity this)
55 self.enemy = find(world, targetname, self.target);
59 void misc_laser_think(entity this)
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 SUB_UseTargets(self.enemy, self.enemy.pusher, NULL);
109 SUB_UseTargets(self.enemy, self.enemy.pusher, NULL);
117 if(((self.spawnflags & 8) == 0) == (self.team != hitent.team))
119 if(hitent.takedamage)
120 Damage(hitent, self, self, ((self.dmg < 0) ? 100000 : (self.dmg * frametime)), DEATH_HURTTRIGGER.m_id, hitloc, '0 0 0');
124 bool laser_SendEntity(entity this, entity to, float fl)
126 WriteHeader(MSG_ENTITY, ENT_CLIENT_LASER);
127 fl = fl - (fl & 0xF0); // use that bit to indicate finite length laser
128 if(self.spawnflags & 2)
132 if(self.scale != 1 || self.modelscale != 1)
134 if(self.spawnflags & 4)
136 WriteByte(MSG_ENTITY, fl);
139 WriteCoord(MSG_ENTITY, self.origin_x);
140 WriteCoord(MSG_ENTITY, self.origin_y);
141 WriteCoord(MSG_ENTITY, self.origin_z);
145 WriteByte(MSG_ENTITY, self.colormod_x * 255.0);
146 WriteByte(MSG_ENTITY, self.colormod_y * 255.0);
147 WriteByte(MSG_ENTITY, self.colormod_z * 255.0);
149 WriteByte(MSG_ENTITY, self.alpha * 255.0);
152 WriteByte(MSG_ENTITY, bound(0, self.scale * 16.0, 255));
153 WriteByte(MSG_ENTITY, bound(0, self.modelscale * 16.0, 255));
155 if((fl & 0x80) || !(fl & 0x10)) // effect doesn't need sending if the laser is infinite and has collision testing turned off
156 WriteShort(MSG_ENTITY, self.cnt + 1);
162 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
163 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
164 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
168 WriteAngle(MSG_ENTITY, self.mangle_x);
169 WriteAngle(MSG_ENTITY, self.mangle_y);
173 WriteByte(MSG_ENTITY, self.state);
177 /*QUAKED spawnfunc_misc_laser (.5 .5 .5) ? START_ON DEST_IS_FIXED
178 Any object touching the beam will be hurt
181 spawnfunc_target_position where the laser ends
183 name of beam end effect to use
185 color of the beam (default: red)
187 damage per second (-1 for a laser that kills immediately)
189 void laser_use(entity this, entity actor, entity trigger)
191 this.state = !this.state;
193 misc_laser_aim(this);
196 void laser_reset(entity this)
198 if(this.spawnflags & 1)
204 spawnfunc(misc_laser)
208 if(this.mdl == "none")
212 this.cnt = _particleeffectnum(this.mdl);
213 if(this.cnt < 0 && this.dmg)
214 this.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
220 this.cnt = particleeffectnum(EFFECT_LASER_DEADLY);
227 if(this.colormod == '0 0 0')
229 this.colormod = '1 0 0';
230 if(this.message == "") this.message = "saw the light";
231 if (this.message2 == "") this.message2 = "was pushed into a laser by";
232 if(!this.scale) this.scale = 1;
233 if(!this.modelscale) this.modelscale = 1;
234 else if(this.modelscale < 0) this.modelscale = 0;
235 setthink(this, misc_laser_think);
236 this.nextthink = time;
237 InitializeEntity(this, misc_laser_init, INITPRIO_FINDTARGET);
239 this.mangle = this.angles;
241 Net_LinkEntity(this, false, 0, laser_SendEntity);
245 this.reset = laser_reset;
247 this.use = laser_use;
254 // a laser goes from origin in direction angles
255 // it has color 'colormod'
256 // and stops when something is in the way
258 class(Laser) .int cnt; // end effect
259 class(Laser) .vector colormod;
260 class(Laser) .int state; // on-off
261 class(Laser) .int count; // flags for the laser
262 class(Laser) .vector velocity;
263 class(Laser) .float alpha;
264 class(Laser) .float scale; // scaling factor of the thickness
265 class(Laser) .float modelscale; // scaling factor of the dlight
267 void Draw_Laser(entity this)
271 InterpolateOrigin_Do(this);
272 if(this.count & 0x80)
274 if(this.count & 0x10)
276 trace_endpos = this.velocity;
277 trace_dphitq3surfaceflags = 0;
280 traceline(this.origin, this.velocity, 0, this);
284 if(this.count & 0x10)
286 makevectors(this.angles);
287 trace_endpos = this.origin + v_forward * 1048576;
288 trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY;
292 makevectors(this.angles);
293 traceline(this.origin, this.origin + v_forward * 32768, 0, this);
294 if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY)
295 trace_endpos = this.origin + v_forward * 1048576;
302 Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.colormod, this.alpha, DRAWFLAG_NORMAL, view_origin);
306 Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin);
309 if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT)))
312 __pointparticles(this.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000);
313 if(this.colormod != '0 0 0' && this.modelscale != 0)
314 adddynamiclight(trace_endpos + trace_plane_normal * 1, this.modelscale, this.colormod * 5);
318 NET_HANDLE(ENT_CLIENT_LASER, bool isnew)
320 InterpolateOrigin_Undo(this);
322 // 30 bytes, or 13 bytes for just moving
324 this.count = (f & 0xF0);
326 if(this.count & 0x80)
327 this.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN;
329 this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN;
333 this.origin_x = ReadCoord();
334 this.origin_y = ReadCoord();
335 this.origin_z = ReadCoord();
336 setorigin(this, this.origin);
340 this.colormod_x = ReadByte() / 255.0;
341 this.colormod_y = ReadByte() / 255.0;
342 this.colormod_z = ReadByte() / 255.0;
344 this.alpha = ReadByte() / 255.0;
348 this.modelscale = 50;
351 this.scale *= ReadByte() / 16.0; // beam radius
352 this.modelscale *= ReadByte() / 16.0; // dlight radius
354 if((f & 0x80) || !(f & 0x10))
355 this.cnt = ReadShort() - 1; // effect number
363 this.velocity_x = ReadCoord();
364 this.velocity_y = ReadCoord();
365 this.velocity_z = ReadCoord();
369 this.angles_x = ReadAngle();
370 this.angles_y = ReadAngle();
374 this.state = ReadByte();
378 InterpolateOrigin_Note(this);
379 this.draw = Draw_Laser;