3 #include <common/constants.qh>
4 #include <common/deathtypes/all.qh>
5 #include <common/gamemodes/gamemode/cts/cts.qh>
6 #include <common/items/_mod.qh>
7 #include <common/mapobjects/subs.qh>
8 #include <common/mapobjects/triggers.qh>
9 #include <common/monsters/_mod.qh>
10 #include <common/mutators/mutator/buffs/buffs.qh>
11 #include <common/mutators/mutator/buffs/sv_buffs.qh>
12 #include <common/notifications/all.qh>
13 #include <common/util.qh>
14 #include <common/weapons/_all.qh>
15 #include <common/wepent.qh>
16 #include <lib/warpzone/common.qh>
17 #include <lib/warpzone/util_server.qh>
18 #include <server/bot/api.qh>
19 #include <server/command/vote.qh>
20 #include <server/damage.qh>
21 #include <server/mutators/_mod.qh>
22 #include <server/teamplay.qh>
23 #include <server/weapons/common.qh>
24 #include <server/weapons/selection.qh>
25 #include <server/weapons/weaponsystem.qh>
26 #include <server/world.qh>
28 bool ItemSend(entity this, entity to, int sf)
35 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
36 WriteByte(MSG_ENTITY, sf);
38 //WriteByte(MSG_ENTITY, this.cnt);
41 WriteVector(MSG_ENTITY, this.origin);
46 WriteAngleVector(MSG_ENTITY, this.angles);
49 // sets size on the client, unused on server
53 WriteByte(MSG_ENTITY, this.ItemStatus);
57 WriteShort(MSG_ENTITY, bound(0, this.fade_end, 32767));
58 WriteShort(MSG_ENTITY, bound(0, this.fade_start, 32767));
61 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now");
63 WriteString(MSG_ENTITY, this.mdl);
69 WriteShort(MSG_ENTITY, this.colormap);
70 WriteByte(MSG_ENTITY, this.glowmod.x * 255.0);
71 WriteByte(MSG_ENTITY, this.glowmod.y * 255.0);
72 WriteByte(MSG_ENTITY, this.glowmod.z * 255.0);
77 WriteVector(MSG_ENTITY, this.velocity);
83 void ItemUpdate(entity this)
85 this.oldorigin = this.origin;
86 this.SendFlags |= ISF_LOCATION;
89 void UpdateItemAfterTeleport(entity this)
91 if(getSendEntity(this) == ItemSend)
95 bool have_pickup_item(entity this)
97 if(this.itemdef.instanceOfPowerup)
99 if(autocvar_g_powerups > 0)
101 if(autocvar_g_powerups == 0)
106 if(autocvar_g_pickup_items > 0)
108 if(autocvar_g_pickup_items == 0)
111 if(STAT(WEAPONS, this) || this.itemdef.instanceOfAmmo) // no item or ammo pickups in weaponarena
117 void Item_Show(entity e, int mode)
119 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
120 e.ItemStatus &= ~ITS_STAYWEP;
121 entity def = e.itemdef;
124 // make the item look normal, and be touchable
126 e.solid = SOLID_TRIGGER;
127 e.spawnshieldtime = 1;
128 e.ItemStatus |= ITS_AVAILABLE;
132 // hide the item completely
133 e.model = string_null;
135 e.spawnshieldtime = 1;
136 e.ItemStatus &= ~ITS_AVAILABLE;
140 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.m_wepset & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
141 || e.team // weapon stay isn't supported for teamed weapons
143 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
145 // make the item translucent and not touchable
147 e.solid = SOLID_TRIGGER; // can STILL be picked up!
148 e.effects |= EF_STARDUST;
149 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
150 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
154 //setmodel(e, "null");
156 e.colormod = '0 0 0';
157 //e.glowmod = e.colormod;
158 e.spawnshieldtime = 1;
159 e.ItemStatus &= ~ITS_AVAILABLE;
164 e.ItemStatus |= ITS_GLOW;
166 if (autocvar_g_nodepthtestitems)
167 e.effects |= EF_NODEPTHTEST;
169 if (autocvar_g_fullbrightitems)
170 e.ItemStatus |= ITS_ALLOWFB;
172 e.ItemStatus &= ~ITS_ALLOWFB;
174 if (autocvar_sv_simple_items)
175 e.ItemStatus |= ITS_ALLOWSI;
177 // relink entity (because solid may have changed)
178 setorigin(e, e.origin);
179 e.SendFlags |= ISF_STATUS;
182 void Item_Think(entity this)
184 this.nextthink = time;
185 if(this.origin != this.oldorigin)
189 bool Item_ItemsTime_SpectatorOnly(GameItem it);
190 bool Item_ItemsTime_Allow(GameItem it);
191 float Item_ItemsTime_UpdateTime(entity e, float t);
192 void Item_ItemsTime_SetTime(entity e, float t);
193 void Item_ItemsTime_SetTimesForAllPlayers();
195 void Item_Respawn(entity this)
198 sound(this, CH_TRIGGER, this.itemdef.m_respawnsound, VOL_BASE, ATTEN_NORM); // play respawn sound
199 setorigin(this, this.origin);
201 if (Item_ItemsTime_Allow(this.itemdef) || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS))
203 float t = Item_ItemsTime_UpdateTime(this, 0);
204 Item_ItemsTime_SetTime(this, t);
205 Item_ItemsTime_SetTimesForAllPlayers();
208 setthink(this, Item_Think);
209 this.nextthink = time;
211 //Send_Effect(EFFECT_ITEM_RESPAWN, this.origin + this.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
212 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
215 void Item_RespawnCountdown(entity this)
217 if(this.item_respawncounter >= ITEM_RESPAWN_TICKS)
219 if(this.waypointsprite_attached)
220 WaypointSprite_Kill(this.waypointsprite_attached);
225 this.nextthink = time + 1;
226 this.item_respawncounter += 1;
227 if(this.item_respawncounter == 1)
231 entity wi = REGISTRY_GET(Weapons, this.weapon);
232 if (wi != WEP_Null) {
233 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon);
234 wp.wp_extra = wi.m_id;
239 entity ii = this.itemdef;
241 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Item);
242 wp.wp_extra = ii.m_id;
247 bool mutator_returnvalue = MUTATOR_CALLHOOK(Item_RespawnCountdown, this);
248 if(this.waypointsprite_attached)
250 GameItem def = this.itemdef;
251 if (Item_ItemsTime_SpectatorOnly(def) && !mutator_returnvalue)
252 WaypointSprite_UpdateRule(this.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
253 WaypointSprite_UpdateBuildFinished(this.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
257 if(this.waypointsprite_attached)
259 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
260 if(this.waypointsprite_attached.waypointsprite_visible_for_player(this.waypointsprite_attached, it, it))
263 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM, 0); // play respawn sound
267 WaypointSprite_Ping(this.waypointsprite_attached);
268 //WaypointSprite_UpdateHealth(this.waypointsprite_attached, this.item_respawncounter);
273 void Item_RespawnThink(entity this)
275 this.nextthink = time;
276 if(this.origin != this.oldorigin)
279 if(time >= this.wait)
283 void Item_ScheduleRespawnIn(entity e, float t)
285 // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
286 if ((Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS) || MUTATOR_CALLHOOK(Item_ScheduleRespawn, e, t)) && (t - ITEM_RESPAWN_TICKS) > 0)
288 setthink(e, Item_RespawnCountdown);
289 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
290 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
291 e.item_respawncounter = 0;
292 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
294 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
295 Item_ItemsTime_SetTime(e, t);
296 Item_ItemsTime_SetTimesForAllPlayers();
301 setthink(e, Item_RespawnThink);
303 e.scheduledrespawntime = time + t;
306 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
308 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
309 Item_ItemsTime_SetTime(e, t);
310 Item_ItemsTime_SetTimesForAllPlayers();
315 AUTOCVAR(g_pickup_respawntime_scaling_reciprocal, float, 0.0, "Multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players, takes effect with 2 or more players present, `reciprocal` (with `offset` and `linear` set to 0) can be used to achieve a constant number of items spawned *per player*");
316 AUTOCVAR(g_pickup_respawntime_scaling_offset, float, 0.0, "Multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players, takes effect with 2 or more players present, `offset` offsets the curve left or right - the results are not intuitive and I recommend plotting the respawn time and the number of items per player to see what's happening");
317 AUTOCVAR(g_pickup_respawntime_scaling_linear, float, 1.0, "Multiply respawn time by `reciprocal / (p + offset) + linear` where `p` is the current number of players, takes effect with 2 or more players present, `linear` can be used to simply scale the respawn time linearly");
319 /// Adjust respawn time according to the number of players.
320 float adjust_respawntime(float normal_respawntime) {
321 float r = autocvar_g_pickup_respawntime_scaling_reciprocal;
322 float o = autocvar_g_pickup_respawntime_scaling_offset;
323 float l = autocvar_g_pickup_respawntime_scaling_linear;
325 if (r == 0 && l == 1) {
326 return normal_respawntime;
329 entity balance = TeamBalance_CheckAllowedTeams(NULL);
330 TeamBalance_GetTeamCounts(balance, NULL);
332 for (int i = 1; i <= NUM_TEAMS; ++i)
334 if (TeamBalance_IsTeamAllowed(balance, i))
336 players += TeamBalance_GetNumberOfPlayers(balance, i);
339 TeamBalance_Destroy(balance);
342 return normal_respawntime * (r / (players + o) + l);
344 return normal_respawntime;
348 void Item_ScheduleRespawn(entity e)
350 if(e.respawntime > 0)
354 float adjusted_respawntime = adjust_respawntime(e.respawntime);
355 //LOG_INFOF("item %s will respawn in %f", e.classname, adjusted_respawntime);
357 // range: adjusted_respawntime - respawntimejitter .. adjusted_respawntime + respawntimejitter
358 float respawn_in = adjusted_respawntime + crandom() * e.respawntimejitter;
359 Item_ScheduleRespawnIn(e, respawn_in);
361 else // if respawntime is -1, this item does not respawn
365 AUTOCVAR(g_pickup_respawntime_initial_random, int, 1,
366 "For items that don't start spawned: 0: spawn after their normal respawntime; 1: spawn after `random * respawntime` with the *same* random; 2: same as 1 but each item has separate random");
368 void Item_ScheduleInitialRespawn(entity e)
373 if (autocvar_g_pickup_respawntime_initial_random == 0)
375 // range: respawntime .. respawntime + respawntimejitter
376 spawn_in = e.respawntime + random() * e.respawntimejitter;
381 if (autocvar_g_pickup_respawntime_initial_random == 1)
383 static float shared_random = 0;
384 // NOTE this code works only if items are scheduled at the same time (normal case)
385 // NOTE2 random() can't return exactly 1 so this check always work as intended
386 if (!shared_random || floor(time) > shared_random)
387 shared_random = floor(time) + random();
388 rnd = shared_random - floor(time);
394 // if respawntime >= ITEM_RESPAWN_TICKS: ITEM_RESPAWN_TICKS .. respawntime + respawntimejitter
395 // else: 0 .. ITEM_RESPAWN_TICKS
396 // this is to prevent powerups spawning unexpectedly without waypoints
397 spawn_in = ITEM_RESPAWN_TICKS + rnd * (e.respawntime + e.respawntimejitter - ITEM_RESPAWN_TICKS);
400 Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : spawn_in));
403 void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
406 if (num_weapons == 0)
410 int num_potential_weapons = tokenize_console(weapon_names);
411 for (int give_attempt = 0; give_attempt < num_weapons; ++give_attempt)
413 RandomSelection_Init();
414 for (int weapon_index = 0; weapon_index < num_potential_weapons;
417 string weapon = argv(weapon_index);
418 FOREACH(Weapons, it != WEP_Null,
420 // Finding a weapon which player doesn't have.
421 if (!(STAT(WEAPONS, receiver) & it.m_wepset) && (it.netname == weapon))
423 RandomSelection_AddEnt(it, 1, 1);
428 if (RandomSelection_chosen_ent == NULL)
432 STAT(WEAPONS, receiver) |= RandomSelection_chosen_ent.m_wepset;
433 if (RandomSelection_chosen_ent.ammo_type == RES_NONE)
437 if (GetResource(receiver,
438 RandomSelection_chosen_ent.ammo_type) != 0)
442 GiveResource(receiver, RandomSelection_chosen_ent.ammo_type,
443 GetResource(ammo_entity,
444 RandomSelection_chosen_ent.ammo_type));
448 bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax)
450 float amount = GetResource(item, res_type);
455 float player_amount = GetResource(player, res_type);
456 if (item.spawnshieldtime)
458 if ((player_amount >= ammomax) && (item.pickup_anyway <= 0))
461 else if (g_weapon_stay == 2)
463 ammomax = min(amount, ammomax);
464 if(player_amount >= ammomax)
470 TakeResourceWithLimit(player, res_type, -amount, ammomax);
472 GiveResourceWithLimit(player, res_type, amount, ammomax);
476 bool Item_GiveTo(entity item, entity player)
478 // if nothing happens to player, just return without taking the item
479 int _switchweapon = 0;
480 // in case the player has autoswitch enabled do the following:
481 // if the player is using their best weapon before items are given, they
482 // probably want to switch to an even better weapon after items are given
484 if(CS_CVAR(player).autoswitch)
486 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
488 .entity weaponentity = weaponentities[slot];
489 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
491 if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
492 _switchweapon |= BIT(slot);
494 if(!(STAT(WEAPONS, player) & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
495 _switchweapon |= BIT(slot);
499 bool pickedup = false;
500 pickedup |= Item_GiveAmmoTo(item, player, RES_HEALTH, item.max_health);
501 pickedup |= Item_GiveAmmoTo(item, player, RES_ARMOR, item.max_armorvalue);
502 pickedup |= Item_GiveAmmoTo(item, player, RES_SHELLS, g_pickup_shells_max);
503 pickedup |= Item_GiveAmmoTo(item, player, RES_BULLETS, g_pickup_nails_max);
504 pickedup |= Item_GiveAmmoTo(item, player, RES_ROCKETS, g_pickup_rockets_max);
505 pickedup |= Item_GiveAmmoTo(item, player, RES_CELLS, g_pickup_cells_max);
506 pickedup |= Item_GiveAmmoTo(item, player, RES_PLASMA, g_pickup_plasma_max);
507 pickedup |= Item_GiveAmmoTo(item, player, RES_FUEL, g_pickup_fuel_max);
508 if (item.itemdef.instanceOfWeaponPickup)
511 w = STAT(WEAPONS, item);
512 w &= ~STAT(WEAPONS, player);
514 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
517 FOREACH(Weapons, it != WEP_Null, {
518 if(w & (it.m_wepset))
520 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
522 .entity weaponentity = weaponentities[slot];
523 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
524 W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
526 W_GiveWeapon(player, it.m_id);
532 if (item.itemdef.instanceOfPowerup)
534 if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
535 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
536 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
537 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
541 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
545 // TODO: we probably want to show a message in the console, but not this one!
546 //Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
549 if (item.strength_finished)
552 STAT(STRENGTH_FINISHED, player) = max(STAT(STRENGTH_FINISHED, player), time) + item.strength_finished;
554 if (item.invincible_finished)
557 STAT(INVINCIBLE_FINISHED, player) = max(STAT(INVINCIBLE_FINISHED, player), time) + item.invincible_finished;
559 if (item.superweapons_finished)
562 STAT(SUPERWEAPONS_FINISHED, player) = max(STAT(SUPERWEAPONS_FINISHED, player), time) + item.superweapons_finished;
565 // always eat teamed entities
572 // crude hack to enforce switching weapons
573 if(g_cts && item.itemdef.instanceOfWeaponPickup && !CS_CVAR(player).cvar_cl_cts_noautoswitch)
575 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
577 .entity weaponentity = weaponentities[slot];
578 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
579 W_SwitchWeapon_Force(player, REGISTRY_GET(Weapons, item.weapon), weaponentity);
586 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
588 .entity weaponentity = weaponentities[slot];
589 if(_switchweapon & BIT(slot))
590 if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity))
591 W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity);
598 void Item_Touch(entity this, entity toucher)
600 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
601 if (Item_IsLoot(this))
603 if (ITEM_TOUCH_NEEDKILL())
610 if(!(toucher.flags & FL_PICKUPITEMS)
611 || STAT(FROZEN, toucher)
613 || (this.solid != SOLID_TRIGGER)
614 || (this.owner == toucher)
615 || (time < this.item_spawnshieldtime)
618 switch (MUTATOR_CALLHOOK(ItemTouch, this, toucher))
620 case MUT_ITEMTOUCH_RETURN: { return; }
621 case MUT_ITEMTOUCH_PICKUP: { toucher = M_ARGV(1, entity); goto pickup; }
624 toucher = M_ARGV(1, entity);
626 if (Item_IsExpiring(this))
628 this.strength_finished = max(0, this.strength_finished - time);
629 this.invincible_finished = max(0, this.invincible_finished - time);
630 this.superweapons_finished = max(0, this.superweapons_finished - time);
632 bool gave = ITEM_HANDLE(Pickup, this.itemdef, this, toucher);
635 if (Item_IsExpiring(this))
637 // undo what we did above
638 this.strength_finished += time;
639 this.invincible_finished += time;
640 this.superweapons_finished += time;
647 if(this.target && this.target != "" && this.target != "###item###") // defrag support
648 SUB_UseTargets(this, toucher, NULL);
650 STAT(LAST_PICKUP, toucher) = time;
652 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
653 _sound (toucher, (this.itemdef.instanceOfPowerup ? CH_TRIGGER_SINGLE : CH_TRIGGER), (this.item_pickupsound ? this.item_pickupsound : Sound_fixpath(this.item_pickupsound_ent)), VOL_BASE, ATTEN_NORM);
655 MUTATOR_CALLHOOK(ItemTouched, this, toucher);
661 if (Item_IsLoot(this))
666 if (!this.spawnshieldtime)
673 RandomSelection_Init();
674 IL_EACH(g_items, it.team == this.team,
676 if (it.itemdef) // is a registered item
679 it.scheduledrespawntime = 0;
680 RandomSelection_AddEnt(it, it.cnt, 0);
683 e = RandomSelection_chosen_ent;
684 Item_Show(e, 1); // reset its state so it is visible (extra sendflags doesn't matter, this happens anyway)
688 Item_ScheduleRespawn(e);
691 void Item_Reset(entity this)
693 Item_Show(this, !this.state);
694 setorigin(this, this.origin);
696 if (Item_IsLoot(this))
700 setthink(this, Item_Think);
701 this.nextthink = time;
702 if (this.waypointsprite_attached)
704 WaypointSprite_Kill(this.waypointsprite_attached);
706 if (this.itemdef.instanceOfPowerup || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
708 Item_ScheduleInitialRespawn(this);
712 void Item_FindTeam(entity this)
716 if(this.effects & EF_NODRAW)
718 // marker for item team search
719 LOG_TRACE("Initializing item team ", ftos(this.team));
720 RandomSelection_Init();
721 IL_EACH(g_items, it.team == this.team,
723 if(it.itemdef) // is a registered item
724 RandomSelection_AddEnt(it, it.cnt, 0);
727 e = RandomSelection_chosen_ent;
731 IL_EACH(g_items, it.team == this.team,
733 if(it.itemdef) // is a registered item
737 // make it non-spawned
739 it.state = 1; // state 1 = initially hidden item, apparently
743 it.effects &= ~EF_NODRAW;
749 // Savage: used for item garbage-collection
750 void RemoveItem(entity this)
752 if(wasfreed(this) || !this) { return; }
753 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
757 // pickup evaluation functions
758 // these functions decide how desirable an item is to the bots
760 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
762 float weapon_pickupevalfunc(entity player, entity item)
764 // See if I have it already
765 if(STAT(WEAPONS, player) & STAT(WEAPONS, item))
767 // If I can pick it up
768 if(!item.spawnshieldtime)
770 return ammo_pickupevalfunc(player, item);
773 // reduce weapon value if bot already got a good arsenal
775 int weapons_value = 0;
776 FOREACH(Weapons, it != WEP_Null && (STAT(WEAPONS, player) & it.m_wepset), {
777 weapons_value += it.bot_pickupbasevalue;
779 c -= bound(0, weapons_value / 20000, 1) * 0.5;
781 return item.bot_pickupbasevalue * c;
784 float ammo_pickupevalfunc(entity player, entity item)
786 bool need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
791 // Detect needed ammo
792 if(item.itemdef.instanceOfWeaponPickup)
795 if(GetResource(item, RES_SHELLS)) { need_shells = true; ammo = ITEM_Shells; }
796 else if(GetResource(item, RES_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; }
797 else if(GetResource(item, RES_ROCKETS)) { need_rockets = true; ammo = ITEM_Rockets; }
798 else if(GetResource(item, RES_CELLS)) { need_cells = true; ammo = ITEM_Cells; }
799 else if(GetResource(item, RES_PLASMA)) { need_plasma = true; ammo = ITEM_Plasma; }
800 else if(GetResource(item, RES_FUEL)) { need_fuel = true; ammo = ITEM_JetpackFuel; }
805 rating = ammo.m_botvalue;
809 FOREACH(Weapons, it != WEP_Null, {
810 if(!(STAT(WEAPONS, player) & (it.m_wepset)))
815 case RES_SHELLS: need_shells = true; break;
816 case RES_BULLETS: need_nails = true; break;
817 case RES_ROCKETS: need_rockets = true; break;
818 case RES_CELLS: need_cells = true; break;
819 case RES_PLASMA: need_plasma = true; break;
820 case RES_FUEL: need_fuel = true; break;
823 rating = item.bot_pickupbasevalue;
826 float noammorating = 0.5;
828 if ((need_shells) && GetResource(item, RES_SHELLS) && (GetResource(player, RES_SHELLS) < g_pickup_shells_max))
829 c = GetResource(item, RES_SHELLS) / max(noammorating, GetResource(player, RES_SHELLS));
831 if ((need_nails) && GetResource(item, RES_BULLETS) && (GetResource(player, RES_BULLETS) < g_pickup_nails_max))
832 c = GetResource(item, RES_BULLETS) / max(noammorating, GetResource(player, RES_BULLETS));
834 if ((need_rockets) && GetResource(item, RES_ROCKETS) && (GetResource(player, RES_ROCKETS) < g_pickup_rockets_max))
835 c = GetResource(item, RES_ROCKETS) / max(noammorating, GetResource(player, RES_ROCKETS));
837 if ((need_cells) && GetResource(item, RES_CELLS) && (GetResource(player, RES_CELLS) < g_pickup_cells_max))
838 c = GetResource(item, RES_CELLS) / max(noammorating, GetResource(player, RES_CELLS));
840 if ((need_plasma) && GetResource(item, RES_PLASMA) && (GetResource(player, RES_PLASMA) < g_pickup_plasma_max))
841 c = GetResource(item, RES_PLASMA) / max(noammorating, GetResource(player, RES_PLASMA));
843 if ((need_fuel) && GetResource(item, RES_FUEL) && (GetResource(player, RES_FUEL) < g_pickup_fuel_max))
844 c = GetResource(item, RES_FUEL) / max(noammorating, GetResource(player, RES_FUEL));
848 rating += wpn.bot_pickupbasevalue * 0.1;
852 float healtharmor_pickupevalfunc(entity player, entity item)
855 float rating = item.bot_pickupbasevalue;
857 float itemarmor = GetResource(item, RES_ARMOR);
858 float itemhealth = GetResource(item, RES_HEALTH);
862 itemarmor *= min(4, item.item_group_count);
863 itemhealth *= min(4, item.item_group_count);
866 if (itemarmor && (GetResource(player, RES_ARMOR) < item.max_armorvalue))
867 c = itemarmor / max(1, GetResource(player, RES_ARMOR) * 2/3 + GetResource(player, RES_HEALTH) * 1/3);
869 if (itemhealth && (GetResource(player, RES_HEALTH) < item.max_health))
870 c = itemhealth / max(1, GetResource(player, RES_HEALTH));
876 void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
878 if(ITEM_DAMAGE_NEEDKILL(deathtype))
882 void item_use(entity this, entity actor, entity trigger)
884 // use the touch function to handle collection
885 gettouch(this)(this, actor);
888 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
890 string itemname = def.m_name;
891 Model itemmodel = def.m_model;
892 Sound pickupsound = def.m_sound;
893 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
894 float pickupbasevalue = def.m_botvalue;
895 int itemflags = def.m_itemflags;
897 startitem_failed = false;
899 this.item_model_ent = itemmodel;
900 this.item_pickupsound_ent = pickupsound;
903 def.m_iteminit(def, this);
905 if(!this.respawntime) // both need to be set
907 this.respawntime = defaultrespawntime;
908 this.respawntimejitter = defaultrespawntimejitter;
911 if(!this.pickup_anyway && def.m_pickupanyway)
912 this.pickup_anyway = def.m_pickupanyway();
914 int itemid = def.m_itemid;
916 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
917 this.weapon = weaponid;
921 this.fade_start = autocvar_g_items_mindist;
922 this.fade_end = autocvar_g_items_maxdist;
926 STAT(WEAPONS, this) = WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
928 this.flags = FL_ITEM | itemflags;
929 IL_PUSH(g_items, this);
931 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
933 startitem_failed = true;
938 precache_model(this.model);
939 precache_sound(this.item_pickupsound);
941 if (Item_IsLoot(this))
943 this.reset = SUB_Remove;
944 set_movetype(this, MOVETYPE_TOSS);
946 // Savage: remove thrown items after a certain period of time ("garbage collection")
947 setthink(this, RemoveItem);
948 this.nextthink = time + 20;
950 this.takedamage = DAMAGE_YES;
951 this.event_damage = Item_Damage;
953 if (Item_IsExpiring(this))
955 // if item is worthless after a timer, have it expire then
956 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
959 // don't drop if in a NODROP zone (such as lava)
960 traceline(this.origin, this.origin, MOVE_NORMAL, this);
961 if (trace_dpstartcontents & DPCONTENTS_NODROP)
963 startitem_failed = true;
970 if(!have_pickup_item(this))
972 startitem_failed = true;
977 if(this.angles != '0 0 0')
978 this.SendFlags |= ISF_ANGLES;
980 this.reset = Item_Reset;
982 if(this.spawnflags & 1)
984 if (this.noalign > 0)
985 set_movetype(this, MOVETYPE_NONE);
987 set_movetype(this, MOVETYPE_TOSS);
988 // do item filtering according to game mode and other things
989 if (this.noalign <= 0)
991 // first nudge it off the floor a little bit to avoid math errors
992 setorigin(this, this.origin + '0 0 1');
993 // set item size before we spawn a spawnfunc_waypoint
994 setsize(this, def.m_mins, def.m_maxs);
995 this.SendFlags |= ISF_SIZE;
996 // note droptofloor returns false if stuck/or would fall too far
999 waypoint_spawnforitem(this);
1003 * can't do it that way, as it would break maps
1004 * TODO make a target_give like entity another way, that perhaps has
1005 * the weapon name in a key
1008 // target_give not yet supported; maybe later
1009 print("removed targeted ", this.classname, "\n");
1010 startitem_failed = true;
1016 if(this.targetname != "" && (this.spawnflags & 16))
1017 this.use = item_use;
1019 if(autocvar_spawn_debug >= 2)
1021 // why not flags & fl_item?
1022 FOREACH_ENTITY_RADIUS(this.origin, 3, it.is_item, {
1023 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1024 LOG_TRACE(" vs ", it.netname, vtos(it.origin));
1025 error("Mapper sucks.");
1027 this.is_item = true;
1030 weaponsInMap |= WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
1032 if ( def.instanceOfPowerup
1033 || def.instanceOfWeaponPickup
1034 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1035 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1036 || (itemid & (IT_KEY1 | IT_KEY2))
1039 if(!this.target || this.target == "")
1040 this.target = "###item###"; // for finding the nearest item using findnearest
1043 Item_ItemsTime_SetTime(this, 0);
1046 this.bot_pickup = true;
1047 this.bot_pickupevalfunc = pickupevalfunc;
1048 this.bot_pickupbasevalue = pickupbasevalue;
1049 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1050 this.netname = itemname;
1051 settouch(this, Item_Touch);
1052 setmodel(this, MDL_Null); // precision set below
1053 //this.effects |= EF_LOWPRECISION;
1055 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1057 this.SendFlags |= ISF_SIZE;
1059 if (!(this.spawnflags & 1024)) {
1060 if(def.instanceOfPowerup)
1061 this.ItemStatus |= ITS_ANIMATE1;
1063 if(GetResource(this, RES_ARMOR) || GetResource(this, RES_HEALTH))
1064 this.ItemStatus |= ITS_ANIMATE2;
1067 if(Item_IsLoot(this))
1070 if(def.instanceOfWeaponPickup)
1072 if (!Item_IsLoot(this)) // if dropped, colormap is already set up nicely
1073 this.colormap = 1024; // color shirt=0 pants=0 grey
1074 if (!(this.spawnflags & 1024))
1075 this.ItemStatus |= ITS_ANIMATE1;
1076 this.SendFlags |= ISF_COLORMAP;
1083 this.cnt = 1; // item probability weight
1085 this.effects |= EF_NODRAW; // marker for item team search
1086 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1091 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1093 // call this hook after everything else has been done
1094 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1096 startitem_failed = true;
1104 void StartItem(entity this, GameItem def)
1106 def = def.m_spawnfunc_hookreplace(def, this);
1107 if (def.spawnflags & ITEM_FLAG_MUTATORBLOCKED)
1112 this.classname = def.m_canonical_spawnfunc;
1116 def.m_respawntime(), // defaultrespawntime
1117 def.m_respawntimejitter() // defaultrespawntimejitter
1121 #define IS_SMALL(def) ((def.instanceOfHealth && def == ITEM_HealthSmall) || (def.instanceOfArmor && def == ITEM_ArmorSmall))
1122 int group_count = 1;
1124 void setItemGroup(entity this)
1126 if(!IS_SMALL(this.itemdef) || Item_IsLoot(this))
1129 FOREACH_ENTITY_RADIUS(this.origin, 120, (it != this) && IS_SMALL(it.itemdef),
1131 if(!this.item_group)
1135 it.item_group = group_count;
1138 this.item_group = it.item_group;
1140 else // spawning item is already part of a item_group X
1143 it.item_group = this.item_group;
1144 else if(it.item_group != this.item_group) // found an item near the spawning item that is part of a different item_group Y
1146 int grY = it.item_group;
1147 // move all items of item_group Y to item_group X
1148 IL_EACH(g_items, IS_SMALL(it.itemdef),
1150 if(it.item_group == grY)
1151 it.item_group = this.item_group;
1158 void setItemGroupCount()
1160 for (int k = 1; k <= group_count; k++)
1163 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { count++; });
1165 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { it.item_group_count = count; });
1169 void target_items_use(entity this, entity actor, entity trigger)
1171 if(Item_IsLoot(actor))
1173 EXACTTRIGGER_TOUCH(this, trigger);
1178 if (!IS_PLAYER(actor) || IS_DEAD(actor))
1181 if(trigger.solid == SOLID_TRIGGER)
1183 EXACTTRIGGER_TOUCH(this, trigger);
1186 IL_EACH(g_items, it.enemy == actor && Item_IsLoot(it),
1191 if(GiveItems(actor, 0, tokenize_console(this.netname)))
1192 centerprint(actor, this.message);
1195 spawnfunc(target_items)
1197 this.use = target_items_use;
1198 if(!this.strength_finished)
1199 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1200 if(!this.invincible_finished)
1201 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1202 if(!this.superweapons_finished)
1203 this.superweapons_finished = autocvar_g_balance_superweapons_time;
1206 int n = tokenize_console(this.netname);
1207 if(argv(0) == "give")
1209 str = substring(this.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1213 for(int j = 0; j < n; ++j)
1215 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1216 if (argv(j) == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS;
1217 else if(argv(j) == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_AMMO;
1218 else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS;
1219 else if(argv(j) == "strength") this.items |= ITEM_Strength.m_itemid;
1220 else if(argv(j) == "invincible") this.items |= ITEM_Shield.m_itemid;
1221 else if(argv(j) == "superweapons") this.items |= IT_SUPERWEAPON;
1222 else if(argv(j) == "jetpack") this.items |= ITEM_Jetpack.m_itemid;
1223 else if(argv(j) == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid;
1226 FOREACH(Buffs, it != BUFF_Null,
1228 string s = Buff_UndeprecateName(argv(j));
1231 STAT(BUFFS, this) |= (it.m_itemid);
1232 if(!STAT(BUFF_TIME, this))
1233 STAT(BUFF_TIME, this) = it.m_time(it);
1237 FOREACH(Weapons, it != WEP_Null, {
1238 string s = W_UndeprecateName(argv(j));
1241 STAT(WEAPONS, this) |= (it.m_wepset);
1242 if(this.spawnflags == 0 || this.spawnflags == 2)
1250 string itemprefix, valueprefix;
1251 if(this.spawnflags == 0)
1256 else if(this.spawnflags == 1)
1258 itemprefix = "max ";
1259 valueprefix = "max ";
1261 else if(this.spawnflags == 2)
1263 itemprefix = "min ";
1264 valueprefix = "min ";
1266 else if(this.spawnflags == 4)
1268 itemprefix = "minus ";
1269 valueprefix = "max ";
1273 error("invalid spawnflags");
1274 itemprefix = valueprefix = string_null;
1278 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_AMMO), "unlimited_weapon_ammo");
1279 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1280 str = sprintf("%s %s%d %s", str, valueprefix, this.strength_finished * boolean(this.items & ITEM_Strength.m_itemid), "strength");
1281 str = sprintf("%s %s%d %s", str, valueprefix, this.invincible_finished * boolean(this.items & ITEM_Shield.m_itemid), "invincible");
1282 str = sprintf("%s %s%d %s", str, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
1283 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
1284 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1286 res = GetResource(this, RES_SHELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "shells");
1287 res = GetResource(this, RES_BULLETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "nails");
1288 res = GetResource(this, RES_ROCKETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "rockets");
1289 res = GetResource(this, RES_CELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "cells");
1290 res = GetResource(this, RES_PLASMA); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "plasma");
1291 res = GetResource(this, RES_FUEL); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "fuel");
1292 res = GetResource(this, RES_HEALTH); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "health");
1293 res = GetResource(this, RES_ARMOR); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "armor");
1294 // HACK: buffs share a single timer, so we need to include enabled buffs AFTER disabled ones to avoid loss
1295 FOREACH(Buffs, it != BUFF_Null && !(STAT(BUFFS, this) & it.m_itemid), str = sprintf("%s %s%d %s", str, valueprefix, max(0, STAT(BUFF_TIME, this)), it.netname));
1296 FOREACH(Buffs, it != BUFF_Null && (STAT(BUFFS, this) & it.m_itemid), str = sprintf("%s %s%d %s", str, valueprefix, max(0, STAT(BUFF_TIME, this)), it.netname));
1297 FOREACH(Weapons, it != WEP_Null, str = sprintf("%s %s%d %s", str, itemprefix, !!(STAT(WEAPONS, this) & (it.m_wepset)), it.netname));
1299 this.netname = strzone(str);
1301 n = tokenize_console(this.netname);
1302 for(int j = 0; j < n; ++j)
1304 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(argv(j)) == it.netname, {
1311 float GiveWeapon(entity e, float wpn, float op, float val)
1314 WepSet s = WepSet_FromWeapon(REGISTRY_GET(Weapons, wpn));
1315 v0 = (STAT(WEAPONS, e) & s);
1320 STAT(WEAPONS, e) |= s;
1322 STAT(WEAPONS, e) &= ~s;
1327 STAT(WEAPONS, e) |= s;
1331 STAT(WEAPONS, e) &= ~s;
1335 STAT(WEAPONS, e) &= ~s;
1338 v1 = (STAT(WEAPONS, e) & s);
1342 bool GiveBuff(entity e, Buff thebuff, int op, int val)
1344 bool had_buff = (STAT(BUFFS, e) & thebuff.m_itemid);
1345 float new_buff_time = ((had_buff) ? STAT(BUFF_TIME, e) : 0);
1349 new_buff_time = val;
1352 new_buff_time = max(new_buff_time, val);
1355 new_buff_time = min(new_buff_time, val);
1358 new_buff_time += val;
1361 new_buff_time -= val;
1364 if(new_buff_time <= 0)
1367 STAT(BUFF_TIME, e) = new_buff_time;
1368 STAT(BUFFS, e) &= ~thebuff.m_itemid;
1372 STAT(BUFF_TIME, e) = new_buff_time;
1373 STAT(BUFFS, e) = thebuff.m_itemid; // NOTE: replaces any existing buffs on the player!
1375 bool have_buff = (STAT(BUFFS, e) & thebuff.m_itemid);
1376 return (had_buff != have_buff);
1379 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
1385 if(snd_decr != NULL)
1386 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1388 else if(v0 >= v0 + t)
1390 if(snd_incr != NULL)
1391 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1395 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1398 e.(rotfield) = max(e.(rotfield), time + rottime);
1400 e.(regenfield) = max(e.(regenfield), time + regentime);
1402 bool GiveResourceValue(entity e, int res_type, int op, int val)
1404 int v0 = GetResource(e, res_type);
1408 // min 100 cells = at least 100 cells
1409 case OP_SET: new_val = val; break;
1410 case OP_MIN: new_val = max(v0, val); break;
1411 case OP_MAX: new_val = min(v0, val); break;
1412 case OP_PLUS: new_val = v0 + val; break;
1413 case OP_MINUS: new_val = v0 - val; break;
1414 default: return false;
1417 return SetResourceExplicit(e, res_type, new_val);
1420 float GiveItems(entity e, float beginarg, float endarg)
1422 float got, i, val, op;
1430 int _switchweapon = 0;
1432 if(CS_CVAR(e).autoswitch)
1434 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1436 .entity weaponentity = weaponentities[slot];
1437 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1438 if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
1439 _switchweapon |= BIT(slot);
1443 STAT(STRENGTH_FINISHED, e) = max(0, STAT(STRENGTH_FINISHED, e) - time);
1444 STAT(INVINCIBLE_FINISHED, e) = max(0, STAT(INVINCIBLE_FINISHED, e) - time);
1445 STAT(SUPERWEAPONS_FINISHED, e) = max(0, STAT(SUPERWEAPONS_FINISHED, e) - time);
1446 STAT(BUFF_TIME, e) = max(0, STAT(BUFF_TIME, e) - time);
1450 PREGIVE(e, stat_STRENGTH_FINISHED);
1451 PREGIVE(e, stat_INVINCIBLE_FINISHED);
1452 PREGIVE(e, stat_SUPERWEAPONS_FINISHED);
1453 PREGIVE_RESOURCE(e, RES_BULLETS);
1454 PREGIVE_RESOURCE(e, RES_CELLS);
1455 PREGIVE_RESOURCE(e, RES_PLASMA);
1456 PREGIVE_RESOURCE(e, RES_SHELLS);
1457 PREGIVE_RESOURCE(e, RES_ROCKETS);
1458 PREGIVE_RESOURCE(e, RES_FUEL);
1459 PREGIVE_RESOURCE(e, RES_ARMOR);
1460 PREGIVE_RESOURCE(e, RES_HEALTH);
1462 for(i = beginarg; i < endarg; ++i)
1466 if(cmd == "0" || stof(cmd))
1490 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1491 got += GiveValue(e, stat_STRENGTH_FINISHED, op, val);
1492 got += GiveValue(e, stat_INVINCIBLE_FINISHED, op, val);
1493 got += GiveValue(e, stat_SUPERWEAPONS_FINISHED, op, val);
1494 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1496 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1497 got += GiveResourceValue(e, RES_HEALTH, op, val);
1498 got += GiveResourceValue(e, RES_ARMOR, op, val);
1500 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)), got += GiveWeapon(e, it.m_id, op, val));
1501 //case "allbuffs": // all buffs makes a player god, do not want!
1502 //FOREACH(Buffs, it != BUFF_Null, got += GiveBuff(e, it.m_itemid, op, val));
1504 got += GiveResourceValue(e, RES_CELLS, op, val);
1505 got += GiveResourceValue(e, RES_PLASMA, op, val);
1506 got += GiveResourceValue(e, RES_SHELLS, op, val);
1507 got += GiveResourceValue(e, RES_BULLETS, op, val);
1508 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1509 got += GiveResourceValue(e, RES_FUEL, op, val);
1511 case "unlimited_ammo":
1512 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1513 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1515 case "unlimited_weapon_ammo":
1516 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1518 case "unlimited_superweapons":
1519 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1522 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1525 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1528 got += GiveValue(e, stat_STRENGTH_FINISHED, op, val);
1531 got += GiveValue(e, stat_INVINCIBLE_FINISHED, op, val);
1533 case "superweapons":
1534 got += GiveValue(e, stat_SUPERWEAPONS_FINISHED, op, val);
1537 got += GiveResourceValue(e, RES_CELLS, op, val);
1540 got += GiveResourceValue(e, RES_PLASMA, op, val);
1543 got += GiveResourceValue(e, RES_SHELLS, op, val);
1547 got += GiveResourceValue(e, RES_BULLETS, op, val);
1550 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1553 got += GiveResourceValue(e, RES_HEALTH, op, val);
1556 got += GiveResourceValue(e, RES_ARMOR, op, val);
1559 got += GiveResourceValue(e, RES_FUEL, op, val);
1562 FOREACH(Buffs, it != BUFF_Null && buff_Available(it) && Buff_UndeprecateName(cmd) == it.netname,
1564 got += GiveBuff(e, it, op, val);
1567 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
1568 got += GiveWeapon(e, it.m_id, op, val);
1577 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1578 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1579 POSTGIVE_BIT(e, items, IT_UNLIMITED_AMMO, SND_POWERUP, SND_POWEROFF);
1580 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1581 FOREACH(Weapons, it != WEP_Null, {
1582 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1583 if(!(save_weapons & (it.m_wepset)))
1584 if(STAT(WEAPONS, e) & (it.m_wepset))
1587 POSTGIVE_VALUE(e, stat_STRENGTH_FINISHED, 1, SND_POWERUP, SND_POWEROFF);
1588 POSTGIVE_VALUE(e, stat_INVINCIBLE_FINISHED, 1, SND_Shield, SND_POWEROFF);
1589 //POSTGIVE_VALUE(e, stat_SUPERWEAPONS_FINISHED, 1, SND_Null, SND_Null);
1590 POSTGIVE_RESOURCE(e, RES_BULLETS, 0, SND_ITEMPICKUP, SND_Null);
1591 POSTGIVE_RESOURCE(e, RES_CELLS, 0, SND_ITEMPICKUP, SND_Null);
1592 POSTGIVE_RESOURCE(e, RES_PLASMA, 0, SND_ITEMPICKUP, SND_Null);
1593 POSTGIVE_RESOURCE(e, RES_SHELLS, 0, SND_ITEMPICKUP, SND_Null);
1594 POSTGIVE_RESOURCE(e, RES_ROCKETS, 0, SND_ITEMPICKUP, SND_Null);
1595 POSTGIVE_RES_ROT(e, RES_FUEL, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND_ITEMPICKUP, SND_Null);
1596 POSTGIVE_RES_ROT(e, RES_ARMOR, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_ARMOR25, SND_Null);
1597 POSTGIVE_RES_ROT(e, RES_HEALTH, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_MEGAHEALTH, SND_Null);
1599 if(STAT(SUPERWEAPONS_FINISHED, e) <= 0)
1600 if(!g_weaponarena && (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
1601 STAT(SUPERWEAPONS_FINISHED, e) = autocvar_g_balance_superweapons_time;
1603 if(STAT(STRENGTH_FINISHED, e) <= 0)
1604 STAT(STRENGTH_FINISHED, e) = 0;
1606 STAT(STRENGTH_FINISHED, e) += time;
1607 if(STAT(INVINCIBLE_FINISHED, e) <= 0)
1608 STAT(INVINCIBLE_FINISHED, e) = 0;
1610 STAT(INVINCIBLE_FINISHED, e) += time;
1611 if(STAT(SUPERWEAPONS_FINISHED, e) <= 0)
1612 STAT(SUPERWEAPONS_FINISHED, e) = 0;
1614 STAT(SUPERWEAPONS_FINISHED, e) += time;
1615 if(STAT(BUFF_TIME, e) <= 0)
1616 STAT(BUFF_TIME, e) = 0;
1618 STAT(BUFF_TIME, e) += time;
1620 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1622 .entity weaponentity = weaponentities[slot];
1623 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1624 if(!(STAT(WEAPONS, e) & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
1625 _switchweapon |= BIT(slot);
1630 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1632 .entity weaponentity = weaponentities[slot];
1633 if(_switchweapon & BIT(slot))
1635 Weapon wep = w_getbestweapon(e, weaponentity);
1636 if(wep != e.(weaponentity).m_switchweapon)
1637 W_SwitchWeapon_Force(e, wep, weaponentity);