From: Freddy Date: Wed, 7 Mar 2018 16:20:55 +0000 (+0100) Subject: Conveyors: use .active instead of .state X-Git-Tag: xonotic-v0.8.5~2176^2~37 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=6d4c6c37741b30553230ca5a27e6ebb8c6b885ac;p=xonotic%2Fxonotic-data.pk3dir.git Conveyors: use .active instead of .state --- diff --git a/qcsrc/common/triggers/func/conveyor.qc b/qcsrc/common/triggers/func/conveyor.qc index 375a6adb8..acb6529ff 100644 --- a/qcsrc/common/triggers/func/conveyor.qc +++ b/qcsrc/common/triggers/func/conveyor.qc @@ -17,9 +17,9 @@ void conveyor_think(entity this) IL_REMOVE(g_conveyed, it); }); - if(this.state) + if(this.active) { - FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, !it.conveyor.state && isPushable(it), + FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, !it.conveyor.active && isPushable(it), { vector emin = it.absmin; vector emax = it.absmax; @@ -63,18 +63,49 @@ void conveyor_think(entity this) #ifdef SVQC -void conveyor_use(entity this, entity actor, entity trigger) +void conveyor_setactive(entity this, int act) { - this.state = !this.state; + 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; + } - this.SendFlags |= SF_TRIGGER_UPDATE; + if (this.active != old_status) + { + this.SendFlags |= SF_TRIGGER_UPDATE; + } +} + +// Compatibility with old maps +void conveyor_use(entity this, entity actor, entity trigger) +{ + conveyor_setactive(this, ACTIVE_TOGGLE); } void conveyor_reset(entity this) { - if(this.spawnflags & CONVEYOR_START_ENABLED) + IFTARGETED { - this.state = STATE_ON; + if(this.spawnflags & CONVEYOR_START_ENABLED) + { + this.active = ACTIVE_ACTIVE; + } + } + else + { + this.active = ACTIVE_ACTIVE; } this.SendFlags |= SF_TRIGGER_UPDATE; @@ -96,14 +127,14 @@ bool conveyor_send(entity this, entity to, int sendflags) WriteVector(MSG_ENTITY, this.movedir); WriteByte(MSG_ENTITY, this.speed); - WriteByte(MSG_ENTITY, this.state); + WriteByte(MSG_ENTITY, this.active); WriteString(MSG_ENTITY, this.targetname); WriteString(MSG_ENTITY, this.target); } if(sendflags & SF_TRIGGER_UPDATE) - WriteByte(MSG_ENTITY, this.state); + WriteByte(MSG_ENTITY, this.active); return true; } @@ -114,14 +145,14 @@ void conveyor_init(entity this) this.movedir *= this.speed; setthink(this, conveyor_think); this.nextthink = time; + this.setactive = conveyor_setactive; IFTARGETED { + // backwards compatibility this.use = conveyor_use; - this.reset = conveyor_reset; - this.reset(this); } - else - this.state = STATE_ON; + this.reset = conveyor_reset; + this.reset(this); FixSize(this); @@ -179,7 +210,7 @@ NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew) this.movedir = ReadVector(); this.speed = ReadByte(); - this.state = ReadByte(); + this.active = ReadByte(); this.targetname = strzone(ReadString()); this.target = strzone(ReadString()); @@ -188,7 +219,7 @@ NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew) } if(sendflags & SF_TRIGGER_UPDATE) - this.state = ReadByte(); + this.active = ReadByte(); return true; } diff --git a/qcsrc/common/triggers/states.qh b/qcsrc/common/triggers/states.qh index ace3de8f3..6ed47df3d 100644 --- a/qcsrc/common/triggers/states.qh +++ b/qcsrc/common/triggers/states.qh @@ -8,10 +8,6 @@ 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/ecs/systems/physics.qc b/qcsrc/ecs/systems/physics.qc index c8b459962..8896b5a44 100644 --- a/qcsrc/ecs/systems/physics.qc +++ b/qcsrc/ecs/systems/physics.qc @@ -43,7 +43,7 @@ void sys_phys_update(entity this, float dt) float maxspeed_mod = (!this.in_swamp) ? 1 : this.swamp_slowdown; // cvar("g_balance_swamp_moverate"); // conveyors: first fix velocity - if (this.conveyor.state) { this.velocity -= this.conveyor.movedir; } + if (this.conveyor.active) { this.velocity -= this.conveyor.movedir; } MUTATOR_CALLHOOK(PlayerPhysics, this, dt); if (!IS_PLAYER(this)) { @@ -156,7 +156,7 @@ void sys_phys_update(entity this, float dt) LABEL(end) if (IS_ONGROUND(this)) { this.lastground = time; } // conveyors: then break velocity again - if (this.conveyor.state) { this.velocity += this.conveyor.movedir; } + if (this.conveyor.active) { this.velocity += this.conveyor.movedir; } this.lastflags = this.flags; this.lastclassname = this.classname;