4 #include "../dpdefs/progsdefs.qh"
5 #include "../dpdefs/dpextensions.qh"
6 #include "../warpzonelib/util_server.qh"
7 #include "../common/util.qh"
8 #include "../common/monsters/monsters.qh"
10 #include "../common/notifications.qh"
11 #include "item_key.qh"
16 - add an unlock sound (here to trigger_keylock and to func_door)
17 - display available keys on the HUD
19 - think about adding NOT_EASY/NOT_NORMAL/NOT_HARD for Q1 compatibility
20 - should keys have a trigger?
23 bool item_keys_usekey(entity l, entity p) {
24 float valid = l.itemkeys & p.itemkeys;
27 // other 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(void) {
76 if (!IS_PLAYER(other))
79 // player already picked up this key
80 if (other.itemkeys & self.itemkeys)
83 other.itemkeys |= self.itemkeys;
84 play2(other, self.noise);
86 centerprint(other, self.message);
90 * Spawn a key with given model, key code and color.
92 void spawn_item_key() {
93 precache_model(self.model);
95 if (self.spawnflags & 1) // FLOATING
99 self.movetype = MOVETYPE_NONE;
101 self.movetype = MOVETYPE_TOSS;
103 precache_sound(self.noise);
105 self.mdl = self.model;
106 self.effects = EF_LOWPRECISION;
107 setmodel(self, self.model);
108 //setsize(self, '-16 -16 -24', '16 16 32');
109 setorigin(self, self.origin + '0 0 32');
110 setsize(self, '-16 -16 -56', '16 16 0');
111 self.modelflags |= MF_ROTATE;
112 self.solid = SOLID_TRIGGER;
116 // first nudge it off the floor a little bit to avoid math errors
117 setorigin(self, self.origin + '0 0 1');
118 // note droptofloor returns false if stuck/or would fall too far
122 self.touch = item_key_touch;
126 /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
128 The itemkeys should contain one of the following key IDs:
136 ... - last key is 1<<23
137 Keys with bigger Id than 32 don't have a default netname and model, if you use one of them, you MUST provide those.
138 -----------KEYS------------
139 colormod: color of the key (default: '.9 .9 .9').
141 message: message to print when player picks up this key.
142 model: custom key model to use.
143 netname: the display name of the key.
144 noise: custom sound to play when player picks up the key.
145 -------- SPAWNFLAGS --------
146 FLOATING: the item will float in air, instead of aligning to the floor by falling
147 ---------NOTES----------
148 This is the only correct way to put keys on the map!
150 itemkeys MUST always have exactly one bit set.
152 void spawnfunc_item_key() {
156 // reject this entity if more than one key was set!
157 if (self.itemkeys>0 && (self.itemkeys & (self.itemkeys-1)) != 0) {
158 objerror("item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
163 // find default netname and colormod
164 switch(self.itemkeys) {
166 _netname = "GOLD key";
167 _colormod = '1 .9 0';
171 _netname = "SILVER key";
172 _colormod = '.9 .9 .9';
176 _netname = "BRONZE key";
177 _colormod = '.6 .25 0';
181 _netname = "RED keycard";
182 _colormod = '.9 0 0';
186 _netname = "BLUE keycard";
187 _colormod = '0 0 .9';
191 _netname = "GREEN keycard";
192 _colormod = '0 .9 0';
196 _netname = "FLUFFY PINK keycard";
199 if (self.netname == "") {
200 objerror("item_key doesn't have a default name for this key and a custom one was not specified!");
208 // find default model
209 string _model = string_null;
210 if (self.itemkeys <= ITEM_KEY_BIT(2)) {
211 _model = "models/keys/key.md3";
212 } else if (self.itemkeys >= ITEM_KEY_BIT(3) && self.itemkeys <= ITEM_KEY_BIT(5)) {
213 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
214 } else if (self.model == "") {
215 objerror("item_key doesn't have a default model for this key and a custom one was not specified!");
220 // set defailt netname
221 if (self.netname == "")
222 self.netname = _netname;
224 // set default colormod
226 self.colormod = _colormod;
229 if (self.model == "")
232 // set default pickup message
233 if (self.message == "")
234 self.message = strzone(strcat("You've picked up the ", self.netname, "!"));
236 if (self.noise == "")
237 self.noise = "misc/itempickup.wav";
239 // save the name for later
240 item_keys_names[lowestbit(self.itemkeys)] = self.netname;
242 // put the key on the map
246 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
248 -----------KEYS------------
249 colormod: color of the key (default: '.9 .9 .9').
250 message: message to print when player picks up this key.
251 model: custom model to use.
252 noise: custom sound to play when player picks up the key.
253 -------- SPAWNFLAGS --------
254 FLOATING: the item will float in air, instead of aligning to the floor by falling
255 ---------NOTES----------
256 Don't use this entity on new maps! Use item_key instead.
258 void spawnfunc_item_key1(void) {
259 self.classname = "item_key";
260 self.itemkeys = ITEM_KEY_BIT(1);
261 spawnfunc_item_key();
264 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
266 -----------KEYS------------
267 colormod: color of the key (default: '1 .9 0').
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.
276 void spawnfunc_item_key2(void) {
277 self.classname = "item_key";
278 self.itemkeys = ITEM_KEY_BIT(0);
279 spawnfunc_item_key();
284 ================================
286 ================================
290 * trigger givent targets
292 void trigger_keylock_trigger(string s) {
294 entity otemp = other;
295 entity atemp = activator;
298 for(t = world; (t = find(t, targetname, s)); )
312 * kill killtarget of trigger keylock.
314 void trigger_keylock_kill(string s) {
316 for(t = world; (t = find(t, targetname, s)); )
320 void trigger_keylock_touch(void) {
321 bool key_used = false;
322 bool started_delay = false;
324 // only player may trigger the lock
325 if (!IS_PLAYER(other))
331 key_used = item_keys_usekey(self, other);
336 // at least one of the keys is missing
338 // one or more keys were given, but others are still missing!
339 play2(other, self.noise1);
340 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(self.itemkeys));
341 other.key_door_messagetime = time + 2;
342 } else if (other.key_door_messagetime <= time) {
343 // no keys were given
344 play2(other, self.noise2);
345 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(self.itemkeys));
346 other.key_door_messagetime = time + 2;
350 if (self.delay <= time || started_delay == true)
352 trigger_keylock_trigger(self.target2);
353 started_delay = true;
354 self.delay = time + self.wait;
357 // all keys were given!
358 play2(other, self.noise);
359 centerprint(other, self.message);
362 trigger_keylock_trigger(self.target);
365 trigger_keylock_kill(self.killtarget);
372 /*QUAKED trigger_keylock (.0 .5 .8) ?
373 Keylock trigger. Must target other entities.
374 This trigger will trigger target entities when all required keys are provided.
375 -------- KEYS --------
376 itemkeys: A bit field with key IDs that are needed to open this lock.
377 sounds: 1 to play misc/secret.wav, 2 to play misc/talk.wav, 3 to play misc/trigger1.wav (3 is default)
378 target: trigger all entities with this targetname when triggered and all keys have been given to it, then remove this trigger
379 target2: trigger all entities with this targetname when triggered without giving it all the required keys.
380 killtarget: remove all entities with this targetname when triggered with all the needed keys.
381 message: print this message to the player who activated the trigger when all needed keys have been given.
382 message2: print this message to the player who activated the trigger when not all of the needed keys have been given.
383 noise: sound to play when lock gets unlocked (default: see sounds)
384 noise1: sound to play when only some of the needed key were used but not all (default: misc/decreasevalue.wav)
385 noise2: sound to play when a key is missing (default: misc/talk.wav)
386 wait: prevent triggering again for this amount of time (default: 5) - applies to target2, target3, target4.
387 ---------NOTES----------
388 If spawned without any key specified in itemkeys, this trigger will display an error and remove itself.
389 message2 and noise2 will be resent to the player every 2 seconds while he is in the trigger zone.
391 void spawnfunc_trigger_keylock(void) {
392 if (!self.itemkeys) {
397 // set unlocked message
398 if (self.message == "")
399 self.message = "Unlocked!";
401 // set default unlock noise
402 if (self.noise == "") {
403 if (self.sounds == 1)
404 self.noise = "misc/secret.wav";
405 else if (self.sounds == 2)
406 self.noise = "misc/talk.wav";
407 else //if (self.sounds == 3) {
408 self.noise = "misc/trigger1.wav";
411 // set default use key sound
412 if (self.noise1 == "")
413 self.noise1 = "misc/decreasevalue.wav";
416 if (self.noise2 == "")
417 self.noise2 = "misc/talk.wav";
419 // delay between triggering message2 and trigger2
424 precache_sound(self.noise);
425 precache_sound(self.noise1);
426 precache_sound(self.noise2);
430 self.touch = trigger_keylock_touch;