3 #include "../common/items/all.qc"
8 #include "bot/waypoints.qh"
10 #include "mutators/all.qh"
12 #include "weapons/common.qh"
13 #include "weapons/selection.qh"
14 #include "weapons/weaponsystem.qh"
16 #include "../common/constants.qh"
17 #include "../common/deathtypes/all.qh"
18 #include "../common/notifications.qh"
19 #include "../common/triggers/subs.qh"
20 #include "../common/util.qh"
22 #include "../common/monsters/all.qh"
24 #include "../common/weapons/all.qh"
26 #include "../lib/warpzone/util_server.qh"
29 REGISTER_NET_LINKED(ENT_CLIENT_ITEM)
32 void ItemDraw(entity this)
36 Movetype_Physics_MatchServer(this, false);
37 if(this.move_flags & FL_ONGROUND)
38 { // For some reason move_avelocity gets set to '0 0 0' here ...
39 this.oldorigin = this.origin;
42 if(autocvar_cl_animate_items)
43 { // ... so reset it if animations are requested.
44 if(this.ItemStatus & ITS_ANIMATE1)
45 this.move_avelocity = '0 180 0';
47 if(this.ItemStatus & ITS_ANIMATE2)
48 this.move_avelocity = '0 -90 0';
52 else if (autocvar_cl_animate_items)
54 if(this.ItemStatus & ITS_ANIMATE1)
56 this.angles += this.move_avelocity * frametime;
57 setorigin(this, '0 0 10' + this.oldorigin + '0 0 8' * sin(time * 2));
60 if(this.ItemStatus & ITS_ANIMATE2)
62 this.angles += this.move_avelocity * frametime;
63 setorigin(this, '0 0 8' + this.oldorigin + '0 0 4' * sin(time * 3));
68 void ItemDrawSimple(entity this)
72 Movetype_Physics_MatchServer(this, false);
74 if(this.move_flags & FL_ONGROUND)
83 org = getpropertyvec(VF_ORIGIN);
84 if(!checkpvs(org, self)) // this makes sense as long as we don't support recursive warpzones
86 else if(self.fade_start)
87 alph = bound(0, (self.fade_end - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) / (self.fade_end - self.fade_start), 1);
90 //printf("%v <-> %v\n", view_origin, self.origin + 0.5 * (self.mins + self.maxs));
91 if(self.ItemStatus & ITS_AVAILABLE)
96 self.drawmask = MASK_NORMAL;
105 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
109 if(sf & ISF_LOCATION)
111 self.origin_x = ReadCoord();
112 self.origin_y = ReadCoord();
113 self.origin_z = ReadCoord();
114 setorigin(self, self.origin);
115 self.oldorigin = self.origin;
120 self.angles_x = ReadAngle();
121 self.angles_y = ReadAngle();
122 self.angles_z = ReadAngle();
123 self.move_angles = self.angles;
128 float use_bigsize = ReadByte();
129 setsize(self, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
132 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
134 self.ItemStatus = ReadByte();
136 if(self.ItemStatus & ITS_AVAILABLE)
139 self.colormod = self.glowmod = '1 1 1';
143 if (autocvar_cl_ghost_items_color)
145 self.alpha = autocvar_cl_ghost_items;
146 self.colormod = self.glowmod = autocvar_cl_ghost_items_color;
152 if(autocvar_cl_fullbright_items)
153 if(self.ItemStatus & ITS_ALLOWFB)
154 self.effects |= EF_FULLBRIGHT;
156 if(self.ItemStatus & ITS_STAYWEP)
158 self.colormod = self.glowmod = autocvar_cl_weapon_stay_color;
159 self.alpha = autocvar_cl_weapon_stay_alpha;
163 if(self.ItemStatus & ITS_POWERUP)
165 if(self.ItemStatus & ITS_AVAILABLE)
166 self.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
168 self.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
174 self.drawmask = MASK_NORMAL;
175 self.move_movetype = MOVETYPE_TOSS;
176 self.draw = ItemDraw;
177 self.solid = SOLID_TRIGGER;
178 //self.move_flags |= FL_ITEM;
180 bool use_bigsize = ReadByte();
182 self.fade_end = ReadShort();
183 self.fade_start = ReadShort();
184 if(self.fade_start && !autocvar_cl_items_nofade)
185 self.predraw = Item_PreDraw;
191 string _fn = ReadString();
193 if(autocvar_cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
195 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
196 self.draw = ItemDrawSimple;
198 if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
199 self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
200 else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
201 self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
202 else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
203 self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
204 else if(fexists(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix)))
205 self.mdl = strzone(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix));
208 self.draw = ItemDraw;
209 LOG_TRACE("Simple item requested for ", _fn, " but no model exists for it\n");
213 if(self.draw != ItemDrawSimple)
214 self.mdl = strzone(_fn);
218 LOG_TRACE("^1WARNING!^7 self.mdl is unset for item ", self.classname, ", tell tZork about this!\n");
220 precache_model(self.mdl);
221 _setmodel(self, self.mdl);
223 setsize(self, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
226 if(sf & ISF_COLORMAP)
227 self.colormap = ReadShort();
232 self.pushable = true;
233 //self.move_angles = '0 0 0';
234 self.move_movetype = MOVETYPE_TOSS;
235 self.move_velocity_x = ReadCoord();
236 self.move_velocity_y = ReadCoord();
237 self.move_velocity_z = ReadCoord();
238 self.velocity = self.move_velocity;
239 self.move_origin = self.oldorigin;
243 self.move_time = time;
244 self.spawntime = time;
247 self.move_time = max(self.move_time, time);
250 if(autocvar_cl_animate_items)
252 if(self.ItemStatus & ITS_ANIMATE1)
253 self.move_avelocity = '0 180 0';
255 if(self.ItemStatus & ITS_ANIMATE2)
256 self.move_avelocity = '0 -90 0';
259 self.entremove = ItemRemove;
267 bool ItemSend(entity this, entity to, int sf)
274 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
275 WriteByte(MSG_ENTITY, sf);
277 //WriteByte(MSG_ENTITY, self.cnt);
278 if(sf & ISF_LOCATION)
280 WriteCoord(MSG_ENTITY, self.origin.x);
281 WriteCoord(MSG_ENTITY, self.origin.y);
282 WriteCoord(MSG_ENTITY, self.origin.z);
287 WriteAngle(MSG_ENTITY, self.angles_x);
288 WriteAngle(MSG_ENTITY, self.angles_y);
289 WriteAngle(MSG_ENTITY, self.angles_z);
294 Pickup p = this.itemdef;
295 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
299 WriteByte(MSG_ENTITY, self.ItemStatus);
303 Pickup p = this.itemdef;
304 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
305 WriteShort(MSG_ENTITY, self.fade_end);
306 WriteShort(MSG_ENTITY, self.fade_start);
309 LOG_TRACE("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n");
311 WriteString(MSG_ENTITY, self.mdl);
315 if(sf & ISF_COLORMAP)
316 WriteShort(MSG_ENTITY, self.colormap);
320 WriteCoord(MSG_ENTITY, self.velocity.x);
321 WriteCoord(MSG_ENTITY, self.velocity.y);
322 WriteCoord(MSG_ENTITY, self.velocity.z);
328 void ItemUpdate(entity this)
330 this.oldorigin = this.origin;
331 this.SendFlags |= ISF_LOCATION;
334 void UpdateItemAfterTeleport(entity this)
336 if(this.SendEntity3 == ItemSend)
340 bool have_pickup_item(entity this)
342 if(this.itemdef.instanceOfPowerup)
344 if(autocvar_g_powerups > 0)
346 if(autocvar_g_powerups == 0)
351 if(autocvar_g_pickup_items > 0)
353 if(autocvar_g_pickup_items == 0)
356 if(this.weapons || (this.items & IT_AMMO)) // no item or ammo pickups in weaponarena
363 float Item_Customize()
365 if(self.spawnshieldtime)
367 if(self.weapons & ~other.weapons)
369 self.colormod = '0 0 0';
370 self.glowmod = self.colormod;
371 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
378 self.colormod = stov(autocvar_g_ghost_items_color);
379 self.glowmod = self.colormod;
380 self.alpha = g_ghost_items;
389 void Item_Show (entity e, float mode)
391 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
392 e.ItemStatus &= ~ITS_STAYWEP;
395 // make the item look normal, and be touchable
397 e.solid = SOLID_TRIGGER;
398 e.spawnshieldtime = 1;
399 e.ItemStatus |= ITS_AVAILABLE;
403 // hide the item completely
404 e.model = string_null;
406 e.spawnshieldtime = 1;
407 e.ItemStatus &= ~ITS_AVAILABLE;
410 entity def = e.itemdef;
411 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.weapons & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
412 || e.team // weapon stay isn't supported for teamed weapons
414 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
416 // make the item translucent and not touchable
418 e.solid = SOLID_TRIGGER; // can STILL be picked up!
419 e.effects |= EF_STARDUST;
420 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
421 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
425 //setmodel(e, "null");
427 e.colormod = '0 0 0';
428 e.glowmod = e.colormod;
429 e.spawnshieldtime = 1;
430 e.ItemStatus &= ~ITS_AVAILABLE;
433 if (e.items & ITEM_Strength.m_itemid || e.items & ITEM_Shield.m_itemid)
434 e.ItemStatus |= ITS_POWERUP;
436 if (autocvar_g_nodepthtestitems)
437 e.effects |= EF_NODEPTHTEST;
440 if (autocvar_g_fullbrightitems)
441 e.ItemStatus |= ITS_ALLOWFB;
443 if (autocvar_sv_simple_items)
444 e.ItemStatus |= ITS_ALLOWSI;
446 // relink entity (because solid may have changed)
447 setorigin(e, e.origin);
448 e.SendFlags |= ISF_STATUS;
453 self.nextthink = time;
454 if(self.origin != self.oldorigin)
458 bool Item_ItemsTime_SpectatorOnly(GameItem it);
459 bool Item_ItemsTime_Allow(GameItem it, WepSet _weapons);
460 float Item_ItemsTime_UpdateTime(entity e, float t);
461 void Item_ItemsTime_SetTime(entity e, float t);
462 void Item_ItemsTime_SetTimesForAllPlayers();
468 if(self.items == ITEM_Strength.m_itemid)
469 sound (self, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
470 else if(self.items == ITEM_Shield.m_itemid)
471 sound (self, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
473 sound (self, CH_TRIGGER, SND_ITEMRESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
474 setorigin (self, self.origin);
476 if (Item_ItemsTime_Allow(self.itemdef, self.weapons))
478 float t = Item_ItemsTime_UpdateTime(self, 0);
479 Item_ItemsTime_SetTime(self, t);
480 Item_ItemsTime_SetTimesForAllPlayers();
483 self.think = Item_Think;
484 self.nextthink = time;
486 //Send_Effect(EFFECT_ITEM_RESPAWN, self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
487 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
490 void Item_RespawnCountdown ()
492 if(self.count >= ITEM_RESPAWN_TICKS)
494 if(self.waypointsprite_attached)
495 WaypointSprite_Kill(self.waypointsprite_attached);
500 self.nextthink = time + 1;
504 MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0');
507 entity wi = Weapons_from(self.weapon);
508 if (wi != WEP_Null) {
509 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Weapon);
510 wp.wp_extra = wi.m_id;
515 entity ii = self.itemdef;
517 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Item);
518 wp.wp_extra = ii.m_id;
523 if(self.waypointsprite_attached)
525 GameItem def = self.itemdef;
526 if (Item_ItemsTime_SpectatorOnly(def))
527 WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
528 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
532 if(self.waypointsprite_attached)
534 setself(self.waypointsprite_attached);
535 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
536 if(self.waypointsprite_visible_for_player(it))
539 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM); // play respawn sound
544 WaypointSprite_Ping(self.waypointsprite_attached);
545 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
550 void Item_RespawnThink()
552 self.nextthink = time;
553 if(self.origin != self.oldorigin)
556 if(time >= self.wait)
560 void Item_ScheduleRespawnIn(entity e, float t)
562 if (Item_ItemsTime_Allow(e.itemdef, e.weapons))
564 e.think = Item_RespawnCountdown;
565 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
566 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
568 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
569 Item_ItemsTime_SetTime(e, t);
570 Item_ItemsTime_SetTimesForAllPlayers();
574 e.think = Item_RespawnThink;
576 e.scheduledrespawntime = time + t;
581 void Item_ScheduleRespawn(entity e)
583 if(e.respawntime > 0)
586 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
588 else // if respawntime is -1, this item does not respawn
592 void Item_ScheduleInitialRespawn(entity e)
595 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
598 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
600 if (!item.(ammotype))
603 if (item.spawnshieldtime)
605 if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0)
607 player.(ammotype) = bound(player.(ammotype), ammomax, player.(ammotype) + item.(ammotype));
611 else if(g_weapon_stay == 2)
613 float mi = min(item.(ammotype), ammomax);
614 if (player.(ammotype) < mi)
616 player.(ammotype) = mi;
627 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
629 case ITEM_MODE_HEALTH:
630 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
632 case ITEM_MODE_ARMOR:
633 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
641 float Item_GiveTo(entity item, entity player)
646 // if nothing happens to player, just return without taking the item
648 _switchweapon = false;
649 // in case the player has autoswitch enabled do the following:
650 // if the player is using their best weapon before items are given, they
651 // probably want to switch to an even better weapon after items are given
652 if (player.autoswitch)
653 if (PS(player).m_switchweapon == w_getbestweapon(player))
654 _switchweapon = true;
656 if (!(player.weapons & WepSet_FromWeapon(PS(player).m_switchweapon)))
657 _switchweapon = true;
659 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
660 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
661 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
662 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
663 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
664 pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max, ITEM_MODE_NONE);
665 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
666 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
668 if (item.itemdef.instanceOfWeaponPickup)
672 w &= ~player.weapons;
674 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
677 FOREACH(Weapons, it != WEP_Null, LAMBDA(
678 if(w & (it.m_wepset))
680 W_DropEvent(wr_pickup, player, it.m_id, item);
681 W_GiveWeapon(player, it.m_id);
688 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
692 Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
695 if (item.strength_finished)
698 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
700 if (item.invincible_finished)
703 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
705 if (item.superweapons_finished)
708 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
713 // always eat teamed entities
720 // crude hack to enforce switching weapons
721 if(g_cts && item.itemdef.instanceOfWeaponPickup)
723 W_SwitchWeapon_Force(player, Weapons_from(item.weapon));
728 if (PS(player).m_switchweapon != w_getbestweapon(player))
729 W_SwitchWeapon_Force(player, w_getbestweapon(player));
738 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
739 if (this.classname == "droppedweapon")
741 if (ITEM_TOUCH_NEEDKILL())
748 if(!(other.flags & FL_PICKUPITEMS)
751 || (this.solid != SOLID_TRIGGER)
752 || (this.owner == other)
753 || (time < this.item_spawnshieldtime)
756 switch (MUTATOR_CALLHOOK(ItemTouch, this, other))
758 case MUT_ITEMTOUCH_RETURN: { return; }
759 case MUT_ITEMTOUCH_PICKUP: { goto pickup; }
762 if (this.classname == "droppedweapon")
764 this.strength_finished = max(0, this.strength_finished - time);
765 this.invincible_finished = max(0, this.invincible_finished - time);
766 this.superweapons_finished = max(0, this.superweapons_finished - time);
768 entity it = this.itemdef;
769 bool gave = ITEM_HANDLE(Pickup, it, this, other);
772 if (this.classname == "droppedweapon")
774 // undo what we did above
775 this.strength_finished += time;
776 this.invincible_finished += time;
777 this.superweapons_finished += time;
784 other.last_pickup = time;
786 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
787 _sound (other, CH_TRIGGER, (this.item_pickupsound ? this.item_pickupsound : Sound_fixpath(this.item_pickupsound_ent)), VOL_BASE, ATTEN_NORM);
789 if (this.classname == "droppedweapon")
791 else if (this.spawnshieldtime)
796 RandomSelection_Init();
797 for(entity head = world; (head = findfloat(head, team, this.team)); )
799 if(head.flags & FL_ITEM)
800 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
803 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
806 e = RandomSelection_chosen_ent;
811 Item_ScheduleRespawn(e);
815 void Item_Reset(entity this)
817 Item_Show(this, !this.state);
818 setorigin(this, this.origin);
820 if (this.classname != "droppedweapon")
822 this.think = Item_Think;
823 this.nextthink = time;
825 if (this.waypointsprite_attached)
826 WaypointSprite_Kill(this.waypointsprite_attached);
828 if (this.itemdef.instanceOfPowerup || (this.weapons & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
829 Item_ScheduleInitialRespawn(this);
832 void Item_Reset_self() { SELFPARAM(); Item_Reset(this); }
838 if(self.effects & EF_NODRAW)
840 // marker for item team search
841 LOG_TRACE("Initializing item team ", ftos(self.team), "\n");
842 RandomSelection_Init();
843 for(head = world; (head = findfloat(head, team, self.team)); )
844 if(head.flags & FL_ITEM)
845 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
846 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
847 e = RandomSelection_chosen_ent;
851 for(head = world; (head = findfloat(head, team, self.team)); )
852 if(head.flags & FL_ITEM)
853 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
857 // make it a non-spawned item
859 head.state = 1; // state 1 = initially hidden item
861 head.effects &= ~EF_NODRAW;
868 // Savage: used for item garbage-collection
869 // TODO: perhaps nice special effect?
872 if(wasfreed(self) || !self) { return; }
873 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
877 // pickup evaluation functions
878 // these functions decide how desirable an item is to the bots
880 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
882 float weapon_pickupevalfunc(entity player, entity item)
886 // See if I have it already
887 if(item.weapons & ~player.weapons)
889 // If I can pick it up
890 if(!item.spawnshieldtime)
892 else if(player.ammo_cells || player.ammo_shells || player.ammo_plasma || player.ammo_nails || player.ammo_rockets)
894 // Skilled bots will grab more
895 c = bound(0, skill / 10, 1) * 0.5;
903 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
904 if( bot_custom_weapon && c )
906 // Find the highest position on any range
908 for (int j = 0; j < WEP_LAST ; ++j){
910 bot_weapons_far[j] == item.weapon ||
911 bot_weapons_mid[j] == item.weapon ||
912 bot_weapons_close[j] == item.weapon
923 position = WEP_LAST - position;
924 // item.bot_pickupbasevalue is overwritten here
925 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
929 return item.bot_pickupbasevalue * c;
932 float commodity_pickupevalfunc(entity player, entity item)
935 float need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
938 // Detect needed ammo
939 FOREACH(Weapons, it != WEP_Null, LAMBDA(
940 if(!(player.weapons & (it.m_wepset)))
943 if(it.items & ITEM_Shells.m_itemid)
945 else if(it.items & ITEM_Bullets.m_itemid)
947 else if(it.items & ITEM_Rockets.m_itemid)
949 else if(it.items & ITEM_Cells.m_itemid)
951 else if(it.items & ITEM_Plasma.m_itemid)
953 else if(it.items & ITEM_JetpackFuel.m_itemid)
957 // TODO: figure out if the player even has the weapon this ammo is for?
958 // may not affect strategy much though...
959 // find out how much more ammo/armor/health the player can hold
961 if (item.ammo_shells)
962 if (player.ammo_shells < g_pickup_shells_max)
963 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
966 if (player.ammo_nails < g_pickup_nails_max)
967 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
969 if (item.ammo_rockets)
970 if (player.ammo_rockets < g_pickup_rockets_max)
971 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
974 if (player.ammo_cells < g_pickup_cells_max)
975 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
977 if (item.ammo_plasma)
978 if (player.ammo_plasma < g_pickup_plasma_max)
979 c = c + max(0, 1 - player.ammo_plasma / g_pickup_plasma_max);
982 if (player.ammo_fuel < g_pickup_fuel_max)
983 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
985 if (player.armorvalue < item.max_armorvalue)
986 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
988 if (player.health < item.max_health)
989 c = c + max(0, 1 - player.health / item.max_health);
991 return item.bot_pickupbasevalue * c;
994 void Item_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
996 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1000 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
1002 string itemname = def.m_name;
1003 Model itemmodel = def.m_model;
1004 Sound pickupsound = def.m_sound;
1005 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
1006 float pickupbasevalue = def.m_botvalue;
1007 int itemflags = def.m_itemflags;
1009 startitem_failed = false;
1011 this.item_model_ent = itemmodel;
1012 this.item_pickupsound_ent = pickupsound;
1014 if(!this.respawntime) // both need to be set
1016 this.respawntime = defaultrespawntime;
1017 this.respawntimejitter = defaultrespawntimejitter;
1020 int itemid = def.m_itemid;
1021 this.items = itemid;
1022 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
1023 this.weapon = weaponid;
1027 this.fade_start = autocvar_g_items_mindist;
1028 this.fade_end = autocvar_g_items_maxdist;
1032 this.weapons = WepSet_FromWeapon(Weapons_from(weaponid));
1034 this.flags = FL_ITEM | itemflags;
1036 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
1038 startitem_failed = true;
1043 // is it a dropped weapon?
1044 if (this.classname == "droppedweapon")
1046 this.reset = SUB_Remove;
1047 // it's a dropped weapon
1048 this.movetype = MOVETYPE_TOSS;
1050 // Savage: remove thrown items after a certain period of time ("garbage collection")
1051 this.think = RemoveItem;
1052 this.nextthink = time + 20;
1054 this.takedamage = DAMAGE_YES;
1055 this.event_damage = Item_Damage;
1057 if(this.strength_finished || this.invincible_finished || this.superweapons_finished)
1059 // if item is worthless after a timer, have it expire then
1060 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
1063 // don't drop if in a NODROP zone (such as lava)
1064 traceline(this.origin, this.origin, MOVE_NORMAL, this);
1065 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1067 startitem_failed = true;
1074 if(!have_pickup_item(this))
1076 startitem_failed = true;
1081 if(this.angles != '0 0 0')
1082 this.SendFlags |= ISF_ANGLES;
1084 this.reset = Item_Reset;
1085 // it's a level item
1086 if(this.spawnflags & 1)
1088 if (this.noalign > 0)
1089 this.movetype = MOVETYPE_NONE;
1091 this.movetype = MOVETYPE_TOSS;
1092 // do item filtering according to game mode and other things
1093 if (this.noalign <= 0)
1095 // first nudge it off the floor a little bit to avoid math errors
1096 setorigin(this, this.origin + '0 0 1');
1097 // set item size before we spawn a spawnfunc_waypoint
1098 setsize(this, def.m_mins, def.m_maxs);
1099 this.SendFlags |= ISF_SIZE;
1100 // note droptofloor returns false if stuck/or would fall too far
1102 WITH(entity, self, this, droptofloor());
1103 waypoint_spawnforitem(this);
1107 * can't do it that way, as it would break maps
1108 * TODO make a target_give like entity another way, that perhaps has
1109 * the weapon name in a key
1112 // target_give not yet supported; maybe later
1113 print("removed targeted ", this.classname, "\n");
1114 startitem_failed = true;
1120 if(autocvar_spawn_debug >= 2)
1122 for(entity otheritem = findradius(this.origin, 3); otheritem; otheritem = otheritem.chain)
1124 // why not flags & fl_item?
1125 if(otheritem.is_item)
1127 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1128 LOG_TRACE(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1129 error("Mapper sucks.");
1132 this.is_item = true;
1135 weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid));
1137 precache_model(this.model);
1138 precache_sound(this.item_pickupsound);
1140 if ( def.instanceOfPowerup
1141 || def.instanceOfWeaponPickup
1142 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1143 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1144 || (itemid & (IT_KEY1 | IT_KEY2))
1145 ) this.target = "###item###"; // for finding the nearest item using find()
1147 Item_ItemsTime_SetTime(this, 0);
1150 this.bot_pickup = true;
1151 this.bot_pickupevalfunc = pickupevalfunc;
1152 this.bot_pickupbasevalue = pickupbasevalue;
1153 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1154 this.netname = itemname;
1155 this.touch = Item_Touch;
1156 setmodel(this, MDL_Null); // precision set below
1157 //this.effects |= EF_LOWPRECISION;
1159 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1161 this.SendFlags |= ISF_SIZE;
1163 if (!(this.spawnflags & 1024)) {
1164 if(def.instanceOfPowerup)
1165 this.ItemStatus |= ITS_ANIMATE1;
1167 if(this.armorvalue || this.health)
1168 this.ItemStatus |= ITS_ANIMATE2;
1171 if(def.instanceOfWeaponPickup)
1173 if (this.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1174 this.colormap = 1024; // color shirt=0 pants=0 grey
1177 if (!(this.spawnflags & 1024))
1178 this.ItemStatus |= ITS_ANIMATE1;
1179 this.ItemStatus |= ISF_COLORMAP;
1183 if(this.team) // broken, no idea why.
1186 this.cnt = 1; // item probability weight
1188 this.effects |= EF_NODRAW; // marker for item team search
1189 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1194 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1196 // call this hook after everything else has been done
1197 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1199 startitem_failed = true;
1205 void StartItem(entity this, GameItem def)
1210 def.m_respawntime(), // defaultrespawntime
1211 def.m_respawntimejitter() // defaultrespawntimejitter
1215 spawnfunc(item_rockets)
1217 if(!this.ammo_rockets)
1218 this.ammo_rockets = g_pickup_rockets;
1219 if(!this.pickup_anyway)
1220 this.pickup_anyway = g_pickup_ammo_anyway;
1221 StartItem(this, ITEM_Rockets);
1224 spawnfunc(item_bullets)
1227 if(autocvar_sv_q3acompat_machineshotgunswap)
1228 if(this.classname != "droppedweapon")
1230 weaponswapping = true;
1231 spawnfunc_item_shells(this);
1232 weaponswapping = false;
1236 if(!this.ammo_nails)
1237 this.ammo_nails = g_pickup_nails;
1238 if(!this.pickup_anyway)
1239 this.pickup_anyway = g_pickup_ammo_anyway;
1240 StartItem(this, ITEM_Bullets);
1243 spawnfunc(item_cells)
1245 if(!this.ammo_cells)
1246 this.ammo_cells = g_pickup_cells;
1247 if(!this.pickup_anyway)
1248 this.pickup_anyway = g_pickup_ammo_anyway;
1249 StartItem(this, ITEM_Cells);
1252 spawnfunc(item_plasma)
1254 if(!this.ammo_plasma)
1255 this.ammo_plasma = g_pickup_plasma;
1256 if(!this.pickup_anyway)
1257 this.pickup_anyway = g_pickup_ammo_anyway;
1258 StartItem(this, ITEM_Plasma);
1261 spawnfunc(item_shells)
1264 if(autocvar_sv_q3acompat_machineshotgunswap)
1265 if(this.classname != "droppedweapon")
1267 weaponswapping = true;
1268 spawnfunc_item_bullets(this);
1269 weaponswapping = false;
1273 if(!this.ammo_shells)
1274 this.ammo_shells = g_pickup_shells;
1275 if(!this.pickup_anyway)
1276 this.pickup_anyway = g_pickup_ammo_anyway;
1277 StartItem(this, ITEM_Shells);
1280 spawnfunc(item_armor_small)
1282 if(!this.armorvalue)
1283 this.armorvalue = g_pickup_armorsmall;
1284 if(!this.max_armorvalue)
1285 this.max_armorvalue = g_pickup_armorsmall_max;
1286 if(!this.pickup_anyway)
1287 this.pickup_anyway = g_pickup_armorsmall_anyway;
1288 StartItem(this, ITEM_ArmorSmall);
1291 spawnfunc(item_armor_medium)
1293 if(!this.armorvalue)
1294 this.armorvalue = g_pickup_armormedium;
1295 if(!this.max_armorvalue)
1296 this.max_armorvalue = g_pickup_armormedium_max;
1297 if(!this.pickup_anyway)
1298 this.pickup_anyway = g_pickup_armormedium_anyway;
1299 StartItem(this, ITEM_ArmorMedium);
1302 spawnfunc(item_armor_big)
1304 if(!this.armorvalue)
1305 this.armorvalue = g_pickup_armorbig;
1306 if(!this.max_armorvalue)
1307 this.max_armorvalue = g_pickup_armorbig_max;
1308 if(!this.pickup_anyway)
1309 this.pickup_anyway = g_pickup_armorbig_anyway;
1310 StartItem(this, ITEM_ArmorLarge);
1313 spawnfunc(item_armor_large)
1315 if(!this.armorvalue)
1316 this.armorvalue = g_pickup_armorlarge;
1317 if(!this.max_armorvalue)
1318 this.max_armorvalue = g_pickup_armorlarge_max;
1319 if(!this.pickup_anyway)
1320 this.pickup_anyway = g_pickup_armorlarge_anyway;
1321 StartItem(this, ITEM_ArmorMega);
1324 spawnfunc(item_health_small)
1326 if(!this.max_health)
1327 this.max_health = g_pickup_healthsmall_max;
1329 this.health = g_pickup_healthsmall;
1330 if(!this.pickup_anyway)
1331 this.pickup_anyway = g_pickup_healthsmall_anyway;
1332 StartItem(this, ITEM_HealthSmall);
1335 spawnfunc(item_health_medium)
1337 if(!this.max_health)
1338 this.max_health = g_pickup_healthmedium_max;
1340 this.health = g_pickup_healthmedium;
1341 if(!this.pickup_anyway)
1342 this.pickup_anyway = g_pickup_healthmedium_anyway;
1343 StartItem(this, ITEM_HealthMedium);
1346 spawnfunc(item_health_large)
1348 if(!this.max_health)
1349 this.max_health = g_pickup_healthlarge_max;
1351 this.health = g_pickup_healthlarge;
1352 if(!this.pickup_anyway)
1353 this.pickup_anyway = g_pickup_healthlarge_anyway;
1354 StartItem(this, ITEM_HealthLarge);
1357 spawnfunc(item_health_mega)
1359 if(!this.max_health)
1360 this.max_health = g_pickup_healthmega_max;
1362 this.health = g_pickup_healthmega;
1363 if(!this.pickup_anyway)
1364 this.pickup_anyway = g_pickup_healthmega_anyway;
1365 StartItem(this, ITEM_HealthMega);
1368 // support old misnamed entities
1369 spawnfunc(item_armor1) { spawnfunc_item_armor_small(this); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1370 spawnfunc(item_armor25) { spawnfunc_item_armor_large(this); }
1371 spawnfunc(item_health1) { spawnfunc_item_health_small(this); }
1372 spawnfunc(item_health25) { spawnfunc_item_health_medium(this); }
1373 spawnfunc(item_health100) { spawnfunc_item_health_mega(this); }
1375 spawnfunc(item_strength)
1377 if(!this.strength_finished)
1378 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1379 StartItem(this, ITEM_Strength);
1382 spawnfunc(item_invincible)
1384 if(!this.invincible_finished)
1385 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1386 StartItem(this, ITEM_Shield);
1390 spawnfunc(item_quad) { this.classname = "item_strength";spawnfunc_item_strength(this);}
1392 void target_items_use()
1394 if(activator.classname == "droppedweapon")
1401 if (!IS_PLAYER(activator))
1403 if(activator.deadflag != DEAD_NO)
1408 for(e = world; (e = find(e, classname, "droppedweapon")); )
1409 if(e.enemy == activator)
1412 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1413 centerprint(activator, self.message);
1416 spawnfunc(target_items)
1421 self.use = target_items_use;
1422 if(!self.strength_finished)
1423 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1424 if(!self.invincible_finished)
1425 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1426 if(!self.superweapons_finished)
1427 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1429 n = tokenize_console(self.netname);
1430 if(argv(0) == "give")
1432 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1436 for(i = 0; i < n; ++i)
1438 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1439 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1440 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1441 else if(argv(i) == "strength") self.items |= ITEM_Strength.m_itemid;
1442 else if(argv(i) == "invincible") self.items |= ITEM_Shield.m_itemid;
1443 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1444 else if(argv(i) == "jetpack") self.items |= ITEM_Jetpack.m_itemid;
1445 else if(argv(i) == "fuel_regen") self.items |= ITEM_JetpackRegen.m_itemid;
1448 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1449 s = W_UndeprecateName(argv(i));
1452 self.weapons |= (it.m_wepset);
1453 if(self.spawnflags == 0 || self.spawnflags == 2)
1461 string itemprefix, valueprefix;
1462 if(self.spawnflags == 0)
1467 else if(self.spawnflags == 1)
1469 itemprefix = "max ";
1470 valueprefix = "max ";
1472 else if(self.spawnflags == 2)
1474 itemprefix = "min ";
1475 valueprefix = "min ";
1477 else if(self.spawnflags == 4)
1479 itemprefix = "minus ";
1480 valueprefix = "max ";
1484 error("invalid spawnflags");
1485 itemprefix = valueprefix = string_null;
1489 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1490 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1491 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * boolean(self.items & ITEM_Strength.m_itemid), "strength");
1492 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * boolean(self.items & ITEM_Shield.m_itemid), "invincible");
1493 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * boolean(self.items & IT_SUPERWEAPON), "superweapons");
1494 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & ITEM_Jetpack.m_itemid), "jetpack");
1495 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1496 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1497 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1498 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1499 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1500 if(self.ammo_plasma != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_plasma), "plasma");
1501 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1502 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1503 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1504 FOREACH(Weapons, it != WEP_Null, LAMBDA(self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & (it.m_wepset)), it.netname)));
1506 self.netname = strzone(self.netname);
1507 //print(self.netname, "\n");
1509 n = tokenize_console(self.netname);
1510 for(i = 0; i < n; ++i)
1512 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1513 if(argv(i) == it.netname)
1522 spawnfunc(item_fuel)
1525 this.ammo_fuel = g_pickup_fuel;
1526 if(!this.pickup_anyway)
1527 this.pickup_anyway = g_pickup_ammo_anyway;
1528 StartItem(this, ITEM_JetpackFuel);
1531 spawnfunc(item_fuel_regen)
1533 if(start_items & ITEM_JetpackRegen.m_itemid)
1535 spawnfunc_item_fuel(this);
1538 StartItem(this, ITEM_JetpackRegen);
1541 spawnfunc(item_jetpack)
1544 this.ammo_fuel = g_pickup_fuel_jetpack;
1545 if(start_items & ITEM_Jetpack.m_itemid)
1547 spawnfunc_item_fuel(this);
1550 StartItem(this, ITEM_Jetpack);
1553 float GiveWeapon(entity e, float wpn, float op, float val)
1556 WepSet s = WepSet_FromWeapon(Weapons_from(wpn));
1557 v0 = (e.weapons & s);
1580 v1 = (e.weapons & s);
1584 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
1591 _sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1593 else if(v0 >= v0 + t)
1596 _sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1600 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1603 e.(rotfield) = max(e.(rotfield), time + rottime);
1605 e.(regenfield) = max(e.(regenfield), time + regentime);
1607 float GiveItems(entity e, float beginarg, float endarg)
1609 float got, i, val, op;
1610 float _switchweapon;
1618 _switchweapon = false;
1620 if (PS(e).m_switchweapon == w_getbestweapon(e))
1621 _switchweapon = true;
1623 e.strength_finished = max(0, e.strength_finished - time);
1624 e.invincible_finished = max(0, e.invincible_finished - time);
1625 e.superweapons_finished = max(0, e.superweapons_finished - time);
1629 PREGIVE(e, strength_finished);
1630 PREGIVE(e, invincible_finished);
1631 PREGIVE(e, superweapons_finished);
1632 PREGIVE(e, ammo_nails);
1633 PREGIVE(e, ammo_cells);
1634 PREGIVE(e, ammo_plasma);
1635 PREGIVE(e, ammo_shells);
1636 PREGIVE(e, ammo_rockets);
1637 PREGIVE(e, ammo_fuel);
1638 PREGIVE(e, armorvalue);
1641 for(i = beginarg; i < endarg; ++i)
1645 if(cmd == "0" || stof(cmd))
1669 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1670 got += GiveValue(e, strength_finished, op, val);
1671 got += GiveValue(e, invincible_finished, op, val);
1672 got += GiveValue(e, superweapons_finished, op, val);
1673 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1675 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1676 got += GiveValue(e, health, op, val);
1677 got += GiveValue(e, armorvalue, op, val);
1679 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1680 if(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED))
1681 got += GiveWeapon(e, it.m_id, op, val);
1684 got += GiveValue(e, ammo_cells, op, val);
1685 got += GiveValue(e, ammo_plasma, op, val);
1686 got += GiveValue(e, ammo_shells, op, val);
1687 got += GiveValue(e, ammo_nails, op, val);
1688 got += GiveValue(e, ammo_rockets, op, val);
1689 got += GiveValue(e, ammo_fuel, op, val);
1691 case "unlimited_ammo":
1692 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1694 case "unlimited_weapon_ammo":
1695 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1697 case "unlimited_superweapons":
1698 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1701 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1704 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1707 got += GiveValue(e, strength_finished, op, val);
1710 got += GiveValue(e, invincible_finished, op, val);
1712 case "superweapons":
1713 got += GiveValue(e, superweapons_finished, op, val);
1716 got += GiveValue(e, ammo_cells, op, val);
1719 got += GiveValue(e, ammo_plasma, op, val);
1722 got += GiveValue(e, ammo_shells, op, val);
1726 got += GiveValue(e, ammo_nails, op, val);
1729 got += GiveValue(e, ammo_rockets, op, val);
1732 got += GiveValue(e, health, op, val);
1735 got += GiveValue(e, armorvalue, op, val);
1738 got += GiveValue(e, ammo_fuel, op, val);
1741 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1742 if(cmd == it.netname)
1744 got += GiveWeapon(e, it.m_id, op, val);
1754 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND(ITEMPICKUP), string_null);
1755 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND(POWERUP), SND(POWEROFF));
1756 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND(POWERUP), SND(POWEROFF));
1757 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND(ITEMPICKUP), string_null);
1758 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1759 POSTGIVE_WEAPON(e, it, SND(WEAPONPICKUP), string_null);
1760 if(!(save_weapons & (it.m_wepset)))
1761 if(e.weapons & (it.m_wepset))
1764 POSTGIVE_VALUE(e, strength_finished, 1, SND(POWERUP), SND(POWEROFF));
1765 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", SND(POWEROFF));
1766 POSTGIVE_VALUE(e, ammo_nails, 0, SND(ITEMPICKUP), string_null);
1767 POSTGIVE_VALUE(e, ammo_cells, 0, SND(ITEMPICKUP), string_null);
1768 POSTGIVE_VALUE(e, ammo_plasma, 0, SND(ITEMPICKUP), string_null);
1769 POSTGIVE_VALUE(e, ammo_shells, 0, SND(ITEMPICKUP), string_null);
1770 POSTGIVE_VALUE(e, ammo_rockets, 0, SND(ITEMPICKUP), string_null);
1771 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), string_null);
1772 POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND(ARMOR25), string_null);
1773 POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND(MEGAHEALTH), string_null);
1775 if(e.superweapons_finished <= 0)
1776 if(self.weapons & WEPSET_SUPERWEAPONS)
1777 e.superweapons_finished = autocvar_g_balance_superweapons_time;
1779 if(e.strength_finished <= 0)
1780 e.strength_finished = 0;
1782 e.strength_finished += time;
1783 if(e.invincible_finished <= 0)
1784 e.invincible_finished = 0;
1786 e.invincible_finished += time;
1787 if(e.superweapons_finished <= 0)
1788 e.superweapons_finished = 0;
1790 e.superweapons_finished += time;
1792 if (!(e.weapons & WepSet_FromWeapon(PS(e).m_switchweapon)))
1793 _switchweapon = true;
1795 W_SwitchWeapon_Force(e, w_getbestweapon(e));