3 #include "../common/triggers/subs.qh"
4 #include "../common/monsters/all.qh"
5 #include "../common/notifications.qh"
6 #include "../common/util.qh"
7 #include "../lib/warpzone/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)
20 float valid = l.itemkeys & p.itemkeys;
23 // other has none of the needed keys
25 } else if (l.itemkeys == valid) {
26 // ALL needed keys were given
30 // only some of the needed keys were given
36 string item_keys_keylist(float keylist) {
42 if ((keylist & (keylist-1)) != 0)
43 return strcat("the ", item_keys_names[lowestbit(keylist)]);
48 int l = lowestbit(keylist);
50 n = strcat(n, ", the ", item_keys_names[base + l]);
52 n = strcat("the ", item_keys_names[base + l]);
54 keylist = bitshift(keylist, -(l + 1));
63 ================================
65 ================================
73 if (!IS_PLAYER(other))
76 // player already picked up this key
77 if (other.itemkeys & self.itemkeys)
80 other.itemkeys |= self.itemkeys;
81 play2(other, self.noise);
83 centerprint(other, self.message);
90 * Spawn a key with given model, key code and color.
94 precache_model(self.model);
96 if (self.spawnflags & 1) // FLOATING
100 self.movetype = MOVETYPE_NONE;
102 self.movetype = MOVETYPE_TOSS;
104 precache_sound(self.noise);
106 self.mdl = self.model;
107 self.effects = EF_LOWPRECISION;
108 _setmodel(self, self.model);
109 //setsize(self, '-16 -16 -24', '16 16 32');
110 setorigin(self, self.origin + '0 0 32');
111 setsize(self, '-16 -16 -56', '16 16 0');
112 self.modelflags |= MF_ROTATE;
113 self.solid = SOLID_TRIGGER;
117 // first nudge it off the floor a little bit to avoid math errors
118 setorigin(self, self.origin + '0 0 1');
119 // note droptofloor returns false if stuck/or would fall too far
123 self.touch = item_key_touch;
127 /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
129 The itemkeys should contain one of the following key IDs:
137 ... - last key is 1<<23
138 Keys with bigger Id than 32 don't have a default netname and model, if you use one of them, you MUST provide those.
139 -----------KEYS------------
140 colormod: color of the key (default: '.9 .9 .9').
142 message: message to print when player picks up this key.
143 model: custom key model to use.
144 netname: the display name of the key.
145 noise: custom sound to play when player picks up the key.
146 -------- SPAWNFLAGS --------
147 FLOATING: the item will float in air, instead of aligning to the floor by falling
148 ---------NOTES----------
149 This is the only correct way to put keys on the map!
151 itemkeys MUST always have exactly one bit set.
158 // reject this entity if more than one key was set!
159 if (self.itemkeys>0 && (self.itemkeys & (self.itemkeys-1)) != 0) {
160 objerror("item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
165 // find default netname and colormod
166 switch(self.itemkeys) {
168 _netname = "GOLD key";
169 _colormod = '1 .9 0';
173 _netname = "SILVER key";
174 _colormod = '.9 .9 .9';
178 _netname = "BRONZE key";
179 _colormod = '.6 .25 0';
183 _netname = "RED keycard";
184 _colormod = '.9 0 0';
188 _netname = "BLUE keycard";
189 _colormod = '0 0 .9';
193 _netname = "GREEN keycard";
194 _colormod = '0 .9 0';
198 _netname = "FLUFFY PINK keycard";
201 if (self.netname == "") {
202 objerror("item_key doesn't have a default name for this key and a custom one was not specified!");
210 // find default model
211 string _model = string_null;
212 if (self.itemkeys <= ITEM_KEY_BIT(2)) {
213 _model = "models/keys/key.md3";
214 } else if (self.itemkeys >= ITEM_KEY_BIT(3) && self.itemkeys <= ITEM_KEY_BIT(5)) {
215 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
216 } else if (self.model == "") {
217 objerror("item_key doesn't have a default model for this key and a custom one was not specified!");
222 // set defailt netname
223 if (self.netname == "")
224 self.netname = _netname;
226 // set default colormod
228 self.colormod = _colormod;
231 if (self.model == "")
234 // set default pickup message
235 if (self.message == "")
236 self.message = strzone(strcat("You've picked up the ", self.netname, "!"));
238 if (self.noise == "")
239 self.noise = SND(ITEMPICKUP);
241 // save the name for later
242 item_keys_names[lowestbit(self.itemkeys)] = self.netname;
244 // put the key on the map
248 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
250 -----------KEYS------------
251 colormod: color of the key (default: '.9 .9 .9').
252 message: message to print when player picks up this key.
253 model: custom model to use.
254 noise: custom sound to play when player picks up the key.
255 -------- SPAWNFLAGS --------
256 FLOATING: the item will float in air, instead of aligning to the floor by falling
257 ---------NOTES----------
258 Don't use this entity on new maps! Use item_key instead.
262 this.classname = "item_key";
263 this.itemkeys = ITEM_KEY_BIT(1);
264 spawnfunc_item_key(this);
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.
281 this.classname = "item_key";
282 this.itemkeys = ITEM_KEY_BIT(0);
283 spawnfunc_item_key(this);