]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/t_items.qc
next improvement to mapinfo: Q3A SG/MG swap, mapinfo now applies map-specific setting...
[divverent/nexuiz.git] / data / qcsrc / server / t_items.qc
1 //void Item_ClearRespawnEffect (void) {
2 //      self.effects = self.effects - (self.effects & EF_STARDUST);
3 //}
4
5 .float max_armorvalue;
6
7 void Item_Respawn (void)
8 {
9         self.model = self.mdl;          // restore original model
10         self.solid = SOLID_TRIGGER;     // allow it to be touched again
11         sound (self, CHAN_VOICE, "misc/itemrespawn.wav", 1, ATTN_NORM); // play respawn sound
12         setorigin (self, self.origin);
13
14         // LordHavoc: replaced respawn stardust effect with a custom te_wizspike
15         te_wizspike(self.origin + self.mins_z * '0 0 1' + '0 0 48');
16         //// Savage: Add simple Respawn effect and make sure it gets removed
17         //self.effects = self.effects | EF_STARDUST;
18         //self.think = Item_ClearRespawnEffect;
19         //self.nextthink = time + 0.1;
20 }
21
22 void Item_Touch (void)
23 {
24         local entity oldself;
25         local float _switchweapon;
26         local float pickedup;
27         local float it;
28
29         // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
30         if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
31         {
32                 remove(self);
33                 return;
34         }
35         if (other.classname != "player")
36                 return;
37         if (other.deadflag)
38                 return;
39         if (self.solid != SOLID_TRIGGER)
40                 return;
41         if (self.owner == other)
42                 return;
43
44         // if nothing happens to other, just return without taking the item
45         pickedup = FALSE;
46         _switchweapon = FALSE;
47
48         if (g_minstagib)
49         {
50                 _switchweapon = TRUE;
51                 if (self.ammo_cells)
52                 {
53                         pickedup = TRUE;
54                         // play some cool sounds ;)
55                         centerprint(other, "\n");
56                         if(other.health <= 5)
57                                 announce(other, "announcer/robotic/lastsecond.ogg");
58                         else if(other.health < 50)
59                                 announce(other, "announcer/robotic/narrowly.ogg");
60                         // sound not available
61                         // else if(self.items == IT_CELLS)
62                         //      play2(other, "announce/robotic/ammo.ogg");
63
64                         if (self.items & IT_NEX)
65                                 W_GiveWeapon (other, IT_NEX, "Nex");
66                         if (self.ammo_cells)
67                                 other.ammo_cells = min (other.ammo_cells + cvar("g_minstagib_ammo_drop"), 999);
68                         other.health = 100;
69                 }
70
71                 // extralife powerup
72                 if (self.max_health)
73                 {
74                         pickedup = TRUE;
75                         // sound not available
76                         // play2(other, "announce/robotic/extra.ogg\nplay2 announce/robotic/_lives.ogg");
77                         other.armorvalue = other.armorvalue + cvar("g_minstagib_extralives");
78                         sprint(other, "^3You picked up some extra lives\n");
79                 }
80
81                 // invis powerup
82                 if (self.strength_finished)
83                 {
84                         pickedup = TRUE;
85                         // sound not available
86                         // play2(other, "announce/robotic/invisible.ogg");
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                         pickedup = TRUE;
94                         // sound not available
95                         // play2(other, "announce/robotic/speed.ogg");
96                         other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
97                 }
98         }
99         else
100         {
101                 if (cvar("deathmatch") == 2 || cvar("g_weapon_stay"))
102                 {
103                         if (self.flags & FL_WEAPON && other.items & self.items && self.classname != "droppedweapon")
104                                 return;
105                         if (other.items & self.items && self.flags & FL_TOSSED) // don't let players stack ammo by tossing weapons
106                                 return;
107                 }
108
109                 // in case the player has autoswitch enabled do the following:
110                 // if the player is using their best weapon before items are given, they
111                 // probably want to switch to an even better weapon after items are given
112                 if (other.autoswitch)
113                 if (other.switchweapon == w_getbestweapon(other))
114                         _switchweapon = TRUE;
115
116                 if (self.ammo_shells)
117                 if (other.ammo_shells < g_pickup_shells_max)
118                 {
119                         pickedup = TRUE;
120                         other.ammo_shells = min (other.ammo_shells + self.ammo_shells, g_pickup_shells_max);
121                 }
122                 if (self.ammo_nails)
123                 if (other.ammo_nails < g_pickup_nails_max)
124                 {
125                         pickedup = TRUE;
126                         other.ammo_nails = min (other.ammo_nails + self.ammo_nails, g_pickup_nails_max);
127                 }
128                 if (self.ammo_rockets)
129                 if (other.ammo_rockets < g_pickup_rockets_max)
130                 {
131                         pickedup = TRUE;
132                         other.ammo_rockets = min (other.ammo_rockets + self.ammo_rockets, g_pickup_rockets_max);
133                 }
134                 if (self.ammo_cells)
135                 if (other.ammo_cells < g_pickup_cells_max)
136                 {
137                         pickedup = TRUE;
138                         other.ammo_cells = min (other.ammo_cells + self.ammo_cells, g_pickup_cells_max);
139                 }
140
141                 if (self.flags & FL_WEAPON)
142                 if ((it = self.items - (self.items & other.items)))
143                 {
144                         pickedup = TRUE;
145                         if (it & IT_UZI)                W_GiveWeapon (other, IT_UZI, self.netname);
146                         if (it & IT_SHOTGUN)            W_GiveWeapon (other, IT_SHOTGUN, self.netname);
147                         if (it & IT_GRENADE_LAUNCHER)   W_GiveWeapon (other, IT_GRENADE_LAUNCHER, self.netname);
148                         if (it & IT_ELECTRO)            W_GiveWeapon (other, IT_ELECTRO, self.netname);
149                         if (it & IT_NEX)                W_GiveWeapon (other, IT_NEX, self.netname);
150                         if (it & IT_HAGAR)              W_GiveWeapon (other, IT_HAGAR, self.netname);
151                         if (it & IT_ROCKET_LAUNCHER)    W_GiveWeapon (other, IT_ROCKET_LAUNCHER, self.netname);
152                         if (it & IT_CRYLINK)            W_GiveWeapon (other, IT_CRYLINK, self.netname);
153                 }
154
155                 if (self.strength_finished)
156                 {
157                         pickedup = TRUE;
158                         other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
159                 }
160                 if (self.invincible_finished)
161                 {
162                         pickedup = TRUE;
163                         other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
164                 }
165                 //if (self.speed_finished)
166                 //{
167                 //      pickedup = TRUE;
168                 //      other.speed_finished = max(other.speed_finished, time) + cvar("g_balance_powerup_speed_time");
169                 //}
170                 //if (self.slowmo_finished)
171                 //{
172                 //      pickedup = TRUE;
173                 //      other.slowmo_finished = max(other.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
174                 //}
175
176                 if (self.health)
177                 if (other.health < self.max_health)
178                 {
179                         pickedup = TRUE;
180                         other.health = min(other.health + self.health, self.max_health);
181                         other.pauserothealth_finished = max(other.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
182                 }
183                 if (self.armorvalue)
184                 if (other.armorvalue < self.max_armorvalue)
185                 {
186                         pickedup = TRUE;
187                         other.armorvalue = min(other.armorvalue + self.armorvalue, self.max_armorvalue);
188                         other.pauserotarmor_finished = max(other.pauserotarmor_finished, time + cvar("g_balance_pause_armor_rot"));
189                 }
190         }
191
192         if (!pickedup)
193                 return;
194
195         // Savage: Remove the respawn effect if still present
196         self.effects = self.effects - (self.effects & EF_STARDUST);
197
198         sound (self, CHAN_BODY, self.noise, 1, ATTN_NORM);
199         sound (other, CHAN_AUTO, self.item_pickupsound, 1, ATTN_NORM);
200
201         oldself = self;
202         self = other;
203
204         if (_switchweapon)
205                 self.switchweapon = w_getbestweapon(self);
206         if (self.switchweapon != self.weapon)
207                 self.cnt = self.weapon;
208
209         self = oldself;
210
211         if (self.classname == "droppedweapon")
212                 remove (self);
213         else if(self.flags & FL_WEAPON && (cvar("deathmatch") == 2 || cvar("g_weapon_stay")))
214                 return;
215         else
216         {
217                 self.solid = SOLID_NOT;
218                 self.model = string_null;
219                 self.nextthink = time + self.respawntime;
220                 self.think = Item_Respawn;
221                 setorigin (self, self.origin);
222         }
223 }
224
225 // Savage: used for item garbage-collection
226 // TODO: perhaps nice special effect?
227 void RemoveItem(void) = {
228         remove(self);
229 }
230
231 // pickup evaluation functions
232 // these functions decide how desirable an item is to the bots
233
234 float(entity player, entity item) generic_pickupevalfunc = {return item.bot_pickupbasevalue;};
235
236 float(entity player, entity item) weapon_pickupevalfunc =
237 {
238         // if we already have the weapon, rate it 1/5th normal value
239         if ((player.items & item.items) == item.items)
240                 return item.bot_pickupbasevalue * 0.2;
241         return item.bot_pickupbasevalue;
242 };
243
244 float(entity player, entity item) commodity_pickupevalfunc =
245 {
246         float c;
247         c = 0;
248         // TODO: figure out if the player even has the weapon this ammo is for?
249         // may not affect strategy much though...
250         // find out how much more ammo/armor/health the player can hold
251         if (item.ammo_shells)
252         if (player.ammo_shells < g_pickup_shells_max)
253                 c = c + 1 - min(player.ammo_shells / g_pickup_shells_max, 1);
254         if (item.ammo_nails)
255         if (player.ammo_nails < g_pickup_nails_max)
256                 c = c + 1 - min(player.ammo_nails / g_pickup_nails_max, 1);
257         if (item.ammo_rockets)
258         if (player.ammo_rockets < g_pickup_rockets_max)
259                 c = c + 1 - min(player.ammo_rockets / g_pickup_rockets_max, 1);
260         if (item.ammo_cells)
261         if (player.ammo_cells < g_pickup_cells_max)
262                 c = c + 1 - min(player.ammo_cells / g_pickup_cells_max, 1);
263         if (item.armorvalue)
264         if (player.armorvalue < item.max_armorvalue)
265                 c = c + 1 - min(player.armorvalue / item.max_armorvalue, 1);
266         if (item.health)
267         if (player.health < item.max_health)
268                 c = c + 1 - min(player.health / item.max_health, 1);
269
270         if (cvar("deathmatch") == 2) // weapon stay is on, so weapons the player already has are of no interest
271         if (item.flags & FL_WEAPON)
272         if (self.items & item.items)
273         if (item.classname != "droppedweapon")
274                 c = 0;
275
276         return item.bot_pickupbasevalue * c;
277 };
278
279
280 .float is_item;
281 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
282 {
283         startitem_failed = FALSE;
284
285         if (self.classname != "droppedweapon")
286         {
287                 if(teams_matter)
288                 {
289                         if(self.notteam)
290                         {
291                                 print("removed non-teamplay ", self.classname, "\n");
292                                 startitem_failed = TRUE;
293                                 remove (self);
294                                 return;
295                         }
296                 }
297                 else
298                 {
299                         if(self.notfree)
300                         {
301                                 print("removed non-FFA ", self.classname, "\n");
302                                 startitem_failed = TRUE;
303                                 remove (self);
304                                 return;
305                         }
306                 }
307
308                 if(self.notq3a)
309                 {
310                         // We aren't TA or something like that, so we keep the Q3A entities
311                         print("removed non-Q3A ", self.classname, "\n");
312                         startitem_failed = TRUE;
313                         remove (self);
314                         return;
315                 }
316                 
317                 if(self.targetname)
318                 {
319                         // target_give not yet supported; maybe later
320                         print("removed targeted ", self.classname, "\n");
321                         startitem_failed = TRUE;
322                         remove (self);
323                         return;
324                 }
325                 
326                 if(cvar("spawn_debug") >= 2)
327                 {
328                         entity otheritem;
329                         for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
330                         {
331                                 if(otheritem.is_item)
332                                 {
333                                         dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
334                                         dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
335                                         error("Mapper sucks.");
336                                 }
337                         }
338                         self.is_item = TRUE;
339                 }
340
341                 waypoint_spawnforitem(self);
342
343                 itemsInMap |= itemid;
344         }
345
346         if (!(cvar("g_pickup_items") && !g_nixnex) && !g_minstagib &&
347                         itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
348         {
349                 startitem_failed = TRUE;
350                 remove (self);
351                 return;
352         }
353
354         if (g_minstagib)
355         {
356                 // don't remove dropped items and powerups
357                 if (self.classname != "droppedweapon" &&
358                     self.classname != "minstagib")
359                 {
360                         startitem_failed = TRUE;
361                         remove (self);
362                         return;
363                 }
364         }
365
366         if(g_lms && (self.classname != "droppedweapon"))
367         {
368                 startitem_failed = TRUE;
369                 remove(self);
370                 return;
371         }
372
373         if(g_instagib || g_rocketarena)
374         {
375                 startitem_failed = TRUE;
376                 remove(self);
377                 return;
378         }
379
380         if (self.classname == "droppedweapon")
381         {
382                 // don't drop if in a NODROP zone (such as lava)
383                 traceline(self.origin, self.origin, MOVE_NORMAL, self);
384                 if (trace_dpstartcontents & DPCONTENTS_NODROP)
385                 {
386                         startitem_failed = TRUE;
387                         remove(self);
388                         return;
389                 }
390         }
391
392         if (self.classname != "droppedweapon")
393         {
394                 precache_model (itemmodel);
395                 precache_sound (pickupsound);
396                 precache_sound ("misc/itemrespawn.wav");
397         }
398
399         if(itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2 |
400                                 IT_ROCKET_LAUNCHER | IT_HAGAR | IT_NEX | IT_CRYLINK | IT_ELECTRO |
401                                 IT_GRENADE_LAUNCHER | IT_UZI | IT_SHOTGUN | IT_LASER) && self.classname != "droppedweapon")
402         {
403                 self.target = "###item###"; // for finding the nearest item using find()
404         }
405         self.bot_pickup = TRUE;
406         self.bot_pickupevalfunc = pickupevalfunc;
407         self.bot_pickupbasevalue = pickupbasevalue;
408         self.mdl = itemmodel;
409         //self.noise = pickupsound;
410         self.item_pickupsound = pickupsound;
411         // let mappers override respawntime
412         if (!self.respawntime)
413                 self.respawntime = defaultrespawntime;
414         self.netname = itemname;
415         self.items = itemid;
416         self.flags = FL_ITEM | itemflags;
417         if(self.spawnflags & 1)
418                 self.noalign = 1;
419         if (self.noalign)
420                 self.movetype = MOVETYPE_NONE;
421         else
422                 self.movetype = MOVETYPE_TOSS;
423         self.solid = SOLID_TRIGGER;
424         self.touch = Item_Touch;
425         setmodel (self, self.mdl); // precision set below
426         self.effects |= EF_LOWPRECISION;
427         if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
428                 setsize (self, '-16 -16 0', '16 16 48');
429         else
430                 setsize (self, '-16 -16 0', '16 16 32');
431         if (itemflags & FL_WEAPON)
432         {
433                 // neutral team color for pickup weapons
434                 self.colormap = 160 * 1024 + 160;
435         }
436
437         // Savage: remove thrown items after a certain period of time ("garbage collection")
438         if (self.classname == "droppedweapon")
439         {
440                 self.think = RemoveItem;
441                 self.nextthink = time + 60;
442         }
443         else if (!self.noalign)
444         {
445                 // first nudge it off the floor a little bit to avoid math errors
446                 setorigin(self, self.origin + '0 0 1');
447                 // note droptofloor returns FALSE if stuck/or would fall too far
448                 droptofloor();
449         }
450
451         if (cvar("g_fullbrightitems"))
452                 self.effects = self.effects | EF_FULLBRIGHT;
453 }
454
455 /* replace items in minstagib
456  * IT_STRENGTH   = invisibility
457  * IT_NAILS      = extra lives
458  * IT_INVINCIBLE = speed
459  */
460 void minstagib_items (float itemid)
461 {
462         // we don't want to replace dropped weapons ;)
463         if (self.classname == "droppedweapon")
464         {
465                 self.ammo_cells = 25;
466                 StartItem ("models/weapons/g_nex.md3",
467                         "weapons/weaponpickup.wav", 15,
468                         "Nex Gun", IT_NEX, FL_WEAPON, generic_pickupevalfunc, 1000);
469                 return;
470         }
471
472         local float rnd;
473         self.classname = "minstagib";
474
475         // replace rocket launchers and nex guns with ammo cells
476         if (itemid == IT_CELLS)
477         {
478                 self.ammo_cells = 1;
479                 StartItem ("models/items/a_cells.md3",
480                         "misc/itempickup.wav", 45,
481                         "Nex Ammo", IT_CELLS, 0, generic_pickupevalfunc, 100);
482                 return;
483         }
484
485         // randomize
486         rnd = random() * 3;
487         if (rnd <= 1)
488                 itemid = IT_STRENGTH;
489         else if (rnd <= 2)
490                 itemid = IT_NAILS;
491         else
492                 itemid = IT_INVINCIBLE;
493
494         // replace with invis
495         if (itemid == IT_STRENGTH)
496         {
497                 self.effects = EF_ADDITIVE;
498                 self.strength_finished = 30;
499                 StartItem ("models/items/g_strength.md3",
500                         "misc/powerup.wav", 120,
501                         "Invisibility", IT_STRENGTH, FL_POWERUP, generic_pickupevalfunc, 1000);
502         }
503         // replace with extra lives
504         if (itemid == IT_NAILS)
505         {
506                 self.max_health = 1;
507                 StartItem ("models/items/g_h100.md3",
508                         "misc/megahealth.wav", 120,
509                         "Extralife", IT_NAILS, FL_POWERUP, generic_pickupevalfunc, 1000);
510
511         }
512         // replace with speed
513         if (itemid == IT_INVINCIBLE)
514         {
515                 self.effects = EF_ADDITIVE;
516                 self.invincible_finished = 30;
517                 StartItem ("models/items/g_invincible.md3",
518                         "misc/powerup_shield.wav", 120,
519                         "Speed", IT_INVINCIBLE, FL_POWERUP, generic_pickupevalfunc, 1000);
520         }
521
522 }
523
524 float minst_no_auto_cells;
525 void minst_remove_item (void) {
526         if(minst_no_auto_cells)
527                 remove(self);
528 }
529
530 float weaponswapping;
531
532 void weapon_shotgun (void);
533 void weapon_uzi (void) {
534         if(!weaponswapping)
535         if(q3acompat_machineshotgunswap)
536         if(self.classname != "droppedweapon")
537         {
538                 weaponswapping = TRUE;
539                 weapon_shotgun();
540                 weaponswapping = FALSE;
541                 return;
542         }
543
544         if(!self.ammo_nails)
545                 self.ammo_nails = cvar("g_pickup_nails");
546         StartItem ("models/weapons/g_uzi.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_UZI), IT_UZI, FL_WEAPON, weapon_pickupevalfunc, 1000);
547         if (self.modelindex) // don't precache if self was removed
548                 weapon_action(WEP_UZI, WR_PRECACHE);
549 }
550
551 void weapon_shotgun (void) {
552         if(!weaponswapping)
553         if(q3acompat_machineshotgunswap)
554         if(self.classname != "droppedweapon")
555         {
556                 weaponswapping = TRUE;
557                 weapon_uzi();
558                 weaponswapping = FALSE;
559                 return;
560         }
561
562         if(!self.ammo_shells)
563                 self.ammo_shells = cvar("g_pickup_shells");
564         StartItem ("models/weapons/g_shotgun.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_SHOTGUN), IT_SHOTGUN, FL_WEAPON, weapon_pickupevalfunc, 1000);
565         if (self.modelindex) // don't precache if self was removed
566                 weapon_action(WEP_SHOTGUN, WR_PRECACHE);
567 }
568
569 void weapon_grenadelauncher (void)
570 {
571         if(!self.ammo_rockets)
572                 self.ammo_rockets = cvar("g_pickup_rockets");
573         StartItem ("models/weapons/g_gl.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_GRENADE_LAUNCHER), IT_GRENADE_LAUNCHER, FL_WEAPON, weapon_pickupevalfunc, 1000);
574         if (self.modelindex) // don't precache if self was removed
575                 weapon_action(WEP_GRENADE_LAUNCHER, WR_PRECACHE);
576 }
577
578 void weapon_electro (void)
579 {
580         if(!self.ammo_cells)
581                 self.ammo_cells = cvar("g_pickup_cells");
582         StartItem ("models/weapons/g_electro.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_ELECTRO), IT_ELECTRO, FL_WEAPON, weapon_pickupevalfunc, 1000);
583         if (self.modelindex) // don't precache if self was removed
584                 weapon_action(WEP_ELECTRO, WR_PRECACHE);
585 }
586
587 void weapon_crylink (void)
588 {
589         if(!self.ammo_cells)
590                 self.ammo_cells = cvar("g_pickup_cells");
591         StartItem ("models/weapons/g_crylink.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_CRYLINK), IT_CRYLINK, FL_WEAPON, weapon_pickupevalfunc, 1000);
592         if (self.modelindex) // don't precache if self was removed
593                 weapon_action(WEP_CRYLINK, WR_PRECACHE);
594 }
595
596 void weapon_nex (void)
597 {
598         float nextime;
599         if (g_minstagib)
600         {
601                 minstagib_items(IT_CELLS);
602                 self.think = minst_remove_item;
603                 self.nextthink = time + cvar("sys_ticrate");
604                 return;
605         }
606         if(!self.ammo_cells)
607                 self.ammo_cells = cvar("g_pickup_cells");
608         nextime = cvar("g_balance_nex_respawntime_modifier");
609         if(nextime)
610                 nextime = 15 * nextime;
611         else
612                 nextime = 15;
613         StartItem ("models/weapons/g_nex.md3", "weapons/weaponpickup.wav", nextime, W_Name(WEP_NEX), IT_NEX, FL_WEAPON, weapon_pickupevalfunc, 1000);
614         if (self.modelindex) // don't precache if self was removed
615                 weapon_action(WEP_NEX, WR_PRECACHE);
616 }
617
618 void weapon_hagar (void)
619 {
620         if(!self.ammo_rockets)
621                 self.ammo_rockets = cvar("g_pickup_rockets");
622         StartItem ("models/weapons/g_hagar.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_HAGAR), IT_HAGAR, FL_WEAPON, weapon_pickupevalfunc, 1000);
623         if (self.modelindex) // don't precache if self was removed
624                 weapon_action(WEP_HAGAR, WR_PRECACHE);
625 }
626
627 void weapon_rocketlauncher (void)
628 {
629         if (g_minstagib)
630         {
631                 minstagib_items(IT_CELLS);
632                 self.think = minst_remove_item;
633                 self.nextthink = time + cvar("sys_ticrate");
634                 return;
635         }
636         if(!self.ammo_rockets)
637                 self.ammo_rockets = g_pickup_rockets;
638         StartItem ("models/weapons/g_rl.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_ROCKET_LAUNCHER), IT_ROCKET_LAUNCHER, FL_WEAPON, weapon_pickupevalfunc, 1000);
639         if (self.modelindex) // don't precache if self was removed
640                 weapon_action(WEP_ROCKET_LAUNCHER, WR_PRECACHE);
641 }
642
643 void item_rockets (void) {
644         if(!self.ammo_rockets)
645                 self.ammo_rockets = g_pickup_rockets;
646         StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", 15, "rockets", IT_ROCKETS, 0, commodity_pickupevalfunc, 100);
647 }
648
649 void item_shells (void);
650 void item_bullets (void) {
651         if(!weaponswapping)
652         if(q3acompat_machineshotgunswap)
653         if(self.classname != "droppedweapon")
654         {
655                 weaponswapping = TRUE;
656                 item_shells();
657                 weaponswapping = FALSE;
658                 return;
659         }
660
661         if(!self.ammo_nails)
662                 self.ammo_nails = g_pickup_nails;
663         StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", 15, "bullets", IT_NAILS, 0, commodity_pickupevalfunc, 100);
664 }
665
666 void item_cells (void) {
667         if(!self.ammo_cells)
668                 self.ammo_cells = g_pickup_cells;
669         StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", 15, "cells", IT_CELLS, 0, commodity_pickupevalfunc, 100);
670 }
671
672 void item_shells (void) {
673         if(!weaponswapping)
674         if(q3acompat_machineshotgunswap)
675         if(self.classname != "droppedweapon")
676         {
677                 weaponswapping = TRUE;
678                 item_bullets();
679                 weaponswapping = FALSE;
680                 return;
681         }
682
683         if(!self.ammo_shells)
684                 self.ammo_shells = g_pickup_shells;
685         StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", 15, "shells", IT_SHELLS, 0, commodity_pickupevalfunc, 100);
686 }
687
688 void item_armor_small (void) {
689         if(!self.armorvalue)
690                 self.armorvalue = g_pickup_armorsmall;
691         if(!self.max_armorvalue)
692                 self.max_armorvalue = g_pickup_armorsmall_max;
693         StartItem ("models/items/g_a1.md3", "misc/armor1.wav", 15, "Armor Shard", IT_ARMOR_SHARD, 0, commodity_pickupevalfunc, 100);
694 }
695
696 void item_armor_medium (void) {
697         if(!self.armorvalue)
698                 self.armorvalue = g_pickup_armormedium;
699         if(!self.max_armorvalue)
700                 self.max_armorvalue = g_pickup_armormedium_max;
701         self.skin = 1; // "weaker" skin
702         StartItem ("models/items/g_a25.md3", "misc/armor25.wav", 30, "Armor", IT_ARMOR, 0, commodity_pickupevalfunc, 2000);
703 }
704
705 void item_armor_large (void) {
706         if(!self.armorvalue)
707                 self.armorvalue = g_pickup_armorlarge;
708         if(!self.max_armorvalue)
709                 self.max_armorvalue = g_pickup_armorlarge_max;
710         StartItem ("models/items/g_a25.md3", "misc/armor25.wav", 30, "Armor", IT_ARMOR, 0, commodity_pickupevalfunc, 2000);
711 }
712
713 void item_health_small (void) {
714         if(!self.max_health)
715                 self.max_health = g_pickup_healthsmall_max;
716         if(!self.health)
717                 self.health = g_pickup_healthsmall;
718         StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", 15, "5 Health", IT_5HP, 0, commodity_pickupevalfunc, 100);
719 }
720
721 void item_health_medium (void) {
722         if(!self.max_health)
723                 self.max_health = g_pickup_healthmedium_max;
724         if(!self.health)
725                 self.health = g_pickup_healthmedium;
726         StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", 15, "25 Health", IT_25HP, 0, commodity_pickupevalfunc, 500);
727 }
728
729 void item_health_large (void) {
730         if(!self.max_health)
731                 self.max_health = g_pickup_healthlarge_max;
732         if(!self.health)
733                 self.health = g_pickup_healthlarge;
734         self.skin = 1; // "stronger" skin
735         StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", 15, "25 Health", IT_25HP, 0, commodity_pickupevalfunc, 500);
736 }
737
738 void item_health_mega (void) {
739         if(!cvar("g_powerup_superhealth"))
740                 return;
741
742         if(g_arena && !cvar("g_arena_powerups"))
743                 return;
744
745         if(g_minstagib) {
746                 minstagib_items(IT_NAILS);
747         } else {
748                 if(!self.max_health)
749                         self.max_health = g_pickup_healthmega_max;
750                 if(!self.health)
751                         self.health = g_pickup_healthmega;
752                 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", 30, "100 Health", IT_HEALTH, 0, commodity_pickupevalfunc, 2000);
753         }
754 }
755
756 // support old misnamed entities
757 void item_armor1() { item_armor_small(); }
758 void item_armor25() { item_armor_large(); }
759 void item_health1() { item_health_small(); }
760 void item_health25() { item_health_medium(); }
761 void item_health100() { item_health_mega(); }
762
763 void item_strength (void) {
764         if(!cvar("g_powerup_strength"))
765                 return;
766
767         if(g_arena && !cvar("g_arena_powerups"))
768                 return;
769
770         if(g_minstagib) {
771                 minstagib_items(IT_STRENGTH);
772         } else {
773                 precache_sound("weapons/strength_fire.wav");
774                 self.strength_finished = 30;
775                 self.effects = EF_ADDITIVE;StartItem ("models/items/g_strength.md3", "misc/powerup.wav", 120, "Strength Powerup", IT_STRENGTH, FL_POWERUP, generic_pickupevalfunc, 10000);
776         }
777 }
778
779 void item_invincible (void) {
780         if(!cvar("g_powerup_shield"))
781                 return;
782
783         if(g_arena && !cvar("g_arena_powerups"))
784                 return;
785
786         if(g_minstagib) {
787                 minstagib_items(IT_INVINCIBLE);
788         } else {
789                 self.invincible_finished = 30;
790                 self.effects = EF_ADDITIVE;
791                 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", 120, "Invulnerability", IT_INVINCIBLE, FL_POWERUP, generic_pickupevalfunc, 10000);
792         }
793 }
794 //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);}
795 //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);}
796
797 void item_minst_cells (void) {
798         if (g_minstagib)
799         {
800                 minst_no_auto_cells = 1;
801                 minstagib_items(IT_CELLS);
802         }
803         else
804                 remove(self);
805 }
806
807 // compatibility:
808 void item_quad (void) {self.classname = "item_strength";item_strength();}
809
810 void misc_models (void)
811 {
812         precache_model (self.model);
813         setmodel (self, self.model); // precision set by mapper
814         setsize (self, self.mins, self.maxs);
815 }
816
817
818
819
820
821 floatfield Item_CounterField(float it)
822 {
823         switch(it)
824         {
825                 case IT_SHELLS:      return ammo_shells;
826                 case IT_NAILS:       return ammo_nails;
827                 case IT_ROCKETS:     return ammo_rockets;
828                 case IT_CELLS:       return ammo_cells;
829                 case IT_5HP:         return health;
830                 case IT_25HP:        return health;
831                 case IT_HEALTH:      return health;
832                 case IT_ARMOR_SHARD: return armorvalue;
833                 case IT_ARMOR:       return armorvalue;
834                 // add more things here (health, armor)
835                 default:             error("requested item has no counter field");
836         }
837 }
838
839 float Item_WeaponCode(float it)
840 {
841         switch(it)
842         {
843                 case IT_LASER:            return WEP_LASER;
844                 case IT_SHOTGUN:          return WEP_SHOTGUN;
845                 case IT_UZI:              return WEP_UZI;
846                 case IT_GRENADE_LAUNCHER: return WEP_GRENADE_LAUNCHER;
847                 case IT_ELECTRO:          return WEP_ELECTRO;
848                 case IT_CRYLINK:          return WEP_CRYLINK;
849                 case IT_NEX:              return WEP_NEX;
850                 case IT_HAGAR:            return WEP_HAGAR;
851                 case IT_ROCKET_LAUNCHER:  return WEP_ROCKET_LAUNCHER;
852                 default:                  return 0;
853         }
854 }
855
856 void Item_SpawnByItemCode(float it)
857 {
858         switch(it)
859         {
860                 case IT_SHOTGUN:          weapon_shotgun(); break;
861                 case IT_UZI:              weapon_uzi(); break;
862                 case IT_GRENADE_LAUNCHER: weapon_grenadelauncher(); break;
863                 case IT_ELECTRO:          weapon_electro(); break;
864                 case IT_CRYLINK:          weapon_crylink(); break;
865                 case IT_NEX:              weapon_nex(); break;
866                 case IT_HAGAR:            weapon_hagar(); break;
867                 case IT_ROCKET_LAUNCHER:  weapon_rocketlauncher(); break;
868                 // add all other item spawn functions here
869                 default:
870                         error("requested item can't be spawned");
871         }
872 }