make jetpack and fuel regenerator have the powerup respawn time (mapper can override...
[divverent/nexuiz.git] / data / qcsrc / server / t_items.qc
1 floatfield Item_CounterField(float it)
2 {
3         switch(it)
4         {
5                 case IT_SHELLS:      return ammo_shells;
6                 case IT_NAILS:       return ammo_nails;
7                 case IT_ROCKETS:     return ammo_rockets;
8                 case IT_CELLS:       return ammo_cells;
9                 case IT_FUEL:        return ammo_fuel;
10                 case IT_5HP:         return health;
11                 case IT_25HP:        return health;
12                 case IT_HEALTH:      return health;
13                 case IT_ARMOR_SHARD: return armorvalue;
14                 case IT_ARMOR:       return armorvalue;
15                 // add more things here (health, armor)
16                 default:             error("requested item has no counter field");
17         }
18 }
19
20 string Item_CounterFieldName(float it)
21 {
22         switch(it)
23         {
24                 case IT_SHELLS:      return "shells";
25                 case IT_NAILS:       return "nails";
26                 case IT_ROCKETS:     return "rockets";
27                 case IT_CELLS:       return "cells";
28                 case IT_FUEL:        return "fuel";
29
30                 // add more things here (health, armor)
31                 default:             error("requested item has no counter field name");
32         }
33 }
34
35 .float max_armorvalue;
36
37 void Item_Respawn (void)
38 {
39         self.model = self.mdl;          // restore original model
40         self.solid = SOLID_TRIGGER;     // allow it to be touched again
41         sound (self, CHAN_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM);        // play respawn sound
42         setorigin (self, self.origin);
43
44         //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
45         pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
46 }
47
48 float Item_GiveTo(entity item, entity player)
49 {
50         float _switchweapon;
51         float pickedup;
52         float it;
53         float i;
54         entity e;
55
56         // if nothing happens to player, just return without taking the item
57         pickedup = FALSE;
58         _switchweapon = FALSE;
59
60         if (g_minstagib)
61         {
62                 _switchweapon = TRUE;
63                 if (item.ammo_cells)
64                 {
65                         pickedup = TRUE;
66                         // play some cool sounds ;)
67                         centerprint(player, "\n");
68                         if(player.health <= 5)
69                                 announce(player, "announcer/robotic/lastsecond.wav");
70                         else if(player.health < 50)
71                                 announce(player, "announcer/robotic/narrowly.wav");
72                         // sound not available
73                         // else if(item.items == IT_CELLS)
74                         //      play2(player, "announce/robotic/ammo.wav");
75
76                         if (item.weapons & WEPBIT_MINSTANEX)
77                                 W_GiveWeapon (player, WEP_MINSTANEX, "Nex");
78                         if (item.ammo_cells)
79                                 player.ammo_cells = min (player.ammo_cells + cvar("g_minstagib_ammo_drop"), 999);
80                         player.health = 100;
81                 }
82
83                 // extralife powerup
84                 if (item.max_health)
85                 {
86                         pickedup = TRUE;
87                         // sound not available
88                         // play2(player, "announce/robotic/extra.ogg\nplay2 announce/robotic/_lives.wav");
89                         player.armorvalue = player.armorvalue + cvar("g_minstagib_extralives");
90                         sprint(player, "^3You picked up some extra lives\n");
91                 }
92
93                 // invis powerup
94                 if (item.strength_finished)
95                 {
96                         pickedup = TRUE;
97                         // sound not available
98                         // play2(player, "announce/robotic/invisible.wav");
99                         player.strength_finished = max(player.strength_finished, time) + cvar("g_balance_powerup_strength_time");
100                 }
101
102                 // speed powerup
103                 if (item.invincible_finished)
104                 {
105                         pickedup = TRUE;
106                         // sound not available
107                         // play2(player, "announce/robotic/speed.wav");
108                         player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
109                 }
110         }
111         else
112         {
113                 if (g_weapon_stay == 1)
114                 if not(item.flags & FL_NO_WEAPON_STAY)
115                 if (item.flags & FL_WEAPON)
116                 {
117                         if(item.classname == "droppedweapon")
118                         {
119                                 if (player.weapons & item.weapons)      // don't let players stack ammo by tossing weapons
120                                         goto skip;
121                         }
122                         else
123                         {
124                                 if (player.weapons & item.weapons)
125                                         goto skip;
126                         }
127                 }
128
129                 // in case the player has autoswitch enabled do the following:
130                 // if the player is using their best weapon before items are given, they
131                 // probably want to switch to an even better weapon after items are given
132                 if (player.autoswitch)
133                 if (player.switchweapon == w_getbestweapon(player))
134                         _switchweapon = TRUE;
135
136                 if not(player.weapons & W_WeaponBit(player.switchweapon))
137                         _switchweapon = TRUE;
138
139                 if (item.ammo_shells)
140                 if (player.ammo_shells < g_pickup_shells_max)
141                 {
142                         pickedup = TRUE;
143                         player.ammo_shells = min (player.ammo_shells + item.ammo_shells, g_pickup_shells_max);
144                 }
145                 if (item.ammo_nails)
146                 if (player.ammo_nails < g_pickup_nails_max)
147                 {
148                         pickedup = TRUE;
149                         player.ammo_nails = min (player.ammo_nails + item.ammo_nails, g_pickup_nails_max);
150                 }
151                 if (item.ammo_rockets)
152                 if (player.ammo_rockets < g_pickup_rockets_max)
153                 {
154                         pickedup = TRUE;
155                         player.ammo_rockets = min (player.ammo_rockets + item.ammo_rockets, g_pickup_rockets_max);
156                 }
157                 if (item.ammo_cells)
158                 if (player.ammo_cells < g_pickup_cells_max)
159                 {
160                         pickedup = TRUE;
161                         player.ammo_cells = min (player.ammo_cells + item.ammo_cells, g_pickup_cells_max);
162                 }
163                 if (item.ammo_fuel)
164                 if (player.ammo_fuel < g_pickup_fuel_max)
165                 {
166                         pickedup = TRUE;
167                         player.ammo_fuel = min(player.ammo_fuel + item.ammo_fuel, g_pickup_fuel_max);
168                         player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + cvar("g_balance_pause_fuel_rot"));
169                 }
170
171                 if (item.flags & FL_WEAPON)
172                 if ((it = item.weapons - (item.weapons & player.weapons)))
173                 {
174                         pickedup = TRUE;
175                         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
176                         {
177                                 e = get_weaponinfo(i);
178                                 if(it & e.weapons)
179                                         W_GiveWeapon (player, e.weapon, item.netname);
180                         }
181                 }
182
183                 if((it = (item.items - (item.items & player.items) & IT_PICKUPMASK)))
184                 {
185                         pickedup = TRUE;
186                         player.items |= it;
187                 }
188
189                 if (item.strength_finished)
190                 {
191                         pickedup = TRUE;
192                         player.strength_finished = max(player.strength_finished, time) + cvar("g_balance_powerup_strength_time");
193                 }
194                 if (item.invincible_finished)
195                 {
196                         pickedup = TRUE;
197                         player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
198                 }
199                 //if (item.speed_finished)
200                 //{
201                 //      pickedup = TRUE;
202                 //      player.speed_finished = max(player.speed_finished, time) + cvar("g_balance_powerup_speed_time");
203                 //}
204                 //if (item.slowmo_finished)
205                 //{
206                 //      pickedup = TRUE;
207                 //      player.slowmo_finished = max(player.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
208                 //}
209
210                 if (item.health)
211                 if (player.health < item.max_health)
212                 {
213                         pickedup = TRUE;
214                         player.health = min(player.health + item.health, item.max_health);
215                         player.pauserothealth_finished = max(player.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
216                 }
217                 if (item.armorvalue)
218                 if (player.armorvalue < item.max_armorvalue)
219                 {
220                         pickedup = TRUE;
221                         player.armorvalue = min(player.armorvalue + item.armorvalue, item.max_armorvalue);
222                         player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + cvar("g_balance_pause_armor_rot"));
223                 }
224         }
225
226 :skip
227         // always eat teamed entities
228         if(item.team)
229                 pickedup = TRUE;
230
231         if (!pickedup)
232                 return 0;
233
234         sound (player, CHAN_AUTO, item.item_pickupsound, VOL_BASE, ATTN_NORM);
235         if (_switchweapon)
236                 W_SwitchWeapon_Force(player, w_getbestweapon(player));
237
238         return 1;
239 }
240
241 void Item_Touch (void)
242 {
243         entity e, head;
244
245         // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
246         if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
247         {
248                 remove(self);
249                 return;
250         }
251         if (other.classname != "player")
252                 return;
253         if (other.deadflag)
254                 return;
255         if (self.solid != SOLID_TRIGGER)
256                 return;
257         if (self.owner == other)
258                 return;
259
260         if(!Item_GiveTo(self, other))
261                 return;
262
263         if (self.classname == "droppedweapon")
264                 remove (self);
265         else if((self.flags & FL_WEAPON) && !(self.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
266                 return;
267         else
268         {
269                 self.solid = SOLID_NOT;
270                 self.model = string_null;
271                 if(self.team)
272                 {
273                         RandomSelection_Init();
274                         for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
275                                 RandomSelection_Add(head, 0, head.cnt, 0);
276                         e = RandomSelection_chosen_ent;
277                 }
278                 else
279                         e = self;
280                 e.nextthink = time + self.respawntime;
281                 e.think = Item_Respawn;
282         }
283 }
284
285 void Item_FindTeam()
286 {
287         entity head, e;
288
289         if(self.effects & EF_NODRAW)
290         {
291                 // marker for item team search
292                 dprint("Initializing item team ", ftos(self.team), "\n");
293                 RandomSelection_Init();
294                 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
295                         RandomSelection_Add(head, 0, head.cnt, 0);
296                 e = RandomSelection_chosen_ent;
297                 e.state = 0;
298
299                 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
300                 {
301                         if(head != e)
302                         {
303                                 // make it a non-spawned item
304                                 head.solid = SOLID_NOT;
305                                 head.model = string_null;
306                                 head.state = 1; // state 1 = initially hidden item
307                         }
308                         head.effects = head.effects - (head.effects & EF_NODRAW);
309                 }
310         }
311 }
312
313 void Item_Reset()
314 {
315         if(self.state == 1)
316         {
317                 self.model = string_null;
318                 self.solid = SOLID_NOT;
319         }
320         else
321         {
322                 self.model = self.mdl;
323                 self.solid = SOLID_TRIGGER;
324         }
325         setorigin (self, self.origin);
326         self.think = SUB_Null;
327         self.nextthink = 0;
328 }
329
330 // Savage: used for item garbage-collection
331 // TODO: perhaps nice special effect?
332 void RemoveItem(void)
333 {
334         remove(self);
335 }
336
337 // pickup evaluation functions
338 // these functions decide how desirable an item is to the bots
339
340 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;};
341
342 float weapon_pickupevalfunc(entity player, entity item)
343 {
344         // if we already have the weapon, rate it 1/5th normal value
345         if ((player.weapons & item.weapons) == item.weapons)
346                 return item.bot_pickupbasevalue * 0.2;
347         return item.bot_pickupbasevalue;
348 };
349
350 float commodity_pickupevalfunc(entity player, entity item)
351 {
352         float c;
353         c = 0;
354         // TODO: figure out if the player even has the weapon this ammo is for?
355         // may not affect strategy much though...
356         // find out how much more ammo/armor/health the player can hold
357         if (item.ammo_shells)
358         if (player.ammo_shells < g_pickup_shells_max)
359                 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
360         if (item.ammo_nails)
361         if (player.ammo_nails < g_pickup_nails_max)
362                 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
363         if (item.ammo_rockets)
364         if (player.ammo_rockets < g_pickup_rockets_max)
365                 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
366         if (item.ammo_cells)
367         if (player.ammo_cells < g_pickup_cells_max)
368                 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
369         if (item.armorvalue)
370         if (player.armorvalue < item.max_armorvalue)
371                 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
372         if (item.health)
373         if (player.health < item.max_health)
374                 c = c + max(0, 1 - player.health / item.max_health);
375
376         return item.bot_pickupbasevalue * c;
377 };
378
379
380 .float is_item;
381 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
382 {
383         startitem_failed = FALSE;
384
385         // is it a dropped weapon?
386         if (self.classname == "droppedweapon")
387         {
388                 self.reset = SUB_Remove;
389                 // it's a dropped weapon
390                 self.movetype = MOVETYPE_TOSS;
391                 self.solid = SOLID_TRIGGER;
392                 // Savage: remove thrown items after a certain period of time ("garbage collection")
393                 self.think = RemoveItem;
394                 self.nextthink = time + 60;
395                 // don't drop if in a NODROP zone (such as lava)
396                 traceline(self.origin, self.origin, MOVE_NORMAL, self);
397                 if (trace_dpstartcontents & DPCONTENTS_NODROP)
398                 {
399                         startitem_failed = TRUE;
400                         remove(self);
401                         return;
402                 }
403         }
404         else
405         {
406                 self.reset = Item_Reset;
407                 // it's a level item
408                 if(self.spawnflags & 1)
409                         self.noalign = 1;
410                 if (self.noalign)
411                         self.movetype = MOVETYPE_NONE;
412                 else
413                         self.movetype = MOVETYPE_TOSS;
414                 self.solid = SOLID_TRIGGER;
415                 // do item filtering according to game mode and other things
416                 if (!self.noalign)
417                 {
418                         // first nudge it off the floor a little bit to avoid math errors
419                         setorigin(self, self.origin + '0 0 1');
420                         // set item size before we spawn a spawnfunc_waypoint
421                         if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
422                                 setsize (self, '-16 -16 0', '16 16 48');
423                         else
424                                 setsize (self, '-16 -16 0', '16 16 32');
425                         // note droptofloor returns FALSE if stuck/or would fall too far
426                         droptofloor();
427                         waypoint_spawnforitem(self);
428                 }
429
430                 if(teams_matter)
431                 {
432                         if(self.notteam)
433                         {
434                                 print("removed non-teamplay ", self.classname, "\n");
435                                 startitem_failed = TRUE;
436                                 remove (self);
437                                 return;
438                         }
439                 }
440                 else
441                 {
442                         if(self.notfree)
443                         {
444                                 print("removed non-FFA ", self.classname, "\n");
445                                 startitem_failed = TRUE;
446                                 remove (self);
447                                 return;
448                         }
449                 }
450
451                 if(self.notq3a)
452                 {
453                         // We aren't TA or something like that, so we keep the Q3A entities
454                         print("removed non-Q3A ", self.classname, "\n");
455                         startitem_failed = TRUE;
456                         remove (self);
457                         return;
458                 }
459
460                 /*
461                  * can't do it that way, as it would break maps
462                  * TODO make a target_give like entity another way, that perhaps has
463                  * the weapon name in a key
464                 if(self.targetname)
465                 {
466                         // target_give not yet supported; maybe later
467                         print("removed targeted ", self.classname, "\n");
468                         startitem_failed = TRUE;
469                         remove (self);
470                         return;
471                 }
472                 */
473
474                 if(cvar("spawn_debug") >= 2)
475                 {
476                         entity otheritem;
477                         for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
478                         {
479                                 if(otheritem.is_item)
480                                 {
481                                         dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
482                                         dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
483                                         error("Mapper sucks.");
484                                 }
485                         }
486                         self.is_item = TRUE;
487                 }
488
489                 weaponsInMap |= weaponid;
490
491                 if(g_lms)
492                 {
493                         startitem_failed = TRUE;
494                         remove(self);
495                         return;
496                 }
497                 else if (g_weaponarena && ((weaponid & WEPBIT_ALL) || (itemid & IT_AMMO)))
498                 {
499                         startitem_failed = TRUE;
500                         remove(self);
501                         return;
502                 }
503                 else if (g_minstagib)
504                 {
505                         // don't remove dropped items and powerups
506                         if (self.classname != "minstagib")
507                         {
508                                 startitem_failed = TRUE;
509                                 remove (self);
510                                 return;
511                         }
512                 }
513                 else if ((!cvar("g_pickup_items") || g_nixnex) && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
514                 {
515                         startitem_failed = TRUE;
516                         remove (self);
517                         return;
518                 }
519
520                 precache_model (itemmodel);
521                 precache_sound (pickupsound);
522                 precache_sound ("misc/itemrespawn.wav");
523
524                 if((itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)) || (weaponid & WEPBIT_ALL))
525                         self.target = "###item###"; // for finding the nearest item using find()
526         }
527
528         self.bot_pickup = TRUE;
529         self.bot_pickupevalfunc = pickupevalfunc;
530         self.bot_pickupbasevalue = pickupbasevalue;
531         self.mdl = itemmodel;
532         self.item_pickupsound = pickupsound;
533         // let mappers override respawntime
534         if (!self.respawntime)
535                 self.respawntime = defaultrespawntime;
536         self.netname = itemname;
537         self.items = itemid;
538         self.weapons = weaponid;
539         self.flags = FL_ITEM | itemflags;
540         self.touch = Item_Touch;
541         setmodel (self, self.mdl); // precision set below
542         self.effects |= EF_LOWPRECISION;
543         if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
544                 setsize (self, '-16 -16 0', '16 16 48');
545         else
546                 setsize (self, '-16 -16 0', '16 16 32');
547         if(itemflags & FL_WEAPON)
548                 self.modelflags |= MF_ROTATE;
549
550         if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
551         if (itemflags & FL_WEAPON)
552         {
553                 // neutral team color for pickup weapons
554                 self.colormap = 1024; // color shirt=0 pants=0 grey
555         }
556
557         if (cvar("g_fullbrightitems"))
558                 self.effects = self.effects | EF_FULLBRIGHT;
559
560         self.state = 0;
561         if(self.team)
562         {
563                 if(!self.cnt)
564                         self.cnt = 1; // item probability weight
565                 self.effects = self.effects | EF_NODRAW; // marker for item team search
566                 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
567         }
568 }
569
570 /* replace items in minstagib
571  * IT_STRENGTH   = invisibility
572  * IT_NAILS      = extra lives
573  * IT_INVINCIBLE = speed
574  */
575 void minstagib_items (float itemid)
576 {
577         // we don't want to replace dropped weapons ;)
578         if (self.classname == "droppedweapon")
579         {
580                 self.ammo_cells = 25;
581                 StartItem ("models/weapons/g_nex.md3",
582                         "weapons/weaponpickup.wav", 15,
583                         "MinstaNex", 0, WEPBIT_MINSTANEX, FL_WEAPON, generic_pickupevalfunc, 1000);
584                 return;
585         }
586
587         local float rnd;
588         self.classname = "minstagib";
589
590         // replace rocket launchers and nex guns with ammo cells
591         if (itemid == IT_CELLS)
592         {
593                 self.ammo_cells = 1;
594                 StartItem ("models/items/a_cells.md3",
595                         "misc/itempickup.wav", 45,
596                         "Nex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
597                 return;
598         }
599
600         // randomize
601         rnd = random() * 3;
602         if (rnd <= 1)
603                 itemid = IT_STRENGTH;
604         else if (rnd <= 2)
605                 itemid = IT_NAILS;
606         else
607                 itemid = IT_INVINCIBLE;
608
609         // replace with invis
610         if (itemid == IT_STRENGTH)
611         {
612                 self.effects = EF_ADDITIVE;
613                 self.strength_finished = 30;
614                 StartItem ("models/items/g_strength.md3",
615                         "misc/powerup.wav", g_pickup_respawntime_powerup,
616                         "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
617         }
618         // replace with extra lives
619         if (itemid == IT_NAILS)
620         {
621                 self.max_health = 1;
622                 StartItem ("models/items/g_h100.md3",
623                         "misc/megahealth.wav", g_pickup_respawntime_powerup,
624                         "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
625
626         }
627         // replace with speed
628         if (itemid == IT_INVINCIBLE)
629         {
630                 self.effects = EF_ADDITIVE;
631                 self.invincible_finished = 30;
632                 StartItem ("models/items/g_invincible.md3",
633                         "misc/powerup_shield.wav", g_pickup_respawntime_powerup,
634                         "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
635         }
636
637 }
638
639 float minst_no_auto_cells;
640 void minst_remove_item (void) {
641         if(minst_no_auto_cells)
642                 remove(self);
643 }
644
645 float weaponswapping;
646 float internalteam;
647
648 void weapon_defaultspawnfunc(float wpn)
649 {
650         entity e;
651         float t;
652         var .float ammofield;
653         string s;
654         entity oldself;
655         float i, j;
656
657         // set the respawntime in advance (so replaced weapons can copy it)
658         if(!self.respawntime)
659         {
660                 e = get_weaponinfo(wpn);
661                 if(e.items == IT_SUPERWEAPON)
662                         self.respawntime = g_pickup_respawntime_powerup;
663                 else
664                         self.respawntime = g_pickup_respawntime_weapon;
665         }
666
667         if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
668         {
669                 e = get_weaponinfo(wpn);
670                 s = cvar_string(strcat("g_weaponreplace_", e.netname));
671                 if(s == "0")
672                 {
673                         remove(self);
674                         startitem_failed = TRUE;
675                         return;
676                 }
677                 t = tokenize_sane(s);
678                 if(t >= 2)
679                 {
680                         self.team = --internalteam;
681                         oldself = self;
682                         for(i = 1; i < t; ++i)
683                         {
684                                 s = argv(i);
685                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
686                                 {
687                                         e = get_weaponinfo(j);
688                                         if(e.netname == s)
689                                         {
690                                                 self = spawn();
691                                                 copyentity(oldself, self);
692                                                 self.classname = "replacedweapon";
693                                                 weapon_defaultspawnfunc(j);
694                                                 break;
695                                         }
696                                 }
697                                 if(j > WEP_LAST)
698                                 {
699                                         print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
700                                 }
701                         }
702                         self = oldself;
703                 }
704                 if(t >= 1)
705                 {
706                         s = argv(0);
707                         wpn = 0;
708                         for(j = WEP_FIRST; j <= WEP_LAST; ++j)
709                         {
710                                 e = get_weaponinfo(j);
711                                 if(e.netname == s)
712                                 {
713                                         wpn = j;
714                                         break;
715                                 }
716                         }
717                         if(j > WEP_LAST)
718                         {
719                                 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
720                         }
721                 }
722                 if(wpn == 0)
723                 {
724                         remove(self);
725                         startitem_failed = TRUE;
726                         return;
727                 }
728         }
729
730         e = get_weaponinfo(wpn);
731
732         if(e.items && e.items != IT_SUPERWEAPON)
733         {
734                 ammofield = Item_CounterField(e.items);
735                 if(!self.ammofield)
736                         self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(e.items)));
737         }
738         else
739         {
740                 self.flags |= FL_NO_WEAPON_STAY;
741         }
742
743         // weapon stay isn't supported for teamed weapons
744         if(self.team)
745                 self.flags |= FL_NO_WEAPON_STAY;
746
747         if(g_weapon_stay == 2 && self.classname != "droppedweapon")
748         {
749                 self.ammo_shells = 0;
750                 self.ammo_nails = 0;
751                 self.ammo_cells = 0;
752                 self.ammo_rockets = 0;
753                 // weapon stay 2: don't use ammo on weapon pickups; instead
754                 // initialize all ammo types to the pickup ammo unless set by g_start_ammo_*
755         }
756
757         StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, e.bot_pickupbasevalue);
758         if (self.modelindex) // don't precache if self was removed
759                 weapon_action(e.weapon, WR_PRECACHE);
760 }
761
762 void spawnfunc_weapon_shotgun (void);
763 void spawnfunc_weapon_uzi (void) {
764         if(q3acompat_machineshotgunswap)
765         if(self.classname != "droppedweapon")
766         {
767                 weapon_defaultspawnfunc(WEP_SHOTGUN);
768                 return;
769         }
770         weapon_defaultspawnfunc(WEP_UZI);
771 }
772
773 void spawnfunc_weapon_shotgun (void) {
774         if(q3acompat_machineshotgunswap)
775         if(self.classname != "droppedweapon")
776         {
777                 weapon_defaultspawnfunc(WEP_UZI);
778                 return;
779         }
780         weapon_defaultspawnfunc(WEP_SHOTGUN);
781 }
782
783 void spawnfunc_weapon_nex (void)
784 {
785         if (g_minstagib)
786         {
787                 minstagib_items(IT_CELLS);
788                 self.think = minst_remove_item;
789                 self.nextthink = time;
790                 return;
791         }
792         weapon_defaultspawnfunc(WEP_NEX);
793 }
794
795 void spawnfunc_weapon_minstanex (void)
796 {
797         if (g_minstagib)
798         {
799                 minstagib_items(IT_CELLS);
800                 self.think = minst_remove_item;
801                 self.nextthink = time;
802                 return;
803         }
804         weapon_defaultspawnfunc(WEP_MINSTANEX);
805 }
806
807 void spawnfunc_weapon_rocketlauncher (void)
808 {
809         if (g_minstagib)
810         {
811                 minstagib_items(IT_CELLS);
812                 self.think = minst_remove_item;
813                 self.nextthink = time;
814                 return;
815         }
816         weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
817 }
818
819 void spawnfunc_item_rockets (void) {
820         if(!self.ammo_rockets)
821                 self.ammo_rockets = g_pickup_rockets;
822         StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
823 }
824
825 void spawnfunc_item_shells (void);
826 void spawnfunc_item_bullets (void) {
827         if(!weaponswapping)
828         if(q3acompat_machineshotgunswap)
829         if(self.classname != "droppedweapon")
830         {
831                 weaponswapping = TRUE;
832                 spawnfunc_item_shells();
833                 weaponswapping = FALSE;
834                 return;
835         }
836
837         if(!self.ammo_nails)
838                 self.ammo_nails = g_pickup_nails;
839         StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", g_pickup_respawntime_ammo, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
840 }
841
842 void spawnfunc_item_cells (void) {
843         if(!self.ammo_cells)
844                 self.ammo_cells = g_pickup_cells;
845         StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
846 }
847
848 void spawnfunc_item_shells (void) {
849         if(!weaponswapping)
850         if(q3acompat_machineshotgunswap)
851         if(self.classname != "droppedweapon")
852         {
853                 weaponswapping = TRUE;
854                 spawnfunc_item_bullets();
855                 weaponswapping = FALSE;
856                 return;
857         }
858
859         if(!self.ammo_shells)
860                 self.ammo_shells = g_pickup_shells;
861         StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
862 }
863
864 void spawnfunc_item_armor_small (void) {
865         if(!self.armorvalue)
866                 self.armorvalue = g_pickup_armorsmall;
867         if(!self.max_armorvalue)
868                 self.max_armorvalue = g_pickup_armorsmall_max;
869         StartItem ("models/items/g_a1.md3", "misc/armor1.wav", g_pickup_respawntime_short, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
870 }
871
872 void spawnfunc_item_armor_medium (void) {
873         if(!self.armorvalue)
874                 self.armorvalue = g_pickup_armormedium;
875         if(!self.max_armorvalue)
876                 self.max_armorvalue = g_pickup_armormedium_max;
877         StartItem ("models/items/g_armormedium.md3", "misc/armor10.wav", g_pickup_respawntime_medium, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
878 }
879
880 void spawnfunc_item_armor_big (void) {
881         if(!self.armorvalue)
882                 self.armorvalue = g_pickup_armorbig;
883         if(!self.max_armorvalue)
884                 self.max_armorvalue = g_pickup_armorbig_max;
885         StartItem ("models/items/g_a50.md3", "misc/armor17_5.wav", g_pickup_respawntime_long, "50 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
886 }
887
888 void spawnfunc_item_armor_large (void) {
889         if(!self.armorvalue)
890                 self.armorvalue = g_pickup_armorlarge;
891         if(!self.max_armorvalue)
892                 self.max_armorvalue = g_pickup_armorlarge_max;
893         StartItem ("models/items/g_a25.md3", "misc/armor25.wav", g_pickup_respawntime_long, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
894 }
895
896 void spawnfunc_item_health_small (void) {
897         if(!self.max_health)
898                 self.max_health = g_pickup_healthsmall_max;
899         if(!self.health)
900                 self.health = g_pickup_healthsmall;
901         StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", g_pickup_respawntime_short, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
902 }
903
904 void spawnfunc_item_health_medium (void) {
905         if(!self.max_health)
906                 self.max_health = g_pickup_healthmedium_max;
907         if(!self.health)
908                 self.health = g_pickup_healthmedium;
909         StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", g_pickup_respawntime_short, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
910 }
911
912 void spawnfunc_item_health_large (void) {
913         if(!self.max_health)
914                 self.max_health = g_pickup_healthlarge_max;
915         if(!self.health)
916                 self.health = g_pickup_healthlarge;
917         StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", g_pickup_respawntime_medium, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
918 }
919
920 void spawnfunc_item_health_mega (void) {
921         if(!cvar("g_powerup_superhealth"))
922                 return;
923
924         if(g_arena && !cvar("g_arena_powerups"))
925                 return;
926
927         if(g_minstagib) {
928                 minstagib_items(IT_NAILS);
929         } else {
930                 if(!self.max_health)
931                         self.max_health = g_pickup_healthmega_max;
932                 if(!self.health)
933                         self.health = g_pickup_healthmega;
934                 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", g_pickup_respawntime_long, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
935         }
936 }
937
938 // support old misnamed entities
939 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); }  // FIXME: in Quake this is green armor, in Nexuiz maps it is an armor shard
940 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
941 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
942 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
943 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
944
945 void spawnfunc_item_strength (void) {
946         if(!cvar("g_powerup_strength"))
947                 return;
948
949         if(g_arena && !cvar("g_arena_powerups"))
950                 return;
951
952         if(g_minstagib) {
953                 minstagib_items(IT_STRENGTH);
954         } else {
955                 precache_sound("weapons/strength_fire.wav");
956                 self.strength_finished = 30;
957                 self.effects = EF_ADDITIVE;
958                 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", g_pickup_respawntime_powerup, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
959         }
960 }
961
962 void spawnfunc_item_invincible (void) {
963         if(!cvar("g_powerup_shield"))
964                 return;
965
966         if(g_arena && !cvar("g_arena_powerups"))
967                 return;
968
969         if(g_minstagib) {
970                 minstagib_items(IT_INVINCIBLE);
971         } else {
972                 self.invincible_finished = 30;
973                 self.effects = EF_ADDITIVE;
974                 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", g_pickup_respawntime_powerup, "Invulnerability", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
975         }
976 }
977
978 void spawnfunc_item_minst_cells (void) {
979         if (g_minstagib)
980         {
981                 minst_no_auto_cells = 1;
982                 minstagib_items(IT_CELLS);
983         }
984         else
985                 remove(self);
986 }
987
988 // compatibility:
989 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
990
991 void spawnfunc_misc_models (void)
992 {
993         // exists as alias name for 2.4.2 compat
994         SetBrushEntityModel();
995 }
996
997 void spawnfunc_func_static (void)
998 {
999         // exists as alias name for having it with brushes
1000         SetBrushEntityModel();
1001 }
1002
1003 void func_wall_use (void)
1004 {
1005         if(teams_matter)
1006         {
1007                 if(activator.team)
1008                         self.colormap = (activator.team - 1) * 0x11;
1009                 else
1010                         self.colormap = 0x00;
1011         }
1012         else
1013                 self.colormap = floor(random() * 256);
1014         self.colormap |= 1024; // RENDER_COLORMAPPED
1015 }
1016
1017 void spawnfunc_func_wall (void)
1018 {
1019         SetBrushEntityModel();
1020         if(!self.solid)
1021                 self.solid = SOLID_BSP;
1022         self.use = func_wall_use;
1023 }
1024
1025 void spawnfunc_func_illusionary (void)
1026 {
1027         SetBrushEntityModel();
1028         self.use = func_wall_use;
1029 }
1030
1031 void gamemodel_drop()
1032 {
1033         if(self.spawnflags & 3 == 1) // ALIGN_ORIGIN
1034         {
1035                 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
1036                 setorigin(self, trace_endpos);
1037         }
1038         else if(self.spawnflags & 3 == 2) // ALIGN_BOTTOM
1039         {
1040                 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
1041                 setorigin(self, trace_endpos);
1042         }
1043         else if(self.spawnflags & 3 == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
1044         {
1045                 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
1046                 setorigin(self, trace_endpos - '0 0 1' * self.mins_z);
1047         }
1048 }
1049
1050 .float modelscale;
1051 void spawnfunc_misc_gamemodel (void)
1052 {
1053         if(!self.scale)
1054                 self.scale = self.modelscale;
1055         SetBrushEntityModel();
1056         self.use = func_wall_use;
1057
1058         InitializeEntity(self, gamemodel_drop, INITPRIO_DROPTOFLOOR);
1059 }
1060
1061 float target_item_func_set(float a, float b)
1062 {
1063         if(b == 0)
1064                 return a;
1065         else if(b < 0)
1066                 return 0;
1067         else
1068                 return b;
1069 }
1070
1071 float target_item_func_min(float a, float b)
1072 {
1073         if(b == 0)
1074                 return a;
1075         else if(b < 0)
1076                 return 0;
1077         else
1078                 return min(a, b);
1079 }
1080
1081 float target_item_func_max(float a, float b)
1082 {
1083         return max(a, b);
1084 }
1085
1086 float target_item_func_bitset(float a, float b)
1087 {
1088         return b;
1089 }
1090
1091 float target_item_func_and(float a, float b)
1092 {
1093         return a & b;
1094 }
1095
1096 float target_item_func_itembitset(float a, float b)
1097 {
1098         return (a - (a & (IT_UNLIMITED_WEAPON_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | b;
1099 }
1100
1101 float target_item_func_itemand(float a, float b)
1102 {
1103         return (a - (a & (IT_UNLIMITED_WEAPON_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | (a & b);
1104 }
1105
1106 float target_item_func_or(float a, float b)
1107 {
1108         return a | b;
1109 }
1110
1111 float target_item_func_andnot(float a, float b)
1112 {
1113         return a - (a & b);
1114 }
1115
1116 float target_item_changed;
1117 void target_item_change(float binary, .float field, float(float a, float b) func, string sound_increase, string sound_decrease)
1118 {
1119         float n, d;
1120         n = func(activator.field, self.field);
1121
1122         if(binary)
1123         {
1124                 d = n & activator.field;
1125                 if(d != n) // bits added?
1126                         d = +1;
1127                 else if(d != activator.field) // bits removed?
1128                         d = -1;
1129                 else
1130                         d = 0;
1131         }
1132         else
1133                 d = n - activator.field;
1134
1135         if(d < 0)
1136         {
1137                 if(sound_decrease != "")
1138                         sound (activator, CHAN_AUTO, sound_decrease, VOL_BASE, ATTN_NORM);
1139                 target_item_changed = 1;
1140         }
1141         else if(d > 0)
1142         {
1143                 if(sound_increase != "")
1144                         sound (activator, CHAN_AUTO, sound_increase, VOL_BASE, ATTN_NORM);
1145                 target_item_changed = 1;
1146         }
1147         activator.field = n;
1148 }
1149
1150 void target_items_use (void)
1151 {
1152         float h0, a0;
1153         if(activator.classname != "player")
1154                 return;
1155         if(activator.deadflag != DEAD_NO)
1156                 return;
1157         EXACTTRIGGER_TOUCH;
1158
1159         entity e;
1160         for(e = world; (e = find(e, classname, "droppedweapon")); )
1161                 if(e.enemy == activator)
1162                         remove(e);
1163
1164         float _switchweapon;
1165         _switchweapon = FALSE;
1166         if (activator.autoswitch)
1167                 if (activator.switchweapon == w_getbestweapon(activator))
1168                         _switchweapon = TRUE;
1169
1170         a0 = activator.armorvalue;
1171         h0 = activator.health;
1172         target_item_changed = 0;
1173
1174         if(self.spawnflags == 0) // SET
1175         {
1176                 target_item_change(0, ammo_shells, target_item_func_set, "misc/itempickup.wav", "");
1177                 target_item_change(0, ammo_nails, target_item_func_set, "misc/itempickup.wav", "");
1178                 target_item_change(0, ammo_rockets, target_item_func_set, "misc/itempickup.wav", "");
1179                 target_item_change(0, ammo_cells, target_item_func_set, "misc/itempickup.wav", "");
1180                 target_item_change(0, ammo_fuel, target_item_func_set, "misc/itempickup.wav", "");
1181                 target_item_change(0, health, target_item_func_set, "misc/megahealth.wav", "");
1182                 target_item_change(0, armorvalue, target_item_func_set, "misc/armor25.wav", "");
1183                 target_item_change(1, items, target_item_func_itembitset, "misc/powerup.wav", "");
1184                 target_item_change(1, weapons, target_item_func_bitset, "weapons/weaponpickup.wav", "");
1185
1186                 if((self.items & activator.items) & IT_STRENGTH)
1187                         activator.strength_finished = time + self.strength_finished;
1188                 if((self.items & activator.items) & IT_INVINCIBLE)
1189                         activator.invincible_finished = time + self.invincible_finished;
1190         }
1191         else if(self.spawnflags == 1) // AND/MIN
1192         {
1193                 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1194                 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1195                 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1196                 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1197                 target_item_change(0, ammo_fuel, target_item_func_min, "misc/itempickup.wav", "");
1198                 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1199                 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1200                 target_item_change(1, items, target_item_func_itemand, "misc/powerup.wav", "");
1201                 target_item_change(1, weapons, target_item_func_and, "weapons/weaponpickup.wav", "");
1202
1203                 if((self.items & activator.items) & IT_STRENGTH)
1204                         activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1205                 if((self.items & activator.items) & IT_INVINCIBLE)
1206                         activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1207         }
1208         else if(self.spawnflags == 2) // OR/MAX
1209         {
1210                 target_item_change(0, ammo_shells, target_item_func_max, "misc/itempickup.wav", "");
1211                 target_item_change(0, ammo_nails, target_item_func_max, "misc/itempickup.wav", "");
1212                 target_item_change(0, ammo_rockets, target_item_func_max, "misc/itempickup.wav", "");
1213                 target_item_change(0, ammo_cells, target_item_func_max, "misc/itempickup.wav", "");
1214                 target_item_change(0, ammo_fuel, target_item_func_max, "misc/itempickup.wav", "");
1215                 target_item_change(0, health, target_item_func_max, "misc/megahealth.wav", "");
1216                 target_item_change(0, armorvalue, target_item_func_max, "misc/armor25.wav", "");
1217                 target_item_change(1, items, target_item_func_or, "misc/powerup.wav", "");
1218                 target_item_change(1, weapons, target_item_func_or, "weapons/weaponpickup.wav", "");
1219
1220                 if((self.items & activator.items) & IT_STRENGTH)
1221                         activator.strength_finished = max(activator.strength_finished, time + self.strength_finished);
1222                 if((self.items & activator.items) & IT_INVINCIBLE)
1223                         activator.invincible_finished = max(activator.invincible_finished, time + self.invincible_finished);
1224         }
1225         else if(self.spawnflags == 4) // ANDNOT/MIN
1226         {
1227                 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1228                 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1229                 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1230                 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1231                 target_item_change(0, ammo_fuel, target_item_func_min, "misc/itempickup.wav", "");
1232                 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1233                 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1234                 target_item_change(1, items, target_item_func_andnot, "misc/powerup.wav", "");
1235                 target_item_change(1, weapons, target_item_func_andnot, "weapons/weaponpickup.wav", "");
1236
1237                 if((self.items & activator.items) & IT_STRENGTH)
1238                         activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1239                 if((self.items & activator.items) & IT_INVINCIBLE)
1240                         activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1241         }
1242
1243         if not(activator.items & IT_STRENGTH)
1244                 activator.strength_finished = 0;
1245         if not(activator.items & IT_INVINCIBLE)
1246                 activator.invincible_finished = 0;
1247
1248         if(activator.health > h0)
1249                 activator.pauserothealth_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1250         else if(activator.health < h0)
1251                 activator.pauseregen_finished = max(activator.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
1252
1253         if(activator.armorvalue > a0)
1254                 activator.pauserotarmor_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1255
1256         if not(activator.weapons & W_WeaponBit(activator.switchweapon))
1257                 _switchweapon = TRUE;
1258         if(_switchweapon)
1259                 W_SwitchWeapon_Force(activator, w_getbestweapon(activator));
1260
1261         if(target_item_changed)
1262                 centerprint(activator, self.message);
1263 }
1264
1265 void spawnfunc_target_items (void)
1266 {
1267         float n, i, j;
1268         entity e;
1269         self.use = target_items_use;
1270         if(!self.strength_finished)
1271                 self.strength_finished = cvar("g_balance_powerup_strength_time");
1272         if(!self.invincible_finished)
1273                 self.invincible_finished = cvar("g_balance_powerup_invincible_time");
1274
1275         precache_sound("misc/itempickup.wav");
1276         precache_sound("misc/itempickup.wav");
1277         precache_sound("misc/itempickup.wav");
1278         precache_sound("misc/itempickup.wav");
1279         precache_sound("misc/megahealth.wav");
1280         precache_sound("misc/armor25.wav");
1281         precache_sound("misc/powerup.wav");
1282         precache_sound("weapons/weaponpickup.wav");
1283
1284         n = tokenize_sane(self.netname);
1285         for(i = 0; i < n; ++i)
1286         {
1287                 if(argv(i) == "unlimited_ammo")         self.items |= IT_UNLIMITED_AMMO;
1288                 if(argv(i) == "unlimited_weapon_ammo")  self.items |= IT_UNLIMITED_WEAPON_AMMO;
1289                 if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1290                 if(argv(i) == "strength")               self.items |= IT_STRENGTH;
1291                 if(argv(i) == "invincible")             self.items |= IT_INVINCIBLE;
1292                 if(argv(i) == "jetpack")                self.items |= IT_JETPACK;
1293                 if(argv(i) == "fuel_regen")             self.items |= IT_FUEL_REGEN;
1294                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1295                 {
1296                         e = get_weaponinfo(j);
1297                         if(argv(i) == e.netname)
1298                         {
1299                                 self.weapons |= e.weapons;
1300                                 if(self.spawnflags == 0 || self.spawnflags == 2)
1301                                         weapon_action(e.weapon, WR_PRECACHE);
1302                         }
1303                 }
1304         }
1305 }
1306
1307 void spawnfunc_item_fuel(void)
1308 {
1309         if(!self.ammo_fuel)
1310                 self.ammo_fuel = g_pickup_fuel;
1311         StartItem ("models/items/g_fuel.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "Fuel", IT_FUEL, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1312 }
1313
1314 void spawnfunc_item_fuel_regen(void)
1315 {
1316         StartItem ("models/items/g_fuelregen.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, "Fuel regenerator", IT_FUEL_REGEN, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1317 }
1318
1319 void spawnfunc_item_jetpack(void)
1320 {
1321         if(!self.ammo_fuel)
1322                 self.ammo_fuel = g_pickup_fuel_jetpack;
1323         StartItem ("models/items/g_jetpack.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, "Jet pack", IT_JETPACK, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1324 }