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"
9 #include "../common/triggers/subs.qh"
11 #include "../common/notifications.qh"
12 #include "item_key.qh"
17 - add an unlock sound (here to trigger_keylock and to func_door)
18 - display available keys on the HUD
20 - think about adding NOT_EASY/NOT_NORMAL/NOT_HARD for Q1 compatibility
21 - should keys have a trigger?
24 bool item_keys_usekey(entity l, entity p)
26 float valid = l.itemkeys & p.itemkeys;
29 // other has none of the needed keys
31 } else if (l.itemkeys == valid) {
32 // ALL needed keys were given
36 // only some of the needed keys were given
42 string item_keys_keylist(float keylist) {
51 if ((keylist & (keylist-1)) != 0)
52 return strcat("the ", item_keys_names[lowestbit(keylist)]);
57 l = lowestbit(keylist);
59 n = strcat(n, ", the ", item_keys_names[base + l]);
61 n = strcat("the ", item_keys_names[base + l]);
63 keylist = bitshift(keylist, -(l + 1));
72 ================================
74 ================================
80 void item_key_touch(void) {
81 if (!IS_PLAYER(other))
84 // player already picked up this key
85 if (other.itemkeys & self.itemkeys)
88 other.itemkeys |= self.itemkeys;
89 play2(other, self.noise);
91 centerprint(other, self.message);
95 * Spawn a key with given model, key code and color.
97 void spawn_item_key() {
98 precache_model(self.model);
100 if (self.spawnflags & 1) // FLOATING
104 self.movetype = MOVETYPE_NONE;
106 self.movetype = MOVETYPE_TOSS;
108 precache_sound(self.noise);
110 self.mdl = self.model;
111 self.effects = EF_LOWPRECISION;
112 setmodel(self, self.model);
113 //setsize(self, '-16 -16 -24', '16 16 32');
114 setorigin(self, self.origin + '0 0 32');
115 setsize(self, '-16 -16 -56', '16 16 0');
116 self.modelflags |= MF_ROTATE;
117 self.solid = SOLID_TRIGGER;
121 // first nudge it off the floor a little bit to avoid math errors
122 setorigin(self, self.origin + '0 0 1');
123 // note droptofloor returns false if stuck/or would fall too far
127 self.touch = item_key_touch;
131 /*QUAKED item_key (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
133 The itemkeys should contain one of the following key IDs:
141 ... - last key is 1<<23
142 Keys with bigger Id than 32 don't have a default netname and model, if you use one of them, you MUST provide those.
143 -----------KEYS------------
144 colormod: color of the key (default: '.9 .9 .9').
146 message: message to print when player picks up this key.
147 model: custom key model to use.
148 netname: the display name of the key.
149 noise: custom sound to play when player picks up the key.
150 -------- SPAWNFLAGS --------
151 FLOATING: the item will float in air, instead of aligning to the floor by falling
152 ---------NOTES----------
153 This is the only correct way to put keys on the map!
155 itemkeys MUST always have exactly one bit set.
157 void spawnfunc_item_key() {
161 // reject this entity if more than one key was set!
162 if (self.itemkeys>0 && (self.itemkeys & (self.itemkeys-1)) != 0) {
163 objerror("item_key.itemkeys must contain only 1 bit set specifying the key it represents!");
168 // find default netname and colormod
169 switch(self.itemkeys) {
171 _netname = "GOLD key";
172 _colormod = '1 .9 0';
176 _netname = "SILVER key";
177 _colormod = '.9 .9 .9';
181 _netname = "BRONZE key";
182 _colormod = '.6 .25 0';
186 _netname = "RED keycard";
187 _colormod = '.9 0 0';
191 _netname = "BLUE keycard";
192 _colormod = '0 0 .9';
196 _netname = "GREEN keycard";
197 _colormod = '0 .9 0';
201 _netname = "FLUFFY PINK keycard";
204 if (self.netname == "") {
205 objerror("item_key doesn't have a default name for this key and a custom one was not specified!");
213 // find default model
214 string _model = string_null;
215 if (self.itemkeys <= ITEM_KEY_BIT(2)) {
216 _model = "models/keys/key.md3";
217 } else if (self.itemkeys >= ITEM_KEY_BIT(3) && self.itemkeys <= ITEM_KEY_BIT(5)) {
218 _model = "models/keys/key.md3"; // FIXME: replace it by a keycard model!
219 } else if (self.model == "") {
220 objerror("item_key doesn't have a default model for this key and a custom one was not specified!");
225 // set defailt netname
226 if (self.netname == "")
227 self.netname = _netname;
229 // set default colormod
231 self.colormod = _colormod;
234 if (self.model == "")
237 // set default pickup message
238 if (self.message == "")
239 self.message = strzone(strcat("You've picked up the ", self.netname, "!"));
241 if (self.noise == "")
242 self.noise = "misc/itempickup.wav";
244 // save the name for later
245 item_keys_names[lowestbit(self.itemkeys)] = self.netname;
247 // put the key on the map
251 /*QUAKED item_key1 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
253 -----------KEYS------------
254 colormod: color of the key (default: '.9 .9 .9').
255 message: message to print when player picks up this key.
256 model: custom model to use.
257 noise: custom sound to play when player picks up the key.
258 -------- SPAWNFLAGS --------
259 FLOATING: the item will float in air, instead of aligning to the floor by falling
260 ---------NOTES----------
261 Don't use this entity on new maps! Use item_key instead.
263 void spawnfunc_item_key1(void) {
264 self.classname = "item_key";
265 self.itemkeys = ITEM_KEY_BIT(1);
266 spawnfunc_item_key();
269 /*QUAKED item_key2 (0 .5 .8) (-16 -16 -24) (16 16 32) FLOATING
271 -----------KEYS------------
272 colormod: color of the key (default: '1 .9 0').
273 message: message to print when player picks up this key.
274 model: custom model to use.
275 noise: custom sound to play when player picks up the key.
276 -------- SPAWNFLAGS --------
277 FLOATING: the item will float in air, instead of aligning to the floor by falling
278 ---------NOTES----------
279 Don't use this entity on new maps! Use item_key instead.
281 void spawnfunc_item_key2(void) {
282 self.classname = "item_key";
283 self.itemkeys = ITEM_KEY_BIT(0);
284 spawnfunc_item_key();