X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fitem_key.qc;h=713fbf6c3df57e87a8c704e7916da1ba11e562b0;hb=32ca966802c45c4c231210c2d8776bc3f4135dc2;hp=0963a294a1eb867272a9e2e0ea3315866a5339a7;hpb=ba0988ca930f50286f8cf3b6c114ebc6584964af;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/item_key.qc b/qcsrc/server/item_key.qc index 0963a294a..713fbf6c3 100644 --- a/qcsrc/server/item_key.qc +++ b/qcsrc/server/item_key.qc @@ -1,15 +1,11 @@ -#if defined(CSQC) -#elif defined(MENUQC) -#elif defined(SVQC) - #include "../dpdefs/progsdefs.qc" - #include "../dpdefs/dpextensions.qc" - #include "../warpzonelib/util_server.qh" - #include "../common/util.qh" - #include "../common/monsters/monsters.qh" - #include "defs.qh" - #include "../common/notifications.qh" - #include "item_key.qh" -#endif +#include "item_key.qh" +#include "_all.qh" + +#include "../common/triggers/subs.qh" +#include "../common/monsters/all.qh" +#include "../common/notifications.qh" +#include "../common/util.qh" +#include "../warpzonelib/util_server.qh" /* TODO: @@ -20,7 +16,8 @@ TODO: - should keys have a trigger? */ -bool item_keys_usekey(entity l, entity p) { +bool item_keys_usekey(entity l, entity p) +{ float valid = l.itemkeys & p.itemkeys; if (!valid) { @@ -38,9 +35,6 @@ bool item_keys_usekey(entity l, entity p) { } string item_keys_keylist(float keylist) { - float base, l; - string n; - // no keys if (!keylist) return ""; @@ -49,10 +43,10 @@ string item_keys_keylist(float keylist) { if ((keylist & (keylist-1)) != 0) return strcat("the ", item_keys_names[lowestbit(keylist)]); - n = ""; - base = 0; + string n = ""; + int base = 0; while (keylist) { - l = lowestbit(keylist); + int l = lowestbit(keylist); if (n) n = strcat(n, ", the ", item_keys_names[base + l]); else @@ -75,7 +69,8 @@ item_key /** * Key touch handler. */ -void item_key_touch(void) { +void item_key_touch() +{SELFPARAM(); if (!IS_PLAYER(other)) return; @@ -92,7 +87,8 @@ void item_key_touch(void) { /** * Spawn a key with given model, key code and color. */ -void spawn_item_key() { +void spawn_item_key() +{SELFPARAM(); precache_model(self.model); if (self.spawnflags & 1) // FLOATING @@ -107,7 +103,7 @@ void spawn_item_key() { self.mdl = self.model; self.effects = EF_LOWPRECISION; - setmodel(self, self.model); + _setmodel(self, self.model); //setsize(self, '-16 -16 -24', '16 16 32'); setorigin(self, self.origin + '0 0 32'); setsize(self, '-16 -16 -56', '16 16 0'); @@ -152,7 +148,8 @@ This is the only correct way to put keys on the map! itemkeys MUST always have exactly one bit set. */ -void spawnfunc_item_key() { +spawnfunc(item_key) +{ string _netname; vector _colormod; @@ -237,7 +234,7 @@ void spawnfunc_item_key() { self.message = strzone(strcat("You've picked up the ", self.netname, "!")); if (self.noise == "") - self.noise = "misc/itempickup.wav"; + self.noise = SND(ITEMPICKUP); // save the name for later item_keys_names[lowestbit(self.itemkeys)] = self.netname; @@ -258,10 +255,11 @@ FLOATING: the item will float in air, instead of aligning to the floor by fallin ---------NOTES---------- Don't use this entity on new maps! Use item_key instead. */ -void spawnfunc_item_key1(void) { - self.classname = "item_key"; - self.itemkeys = ITEM_KEY_BIT(1); - spawnfunc_item_key(); +spawnfunc(item_key1) +{ + this.classname = "item_key"; + this.itemkeys = ITEM_KEY_BIT(1); + spawnfunc_item_key(this); }; /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING @@ -276,161 +274,9 @@ FLOATING: the item will float in air, instead of aligning to the floor by fallin ---------NOTES---------- Don't use this entity on new maps! Use item_key instead. */ -void spawnfunc_item_key2(void) { - self.classname = "item_key"; - self.itemkeys = ITEM_KEY_BIT(0); - spawnfunc_item_key(); -}; - - -/* -================================ -trigger_keylock -================================ -*/ - -/** - * trigger givent targets - */ -void trigger_keylock_trigger(string s) { - entity stemp = self; - entity otemp = other; - entity atemp = activator; - - entity t; - for(t = world; (t = find(t, targetname, s)); ) - if (t.use) { - self = t; - other = stemp; - activator = atemp; - self.use(); - } - - self = stemp; - other = otemp; - activator = atemp; -}; - -/** - * kill killtarget of trigger keylock. - */ -void trigger_keylock_kill(string s) { - entity t; - for(t = world; (t = find(t, targetname, s)); ) - remove(t); -}; - -void trigger_keylock_touch(void) { - bool key_used = false; - bool started_delay = false; - - // only player may trigger the lock - if (!IS_PLAYER(other)) - return; - - - // check silver key - if (self.itemkeys) - key_used = item_keys_usekey(self, other); - - activator = other; - - if (self.itemkeys) { - // at least one of the keys is missing - if (key_used) { - // one or more keys were given, but others are still missing! - play2(other, self.noise1); - Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_ALSONEED, item_keys_keylist(self.itemkeys)); - other.key_door_messagetime = time + 2; - } else if (other.key_door_messagetime <= time) { - // no keys were given - play2(other, self.noise2); - Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_DOOR_LOCKED_NEED, item_keys_keylist(self.itemkeys)); - other.key_door_messagetime = time + 2; - } - - // trigger target2 - if (self.delay <= time || started_delay == true) - if (self.target2) { - trigger_keylock_trigger(self.target2); - started_delay = true; - self.delay = time + self.wait; - } - } else { - // all keys were given! - play2(other, self.noise); - centerprint(other, self.message); - - if (self.target) - trigger_keylock_trigger(self.target); - - if (self.killtarget) - trigger_keylock_kill(self.killtarget); - - remove(self); - } - -}; - -/*QUAKED trigger_keylock (.0 .5 .8) ? -Keylock trigger. Must target other entities. -This trigger will trigger target entities when all required keys are provided. --------- KEYS -------- -itemkeys: A bit field with key IDs that are needed to open this lock. -sounds: 1 to play misc/secret.wav, 2 to play misc/talk.wav, 3 to play misc/trigger1.wav (3 is default) -target: trigger all entities with this targetname when triggered and all keys have been given to it, then remove this trigger -target2: trigger all entities with this targetname when triggered without giving it all the required keys. -killtarget: remove all entities with this targetname when triggered with all the needed keys. -message: print this message to the player who activated the trigger when all needed keys have been given. -message2: print this message to the player who activated the trigger when not all of the needed keys have been given. -noise: sound to play when lock gets unlocked (default: see sounds) -noise1: sound to play when only some of the needed key were used but not all (default: misc/decreasevalue.wav) -noise2: sound to play when a key is missing (default: misc/talk.wav) -wait: prevent triggering again for this amount of time (default: 5) - applies to target2, target3, target4. ----------NOTES---------- -If spawned without any key specified in itemkeys, this trigger will display an error and remove itself. -message2 and noise2 will be resent to the player every 2 seconds while he is in the trigger zone. -*/ -void spawnfunc_trigger_keylock(void) { - if (!self.itemkeys) { - remove(self); - return; - } - - // set unlocked message - if (self.message == "") - self.message = "Unlocked!"; - - // set default unlock noise - if (self.noise == "") { - if (self.sounds == 1) - self.noise = "misc/secret.wav"; - else if (self.sounds == 2) - self.noise = "misc/talk.wav"; - else //if (self.sounds == 3) { - self.noise = "misc/trigger1.wav"; - } - - // set default use key sound - if (self.noise1 == "") - self.noise1 = "misc/decreasevalue.wav"; - - // set closed sourd - if (self.noise2 == "") - self.noise2 = "misc/talk.wav"; - - // delay between triggering message2 and trigger2 - if (!self.wait) - self.wait = 5; - - // precache sounds - precache_sound(self.noise); - precache_sound(self.noise1); - precache_sound(self.noise2); - - EXACTTRIGGER_INIT; - - self.touch = trigger_keylock_touch; +spawnfunc(item_key2) +{ + this.classname = "item_key"; + this.itemkeys = ITEM_KEY_BIT(0); + spawnfunc_item_key(this); }; - -