]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/t_items.qc
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / t_items.qc
1 #include "t_items.qh"
2
3 #include "items/_mod.qh"
4
5 #if defined(SVQC)
6
7     #include "../server/bot/api.qh"
8
9     #include <server/mutators/_mod.qh>
10
11     #include "../server/weapons/common.qh"
12     #include "../server/weapons/selection.qh"
13     #include "../server/weapons/weaponsystem.qh"
14
15     #include "constants.qh"
16     #include <common/deathtypes/all.qh>
17     #include <common/notifications/all.qh>
18         #include "triggers/subs.qh"
19     #include "util.qh"
20
21     #include <common/monsters/_mod.qh>
22
23     #include <common/weapons/_all.qh>
24
25     #include "../lib/warpzone/util_server.qh"
26 #elif defined(CSQC)
27         #include "physics/movetypes/movetypes.qh"
28         #include <common/weapons/_all.qh>
29         #include "../lib/csqcmodel/cl_model.qh"
30         #include "../lib/csqcmodel/common.qh"
31 #endif
32
33 REGISTER_NET_LINKED(ENT_CLIENT_ITEM)
34
35 #ifdef CSQC
36 bool autocvar_cl_ghost_items_vehicle = true;
37 .vector item_glowmod;
38 void Item_SetAlpha(entity this)
39 {
40         bool veh_hud = (hud && autocvar_cl_ghost_items_vehicle);
41
42         if(!veh_hud && (this.ItemStatus & ITS_AVAILABLE))
43         {
44                 this.alpha = 1;
45                 this.colormod = '1 1 1';
46                 this.glowmod = this.item_glowmod;
47         }
48         else
49         {
50                 if (autocvar_cl_ghost_items_color)
51                 {
52                         this.alpha = autocvar_cl_ghost_items;
53                         this.colormod = this.glowmod = autocvar_cl_ghost_items_color;
54                 }
55                 else
56                         this.alpha = -1;
57         }
58
59         if(!veh_hud)
60         if(this.ItemStatus & ITS_STAYWEP)
61         {
62                 this.colormod = this.glowmod = autocvar_cl_weapon_stay_color;
63                 this.alpha = autocvar_cl_weapon_stay_alpha;
64         }
65 }
66
67 void ItemDraw(entity this)
68 {
69     if(this.gravity)
70     {
71         Movetype_Physics_MatchServer(this, false);
72         if(IS_ONGROUND(this))
73         { // For some reason avelocity gets set to '0 0 0' here ...
74             this.oldorigin = this.origin;
75             this.gravity = 0;
76
77             if(autocvar_cl_animate_items)
78             { // ... so reset it if animations are requested.
79                 if(this.ItemStatus & ITS_ANIMATE1)
80                     this.avelocity = '0 180 0';
81
82                 if(this.ItemStatus & ITS_ANIMATE2)
83                     this.avelocity = '0 -90 0';
84             }
85         }
86     }
87     else if (autocvar_cl_animate_items)
88     {
89         if(this.ItemStatus & ITS_ANIMATE1)
90         {
91             this.angles += this.avelocity * frametime;
92             setorigin(this, '0 0 10' + this.oldorigin + '0 0 8' * sin(time * 2));
93         }
94
95         if(this.ItemStatus & ITS_ANIMATE2)
96         {
97             this.angles += this.avelocity * frametime;
98             setorigin(this, '0 0 8' + this.oldorigin + '0 0 4' * sin(time * 3));
99         }
100     }
101
102     Item_SetAlpha(this);
103 }
104
105 void ItemDrawSimple(entity this)
106 {
107     if(this.gravity)
108     {
109         Movetype_Physics_MatchServer(this, false);
110
111         if(IS_ONGROUND(this))
112             this.gravity = 0;
113     }
114
115     Item_SetAlpha(this);
116 }
117
118 void Item_PreDraw(entity this)
119 {
120         if(warpzone_warpzones_exist)
121         {
122                 // just incase warpzones were initialized last, reset these
123                 //this.alpha = 1; // alpha is already set by the draw function
124                 this.drawmask = MASK_NORMAL;
125                 return;
126         }
127         float alph;
128         vector org = getpropertyvec(VF_ORIGIN);
129         if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones
130                 alph = 0;
131         else if(this.fade_start)
132                 alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1);
133         else
134                 alph = 1;
135         //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
136         if(!hud && (this.ItemStatus & ITS_AVAILABLE))
137                 this.alpha = alph;
138         if(alph <= 0)
139                 this.drawmask = 0;
140         else
141                 this.drawmask = MASK_NORMAL;
142 }
143
144 void ItemRemove(entity this)
145 {
146         if(this.mdl)
147                 strunzone(this.mdl);
148 }
149
150 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
151 {
152     int sf = ReadByte();
153
154     if(sf & ISF_LOCATION)
155     {
156         this.origin_x = ReadCoord();
157         this.origin_y = ReadCoord();
158         this.origin_z = ReadCoord();
159         setorigin(this, this.origin);
160         this.oldorigin = this.origin;
161     }
162
163     if(sf & ISF_ANGLES)
164     {
165         this.angles_x = ReadAngle();
166         this.angles_y = ReadAngle();
167         this.angles_z = ReadAngle();
168     }
169
170     if(sf & ISF_SIZE)
171     {
172         float use_bigsize = ReadByte();
173         setsize(this, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
174     }
175
176     if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
177     {
178         this.ItemStatus = ReadByte();
179
180         Item_SetAlpha(this);
181
182         if(autocvar_cl_fullbright_items)
183             if(this.ItemStatus & ITS_ALLOWFB)
184                 this.effects |= EF_FULLBRIGHT;
185
186         if(this.ItemStatus & ITS_POWERUP)
187         {
188             if(this.ItemStatus & ITS_AVAILABLE)
189                 this.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
190             else
191                  this.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
192         }
193     }
194
195     if(sf & ISF_MODEL)
196     {
197         this.drawmask  = MASK_NORMAL;
198                 set_movetype(this, MOVETYPE_TOSS);
199                 if (isnew) IL_PUSH(g_drawables, this);
200         this.draw       = ItemDraw;
201         this.solid = SOLID_TRIGGER;
202         //this.flags |= FL_ITEM;
203
204         bool use_bigsize = ReadByte();
205
206         this.fade_end = ReadShort();
207         this.fade_start = ReadShort();
208         if(this.fade_start && !autocvar_cl_items_nofade)
209                 setpredraw(this, Item_PreDraw);
210
211         if(this.mdl)
212             strunzone(this.mdl);
213
214         this.mdl = "";
215         string _fn = ReadString();
216
217         if(autocvar_cl_simple_items && (this.ItemStatus & ITS_ALLOWSI))
218         {
219             string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
220             this.draw = ItemDrawSimple;
221
222             if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
223                 this.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
224             else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
225                 this.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
226             else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
227                 this.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
228             else if(fexists(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix)))
229                 this.mdl = strzone(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix));
230             else
231             {
232                 this.draw = ItemDraw;
233                 LOG_TRACE("Simple item requested for ", _fn, " but no model exists for it");
234             }
235         }
236
237         if(this.draw != ItemDrawSimple)
238             this.mdl = strzone(_fn);
239
240
241         if(this.mdl == "")
242             LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, ", tell tZork about this!");
243
244         precache_model(this.mdl);
245         _setmodel(this, this.mdl);
246
247         setsize(this, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
248     }
249
250     if(sf & ISF_COLORMAP)
251     {
252         this.colormap = ReadShort();
253         this.item_glowmod_x = ReadByte() / 255.0;
254         this.item_glowmod_y = ReadByte() / 255.0;
255         this.item_glowmod_z = ReadByte() / 255.0;
256     }
257
258     if(sf & ISF_DROP)
259     {
260         this.gravity = 1;
261         this.pushable = true;
262         //this.angles = '0 0 0';
263         set_movetype(this, MOVETYPE_TOSS);
264         this.velocity_x = ReadCoord();
265         this.velocity_y = ReadCoord();
266         this.velocity_z = ReadCoord();
267         setorigin(this, this.oldorigin);
268
269         if(!this.move_time)
270         {
271             this.move_time = time;
272             this.spawntime = time;
273         }
274         else
275             this.move_time = max(this.move_time, time);
276     }
277
278     if(autocvar_cl_animate_items)
279     {
280         if(this.ItemStatus & ITS_ANIMATE1)
281             this.avelocity = '0 180 0';
282
283         if(this.ItemStatus & ITS_ANIMATE2)
284             this.avelocity = '0 -90 0';
285     }
286
287     this.entremove = ItemRemove;
288
289     return true;
290 }
291
292 #endif
293
294 #ifdef SVQC
295 bool ItemSend(entity this, entity to, int sf)
296 {
297         if(this.gravity)
298                 sf |= ISF_DROP;
299         else
300                 sf &= ~ISF_DROP;
301
302         WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
303         WriteByte(MSG_ENTITY, sf);
304
305         //WriteByte(MSG_ENTITY, this.cnt);
306         if(sf & ISF_LOCATION)
307         {
308                 WriteCoord(MSG_ENTITY, this.origin.x);
309                 WriteCoord(MSG_ENTITY, this.origin.y);
310                 WriteCoord(MSG_ENTITY, this.origin.z);
311         }
312
313         if(sf & ISF_ANGLES)
314         {
315                 WriteAngle(MSG_ENTITY, this.angles_x);
316                 WriteAngle(MSG_ENTITY, this.angles_y);
317                 WriteAngle(MSG_ENTITY, this.angles_z);
318         }
319
320         if(sf & ISF_SIZE)
321         {
322                 Pickup p = this.itemdef;
323                 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
324         }
325
326         if(sf & ISF_STATUS)
327                 WriteByte(MSG_ENTITY, this.ItemStatus);
328
329         if(sf & ISF_MODEL)
330         {
331                 Pickup p = this.itemdef;
332                 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
333                 WriteShort(MSG_ENTITY, this.fade_end);
334                 WriteShort(MSG_ENTITY, this.fade_start);
335
336                 if(this.mdl == "")
337                         LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now");
338
339                 WriteString(MSG_ENTITY, this.mdl);
340         }
341
342
343         if(sf & ISF_COLORMAP)
344         {
345                 WriteShort(MSG_ENTITY, this.colormap);
346                 WriteByte(MSG_ENTITY, this.glowmod.x * 255.0);
347         WriteByte(MSG_ENTITY, this.glowmod.y * 255.0);
348         WriteByte(MSG_ENTITY, this.glowmod.z * 255.0);
349         }
350
351         if(sf & ISF_DROP)
352         {
353                 WriteCoord(MSG_ENTITY, this.velocity.x);
354                 WriteCoord(MSG_ENTITY, this.velocity.y);
355                 WriteCoord(MSG_ENTITY, this.velocity.z);
356         }
357
358         return true;
359 }
360
361 void ItemUpdate(entity this)
362 {
363         this.oldorigin = this.origin;
364         this.SendFlags |= ISF_LOCATION;
365 }
366
367 void UpdateItemAfterTeleport(entity this)
368 {
369         if(getSendEntity(this) == ItemSend)
370                 ItemUpdate(this);
371 }
372
373 bool have_pickup_item(entity this)
374 {
375         if(this.itemdef.instanceOfPowerup)
376         {
377                 if(autocvar_g_powerups > 0)
378                         return true;
379                 if(autocvar_g_powerups == 0)
380                         return false;
381         }
382         else
383         {
384                 if(autocvar_g_pickup_items > 0)
385                         return true;
386                 if(autocvar_g_pickup_items == 0)
387                         return false;
388                 if(g_weaponarena)
389                         if(this.weapons || (this.items & IT_AMMO)) // no item or ammo pickups in weaponarena
390                                 return false;
391         }
392         return true;
393 }
394
395 /*
396 float Item_Customize()
397 {
398         if(this.spawnshieldtime)
399                 return true;
400         if(this.weapons & ~other.weapons)
401         {
402                 this.colormod = '0 0 0';
403                 this.glowmod = this.colormod;
404                 this.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
405                 return true;
406         }
407         else
408         {
409                 if(g_ghost_items)
410                 {
411                         this.colormod = stov(autocvar_g_ghost_items_color);
412                         this.glowmod = this.colormod;
413                         this.alpha = g_ghost_items;
414                         return true;
415                 }
416                 else
417                         return false;
418         }
419 }
420 */
421
422 void Item_Show (entity e, float mode)
423 {
424         e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
425         e.ItemStatus &= ~ITS_STAYWEP;
426         if (mode > 0)
427         {
428                 // make the item look normal, and be touchable
429                 e.model = e.mdl;
430                 e.solid = SOLID_TRIGGER;
431                 e.spawnshieldtime = 1;
432                 e.ItemStatus |= ITS_AVAILABLE;
433         }
434         else if (mode < 0)
435         {
436                 // hide the item completely
437                 e.model = string_null;
438                 e.solid = SOLID_NOT;
439                 e.spawnshieldtime = 1;
440                 e.ItemStatus &= ~ITS_AVAILABLE;
441         }
442         else {
443         entity def = e.itemdef;
444         bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.weapons & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
445                 || e.team // weapon stay isn't supported for teamed weapons
446                 ;
447         if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
448         {
449                 // make the item translucent and not touchable
450                 e.model = e.mdl;
451                 e.solid = SOLID_TRIGGER; // can STILL be picked up!
452                 e.effects |= EF_STARDUST;
453                 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
454                 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
455         }
456         else
457         {
458                 //setmodel(e, "null");
459                 e.solid = SOLID_NOT;
460                 e.colormod = '0 0 0';
461                 //e.glowmod = e.colormod;
462                 e.spawnshieldtime = 1;
463                 e.ItemStatus &= ~ITS_AVAILABLE;
464         }}
465
466         if (e.items & ITEM_Strength.m_itemid || e.items & ITEM_Shield.m_itemid)
467                 e.ItemStatus |= ITS_POWERUP;
468
469         if (autocvar_g_nodepthtestitems)
470                 e.effects |= EF_NODEPTHTEST;
471
472
473         if (autocvar_g_fullbrightitems)
474                 e.ItemStatus |= ITS_ALLOWFB;
475
476         if (autocvar_sv_simple_items)
477                 e.ItemStatus |= ITS_ALLOWSI;
478
479         // relink entity (because solid may have changed)
480         setorigin(e, e.origin);
481         e.SendFlags |= ISF_STATUS;
482 }
483
484 void Item_Think(entity this)
485 {
486         this.nextthink = time;
487         if(this.origin != this.oldorigin)
488                 ItemUpdate(this);
489 }
490
491 bool Item_ItemsTime_SpectatorOnly(GameItem it);
492 bool Item_ItemsTime_Allow(GameItem it);
493 float Item_ItemsTime_UpdateTime(entity e, float t);
494 void Item_ItemsTime_SetTime(entity e, float t);
495 void Item_ItemsTime_SetTimesForAllPlayers();
496
497 void Item_Respawn (entity this)
498 {
499         Item_Show(this, 1);
500         // this is ugly...
501         if(this.items == ITEM_Strength.m_itemid)
502                 sound (this, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTEN_NORM);   // play respawn sound
503         else if(this.items == ITEM_Shield.m_itemid)
504                 sound (this, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTEN_NORM);     // play respawn sound
505         else
506                 sound (this, CH_TRIGGER, SND_ITEMRESPAWN, VOL_BASE, ATTEN_NORM);        // play respawn sound
507         setorigin(this, this.origin);
508
509     if (Item_ItemsTime_Allow(this.itemdef) || this.weapons & WEPSET_SUPERWEAPONS)
510         {
511                 float t = Item_ItemsTime_UpdateTime(this, 0);
512                 Item_ItemsTime_SetTime(this, t);
513                 Item_ItemsTime_SetTimesForAllPlayers();
514         }
515
516         setthink(this, Item_Think);
517         this.nextthink = time;
518
519         //Send_Effect(EFFECT_ITEM_RESPAWN, this.origin + this.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
520         Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
521 }
522
523 void Item_RespawnCountdown (entity this)
524 {
525         if(this.count >= ITEM_RESPAWN_TICKS)
526         {
527                 if(this.waypointsprite_attached)
528                         WaypointSprite_Kill(this.waypointsprite_attached);
529                 Item_Respawn(this);
530         }
531         else
532         {
533                 this.nextthink = time + 1;
534                 this.count += 1;
535                 if(this.count == 1)
536                 {
537                         MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0');
538                         do {
539                                 {
540                                         entity wi = Weapons_from(this.weapon);
541                                         if (wi != WEP_Null) {
542                                                 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon);
543                                                 wp.wp_extra = wi.m_id;
544                                                 break;
545                                         }
546                                 }
547                                 {
548                                         entity ii = this.itemdef;
549                                         if (ii != NULL) {
550                                                 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Item);
551                                                 wp.wp_extra = ii.m_id;
552                                                 break;
553                                         }
554                                 }
555                         } while (0);
556             if(this.waypointsprite_attached)
557             {
558                 GameItem def = this.itemdef;
559                 if (Item_ItemsTime_SpectatorOnly(def))
560                     WaypointSprite_UpdateRule(this.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
561                 WaypointSprite_UpdateBuildFinished(this.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
562             }
563                 }
564
565                 if(this.waypointsprite_attached)
566                 {
567                         FOREACH_CLIENT(IS_REAL_CLIENT(it), {
568                                 if(this.waypointsprite_attached.waypointsprite_visible_for_player(this.waypointsprite_attached, it, it))
569                                 {
570                                         msg_entity = it;
571                                         soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM);    // play respawn sound
572                                 }
573                         });
574
575                         WaypointSprite_Ping(this.waypointsprite_attached);
576                         //WaypointSprite_UpdateHealth(this.waypointsprite_attached, this.count);
577                 }
578         }
579 }
580
581 void Item_RespawnThink(entity this)
582 {
583         this.nextthink = time;
584         if(this.origin != this.oldorigin)
585                 ItemUpdate(this);
586
587         if(time >= this.wait)
588                 Item_Respawn(this);
589 }
590
591 void Item_ScheduleRespawnIn(entity e, float t)
592 {
593         // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
594         if ((Item_ItemsTime_Allow(e.itemdef) || e.weapons & WEPSET_SUPERWEAPONS) && (t - ITEM_RESPAWN_TICKS) > 0)
595         {
596                 setthink(e, Item_RespawnCountdown);
597                 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
598                 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
599                 e.count = 0;
600                 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
601                 Item_ItemsTime_SetTime(e, t);
602                 Item_ItemsTime_SetTimesForAllPlayers();
603         }
604         else
605         {
606                 setthink(e, Item_RespawnThink);
607                 e.nextthink = time;
608                 e.scheduledrespawntime = time + t;
609                 e.wait = time + t;
610         }
611 }
612
613 void Item_ScheduleRespawn(entity e)
614 {
615         if(e.respawntime > 0)
616         {
617                 Item_Show(e, 0);
618                 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
619         }
620         else // if respawntime is -1, this item does not respawn
621                 Item_Show(e, -1);
622 }
623
624 void Item_ScheduleInitialRespawn(entity e)
625 {
626         Item_Show(e, 0);
627         Item_ScheduleRespawnIn(e, game_starttime - time + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
628 }
629
630 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
631 {
632         if (!item.(ammotype))
633                 return false;
634
635         if (item.spawnshieldtime)
636         {
637                 if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0)
638                 {
639                         player.(ammotype) = bound(player.(ammotype), ammomax, player.(ammotype) + item.(ammotype));
640                         goto YEAH;
641                 }
642         }
643         else if(g_weapon_stay == 2)
644         {
645                 float mi = min(item.(ammotype), ammomax);
646                 if (player.(ammotype) < mi)
647                 {
648                         player.(ammotype) = mi;
649                         goto YEAH;
650                 }
651         }
652
653         return false;
654
655 LABEL(YEAH)
656         switch(mode)
657         {
658                 case ITEM_MODE_FUEL:
659                         player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
660                         break;
661                 case ITEM_MODE_HEALTH:
662                         player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
663                         break;
664                 case ITEM_MODE_ARMOR:
665                         player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
666                         break;
667                 default:
668                         break;
669         }
670         return true;
671 }
672
673 float Item_GiveTo(entity item, entity player)
674 {
675         float pickedup;
676
677         // if nothing happens to player, just return without taking the item
678         pickedup = false;
679         int _switchweapon = 0;
680         // in case the player has autoswitch enabled do the following:
681         // if the player is using their best weapon before items are given, they
682         // probably want to switch to an even better weapon after items are given
683
684         if(player.autoswitch)
685         {
686                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
687                 {
688                         .entity weaponentity = weaponentities[slot];
689                         if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
690                         {
691                                 if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
692                                         _switchweapon |= BIT(slot);
693
694                                 if(!(player.weapons & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
695                                         _switchweapon |= BIT(slot);
696                         }
697                 }
698         }
699
700         pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
701         pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
702         pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
703         pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
704         pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
705         pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max, ITEM_MODE_NONE);
706         pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
707         pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
708
709         if (item.itemdef.instanceOfWeaponPickup)
710         {
711                 WepSet w;
712                 w = item.weapons;
713                 w &= ~player.weapons;
714
715                 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
716                 {
717                         pickedup = true;
718                         FOREACH(Weapons, it != WEP_Null, {
719                                 if(w & (it.m_wepset))
720                                 {
721                                         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
722                                         {
723                                                 .entity weaponentity = weaponentities[slot];
724                                                 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
725                                                         W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
726                                         }
727                                         W_GiveWeapon(player, it.m_id);
728                                 }
729                         });
730                 }
731         }
732
733         if (item.itemdef.instanceOfPowerup)
734         {
735                 if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
736                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
737                 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
738                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
739         }
740
741         int its;
742         if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
743         {
744                 pickedup = true;
745                 player.items |= its;
746                 Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
747         }
748
749         if (item.strength_finished)
750         {
751                 pickedup = true;
752                 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
753         }
754         if (item.invincible_finished)
755         {
756                 pickedup = true;
757                 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
758         }
759         if (item.superweapons_finished)
760         {
761                 pickedup = true;
762                 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
763         }
764
765 LABEL(skip)
766
767         // always eat teamed entities
768         if(item.team)
769                 pickedup = true;
770
771         if (!pickedup)
772                 return 0;
773
774         // crude hack to enforce switching weapons
775         if(g_cts && item.itemdef.instanceOfWeaponPickup)
776         {
777                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
778                 {
779                         .entity weaponentity = weaponentities[slot];
780                         if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
781                                 W_SwitchWeapon_Force(player, Weapons_from(item.weapon), weaponentity);
782                 }
783                 return 1;
784         }
785
786         if(_switchweapon)
787         {
788                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
789                 {
790                         .entity weaponentity = weaponentities[slot];
791                         if(_switchweapon & BIT(slot))
792                         if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity))
793                                 W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity);
794                 }
795         }
796
797         return 1;
798 }
799
800 void Item_Touch(entity this, entity toucher)
801 {
802
803         // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
804         if (this.classname == "droppedweapon")
805         {
806                 if (ITEM_TOUCH_NEEDKILL())
807                 {
808                         delete(this);
809                         return;
810                 }
811         }
812
813         if(!(toucher.flags & FL_PICKUPITEMS)
814         || STAT(FROZEN, toucher)
815         || IS_DEAD(toucher)
816         || (this.solid != SOLID_TRIGGER)
817         || (this.owner == toucher)
818         || (time < this.item_spawnshieldtime)
819         ) { return; }
820
821         switch (MUTATOR_CALLHOOK(ItemTouch, this, toucher))
822         {
823                 case MUT_ITEMTOUCH_RETURN: { return; }
824                 case MUT_ITEMTOUCH_PICKUP: { toucher = M_ARGV(1, entity); goto pickup; }
825         }
826
827         toucher = M_ARGV(1, entity);
828
829         if (this.classname == "droppedweapon")
830         {
831                 this.strength_finished = max(0, this.strength_finished - time);
832                 this.invincible_finished = max(0, this.invincible_finished - time);
833                 this.superweapons_finished = max(0, this.superweapons_finished - time);
834         }
835         entity it = this.itemdef;
836         bool gave = ITEM_HANDLE(Pickup, it, this, toucher);
837         if (!gave)
838         {
839                 if (this.classname == "droppedweapon")
840                 {
841                         // undo what we did above
842                         this.strength_finished += time;
843                         this.invincible_finished += time;
844                         this.superweapons_finished += time;
845                 }
846                 return;
847         }
848
849 LABEL(pickup)
850
851         toucher.last_pickup = time;
852
853         Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
854         _sound (toucher, (this.itemdef.instanceOfPowerup ? CH_TRIGGER_SINGLE : CH_TRIGGER), (this.item_pickupsound ? this.item_pickupsound : Sound_fixpath(this.item_pickupsound_ent)), VOL_BASE, ATTEN_NORM);
855
856         if (this.classname == "droppedweapon")
857                 delete (this);
858         else if (this.spawnshieldtime)
859         {
860                 entity e;
861                 if(this.team)
862                 {
863                         RandomSelection_Init();
864                         IL_EACH(g_items, it.team == this.team,
865                         {
866                                 if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
867                                 {
868                                         Item_Show(it, -1);
869                                         RandomSelection_AddEnt(it, it.cnt, 0);
870                                 }
871                         });
872                         e = RandomSelection_chosen_ent;
873
874                 }
875                 else
876                         e = this;
877                 Item_ScheduleRespawn(e);
878         }
879 }
880
881 void Item_Reset(entity this)
882 {
883         Item_Show(this, !this.state);
884         setorigin(this, this.origin);
885
886         if (this.classname != "droppedweapon")
887         {
888                 setthink(this, Item_Think);
889                 this.nextthink = time;
890
891                 if (this.waypointsprite_attached)
892                         WaypointSprite_Kill(this.waypointsprite_attached);
893
894                 if (this.itemdef.instanceOfPowerup || (this.weapons & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
895                         Item_ScheduleInitialRespawn(this);
896         }
897 }
898
899 void Item_FindTeam(entity this)
900 {
901         entity e;
902
903         if(this.effects & EF_NODRAW)
904         {
905                 // marker for item team search
906                 LOG_TRACE("Initializing item team ", ftos(this.team));
907                 RandomSelection_Init();
908                 IL_EACH(g_items, it.team == this.team,
909                 {
910                         if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
911                                 RandomSelection_AddEnt(it, it.cnt, 0);
912                 });
913
914                 e = RandomSelection_chosen_ent;
915                 e.state = 0;
916                 Item_Show(e, 1);
917
918                 IL_EACH(g_items, it.team == this.team,
919                 {
920                         if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
921                         {
922                                 if(it != e)
923                                 {
924                                         // make it non-spawned
925                                         Item_Show(it, -1);
926                                         it.state = 1; // state 1 = initially hidden item, apparently
927                                 }
928                                 it.effects &= ~EF_NODRAW;
929                         }
930                 });
931
932                 Item_Reset(this);
933         }
934 }
935
936 // Savage: used for item garbage-collection
937 void RemoveItem(entity this)
938 {
939         if(wasfreed(this) || !this) { return; }
940         Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
941         delete(this);
942 }
943
944 // pickup evaluation functions
945 // these functions decide how desirable an item is to the bots
946
947 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
948
949 float weapon_pickupevalfunc(entity player, entity item)
950 {
951         float c;
952
953         // See if I have it already
954         if(item.weapons & ~player.weapons)
955         {
956                 // If I can pick it up
957                 if(!item.spawnshieldtime)
958                         c = 0;
959                 else if(player.ammo_cells || player.ammo_shells || player.ammo_plasma || player.ammo_nails || player.ammo_rockets)
960                 {
961                         // Skilled bots will grab more
962                         c = bound(0, skill / 10, 1) * 0.5;
963                 }
964                 else
965                         c = 0;
966         }
967         else
968                 c = 1;
969
970         // If custom weapon priorities for bots is enabled rate most wanted weapons higher
971         if( bot_custom_weapon && c )
972         {
973                 // Find the highest position on any range
974                 int position = -1;
975                 for (int j = 0; j < WEP_LAST ; ++j){
976                         if(
977                                         bot_weapons_far[j] == item.weapon ||
978                                         bot_weapons_mid[j] == item.weapon ||
979                                         bot_weapons_close[j] == item.weapon
980                           )
981                         {
982                                 position = j;
983                                 break;
984                         }
985                 }
986
987                 // Rate it
988                 if (position >= 0 )
989                 {
990                         position = WEP_LAST - position;
991                         // item.bot_pickupbasevalue is overwritten here
992                         return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
993                 }
994         }
995
996         return item.bot_pickupbasevalue * c;
997 }
998
999 float commodity_pickupevalfunc(entity player, entity item)
1000 {
1001         float c;
1002         float need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
1003         c = 0;
1004
1005         // Detect needed ammo
1006         FOREACH(Weapons, it != WEP_Null, {
1007                 if(!(player.weapons & (it.m_wepset)))
1008                         continue;
1009
1010                 if(it.items & ITEM_Shells.m_itemid)
1011                         need_shells = true;
1012                 else if(it.items & ITEM_Bullets.m_itemid)
1013                         need_nails = true;
1014                 else if(it.items & ITEM_Rockets.m_itemid)
1015                         need_rockets = true;
1016                 else if(it.items & ITEM_Cells.m_itemid)
1017                         need_cells = true;
1018                 else if(it.items & ITEM_Plasma.m_itemid)
1019                         need_plasma = true;
1020                 else if(it.items & ITEM_JetpackFuel.m_itemid)
1021                         need_fuel = true;
1022         });
1023
1024         // TODO: figure out if the player even has the weapon this ammo is for?
1025         // may not affect strategy much though...
1026         // find out how much more ammo/armor/health the player can hold
1027         if (need_shells)
1028         if (item.ammo_shells)
1029         if (player.ammo_shells < g_pickup_shells_max)
1030                 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
1031         if (need_nails)
1032         if (item.ammo_nails)
1033         if (player.ammo_nails < g_pickup_nails_max)
1034                 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
1035         if (need_rockets)
1036         if (item.ammo_rockets)
1037         if (player.ammo_rockets < g_pickup_rockets_max)
1038                 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
1039         if (need_cells)
1040         if (item.ammo_cells)
1041         if (player.ammo_cells < g_pickup_cells_max)
1042                 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
1043         if (need_plasma)
1044         if (item.ammo_plasma)
1045         if (player.ammo_plasma < g_pickup_plasma_max)
1046                 c = c + max(0, 1 - player.ammo_plasma / g_pickup_plasma_max);
1047         if (need_fuel)
1048         if (item.ammo_fuel)
1049         if (player.ammo_fuel < g_pickup_fuel_max)
1050                 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
1051         if (item.armorvalue)
1052         if (player.armorvalue < item.max_armorvalue)
1053                 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
1054         if (item.health)
1055         if (player.health < item.max_health)
1056                 c = c + max(0, 1 - player.health / item.max_health);
1057
1058         return item.bot_pickupbasevalue * c;
1059 }
1060
1061 void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
1062 {
1063         if(ITEM_DAMAGE_NEEDKILL(deathtype))
1064                 RemoveItem(this);
1065 }
1066
1067 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
1068 {
1069         string itemname = def.m_name;
1070         Model itemmodel = def.m_model;
1071     Sound pickupsound = def.m_sound;
1072         float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
1073         float pickupbasevalue = def.m_botvalue;
1074         int itemflags = def.m_itemflags;
1075
1076         startitem_failed = false;
1077
1078         this.item_model_ent = itemmodel;
1079     this.item_pickupsound_ent = pickupsound;
1080
1081         if(!this.respawntime) // both need to be set
1082         {
1083                 this.respawntime = defaultrespawntime;
1084                 this.respawntimejitter = defaultrespawntimejitter;
1085         }
1086
1087         int itemid = def.m_itemid;
1088         this.items = itemid;
1089         int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
1090         this.weapon = weaponid;
1091
1092         if(!this.fade_end)
1093         {
1094                 this.fade_start = autocvar_g_items_mindist;
1095                 this.fade_end = autocvar_g_items_maxdist;
1096         }
1097
1098         if(weaponid)
1099                 this.weapons = WepSet_FromWeapon(Weapons_from(weaponid));
1100
1101         this.flags = FL_ITEM | itemflags;
1102         IL_PUSH(g_items, this);
1103
1104         if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
1105         {
1106                 startitem_failed = true;
1107                 delete(this);
1108                 return;
1109         }
1110
1111         // is it a dropped weapon?
1112         if (this.classname == "droppedweapon")
1113         {
1114                 this.reset = SUB_Remove;
1115                 // it's a dropped weapon
1116                 set_movetype(this, MOVETYPE_TOSS);
1117
1118                 // Savage: remove thrown items after a certain period of time ("garbage collection")
1119                 setthink(this, RemoveItem);
1120                 this.nextthink = time + 20;
1121
1122                 this.takedamage = DAMAGE_YES;
1123                 this.event_damage = Item_Damage;
1124
1125                 if(this.strength_finished || this.invincible_finished || this.superweapons_finished)
1126                 {
1127                         // if item is worthless after a timer, have it expire then
1128                         this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
1129                 }
1130
1131                 // don't drop if in a NODROP zone (such as lava)
1132                 traceline(this.origin, this.origin, MOVE_NORMAL, this);
1133                 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1134                 {
1135                         startitem_failed = true;
1136                         delete(this);
1137                         return;
1138                 }
1139         }
1140         else
1141         {
1142                 if(!have_pickup_item(this))
1143                 {
1144                         startitem_failed = true;
1145                         delete (this);
1146                         return;
1147                 }
1148
1149                 if(this.angles != '0 0 0')
1150                         this.SendFlags |= ISF_ANGLES;
1151
1152                 this.reset = Item_Reset;
1153                 // it's a level item
1154                 if(this.spawnflags & 1)
1155                         this.noalign = 1;
1156                 if (this.noalign > 0)
1157                         set_movetype(this, MOVETYPE_NONE);
1158                 else
1159                         set_movetype(this, MOVETYPE_TOSS);
1160                 // do item filtering according to game mode and other things
1161                 if (this.noalign <= 0)
1162                 {
1163                         // first nudge it off the floor a little bit to avoid math errors
1164                         setorigin(this, this.origin + '0 0 1');
1165                         // set item size before we spawn a spawnfunc_waypoint
1166                         setsize(this, def.m_mins, def.m_maxs);
1167                         this.SendFlags |= ISF_SIZE;
1168                         // note droptofloor returns false if stuck/or would fall too far
1169                         if (!this.noalign)
1170                                 droptofloor(this);
1171                         waypoint_spawnforitem(this);
1172                 }
1173
1174                 /*
1175                  * can't do it that way, as it would break maps
1176                  * TODO make a target_give like entity another way, that perhaps has
1177                  * the weapon name in a key
1178                 if(this.targetname)
1179                 {
1180                         // target_give not yet supported; maybe later
1181                         print("removed targeted ", this.classname, "\n");
1182                         startitem_failed = true;
1183                         remove (this);
1184                         return;
1185                 }
1186                 */
1187
1188                 if(autocvar_spawn_debug >= 2)
1189                 {
1190             // why not flags & fl_item?
1191                     FOREACH_ENTITY_RADIUS(this.origin, 3, it.is_item, {
1192                 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1193                 LOG_TRACE(" vs ", it.netname, vtos(it.origin));
1194                 error("Mapper sucks.");
1195             });
1196                         this.is_item = true;
1197                 }
1198
1199                 weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid));
1200
1201                 precache_model(this.model);
1202                 precache_sound(this.item_pickupsound);
1203
1204                 if (   def.instanceOfPowerup
1205                         || def.instanceOfWeaponPickup
1206                         || (def.instanceOfHealth && def != ITEM_HealthSmall)
1207                         || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1208                         || (itemid & (IT_KEY1 | IT_KEY2))
1209                 ) this.target = "###item###"; // for finding the nearest item using find()
1210
1211                 Item_ItemsTime_SetTime(this, 0);
1212         }
1213
1214         this.bot_pickup = true;
1215         this.bot_pickupevalfunc = pickupevalfunc;
1216         this.bot_pickupbasevalue = pickupbasevalue;
1217         this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1218         this.netname = itemname;
1219         settouch(this, Item_Touch);
1220         setmodel(this, MDL_Null); // precision set below
1221         //this.effects |= EF_LOWPRECISION;
1222
1223         setsize (this, this.pos1 =  def.m_mins, this.pos2 = def.m_maxs);
1224
1225         this.SendFlags |= ISF_SIZE;
1226
1227         if (!(this.spawnflags & 1024)) {
1228                 if(def.instanceOfPowerup)
1229                         this.ItemStatus |= ITS_ANIMATE1;
1230
1231                 if(this.armorvalue || this.health)
1232                         this.ItemStatus |= ITS_ANIMATE2;
1233         }
1234
1235         if(def.instanceOfWeaponPickup)
1236         {
1237                 if (this.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1238                         this.colormap = 1024; // color shirt=0 pants=0 grey
1239                 else
1240                         this.gravity = 1;
1241                 if (!(this.spawnflags & 1024))
1242                         this.ItemStatus |= ITS_ANIMATE1;
1243                 this.SendFlags |= ISF_COLORMAP;
1244         }
1245
1246         this.state = 0;
1247         if(this.team) // broken, no idea why.
1248         {
1249                 if(!this.cnt)
1250                         this.cnt = 1; // item probability weight
1251
1252                 this.effects |= EF_NODRAW; // marker for item team search
1253                 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1254         }
1255         else
1256                 Item_Reset(this);
1257
1258         Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1259
1260         // call this hook after everything else has been done
1261         if (MUTATOR_CALLHOOK(Item_Spawn, this))
1262         {
1263                 startitem_failed = true;
1264                 delete(this);
1265                 return;
1266         }
1267 }
1268
1269 void StartItem(entity this, GameItem def)
1270 {
1271     _StartItem(
1272         this,
1273         this.itemdef = def,
1274         def.m_respawntime(), // defaultrespawntime
1275         def.m_respawntimejitter() // defaultrespawntimejitter
1276         );
1277 }
1278
1279 spawnfunc(item_rockets)
1280 {
1281         if(!this.ammo_rockets)
1282                 this.ammo_rockets = g_pickup_rockets;
1283         if(!this.pickup_anyway)
1284                 this.pickup_anyway = g_pickup_ammo_anyway;
1285     StartItem(this, ITEM_Rockets);
1286 }
1287
1288 spawnfunc(item_bullets)
1289 {
1290         if(!weaponswapping)
1291         if(autocvar_sv_q3acompat_machineshotgunswap)
1292         if(this.classname != "droppedweapon")
1293         {
1294                 weaponswapping = true;
1295                 spawnfunc_item_shells(this);
1296                 weaponswapping = false;
1297                 return;
1298         }
1299
1300         if(!this.ammo_nails)
1301                 this.ammo_nails = g_pickup_nails;
1302         if(!this.pickup_anyway)
1303                 this.pickup_anyway = g_pickup_ammo_anyway;
1304     StartItem(this, ITEM_Bullets);
1305 }
1306
1307 spawnfunc(item_cells)
1308 {
1309         if(!this.ammo_cells)
1310                 this.ammo_cells = g_pickup_cells;
1311         if(!this.pickup_anyway)
1312                 this.pickup_anyway = g_pickup_ammo_anyway;
1313         StartItem(this, ITEM_Cells);
1314 }
1315
1316 spawnfunc(item_plasma)
1317 {
1318         if(!this.ammo_plasma)
1319                 this.ammo_plasma = g_pickup_plasma;
1320         if(!this.pickup_anyway)
1321                 this.pickup_anyway = g_pickup_ammo_anyway;
1322         StartItem(this, ITEM_Plasma);
1323 }
1324
1325 spawnfunc(item_shells)
1326 {
1327         if(!weaponswapping)
1328         if(autocvar_sv_q3acompat_machineshotgunswap)
1329         if(this.classname != "droppedweapon")
1330         {
1331                 weaponswapping = true;
1332                 spawnfunc_item_bullets(this);
1333                 weaponswapping = false;
1334                 return;
1335         }
1336
1337         if(!this.ammo_shells)
1338                 this.ammo_shells = g_pickup_shells;
1339         if(!this.pickup_anyway)
1340                 this.pickup_anyway = g_pickup_ammo_anyway;
1341         StartItem(this, ITEM_Shells);
1342 }
1343
1344 spawnfunc(item_armor_small)
1345 {
1346         if(!this.armorvalue)
1347                 this.armorvalue = g_pickup_armorsmall;
1348         if(!this.max_armorvalue)
1349                 this.max_armorvalue = g_pickup_armorsmall_max;
1350         if(!this.pickup_anyway)
1351                 this.pickup_anyway = g_pickup_armorsmall_anyway;
1352         StartItem(this, ITEM_ArmorSmall);
1353 }
1354
1355 spawnfunc(item_armor_medium)
1356 {
1357         if(!this.armorvalue)
1358                 this.armorvalue = g_pickup_armormedium;
1359         if(!this.max_armorvalue)
1360                 this.max_armorvalue = g_pickup_armormedium_max;
1361         if(!this.pickup_anyway)
1362                 this.pickup_anyway = g_pickup_armormedium_anyway;
1363         StartItem(this, ITEM_ArmorMedium);
1364 }
1365
1366 spawnfunc(item_armor_big)
1367 {
1368         if(!this.armorvalue)
1369                 this.armorvalue = g_pickup_armorbig;
1370         if(!this.max_armorvalue)
1371                 this.max_armorvalue = g_pickup_armorbig_max;
1372         if(!this.pickup_anyway)
1373                 this.pickup_anyway = g_pickup_armorbig_anyway;
1374         StartItem(this, ITEM_ArmorLarge);
1375 }
1376
1377 spawnfunc(item_armor_large)
1378 {
1379         if(!this.armorvalue)
1380                 this.armorvalue = g_pickup_armorlarge;
1381         if(!this.max_armorvalue)
1382                 this.max_armorvalue = g_pickup_armorlarge_max;
1383         if(!this.pickup_anyway)
1384                 this.pickup_anyway = g_pickup_armorlarge_anyway;
1385         StartItem(this, ITEM_ArmorMega);
1386 }
1387
1388 spawnfunc(item_health_small)
1389 {
1390         if(!this.max_health)
1391                 this.max_health = g_pickup_healthsmall_max;
1392         if(!this.health)
1393                 this.health = g_pickup_healthsmall;
1394         if(!this.pickup_anyway)
1395                 this.pickup_anyway = g_pickup_healthsmall_anyway;
1396         StartItem(this, ITEM_HealthSmall);
1397 }
1398
1399 spawnfunc(item_health_medium)
1400 {
1401         if(!this.max_health)
1402                 this.max_health = g_pickup_healthmedium_max;
1403         if(!this.health)
1404                 this.health = g_pickup_healthmedium;
1405         if(!this.pickup_anyway)
1406                 this.pickup_anyway = g_pickup_healthmedium_anyway;
1407     StartItem(this, ITEM_HealthMedium);
1408 }
1409
1410 spawnfunc(item_health_large)
1411 {
1412         if(!this.max_health)
1413                 this.max_health = g_pickup_healthlarge_max;
1414         if(!this.health)
1415                 this.health = g_pickup_healthlarge;
1416         if(!this.pickup_anyway)
1417                 this.pickup_anyway = g_pickup_healthlarge_anyway;
1418         StartItem(this, ITEM_HealthLarge);
1419 }
1420
1421 spawnfunc(item_health_mega)
1422 {
1423     if(!this.max_health)
1424         this.max_health = g_pickup_healthmega_max;
1425     if(!this.health)
1426         this.health = g_pickup_healthmega;
1427     if(!this.pickup_anyway)
1428         this.pickup_anyway = g_pickup_healthmega_anyway;
1429     StartItem(this, ITEM_HealthMega);
1430 }
1431
1432 // support old misnamed entities
1433 spawnfunc(item_armor1) { spawnfunc_item_armor_small(this); }  // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1434 spawnfunc(item_armor25) { spawnfunc_item_armor_large(this); }
1435 spawnfunc(item_health1) { spawnfunc_item_health_small(this); }
1436 spawnfunc(item_health25) { spawnfunc_item_health_medium(this); }
1437 spawnfunc(item_health100) { spawnfunc_item_health_mega(this); }
1438
1439 spawnfunc(item_strength)
1440 {
1441                 if(!this.strength_finished)
1442                         this.strength_finished = autocvar_g_balance_powerup_strength_time;
1443                 StartItem(this, ITEM_Strength);
1444 }
1445
1446 spawnfunc(item_invincible)
1447 {
1448                 if(!this.invincible_finished)
1449                         this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1450                 StartItem(this, ITEM_Shield);
1451 }
1452
1453 // compatibility:
1454 spawnfunc(item_quad) { this.classname = "item_strength";spawnfunc_item_strength(this);}
1455
1456 void target_items_use(entity this, entity actor, entity trigger)
1457 {
1458         if(actor.classname == "droppedweapon")
1459         {
1460                 EXACTTRIGGER_TOUCH(this, trigger);
1461                 delete(actor);
1462                 return;
1463         }
1464
1465         if (!IS_PLAYER(actor))
1466                 return;
1467         if(IS_DEAD(actor))
1468                 return;
1469         if(trigger.solid == SOLID_TRIGGER)
1470         {
1471                 EXACTTRIGGER_TOUCH(this, trigger);
1472         }
1473
1474         IL_EACH(g_items, it.enemy == actor && it.classname == "droppedweapon",
1475         {
1476                 delete(it);
1477         });
1478
1479         if(GiveItems(actor, 0, tokenize_console(this.netname)))
1480                 centerprint(actor, this.message);
1481 }
1482
1483 spawnfunc(target_items)
1484 {
1485         int n, j;
1486         string s;
1487
1488         this.use = target_items_use;
1489         if(!this.strength_finished)
1490                 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1491         if(!this.invincible_finished)
1492                 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1493         if(!this.superweapons_finished)
1494                 this.superweapons_finished = autocvar_g_balance_superweapons_time;
1495
1496         n = tokenize_console(this.netname);
1497         if(argv(0) == "give")
1498         {
1499                 this.netname = substring(this.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1500         }
1501         else
1502         {
1503                 for(j = 0; j < n; ++j)
1504                 {
1505                         if     (argv(j) == "unlimited_ammo")         this.items |= IT_UNLIMITED_AMMO;
1506                         else if(argv(j) == "unlimited_weapon_ammo")  this.items |= IT_UNLIMITED_WEAPON_AMMO;
1507                         else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS;
1508                         else if(argv(j) == "strength")               this.items |= ITEM_Strength.m_itemid;
1509                         else if(argv(j) == "invincible")             this.items |= ITEM_Shield.m_itemid;
1510                         else if(argv(j) == "superweapons")           this.items |= IT_SUPERWEAPON;
1511                         else if(argv(j) == "jetpack")                this.items |= ITEM_Jetpack.m_itemid;
1512                         else if(argv(j) == "fuel_regen")             this.items |= ITEM_JetpackRegen.m_itemid;
1513                         else
1514                         {
1515                                 FOREACH(Weapons, it != WEP_Null, {
1516                                         s = W_UndeprecateName(argv(j));
1517                                         if(s == it.netname)
1518                                         {
1519                                                 this.weapons |= (it.m_wepset);
1520                                                 if(this.spawnflags == 0 || this.spawnflags == 2)
1521                                                         it.wr_init(it);
1522                                                 break;
1523                                         }
1524                                 });
1525                         }
1526                 }
1527
1528                 string itemprefix, valueprefix;
1529                 if(this.spawnflags == 0)
1530                 {
1531                         itemprefix = "";
1532                         valueprefix = "";
1533                 }
1534                 else if(this.spawnflags == 1)
1535                 {
1536                         itemprefix = "max ";
1537                         valueprefix = "max ";
1538                 }
1539                 else if(this.spawnflags == 2)
1540                 {
1541                         itemprefix = "min ";
1542                         valueprefix = "min ";
1543                 }
1544                 else if(this.spawnflags == 4)
1545                 {
1546                         itemprefix = "minus ";
1547                         valueprefix = "max ";
1548                 }
1549                 else
1550                 {
1551                         error("invalid spawnflags");
1552                         itemprefix = valueprefix = string_null;
1553                 }
1554
1555                 this.netname = "";
1556                 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1557                 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1558                 this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.strength_finished * boolean(this.items & ITEM_Strength.m_itemid), "strength");
1559                 this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.invincible_finished * boolean(this.items & ITEM_Shield.m_itemid), "invincible");
1560                 this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
1561                 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
1562                 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1563                 if(this.ammo_shells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_shells), "shells");
1564                 if(this.ammo_nails != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_nails), "nails");
1565                 if(this.ammo_rockets != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_rockets), "rockets");
1566                 if(this.ammo_cells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_cells), "cells");
1567                 if(this.ammo_plasma != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_plasma), "plasma");
1568                 if(this.ammo_fuel != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_fuel), "fuel");
1569                 if(this.health != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.health), "health");
1570                 if(this.armorvalue != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.armorvalue), "armor");
1571                 FOREACH(Weapons, it != WEP_Null, this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, !!(this.weapons & (it.m_wepset)), it.netname));
1572         }
1573         this.netname = strzone(this.netname);
1574         //print(this.netname, "\n");
1575
1576         n = tokenize_console(this.netname);
1577         for(j = 0; j < n; ++j)
1578         {
1579                 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(argv(j)) == it.netname, {
1580             it.wr_init(it);
1581             break;
1582                 });
1583         }
1584 }
1585
1586 spawnfunc(item_fuel)
1587 {
1588         if(!this.ammo_fuel)
1589                 this.ammo_fuel = g_pickup_fuel;
1590         if(!this.pickup_anyway)
1591                 this.pickup_anyway = g_pickup_ammo_anyway;
1592         StartItem(this, ITEM_JetpackFuel);
1593 }
1594
1595 spawnfunc(item_fuel_regen)
1596 {
1597         if(start_items & ITEM_JetpackRegen.m_itemid)
1598         {
1599                 spawnfunc_item_fuel(this);
1600                 return;
1601         }
1602         StartItem(this, ITEM_JetpackRegen);
1603 }
1604
1605 spawnfunc(item_jetpack)
1606 {
1607         if(!this.ammo_fuel)
1608                 this.ammo_fuel = g_pickup_fuel_jetpack;
1609         if(start_items & ITEM_Jetpack.m_itemid)
1610         {
1611                 spawnfunc_item_fuel(this);
1612                 return;
1613         }
1614         StartItem(this, ITEM_Jetpack);
1615 }
1616
1617 float GiveWeapon(entity e, float wpn, float op, float val)
1618 {
1619         WepSet v0, v1;
1620         WepSet s = WepSet_FromWeapon(Weapons_from(wpn));
1621         v0 = (e.weapons & s);
1622         switch(op)
1623         {
1624                 case OP_SET:
1625                         if(val > 0)
1626                                 e.weapons |= s;
1627                         else
1628                                 e.weapons &= ~s;
1629                         break;
1630                 case OP_MIN:
1631                 case OP_PLUS:
1632                         if(val > 0)
1633                                 e.weapons |= s;
1634                         break;
1635                 case OP_MAX:
1636                         if(val <= 0)
1637                                 e.weapons &= ~s;
1638                         break;
1639                 case OP_MINUS:
1640                         if(val > 0)
1641                                 e.weapons &= ~s;
1642                         break;
1643         }
1644         v1 = (e.weapons & s);
1645         return (v0 != v1);
1646 }
1647
1648 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
1649 {
1650         if(v1 == v0)
1651                 return;
1652         if(v1 <= v0 - t)
1653         {
1654                 if(snd_decr != NULL)
1655                         sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1656         }
1657         else if(v0 >= v0 + t)
1658         {
1659                 if(snd_incr != NULL)
1660                         sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1661         }
1662 }
1663
1664 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1665 {
1666         if(v0 < v1)
1667                 e.(rotfield) = max(e.(rotfield), time + rottime);
1668         else if(v0 > v1)
1669                 e.(regenfield) = max(e.(regenfield), time + regentime);
1670 }
1671 float GiveItems(entity e, float beginarg, float endarg)
1672 {
1673         float got, i, val, op;
1674         string cmd;
1675
1676         val = 999;
1677         op = OP_SET;
1678
1679         got = 0;
1680
1681         int _switchweapon = 0;
1682
1683         if(e.autoswitch)
1684         {
1685                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1686                 {
1687                         .entity weaponentity = weaponentities[slot];
1688                         if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1689                         if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
1690                                 _switchweapon |= BIT(slot);
1691                 }
1692         }
1693
1694         e.strength_finished = max(0, e.strength_finished - time);
1695         e.invincible_finished = max(0, e.invincible_finished - time);
1696         e.superweapons_finished = max(0, e.superweapons_finished - time);
1697
1698         PREGIVE(e, items);
1699         PREGIVE_WEAPONS(e);
1700         PREGIVE(e, strength_finished);
1701         PREGIVE(e, invincible_finished);
1702         PREGIVE(e, superweapons_finished);
1703         PREGIVE(e, ammo_nails);
1704         PREGIVE(e, ammo_cells);
1705         PREGIVE(e, ammo_plasma);
1706         PREGIVE(e, ammo_shells);
1707         PREGIVE(e, ammo_rockets);
1708         PREGIVE(e, ammo_fuel);
1709         PREGIVE(e, armorvalue);
1710         PREGIVE(e, health);
1711
1712         for(i = beginarg; i < endarg; ++i)
1713         {
1714                 cmd = argv(i);
1715
1716                 if(cmd == "0" || stof(cmd))
1717                 {
1718                         val = stof(cmd);
1719                         continue;
1720                 }
1721                 switch(cmd)
1722                 {
1723                         case "no":
1724                                 op = OP_MAX;
1725                                 val = 0;
1726                                 continue;
1727                         case "max":
1728                                 op = OP_MAX;
1729                                 continue;
1730                         case "min":
1731                                 op = OP_MIN;
1732                                 continue;
1733                         case "plus":
1734                                 op = OP_PLUS;
1735                                 continue;
1736                         case "minus":
1737                                 op = OP_MINUS;
1738                                 continue;
1739                         case "ALL":
1740                                 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1741                                 got += GiveValue(e, strength_finished, op, val);
1742                                 got += GiveValue(e, invincible_finished, op, val);
1743                                 got += GiveValue(e, superweapons_finished, op, val);
1744                                 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1745                         case "all":
1746                                 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1747                                 got += GiveValue(e, health, op, val);
1748                                 got += GiveValue(e, armorvalue, op, val);
1749                         case "allweapons":
1750                                 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & WEP_FLAG_MUTATORBLOCKED), got += GiveWeapon(e, it.m_id, op, val));
1751                         case "allammo":
1752                                 got += GiveValue(e, ammo_cells, op, val);
1753                                 got += GiveValue(e, ammo_plasma, op, val);
1754                                 got += GiveValue(e, ammo_shells, op, val);
1755                                 got += GiveValue(e, ammo_nails, op, val);
1756                                 got += GiveValue(e, ammo_rockets, op, val);
1757                                 got += GiveValue(e, ammo_fuel, op, val);
1758                                 break;
1759                         case "unlimited_ammo":
1760                                 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1761                                 break;
1762                         case "unlimited_weapon_ammo":
1763                                 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1764                                 break;
1765                         case "unlimited_superweapons":
1766                                 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1767                                 break;
1768                         case "jetpack":
1769                                 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1770                                 break;
1771                         case "fuel_regen":
1772                                 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1773                                 break;
1774                         case "strength":
1775                                 got += GiveValue(e, strength_finished, op, val);
1776                                 break;
1777                         case "invincible":
1778                                 got += GiveValue(e, invincible_finished, op, val);
1779                                 break;
1780                         case "superweapons":
1781                                 got += GiveValue(e, superweapons_finished, op, val);
1782                                 break;
1783                         case "cells":
1784                                 got += GiveValue(e, ammo_cells, op, val);
1785                                 break;
1786                         case "plasma":
1787                                 got += GiveValue(e, ammo_plasma, op, val);
1788                                 break;
1789                         case "shells":
1790                                 got += GiveValue(e, ammo_shells, op, val);
1791                                 break;
1792                         case "nails":
1793                         case "bullets":
1794                                 got += GiveValue(e, ammo_nails, op, val);
1795                                 break;
1796                         case "rockets":
1797                                 got += GiveValue(e, ammo_rockets, op, val);
1798                                 break;
1799                         case "health":
1800                                 got += GiveValue(e, health, op, val);
1801                                 break;
1802                         case "armor":
1803                                 got += GiveValue(e, armorvalue, op, val);
1804                                 break;
1805                         case "fuel":
1806                                 got += GiveValue(e, ammo_fuel, op, val);
1807                                 break;
1808                         default:
1809                                 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
1810                     got += GiveWeapon(e, it.m_id, op, val);
1811                     break;
1812                                 });
1813                                 break;
1814                 }
1815                 val = 999;
1816                 op = OP_SET;
1817         }
1818
1819         POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1820         POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1821         POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND_POWERUP, SND_POWEROFF);
1822         POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1823         FOREACH(Weapons, it != WEP_Null, {
1824                 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1825                 if(!(save_weapons & (it.m_wepset)))
1826                         if(e.weapons & (it.m_wepset))
1827                                 it.wr_init(it);
1828         });
1829         POSTGIVE_VALUE(e, strength_finished, 1, SND_POWERUP, SND_POWEROFF);
1830         POSTGIVE_VALUE(e, invincible_finished, 1, SND_Shield, SND_POWEROFF);
1831         POSTGIVE_VALUE(e, ammo_nails, 0, SND_ITEMPICKUP, SND_Null);
1832         POSTGIVE_VALUE(e, ammo_cells, 0, SND_ITEMPICKUP, SND_Null);
1833         POSTGIVE_VALUE(e, ammo_plasma, 0, SND_ITEMPICKUP, SND_Null);
1834         POSTGIVE_VALUE(e, ammo_shells, 0, SND_ITEMPICKUP, SND_Null);
1835         POSTGIVE_VALUE(e, ammo_rockets, 0, SND_ITEMPICKUP, SND_Null);
1836         POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND_ITEMPICKUP, SND_Null);
1837         POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_ARMOR25, SND_Null);
1838         POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_MEGAHEALTH, SND_Null);
1839
1840         if(e.superweapons_finished <= 0)
1841                 if(e.weapons & WEPSET_SUPERWEAPONS)
1842                         e.superweapons_finished = autocvar_g_balance_superweapons_time;
1843
1844         if(e.strength_finished <= 0)
1845                 e.strength_finished = 0;
1846         else
1847                 e.strength_finished += time;
1848         if(e.invincible_finished <= 0)
1849                 e.invincible_finished = 0;
1850         else
1851                 e.invincible_finished += time;
1852         if(e.superweapons_finished <= 0)
1853                 e.superweapons_finished = 0;
1854         else
1855                 e.superweapons_finished += time;
1856
1857         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1858         {
1859                 .entity weaponentity = weaponentities[slot];
1860                 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1861                 if(!(e.weapons & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
1862                         _switchweapon |= BIT(slot);
1863         }
1864
1865         if(_switchweapon)
1866         {
1867                 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1868                 {
1869                         .entity weaponentity = weaponentities[slot];
1870                         if(_switchweapon & BIT(slot))
1871                                 W_SwitchWeapon_Force(e, w_getbestweapon(e, weaponentity), weaponentity);
1872                 }
1873         }
1874
1875         return got;
1876 }
1877 #endif