3 #include "items/all.qc"
7 #include "../server/bot/bot.qh"
8 #include "../server/bot/waypoints.qh"
10 #include <server/mutators/all.qh>
12 #include "../server/weapons/common.qh"
13 #include "../server/weapons/selection.qh"
14 #include "../server/weapons/weaponsystem.qh"
16 #include "constants.qh"
17 #include <common/deathtypes/all.qh>
18 #include <common/notifications.qh>
19 #include "triggers/subs.qh"
22 #include <common/monsters/all.qh>
24 #include <common/weapons/all.qh>
26 #include "../lib/warpzone/util_server.qh"
28 #include "physics/movetypes/movetypes.qh"
29 #include <common/weapons/all.qh>
30 #include "../lib/csqcmodel/cl_model.qh"
31 #include "../lib/csqcmodel/common.qh"
34 REGISTER_NET_LINKED(ENT_CLIENT_ITEM)
37 bool autocvar_cl_ghost_items_vehicle = true;
38 void Item_SetAlpha(entity this)
40 bool veh_hud = (hud && autocvar_cl_ghost_items_vehicle);
42 if(!veh_hud && (this.ItemStatus & ITS_AVAILABLE))
45 this.colormod = this.glowmod = '1 1 1';
49 if (autocvar_cl_ghost_items_color)
51 this.alpha = autocvar_cl_ghost_items;
52 this.colormod = this.glowmod = autocvar_cl_ghost_items_color;
59 if(this.ItemStatus & ITS_STAYWEP)
61 this.colormod = this.glowmod = autocvar_cl_weapon_stay_color;
62 this.alpha = autocvar_cl_weapon_stay_alpha;
66 void ItemDraw(entity this)
70 Movetype_Physics_MatchServer(this, false);
71 if(this.move_flags & FL_ONGROUND)
72 { // For some reason move_avelocity gets set to '0 0 0' here ...
73 this.oldorigin = this.origin;
76 if(autocvar_cl_animate_items)
77 { // ... so reset it if animations are requested.
78 if(this.ItemStatus & ITS_ANIMATE1)
79 this.move_avelocity = '0 180 0';
81 if(this.ItemStatus & ITS_ANIMATE2)
82 this.move_avelocity = '0 -90 0';
86 else if (autocvar_cl_animate_items)
88 if(this.ItemStatus & ITS_ANIMATE1)
90 this.angles += this.move_avelocity * frametime;
91 setorigin(this, '0 0 10' + this.oldorigin + '0 0 8' * sin(time * 2));
94 if(this.ItemStatus & ITS_ANIMATE2)
96 this.angles += this.move_avelocity * frametime;
97 setorigin(this, '0 0 8' + this.oldorigin + '0 0 4' * sin(time * 3));
104 void ItemDrawSimple(entity this)
108 Movetype_Physics_MatchServer(this, false);
110 if(this.move_flags & FL_ONGROUND)
117 if(warpzone_warpzones_exist)
119 // just incase warpzones were initialized last, reset these
121 self.drawmask = MASK_NORMAL;
125 vector org = getpropertyvec(VF_ORIGIN);
126 if(!checkpvs(org, self)) // this makes sense as long as we don't support recursive warpzones
128 else if(self.fade_start)
129 alph = bound(0, (self.fade_end - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) / (self.fade_end - self.fade_start), 1);
132 //printf("%v <-> %v\n", view_origin, self.origin + 0.5 * (self.mins + self.maxs));
133 if(!hud && (self.ItemStatus & ITS_AVAILABLE))
138 self.drawmask = MASK_NORMAL;
147 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
151 if(sf & ISF_LOCATION)
153 self.origin_x = ReadCoord();
154 self.origin_y = ReadCoord();
155 self.origin_z = ReadCoord();
156 setorigin(self, self.origin);
157 self.oldorigin = self.origin;
162 self.angles_x = ReadAngle();
163 self.angles_y = ReadAngle();
164 self.angles_z = ReadAngle();
165 self.move_angles = self.angles;
170 float use_bigsize = ReadByte();
171 setsize(self, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
174 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
176 self.ItemStatus = ReadByte();
180 if(autocvar_cl_fullbright_items)
181 if(self.ItemStatus & ITS_ALLOWFB)
182 self.effects |= EF_FULLBRIGHT;
184 if(self.ItemStatus & ITS_POWERUP)
186 if(self.ItemStatus & ITS_AVAILABLE)
187 self.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
189 self.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
195 self.drawmask = MASK_NORMAL;
196 self.move_movetype = MOVETYPE_TOSS;
197 self.draw = ItemDraw;
198 self.solid = SOLID_TRIGGER;
199 //self.move_flags |= FL_ITEM;
201 bool use_bigsize = ReadByte();
203 self.fade_end = ReadShort();
204 self.fade_start = ReadShort();
205 if(self.fade_start && !autocvar_cl_items_nofade)
206 self.predraw = Item_PreDraw;
212 string _fn = ReadString();
214 if(autocvar_cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
216 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
217 self.draw = ItemDrawSimple;
219 if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
220 self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
221 else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
222 self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
223 else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
224 self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
225 else if(fexists(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix)))
226 self.mdl = strzone(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix));
229 self.draw = ItemDraw;
230 LOG_TRACE("Simple item requested for ", _fn, " but no model exists for it\n");
234 if(self.draw != ItemDrawSimple)
235 self.mdl = strzone(_fn);
239 LOG_TRACE("^1WARNING!^7 self.mdl is unset for item ", self.classname, ", tell tZork about this!\n");
241 precache_model(self.mdl);
242 _setmodel(self, self.mdl);
244 setsize(self, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
247 if(sf & ISF_COLORMAP)
248 self.colormap = ReadShort();
253 self.pushable = true;
254 //self.move_angles = '0 0 0';
255 self.move_movetype = MOVETYPE_TOSS;
256 self.move_velocity_x = ReadCoord();
257 self.move_velocity_y = ReadCoord();
258 self.move_velocity_z = ReadCoord();
259 self.velocity = self.move_velocity;
260 self.move_origin = self.oldorigin;
264 self.move_time = time;
265 self.spawntime = time;
268 self.move_time = max(self.move_time, time);
271 if(autocvar_cl_animate_items)
273 if(self.ItemStatus & ITS_ANIMATE1)
274 self.move_avelocity = '0 180 0';
276 if(self.ItemStatus & ITS_ANIMATE2)
277 self.move_avelocity = '0 -90 0';
280 self.entremove = ItemRemove;
288 bool ItemSend(entity this, entity to, int sf)
295 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
296 WriteByte(MSG_ENTITY, sf);
298 //WriteByte(MSG_ENTITY, self.cnt);
299 if(sf & ISF_LOCATION)
301 WriteCoord(MSG_ENTITY, self.origin.x);
302 WriteCoord(MSG_ENTITY, self.origin.y);
303 WriteCoord(MSG_ENTITY, self.origin.z);
308 WriteAngle(MSG_ENTITY, self.angles_x);
309 WriteAngle(MSG_ENTITY, self.angles_y);
310 WriteAngle(MSG_ENTITY, self.angles_z);
315 Pickup p = this.itemdef;
316 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
320 WriteByte(MSG_ENTITY, self.ItemStatus);
324 Pickup p = this.itemdef;
325 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
326 WriteShort(MSG_ENTITY, self.fade_end);
327 WriteShort(MSG_ENTITY, self.fade_start);
330 LOG_TRACE("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n");
332 WriteString(MSG_ENTITY, self.mdl);
336 if(sf & ISF_COLORMAP)
337 WriteShort(MSG_ENTITY, self.colormap);
341 WriteCoord(MSG_ENTITY, self.velocity.x);
342 WriteCoord(MSG_ENTITY, self.velocity.y);
343 WriteCoord(MSG_ENTITY, self.velocity.z);
349 void ItemUpdate(entity this)
351 this.oldorigin = this.origin;
352 this.SendFlags |= ISF_LOCATION;
355 void UpdateItemAfterTeleport(entity this)
357 if(this.SendEntity3 == ItemSend)
361 bool have_pickup_item(entity this)
363 if(this.itemdef.instanceOfPowerup)
365 if(autocvar_g_powerups > 0)
367 if(autocvar_g_powerups == 0)
372 if(autocvar_g_pickup_items > 0)
374 if(autocvar_g_pickup_items == 0)
377 if(this.weapons || (this.items & IT_AMMO)) // no item or ammo pickups in weaponarena
384 float Item_Customize()
386 if(self.spawnshieldtime)
388 if(self.weapons & ~other.weapons)
390 self.colormod = '0 0 0';
391 self.glowmod = self.colormod;
392 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
399 self.colormod = stov(autocvar_g_ghost_items_color);
400 self.glowmod = self.colormod;
401 self.alpha = g_ghost_items;
410 void Item_Show (entity e, float mode)
412 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
413 e.ItemStatus &= ~ITS_STAYWEP;
416 // make the item look normal, and be touchable
418 e.solid = SOLID_TRIGGER;
419 e.spawnshieldtime = 1;
420 e.ItemStatus |= ITS_AVAILABLE;
424 // hide the item completely
425 e.model = string_null;
427 e.spawnshieldtime = 1;
428 e.ItemStatus &= ~ITS_AVAILABLE;
431 entity def = e.itemdef;
432 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.weapons & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
433 || e.team // weapon stay isn't supported for teamed weapons
435 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
437 // make the item translucent and not touchable
439 e.solid = SOLID_TRIGGER; // can STILL be picked up!
440 e.effects |= EF_STARDUST;
441 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
442 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
446 //setmodel(e, "null");
448 e.colormod = '0 0 0';
449 e.glowmod = e.colormod;
450 e.spawnshieldtime = 1;
451 e.ItemStatus &= ~ITS_AVAILABLE;
454 if (e.items & ITEM_Strength.m_itemid || e.items & ITEM_Shield.m_itemid)
455 e.ItemStatus |= ITS_POWERUP;
457 if (autocvar_g_nodepthtestitems)
458 e.effects |= EF_NODEPTHTEST;
461 if (autocvar_g_fullbrightitems)
462 e.ItemStatus |= ITS_ALLOWFB;
464 if (autocvar_sv_simple_items)
465 e.ItemStatus |= ITS_ALLOWSI;
467 // relink entity (because solid may have changed)
468 setorigin(e, e.origin);
469 e.SendFlags |= ISF_STATUS;
474 self.nextthink = time;
475 if(self.origin != self.oldorigin)
479 bool Item_ItemsTime_SpectatorOnly(GameItem it);
480 bool Item_ItemsTime_Allow(GameItem it, WepSet _weapons);
481 float Item_ItemsTime_UpdateTime(entity e, float t);
482 void Item_ItemsTime_SetTime(entity e, float t);
483 void Item_ItemsTime_SetTimesForAllPlayers();
489 if(self.items == ITEM_Strength.m_itemid)
490 sound (self, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
491 else if(self.items == ITEM_Shield.m_itemid)
492 sound (self, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
494 sound (self, CH_TRIGGER, SND_ITEMRESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
495 setorigin (self, self.origin);
497 if (Item_ItemsTime_Allow(self.itemdef, self.weapons))
499 float t = Item_ItemsTime_UpdateTime(self, 0);
500 Item_ItemsTime_SetTime(self, t);
501 Item_ItemsTime_SetTimesForAllPlayers();
504 self.think = Item_Think;
505 self.nextthink = time;
507 //Send_Effect(EFFECT_ITEM_RESPAWN, self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
508 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
511 void Item_RespawnCountdown ()
513 if(self.count >= ITEM_RESPAWN_TICKS)
515 if(self.waypointsprite_attached)
516 WaypointSprite_Kill(self.waypointsprite_attached);
521 self.nextthink = time + 1;
525 MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0');
528 entity wi = Weapons_from(self.weapon);
529 if (wi != WEP_Null) {
530 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Weapon);
531 wp.wp_extra = wi.m_id;
536 entity ii = self.itemdef;
538 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Item);
539 wp.wp_extra = ii.m_id;
544 if(self.waypointsprite_attached)
546 GameItem def = self.itemdef;
547 if (Item_ItemsTime_SpectatorOnly(def))
548 WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
549 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
553 if(self.waypointsprite_attached)
555 setself(self.waypointsprite_attached);
556 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
557 if(self.waypointsprite_visible_for_player(it))
560 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM); // play respawn sound
565 WaypointSprite_Ping(self.waypointsprite_attached);
566 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
571 void Item_RespawnThink()
573 self.nextthink = time;
574 if(self.origin != self.oldorigin)
577 if(time >= self.wait)
581 void Item_ScheduleRespawnIn(entity e, float t)
583 if (Item_ItemsTime_Allow(e.itemdef, e.weapons))
585 e.think = Item_RespawnCountdown;
586 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
587 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
589 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
590 Item_ItemsTime_SetTime(e, t);
591 Item_ItemsTime_SetTimesForAllPlayers();
595 e.think = Item_RespawnThink;
597 e.scheduledrespawntime = time + t;
602 void Item_ScheduleRespawn(entity e)
604 if(e.respawntime > 0)
607 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
609 else // if respawntime is -1, this item does not respawn
613 void Item_ScheduleInitialRespawn(entity e)
616 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
619 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
621 if (!item.(ammotype))
624 if (item.spawnshieldtime)
626 if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0)
628 player.(ammotype) = bound(player.(ammotype), ammomax, player.(ammotype) + item.(ammotype));
632 else if(g_weapon_stay == 2)
634 float mi = min(item.(ammotype), ammomax);
635 if (player.(ammotype) < mi)
637 player.(ammotype) = mi;
648 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
650 case ITEM_MODE_HEALTH:
651 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
653 case ITEM_MODE_ARMOR:
654 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
662 float Item_GiveTo(entity item, entity player)
667 // if nothing happens to player, just return without taking the item
669 _switchweapon = false;
670 // in case the player has autoswitch enabled do the following:
671 // if the player is using their best weapon before items are given, they
672 // probably want to switch to an even better weapon after items are given
673 if (player.autoswitch)
674 if (PS(player).m_switchweapon == w_getbestweapon(player))
675 _switchweapon = true;
677 if (!(player.weapons & WepSet_FromWeapon(PS(player).m_switchweapon)))
678 _switchweapon = true;
680 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
681 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
682 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
683 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
684 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
685 pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max, ITEM_MODE_NONE);
686 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
687 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
689 if (item.itemdef.instanceOfWeaponPickup)
693 w &= ~player.weapons;
695 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
698 FOREACH(Weapons, it != WEP_Null, LAMBDA(
699 if(w & (it.m_wepset))
701 W_DropEvent(wr_pickup, player, it.m_id, item);
702 W_GiveWeapon(player, it.m_id);
709 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
713 Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
716 if (item.strength_finished)
719 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
721 if (item.invincible_finished)
724 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
726 if (item.superweapons_finished)
729 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
734 // always eat teamed entities
741 // crude hack to enforce switching weapons
742 if(g_cts && item.itemdef.instanceOfWeaponPickup)
744 W_SwitchWeapon_Force(player, Weapons_from(item.weapon));
749 if (PS(player).m_switchweapon != w_getbestweapon(player))
750 W_SwitchWeapon_Force(player, w_getbestweapon(player));
759 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
760 if (this.classname == "droppedweapon")
762 if (ITEM_TOUCH_NEEDKILL())
769 if(!(other.flags & FL_PICKUPITEMS)
772 || (this.solid != SOLID_TRIGGER)
773 || (this.owner == other)
774 || (time < this.item_spawnshieldtime)
777 switch (MUTATOR_CALLHOOK(ItemTouch, this, other))
779 case MUT_ITEMTOUCH_RETURN: { return; }
780 case MUT_ITEMTOUCH_PICKUP: { goto pickup; }
783 if (this.classname == "droppedweapon")
785 this.strength_finished = max(0, this.strength_finished - time);
786 this.invincible_finished = max(0, this.invincible_finished - time);
787 this.superweapons_finished = max(0, this.superweapons_finished - time);
789 entity it = this.itemdef;
790 bool gave = ITEM_HANDLE(Pickup, it, this, other);
793 if (this.classname == "droppedweapon")
795 // undo what we did above
796 this.strength_finished += time;
797 this.invincible_finished += time;
798 this.superweapons_finished += time;
805 other.last_pickup = time;
807 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
808 _sound (other, CH_TRIGGER, (this.item_pickupsound ? this.item_pickupsound : Sound_fixpath(this.item_pickupsound_ent)), VOL_BASE, ATTEN_NORM);
810 if (this.classname == "droppedweapon")
812 else if (this.spawnshieldtime)
817 RandomSelection_Init();
818 for(entity head = world; (head = findfloat(head, team, this.team)); )
820 if(head.flags & FL_ITEM)
821 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
824 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
827 e = RandomSelection_chosen_ent;
832 Item_ScheduleRespawn(e);
836 void Item_Reset(entity this)
838 Item_Show(this, !this.state);
839 setorigin(this, this.origin);
841 if (this.classname != "droppedweapon")
843 this.think = Item_Think;
844 this.nextthink = time;
846 if (this.waypointsprite_attached)
847 WaypointSprite_Kill(this.waypointsprite_attached);
849 if (this.itemdef.instanceOfPowerup || (this.weapons & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
850 Item_ScheduleInitialRespawn(this);
853 void Item_Reset_self() { SELFPARAM(); Item_Reset(this); }
859 if(self.effects & EF_NODRAW)
861 // marker for item team search
862 LOG_TRACE("Initializing item team ", ftos(self.team), "\n");
863 RandomSelection_Init();
864 for(head = world; (head = findfloat(head, team, self.team)); )
865 if(head.flags & FL_ITEM)
866 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
867 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
868 e = RandomSelection_chosen_ent;
872 for(head = world; (head = findfloat(head, team, self.team)); )
873 if(head.flags & FL_ITEM)
874 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
878 // make it a non-spawned item
880 head.state = 1; // state 1 = initially hidden item
882 head.effects &= ~EF_NODRAW;
889 // Savage: used for item garbage-collection
890 // TODO: perhaps nice special effect?
893 if(wasfreed(self) || !self) { return; }
894 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
898 // pickup evaluation functions
899 // these functions decide how desirable an item is to the bots
901 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
903 float weapon_pickupevalfunc(entity player, entity item)
907 // See if I have it already
908 if(item.weapons & ~player.weapons)
910 // If I can pick it up
911 if(!item.spawnshieldtime)
913 else if(player.ammo_cells || player.ammo_shells || player.ammo_plasma || player.ammo_nails || player.ammo_rockets)
915 // Skilled bots will grab more
916 c = bound(0, skill / 10, 1) * 0.5;
924 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
925 if( bot_custom_weapon && c )
927 // Find the highest position on any range
929 for (int j = 0; j < WEP_LAST ; ++j){
931 bot_weapons_far[j] == item.weapon ||
932 bot_weapons_mid[j] == item.weapon ||
933 bot_weapons_close[j] == item.weapon
944 position = WEP_LAST - position;
945 // item.bot_pickupbasevalue is overwritten here
946 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
950 return item.bot_pickupbasevalue * c;
953 float commodity_pickupevalfunc(entity player, entity item)
956 float need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
959 // Detect needed ammo
960 FOREACH(Weapons, it != WEP_Null, LAMBDA(
961 if(!(player.weapons & (it.m_wepset)))
964 if(it.items & ITEM_Shells.m_itemid)
966 else if(it.items & ITEM_Bullets.m_itemid)
968 else if(it.items & ITEM_Rockets.m_itemid)
970 else if(it.items & ITEM_Cells.m_itemid)
972 else if(it.items & ITEM_Plasma.m_itemid)
974 else if(it.items & ITEM_JetpackFuel.m_itemid)
978 // TODO: figure out if the player even has the weapon this ammo is for?
979 // may not affect strategy much though...
980 // find out how much more ammo/armor/health the player can hold
982 if (item.ammo_shells)
983 if (player.ammo_shells < g_pickup_shells_max)
984 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
987 if (player.ammo_nails < g_pickup_nails_max)
988 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
990 if (item.ammo_rockets)
991 if (player.ammo_rockets < g_pickup_rockets_max)
992 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
995 if (player.ammo_cells < g_pickup_cells_max)
996 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
998 if (item.ammo_plasma)
999 if (player.ammo_plasma < g_pickup_plasma_max)
1000 c = c + max(0, 1 - player.ammo_plasma / g_pickup_plasma_max);
1003 if (player.ammo_fuel < g_pickup_fuel_max)
1004 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
1005 if (item.armorvalue)
1006 if (player.armorvalue < item.max_armorvalue)
1007 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
1009 if (player.health < item.max_health)
1010 c = c + max(0, 1 - player.health / item.max_health);
1012 return item.bot_pickupbasevalue * c;
1015 void Item_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
1017 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1021 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
1023 string itemname = def.m_name;
1024 Model itemmodel = def.m_model;
1025 Sound pickupsound = def.m_sound;
1026 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
1027 float pickupbasevalue = def.m_botvalue;
1028 int itemflags = def.m_itemflags;
1030 startitem_failed = false;
1032 this.item_model_ent = itemmodel;
1033 this.item_pickupsound_ent = pickupsound;
1035 if(!this.respawntime) // both need to be set
1037 this.respawntime = defaultrespawntime;
1038 this.respawntimejitter = defaultrespawntimejitter;
1041 int itemid = def.m_itemid;
1042 this.items = itemid;
1043 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
1044 this.weapon = weaponid;
1048 this.fade_start = autocvar_g_items_mindist;
1049 this.fade_end = autocvar_g_items_maxdist;
1053 this.weapons = WepSet_FromWeapon(Weapons_from(weaponid));
1055 this.flags = FL_ITEM | itemflags;
1057 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
1059 startitem_failed = true;
1064 // is it a dropped weapon?
1065 if (this.classname == "droppedweapon")
1067 this.reset = SUB_Remove;
1068 // it's a dropped weapon
1069 this.movetype = MOVETYPE_TOSS;
1071 // Savage: remove thrown items after a certain period of time ("garbage collection")
1072 this.think = RemoveItem;
1073 this.nextthink = time + 20;
1075 this.takedamage = DAMAGE_YES;
1076 this.event_damage = Item_Damage;
1078 if(this.strength_finished || this.invincible_finished || this.superweapons_finished)
1080 // if item is worthless after a timer, have it expire then
1081 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
1084 // don't drop if in a NODROP zone (such as lava)
1085 traceline(this.origin, this.origin, MOVE_NORMAL, this);
1086 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1088 startitem_failed = true;
1095 if(!have_pickup_item(this))
1097 startitem_failed = true;
1102 if(this.angles != '0 0 0')
1103 this.SendFlags |= ISF_ANGLES;
1105 this.reset = Item_Reset;
1106 // it's a level item
1107 if(this.spawnflags & 1)
1109 if (this.noalign > 0)
1110 this.movetype = MOVETYPE_NONE;
1112 this.movetype = MOVETYPE_TOSS;
1113 // do item filtering according to game mode and other things
1114 if (this.noalign <= 0)
1116 // first nudge it off the floor a little bit to avoid math errors
1117 setorigin(this, this.origin + '0 0 1');
1118 // set item size before we spawn a spawnfunc_waypoint
1119 setsize(this, def.m_mins, def.m_maxs);
1120 this.SendFlags |= ISF_SIZE;
1121 // note droptofloor returns false if stuck/or would fall too far
1123 WITH(entity, self, this, droptofloor());
1124 waypoint_spawnforitem(this);
1128 * can't do it that way, as it would break maps
1129 * TODO make a target_give like entity another way, that perhaps has
1130 * the weapon name in a key
1133 // target_give not yet supported; maybe later
1134 print("removed targeted ", this.classname, "\n");
1135 startitem_failed = true;
1141 if(autocvar_spawn_debug >= 2)
1143 for(entity otheritem = findradius(this.origin, 3); otheritem; otheritem = otheritem.chain)
1145 // why not flags & fl_item?
1146 if(otheritem.is_item)
1148 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1149 LOG_TRACE(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1150 error("Mapper sucks.");
1153 this.is_item = true;
1156 weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid));
1158 precache_model(this.model);
1159 precache_sound(this.item_pickupsound);
1161 if ( def.instanceOfPowerup
1162 || def.instanceOfWeaponPickup
1163 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1164 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1165 || (itemid & (IT_KEY1 | IT_KEY2))
1166 ) this.target = "###item###"; // for finding the nearest item using find()
1168 Item_ItemsTime_SetTime(this, 0);
1171 this.bot_pickup = true;
1172 this.bot_pickupevalfunc = pickupevalfunc;
1173 this.bot_pickupbasevalue = pickupbasevalue;
1174 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1175 this.netname = itemname;
1176 this.touch = Item_Touch;
1177 setmodel(this, MDL_Null); // precision set below
1178 //this.effects |= EF_LOWPRECISION;
1180 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1182 this.SendFlags |= ISF_SIZE;
1184 if (!(this.spawnflags & 1024)) {
1185 if(def.instanceOfPowerup)
1186 this.ItemStatus |= ITS_ANIMATE1;
1188 if(this.armorvalue || this.health)
1189 this.ItemStatus |= ITS_ANIMATE2;
1192 if(def.instanceOfWeaponPickup)
1194 if (this.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1195 this.colormap = 1024; // color shirt=0 pants=0 grey
1198 if (!(this.spawnflags & 1024))
1199 this.ItemStatus |= ITS_ANIMATE1;
1200 this.ItemStatus |= ISF_COLORMAP;
1204 if(this.team) // broken, no idea why.
1207 this.cnt = 1; // item probability weight
1209 this.effects |= EF_NODRAW; // marker for item team search
1210 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1215 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1217 // call this hook after everything else has been done
1218 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1220 startitem_failed = true;
1226 void StartItem(entity this, GameItem def)
1231 def.m_respawntime(), // defaultrespawntime
1232 def.m_respawntimejitter() // defaultrespawntimejitter
1236 spawnfunc(item_rockets)
1238 if(!this.ammo_rockets)
1239 this.ammo_rockets = g_pickup_rockets;
1240 if(!this.pickup_anyway)
1241 this.pickup_anyway = g_pickup_ammo_anyway;
1242 StartItem(this, ITEM_Rockets);
1245 spawnfunc(item_bullets)
1248 if(autocvar_sv_q3acompat_machineshotgunswap)
1249 if(this.classname != "droppedweapon")
1251 weaponswapping = true;
1252 spawnfunc_item_shells(this);
1253 weaponswapping = false;
1257 if(!this.ammo_nails)
1258 this.ammo_nails = g_pickup_nails;
1259 if(!this.pickup_anyway)
1260 this.pickup_anyway = g_pickup_ammo_anyway;
1261 StartItem(this, ITEM_Bullets);
1264 spawnfunc(item_cells)
1266 if(!this.ammo_cells)
1267 this.ammo_cells = g_pickup_cells;
1268 if(!this.pickup_anyway)
1269 this.pickup_anyway = g_pickup_ammo_anyway;
1270 StartItem(this, ITEM_Cells);
1273 spawnfunc(item_plasma)
1275 if(!this.ammo_plasma)
1276 this.ammo_plasma = g_pickup_plasma;
1277 if(!this.pickup_anyway)
1278 this.pickup_anyway = g_pickup_ammo_anyway;
1279 StartItem(this, ITEM_Plasma);
1282 spawnfunc(item_shells)
1285 if(autocvar_sv_q3acompat_machineshotgunswap)
1286 if(this.classname != "droppedweapon")
1288 weaponswapping = true;
1289 spawnfunc_item_bullets(this);
1290 weaponswapping = false;
1294 if(!this.ammo_shells)
1295 this.ammo_shells = g_pickup_shells;
1296 if(!this.pickup_anyway)
1297 this.pickup_anyway = g_pickup_ammo_anyway;
1298 StartItem(this, ITEM_Shells);
1301 spawnfunc(item_armor_small)
1303 if(!this.armorvalue)
1304 this.armorvalue = g_pickup_armorsmall;
1305 if(!this.max_armorvalue)
1306 this.max_armorvalue = g_pickup_armorsmall_max;
1307 if(!this.pickup_anyway)
1308 this.pickup_anyway = g_pickup_armorsmall_anyway;
1309 StartItem(this, ITEM_ArmorSmall);
1312 spawnfunc(item_armor_medium)
1314 if(!this.armorvalue)
1315 this.armorvalue = g_pickup_armormedium;
1316 if(!this.max_armorvalue)
1317 this.max_armorvalue = g_pickup_armormedium_max;
1318 if(!this.pickup_anyway)
1319 this.pickup_anyway = g_pickup_armormedium_anyway;
1320 StartItem(this, ITEM_ArmorMedium);
1323 spawnfunc(item_armor_big)
1325 if(!this.armorvalue)
1326 this.armorvalue = g_pickup_armorbig;
1327 if(!this.max_armorvalue)
1328 this.max_armorvalue = g_pickup_armorbig_max;
1329 if(!this.pickup_anyway)
1330 this.pickup_anyway = g_pickup_armorbig_anyway;
1331 StartItem(this, ITEM_ArmorLarge);
1334 spawnfunc(item_armor_large)
1336 if(!this.armorvalue)
1337 this.armorvalue = g_pickup_armorlarge;
1338 if(!this.max_armorvalue)
1339 this.max_armorvalue = g_pickup_armorlarge_max;
1340 if(!this.pickup_anyway)
1341 this.pickup_anyway = g_pickup_armorlarge_anyway;
1342 StartItem(this, ITEM_ArmorMega);
1345 spawnfunc(item_health_small)
1347 if(!this.max_health)
1348 this.max_health = g_pickup_healthsmall_max;
1350 this.health = g_pickup_healthsmall;
1351 if(!this.pickup_anyway)
1352 this.pickup_anyway = g_pickup_healthsmall_anyway;
1353 StartItem(this, ITEM_HealthSmall);
1356 spawnfunc(item_health_medium)
1358 if(!this.max_health)
1359 this.max_health = g_pickup_healthmedium_max;
1361 this.health = g_pickup_healthmedium;
1362 if(!this.pickup_anyway)
1363 this.pickup_anyway = g_pickup_healthmedium_anyway;
1364 StartItem(this, ITEM_HealthMedium);
1367 spawnfunc(item_health_large)
1369 if(!this.max_health)
1370 this.max_health = g_pickup_healthlarge_max;
1372 this.health = g_pickup_healthlarge;
1373 if(!this.pickup_anyway)
1374 this.pickup_anyway = g_pickup_healthlarge_anyway;
1375 StartItem(this, ITEM_HealthLarge);
1378 spawnfunc(item_health_mega)
1380 if(!this.max_health)
1381 this.max_health = g_pickup_healthmega_max;
1383 this.health = g_pickup_healthmega;
1384 if(!this.pickup_anyway)
1385 this.pickup_anyway = g_pickup_healthmega_anyway;
1386 StartItem(this, ITEM_HealthMega);
1389 // support old misnamed entities
1390 spawnfunc(item_armor1) { spawnfunc_item_armor_small(this); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1391 spawnfunc(item_armor25) { spawnfunc_item_armor_large(this); }
1392 spawnfunc(item_health1) { spawnfunc_item_health_small(this); }
1393 spawnfunc(item_health25) { spawnfunc_item_health_medium(this); }
1394 spawnfunc(item_health100) { spawnfunc_item_health_mega(this); }
1396 spawnfunc(item_strength)
1398 if(!this.strength_finished)
1399 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1400 StartItem(this, ITEM_Strength);
1403 spawnfunc(item_invincible)
1405 if(!this.invincible_finished)
1406 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1407 StartItem(this, ITEM_Shield);
1411 spawnfunc(item_quad) { this.classname = "item_strength";spawnfunc_item_strength(this);}
1413 void target_items_use()
1415 if(activator.classname == "droppedweapon")
1422 if (!IS_PLAYER(activator))
1424 if(IS_DEAD(activator))
1428 FOREACH_ENTITY_ENT(enemy, activator,
1430 if(it.classname == "droppedweapon")
1434 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1435 centerprint(activator, self.message);
1438 spawnfunc(target_items)
1443 self.use = target_items_use;
1444 if(!self.strength_finished)
1445 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1446 if(!self.invincible_finished)
1447 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1448 if(!self.superweapons_finished)
1449 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1451 n = tokenize_console(self.netname);
1452 if(argv(0) == "give")
1454 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1458 for(i = 0; i < n; ++i)
1460 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1461 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1462 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1463 else if(argv(i) == "strength") self.items |= ITEM_Strength.m_itemid;
1464 else if(argv(i) == "invincible") self.items |= ITEM_Shield.m_itemid;
1465 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1466 else if(argv(i) == "jetpack") self.items |= ITEM_Jetpack.m_itemid;
1467 else if(argv(i) == "fuel_regen") self.items |= ITEM_JetpackRegen.m_itemid;
1470 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1471 s = W_UndeprecateName(argv(i));
1474 self.weapons |= (it.m_wepset);
1475 if(self.spawnflags == 0 || self.spawnflags == 2)
1483 string itemprefix, valueprefix;
1484 if(self.spawnflags == 0)
1489 else if(self.spawnflags == 1)
1491 itemprefix = "max ";
1492 valueprefix = "max ";
1494 else if(self.spawnflags == 2)
1496 itemprefix = "min ";
1497 valueprefix = "min ";
1499 else if(self.spawnflags == 4)
1501 itemprefix = "minus ";
1502 valueprefix = "max ";
1506 error("invalid spawnflags");
1507 itemprefix = valueprefix = string_null;
1511 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1512 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1513 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * boolean(self.items & ITEM_Strength.m_itemid), "strength");
1514 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * boolean(self.items & ITEM_Shield.m_itemid), "invincible");
1515 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * boolean(self.items & IT_SUPERWEAPON), "superweapons");
1516 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & ITEM_Jetpack.m_itemid), "jetpack");
1517 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1518 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1519 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1520 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1521 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1522 if(self.ammo_plasma != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_plasma), "plasma");
1523 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1524 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1525 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1526 FOREACH(Weapons, it != WEP_Null, LAMBDA(self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & (it.m_wepset)), it.netname)));
1528 self.netname = strzone(self.netname);
1529 //print(self.netname, "\n");
1531 n = tokenize_console(self.netname);
1532 for(i = 0; i < n; ++i)
1534 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1535 if(argv(i) == it.netname)
1544 spawnfunc(item_fuel)
1547 this.ammo_fuel = g_pickup_fuel;
1548 if(!this.pickup_anyway)
1549 this.pickup_anyway = g_pickup_ammo_anyway;
1550 StartItem(this, ITEM_JetpackFuel);
1553 spawnfunc(item_fuel_regen)
1555 if(start_items & ITEM_JetpackRegen.m_itemid)
1557 spawnfunc_item_fuel(this);
1560 StartItem(this, ITEM_JetpackRegen);
1563 spawnfunc(item_jetpack)
1566 this.ammo_fuel = g_pickup_fuel_jetpack;
1567 if(start_items & ITEM_Jetpack.m_itemid)
1569 spawnfunc_item_fuel(this);
1572 StartItem(this, ITEM_Jetpack);
1575 float GiveWeapon(entity e, float wpn, float op, float val)
1578 WepSet s = WepSet_FromWeapon(Weapons_from(wpn));
1579 v0 = (e.weapons & s);
1602 v1 = (e.weapons & s);
1606 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
1613 _sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1615 else if(v0 >= v0 + t)
1618 _sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1622 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1625 e.(rotfield) = max(e.(rotfield), time + rottime);
1627 e.(regenfield) = max(e.(regenfield), time + regentime);
1629 float GiveItems(entity e, float beginarg, float endarg)
1631 float got, i, val, op;
1632 float _switchweapon;
1640 _switchweapon = false;
1642 if (PS(e).m_switchweapon == w_getbestweapon(e))
1643 _switchweapon = true;
1645 e.strength_finished = max(0, e.strength_finished - time);
1646 e.invincible_finished = max(0, e.invincible_finished - time);
1647 e.superweapons_finished = max(0, e.superweapons_finished - time);
1651 PREGIVE(e, strength_finished);
1652 PREGIVE(e, invincible_finished);
1653 PREGIVE(e, superweapons_finished);
1654 PREGIVE(e, ammo_nails);
1655 PREGIVE(e, ammo_cells);
1656 PREGIVE(e, ammo_plasma);
1657 PREGIVE(e, ammo_shells);
1658 PREGIVE(e, ammo_rockets);
1659 PREGIVE(e, ammo_fuel);
1660 PREGIVE(e, armorvalue);
1663 for(i = beginarg; i < endarg; ++i)
1667 if(cmd == "0" || stof(cmd))
1691 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1692 got += GiveValue(e, strength_finished, op, val);
1693 got += GiveValue(e, invincible_finished, op, val);
1694 got += GiveValue(e, superweapons_finished, op, val);
1695 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1697 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1698 got += GiveValue(e, health, op, val);
1699 got += GiveValue(e, armorvalue, op, val);
1701 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1702 if(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED))
1703 got += GiveWeapon(e, it.m_id, op, val);
1706 got += GiveValue(e, ammo_cells, op, val);
1707 got += GiveValue(e, ammo_plasma, op, val);
1708 got += GiveValue(e, ammo_shells, op, val);
1709 got += GiveValue(e, ammo_nails, op, val);
1710 got += GiveValue(e, ammo_rockets, op, val);
1711 got += GiveValue(e, ammo_fuel, op, val);
1713 case "unlimited_ammo":
1714 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1716 case "unlimited_weapon_ammo":
1717 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1719 case "unlimited_superweapons":
1720 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1723 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1726 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1729 got += GiveValue(e, strength_finished, op, val);
1732 got += GiveValue(e, invincible_finished, op, val);
1734 case "superweapons":
1735 got += GiveValue(e, superweapons_finished, op, val);
1738 got += GiveValue(e, ammo_cells, op, val);
1741 got += GiveValue(e, ammo_plasma, op, val);
1744 got += GiveValue(e, ammo_shells, op, val);
1748 got += GiveValue(e, ammo_nails, op, val);
1751 got += GiveValue(e, ammo_rockets, op, val);
1754 got += GiveValue(e, health, op, val);
1757 got += GiveValue(e, armorvalue, op, val);
1760 got += GiveValue(e, ammo_fuel, op, val);
1763 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1764 if(cmd == it.netname)
1766 got += GiveWeapon(e, it.m_id, op, val);
1776 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND(ITEMPICKUP), string_null);
1777 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND(POWERUP), SND(POWEROFF));
1778 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND(POWERUP), SND(POWEROFF));
1779 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND(ITEMPICKUP), string_null);
1780 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1781 POSTGIVE_WEAPON(e, it, SND(WEAPONPICKUP), string_null);
1782 if(!(save_weapons & (it.m_wepset)))
1783 if(e.weapons & (it.m_wepset))
1786 POSTGIVE_VALUE(e, strength_finished, 1, SND(POWERUP), SND(POWEROFF));
1787 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", SND(POWEROFF));
1788 POSTGIVE_VALUE(e, ammo_nails, 0, SND(ITEMPICKUP), string_null);
1789 POSTGIVE_VALUE(e, ammo_cells, 0, SND(ITEMPICKUP), string_null);
1790 POSTGIVE_VALUE(e, ammo_plasma, 0, SND(ITEMPICKUP), string_null);
1791 POSTGIVE_VALUE(e, ammo_shells, 0, SND(ITEMPICKUP), string_null);
1792 POSTGIVE_VALUE(e, ammo_rockets, 0, SND(ITEMPICKUP), string_null);
1793 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);
1794 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);
1795 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);
1797 if(e.superweapons_finished <= 0)
1798 if(self.weapons & WEPSET_SUPERWEAPONS)
1799 e.superweapons_finished = autocvar_g_balance_superweapons_time;
1801 if(e.strength_finished <= 0)
1802 e.strength_finished = 0;
1804 e.strength_finished += time;
1805 if(e.invincible_finished <= 0)
1806 e.invincible_finished = 0;
1808 e.invincible_finished += time;
1809 if(e.superweapons_finished <= 0)
1810 e.superweapons_finished = 0;
1812 e.superweapons_finished += time;
1814 if (!(e.weapons & WepSet_FromWeapon(PS(e).m_switchweapon)))
1815 _switchweapon = true;
1817 W_SwitchWeapon_Force(e, w_getbestweapon(e));