4 #include "../common/monsters/all.qh"
5 #include "../common/notifications.qh"
6 #include "../common/util.qh"
7 #include "../warpzonelib/util_server.qh"
11 - add an unlock sound (here to trigger_keylock and to func_door)
12 - display available keys on the HUD
14 - think about adding NOT_EASY/NOT_NORMAL/NOT_HARD for Q1 compatibility
15 - should keys have a trigger?
18 bool item_keys_usekey(entity l, entity p) {
19 float valid = l.itemkeys & p.itemkeys;
22 // other has none of the needed keys
24 } else if (l.itemkeys == valid) {
25 // ALL needed keys were given
29 // only some of the needed keys were given
35 string item_keys_keylist(float keylist) {
41 if ((keylist & (keylist-1)) != 0)
42 return strcat("the ", item_keys_names[lowestbit(keylist)]);
47 int l = lowestbit(keylist);
49 n = strcat(n, ", the ", item_keys_names[base + l]);
51 n = strcat("the ", item_keys_names[base + l]);
53 keylist = bitshift(keylist, -(l + 1));
62 ================================
64 ================================
70 void item_key_touch(void) {
71 if (!IS_PLAYER(other))
74 // player already picked up this key
75 if (other.itemkeys & self.itemkeys)
78 other.itemkeys |= self.itemkeys;
79 play2(other, self.noise);
81 centerprint(other, self.message);
85 * Spawn a key with given model, key code and color.
87 void spawn_item_key() {
88 precache_model(self.model);
90 if (self.spawnflags & 1) // FLOATING
94 self.movetype = MOVETYPE_NONE;
96 self.movetype = MOVETYPE_TOSS;
98 precache_sound(self.noise);
100 self.mdl = self.model;
101 self.effects = EF_LOWPRECISION;
102 setmodel(self, self.model);
103 //setsize(self, '-16 -16 -24', '16 16 32');
104 setorigin(self, self.origin + '0 0 32');
105 setsize(self, '-16 -16 -56', '16 16 0');
106 self.modelflags |= MF_ROTATE;
107 self.solid = SOLID_TRIGGER;
111 // first nudge it off the floor a little bit to avoid math errors
112 setorigin(self, self.origin + '0 0 1');
113 // note droptofloor returns false if stuck/or would fall too far
117 self.touch = item_key_touch;
121 /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
123 The itemkeys should contain one of the following key IDs:
131 ... - last key is 1<<23
132 Keys with bigger Id than 32 don't have a default netname and model, if you use one of them, you MUST provide those.
133 -----------KEYS------------
134 colormod: color of the key (default: '.9 .9 .9').
136 message: message to print when player picks up this key.
137 model: custom key model to use.
138 netname: the display name of the key.
139 noise: custom sound to play when player picks up the key.
140 -------- SPAWNFLAGS --------
141 FLOATING: the item will float in air, instead of aligning to the floor by falling
142 ---------NOTES----------
143 This is the only correct way to put keys on the map!
145 itemkeys MUST always have exactly one bit set.
147 void spawnfunc_item_key() {
151 // reject this entity if more than one key was set!
152 if (self.itemkeys>0 && (self.itemkeys & (self.itemkeys-1)) != 0) {
153 objerror("item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
158 // find default netname and colormod
159 switch(self.itemkeys) {
161 _netname = "GOLD key";
162 _colormod = '1 .9 0';
166 _netname = "SILVER key";
167 _colormod = '.9 .9 .9';
171 _netname = "BRONZE key";
172 _colormod = '.6 .25 0';
176 _netname = "RED keycard";
177 _colormod = '.9 0 0';
181 _netname = "BLUE keycard";
182 _colormod = '0 0 .9';
186 _netname = "GREEN keycard";
187 _colormod = '0 .9 0';
191 _netname = "FLUFFY PINK keycard";
194 if (self.netname == "") {
195 objerror("item_key doesn't have a default name for this key and a custom one was not specified!");
203 // find default model
204 string _model = string_null;
205 if (self.itemkeys <= ITEM_KEY_BIT(2)) {
206 _model = "models/keys/key.md3";
207 } else if (self.itemkeys >= ITEM_KEY_BIT(3) && self.itemkeys <= ITEM_KEY_BIT(5)) {
208 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
209 } else if (self.model == "") {
210 objerror("item_key doesn't have a default model for this key and a custom one was not specified!");
215 // set defailt netname
216 if (self.netname == "")
217 self.netname = _netname;
219 // set default colormod
221 self.colormod = _colormod;
224 if (self.model == "")
227 // set default pickup message
228 if (self.message == "")
229 self.message = strzone(strcat("You've picked up the ", self.netname, "!"));
231 if (self.noise == "")
232 self.noise = "misc/itempickup.wav";
234 // save the name for later
235 item_keys_names[lowestbit(self.itemkeys)] = self.netname;
237 // put the key on the map
241 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
243 -----------KEYS------------
244 colormod: color of the key (default: '.9 .9 .9').
245 message: message to print when player picks up this key.
246 model: custom model to use.
247 noise: custom sound to play when player picks up the key.
248 -------- SPAWNFLAGS --------
249 FLOATING: the item will float in air, instead of aligning to the floor by falling
250 ---------NOTES----------
251 Don't use this entity on new maps! Use item_key instead.
253 void spawnfunc_item_key1(void) {
254 self.classname = "item_key";
255 self.itemkeys = ITEM_KEY_BIT(1);
256 spawnfunc_item_key();
259 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
261 -----------KEYS------------
262 colormod: color of the key (default: '1 .9 0').
263 message: message to print when player picks up this key.
264 model: custom model to use.
265 noise: custom sound to play when player picks up the key.
266 -------- SPAWNFLAGS --------
267 FLOATING: the item will float in air, instead of aligning to the floor by falling
268 ---------NOTES----------
269 Don't use this entity on new maps! Use item_key instead.
271 void spawnfunc_item_key2(void) {
272 self.classname = "item_key";
273 self.itemkeys = ITEM_KEY_BIT(0);
274 spawnfunc_item_key();
279 ================================
281 ================================
285 * trigger givent targets
287 void trigger_keylock_trigger(string s) {
289 entity otemp = other;
290 entity atemp = activator;
293 for(t = world; (t = find(t, targetname, s)); )
307 * kill killtarget of trigger keylock.
309 void trigger_keylock_kill(string s) {
311 for(t = world; (t = find(t, targetname, s)); )
315 void trigger_keylock_touch(void) {
316 bool key_used = false;
317 bool started_delay = false;
319 // only player may trigger the lock
320 if (!IS_PLAYER(other))
326 key_used = item_keys_usekey(self, other);
331 // at least one of the keys is missing
333 // one or more keys were given, but others are still missing!
334 play2(other, self.noise1);
335 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(self.itemkeys));
336 other.key_door_messagetime = time + 2;
337 } else if (other.key_door_messagetime <= time) {
338 // no keys were given
339 play2(other, self.noise2);
340 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(self.itemkeys));
341 other.key_door_messagetime = time + 2;
345 if (self.delay <= time || started_delay == true)
347 trigger_keylock_trigger(self.target2);
348 started_delay = true;
349 self.delay = time + self.wait;
352 // all keys were given!
353 play2(other, self.noise);
354 centerprint(other, self.message);
357 trigger_keylock_trigger(self.target);
360 trigger_keylock_kill(self.killtarget);
367 /*QUAKED trigger_keylock (.0 .5 .8) ?
368 Keylock trigger. Must target other entities.
369 This trigger will trigger target entities when all required keys are provided.
370 -------- KEYS --------
371 itemkeys: A bit field with key IDs that are needed to open this lock.
372 sounds: 1 to play misc/secret.wav, 2 to play misc/talk.wav, 3 to play misc/trigger1.wav (3 is default)
373 target: trigger all entities with this targetname when triggered and all keys have been given to it, then remove this trigger
374 target2: trigger all entities with this targetname when triggered without giving it all the required keys.
375 killtarget: remove all entities with this targetname when triggered with all the needed keys.
376 message: print this message to the player who activated the trigger when all needed keys have been given.
377 message2: print this message to the player who activated the trigger when not all of the needed keys have been given.
378 noise: sound to play when lock gets unlocked (default: see sounds)
379 noise1: sound to play when only some of the needed key were used but not all (default: misc/decreasevalue.wav)
380 noise2: sound to play when a key is missing (default: misc/talk.wav)
381 wait: prevent triggering again for this amount of time (default: 5) - applies to target2, target3, target4.
382 ---------NOTES----------
383 If spawned without any key specified in itemkeys, this trigger will display an error and remove itself.
384 message2 and noise2 will be resent to the player every 2 seconds while he is in the trigger zone.
386 void spawnfunc_trigger_keylock(void) {
387 if (!self.itemkeys) {
392 // set unlocked message
393 if (self.message == "")
394 self.message = "Unlocked!";
396 // set default unlock noise
397 if (self.noise == "") {
398 if (self.sounds == 1)
399 self.noise = "misc/secret.wav";
400 else if (self.sounds == 2)
401 self.noise = "misc/talk.wav";
402 else //if (self.sounds == 3) {
403 self.noise = "misc/trigger1.wav";
406 // set default use key sound
407 if (self.noise1 == "")
408 self.noise1 = "misc/decreasevalue.wav";
411 if (self.noise2 == "")
412 self.noise2 = "misc/talk.wav";
414 // delay between triggering message2 and trigger2
419 precache_sound(self.noise);
420 precache_sound(self.noise1);
421 precache_sound(self.noise2);
425 self.touch = trigger_keylock_touch;