2 #include "../spawnflags.qh"
4 // button and multiple button
6 void button_wait(entity this);
7 void button_return(entity this);
9 void button_wait(entity this)
11 this.state = STATE_TOP;
14 this.nextthink = this.ltime + this.wait;
15 setthink(this, button_return);
17 SUB_UseTargets(this, this.enemy, NULL);
18 this.frame = 1; // use alternate textures
21 void button_done(entity this)
23 this.state = STATE_BOTTOM;
26 void button_return(entity this)
28 this.state = STATE_DOWN;
29 SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, button_done);
30 this.frame = 0; // use normal textures
32 this.takedamage = DAMAGE_YES; // can be shot again
36 void button_blocked(entity this, entity blocker)
38 // do nothing, just don't come all the way back out
42 void button_fire(entity this)
44 this.health = this.max_health;
45 this.takedamage = DAMAGE_NO; // will be reset upon return
47 if (this.state == STATE_UP || this.state == STATE_TOP)
51 _sound (this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
53 this.state = STATE_UP;
54 SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, button_wait);
57 void button_reset(entity this)
59 this.health = this.max_health;
60 setorigin(this, this.pos1);
61 this.frame = 0; // use normal textures
62 this.state = STATE_BOTTOM;
63 this.velocity = '0 0 0';
64 setthink(this, func_null);
67 this.takedamage = DAMAGE_YES; // can be shot again
70 void button_use(entity this, entity actor, entity trigger)
72 if(this.active != ACTIVE_ACTIVE)
79 void button_touch(entity this, entity toucher)
83 if (!toucher.iscreature)
85 if(toucher.velocity * this.movedir < 0)
89 this.enemy = toucher.owner;
93 void button_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
95 if(this.spawnflags & NOSPLASH)
96 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
98 if (this.spawnflags & BUTTON_DONTACCUMULATEDMG)
100 if (this.health <= damage)
102 this.enemy = attacker;
108 this.health = this.health - damage;
109 if (this.health <= 0)
111 this.enemy = attacker;
118 /*QUAKED spawnfunc_func_button (0 .5 .8) ?
119 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.
121 "angle" determines the opening direction
122 "target" all entities with a matching targetname will be used
123 "speed" override the default 40 speed
124 "wait" override the default 1 second wait (-1 = never return)
125 "lip" override the default 4 pixel lip remaining at end of move
126 "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
127 "noise" sound that is played when the button is activated
129 spawnfunc(func_button)
133 if (!InitMovingBrushTrigger(this))
135 this.effects |= EF_LOWPRECISION;
137 setblocked(this, button_blocked);
138 this.use = button_use;
140 // if (this.health == 0) // all buttons are now shootable
144 this.max_health = this.health;
145 this.event_damage = button_damage;
146 this.takedamage = DAMAGE_YES;
149 settouch(this, button_touch);
159 precache_sound(this.noise);
161 this.active = ACTIVE_ACTIVE;
163 this.pos1 = this.origin;
164 this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip);
165 this.flags |= FL_NOTARGET;
167 this.reset = button_reset;