]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/t_items.qc
changed all te_ effects (except te_bloodshower) to pointparticles()
[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_VOICE, "misc/itemrespawn.wav", 1, 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 (self, CHAN_BODY, self.noise, 1, ATTN_NORM);
189         sound (other, CHAN_AUTO, self.item_pickupsound, 1, 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) = {
218         remove(self);
219 }
220
221 // pickup evaluation functions
222 // these functions decide how desirable an item is to the bots
223
224 float(entity player, entity item) generic_pickupevalfunc = {return item.bot_pickupbasevalue;};
225
226 float(entity player, entity item) weapon_pickupevalfunc =
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(entity player, entity item) commodity_pickupevalfunc =
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 + 1 - min(player.ammo_shells / g_pickup_shells_max, 1);
244         if (item.ammo_nails)
245         if (player.ammo_nails < g_pickup_nails_max)
246                 c = c + 1 - min(player.ammo_nails / g_pickup_nails_max, 1);
247         if (item.ammo_rockets)
248         if (player.ammo_rockets < g_pickup_rockets_max)
249                 c = c + 1 - min(player.ammo_rockets / g_pickup_rockets_max, 1);
250         if (item.ammo_cells)
251         if (player.ammo_cells < g_pickup_cells_max)
252                 c = c + 1 - min(player.ammo_cells / g_pickup_cells_max, 1);
253         if (item.armorvalue)
254         if (player.armorvalue < item.max_armorvalue)
255                 c = c + 1 - min(player.armorvalue / item.max_armorvalue, 1);
256         if (item.health)
257         if (player.health < item.max_health)
258                 c = c + 1 - min(player.health / item.max_health, 1);
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         if (self.classname != "droppedweapon")
276         {
277                 if(teams_matter)
278                 {
279                         if(self.notteam)
280                         {
281                                 print("removed non-teamplay ", self.classname, "\n");
282                                 startitem_failed = TRUE;
283                                 remove (self);
284                                 return;
285                         }
286                 }
287                 else
288                 {
289                         if(self.notfree)
290                         {
291                                 print("removed non-FFA ", self.classname, "\n");
292                                 startitem_failed = TRUE;
293                                 remove (self);
294                                 return;
295                         }
296                 }
297
298                 if(self.notq3a)
299                 {
300                         // We aren't TA or something like that, so we keep the Q3A entities
301                         print("removed non-Q3A ", self.classname, "\n");
302                         startitem_failed = TRUE;
303                         remove (self);
304                         return;
305                 }
306                 
307                 if(self.targetname)
308                 {
309                         // target_give not yet supported; maybe later
310                         print("removed targeted ", self.classname, "\n");
311                         startitem_failed = TRUE;
312                         remove (self);
313                         return;
314                 }
315                 
316                 if(cvar("spawn_debug") >= 2)
317                 {
318                         entity otheritem;
319                         for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
320                         {
321                                 if(otheritem.is_item)
322                                 {
323                                         dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
324                                         dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
325                                         error("Mapper sucks.");
326                                 }
327                         }
328                         self.is_item = TRUE;
329                 }
330
331                 waypoint_spawnforitem(self);
332
333                 itemsInMap |= itemid;
334         }
335
336         if (!(cvar("g_pickup_items") && !g_nixnex) && !g_minstagib &&
337                         itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
338         {
339                 startitem_failed = TRUE;
340                 remove (self);
341                 return;
342         }
343
344         if (g_minstagib)
345         {
346                 // don't remove dropped items and powerups
347                 if (self.classname != "droppedweapon" &&
348                     self.classname != "minstagib")
349                 {
350                         startitem_failed = TRUE;
351                         remove (self);
352                         return;
353                 }
354         }
355
356         if(g_lms && (self.classname != "droppedweapon"))
357         {
358                 startitem_failed = TRUE;
359                 remove(self);
360                 return;
361         }
362
363         if(g_instagib || g_rocketarena)
364         {
365                 startitem_failed = TRUE;
366                 remove(self);
367                 return;
368         }
369
370         if (self.classname == "droppedweapon")
371         {
372                 // don't drop if in a NODROP zone (such as lava)
373                 traceline(self.origin, self.origin, MOVE_NORMAL, self);
374                 if (trace_dpstartcontents & DPCONTENTS_NODROP)
375                 {
376                         startitem_failed = TRUE;
377                         remove(self);
378                         return;
379                 }
380         }
381
382         if (self.classname != "droppedweapon")
383         {
384                 precache_model (itemmodel);
385                 precache_sound (pickupsound);
386                 precache_sound ("misc/itemrespawn.wav");
387         }
388
389         if(itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2 |
390                                 IT_ROCKET_LAUNCHER | IT_HAGAR | IT_NEX | IT_CRYLINK | IT_ELECTRO |
391                                 IT_GRENADE_LAUNCHER | IT_UZI | IT_SHOTGUN | IT_LASER) && self.classname != "droppedweapon")
392         {
393                 self.target = "###item###"; // for finding the nearest item using find()
394         }
395         self.bot_pickup = TRUE;
396         self.bot_pickupevalfunc = pickupevalfunc;
397         self.bot_pickupbasevalue = pickupbasevalue;
398         self.mdl = itemmodel;
399         //self.noise = pickupsound;
400         self.item_pickupsound = pickupsound;
401         // let mappers override respawntime
402         if (!self.respawntime)
403                 self.respawntime = defaultrespawntime;
404         self.netname = itemname;
405         self.items = itemid;
406         self.flags = FL_ITEM | itemflags;
407         if(self.spawnflags & 1)
408                 self.noalign = 1;
409         if (self.noalign)
410                 self.movetype = MOVETYPE_NONE;
411         else
412                 self.movetype = MOVETYPE_TOSS;
413         self.solid = SOLID_TRIGGER;
414         self.touch = Item_Touch;
415         setmodel (self, self.mdl); // precision set below
416         self.effects |= EF_LOWPRECISION;
417         if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
418                 setsize (self, '-16 -16 0', '16 16 48');
419         else
420                 setsize (self, '-16 -16 0', '16 16 32');
421         if (itemflags & FL_WEAPON)
422         {
423                 // neutral team color for pickup weapons
424                 self.colormap = 160 * 1024 + 160;
425         }
426
427         // Savage: remove thrown items after a certain period of time ("garbage collection")
428         if (self.classname == "droppedweapon")
429         {
430                 self.think = RemoveItem;
431                 self.nextthink = time + 60;
432         }
433         else if (!self.noalign)
434         {
435                 // first nudge it off the floor a little bit to avoid math errors
436                 setorigin(self, self.origin + '0 0 1');
437                 // note droptofloor returns FALSE if stuck/or would fall too far
438                 droptofloor();
439         }
440
441         if (cvar("g_fullbrightitems"))
442                 self.effects = self.effects | EF_FULLBRIGHT;
443 }
444
445 /* replace items in minstagib
446  * IT_STRENGTH   = invisibility
447  * IT_NAILS      = extra lives
448  * IT_INVINCIBLE = speed
449  */
450 void minstagib_items (float itemid)
451 {
452         // we don't want to replace dropped weapons ;)
453         if (self.classname == "droppedweapon")
454         {
455                 self.ammo_cells = 25;
456                 StartItem ("models/weapons/g_nex.md3",
457                         "weapons/weaponpickup.wav", 15,
458                         "Nex Gun", IT_NEX, FL_WEAPON, generic_pickupevalfunc, 1000);
459                 return;
460         }
461
462         local float rnd;
463         self.classname = "minstagib";
464
465         // replace rocket launchers and nex guns with ammo cells
466         if (itemid == IT_CELLS)
467         {
468                 self.ammo_cells = 1;
469                 StartItem ("models/items/a_cells.md3",
470                         "misc/itempickup.wav", 45,
471                         "Nex Ammo", IT_CELLS, 0, generic_pickupevalfunc, 100);
472                 return;
473         }
474
475         // randomize
476         rnd = random() * 3;
477         if (rnd <= 1)
478                 itemid = IT_STRENGTH;
479         else if (rnd <= 2)
480                 itemid = IT_NAILS;
481         else
482                 itemid = IT_INVINCIBLE;
483
484         // replace with invis
485         if (itemid == IT_STRENGTH)
486         {
487                 self.effects = EF_ADDITIVE;
488                 self.strength_finished = 30;
489                 StartItem ("models/items/g_strength.md3",
490                         "misc/powerup.wav", 120,
491                         "Invisibility", IT_STRENGTH, FL_POWERUP, generic_pickupevalfunc, 1000);
492         }
493         // replace with extra lives
494         if (itemid == IT_NAILS)
495         {
496                 self.max_health = 1;
497                 StartItem ("models/items/g_h100.md3",
498                         "misc/megahealth.wav", 120,
499                         "Extralife", IT_NAILS, FL_POWERUP, generic_pickupevalfunc, 1000);
500
501         }
502         // replace with speed
503         if (itemid == IT_INVINCIBLE)
504         {
505                 self.effects = EF_ADDITIVE;
506                 self.invincible_finished = 30;
507                 StartItem ("models/items/g_invincible.md3",
508                         "misc/powerup_shield.wav", 120,
509                         "Speed", IT_INVINCIBLE, FL_POWERUP, generic_pickupevalfunc, 1000);
510         }
511
512 }
513
514 float minst_no_auto_cells;
515 void minst_remove_item (void) {
516         if(minst_no_auto_cells)
517                 remove(self);
518 }
519
520 float weaponswapping;
521
522 void weapon_shotgun (void);
523 void weapon_uzi (void) {
524         if(!weaponswapping)
525         if(q3acompat_machineshotgunswap)
526         if(self.classname != "droppedweapon")
527         {
528                 weaponswapping = TRUE;
529                 weapon_shotgun();
530                 weaponswapping = FALSE;
531                 return;
532         }
533
534         if(!self.ammo_nails)
535                 self.ammo_nails = cvar("g_pickup_nails");
536         StartItem ("models/weapons/g_uzi.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_UZI), IT_UZI, FL_WEAPON, weapon_pickupevalfunc, 1000);
537         if (self.modelindex) // don't precache if self was removed
538                 weapon_action(WEP_UZI, WR_PRECACHE);
539 }
540
541 void weapon_shotgun (void) {
542         if(!weaponswapping)
543         if(q3acompat_machineshotgunswap)
544         if(self.classname != "droppedweapon")
545         {
546                 weaponswapping = TRUE;
547                 weapon_uzi();
548                 weaponswapping = FALSE;
549                 return;
550         }
551
552         if(!self.ammo_shells)
553                 self.ammo_shells = cvar("g_pickup_shells");
554         StartItem ("models/weapons/g_shotgun.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_SHOTGUN), IT_SHOTGUN, FL_WEAPON, weapon_pickupevalfunc, 1000);
555         if (self.modelindex) // don't precache if self was removed
556                 weapon_action(WEP_SHOTGUN, WR_PRECACHE);
557 }
558
559 void weapon_grenadelauncher (void)
560 {
561         if(!self.ammo_rockets)
562                 self.ammo_rockets = cvar("g_pickup_rockets");
563         StartItem ("models/weapons/g_gl.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_GRENADE_LAUNCHER), IT_GRENADE_LAUNCHER, FL_WEAPON, weapon_pickupevalfunc, 1000);
564         if (self.modelindex) // don't precache if self was removed
565                 weapon_action(WEP_GRENADE_LAUNCHER, WR_PRECACHE);
566 }
567
568 void weapon_electro (void)
569 {
570         if(!self.ammo_cells)
571                 self.ammo_cells = cvar("g_pickup_cells");
572         StartItem ("models/weapons/g_electro.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_ELECTRO), IT_ELECTRO, FL_WEAPON, weapon_pickupevalfunc, 1000);
573         if (self.modelindex) // don't precache if self was removed
574                 weapon_action(WEP_ELECTRO, WR_PRECACHE);
575 }
576
577 void weapon_crylink (void)
578 {
579         if(!self.ammo_cells)
580                 self.ammo_cells = cvar("g_pickup_cells");
581         StartItem ("models/weapons/g_crylink.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_CRYLINK), IT_CRYLINK, FL_WEAPON, weapon_pickupevalfunc, 1000);
582         if (self.modelindex) // don't precache if self was removed
583                 weapon_action(WEP_CRYLINK, WR_PRECACHE);
584 }
585
586 void weapon_nex (void)
587 {
588         float nextime;
589         if (g_minstagib)
590         {
591                 minstagib_items(IT_CELLS);
592                 self.think = minst_remove_item;
593                 self.nextthink = time + cvar("sys_ticrate");
594                 return;
595         }
596         if(!self.ammo_cells)
597                 self.ammo_cells = cvar("g_pickup_cells");
598         nextime = cvar("g_balance_nex_respawntime_modifier");
599         if(nextime)
600                 nextime = 15 * nextime;
601         else
602                 nextime = 15;
603         StartItem ("models/weapons/g_nex.md3", "weapons/weaponpickup.wav", nextime, W_Name(WEP_NEX), IT_NEX, FL_WEAPON, weapon_pickupevalfunc, 1000);
604         if (self.modelindex) // don't precache if self was removed
605                 weapon_action(WEP_NEX, WR_PRECACHE);
606 }
607
608 void weapon_hagar (void)
609 {
610         if(!self.ammo_rockets)
611                 self.ammo_rockets = cvar("g_pickup_rockets");
612         StartItem ("models/weapons/g_hagar.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_HAGAR), IT_HAGAR, FL_WEAPON, weapon_pickupevalfunc, 1000);
613         if (self.modelindex) // don't precache if self was removed
614                 weapon_action(WEP_HAGAR, WR_PRECACHE);
615 }
616
617 void weapon_rocketlauncher (void)
618 {
619         if (g_minstagib)
620         {
621                 minstagib_items(IT_CELLS);
622                 self.think = minst_remove_item;
623                 self.nextthink = time + cvar("sys_ticrate");
624                 return;
625         }
626         if(!self.ammo_rockets)
627                 self.ammo_rockets = g_pickup_rockets;
628         StartItem ("models/weapons/g_rl.md3", "weapons/weaponpickup.wav", 15, W_Name(WEP_ROCKET_LAUNCHER), IT_ROCKET_LAUNCHER, FL_WEAPON, weapon_pickupevalfunc, 1000);
629         if (self.modelindex) // don't precache if self was removed
630                 weapon_action(WEP_ROCKET_LAUNCHER, WR_PRECACHE);
631 }
632
633 void item_rockets (void) {
634         if(!self.ammo_rockets)
635                 self.ammo_rockets = g_pickup_rockets;
636         StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", 15, "rockets", IT_ROCKETS, 0, commodity_pickupevalfunc, 100);
637 }
638
639 void item_shells (void);
640 void item_bullets (void) {
641         if(!weaponswapping)
642         if(q3acompat_machineshotgunswap)
643         if(self.classname != "droppedweapon")
644         {
645                 weaponswapping = TRUE;
646                 item_shells();
647                 weaponswapping = FALSE;
648                 return;
649         }
650
651         if(!self.ammo_nails)
652                 self.ammo_nails = g_pickup_nails;
653         StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", 15, "bullets", IT_NAILS, 0, commodity_pickupevalfunc, 100);
654 }
655
656 void item_cells (void) {
657         if(!self.ammo_cells)
658                 self.ammo_cells = g_pickup_cells;
659         StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", 15, "cells", IT_CELLS, 0, commodity_pickupevalfunc, 100);
660 }
661
662 void item_shells (void) {
663         if(!weaponswapping)
664         if(q3acompat_machineshotgunswap)
665         if(self.classname != "droppedweapon")
666         {
667                 weaponswapping = TRUE;
668                 item_bullets();
669                 weaponswapping = FALSE;
670                 return;
671         }
672
673         if(!self.ammo_shells)
674                 self.ammo_shells = g_pickup_shells;
675         StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", 15, "shells", IT_SHELLS, 0, commodity_pickupevalfunc, 100);
676 }
677
678 void item_armor_small (void) {
679         if(!self.armorvalue)
680                 self.armorvalue = g_pickup_armorsmall;
681         if(!self.max_armorvalue)
682                 self.max_armorvalue = g_pickup_armorsmall_max;
683         StartItem ("models/items/g_a1.md3", "misc/armor1.wav", 15, "5 Armor", IT_ARMOR_SHARD, 0, commodity_pickupevalfunc, 100);
684 }
685
686 void item_armor_medium (void) {
687         if(!self.armorvalue)
688                 self.armorvalue = g_pickup_armormedium;
689         if(!self.max_armorvalue)
690                 self.max_armorvalue = g_pickup_armormedium_max;
691         StartItem ("models/items/g_armormedium.md3", "misc/armor1.wav", 30, "25 Armor", IT_ARMOR, 0, commodity_pickupevalfunc, 2000);
692 }
693
694 void item_armor_large (void) {
695         if(!self.armorvalue)
696                 self.armorvalue = g_pickup_armorlarge;
697         if(!self.max_armorvalue)
698                 self.max_armorvalue = g_pickup_armorlarge_max;
699         StartItem ("models/items/g_a25.md3", "misc/armor25.wav", 30, "100 Armor", IT_ARMOR, 0, commodity_pickupevalfunc, 2000);
700 }
701
702 void item_health_small (void) {
703         if(!self.max_health)
704                 self.max_health = g_pickup_healthsmall_max;
705         if(!self.health)
706                 self.health = g_pickup_healthsmall;
707         StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", 15, "5 Health", IT_5HP, 0, commodity_pickupevalfunc, 100);
708 }
709
710 void item_health_medium (void) {
711         if(!self.max_health)
712                 self.max_health = g_pickup_healthmedium_max;
713         if(!self.health)
714                 self.health = g_pickup_healthmedium;
715         StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", 15, "25 Health", IT_25HP, 0, commodity_pickupevalfunc, 500);
716 }
717
718 void item_health_large (void) {
719         if(!self.max_health)
720                 self.max_health = g_pickup_healthlarge_max;
721         if(!self.health)
722                 self.health = g_pickup_healthlarge;
723         StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", 15, "50 Health", IT_25HP, 0, commodity_pickupevalfunc, 500);
724 }
725
726 void item_health_mega (void) {
727         if(!cvar("g_powerup_superhealth"))
728                 return;
729
730         if(g_arena && !cvar("g_arena_powerups"))
731                 return;
732
733         if(g_minstagib) {
734                 minstagib_items(IT_NAILS);
735         } else {
736                 if(!self.max_health)
737                         self.max_health = g_pickup_healthmega_max;
738                 if(!self.health)
739                         self.health = g_pickup_healthmega;
740                 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", 30, "100 Health", IT_HEALTH, 0, commodity_pickupevalfunc, 2000);
741         }
742 }
743
744 // support old misnamed entities
745 void item_armor1() { item_armor_small(); }
746 void item_armor25() { item_armor_large(); }
747 void item_health1() { item_health_small(); }
748 void item_health25() { item_health_medium(); }
749 void item_health100() { item_health_mega(); }
750
751 void item_strength (void) {
752         if(!cvar("g_powerup_strength"))
753                 return;
754
755         if(g_arena && !cvar("g_arena_powerups"))
756                 return;
757
758         if(g_minstagib) {
759                 minstagib_items(IT_STRENGTH);
760         } else {
761                 precache_sound("weapons/strength_fire.wav");
762                 self.strength_finished = 30;
763                 self.effects = EF_ADDITIVE;StartItem ("models/items/g_strength.md3", "misc/powerup.wav", 120, "Strength Powerup", IT_STRENGTH, FL_POWERUP, generic_pickupevalfunc, 10000);
764         }
765 }
766
767 void item_invincible (void) {
768         if(!cvar("g_powerup_shield"))
769                 return;
770
771         if(g_arena && !cvar("g_arena_powerups"))
772                 return;
773
774         if(g_minstagib) {
775                 minstagib_items(IT_INVINCIBLE);
776         } else {
777                 self.invincible_finished = 30;
778                 self.effects = EF_ADDITIVE;
779                 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", 120, "Invulnerability", IT_INVINCIBLE, FL_POWERUP, generic_pickupevalfunc, 10000);
780         }
781 }
782 //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);}
783 //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);}
784
785 void item_minst_cells (void) {
786         if (g_minstagib)
787         {
788                 minst_no_auto_cells = 1;
789                 minstagib_items(IT_CELLS);
790         }
791         else
792                 remove(self);
793 }
794
795 // compatibility:
796 void item_quad (void) {self.classname = "item_strength";item_strength();}
797
798 void misc_models (void)
799 {
800         precache_model (self.model);
801         setmodel (self, self.model); // precision set by mapper
802         setsize (self, self.mins, self.maxs);
803 }
804
805 void func_wall_use (void)
806 {
807         if(teams_matter)
808         {
809                 if(activator.team)
810                         self.colormap = (activator.team - 1) * 0x11;
811                 else
812                         self.colormap = 0x00;
813         }
814         else
815                 self.colormap = ceil(random() * 256) - 1;
816 }
817
818 void func_wall (void)
819 {
820         precache_model (self.model);
821         setmodel (self, self.model); // precision set by mapper
822         setsize (self, self.mins, self.maxs);
823         self.solid = SOLID_BSP;
824         self.use = func_wall_use;
825 }
826
827 floatfield Item_CounterField(float it)
828 {
829         switch(it)
830         {
831                 case IT_SHELLS:      return ammo_shells;
832                 case IT_NAILS:       return ammo_nails;
833                 case IT_ROCKETS:     return ammo_rockets;
834                 case IT_CELLS:       return ammo_cells;
835                 case IT_5HP:         return health;
836                 case IT_25HP:        return health;
837                 case IT_HEALTH:      return health;
838                 case IT_ARMOR_SHARD: return armorvalue;
839                 case IT_ARMOR:       return armorvalue;
840                 // add more things here (health, armor)
841                 default:             error("requested item has no counter field");
842         }
843 }
844
845 float Item_WeaponCode(float it)
846 {
847         switch(it)
848         {
849                 case IT_LASER:            return WEP_LASER;
850                 case IT_SHOTGUN:          return WEP_SHOTGUN;
851                 case IT_UZI:              return WEP_UZI;
852                 case IT_GRENADE_LAUNCHER: return WEP_GRENADE_LAUNCHER;
853                 case IT_ELECTRO:          return WEP_ELECTRO;
854                 case IT_CRYLINK:          return WEP_CRYLINK;
855                 case IT_NEX:              return WEP_NEX;
856                 case IT_HAGAR:            return WEP_HAGAR;
857                 case IT_ROCKET_LAUNCHER:  return WEP_ROCKET_LAUNCHER;
858                 default:                  return 0;
859         }
860 }
861
862 void Item_SpawnByItemCode(float it)
863 {
864         switch(it)
865         {
866                 case IT_SHOTGUN:          weapon_shotgun(); break;
867                 case IT_UZI:              weapon_uzi(); break;
868                 case IT_GRENADE_LAUNCHER: weapon_grenadelauncher(); break;
869                 case IT_ELECTRO:          weapon_electro(); break;
870                 case IT_CRYLINK:          weapon_crylink(); break;
871                 case IT_NEX:              weapon_nex(); break;
872                 case IT_HAGAR:            weapon_hagar(); break;
873                 case IT_ROCKET_LAUNCHER:  weapon_rocketlauncher(); break;
874                 // add all other item spawn functions here
875                 default:
876                         error("requested item can't be spawned");
877         }
878 }