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