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