3 #include <common/items/_mod.qh>
5 #include <server/bot/api.qh>
7 #include <server/command/vote.qh>
9 #include <server/damage.qh>
11 #include <server/mutators/_mod.qh>
13 #include <server/teamplay.qh>
14 #include <server/world.qh>
16 #include <server/weapons/common.qh>
17 #include <server/weapons/selection.qh>
18 #include <server/weapons/weaponsystem.qh>
20 #include <common/constants.qh>
21 #include <common/deathtypes/all.qh>
22 #include <common/notifications/all.qh>
23 #include <common/mapobjects/subs.qh>
24 #include <common/mapobjects/triggers.qh>
25 #include <common/util.qh>
27 #include <common/monsters/_mod.qh>
29 #include <common/wepent.qh>
30 #include <common/weapons/_all.qh>
32 #include <common/mutators/mutator/buffs/buffs.qh>
33 #include <common/mutators/mutator/buffs/sv_buffs.qh>
35 #include <lib/warpzone/util_server.qh>
37 bool ItemSend(entity this, entity to, int sf)
44 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
45 WriteByte(MSG_ENTITY, sf);
47 //WriteByte(MSG_ENTITY, this.cnt);
50 WriteVector(MSG_ENTITY, this.origin);
55 WriteAngleVector(MSG_ENTITY, this.angles);
58 // sets size on the client, unused on server
62 WriteByte(MSG_ENTITY, this.ItemStatus);
66 WriteShort(MSG_ENTITY, this.fade_end);
67 WriteShort(MSG_ENTITY, this.fade_start);
70 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now");
72 WriteString(MSG_ENTITY, this.mdl);
78 WriteShort(MSG_ENTITY, this.colormap);
79 WriteByte(MSG_ENTITY, this.glowmod.x * 255.0);
80 WriteByte(MSG_ENTITY, this.glowmod.y * 255.0);
81 WriteByte(MSG_ENTITY, this.glowmod.z * 255.0);
86 WriteVector(MSG_ENTITY, this.velocity);
92 void ItemUpdate(entity this)
94 this.oldorigin = this.origin;
95 this.SendFlags |= ISF_LOCATION;
98 void UpdateItemAfterTeleport(entity this)
100 if(getSendEntity(this) == ItemSend)
104 bool have_pickup_item(entity this)
106 if(this.itemdef.instanceOfPowerup)
108 if(autocvar_g_powerups > 0)
110 if(autocvar_g_powerups == 0)
115 if(autocvar_g_pickup_items > 0)
117 if(autocvar_g_pickup_items == 0)
120 if(STAT(WEAPONS, this) || this.itemdef.instanceOfAmmo) // no item or ammo pickups in weaponarena
126 void Item_Show(entity e, int mode)
128 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
129 e.ItemStatus &= ~ITS_STAYWEP;
130 entity def = e.itemdef;
133 // make the item look normal, and be touchable
135 e.solid = SOLID_TRIGGER;
136 e.spawnshieldtime = 1;
137 e.ItemStatus |= ITS_AVAILABLE;
141 // hide the item completely
142 e.model = string_null;
144 e.spawnshieldtime = 1;
145 e.ItemStatus &= ~ITS_AVAILABLE;
149 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.m_wepset & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
150 || e.team // weapon stay isn't supported for teamed weapons
152 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
154 // make the item translucent and not touchable
156 e.solid = SOLID_TRIGGER; // can STILL be picked up!
157 e.effects |= EF_STARDUST;
158 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
159 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
163 //setmodel(e, "null");
165 e.colormod = '0 0 0';
166 //e.glowmod = e.colormod;
167 e.spawnshieldtime = 1;
168 e.ItemStatus &= ~ITS_AVAILABLE;
173 e.ItemStatus |= ITS_GLOW;
175 if (autocvar_g_nodepthtestitems)
176 e.effects |= EF_NODEPTHTEST;
178 if (autocvar_g_fullbrightitems)
179 e.ItemStatus |= ITS_ALLOWFB;
181 e.ItemStatus &= ~ITS_ALLOWFB;
183 if (autocvar_sv_simple_items)
184 e.ItemStatus |= ITS_ALLOWSI;
186 // relink entity (because solid may have changed)
187 setorigin(e, e.origin);
188 e.SendFlags |= ISF_STATUS;
191 void Item_Think(entity this)
193 this.nextthink = time;
194 if(this.origin != this.oldorigin)
198 bool Item_ItemsTime_SpectatorOnly(GameItem it);
199 bool Item_ItemsTime_Allow(GameItem it);
200 float Item_ItemsTime_UpdateTime(entity e, float t);
201 void Item_ItemsTime_SetTime(entity e, float t);
202 void Item_ItemsTime_SetTimesForAllPlayers();
204 void Item_Respawn(entity this)
207 sound(this, CH_TRIGGER, this.itemdef.m_respawnsound, VOL_BASE, ATTEN_NORM); // play respawn sound
208 setorigin(this, this.origin);
210 if (Item_ItemsTime_Allow(this.itemdef) || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS))
212 float t = Item_ItemsTime_UpdateTime(this, 0);
213 Item_ItemsTime_SetTime(this, t);
214 Item_ItemsTime_SetTimesForAllPlayers();
217 setthink(this, Item_Think);
218 this.nextthink = time;
220 //Send_Effect(EFFECT_ITEM_RESPAWN, this.origin + this.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
221 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
224 void Item_RespawnCountdown(entity this)
226 if(this.item_respawncounter >= ITEM_RESPAWN_TICKS)
228 if(this.waypointsprite_attached)
229 WaypointSprite_Kill(this.waypointsprite_attached);
234 this.nextthink = time + 1;
235 this.item_respawncounter += 1;
236 if(this.item_respawncounter == 1)
240 entity wi = REGISTRY_GET(Weapons, this.weapon);
241 if (wi != WEP_Null) {
242 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon);
243 wp.wp_extra = wi.m_id;
248 entity ii = this.itemdef;
250 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Item);
251 wp.wp_extra = ii.m_id;
256 bool mutator_returnvalue = MUTATOR_CALLHOOK(Item_RespawnCountdown, this);
257 if(this.waypointsprite_attached)
259 GameItem def = this.itemdef;
260 if (Item_ItemsTime_SpectatorOnly(def) && !mutator_returnvalue)
261 WaypointSprite_UpdateRule(this.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
262 WaypointSprite_UpdateBuildFinished(this.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
266 if(this.waypointsprite_attached)
268 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
269 if(this.waypointsprite_attached.waypointsprite_visible_for_player(this.waypointsprite_attached, it, it))
272 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM, 0); // play respawn sound
276 WaypointSprite_Ping(this.waypointsprite_attached);
277 //WaypointSprite_UpdateHealth(this.waypointsprite_attached, this.item_respawncounter);
282 void Item_RespawnThink(entity this)
284 this.nextthink = time;
285 if(this.origin != this.oldorigin)
288 if(time >= this.wait)
292 void Item_ScheduleRespawnIn(entity e, float t)
294 // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
295 if ((Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS) || MUTATOR_CALLHOOK(Item_ScheduleRespawn, e, t)) && (t - ITEM_RESPAWN_TICKS) > 0)
297 setthink(e, Item_RespawnCountdown);
298 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
299 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
300 e.item_respawncounter = 0;
301 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
303 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
304 Item_ItemsTime_SetTime(e, t);
305 Item_ItemsTime_SetTimesForAllPlayers();
310 setthink(e, Item_RespawnThink);
312 e.scheduledrespawntime = time + t;
315 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
317 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
318 Item_ItemsTime_SetTime(e, t);
319 Item_ItemsTime_SetTimesForAllPlayers();
324 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*");
325 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");
326 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");
328 /// Adjust respawn time according to the number of players.
329 float adjust_respawntime(float normal_respawntime) {
330 float r = autocvar_g_pickup_respawntime_scaling_reciprocal;
331 float o = autocvar_g_pickup_respawntime_scaling_offset;
332 float l = autocvar_g_pickup_respawntime_scaling_linear;
334 if (r == 0 && l == 1) {
335 return normal_respawntime;
338 entity balance = TeamBalance_CheckAllowedTeams(NULL);
339 TeamBalance_GetTeamCounts(balance, NULL);
341 for (int i = 1; i <= NUM_TEAMS; ++i)
343 if (TeamBalance_IsTeamAllowed(balance, i))
345 players += TeamBalance_GetNumberOfPlayers(balance, i);
348 TeamBalance_Destroy(balance);
351 return normal_respawntime * (r / (players + o) + l);
353 return normal_respawntime;
357 void Item_ScheduleRespawn(entity e)
359 if(e.respawntime > 0)
363 float adjusted_respawntime = adjust_respawntime(e.respawntime);
364 //LOG_INFOF("item %s will respawn in %f", e.classname, adjusted_respawntime);
366 // range: adjusted_respawntime - respawntimejitter .. adjusted_respawntime + respawntimejitter
367 float respawn_in = adjusted_respawntime + crandom() * e.respawntimejitter;
368 Item_ScheduleRespawnIn(e, respawn_in);
370 else // if respawntime is -1, this item does not respawn
374 AUTOCVAR(g_pickup_respawntime_initial_random, int, 1,
375 "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");
377 void Item_ScheduleInitialRespawn(entity e)
382 if (autocvar_g_pickup_respawntime_initial_random == 0)
384 // range: respawntime .. respawntime + respawntimejitter
385 spawn_in = e.respawntime + random() * e.respawntimejitter;
390 if (autocvar_g_pickup_respawntime_initial_random == 1)
392 static float shared_random = 0;
393 // NOTE this code works only if items are scheduled at the same time (normal case)
394 // NOTE2 random() can't return exactly 1 so this check always work as intended
395 if (!shared_random || floor(time) > shared_random)
396 shared_random = floor(time) + random();
397 rnd = shared_random - floor(time);
403 // if respawntime >= ITEM_RESPAWN_TICKS: ITEM_RESPAWN_TICKS .. respawntime + respawntimejitter
404 // else: 0 .. ITEM_RESPAWN_TICKS
405 // this is to prevent powerups spawning unexpectedly without waypoints
406 spawn_in = ITEM_RESPAWN_TICKS + rnd * (e.respawntime + e.respawntimejitter - ITEM_RESPAWN_TICKS);
409 Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : spawn_in));
412 void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
415 if (num_weapons == 0)
419 int num_potential_weapons = tokenize_console(weapon_names);
420 for (int give_attempt = 0; give_attempt < num_weapons; ++give_attempt)
422 RandomSelection_Init();
423 for (int weapon_index = 0; weapon_index < num_potential_weapons;
426 string weapon = argv(weapon_index);
427 FOREACH(Weapons, it != WEP_Null,
429 // Finding a weapon which player doesn't have.
430 if (!(STAT(WEAPONS, receiver) & it.m_wepset) && (it.netname == weapon))
432 RandomSelection_AddEnt(it, 1, 1);
437 if (RandomSelection_chosen_ent == NULL)
441 STAT(WEAPONS, receiver) |= RandomSelection_chosen_ent.m_wepset;
442 if (RandomSelection_chosen_ent.ammo_type == RES_NONE)
446 if (GetResource(receiver,
447 RandomSelection_chosen_ent.ammo_type) != 0)
451 GiveResource(receiver, RandomSelection_chosen_ent.ammo_type,
452 GetResource(ammo_entity,
453 RandomSelection_chosen_ent.ammo_type));
457 bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax)
459 float amount = GetResource(item, res_type);
464 float player_amount = GetResource(player, res_type);
465 if (item.spawnshieldtime)
467 if ((player_amount >= ammomax) && (item.pickup_anyway <= 0))
470 else if (g_weapon_stay == 2)
472 ammomax = min(amount, ammomax);
473 if(player_amount >= ammomax)
479 TakeResourceWithLimit(player, res_type, -amount, ammomax);
481 GiveResourceWithLimit(player, res_type, amount, ammomax);
485 bool Item_GiveTo(entity item, entity player)
487 // if nothing happens to player, just return without taking the item
488 int _switchweapon = 0;
489 // in case the player has autoswitch enabled do the following:
490 // if the player is using their best weapon before items are given, they
491 // probably want to switch to an even better weapon after items are given
493 if(CS(player).autoswitch)
495 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
497 .entity weaponentity = weaponentities[slot];
498 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
500 if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
501 _switchweapon |= BIT(slot);
503 if(!(STAT(WEAPONS, player) & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
504 _switchweapon |= BIT(slot);
508 bool pickedup = false;
509 pickedup |= Item_GiveAmmoTo(item, player, RES_HEALTH, item.max_health);
510 pickedup |= Item_GiveAmmoTo(item, player, RES_ARMOR, item.max_armorvalue);
511 pickedup |= Item_GiveAmmoTo(item, player, RES_SHELLS, g_pickup_shells_max);
512 pickedup |= Item_GiveAmmoTo(item, player, RES_BULLETS, g_pickup_nails_max);
513 pickedup |= Item_GiveAmmoTo(item, player, RES_ROCKETS, g_pickup_rockets_max);
514 pickedup |= Item_GiveAmmoTo(item, player, RES_CELLS, g_pickup_cells_max);
515 pickedup |= Item_GiveAmmoTo(item, player, RES_PLASMA, g_pickup_plasma_max);
516 pickedup |= Item_GiveAmmoTo(item, player, RES_FUEL, g_pickup_fuel_max);
517 if (item.itemdef.instanceOfWeaponPickup)
520 w = STAT(WEAPONS, item);
521 w &= ~STAT(WEAPONS, player);
523 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
526 FOREACH(Weapons, it != WEP_Null, {
527 if(w & (it.m_wepset))
529 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
531 .entity weaponentity = weaponentities[slot];
532 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
533 W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
535 W_GiveWeapon(player, it.m_id);
541 if (item.itemdef.instanceOfPowerup)
543 if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
544 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
545 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
546 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
550 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
554 // TODO: we probably want to show a message in the console, but not this one!
555 //Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
558 if (item.strength_finished)
561 STAT(STRENGTH_FINISHED, player) = max(STAT(STRENGTH_FINISHED, player), time) + item.strength_finished;
563 if (item.invincible_finished)
566 STAT(INVINCIBLE_FINISHED, player) = max(STAT(INVINCIBLE_FINISHED, player), time) + item.invincible_finished;
568 if (item.superweapons_finished)
571 STAT(SUPERWEAPONS_FINISHED, player) = max(STAT(SUPERWEAPONS_FINISHED, player), time) + item.superweapons_finished;
574 // always eat teamed entities
581 // crude hack to enforce switching weapons
582 if(g_cts && item.itemdef.instanceOfWeaponPickup && !CS(player).cvar_cl_cts_noautoswitch)
584 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
586 .entity weaponentity = weaponentities[slot];
587 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
588 W_SwitchWeapon_Force(player, REGISTRY_GET(Weapons, item.weapon), weaponentity);
595 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
597 .entity weaponentity = weaponentities[slot];
598 if(_switchweapon & BIT(slot))
599 if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity))
600 W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity);
607 void Item_Touch(entity this, entity toucher)
609 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
610 if (Item_IsLoot(this))
612 if (ITEM_TOUCH_NEEDKILL())
619 if(!(toucher.flags & FL_PICKUPITEMS)
620 || STAT(FROZEN, toucher)
622 || (this.solid != SOLID_TRIGGER)
623 || (this.owner == toucher)
624 || (time < this.item_spawnshieldtime)
627 switch (MUTATOR_CALLHOOK(ItemTouch, this, toucher))
629 case MUT_ITEMTOUCH_RETURN: { return; }
630 case MUT_ITEMTOUCH_PICKUP: { toucher = M_ARGV(1, entity); goto pickup; }
633 toucher = M_ARGV(1, entity);
635 if (Item_IsExpiring(this))
637 this.strength_finished = max(0, this.strength_finished - time);
638 this.invincible_finished = max(0, this.invincible_finished - time);
639 this.superweapons_finished = max(0, this.superweapons_finished - time);
641 bool gave = ITEM_HANDLE(Pickup, this.itemdef, this, toucher);
644 if (Item_IsExpiring(this))
646 // undo what we did above
647 this.strength_finished += time;
648 this.invincible_finished += time;
649 this.superweapons_finished += time;
656 if(this.target && this.target != "" && this.target != "###item###") // defrag support
657 SUB_UseTargets(this, toucher, NULL);
659 STAT(LAST_PICKUP, toucher) = time;
661 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
662 _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);
664 MUTATOR_CALLHOOK(ItemTouched, this, toucher);
670 if (Item_IsLoot(this))
675 if (!this.spawnshieldtime)
682 RandomSelection_Init();
683 IL_EACH(g_items, it.team == this.team,
685 if (it.itemdef) // is a registered item
688 it.scheduledrespawntime = 0;
689 RandomSelection_AddEnt(it, it.cnt, 0);
692 e = RandomSelection_chosen_ent;
693 Item_Show(e, 1); // reset its state so it is visible (extra sendflags doesn't matter, this happens anyway)
697 Item_ScheduleRespawn(e);
700 void Item_Reset(entity this)
702 Item_Show(this, !this.state);
703 setorigin(this, this.origin);
705 if (Item_IsLoot(this))
709 setthink(this, Item_Think);
710 this.nextthink = time;
711 if (this.waypointsprite_attached)
713 WaypointSprite_Kill(this.waypointsprite_attached);
715 if (this.itemdef.instanceOfPowerup || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
717 Item_ScheduleInitialRespawn(this);
721 void Item_FindTeam(entity this)
725 if(this.effects & EF_NODRAW)
727 // marker for item team search
728 LOG_TRACE("Initializing item team ", ftos(this.team));
729 RandomSelection_Init();
730 IL_EACH(g_items, it.team == this.team,
732 if(it.itemdef) // is a registered item
733 RandomSelection_AddEnt(it, it.cnt, 0);
736 e = RandomSelection_chosen_ent;
740 IL_EACH(g_items, it.team == this.team,
742 if(it.itemdef) // is a registered item
746 // make it non-spawned
748 it.state = 1; // state 1 = initially hidden item, apparently
752 it.effects &= ~EF_NODRAW;
758 // Savage: used for item garbage-collection
759 void RemoveItem(entity this)
761 if(wasfreed(this) || !this) { return; }
762 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
766 // pickup evaluation functions
767 // these functions decide how desirable an item is to the bots
769 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
771 float weapon_pickupevalfunc(entity player, entity item)
773 // See if I have it already
774 if(STAT(WEAPONS, player) & STAT(WEAPONS, item))
776 // If I can pick it up
777 if(!item.spawnshieldtime)
779 return ammo_pickupevalfunc(player, item);
782 // reduce weapon value if bot already got a good arsenal
784 int weapons_value = 0;
785 FOREACH(Weapons, it != WEP_Null && (STAT(WEAPONS, player) & it.m_wepset), {
786 weapons_value += it.bot_pickupbasevalue;
788 c -= bound(0, weapons_value / 20000, 1) * 0.5;
790 return item.bot_pickupbasevalue * c;
793 float ammo_pickupevalfunc(entity player, entity item)
795 bool need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
800 // Detect needed ammo
801 if(item.itemdef.instanceOfWeaponPickup)
804 if(GetResource(item, RES_SHELLS)) { need_shells = true; ammo = ITEM_Shells; }
805 else if(GetResource(item, RES_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; }
806 else if(GetResource(item, RES_ROCKETS)) { need_rockets = true; ammo = ITEM_Rockets; }
807 else if(GetResource(item, RES_CELLS)) { need_cells = true; ammo = ITEM_Cells; }
808 else if(GetResource(item, RES_PLASMA)) { need_plasma = true; ammo = ITEM_Plasma; }
809 else if(GetResource(item, RES_FUEL)) { need_fuel = true; ammo = ITEM_JetpackFuel; }
814 rating = ammo.m_botvalue;
818 FOREACH(Weapons, it != WEP_Null, {
819 if(!(STAT(WEAPONS, player) & (it.m_wepset)))
824 case RES_SHELLS: need_shells = true; break;
825 case RES_BULLETS: need_nails = true; break;
826 case RES_ROCKETS: need_rockets = true; break;
827 case RES_CELLS: need_cells = true; break;
828 case RES_PLASMA: need_plasma = true; break;
829 case RES_FUEL: need_fuel = true; break;
832 rating = item.bot_pickupbasevalue;
835 float noammorating = 0.5;
837 if ((need_shells) && GetResource(item, RES_SHELLS) && (GetResource(player, RES_SHELLS) < g_pickup_shells_max))
838 c = GetResource(item, RES_SHELLS) / max(noammorating, GetResource(player, RES_SHELLS));
840 if ((need_nails) && GetResource(item, RES_BULLETS) && (GetResource(player, RES_BULLETS) < g_pickup_nails_max))
841 c = GetResource(item, RES_BULLETS) / max(noammorating, GetResource(player, RES_BULLETS));
843 if ((need_rockets) && GetResource(item, RES_ROCKETS) && (GetResource(player, RES_ROCKETS) < g_pickup_rockets_max))
844 c = GetResource(item, RES_ROCKETS) / max(noammorating, GetResource(player, RES_ROCKETS));
846 if ((need_cells) && GetResource(item, RES_CELLS) && (GetResource(player, RES_CELLS) < g_pickup_cells_max))
847 c = GetResource(item, RES_CELLS) / max(noammorating, GetResource(player, RES_CELLS));
849 if ((need_plasma) && GetResource(item, RES_PLASMA) && (GetResource(player, RES_PLASMA) < g_pickup_plasma_max))
850 c = GetResource(item, RES_PLASMA) / max(noammorating, GetResource(player, RES_PLASMA));
852 if ((need_fuel) && GetResource(item, RES_FUEL) && (GetResource(player, RES_FUEL) < g_pickup_fuel_max))
853 c = GetResource(item, RES_FUEL) / max(noammorating, GetResource(player, RES_FUEL));
857 rating += wpn.bot_pickupbasevalue * 0.1;
861 float healtharmor_pickupevalfunc(entity player, entity item)
864 float rating = item.bot_pickupbasevalue;
866 float itemarmor = GetResource(item, RES_ARMOR);
867 float itemhealth = GetResource(item, RES_HEALTH);
871 itemarmor *= min(4, item.item_group_count);
872 itemhealth *= min(4, item.item_group_count);
875 if (itemarmor && (GetResource(player, RES_ARMOR) < item.max_armorvalue))
876 c = itemarmor / max(1, GetResource(player, RES_ARMOR) * 2/3 + GetResource(player, RES_HEALTH) * 1/3);
878 if (itemhealth && (GetResource(player, RES_HEALTH) < item.max_health))
879 c = itemhealth / max(1, GetResource(player, RES_HEALTH));
885 void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
887 if(ITEM_DAMAGE_NEEDKILL(deathtype))
891 void item_use(entity this, entity actor, entity trigger)
893 // use the touch function to handle collection
894 gettouch(this)(this, actor);
897 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
899 string itemname = def.m_name;
900 Model itemmodel = def.m_model;
901 Sound pickupsound = def.m_sound;
902 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
903 float pickupbasevalue = def.m_botvalue;
904 int itemflags = def.m_itemflags;
906 startitem_failed = false;
908 this.item_model_ent = itemmodel;
909 this.item_pickupsound_ent = pickupsound;
912 def.m_iteminit(def, this);
914 if(!this.respawntime) // both need to be set
916 this.respawntime = defaultrespawntime;
917 this.respawntimejitter = defaultrespawntimejitter;
920 if(!this.pickup_anyway && def.m_pickupanyway)
921 this.pickup_anyway = def.m_pickupanyway();
923 int itemid = def.m_itemid;
925 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
926 this.weapon = weaponid;
930 this.fade_start = autocvar_g_items_mindist;
931 this.fade_end = autocvar_g_items_maxdist;
935 STAT(WEAPONS, this) = WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
937 this.flags = FL_ITEM | itemflags;
938 IL_PUSH(g_items, this);
940 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
942 startitem_failed = true;
947 precache_model(this.model);
948 precache_sound(this.item_pickupsound);
950 if (Item_IsLoot(this))
952 this.reset = SUB_Remove;
953 set_movetype(this, MOVETYPE_TOSS);
955 // Savage: remove thrown items after a certain period of time ("garbage collection")
956 setthink(this, RemoveItem);
957 this.nextthink = time + 20;
959 this.takedamage = DAMAGE_YES;
960 this.event_damage = Item_Damage;
962 if (Item_IsExpiring(this))
964 // if item is worthless after a timer, have it expire then
965 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
968 // don't drop if in a NODROP zone (such as lava)
969 traceline(this.origin, this.origin, MOVE_NORMAL, this);
970 if (trace_dpstartcontents & DPCONTENTS_NODROP)
972 startitem_failed = true;
979 if(!have_pickup_item(this))
981 startitem_failed = true;
986 if(this.angles != '0 0 0')
987 this.SendFlags |= ISF_ANGLES;
989 this.reset = Item_Reset;
991 if(this.spawnflags & 1)
993 if (this.noalign > 0)
994 set_movetype(this, MOVETYPE_NONE);
996 set_movetype(this, MOVETYPE_TOSS);
997 // do item filtering according to game mode and other things
998 if (this.noalign <= 0)
1000 // first nudge it off the floor a little bit to avoid math errors
1001 setorigin(this, this.origin + '0 0 1');
1002 // set item size before we spawn a spawnfunc_waypoint
1003 setsize(this, def.m_mins, def.m_maxs);
1004 this.SendFlags |= ISF_SIZE;
1005 // note droptofloor returns false if stuck/or would fall too far
1008 waypoint_spawnforitem(this);
1012 * can't do it that way, as it would break maps
1013 * TODO make a target_give like entity another way, that perhaps has
1014 * the weapon name in a key
1017 // target_give not yet supported; maybe later
1018 print("removed targeted ", this.classname, "\n");
1019 startitem_failed = true;
1025 if(this.targetname != "" && (this.spawnflags & 16))
1026 this.use = item_use;
1028 if(autocvar_spawn_debug >= 2)
1030 // why not flags & fl_item?
1031 FOREACH_ENTITY_RADIUS(this.origin, 3, it.is_item, {
1032 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1033 LOG_TRACE(" vs ", it.netname, vtos(it.origin));
1034 error("Mapper sucks.");
1036 this.is_item = true;
1039 weaponsInMap |= WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
1041 if ( def.instanceOfPowerup
1042 || def.instanceOfWeaponPickup
1043 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1044 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1045 || (itemid & (IT_KEY1 | IT_KEY2))
1048 if(!this.target || this.target == "")
1049 this.target = "###item###"; // for finding the nearest item using findnearest
1052 Item_ItemsTime_SetTime(this, 0);
1055 this.bot_pickup = true;
1056 this.bot_pickupevalfunc = pickupevalfunc;
1057 this.bot_pickupbasevalue = pickupbasevalue;
1058 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1059 this.netname = itemname;
1060 settouch(this, Item_Touch);
1061 setmodel(this, MDL_Null); // precision set below
1062 //this.effects |= EF_LOWPRECISION;
1064 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1066 this.SendFlags |= ISF_SIZE;
1068 if (!(this.spawnflags & 1024)) {
1069 if(def.instanceOfPowerup)
1070 this.ItemStatus |= ITS_ANIMATE1;
1072 if(GetResource(this, RES_ARMOR) || GetResource(this, RES_HEALTH))
1073 this.ItemStatus |= ITS_ANIMATE2;
1076 if(Item_IsLoot(this))
1079 if(def.instanceOfWeaponPickup)
1081 if (!Item_IsLoot(this)) // if dropped, colormap is already set up nicely
1082 this.colormap = 1024; // color shirt=0 pants=0 grey
1083 if (!(this.spawnflags & 1024))
1084 this.ItemStatus |= ITS_ANIMATE1;
1085 this.SendFlags |= ISF_COLORMAP;
1092 this.cnt = 1; // item probability weight
1094 this.effects |= EF_NODRAW; // marker for item team search
1095 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1100 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1102 // call this hook after everything else has been done
1103 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1105 startitem_failed = true;
1113 void StartItem(entity this, GameItem def)
1115 def = def.m_spawnfunc_hookreplace(def, this);
1116 if (def.spawnflags & ITEM_FLAG_MUTATORBLOCKED)
1121 this.classname = def.m_canonical_spawnfunc;
1125 def.m_respawntime(), // defaultrespawntime
1126 def.m_respawntimejitter() // defaultrespawntimejitter
1130 #define IS_SMALL(def) ((def.instanceOfHealth && def == ITEM_HealthSmall) || (def.instanceOfArmor && def == ITEM_ArmorSmall))
1131 int group_count = 1;
1133 void setItemGroup(entity this)
1135 if(!IS_SMALL(this.itemdef) || Item_IsLoot(this))
1138 FOREACH_ENTITY_RADIUS(this.origin, 120, (it != this) && IS_SMALL(it.itemdef),
1140 if(!this.item_group)
1144 it.item_group = group_count;
1147 this.item_group = it.item_group;
1149 else // spawning item is already part of a item_group X
1152 it.item_group = this.item_group;
1153 else if(it.item_group != this.item_group) // found an item near the spawning item that is part of a different item_group Y
1155 int grY = it.item_group;
1156 // move all items of item_group Y to item_group X
1157 IL_EACH(g_items, IS_SMALL(it.itemdef),
1159 if(it.item_group == grY)
1160 it.item_group = this.item_group;
1167 void setItemGroupCount()
1169 for (int k = 1; k <= group_count; k++)
1172 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { count++; });
1174 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { it.item_group_count = count; });
1178 void target_items_use(entity this, entity actor, entity trigger)
1180 if(Item_IsLoot(actor))
1182 EXACTTRIGGER_TOUCH(this, trigger);
1187 if (!IS_PLAYER(actor) || IS_DEAD(actor))
1190 if(trigger.solid == SOLID_TRIGGER)
1192 EXACTTRIGGER_TOUCH(this, trigger);
1195 IL_EACH(g_items, it.enemy == actor && Item_IsLoot(it),
1200 if(GiveItems(actor, 0, tokenize_console(this.netname)))
1201 centerprint(actor, this.message);
1204 spawnfunc(target_items)
1206 this.use = target_items_use;
1207 if(!this.strength_finished)
1208 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1209 if(!this.invincible_finished)
1210 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1211 if(!this.superweapons_finished)
1212 this.superweapons_finished = autocvar_g_balance_superweapons_time;
1215 int n = tokenize_console(this.netname);
1216 if(argv(0) == "give")
1218 str = substring(this.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1222 for(int j = 0; j < n; ++j)
1224 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1225 if (argv(j) == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS;
1226 else if(argv(j) == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_AMMO;
1227 else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS;
1228 else if(argv(j) == "strength") this.items |= ITEM_Strength.m_itemid;
1229 else if(argv(j) == "invincible") this.items |= ITEM_Shield.m_itemid;
1230 else if(argv(j) == "superweapons") this.items |= IT_SUPERWEAPON;
1231 else if(argv(j) == "jetpack") this.items |= ITEM_Jetpack.m_itemid;
1232 else if(argv(j) == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid;
1235 FOREACH(Buffs, it != BUFF_Null,
1237 string s = Buff_UndeprecateName(argv(j));
1240 STAT(BUFFS, this) |= (it.m_itemid);
1241 if(!STAT(BUFF_TIME, this))
1242 STAT(BUFF_TIME, this) = it.m_time(it);
1246 FOREACH(Weapons, it != WEP_Null, {
1247 string s = W_UndeprecateName(argv(j));
1250 STAT(WEAPONS, this) |= (it.m_wepset);
1251 if(this.spawnflags == 0 || this.spawnflags == 2)
1259 string itemprefix, valueprefix;
1260 if(this.spawnflags == 0)
1265 else if(this.spawnflags == 1)
1267 itemprefix = "max ";
1268 valueprefix = "max ";
1270 else if(this.spawnflags == 2)
1272 itemprefix = "min ";
1273 valueprefix = "min ";
1275 else if(this.spawnflags == 4)
1277 itemprefix = "minus ";
1278 valueprefix = "max ";
1282 error("invalid spawnflags");
1283 itemprefix = valueprefix = string_null;
1287 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_AMMO), "unlimited_weapon_ammo");
1288 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1289 str = sprintf("%s %s%d %s", str, valueprefix, this.strength_finished * boolean(this.items & ITEM_Strength.m_itemid), "strength");
1290 str = sprintf("%s %s%d %s", str, valueprefix, this.invincible_finished * boolean(this.items & ITEM_Shield.m_itemid), "invincible");
1291 str = sprintf("%s %s%d %s", str, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
1292 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
1293 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1295 res = GetResource(this, RES_SHELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "shells");
1296 res = GetResource(this, RES_BULLETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "nails");
1297 res = GetResource(this, RES_ROCKETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "rockets");
1298 res = GetResource(this, RES_CELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "cells");
1299 res = GetResource(this, RES_PLASMA); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "plasma");
1300 res = GetResource(this, RES_FUEL); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "fuel");
1301 res = GetResource(this, RES_HEALTH); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "health");
1302 res = GetResource(this, RES_ARMOR); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "armor");
1303 // HACK: buffs share a single timer, so we need to include enabled buffs AFTER disabled ones to avoid loss
1304 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));
1305 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));
1306 FOREACH(Weapons, it != WEP_Null, str = sprintf("%s %s%d %s", str, itemprefix, !!(STAT(WEAPONS, this) & (it.m_wepset)), it.netname));
1308 this.netname = strzone(str);
1310 n = tokenize_console(this.netname);
1311 for(int j = 0; j < n; ++j)
1313 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(argv(j)) == it.netname, {
1320 float GiveWeapon(entity e, float wpn, float op, float val)
1323 WepSet s = WepSet_FromWeapon(REGISTRY_GET(Weapons, wpn));
1324 v0 = (STAT(WEAPONS, e) & s);
1329 STAT(WEAPONS, e) |= s;
1331 STAT(WEAPONS, e) &= ~s;
1336 STAT(WEAPONS, e) |= s;
1340 STAT(WEAPONS, e) &= ~s;
1344 STAT(WEAPONS, e) &= ~s;
1347 v1 = (STAT(WEAPONS, e) & s);
1351 bool GiveBuff(entity e, Buff thebuff, int op, int val)
1353 bool had_buff = (STAT(BUFFS, e) & thebuff.m_itemid);
1354 float new_buff_time = ((had_buff) ? STAT(BUFF_TIME, e) : 0);
1358 new_buff_time = val;
1361 new_buff_time = max(new_buff_time, val);
1364 new_buff_time = min(new_buff_time, val);
1367 new_buff_time += val;
1370 new_buff_time -= val;
1373 if(new_buff_time <= 0)
1376 STAT(BUFF_TIME, e) = new_buff_time;
1377 STAT(BUFFS, e) &= ~thebuff.m_itemid;
1381 STAT(BUFF_TIME, e) = new_buff_time;
1382 STAT(BUFFS, e) = thebuff.m_itemid; // NOTE: replaces any existing buffs on the player!
1384 bool have_buff = (STAT(BUFFS, e) & thebuff.m_itemid);
1385 return (had_buff != have_buff);
1388 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
1394 if(snd_decr != NULL)
1395 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1397 else if(v0 >= v0 + t)
1399 if(snd_incr != NULL)
1400 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1404 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1407 e.(rotfield) = max(e.(rotfield), time + rottime);
1409 e.(regenfield) = max(e.(regenfield), time + regentime);
1411 bool GiveResourceValue(entity e, int res_type, int op, int val)
1413 int v0 = GetResource(e, res_type);
1417 // min 100 cells = at least 100 cells
1418 case OP_SET: new_val = val; break;
1419 case OP_MIN: new_val = max(v0, val); break;
1420 case OP_MAX: new_val = min(v0, val); break;
1421 case OP_PLUS: new_val = v0 + val; break;
1422 case OP_MINUS: new_val = v0 - val; break;
1423 default: return false;
1426 return SetResourceExplicit(e, res_type, new_val);
1429 float GiveItems(entity e, float beginarg, float endarg)
1431 float got, i, val, op;
1439 int _switchweapon = 0;
1441 if(CS(e).autoswitch)
1443 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1445 .entity weaponentity = weaponentities[slot];
1446 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1447 if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
1448 _switchweapon |= BIT(slot);
1452 STAT(STRENGTH_FINISHED, e) = max(0, STAT(STRENGTH_FINISHED, e) - time);
1453 STAT(INVINCIBLE_FINISHED, e) = max(0, STAT(INVINCIBLE_FINISHED, e) - time);
1454 STAT(SUPERWEAPONS_FINISHED, e) = max(0, STAT(SUPERWEAPONS_FINISHED, e) - time);
1455 STAT(BUFF_TIME, e) = max(0, STAT(BUFF_TIME, e) - time);
1459 PREGIVE(e, stat_STRENGTH_FINISHED);
1460 PREGIVE(e, stat_INVINCIBLE_FINISHED);
1461 PREGIVE(e, stat_SUPERWEAPONS_FINISHED);
1462 PREGIVE_RESOURCE(e, RES_BULLETS);
1463 PREGIVE_RESOURCE(e, RES_CELLS);
1464 PREGIVE_RESOURCE(e, RES_PLASMA);
1465 PREGIVE_RESOURCE(e, RES_SHELLS);
1466 PREGIVE_RESOURCE(e, RES_ROCKETS);
1467 PREGIVE_RESOURCE(e, RES_FUEL);
1468 PREGIVE_RESOURCE(e, RES_ARMOR);
1469 PREGIVE_RESOURCE(e, RES_HEALTH);
1471 for(i = beginarg; i < endarg; ++i)
1475 if(cmd == "0" || stof(cmd))
1499 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1500 got += GiveValue(e, stat_STRENGTH_FINISHED, op, val);
1501 got += GiveValue(e, stat_INVINCIBLE_FINISHED, op, val);
1502 got += GiveValue(e, stat_SUPERWEAPONS_FINISHED, op, val);
1503 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1505 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1506 got += GiveResourceValue(e, RES_HEALTH, op, val);
1507 got += GiveResourceValue(e, RES_ARMOR, op, val);
1509 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)), got += GiveWeapon(e, it.m_id, op, val));
1510 //case "allbuffs": // all buffs makes a player god, do not want!
1511 //FOREACH(Buffs, it != BUFF_Null, got += GiveBuff(e, it.m_itemid, op, val));
1513 got += GiveResourceValue(e, RES_CELLS, op, val);
1514 got += GiveResourceValue(e, RES_PLASMA, op, val);
1515 got += GiveResourceValue(e, RES_SHELLS, op, val);
1516 got += GiveResourceValue(e, RES_BULLETS, op, val);
1517 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1518 got += GiveResourceValue(e, RES_FUEL, op, val);
1520 case "unlimited_ammo":
1521 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1522 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1524 case "unlimited_weapon_ammo":
1525 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1527 case "unlimited_superweapons":
1528 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1531 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1534 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1537 got += GiveValue(e, stat_STRENGTH_FINISHED, op, val);
1540 got += GiveValue(e, stat_INVINCIBLE_FINISHED, op, val);
1542 case "superweapons":
1543 got += GiveValue(e, stat_SUPERWEAPONS_FINISHED, op, val);
1546 got += GiveResourceValue(e, RES_CELLS, op, val);
1549 got += GiveResourceValue(e, RES_PLASMA, op, val);
1552 got += GiveResourceValue(e, RES_SHELLS, op, val);
1556 got += GiveResourceValue(e, RES_BULLETS, op, val);
1559 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1562 got += GiveResourceValue(e, RES_HEALTH, op, val);
1565 got += GiveResourceValue(e, RES_ARMOR, op, val);
1568 got += GiveResourceValue(e, RES_FUEL, op, val);
1571 FOREACH(Buffs, it != BUFF_Null && buff_Available(it) && Buff_UndeprecateName(cmd) == it.netname,
1573 got += GiveBuff(e, it, op, val);
1576 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
1577 got += GiveWeapon(e, it.m_id, op, val);
1586 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1587 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1588 POSTGIVE_BIT(e, items, IT_UNLIMITED_AMMO, SND_POWERUP, SND_POWEROFF);
1589 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1590 FOREACH(Weapons, it != WEP_Null, {
1591 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1592 if(!(save_weapons & (it.m_wepset)))
1593 if(STAT(WEAPONS, e) & (it.m_wepset))
1596 POSTGIVE_VALUE(e, stat_STRENGTH_FINISHED, 1, SND_POWERUP, SND_POWEROFF);
1597 POSTGIVE_VALUE(e, stat_INVINCIBLE_FINISHED, 1, SND_Shield, SND_POWEROFF);
1598 //POSTGIVE_VALUE(e, stat_SUPERWEAPONS_FINISHED, 1, SND_Null, SND_Null);
1599 POSTGIVE_RESOURCE(e, RES_BULLETS, 0, SND_ITEMPICKUP, SND_Null);
1600 POSTGIVE_RESOURCE(e, RES_CELLS, 0, SND_ITEMPICKUP, SND_Null);
1601 POSTGIVE_RESOURCE(e, RES_PLASMA, 0, SND_ITEMPICKUP, SND_Null);
1602 POSTGIVE_RESOURCE(e, RES_SHELLS, 0, SND_ITEMPICKUP, SND_Null);
1603 POSTGIVE_RESOURCE(e, RES_ROCKETS, 0, SND_ITEMPICKUP, SND_Null);
1604 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);
1605 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);
1606 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);
1608 if(STAT(SUPERWEAPONS_FINISHED, e) <= 0)
1609 if(!g_weaponarena && (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
1610 STAT(SUPERWEAPONS_FINISHED, e) = autocvar_g_balance_superweapons_time;
1612 if(STAT(STRENGTH_FINISHED, e) <= 0)
1613 STAT(STRENGTH_FINISHED, e) = 0;
1615 STAT(STRENGTH_FINISHED, e) += time;
1616 if(STAT(INVINCIBLE_FINISHED, e) <= 0)
1617 STAT(INVINCIBLE_FINISHED, e) = 0;
1619 STAT(INVINCIBLE_FINISHED, e) += time;
1620 if(STAT(SUPERWEAPONS_FINISHED, e) <= 0)
1621 STAT(SUPERWEAPONS_FINISHED, e) = 0;
1623 STAT(SUPERWEAPONS_FINISHED, e) += time;
1624 if(STAT(BUFF_TIME, e) <= 0)
1625 STAT(BUFF_TIME, e) = 0;
1627 STAT(BUFF_TIME, e) += time;
1629 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1631 .entity weaponentity = weaponentities[slot];
1632 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1633 if(!(STAT(WEAPONS, e) & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
1634 _switchweapon |= BIT(slot);
1639 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1641 .entity weaponentity = weaponentities[slot];
1642 if(_switchweapon & BIT(slot))
1644 Weapon wep = w_getbestweapon(e, weaponentity);
1645 if(wep != e.(weaponentity).m_switchweapon)
1646 W_SwitchWeapon_Force(e, wep, weaponentity);