From 75edeb6bf721a0e50f1187ce1e80c02cadb46e99 Mon Sep 17 00:00:00 2001 From: Freddy Date: Wed, 7 Mar 2018 00:00:24 +0100 Subject: [PATCH] Common file for trigger/func states, replace more magic numbers --- qcsrc/common/triggers/func/breakable.qh | 4 +--- qcsrc/common/triggers/func/button.qc | 1 - qcsrc/common/triggers/func/button.qh | 1 + qcsrc/common/triggers/func/conveyor.qc | 27 ++++++++++++++----------- qcsrc/common/triggers/func/conveyor.qh | 2 ++ qcsrc/common/triggers/spawnflags.qh | 3 +++ qcsrc/common/triggers/states.qh | 17 ++++++++++++++++ qcsrc/common/triggers/subs.qh | 6 +----- 8 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 qcsrc/common/triggers/states.qh diff --git a/qcsrc/common/triggers/func/breakable.qh b/qcsrc/common/triggers/func/breakable.qh index 9a51be8c6..9b16355dd 100644 --- a/qcsrc/common/triggers/func/breakable.qh +++ b/qcsrc/common/triggers/func/breakable.qh @@ -1,10 +1,8 @@ #pragma once #include "../spawnflags.qh" +#include "../states.qh" -const int STATE_ALIVE = 0; -const int STATE_BROKEN = 1; - #ifdef SVQC spawnfunc(func_breakable); #endif diff --git a/qcsrc/common/triggers/func/button.qc b/qcsrc/common/triggers/func/button.qc index fd113205f..28e6481c8 100644 --- a/qcsrc/common/triggers/func/button.qc +++ b/qcsrc/common/triggers/func/button.qc @@ -1,5 +1,4 @@ #include "button.qh" -#include "../spawnflags.qh" #ifdef SVQC // button and multiple button diff --git a/qcsrc/common/triggers/func/button.qh b/qcsrc/common/triggers/func/button.qh index 6f70f09be..7c39519e1 100644 --- a/qcsrc/common/triggers/func/button.qh +++ b/qcsrc/common/triggers/func/button.qh @@ -1 +1,2 @@ #pragma once +#include "../spawnflags.qh" diff --git a/qcsrc/common/triggers/func/conveyor.qc b/qcsrc/common/triggers/func/conveyor.qc index 1802a75db..375a6adb8 100644 --- a/qcsrc/common/triggers/func/conveyor.qc +++ b/qcsrc/common/triggers/func/conveyor.qc @@ -67,22 +67,25 @@ void conveyor_use(entity this, entity actor, entity trigger) { this.state = !this.state; - this.SendFlags |= 2; + this.SendFlags |= SF_TRIGGER_UPDATE; } void conveyor_reset(entity this) { - this.state = (this.spawnflags & 1); + if(this.spawnflags & CONVEYOR_START_ENABLED) + { + this.state = STATE_ON; + } - this.SendFlags |= 2; + this.SendFlags |= SF_TRIGGER_UPDATE; } -bool conveyor_send(entity this, entity to, int sf) +bool conveyor_send(entity this, entity to, int sendflags) { WriteHeader(MSG_ENTITY, ENT_CLIENT_CONVEYOR); - WriteByte(MSG_ENTITY, sf); + WriteByte(MSG_ENTITY, sendflags); - if(sf & 1) + if(sendflags & SF_TRIGGER_INIT) { WriteByte(MSG_ENTITY, this.warpzone_isboxy); WriteVector(MSG_ENTITY, this.origin); @@ -99,7 +102,7 @@ bool conveyor_send(entity this, entity to, int sf) WriteString(MSG_ENTITY, this.target); } - if(sf & 2) + if(sendflags & SF_TRIGGER_UPDATE) WriteByte(MSG_ENTITY, this.state); return true; @@ -118,13 +121,13 @@ void conveyor_init(entity this) this.reset(this); } else - this.state = 1; + this.state = STATE_ON; FixSize(this); Net_LinkEntity(this, 0, false, conveyor_send); - this.SendFlags |= 1; + this.SendFlags |= SF_TRIGGER_INIT; } spawnfunc(trigger_conveyor) @@ -161,9 +164,9 @@ void conveyor_init(entity this, bool isnew) NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew) { - int sf = ReadByte(); + int sendflags = ReadByte(); - if(sf & 1) + if(sendflags & SF_TRIGGER_INIT) { this.warpzone_isboxy = ReadByte(); this.origin = ReadVector(); @@ -184,7 +187,7 @@ NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew) conveyor_init(this, isnew); } - if(sf & 2) + if(sendflags & SF_TRIGGER_UPDATE) this.state = ReadByte(); return true; diff --git a/qcsrc/common/triggers/func/conveyor.qh b/qcsrc/common/triggers/func/conveyor.qh index c12b52d2d..20b790f4a 100644 --- a/qcsrc/common/triggers/func/conveyor.qh +++ b/qcsrc/common/triggers/func/conveyor.qh @@ -1,4 +1,6 @@ #pragma once +#include "../spawnflags.qh" +#include "../states.qh" IntrusiveList g_conveyed; STATIC_INIT(g_conveyed) { g_conveyed = IL_NEW(); } diff --git a/qcsrc/common/triggers/spawnflags.qh b/qcsrc/common/triggers/spawnflags.qh index 8712e7110..b2e397d1b 100644 --- a/qcsrc/common/triggers/spawnflags.qh +++ b/qcsrc/common/triggers/spawnflags.qh @@ -15,6 +15,9 @@ const int BREAKABLE_NODAMAGE = BIT(2); // button const int BUTTON_DONTACCUMULATEDMG = BIT(7); +// conveyor +const int CONVEYOR_START_ENABLED = BIT(0); + // door, door_rotating and door_secret const int DOOR_START_OPEN = BIT(0); const int DOOR_DONT_LINK = BIT(2); diff --git a/qcsrc/common/triggers/states.qh b/qcsrc/common/triggers/states.qh new file mode 100644 index 000000000..ace3de8f3 --- /dev/null +++ b/qcsrc/common/triggers/states.qh @@ -0,0 +1,17 @@ +#pragma once + +#ifdef CSQC +// this stuff is defined in the server side engine VM, so we must define it separately here +const int STATE_TOP = 0; +const int STATE_BOTTOM = 1; +const int STATE_UP = 2; +const int STATE_DOWN = 3; +#endif + +// generic +const int STATE_OFF = 0; +const int STATE_ON = 1; + +// breakable +const int STATE_ALIVE = 0; +const int STATE_BROKEN = 1; diff --git a/qcsrc/common/triggers/subs.qh b/qcsrc/common/triggers/subs.qh index d2d36a8d1..d8d926c80 100644 --- a/qcsrc/common/triggers/subs.qh +++ b/qcsrc/common/triggers/subs.qh @@ -1,4 +1,5 @@ #pragma once +#include "states.qh" void SUB_SetFade (entity ent, float when, float fading_time); void SUB_VanishOrRemove (entity ent); @@ -50,11 +51,6 @@ const int DAMAGE_NO = 0; const int DAMAGE_YES = 1; const int DAMAGE_AIM = 2; -const int STATE_TOP = 0; -const int STATE_BOTTOM = 1; -const int STATE_UP = 2; -const int STATE_DOWN = 3; - .string noise, noise1, noise2, noise3; // contains names of wavs to play .float max_health; // players maximum health is stored here -- 2.39.2