]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/triggers/func/button.qc
Properly support team field on trigger_multiple
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / button.qc
1 #include "button.qh"
2 #ifdef SVQC
3 // button and multiple button
4
5 void button_wait(entity this);
6 void button_return(entity this);
7
8 void button_wait(entity this)
9 {
10         this.state = STATE_TOP;
11         if(this.wait >= 0)
12         {
13                 this.nextthink = this.ltime + this.wait;
14                 setthink(this, button_return);
15         }
16         SUB_UseTargets(this, this.enemy, NULL);
17         this.frame = 1;                 // use alternate textures
18 }
19
20 void button_done(entity this)
21 {
22         this.state = STATE_BOTTOM;
23 }
24
25 void button_return(entity this)
26 {
27         this.state = STATE_DOWN;
28         SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, button_done);
29         this.frame = 0;                 // use normal textures
30         if (this.health)
31                 this.takedamage = DAMAGE_YES;   // can be shot again
32 }
33
34
35 void button_blocked(entity this, entity blocker)
36 {
37         // do nothing, just don't come all the way back out
38 }
39
40
41 void button_fire(entity this)
42 {
43         this.health = this.max_health;
44         this.takedamage = DAMAGE_NO;    // will be reset upon return
45
46         if (this.state == STATE_UP || this.state == STATE_TOP)
47                 return;
48
49         if (this.noise != "")
50                 _sound (this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
51
52         this.state = STATE_UP;
53         SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, button_wait);
54 }
55
56 void button_reset(entity this)
57 {
58         this.health = this.max_health;
59         setorigin(this, this.pos1);
60         this.frame = 0;                 // use normal textures
61         this.state = STATE_BOTTOM;
62         this.velocity = '0 0 0';
63         setthink(this, func_null);
64         this.nextthink = 0;
65         if (this.health)
66                 this.takedamage = DAMAGE_YES;   // can be shot again
67 }
68
69 void button_use(entity this, entity actor, entity trigger)
70 {
71         if(this.active != ACTIVE_ACTIVE)
72                 return;
73
74         this.enemy = actor;
75         button_fire(this);
76 }
77
78 void button_touch(entity this, entity toucher)
79 {
80         if (!toucher)
81                 return;
82         if (!toucher.iscreature)
83                 return;
84         if(toucher.velocity * this.movedir < 0)
85                 return;
86         this.enemy = toucher;
87         if (toucher.owner)
88                 this.enemy = toucher.owner;
89         button_fire (this);
90 }
91
92 void button_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
93 {
94         if(this.spawnflags & DOOR_NOSPLASH)
95                 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
96                         return;
97         if (this.spawnflags & BUTTON_DONTACCUMULATEDMG)
98         {
99                 if (this.health <= damage)
100                 {
101                         this.enemy = attacker;
102                         button_fire(this);
103                 }
104         }
105         else
106         {
107                 this.health = this.health - damage;
108                 if (this.health <= 0)
109                 {
110                         this.enemy = attacker;
111                         button_fire(this);
112                 }
113         }
114 }
115
116
117 /*QUAKED spawnfunc_func_button (0 .5 .8) ?
118 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.
119
120 "angle"         determines the opening direction
121 "target"        all entities with a matching targetname will be used
122 "speed"         override the default 40 speed
123 "wait"          override the default 1 second wait (-1 = never return)
124 "lip"           override the default 4 pixel lip remaining at end of move
125 "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
126 "sounds"
127 0) steam metal
128 1) wooden clunk
129 2) metallic click
130 3) in-out
131 */
132 spawnfunc(func_button)
133 {
134         SetMovedir(this);
135
136         if (!InitMovingBrushTrigger(this))
137                 return;
138         this.effects |= EF_LOWPRECISION;
139
140         setblocked(this, button_blocked);
141         this.use = button_use;
142
143 //      if (this.health == 0) // all buttons are now shootable
144 //              this.health = 10;
145         if (this.health)
146         {
147                 this.max_health = this.health;
148                 this.event_damage = button_damage;
149                 this.takedamage = DAMAGE_YES;
150         }
151         else
152                 settouch(this, button_touch);
153
154         if (!this.speed)
155                 this.speed = 40;
156         if (!this.wait)
157                 this.wait = 1;
158         if (!this.lip)
159                 this.lip = 4;
160
161     if(this.noise != "")
162         precache_sound(this.noise);
163
164         this.active = ACTIVE_ACTIVE;
165
166         this.pos1 = this.origin;
167         this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip);
168     this.flags |= FL_NOTARGET;
169
170     this.reset = button_reset;
171
172         button_reset(this);
173 }
174 #endif