3 // button and multiple button
5 void button_wait(entity this);
6 void button_return(entity this);
9 .float activation_time;
11 void button_setactive(entity this, int astate)
13 int oldstate = this.active;
14 if (astate == ACTIVE_TOGGLE)
16 if (this.active == ACTIVE_ACTIVE)
17 this.active = ACTIVE_NOT;
19 this.active = ACTIVE_ACTIVE;
24 if (this.active == ACTIVE_ACTIVE && oldstate == ACTIVE_NOT)
26 if (this.wait_remaining >= 0)
28 this.nextthink = this.wait_remaining + this.ltime;
29 setthink(this, button_return);
32 else if (this.active == ACTIVE_NOT && oldstate == ACTIVE_ACTIVE)
34 this.wait_remaining = this.wait - (time - this.activation_time);
38 void button_wait(entity this)
40 this.state = STATE_TOP;
43 this.nextthink = this.ltime + this.wait;
44 setthink(this, button_return);
46 SUB_UseTargets(this, this.enemy, NULL);
47 this.frame = 1; // use alternate textures
50 void button_done(entity this)
52 this.state = STATE_BOTTOM;
55 void button_return(entity this)
57 if (this.active != ACTIVE_ACTIVE)
61 this.state = STATE_DOWN;
62 SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, button_done);
63 this.frame = 0; // use normal textures
65 this.takedamage = DAMAGE_YES; // can be shot again
66 this.wait_remaining = this.wait;
70 void button_blocked(entity this, entity blocker)
72 // do nothing, just don't come all the way back out
76 void button_fire(entity this)
78 this.health = this.max_health;
79 this.takedamage = DAMAGE_NO; // will be reset upon return
81 if (this.state == STATE_UP || this.state == STATE_TOP)
84 this.activation_time = time;
87 _sound (this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
89 this.state = STATE_UP;
90 SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, button_wait);
93 void button_reset(entity this)
95 this.health = this.max_health;
96 setorigin(this, this.pos1);
97 this.frame = 0; // use normal textures
98 this.state = STATE_BOTTOM;
99 this.velocity = '0 0 0';
100 setthink(this, func_null);
103 this.takedamage = DAMAGE_YES; // can be shot again
106 void button_use(entity this, entity actor, entity trigger)
108 if(this.active != ACTIVE_ACTIVE)
115 void button_touch(entity this, entity toucher)
117 if (this.active != ACTIVE_ACTIVE)
121 if (!toucher.iscreature)
123 if(toucher.velocity * this.movedir < 0)
125 this.enemy = toucher;
127 this.enemy = toucher.owner;
131 void button_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
133 if (this.active != ACTIVE_ACTIVE)
135 if(this.spawnflags & DOOR_NOSPLASH)
136 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
138 this.health = this.health - damage;
139 if (this.health <= 0)
141 this.enemy = attacker;
147 /*QUAKED spawnfunc_func_button (0 .5 .8) ?
148 When a button is touched, it moves some distance in the direction of it's angle, triggers all of it's targets, waits some time, then returns to it's original position where it can be triggered again.
150 "angle" determines the opening direction
151 "target" all entities with a matching targetname will be used
152 "speed" override the default 40 speed
153 "wait" override the default 1 second wait (-1 = never return)
154 "lip" override the default 4 pixel lip remaining at end of move
155 "health" if set, the button must be killed instead of touched. If set to -1, the button will fire on ANY attack, even damageless ones like the InstaGib laser
162 spawnfunc(func_button)
166 if (!InitMovingBrushTrigger(this))
168 this.effects |= EF_LOWPRECISION;
170 setblocked(this, button_blocked);
171 this.use = button_use;
173 // if (this.health == 0) // all buttons are now shootable
177 this.max_health = this.health;
178 this.event_damage = button_damage;
179 this.takedamage = DAMAGE_YES;
182 settouch(this, button_touch);
191 this.wait_remaining = this.wait;
194 precache_sound(this.noise);
196 this.active = ACTIVE_ACTIVE;
198 this.setactive = button_setactive;
200 this.pos1 = this.origin;
201 this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip);
202 this.flags |= FL_NOTARGET;
204 this.reset = button_reset;