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

Go to the source code of this file.

Functions

void item_key_touch (entity this, entity toucher)
 Key touch handler.
string item_keys_keylist (float keylist)
 Returns a string with a comma separated list of key names, as specified in keylist.
bool item_keys_usekey (entity l, entity p)
 Use keys from p on l.
void spawn_item_key (entity this)
 Spawn a key with given model, key code and color.
 spawnfunc (item_key)
 spawnfunc (item_key1)
 spawnfunc (item_key2)
 spawnfunc (item_key_gold)
 spawnfunc (item_key_master)
 spawnfunc (item_key_silver)

Function Documentation

◆ item_key_touch()

void item_key_touch ( entity this,
entity toucher )

Key touch handler.

Definition at line 77 of file keys.qc.

78{
79 if (!IS_PLAYER(toucher))
80 return;
81
82 // player already picked up this key
83 if (PS(toucher).itemkeys & this.itemkeys)
84 return;
85
86 PS(toucher).itemkeys |= this.itemkeys;
87 play2(toucher, this.noise);
88
90
91 string oldmsg = this.message;
92 this.message = "";
93 SUB_UseTargets(this, toucher, toucher); // TODO: should we be using toucher for the trigger here?
94 this.message = oldmsg;
95}
string message
Definition powerups.qc:19
#define IS_PLAYER(s)
Definition player.qh:243
void SUB_UseTargets(entity this, entity actor, entity trigger)
Definition triggers.qc:344
void centerprint(string text,...)
entity entity toucher
Definition self.qh:72
void play2(entity e, string filename)
Definition all.qc:116
#define PS(this)
Definition state.qh:18
string noise
Definition subs.qh:83
float itemkeys
Definition subs.qh:61

References centerprint(), entity(), IS_PLAYER, itemkeys, message, noise, play2(), PS, SUB_UseTargets(), and toucher.

Referenced by spawn_item_key().

◆ item_keys_keylist()

string item_keys_keylist ( float keylist)

Returns a string with a comma separated list of key names, as specified in keylist.

Definition at line 40 of file keys.qc.

41{
42 // no keys
43 if (!keylist)
44 return "";
45
46 // one key
47 if ((keylist & (keylist-1)) == 0)
48 return strcat("the ", item_keys_names[lowestbit(keylist)]);
49
50 string n = "";
51 int base = 0;
52 while (keylist)
53 {
54 int l = lowestbit(keylist);
55 if (n)
56 n = strcat(n, ", the ", item_keys_names[base + l]);
57 else
58 n = strcat("the ", item_keys_names[base + l]);
59
60 keylist = bitshift(keylist, -(l + 1));
61 base += l + 1;
62 }
63
64 return n;
65}
ERASEABLE int lowestbit(int f)
Definition bits.qh:17
string item_keys_names[ITEM_KEY_MAX]
list of key names.
Definition keys.qh:9
strcat(_("^F4Countdown stopped!"), "\n^BG", _("Teams are too unbalanced."))

References item_keys_names, lowestbit(), and strcat().

Referenced by door_check_keys(), and trigger_keylock_touch().

◆ item_keys_usekey()

bool item_keys_usekey ( entity l,
entity p )

Use keys from p on l.

Returns true if any new keys were given, false otherwise.

Definition at line 4 of file keys.qc.

5{
6 int valid = (l.itemkeys & p.itemkeys); // TODO: itemkeys isn't networked or anything!
7 l.itemkeys &= ~valid; // only some of the needed keys were given
8 return valid != 0;
9}

References entity().

Referenced by trigger_keylock_touch().

◆ spawn_item_key()

void spawn_item_key ( entity this)

Spawn a key with given model, key code and color.

Definition at line 100 of file keys.qc.

101{
102 precache_model(this.model);
103
104 if (this.spawnflags & 1) // FLOATING
105 this.noalign = 1;
106
107 if (this.noalign)
109 else
111
112 precache_sound(this.noise);
113
114 this.mdl = this.model;
116 _setmodel(this, this.model);
117 this.modelflags |= MF_ROTATE;
118 this.solid = SOLID_TRIGGER;
119
120 // The origin.z was raised within the bbox to support the current model
121 //setsize(this, '-16 -16 -24', '16 16 32');
122 setorigin(this, this.origin + '0 0 32');
123 setsize(this, '-16 -16 -56', '16 16 0');
124
125 if (Q3COMPAT_COMMON) // QL compat, Q3 has no keys
126 // QL bbox is '-16 -16 -16' '16 16 16' so raise to match QL absmin.z
127 setorigin(this, this.origin + '0 0 8');
128
129 // NOTE: this isn't an FL_ITEM so it doesn't get the special treatment in DropToFloor_QC()
130 if (!this.noalign)
132
134}
int spawnflags
Definition ammo.qh:15
string mdl
Definition item.qh:89
#define Q3COMPAT_COMMON
Definition stats.qh:368
const float SOLID_TRIGGER
float effects
vector origin
int modelflags
const int MF_ROTATE
float EF_LOWPRECISION
model
Definition ent_cs.qc:139
solid
Definition ent_cs.qc:165
void item_key_touch(entity this, entity toucher)
Key touch handler.
Definition keys.qc:77
string precache_sound(string sample)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:129
const int MOVETYPE_TOSS
Definition movetypes.qh:135
#define settouch(e, f)
Definition self.qh:73
bool noalign
Definition items.qh:36
void DropToFloor_QC_DelayedInit(entity this)
Definition world.qc:2407

