]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/t_items.c
New location escapes: %d - location of last death, %y: location of crosshair
[divverent/nexuiz.git] / data / qcsrc / server / gamec / t_items.c
1 void Item_ClearRespawnEffect (void) {
2         self.effects = self.effects - (self.effects & EF_STARDUST);
3 }
4
5 void Item_Respawn (void)
6 {
7         self.model = self.mdl;          // restore original model
8         self.solid = SOLID_TRIGGER;     // allow it to be touched again
9         sound (self, CHAN_VOICE, "misc/itemrespawn.ogg", 1, ATTN_NORM); // play respawn sound
10         setorigin (self, self.origin);
11
12         // Savage: Add simple Respawn effect and make sure it gets removed
13         self.effects = self.effects | EF_STARDUST;
14         self.think = Item_ClearRespawnEffect;
15         self.nextthink = time + 0.1;
16 }
17
18 void Item_Touch (void)
19 {
20         local entity oldself;
21         local float _switchweapon;
22
23         // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
24         if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
25         {
26                 remove(self);
27                 return;
28         }
29         if (other.classname != "player")
30                 return;
31         if (other.deadflag)
32                 return;
33         if (self.solid != SOLID_TRIGGER)
34                 return;
35         if (self.health && other.health >= other.max_health)
36                 return;
37         if (self.owner == other)
38                 return;
39         // Savage: Remove the respawn effect if still present
40         self.effects = self.effects - (self.effects & EF_STARDUST);
41
42         sound (self, CHAN_BODY, self.noise, 1, ATTN_NORM);
43
44         // in case the player has autoswitch enabled do the following:
45         // if the player is using their best weapon before items are given, they
46         // probably want to switch to an even better weapon after items are given
47         _switchweapon = (other.autoswitch && (other.switchweapon == w_getbestweapon(other)) || cvar("g_minstagib"));
48
49         if (cvar("g_minstagib"))
50         {
51                 if (self.ammo_cells)
52                 {
53                         // play some cool sounds ;)
54                         centerprint(other, "\n");
55                         if(other.health <= 5)
56                                 stuffcmd(other, "play2 announcer/robotic/lastsecond.ogg\n");
57                         else if(other.health < 50)
58                                 stuffcmd(other, "play2 announcer/robotic/narrowly.ogg\n");
59                         // sound not available
60                         // else if(self.items == IT_CELLS)
61                         //      stuffcmd(other, "play2 announce/robotic/ammo.ogg\n");
62
63                         if (self.items & IT_NEX)
64                                 W_GiveWeapon (other, IT_NEX, "Nex");
65                         if (self.ammo_cells)
66                                 other.ammo_cells = min (other.ammo_cells + cvar("g_minstagib_ammo_drop"), 999);
67                         other.health = 100;
68                 }
69
70                 // extralife powerup
71                 if (self.max_health)
72                 {
73                         // sound not available
74                         // stuffcmd(other, "play2 announce/robotic/extra.ogg\nplay2 announce/robotic/_lives.ogg\n");
75                         other.extralives = other.extralives + cvar("g_minstagib_extralives");
76                         other.armorvalue = other.extralives;
77                         sprint(other, "^3You picked up some extra lives\n");
78                 }
79
80                 // invis powerup
81                 if (self.strength_finished)
82                 {
83                         // sound not available
84                         // stuffcmd(other, "play2 announce/robotic/invisible.ogg\n");
85                         other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
86                 }
87
88                 // speed powerup
89                 if (self.invincible_finished)
90                 {
91                         // sound not available
92                         // stuffcmd(other, "play2 announce/robotic/speed.ogg\n");
93                         other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
94                 }
95         }
96         else
97         {
98                 if (cvar("deathmatch") == 2 && self.flags & FL_WEAPON && other.items & self.items && self.classname != "droppedweapon")
99                         return;
100                 
101                 if (self.ammo_shells)
102                         other.ammo_shells = min (other.ammo_shells + self.ammo_shells, 999);
103                 if (self.ammo_nails)
104                         other.ammo_nails = min (other.ammo_nails + self.ammo_nails, 999);
105                 if (self.ammo_rockets)
106                         other.ammo_rockets = min (other.ammo_rockets + self.ammo_rockets, 999);
107                 if (self.ammo_cells)
108                         other.ammo_cells = min (other.ammo_cells + self.ammo_cells, 999);
109
110                 if (self.items & IT_UZI)                W_GiveWeapon (other, IT_UZI, self.netname);
111                 if (self.items & IT_SHOTGUN)            W_GiveWeapon (other, IT_SHOTGUN, self.netname);
112                 if (self.items & IT_GRENADE_LAUNCHER)   W_GiveWeapon (other, IT_GRENADE_LAUNCHER, self.netname);
113                 if (self.items & IT_ELECTRO)            W_GiveWeapon (other, IT_ELECTRO, self.netname);
114                 if (self.items & IT_NEX)                W_GiveWeapon (other, IT_NEX, self.netname);
115                 if (self.items & IT_HAGAR)              W_GiveWeapon (other, IT_HAGAR, self.netname);
116                 if (self.items & IT_ROCKET_LAUNCHER)    W_GiveWeapon (other, IT_ROCKET_LAUNCHER, self.netname);
117                 if (self.items & IT_CRYLINK)            W_GiveWeapon (other, IT_CRYLINK, self.netname);
118
119                 if (self.strength_finished)
120                         other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
121                 if (self.invincible_finished)
122                         other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
123                 //if (self.speed_finished)
124                 //      other.speed_finished = max(other.speed_finished, time) + cvar("g_balance_powerup_speed_time");
125                 //if (self.slowmo_finished)
126                 //      other.slowmo_finished = max(other.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
127
128                 if (self.max_health)
129                 {
130                         other.health = other.health + self.max_health;
131                         other.pauserothealth_finished = max(other.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
132                 }
133                 if (self.health && other.health < other.max_health)
134                         other.health = min(other.health + self.health, other.max_health);
135                 if (self.armorvalue)
136                 {
137                         other.armorvalue = other.armorvalue + self.armorvalue;
138                         other.pauserotarmor_finished = max(other.pauserotarmor_finished, time + cvar("g_balance_pause_armor_rot"));
139                 }
140         }
141
142         sound (other, CHAN_AUTO, self.item_pickupsound, 1, ATTN_NORM);
143
144         oldself = self;
145         self = other;
146
147         if (_switchweapon)
148                 self.switchweapon = w_getbestweapon(self);
149         if (self.switchweapon != self.weapon)
150                 self.cnt = self.weapon;
151
152         //w_updateweapon ();
153         //w_updateammo ();
154         weapon_action(self.weapon, WR_UPDATECOUNTS);
155
156         self = oldself;
157
158         if (self.classname == "droppedweapon")
159                 remove (self);
160         else
161         {
162                 self.solid = SOLID_NOT;
163                 self.model = string_null;
164                 self.nextthink = time + self.respawntime;
165                 self.think = Item_Respawn;
166                 setorigin (self, self.origin);
167         }
168 }
169
170 // Savage: used for item garbage-collection
171 // TODO: perhaps nice special effect?
172 void RemoveItem(void) = {
173         remove(self);
174 }
175
176 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float itemflags)
177 {
178         vector org;
179         org = self.origin;
180         
181         if (!(cvar("g_pickup_items") && !cvar("g_nixnex")) && !cvar("g_minstagib") &&
182                         itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
183         {
184                 remove (self);
185                 return;
186         }
187
188         if (cvar("g_minstagib"))
189         {
190                 // don't remove dropped items and powerups
191                 if (self.classname != "droppedweapon" &&
192                     self.classname != "minstagib")
193                 {
194                         remove (self);
195                         return;
196                 }
197         }
198
199         if(cvar("g_lms") && (self.classname != "droppedweapon"))
200         {
201                 remove(self);
202                 return;
203         }
204
205         if(cvar("g_instagib") || cvar("g_rocketarena"))
206         {
207                 remove(self);
208                 return;
209         }
210
211         if (self.classname == "droppedweapon")
212         {
213                 // don't drop if in a NODROP zone (such as lava)
214                 traceline(self.origin, self.origin, MOVE_NORMAL, self);
215                 if (trace_dpstartcontents & DPCONTENTS_NODROP)
216                 {
217                         remove(self);
218                         return;
219                 }
220         }
221
222         if(itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2 | 
223                                 IT_ROCKET_LAUNCHER | IT_HAGAR | IT_NEX | IT_CRYLINK | IT_ELECTRO | 
224                                 IT_GRENADE_LAUNCHER | IT_UZI | IT_SHOTGUN | IT_LASER) && self.classname != "droppedweapon")
225         {
226                 self.target = "###item###"; // for finding the nearest item using find()
227         }
228         self.mdl = itemmodel;
229         //self.noise = pickupsound;
230         self.item_pickupsound = pickupsound;
231         // let mappers override respawntime
232         if (!self.respawntime)
233                 self.respawntime = defaultrespawntime;
234         self.netname = itemname;
235         self.items = itemid;
236         self.flags = FL_ITEM | itemflags;
237         setmodel (self, self.mdl);
238         if (itemflags & FL_WEAPON)
239         {
240                 setorigin (self, self.origin + '0 0 23');
241                 setsize (self, '-12 -12 -12', '12 12 12');
242
243                 // neutral team color for pickup weapons
244                 self.colormap = 160 * 1024 + 160;
245         }
246         else
247         {
248                 setorigin (self, self.origin + '0 0 25');
249         //      setsize (self, '-8 -8 -5', '8 8 8');
250         }
251         self.movetype = MOVETYPE_TOSS;
252         self.solid = SOLID_TRIGGER;
253         self.touch = Item_Touch;
254
255         // Savage: remove thrown items after a certain period of time ("garbage collection")
256         if (self.classname == "droppedweapon")
257         {
258                 self.think = RemoveItem;
259                 self.nextthink = time + 60;
260         }
261         else if (!self.noalign)
262         {
263                 vector z_offset;
264
265                 z_offset = '0 0 1';
266
267                 if (itemid == IT_SHELLS)
268                         z_offset = '0 0 4';
269                 else if (itemid == IT_ROCKETS)
270                         z_offset = '0 0 4';
271                 else if (itemid == IT_NAILS)
272                         z_offset = '0 0 0';
273                 else if (itemid == IT_25HP)
274                         z_offset = '0 0 5';
275                 else if (itemid == IT_ARMOR)
276                         z_offset = '0 0 3';
277
278                 self.movetype = MOVETYPE_NONE;
279                 setorigin(self, find_floor(org) + z_offset);
280         }
281         else
282         {
283                 self.movetype = MOVETYPE_NONE;
284                 setorigin(self, org);
285         }
286
287         if (cvar("g_fullbrightitems"))
288                 self.effects = self.effects | EF_FULLBRIGHT;
289
290 }
291
292 /* replace items in minstagib
293  * IT_STRENGTH   = invisibility
294  * IT_NAILS      = extra lives
295  * IT_INVINCIBLE = speed
296  */
297 void minstagib_items (float itemid)
298 {
299         // we don't want to replace dropped weapons ;)
300         if (self.classname == "droppedweapon")
301         {
302                 self.ammo_cells = 25;
303                 StartItem ("models/weapons/g_nex.md3",
304                         "weapons/weaponpickup.ogg", 15,
305                         "Nex Gun", IT_NEX, FL_WEAPON);
306                 return;
307         }
308
309         local float rnd;
310         self.classname = "minstagib";
311
312         // replace rocket launchers and nex guns with ammo cells
313         if (itemid == IT_CELLS)
314         {
315                 self.ammo_cells = 1;
316                 StartItem ("models/items/a_cells.md3",
317                         "misc/itempickup.ogg", 45,
318                         "Nex Ammo", IT_CELLS, 0);
319                 return;
320         }
321
322         // randomize
323         rnd = random() * 3;
324         if (rnd <= 1)
325                 itemid = IT_STRENGTH;
326         else if (rnd <= 2)
327                 itemid = IT_NAILS;
328         else
329                 itemid = IT_INVINCIBLE;
330
331         // replace with invis
332         if (itemid == IT_STRENGTH)
333         {
334                 self.effects = EF_ADDITIVE;
335                 self.strength_finished = 30;
336                 StartItem ("models/items/g_strength.md3",
337                         "misc/powerup.ogg", 120,
338                         "Invisibility", IT_STRENGTH, FL_POWERUP);
339         }
340         // replace with extra lives
341         if (itemid == IT_NAILS)
342         {
343                 self.max_health = 1;
344                 StartItem ("models/items/g_h100.md3",
345                         "misc/megahealth.ogg", 120,
346                         "Extralife", IT_NAILS, FL_POWERUP);
347
348         }
349         // replace with ammo
350         if (itemid == IT_INVINCIBLE)
351         {
352                 self.effects = EF_ADDITIVE;
353                 self.invincible_finished = 30;
354                 StartItem ("models/items/g_invincible.md3",
355                         "misc/powerup_shield.ogg", 120,
356                         "Speed", IT_INVINCIBLE, FL_POWERUP);
357         }
358
359 }
360
361 void weapon_uzi (void) {
362         self.ammo_nails = 120;
363         StartItem ("models/weapons/g_uzi.md3", "weapons/weaponpickup.ogg", 15, W_Name(WEP_UZI), IT_UZI, FL_WEAPON);
364 }
365
366 void weapon_shotgun (void) {
367         self.ammo_shells = 15;
368         StartItem ("models/weapons/g_shotgun.md3", "weapons/weaponpickup.ogg", 15, W_Name(WEP_SHOTGUN), IT_SHOTGUN, FL_WEAPON);
369 }
370
371 void weapon_grenadelauncher (void) {
372         self.ammo_rockets = 15;
373         StartItem ("models/weapons/g_gl.md3", "weapons/weaponpickup.ogg", 15, W_Name(WEP_GRENADE_LAUNCHER), IT_GRENADE_LAUNCHER, FL_WEAPON);
374 }
375
376 void weapon_electro (void) {
377         self.ammo_cells = 25;
378         StartItem ("models/weapons/g_electro.md3", "weapons/weaponpickup.ogg", 15, W_Name(WEP_ELECTRO), IT_ELECTRO, FL_WEAPON);
379 }
380
381 void weapon_crylink (void) {
382         self.ammo_cells = 25;
383         StartItem ("models/weapons/g_crylink.md3", "weapons/weaponpickup.ogg", 15, W_Name(WEP_CRYLINK), IT_CRYLINK, FL_WEAPON);
384 }
385
386 void weapon_nex (void) {
387         if (cvar("g_minstagib")) {
388                 minstagib_items(IT_CELLS);
389         } else {
390                 self.ammo_cells = 25;
391                 StartItem ("models/weapons/g_nex.md3", "weapons/weaponpickup.ogg", 15, W_Name(WEP_NEX), IT_NEX, FL_WEAPON);
392         }
393 }
394
395 void weapon_hagar (void) {
396         self.ammo_rockets = 15;
397         StartItem ("models/weapons/g_hagar.md3", "weapons/weaponpickup.ogg", 15, W_Name(WEP_HAGAR), IT_HAGAR, FL_WEAPON);
398 }
399
400 void weapon_rocketlauncher (void) {
401         if (cvar("g_minstagib")) {
402                 minstagib_items(IT_CELLS);
403         } else {
404                 self.ammo_rockets = 15;
405                 StartItem ("models/weapons/g_rl.md3", "weapons/weaponpickup.ogg", 15, W_Name(WEP_ROCKET_LAUNCHER), IT_ROCKET_LAUNCHER, FL_WEAPON);
406         }
407 }
408
409 void item_rockets (void) {
410         self.ammo_rockets = 15;
411         StartItem ("models/items/a_rockets.md3", "misc/itempickup.ogg", 15, "rockets", IT_ROCKETS, 0);
412 }
413
414 void item_bullets (void) {
415         self.ammo_nails = 120;
416         StartItem ("models/items/a_bullets.mdl", "misc/itempickup.ogg", 15, "bullets", IT_NAILS, 0);
417 }
418
419 void item_cells (void) {
420         self.ammo_cells = 25;
421         StartItem ("models/items/a_cells.md3", "misc/itempickup.ogg", 15, "cells", IT_CELLS, 0);
422 }
423
424 void item_shells (void) {
425         self.ammo_shells = 15;
426         StartItem ("models/items/a_shells.md3", "misc/itempickup.ogg", 15, "shells", IT_SHELLS, 0);
427 }
428
429 void item_armor1 (void) {
430         self.armorvalue = 5;
431         StartItem ("models/items/g_a1.md3", "misc/armor1.wav", 15, "Armor Shard", IT_ARMOR_SHARD, 0);
432 }
433
434 void item_armor25 (void) {
435         self.armorvalue = 100;
436         StartItem ("models/items/g_a25.md3", "misc/armor25.wav", 30, "Armor", IT_ARMOR, 0);
437 }
438
439 void item_health1 (void) {
440         self.max_health = 5;
441         StartItem ("models/items/g_h1.md3", "misc/minihealth.ogg", 15, "5 Health", IT_5HP, 0);
442 }
443
444 void item_health25 (void) {
445         self.max_health = 25;
446         StartItem ("models/items/g_h25.md3", "misc/mediumhealth.ogg", 15, "25 Health", IT_25HP, 0);
447 }
448
449 void item_health100 (void) {
450         if(!cvar("g_powerup_superhealth"))
451                 return;
452
453         if(cvar("g_minstagib")) {
454                 minstagib_items(IT_NAILS);
455         } else {
456                 self.max_health = 100;
457                 StartItem ("models/items/g_h100.md3", "misc/megahealth.ogg", 30, "100 Health", IT_HEALTH, 0);
458         }
459 }
460
461 void item_strength (void) {
462         if(!cvar("g_powerup_strength"))
463                 return;
464
465         if(cvar("g_minstagib")) {
466                 minstagib_items(IT_STRENGTH);
467         } else {
468                 self.strength_finished = 30;
469                 self.effects = EF_ADDITIVE;StartItem ("models/items/g_strength.md3", "misc/powerup.ogg", 120, "Strength Powerup", IT_STRENGTH, FL_POWERUP);
470         }
471 }
472
473 void item_invincible (void) {
474         if(!cvar("g_powerup_shield"))
475                 return;
476
477         if(cvar("g_minstagib")) {
478                 minstagib_items(IT_INVINCIBLE);
479         } else {
480                 self.invincible_finished = 30;
481                 self.effects = EF_ADDITIVE;
482                 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.ogg", 120, "Invulnerability", IT_INVINCIBLE, FL_POWERUP);
483         }
484 }
485 //void item_speed (void) {self.speed_finished = 30;StartItem ("models/items/g_speed.md3", "misc/powerup.wav", 120, "Speed Powerup", IT_SPEED, FL_POWERUP);}
486 //void item_slowmo (void) {self.slowmo_finished = 30;StartItem ("models/items/g_slowmo.md3", "misc/powerup.wav", 120, "Slow Motion", IT_SLOWMO, FL_POWERUP);}
487
488 void misc_models (void)
489 {
490         precache_model (self.model);
491         setmodel (self, self.model);
492         setsize (self, self.mins, self.maxs);
493 }
494
495