4 #include "../common/triggers/subs.qh"
5 #include "../common/monsters/all.qh"
6 #include "../common/notifications.qh"
7 #include "../common/util.qh"
8 #include "../warpzonelib/util_server.qh"
12 - add an unlock sound (here to trigger_keylock and to func_door)
13 - display available keys on the HUD
15 - think about adding NOT_EASY/NOT_NORMAL/NOT_HARD for Q1 compatibility
16 - should keys have a trigger?
19 bool item_keys_usekey(entity l, entity p)
21 float valid = l.itemkeys & p.itemkeys;
24 // other has none of the needed keys
26 } else if (l.itemkeys == valid) {
27 // ALL needed keys were given
31 // only some of the needed keys were given
37 string item_keys_keylist(float keylist) {
43 if ((keylist & (keylist-1)) != 0)
44 return strcat("the ", item_keys_names[lowestbit(keylist)]);
49 int l = lowestbit(keylist);
51 n = strcat(n, ", the ", item_keys_names[base + l]);
53 n = strcat("the ", item_keys_names[base + l]);
55 keylist = bitshift(keylist, -(l + 1));
64 ================================
66 ================================
74 if (!IS_PLAYER(other))
77 // player already picked up this key
78 if (other.itemkeys & self.itemkeys)
81 other.itemkeys |= self.itemkeys;
82 play2(other, self.noise);
84 centerprint(other, self.message);
88 * Spawn a key with given model, key code and color.
92 precache_model(self.model);
94 if (self.spawnflags & 1) // FLOATING
98 self.movetype = MOVETYPE_NONE;
100 self.movetype = MOVETYPE_TOSS;
102 precache_sound(self.noise);
104 self.mdl = self.model;
105 self.effects = EF_LOWPRECISION;
106 _setmodel(self, self.model);
107 //setsize(self, '-16 -16 -24', '16 16 32');
108 setorigin(self, self.origin + '0 0 32');
109 setsize(self, '-16 -16 -56', '16 16 0');
110 self.modelflags |= MF_ROTATE;
111 self.solid = SOLID_TRIGGER;
115 // first nudge it off the floor a little bit to avoid math errors
116 setorigin(self, self.origin + '0 0 1');
117 // note droptofloor returns false if stuck/or would fall too far
121 self.touch = item_key_touch;
125 /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
127 The itemkeys should contain one of the following key IDs:
135 ... - last key is 1<<23
136 Keys with bigger Id than 32 don't have a default netname and model, if you use one of them, you MUST provide those.
137 -----------KEYS------------
138 colormod: color of the key (default: '.9 .9 .9').
140 message: message to print when player picks up this key.
141 model: custom key model to use.
142 netname: the display name of the key.
143 noise: custom sound to play when player picks up the key.
144 -------- SPAWNFLAGS --------
145 FLOATING: the item will float in air, instead of aligning to the floor by falling
146 ---------NOTES----------
147 This is the only correct way to put keys on the map!
149 itemkeys MUST always have exactly one bit set.
151 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 = SND(ITEMPICKUP);
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)
260 self.classname = "item_key";
261 self.itemkeys = ITEM_KEY_BIT(1);
262 spawnfunc_item_key();
265 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
267 -----------KEYS------------
268 colormod: color of the key (default: '1 .9 0').
269 message: message to print when player picks up this key.
270 model: custom model to use.
271 noise: custom sound to play when player picks up the key.
272 -------- SPAWNFLAGS --------
273 FLOATING: the item will float in air, instead of aligning to the floor by falling
274 ---------NOTES----------
275 Don't use this entity on new maps! Use item_key instead.
277 void spawnfunc_item_key2(void)
279 self.classname = "item_key";
280 self.itemkeys = ITEM_KEY_BIT(0);
281 spawnfunc_item_key();