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