]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/t_items.qc
Show countdown waypoints for mega health and large armor when player is spectating
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / t_items.qc
1 #define ITEM_RESPAWN_TICKS 10
2
3 #define ITEM_RESPAWNTIME(i)         ((i).respawntime + crandom() * (i).respawntimejitter)
4         // range: respawntime - respawntimejitter .. respawntime + respawntimejitter
5 #define ITEM_RESPAWNTIME_INITIAL(i) (ITEM_RESPAWN_TICKS + random() * ((i).respawntime + (i).respawntimejitter - ITEM_RESPAWN_TICKS))
6         // range: 10 .. respawntime + respawntimejitter
7
8 floatfield Item_CounterField(float it)
9 {
10         switch(it)
11         {
12                 case IT_SHELLS:      return ammo_shells;
13                 case IT_NAILS:       return ammo_nails;
14                 case IT_ROCKETS:     return ammo_rockets;
15                 case IT_CELLS:       return ammo_cells;
16                 case IT_FUEL:        return ammo_fuel;
17                 case IT_5HP:         return health;
18                 case IT_25HP:        return health;
19                 case IT_HEALTH:      return health;
20                 case IT_ARMOR_SHARD: return armorvalue;
21                 case IT_ARMOR:       return armorvalue;
22                 // add more things here (health, armor)
23                 default:             error("requested item has no counter field");
24         }
25 }
26
27 string Item_CounterFieldName(float it)
28 {
29         switch(it)
30         {
31                 case IT_SHELLS:      return "shells";
32                 case IT_NAILS:       return "nails";
33                 case IT_ROCKETS:     return "rockets";
34                 case IT_CELLS:       return "cells";
35                 case IT_FUEL:        return "fuel";
36
37                 // add more things here (health, armor)
38                 default:             error("requested item has no counter field name");
39         }
40 }
41
42 .float max_armorvalue;
43 .float pickup_anyway;
44
45 float Item_Customize()
46 {
47         if(self.spawnshieldtime)
48                 return TRUE;
49         if(self.weapons != (self.weapons & other.weapons))
50         {
51                 self.colormod = '0 0 0';
52                 self.glowmod = self.colormod;
53                 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
54                 return TRUE;
55         }
56         else
57         {
58                 if(g_ghost_items)
59                 {
60                         self.colormod = stov(autocvar_g_ghost_items_color);
61                         self.glowmod = self.colormod;
62                         self.alpha = g_ghost_items;
63                         return TRUE;
64                 }
65                 else
66                         return FALSE;
67         }
68 }
69
70 void Item_Show (entity e, float mode)
71 {
72         e.effects &~= EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST;
73         if (mode > 0)
74         {
75                 // make the item look normal, and be touchable
76                 e.model = e.mdl;
77                 e.solid = SOLID_TRIGGER;
78                 e.colormod = '0 0 0';
79                 self.glowmod = self.colormod;
80                 e.alpha = 0;
81                 e.customizeentityforclient = func_null;
82
83                 e.spawnshieldtime = 1;
84         }
85         else if (mode < 0)
86         {
87                 // hide the item completely
88                 e.model = string_null;
89                 e.solid = SOLID_NOT;
90                 e.colormod = '0 0 0';
91                 self.glowmod = self.colormod;
92                 e.alpha = 0;
93                 e.customizeentityforclient = func_null;
94
95                 e.spawnshieldtime = 1;
96         }
97         else if((e.flags & FL_WEAPON) && (g_weapon_stay == 3))
98         {
99                 // make the item translucent and not touchable
100                 e.model = e.mdl;
101                 e.solid = SOLID_TRIGGER; // can STILL be picked up!
102                 e.colormod = '0 0 0';
103                 self.glowmod = self.colormod;
104                 e.effects |= EF_STARDUST;
105                 e.customizeentityforclient = Item_Customize;
106
107                 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
108         }
109         else if(g_ghost_items)
110         {
111                 // make the item translucent and not touchable
112                 e.model = e.mdl;
113                 e.solid = SOLID_NOT;
114                 e.colormod = stov(autocvar_g_ghost_items_color);
115                 e.glowmod = e.colormod;
116                 e.alpha = g_ghost_items;
117                 e.customizeentityforclient = func_null;
118
119                 e.spawnshieldtime = 1;
120         }
121         else
122         {
123                 // hide the item completely
124                 e.model = string_null;
125                 e.solid = SOLID_NOT;
126                 e.colormod = '0 0 0';
127                 e.glowmod = e.colormod;
128                 e.alpha = 0;
129                 e.customizeentityforclient = func_null;
130
131                 e.spawnshieldtime = 1;
132         }
133
134         if (e.strength_finished || e.invincible_finished)
135                 e.effects |= EF_ADDITIVE | EF_FULLBRIGHT;
136         if (autocvar_g_nodepthtestitems)
137                 e.effects |= EF_NODEPTHTEST;
138         if (autocvar_g_fullbrightitems)
139                 e.effects |= EF_FULLBRIGHT;
140
141         // relink entity (because solid may have changed)
142         setorigin(e, e.origin);
143 }
144
145 float it_armor_large_time;
146 float it_health_mega_time;
147 float it_strength_time;
148 float it_invisible_time;
149 float it_extralife_time;
150 float it_speed_time;
151 float it_shield_time;
152 float it_fuelregen_time;
153 float it_jetpack_time;
154
155 void Item_ClearItemsTime()
156 {
157         self.item_armor_large_time = 0;
158         self.item_health_mega_time = 0;
159         self.item_strength_time = 0;
160         self.item_invisible_time = 0;
161         self.item_extralife_time = 0;
162         self.item_speed_time = 0;
163         self.item_shield_time = 0;
164         self.item_fuelregen_time = 0;
165         self.item_jetpack_time = 0;
166 }
167 void Item_GetItemsTime(entity e)
168 {
169         e.item_armor_large_time = it_armor_large_time;
170         e.item_health_mega_time = it_health_mega_time;
171         e.item_strength_time = it_strength_time;
172         e.item_invisible_time = it_invisible_time;
173         e.item_extralife_time = it_extralife_time;
174         e.item_speed_time = it_speed_time;
175         e.item_shield_time = it_shield_time;
176         e.item_fuelregen_time = it_fuelregen_time;
177         e.item_jetpack_time = it_jetpack_time;
178 }
179 void Item_UpdateTime(entity e, float t)
180 {
181         if(g_minstagib)
182         {
183                 switch(e.items)
184                 {
185                         case IT_STRENGTH://"item-invis"
186                                 if (it_invisible_time > time && t > it_invisible_time)
187                                         return;
188                                 it_invisible_time = t;
189                                 return;
190                         case IT_NAILS://"item-extralife"
191                                 if (it_extralife_time > time && t > it_extralife_time)
192                                         return;
193                                 it_extralife_time = t;
194                                 return;
195                         case IT_INVINCIBLE://"item-speed"
196                                 if (it_speed_time > time && t > it_speed_time)
197                                         return;
198                                 it_speed_time = t;
199                                 return;
200                 }
201         }
202         else
203         {
204                 switch(e.items)
205                 {
206                         case IT_HEALTH:
207                                 if (e.classname == "item_health_mega")
208                                 {
209                                         if (it_health_mega_time > time && t > it_health_mega_time)
210                                                 return;
211                                         it_health_mega_time = t;
212                                 }
213                                 return;
214                         case IT_ARMOR:
215                                 if (e.classname == "item_armor_large")
216                                 {
217                                         if (it_armor_large_time > time && t > it_armor_large_time)
218                                                 return;
219                                         it_armor_large_time = t;
220                                 }
221                                 return;
222                         case IT_STRENGTH://"item-strength"
223                                 if (it_strength_time > time && t > it_strength_time)
224                                         return;
225                                 it_strength_time = t;
226                                 return;
227                         case IT_INVINCIBLE://"item-shield"
228                                 if (it_shield_time > time && t > it_shield_time)
229                                         return;
230                                 it_shield_time = t;
231                                 return;
232                 }
233         }
234         switch(e.items)
235         {
236                 case IT_FUEL_REGEN://"item-fuelregen"
237                         if (it_fuelregen_time > time && t > it_fuelregen_time)
238                                 return;
239                         it_fuelregen_time = t;
240                         return;
241                 case IT_JETPACK://"item-jetpack"
242                         if (it_jetpack_time > time && t > it_jetpack_time)
243                                 return;
244                         it_jetpack_time = t;
245                         return;
246         }
247 }
248
249 void Item_Respawn (void)
250 {
251         float t;
252         entity head;
253         Item_Show(self, 1);
254         if(!g_minstagib && self.items == IT_STRENGTH)
255                 sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTN_NORM);     // play respawn sound
256         else if(!g_minstagib && self.items == IT_INVINCIBLE)
257                 sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTN_NORM);       // play respawn sound
258         else
259                 sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM);  // play respawn sound
260         setorigin (self, self.origin);
261
262         if (self.flags & FL_POWERUP || self.classname == "item_armor_large" || self.classname == "item_health_mega")
263         {
264                 for(t = 0, head = world; (head = find(head, classname, self.classname)); )
265                 {
266                         // in minstagib .classname is "minstagib" for every item
267                         if (g_minstagib && self.items != head.items)
268                                 continue;
269                         if (head.scheduledrespawntime > time)
270                                 if (t == 0 || head.scheduledrespawntime < t)
271                                         t = head.scheduledrespawntime;
272                 }
273                 Item_UpdateTime(self, t);
274                 FOR_EACH_REALCLIENT(head)
275                 {
276                         if (head.classname != "player")
277                                 Item_GetItemsTime(head);
278                 }
279         }
280
281         //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
282         pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
283 }
284
285 void Item_RespawnCountdown (void)
286 {
287         if(self.count >= ITEM_RESPAWN_TICKS)
288         {
289                 if(self.waypointsprite_attached)
290                         WaypointSprite_Kill(self.waypointsprite_attached);
291                 Item_Respawn();
292         }
293         else
294         {
295                 self.nextthink = time + 1;
296                 self.count += 1;
297                 if(self.count == 1)
298                 {
299                         string name;
300                         vector rgb;
301                         name = string_null;
302                         if(g_minstagib)
303                         {
304                                 switch(self.items)
305                                 {
306                                         case IT_STRENGTH:   name = "item-invis"; rgb = '0 0 1'; break;
307                                         case IT_NAILS:      name = "item-extralife"; rgb = '1 0 0'; break;
308                                         case IT_INVINCIBLE: name = "item-speed"; rgb = '1 0 1'; break;
309                                 }
310                         }
311                         else
312                         {
313                                 switch(self.items)
314                                 {
315                                         case IT_STRENGTH:   name = "item-strength"; rgb = '0 0 1'; break;
316                                         case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
317                                         case IT_HEALTH:
318                                                 if (self.classname == "item_health_mega")
319                                                         {name = "item_health_mega"; rgb = '1 0 0';}
320                                                 break;
321                                         case IT_ARMOR:
322                                                 if (self.classname == "item_armor_large")
323                                                         {name = "item_armor_large"; rgb = '0 1 0';}
324                                                 break;
325                                 }
326                         }
327                         switch(self.items)
328                         {
329                                 case IT_FUEL_REGEN:     name = "item-fuelregen"; rgb = '1 0.5 0'; break;
330                                 case IT_JETPACK:        name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
331                         }
332                         if(name)
333                         {
334                                 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
335                                 if(self.waypointsprite_attached)
336                                 {
337                                         if (self.items == IT_HEALTH || self.items == IT_ARMOR)
338                                                 WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
339                                         WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
340                                 }
341                         }
342                 }
343                 sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTN_NORM); // play respawn sound
344                 if(self.waypointsprite_attached)
345                 {
346                         WaypointSprite_Ping(self.waypointsprite_attached);
347                         //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
348                 }
349         }
350 }
351
352 void Item_ScheduleRespawnIn(entity e, float t)
353 {
354         if(e.flags & FL_POWERUP || self.classname == "item_armor_large" || self.classname == "item_health_mega")
355         {
356                 e.think = Item_RespawnCountdown;
357                 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
358                 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
359                 e.count = 0;
360         }
361         else
362         {
363                 e.think = Item_Respawn;
364                 e.nextthink = time + t;
365                 e.scheduledrespawntime = e.nextthink;
366         }
367         Item_UpdateTime(e, e.scheduledrespawntime);
368         FOR_EACH_REALCLIENT(e)
369         {
370                 if (e.classname != "player")
371                         Item_GetItemsTime(e);
372         }
373 }
374
375 void Item_ScheduleRespawn(entity e)
376 {
377         if(e.respawntime > 0)
378         {
379                 Item_Show(e, 0);
380                 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
381         }
382         else // if respawntime is -1, this item does not respawn
383                 Item_Show(e, -1);
384 }
385
386 void Item_ScheduleInitialRespawn(entity e)
387 {
388         Item_Show(e, 0);
389         Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
390 }
391
392 float Item_GiveTo(entity item, entity player)
393 {
394         float _switchweapon;
395         float pickedup;
396         float it;
397         float i;
398         entity e;
399
400         // if nothing happens to player, just return without taking the item
401         pickedup = FALSE;
402         _switchweapon = FALSE;
403
404         if (g_minstagib)
405         {
406                 if(item.spawnshieldtime)
407                 {
408                         if (item.ammo_fuel)
409                         if (player.ammo_fuel < g_pickup_fuel_max)
410                         {
411                                 pickedup = TRUE;
412                                 player.ammo_fuel = bound(player.ammo_fuel, g_pickup_fuel_max, player.ammo_fuel + item.ammo_fuel);
413                                 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
414                         }
415                         if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
416                         {
417                                 pickedup = TRUE;
418                                 player.items |= it;
419                                 sprint (player, strcat("You got the ^2", item.netname, "\n"));
420                         }
421
422                         _switchweapon = TRUE;
423                         if (item.ammo_cells)
424                         {
425                                 pickedup = TRUE;
426                                 // play some cool sounds ;)
427                                 if (clienttype(player) == CLIENTTYPE_REAL)
428                                 {
429                                         if(player.health <= 5)
430                                                 AnnounceTo(player, "lastsecond");
431                                         else if(player.health < 50)
432                                                 AnnounceTo(player, "narrowly");
433                                 }
434                                 // sound not available
435                                 // else if(item.items == IT_CELLS)
436                                 //      AnnounceTo(player, "ammo");
437
438                                 if (item.weapons & WEPBIT_MINSTANEX)
439                                         W_GiveWeapon (player, WEP_MINSTANEX, item.netname);
440                                 if (item.ammo_cells)
441                                         player.ammo_cells = bound(player.ammo_cells, 999, player.ammo_cells + autocvar_g_minstagib_ammo_drop);
442                                 player.health = 100;
443                         }
444
445                         // extralife powerup
446                         if (item.max_health)
447                         {
448                                 pickedup = TRUE;
449                                 // sound not available
450                                 // AnnounceTo(player, "_lives");
451                                 player.armorvalue = bound(player.armorvalue, 999, player.armorvalue + autocvar_g_minstagib_extralives);
452                                 sprint(player, "^3You picked up some extra lives\n");
453                         }
454
455                         // invis powerup
456                         if (item.strength_finished)
457                         {
458                                 pickedup = TRUE;
459                                 // sound not available
460                                 // AnnounceTo(player, "invisible");
461                                 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
462                         }
463
464                         // speed powerup
465                         if (item.invincible_finished)
466                         {
467                                 pickedup = TRUE;
468                                 // sound not available
469                                 // AnnounceTo(player, "speed");
470                                 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_strength_time;
471                         }
472                 }
473         }
474         else
475         {
476                 if (g_weapon_stay == 1)
477                 if not(item.flags & FL_NO_WEAPON_STAY)
478                 if (item.flags & FL_WEAPON)
479                 {
480                         if(item.classname == "droppedweapon")
481                         {
482                                 if (player.weapons & item.weapons)      // don't let players stack ammo by tossing weapons
483                                         goto skip;
484                         }
485                         else
486                         {
487                                 if (player.weapons & item.weapons)
488                                         goto skip;
489                         }
490                 }
491
492                 // in case the player has autoswitch enabled do the following:
493                 // if the player is using their best weapon before items are given, they
494                 // probably want to switch to an even better weapon after items are given
495                 if (player.autoswitch)
496                 if (player.switchweapon == w_getbestweapon(player))
497                         _switchweapon = TRUE;
498
499                 if not(player.weapons & W_WeaponBit(player.switchweapon))
500                         _switchweapon = TRUE;
501
502                 if(item.spawnshieldtime)
503                 {
504                         if (item.ammo_shells)
505                         if ((player.ammo_shells < g_pickup_shells_max) || item.pickup_anyway)
506                         {
507                                 pickedup = TRUE;
508                                 player.ammo_shells = bound(player.ammo_shells, g_pickup_shells_max, player.ammo_shells + item.ammo_shells);
509                         }
510                         if (item.ammo_nails)
511                         if ((player.ammo_nails < g_pickup_nails_max) || item.pickup_anyway)
512                         {
513                                 pickedup = TRUE;
514                                 player.ammo_nails = bound(player.ammo_nails, g_pickup_nails_max, player.ammo_nails + item.ammo_nails);
515                         }
516                         if (item.ammo_rockets)
517                         if ((player.ammo_rockets < g_pickup_rockets_max) || item.pickup_anyway)
518                         {
519                                 pickedup = TRUE;
520                                 player.ammo_rockets = bound(player.ammo_rockets, g_pickup_rockets_max, player.ammo_rockets + item.ammo_rockets);
521                         }
522                         if (item.ammo_cells)
523                         if ((player.ammo_cells < g_pickup_cells_max) || item.pickup_anyway)
524                         {
525                                 pickedup = TRUE;
526                                 player.ammo_cells = bound(player.ammo_cells, g_pickup_cells_max, player.ammo_cells + item.ammo_cells);
527                         }
528                         if (item.ammo_fuel)
529                         if ((player.ammo_fuel < g_pickup_fuel_max) || item.pickup_anyway)
530                         {
531                                 pickedup = TRUE;
532                                 player.ammo_fuel = bound(player.ammo_fuel, g_pickup_fuel_max, player.ammo_fuel + item.ammo_fuel);
533                                 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
534                         }
535                 }
536
537                 if (item.flags & FL_WEAPON)
538                         if ((it = item.weapons - (item.weapons & player.weapons)) || (g_pickup_weapons_anyway && g_weapon_stay == 0))
539                 {
540                         pickedup = TRUE;
541                         for(i = WEP_FIRST; i <= WEP_LAST; ++i)
542                         {
543                                 e = get_weaponinfo(i);
544                                 if(it & e.weapons)
545                                         W_GiveWeapon (player, e.weapon, item.netname);
546                         }
547                 }
548
549                 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
550                 {
551                         pickedup = TRUE;
552                         player.items |= it;
553                         sprint (player, strcat("You got the ^2", item.netname, "\n"));
554                 }
555
556                 if(item.spawnshieldtime)
557                 {
558                         if (item.strength_finished)
559                         {
560                                 pickedup = TRUE;
561                                 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
562                         }
563                         if (item.invincible_finished)
564                         {
565                                 pickedup = TRUE;
566                                 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_invincible_time;
567                         }
568
569                         if (item.health)
570                         if ((player.health < item.max_health) || item.pickup_anyway)
571                         {
572                                 pickedup = TRUE;
573                                 player.health = bound(player.health, item.max_health, player.health + item.health);
574                                 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
575                         }
576                         if (item.armorvalue)
577                         if ((player.armorvalue < item.max_armorvalue) || item.pickup_anyway)
578                         {
579                                 pickedup = TRUE;
580                                 player.armorvalue = bound(player.armorvalue, item.max_armorvalue, player.armorvalue + item.armorvalue);
581                                 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
582                         }
583                 }
584         }
585
586 :skip
587         // always eat teamed entities
588         if(item.team)
589                 pickedup = TRUE;
590
591         if (!pickedup)
592                 return 0;
593
594         sound (player, CH_TRIGGER, item.item_pickupsound, VOL_BASE, ATTN_NORM);
595         if (_switchweapon)
596                 if (player.switchweapon != w_getbestweapon(player))
597                         W_SwitchWeapon_Force(player, w_getbestweapon(player));
598
599         return 1;
600 }
601
602 void Item_Touch (void)
603 {
604         entity e, head;
605
606         // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
607         if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
608         {
609                 remove(self);
610                 return;
611         }
612         if (other.classname != "player")
613                 return;
614         if (other.deadflag)
615                 return;
616         if (self.solid != SOLID_TRIGGER)
617                 return;
618         if (self.owner == other)
619                 return;
620
621         if(!Item_GiveTo(self, other))
622                 return;
623
624         other.last_pickup = time;
625
626         pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
627
628         if (self.classname == "droppedweapon")
629                 remove (self);
630         else if not(self.spawnshieldtime)
631                 return;
632         else if((self.flags & FL_WEAPON) && !(self.flags & FL_NO_WEAPON_STAY) && (g_weapon_stay == 1 || g_weapon_stay == 2))
633                 return;
634         else
635         {
636                 if(self.team)
637                 {
638                         RandomSelection_Init();
639                         for(head = world; (head = findfloat(head, team, self.team)); )
640                         {
641                                 if(head.flags & FL_ITEM)
642                                 {
643                                         Item_Show(head, -1);
644                                         RandomSelection_Add(head, 0, string_null, head.cnt, 0);
645                                 }
646                         }
647                         e = RandomSelection_chosen_ent;
648                 }
649                 else
650                         e = self;
651                 Item_ScheduleRespawn(e);
652         }
653 }
654
655 void Item_FindTeam()
656 {
657         entity head, e;
658
659         if(self.effects & EF_NODRAW)
660         {
661                 // marker for item team search
662                 dprint("Initializing item team ", ftos(self.team), "\n");
663                 RandomSelection_Init();
664                 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
665                         RandomSelection_Add(head, 0, string_null, head.cnt, 0);
666                 e = RandomSelection_chosen_ent;
667                 e.state = 0;
668                 Item_Show(e, 1);
669
670                 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
671                 {
672                         if(head != e)
673                         {
674                                 // make it a non-spawned item
675                                 Item_Show(head, -1);
676                                 head.state = 1; // state 1 = initially hidden item
677                         }
678                         head.effects &~= EF_NODRAW;
679                 }
680
681                 if(e.flags & FL_POWERUP) // do not spawn powerups initially!
682                         Item_ScheduleInitialRespawn(e);
683         }
684 }
685
686 void Item_Reset()
687 {
688         Item_Show(self, !self.state);
689         setorigin (self, self.origin);
690         self.think = SUB_Null;
691         self.nextthink = 0;
692
693         if(self.flags & FL_POWERUP) // do not spawn powerups initially!
694                 Item_ScheduleInitialRespawn(self);
695 }
696
697 // Savage: used for item garbage-collection
698 // TODO: perhaps nice special effect?
699 void RemoveItem(void)
700 {
701         remove(self);
702 }
703
704 // pickup evaluation functions
705 // these functions decide how desirable an item is to the bots
706
707 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
708
709 float weapon_pickupevalfunc(entity player, entity item)
710 {
711         float c, i, j, position;
712
713         // See if I have it already
714         if(player.weapons & item.weapons == item.weapons)
715         {
716                 // If I can pick it up
717                 if(g_weapon_stay == 1 || g_weapon_stay == 2 || !item.spawnshieldtime)
718                         c = 0;
719                 else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
720                 {
721                         // Skilled bots will grab more
722                         c = bound(0, skill / 10, 1) * 0.5;
723                 }
724                 else
725                         c = 0;
726         }
727         else
728                 c = 1;
729
730         // If custom weapon priorities for bots is enabled rate most wanted weapons higher
731         if( bot_custom_weapon && c )
732         {
733                 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
734                 {
735                         // Find weapon
736                         if( (get_weaponinfo(i)).weapons & item.weapons  != item.weapons )
737                                 continue;
738
739                         // Find the highest position on any range
740                         position = -1;
741                         for(j = 0; j < WEP_LAST ; ++j){
742                                 if(
743                                                 bot_weapons_far[j] == i ||
744                                                 bot_weapons_mid[j] == i ||
745                                                 bot_weapons_close[j] == i
746                                   )
747                                 {
748                                         position = j;
749                                         break;
750                                 }
751                         }
752
753                         // Rate it
754                         if (position >= 0 )
755                         {
756                                 position = WEP_LAST - position;
757                                 // item.bot_pickupbasevalue is overwritten here
758                                 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
759                         }
760                 }
761         }
762
763         return item.bot_pickupbasevalue * c;
764 }
765
766 float commodity_pickupevalfunc(entity player, entity item)
767 {
768         float c, i, need_shells, need_nails, need_rockets, need_cells;
769         entity wi;
770         c = 0;
771
772         // Detect needed ammo
773         for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
774         {
775                 wi = get_weaponinfo(i);
776
777                 if not(wi.weapons & player.weapons)
778                         continue;
779
780                 if(wi.items & IT_SHELLS)
781                         need_shells = TRUE;
782                 else if(wi.items & IT_NAILS)
783                         need_nails = TRUE;
784                 else if(wi.items & IT_ROCKETS)
785                         need_rockets = TRUE;
786                 else if(wi.items & IT_CELLS)
787                         need_cells = TRUE;
788         }
789
790         // TODO: figure out if the player even has the weapon this ammo is for?
791         // may not affect strategy much though...
792         // find out how much more ammo/armor/health the player can hold
793         if (need_shells)
794         if (item.ammo_shells)
795         if (player.ammo_shells < g_pickup_shells_max)
796                 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
797         if (need_nails)
798         if (item.ammo_nails)
799         if (player.ammo_nails < g_pickup_nails_max)
800                 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
801         if (need_rockets)
802         if (item.ammo_rockets)
803         if (player.ammo_rockets < g_pickup_rockets_max)
804                 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
805         if (need_cells)
806         if (item.ammo_cells)
807         if (player.ammo_cells < g_pickup_cells_max)
808                 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
809         if (item.armorvalue)
810         if (player.armorvalue < item.max_armorvalue)
811                 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
812         if (item.health)
813         if (player.health < item.max_health)
814                 c = c + max(0, 1 - player.health / item.max_health);
815
816         return item.bot_pickupbasevalue * c;
817 }
818
819
820 .float is_item;
821 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, float defaultrespawntimejitter, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
822 {
823         startitem_failed = FALSE;
824
825         self.items = itemid;
826         self.weapons = weaponid;
827
828         // is it a dropped weapon?
829         if (self.classname == "droppedweapon")
830         {
831                 self.reset = SUB_Remove;
832                 // it's a dropped weapon
833                 self.movetype = MOVETYPE_TOSS;
834                 // Savage: remove thrown items after a certain period of time ("garbage collection")
835                 self.think = RemoveItem;
836                 self.nextthink = time + 60;
837                 // don't drop if in a NODROP zone (such as lava)
838                 traceline(self.origin, self.origin, MOVE_NORMAL, self);
839                 if (trace_dpstartcontents & DPCONTENTS_NODROP)
840                 {
841                         startitem_failed = TRUE;
842                         remove(self);
843                         return;
844                 }
845         }
846         else
847         {
848                 if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
849                 {
850                         startitem_failed = TRUE;
851                         remove(self);
852                         return;
853                 }
854
855                 self.reset = Item_Reset;
856                 // it's a level item
857                 if(self.spawnflags & 1)
858                         self.noalign = 1;
859                 if (self.noalign)
860                         self.movetype = MOVETYPE_NONE;
861                 else
862                         self.movetype = MOVETYPE_TOSS;
863                 // do item filtering according to game mode and other things
864                 if (!self.noalign)
865                 {
866                         // first nudge it off the floor a little bit to avoid math errors
867                         setorigin(self, self.origin + '0 0 1');
868                         // set item size before we spawn a spawnfunc_waypoint
869                         if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
870                                 setsize (self, '-16 -16 0', '16 16 48');
871                         else
872                                 setsize (self, '-16 -16 0', '16 16 32');
873                         // note droptofloor returns FALSE if stuck/or would fall too far
874                         droptofloor();
875                         waypoint_spawnforitem(self);
876                 }
877
878                 /*
879                  * can't do it that way, as it would break maps
880                  * TODO make a target_give like entity another way, that perhaps has
881                  * the weapon name in a key
882                 if(self.targetname)
883                 {
884                         // target_give not yet supported; maybe later
885                         print("removed targeted ", self.classname, "\n");
886                         startitem_failed = TRUE;
887                         remove (self);
888                         return;
889                 }
890                 */
891
892                 if(autocvar_spawn_debug >= 2)
893                 {
894                         entity otheritem;
895                         for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
896                         {
897                                 if(otheritem.is_item)
898                                 {
899                                         dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
900                                         dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
901                                         error("Mapper sucks.");
902                                 }
903                         }
904                         self.is_item = TRUE;
905                 }
906
907                 if(g_lms || g_ca)
908                 {
909                         startitem_failed = TRUE;
910                         remove(self);
911                         return;
912                 }
913                 else if (g_weaponarena && ((weaponid & WEPBIT_ALL) || (itemid & IT_AMMO)))
914                 {
915                         startitem_failed = TRUE;
916                         remove(self);
917                         return;
918                 }
919                 else if (g_minstagib)
920                 {
921                         // don't remove dropped items and powerups
922                         if (self.classname != "minstagib")
923                         {
924                                 startitem_failed = TRUE;
925                                 remove (self);
926                                 return;
927                         }
928                 }
929                 else if (!autocvar_g_pickup_items && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
930                 {
931                         startitem_failed = TRUE;
932                         remove (self);
933                         return;
934                 }
935
936                 weaponsInMap |= weaponid;
937
938                 precache_model (itemmodel);
939                 precache_sound (pickupsound);
940
941                 precache_sound ("misc/itemrespawncountdown.wav");
942                 if(!g_minstagib && itemid == IT_STRENGTH)
943                         precache_sound ("misc/strength_respawn.wav");
944                 else if(!g_minstagib && itemid == IT_INVINCIBLE)
945                         precache_sound ("misc/shield_respawn.wav");
946                 else
947                         precache_sound ("misc/itemrespawn.wav");
948
949                 if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
950                         self.target = "###item###"; // for finding the nearest item using find()
951         }
952
953         self.bot_pickup = TRUE;
954         self.bot_pickupevalfunc = pickupevalfunc;
955         self.bot_pickupbasevalue = pickupbasevalue;
956         self.mdl = itemmodel;
957         self.item_pickupsound = pickupsound;
958         // let mappers override respawntime
959         if(!self.respawntime) // both set
960         {
961                 self.respawntime = defaultrespawntime;
962                 self.respawntimejitter = defaultrespawntimejitter;
963         }
964         self.netname = itemname;
965         self.flags = FL_ITEM | itemflags;
966         self.touch = Item_Touch;
967         setmodel (self, self.mdl); // precision set below
968         self.effects |= EF_LOWPRECISION;
969         if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
970                 setsize (self, '-16 -16 0', '16 16 48');
971         else
972                 setsize (self, '-16 -16 0', '16 16 32');
973         if(itemflags & FL_WEAPON)
974                 self.modelflags |= MF_ROTATE;
975
976         if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
977         if (itemflags & FL_WEAPON)
978         {
979                 // neutral team color for pickup weapons
980                 self.colormap = 1024; // color shirt=0 pants=0 grey
981         }
982
983         Item_Show(self, 1);
984         self.state = 0;
985         if(self.team)
986         {
987                 if(!self.cnt)
988                         self.cnt = 1; // item probability weight
989                 self.effects = self.effects | EF_NODRAW; // marker for item team search
990                 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
991         }
992         else if(self.flags & FL_POWERUP) // do not spawn powerups initially!
993                 Item_ScheduleInitialRespawn(self);
994 }
995
996 /* replace items in minstagib
997  * IT_STRENGTH   = invisibility
998  * IT_NAILS      = extra lives
999  * IT_INVINCIBLE = speed
1000  */
1001 void minstagib_items (float itemid)
1002 {
1003         float rnd;
1004         self.classname = "minstagib";
1005
1006         // replace rocket launchers and nex guns with ammo cells
1007         if (itemid == IT_CELLS)
1008         {
1009                 self.ammo_cells = 1;
1010                 StartItem ("models/items/a_cells.md3",
1011                         "misc/itempickup.wav", 45, 0,
1012                         "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
1013                 return;
1014         }
1015
1016         // randomize
1017         rnd = random() * 3;
1018         if (rnd <= 1)
1019                 itemid = IT_STRENGTH;
1020         else if (rnd <= 2)
1021                 itemid = IT_NAILS;
1022         else
1023                 itemid = IT_INVINCIBLE;
1024
1025         // replace with invis
1026         if (itemid == IT_STRENGTH)
1027         {
1028                 self.strength_finished = 30;
1029                 StartItem ("models/items/g_strength.md3",
1030                         "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1031                         "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1032         }
1033         // replace with extra lives
1034         if (itemid == IT_NAILS)
1035         {
1036                 self.max_health = 1;
1037                 StartItem ("models/items/g_h100.md3",
1038                         "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1039                         "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1040         }
1041         // replace with speed
1042         if (itemid == IT_INVINCIBLE)
1043         {
1044                 self.invincible_finished = 30;
1045                 StartItem ("models/items/g_invincible.md3",
1046                         "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1047                         "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1048         }
1049 }
1050
1051 float minst_no_auto_cells;
1052 void minst_remove_item (void) {
1053         if(minst_no_auto_cells)
1054                 remove(self);
1055 }
1056
1057 float weaponswapping;
1058 float internalteam;
1059
1060 void weapon_defaultspawnfunc(float wpn)
1061 {
1062         entity e;
1063         float t;
1064         var .float ammofield;
1065         string s;
1066         entity oldself;
1067         float i, j;
1068
1069         // set the respawntime in advance (so replaced weapons can copy it)
1070
1071         if(!self.respawntime)
1072         {
1073                 e = get_weaponinfo(wpn);
1074                 if(e.items == IT_SUPERWEAPON)
1075                 {
1076                         self.respawntime = g_pickup_respawntime_powerup;
1077                         self.respawntimejitter = g_pickup_respawntimejitter_powerup;
1078                 }
1079                 else
1080                 {
1081                         self.respawntime = g_pickup_respawntime_weapon;
1082                         self.respawntimejitter = g_pickup_respawntimejitter_weapon;
1083                 }
1084         }
1085
1086         if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
1087         {
1088                 e = get_weaponinfo(wpn);
1089                 s = cvar_string(strcat("g_weaponreplace_", e.netname));
1090                 if(s == "0")
1091                 {
1092                         remove(self);
1093                         startitem_failed = TRUE;
1094                         return;
1095                 }
1096                 t = tokenize_console(s);
1097                 if(t >= 2)
1098                 {
1099                         self.team = --internalteam;
1100                         oldself = self;
1101                         for(i = 1; i < t; ++i)
1102                         {
1103                                 s = argv(i);
1104                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1105                                 {
1106                                         e = get_weaponinfo(j);
1107                                         if(e.netname == s)
1108                                         {
1109                                                 self = spawn();
1110                                                 copyentity(oldself, self);
1111                                                 self.classname = "replacedweapon";
1112                                                 weapon_defaultspawnfunc(j);
1113                                                 break;
1114                                         }
1115                                 }
1116                                 if(j > WEP_LAST)
1117                                 {
1118                                         print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1119                                 }
1120                         }
1121                         self = oldself;
1122                 }
1123                 if(t >= 1)
1124                 {
1125                         s = argv(0);
1126                         wpn = 0;
1127                         for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1128                         {
1129                                 e = get_weaponinfo(j);
1130                                 if(e.netname == s)
1131                                 {
1132                                         wpn = j;
1133                                         break;
1134                                 }
1135                         }
1136                         if(j > WEP_LAST)
1137                         {
1138                                 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1139                         }
1140                 }
1141                 if(wpn == 0)
1142                 {
1143                         remove(self);
1144                         startitem_failed = TRUE;
1145                         return;
1146                 }
1147         }
1148
1149         e = get_weaponinfo(wpn);
1150
1151         if(e.items && e.items != IT_SUPERWEAPON)
1152         {
1153                 for(i = 0, j = 1; i < 24; ++i, j *= 2)
1154                 {
1155                         if(e.items & j)
1156                         {
1157                                 ammofield = Item_CounterField(j);
1158                                 if(!self.ammofield)
1159                                         self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
1160                         }
1161                 }
1162         }
1163         else
1164         {
1165                 self.flags |= FL_NO_WEAPON_STAY;
1166         }
1167
1168         // weapon stay isn't supported for teamed weapons
1169         if(self.team)
1170                 self.flags |= FL_NO_WEAPON_STAY;
1171
1172         if(g_weapon_stay == 2 && self.classname != "droppedweapon")
1173         {
1174                 self.ammo_shells = 0;
1175                 self.ammo_nails = 0;
1176                 self.ammo_cells = 0;
1177                 self.ammo_rockets = 0;
1178                 // weapon stay 2: don't use ammo on weapon pickups; instead
1179                 // initialize all ammo types to the pickup ammo unless set by g_start_ammo_*
1180         }
1181
1182         StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, e.bot_pickupbasevalue);
1183         if (self.modelindex) // don't precache if self was removed
1184                 weapon_action(e.weapon, WR_PRECACHE);
1185 }
1186
1187 void spawnfunc_weapon_shotgun (void);
1188 void spawnfunc_weapon_uzi (void) {
1189         if(autocvar_sv_q3acompat_machineshotgunswap)
1190         if(self.classname != "droppedweapon")
1191         {
1192                 weapon_defaultspawnfunc(WEP_SHOTGUN);
1193                 return;
1194         }
1195         weapon_defaultspawnfunc(WEP_UZI);
1196 }
1197
1198 void spawnfunc_weapon_shotgun (void) {
1199         if(autocvar_sv_q3acompat_machineshotgunswap)
1200         if(self.classname != "droppedweapon")
1201         {
1202                 weapon_defaultspawnfunc(WEP_UZI);
1203                 return;
1204         }
1205         weapon_defaultspawnfunc(WEP_SHOTGUN);
1206 }
1207
1208 void spawnfunc_weapon_nex (void)
1209 {
1210         if (g_minstagib)
1211         {
1212                 minstagib_items(IT_CELLS);
1213                 self.think = minst_remove_item;
1214                 self.nextthink = time;
1215                 return;
1216         }
1217         weapon_defaultspawnfunc(WEP_NEX);
1218 }
1219
1220 void spawnfunc_weapon_minstanex (void)
1221 {
1222         if (g_minstagib)
1223         {
1224                 minstagib_items(IT_CELLS);
1225                 self.think = minst_remove_item;
1226                 self.nextthink = time;
1227                 return;
1228         }
1229         weapon_defaultspawnfunc(WEP_MINSTANEX);
1230 }
1231
1232 void spawnfunc_weapon_rocketlauncher (void)
1233 {
1234         if (g_minstagib)
1235         {
1236                 minstagib_items(IT_CELLS); // replace rocketlauncher with cells
1237                 self.think = minst_remove_item;
1238                 self.nextthink = time;
1239                 return;
1240         }
1241         weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
1242 }
1243
1244 void spawnfunc_item_rockets (void) {
1245         if(!self.ammo_rockets)
1246                 self.ammo_rockets = g_pickup_rockets;
1247         if(!self.pickup_anyway)
1248                 self.pickup_anyway = g_pickup_ammo_anyway;
1249         StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
1250 }
1251
1252 void spawnfunc_item_shells (void);
1253 void spawnfunc_item_bullets (void) {
1254         if(!weaponswapping)
1255         if(autocvar_sv_q3acompat_machineshotgunswap)
1256         if(self.classname != "droppedweapon")
1257         {
1258                 weaponswapping = TRUE;
1259                 spawnfunc_item_shells();
1260                 weaponswapping = FALSE;
1261                 return;
1262         }
1263
1264         if(!self.ammo_nails)
1265                 self.ammo_nails = g_pickup_nails;
1266         if(!self.pickup_anyway)
1267                 self.pickup_anyway = g_pickup_ammo_anyway;
1268         StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
1269 }
1270
1271 void spawnfunc_item_cells (void) {
1272         if(!self.ammo_cells)
1273                 self.ammo_cells = g_pickup_cells;
1274         if(!self.pickup_anyway)
1275                 self.pickup_anyway = g_pickup_ammo_anyway;
1276         StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
1277 }
1278
1279 void spawnfunc_item_shells (void) {
1280         if(!weaponswapping)
1281         if(autocvar_sv_q3acompat_machineshotgunswap)
1282         if(self.classname != "droppedweapon")
1283         {
1284                 weaponswapping = TRUE;
1285                 spawnfunc_item_bullets();
1286                 weaponswapping = FALSE;
1287                 return;
1288         }
1289
1290         if(!self.ammo_shells)
1291                 self.ammo_shells = g_pickup_shells;
1292         if(!self.pickup_anyway)
1293                 self.pickup_anyway = g_pickup_ammo_anyway;
1294         StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
1295 }
1296
1297 void spawnfunc_item_armor_small (void) {
1298         if(!self.armorvalue)
1299                 self.armorvalue = g_pickup_armorsmall;
1300         if(!self.max_armorvalue)
1301                 self.max_armorvalue = g_pickup_armorsmall_max;
1302         if(!self.pickup_anyway)
1303                 self.pickup_anyway = g_pickup_armorsmall_anyway;
1304         StartItem ("models/items/item_armor_small.md3", "misc/armor1.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1305 }
1306
1307 void spawnfunc_item_armor_medium (void) {
1308         if(!self.armorvalue)
1309                 self.armorvalue = g_pickup_armormedium;
1310         if(!self.max_armorvalue)
1311                 self.max_armorvalue = g_pickup_armormedium_max;
1312         if(!self.pickup_anyway)
1313                 self.pickup_anyway = g_pickup_armormedium_anyway;
1314         StartItem ("models/items/item_armor_medium.md3", "misc/armor10.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1315 }
1316
1317 void spawnfunc_item_armor_big (void) {
1318         if(!self.armorvalue)
1319                 self.armorvalue = g_pickup_armorbig;
1320         if(!self.max_armorvalue)
1321                 self.max_armorvalue = g_pickup_armorbig_max;
1322         if(!self.pickup_anyway)
1323                 self.pickup_anyway = g_pickup_armorbig_anyway;
1324         StartItem ("models/items/item_armor_big.md3", "misc/armor17_5.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "50 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
1325 }
1326
1327 void spawnfunc_item_armor_large (void) {
1328         if(!self.armorvalue)
1329                 self.armorvalue = g_pickup_armorlarge;
1330         if(!self.max_armorvalue)
1331                 self.max_armorvalue = g_pickup_armorlarge_max;
1332         if(!self.pickup_anyway)
1333                 self.pickup_anyway = g_pickup_armorlarge_anyway;
1334         StartItem ("models/items/item_armor_large.md3", "misc/armor25.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1335 }
1336
1337 void spawnfunc_item_health_small (void) {
1338         if(!self.max_health)
1339                 self.max_health = g_pickup_healthsmall_max;
1340         if(!self.health)
1341                 self.health = g_pickup_healthsmall;
1342         if(!self.pickup_anyway)
1343                 self.pickup_anyway = g_pickup_healthsmall_anyway;
1344         StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1345 }
1346
1347 void spawnfunc_item_health_medium (void) {
1348         if(!self.max_health)
1349                 self.max_health = g_pickup_healthmedium_max;
1350         if(!self.health)
1351                 self.health = g_pickup_healthmedium;
1352         if(!self.pickup_anyway)
1353                 self.pickup_anyway = g_pickup_healthmedium_anyway;
1354         StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1355 }
1356
1357 void spawnfunc_item_health_large (void) {
1358         if(!self.max_health)
1359                 self.max_health = g_pickup_healthlarge_max;
1360         if(!self.health)
1361                 self.health = g_pickup_healthlarge;
1362         if(!self.pickup_anyway)
1363                 self.pickup_anyway = g_pickup_healthlarge_anyway;
1364         StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1365 }
1366
1367 void spawnfunc_item_health_mega (void) {
1368         if(!autocvar_g_powerup_superhealth)
1369                 return;
1370
1371         if((g_arena || g_ca) && !autocvar_g_arena_powerups)
1372                 return;
1373
1374         if(g_minstagib) {
1375                 minstagib_items(IT_NAILS);
1376         } else {
1377                 if(!self.max_health)
1378                         self.max_health = g_pickup_healthmega_max;
1379                 if(!self.health)
1380                         self.health = g_pickup_healthmega;
1381                 if(!self.pickup_anyway)
1382                         self.pickup_anyway = g_pickup_healthmega_anyway;
1383                 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1384         }
1385 }
1386
1387 // support old misnamed entities
1388 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); }  // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1389 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1390 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1391 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1392 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1393
1394 void spawnfunc_item_strength (void) {
1395         if(!autocvar_g_powerup_strength)
1396                 return;
1397
1398         if((g_arena || g_ca) && !autocvar_g_arena_powerups)
1399                 return;
1400
1401         if(g_minstagib) {
1402                 minstagib_items(IT_STRENGTH);
1403         } else {
1404                 precache_sound("weapons/strength_fire.wav");
1405                 self.strength_finished = 30;
1406                 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
1407         }
1408 }
1409
1410 void spawnfunc_item_invincible (void) {
1411         if(!autocvar_g_powerup_shield)
1412                 return;
1413
1414         if((g_arena || g_ca) && !autocvar_g_arena_powerups)
1415                 return;
1416
1417         if(g_minstagib) {
1418                 minstagib_items(IT_INVINCIBLE);
1419         } else {
1420                 self.invincible_finished = 30;
1421                 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Shield", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
1422         }
1423 }
1424
1425 void spawnfunc_item_minst_cells (void) {
1426         if (g_minstagib)
1427         {
1428                 minst_no_auto_cells = 1;
1429                 minstagib_items(IT_CELLS);
1430         }
1431         else
1432                 remove(self);
1433 }
1434
1435 // compatibility:
1436 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1437
1438 float GiveItems(entity e, float beginarg, float endarg);
1439 void target_items_use (void)
1440 {
1441         if(activator.classname == "droppedweapon")
1442         {
1443                 EXACTTRIGGER_TOUCH;
1444                 remove(activator);
1445                 return;
1446         }
1447
1448         if(activator.classname != "player")
1449                 return;
1450         if(activator.deadflag != DEAD_NO)
1451                 return;
1452         EXACTTRIGGER_TOUCH;
1453
1454         entity e;
1455         for(e = world; (e = find(e, classname, "droppedweapon")); )
1456                 if(e.enemy == activator)
1457                         remove(e);
1458
1459         if(GiveItems(activator, 0, tokenize_console(self.netname)))
1460                 centerprint(activator, self.message);
1461 }
1462
1463 void spawnfunc_target_items (void)
1464 {
1465         float n, i, j;
1466         entity e;
1467
1468         self.use = target_items_use;
1469         if(!self.strength_finished)
1470                 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1471         if(!self.invincible_finished)
1472                 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1473
1474         precache_sound("misc/itempickup.wav");
1475         precache_sound("misc/megahealth.wav");
1476         precache_sound("misc/armor25.wav");
1477         precache_sound("misc/powerup.wav");
1478         precache_sound("misc/poweroff.wav");
1479         precache_sound("weapons/weaponpickup.wav");
1480
1481         n = tokenize_console(self.netname);
1482         if(argv(0) == "give")
1483         {
1484                 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1485         }
1486         else
1487         {
1488                 for(i = 0; i < n; ++i)
1489                 {
1490                         if     (argv(i) == "unlimited_ammo")         self.items |= IT_UNLIMITED_AMMO;
1491                         else if(argv(i) == "unlimited_weapon_ammo")  self.items |= IT_UNLIMITED_WEAPON_AMMO;
1492                         else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1493                         else if(argv(i) == "strength")               self.items |= IT_STRENGTH;
1494                         else if(argv(i) == "invincible")             self.items |= IT_INVINCIBLE;
1495                         else if(argv(i) == "jetpack")                self.items |= IT_JETPACK;
1496                         else if(argv(i) == "fuel_regen")             self.items |= IT_FUEL_REGEN;
1497                         else
1498                         for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1499                         {
1500                                 e = get_weaponinfo(j);
1501                                 if(argv(i) == e.netname)
1502                                 {
1503                                         self.weapons |= e.weapons;
1504                                         if(self.spawnflags == 0 || self.spawnflags == 2)
1505                                                 weapon_action(e.weapon, WR_PRECACHE);
1506                                         break;
1507                                 }
1508                         }
1509                         if(j > WEP_LAST)
1510                                 print("target_items: invalid item ", argv(i), "\n");
1511                 }
1512
1513                 string itemprefix, valueprefix;
1514                 if(self.spawnflags == 0)
1515                 {
1516                         itemprefix = "";
1517                         valueprefix = "";
1518                 }
1519                 else if(self.spawnflags == 1)
1520                 {
1521                         itemprefix = "max ";
1522                         valueprefix = "max ";
1523                 }
1524                 else if(self.spawnflags == 2)
1525                 {
1526                         itemprefix = "min ";
1527                         valueprefix = "min ";
1528                 }
1529                 else if(self.spawnflags == 4)
1530                 {
1531                         itemprefix = "minus ";
1532                         valueprefix = "max ";
1533                 }
1534                 else
1535                         error("invalid spawnflags");
1536
1537                 self.netname = "";
1538                 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1539                 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1540                 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * !!(self.items & IT_STRENGTH), "strength");
1541                 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * !!(self.items & IT_INVINCIBLE), "invincible");
1542                 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_JETPACK), "jetpack");
1543                 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_FUEL_REGEN), "fuel_regen");
1544                 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1545                 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1546                 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1547                 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1548                 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1549                 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1550                 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1551                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1552                 {
1553                         e = get_weaponinfo(j);
1554                         if(e.weapons)
1555                                 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & e.weapons), e.netname);
1556                 }
1557         }
1558         self.netname = strzone(self.netname);
1559         //print(self.netname, "\n");
1560
1561         n = tokenize_console(self.netname);
1562         for(i = 0; i < n; ++i)
1563         {
1564                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1565                 {
1566                         e = get_weaponinfo(j);
1567                         if(argv(i) == e.netname)
1568                         {
1569                                 weapon_action(e.weapon, WR_PRECACHE);
1570                                 break;
1571                         }
1572                 }
1573         }
1574 }
1575
1576 void spawnfunc_item_fuel(void)
1577 {
1578         if(!self.ammo_fuel)
1579                 self.ammo_fuel = g_pickup_fuel;
1580         if(!self.pickup_anyway)
1581                 self.pickup_anyway = g_pickup_ammo_anyway;
1582         StartItem ("models/items/g_fuel.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "Fuel", IT_FUEL, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1583 }
1584
1585 void spawnfunc_item_fuel_regen(void)
1586 {
1587         if(start_items & IT_FUEL_REGEN)
1588         {
1589                 spawnfunc_item_fuel();
1590                 return;
1591         }
1592         StartItem ("models/items/g_fuelregen.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Fuel regenerator", IT_FUEL_REGEN, 0, FL_POWERUP, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1593 }
1594
1595 void spawnfunc_item_jetpack(void)
1596 {
1597         if(g_grappling_hook)
1598                 return; // sorry, but these two can't coexist (same button); spawn fuel instead
1599         if(!self.ammo_fuel)
1600                 self.ammo_fuel = g_pickup_fuel_jetpack;
1601         if(start_items & IT_JETPACK)
1602         {
1603                 spawnfunc_item_fuel();
1604                 return;
1605         }
1606         StartItem ("models/items/g_jetpack.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Jet pack", IT_JETPACK, 0, FL_POWERUP, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1607 }
1608
1609
1610 #define OP_SET 0
1611 #define OP_MIN 1
1612 #define OP_MAX 2
1613 #define OP_PLUS 3
1614 #define OP_MINUS 4
1615
1616 float GiveBit(entity e, .float fld, float bit, float op, float val)
1617 {
1618         float v0, v1;
1619         v0 = (e.fld & bit);
1620         switch(op)
1621         {
1622                 case OP_SET:
1623                         if(val > 0)
1624                                 e.fld |= bit;
1625                         else
1626                                 e.fld &~= bit;
1627                         break;
1628                 case OP_MIN:
1629                 case OP_PLUS:
1630                         if(val > 0)
1631                                 e.fld |= bit;
1632                         break;
1633                 case OP_MAX:
1634                         if(val <= 0)
1635                                 e.fld &~= bit;
1636                         break;
1637                 case OP_MINUS:
1638                         if(val > 0)
1639                                 e.fld &~= bit;
1640                         break;
1641         }
1642         v1 = (e.fld & bit);
1643         return (v0 != v1);
1644 }
1645
1646 float GiveValue(entity e, .float fld, float op, float val)
1647 {
1648         float v0, v1;
1649         v0 = e.fld;
1650         switch(op)
1651         {
1652                 case OP_SET:
1653                         e.fld = val;
1654                         break;
1655                 case OP_MIN:
1656                         e.fld = max(e.fld, val); // min 100 cells = at least 100 cells
1657                         break;
1658                 case OP_MAX:
1659                         e.fld = min(e.fld, val);
1660                         break;
1661                 case OP_PLUS:
1662                         e.fld += val;
1663                         break;
1664                 case OP_MINUS:
1665                         e.fld -= val;
1666                         break;
1667         }
1668         v1 = e.fld;
1669         return (v0 != v1);
1670 }
1671
1672 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
1673 {
1674         if(v1 == v0)
1675                 return;
1676         if(v1 <= v0 - t)
1677         {
1678                 if(snd_decr != "")
1679                         sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTN_NORM);
1680         }
1681         else if(v0 >= v0 + t)
1682         {
1683                 if(snd_incr != "")
1684                         sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTN_NORM);
1685         }
1686 }
1687
1688 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1689 {
1690         if(v0 < v1)
1691                 e.rotfield = max(e.rotfield, time + rottime);
1692         else if(v0 > v1)
1693                 e.regenfield = max(e.regenfield, time + regentime);
1694 }
1695
1696 #define PREGIVE(e,f) float save_##f; save_##f = (e).f
1697 #define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr)
1698 #define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
1699 #define POSTGIVE_VALUE_ROT(e,f,t,rotfield,rottime,regenfield,regentime,snd_incr,snd_decr) GiveRot((e), save_##f, (e).f, rotfield, rottime, regenfield, regentime); GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
1700
1701 float GiveItems(entity e, float beginarg, float endarg)
1702 {
1703         float got, i, j, val, op;
1704         float _switchweapon;
1705         entity wi;
1706         string cmd;
1707
1708         val = 999;
1709         op = OP_SET;
1710
1711         got = 0;
1712
1713         _switchweapon = FALSE;
1714         if (e.autoswitch)
1715                 if (e.switchweapon == w_getbestweapon(e))
1716                         _switchweapon = TRUE;
1717
1718         e.strength_finished = max(0, e.strength_finished - time);
1719         e.invincible_finished = max(0, e.invincible_finished - time);
1720         
1721         PREGIVE(e, items);
1722         PREGIVE(e, weapons);
1723         PREGIVE(e, strength_finished);
1724         PREGIVE(e, invincible_finished);
1725         PREGIVE(e, ammo_nails);
1726         PREGIVE(e, ammo_cells);
1727         PREGIVE(e, ammo_shells);
1728         PREGIVE(e, ammo_rockets);
1729         PREGIVE(e, ammo_fuel);
1730         PREGIVE(e, armorvalue);
1731         PREGIVE(e, health);
1732
1733         for(i = beginarg; i < endarg; ++i)
1734         {
1735                 cmd = argv(i);
1736
1737                 if(cmd == "0" || stof(cmd))
1738                 {
1739                         val = stof(cmd);
1740                         continue;
1741                 }
1742                 switch(cmd)
1743                 {
1744                         case "no":
1745                                 op = OP_MAX;
1746                                 val = 0;
1747                                 continue;
1748                         case "max":
1749                                 op = OP_MAX;
1750                                 continue;
1751                         case "min":
1752                                 op = OP_MIN;
1753                                 continue;
1754                         case "plus":
1755                                 op = OP_PLUS;
1756                                 continue;
1757                         case "minus":
1758                                 op = OP_MINUS;
1759                                 continue;
1760                         case "ALL":
1761                                 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1762                                 got += GiveValue(e, strength_finished, op, time);
1763                                 got += GiveValue(e, invincible_finished, op, time);
1764                                 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1765                         case "all":
1766                                 got += GiveBit(e, items, IT_JETPACK, op, val);
1767                                 got += GiveValue(e, health, op, val);
1768                                 got += GiveValue(e, armorvalue, op, val);
1769                         case "allweapons":
1770                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1771                                 {
1772                                         wi = get_weaponinfo(j);
1773                                         if(wi.weapons)
1774                                                 got += GiveBit(e, weapons, wi.weapons, op, val);
1775                                 }
1776                         case "allammo":
1777                                 got += GiveValue(e, ammo_cells, op, val);
1778                                 got += GiveValue(e, ammo_shells, op, val);
1779                                 got += GiveValue(e, ammo_nails, op, val);
1780                                 got += GiveValue(e, ammo_rockets, op, val);
1781                                 got += GiveValue(e, ammo_fuel, op, val);
1782                                 break;
1783                         case "unlimited_ammo":
1784                                 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1785                                 break;
1786                         case "unlimited_weapon_ammo":
1787                                 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1788                                 break;
1789                         case "unlimited_superweapons":
1790                                 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1791                                 break;
1792                         case "jetpack":
1793                                 got += GiveBit(e, items, IT_JETPACK, op, val);
1794                                 break;
1795                         case "fuel_regen":
1796                                 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1797                                 break;
1798                         case "strength":
1799                                 got += GiveValue(e, strength_finished, op, val);
1800                                 break;
1801                         case "invincible":
1802                                 got += GiveValue(e, invincible_finished, op, val);
1803                                 break;
1804                         case "cells":
1805                                 got += GiveValue(e, ammo_cells, op, val);
1806                                 break;
1807                         case "shells":
1808                                 got += GiveValue(e, ammo_shells, op, val);
1809                                 break;
1810                         case "nails":
1811                         case "bullets":
1812                                 got += GiveValue(e, ammo_nails, op, val);
1813                                 break;
1814                         case "rockets":
1815                                 got += GiveValue(e, ammo_rockets, op, val);
1816                                 break;
1817                         case "health":
1818                                 got += GiveValue(e, health, op, val);
1819                                 break;
1820                         case "armor":
1821                                 got += GiveValue(e, armorvalue, op, val);
1822                                 break;
1823                         case "fuel":
1824                                 got += GiveValue(e, ammo_fuel, op, val);
1825                                 break;
1826                         default:
1827                                 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1828                                 {
1829                                         wi = get_weaponinfo(j);
1830                                         if(cmd == wi.netname)
1831                                         {
1832                                                 got += GiveBit(e, weapons, wi.weapons, op, val);
1833                                                 break;
1834                                         }
1835                                 }
1836                                 if(j > WEP_LAST)
1837                                         print("give: invalid item ", cmd, "\n");
1838                                 break;
1839                 }
1840                 val = 999;
1841                 op = OP_SET;
1842         }
1843
1844         POSTGIVE_BIT(e, items, IT_FUEL_REGEN, "misc/itempickup.wav", string_null);
1845         POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
1846         POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
1847         POSTGIVE_BIT(e, items, IT_JETPACK, "misc/itempickup.wav", string_null);
1848         for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1849         {
1850                 wi = get_weaponinfo(j);
1851                 if(wi.weapons)
1852                 {
1853                         POSTGIVE_BIT(e, weapons, wi.weapons, "weapons/weaponpickup.wav", string_null);
1854                         if not(save_weapons & wi.weapons)
1855                                 if(e.weapons & wi.weapons)
1856                                         weapon_action(wi.weapon, WR_PRECACHE);
1857                 }
1858         }
1859         POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
1860         POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
1861         POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
1862         POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
1863         POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
1864         POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
1865         POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, "misc/itempickup.wav", string_null);
1866         POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, "misc/armor25.wav", string_null);
1867         POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, "misc/megahealth.wav", string_null);
1868
1869         if (g_minstagib)
1870         {
1871                 e.health = bound(0, e.health, 100);
1872                 e.armorvalue = bound(0, e.armorvalue, 999);
1873         }
1874
1875         if(e.strength_finished <= 0)
1876                 e.strength_finished = 0;
1877         else
1878                 e.strength_finished += time;
1879         if(e.invincible_finished <= 0)
1880                 e.invincible_finished = 0;
1881         else
1882                 e.invincible_finished += time;
1883
1884         if not(e.weapons & W_WeaponBit(e.switchweapon))
1885                 _switchweapon = TRUE;
1886         if(_switchweapon)
1887                 W_SwitchWeapon_Force(e, w_getbestweapon(e));
1888
1889         return got;
1890 }