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) {
49 if ((keylist & (keylist-1)) != 0)
50 return strcat("the ", item_keys_names[lowestbit(keylist)]);
55 l = lowestbit(keylist);
57 n = strcat(n, ", the ", item_keys_names[base + l]);
59 n = strcat("the ", item_keys_names[base + l]);
61 keylist = bitshift(keylist, -(l + 1));
70 ================================
72 ================================
78 void item_key_touch(void) {
79 if (!IS_PLAYER(other))
82 // player already picked up this key
83 if (other.itemkeys & self.itemkeys)
86 other.itemkeys |= self.itemkeys;
87 play2(other, self.noise);
89 centerprint(other, self.message);
93 * Spawn a key with given model, key code and color.
95 void spawn_item_key() {
96 precache_model(self.model);
98 if (self.spawnflags & 1) // FLOATING
102 self.movetype = MOVETYPE_NONE;
104 self.movetype = MOVETYPE_TOSS;
106 precache_sound(self.noise);
108 self.mdl = self.model;
109 self.effects = EF_LOWPRECISION;
110 setmodel(self, self.model);
111 //setsize(self, '-16 -16 -24', '16 16 32');
112 setorigin(self, self.origin + '0 0 32');
113 setsize(self, '-16 -16 -56', '16 16 0');
114 self.modelflags |= MF_ROTATE;
115 self.solid = SOLID_TRIGGER;
119 // first nudge it off the floor a little bit to avoid math errors
120 setorigin(self, self.origin + '0 0 1');
121 // note droptofloor returns false if stuck/or would fall too far
125 self.touch = item_key_touch;
129 /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
131 The itemkeys should contain one of the following key IDs:
139 ... - last key is 1<<23
140 Keys with bigger Id than 32 don't have a default netname and model, if you use one of them, you MUST provide those.
141 -----------KEYS------------
142 colormod: color of the key (default: '.9 .9 .9').
144 message: message to print when player picks up this key.
145 model: custom key model to use.
146 netname: the display name of the key.
147 noise: custom sound to play when player picks up the key.
148 -------- SPAWNFLAGS --------
149 FLOATING: the item will float in air, instead of aligning to the floor by falling
150 ---------NOTES----------
151 This is the only correct way to put keys on the map!
153 itemkeys MUST always have exactly one bit set.
155 void spawnfunc_item_key() {
159 // reject this entity if more than one key was set!
160 if (self.itemkeys>0 && (self.itemkeys & (self.itemkeys-1)) != 0) {
161 objerror("item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
166 // find default netname and colormod
167 switch(self.itemkeys) {
169 _netname = "GOLD key";
170 _colormod = '1 .9 0';
174 _netname = "SILVER key";
175 _colormod = '.9 .9 .9';
179 _netname = "BRONZE key";
180 _colormod = '.6 .25 0';
184 _netname = "RED keycard";
185 _colormod = '.9 0 0';
189 _netname = "BLUE keycard";
190 _colormod = '0 0 .9';
194 _netname = "GREEN keycard";
195 _colormod = '0 .9 0';
199 _netname = "FLUFFY PINK keycard";
202 if (self.netname == "") {
203 objerror("item_key doesn't have a default name for this key and a custom one was not specified!");
211 // find default model
212 string _model = string_null;
213 if (self.itemkeys <= ITEM_KEY_BIT(2)) {
214 _model = "models/keys/key.md3";
215 } else if (self.itemkeys >= ITEM_KEY_BIT(3) && self.itemkeys <= ITEM_KEY_BIT(5)) {
216 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
217 } else if (self.model == "") {
218 objerror("item_key doesn't have a default model for this key and a custom one was not specified!");
223 // set defailt netname
224 if (self.netname == "")
225 self.netname = _netname;
227 // set default colormod
229 self.colormod = _colormod;
232 if (self.model == "")
235 // set default pickup message
236 if (self.message == "")
237 self.message = strzone(strcat("You've picked up the ", self.netname, "!"));
239 if (self.noise == "")
240 self.noise = "misc/itempickup.wav";
242 // save the name for later
243 item_keys_names[lowestbit(self.itemkeys)] = self.netname;
245 // put the key on the map
249 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
251 -----------KEYS------------
252 colormod: color of the key (default: '.9 .9 .9').
253 message: message to print when player picks up this key.
254 model: custom model to use.
255 noise: custom sound to play when player picks up the key.
256 -------- SPAWNFLAGS --------
257 FLOATING: the item will float in air, instead of aligning to the floor by falling
258 ---------NOTES----------
259 Don't use this entity on new maps! Use item_key instead.
261 void spawnfunc_item_key1(void) {
262 self.classname = "item_key";
263 self.itemkeys = ITEM_KEY_BIT(1);
264 spawnfunc_item_key();
267 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
269 -----------KEYS------------
270 colormod: color of the key (default: '1 .9 0').
271 message: message to print when player picks up this key.
272 model: custom model to use.
273 noise: custom sound to play when player picks up the key.
274 -------- SPAWNFLAGS --------
275 FLOATING: the item will float in air, instead of aligning to the floor by falling
276 ---------NOTES----------
277 Don't use this entity on new maps! Use item_key instead.
279 void spawnfunc_item_key2(void) {
280 self.classname = "item_key";
281 self.itemkeys = ITEM_KEY_BIT(0);
282 spawnfunc_item_key();
287 ================================
289 ================================
293 * trigger givent targets
295 void trigger_keylock_trigger(string s) {
297 entity otemp = other;
298 entity atemp = activator;
301 for(t = world; (t = find(t, targetname, s)); )
315 * kill killtarget of trigger keylock.
317 void trigger_keylock_kill(string s) {
319 for(t = world; (t = find(t, targetname, s)); )
323 void trigger_keylock_touch(void) {
324 bool key_used = false;
325 bool started_delay = false;
327 // only player may trigger the lock
328 if (!IS_PLAYER(other))
334 key_used = item_keys_usekey(self, other);
339 // at least one of the keys is missing
341 // one or more keys were given, but others are still missing!
342 play2(other, self.noise1);
343 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(self.itemkeys));
344 other.key_door_messagetime = time + 2;
345 } else if (other.key_door_messagetime <= time) {
346 // no keys were given
347 play2(other, self.noise2);
348 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(self.itemkeys));
349 other.key_door_messagetime = time + 2;
353 if (self.delay <= time || started_delay == true)
355 trigger_keylock_trigger(self.target2);
356 started_delay = true;
357 self.delay = time + self.wait;
360 // all keys were given!
361 play2(other, self.noise);
362 centerprint(other, self.message);
365 trigger_keylock_trigger(self.target);
368 trigger_keylock_kill(self.killtarget);
375 /*QUAKED trigger_keylock (.0 .5 .8) ?
376 Keylock trigger. Must target other entities.
377 This trigger will trigger target entities when all required keys are provided.
378 -------- KEYS --------
379 itemkeys: A bit field with key IDs that are needed to open this lock.
380 sounds: 1 to play misc/secret.wav, 2 to play misc/talk.wav, 3 to play misc/trigger1.wav (3 is default)
381 target: trigger all entities with this targetname when triggered and all keys have been given to it, then remove this trigger
382 target2: trigger all entities with this targetname when triggered without giving it all the required keys.
383 killtarget: remove all entities with this targetname when triggered with all the needed keys.
384 message: print this message to the player who activated the trigger when all needed keys have been given.
385 message2: print this message to the player who activated the trigger when not all of the needed keys have been given.
386 noise: sound to play when lock gets unlocked (default: see sounds)
387 noise1: sound to play when only some of the needed key were used but not all (default: misc/decreasevalue.wav)
388 noise2: sound to play when a key is missing (default: misc/talk.wav)
389 wait: prevent triggering again for this amount of time (default: 5) - applies to target2, target3, target4.
390 ---------NOTES----------
391 If spawned without any key specified in itemkeys, this trigger will display an error and remove itself.
392 message2 and noise2 will be resent to the player every 2 seconds while he is in the trigger zone.
394 void spawnfunc_trigger_keylock(void) {
395 if (!self.itemkeys) {
400 // set unlocked message
401 if (self.message == "")
402 self.message = "Unlocked!";
404 // set default unlock noise
405 if (self.noise == "") {
406 if (self.sounds == 1)
407 self.noise = "misc/secret.wav";
408 else if (self.sounds == 2)
409 self.noise = "misc/talk.wav";
410 else //if (self.sounds == 3) {
411 self.noise = "misc/trigger1.wav";
414 // set default use key sound
415 if (self.noise1 == "")
416 self.noise1 = "misc/decreasevalue.wav";
419 if (self.noise2 == "")
420 self.noise2 = "misc/talk.wav";
422 // delay between triggering message2 and trigger2
427 precache_sound(self.noise);
428 precache_sound(self.noise1);
429 precache_sound(self.noise2);
433 self.touch = trigger_keylock_touch;