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