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