From f281ed110c47171745b6ebd0b14bcc6ea6fd9405 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 4 Dec 2015 15:09:35 +1000 Subject: [PATCH] Make the trigger functions handle fixing of trigger model, fixes most triggers with odd sizes and angles --- qcsrc/common/triggers/func/door.qc | 2 +- qcsrc/common/triggers/func/ladder.qc | 60 +----------- qcsrc/common/triggers/func/plat.qc | 2 +- qcsrc/common/triggers/func/train.qc | 2 +- qcsrc/common/triggers/trigger/impulse.qc | 17 ++-- qcsrc/common/triggers/trigger/jumppads.qc | 64 +++++-------- qcsrc/common/triggers/trigger/keylock.qc | 2 +- qcsrc/common/triggers/trigger/swamp.qc | 12 +-- qcsrc/common/triggers/trigger/teleport.qc | 73 ++------------- qcsrc/common/triggers/triggers.qc | 106 +++++++++++++++------- qcsrc/common/triggers/triggers.qh | 2 +- 11 files changed, 127 insertions(+), 215 deletions(-) diff --git a/qcsrc/common/triggers/func/door.qc b/qcsrc/common/triggers/func/door.qc index 87496b217..35a2ff8f7 100644 --- a/qcsrc/common/triggers/func/door.qc +++ b/qcsrc/common/triggers/func/door.qc @@ -643,7 +643,7 @@ float door_send(entity to, float sf) WriteString(MSG_ENTITY, self.model); - trigger_common_write(true); + trigger_common_write(self, true); WriteCoord(MSG_ENTITY, self.pos1_x); WriteCoord(MSG_ENTITY, self.pos1_y); diff --git a/qcsrc/common/triggers/func/ladder.qc b/qcsrc/common/triggers/func/ladder.qc index edba03233..bcf994ff4 100644 --- a/qcsrc/common/triggers/func/ladder.qc +++ b/qcsrc/common/triggers/func/ladder.qc @@ -20,35 +20,11 @@ bool func_ladder_send(entity to, int sf) {SELFPARAM(); WriteHeader(MSG_ENTITY, ENT_CLIENT_LADDER); - int f = 0; - if(self.warpzone_isboxy) - BITSET_ASSIGN(f, 1); - if(self.origin != '0 0 0') - BITSET_ASSIGN(f, 4); - WriteByte(MSG_ENTITY, f); - - // we need THESE to render the warpzone (and cull properly)... - if(f & 4) - { - WriteCoord(MSG_ENTITY, self.origin.x); - WriteCoord(MSG_ENTITY, self.origin.y); - WriteCoord(MSG_ENTITY, self.origin.z); - } - - WriteShort(MSG_ENTITY, self.modelindex); - WriteCoord(MSG_ENTITY, self.mins.x); - WriteCoord(MSG_ENTITY, self.mins.y); - WriteCoord(MSG_ENTITY, self.mins.z); - WriteCoord(MSG_ENTITY, self.maxs.x); - WriteCoord(MSG_ENTITY, self.maxs.y); - WriteCoord(MSG_ENTITY, self.maxs.z); - WriteByte(MSG_ENTITY, bound(1, self.scale * 16, 255)); - WriteString(MSG_ENTITY, self.classname); WriteByte(MSG_ENTITY, self.skin); WriteCoord(MSG_ENTITY, self.speed); - trigger_common_write(false); + trigger_common_write(self, false); return true; } @@ -62,22 +38,9 @@ void func_ladder_link() void func_ladder_init() { - //self.mdl = self.model; - string m = self.model; - WarpZoneLib_ExactTrigger_Init(); - if(m != "") - { - precache_model(m); - _setmodel(self, m); // no precision needed - } - setorigin(self, self.origin); - if(self.scale) - setsize(self, self.mins * self.scale, self.maxs * self.scale); - else - setsize(self, self.mins, self.maxs); self.touch = func_ladder_touch; - BITSET_ASSIGN(self.effects, EF_NODEPTHTEST); + trigger_init(self); func_ladder_link(); } @@ -102,25 +65,6 @@ void func_ladder_remove() NET_HANDLE(ENT_CLIENT_LADDER, bool isnew) { - int f = ReadByte(); - self.warpzone_isboxy = (f & 1); - if(f & 4) - { - self.origin_x = ReadCoord(); - self.origin_y = ReadCoord(); - self.origin_z = ReadCoord(); - } - else - self.origin = '0 0 0'; - - self.modelindex = ReadShort(); - self.mins_x = ReadCoord(); - self.mins_y = ReadCoord(); - self.mins_z = ReadCoord(); - self.maxs_x = ReadCoord(); - self.maxs_y = ReadCoord(); - self.maxs_z = ReadCoord(); - self.scale = ReadByte() / 16; self.classname = strzone(ReadString()); self.skin = ReadByte(); self.speed = ReadCoord(); diff --git a/qcsrc/common/triggers/func/plat.qc b/qcsrc/common/triggers/func/plat.qc index 9e98d12ba..ea546164c 100644 --- a/qcsrc/common/triggers/func/plat.qc +++ b/qcsrc/common/triggers/func/plat.qc @@ -23,7 +23,7 @@ float plat_send(entity to, float sf) WriteString(MSG_ENTITY, self.model); - trigger_common_write(true); + trigger_common_write(self, true); WriteCoord(MSG_ENTITY, self.pos1_x); WriteCoord(MSG_ENTITY, self.pos1_y); diff --git a/qcsrc/common/triggers/func/train.qc b/qcsrc/common/triggers/func/train.qc index 80350e743..e02b917d1 100644 --- a/qcsrc/common/triggers/func/train.qc +++ b/qcsrc/common/triggers/func/train.qc @@ -117,7 +117,7 @@ float train_send(entity to, float sf) WriteString(MSG_ENTITY, self.model); - trigger_common_write(true); + trigger_common_write(self, true); WriteString(MSG_ENTITY, self.curvetarget); diff --git a/qcsrc/common/triggers/trigger/impulse.qc b/qcsrc/common/triggers/trigger/impulse.qc index abb40563e..c2b59a3e0 100644 --- a/qcsrc/common/triggers/trigger/impulse.qc +++ b/qcsrc/common/triggers/trigger/impulse.qc @@ -168,27 +168,28 @@ bool trigger_impulse_send(entity this, entity to, int sf) { WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_IMPULSE); - WriteInt24_t(MSG_ENTITY, self.spawnflags); - WriteCoord(MSG_ENTITY, self.radius); - WriteCoord(MSG_ENTITY, self.strength); - WriteByte(MSG_ENTITY, self.falloff); - WriteByte(MSG_ENTITY, self.active); + WriteInt24_t(MSG_ENTITY, this.spawnflags); + WriteCoord(MSG_ENTITY, this.radius); + WriteCoord(MSG_ENTITY, this.strength); + WriteByte(MSG_ENTITY, this.falloff); + WriteByte(MSG_ENTITY, this.active); - trigger_common_write(true); + trigger_common_write(this, true); return true; } void trigger_impulse_link() { - Net_LinkEntity(self, 0, false, trigger_impulse_send); + trigger_link(self, trigger_impulse_send); } spawnfunc(trigger_impulse) { self.active = ACTIVE_ACTIVE; - EXACTTRIGGER_INIT; + trigger_init(self); + if(self.radius) { if(!self.strength) self.strength = 2000 * autocvar_g_triggerimpulse_radial_multiplier; diff --git a/qcsrc/common/triggers/trigger/jumppads.qc b/qcsrc/common/triggers/trigger/jumppads.qc index ea3170a24..cdd383e53 100644 --- a/qcsrc/common/triggers/trigger/jumppads.qc +++ b/qcsrc/common/triggers/trigger/jumppads.qc @@ -323,23 +323,13 @@ void trigger_push_findtarget() float trigger_push_send(entity this, entity to, float sf) { WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_PUSH); - WriteByte(MSG_ENTITY, sf); - if(sf & 1) - { - WriteByte(MSG_ENTITY, self.team); - WriteInt24_t(MSG_ENTITY, self.spawnflags); - WriteByte(MSG_ENTITY, self.active); - WriteCoord(MSG_ENTITY, self.height); + WriteByte(MSG_ENTITY, self.team); + WriteInt24_t(MSG_ENTITY, self.spawnflags); + WriteByte(MSG_ENTITY, self.active); + WriteCoord(MSG_ENTITY, self.height); - trigger_common_write(true); - } - - if(sf & 2) - { - WriteByte(MSG_ENTITY, self.team); - WriteByte(MSG_ENTITY, self.active); - } + trigger_common_write(self, true); return true; } @@ -351,8 +341,7 @@ void trigger_push_updatelink() void trigger_push_link() { - BITSET_ASSIGN(self.effects, EF_NODEPTHTEST); - Net_LinkEntity(self, false, 0, trigger_push_send); + trigger_link(self, trigger_push_send); } /* @@ -371,7 +360,7 @@ spawnfunc(trigger_push) { SetMovedir(self); - EXACTTRIGGER_INIT; + trigger_init(self); self.active = ACTIVE_ACTIVE; self.use = trigger_push_use; @@ -424,32 +413,23 @@ spawnfunc(target_position) { make_pure(this); target_push_link(); } NET_HANDLE(ENT_CLIENT_TRIGGER_PUSH, bool isnew) { make_pure(this); - float sf = ReadByte(); - if(sf & 1) - { - self.classname = "jumppad"; - int mytm = ReadByte(); if(mytm) { self.team = mytm - 1; } - self.spawnflags = ReadInt24_t(); - self.active = ReadByte(); - self.height = ReadCoord(); - - trigger_common_read(true); - - self.entremove = trigger_remove_generic; - self.solid = SOLID_TRIGGER; - //self.draw = trigger_draw_generic; - self.move_touch = trigger_push_touch; - self.drawmask = MASK_NORMAL; - self.move_time = time; - defer(self, 0.25, trigger_push_findtarget); - } + self.classname = "jumppad"; + int mytm = ReadByte(); if(mytm) { self.team = mytm - 1; } + self.spawnflags = ReadInt24_t(); + self.active = ReadByte(); + self.height = ReadCoord(); + + trigger_common_read(true); + + self.entremove = trigger_remove_generic; + self.solid = SOLID_TRIGGER; + //self.draw = trigger_draw_generic; + self.move_touch = trigger_push_touch; + self.drawmask = MASK_NORMAL; + self.move_time = time; + defer(self, 0.25, trigger_push_findtarget); - if(sf & 2) - { - self.team = ReadByte(); - self.active = ReadByte(); - } return true; } diff --git a/qcsrc/common/triggers/trigger/keylock.qc b/qcsrc/common/triggers/trigger/keylock.qc index 98b121d6e..b628eaf82 100644 --- a/qcsrc/common/triggers/trigger/keylock.qc +++ b/qcsrc/common/triggers/trigger/keylock.qc @@ -104,7 +104,7 @@ bool trigger_keylock_send(entity to, int sf) WriteInt24_t(MSG_ENTITY, self.itemkeys); WriteByte(MSG_ENTITY, self.height); - trigger_common_write(true); + trigger_common_write(self, true); return true; } diff --git a/qcsrc/common/triggers/trigger/swamp.qc b/qcsrc/common/triggers/trigger/swamp.qc index 768a3c78b..2a03db78d 100644 --- a/qcsrc/common/triggers/trigger/swamp.qc +++ b/qcsrc/common/triggers/trigger/swamp.qc @@ -99,18 +99,18 @@ float swamp_send(entity this, entity to, float sf) { WriteHeader(MSG_ENTITY, ENT_CLIENT_SWAMP); - WriteByte(MSG_ENTITY, self.dmg); // can probably get away with using a single byte here - WriteByte(MSG_ENTITY, self.swamp_slowdown); - WriteByte(MSG_ENTITY, self.swamp_interval); + WriteByte(MSG_ENTITY, this.dmg); // can probably get away with using a single byte here + WriteByte(MSG_ENTITY, this.swamp_slowdown); + WriteByte(MSG_ENTITY, this.swamp_interval); - trigger_common_write(false); + trigger_common_write(this, false); return true; } void swamp_link() {SELFPARAM(); - Net_LinkEntity(self, false, 0, swamp_send); + trigger_link(self, swamp_send); } /*QUAKED spawnfunc_trigger_swamp (.5 .5 .5) ? @@ -120,7 +120,7 @@ get slowd down and damaged spawnfunc(trigger_swamp) { // Init stuff - EXACTTRIGGER_INIT; + trigger_init(self); self.touch = swamp_touch; // Setup default keys, if missing diff --git a/qcsrc/common/triggers/trigger/teleport.qc b/qcsrc/common/triggers/trigger/teleport.qc index 252ead261..48b0341d3 100644 --- a/qcsrc/common/triggers/trigger/teleport.qc +++ b/qcsrc/common/triggers/trigger/teleport.qc @@ -56,67 +56,31 @@ void Teleport_Touch () } #ifdef SVQC -float trigger_teleport_send(entity to, float sf) -{SELFPARAM(); +float trigger_teleport_send(entity this, entity to, float sf) +{ WriteHeader(MSG_ENTITY, ENT_CLIENT_TRIGGER_TELEPORT); - int f = 0; - if(self.warpzone_isboxy) - BITSET_ASSIGN(f, 1); - if(self.origin != '0 0 0') - BITSET_ASSIGN(f, 4); - WriteByte(MSG_ENTITY, f); - - if(f & 4) - { - WriteCoord(MSG_ENTITY, self.origin.x); - WriteCoord(MSG_ENTITY, self.origin.y); - WriteCoord(MSG_ENTITY, self.origin.z); - } + WriteByte(MSG_ENTITY, this.team); + WriteInt24_t(MSG_ENTITY, this.spawnflags); + WriteByte(MSG_ENTITY, this.active); + WriteCoord(MSG_ENTITY, this.speed); - WriteShort(MSG_ENTITY, self.modelindex); - WriteCoord(MSG_ENTITY, self.mins.x); - WriteCoord(MSG_ENTITY, self.mins.y); - WriteCoord(MSG_ENTITY, self.mins.z); - WriteCoord(MSG_ENTITY, self.maxs.x); - WriteCoord(MSG_ENTITY, self.maxs.y); - WriteCoord(MSG_ENTITY, self.maxs.z); - WriteByte(MSG_ENTITY, bound(1, self.scale * 16, 255)); - WriteByte(MSG_ENTITY, self.team); - WriteInt24_t(MSG_ENTITY, self.spawnflags); - WriteByte(MSG_ENTITY, self.active); - WriteCoord(MSG_ENTITY, self.speed); - - trigger_common_write(true); + trigger_common_write(this, true); return true; } void trigger_teleport_link(entity this) { - this.SendEntity = trigger_teleport_send; - this.SendFlags = 0xFFFFFF; + trigger_link(this, trigger_teleport_send); } spawnfunc(trigger_teleport) { self.angles = '0 0 0'; - string m = self.model; - WarpZoneLib_ExactTrigger_Init(); - if(m != "") - { - precache_model(m); - _setmodel(self, m); // no precision needed - } - setorigin(self, self.origin); - if(self.scale) - setsize(self, self.mins * self.scale, self.maxs * self.scale); - else - setsize(self, self.mins, self.maxs); - self.active = ACTIVE_ACTIVE; - BITSET_ASSIGN(self.effects, EF_NODEPTHTEST); + trigger_init(self); self.use = trigger_teleport_use; // this must be called to spawn the teleport waypoints for bots @@ -134,25 +98,6 @@ spawnfunc(trigger_teleport) #elif defined(CSQC) NET_HANDLE(ENT_CLIENT_TRIGGER_TELEPORT, bool isnew) { - int f = ReadByte(); - self.warpzone_isboxy = (f & 1); - if(f & 4) - { - self.origin_x = ReadCoord(); - self.origin_y = ReadCoord(); - self.origin_z = ReadCoord(); - } - else - self.origin = '0 0 0'; - - self.modelindex = ReadShort(); - self.mins_x = ReadCoord(); - self.mins_y = ReadCoord(); - self.mins_z = ReadCoord(); - self.maxs_x = ReadCoord(); - self.maxs_y = ReadCoord(); - self.maxs_z = ReadCoord(); - self.scale = ReadByte() / 16; self.classname = "trigger_teleport"; int mytm = ReadByte(); if(mytm) { self.team = mytm - 1; } self.spawnflags = ReadInt24_t(); diff --git a/qcsrc/common/triggers/triggers.qc b/qcsrc/common/triggers/triggers.qc index cce879eed..cd1d0260c 100644 --- a/qcsrc/common/triggers/triggers.qc +++ b/qcsrc/common/triggers/triggers.qc @@ -21,47 +21,82 @@ void FixSize(entity e) } #ifdef SVQC -void trigger_common_write(bool withtarget) -{SELFPARAM(); - WriteByte(MSG_ENTITY, self.warpzone_isboxy); - WriteByte(MSG_ENTITY, self.scale); - if(withtarget) - { - WriteString(MSG_ENTITY, self.target); - WriteString(MSG_ENTITY, self.target2); - WriteString(MSG_ENTITY, self.target3); - WriteString(MSG_ENTITY, self.target4); - WriteString(MSG_ENTITY, self.targetname); - WriteString(MSG_ENTITY, self.killtarget); +void trigger_init(entity this) +{ + string m = this.model; + WITH(entity, self, this, WarpZoneLib_ExactTrigger_Init()); + if(m != "") + { + precache_model(m); + _setmodel(this, m); // no precision needed } + setorigin(this, this.origin); + if(this.scale) + setsize(this, this.mins * this.scale, this.maxs * this.scale); + else + setsize(this, this.mins, this.maxs); - WriteCoord(MSG_ENTITY, self.origin_x); - WriteCoord(MSG_ENTITY, self.origin_y); - WriteCoord(MSG_ENTITY, self.origin_z); + BITSET_ASSIGN(this.effects, EF_NODEPTHTEST); +} - WriteCoord(MSG_ENTITY, self.mins_x); - WriteCoord(MSG_ENTITY, self.mins_y); - WriteCoord(MSG_ENTITY, self.mins_z); - WriteCoord(MSG_ENTITY, self.maxs_x); - WriteCoord(MSG_ENTITY, self.maxs_y); - WriteCoord(MSG_ENTITY, self.maxs_z); +void trigger_link(entity this, bool(entity this, entity to, int sendflags) sendfunc) +{ + this.SendEntity = SendEntity_self; + this.SendEntity3 = sendfunc; + this.SendFlags = 0xFFFFFF; +} - WriteCoord(MSG_ENTITY, self.movedir_x); - WriteCoord(MSG_ENTITY, self.movedir_y); - WriteCoord(MSG_ENTITY, self.movedir_z); +void trigger_common_write(entity this, bool withtarget) +{ + int f = 0; + if(this.warpzone_isboxy) + BITSET_ASSIGN(f, 1); + if(this.origin != '0 0 0') + BITSET_ASSIGN(f, 4); + WriteByte(MSG_ENTITY, f); - WriteCoord(MSG_ENTITY, self.angles_x); - WriteCoord(MSG_ENTITY, self.angles_y); - WriteCoord(MSG_ENTITY, self.angles_z); + if(withtarget) + { + WriteString(MSG_ENTITY, this.target); + WriteString(MSG_ENTITY, this.target2); + WriteString(MSG_ENTITY, this.target3); + WriteString(MSG_ENTITY, this.target4); + WriteString(MSG_ENTITY, this.targetname); + WriteString(MSG_ENTITY, this.killtarget); + } + + if(f & 4) + { + WriteCoord(MSG_ENTITY, this.origin.x); + WriteCoord(MSG_ENTITY, this.origin.y); + WriteCoord(MSG_ENTITY, this.origin.z); + } + + WriteShort(MSG_ENTITY, this.modelindex); + WriteCoord(MSG_ENTITY, this.mins.x); + WriteCoord(MSG_ENTITY, this.mins.y); + WriteCoord(MSG_ENTITY, this.mins.z); + WriteCoord(MSG_ENTITY, this.maxs.x); + WriteCoord(MSG_ENTITY, this.maxs.y); + WriteCoord(MSG_ENTITY, this.maxs.z); + WriteByte(MSG_ENTITY, bound(1, this.scale * 16, 255)); + + WriteCoord(MSG_ENTITY, this.movedir_x); + WriteCoord(MSG_ENTITY, this.movedir_y); + WriteCoord(MSG_ENTITY, this.movedir_z); + + WriteCoord(MSG_ENTITY, this.angles_x); + WriteCoord(MSG_ENTITY, this.angles_y); + WriteCoord(MSG_ENTITY, this.angles_z); } #elif defined(CSQC) void trigger_common_read(bool withtarget) {SELFPARAM(); - self.warpzone_isboxy = ReadByte(); - self.scale = ReadByte(); + int f = ReadByte(); + self.warpzone_isboxy = (f & 1); if(withtarget) { @@ -79,17 +114,24 @@ void trigger_common_read(bool withtarget) self.killtarget = strzone(ReadString()); } - self.origin_x = ReadCoord(); - self.origin_y = ReadCoord(); - self.origin_z = ReadCoord(); + if(f & 4) + { + self.origin_x = ReadCoord(); + self.origin_y = ReadCoord(); + self.origin_z = ReadCoord(); + } + else + self.origin = '0 0 0'; setorigin(self, self.origin); + self.modelindex = ReadShort(); self.mins_x = ReadCoord(); self.mins_y = ReadCoord(); self.mins_z = ReadCoord(); self.maxs_x = ReadCoord(); self.maxs_y = ReadCoord(); self.maxs_z = ReadCoord(); + self.scale = ReadByte() / 16; setsize(self, self.mins, self.maxs); self.movedir_x = ReadCoord(); diff --git a/qcsrc/common/triggers/triggers.qh b/qcsrc/common/triggers/triggers.qh index c8e593f9c..31b8be441 100644 --- a/qcsrc/common/triggers/triggers.qh +++ b/qcsrc/common/triggers/triggers.qh @@ -22,7 +22,7 @@ const float SPAWNFLAG_NOTOUCH = 1; // used elsewhere (will fix) #ifdef SVQC -void trigger_common_write(bool withtarget); +void trigger_common_write(entity this, bool withtarget); string trigger_magicear_processmessage_forallears(entity source, float teamsay, entity privatesay, string msgin); -- 2.39.2