3 #include "items/_mod.qh"
7 #include "../server/bot/api.qh"
9 #include <server/mutators/_mod.qh>
11 #include "../server/weapons/common.qh"
12 #include "../server/weapons/selection.qh"
13 #include "../server/weapons/weaponsystem.qh"
15 #include "constants.qh"
16 #include <common/deathtypes/all.qh>
17 #include <common/notifications/all.qh>
18 #include "triggers/subs.qh"
21 #include <common/monsters/_mod.qh>
23 #include <common/weapons/_all.qh>
25 #include "../lib/warpzone/util_server.qh"
27 #include "physics/movetypes/movetypes.qh"
28 #include <common/weapons/_all.qh>
29 #include "../lib/csqcmodel/cl_model.qh"
30 #include "../lib/csqcmodel/common.qh"
33 REGISTER_NET_LINKED(ENT_CLIENT_ITEM)
36 bool autocvar_cl_ghost_items_vehicle = true;
38 void Item_SetAlpha(entity this)
40 bool veh_hud = (hud && autocvar_cl_ghost_items_vehicle);
42 if(!veh_hud && (this.ItemStatus & ITS_AVAILABLE))
45 this.colormod = '1 1 1';
46 this.glowmod = this.item_glowmod;
50 if (autocvar_cl_ghost_items_color)
52 this.alpha = autocvar_cl_ghost_items;
53 this.colormod = this.glowmod = autocvar_cl_ghost_items_color;
60 if(this.ItemStatus & ITS_STAYWEP)
62 this.colormod = this.glowmod = autocvar_cl_weapon_stay_color;
63 this.alpha = autocvar_cl_weapon_stay_alpha;
67 void ItemDraw(entity this)
71 Movetype_Physics_MatchServer(this, false);
73 { // For some reason avelocity gets set to '0 0 0' here ...
74 this.oldorigin = this.origin;
77 if(autocvar_cl_animate_items)
78 { // ... so reset it if animations are requested.
79 if(this.ItemStatus & ITS_ANIMATE1)
80 this.avelocity = '0 180 0';
82 if(this.ItemStatus & ITS_ANIMATE2)
83 this.avelocity = '0 -90 0';
87 else if (autocvar_cl_animate_items)
89 if(this.ItemStatus & ITS_ANIMATE1)
91 this.angles += this.avelocity * frametime;
92 setorigin(this, '0 0 10' + this.oldorigin + '0 0 8' * sin(time * 2));
95 if(this.ItemStatus & ITS_ANIMATE2)
97 this.angles += this.avelocity * frametime;
98 setorigin(this, '0 0 8' + this.oldorigin + '0 0 4' * sin(time * 3));
105 void ItemDrawSimple(entity this)
109 Movetype_Physics_MatchServer(this, false);
111 if(IS_ONGROUND(this))
118 void Item_PreDraw(entity this)
120 if(warpzone_warpzones_exist)
122 // just incase warpzones were initialized last, reset these
123 //this.alpha = 1; // alpha is already set by the draw function
124 this.drawmask = MASK_NORMAL;
128 vector org = getpropertyvec(VF_ORIGIN);
129 if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones
131 else if(this.fade_start)
132 alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1);
135 //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
136 if(!hud && (this.ItemStatus & ITS_AVAILABLE))
141 this.drawmask = MASK_NORMAL;
144 void ItemRemove(entity this)
150 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
154 if(sf & ISF_LOCATION)
156 this.origin_x = ReadCoord();
157 this.origin_y = ReadCoord();
158 this.origin_z = ReadCoord();
159 setorigin(this, this.origin);
160 this.oldorigin = this.origin;
165 this.angles_x = ReadAngle();
166 this.angles_y = ReadAngle();
167 this.angles_z = ReadAngle();
172 float use_bigsize = ReadByte();
173 setsize(this, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
176 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
178 this.ItemStatus = ReadByte();
182 if(autocvar_cl_fullbright_items)
183 if(this.ItemStatus & ITS_ALLOWFB)
184 this.effects |= EF_FULLBRIGHT;
186 if(this.ItemStatus & ITS_GLOW)
188 if(this.ItemStatus & ITS_AVAILABLE)
189 this.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
191 this.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
197 this.drawmask = MASK_NORMAL;
198 set_movetype(this, MOVETYPE_TOSS);
199 if (isnew) IL_PUSH(g_drawables, this);
200 this.draw = ItemDraw;
201 this.solid = SOLID_TRIGGER;
202 //this.flags |= FL_ITEM;
204 bool use_bigsize = ReadByte();
206 this.fade_end = ReadShort();
207 this.fade_start = ReadShort();
208 if(this.fade_start && !autocvar_cl_items_nofade)
209 setpredraw(this, Item_PreDraw);
215 string _fn = ReadString();
217 if(autocvar_cl_simple_items && (this.ItemStatus & ITS_ALLOWSI))
219 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
220 this.draw = ItemDrawSimple;
222 if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
223 this.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
224 else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
225 this.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
226 else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
227 this.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
228 else if(fexists(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix)))
229 this.mdl = strzone(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix));
232 this.draw = ItemDraw;
233 LOG_TRACE("Simple item requested for ", _fn, " but no model exists for it");
237 if(this.draw != ItemDrawSimple)
238 this.mdl = strzone(_fn);
242 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, ", tell tZork about this!");
244 precache_model(this.mdl);
245 _setmodel(this, this.mdl);
247 setsize(this, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
250 if(sf & ISF_COLORMAP)
252 this.colormap = ReadShort();
253 this.item_glowmod_x = ReadByte() / 255.0;
254 this.item_glowmod_y = ReadByte() / 255.0;
255 this.item_glowmod_z = ReadByte() / 255.0;
261 this.pushable = true;
262 //this.angles = '0 0 0';
263 set_movetype(this, MOVETYPE_TOSS);
264 this.velocity_x = ReadCoord();
265 this.velocity_y = ReadCoord();
266 this.velocity_z = ReadCoord();
267 setorigin(this, this.oldorigin);
271 this.move_time = time;
272 this.spawntime = time;
275 this.move_time = max(this.move_time, time);
278 if(autocvar_cl_animate_items)
280 if(this.ItemStatus & ITS_ANIMATE1)
281 this.avelocity = '0 180 0';
283 if(this.ItemStatus & ITS_ANIMATE2)
284 this.avelocity = '0 -90 0';
287 this.entremove = ItemRemove;
295 bool ItemSend(entity this, entity to, int sf)
302 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
303 WriteByte(MSG_ENTITY, sf);
305 //WriteByte(MSG_ENTITY, this.cnt);
306 if(sf & ISF_LOCATION)
308 WriteCoord(MSG_ENTITY, this.origin.x);
309 WriteCoord(MSG_ENTITY, this.origin.y);
310 WriteCoord(MSG_ENTITY, this.origin.z);
315 WriteAngle(MSG_ENTITY, this.angles_x);
316 WriteAngle(MSG_ENTITY, this.angles_y);
317 WriteAngle(MSG_ENTITY, this.angles_z);
322 Pickup p = this.itemdef;
323 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
327 WriteByte(MSG_ENTITY, this.ItemStatus);
331 Pickup p = this.itemdef;
332 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
333 WriteShort(MSG_ENTITY, this.fade_end);
334 WriteShort(MSG_ENTITY, this.fade_start);
337 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now");
339 WriteString(MSG_ENTITY, this.mdl);
343 if(sf & ISF_COLORMAP)
345 WriteShort(MSG_ENTITY, this.colormap);
346 WriteByte(MSG_ENTITY, this.glowmod.x * 255.0);
347 WriteByte(MSG_ENTITY, this.glowmod.y * 255.0);
348 WriteByte(MSG_ENTITY, this.glowmod.z * 255.0);
353 WriteCoord(MSG_ENTITY, this.velocity.x);
354 WriteCoord(MSG_ENTITY, this.velocity.y);
355 WriteCoord(MSG_ENTITY, this.velocity.z);
361 void ItemUpdate(entity this)
363 this.oldorigin = this.origin;
364 this.SendFlags |= ISF_LOCATION;
367 void UpdateItemAfterTeleport(entity this)
369 if(getSendEntity(this) == ItemSend)
373 bool have_pickup_item(entity this)
375 if(this.itemdef.instanceOfPowerup)
377 if(autocvar_g_powerups > 0)
379 if(autocvar_g_powerups == 0)
384 if(autocvar_g_pickup_items > 0)
386 if(autocvar_g_pickup_items == 0)
389 if(this.weapons || (this.items & IT_AMMO)) // no item or ammo pickups in weaponarena
396 float Item_Customize()
398 if(this.spawnshieldtime)
400 if(this.weapons & ~other.weapons)
402 this.colormod = '0 0 0';
403 this.glowmod = this.colormod;
404 this.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
411 this.colormod = stov(autocvar_g_ghost_items_color);
412 this.glowmod = this.colormod;
413 this.alpha = g_ghost_items;
422 void Item_Show (entity e, float mode)
424 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
425 e.ItemStatus &= ~ITS_STAYWEP;
426 entity def = e.itemdef;
429 // make the item look normal, and be touchable
431 e.solid = SOLID_TRIGGER;
432 e.spawnshieldtime = 1;
433 e.ItemStatus |= ITS_AVAILABLE;
437 // hide the item completely
438 e.model = string_null;
440 e.spawnshieldtime = 1;
441 e.ItemStatus &= ~ITS_AVAILABLE;
444 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.weapons & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
445 || e.team // weapon stay isn't supported for teamed weapons
447 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
449 // make the item translucent and not touchable
451 e.solid = SOLID_TRIGGER; // can STILL be picked up!
452 e.effects |= EF_STARDUST;
453 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
454 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
458 //setmodel(e, "null");
460 e.colormod = '0 0 0';
461 //e.glowmod = e.colormod;
462 e.spawnshieldtime = 1;
463 e.ItemStatus &= ~ITS_AVAILABLE;
467 e.ItemStatus |= ITS_GLOW;
469 if (autocvar_g_nodepthtestitems)
470 e.effects |= EF_NODEPTHTEST;
473 if (autocvar_g_fullbrightitems)
474 e.ItemStatus |= ITS_ALLOWFB;
476 if (autocvar_sv_simple_items)
477 e.ItemStatus |= ITS_ALLOWSI;
479 // relink entity (because solid may have changed)
480 setorigin(e, e.origin);
481 e.SendFlags |= ISF_STATUS;
484 void Item_Think(entity this)
486 this.nextthink = time;
487 if(this.origin != this.oldorigin)
491 bool Item_ItemsTime_SpectatorOnly(GameItem it);
492 bool Item_ItemsTime_Allow(GameItem it);
493 float Item_ItemsTime_UpdateTime(entity e, float t);
494 void Item_ItemsTime_SetTime(entity e, float t);
495 void Item_ItemsTime_SetTimesForAllPlayers();
497 void Item_Respawn (entity this)
500 sound(this, CH_TRIGGER, this.itemdef.m_respawnsound, VOL_BASE, ATTEN_NORM); // play respawn sound
501 setorigin(this, this.origin);
503 if (Item_ItemsTime_Allow(this.itemdef) || this.weapons & WEPSET_SUPERWEAPONS)
505 float t = Item_ItemsTime_UpdateTime(this, 0);
506 Item_ItemsTime_SetTime(this, t);
507 Item_ItemsTime_SetTimesForAllPlayers();
510 setthink(this, Item_Think);
511 this.nextthink = time;
513 //Send_Effect(EFFECT_ITEM_RESPAWN, this.origin + this.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
514 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
517 void Item_RespawnCountdown (entity this)
519 if(this.count >= ITEM_RESPAWN_TICKS)
521 if(this.waypointsprite_attached)
522 WaypointSprite_Kill(this.waypointsprite_attached);
527 this.nextthink = time + 1;
531 MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0');
534 entity wi = Weapons_from(this.weapon);
535 if (wi != WEP_Null) {
536 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon);
537 wp.wp_extra = wi.m_id;
542 entity ii = this.itemdef;
544 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Item);
545 wp.wp_extra = ii.m_id;
550 if(this.waypointsprite_attached)
552 GameItem def = this.itemdef;
553 if (Item_ItemsTime_SpectatorOnly(def))
554 WaypointSprite_UpdateRule(this.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
555 WaypointSprite_UpdateBuildFinished(this.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
559 if(this.waypointsprite_attached)
561 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
562 if(this.waypointsprite_attached.waypointsprite_visible_for_player(this.waypointsprite_attached, it, it))
565 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM); // play respawn sound
569 WaypointSprite_Ping(this.waypointsprite_attached);
570 //WaypointSprite_UpdateHealth(this.waypointsprite_attached, this.count);
575 void Item_RespawnThink(entity this)
577 this.nextthink = time;
578 if(this.origin != this.oldorigin)
581 if(time >= this.wait)
585 void Item_ScheduleRespawnIn(entity e, float t)
587 // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
588 if ((Item_ItemsTime_Allow(e.itemdef) || e.weapons & WEPSET_SUPERWEAPONS) && (t - ITEM_RESPAWN_TICKS) > 0)
590 setthink(e, Item_RespawnCountdown);
591 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
592 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
594 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
595 Item_ItemsTime_SetTime(e, t);
596 Item_ItemsTime_SetTimesForAllPlayers();
600 setthink(e, Item_RespawnThink);
602 e.scheduledrespawntime = time + t;
607 void Item_ScheduleRespawn(entity e)
609 if(e.respawntime > 0)
612 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
614 else // if respawntime is -1, this item does not respawn
618 void Item_ScheduleInitialRespawn(entity e)
621 Item_ScheduleRespawnIn(e, game_starttime - time + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
624 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
626 if (!item.(ammotype))
629 if (item.spawnshieldtime)
631 if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0)
633 player.(ammotype) = bound(player.(ammotype), ammomax, player.(ammotype) + item.(ammotype));
637 else if(g_weapon_stay == 2)
639 float mi = min(item.(ammotype), ammomax);
640 if (player.(ammotype) < mi)
642 player.(ammotype) = mi;
653 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
655 case ITEM_MODE_HEALTH:
656 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
658 case ITEM_MODE_ARMOR:
659 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
667 float Item_GiveTo(entity item, entity player)
671 // if nothing happens to player, just return without taking the item
673 int _switchweapon = 0;
674 // in case the player has autoswitch enabled do the following:
675 // if the player is using their best weapon before items are given, they
676 // probably want to switch to an even better weapon after items are given
678 if(player.autoswitch)
680 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
682 .entity weaponentity = weaponentities[slot];
683 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
685 if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
686 _switchweapon |= BIT(slot);
688 if(!(player.weapons & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
689 _switchweapon |= BIT(slot);
694 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
695 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
696 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
697 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
698 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
699 pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max, ITEM_MODE_NONE);
700 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
701 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
703 if (item.itemdef.instanceOfWeaponPickup)
707 w &= ~player.weapons;
709 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
712 FOREACH(Weapons, it != WEP_Null, {
713 if(w & (it.m_wepset))
715 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
717 .entity weaponentity = weaponentities[slot];
718 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
719 W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
721 W_GiveWeapon(player, it.m_id);
727 if (item.itemdef.instanceOfPowerup)
729 if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
730 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
731 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
732 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
736 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
740 Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
743 if (item.strength_finished)
746 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
748 if (item.invincible_finished)
751 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
753 if (item.superweapons_finished)
756 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
761 // always eat teamed entities
768 // crude hack to enforce switching weapons
769 if(g_cts && item.itemdef.instanceOfWeaponPickup)
771 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
773 .entity weaponentity = weaponentities[slot];
774 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
775 W_SwitchWeapon_Force(player, Weapons_from(item.weapon), weaponentity);
782 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
784 .entity weaponentity = weaponentities[slot];
785 if(_switchweapon & BIT(slot))
786 if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity))
787 W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity);
794 void Item_Touch(entity this, entity toucher)
797 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
798 if (this.classname == "droppedweapon")
800 if (ITEM_TOUCH_NEEDKILL())
807 if(!(toucher.flags & FL_PICKUPITEMS)
808 || STAT(FROZEN, toucher)
810 || (this.solid != SOLID_TRIGGER)
811 || (this.owner == toucher)
812 || (time < this.item_spawnshieldtime)
815 switch (MUTATOR_CALLHOOK(ItemTouch, this, toucher))
817 case MUT_ITEMTOUCH_RETURN: { return; }
818 case MUT_ITEMTOUCH_PICKUP: { toucher = M_ARGV(1, entity); goto pickup; }
821 toucher = M_ARGV(1, entity);
823 if (this.classname == "droppedweapon")
825 this.strength_finished = max(0, this.strength_finished - time);
826 this.invincible_finished = max(0, this.invincible_finished - time);
827 this.superweapons_finished = max(0, this.superweapons_finished - time);
829 entity it = this.itemdef;
830 bool gave = ITEM_HANDLE(Pickup, it, this, toucher);
833 if (this.classname == "droppedweapon")
835 // undo what we did above
836 this.strength_finished += time;
837 this.invincible_finished += time;
838 this.superweapons_finished += time;
845 toucher.last_pickup = time;
847 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
848 _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);
850 if (this.classname == "droppedweapon")
852 else if (this.spawnshieldtime)
857 RandomSelection_Init();
858 IL_EACH(g_items, it.team == this.team,
860 if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
863 RandomSelection_AddEnt(it, it.cnt, 0);
866 e = RandomSelection_chosen_ent;
871 Item_ScheduleRespawn(e);
875 void Item_Reset(entity this)
877 Item_Show(this, !this.state);
878 setorigin(this, this.origin);
880 if (this.classname != "droppedweapon")
882 setthink(this, Item_Think);
883 this.nextthink = time;
885 if (this.waypointsprite_attached)
886 WaypointSprite_Kill(this.waypointsprite_attached);
888 if (this.itemdef.instanceOfPowerup || (this.weapons & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
889 Item_ScheduleInitialRespawn(this);
893 void Item_FindTeam(entity this)
897 if(this.effects & EF_NODRAW)
899 // marker for item team search
900 LOG_TRACE("Initializing item team ", ftos(this.team));
901 RandomSelection_Init();
902 IL_EACH(g_items, it.team == this.team,
904 if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
905 RandomSelection_AddEnt(it, it.cnt, 0);
908 e = RandomSelection_chosen_ent;
912 IL_EACH(g_items, it.team == this.team,
914 if(it.classname != "item_flag_team" && it.classname != "item_kh_key")
918 // make it non-spawned
920 it.state = 1; // state 1 = initially hidden item, apparently
922 it.effects &= ~EF_NODRAW;
930 // Savage: used for item garbage-collection
931 void RemoveItem(entity this)
933 if(wasfreed(this) || !this) { return; }
934 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
938 // pickup evaluation functions
939 // these functions decide how desirable an item is to the bots
941 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
943 float weapon_pickupevalfunc(entity player, entity item)
947 // See if I have it already
948 if(item.weapons & ~player.weapons)
950 // If I can pick it up
951 if(!item.spawnshieldtime)
953 else if(player.ammo_cells || player.ammo_shells || player.ammo_plasma || player.ammo_nails || player.ammo_rockets)
955 // Skilled bots will grab more
956 c = bound(0, skill / 10, 1) * 0.5;
964 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
965 if( bot_custom_weapon && c )
967 // Find the highest position on any range
969 for (int j = 0; j < WEP_LAST ; ++j){
971 bot_weapons_far[j] == item.weapon ||
972 bot_weapons_mid[j] == item.weapon ||
973 bot_weapons_close[j] == item.weapon
984 position = WEP_LAST - position;
985 // item.bot_pickupbasevalue is overwritten here
986 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
990 return item.bot_pickupbasevalue * c;
993 float commodity_pickupevalfunc(entity player, entity item)
996 float need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
999 // Detect needed ammo
1000 FOREACH(Weapons, it != WEP_Null, {
1001 if(!(player.weapons & (it.m_wepset)))
1004 if(it.items & ITEM_Shells.m_itemid)
1006 else if(it.items & ITEM_Bullets.m_itemid)
1008 else if(it.items & ITEM_Rockets.m_itemid)
1009 need_rockets = true;
1010 else if(it.items & ITEM_Cells.m_itemid)
1012 else if(it.items & ITEM_Plasma.m_itemid)
1014 else if(it.items & ITEM_JetpackFuel.m_itemid)
1018 // TODO: figure out if the player even has the weapon this ammo is for?
1019 // may not affect strategy much though...
1020 // find out how much more ammo/armor/health the player can hold
1022 if (item.ammo_shells)
1023 if (player.ammo_shells < g_pickup_shells_max)
1024 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
1026 if (item.ammo_nails)
1027 if (player.ammo_nails < g_pickup_nails_max)
1028 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
1030 if (item.ammo_rockets)
1031 if (player.ammo_rockets < g_pickup_rockets_max)
1032 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
1034 if (item.ammo_cells)
1035 if (player.ammo_cells < g_pickup_cells_max)
1036 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
1038 if (item.ammo_plasma)
1039 if (player.ammo_plasma < g_pickup_plasma_max)
1040 c = c + max(0, 1 - player.ammo_plasma / g_pickup_plasma_max);
1043 if (player.ammo_fuel < g_pickup_fuel_max)
1044 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
1045 if (item.armorvalue)
1046 if (player.armorvalue < item.max_armorvalue)
1047 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
1049 if (player.health < item.max_health)
1050 c = c + max(0, 1 - player.health / item.max_health);
1052 return item.bot_pickupbasevalue * c;
1055 void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
1057 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1061 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
1063 string itemname = def.m_name;
1064 Model itemmodel = def.m_model;
1065 Sound pickupsound = def.m_sound;
1066 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
1067 float pickupbasevalue = def.m_botvalue;
1068 int itemflags = def.m_itemflags;
1070 startitem_failed = false;
1072 this.item_model_ent = itemmodel;
1073 this.item_pickupsound_ent = pickupsound;
1075 if(!this.respawntime) // both need to be set
1077 this.respawntime = defaultrespawntime;
1078 this.respawntimejitter = defaultrespawntimejitter;
1081 int itemid = def.m_itemid;
1082 this.items = itemid;
1083 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
1084 this.weapon = weaponid;
1088 this.fade_start = autocvar_g_items_mindist;
1089 this.fade_end = autocvar_g_items_maxdist;
1093 this.weapons = WepSet_FromWeapon(Weapons_from(weaponid));
1095 this.flags = FL_ITEM | itemflags;
1096 IL_PUSH(g_items, this);
1098 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
1100 startitem_failed = true;
1105 // is it a dropped weapon?
1106 if (this.classname == "droppedweapon")
1108 this.reset = SUB_Remove;
1109 // it's a dropped weapon
1110 set_movetype(this, MOVETYPE_TOSS);
1112 // Savage: remove thrown items after a certain period of time ("garbage collection")
1113 setthink(this, RemoveItem);
1114 this.nextthink = time + 20;
1116 this.takedamage = DAMAGE_YES;
1117 this.event_damage = Item_Damage;
1119 if(this.strength_finished || this.invincible_finished || this.superweapons_finished)
1121 // if item is worthless after a timer, have it expire then
1122 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
1125 // don't drop if in a NODROP zone (such as lava)
1126 traceline(this.origin, this.origin, MOVE_NORMAL, this);
1127 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1129 startitem_failed = true;
1136 if(!have_pickup_item(this))
1138 startitem_failed = true;
1143 if(this.angles != '0 0 0')
1144 this.SendFlags |= ISF_ANGLES;
1146 this.reset = Item_Reset;
1147 // it's a level item
1148 if(this.spawnflags & 1)
1150 if (this.noalign > 0)
1151 set_movetype(this, MOVETYPE_NONE);
1153 set_movetype(this, MOVETYPE_TOSS);
1154 // do item filtering according to game mode and other things
1155 if (this.noalign <= 0)
1157 // first nudge it off the floor a little bit to avoid math errors
1158 setorigin(this, this.origin + '0 0 1');
1159 // set item size before we spawn a spawnfunc_waypoint
1160 setsize(this, def.m_mins, def.m_maxs);
1161 this.SendFlags |= ISF_SIZE;
1162 // note droptofloor returns false if stuck/or would fall too far
1165 waypoint_spawnforitem(this);
1169 * can't do it that way, as it would break maps
1170 * TODO make a target_give like entity another way, that perhaps has
1171 * the weapon name in a key
1174 // target_give not yet supported; maybe later
1175 print("removed targeted ", this.classname, "\n");
1176 startitem_failed = true;
1182 if(autocvar_spawn_debug >= 2)
1184 // why not flags & fl_item?
1185 FOREACH_ENTITY_RADIUS(this.origin, 3, it.is_item, {
1186 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1187 LOG_TRACE(" vs ", it.netname, vtos(it.origin));
1188 error("Mapper sucks.");
1190 this.is_item = true;
1193 weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid));
1195 precache_model(this.model);
1196 precache_sound(this.item_pickupsound);
1198 if ( def.instanceOfPowerup
1199 || def.instanceOfWeaponPickup
1200 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1201 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1202 || (itemid & (IT_KEY1 | IT_KEY2))
1203 ) this.target = "###item###"; // for finding the nearest item using find()
1205 Item_ItemsTime_SetTime(this, 0);
1208 this.bot_pickup = true;
1209 this.bot_pickupevalfunc = pickupevalfunc;
1210 this.bot_pickupbasevalue = pickupbasevalue;
1211 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1212 this.netname = itemname;
1213 settouch(this, Item_Touch);
1214 setmodel(this, MDL_Null); // precision set below
1215 //this.effects |= EF_LOWPRECISION;
1217 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1219 this.SendFlags |= ISF_SIZE;
1221 if (!(this.spawnflags & 1024)) {
1222 if(def.instanceOfPowerup)
1223 this.ItemStatus |= ITS_ANIMATE1;
1225 if(this.armorvalue || this.health)
1226 this.ItemStatus |= ITS_ANIMATE2;
1229 if(def.instanceOfWeaponPickup)
1231 if (this.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1232 this.colormap = 1024; // color shirt=0 pants=0 grey
1235 if (!(this.spawnflags & 1024))
1236 this.ItemStatus |= ITS_ANIMATE1;
1237 this.SendFlags |= ISF_COLORMAP;
1241 if(this.team) // broken, no idea why.
1244 this.cnt = 1; // item probability weight
1246 this.effects |= EF_NODRAW; // marker for item team search
1247 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1252 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1254 // call this hook after everything else has been done
1255 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1257 startitem_failed = true;
1263 void StartItem(entity this, GameItem def)
1268 def.m_respawntime(), // defaultrespawntime
1269 def.m_respawntimejitter() // defaultrespawntimejitter
1273 spawnfunc(item_rockets)
1275 if(!this.ammo_rockets)
1276 this.ammo_rockets = g_pickup_rockets;
1277 if(!this.pickup_anyway)
1278 this.pickup_anyway = g_pickup_ammo_anyway;
1279 StartItem(this, ITEM_Rockets);
1282 spawnfunc(item_bullets)
1285 if(autocvar_sv_q3acompat_machineshotgunswap)
1286 if(this.classname != "droppedweapon")
1288 weaponswapping = true;
1289 spawnfunc_item_shells(this);
1290 weaponswapping = false;
1294 if(!this.ammo_nails)
1295 this.ammo_nails = g_pickup_nails;
1296 if(!this.pickup_anyway)
1297 this.pickup_anyway = g_pickup_ammo_anyway;
1298 StartItem(this, ITEM_Bullets);
1301 spawnfunc(item_cells)
1303 if(!this.ammo_cells)
1304 this.ammo_cells = g_pickup_cells;
1305 if(!this.pickup_anyway)
1306 this.pickup_anyway = g_pickup_ammo_anyway;
1307 StartItem(this, ITEM_Cells);
1310 spawnfunc(item_plasma)
1312 if(!this.ammo_plasma)
1313 this.ammo_plasma = g_pickup_plasma;
1314 if(!this.pickup_anyway)
1315 this.pickup_anyway = g_pickup_ammo_anyway;
1316 StartItem(this, ITEM_Plasma);
1319 spawnfunc(item_shells)
1322 if(autocvar_sv_q3acompat_machineshotgunswap)
1323 if(this.classname != "droppedweapon")
1325 weaponswapping = true;
1326 spawnfunc_item_bullets(this);
1327 weaponswapping = false;
1331 if(!this.ammo_shells)
1332 this.ammo_shells = g_pickup_shells;
1333 if(!this.pickup_anyway)
1334 this.pickup_anyway = g_pickup_ammo_anyway;
1335 StartItem(this, ITEM_Shells);
1338 spawnfunc(item_armor_small)
1340 if(!this.armorvalue)
1341 this.armorvalue = g_pickup_armorsmall;
1342 if(!this.max_armorvalue)
1343 this.max_armorvalue = g_pickup_armorsmall_max;
1344 if(!this.pickup_anyway)
1345 this.pickup_anyway = g_pickup_armorsmall_anyway;
1346 StartItem(this, ITEM_ArmorSmall);
1349 spawnfunc(item_armor_medium)
1351 if(!this.armorvalue)
1352 this.armorvalue = g_pickup_armormedium;
1353 if(!this.max_armorvalue)
1354 this.max_armorvalue = g_pickup_armormedium_max;
1355 if(!this.pickup_anyway)
1356 this.pickup_anyway = g_pickup_armormedium_anyway;
1357 StartItem(this, ITEM_ArmorMedium);
1360 spawnfunc(item_armor_big)
1362 if(!this.armorvalue)
1363 this.armorvalue = g_pickup_armorbig;
1364 if(!this.max_armorvalue)
1365 this.max_armorvalue = g_pickup_armorbig_max;
1366 if(!this.pickup_anyway)
1367 this.pickup_anyway = g_pickup_armorbig_anyway;
1368 StartItem(this, ITEM_ArmorLarge);
1371 spawnfunc(item_armor_large)
1373 if(!this.armorvalue)
1374 this.armorvalue = g_pickup_armorlarge;
1375 if(!this.max_armorvalue)
1376 this.max_armorvalue = g_pickup_armorlarge_max;
1377 if(!this.pickup_anyway)
1378 this.pickup_anyway = g_pickup_armorlarge_anyway;
1379 StartItem(this, ITEM_ArmorMega);
1382 spawnfunc(item_health_small)
1384 if(!this.max_health)
1385 this.max_health = g_pickup_healthsmall_max;
1387 this.health = g_pickup_healthsmall;
1388 if(!this.pickup_anyway)
1389 this.pickup_anyway = g_pickup_healthsmall_anyway;
1390 StartItem(this, ITEM_HealthSmall);
1393 spawnfunc(item_health_medium)
1395 if(!this.max_health)
1396 this.max_health = g_pickup_healthmedium_max;
1398 this.health = g_pickup_healthmedium;
1399 if(!this.pickup_anyway)
1400 this.pickup_anyway = g_pickup_healthmedium_anyway;
1401 StartItem(this, ITEM_HealthMedium);
1404 spawnfunc(item_health_large)
1406 if(!this.max_health)
1407 this.max_health = g_pickup_healthlarge_max;
1409 this.health = g_pickup_healthlarge;
1410 if(!this.pickup_anyway)
1411 this.pickup_anyway = g_pickup_healthlarge_anyway;
1412 StartItem(this, ITEM_HealthLarge);
1415 spawnfunc(item_health_mega)
1417 if(!this.max_health)
1418 this.max_health = g_pickup_healthmega_max;
1420 this.health = g_pickup_healthmega;
1421 if(!this.pickup_anyway)
1422 this.pickup_anyway = g_pickup_healthmega_anyway;
1423 StartItem(this, ITEM_HealthMega);
1426 // support old misnamed entities
1427 spawnfunc(item_armor1) { spawnfunc_item_armor_small(this); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1428 spawnfunc(item_armor25) { spawnfunc_item_armor_large(this); }
1429 spawnfunc(item_health1) { spawnfunc_item_health_small(this); }
1430 spawnfunc(item_health25) { spawnfunc_item_health_medium(this); }
1431 spawnfunc(item_health100) { spawnfunc_item_health_mega(this); }
1433 spawnfunc(item_strength)
1435 if(!this.strength_finished)
1436 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1437 StartItem(this, ITEM_Strength);
1440 spawnfunc(item_invincible)
1442 if(!this.invincible_finished)
1443 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1444 StartItem(this, ITEM_Shield);
1448 spawnfunc(item_quad) { this.classname = "item_strength";spawnfunc_item_strength(this);}
1450 void target_items_use(entity this, entity actor, entity trigger)
1452 if(actor.classname == "droppedweapon")
1454 EXACTTRIGGER_TOUCH(this, trigger);
1459 if (!IS_PLAYER(actor))
1463 if(trigger.solid == SOLID_TRIGGER)
1465 EXACTTRIGGER_TOUCH(this, trigger);
1468 IL_EACH(g_items, it.enemy == actor && it.classname == "droppedweapon",
1473 if(GiveItems(actor, 0, tokenize_console(this.netname)))
1474 centerprint(actor, this.message);
1477 spawnfunc(target_items)
1482 this.use = target_items_use;
1483 if(!this.strength_finished)
1484 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1485 if(!this.invincible_finished)
1486 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1487 if(!this.superweapons_finished)
1488 this.superweapons_finished = autocvar_g_balance_superweapons_time;
1490 n = tokenize_console(this.netname);
1491 if(argv(0) == "give")
1493 this.netname = substring(this.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1497 for(j = 0; j < n; ++j)
1499 if (argv(j) == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO;
1500 else if(argv(j) == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_WEAPON_AMMO;
1501 else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS;
1502 else if(argv(j) == "strength") this.items |= ITEM_Strength.m_itemid;
1503 else if(argv(j) == "invincible") this.items |= ITEM_Shield.m_itemid;
1504 else if(argv(j) == "superweapons") this.items |= IT_SUPERWEAPON;
1505 else if(argv(j) == "jetpack") this.items |= ITEM_Jetpack.m_itemid;
1506 else if(argv(j) == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid;
1509 FOREACH(Weapons, it != WEP_Null, {
1510 s = W_UndeprecateName(argv(j));
1513 this.weapons |= (it.m_wepset);
1514 if(this.spawnflags == 0 || this.spawnflags == 2)
1522 string itemprefix, valueprefix;
1523 if(this.spawnflags == 0)
1528 else if(this.spawnflags == 1)
1530 itemprefix = "max ";
1531 valueprefix = "max ";
1533 else if(this.spawnflags == 2)
1535 itemprefix = "min ";
1536 valueprefix = "min ";
1538 else if(this.spawnflags == 4)
1540 itemprefix = "minus ";
1541 valueprefix = "max ";
1545 error("invalid spawnflags");
1546 itemprefix = valueprefix = string_null;
1550 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1551 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1552 this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.strength_finished * boolean(this.items & ITEM_Strength.m_itemid), "strength");
1553 this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.invincible_finished * boolean(this.items & ITEM_Shield.m_itemid), "invincible");
1554 this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
1555 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
1556 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1557 if(this.ammo_shells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_shells), "shells");
1558 if(this.ammo_nails != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_nails), "nails");
1559 if(this.ammo_rockets != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_rockets), "rockets");
1560 if(this.ammo_cells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_cells), "cells");
1561 if(this.ammo_plasma != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_plasma), "plasma");
1562 if(this.ammo_fuel != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_fuel), "fuel");
1563 if(this.health != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.health), "health");
1564 if(this.armorvalue != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.armorvalue), "armor");
1565 FOREACH(Weapons, it != WEP_Null, this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, !!(this.weapons & (it.m_wepset)), it.netname));
1567 this.netname = strzone(this.netname);
1568 //print(this.netname, "\n");
1570 n = tokenize_console(this.netname);
1571 for(j = 0; j < n; ++j)
1573 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(argv(j)) == it.netname, {
1580 spawnfunc(item_fuel)
1583 this.ammo_fuel = g_pickup_fuel;
1584 if(!this.pickup_anyway)
1585 this.pickup_anyway = g_pickup_ammo_anyway;
1586 StartItem(this, ITEM_JetpackFuel);
1589 spawnfunc(item_fuel_regen)
1591 if(start_items & ITEM_JetpackRegen.m_itemid)
1593 spawnfunc_item_fuel(this);
1596 StartItem(this, ITEM_JetpackRegen);
1599 spawnfunc(item_jetpack)
1602 this.ammo_fuel = g_pickup_fuel_jetpack;
1603 if(start_items & ITEM_Jetpack.m_itemid)
1605 spawnfunc_item_fuel(this);
1608 StartItem(this, ITEM_Jetpack);
1611 float GiveWeapon(entity e, float wpn, float op, float val)
1614 WepSet s = WepSet_FromWeapon(Weapons_from(wpn));
1615 v0 = (e.weapons & s);
1638 v1 = (e.weapons & s);
1642 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
1648 if(snd_decr != NULL)
1649 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1651 else if(v0 >= v0 + t)
1653 if(snd_incr != NULL)
1654 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1658 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1661 e.(rotfield) = max(e.(rotfield), time + rottime);
1663 e.(regenfield) = max(e.(regenfield), time + regentime);
1665 float GiveItems(entity e, float beginarg, float endarg)
1667 float got, i, val, op;
1675 int _switchweapon = 0;
1679 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1681 .entity weaponentity = weaponentities[slot];
1682 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1683 if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
1684 _switchweapon |= BIT(slot);
1688 e.strength_finished = max(0, e.strength_finished - time);
1689 e.invincible_finished = max(0, e.invincible_finished - time);
1690 e.superweapons_finished = max(0, e.superweapons_finished - time);
1694 PREGIVE(e, strength_finished);
1695 PREGIVE(e, invincible_finished);
1696 PREGIVE(e, superweapons_finished);
1697 PREGIVE(e, ammo_nails);
1698 PREGIVE(e, ammo_cells);
1699 PREGIVE(e, ammo_plasma);
1700 PREGIVE(e, ammo_shells);
1701 PREGIVE(e, ammo_rockets);
1702 PREGIVE(e, ammo_fuel);
1703 PREGIVE(e, armorvalue);
1706 for(i = beginarg; i < endarg; ++i)
1710 if(cmd == "0" || stof(cmd))
1734 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1735 got += GiveValue(e, strength_finished, op, val);
1736 got += GiveValue(e, invincible_finished, op, val);
1737 got += GiveValue(e, superweapons_finished, op, val);
1738 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1740 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1741 got += GiveValue(e, health, op, val);
1742 got += GiveValue(e, armorvalue, op, val);
1744 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & WEP_FLAG_MUTATORBLOCKED), got += GiveWeapon(e, it.m_id, op, val));
1746 got += GiveValue(e, ammo_cells, op, val);
1747 got += GiveValue(e, ammo_plasma, op, val);
1748 got += GiveValue(e, ammo_shells, op, val);
1749 got += GiveValue(e, ammo_nails, op, val);
1750 got += GiveValue(e, ammo_rockets, op, val);
1751 got += GiveValue(e, ammo_fuel, op, val);
1753 case "unlimited_ammo":
1754 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1756 case "unlimited_weapon_ammo":
1757 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1759 case "unlimited_superweapons":
1760 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1763 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1766 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1769 got += GiveValue(e, strength_finished, op, val);
1772 got += GiveValue(e, invincible_finished, op, val);
1774 case "superweapons":
1775 got += GiveValue(e, superweapons_finished, op, val);
1778 got += GiveValue(e, ammo_cells, op, val);
1781 got += GiveValue(e, ammo_plasma, op, val);
1784 got += GiveValue(e, ammo_shells, op, val);
1788 got += GiveValue(e, ammo_nails, op, val);
1791 got += GiveValue(e, ammo_rockets, op, val);
1794 got += GiveValue(e, health, op, val);
1797 got += GiveValue(e, armorvalue, op, val);
1800 got += GiveValue(e, ammo_fuel, op, val);
1803 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
1804 got += GiveWeapon(e, it.m_id, op, val);
1813 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1814 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1815 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND_POWERUP, SND_POWEROFF);
1816 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1817 FOREACH(Weapons, it != WEP_Null, {
1818 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1819 if(!(save_weapons & (it.m_wepset)))
1820 if(e.weapons & (it.m_wepset))
1823 POSTGIVE_VALUE(e, strength_finished, 1, SND_POWERUP, SND_POWEROFF);
1824 POSTGIVE_VALUE(e, invincible_finished, 1, SND_Shield, SND_POWEROFF);
1825 POSTGIVE_VALUE(e, ammo_nails, 0, SND_ITEMPICKUP, SND_Null);
1826 POSTGIVE_VALUE(e, ammo_cells, 0, SND_ITEMPICKUP, SND_Null);
1827 POSTGIVE_VALUE(e, ammo_plasma, 0, SND_ITEMPICKUP, SND_Null);
1828 POSTGIVE_VALUE(e, ammo_shells, 0, SND_ITEMPICKUP, SND_Null);
1829 POSTGIVE_VALUE(e, ammo_rockets, 0, SND_ITEMPICKUP, SND_Null);
1830 POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND_ITEMPICKUP, SND_Null);
1831 POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_ARMOR25, SND_Null);
1832 POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_MEGAHEALTH, SND_Null);
1834 if(e.superweapons_finished <= 0)
1835 if(e.weapons & WEPSET_SUPERWEAPONS)
1836 e.superweapons_finished = autocvar_g_balance_superweapons_time;
1838 if(e.strength_finished <= 0)
1839 e.strength_finished = 0;
1841 e.strength_finished += time;
1842 if(e.invincible_finished <= 0)
1843 e.invincible_finished = 0;
1845 e.invincible_finished += time;
1846 if(e.superweapons_finished <= 0)
1847 e.superweapons_finished = 0;
1849 e.superweapons_finished += time;
1851 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1853 .entity weaponentity = weaponentities[slot];
1854 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1855 if(!(e.weapons & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
1856 _switchweapon |= BIT(slot);
1861 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1863 .entity weaponentity = weaponentities[slot];
1864 if(_switchweapon & BIT(slot))
1865 W_SwitchWeapon_Force(e, w_getbestweapon(e, weaponentity), weaponentity);