References DropToFloor_QC_DelayedInit(), EF_LOWPRECISION, effects, entity(), item_key_touch(), mdl, MF_ROTATE, model, modelflags, MOVETYPE_NONE, MOVETYPE_TOSS, noalign, noise, origin, precache_sound(), Q3COMPAT_COMMON, set_movetype(), settouch, solid, SOLID_TRIGGER, and spawnflags.

Referenced by spawnfunc().

◆ spawnfunc() [1/6]

spawnfunc ( item_key )

Definition at line 166 of file keys.qc.

167{
168 string _netname;
169 vector _colormod;
170 string _model = "models/keys/key.md3";
171
172 // reject this entity if more than one key was set!
173 if (this.itemkeys>0 && (this.itemkeys & (this.itemkeys-1)) != 0)
174 if (this.itemkeys != 0xffffff) // unless it's a master key
175 {
176 objerror(this, "item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
177 delete(this);
178 return;
179 }
180
181 // find default netname and colormod
182 switch(this.itemkeys) {
183 case BIT(0):
184 _netname = "GOLD key";
185 _colormod = '1 .9 0';
186 break;
187
188 case BIT(1):
189 _netname = "SILVER key";
190 _colormod = '.9 .9 .9';
191 break;
192
193 case BIT(2):
194 _netname = "BRONZE key";
195 _colormod = '.6 .25 0';
196 break;
197
198 case BIT(3):
199 _netname = "RED keycard";
200 _colormod = '.9 0 0';
201 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
202 break;
203
204 case BIT(4):
205 _netname = "BLUE keycard";
206 _colormod = '0 0 .9';
207 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
208 break;
209
210 case BIT(5):
211 _netname = "GREEN keycard";
212 _colormod = '0 .9 0';
213 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
214 break;
215
216 case 0xffffff: // an unlisted key...
217 _netname = "MASTER key";
218 _colormod = '1 0.25 0.25';
219 break;
220
221 default:
222 _netname = "FLUFFY PINK keycard";
223 _colormod = '1 1 1';
224
225 if (this.netname == "")
226 {
227 objerror(this, "item_key doesn't have a default name for this key and a custom one was not specified!");
228 delete(this);
229 return;
230 }
231 if (this.model == "")
232 {
233 objerror(this, "item_key doesn't have a default model for this key and a custom one was not specified!");
234 delete(this);
235 return;
236 }
237 break;
238 }
239
240 // set default netname
241 if (this.netname == "")
242 this.netname = _netname;
243
244 // set default colormod
245 if (!this.colormod)
246 this.colormod = _colormod;
247
248 // set default model
249 if (this.model == "")
250 this.model = _model;
251
252 // set default pickup message
253 if (this.message == "")
254 this.message = strzone(strcat("You've picked up the ", this.netname, "!"));
255
256 if (this.noise == "")
257 this.noise = strzone(SND(ITEMPICKUP));
258
259 // save the name for later
261
262 // put the key on the map
263 spawn_item_key(this);
264}
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
string netname
Definition powerups.qc:20
vector colormod
Definition powerups.qc:21
void spawn_item_key(entity this)
Spawn a key with given model, key code and color.
Definition keys.qc:100
string strzone(string s)
#define objerror
Definition pre.qh:8
vector
Definition self.qh:92
#define SND(id)
Definition all.qh:35

References BIT, colormod, item_keys_names, itemkeys, lowestbit(), message, model, netname, noise, objerror, SND, spawn_item_key(), strcat(), strzone(), and vector.

◆ spawnfunc() [2/6]

spawnfunc ( item_key1 )

Definition at line 278 of file keys.qc.

279{
280 this.itemkeys = BIT(1);
281 spawnfunc_item_key(this);
282}

References BIT, and itemkeys.

◆ spawnfunc() [3/6]

spawnfunc ( item_key2 )

Definition at line 296 of file keys.qc.

297{
298 this.itemkeys = BIT(0);
299 spawnfunc_item_key(this);
300}

References BIT, and itemkeys.

◆ spawnfunc() [4/6]

spawnfunc ( item_key_gold )

Definition at line 304 of file keys.qc.

305{
306 this.itemkeys = BIT(0);
307 spawnfunc_item_key(this);
308}

References BIT, and itemkeys.

◆ spawnfunc() [5/6]

spawnfunc ( item_key_master )

Definition at line 331 of file keys.qc.

332{
333 // We have more key types than QL, may as well open them all.
334 this.itemkeys = 0xffffff;
335 spawnfunc_item_key(this);
336}

References itemkeys.

◆ spawnfunc() [6/6]

spawnfunc ( item_key_silver )

Definition at line 310 of file keys.qc.

311{
312 this.itemkeys = BIT(1);
313 spawnfunc_item_key(this);
314}

References BIT, and itemkeys.