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/all.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 void Item_PreDraw(entity this)
119 if(warpzone_warpzones_exist)
121 // just incase warpzones were initialized last, reset these
122 //this.alpha = 1; // alpha is already set by the draw function
123 this.drawmask = MASK_NORMAL;
127 vector org = getpropertyvec(VF_ORIGIN);
128 if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones
130 else if(this.fade_start)
131 alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1);
134 //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
135 if(!hud && (this.ItemStatus & ITS_AVAILABLE))
140 this.drawmask = MASK_NORMAL;
143 void ItemRemove(entity this)
149 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
153 if(sf & ISF_LOCATION)
155 self.origin_x = ReadCoord();
156 self.origin_y = ReadCoord();
157 self.origin_z = ReadCoord();
158 setorigin(self, self.origin);
159 self.oldorigin = self.origin;
164 self.angles_x = ReadAngle();
165 self.angles_y = ReadAngle();
166 self.angles_z = ReadAngle();
167 self.move_angles = self.angles;
172 float use_bigsize = ReadByte();
173 setsize(self, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
176 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
178 self.ItemStatus = ReadByte();
182 if(autocvar_cl_fullbright_items)
183 if(self.ItemStatus & ITS_ALLOWFB)
184 self.effects |= EF_FULLBRIGHT;
186 if(self.ItemStatus & ITS_POWERUP)
188 if(self.ItemStatus & ITS_AVAILABLE)
189 self.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
191 self.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
197 self.drawmask = MASK_NORMAL;
198 self.move_movetype = MOVETYPE_TOSS;
199 self.draw = ItemDraw;
200 self.solid = SOLID_TRIGGER;
201 //self.move_flags |= FL_ITEM;
203 bool use_bigsize = ReadByte();
205 self.fade_end = ReadShort();
206 self.fade_start = ReadShort();
207 if(self.fade_start && !autocvar_cl_items_nofade)
208 setpredraw(self, Item_PreDraw);
214 string _fn = ReadString();
216 if(autocvar_cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
218 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
219 self.draw = ItemDrawSimple;
221 if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
222 self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
223 else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
224 self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
225 else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
226 self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
227 else if(fexists(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix)))
228 self.mdl = strzone(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix));
231 self.draw = ItemDraw;
232 LOG_TRACE("Simple item requested for ", _fn, " but no model exists for it\n");
236 if(self.draw != ItemDrawSimple)
237 self.mdl = strzone(_fn);
241 LOG_TRACE("^1WARNING!^7 self.mdl is unset for item ", self.classname, ", tell tZork about this!\n");
243 precache_model(self.mdl);
244 _setmodel(self, self.mdl);
246 setsize(self, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
249 if(sf & ISF_COLORMAP)
250 self.colormap = ReadShort();
255 self.pushable = true;
256 //self.move_angles = '0 0 0';
257 self.move_movetype = MOVETYPE_TOSS;
258 self.move_velocity_x = ReadCoord();
259 self.move_velocity_y = ReadCoord();
260 self.move_velocity_z = ReadCoord();
261 self.velocity = self.move_velocity;
262 self.move_origin = self.oldorigin;
266 self.move_time = time;
267 self.spawntime = time;
270 self.move_time = max(self.move_time, time);
273 if(autocvar_cl_animate_items)
275 if(self.ItemStatus & ITS_ANIMATE1)
276 self.move_avelocity = '0 180 0';
278 if(self.ItemStatus & ITS_ANIMATE2)
279 self.move_avelocity = '0 -90 0';
282 self.entremove = ItemRemove;
290 bool ItemSend(entity this, entity to, int sf)
297 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
298 WriteByte(MSG_ENTITY, sf);
300 //WriteByte(MSG_ENTITY, self.cnt);
301 if(sf & ISF_LOCATION)
303 WriteCoord(MSG_ENTITY, self.origin.x);
304 WriteCoord(MSG_ENTITY, self.origin.y);
305 WriteCoord(MSG_ENTITY, self.origin.z);
310 WriteAngle(MSG_ENTITY, self.angles_x);
311 WriteAngle(MSG_ENTITY, self.angles_y);
312 WriteAngle(MSG_ENTITY, self.angles_z);
317 Pickup p = this.itemdef;
318 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
322 WriteByte(MSG_ENTITY, self.ItemStatus);
326 Pickup p = this.itemdef;
327 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
328 WriteShort(MSG_ENTITY, self.fade_end);
329 WriteShort(MSG_ENTITY, self.fade_start);
332 LOG_TRACE("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n");
334 WriteString(MSG_ENTITY, self.mdl);
338 if(sf & ISF_COLORMAP)
339 WriteShort(MSG_ENTITY, self.colormap);
343 WriteCoord(MSG_ENTITY, self.velocity.x);
344 WriteCoord(MSG_ENTITY, self.velocity.y);
345 WriteCoord(MSG_ENTITY, self.velocity.z);
351 void ItemUpdate(entity this)
353 this.oldorigin = this.origin;
354 this.SendFlags |= ISF_LOCATION;
357 void UpdateItemAfterTeleport(entity this)
359 if(this.SendEntity3 == ItemSend)
363 bool have_pickup_item(entity this)
365 if(this.itemdef.instanceOfPowerup)
367 if(autocvar_g_powerups > 0)
369 if(autocvar_g_powerups == 0)
374 if(autocvar_g_pickup_items > 0)
376 if(autocvar_g_pickup_items == 0)
379 if(this.weapons || (this.items & IT_AMMO)) // no item or ammo pickups in weaponarena
386 float Item_Customize()
388 if(self.spawnshieldtime)
390 if(self.weapons & ~other.weapons)
392 self.colormod = '0 0 0';
393 self.glowmod = self.colormod;
394 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
401 self.colormod = stov(autocvar_g_ghost_items_color);
402 self.glowmod = self.colormod;
403 self.alpha = g_ghost_items;
412 void Item_Show (entity e, float mode)
414 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
415 e.ItemStatus &= ~ITS_STAYWEP;
418 // make the item look normal, and be touchable
420 e.solid = SOLID_TRIGGER;
421 e.spawnshieldtime = 1;
422 e.ItemStatus |= ITS_AVAILABLE;
426 // hide the item completely
427 e.model = string_null;
429 e.spawnshieldtime = 1;
430 e.ItemStatus &= ~ITS_AVAILABLE;
433 entity def = e.itemdef;
434 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.weapons & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
435 || e.team // weapon stay isn't supported for teamed weapons
437 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
439 // make the item translucent and not touchable
441 e.solid = SOLID_TRIGGER; // can STILL be picked up!
442 e.effects |= EF_STARDUST;
443 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
444 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
448 //setmodel(e, "null");
450 e.colormod = '0 0 0';
451 e.glowmod = e.colormod;
452 e.spawnshieldtime = 1;
453 e.ItemStatus &= ~ITS_AVAILABLE;
456 if (e.items & ITEM_Strength.m_itemid || e.items & ITEM_Shield.m_itemid)
457 e.ItemStatus |= ITS_POWERUP;
459 if (autocvar_g_nodepthtestitems)
460 e.effects |= EF_NODEPTHTEST;
463 if (autocvar_g_fullbrightitems)
464 e.ItemStatus |= ITS_ALLOWFB;
466 if (autocvar_sv_simple_items)
467 e.ItemStatus |= ITS_ALLOWSI;
469 // relink entity (because solid may have changed)
470 setorigin(e, e.origin);
471 e.SendFlags |= ISF_STATUS;
476 self.nextthink = time;
477 if(self.origin != self.oldorigin)
481 bool Item_ItemsTime_SpectatorOnly(GameItem it);
482 bool Item_ItemsTime_Allow(GameItem it);
483 float Item_ItemsTime_UpdateTime(entity e, float t);
484 void Item_ItemsTime_SetTime(entity e, float t);
485 void Item_ItemsTime_SetTimesForAllPlayers();
491 if(self.items == ITEM_Strength.m_itemid)
492 sound (self, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
493 else if(self.items == ITEM_Shield.m_itemid)
494 sound (self, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
496 sound (self, CH_TRIGGER, SND_ITEMRESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
497 setorigin (self, self.origin);
499 if (Item_ItemsTime_Allow(self.itemdef) || self.weapons & WEPSET_SUPERWEAPONS)
501 float t = Item_ItemsTime_UpdateTime(self, 0);
502 Item_ItemsTime_SetTime(self, t);
503 Item_ItemsTime_SetTimesForAllPlayers();
506 self.think = Item_Think;
507 self.nextthink = time;
509 //Send_Effect(EFFECT_ITEM_RESPAWN, self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
510 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
513 void Item_RespawnCountdown ()
515 if(self.count >= ITEM_RESPAWN_TICKS)
517 if(self.waypointsprite_attached)
518 WaypointSprite_Kill(self.waypointsprite_attached);
523 self.nextthink = time + 1;
527 MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0');
530 entity wi = Weapons_from(self.weapon);
531 if (wi != WEP_Null) {
532 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Weapon);
533 wp.wp_extra = wi.m_id;
538 entity ii = self.itemdef;
540 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Item);
541 wp.wp_extra = ii.m_id;
546 if(self.waypointsprite_attached)
548 GameItem def = self.itemdef;
549 if (Item_ItemsTime_SpectatorOnly(def))
550 WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
551 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
555 if(self.waypointsprite_attached)
557 setself(self.waypointsprite_attached);
558 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
559 if(self.waypointsprite_visible_for_player(it))
562 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM); // play respawn sound
567 WaypointSprite_Ping(self.waypointsprite_attached);
568 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
573 void Item_RespawnThink()
575 self.nextthink = time;
576 if(self.origin != self.oldorigin)
579 if(time >= self.wait)
583 void Item_ScheduleRespawnIn(entity e, float t)
585 // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
586 if ((Item_ItemsTime_Allow(e.itemdef) || e.weapons & WEPSET_SUPERWEAPONS) && (t - ITEM_RESPAWN_TICKS) > 0)
588 e.think = Item_RespawnCountdown;
589 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
590 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
592 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
593 Item_ItemsTime_SetTime(e, t);
594 Item_ItemsTime_SetTimesForAllPlayers();
598 e.think = Item_RespawnThink;
600 e.scheduledrespawntime = time + t;
605 void Item_ScheduleRespawn(entity e)
607 if(e.respawntime > 0)
610 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
612 else // if respawntime is -1, this item does not respawn
616 void Item_ScheduleInitialRespawn(entity e)
619 Item_ScheduleRespawnIn(e, game_starttime - time + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
622 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
624 if (!item.(ammotype))
627 if (item.spawnshieldtime)
629 if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0)
631 player.(ammotype) = bound(player.(ammotype), ammomax, player.(ammotype) + item.(ammotype));
635 else if(g_weapon_stay == 2)
637 float mi = min(item.(ammotype), ammomax);
638 if (player.(ammotype) < mi)
640 player.(ammotype) = mi;
651 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
653 case ITEM_MODE_HEALTH:
654 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
656 case ITEM_MODE_ARMOR:
657 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
665 float Item_GiveTo(entity item, entity player)
670 // if nothing happens to player, just return without taking the item
672 _switchweapon = false;
673 // in case the player has autoswitch enabled do the following:
674 // if the player is using their best weapon before items are given, they
675 // probably want to switch to an even better weapon after items are given
676 if (player.autoswitch)
677 if (PS(player).m_switchweapon == w_getbestweapon(player))
678 _switchweapon = true;
680 if (!(player.weapons & WepSet_FromWeapon(PS(player).m_switchweapon)))
681 _switchweapon = true;
683 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
684 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
685 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
686 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
687 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
688 pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max, ITEM_MODE_NONE);
689 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
690 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
692 if (item.itemdef.instanceOfWeaponPickup)
696 w &= ~player.weapons;
698 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
701 FOREACH(Weapons, it != WEP_Null, LAMBDA(
702 if(w & (it.m_wepset))
704 W_DropEvent(wr_pickup, player, it.m_id, item);
705 W_GiveWeapon(player, it.m_id);
711 if (item.itemdef.instanceOfPowerup)
713 if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
714 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
715 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
716 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
720 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
724 Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
727 if (item.strength_finished)
730 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
732 if (item.invincible_finished)
735 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
737 if (item.superweapons_finished)
740 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
745 // always eat teamed entities
752 // crude hack to enforce switching weapons
753 if(g_cts && item.itemdef.instanceOfWeaponPickup)
755 W_SwitchWeapon_Force(player, Weapons_from(item.weapon));
760 if (PS(player).m_switchweapon != w_getbestweapon(player))
761 W_SwitchWeapon_Force(player, w_getbestweapon(player));
770 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
771 if (this.classname == "droppedweapon")
773 if (ITEM_TOUCH_NEEDKILL())
780 if(!(other.flags & FL_PICKUPITEMS)
781 || STAT(FROZEN, other)
783 || (this.solid != SOLID_TRIGGER)
784 || (this.owner == other)
785 || (time < this.item_spawnshieldtime)
788 switch (MUTATOR_CALLHOOK(ItemTouch, this, other))
790 case MUT_ITEMTOUCH_RETURN: { return; }
791 case MUT_ITEMTOUCH_PICKUP: { goto pickup; }
794 if (this.classname == "droppedweapon")
796 this.strength_finished = max(0, this.strength_finished - time);
797 this.invincible_finished = max(0, this.invincible_finished - time);
798 this.superweapons_finished = max(0, this.superweapons_finished - time);
800 entity it = this.itemdef;
801 bool gave = ITEM_HANDLE(Pickup, it, this, other);
804 if (this.classname == "droppedweapon")
806 // undo what we did above
807 this.strength_finished += time;
808 this.invincible_finished += time;
809 this.superweapons_finished += time;
816 other.last_pickup = time;
818 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
819 _sound (other, CH_TRIGGER, (this.item_pickupsound ? this.item_pickupsound : Sound_fixpath(this.item_pickupsound_ent)), VOL_BASE, ATTEN_NORM);
821 if (this.classname == "droppedweapon")
823 else if (this.spawnshieldtime)
828 RandomSelection_Init();
829 for(entity head = world; (head = findfloat(head, team, this.team)); )
831 if(head.flags & FL_ITEM)
832 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
835 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
838 e = RandomSelection_chosen_ent;
843 Item_ScheduleRespawn(e);
847 void Item_Reset(entity this)
849 Item_Show(this, !this.state);
850 setorigin(this, this.origin);
852 if (this.classname != "droppedweapon")
854 this.think = Item_Think;
855 this.nextthink = time;
857 if (this.waypointsprite_attached)
858 WaypointSprite_Kill(this.waypointsprite_attached);
860 if (this.itemdef.instanceOfPowerup || (this.weapons & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
861 Item_ScheduleInitialRespawn(this);
864 void Item_Reset_self() { SELFPARAM(); Item_Reset(this); }
870 if(self.effects & EF_NODRAW)
872 // marker for item team search
873 LOG_TRACE("Initializing item team ", ftos(self.team), "\n");
874 RandomSelection_Init();
875 FOREACH_ENTITY_FLOAT(team, self.team,
877 if(it.flags & FL_ITEM)
878 if(it.classname != "item_flag_team" && it.classname != "item_key_team")
879 RandomSelection_Add(it, 0, string_null, it.cnt, 0);
882 e = RandomSelection_chosen_ent;
886 FOREACH_ENTITY_FLOAT(team, self.team,
888 if(it.flags & FL_ITEM)
889 if(it.classname != "item_flag_team" && it.classname != "item_key_team")
893 // make it non-spawned
895 it.state = 1; // state 1 = initially hidden item, apparently
897 it.effects &= ~EF_NODRAW;
905 // Savage: used for item garbage-collection
908 if(wasfreed(self) || !self) { return; }
909 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
913 // pickup evaluation functions
914 // these functions decide how desirable an item is to the bots
916 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
918 float weapon_pickupevalfunc(entity player, entity item)
922 // See if I have it already
923 if(item.weapons & ~player.weapons)
925 // If I can pick it up
926 if(!item.spawnshieldtime)
928 else if(player.ammo_cells || player.ammo_shells || player.ammo_plasma || player.ammo_nails || player.ammo_rockets)
930 // Skilled bots will grab more
931 c = bound(0, skill / 10, 1) * 0.5;
939 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
940 if( bot_custom_weapon && c )
942 // Find the highest position on any range
944 for (int j = 0; j < WEP_LAST ; ++j){
946 bot_weapons_far[j] == item.weapon ||
947 bot_weapons_mid[j] == item.weapon ||
948 bot_weapons_close[j] == item.weapon
959 position = WEP_LAST - position;
960 // item.bot_pickupbasevalue is overwritten here
961 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
965 return item.bot_pickupbasevalue * c;
968 float commodity_pickupevalfunc(entity player, entity item)
971 float need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
974 // Detect needed ammo
975 FOREACH(Weapons, it != WEP_Null, LAMBDA(
976 if(!(player.weapons & (it.m_wepset)))
979 if(it.items & ITEM_Shells.m_itemid)
981 else if(it.items & ITEM_Bullets.m_itemid)
983 else if(it.items & ITEM_Rockets.m_itemid)
985 else if(it.items & ITEM_Cells.m_itemid)
987 else if(it.items & ITEM_Plasma.m_itemid)
989 else if(it.items & ITEM_JetpackFuel.m_itemid)
993 // TODO: figure out if the player even has the weapon this ammo is for?
994 // may not affect strategy much though...
995 // find out how much more ammo/armor/health the player can hold
997 if (item.ammo_shells)
998 if (player.ammo_shells < g_pickup_shells_max)
999 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
1001 if (item.ammo_nails)
1002 if (player.ammo_nails < g_pickup_nails_max)
1003 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
1005 if (item.ammo_rockets)
1006 if (player.ammo_rockets < g_pickup_rockets_max)
1007 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
1009 if (item.ammo_cells)
1010 if (player.ammo_cells < g_pickup_cells_max)
1011 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
1013 if (item.ammo_plasma)
1014 if (player.ammo_plasma < g_pickup_plasma_max)
1015 c = c + max(0, 1 - player.ammo_plasma / g_pickup_plasma_max);
1018 if (player.ammo_fuel < g_pickup_fuel_max)
1019 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
1020 if (item.armorvalue)
1021 if (player.armorvalue < item.max_armorvalue)
1022 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
1024 if (player.health < item.max_health)
1025 c = c + max(0, 1 - player.health / item.max_health);
1027 return item.bot_pickupbasevalue * c;
1030 void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
1032 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1033 WITH(entity, self, this, RemoveItem());
1036 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
1038 string itemname = def.m_name;
1039 Model itemmodel = def.m_model;
1040 Sound pickupsound = def.m_sound;
1041 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
1042 float pickupbasevalue = def.m_botvalue;
1043 int itemflags = def.m_itemflags;
1045 startitem_failed = false;
1047 this.item_model_ent = itemmodel;
1048 this.item_pickupsound_ent = pickupsound;
1050 if(!this.respawntime) // both need to be set
1052 this.respawntime = defaultrespawntime;
1053 this.respawntimejitter = defaultrespawntimejitter;
1056 int itemid = def.m_itemid;
1057 this.items = itemid;
1058 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
1059 this.weapon = weaponid;
1063 this.fade_start = autocvar_g_items_mindist;
1064 this.fade_end = autocvar_g_items_maxdist;
1068 this.weapons = WepSet_FromWeapon(Weapons_from(weaponid));
1070 this.flags = FL_ITEM | itemflags;
1072 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
1074 startitem_failed = true;
1079 // is it a dropped weapon?
1080 if (this.classname == "droppedweapon")
1082 this.reset = SUB_Remove;
1083 // it's a dropped weapon
1084 this.movetype = MOVETYPE_TOSS;
1086 // Savage: remove thrown items after a certain period of time ("garbage collection")
1087 this.think = RemoveItem;
1088 this.nextthink = time + 20;
1090 this.takedamage = DAMAGE_YES;
1091 this.event_damage = Item_Damage;
1093 if(this.strength_finished || this.invincible_finished || this.superweapons_finished)
1095 // if item is worthless after a timer, have it expire then
1096 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
1099 // don't drop if in a NODROP zone (such as lava)
1100 traceline(this.origin, this.origin, MOVE_NORMAL, this);
1101 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1103 startitem_failed = true;
1110 if(!have_pickup_item(this))
1112 startitem_failed = true;
1117 if(this.angles != '0 0 0')
1118 this.SendFlags |= ISF_ANGLES;
1120 this.reset = Item_Reset;
1121 // it's a level item
1122 if(this.spawnflags & 1)
1124 if (this.noalign > 0)
1125 this.movetype = MOVETYPE_NONE;
1127 this.movetype = MOVETYPE_TOSS;
1128 // do item filtering according to game mode and other things
1129 if (this.noalign <= 0)
1131 // first nudge it off the floor a little bit to avoid math errors
1132 setorigin(this, this.origin + '0 0 1');
1133 // set item size before we spawn a spawnfunc_waypoint
1134 setsize(this, def.m_mins, def.m_maxs);
1135 this.SendFlags |= ISF_SIZE;
1136 // note droptofloor returns false if stuck/or would fall too far
1138 WITH(entity, self, this, droptofloor());
1139 waypoint_spawnforitem(this);
1143 * can't do it that way, as it would break maps
1144 * TODO make a target_give like entity another way, that perhaps has
1145 * the weapon name in a key
1148 // target_give not yet supported; maybe later
1149 print("removed targeted ", this.classname, "\n");
1150 startitem_failed = true;
1156 if(autocvar_spawn_debug >= 2)
1158 for(entity otheritem = findradius(this.origin, 3); otheritem; otheritem = otheritem.chain)
1160 // why not flags & fl_item?
1161 if(otheritem.is_item)
1163 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1164 LOG_TRACE(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1165 error("Mapper sucks.");
1168 this.is_item = true;
1171 weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid));
1173 precache_model(this.model);
1174 precache_sound(this.item_pickupsound);
1176 if ( def.instanceOfPowerup
1177 || def.instanceOfWeaponPickup
1178 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1179 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1180 || (itemid & (IT_KEY1 | IT_KEY2))
1181 ) this.target = "###item###"; // for finding the nearest item using find()
1183 Item_ItemsTime_SetTime(this, 0);
1186 this.bot_pickup = true;
1187 this.bot_pickupevalfunc = pickupevalfunc;
1188 this.bot_pickupbasevalue = pickupbasevalue;
1189 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1190 this.netname = itemname;
1191 this.touch = Item_Touch;
1192 setmodel(this, MDL_Null); // precision set below
1193 //this.effects |= EF_LOWPRECISION;
1195 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1197 this.SendFlags |= ISF_SIZE;
1199 if (!(this.spawnflags & 1024)) {
1200 if(def.instanceOfPowerup)
1201 this.ItemStatus |= ITS_ANIMATE1;
1203 if(this.armorvalue || this.health)
1204 this.ItemStatus |= ITS_ANIMATE2;
1207 if(def.instanceOfWeaponPickup)
1209 if (this.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1210 this.colormap = 1024; // color shirt=0 pants=0 grey
1213 if (!(this.spawnflags & 1024))
1214 this.ItemStatus |= ITS_ANIMATE1;
1215 this.ItemStatus |= ISF_COLORMAP;
1219 if(this.team) // broken, no idea why.
1222 this.cnt = 1; // item probability weight
1224 this.effects |= EF_NODRAW; // marker for item team search
1225 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1230 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1232 // call this hook after everything else has been done
1233 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1235 startitem_failed = true;
1241 void StartItem(entity this, GameItem def)
1246 def.m_respawntime(), // defaultrespawntime
1247 def.m_respawntimejitter() // defaultrespawntimejitter
1251 spawnfunc(item_rockets)
1253 if(!this.ammo_rockets)
1254 this.ammo_rockets = g_pickup_rockets;
1255 if(!this.pickup_anyway)
1256 this.pickup_anyway = g_pickup_ammo_anyway;
1257 StartItem(this, ITEM_Rockets);
1260 spawnfunc(item_bullets)
1263 if(autocvar_sv_q3acompat_machineshotgunswap)
1264 if(this.classname != "droppedweapon")
1266 weaponswapping = true;
1267 spawnfunc_item_shells(this);
1268 weaponswapping = false;
1272 if(!this.ammo_nails)
1273 this.ammo_nails = g_pickup_nails;
1274 if(!this.pickup_anyway)
1275 this.pickup_anyway = g_pickup_ammo_anyway;
1276 StartItem(this, ITEM_Bullets);
1279 spawnfunc(item_cells)
1281 if(!this.ammo_cells)
1282 this.ammo_cells = g_pickup_cells;
1283 if(!this.pickup_anyway)
1284 this.pickup_anyway = g_pickup_ammo_anyway;
1285 StartItem(this, ITEM_Cells);
1288 spawnfunc(item_plasma)
1290 if(!this.ammo_plasma)
1291 this.ammo_plasma = g_pickup_plasma;
1292 if(!this.pickup_anyway)
1293 this.pickup_anyway = g_pickup_ammo_anyway;
1294 StartItem(this, ITEM_Plasma);
1297 spawnfunc(item_shells)
1300 if(autocvar_sv_q3acompat_machineshotgunswap)
1301 if(this.classname != "droppedweapon")
1303 weaponswapping = true;
1304 spawnfunc_item_bullets(this);
1305 weaponswapping = false;
1309 if(!this.ammo_shells)
1310 this.ammo_shells = g_pickup_shells;
1311 if(!this.pickup_anyway)
1312 this.pickup_anyway = g_pickup_ammo_anyway;
1313 StartItem(this, ITEM_Shells);
1316 spawnfunc(item_armor_small)
1318 if(!this.armorvalue)
1319 this.armorvalue = g_pickup_armorsmall;
1320 if(!this.max_armorvalue)
1321 this.max_armorvalue = g_pickup_armorsmall_max;
1322 if(!this.pickup_anyway)
1323 this.pickup_anyway = g_pickup_armorsmall_anyway;
1324 StartItem(this, ITEM_ArmorSmall);
1327 spawnfunc(item_armor_medium)
1329 if(!this.armorvalue)
1330 this.armorvalue = g_pickup_armormedium;
1331 if(!this.max_armorvalue)
1332 this.max_armorvalue = g_pickup_armormedium_max;
1333 if(!this.pickup_anyway)
1334 this.pickup_anyway = g_pickup_armormedium_anyway;
1335 StartItem(this, ITEM_ArmorMedium);
1338 spawnfunc(item_armor_big)
1340 if(!this.armorvalue)
1341 this.armorvalue = g_pickup_armorbig;
1342 if(!this.max_armorvalue)
1343 this.max_armorvalue = g_pickup_armorbig_max;
1344 if(!this.pickup_anyway)
1345 this.pickup_anyway = g_pickup_armorbig_anyway;
1346 StartItem(this, ITEM_ArmorLarge);
1349 spawnfunc(item_armor_large)
1351 if(!this.armorvalue)
1352 this.armorvalue = g_pickup_armorlarge;
1353 if(!this.max_armorvalue)
1354 this.max_armorvalue = g_pickup_armorlarge_max;
1355 if(!this.pickup_anyway)
1356 this.pickup_anyway = g_pickup_armorlarge_anyway;
1357 StartItem(this, ITEM_ArmorMega);
1360 spawnfunc(item_health_small)
1362 if(!this.max_health)
1363 this.max_health = g_pickup_healthsmall_max;
1365 this.health = g_pickup_healthsmall;
1366 if(!this.pickup_anyway)
1367 this.pickup_anyway = g_pickup_healthsmall_anyway;
1368 StartItem(this, ITEM_HealthSmall);
1371 spawnfunc(item_health_medium)
1373 if(!this.max_health)
1374 this.max_health = g_pickup_healthmedium_max;
1376 this.health = g_pickup_healthmedium;
1377 if(!this.pickup_anyway)
1378 this.pickup_anyway = g_pickup_healthmedium_anyway;
1379 StartItem(this, ITEM_HealthMedium);
1382 spawnfunc(item_health_large)
1384 if(!this.max_health)
1385 this.max_health = g_pickup_healthlarge_max;
1387 this.health = g_pickup_healthlarge;
1388 if(!this.pickup_anyway)
1389 this.pickup_anyway = g_pickup_healthlarge_anyway;
1390 StartItem(this, ITEM_HealthLarge);
1393 spawnfunc(item_health_mega)
1395 if(!this.max_health)
1396 this.max_health = g_pickup_healthmega_max;
1398 this.health = g_pickup_healthmega;
1399 if(!this.pickup_anyway)
1400 this.pickup_anyway = g_pickup_healthmega_anyway;
1401 StartItem(this, ITEM_HealthMega);
1404 // support old misnamed entities
1405 spawnfunc(item_armor1) { spawnfunc_item_armor_small(this); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1406 spawnfunc(item_armor25) { spawnfunc_item_armor_large(this); }
1407 spawnfunc(item_health1) { spawnfunc_item_health_small(this); }
1408 spawnfunc(item_health25) { spawnfunc_item_health_medium(this); }
1409 spawnfunc(item_health100) { spawnfunc_item_health_mega(this); }
1411 spawnfunc(item_strength)
1413 if(!this.strength_finished)
1414 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1415 StartItem(this, ITEM_Strength);
1418 spawnfunc(item_invincible)
1420 if(!this.invincible_finished)
1421 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1422 StartItem(this, ITEM_Shield);
1426 spawnfunc(item_quad) { this.classname = "item_strength";spawnfunc_item_strength(this);}
1428 void target_items_use()
1430 if(activator.classname == "droppedweapon")
1437 if (!IS_PLAYER(activator))
1439 if(IS_DEAD(activator))
1443 FOREACH_ENTITY_ENT(enemy, activator,
1445 if(it.classname == "droppedweapon")
1449 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1450 centerprint(activator, self.message);
1453 spawnfunc(target_items)
1458 self.use = target_items_use;
1459 if(!self.strength_finished)
1460 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1461 if(!self.invincible_finished)
1462 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1463 if(!self.superweapons_finished)
1464 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1466 n = tokenize_console(self.netname);
1467 if(argv(0) == "give")
1469 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1473 for(i = 0; i < n; ++i)
1475 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1476 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1477 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1478 else if(argv(i) == "strength") self.items |= ITEM_Strength.m_itemid;
1479 else if(argv(i) == "invincible") self.items |= ITEM_Shield.m_itemid;
1480 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1481 else if(argv(i) == "jetpack") self.items |= ITEM_Jetpack.m_itemid;
1482 else if(argv(i) == "fuel_regen") self.items |= ITEM_JetpackRegen.m_itemid;
1485 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1486 s = W_UndeprecateName(argv(i));
1489 self.weapons |= (it.m_wepset);
1490 if(self.spawnflags == 0 || self.spawnflags == 2)
1498 string itemprefix, valueprefix;
1499 if(self.spawnflags == 0)
1504 else if(self.spawnflags == 1)
1506 itemprefix = "max ";
1507 valueprefix = "max ";
1509 else if(self.spawnflags == 2)
1511 itemprefix = "min ";
1512 valueprefix = "min ";
1514 else if(self.spawnflags == 4)
1516 itemprefix = "minus ";
1517 valueprefix = "max ";
1521 error("invalid spawnflags");
1522 itemprefix = valueprefix = string_null;
1526 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1527 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1528 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * boolean(self.items & ITEM_Strength.m_itemid), "strength");
1529 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * boolean(self.items & ITEM_Shield.m_itemid), "invincible");
1530 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * boolean(self.items & IT_SUPERWEAPON), "superweapons");
1531 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & ITEM_Jetpack.m_itemid), "jetpack");
1532 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1533 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1534 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1535 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1536 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1537 if(self.ammo_plasma != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_plasma), "plasma");
1538 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1539 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1540 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.armorvalue), "armor");
1541 FOREACH(Weapons, it != WEP_Null, LAMBDA(self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & (it.m_wepset)), it.netname)));
1543 self.netname = strzone(self.netname);
1544 //print(self.netname, "\n");
1546 n = tokenize_console(self.netname);
1547 for(i = 0; i < n; ++i)
1549 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1550 if(argv(i) == it.netname)
1559 spawnfunc(item_fuel)
1562 this.ammo_fuel = g_pickup_fuel;
1563 if(!this.pickup_anyway)
1564 this.pickup_anyway = g_pickup_ammo_anyway;
1565 StartItem(this, ITEM_JetpackFuel);
1568 spawnfunc(item_fuel_regen)
1570 if(start_items & ITEM_JetpackRegen.m_itemid)
1572 spawnfunc_item_fuel(this);
1575 StartItem(this, ITEM_JetpackRegen);
1578 spawnfunc(item_jetpack)
1581 this.ammo_fuel = g_pickup_fuel_jetpack;
1582 if(start_items & ITEM_Jetpack.m_itemid)
1584 spawnfunc_item_fuel(this);
1587 StartItem(this, ITEM_Jetpack);
1590 float GiveWeapon(entity e, float wpn, float op, float val)
1593 WepSet s = WepSet_FromWeapon(Weapons_from(wpn));
1594 v0 = (e.weapons & s);
1617 v1 = (e.weapons & s);
1621 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
1627 if(snd_decr != NULL)
1628 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1630 else if(v0 >= v0 + t)
1632 if(snd_incr != NULL)
1633 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1637 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1640 e.(rotfield) = max(e.(rotfield), time + rottime);
1642 e.(regenfield) = max(e.(regenfield), time + regentime);
1644 float GiveItems(entity e, float beginarg, float endarg)
1646 float got, i, val, op;
1647 float _switchweapon;
1655 _switchweapon = false;
1657 if (PS(e).m_switchweapon == w_getbestweapon(e))
1658 _switchweapon = true;
1660 e.strength_finished = max(0, e.strength_finished - time);
1661 e.invincible_finished = max(0, e.invincible_finished - time);
1662 e.superweapons_finished = max(0, e.superweapons_finished - time);
1666 PREGIVE(e, strength_finished);
1667 PREGIVE(e, invincible_finished);
1668 PREGIVE(e, superweapons_finished);
1669 PREGIVE(e, ammo_nails);
1670 PREGIVE(e, ammo_cells);
1671 PREGIVE(e, ammo_plasma);
1672 PREGIVE(e, ammo_shells);
1673 PREGIVE(e, ammo_rockets);
1674 PREGIVE(e, ammo_fuel);
1675 PREGIVE(e, armorvalue);
1678 for(i = beginarg; i < endarg; ++i)
1682 if(cmd == "0" || stof(cmd))
1706 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1707 got += GiveValue(e, strength_finished, op, val);
1708 got += GiveValue(e, invincible_finished, op, val);
1709 got += GiveValue(e, superweapons_finished, op, val);
1710 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1712 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1713 got += GiveValue(e, health, op, val);
1714 got += GiveValue(e, armorvalue, op, val);
1716 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1717 if(!(it.spawnflags & WEP_FLAG_MUTATORBLOCKED))
1718 got += GiveWeapon(e, it.m_id, op, val);
1721 got += GiveValue(e, ammo_cells, op, val);
1722 got += GiveValue(e, ammo_plasma, op, val);
1723 got += GiveValue(e, ammo_shells, op, val);
1724 got += GiveValue(e, ammo_nails, op, val);
1725 got += GiveValue(e, ammo_rockets, op, val);
1726 got += GiveValue(e, ammo_fuel, op, val);
1728 case "unlimited_ammo":
1729 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1731 case "unlimited_weapon_ammo":
1732 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1734 case "unlimited_superweapons":
1735 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1738 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1741 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1744 got += GiveValue(e, strength_finished, op, val);
1747 got += GiveValue(e, invincible_finished, op, val);
1749 case "superweapons":
1750 got += GiveValue(e, superweapons_finished, op, val);
1753 got += GiveValue(e, ammo_cells, op, val);
1756 got += GiveValue(e, ammo_plasma, op, val);
1759 got += GiveValue(e, ammo_shells, op, val);
1763 got += GiveValue(e, ammo_nails, op, val);
1766 got += GiveValue(e, ammo_rockets, op, val);
1769 got += GiveValue(e, health, op, val);
1772 got += GiveValue(e, armorvalue, op, val);
1775 got += GiveValue(e, ammo_fuel, op, val);
1778 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1779 if(cmd == it.netname)
1781 got += GiveWeapon(e, it.m_id, op, val);
1791 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1792 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1793 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND_POWERUP, SND_POWEROFF);
1794 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1795 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1796 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1797 if(!(save_weapons & (it.m_wepset)))
1798 if(e.weapons & (it.m_wepset))
1801 POSTGIVE_VALUE(e, strength_finished, 1, SND_POWERUP, SND_POWEROFF);
1802 POSTGIVE_VALUE(e, invincible_finished, 1, SND_Shield, SND_POWEROFF);
1803 POSTGIVE_VALUE(e, ammo_nails, 0, SND_ITEMPICKUP, SND_Null);
1804 POSTGIVE_VALUE(e, ammo_cells, 0, SND_ITEMPICKUP, SND_Null);
1805 POSTGIVE_VALUE(e, ammo_plasma, 0, SND_ITEMPICKUP, SND_Null);
1806 POSTGIVE_VALUE(e, ammo_shells, 0, SND_ITEMPICKUP, SND_Null);
1807 POSTGIVE_VALUE(e, ammo_rockets, 0, SND_ITEMPICKUP, SND_Null);
1808 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);
1809 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);
1810 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);
1812 if(e.superweapons_finished <= 0)
1813 if(self.weapons & WEPSET_SUPERWEAPONS)
1814 e.superweapons_finished = autocvar_g_balance_superweapons_time;
1816 if(e.strength_finished <= 0)
1817 e.strength_finished = 0;
1819 e.strength_finished += time;
1820 if(e.invincible_finished <= 0)
1821 e.invincible_finished = 0;
1823 e.invincible_finished += time;
1824 if(e.superweapons_finished <= 0)
1825 e.superweapons_finished = 0;
1827 e.superweapons_finished += time;
1829 if (!(e.weapons & WepSet_FromWeapon(PS(e).m_switchweapon)))
1830 _switchweapon = true;
1832 W_SwitchWeapon_Force(e, w_getbestweapon(e));