Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
button.qc File Reference
#include "button.qh"
Include dependency graph for button.qc:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void button_blocked (entity this, entity blocker)
void button_damage (entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
void button_done (entity this)
void button_fire (entity this)
void button_reset (entity this)
void button_return (entity this)
void button_setactive (entity this, int astate)
void button_touch (entity this, entity toucher)
void button_use (entity this, entity actor, entity trigger)
void button_wait (entity this)
 spawnfunc (func_button)

Variables

float activation_time
float wait_remaining

Function Documentation

◆ button_blocked()

void button_blocked ( entity this,
entity blocker )

Definition at line 78 of file button.qc.

79{
80 // do nothing, just don't come all the way back out
81}

References entity().

Referenced by spawnfunc().

◆ button_damage()

void button_damage ( entity this,
entity inflictor,
entity attacker,
float damage,
int deathtype,
.entity weaponentity,
vector hitloc,
vector force )

Definition at line 142 of file button.qc.

143{
144 if (this.active != ACTIVE_ACTIVE)
145 return;
146 if(this.spawnflags & NOSPLASH)
147 if(!(DEATH_ISSPECIAL(deathtype)) && (deathtype & HITTYPE_SPLASH))
148 return;
150 {
151 if (GetResource(this, RES_HEALTH) <= damage)
152 {
153 this.enemy = attacker;
154 button_fire(this);
155 }
156 }
157 else
158 {
159 TakeResource(this, RES_HEALTH, damage);
160 if (GetResource(this, RES_HEALTH) <= 0)
161 {
162 this.enemy = attacker;
163 button_fire(this);
164 }
165 }
166}
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
void TakeResource(entity receiver, Resource res_type, float amount)
Takes an entity some resource.
int spawnflags
Definition ammo.qh:15
void button_fire(entity this)
Definition button.qc:84
const int BUTTON_DONTACCUMULATEDMG
Definition button.qh:4
#define DEATH_ISSPECIAL(t)
Definition all.qh:39
const int HITTYPE_SPLASH
Definition all.qh:30
const int NOSPLASH
Definition defs.qh:12
int active
Definition defs.qh:34
const int ACTIVE_ACTIVE
Definition defs.qh:37
entity enemy
Definition sv_ctf.qh:153

References active, ACTIVE_ACTIVE, BUTTON_DONTACCUMULATEDMG, button_fire(), DEATH_ISSPECIAL, enemy, entity(), GetResource(), HITTYPE_SPLASH, NOSPLASH, spawnflags, TakeResource(), and vector.

Referenced by spawnfunc().

◆ button_done()

void button_done ( entity this)

Definition at line 57 of file button.qc.

58{
59 this.state = STATE_BOTTOM;
60}
int state
#define STATE_BOTTOM
Definition sys-pre.qh:29

References entity(), state, and STATE_BOTTOM.

Referenced by button_return().

◆ button_fire()

void button_fire ( entity this)

Definition at line 84 of file button.qc.

85{
86 SetResourceExplicit(this, RES_HEALTH, this.max_health);
87 this.takedamage = DAMAGE_NO; // will be reset upon return
88
89 if (this.state == STATE_UP || this.state == STATE_TOP)
90 return;
91
92 this.activation_time = time;
93
94 if (this.noise != "")
96
97 this.state = STATE_UP;
98 SUB_CalcMove (this, this.pos2, TSPEED_LINEAR, this.speed, button_wait);
99}
float max_health
bool SetResourceExplicit(entity e, Resource res_type, float amount)
Sets the resource amount of an entity without calling any hooks.
void button_wait(entity this)
Definition button.qc:45
float activation_time
Definition button.qc:11
float time
float speed
Definition dynlight.qc:9
const int CH_TRIGGER
Definition sound.qh:12
const float VOL_BASE
Definition sound.qh:36
#define _sound(e, c, s, v, a)
Definition sound.qh:43
const float ATTEN_NORM
Definition sound.qh:30
void SUB_CalcMove(entity this, vector tdest, float tspeedtype, float tspeed, void(entity this) func)
Definition subs.qc:267
string noise
Definition subs.qh:83
const int DAMAGE_NO
Definition subs.qh:79
vector pos2
Definition subs.qh:50
const int TSPEED_LINEAR
Definition subs.qh:71
float takedamage
Definition subs.qh:78
#define STATE_UP
Definition sys-pre.qh:30
#define STATE_TOP
Definition sys-pre.qh:28

References _sound, activation_time, ATTEN_NORM, button_wait(), CH_TRIGGER, DAMAGE_NO, entity(), max_health, noise, pos2, SetResourceExplicit(), speed, state, STATE_TOP, STATE_UP, SUB_CalcMove(), takedamage, time, TSPEED_LINEAR, and VOL_BASE.

Referenced by button_damage(), button_touch(), and button_use().

◆ button_reset()

void button_reset ( entity this)

Definition at line 101 of file button.qc.

102{
103 SetResourceExplicit(this, RES_HEALTH, this.max_health);
104 setorigin(this, this.pos1);
105 this.frame = 0; // use normal textures
106 this.state = STATE_BOTTOM;
107 this.velocity = '0 0 0';
108 this.wait_remaining = -1;
109 this.activation_time = -1;
110 this.active = ACTIVE_ACTIVE;
111 setthink(this, func_null);
112 this.nextthink = 0;
113 if (GetResource(this, RES_HEALTH))
114 this.takedamage = DAMAGE_YES; // can be shot again
115}
float frame
primary framegroup animation (strength = 1 - lerpfrac - lerpfrac3 - lerpfrac4)
Definition anim.qh:6
float wait_remaining
Definition button.qc:10
vector velocity
float nextthink
var void func_null()
#define setthink(e, f)
const int DAMAGE_YES
Definition subs.qh:80
vector pos1
Definition subs.qh:50

References activation_time, active, ACTIVE_ACTIVE, DAMAGE_YES, entity(), frame, func_null(), GetResource(), max_health, nextthink, pos1, SetResourceExplicit(), setthink, state, STATE_BOTTOM, takedamage, velocity, and wait_remaining.

Referenced by spawnfunc().

◆ button_return()

void button_return ( entity this)

Definition at line 62 of file button.qc.

63{
64 if (this.active != ACTIVE_ACTIVE)
65 {
66 return;
67 }
68 this.state = STATE_DOWN;
69 SUB_CalcMove (this, this.pos1, TSPEED_LINEAR, this.speed, button_done);
70 this.frame = 0; // use normal textures
71 if (GetResource(this, RES_HEALTH))
72 this.takedamage = DAMAGE_YES; // can be shot again
73 this.wait_remaining = -1;
74 this.activation_time = -1;
75}
void button_done(entity this)
Definition button.qc:57
#define STATE_DOWN
Definition sys-pre.qh:31

References activation_time, active, ACTIVE_ACTIVE, button_done(), DAMAGE_YES, entity(), frame, GetResource(), pos1, speed, state, STATE_DOWN, SUB_CalcMove(), takedamage, TSPEED_LINEAR, and wait_remaining.

Referenced by button_setactive(), and button_wait().

◆ button_setactive()

void button_setactive ( entity this,
int astate )

Definition at line 13 of file button.qc.

14{
15 int oldstate = this.active;
16 if (astate == ACTIVE_TOGGLE)
17 {
18 if (this.active == ACTIVE_ACTIVE)
19 this.active = ACTIVE_NOT;
20 else
21 this.active = ACTIVE_ACTIVE;
22 }
23 else
24 this.active = astate;
25
26 if (this.active == ACTIVE_ACTIVE && oldstate == ACTIVE_NOT)
27 {
28 // button was deactivated while it was pressed
29 if (this.wait_remaining >= 0)
30 {
31 this.nextthink = this.wait_remaining + this.ltime;
33 }
34 }
35 else if (this.active == ACTIVE_NOT && oldstate == ACTIVE_ACTIVE)
36 {
37 // check if button is in pressed state
38 if (this.activation_time >= 0)
39 {
40 this.wait_remaining = this.wait - (time - this.activation_time);
41 }
42 }
43}
float wait
Definition items.qc:17
void button_return(entity this)
Definition button.qc:62
const int ACTIVE_TOGGLE
Definition defs.qh:40
const int ACTIVE_NOT
Definition defs.qh:36
float ltime
Definition net.qc:10

References activation_time, active, ACTIVE_ACTIVE, ACTIVE_NOT, ACTIVE_TOGGLE, button_return(), entity(), ltime, nextthink, setthink, time, wait, and wait_remaining.

Referenced by spawnfunc().

◆ button_touch()

void button_touch ( entity this,
entity toucher )

Definition at line 126 of file button.qc.

127{
128 if (this.active != ACTIVE_ACTIVE)
129 return;
130 if (!toucher)
131 return;
132 if (!toucher.iscreature)
133 return;
134 if(toucher.velocity * this.movedir < 0)
135 return;
136 this.enemy = toucher;
137 if (toucher.owner)
138 this.enemy = toucher.owner;
139 button_fire (this);
140}
entity entity toucher
Definition self.qh:72

References active, ACTIVE_ACTIVE, button_fire(), enemy, entity(), and toucher.

Referenced by spawnfunc().

◆ button_use()

void button_use ( entity this,
entity actor,
entity trigger )

Definition at line 117 of file button.qc.

118{
119 if(this.active != ACTIVE_ACTIVE)
120 return;
121
122 this.enemy = actor;
123 button_fire(this);
124}

References active, ACTIVE_ACTIVE, button_fire(), enemy, and entity().

Referenced by spawnfunc().

◆ button_wait()

void button_wait ( entity this)

Definition at line 45 of file button.qc.

46{
47 this.state = STATE_TOP;
48 if(this.wait >= 0)
49 {
50 this.nextthink = this.ltime + this.wait;
52 }
53 SUB_UseTargets(this, this.enemy, NULL);
54 this.frame = 1; // use alternate textures
55}
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition triggers.qc:344
#define NULL
Definition post.qh:14

References button_return(), enemy, entity(), frame, ltime, nextthink, NULL, setthink, state, STATE_TOP, SUB_UseTargets(), and wait.

Referenced by button_fire().

◆ spawnfunc()

spawnfunc ( func_button )

Definition at line 180 of file button.qc.

181{
182 SetMovedir(this);
183
184 if (!InitMovingBrushTrigger(this))
185 return;
186 this.effects |= EF_LOWPRECISION;
187
189 this.use = button_use;
190
191// if (this.health == 0) // all buttons are now shootable
192// this.health = 10;
193 if (GetResource(this, RES_HEALTH))
194 {
195 this.max_health = GetResource(this, RES_HEALTH);
196 this.event_damage = button_damage;
197 this.takedamage = DAMAGE_YES;
198 }
199 else
200 settouch(this, button_touch);
201
202 if (!this.speed)
203 this.speed = 40;
204 if (!this.wait)
205 this.wait = 1;
206 if (!this.lip)
207 this.lip = 4;
208
209 if(this.wait < 0 && q3compat)
210 this.wait = 0.1; // compatibility for q3: -1 = return immediately
211
212 if(this.noise != "")
213 precache_sound(this.noise);
214
215 this.draggable = drag_undraggable;
216
217 this.setactive = button_setactive;
218
219 this.pos1 = this.origin;
220 this.pos2 = this.pos1 + this.movedir*(fabs(this.movedir*this.size) - this.lip);
221 this.flags |= FL_NOTARGET;
222
223 this.reset = button_reset;
224
225 button_reset(this);
226}
bool drag_undraggable(entity draggee, entity dragger)
Definition cheats.qc:903
void button_blocked(entity this, entity blocker)
Definition button.qc:78
void button_setactive(entity this, int astate)
Definition button.qc:13
void button_touch(entity this, entity toucher)
Definition button.qc:126
void button_use(entity this, entity actor, entity trigger)
Definition button.qc:117
void button_reset(entity this)
Definition button.qc:101
void button_damage(entity this, entity inflictor, entity attacker, float damage, int deathtype,.entity weaponentity, vector hitloc, vector force)
Definition button.qc:142
const int FL_NOTARGET
Definition constants.qh:76
float flags
float effects
vector size
vector origin
#define use
float EF_LOWPRECISION
vector movedir
Definition viewloc.qh:18
string precache_sound(string sample)
float fabs(float f)
q3compat
Definition quake3.qc:59
#define settouch(e, f)
Definition self.qh:73
#define setblocked(e, f)
void SetMovedir(entity this)
Definition subs.qc:540
bool InitMovingBrushTrigger(entity this)
Definition subs.qc:577
float lip
Definition subs.qh:40

References button_blocked(), button_damage(), button_reset(), button_setactive(), button_touch(), button_use(), DAMAGE_YES, drag_undraggable(), EF_LOWPRECISION, effects, fabs(), FL_NOTARGET, flags, GetResource(), InitMovingBrushTrigger(), lip, max_health, movedir, noise, origin, pos1, pos2, precache_sound(), q3compat, setblocked, SetMovedir(), settouch, size, speed, takedamage, use, and wait.

Variable Documentation

◆ activation_time

float activation_time

Definition at line 11 of file button.qc.

Referenced by button_fire(), button_reset(), button_return(), and button_setactive().

◆ wait_remaining

float wait_remaining

Definition at line 10 of file button.qc.

Referenced by button_reset(), button_return(), and button_setactive().