From: Freddy Date: Thu, 7 Sep 2017 23:37:48 +0000 (+0200) Subject: Use setactive function field for button (de)activation X-Git-Tag: xonotic-v0.8.5~1807^2~2^2~2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fd8df396aa5a41884c2b0629b133b95d998a270e;p=xonotic%2Fxonotic-data.pk3dir.git Use setactive function field for button (de)activation --- diff --git a/qcsrc/common/triggers/func/button.qc b/qcsrc/common/triggers/func/button.qc index 8c157d93c..e6394d085 100644 --- a/qcsrc/common/triggers/func/button.qc +++ b/qcsrc/common/triggers/func/button.qc @@ -5,6 +5,36 @@ void button_wait(entity this); void button_return(entity this); +.float wait_remaining; +.float activation_time; + +void button_setactive(entity this, int astate) +{ + int oldstate = this.active; + if (astate == ACTIVE_TOGGLE) + { + if (this.active == ACTIVE_ACTIVE) + this.active = ACTIVE_NOT; + else + this.active = ACTIVE_ACTIVE; + } + else + this.active = astate; + + if (this.active == ACTIVE_ACTIVE && oldstate == ACTIVE_NOT) + { + if (this.wait_remaining >= 0) + { + this.nextthink = this.wait_remaining + this.ltime; + setthink(this, button_return); + } + } + else if (this.active == ACTIVE_NOT && oldstate == ACTIVE_ACTIVE) + { + this.wait_remaining = this.wait - (time - this.activation_time); + } +} + void button_wait(entity this) { this.state = STATE_TOP; @@ -26,8 +56,6 @@ void button_return(entity this) { if (this.active != ACTIVE_ACTIVE) { - this.nextthink = this.ltime + frametime; - setthink(this, button_return); return; } this.state = STATE_DOWN; @@ -35,6 +63,7 @@ void button_return(entity this) this.frame = 0; // use normal textures if (this.health) this.takedamage = DAMAGE_YES; // can be shot again + this.wait_remaining = this.wait; } @@ -52,6 +81,8 @@ void button_fire(entity this) if (this.state == STATE_UP || this.state == STATE_TOP) return; + this.activation_time = time; + if (this.noise != "") _sound (this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM); @@ -157,11 +188,15 @@ spawnfunc(func_button) if (!this.lip) this.lip = 4; + this.wait_remaining = this.wait; + if(this.noise != "") precache_sound(this.noise); this.active = ACTIVE_ACTIVE; + this.setactive = button_setactive; + this.pos1 = this.origin; this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip); this.flags |= FL_NOTARGET;