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/powerups/_mod.qh>
13 #include <common/mutators/mutator/status_effects/_mod.qh>
14 #include <common/notifications/all.qh>
15 #include <common/resources/resources.qh>
16 #include <common/util.qh>
17 #include <common/weapons/_all.qh>
18 #include <common/wepent.qh>
19 #include <lib/warpzone/common.qh>
20 #include <lib/warpzone/util_server.qh>
21 #include <server/bot/api.qh>
22 #include <server/command/vote.qh>
23 #include <server/damage.qh>
24 #include <server/mutators/_mod.qh>
25 #include <server/teamplay.qh>
26 #include <server/weapons/common.qh>
27 #include <server/weapons/selection.qh>
28 #include <server/weapons/weaponsystem.qh>
29 #include <server/world.qh>
31 bool ItemSend(entity this, entity to, int sf)
38 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
39 WriteByte(MSG_ENTITY, sf);
41 //WriteByte(MSG_ENTITY, this.cnt);
44 WriteVector(MSG_ENTITY, this.origin);
49 WriteAngleVector(MSG_ENTITY, this.angles);
52 // sets size on the client, unused on server
56 WriteByte(MSG_ENTITY, this.ItemStatus);
60 WriteShort(MSG_ENTITY, bound(0, this.fade_end, 32767));
61 WriteShort(MSG_ENTITY, bound(0, this.fade_start, 32767));
64 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now");
66 WriteString(MSG_ENTITY, this.mdl);
67 WriteByte(MSG_ENTITY, bound(0, this.skin, 255));
72 WriteShort(MSG_ENTITY, this.colormap);
73 WriteByte(MSG_ENTITY, this.glowmod.x * 255.0);
74 WriteByte(MSG_ENTITY, this.glowmod.y * 255.0);
75 WriteByte(MSG_ENTITY, this.glowmod.z * 255.0);
80 WriteVector(MSG_ENTITY, this.velocity);
86 void ItemUpdate(entity this)
88 this.oldorigin = this.origin;
89 this.SendFlags |= ISF_LOCATION;
92 void UpdateItemAfterTeleport(entity this)
94 if(getSendEntity(this) == ItemSend)
98 bool have_pickup_item(entity this)
100 if(this.itemdef.instanceOfPowerup)
102 if(autocvar_g_powerups > 0)
104 if(autocvar_g_powerups == 0)
109 if(autocvar_g_pickup_items > 0)
111 if(autocvar_g_pickup_items == 0)
114 if(STAT(WEAPONS, this) || this.itemdef.instanceOfAmmo) // no item or ammo pickups in weaponarena
120 void Item_Show(entity e, int mode)
122 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
123 e.ItemStatus &= ~ITS_STAYWEP;
124 entity def = e.itemdef;
127 // make the item look normal, and be touchable
129 e.solid = SOLID_TRIGGER;
130 e.spawnshieldtime = 1;
131 e.ItemStatus |= ITS_AVAILABLE;
135 // hide the item completely
136 e.model = string_null;
138 e.spawnshieldtime = 1;
139 e.ItemStatus &= ~ITS_AVAILABLE;
143 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.m_wepset & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
144 || e.team // weapon stay isn't supported for teamed weapons
146 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
148 // make the item translucent and not touchable
150 e.solid = SOLID_TRIGGER; // can STILL be picked up!
151 e.effects |= EF_STARDUST;
152 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
153 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
157 //setmodel(e, "null");
159 e.colormod = '0 0 0';
160 //e.glowmod = e.colormod;
161 e.spawnshieldtime = 1;
162 e.ItemStatus &= ~ITS_AVAILABLE;
167 e.ItemStatus |= ITS_GLOW;
169 if (autocvar_g_nodepthtestitems)
170 e.effects |= EF_NODEPTHTEST;
172 if (autocvar_g_fullbrightitems)
173 e.ItemStatus |= ITS_ALLOWFB;
175 e.ItemStatus &= ~ITS_ALLOWFB;
177 if (autocvar_sv_simple_items)
178 e.ItemStatus |= ITS_ALLOWSI;
180 // relink entity (because solid may have changed)
181 setorigin(e, e.origin);
182 e.SendFlags |= ISF_STATUS;
185 void Item_Think(entity this)
187 this.nextthink = time;
188 if(this.origin != this.oldorigin)
192 bool Item_ItemsTime_SpectatorOnly(GameItem it);
193 bool Item_ItemsTime_Allow(GameItem it);
194 float Item_ItemsTime_UpdateTime(entity e, float t);
195 void Item_ItemsTime_SetTime(entity e, float t);
196 void Item_ItemsTime_SetTimesForAllPlayers();
198 void Item_Respawn(entity this)
201 sound(this, CH_TRIGGER, this.itemdef.m_respawnsound, VOL_BASE, ATTEN_NORM); // play respawn sound
202 setorigin(this, this.origin);
204 if (Item_ItemsTime_Allow(this.itemdef) || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS))
206 float t = Item_ItemsTime_UpdateTime(this, 0);
207 Item_ItemsTime_SetTime(this, t);
208 Item_ItemsTime_SetTimesForAllPlayers();
211 setthink(this, Item_Think);
212 this.nextthink = time;
214 //Send_Effect(EFFECT_ITEM_RESPAWN, this.origin + this.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
215 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
218 void Item_RespawnCountdown(entity this)
220 if(this.item_respawncounter >= ITEM_RESPAWN_TICKS)
222 if(this.waypointsprite_attached)
223 WaypointSprite_Kill(this.waypointsprite_attached);
228 this.nextthink = time + 1;
229 this.item_respawncounter += 1;
230 if(this.item_respawncounter == 1)
234 entity wi = REGISTRY_GET(Weapons, this.weapon);
235 if (wi != WEP_Null) {
236 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon);
237 wp.wp_extra = wi.m_id;
242 entity ii = this.itemdef;
244 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Item);
245 wp.wp_extra = ii.m_id;
250 bool mutator_returnvalue = MUTATOR_CALLHOOK(Item_RespawnCountdown, this);
251 if(this.waypointsprite_attached)
253 GameItem def = this.itemdef;
254 if (Item_ItemsTime_SpectatorOnly(def) && !mutator_returnvalue)
255 WaypointSprite_UpdateRule(this.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
256 WaypointSprite_UpdateBuildFinished(this.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
260 if(this.waypointsprite_attached)
262 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
263 if(this.waypointsprite_attached.waypointsprite_visible_for_player(this.waypointsprite_attached, it, it))
266 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM, 0); // play respawn sound
270 WaypointSprite_Ping(this.waypointsprite_attached);
271 //WaypointSprite_UpdateHealth(this.waypointsprite_attached, this.item_respawncounter);
276 void Item_RespawnThink(entity this)
278 this.nextthink = time;
279 if(this.origin != this.oldorigin)
282 if(time >= this.wait)
286 void Item_ScheduleRespawnIn(entity e, float t)
288 // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
289 if ((Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS) || MUTATOR_CALLHOOK(Item_ScheduleRespawn, e, t)) && (t - ITEM_RESPAWN_TICKS) > 0)
291 setthink(e, Item_RespawnCountdown);
292 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
293 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
294 e.item_respawncounter = 0;
295 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
297 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
298 Item_ItemsTime_SetTime(e, t);
299 Item_ItemsTime_SetTimesForAllPlayers();
304 setthink(e, Item_RespawnThink);
306 e.scheduledrespawntime = time + t;
309 if(Item_ItemsTime_Allow(e.itemdef) || (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
311 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
312 Item_ItemsTime_SetTime(e, t);
313 Item_ItemsTime_SetTimesForAllPlayers();
318 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*");
319 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");
320 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");
322 /// Adjust respawn time according to the number of players.
323 float adjust_respawntime(float normal_respawntime) {
324 float r = autocvar_g_pickup_respawntime_scaling_reciprocal;
325 float o = autocvar_g_pickup_respawntime_scaling_offset;
326 float l = autocvar_g_pickup_respawntime_scaling_linear;
328 if (r == 0 && l == 1) {
329 return normal_respawntime;
332 entity balance = TeamBalance_CheckAllowedTeams(NULL);
333 TeamBalance_GetTeamCounts(balance, NULL);
335 for (int i = 1; i <= NUM_TEAMS; ++i)
337 if (TeamBalance_IsTeamAllowed(balance, i))
339 players += TeamBalance_GetNumberOfPlayers(balance, i);
342 TeamBalance_Destroy(balance);
345 return normal_respawntime * (r / (players + o) + l);
347 return normal_respawntime;
351 void Item_ScheduleRespawn(entity e)
353 if(e.respawntime > 0)
357 float adjusted_respawntime = adjust_respawntime(e.respawntime);
358 //LOG_INFOF("item %s will respawn in %f", e.classname, adjusted_respawntime);
360 // range: adjusted_respawntime - respawntimejitter .. adjusted_respawntime + respawntimejitter
361 float respawn_in = adjusted_respawntime + crandom() * e.respawntimejitter;
362 Item_ScheduleRespawnIn(e, respawn_in);
364 else // if respawntime is -1, this item does not respawn
368 AUTOCVAR(g_pickup_respawntime_initial_random, int, 1,
369 "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");
371 void Item_ScheduleInitialRespawn(entity e)
376 if (autocvar_g_pickup_respawntime_initial_random == 0)
378 // range: respawntime .. respawntime + respawntimejitter
379 spawn_in = e.respawntime + random() * e.respawntimejitter;
384 if (autocvar_g_pickup_respawntime_initial_random == 1)
386 static float shared_random = 0;
387 // NOTE this code works only if items are scheduled at the same time (normal case)
388 // NOTE2 random() can't return exactly 1 so this check always work as intended
389 if (!shared_random || floor(time) > shared_random)
390 shared_random = floor(time) + random();
391 rnd = shared_random - floor(time);
397 // if respawntime >= ITEM_RESPAWN_TICKS: ITEM_RESPAWN_TICKS .. respawntime + respawntimejitter
398 // else: 0 .. ITEM_RESPAWN_TICKS
399 // this is to prevent powerups spawning unexpectedly without waypoints
400 spawn_in = ITEM_RESPAWN_TICKS + rnd * (e.respawntime + e.respawntimejitter - ITEM_RESPAWN_TICKS);
403 Item_ScheduleRespawnIn(e, max(0, game_starttime - time) + ((e.respawntimestart) ? e.respawntimestart : spawn_in));
406 void GiveRandomWeapons(entity receiver, int num_weapons, string weapon_names,
409 if (num_weapons == 0)
413 int num_potential_weapons = tokenize_console(weapon_names);
414 for (int give_attempt = 0; give_attempt < num_weapons; ++give_attempt)
416 RandomSelection_Init();
417 for (int weapon_index = 0; weapon_index < num_potential_weapons;
420 string weapon = argv(weapon_index);
421 FOREACH(Weapons, it != WEP_Null,
423 // Finding a weapon which player doesn't have.
424 if (!(STAT(WEAPONS, receiver) & it.m_wepset) && (it.netname == weapon))
426 RandomSelection_AddEnt(it, 1, 1);
431 if (RandomSelection_chosen_ent == NULL)
435 STAT(WEAPONS, receiver) |= RandomSelection_chosen_ent.m_wepset;
436 if (RandomSelection_chosen_ent.ammo_type == RES_NONE)
440 if (GetResource(receiver,
441 RandomSelection_chosen_ent.ammo_type) != 0)
445 GiveResource(receiver, RandomSelection_chosen_ent.ammo_type,
446 GetResource(ammo_entity,
447 RandomSelection_chosen_ent.ammo_type));
451 bool Item_GiveAmmoTo(entity item, entity player, Resource res_type, float ammomax)
453 float amount = GetResource(item, res_type);
458 float player_amount = GetResource(player, res_type);
459 if (item.spawnshieldtime)
461 if ((player_amount >= ammomax) && (item.pickup_anyway <= 0))
464 else if (g_weapon_stay == 2)
466 ammomax = min(amount, ammomax);
467 if(player_amount >= ammomax)
473 TakeResourceWithLimit(player, res_type, -amount, ammomax);
475 GiveResourceWithLimit(player, res_type, amount, ammomax);
479 bool Item_GiveTo(entity item, entity player)
481 // if nothing happens to player, just return without taking the item
482 int _switchweapon = 0;
483 // in case the player has autoswitch enabled do the following:
484 // if the player is using their best weapon before items are given, they
485 // probably want to switch to an even better weapon after items are given
487 if(CS_CVAR(player).cvar_cl_autoswitch)
489 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
491 .entity weaponentity = weaponentities[slot];
492 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
494 if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
495 _switchweapon |= BIT(slot);
497 if(!(STAT(WEAPONS, player) & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
498 _switchweapon |= BIT(slot);
502 bool pickedup = false;
503 pickedup |= Item_GiveAmmoTo(item, player, RES_HEALTH, item.max_health);
504 pickedup |= Item_GiveAmmoTo(item, player, RES_ARMOR, item.max_armorvalue);
505 pickedup |= Item_GiveAmmoTo(item, player, RES_SHELLS, g_pickup_shells_max);
506 pickedup |= Item_GiveAmmoTo(item, player, RES_BULLETS, g_pickup_nails_max);
507 pickedup |= Item_GiveAmmoTo(item, player, RES_ROCKETS, g_pickup_rockets_max);
508 pickedup |= Item_GiveAmmoTo(item, player, RES_CELLS, g_pickup_cells_max);
509 pickedup |= Item_GiveAmmoTo(item, player, RES_PLASMA, g_pickup_plasma_max);
510 pickedup |= Item_GiveAmmoTo(item, player, RES_FUEL, g_pickup_fuel_max);
511 if (item.itemdef.instanceOfWeaponPickup)
514 w = STAT(WEAPONS, item);
515 w &= ~STAT(WEAPONS, player);
517 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
520 FOREACH(Weapons, it != WEP_Null, {
521 if(w & (it.m_wepset))
523 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
525 .entity weaponentity = weaponentities[slot];
526 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
527 W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
529 W_GiveWeapon(player, it.m_id);
535 if (item.itemdef.instanceOfPowerup)
537 if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
538 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
539 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
540 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
544 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
548 // TODO: we probably want to show a message in the console, but not this one!
549 //Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
552 if (item.strength_finished)
555 float t = max(StatusEffects_gettime(STATUSEFFECT_Strength, player), time);
556 if (autocvar_g_powerups_stack)
557 t += item.strength_finished;
559 t = max(t, time + item.strength_finished);
560 StatusEffects_apply(STATUSEFFECT_Strength, player, t, 0);
562 if (item.invincible_finished)
565 float t = max(StatusEffects_gettime(STATUSEFFECT_Shield, player), time);
566 if (autocvar_g_powerups_stack)
567 t += item.invincible_finished;
569 t = max(t, time + item.invincible_finished);
570 StatusEffects_apply(STATUSEFFECT_Shield, player, t, 0);
572 if (item.speed_finished)
575 float t = max(StatusEffects_gettime(STATUSEFFECT_Speed, player), time);
576 if (autocvar_g_powerups_stack)
577 t += item.speed_finished;
579 t = max(t, time + item.speed_finished);
580 StatusEffects_apply(STATUSEFFECT_Speed, player, t, 0);
582 if (item.invisibility_finished)
585 float t = max(StatusEffects_gettime(STATUSEFFECT_Invisibility, player), time);
586 if (autocvar_g_powerups_stack)
587 t += item.invisibility_finished;
589 t = max(t, time + item.invisibility_finished);
590 StatusEffects_apply(STATUSEFFECT_Invisibility, player, t, 0);
592 if (item.superweapons_finished)
595 StatusEffects_apply(STATUSEFFECT_Superweapons, player, max(StatusEffects_gettime(STATUSEFFECT_Superweapons, player), time) + item.superweapons_finished, 0);
598 // always eat teamed entities
605 // crude hack to enforce switching weapons
606 if(g_cts && item.itemdef.instanceOfWeaponPickup && !CS_CVAR(player).cvar_cl_cts_noautoswitch)
608 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
610 .entity weaponentity = weaponentities[slot];
611 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
612 W_SwitchWeapon_Force(player, REGISTRY_GET(Weapons, item.weapon), weaponentity);
619 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
621 .entity weaponentity = weaponentities[slot];
622 if(_switchweapon & BIT(slot))
623 if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity))
624 W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity);
631 void Item_Touch(entity this, entity toucher)
633 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
634 if (Item_IsLoot(this))
636 if (ITEM_TOUCH_NEEDKILL())
643 if(!(toucher.flags & FL_PICKUPITEMS)
644 || STAT(FROZEN, toucher)
646 || (this.solid != SOLID_TRIGGER)
647 || (this.owner == toucher)
648 || (time < this.item_spawnshieldtime)
651 switch (MUTATOR_CALLHOOK(ItemTouch, this, toucher))
653 case MUT_ITEMTOUCH_RETURN: { return; }
654 case MUT_ITEMTOUCH_PICKUP: { toucher = M_ARGV(1, entity); goto pickup; }
657 toucher = M_ARGV(1, entity);
659 if (Item_IsExpiring(this))
661 this.strength_finished = max(0, this.strength_finished - time);
662 this.invincible_finished = max(0, this.invincible_finished - time);
663 this.speed_finished = max(0, this.speed_finished - time);
664 this.invisibility_finished = max(0, this.invisibility_finished - time);
665 this.superweapons_finished = max(0, this.superweapons_finished - time);
667 bool gave = ITEM_HANDLE(Pickup, this.itemdef, this, toucher);
670 if (Item_IsExpiring(this))
672 // undo what we did above
673 this.strength_finished += time;
674 this.invincible_finished += time;
675 this.speed_finished += time;
676 this.invisibility_finished += time;
677 this.superweapons_finished += time;
684 if(this.target && this.target != "" && this.target != "###item###") // defrag support
685 SUB_UseTargets(this, toucher, NULL);
687 STAT(LAST_PICKUP, toucher) = time;
689 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
690 _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);
692 MUTATOR_CALLHOOK(ItemTouched, this, toucher);
698 if (Item_IsLoot(this))
703 if (!this.spawnshieldtime)
710 RandomSelection_Init();
711 IL_EACH(g_items, it.team == this.team,
713 if (it.itemdef) // is a registered item
716 it.scheduledrespawntime = 0;
717 RandomSelection_AddEnt(it, it.cnt, 0);
720 e = RandomSelection_chosen_ent;
721 Item_Show(e, 1); // reset its state so it is visible (extra sendflags doesn't matter, this happens anyway)
725 Item_ScheduleRespawn(e);
728 void Item_Reset(entity this)
730 Item_Show(this, !this.state);
731 setorigin(this, this.origin);
733 if (Item_IsLoot(this))
737 setthink(this, Item_Think);
738 this.nextthink = time;
739 if (this.waypointsprite_attached)
741 WaypointSprite_Kill(this.waypointsprite_attached);
743 if (this.itemdef.instanceOfPowerup || (STAT(WEAPONS, this) & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
745 Item_ScheduleInitialRespawn(this);
749 void Item_FindTeam(entity this)
753 if(this.effects & EF_NODRAW)
755 // marker for item team search
756 LOG_TRACE("Initializing item team ", ftos(this.team));
757 RandomSelection_Init();
758 IL_EACH(g_items, it.team == this.team,
760 if(it.itemdef) // is a registered item
761 RandomSelection_AddEnt(it, it.cnt, 0);
764 e = RandomSelection_chosen_ent;
768 IL_EACH(g_items, it.team == this.team,
770 if(it.itemdef) // is a registered item
774 // make it non-spawned
776 it.state = 1; // state 1 = initially hidden item, apparently
780 it.effects &= ~EF_NODRAW;
786 // Savage: used for item garbage-collection
787 void RemoveItem(entity this)
789 if(wasfreed(this) || !this) { return; }
790 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
794 // pickup evaluation functions
795 // these functions decide how desirable an item is to the bots
797 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
799 float weapon_pickupevalfunc(entity player, entity item)
801 // See if I have it already
802 if(STAT(WEAPONS, player) & STAT(WEAPONS, item))
804 // If I can pick it up
805 if(!item.spawnshieldtime)
807 return ammo_pickupevalfunc(player, item);
810 // reduce weapon value if bot already got a good arsenal
812 int weapons_value = 0;
813 FOREACH(Weapons, it != WEP_Null && (STAT(WEAPONS, player) & it.m_wepset), {
814 weapons_value += it.bot_pickupbasevalue;
816 c -= bound(0, weapons_value / 20000, 1) * 0.5;
818 return item.bot_pickupbasevalue * c;
821 float ammo_pickupevalfunc(entity player, entity item)
823 bool need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
828 // Detect needed ammo
829 if(item.itemdef.instanceOfWeaponPickup)
832 if(GetResource(item, RES_SHELLS)) { need_shells = true; ammo = ITEM_Shells; }
833 else if(GetResource(item, RES_BULLETS)) { need_nails = true; ammo = ITEM_Bullets; }
834 else if(GetResource(item, RES_ROCKETS)) { need_rockets = true; ammo = ITEM_Rockets; }
835 else if(GetResource(item, RES_CELLS)) { need_cells = true; ammo = ITEM_Cells; }
836 else if(GetResource(item, RES_PLASMA)) { need_plasma = true; ammo = ITEM_Plasma; }
837 else if(GetResource(item, RES_FUEL)) { need_fuel = true; ammo = ITEM_JetpackFuel; }
842 rating = ammo.m_botvalue;
846 FOREACH(Weapons, it != WEP_Null, {
847 if(!(STAT(WEAPONS, player) & (it.m_wepset)))
852 case RES_SHELLS: need_shells = true; break;
853 case RES_BULLETS: need_nails = true; break;
854 case RES_ROCKETS: need_rockets = true; break;
855 case RES_CELLS: need_cells = true; break;
856 case RES_PLASMA: need_plasma = true; break;
857 case RES_FUEL: need_fuel = true; break;
860 rating = item.bot_pickupbasevalue;
863 float noammorating = 0.5;
865 if ((need_shells) && GetResource(item, RES_SHELLS) && (GetResource(player, RES_SHELLS) < g_pickup_shells_max))
866 c = GetResource(item, RES_SHELLS) / max(noammorating, GetResource(player, RES_SHELLS));
868 if ((need_nails) && GetResource(item, RES_BULLETS) && (GetResource(player, RES_BULLETS) < g_pickup_nails_max))
869 c = GetResource(item, RES_BULLETS) / max(noammorating, GetResource(player, RES_BULLETS));
871 if ((need_rockets) && GetResource(item, RES_ROCKETS) && (GetResource(player, RES_ROCKETS) < g_pickup_rockets_max))
872 c = GetResource(item, RES_ROCKETS) / max(noammorating, GetResource(player, RES_ROCKETS));
874 if ((need_cells) && GetResource(item, RES_CELLS) && (GetResource(player, RES_CELLS) < g_pickup_cells_max))
875 c = GetResource(item, RES_CELLS) / max(noammorating, GetResource(player, RES_CELLS));
877 if ((need_plasma) && GetResource(item, RES_PLASMA) && (GetResource(player, RES_PLASMA) < g_pickup_plasma_max))
878 c = GetResource(item, RES_PLASMA) / max(noammorating, GetResource(player, RES_PLASMA));
880 if ((need_fuel) && GetResource(item, RES_FUEL) && (GetResource(player, RES_FUEL) < g_pickup_fuel_max))
881 c = GetResource(item, RES_FUEL) / max(noammorating, GetResource(player, RES_FUEL));
885 rating += wpn.bot_pickupbasevalue * 0.1;
889 float healtharmor_pickupevalfunc(entity player, entity item)
892 float rating = item.bot_pickupbasevalue;
894 float itemarmor = GetResource(item, RES_ARMOR);
895 float itemhealth = GetResource(item, RES_HEALTH);
899 itemarmor *= min(4, item.item_group_count);
900 itemhealth *= min(4, item.item_group_count);
903 if (itemarmor && (GetResource(player, RES_ARMOR) < item.max_armorvalue))
904 c = itemarmor / max(1, GetResource(player, RES_ARMOR) * 2/3 + GetResource(player, RES_HEALTH) * 1/3);
906 if (itemhealth && (GetResource(player, RES_HEALTH) < item.max_health))
907 c = itemhealth / max(1, GetResource(player, RES_HEALTH));
913 void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
915 if(ITEM_DAMAGE_NEEDKILL(deathtype))
919 void item_use(entity this, entity actor, entity trigger)
921 // use the touch function to handle collection
922 gettouch(this)(this, actor);
925 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
927 string itemname = def.m_name;
928 Model itemmodel = def.m_model;
929 Sound pickupsound = def.m_sound;
930 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
931 float pickupbasevalue = def.m_botvalue;
932 int itemflags = def.m_itemflags;
934 startitem_failed = false;
936 this.item_model_ent = itemmodel;
937 this.item_pickupsound_ent = pickupsound;
940 def.m_iteminit(def, this);
942 if(!this.respawntime) // both need to be set
944 this.respawntime = defaultrespawntime;
945 this.respawntimejitter = defaultrespawntimejitter;
948 if(!this.pickup_anyway && def.m_pickupanyway)
949 this.pickup_anyway = def.m_pickupanyway();
951 int itemid = def.m_itemid;
953 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
954 this.weapon = weaponid;
958 this.fade_start = autocvar_g_items_mindist;
959 this.fade_end = autocvar_g_items_maxdist;
963 STAT(WEAPONS, this) = WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
965 this.flags = FL_ITEM | itemflags;
966 IL_PUSH(g_items, this);
968 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
970 startitem_failed = true;
975 precache_model(this.model);
976 precache_sound(this.item_pickupsound);
978 if (Item_IsLoot(this))
980 this.reset = SUB_Remove;
981 set_movetype(this, MOVETYPE_TOSS);
983 // Savage: remove thrown items after a certain period of time ("garbage collection")
984 setthink(this, RemoveItem);
985 this.nextthink = time + autocvar_g_items_dropped_lifetime;
987 this.takedamage = DAMAGE_YES;
988 this.event_damage = Item_Damage;
989 // enable this to have thrown items burn in lava
990 //this.damagedbycontents = true;
991 //IL_PUSH(g_damagedbycontents, this);
993 if (Item_IsExpiring(this))
995 // if item is worthless after a timer, have it expire then
996 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
999 // don't drop if in a NODROP zone (such as lava)
1000 traceline(this.origin, this.origin, MOVE_NORMAL, this);
1001 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1003 startitem_failed = true;
1010 if(!have_pickup_item(this))
1012 startitem_failed = true;
1017 if(this.angles != '0 0 0')
1018 this.SendFlags |= ISF_ANGLES;
1020 this.reset = Item_Reset;
1021 // it's a level item
1022 if(this.spawnflags & 1)
1024 if (this.noalign > 0)
1025 set_movetype(this, MOVETYPE_NONE);
1027 set_movetype(this, MOVETYPE_TOSS);
1028 // do item filtering according to game mode and other things
1029 if (this.noalign <= 0)
1031 // first nudge it off the floor a little bit to avoid math errors
1032 setorigin(this, this.origin + '0 0 1');
1033 // set item size before we spawn a spawnfunc_waypoint
1034 setsize(this, def.m_mins, def.m_maxs);
1035 this.SendFlags |= ISF_SIZE;
1036 // note droptofloor returns false if stuck/or would fall too far
1039 waypoint_spawnforitem(this);
1043 * can't do it that way, as it would break maps
1044 * TODO make a target_give like entity another way, that perhaps has
1045 * the weapon name in a key
1048 // target_give not yet supported; maybe later
1049 print("removed targeted ", this.classname, "\n");
1050 startitem_failed = true;
1056 if(this.targetname != "" && (this.spawnflags & 16))
1057 this.use = item_use;
1059 if(autocvar_spawn_debug >= 2)
1061 // why not flags & fl_item?
1062 FOREACH_ENTITY_RADIUS(this.origin, 3, it.is_item, {
1063 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1064 LOG_TRACE(" vs ", it.netname, vtos(it.origin));
1065 error("Mapper sucks.");
1067 this.is_item = true;
1070 weaponsInMap |= WepSet_FromWeapon(REGISTRY_GET(Weapons, weaponid));
1072 if ( def.instanceOfPowerup
1073 || def.instanceOfWeaponPickup
1074 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1075 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1076 || (itemid & (IT_KEY1 | IT_KEY2))
1079 if(!this.target || this.target == "")
1080 this.target = "###item###"; // for finding the nearest item using findnearest
1083 Item_ItemsTime_SetTime(this, 0);
1086 this.bot_pickup = true;
1087 this.bot_pickupevalfunc = pickupevalfunc;
1088 this.bot_pickupbasevalue = pickupbasevalue;
1089 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1090 this.netname = itemname;
1091 settouch(this, Item_Touch);
1092 setmodel(this, MDL_Null); // precision set below
1093 //this.effects |= EF_LOWPRECISION;
1095 // support skinned models for powerups
1096 this.skin = def.m_skin;
1098 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1100 this.SendFlags |= ISF_SIZE;
1102 if (!(this.spawnflags & 1024)) {
1103 if(def.instanceOfPowerup)
1104 this.ItemStatus |= ITS_ANIMATE1;
1106 if(GetResource(this, RES_ARMOR) || GetResource(this, RES_HEALTH))
1107 this.ItemStatus |= ITS_ANIMATE2;
1110 if(Item_IsLoot(this))
1113 this.glowmod = def.m_color;
1115 if(def.instanceOfWeaponPickup)
1117 if (!Item_IsLoot(this)) // if dropped, colormap is already set up nicely
1118 this.colormap = 1024; // color shirt=0 pants=0 grey
1119 if (!(this.spawnflags & 1024))
1120 this.ItemStatus |= ITS_ANIMATE1;
1121 this.SendFlags |= ISF_COLORMAP;
1128 this.cnt = 1; // item probability weight
1130 this.effects |= EF_NODRAW; // marker for item team search
1131 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1136 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1138 // call this hook after everything else has been done
1139 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1141 startitem_failed = true;
1149 void StartItem(entity this, GameItem def)
1151 def = def.m_spawnfunc_hookreplace(def, this);
1153 if (def.spawnflags & ITEM_FLAG_MUTATORBLOCKED)
1159 this.classname = def.m_canonical_spawnfunc;
1164 def.m_respawntime(), // defaultrespawntime
1165 def.m_respawntimejitter() // defaultrespawntimejitter
1169 #define IS_SMALL(def) ((def.instanceOfHealth && def == ITEM_HealthSmall) || (def.instanceOfArmor && def == ITEM_ArmorSmall))
1170 int group_count = 1;
1172 void setItemGroup(entity this)
1174 if(!IS_SMALL(this.itemdef) || Item_IsLoot(this))
1177 FOREACH_ENTITY_RADIUS(this.origin, 120, (it != this) && IS_SMALL(it.itemdef),
1179 if(!this.item_group)
1183 it.item_group = group_count;
1186 this.item_group = it.item_group;
1188 else // spawning item is already part of a item_group X
1191 it.item_group = this.item_group;
1192 else if(it.item_group != this.item_group) // found an item near the spawning item that is part of a different item_group Y
1194 int grY = it.item_group;
1195 // move all items of item_group Y to item_group X
1196 IL_EACH(g_items, IS_SMALL(it.itemdef),
1198 if(it.item_group == grY)
1199 it.item_group = this.item_group;
1206 void setItemGroupCount()
1208 for (int k = 1; k <= group_count; k++)
1211 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { count++; });
1213 IL_EACH(g_items, IS_SMALL(it.itemdef) && it.item_group == k, { it.item_group_count = count; });
1217 void target_items_use(entity this, entity actor, entity trigger)
1219 if(Item_IsLoot(actor))
1221 EXACTTRIGGER_TOUCH(this, trigger);
1226 if (!IS_PLAYER(actor) || IS_DEAD(actor))
1229 if(trigger.solid == SOLID_TRIGGER)
1231 EXACTTRIGGER_TOUCH(this, trigger);
1234 IL_EACH(g_items, it.enemy == actor && Item_IsLoot(it),
1239 if(GiveItems(actor, 0, tokenize_console(this.netname)))
1240 centerprint(actor, this.message);
1243 spawnfunc(target_items)
1245 this.use = target_items_use;
1246 if(!this.strength_finished)
1247 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1248 if(!this.invincible_finished)
1249 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1250 if(!this.speed_finished)
1251 this.speed_finished = autocvar_g_balance_powerup_speed_time;
1252 if(!this.invisibility_finished)
1253 this.invisibility_finished = autocvar_g_balance_powerup_invisibility_time;
1254 if(!this.superweapons_finished)
1255 this.superweapons_finished = autocvar_g_balance_superweapons_time;
1258 int n = tokenize_console(this.netname);
1259 if(argv(0) == "give")
1261 str = substring(this.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1265 for(int j = 0; j < n; ++j)
1267 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1268 if (argv(j) == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS;
1269 else if(argv(j) == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_AMMO;
1270 else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS;
1271 else if(argv(j) == "strength") this.items |= ITEM_Strength.m_itemid;
1272 else if(argv(j) == "invincible") this.items |= ITEM_Shield.m_itemid;
1273 else if(argv(j) == "speed") this.items |= ITEM_Speed.m_itemid;
1274 else if(argv(j) == "invisibility") this.items |= ITEM_Invisibility.m_itemid;
1275 else if(argv(j) == "superweapons") this.items |= IT_SUPERWEAPON;
1276 else if(argv(j) == "jetpack") this.items |= ITEM_Jetpack.m_itemid;
1277 else if(argv(j) == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid;
1280 FOREACH(StatusEffect, it.instanceOfBuff,
1282 string s = Buff_UndeprecateName(argv(j));
1286 if(!this.buffs_finished)
1287 this.buffs_finished = it.m_time(it);
1291 FOREACH(Weapons, it != WEP_Null, {
1292 string s = W_UndeprecateName(argv(j));
1295 STAT(WEAPONS, this) |= (it.m_wepset);
1296 if(this.spawnflags == 0 || this.spawnflags == 2)
1304 string itemprefix, valueprefix;
1305 if(this.spawnflags == 0)
1310 else if(this.spawnflags == 1)
1312 itemprefix = "max ";
1313 valueprefix = "max ";
1315 else if(this.spawnflags == 2)
1317 itemprefix = "min ";
1318 valueprefix = "min ";
1320 else if(this.spawnflags == 4)
1322 itemprefix = "minus ";
1323 valueprefix = "max ";
1327 error("invalid spawnflags");
1328 itemprefix = valueprefix = string_null;
1332 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_AMMO), "unlimited_weapon_ammo");
1333 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1334 str = sprintf("%s %s%d %s", str, valueprefix, this.strength_finished * boolean(this.items & ITEM_Strength.m_itemid), "strength");
1335 str = sprintf("%s %s%d %s", str, valueprefix, this.invincible_finished * boolean(this.items & ITEM_Shield.m_itemid), "invincible");
1336 str = sprintf("%s %s%d %s", str, valueprefix, this.invisibility_finished * boolean(this.items & ITEM_Invisibility.m_itemid), "invisibility");
1337 str = sprintf("%s %s%d %s", str, valueprefix, this.speed_finished * boolean(this.items & ITEM_Speed.m_itemid), "speed");
1338 str = sprintf("%s %s%d %s", str, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
1339 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
1340 str = sprintf("%s %s%d %s", str, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1342 res = GetResource(this, RES_SHELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "shells");
1343 res = GetResource(this, RES_BULLETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "nails");
1344 res = GetResource(this, RES_ROCKETS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "rockets");
1345 res = GetResource(this, RES_CELLS); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "cells");
1346 res = GetResource(this, RES_PLASMA); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "plasma");
1347 res = GetResource(this, RES_FUEL); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "fuel");
1348 res = GetResource(this, RES_HEALTH); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "health");
1349 res = GetResource(this, RES_ARMOR); if(res != 0) str = sprintf("%s %s%d %s", str, valueprefix, max(0, res), "armor");
1350 FOREACH(StatusEffect, it.instanceOfBuff, str = sprintf("%s %s%d %s", str, valueprefix, this.buffs_finished * boolean(this.buffdef == it), it.netname));
1351 FOREACH(Weapons, it != WEP_Null, str = sprintf("%s %s%d %s", str, itemprefix, !!(STAT(WEAPONS, this) & (it.m_wepset)), it.netname));
1353 this.netname = strzone(str);
1355 n = tokenize_console(this.netname);
1356 for(int j = 0; j < n; ++j)
1358 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(argv(j)) == it.netname, {
1365 float GiveWeapon(entity e, float wpn, float op, float val)
1368 WepSet s = WepSet_FromWeapon(REGISTRY_GET(Weapons, wpn));
1369 v0 = (STAT(WEAPONS, e) & s);
1374 STAT(WEAPONS, e) |= s;
1376 STAT(WEAPONS, e) &= ~s;
1381 STAT(WEAPONS, e) |= s;
1385 STAT(WEAPONS, e) &= ~s;
1389 STAT(WEAPONS, e) &= ~s;
1392 v1 = (STAT(WEAPONS, e) & s);
1396 bool GiveBuff(entity e, Buff thebuff, int op, int val)
1398 bool had_buff = StatusEffects_active(thebuff, e);
1399 float new_buff_time = ((had_buff) ? StatusEffects_gettime(thebuff, e) : 0);
1403 new_buff_time = val;
1406 new_buff_time = max(new_buff_time, val);
1409 new_buff_time = min(new_buff_time, val);
1412 new_buff_time += val;
1415 new_buff_time -= val;
1418 if(new_buff_time <= 0)
1420 if(had_buff) // only trigger removal mechanics if there is an effect to remove!
1421 StatusEffects_remove(thebuff, e, STATUSEFFECT_REMOVE_NORMAL);
1425 buff_RemoveAll(e, STATUSEFFECT_REMOVE_CLEAR); // clear old buffs on the player first!
1426 StatusEffects_apply(thebuff, e, new_buff_time, 0);
1428 bool have_buff = StatusEffects_active(thebuff, e);
1429 return (had_buff != have_buff);
1432 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
1438 if(snd_decr != NULL)
1439 sound(e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1441 else if(v0 >= v0 + t)
1443 if(snd_incr != NULL)
1444 sound(e, ((snd_incr == SND_POWERUP) ? CH_TRIGGER_SINGLE : CH_TRIGGER), snd_incr, VOL_BASE, ATTEN_NORM);
1448 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1451 e.(rotfield) = max(e.(rotfield), time + rottime);
1453 e.(regenfield) = max(e.(regenfield), time + regentime);
1455 bool GiveResourceValue(entity e, Resource res_type, int op, int val)
1457 int v0 = GetResource(e, res_type);
1461 // min 100 cells = at least 100 cells
1462 case OP_SET: new_val = val; break;
1463 case OP_MIN: new_val = max(v0, val); break;
1464 case OP_MAX: new_val = min(v0, val); break;
1465 case OP_PLUS: new_val = v0 + val; break;
1466 case OP_MINUS: new_val = v0 - val; break;
1467 default: return false;
1470 return SetResourceExplicit(e, res_type, new_val);
1472 bool GiveStatusEffect(entity e, StatusEffects this, int op, float val)
1474 bool had_eff = StatusEffects_active(this, e);
1475 float new_eff_time = ((had_eff) ? StatusEffects_gettime(this, e) : 0);
1482 new_eff_time = max(new_eff_time, val);
1485 new_eff_time = min(new_eff_time, val);
1488 new_eff_time += val;
1491 new_eff_time -= val;
1494 if(new_eff_time <= 0)
1496 if(had_eff) // only trigger removal mechanics if there is an effect to remove!
1497 StatusEffects_remove(this, e, STATUSEFFECT_REMOVE_NORMAL);
1500 StatusEffects_apply(this, e, new_eff_time, 0);
1501 bool have_eff = StatusEffects_active(this, e);
1502 return (had_eff != have_eff);
1505 float GiveItems(entity e, float beginarg, float endarg)
1507 float got, i, val, op;
1515 int _switchweapon = 0;
1517 if(CS_CVAR(e).cvar_cl_autoswitch)
1519 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1521 .entity weaponentity = weaponentities[slot];
1522 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1523 if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
1524 _switchweapon |= BIT(slot);
1530 FOREACH(StatusEffect, true,
1532 e.statuseffects.statuseffect_time[it.m_id] = max(0, e.statuseffects.statuseffect_time[it.m_id] - time);
1538 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Strength);
1539 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Shield);
1540 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Speed);
1541 PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Invisibility);
1542 //PREGIVE_STATUSEFFECT(e, STATUSEFFECT_Superweapons);
1543 PREGIVE_RESOURCE(e, RES_BULLETS);
1544 PREGIVE_RESOURCE(e, RES_CELLS);
1545 PREGIVE_RESOURCE(e, RES_PLASMA);
1546 PREGIVE_RESOURCE(e, RES_SHELLS);
1547 PREGIVE_RESOURCE(e, RES_ROCKETS);
1548 PREGIVE_RESOURCE(e, RES_FUEL);
1549 PREGIVE_RESOURCE(e, RES_ARMOR);
1550 PREGIVE_RESOURCE(e, RES_HEALTH);
1552 for(i = beginarg; i < endarg; ++i)
1556 if(cmd == "0" || stof(cmd))
1580 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1581 FOREACH(StatusEffect, it.instanceOfPowerups, got += GiveStatusEffect(e, it, op, val));
1582 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1584 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1585 got += GiveResourceValue(e, RES_HEALTH, op, val);
1586 got += GiveResourceValue(e, RES_ARMOR, op, val);
1588 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & (WEP_FLAG_MUTATORBLOCKED | WEP_FLAG_SPECIALATTACK)), got += GiveWeapon(e, it.m_id, op, val));
1589 //case "allbuffs": // all buffs makes a player god, do not want!
1590 //FOREACH(StatusEffect, it.instanceOfBuff, got += GiveBuff(e, it, op, val));
1592 got += GiveResourceValue(e, RES_CELLS, op, val);
1593 got += GiveResourceValue(e, RES_PLASMA, op, val);
1594 got += GiveResourceValue(e, RES_SHELLS, op, val);
1595 got += GiveResourceValue(e, RES_BULLETS, op, val);
1596 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1597 got += GiveResourceValue(e, RES_FUEL, op, val);
1599 case "unlimited_ammo":
1600 // this is from a time when unlimited superweapons were handled together with ammo in some parts of the code
1601 got += GiveBit(e, items, IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS, op, val);
1603 case "unlimited_weapon_ammo":
1604 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1606 case "unlimited_superweapons":
1607 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1610 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1613 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1616 got += GiveStatusEffect(e, STATUSEFFECT_Strength, op, val);
1620 got += GiveStatusEffect(e, STATUSEFFECT_Shield, op, val);
1623 got += GiveStatusEffect(e, STATUSEFFECT_Speed, op, val);
1625 case "invisibility":
1626 got += GiveStatusEffect(e, STATUSEFFECT_Invisibility, op, val);
1628 case "superweapons":
1629 got += GiveStatusEffect(e, STATUSEFFECT_Superweapons, op, val);
1632 got += GiveResourceValue(e, RES_CELLS, op, val);
1635 got += GiveResourceValue(e, RES_PLASMA, op, val);
1638 got += GiveResourceValue(e, RES_SHELLS, op, val);
1642 got += GiveResourceValue(e, RES_BULLETS, op, val);
1645 got += GiveResourceValue(e, RES_ROCKETS, op, val);
1648 got += GiveResourceValue(e, RES_HEALTH, op, val);
1651 got += GiveResourceValue(e, RES_ARMOR, op, val);
1654 got += GiveResourceValue(e, RES_FUEL, op, val);
1657 FOREACH(StatusEffect, it.instanceOfBuff && buff_Available(it) && Buff_UndeprecateName(cmd) == it.netname,
1659 got += GiveBuff(e, it, op, val);
1662 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
1663 got += GiveWeapon(e, it.m_id, op, val);
1672 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1673 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1674 POSTGIVE_BIT(e, items, IT_UNLIMITED_AMMO, SND_POWERUP, SND_POWEROFF);
1675 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1676 FOREACH(Weapons, it != WEP_Null, {
1677 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1678 if(!(save_weapons & (it.m_wepset)))
1679 if(STAT(WEAPONS, e) & (it.m_wepset))
1682 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Strength, SND_POWERUP, SND_POWEROFF);
1683 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Shield, SND_POWERUP, SND_POWEROFF);
1684 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Speed, SND_POWERUP, SND_POWEROFF);
1685 POSTGIVE_STATUSEFFECT(e, STATUSEFFECT_Invisibility, SND_POWERUP, SND_POWEROFF);
1686 POSTGIVE_RESOURCE(e, RES_BULLETS, 0, SND_ITEMPICKUP, SND_Null);
1687 POSTGIVE_RESOURCE(e, RES_CELLS, 0, SND_ITEMPICKUP, SND_Null);
1688 POSTGIVE_RESOURCE(e, RES_PLASMA, 0, SND_ITEMPICKUP, SND_Null);
1689 POSTGIVE_RESOURCE(e, RES_SHELLS, 0, SND_ITEMPICKUP, SND_Null);
1690 POSTGIVE_RESOURCE(e, RES_ROCKETS, 0, SND_ITEMPICKUP, SND_Null);
1691 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);
1692 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);
1693 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);
1695 if(!StatusEffects_active(STATUSEFFECT_Superweapons, e))
1697 if(!g_weaponarena && (STAT(WEAPONS, e) & WEPSET_SUPERWEAPONS))
1698 StatusEffects_apply(STATUSEFFECT_Superweapons, e, autocvar_g_balance_superweapons_time, 0);
1703 FOREACH(StatusEffect, true,
1705 if(e.statuseffects.statuseffect_time[it.m_id] <= 0)
1706 e.statuseffects.statuseffect_time[it.m_id] = 0;
1708 e.statuseffects.statuseffect_time[it.m_id] += time;
1711 StatusEffects_update(e);
1714 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1716 .entity weaponentity = weaponentities[slot];
1717 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1718 if(!(STAT(WEAPONS, e) & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
1719 _switchweapon |= BIT(slot);
1724 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1726 .entity weaponentity = weaponentities[slot];
1727 if(_switchweapon & BIT(slot))
1729 Weapon wep = w_getbestweapon(e, weaponentity);
1730 if(wep != e.(weaponentity).m_switchweapon)
1731 W_SwitchWeapon_Force(e, wep, weaponentity);