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/mutators/mutator/status_effects/_mod.qh>
13 #include <common/notifications/all.qh>
14 #include <common/util.qh>
15 #include <common/weapons/_all.qh>
16 #include <common/wepent.qh>
17 #include <lib/warpzone/common.qh>
18 #include <lib/warpzone/util_server.qh>
19 #include <server/bot/api.qh>
20 #include <server/command/vote.qh>
21 #include <server/damage.qh>
22 #include <server/mutators/_mod.qh>
23 #include <server/teamplay.qh>
24 #include <server/weapons/common.qh>
25 #include <server/weapons/selection.qh>
26 #include <server/weapons/weaponsystem.qh>
27 #include <server/world.qh>
29 bool ItemSend(entity this, entity to, int sf)
36 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
37 WriteByte(MSG_ENTITY, sf);
39 //WriteByte(MSG_ENTITY, this.cnt);
42 WriteVector(MSG_ENTITY, this.origin);
47 WriteAngleVector(MSG_ENTITY, this.angles);
50 // sets size on the client, unused on server
54 WriteByte(MSG_ENTITY, this.ItemStatus);
58 WriteShort(MSG_ENTITY, bound(0, this.fade_end, 32767));
59 WriteShort(MSG_ENTITY, bound(0, this.fade_start, 32767));
62 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now");
64 WriteString(MSG_ENTITY, this.mdl);
70 WriteShort(MSG_ENTITY, this.colormap);
71 WriteByte(MSG_ENTITY, this.glowmod.x * 255.0);
72 WriteByte(MSG_ENTITY, this.glowmod.y * 255.0);
73 WriteByte(MSG_ENTITY, this.glowmod.z * 255.0);
78 WriteVector(MSG_ENTITY, this.velocity);
84 void ItemUpdate(entity this)
86 this.oldorigin = this.origin;
87 this.SendFlags |= ISF_LOCATION;
90 void UpdateItemAfterTeleport(entity this)
92 if(getSendEntity(this) == ItemSend)
96 bool have_pickup_item(entity this)
98 if(this.itemdef.instanceOfPowerup)
100 if(autocvar_g_powerups > 0)
102 if(autocvar_g_powerups == 0)
107 if(autocvar_g_pickup_items > 0)
109 if(autocvar_g_pickup_items == 0)
112 if(STAT(WEAPONS, this) || this.itemdef.instanceOfAmmo) // no item or ammo pickups in weaponarena
118 void Item_Show(entity e, int mode)
120 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
121 e.ItemStatus &= ~ITS_STAYWEP;
122 entity def = e.itemdef;
125 // make the item look normal, and be touchable
127 e.solid = SOLID_TRIGGER;
128 e.spawnshieldtime = 1;
129 e.ItemStatus |= ITS_AVAILABLE;
133 // hide the item completely
134 e.model = string_null;
136 e.spawnshieldtime = 1;
137 e.ItemStatus &= ~ITS_AVAILABLE;
141 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.m_wepset & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
142 || e.team // weapon stay isn't supported for teamed weapons
144 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
146 // make the item translucent and not touchable
148 e.solid = SOLID_TRIGGER; // can STILL be picked up!
149 e.effects |= EF_STARDUST;
150 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
151 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
155 //setmodel(e, "null");
157 e.colormod = '0 0 0';
158 //e.glowmod = e.colormod;
159 e.spawnshieldtime = 1;
160 e.ItemStatus &= ~ITS_AVAILABLE;
165 e.ItemStatus |= ITS_GLOW;
167 if (autocvar_g_nodepthtestitems)
168 e.effects |= EF_NODEPTHTEST;
170 if (autocvar_g_fullbrightitems)
171 e.ItemStatus |= ITS_ALLOWFB;
173 e.ItemStatus &= ~ITS_ALLOWFB;
175 if (autocvar_sv_simple_items)
176 e.ItemStatus |= ITS_ALLOWSI;
178 // relink entity (because solid may have changed)
179 setorigin(e, e.origin);
180 e.SendFlags |= ISF_STATUS;
183 void Item_Think(entity this)
185 this.nextthink = time;
186 if(this.origin != this.oldorigin)
190 bool Item_ItemsTime_SpectatorOnly(GameItem it);
191 bool Item_ItemsTime_Allow(GameItem it);
192 float Item_ItemsTime_UpdateTime(entity e, float t);
193 void Item_ItemsTime_SetTime(entity e, float t);
194 void Item_ItemsTime_SetTimesForAllPlayers();
196 void Item_Respawn(entity this)
199 sound(this, CH_TRIGGER, this.itemdef.m_respawnsound, VOL_BASE, ATTEN_NORM); // play respawn sound
200 setorigin(this, this.origin);
202 if (Item_ItemsTime_Allow(this.itemdef) || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS))
204 float t = Item_ItemsTime_UpdateTime(this, 0);
205 Item_ItemsTime_SetTime(this, t);
206 Item_ItemsTime_SetTimesForAllPlayers();
209 setthink(this, Item_Think);
210 this.nextthink = time;
212 //Send_Effect(EFFECT_ITEM_RESPAWN, this.origin + this.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
213 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
216 void Item_RespawnCountdown(entity this)
218 if(this.item_respawncounter >= ITEM_RESPAWN_TICKS)
220 if(this.waypointsprite_attached)
221 WaypointSprite_Kill(this.waypointsprite_attached);
226 this.nextthink = time + 1;
227 this.item_respawncounter += 1;
228 if(this.item_respawncounter == 1)
232 entity wi = REGISTRY_GET(Weapons, this.weapon);
233 if (wi != WEP_Null) {
234 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon);
235 wp.wp_extra = wi.m_id;
240 entity ii = this.itemdef;
242 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Item);
243 wp.wp_extra = ii.m_id;
248 bool mutator_returnvalue = MUTATOR_CALLHOOK(Item_RespawnCountdown, this);
249 if(this.waypointsprite_attached)
251 GameItem def = this.itemdef;
252 if (Item_ItemsTime_SpectatorOnly(def) && !mutator_returnvalue)
253 WaypointSprite_UpdateRule(this.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
254 WaypointSprite_UpdateBuildFinished(this.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
258 if(this.waypointsprite_attached)
260 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
261 if(this.waypointsprite_attached.waypointsprite_visible_for_player(this.waypointsprite_attached, it, it))
264 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM, 0); // play respawn sound
268 WaypointSprite_Ping(this.waypointsprite_attached);
269 //WaypointSprite_UpdateHealth(this.waypointsprite_attached, this.item_respawncounter);
274 void Item_RespawnThink(entity this)
276 this.nextthink = time;
277 if(this.origin != this.oldorigin)
280 if(time >= this.wait)
284 void Item_ScheduleRespawnIn(entity e, float t)
286 // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
287 if ((Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS) || MUTATOR_CALLHOOK(Item_ScheduleRespawn, e, t)) && (t - ITEM_RESPAWN_TICKS) > 0)
289 setthink(e, Item_RespawnCountdown);
290 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
291 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
292 e.item_respawncounter = 0;
293 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
295 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
296 Item_ItemsTime_SetTime(e, t);
297 Item_ItemsTime_SetTimesForAllPlayers();
302 setthink(e, Item_RespawnThink);
304 e.scheduledrespawntime = time + t;
307 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
309 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
310 Item_ItemsTime_SetTime(e, t);
311 Item_ItemsTime_SetTimesForAllPlayers();
316 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*");
317 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");
318 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");
320 /// Adjust respawn time according to the number of players.
321 float adjust_respawntime(float normal_respawntime) {
322 float r = autocvar_g_pickup_respawntime_scaling_reciprocal;
323 float o = autocvar_g_pickup_respawntime_scaling_offset;
324 float l = autocvar_g_pickup_respawntime_scaling_linear;
326 if (r == 0 && l == 1) {
327 return normal_respawntime;
330 entity balance = TeamBalance_CheckAllowedTeams(NULL);
331 TeamBalance_GetTeamCounts(balance, NULL);
333 for (int i = 1; i <= NUM_TEAMS; ++i)
335 if (TeamBalance_IsTeamAllowed(balance, i))
337 players += TeamBalance_GetNumberOfPlayers(balance, i);
340 TeamBalance_Destroy(balance);
343 return normal_respawntime * (r / (players + o) + l);
345 return normal_respawntime;
349 void Item_ScheduleRespawn(entity e)
351 if(e.respawntime > 0)
355 float adjusted_respawntime = adjust_respawntime(e.respawntime);
356 //LOG_INFOF("item %s will respawn in %f", e.classname, adjusted_respawntime);
358 // range: adjusted_respawntime - respawntimejitter .. adjusted_respawntime + respawntimejitter
359 float respawn_in = adjusted_respawntime + crandom() * e.respawntimejitter;
360 Item_ScheduleRespawnIn(e, respawn_in);
362 else // if respawntime is -1, this item does not respawn
366 AUTOCVAR(g_pickup_respawntime_initial_random, int, 1,
367 "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");
369 void Item_ScheduleInitialRespawn(entity e)
374 if (autocvar_g_pickup_respawntime_initial_random == 0)
376 // range: respawntime .. respawntime + respawntimejitter
377 spawn_in = e.respawntime + random() * e.respawntimejitter;
382 if (autocvar_g_pickup_respawntime_initial_random == 1)
384 static float shared_random = 0;
385 // NOTE this code works only if items are scheduled at the same time (normal case)
386 // NOTE2 random() can't return exactly 1 so this check always work as intended
387 if (!shared_random || floor(time) > shared_random)
388 shared_random = floor(time) + random();
389 rnd = shared_random - floor(time);
395 // if respawntime >= ITEM_RESPAWN_TICKS: ITEM_RESPAWN_TICKS .. respawntime + respawntimejitter
396 // else: 0 .. ITEM_RESPAWN_TICKS
397 // this is to prevent powerups spawning unexpectedly without waypoints
398 spawn_in = ITEM_RESPAWN_TICKS + rnd * (e.respawntime + e.respawntimejitter - ITEM_RESPAWN_TICKS);
401 Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : spawn_in));
404 void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
407 if (num_weapons == 0)
411 int num_potential_weapons = tokenize_console(weapon_names);
412 for (int give_attempt = 0; give_attempt < num_weapons; ++give_attempt)
414 RandomSelection_Init();
415 for (int weapon_index = 0; weapon_index < num_potential_weapons;
418 string weapon = argv(weapon_index);
419 FOREACH(Weapons, it != WEP_Null,
421 // Finding a weapon which player doesn't have.
422 if (!(STAT(WEAPONS, receiver) & it.m_wepset) && (it.netname == weapon))
424 RandomSelection_AddEnt(it, 1, 1);
429 if (RandomSelection_chosen_ent == NULL)
433 STAT(WEAPONS, receiver) |= RandomSelection_chosen_ent.m_wepset;
434 if (RandomSelection_chosen_ent.ammo_type == RES_NONE)
438 if (GetResource(receiver,
439 RandomSelection_chosen_ent.ammo_type) != 0)
443 GiveResource(receiver, RandomSelection_chosen_ent.ammo_type,
444 GetResource(ammo_entity,
445 RandomSelection_chosen_ent.ammo_type));
449 bool Item_GiveAmmoTo(entity item, entity player, int res_type, float ammomax)
451 float amount = GetResource(item, res_type);
456 float player_amount = GetResource(player, res_type);
457 if (item.spawnshieldtime)
459 if ((player_amount >= ammomax) && (item.pickup_anyway <= 0))
462 else if (g_weapon_stay == 2)
464 ammomax = min(amount, ammomax);
465 if(player_amount >= ammomax)
471 TakeResourceWithLimit(player, res_type, -amount, ammomax);
473 GiveResourceWithLimit(player, res_type, amount, ammomax);
477 bool Item_GiveTo(entity item, entity player)
479 // if nothing happens to player, just return without taking the item
480 int _switchweapon = 0;
481 // in case the player has autoswitch enabled do the following:
482 // if the player is using their best weapon before items are given, they
483 // probably want to switch to an even better weapon after items are given
485 if(CS_CVAR(player).autoswitch)
487 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
489 .entity weaponentity = weaponentities[slot];
490 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
492 if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
493 _switchweapon |= BIT(slot);
495 if(!(STAT(WEAPONS, player) & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
496 _switchweapon |= BIT(slot);
500 bool pickedup = false;
501 pickedup |= Item_GiveAmmoTo(item, player, RES_HEALTH, item.max_health);
502 pickedup |= Item_GiveAmmoTo(item, player, RES_ARMOR, item.max_armorvalue);
503 pickedup |= Item_GiveAmmoTo(item, player, RES_SHELLS, g_pickup_shells_max);
504 pickedup |= Item_GiveAmmoTo(item, player, RES_BULLETS, g_pickup_nails_max);
505 pickedup |= Item_GiveAmmoTo(item, player, RES_ROCKETS, g_pickup_rockets_max);
506 pickedup |= Item_GiveAmmoTo(item, player, RES_CELLS, g_pickup_cells_max);
507 pickedup |= Item_GiveAmmoTo(item, player, RES_PLASMA, g_pickup_plasma_max);
508 pickedup |= Item_GiveAmmoTo(item, player, RES_FUEL, g_pickup_fuel_max);
509 if (item.itemdef.instanceOfWeaponPickup)
512 w = STAT(WEAPONS, item);
513 w &= ~STAT(WEAPONS, player);
515 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
518 FOREACH(Weapons, it != WEP_Null, {
519 if(w & (it.m_wepset))
521 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
523 .entity weaponentity = weaponentities[slot];
524 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
525 W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
527 W_GiveWeapon(player, it.m_id);
533 if (item.itemdef.instanceOfPowerup)
535 if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
536 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
537 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
538 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
542 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
546 // TODO: we probably want to show a message in the console, but not this one!
547 //Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
550 if (item.strength_finished)
553 StatusEffects_apply(STATUSEFFECT_Strength, player, max(StatusEffects_gettime(STATUSEFFECT_Strength, player), time) + item.strength_finished, 0);
555 if (item.invincible_finished)
558 StatusEffects_apply(STATUSEFFECT_Shield, player, max(StatusEffects_gettime(STATUSEFFECT_Shield, player), time) + item.invincible_finished, 0);
560 if (item.superweapons_finished)
563 StatusEffects_apply(STATUSEFFECT_Superweapons, player, max(StatusEffects_gettime(STATUSEFFECT_Superweapons, player), time) + item.superweapons_finished, 0);
566 // always eat teamed entities
573 // crude hack to enforce switching weapons
574 if(g_cts && item.itemdef.instanceOfWeaponPickup && !CS_CVAR(player).cvar_cl_cts_noautoswitch)
576 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
578 .entity weaponentity = weaponentities[slot];
579 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
580 W_SwitchWeapon_Force(player, REGISTRY_GET(Weapons, item.weapon), weaponentity);
587 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
589 .entity weaponentity = weaponentities[slot];
590 if(_switchweapon & BIT(slot))
591 if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity))
592 W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity);
599 void Item_Touch(entity this, entity toucher)
601 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
602 if (Item_IsLoot(this))
604 if (ITEM_TOUCH_NEEDKILL())
611 if(!(toucher.flags & FL_PICKUPITEMS)
612 || STAT(FROZEN, toucher)
614 || (this.solid != SOLID_TRIGGER)
615 || (this.owner == toucher)
616 || (time < this.item_spawnshieldtime)
619 switch (MUTATOR_CALLHOOK(ItemTouch, this, toucher))
621 case MUT_ITEMTOUCH_RETURN: { return; }
622 case MUT_ITEMTOUCH_PICKUP: { toucher = M_ARGV(1, entity); goto pickup; }
625 toucher = M_ARGV(1, entity);
627 if (Item_IsExpiring(this))
629 this.strength_finished = max(0, this.strength_finished - time);
630 this.invincible_finished = max(0, this.invincible_finished - time);
631 this.superweapons_finished = max(0, this.superweapons_finished - time);
633 bool gave = ITEM_HANDLE(Pickup, this.itemdef, this, toucher);
636 if (Item_IsExpiring(this))
638 // undo what we did above
639 this.strength_finished += time;
640 this.invincible_finished += time;
641 this.superweapons_finished += time;
648 if(this.target && this.target != "" && this.target != "###item###") // defrag support
649 SUB_UseTargets(this, toucher, NULL);
651 STAT(LAST_PICKUP, toucher) = time;
653 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
654 _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);
656 MUTATOR_CALLHOOK(ItemTouched, this, toucher);
662 if (Item_IsLoot(this))
667 if (!this.spawnshieldtime)
674 RandomSelection_Init();
675 IL_EACH(g_items, it.team == this.team,
677 if (it.itemdef) // is a registered item
680 it.scheduledrespawntime = 0;
681 RandomSelection_AddEnt(it, it.cnt, 0);
684 e = RandomSelection_chosen_ent;
685 Item_Show(e, 1); // reset its state so it is visible (extra sendflags doesn't matter, this happens anyway)
689 Item_ScheduleRespawn(e);
692 void Item_Reset(entity this)
694 Item_Show(this, !this.state);
695 setorigin(this, this.origin);
697 if (Item_IsLoot(this))
701 setthink(this, Item_Think);
702 this.nextthink = time;
703 if (this.waypointsprite_attached)
705 WaypointSprite_Kill(this.waypointsprite_attached);
707 if (this.itemdef.instanceOfPowerup || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
709 Item_ScheduleInitialRespawn(this);
713 void Item_FindTeam(entity this)
717 if(this.effects & EF_NODRAW)
719 // marker for item team search
720 LOG_TRACE("Initializing item team ", ftos(this.team));
721 RandomSelection_Init();
722 IL_EACH(g_items, it.team == this.team,
724 if(it.itemdef) // is a registered item
725 RandomSelection_AddEnt(it, it.cnt, 0);
728 e = RandomSelection_chosen_ent;
732 IL_EACH(g_items, it.team == this.team,
734 if(it.itemdef) // is a registered item
738 // make it non-spawned
740 it.state = 1; // state 1 = initially hidden item, apparently
744 it.effects &= ~EF_NODRAW;
750 // Savage: used for item garbage-collection
751 void RemoveItem(entity this)
753 if(wasfreed(this) || !this) { return; }
754 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
758 // pickup evaluation functions
759 // these functions decide how desirable an item is to the bots
761 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
763 float weapon_pickupevalfunc(entity player, entity item)
765 // See if I have it already
766 if(STAT(WEAPONS, player) & STAT(WEAPONS, item))
768 // If I can pick it up
769 if(!item.spawnshieldtime)
771 return ammo_pickupevalfunc(player, item);
774 // reduce weapon value if bot already got a good arsenal
776 int weapons_value = 0;
777 FOREACH(Weapons, it != WEP_Null && (STAT(WEAPONS, player) & it.m_wepset), {
778 weapons_value += it.bot_pickupbasevalue;
780 c -= bound(0, weapons_value / 20000, 1) * 0.5;
782 return item.bot_pickupbasevalue * c;
785 float ammo_pickupevalfunc(entity player, entity item)
787 bool need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
792 // Detect needed ammo
793 if(item.itemdef.instanceOfWeaponPickup)
796 if(GetResource(item, RES_SHELLS)) { need_shells = true; ammo = ITEM_Shells; }
797 else if(GetResource(item, RES_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; }
798 else if(GetResource(item, RES_ROCKETS)) { need_rockets = true; ammo = ITEM_Rockets; }
799 else if(GetResource(item, RES_CELLS)) { need_cells = true; ammo = ITEM_Cells; }
800 else if(GetResource(item, RES_PLASMA)) { need_plasma = true; ammo = ITEM_Plasma; }
801 else if(GetResource(item, RES_FUEL)) { need_fuel = true; ammo = ITEM_JetpackFuel; }
806 rating = ammo.m_botvalue;
810 FOREACH(Weapons, it != WEP_Null, {
811 if(!(STAT(WEAPONS, player) & (it.m_wepset)))
816 case RES_SHELLS: need_shells = true; break;
817 case RES_BULLETS: need_nails = true; break;
818 case RES_ROCKETS: need_rockets = true; break;
819 case RES_CELLS: need_cells = true; break;
820 case RES_PLASMA: need_plasma = true; break;
821 case RES_FUEL: need_fuel = true; break;
824 rating = item.bot_pickupbasevalue;
827 float noammorating = 0.5;
829 if ((need_shells) && GetResource(item, RES_SHELLS) && (GetResource(player, RES_SHELLS) < g_pickup_shells_max))
830 c = GetResource(item, RES_SHELLS) / max(noammorating, GetResource(player, RES_SHELLS));
832 if ((need_nails) && GetResource(item, RES_BULLETS) && (GetResource(player, RES_BULLETS) < g_pickup_nails_max))
833 c = GetResource(item, RES_BULLETS) / max(noammorating, GetResource(player, RES_BULLETS));
835 if ((need_rockets) && GetResource(item, RES_ROCKETS) && (GetResource(player, RES_ROCKETS) < g_pickup_rockets_max))
836 c = GetResource(item, RES_ROCKETS) / max(noammorating, GetResource(player, RES_ROCKETS));
838 if ((need_cells) && GetResource(item, RES_CELLS) && (GetResource(player, RES_CELLS) < g_pickup_cells_max))
839 c = GetResource(item, RES_CELLS) / max(noammorating, GetResource(player, RES_CELLS));
841 if ((need_plasma) && GetResource(item, RES_PLASMA) && (GetResource(player, RES_PLASMA) < g_pickup_plasma_max))
842 c = GetResource(item, RES_PLASMA) / max(noammorating, GetResource(player, RES_PLASMA));
844 if ((need_fuel) && GetResource(item, RES_FUEL) && (GetResource(player, RES_FUEL) < g_pickup_fuel_max))
845 c = GetResource(item, RES_FUEL) / max(noammorating, GetResource(player, RES_FUEL));
849 rating += wpn.bot_pickupbasevalue * 0.1;
853 float healtharmor_pickupevalfunc(entity player, entity item)
856 float rating = item.bot_pickupbasevalue;
858 float itemarmor = GetResource(item, RES_ARMOR);
859 float itemhealth = GetResource(item, RES_HEALTH);
863 itemarmor *= min(4, item.item_group_count);
864 itemhealth *= min(4, item.item_group_count);
867 if (itemarmor && (GetResource(player, RES_ARMOR) < item.max_armorvalue))
868 c = itemarmor / max(1, GetResource(player, RES_ARMOR) * 2/3 + GetResource(player, RES_HEALTH) * 1/3);
870 if (itemhealth && (GetResource(player, RES_HEALTH) < item.max_health))
871 c = itemhealth / max(1, GetResource(player, RES_HEALTH));
877 void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
879 if(ITEM_DAMAGE_NEEDKILL(deathtype))
883 void item_use(entity this, entity actor, entity trigger)
885 // use the touch function to handle collection
886 gettouch(this)(this, actor);
889 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
891 string itemname = def.m_name;
892 Model itemmodel = def.m_model;
893 Sound pickupsound = def.m_sound;
894 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
895 float pickupbasevalue = def.m_botvalue;
896 int itemflags = def.m_itemflags;
898 startitem_failed = false;
900 this.item_model_ent = itemmodel;
901 this.item_pickupsound_ent = pickupsound;
904 def.m_iteminit(def, this);
906 if(!this.respawntime) // both need to be set
908 this.respawntime = defaultrespawntime;
909 this.respawntimejitter = defaultrespawntimejitter;
912 if(!this.pickup_anyway && def.m_pickupanyway)
913 this.pickup_anyway = def.m_pickupanyway();
915 int itemid = def.m_itemid;
917 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
918 this.weapon = weaponid;
922 this.fade_start = autocvar_g_items_mindist;
923 this.fade_end = autocvar_g_items_maxdist;
927 STAT(WEAPONS, this) = WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
929 this.flags = FL_ITEM | itemflags;
930 IL_PUSH(g_items, this);
932 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
934 startitem_failed = true;
939 precache_model(this.model);
940 precache_sound(this.item_pickupsound);
942 if (Item_IsLoot(this))
944 this.reset = SUB_Remove;
945 set_movetype(this, MOVETYPE_TOSS);
947 // Savage: remove thrown items after a certain period of time ("garbage collection")
948 setthink(this, RemoveItem);
949 this.nextthink = time + 20;
951 this.takedamage = DAMAGE_YES;
952 this.event_damage = Item_Damage;
954 if (Item_IsExpiring(this))
956 // if item is worthless after a timer, have it expire then
957 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
960 // don't drop if in a NODROP zone (such as lava)
961 traceline(this.origin, this.origin, MOVE_NORMAL, this);
962 if (trace_dpstartcontents & DPCONTENTS_NODROP)
964 startitem_failed = true;
971 if(!have_pickup_item(this))
973 startitem_failed = true;
978 if(this.angles != '0 0 0')
979 this.SendFlags |= ISF_ANGLES;
981 this.reset = Item_Reset;
983 if(this.spawnflags & 1)
985 if (this.noalign > 0)
986 set_movetype(this, MOVETYPE_NONE);
988 set_movetype(this, MOVETYPE_TOSS);
989 // do item filtering according to game mode and other things
990 if (this.noalign <= 0)
992 // first nudge it off the floor a little bit to avoid math errors
993 setorigin(this, this.origin + '0 0 1');
994 // set item size before we spawn a spawnfunc_waypoint
995 setsize(this, def.m_mins, def.m_maxs);
996 this.SendFlags |= ISF_SIZE;
997 // note droptofloor returns false if stuck/or would fall too far
1000 waypoint_spawnforitem(this);
1004 * can't do it that way, as it would break maps
1005 * TODO make a target_give like entity another way, that perhaps has
1006 * the weapon name in a key
1009 // target_give not yet supported; maybe later
1010 print("removed targeted ", this.classname, "\n");
1011 startitem_failed = true;
1017 if(this.targetname != "" && (this.spawnflags & 16))
1018 this.use = item_use;
1020 if(autocvar_spawn_debug >= 2)
1022 // why not flags & fl_item?
1023 FOREACH_ENTITY_RADIUS(this.origin, 3, it.is_item, {
1024 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1025 LOG_TRACE(" vs ", it.netname, vtos(it.origin));
1026 error("Mapper sucks.");
1028 this.is_item = true;
1031 weaponsInMap |= WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
1033 if ( def.instanceOfPowerup
1034 || def.instanceOfWeaponPickup
1035 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1036 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1037 || (itemid & (IT_KEY1 | IT_KEY2))
1040 if(!this.target || this.target == "")
1041 this.target = "###item###"; // for finding the nearest item using findnearest
1044 Item_ItemsTime_SetTime(this, 0);
1047 this.bot_pickup = true;
1048 this.bot_pickupevalfunc = pickupevalfunc;
1049 this.bot_pickupbasevalue = pickupbasevalue;
1050 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1051 this.netname = itemname;
1052 settouch(this, Item_Touch);
1053 setmodel(this, MDL_Null); // precision set below
1054 //this.effects |= EF_LOWPRECISION;
1056 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1058 this.SendFlags |= ISF_SIZE;
1060 if (!(this.spawnflags & 1024)) {
1061 if(def.instanceOfPowerup)
1062 this.ItemStatus |= ITS_ANIMATE1;
1064 if(GetResource(this, RES_ARMOR) || GetResource(this, RES_HEALTH))
1065 this.ItemStatus |= ITS_ANIMATE2;
1068 if(Item_IsLoot(this))
1071 if(def.instanceOfWeaponPickup)
1073 if (!Item_IsLoot(this)) // if dropped, colormap is already set up nicely
1074 this.colormap = 1024; // color shirt=0 pants=0 grey
1075 if (!(this.spawnflags & 1024))
1076 this.ItemStatus |= ITS_ANIMATE1;
1077 this.SendFlags |= ISF_COLORMAP;
1084 this.cnt = 1; // item probability weight
1086 this.effects |= EF_NODRAW; // marker for item team search
1087 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1092 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1094 // call this hook after everything else has been done
1095 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1097 startitem_failed = true;
1105 void StartItem(entity this, GameItem def)
1107 def = def.m_spawnfunc_hookreplace(def, this);
1108 if (def.spawnflags & ITEM_FLAG_MUTATORBLOCKED)
1113 this.classname = def.m_canonical_spawnfunc;
1117 def.m_respawntime(), // defaultrespawntime
1118 def.m_respawntimejitter() // defaultrespawntimejitter
1122 #define IS_SMALL(def) ((def.instanceOfHealth && def == ITEM_HealthSmall) || (def.instanceOfArmor && def == ITEM_ArmorSmall))
1123 int group_count = 1;
1125 void setItemGroup(entity this)
1127 if(!IS_SMALL(this.itemdef) || Item_IsLoot(this))
1130 FOREACH_ENTITY_RADIUS(this.origin, 120, (it != this) && IS_SMALL(it.itemdef),
1132 if(!this.item_group)
1136 it.item_group = group_count;
1139 this.item_group = it.item_group;
1141 else // spawning item is already part of a item_group X
1144 it.item_group = this.item_group;
1145 else if(it.item_group != this.item_group) // found an item near the spawning item that is part of a different item_group Y
1147 int grY = it.item_group;
1148 // move all items of item_group Y to item_group X
1149 IL_EACH(g_items, IS_SMALL(it.itemdef),
1151 if(it.item_group == grY)
1152 it.item_group = this.item_group;
1159 void setItemGroupCount()
1161 for (int k = 1; k <= group_count; k++)
1164 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { count++; });
1166 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { it.item_group_count = count; });
1170 void target_items_use(entity this, entity actor, entity trigger)
1172 if(Item_IsLoot(actor))
1174 EXACTTRIGGER_TOUCH(this, trigger);
1179 if (!IS_PLAYER(actor) || IS_DEAD(actor))
1182 if(trigger.solid == SOLID_TRIGGER)
1184 EXACTTRIGGER_TOUCH(this, trigger);
1187 IL_EACH(g_items, it.enemy == actor && Item_IsLoot(it),
1192 if(GiveItems(actor, 0, tokenize_console(this.netname)))
1193 centerprint(actor, this.message);
1196 spawnfunc(target_items)
1198 this.use = target_items_use;
1199 if(!this.strength_finished)
1200 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1201 if(!this.invincible_finished)
1202 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1203 if(!this.superweapons_finished)
1204 this.superweapons_finished = autocvar_g_balance_superweapons_time;
1207 int n = tokenize_console(this.netname);
1208 if(argv(0) == "give")
1210 str = substring(this.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1214 for(int j = 0; j < n; ++j)
1216 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1217 if (argv(j) == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS;
1218 else if(argv(j) == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_AMMO;
1219 else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS;
1220 else if(argv(j) == "strength") this.items |= ITEM_Strength.m_itemid;
1221 else if(argv(j) == "invincible") this.items |= ITEM_Shield.m_itemid;
1222 else if(argv(j) == "superweapons") this.items |= IT_SUPERWEAPON;
1223 else if(argv(j) == "jetpack") this.items |= ITEM_Jetpack.m_itemid;
1224 else if(argv(j) == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid;
1227 FOREACH(StatusEffect, it.instanceOfBuff,
1229 string s = Buff_UndeprecateName(argv(j));
1233 if(!this.buffs_finished)
1234 this.buffs_finished = it.m_time(it);
1238 FOREACH(Weapons, it != WEP_Null, {
1239 string s = W_UndeprecateName(argv(j));
1242 STAT(WEAPONS, this) |= (it.m_wepset);
1243 if(this.spawnflags == 0 || this.spawnflags == 2)
1251 string itemprefix, valueprefix;
1252 if(this.spawnflags == 0)
1257 else if(this.spawnflags == 1)
1259 itemprefix = "max ";
1260 valueprefix = "max ";
1262 else if(this.spawnflags == 2)
1264 itemprefix = "min ";
1265 valueprefix = "min ";
1267 else if(this.spawnflags == 4)
1269 itemprefix = "minus ";
1270 valueprefix = "max ";
1274 error("invalid spawnflags");
1275 itemprefix = valueprefix = string_null;
1279 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_AMMO), "unlimited_weapon_ammo");
1280 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1281 str = sprintf("%s %s%d %s", str, valueprefix, this.strength_finished * boolean(this.items & ITEM_Strength.m_itemid), "strength");
1282 str = sprintf("%s %s%d %s", str, valueprefix, this.invincible_finished * boolean(this.items & ITEM_Shield.m_itemid), "invincible");
1283 str = sprintf("%s %s%d %s", str, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
1284 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
1285 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1287 res = GetResource(this, RES_SHELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "shells");
1288 res = GetResource(this, RES_BULLETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "nails");
1289 res = GetResource(this, RES_ROCKETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "rockets");
1290 res = GetResource(this, RES_CELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "cells");
1291 res = GetResource(this, RES_PLASMA); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "plasma");
1292 res = GetResource(this, RES_FUEL); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "fuel");
1293 res = GetResource(this, RES_HEALTH); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "health");
1294 res = GetResource(this, RES_ARMOR); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "armor");
1295 FOREACH(StatusEffect, it.instanceOfBuff, str = sprintf("%s %s%d %s", str, valueprefix, this.buffs_finished * boolean(this.buffdef == it), it.netname));
1296 FOREACH(Weapons, it != WEP_Null, str = sprintf("%s %s%d %s", str, itemprefix, !!(STAT(WEAPONS, this) & (it.m_wepset)), it.netname));
1298 this.netname = strzone(str);
1300 n = tokenize_console(this.netname);
1301 for(int j = 0; j < n; ++j)
1303 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(argv(j)) == it.netname, {
1310 float GiveWeapon(entity e, float wpn, float op, float val)
1313 WepSet s = WepSet_FromWeapon(REGISTRY_GET(Weapons, wpn));
1314 v0 = (STAT(WEAPONS, e) & s);
1319 STAT(WEAPONS, e) |= s;
1321 STAT(WEAPONS, e) &= ~s;
1326 STAT(WEAPONS, e) |= s;
1330 STAT(WEAPONS, e) &= ~s;
1334 STAT(WEAPONS, e) &= ~s;
1337 v1 = (STAT(WEAPONS, e) & s);
1341 bool GiveBuff(entity e, Buff thebuff, int op, int val)
1343 bool had_buff = StatusEffects_active(thebuff, e);
1344 float new_buff_time = ((had_buff) ? StatusEffects_gettime(thebuff, e) : 0);
1348 new_buff_time = val;
1351 new_buff_time = max(new_buff_time, val);
1354 new_buff_time = min(new_buff_time, val);
1357 new_buff_time += val;
1360 new_buff_time -= val;
1363 if(new_buff_time <= 0)
1365 StatusEffects_remove(thebuff, e, STATUSEFFECT_REMOVE_TIMEOUT);
1369 buff_RemoveAll(e, STATUSEFFECT_REMOVE_CLEAR); // clear old buffs on the player first!
1370 StatusEffects_apply(thebuff, e, new_buff_time, 0);
1372 bool have_buff = StatusEffects_active(thebuff, e);
1373 return (had_buff != have_buff);
1376 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
1382 if(snd_decr != NULL)
1383 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1385 else if(v0 >= v0 + t)
1387 if(snd_incr != NULL)
1388 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1392 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1395 e.(rotfield) = max(e.(rotfield), time + rottime);
1397 e.(regenfield) = max(e.(regenfield), time + regentime);
1399 bool GiveResourceValue(entity e, int res_type, int op, int val)
1401 int v0 = GetResource(e, res_type);
1405 // min 100 cells = at least 100 cells
1406 case OP_SET: new_val = val; break;
1407 case OP_MIN: new_val = max(v0, val); break;
1408 case OP_MAX: new_val = min(v0, val); break;
1409 case OP_PLUS: new_val = v0 + val; break;
1410 case OP_MINUS: new_val = v0 - val; break;
1411 default: return false;
1414 return SetResourceExplicit(e, res_type, new_val);
1416 bool GiveStatusEffect(entity e, StatusEffects this, int op, float val)
1418 bool had_eff = StatusEffects_active(this, e);
1419 float new_eff_time = ((had_eff) ? StatusEffects_gettime(this, e) : 0);
1426 new_eff_time = max(new_eff_time, val);
1429 new_eff_time = min(new_eff_time, val);
1432 new_eff_time += val;
1435 new_eff_time -= val;
1438 if(new_eff_time <= 0)
1439 StatusEffects_remove(this, e, STATUSEFFECT_REMOVE_TIMEOUT);
1441 StatusEffects_apply(this, e, new_eff_time, 0);
1442 bool have_eff = StatusEffects_active(this, e);
1443 return (had_eff != have_eff);
1446 float GiveItems(entity e, float beginarg, float endarg)
1448 float got, i, val, op;
1456 int _switchweapon = 0;
1458 if(CS_CVAR(e).autoswitch)
1460 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1462 .entity weaponentity = weaponentities[slot];
1463 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1464 if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
1465 _switchweapon |= BIT(slot);
1471 FOREACH(StatusEffect, true,
1473 e.statuseffects.statuseffect_time[it.m_id] = max(0, e.statuseffects.statuseffect_time[it.m_id] - time);
1479 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Strength);
1480 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Shield);
1481 //PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Superweapons);
1482 PREGIVE_RESOURCE(e, RES_BULLETS);
1483 PREGIVE_RESOURCE(e, RES_CELLS);
1484 PREGIVE_RESOURCE(e, RES_PLASMA);
1485 PREGIVE_RESOURCE(e, RES_SHELLS);
1486 PREGIVE_RESOURCE(e, RES_ROCKETS);
1487 PREGIVE_RESOURCE(e, RES_FUEL);
1488 PREGIVE_RESOURCE(e, RES_ARMOR);
1489 PREGIVE_RESOURCE(e, RES_HEALTH);
1491 for(i = beginarg; i < endarg; ++i)
1495 if(cmd == "0" || stof(cmd))
1519 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1520 got += GiveStatusEffect(e, STATUSEFFECT_Strength, op, val);
1521 got += GiveStatusEffect(e, STATUSEFFECT_Shield, op, val);
1522 got += GiveStatusEffect(e, STATUSEFFECT_Superweapons, op, val);
1523 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1525 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1526 got += GiveResourceValue(e, RES_HEALTH, op, val);
1527 got += GiveResourceValue(e, RES_ARMOR, op, val);
1529 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)), got += GiveWeapon(e, it.m_id, op, val));
1530 //case "allbuffs": // all buffs makes a player god, do not want!
1531 //FOREACH(StatusEffect, it.instanceOfBuff, got += GiveBuff(e, it, op, val));
1533 got += GiveResourceValue(e, RES_CELLS, op, val);
1534 got += GiveResourceValue(e, RES_PLASMA, op, val);
1535 got += GiveResourceValue(e, RES_SHELLS, op, val);
1536 got += GiveResourceValue(e, RES_BULLETS, op, val);
1537 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1538 got += GiveResourceValue(e, RES_FUEL, op, val);
1540 case "unlimited_ammo":
1541 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1542 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1544 case "unlimited_weapon_ammo":
1545 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1547 case "unlimited_superweapons":
1548 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1551 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1554 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1557 got += GiveStatusEffect(e, STATUSEFFECT_Strength, op, val);
1560 got += GiveStatusEffect(e, STATUSEFFECT_Shield, op, val);
1562 case "superweapons":
1563 got += GiveStatusEffect(e, STATUSEFFECT_Superweapons, op, val);
1566 got += GiveResourceValue(e, RES_CELLS, op, val);
1569 got += GiveResourceValue(e, RES_PLASMA, op, val);
1572 got += GiveResourceValue(e, RES_SHELLS, op, val);
1576 got += GiveResourceValue(e, RES_BULLETS, op, val);
1579 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1582 got += GiveResourceValue(e, RES_HEALTH, op, val);
1585 got += GiveResourceValue(e, RES_ARMOR, op, val);
1588 got += GiveResourceValue(e, RES_FUEL, op, val);
1591 FOREACH(StatusEffect, it.instanceOfBuff && buff_Available(it) && Buff_UndeprecateName(cmd) == it.netname,
1593 got += GiveBuff(e, it, op, val);
1596 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
1597 got += GiveWeapon(e, it.m_id, op, val);
1606 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1607 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1608 POSTGIVE_BIT(e, items, IT_UNLIMITED_AMMO, SND_POWERUP, SND_POWEROFF);
1609 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1610 FOREACH(Weapons, it != WEP_Null, {
1611 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1612 if(!(save_weapons & (it.m_wepset)))
1613 if(STAT(WEAPONS, e) & (it.m_wepset))
1616 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Strength, 1, SND_POWERUP, SND_POWEROFF);
1617 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Shield, 1, SND_POWERUP, SND_POWEROFF);
1618 POSTGIVE_RESOURCE(e, RES_BULLETS, 0, SND_ITEMPICKUP, SND_Null);
1619 POSTGIVE_RESOURCE(e, RES_CELLS, 0, SND_ITEMPICKUP, SND_Null);
1620 POSTGIVE_RESOURCE(e, RES_PLASMA, 0, SND_ITEMPICKUP, SND_Null);
1621 POSTGIVE_RESOURCE(e, RES_SHELLS, 0, SND_ITEMPICKUP, SND_Null);
1622 POSTGIVE_RESOURCE(e, RES_ROCKETS, 0, SND_ITEMPICKUP, SND_Null);
1623 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);
1624 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);
1625 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);
1627 if(!StatusEffects_active(STATUSEFFECT_Superweapons, e))
1629 if(!g_weaponarena && (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
1630 StatusEffects_apply(STATUSEFFECT_Superweapons, e, autocvar_g_balance_superweapons_time, 0);
1635 FOREACH(StatusEffect, true,
1637 if(e.statuseffects.statuseffect_time[it.m_id] <= 0)
1638 e.statuseffects.statuseffect_time[it.m_id] = 0;
1640 e.statuseffects.statuseffect_time[it.m_id] += time;
1643 StatusEffects_update(e);
1646 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1648 .entity weaponentity = weaponentities[slot];
1649 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1650 if(!(STAT(WEAPONS, e) & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
1651 _switchweapon |= BIT(slot);
1656 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1658 .entity weaponentity = weaponentities[slot];
1659 if(_switchweapon & BIT(slot))
1661 Weapon wep = w_getbestweapon(e, weaponentity);
1662 if(wep != e.(weaponentity).m_switchweapon)
1663 W_SwitchWeapon_Force(e, wep, weaponentity);