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).
168 string _model = "models/keys/key.md3";
170 // reject this entity if more than one key was set!
171 if (this.itemkeys>0 && (this.itemkeys & (this.itemkeys-1)) != 0)
172 if (this.itemkeys != 0xffffff) // unless it's a master key
174 objerror(this, "item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
179 // find default netname and colormod
180 switch(this.itemkeys) {
182 _netname = "GOLD key";
183 _colormod = '1 .9 0';
187 _netname = "SILVER key";
188 _colormod = '.9 .9 .9';
192 _netname = "BRONZE key";
193 _colormod = '.6 .25 0';
197 _netname = "RED keycard";
198 _colormod = '.9 0 0';
199 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
203 _netname = "BLUE keycard";
204 _colormod = '0 0 .9';
205 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
209 _netname = "GREEN keycard";
210 _colormod = '0 .9 0';
211 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
214 case 0xffffff: // an unlisted key...
215 _netname = "MASTER key";
216 _colormod = '1 0.25 0.25';
220 _netname = "FLUFFY PINK keycard";
223 if (this.netname == "")
225 objerror(this, "item_key doesn't have a default name for this key and a custom one was not specified!");
229 if (this.model == "")
231 objerror(this, "item_key doesn't have a default model for this key and a custom one was not specified!");
238 // set default netname
239 if (this.netname == "")
240 this.netname = _netname;
242 // set default colormod
244 this.colormod = _colormod;
247 if (this.model == "")
250 // set default pickup message
251 if (this.message == "")
252 this.message = strzone(strcat("You've picked up the ", this.netname, "!"));
254 if (this.noise == "")
255 this.noise = strzone(SND(ITEMPICKUP));
257 // save the name for later
258 item_keys_names[lowestbit(this.itemkeys)] = this.netname;
260 // put the key on the map
261 spawn_item_key(this);
264 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
266 -----------KEYS------------
267 colormod: color of the key (default: '.9 .9 .9').
268 message: message to print when player picks up this key.
269 model: custom model to use.
270 noise: custom sound to play when player picks up the key.
271 -------- SPAWNFLAGS --------
272 FLOATING: the item will float in air, instead of aligning to the floor by falling
273 ---------NOTES----------
274 Don't use this entity on new maps! Use item_key instead.
278 this.itemkeys = BIT(1);
279 spawnfunc_item_key(this);
282 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
284 -----------KEYS------------
285 colormod: color of the key (default: '1 .9 0').
286 message: message to print when player picks up this key.
287 model: custom model to use.
288 noise: custom sound to play when player picks up the key.
289 -------- SPAWNFLAGS --------
290 FLOATING: the item will float in air, instead of aligning to the floor by falling
291 ---------NOTES----------
292 Don't use this entity on new maps! Use item_key instead.
296 this.itemkeys = BIT(0);
297 spawnfunc_item_key(this);
301 /*QUAKED item_key_gold (1 .66 0) (-16 -16 -16) (16 16 16) SUSPENDED */
302 spawnfunc(item_key_gold)
304 this.itemkeys = BIT(0);
305 spawnfunc_item_key(this);
307 /*QUAKED item_key_silver (.56 .56 .56) (-16 -16 -16) (16 16 16) SUSPENDED */
308 spawnfunc(item_key_silver)
310 this.itemkeys = BIT(1);
311 spawnfunc_item_key(this);
313 /*QUAKED item_key_master (1 0 0) (-16 -16 -16) (16 16 16) SUSPENDED
314 Master key, opens silver and gold doors.
316 -------- KEYS --------
317 target : picking up the item will trigger the entity this points to.
318 targetname : a target_give entity can point to this for respawn freebies.
319 notfree : when set to 1, entity will not spawn in "Free for all", "Race", and "Duel" modes.
320 notteam : when set to 1, entity will not spawn in "Teamplay" and "CTF" modes.
321 notsingle : when set to 1, entity will not spawn in Single Player mode (bot play mode).
322 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.
323 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.
324 notbot : when set to 1, used to make an item invisible for bot attraction.
326 -------- SPAWNFLAGS --------
327 1 = suspended : item will spawn where it was placed in map and won't drop to the floor.
329 spawnfunc(item_key_master)
331 // We have more key types than QL, may as well open them all.
332 this.itemkeys = 0xffffff;
333 spawnfunc_item_key(this);