X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;ds=sidebyside;f=qcsrc%2Fcommon%2Ftriggers%2Fmisc%2Flaser.qc;h=df88b750f245dbc7000deccd0a6785bf5ae1a300;hb=0b6694545ba935bbac13c20fc11842ba1850d972;hp=45bd21fd1b15cd32eda5a9b170fa0732711b7029;hpb=bebef6b9a1c5d5d79cb9cf11180dbb6cda6fcd29;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/triggers/misc/laser.qc b/qcsrc/common/triggers/misc/laser.qc index 45bd21fd1..df88b750f 100644 --- a/qcsrc/common/triggers/misc/laser.qc +++ b/qcsrc/common/triggers/misc/laser.qc @@ -16,12 +16,12 @@ void misc_laser_aim(entity this) vector a; if(this.enemy) { - if(this.spawnflags & 2) + if(this.spawnflags & LASER_FINITE) { if(this.enemy.origin != this.mangle) { this.mangle = this.enemy.origin; - this.SendFlags |= 2; + this.SendFlags |= SF_LASER_UPDATE_TARGET; } } else @@ -31,7 +31,7 @@ void misc_laser_aim(entity this) if(a != this.mangle) { this.mangle = a; - this.SendFlags |= 2; + this.SendFlags |= SF_LASER_UPDATE_TARGET; } } } @@ -40,12 +40,12 @@ void misc_laser_aim(entity this) if(this.angles != this.mangle) { this.mangle = this.angles; - this.SendFlags |= 2; + this.SendFlags |= SF_LASER_UPDATE_TARGET; } } if(this.origin != this.oldorigin) { - this.SendFlags |= 1; + this.SendFlags |= SF_LASER_UPDATE_ORIGIN; this.oldorigin = this.origin; } } @@ -65,7 +65,7 @@ void misc_laser_think(entity this) this.nextthink = time; - if(!this.state) + if(this.active == ACTIVE_NOT) return; misc_laser_aim(this); @@ -73,13 +73,13 @@ void misc_laser_think(entity this) if(this.enemy) { o = this.enemy.origin; - if (!(this.spawnflags & 2)) - o = this.origin + normalize(o - this.origin) * 32768; + if (!(this.spawnflags & LASER_FINITE)) + o = this.origin + normalize(o - this.origin) * LASER_BEAM_MAXLENGTH; } else { makevectors(this.mangle); - o = this.origin + v_forward * 32768; + o = this.origin + v_forward * LASER_BEAM_MAXLENGTH; } if(this.dmg || this.enemy.target != "") @@ -115,54 +115,50 @@ void misc_laser_think(entity this) if(this.dmg) { if(this.team) - if(((this.spawnflags & 8) == 0) == (this.team != hitent.team)) + if(((this.spawnflags & LASER_INVERT_TEAM) == 0) == (this.team != hitent.team)) return; if(hitent.takedamage) Damage(hitent, this, this, ((this.dmg < 0) ? 100000 : (this.dmg * frametime)), DEATH_HURTTRIGGER.m_id, DMG_NOWEP, hitloc, '0 0 0'); } } -bool laser_SendEntity(entity this, entity to, float fl) +bool laser_SendEntity(entity this, entity to, float sendflags) { WriteHeader(MSG_ENTITY, ENT_CLIENT_LASER); - fl = fl - (fl & 0xF0); // use that bit to indicate finite length laser - if(this.spawnflags & 2) - fl |= 0x80; + sendflags = sendflags & 0x0F; // use that bit to indicate finite length laser + if(this.spawnflags & LASER_FINITE) + sendflags |= SF_LASER_FINITE; if(this.alpha) - fl |= 0x40; + sendflags |= SF_LASER_ALPHA; if(this.scale != 1 || this.modelscale != 1) - fl |= 0x20; - if(this.spawnflags & 4) - fl |= 0x10; - WriteByte(MSG_ENTITY, fl); - if(fl & 1) + sendflags |= SF_LASER_SCALE; + if(this.spawnflags & LASER_NOTRACE) + sendflags |= SF_LASER_NOTRACE; + WriteByte(MSG_ENTITY, sendflags); + if(sendflags & SF_LASER_UPDATE_ORIGIN) { - WriteCoord(MSG_ENTITY, this.origin_x); - WriteCoord(MSG_ENTITY, this.origin_y); - WriteCoord(MSG_ENTITY, this.origin_z); + WriteVector(MSG_ENTITY, this.origin); } - if(fl & 8) + if(sendflags & SF_LASER_UPDATE_EFFECT) { - WriteByte(MSG_ENTITY, this.colormod_x * 255.0); - WriteByte(MSG_ENTITY, this.colormod_y * 255.0); - WriteByte(MSG_ENTITY, this.colormod_z * 255.0); - if(fl & 0x40) + WriteByte(MSG_ENTITY, this.beam_color.x * 255.0); + WriteByte(MSG_ENTITY, this.beam_color.y * 255.0); + WriteByte(MSG_ENTITY, this.beam_color.z * 255.0); + if(sendflags & SF_LASER_ALPHA) WriteByte(MSG_ENTITY, this.alpha * 255.0); - if(fl & 0x20) + if(sendflags & SF_LASER_SCALE) { WriteByte(MSG_ENTITY, bound(0, this.scale * 16.0, 255)); WriteByte(MSG_ENTITY, bound(0, this.modelscale * 16.0, 255)); } - if((fl & 0x80) || !(fl & 0x10)) // effect doesn't need sending if the laser is infinite and has collision testing turned off - WriteShort(MSG_ENTITY, this.cnt + 1); + if((sendflags & SF_LASER_FINITE) || !(sendflags & SF_LASER_NOTRACE)) // effect doesn't need sending if the laser is infinite and has collision testing turned off + WriteShort(MSG_ENTITY, this.cnt); } - if(fl & 2) + if(sendflags & SF_LASER_UPDATE_TARGET) { - if(fl & 0x80) + if(sendflags & SF_LASER_FINITE) { - WriteCoord(MSG_ENTITY, this.enemy.origin_x); - WriteCoord(MSG_ENTITY, this.enemy.origin_y); - WriteCoord(MSG_ENTITY, this.enemy.origin_z); + WriteVector(MSG_ENTITY, this.enemy.origin); } else { @@ -170,9 +166,9 @@ bool laser_SendEntity(entity this, entity to, float fl) WriteAngle(MSG_ENTITY, this.mangle_y); } } - if(fl & 4) - WriteByte(MSG_ENTITY, this.state); - return 1; + if(sendflags & SF_LASER_UPDATE_ACTIVE) + WriteByte(MSG_ENTITY, this.active); + return true; } /*QUAKED spawnfunc_misc_laser (.5 .5 .5) ? START_ON DEST_IS_FIXED @@ -182,24 +178,41 @@ Keys: spawnfunc_target_position where the laser ends "mdl" name of beam end effect to use -"colormod" +"beam_color" color of the beam (default: red) "dmg" damage per second (-1 for a laser that kills immediately) */ -void laser_use(entity this, entity actor, entity trigger) + +void laser_setactive(entity this, int act) { - this.state = !this.state; - this.SendFlags |= 4; - misc_laser_aim(this); + int old_status = this.active; + if(act == ACTIVE_TOGGLE) + { + if(this.active == ACTIVE_ACTIVE) + { + this.active = ACTIVE_NOT; + } + else + { + this.active = ACTIVE_ACTIVE; + } + } + else + { + this.active = act; + } + + if (this.active != old_status) + { + this.SendFlags |= SF_LASER_UPDATE_ACTIVE; + misc_laser_aim(this); + } } -void laser_reset(entity this) +void laser_use(entity this, entity actor, entity trigger) { - if(this.spawnflags & 1) - this.state = 1; - else - this.state = 0; + this.setactive(this, ACTIVE_TOGGLE); } spawnfunc(misc_laser) @@ -225,14 +238,38 @@ spawnfunc(misc_laser) if(this.cnt < 0) this.cnt = -1; - if(this.colormod == '0 0 0') + if(!this.beam_color && this.colormod) + { + LOG_WARN("misc_laser uses legacy field 'colormod', please use 'beam_color' instead"); + this.beam_color = this.colormod; + } + + if(this.beam_color == '0 0 0') + { if(!this.alpha) - this.colormod = '1 0 0'; - if(this.message == "") this.message = "saw the light"; - if (this.message2 == "") this.message2 = "was pushed into a laser by"; - if(!this.scale) this.scale = 1; - if(!this.modelscale) this.modelscale = 1; - else if(this.modelscale < 0) this.modelscale = 0; + this.beam_color = '1 0 0'; + } + + if(this.message == "") + { + this.message = "saw the light"; + } + if (this.message2 == "") + { + this.message2 = "was pushed into a laser by"; + } + if(!this.scale) + { + this.scale = 1; + } + if(!this.modelscale) + { + this.modelscale = 1; + } + else if(this.modelscale < 0) + { + this.modelscale = 0; + } setthink(this, misc_laser_think); this.nextthink = time; InitializeEntity(this, misc_laser_init, INITPRIO_FINDTARGET); @@ -241,38 +278,40 @@ spawnfunc(misc_laser) Net_LinkEntity(this, false, 0, laser_SendEntity); + this.setactive = laser_setactive; + IFTARGETED { - this.reset = laser_reset; - this.reset(this); + // backwards compatibility this.use = laser_use; } - else - this.state = 1; + + this.reset = generic_netlinked_reset; + this.reset(this); } #elif defined(CSQC) // a laser goes from origin in direction angles -// it has color 'colormod' +// it has color 'beam_color' // and stops when something is in the way entityclass(Laser); -class(Laser) .int cnt; // end effect -class(Laser) .vector colormod; -class(Laser) .int state; // on-off -class(Laser) .int count; // flags for the laser -class(Laser) .vector velocity; -class(Laser) .float alpha; -class(Laser) .float scale; // scaling factor of the thickness -class(Laser) .float modelscale; // scaling factor of the dlight +classfield(Laser) .int cnt; // end effect +classfield(Laser) .vector colormod; +classfield(Laser) .int state; // on-off +classfield(Laser) .int count; // flags for the laser +classfield(Laser) .vector velocity; // laser endpoint if it is FINITE +classfield(Laser) .float alpha; +classfield(Laser) .float scale; // scaling factor of the thickness +classfield(Laser) .float modelscale; // scaling factor of the dlight void Draw_Laser(entity this) { - if(!this.state) + if(this.active == ACTIVE_NOT) return; InterpolateOrigin_Do(this); - if(this.count & 0x80) + if(this.count & SF_LASER_FINITE) { - if(this.count & 0x10) + if(this.count & SF_LASER_NOTRACE) { trace_endpos = this.velocity; trace_dphitq3surfaceflags = 0; @@ -282,37 +321,37 @@ void Draw_Laser(entity this) } else { - if(this.count & 0x10) + if(this.count & SF_LASER_NOTRACE) { makevectors(this.angles); - trace_endpos = this.origin + v_forward * 1048576; + trace_endpos = this.origin + v_forward * LASER_BEAM_MAXWORLDSIZE; trace_dphitq3surfaceflags = Q3SURFACEFLAG_SKY; } else { makevectors(this.angles); - traceline(this.origin, this.origin + v_forward * 32768, 0, this); + traceline(this.origin, this.origin + v_forward * LASER_BEAM_MAXLENGTH, 0, this); if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SKY) - trace_endpos = this.origin + v_forward * 1048576; + trace_endpos = this.origin + v_forward * LASER_BEAM_MAXWORLDSIZE; } } if(this.scale != 0) { if(this.alpha) { - Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.colormod, this.alpha, DRAWFLAG_NORMAL, view_origin); + Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.beam_color, this.alpha, DRAWFLAG_NORMAL, view_origin); } else { - Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.colormod, 0.5, DRAWFLAG_ADDITIVE, view_origin); + Draw_CylindricLine(this.origin, trace_endpos, this.scale, "particles/laserbeam", 0, time * 3, this.beam_color, 0.5, DRAWFLAG_ADDITIVE, view_origin); } } if (!(trace_dphitq3surfaceflags & (Q3SURFACEFLAG_SKY | Q3SURFACEFLAG_NOIMPACT))) { if(this.cnt >= 0) __pointparticles(this.cnt, trace_endpos, trace_plane_normal, drawframetime * 1000); - if(this.colormod != '0 0 0' && this.modelscale != 0) - adddynamiclight(trace_endpos + trace_plane_normal * 1, this.modelscale, this.colormod * 5); + if(this.beam_color != '0 0 0' && this.modelscale != 0) + adddynamiclight(trace_endpos + trace_plane_normal * 1, this.modelscale, this.beam_color * 5); } } @@ -321,49 +360,45 @@ NET_HANDLE(ENT_CLIENT_LASER, bool isnew) InterpolateOrigin_Undo(this); // 30 bytes, or 13 bytes for just moving - int f = ReadByte(); - this.count = (f & 0xF0); + int sendflags = ReadByte(); + this.count = (sendflags & 0xF0); - if(this.count & 0x80) + if(this.count & SF_LASER_FINITE) this.iflags = IFLAG_VELOCITY | IFLAG_ORIGIN; else this.iflags = IFLAG_ANGLES | IFLAG_ORIGIN; - if(f & 1) + if(sendflags & SF_LASER_UPDATE_ORIGIN) { - this.origin_x = ReadCoord(); - this.origin_y = ReadCoord(); - this.origin_z = ReadCoord(); + this.origin = ReadVector(); setorigin(this, this.origin); } - if(f & 8) + if(sendflags & SF_LASER_UPDATE_EFFECT) { - this.colormod_x = ReadByte() / 255.0; - this.colormod_y = ReadByte() / 255.0; - this.colormod_z = ReadByte() / 255.0; - if(f & 0x40) + this.beam_color.x = ReadByte() / 255.0; + this.beam_color.y = ReadByte() / 255.0; + this.beam_color.z = ReadByte() / 255.0; + if(sendflags & SF_LASER_ALPHA) this.alpha = ReadByte() / 255.0; else this.alpha = 0; - this.scale = 2; - this.modelscale = 50; - if(f & 0x20) + this.scale = 2; // NOTE: why 2? + this.modelscale = 50; // NOTE: why 50? + if(sendflags & SF_LASER_SCALE) { this.scale *= ReadByte() / 16.0; // beam radius this.modelscale *= ReadByte() / 16.0; // dlight radius } - if((f & 0x80) || !(f & 0x10)) - this.cnt = ReadShort() - 1; // effect number + if((sendflags & SF_LASER_FINITE) || !(sendflags & SF_LASER_NOTRACE)) + this.cnt = ReadShort(); // effect number else this.cnt = 0; } - if(f & 2) + if(sendflags & SF_LASER_UPDATE_TARGET) { - if(f & 0x80) + if(sendflags & SF_LASER_FINITE) { - this.velocity_x = ReadCoord(); - this.velocity_y = ReadCoord(); - this.velocity_z = ReadCoord(); + this.velocity = ReadVector(); } else { @@ -371,8 +406,8 @@ NET_HANDLE(ENT_CLIENT_LASER, bool isnew) this.angles_y = ReadAngle(); } } - if(f & 4) - this.state = ReadByte(); + if(sendflags & SF_LASER_UPDATE_ACTIVE) + this.active = ReadByte(); return = true;