4 bool item_keys_usekey(entity l, entity p)
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
15 - add an unlock sound (here to trigger_keylock and to func_door)
16 - display available keys on the HUD
18 - think about adding NOT_EASY/NOT_NORMAL/NOT_HARD for Q1 compatibility
19 - should keys have a trigger?
22 bool item_keys_usekey(entity l, entity p)
24 int valid = l.itemkeys & p.itemkeys;
27 // player has none of the needed keys
29 } else if (l.itemkeys == valid) {
30 // ALL needed keys were given
34 // only some of the needed keys were given
40 string item_keys_keylist(float keylist) {
46 if ((keylist & (keylist-1)) == 0)
47 return strcat("the ", item_keys_names[lowestbit(keylist)]);
52 int l = lowestbit(keylist);
54 n = strcat(n, ", the ", item_keys_names[base + l]);
56 n = strcat("the ", item_keys_names[base + l]);
58 keylist = bitshift(keylist, -(l + 1));
67 ================================
69 ================================
75 void item_key_touch(entity this, entity toucher)
77 if (!IS_PLAYER(toucher))
80 // player already picked up this key
81 if (PS(toucher).itemkeys & this.itemkeys)
84 PS(toucher).itemkeys |= this.itemkeys;
85 play2(toucher, this.noise);
87 centerprint(toucher, this.message);
89 string oldmsg = this.message;
91 SUB_UseTargets(this, toucher, toucher); // TODO: should we be using toucher for the trigger here?
92 this.message = oldmsg;
96 * Spawn a key with given model, key code and color.
98 void spawn_item_key(entity this)
100 precache_model(this.model);
102 if (this.spawnflags & 1) // FLOATING
106 set_movetype(this, MOVETYPE_NONE);
108 set_movetype(this, MOVETYPE_TOSS);
110 precache_sound(this.noise);
112 this.mdl = this.model;
113 this.effects = EF_LOWPRECISION;
114 _setmodel(this, this.model);
115 this.modelflags |= MF_ROTATE;
116 this.solid = SOLID_TRIGGER;
118 // The origin.z was raised within the bbox to support the current model
119 //setsize(this, '-16 -16 -24', '16 16 32');
120 setorigin(this, this.origin + '0 0 32');
121 setsize(this, '-16 -16 -56', '16 16 0');
123 if (Q3COMPAT_COMMON) // QL compat, Q3 has no keys
124 // QL bbox is '-16 -16 -16' '16 16 16' so raise to match QL absmin.z
125 setorigin(this, this.origin + '0 0 8');
127 // NOTE: this isn't an FL_ITEM so it doesn't get the special treatment in DropToFloor_QC()
131 settouch(this, item_key_touch);
135 /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
137 The itemkeys bitfield should contain one of the following key IDs:
144 16777215 (0xffffff) - MASTER key (all 24 bits set)
147 - last key ID is 8388608 (1<<23 or 0x800000)
148 Keys (other than master keys) with bigger ID than 32 don't have a default netname and model,
149 if you use one of them, you MUST provide those.
150 -----------KEYS------------
151 colormod: color of the key (default: '.9 .9 .9').
153 message: message to print when player picks up this key.
154 model: custom key model to use.
155 netname: the display name of the key.
156 noise: custom sound to play when player picks up the key.
157 -------- SPAWNFLAGS --------
158 FLOATING: the item will float in air, instead of aligning to the floor by falling
159 ---------NOTES----------
160 This is the only correct way to put keys on the map!
162 itemkeys MUST always have exactly one bit set (unless it's a master key).
169 // reject this entity if more than one key was set!
170 if (this.itemkeys>0 && (this.itemkeys & (this.itemkeys-1)) != 0)
171 if (this.itemkeys != 0xffffff) // unless it's a master key
173 objerror(this, "item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
178 // find default netname and colormod
179 switch(this.itemkeys) {
181 _netname = "GOLD key";
182 _colormod = '1 .9 0';
186 _netname = "SILVER key";
187 _colormod = '.9 .9 .9';
191 _netname = "BRONZE key";
192 _colormod = '.6 .25 0';
196 _netname = "RED keycard";
197 _colormod = '.9 0 0';
201 _netname = "BLUE keycard";
202 _colormod = '0 0 .9';
206 _netname = "GREEN keycard";
207 _colormod = '0 .9 0';
210 case 0xffffff: // an unlisted key...
211 _netname = "MASTER key";
212 _colormod = '1 0.25 0.25';
216 _netname = "FLUFFY PINK keycard";
219 if (this.netname == "") {
220 objerror(this, "item_key doesn't have a default name for this key and a custom one was not specified!");
228 // find default model
229 string _model = string_null;
230 if (this.itemkeys <= ITEM_KEY_BIT(2) || this.itemkeys == 0xffffff) {
231 _model = "models/keys/key.md3";
232 } else if (this.itemkeys >= ITEM_KEY_BIT(3) && this.itemkeys <= ITEM_KEY_BIT(5)) {
233 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
234 } else if (this.model == "") {
235 objerror(this, "item_key doesn't have a default model for this key and a custom one was not specified!");
240 // set defailt netname
241 if (this.netname == "")
242 this.netname = _netname;
244 // set default colormod
246 this.colormod = _colormod;
249 if (this.model == "")
252 // set default pickup message
253 if (this.message == "")
254 this.message = strzone(strcat("You've picked up the ", this.netname, "!"));
256 if (this.noise == "")
257 this.noise = strzone(SND(ITEMPICKUP));
259 // save the name for later
260 item_keys_names[lowestbit(this.itemkeys)] = this.netname;
262 // put the key on the map
263 spawn_item_key(this);
266 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
268 -----------KEYS------------
269 colormod: color of the key (default: '.9 .9 .9').
270 message: message to print when player picks up this key.
271 model: custom model to use.
272 noise: custom sound to play when player picks up the key.
273 -------- SPAWNFLAGS --------
274 FLOATING: the item will float in air, instead of aligning to the floor by falling
275 ---------NOTES----------
276 Don't use this entity on new maps! Use item_key instead.
280 this.itemkeys = ITEM_KEY_BIT(1);
281 spawnfunc_item_key(this);
284 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
286 -----------KEYS------------
287 colormod: color of the key (default: '1 .9 0').
288 message: message to print when player picks up this key.
289 model: custom model to use.
290 noise: custom sound to play when player picks up the key.
291 -------- SPAWNFLAGS --------
292 FLOATING: the item will float in air, instead of aligning to the floor by falling
293 ---------NOTES----------
294 Don't use this entity on new maps! Use item_key instead.
298 this.itemkeys = ITEM_KEY_BIT(0);
299 spawnfunc_item_key(this);
303 /*QUAKED item_key_gold (1 .66 0) (-16 -16 -16) (16 16 16) SUSPENDED */
304 spawnfunc(item_key_gold)
306 this.itemkeys = BIT(0);
307 spawnfunc_item_key(this);
309 /*QUAKED item_key_silver (.56 .56 .56) (-16 -16 -16) (16 16 16) SUSPENDED */
310 spawnfunc(item_key_silver)
312 this.itemkeys = BIT(1);
313 spawnfunc_item_key(this);
315 /*QUAKED item_key_master (1 0 0) (-16 -16 -16) (16 16 16) SUSPENDED
316 Master key, opens silver and gold doors.
318 -------- KEYS --------
319 target : picking up the item will trigger the entity this points to.
320 targetname : a target_give entity can point to this for respawn freebies.
321 notfree : when set to 1, entity will not spawn in "Free for all", "Race", and "Duel" modes.
322 notteam : when set to 1, entity will not spawn in "Teamplay" and "CTF" modes.
323 notsingle : when set to 1, entity will not spawn in Single Player mode (bot play mode).
324 not_gametype : space delineated list of gametype shortnames (ffa duel race tdm ca ctf 1f ob har ft dom ad rr) in which to inhibit the entity.
325 gametype : space delineated list of gametype shortnames (ffa duel race tdm ca ctf 1f ob har ft dom ad rr) to only spawn entity in this gametype.
326 notbot : when set to 1, used to make an item invisible for bot attraction.
328 -------- SPAWNFLAGS --------
329 1 = suspended : item will spawn where it was placed in map and won't drop to the floor.
331 spawnfunc(item_key_master)
333 // We have more key types than QL, may as well open them all.
334 this.itemkeys = 0xffffff;
335 spawnfunc_item_key(this);