3 #include <common/constants.qh>
4 #include <common/deathtypes/all.qh>
5 #include <common/items/_mod.qh>
6 #include <common/mapobjects/subs.qh>
7 #include <common/mapobjects/triggers.qh>
8 #include <common/monsters/_mod.qh>
9 #include <common/mutators/mutator/buffs/buffs.qh>
10 #include <common/mutators/mutator/buffs/sv_buffs.qh>
11 #include <common/notifications/all.qh>
12 #include <common/util.qh>
13 #include <common/weapons/_all.qh>
14 #include <common/wepent.qh>
15 #include <lib/warpzone/util_server.qh>
16 #include <server/bot/api.qh>
17 #include <server/command/vote.qh>
18 #include <server/damage.qh>
19 #include <server/mutators/_mod.qh>
20 #include <server/teamplay.qh>
21 #include <server/weapons/common.qh>
22 #include <server/weapons/selection.qh>
23 #include <server/weapons/weaponsystem.qh>
24 #include <server/world.qh>
26 bool ItemSend(entity this, entity to, int sf)
33 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
34 WriteByte(MSG_ENTITY, sf);
36 //WriteByte(MSG_ENTITY, this.cnt);
39 WriteVector(MSG_ENTITY, this.origin);
44 WriteAngleVector(MSG_ENTITY, this.angles);
47 // sets size on the client, unused on server
51 WriteByte(MSG_ENTITY, this.ItemStatus);
55 WriteShort(MSG_ENTITY, this.fade_end);
56 WriteShort(MSG_ENTITY, this.fade_start);
59 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now");
61 WriteString(MSG_ENTITY, this.mdl);
67 WriteShort(MSG_ENTITY, this.colormap);
68 WriteByte(MSG_ENTITY, this.glowmod.x * 255.0);
69 WriteByte(MSG_ENTITY, this.glowmod.y * 255.0);
70 WriteByte(MSG_ENTITY, this.glowmod.z * 255.0);
75 WriteVector(MSG_ENTITY, this.velocity);
81 void ItemUpdate(entity this)
83 this.oldorigin = this.origin;
84 this.SendFlags |= ISF_LOCATION;
87 void UpdateItemAfterTeleport(entity this)
89 if(getSendEntity(this) == ItemSend)
93 bool have_pickup_item(entity this)
95 if(this.itemdef.instanceOfPowerup)
97 if(autocvar_g_powerups > 0)
99 if(autocvar_g_powerups == 0)
104 if(autocvar_g_pickup_items > 0)
106 if(autocvar_g_pickup_items == 0)
109 if(STAT(WEAPONS, this) || this.itemdef.instanceOfAmmo) // no item or ammo pickups in weaponarena
115 void Item_Show(entity e, int mode)
117 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
118 e.ItemStatus &= ~ITS_STAYWEP;
119 entity def = e.itemdef;
122 // make the item look normal, and be touchable
124 e.solid = SOLID_TRIGGER;
125 e.spawnshieldtime = 1;
126 e.ItemStatus |= ITS_AVAILABLE;
130 // hide the item completely
131 e.model = string_null;
133 e.spawnshieldtime = 1;
134 e.ItemStatus &= ~ITS_AVAILABLE;
138 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.m_wepset & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
139 || e.team // weapon stay isn't supported for teamed weapons
141 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
143 // make the item translucent and not touchable
145 e.solid = SOLID_TRIGGER; // can STILL be picked up!
146 e.effects |= EF_STARDUST;
147 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
148 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
152 //setmodel(e, "null");
154 e.colormod = '0 0 0';
155 //e.glowmod = e.colormod;
156 e.spawnshieldtime = 1;
157 e.ItemStatus &= ~ITS_AVAILABLE;
162 e.ItemStatus |= ITS_GLOW;
164 if (autocvar_g_nodepthtestitems)
165 e.effects |= EF_NODEPTHTEST;
167 if (autocvar_g_fullbrightitems)
168 e.ItemStatus |= ITS_ALLOWFB;
170 e.ItemStatus &= ~ITS_ALLOWFB;
172 if (autocvar_sv_simple_items)
173 e.ItemStatus |= ITS_ALLOWSI;
175 // relink entity (because solid may have changed)
176 setorigin(e, e.origin);
177 e.SendFlags |= ISF_STATUS;
180 void Item_Think(entity this)
182 this.nextthink = time;
183 if(this.origin != this.oldorigin)
187 bool Item_ItemsTime_SpectatorOnly(GameItem it);
188 bool Item_ItemsTime_Allow(GameItem it);
189 float Item_ItemsTime_UpdateTime(entity e, float t);
190 void Item_ItemsTime_SetTime(entity e, float t);
191 void Item_ItemsTime_SetTimesForAllPlayers();
193 void Item_Respawn(entity this)
196 sound(this, CH_TRIGGER, this.itemdef.m_respawnsound, VOL_BASE, ATTEN_NORM); // play respawn sound
197 setorigin(this, this.origin);
199 if (Item_ItemsTime_Allow(this.itemdef) || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS))
201 float t = Item_ItemsTime_UpdateTime(this, 0);
202 Item_ItemsTime_SetTime(this, t);
203 Item_ItemsTime_SetTimesForAllPlayers();
206 setthink(this, Item_Think);
207 this.nextthink = time;
209 //Send_Effect(EFFECT_ITEM_RESPAWN, this.origin + this.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
210 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
213 void Item_RespawnCountdown(entity this)
215 if(this.item_respawncounter >= ITEM_RESPAWN_TICKS)
217 if(this.waypointsprite_attached)
218 WaypointSprite_Kill(this.waypointsprite_attached);
223 this.nextthink = time + 1;
224 this.item_respawncounter += 1;
225 if(this.item_respawncounter == 1)
229 entity wi = REGISTRY_GET(Weapons, this.weapon);
230 if (wi != WEP_Null) {
231 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon);
232 wp.wp_extra = wi.m_id;
237 entity ii = this.itemdef;
239 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Item);
240 wp.wp_extra = ii.m_id;
245 bool mutator_returnvalue = MUTATOR_CALLHOOK(Item_RespawnCountdown, this);
246 if(this.waypointsprite_attached)
248 GameItem def = this.itemdef;
249 if (Item_ItemsTime_SpectatorOnly(def) && !mutator_returnvalue)
250 WaypointSprite_UpdateRule(this.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
251 WaypointSprite_UpdateBuildFinished(this.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
255 if(this.waypointsprite_attached)
257 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
258 if(this.waypointsprite_attached.waypointsprite_visible_for_player(this.waypointsprite_attached, it, it))
261 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM, 0); // play respawn sound
265 WaypointSprite_Ping(this.waypointsprite_attached);
266 //WaypointSprite_UpdateHealth(this.waypointsprite_attached, this.item_respawncounter);
271 void Item_RespawnThink(entity this)
273 this.nextthink = time;
274 if(this.origin != this.oldorigin)
277 if(time >= this.wait)
281 void Item_ScheduleRespawnIn(entity e, float t)
283 // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
284 if ((Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS) || MUTATOR_CALLHOOK(Item_ScheduleRespawn, e, t)) && (t - ITEM_RESPAWN_TICKS) > 0)
286 setthink(e, Item_RespawnCountdown);
287 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
288 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
289 e.item_respawncounter = 0;
290 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
292 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
293 Item_ItemsTime_SetTime(e, t);
294 Item_ItemsTime_SetTimesForAllPlayers();
299 setthink(e, Item_RespawnThink);
301 e.scheduledrespawntime = time + t;
304 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
306 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
307 Item_ItemsTime_SetTime(e, t);
308 Item_ItemsTime_SetTimesForAllPlayers();
313 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*");
314 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");
315 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");
317 /// Adjust respawn time according to the number of players.
318 float adjust_respawntime(float normal_respawntime) {
319 float r = autocvar_g_pickup_respawntime_scaling_reciprocal;
320 float o = autocvar_g_pickup_respawntime_scaling_offset;
321 float l = autocvar_g_pickup_respawntime_scaling_linear;
323 if (r == 0 && l == 1) {
324 return normal_respawntime;
327 entity balance = TeamBalance_CheckAllowedTeams(NULL);
328 TeamBalance_GetTeamCounts(balance, NULL);
330 for (int i = 1; i <= NUM_TEAMS; ++i)
332 if (TeamBalance_IsTeamAllowed(balance, i))
334 players += TeamBalance_GetNumberOfPlayers(balance, i);
337 TeamBalance_Destroy(balance);
340 return normal_respawntime * (r / (players + o) + l);
342 return normal_respawntime;
346 void Item_ScheduleRespawn(entity e)
348 if(e.respawntime > 0)
352 float adjusted_respawntime = adjust_respawntime(e.respawntime);
353 //LOG_INFOF("item %s will respawn in %f", e.classname, adjusted_respawntime);
355 // range: adjusted_respawntime - respawntimejitter .. adjusted_respawntime + respawntimejitter
356 float respawn_in = adjusted_respawntime + crandom() * e.respawntimejitter;
357 Item_ScheduleRespawnIn(e, respawn_in);
359 else // if respawntime is -1, this item does not respawn
363 AUTOCVAR(g_pickup_respawntime_initial_random, int, 1,
364 "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");
366 void Item_ScheduleInitialRespawn(entity e)
371 if (autocvar_g_pickup_respawntime_initial_random == 0)
373 // range: respawntime .. respawntime + respawntimejitter
374 spawn_in = e.respawntime + random() * e.respawntimejitter;
379 if (autocvar_g_pickup_respawntime_initial_random == 1)
381 static float shared_random = 0;
382 // NOTE this code works only if items are scheduled at the same time (normal case)
383 // NOTE2 random() can't return exactly 1 so this check always work as intended
384 if (!shared_random || floor(time) > shared_random)
385 shared_random = floor(time) + random();
386 rnd = shared_random - floor(time);
392 // if respawntime >= ITEM_RESPAWN_TICKS: ITEM_RESPAWN_TICKS .. respawntime + respawntimejitter
393 // else: 0 .. ITEM_RESPAWN_TICKS
394 // this is to prevent powerups spawning unexpectedly without waypoints
395 spawn_in = ITEM_RESPAWN_TICKS + rnd * (e.respawntime + e.respawntimejitter - ITEM_RESPAWN_TICKS);
398 Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : spawn_in));
401 void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
404 if (num_weapons == 0)
408 int num_potential_weapons = tokenize_console(weapon_names);
409 for (int give_attempt = 0; give_attempt < num_weapons; ++give_attempt)
411 RandomSelection_Init();
412 for (int weapon_index = 0; weapon_index < num_potential_weapons;
415 string weapon = argv(weapon_index);
416 FOREACH(Weapons, it != WEP_Null,
418 // Finding a weapon which player doesn't have.
419 if (!(STAT(WEAPONS, receiver) & it.m_wepset) && (it.netname == weapon))
421 RandomSelection_AddEnt(it, 1, 1);
426 if (RandomSelection_chosen_ent == NULL)
430 STAT(WEAPONS, receiver) |= RandomSelection_chosen_ent.m_wepset;
431 if (RandomSelection_chosen_ent.ammo_type == RES_NONE)
435 if (GetResource(receiver,
436 RandomSelection_chosen_ent.ammo_type) != 0)
440 GiveResource(receiver, RandomSelection_chosen_ent.ammo_type,
441 GetResource(ammo_entity,
442 RandomSelection_chosen_ent.ammo_type));
446 bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax)
448 float amount = GetResource(item, res_type);
453 float player_amount = GetResource(player, res_type);
454 if (item.spawnshieldtime)
456 if ((player_amount >= ammomax) && (item.pickup_anyway <= 0))
459 else if (g_weapon_stay == 2)
461 ammomax = min(amount, ammomax);
462 if(player_amount >= ammomax)
468 TakeResourceWithLimit(player, res_type, -amount, ammomax);
470 GiveResourceWithLimit(player, res_type, amount, ammomax);
474 bool Item_GiveTo(entity item, entity player)
476 // if nothing happens to player, just return without taking the item
477 int _switchweapon = 0;
478 // in case the player has autoswitch enabled do the following:
479 // if the player is using their best weapon before items are given, they
480 // probably want to switch to an even better weapon after items are given
482 if(CS(player).autoswitch)
484 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
486 .entity weaponentity = weaponentities[slot];
487 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
489 if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
490 _switchweapon |= BIT(slot);
492 if(!(STAT(WEAPONS, player) & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
493 _switchweapon |= BIT(slot);
497 bool pickedup = false;
498 pickedup |= Item_GiveAmmoTo(item, player, RES_HEALTH, item.max_health);
499 pickedup |= Item_GiveAmmoTo(item, player, RES_ARMOR, item.max_armorvalue);
500 pickedup |= Item_GiveAmmoTo(item, player, RES_SHELLS, g_pickup_shells_max);
501 pickedup |= Item_GiveAmmoTo(item, player, RES_BULLETS, g_pickup_nails_max);
502 pickedup |= Item_GiveAmmoTo(item, player, RES_ROCKETS, g_pickup_rockets_max);
503 pickedup |= Item_GiveAmmoTo(item, player, RES_CELLS, g_pickup_cells_max);
504 pickedup |= Item_GiveAmmoTo(item, player, RES_PLASMA, g_pickup_plasma_max);
505 pickedup |= Item_GiveAmmoTo(item, player, RES_FUEL, g_pickup_fuel_max);
506 if (item.itemdef.instanceOfWeaponPickup)
509 w = STAT(WEAPONS, item);
510 w &= ~STAT(WEAPONS, player);
512 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
515 FOREACH(Weapons, it != WEP_Null, {
516 if(w & (it.m_wepset))
518 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
520 .entity weaponentity = weaponentities[slot];
521 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
522 W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
524 W_GiveWeapon(player, it.m_id);
530 if (item.itemdef.instanceOfPowerup)
532 if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
533 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
534 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
535 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
539 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
543 // TODO: we probably want to show a message in the console, but not this one!
544 //Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
547 if (item.strength_finished)
550 STAT(STRENGTH_FINISHED, player) = max(STAT(STRENGTH_FINISHED, player), time) + item.strength_finished;
552 if (item.invincible_finished)
555 STAT(INVINCIBLE_FINISHED, player) = max(STAT(INVINCIBLE_FINISHED, player), time) + item.invincible_finished;
557 if (item.superweapons_finished)
560 STAT(SUPERWEAPONS_FINISHED, player) = max(STAT(SUPERWEAPONS_FINISHED, player), time) + item.superweapons_finished;
563 // always eat teamed entities
570 // crude hack to enforce switching weapons
571 if(g_cts && item.itemdef.instanceOfWeaponPickup && !CS(player).cvar_cl_cts_noautoswitch)
573 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
575 .entity weaponentity = weaponentities[slot];
576 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
577 W_SwitchWeapon_Force(player, REGISTRY_GET(Weapons, item.weapon), weaponentity);
584 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
586 .entity weaponentity = weaponentities[slot];
587 if(_switchweapon & BIT(slot))
588 if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity))
589 W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity);
596 void Item_Touch(entity this, entity toucher)
598 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
599 if (Item_IsLoot(this))
601 if (ITEM_TOUCH_NEEDKILL())
608 if(!(toucher.flags & FL_PICKUPITEMS)
609 || STAT(FROZEN, toucher)
611 || (this.solid != SOLID_TRIGGER)
612 || (this.owner == toucher)
613 || (time < this.item_spawnshieldtime)
616 switch (MUTATOR_CALLHOOK(ItemTouch, this, toucher))
618 case MUT_ITEMTOUCH_RETURN: { return; }
619 case MUT_ITEMTOUCH_PICKUP: { toucher = M_ARGV(1, entity); goto pickup; }
622 toucher = M_ARGV(1, entity);
624 if (Item_IsExpiring(this))
626 this.strength_finished = max(0, this.strength_finished - time);
627 this.invincible_finished = max(0, this.invincible_finished - time);
628 this.superweapons_finished = max(0, this.superweapons_finished - time);
630 bool gave = ITEM_HANDLE(Pickup, this.itemdef, this, toucher);
633 if (Item_IsExpiring(this))
635 // undo what we did above
636 this.strength_finished += time;
637 this.invincible_finished += time;
638 this.superweapons_finished += time;
645 if(this.target && this.target != "" && this.target != "###item###") // defrag support
646 SUB_UseTargets(this, toucher, NULL);
648 STAT(LAST_PICKUP, toucher) = time;
650 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
651 _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);
653 MUTATOR_CALLHOOK(ItemTouched, this, toucher);
659 if (Item_IsLoot(this))
664 if (!this.spawnshieldtime)
671 RandomSelection_Init();
672 IL_EACH(g_items, it.team == this.team,
674 if (it.itemdef) // is a registered item
677 it.scheduledrespawntime = 0;
678 RandomSelection_AddEnt(it, it.cnt, 0);
681 e = RandomSelection_chosen_ent;
682 Item_Show(e, 1); // reset its state so it is visible (extra sendflags doesn't matter, this happens anyway)
686 Item_ScheduleRespawn(e);
689 void Item_Reset(entity this)
691 Item_Show(this, !this.state);
692 setorigin(this, this.origin);
694 if (Item_IsLoot(this))
698 setthink(this, Item_Think);
699 this.nextthink = time;
700 if (this.waypointsprite_attached)
702 WaypointSprite_Kill(this.waypointsprite_attached);
704 if (this.itemdef.instanceOfPowerup || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
706 Item_ScheduleInitialRespawn(this);
710 void Item_FindTeam(entity this)
714 if(this.effects & EF_NODRAW)
716 // marker for item team search
717 LOG_TRACE("Initializing item team ", ftos(this.team));
718 RandomSelection_Init();
719 IL_EACH(g_items, it.team == this.team,
721 if(it.itemdef) // is a registered item
722 RandomSelection_AddEnt(it, it.cnt, 0);
725 e = RandomSelection_chosen_ent;
729 IL_EACH(g_items, it.team == this.team,
731 if(it.itemdef) // is a registered item
735 // make it non-spawned
737 it.state = 1; // state 1 = initially hidden item, apparently
741 it.effects &= ~EF_NODRAW;
747 // Savage: used for item garbage-collection
748 void RemoveItem(entity this)
750 if(wasfreed(this) || !this) { return; }
751 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
755 // pickup evaluation functions
756 // these functions decide how desirable an item is to the bots
758 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
760 float weapon_pickupevalfunc(entity player, entity item)
762 // See if I have it already
763 if(STAT(WEAPONS, player) & STAT(WEAPONS, item))
765 // If I can pick it up
766 if(!item.spawnshieldtime)
768 return ammo_pickupevalfunc(player, item);
771 // reduce weapon value if bot already got a good arsenal
773 int weapons_value = 0;
774 FOREACH(Weapons, it != WEP_Null && (STAT(WEAPONS, player) & it.m_wepset), {
775 weapons_value += it.bot_pickupbasevalue;
777 c -= bound(0, weapons_value / 20000, 1) * 0.5;
779 return item.bot_pickupbasevalue * c;
782 float ammo_pickupevalfunc(entity player, entity item)
784 bool need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
789 // Detect needed ammo
790 if(item.itemdef.instanceOfWeaponPickup)
793 if(GetResource(item, RES_SHELLS)) { need_shells = true; ammo = ITEM_Shells; }
794 else if(GetResource(item, RES_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; }
795 else if(GetResource(item, RES_ROCKETS)) { need_rockets = true; ammo = ITEM_Rockets; }
796 else if(GetResource(item, RES_CELLS)) { need_cells = true; ammo = ITEM_Cells; }
797 else if(GetResource(item, RES_PLASMA)) { need_plasma = true; ammo = ITEM_Plasma; }
798 else if(GetResource(item, RES_FUEL)) { need_fuel = true; ammo = ITEM_JetpackFuel; }
803 rating = ammo.m_botvalue;
807 FOREACH(Weapons, it != WEP_Null, {
808 if(!(STAT(WEAPONS, player) & (it.m_wepset)))
813 case RES_SHELLS: need_shells = true; break;
814 case RES_BULLETS: need_nails = true; break;
815 case RES_ROCKETS: need_rockets = true; break;
816 case RES_CELLS: need_cells = true; break;
817 case RES_PLASMA: need_plasma = true; break;
818 case RES_FUEL: need_fuel = true; break;
821 rating = item.bot_pickupbasevalue;
824 float noammorating = 0.5;
826 if ((need_shells) && GetResource(item, RES_SHELLS) && (GetResource(player, RES_SHELLS) < g_pickup_shells_max))
827 c = GetResource(item, RES_SHELLS) / max(noammorating, GetResource(player, RES_SHELLS));
829 if ((need_nails) && GetResource(item, RES_BULLETS) && (GetResource(player, RES_BULLETS) < g_pickup_nails_max))
830 c = GetResource(item, RES_BULLETS) / max(noammorating, GetResource(player, RES_BULLETS));
832 if ((need_rockets) && GetResource(item, RES_ROCKETS) && (GetResource(player, RES_ROCKETS) < g_pickup_rockets_max))
833 c = GetResource(item, RES_ROCKETS) / max(noammorating, GetResource(player, RES_ROCKETS));
835 if ((need_cells) && GetResource(item, RES_CELLS) && (GetResource(player, RES_CELLS) < g_pickup_cells_max))
836 c = GetResource(item, RES_CELLS) / max(noammorating, GetResource(player, RES_CELLS));
838 if ((need_plasma) && GetResource(item, RES_PLASMA) && (GetResource(player, RES_PLASMA) < g_pickup_plasma_max))
839 c = GetResource(item, RES_PLASMA) / max(noammorating, GetResource(player, RES_PLASMA));
841 if ((need_fuel) && GetResource(item, RES_FUEL) && (GetResource(player, RES_FUEL) < g_pickup_fuel_max))
842 c = GetResource(item, RES_FUEL) / max(noammorating, GetResource(player, RES_FUEL));
846 rating += wpn.bot_pickupbasevalue * 0.1;
850 float healtharmor_pickupevalfunc(entity player, entity item)
853 float rating = item.bot_pickupbasevalue;
855 float itemarmor = GetResource(item, RES_ARMOR);
856 float itemhealth = GetResource(item, RES_HEALTH);
860 itemarmor *= min(4, item.item_group_count);
861 itemhealth *= min(4, item.item_group_count);
864 if (itemarmor && (GetResource(player, RES_ARMOR) < item.max_armorvalue))
865 c = itemarmor / max(1, GetResource(player, RES_ARMOR) * 2/3 + GetResource(player, RES_HEALTH) * 1/3);
867 if (itemhealth && (GetResource(player, RES_HEALTH) < item.max_health))
868 c = itemhealth / max(1, GetResource(player, RES_HEALTH));
874 void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
876 if(ITEM_DAMAGE_NEEDKILL(deathtype))
880 void item_use(entity this, entity actor, entity trigger)
882 // use the touch function to handle collection
883 gettouch(this)(this, actor);
886 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
888 string itemname = def.m_name;
889 Model itemmodel = def.m_model;
890 Sound pickupsound = def.m_sound;
891 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
892 float pickupbasevalue = def.m_botvalue;
893 int itemflags = def.m_itemflags;
895 startitem_failed = false;
897 this.item_model_ent = itemmodel;
898 this.item_pickupsound_ent = pickupsound;
901 def.m_iteminit(def, this);
903 if(!this.respawntime) // both need to be set
905 this.respawntime = defaultrespawntime;
906 this.respawntimejitter = defaultrespawntimejitter;
909 if(!this.pickup_anyway && def.m_pickupanyway)
910 this.pickup_anyway = def.m_pickupanyway();
912 int itemid = def.m_itemid;
914 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
915 this.weapon = weaponid;
919 this.fade_start = autocvar_g_items_mindist;
920 this.fade_end = autocvar_g_items_maxdist;
924 STAT(WEAPONS, this) = WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
926 this.flags = FL_ITEM | itemflags;
927 IL_PUSH(g_items, this);
929 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
931 startitem_failed = true;
936 precache_model(this.model);
937 precache_sound(this.item_pickupsound);
939 if (Item_IsLoot(this))
941 this.reset = SUB_Remove;
942 set_movetype(this, MOVETYPE_TOSS);
944 // Savage: remove thrown items after a certain period of time ("garbage collection")
945 setthink(this, RemoveItem);
946 this.nextthink = time + 20;
948 this.takedamage = DAMAGE_YES;
949 this.event_damage = Item_Damage;
951 if (Item_IsExpiring(this))
953 // if item is worthless after a timer, have it expire then
954 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
957 // don't drop if in a NODROP zone (such as lava)
958 traceline(this.origin, this.origin, MOVE_NORMAL, this);
959 if (trace_dpstartcontents & DPCONTENTS_NODROP)
961 startitem_failed = true;
968 if(!have_pickup_item(this))
970 startitem_failed = true;
975 if(this.angles != '0 0 0')
976 this.SendFlags |= ISF_ANGLES;
978 this.reset = Item_Reset;
980 if(this.spawnflags & 1)
982 if (this.noalign > 0)
983 set_movetype(this, MOVETYPE_NONE);
985 set_movetype(this, MOVETYPE_TOSS);
986 // do item filtering according to game mode and other things
987 if (this.noalign <= 0)
989 // first nudge it off the floor a little bit to avoid math errors
990 setorigin(this, this.origin + '0 0 1');
991 // set item size before we spawn a spawnfunc_waypoint
992 setsize(this, def.m_mins, def.m_maxs);
993 this.SendFlags |= ISF_SIZE;
994 // note droptofloor returns false if stuck/or would fall too far
997 waypoint_spawnforitem(this);
1001 * can't do it that way, as it would break maps
1002 * TODO make a target_give like entity another way, that perhaps has
1003 * the weapon name in a key
1006 // target_give not yet supported; maybe later
1007 print("removed targeted ", this.classname, "\n");
1008 startitem_failed = true;
1014 if(this.targetname != "" && (this.spawnflags & 16))
1015 this.use = item_use;
1017 if(autocvar_spawn_debug >= 2)
1019 // why not flags & fl_item?
1020 FOREACH_ENTITY_RADIUS(this.origin, 3, it.is_item, {
1021 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1022 LOG_TRACE(" vs ", it.netname, vtos(it.origin));
1023 error("Mapper sucks.");
1025 this.is_item = true;
1028 weaponsInMap |= WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
1030 if ( def.instanceOfPowerup
1031 || def.instanceOfWeaponPickup
1032 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1033 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1034 || (itemid & (IT_KEY1 | IT_KEY2))
1037 if(!this.target || this.target == "")
1038 this.target = "###item###"; // for finding the nearest item using findnearest
1041 Item_ItemsTime_SetTime(this, 0);
1044 this.bot_pickup = true;
1045 this.bot_pickupevalfunc = pickupevalfunc;
1046 this.bot_pickupbasevalue = pickupbasevalue;
1047 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1048 this.netname = itemname;
1049 settouch(this, Item_Touch);
1050 setmodel(this, MDL_Null); // precision set below
1051 //this.effects |= EF_LOWPRECISION;
1053 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1055 this.SendFlags |= ISF_SIZE;
1057 if (!(this.spawnflags & 1024)) {
1058 if(def.instanceOfPowerup)
1059 this.ItemStatus |= ITS_ANIMATE1;
1061 if(GetResource(this, RES_ARMOR) || GetResource(this, RES_HEALTH))
1062 this.ItemStatus |= ITS_ANIMATE2;
1065 if(Item_IsLoot(this))
1068 if(def.instanceOfWeaponPickup)
1070 if (!Item_IsLoot(this)) // if dropped, colormap is already set up nicely
1071 this.colormap = 1024; // color shirt=0 pants=0 grey
1072 if (!(this.spawnflags & 1024))
1073 this.ItemStatus |= ITS_ANIMATE1;
1074 this.SendFlags |= ISF_COLORMAP;
1081 this.cnt = 1; // item probability weight
1083 this.effects |= EF_NODRAW; // marker for item team search
1084 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1089 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1091 // call this hook after everything else has been done
1092 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1094 startitem_failed = true;
1102 void StartItem(entity this, GameItem def)
1104 def = def.m_spawnfunc_hookreplace(def, this);
1105 if (def.spawnflags & ITEM_FLAG_MUTATORBLOCKED)
1110 this.classname = def.m_canonical_spawnfunc;
1114 def.m_respawntime(), // defaultrespawntime
1115 def.m_respawntimejitter() // defaultrespawntimejitter
1119 #define IS_SMALL(def) ((def.instanceOfHealth && def == ITEM_HealthSmall) || (def.instanceOfArmor && def == ITEM_ArmorSmall))
1120 int group_count = 1;
1122 void setItemGroup(entity this)
1124 if(!IS_SMALL(this.itemdef) || Item_IsLoot(this))
1127 FOREACH_ENTITY_RADIUS(this.origin, 120, (it != this) && IS_SMALL(it.itemdef),
1129 if(!this.item_group)
1133 it.item_group = group_count;
1136 this.item_group = it.item_group;
1138 else // spawning item is already part of a item_group X
1141 it.item_group = this.item_group;
1142 else if(it.item_group != this.item_group) // found an item near the spawning item that is part of a different item_group Y
1144 int grY = it.item_group;
1145 // move all items of item_group Y to item_group X
1146 IL_EACH(g_items, IS_SMALL(it.itemdef),
1148 if(it.item_group == grY)
1149 it.item_group = this.item_group;
1156 void setItemGroupCount()
1158 for (int k = 1; k <= group_count; k++)
1161 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { count++; });
1163 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { it.item_group_count = count; });
1167 void target_items_use(entity this, entity actor, entity trigger)
1169 if(Item_IsLoot(actor))
1171 EXACTTRIGGER_TOUCH(this, trigger);
1176 if (!IS_PLAYER(actor) || IS_DEAD(actor))
1179 if(trigger.solid == SOLID_TRIGGER)
1181 EXACTTRIGGER_TOUCH(this, trigger);
1184 IL_EACH(g_items, it.enemy == actor && Item_IsLoot(it),
1189 if(GiveItems(actor, 0, tokenize_console(this.netname)))
1190 centerprint(actor, this.message);
1193 spawnfunc(target_items)
1195 this.use = target_items_use;
1196 if(!this.strength_finished)
1197 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1198 if(!this.invincible_finished)
1199 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1200 if(!this.superweapons_finished)
1201 this.superweapons_finished = autocvar_g_balance_superweapons_time;
1204 int n = tokenize_console(this.netname);
1205 if(argv(0) == "give")
1207 str = substring(this.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1211 for(int j = 0; j < n; ++j)
1213 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1214 if (argv(j) == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS;
1215 else if(argv(j) == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_AMMO;
1216 else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS;
1217 else if(argv(j) == "strength") this.items |= ITEM_Strength.m_itemid;
1218 else if(argv(j) == "invincible") this.items |= ITEM_Shield.m_itemid;
1219 else if(argv(j) == "superweapons") this.items |= IT_SUPERWEAPON;
1220 else if(argv(j) == "jetpack") this.items |= ITEM_Jetpack.m_itemid;
1221 else if(argv(j) == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid;
1224 FOREACH(Buffs, it != BUFF_Null,
1226 string s = Buff_UndeprecateName(argv(j));
1229 STAT(BUFFS, this) |= (it.m_itemid);
1230 if(!STAT(BUFF_TIME, this))
1231 STAT(BUFF_TIME, this) = it.m_time(it);
1235 FOREACH(Weapons, it != WEP_Null, {
1236 string s = W_UndeprecateName(argv(j));
1239 STAT(WEAPONS, this) |= (it.m_wepset);
1240 if(this.spawnflags == 0 || this.spawnflags == 2)
1248 string itemprefix, valueprefix;
1249 if(this.spawnflags == 0)
1254 else if(this.spawnflags == 1)
1256 itemprefix = "max ";
1257 valueprefix = "max ";
1259 else if(this.spawnflags == 2)
1261 itemprefix = "min ";
1262 valueprefix = "min ";
1264 else if(this.spawnflags == 4)
1266 itemprefix = "minus ";
1267 valueprefix = "max ";
1271 error("invalid spawnflags");
1272 itemprefix = valueprefix = string_null;
1276 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_AMMO), "unlimited_weapon_ammo");
1277 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1278 str = sprintf("%s %s%d %s", str, valueprefix, this.strength_finished * boolean(this.items & ITEM_Strength.m_itemid), "strength");
1279 str = sprintf("%s %s%d %s", str, valueprefix, this.invincible_finished * boolean(this.items & ITEM_Shield.m_itemid), "invincible");
1280 str = sprintf("%s %s%d %s", str, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
1281 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
1282 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1284 res = GetResource(this, RES_SHELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "shells");
1285 res = GetResource(this, RES_BULLETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "nails");
1286 res = GetResource(this, RES_ROCKETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "rockets");
1287 res = GetResource(this, RES_CELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "cells");
1288 res = GetResource(this, RES_PLASMA); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "plasma");
1289 res = GetResource(this, RES_FUEL); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "fuel");
1290 res = GetResource(this, RES_HEALTH); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "health");
1291 res = GetResource(this, RES_ARMOR); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "armor");
1292 // HACK: buffs share a single timer, so we need to include enabled buffs AFTER disabled ones to avoid loss
1293 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));
1294 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));
1295 FOREACH(Weapons, it != WEP_Null, str = sprintf("%s %s%d %s", str, itemprefix, !!(STAT(WEAPONS, this) & (it.m_wepset)), it.netname));
1297 this.netname = strzone(str);
1299 n = tokenize_console(this.netname);
1300 for(int j = 0; j < n; ++j)
1302 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(argv(j)) == it.netname, {
1309 float GiveWeapon(entity e, float wpn, float op, float val)
1312 WepSet s = WepSet_FromWeapon(REGISTRY_GET(Weapons, wpn));
1313 v0 = (STAT(WEAPONS, e) & s);
1318 STAT(WEAPONS, e) |= s;
1320 STAT(WEAPONS, e) &= ~s;
1325 STAT(WEAPONS, e) |= s;
1329 STAT(WEAPONS, e) &= ~s;
1333 STAT(WEAPONS, e) &= ~s;
1336 v1 = (STAT(WEAPONS, e) & s);
1340 bool GiveBuff(entity e, Buff thebuff, int op, int val)
1342 bool had_buff = (STAT(BUFFS, e) & thebuff.m_itemid);
1343 float new_buff_time = ((had_buff) ? STAT(BUFF_TIME, e) : 0);
1347 new_buff_time = val;
1350 new_buff_time = max(new_buff_time, val);
1353 new_buff_time = min(new_buff_time, val);
1356 new_buff_time += val;
1359 new_buff_time -= val;
1362 if(new_buff_time <= 0)
1365 STAT(BUFF_TIME, e) = new_buff_time;
1366 STAT(BUFFS, e) &= ~thebuff.m_itemid;
1370 STAT(BUFF_TIME, e) = new_buff_time;
1371 STAT(BUFFS, e) = thebuff.m_itemid; // NOTE: replaces any existing buffs on the player!
1373 bool have_buff = (STAT(BUFFS, e) & thebuff.m_itemid);
1374 return (had_buff != have_buff);
1377 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
1383 if(snd_decr != NULL)
1384 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1386 else if(v0 >= v0 + t)
1388 if(snd_incr != NULL)
1389 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1393 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1396 e.(rotfield) = max(e.(rotfield), time + rottime);
1398 e.(regenfield) = max(e.(regenfield), time + regentime);
1400 bool GiveResourceValue(entity e, int res_type, int op, int val)
1402 int v0 = GetResource(e, res_type);
1406 // min 100 cells = at least 100 cells
1407 case OP_SET: new_val = val; break;
1408 case OP_MIN: new_val = max(v0, val); break;
1409 case OP_MAX: new_val = min(v0, val); break;
1410 case OP_PLUS: new_val = v0 + val; break;
1411 case OP_MINUS: new_val = v0 - val; break;
1412 default: return false;
1415 return SetResourceExplicit(e, res_type, new_val);
1418 float GiveItems(entity e, float beginarg, float endarg)
1420 float got, i, val, op;
1428 int _switchweapon = 0;
1430 if(CS(e).autoswitch)
1432 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1434 .entity weaponentity = weaponentities[slot];
1435 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1436 if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
1437 _switchweapon |= BIT(slot);
1441 STAT(STRENGTH_FINISHED, e) = max(0, STAT(STRENGTH_FINISHED, e) - time);
1442 STAT(INVINCIBLE_FINISHED, e) = max(0, STAT(INVINCIBLE_FINISHED, e) - time);
1443 STAT(SUPERWEAPONS_FINISHED, e) = max(0, STAT(SUPERWEAPONS_FINISHED, e) - time);
1444 STAT(BUFF_TIME, e) = max(0, STAT(BUFF_TIME, e) - time);
1448 PREGIVE(e, stat_STRENGTH_FINISHED);
1449 PREGIVE(e, stat_INVINCIBLE_FINISHED);
1450 PREGIVE(e, stat_SUPERWEAPONS_FINISHED);
1451 PREGIVE_RESOURCE(e, RES_BULLETS);
1452 PREGIVE_RESOURCE(e, RES_CELLS);
1453 PREGIVE_RESOURCE(e, RES_PLASMA);
1454 PREGIVE_RESOURCE(e, RES_SHELLS);
1455 PREGIVE_RESOURCE(e, RES_ROCKETS);
1456 PREGIVE_RESOURCE(e, RES_FUEL);
1457 PREGIVE_RESOURCE(e, RES_ARMOR);
1458 PREGIVE_RESOURCE(e, RES_HEALTH);
1460 for(i = beginarg; i < endarg; ++i)
1464 if(cmd == "0" || stof(cmd))
1488 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1489 got += GiveValue(e, stat_STRENGTH_FINISHED, op, val);
1490 got += GiveValue(e, stat_INVINCIBLE_FINISHED, op, val);
1491 got += GiveValue(e, stat_SUPERWEAPONS_FINISHED, op, val);
1492 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1494 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1495 got += GiveResourceValue(e, RES_HEALTH, op, val);
1496 got += GiveResourceValue(e, RES_ARMOR, op, val);
1498 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)), got += GiveWeapon(e, it.m_id, op, val));
1499 //case "allbuffs": // all buffs makes a player god, do not want!
1500 //FOREACH(Buffs, it != BUFF_Null, got += GiveBuff(e, it.m_itemid, op, val));
1502 got += GiveResourceValue(e, RES_CELLS, op, val);
1503 got += GiveResourceValue(e, RES_PLASMA, op, val);
1504 got += GiveResourceValue(e, RES_SHELLS, op, val);
1505 got += GiveResourceValue(e, RES_BULLETS, op, val);
1506 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1507 got += GiveResourceValue(e, RES_FUEL, op, val);
1509 case "unlimited_ammo":
1510 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1511 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1513 case "unlimited_weapon_ammo":
1514 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1516 case "unlimited_superweapons":
1517 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1520 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1523 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1526 got += GiveValue(e, stat_STRENGTH_FINISHED, op, val);
1529 got += GiveValue(e, stat_INVINCIBLE_FINISHED, op, val);
1531 case "superweapons":
1532 got += GiveValue(e, stat_SUPERWEAPONS_FINISHED, op, val);
1535 got += GiveResourceValue(e, RES_CELLS, op, val);
1538 got += GiveResourceValue(e, RES_PLASMA, op, val);
1541 got += GiveResourceValue(e, RES_SHELLS, op, val);
1545 got += GiveResourceValue(e, RES_BULLETS, op, val);
1548 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1551 got += GiveResourceValue(e, RES_HEALTH, op, val);
1554 got += GiveResourceValue(e, RES_ARMOR, op, val);
1557 got += GiveResourceValue(e, RES_FUEL, op, val);
1560 FOREACH(Buffs, it != BUFF_Null && buff_Available(it) && Buff_UndeprecateName(cmd) == it.netname,
1562 got += GiveBuff(e, it, op, val);
1565 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
1566 got += GiveWeapon(e, it.m_id, op, val);
1575 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1576 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1577 POSTGIVE_BIT(e, items, IT_UNLIMITED_AMMO, SND_POWERUP, SND_POWEROFF);
1578 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1579 FOREACH(Weapons, it != WEP_Null, {
1580 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1581 if(!(save_weapons & (it.m_wepset)))
1582 if(STAT(WEAPONS, e) & (it.m_wepset))
1585 POSTGIVE_VALUE(e, stat_STRENGTH_FINISHED, 1, SND_POWERUP, SND_POWEROFF);
1586 POSTGIVE_VALUE(e, stat_INVINCIBLE_FINISHED, 1, SND_Shield, SND_POWEROFF);
1587 //POSTGIVE_VALUE(e, stat_SUPERWEAPONS_FINISHED, 1, SND_Null, SND_Null);
1588 POSTGIVE_RESOURCE(e, RES_BULLETS, 0, SND_ITEMPICKUP, SND_Null);
1589 POSTGIVE_RESOURCE(e, RES_CELLS, 0, SND_ITEMPICKUP, SND_Null);
1590 POSTGIVE_RESOURCE(e, RES_PLASMA, 0, SND_ITEMPICKUP, SND_Null);
1591 POSTGIVE_RESOURCE(e, RES_SHELLS, 0, SND_ITEMPICKUP, SND_Null);
1592 POSTGIVE_RESOURCE(e, RES_ROCKETS, 0, SND_ITEMPICKUP, SND_Null);
1593 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);
1594 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);
1595 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);
1597 if(STAT(SUPERWEAPONS_FINISHED, e) <= 0)
1598 if(!g_weaponarena && (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
1599 STAT(SUPERWEAPONS_FINISHED, e) = autocvar_g_balance_superweapons_time;
1601 if(STAT(STRENGTH_FINISHED, e) <= 0)
1602 STAT(STRENGTH_FINISHED, e) = 0;
1604 STAT(STRENGTH_FINISHED, e) += time;
1605 if(STAT(INVINCIBLE_FINISHED, e) <= 0)
1606 STAT(INVINCIBLE_FINISHED, e) = 0;
1608 STAT(INVINCIBLE_FINISHED, e) += time;
1609 if(STAT(SUPERWEAPONS_FINISHED, e) <= 0)
1610 STAT(SUPERWEAPONS_FINISHED, e) = 0;
1612 STAT(SUPERWEAPONS_FINISHED, e) += time;
1613 if(STAT(BUFF_TIME, e) <= 0)
1614 STAT(BUFF_TIME, e) = 0;
1616 STAT(BUFF_TIME, e) += time;
1618 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1620 .entity weaponentity = weaponentities[slot];
1621 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1622 if(!(STAT(WEAPONS, e) & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
1623 _switchweapon |= BIT(slot);
1628 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1630 .entity weaponentity = weaponentities[slot];
1631 if(_switchweapon & BIT(slot))
1633 Weapon wep = w_getbestweapon(e, weaponentity);
1634 if(wep != e.(weaponentity).m_switchweapon)
1635 W_SwitchWeapon_Force(e, wep, weaponentity);