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';
86 // delay is for blocking item's position for a while;
87 // it's a workaround for dropped weapons that receive the position
88 // another time right after they spawn overriding animation position
89 this.onground_time = time + 0.5;
92 else if (autocvar_cl_animate_items)
94 if(this.ItemStatus & ITS_ANIMATE1)
96 this.angles += this.avelocity * frametime;
97 float fade_in = bound(0, time - this.onground_time, 1);
98 setorigin(this, this.oldorigin + fade_in * ('0 0 10' + '0 0 8' * sin((time - this.onground_time) * 2)));
101 if(this.ItemStatus & ITS_ANIMATE2)
103 this.angles += this.avelocity * frametime;
104 float fade_in = bound(0, time - this.onground_time, 1);
105 setorigin(this, this.oldorigin + fade_in * ('0 0 8' + '0 0 4' * sin((time - this.onground_time) * 3)));
112 void ItemDrawSimple(entity this)
116 Movetype_Physics_MatchServer(this, false);
118 if(IS_ONGROUND(this))
125 void Item_PreDraw(entity this)
127 if(warpzone_warpzones_exist)
129 // just incase warpzones were initialized last, reset these
130 //this.alpha = 1; // alpha is already set by the draw function
131 this.drawmask = MASK_NORMAL;
135 vector org = getpropertyvec(VF_ORIGIN);
136 if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones
138 else if(this.fade_start)
139 alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1);
142 //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
143 if(!hud && (this.ItemStatus & ITS_AVAILABLE))
148 this.drawmask = MASK_NORMAL;
151 void ItemRemove(entity this)
157 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
161 if(sf & ISF_LOCATION)
163 this.origin_x = ReadCoord();
164 this.origin_y = ReadCoord();
165 this.origin_z = ReadCoord();
166 setorigin(this, this.origin);
167 this.oldorigin = this.origin;
172 this.angles_x = ReadAngle();
173 this.angles_y = ReadAngle();
174 this.angles_z = ReadAngle();
179 float use_bigsize = ReadByte();
180 setsize(this, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
183 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
185 this.ItemStatus = ReadByte();
189 if(autocvar_cl_fullbright_items)
190 if(this.ItemStatus & ITS_ALLOWFB)
191 this.effects |= EF_FULLBRIGHT;
193 if(this.ItemStatus & ITS_GLOW)
195 if(this.ItemStatus & ITS_AVAILABLE)
196 this.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
198 this.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
204 this.drawmask = MASK_NORMAL;
205 set_movetype(this, MOVETYPE_TOSS);
206 if (isnew) IL_PUSH(g_drawables, this);
207 this.draw = ItemDraw;
208 this.solid = SOLID_TRIGGER;
209 //this.flags |= FL_ITEM;
211 bool use_bigsize = ReadByte();
213 this.fade_end = ReadShort();
214 this.fade_start = ReadShort();
215 if(this.fade_start && !autocvar_cl_items_nofade)
216 setpredraw(this, Item_PreDraw);
222 string _fn = ReadString();
224 if(autocvar_cl_simple_items && (this.ItemStatus & ITS_ALLOWSI))
226 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
227 this.draw = ItemDrawSimple;
229 if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
230 this.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
231 else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
232 this.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
233 else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
234 this.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
235 else if(fexists(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix)))
236 this.mdl = strzone(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix));
239 this.draw = ItemDraw;
240 LOG_TRACE("Simple item requested for ", _fn, " but no model exists for it");
244 if(this.draw != ItemDrawSimple)
245 this.mdl = strzone(_fn);
249 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, ", tell tZork about this!");
251 precache_model(this.mdl);
252 _setmodel(this, this.mdl);
254 setsize(this, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
257 if(sf & ISF_COLORMAP)
259 this.colormap = ReadShort();
260 this.item_glowmod_x = ReadByte() / 255.0;
261 this.item_glowmod_y = ReadByte() / 255.0;
262 this.item_glowmod_z = ReadByte() / 255.0;
268 this.pushable = true;
269 //this.angles = '0 0 0';
270 set_movetype(this, MOVETYPE_TOSS);
271 this.velocity_x = ReadCoord();
272 this.velocity_y = ReadCoord();
273 this.velocity_z = ReadCoord();
274 setorigin(this, this.oldorigin);
278 this.move_time = time;
279 this.spawntime = time;
282 this.move_time = max(this.move_time, time);
285 if(autocvar_cl_animate_items)
287 if(this.ItemStatus & ITS_ANIMATE1)
288 this.avelocity = '0 180 0';
290 if(this.ItemStatus & ITS_ANIMATE2)
291 this.avelocity = '0 -90 0';
294 this.entremove = ItemRemove;
302 bool ItemSend(entity this, entity to, int sf)
309 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
310 WriteByte(MSG_ENTITY, sf);
312 //WriteByte(MSG_ENTITY, this.cnt);
313 if(sf & ISF_LOCATION)
315 WriteCoord(MSG_ENTITY, this.origin.x);
316 WriteCoord(MSG_ENTITY, this.origin.y);
317 WriteCoord(MSG_ENTITY, this.origin.z);
322 WriteAngle(MSG_ENTITY, this.angles_x);
323 WriteAngle(MSG_ENTITY, this.angles_y);
324 WriteAngle(MSG_ENTITY, this.angles_z);
329 Pickup p = this.itemdef;
330 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
334 WriteByte(MSG_ENTITY, this.ItemStatus);
338 Pickup p = this.itemdef;
339 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
340 WriteShort(MSG_ENTITY, this.fade_end);
341 WriteShort(MSG_ENTITY, this.fade_start);
344 LOG_TRACE("^1WARNING!^7 this.mdl is unset for item ", this.classname, "expect a crash just about now");
346 WriteString(MSG_ENTITY, this.mdl);
350 if(sf & ISF_COLORMAP)
352 WriteShort(MSG_ENTITY, this.colormap);
353 WriteByte(MSG_ENTITY, this.glowmod.x * 255.0);
354 WriteByte(MSG_ENTITY, this.glowmod.y * 255.0);
355 WriteByte(MSG_ENTITY, this.glowmod.z * 255.0);
360 WriteCoord(MSG_ENTITY, this.velocity.x);
361 WriteCoord(MSG_ENTITY, this.velocity.y);
362 WriteCoord(MSG_ENTITY, this.velocity.z);
368 void ItemUpdate(entity this)
370 this.oldorigin = this.origin;
371 this.SendFlags |= ISF_LOCATION;
374 void UpdateItemAfterTeleport(entity this)
376 if(getSendEntity(this) == ItemSend)
380 bool have_pickup_item(entity this)
382 if(this.itemdef.instanceOfPowerup)
384 if(autocvar_g_powerups > 0)
386 if(autocvar_g_powerups == 0)
391 if(autocvar_g_pickup_items > 0)
393 if(autocvar_g_pickup_items == 0)
396 if(this.weapons || this.itemdef.instanceOfAmmo) // no item or ammo pickups in weaponarena
403 float Item_Customize()
405 if(this.spawnshieldtime)
407 if(this.weapons & ~other.weapons)
409 this.colormod = '0 0 0';
410 this.glowmod = this.colormod;
411 this.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
418 this.colormod = stov(autocvar_g_ghost_items_color);
419 this.glowmod = this.colormod;
420 this.alpha = g_ghost_items;
429 void Item_Show (entity e, float mode)
431 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
432 e.ItemStatus &= ~ITS_STAYWEP;
433 entity def = e.itemdef;
436 // make the item look normal, and be touchable
438 e.solid = SOLID_TRIGGER;
439 e.spawnshieldtime = 1;
440 e.ItemStatus |= ITS_AVAILABLE;
444 // hide the item completely
445 e.model = string_null;
447 e.spawnshieldtime = 1;
448 e.ItemStatus &= ~ITS_AVAILABLE;
451 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.weapons & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
452 || e.team // weapon stay isn't supported for teamed weapons
454 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
456 // make the item translucent and not touchable
458 e.solid = SOLID_TRIGGER; // can STILL be picked up!
459 e.effects |= EF_STARDUST;
460 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
461 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
465 //setmodel(e, "null");
467 e.colormod = '0 0 0';
468 //e.glowmod = e.colormod;
469 e.spawnshieldtime = 1;
470 e.ItemStatus &= ~ITS_AVAILABLE;
474 e.ItemStatus |= ITS_GLOW;
476 if (autocvar_g_nodepthtestitems)
477 e.effects |= EF_NODEPTHTEST;
480 if (autocvar_g_fullbrightitems)
481 e.ItemStatus |= ITS_ALLOWFB;
483 if (autocvar_sv_simple_items)
484 e.ItemStatus |= ITS_ALLOWSI;
486 // relink entity (because solid may have changed)
487 setorigin(e, e.origin);
488 e.SendFlags |= ISF_STATUS;
491 void Item_Think(entity this)
493 this.nextthink = time;
494 if(this.origin != this.oldorigin)
498 bool Item_ItemsTime_SpectatorOnly(GameItem it);
499 bool Item_ItemsTime_Allow(GameItem it);
500 float Item_ItemsTime_UpdateTime(entity e, float t);
501 void Item_ItemsTime_SetTime(entity e, float t);
502 void Item_ItemsTime_SetTimesForAllPlayers();
504 void Item_Respawn (entity this)
507 sound(this, CH_TRIGGER, this.itemdef.m_respawnsound, VOL_BASE, ATTEN_NORM); // play respawn sound
508 setorigin(this, this.origin);
510 if (Item_ItemsTime_Allow(this.itemdef) || this.weapons & WEPSET_SUPERWEAPONS)
512 float t = Item_ItemsTime_UpdateTime(this, 0);
513 Item_ItemsTime_SetTime(this, t);
514 Item_ItemsTime_SetTimesForAllPlayers();
517 setthink(this, Item_Think);
518 this.nextthink = time;
520 //Send_Effect(EFFECT_ITEM_RESPAWN, this.origin + this.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
521 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
524 void Item_RespawnCountdown (entity this)
526 if(this.count >= ITEM_RESPAWN_TICKS)
528 if(this.waypointsprite_attached)
529 WaypointSprite_Kill(this.waypointsprite_attached);
534 this.nextthink = time + 1;
538 MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0');
541 entity wi = Weapons_from(this.weapon);
542 if (wi != WEP_Null) {
543 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Weapon);
544 wp.wp_extra = wi.m_id;
549 entity ii = this.itemdef;
551 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, this, '0 0 64', NULL, 0, this, waypointsprite_attached, true, RADARICON_Item);
552 wp.wp_extra = ii.m_id;
557 if(this.waypointsprite_attached)
559 GameItem def = this.itemdef;
560 if (Item_ItemsTime_SpectatorOnly(def))
561 WaypointSprite_UpdateRule(this.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
562 WaypointSprite_UpdateBuildFinished(this.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
566 if(this.waypointsprite_attached)
568 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
569 if(this.waypointsprite_attached.waypointsprite_visible_for_player(this.waypointsprite_attached, it, it))
572 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM); // play respawn sound
576 WaypointSprite_Ping(this.waypointsprite_attached);
577 //WaypointSprite_UpdateHealth(this.waypointsprite_attached, this.count);
582 void Item_RespawnThink(entity this)
584 this.nextthink = time;
585 if(this.origin != this.oldorigin)
588 if(time >= this.wait)
592 void Item_ScheduleRespawnIn(entity e, float t)
594 // if the respawn time is longer than 10 seconds, show a waypoint, otherwise, just respawn normally
595 if ((Item_ItemsTime_Allow(e.itemdef) || e.weapons & WEPSET_SUPERWEAPONS) && (t - ITEM_RESPAWN_TICKS) > 0)
597 setthink(e, Item_RespawnCountdown);
598 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
599 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
601 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
602 Item_ItemsTime_SetTime(e, t);
603 Item_ItemsTime_SetTimesForAllPlayers();
607 setthink(e, Item_RespawnThink);
609 e.scheduledrespawntime = time + t;
614 void Item_ScheduleRespawn(entity e)
616 if(e.respawntime > 0)
619 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
621 else // if respawntime is -1, this item does not respawn
625 void Item_ScheduleInitialRespawn(entity e)
628 Item_ScheduleRespawnIn(e, game_starttime - time + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
631 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
633 if (!item.(ammotype))
636 if (item.spawnshieldtime)
638 if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0)
640 player.(ammotype) = bound(player.(ammotype), ammomax, player.(ammotype) + item.(ammotype));
644 else if(g_weapon_stay == 2)
646 float mi = min(item.(ammotype), ammomax);
647 if (player.(ammotype) < mi)
649 player.(ammotype) = mi;
660 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
662 case ITEM_MODE_HEALTH:
663 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
665 case ITEM_MODE_ARMOR:
666 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
674 float Item_GiveTo(entity item, entity player)
678 // if nothing happens to player, just return without taking the item
680 int _switchweapon = 0;
681 // in case the player has autoswitch enabled do the following:
682 // if the player is using their best weapon before items are given, they
683 // probably want to switch to an even better weapon after items are given
685 if(player.autoswitch)
687 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
689 .entity weaponentity = weaponentities[slot];
690 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
692 if(player.(weaponentity).m_switchweapon == w_getbestweapon(player, weaponentity))
693 _switchweapon |= BIT(slot);
695 if(!(player.weapons & WepSet_FromWeapon(player.(weaponentity).m_switchweapon)))
696 _switchweapon |= BIT(slot);
701 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
702 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
703 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
704 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
705 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
706 pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max, ITEM_MODE_NONE);
707 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
708 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
710 if (item.itemdef.instanceOfWeaponPickup)
714 w &= ~player.weapons;
716 if (w || (item.spawnshieldtime && item.pickup_anyway > 0))
719 FOREACH(Weapons, it != WEP_Null, {
720 if(w & (it.m_wepset))
722 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
724 .entity weaponentity = weaponentities[slot];
725 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
726 W_DropEvent(wr_pickup, player, it.m_id, item, weaponentity);
728 W_GiveWeapon(player, it.m_id);
734 if (item.itemdef.instanceOfPowerup)
736 if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
737 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
738 else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
739 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
743 if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
747 Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
750 if (item.strength_finished)
753 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
755 if (item.invincible_finished)
758 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
760 if (item.superweapons_finished)
763 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
768 // always eat teamed entities
775 // crude hack to enforce switching weapons
776 if(g_cts && item.itemdef.instanceOfWeaponPickup)
778 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
780 .entity weaponentity = weaponentities[slot];
781 if(player.(weaponentity).m_weapon != WEP_Null || slot == 0)
782 W_SwitchWeapon_Force(player, Weapons_from(item.weapon), weaponentity);
789 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
791 .entity weaponentity = weaponentities[slot];
792 if(_switchweapon & BIT(slot))
793 if(player.(weaponentity).m_switchweapon != w_getbestweapon(player, weaponentity))
794 W_SwitchWeapon_Force(player, w_getbestweapon(player, weaponentity), weaponentity);
801 void Item_Touch(entity this, entity toucher)
804 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
805 if (this.classname == "droppedweapon")
807 if (ITEM_TOUCH_NEEDKILL())
814 if(!(toucher.flags & FL_PICKUPITEMS)
815 || STAT(FROZEN, toucher)
817 || (this.solid != SOLID_TRIGGER)
818 || (this.owner == toucher)
819 || (time < this.item_spawnshieldtime)
822 switch (MUTATOR_CALLHOOK(ItemTouch, this, toucher))
824 case MUT_ITEMTOUCH_RETURN: { return; }
825 case MUT_ITEMTOUCH_PICKUP: { toucher = M_ARGV(1, entity); goto pickup; }
828 toucher = M_ARGV(1, entity);
830 if (this.classname == "droppedweapon")
832 this.strength_finished = max(0, this.strength_finished - time);
833 this.invincible_finished = max(0, this.invincible_finished - time);
834 this.superweapons_finished = max(0, this.superweapons_finished - time);
836 entity it = this.itemdef;
837 bool gave = ITEM_HANDLE(Pickup, it, this, toucher);
840 if (this.classname == "droppedweapon")
842 // undo what we did above
843 this.strength_finished += time;
844 this.invincible_finished += time;
845 this.superweapons_finished += time;
852 toucher.last_pickup = time;
854 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
855 _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);
857 if (this.classname == "droppedweapon")
859 else if (this.spawnshieldtime)
864 RandomSelection_Init();
865 IL_EACH(g_items, it.team == this.team,
867 if(it.itemdef) // is a registered item
870 RandomSelection_AddEnt(it, it.cnt, 0);
873 e = RandomSelection_chosen_ent;
878 Item_ScheduleRespawn(e);
882 void Item_Reset(entity this)
884 Item_Show(this, !this.state);
885 setorigin(this, this.origin);
887 if (this.classname != "droppedweapon")
889 setthink(this, Item_Think);
890 this.nextthink = time;
892 if (this.waypointsprite_attached)
893 WaypointSprite_Kill(this.waypointsprite_attached);
895 if (this.itemdef.instanceOfPowerup || (this.weapons & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
896 Item_ScheduleInitialRespawn(this);
900 void Item_FindTeam(entity this)
904 if(this.effects & EF_NODRAW)
906 // marker for item team search
907 LOG_TRACE("Initializing item team ", ftos(this.team));
908 RandomSelection_Init();
909 IL_EACH(g_items, it.team == this.team,
911 if(it.itemdef) // is a registered item
912 RandomSelection_AddEnt(it, it.cnt, 0);
915 e = RandomSelection_chosen_ent;
919 IL_EACH(g_items, it.team == this.team,
921 if(it.itemdef) // is a registered item
925 // make it non-spawned
927 it.state = 1; // state 1 = initially hidden item, apparently
929 it.effects &= ~EF_NODRAW;
937 // Savage: used for item garbage-collection
938 void RemoveItem(entity this)
940 if(wasfreed(this) || !this) { return; }
941 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
945 // pickup evaluation functions
946 // these functions decide how desirable an item is to the bots
948 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
950 float weapon_pickupevalfunc(entity player, entity item)
952 // See if I have it already
953 if(player.weapons & item.weapons)
955 // If I can pick it up
956 if(!item.spawnshieldtime)
958 return ammo_pickupevalfunc(player, item);
960 return item.bot_pickupbasevalue;
963 float ammo_pickupevalfunc(entity player, entity item)
965 bool need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
970 // Detect needed ammo
971 if(item.itemdef.instanceOfWeaponPickup)
974 if(item.ammo_shells) { need_shells = true; ammo = ITEM_Shells; }
975 else if(item.ammo_nails) { need_nails = true; ammo = ITEM_Bullets; }
976 else if(item.ammo_rockets) { need_rockets = true; ammo = ITEM_Rockets; }
977 else if(item.ammo_cells) { need_cells = true; ammo = ITEM_Cells; }
978 else if(item.ammo_plasma) { need_plasma = true; ammo = ITEM_Plasma; }
979 else if(item.ammo_fuel) { need_fuel = true; ammo = ITEM_JetpackFuel; }
984 rating = ammo.m_botvalue;
988 FOREACH(Weapons, it != WEP_Null, {
989 if(!(player.weapons & (it.m_wepset)))
992 switch(it.ammo_field)
994 case ammo_shells: need_shells = true; break;
995 case ammo_shells: need_shells = true; break;
996 case ammo_nails: need_nails = true; break;
997 case ammo_rockets: need_rockets = true; break;
998 case ammo_cells: need_cells = true; break;
999 case ammo_plasma: need_plasma = true; break;
1000 case ammo_fuel: need_fuel = true; break;
1003 rating = item.bot_pickupbasevalue;
1007 if (item.ammo_shells)
1008 if (player.ammo_shells < g_pickup_shells_max)
1009 c = (player.ammo_shells + item.ammo_shells) / player.ammo_shells;
1011 if (item.ammo_nails)
1012 if (player.ammo_nails < g_pickup_nails_max)
1013 c = (player.ammo_nails + item.ammo_nails) / player.ammo_nails;
1015 if (item.ammo_rockets)
1016 if (player.ammo_rockets < g_pickup_rockets_max)
1017 c = (player.ammo_rockets + item.ammo_rockets) / player.ammo_rockets;
1019 if (item.ammo_cells)
1020 if (player.ammo_cells < g_pickup_cells_max)
1021 c = (player.ammo_cells + item.ammo_cells) / player.ammo_cells;
1023 if (item.ammo_plasma)
1024 if (player.ammo_plasma < g_pickup_plasma_max)
1025 c = (player.ammo_plasma + item.ammo_plasma) / player.ammo_plasma;
1028 if (player.ammo_fuel < g_pickup_fuel_max)
1029 c = (player.ammo_fuel + item.ammo_fuel) / player.ammo_fuel;
1031 rating *= min(3, c);
1033 // Skilled bots will grab more
1034 rating += wpn.bot_pickupbasevalue * (0.1 + 0.1 * bound(0, skill / 10, 1));
1038 float healtharmor_pickupevalfunc(entity player, entity item)
1041 float rating = item.bot_pickupbasevalue;
1043 if (item.armorvalue)
1044 if (player.armorvalue < item.max_armorvalue)
1045 c = (player.armorvalue + player.health + item.armorvalue) / (max(1, player.armorvalue + player.health));
1047 if (player.health < item.max_health)
1048 c = (player.health + item.health) / (max(1, player.health));
1050 rating *= min(3, c);
1054 void Item_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
1056 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1060 void item_use(entity this, entity actor, entity trigger)
1062 // use the touch function to handle collection
1063 gettouch(this)(this, actor);
1066 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
1068 string itemname = def.m_name;
1069 Model itemmodel = def.m_model;
1070 Sound pickupsound = def.m_sound;
1071 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
1072 float pickupbasevalue = def.m_botvalue;
1073 int itemflags = def.m_itemflags;
1075 startitem_failed = false;
1077 this.item_model_ent = itemmodel;
1078 this.item_pickupsound_ent = pickupsound;
1080 if(!this.respawntime) // both need to be set
1082 this.respawntime = defaultrespawntime;
1083 this.respawntimejitter = defaultrespawntimejitter;
1086 if(!this.pickup_anyway && def.m_pickupanyway)
1087 this.pickup_anyway = def.m_pickupanyway();
1089 int itemid = def.m_itemid;
1090 this.items = itemid;
1091 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
1092 this.weapon = weaponid;
1096 this.fade_start = autocvar_g_items_mindist;
1097 this.fade_end = autocvar_g_items_maxdist;
1101 this.weapons = WepSet_FromWeapon(Weapons_from(weaponid));
1103 this.flags = FL_ITEM | itemflags;
1104 IL_PUSH(g_items, this);
1106 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
1108 startitem_failed = true;
1113 // is it a dropped weapon?
1114 if (this.classname == "droppedweapon")
1116 this.reset = SUB_Remove;
1117 // it's a dropped weapon
1118 set_movetype(this, MOVETYPE_TOSS);
1120 // Savage: remove thrown items after a certain period of time ("garbage collection")
1121 setthink(this, RemoveItem);
1122 this.nextthink = time + 20;
1124 this.takedamage = DAMAGE_YES;
1125 this.event_damage = Item_Damage;
1127 if(this.strength_finished || this.invincible_finished || this.superweapons_finished)
1129 // if item is worthless after a timer, have it expire then
1130 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
1133 // don't drop if in a NODROP zone (such as lava)
1134 traceline(this.origin, this.origin, MOVE_NORMAL, this);
1135 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1137 startitem_failed = true;
1144 if(!have_pickup_item(this))
1146 startitem_failed = true;
1151 if(this.angles != '0 0 0')
1152 this.SendFlags |= ISF_ANGLES;
1154 this.reset = Item_Reset;
1155 // it's a level item
1156 if(this.spawnflags & 1)
1158 if (this.noalign > 0)
1159 set_movetype(this, MOVETYPE_NONE);
1161 set_movetype(this, MOVETYPE_TOSS);
1162 // do item filtering according to game mode and other things
1163 if (this.noalign <= 0)
1165 // first nudge it off the floor a little bit to avoid math errors
1166 setorigin(this, this.origin + '0 0 1');
1167 // set item size before we spawn a spawnfunc_waypoint
1168 setsize(this, def.m_mins, def.m_maxs);
1169 this.SendFlags |= ISF_SIZE;
1170 // note droptofloor returns false if stuck/or would fall too far
1173 waypoint_spawnforitem(this);
1177 * can't do it that way, as it would break maps
1178 * TODO make a target_give like entity another way, that perhaps has
1179 * the weapon name in a key
1182 // target_give not yet supported; maybe later
1183 print("removed targeted ", this.classname, "\n");
1184 startitem_failed = true;
1190 if(this.targetname != "" && (this.spawnflags & 16))
1191 this.use = item_use;
1193 if(autocvar_spawn_debug >= 2)
1195 // why not flags & fl_item?
1196 FOREACH_ENTITY_RADIUS(this.origin, 3, it.is_item, {
1197 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1198 LOG_TRACE(" vs ", it.netname, vtos(it.origin));
1199 error("Mapper sucks.");
1201 this.is_item = true;
1204 weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid));
1206 precache_model(this.model);
1207 precache_sound(this.item_pickupsound);
1209 if ( def.instanceOfPowerup
1210 || def.instanceOfWeaponPickup
1211 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1212 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1213 || (itemid & (IT_KEY1 | IT_KEY2))
1214 ) this.target = "###item###"; // for finding the nearest item using find()
1216 Item_ItemsTime_SetTime(this, 0);
1219 this.bot_pickup = true;
1220 this.bot_pickupevalfunc = pickupevalfunc;
1221 this.bot_pickupbasevalue = pickupbasevalue;
1222 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1223 this.netname = itemname;
1224 settouch(this, Item_Touch);
1225 setmodel(this, MDL_Null); // precision set below
1226 //this.effects |= EF_LOWPRECISION;
1228 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1230 this.SendFlags |= ISF_SIZE;
1232 if (!(this.spawnflags & 1024)) {
1233 if(def.instanceOfPowerup)
1234 this.ItemStatus |= ITS_ANIMATE1;
1236 if(this.armorvalue || this.health)
1237 this.ItemStatus |= ITS_ANIMATE2;
1240 if(def.instanceOfWeaponPickup)
1242 if (this.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1243 this.colormap = 1024; // color shirt=0 pants=0 grey
1246 if (!(this.spawnflags & 1024))
1247 this.ItemStatus |= ITS_ANIMATE1;
1248 this.SendFlags |= ISF_COLORMAP;
1252 if(this.team) // broken, no idea why.
1255 this.cnt = 1; // item probability weight
1257 this.effects |= EF_NODRAW; // marker for item team search
1258 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1263 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1265 // call this hook after everything else has been done
1266 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1268 startitem_failed = true;
1274 void StartItem(entity this, GameItem def)
1279 def.m_respawntime(), // defaultrespawntime
1280 def.m_respawntimejitter() // defaultrespawntimejitter
1284 spawnfunc(item_rockets)
1286 if(!this.ammo_rockets)
1287 this.ammo_rockets = g_pickup_rockets;
1288 StartItem(this, ITEM_Rockets);
1291 spawnfunc(item_bullets)
1294 if(autocvar_sv_q3acompat_machineshotgunswap)
1295 if(this.classname != "droppedweapon")
1297 weaponswapping = true;
1298 spawnfunc_item_shells(this);
1299 weaponswapping = false;
1303 if(!this.ammo_nails)
1304 this.ammo_nails = g_pickup_nails;
1305 StartItem(this, ITEM_Bullets);
1308 spawnfunc(item_cells)
1310 if(!this.ammo_cells)
1311 this.ammo_cells = g_pickup_cells;
1312 StartItem(this, ITEM_Cells);
1315 spawnfunc(item_plasma)
1317 if(!this.ammo_plasma)
1318 this.ammo_plasma = g_pickup_plasma;
1319 StartItem(this, ITEM_Plasma);
1322 spawnfunc(item_shells)
1325 if(autocvar_sv_q3acompat_machineshotgunswap)
1326 if(this.classname != "droppedweapon")
1328 weaponswapping = true;
1329 spawnfunc_item_bullets(this);
1330 weaponswapping = false;
1334 if(!this.ammo_shells)
1335 this.ammo_shells = g_pickup_shells;
1336 StartItem(this, ITEM_Shells);
1339 spawnfunc(item_armor_small)
1341 if(!this.armorvalue)
1342 this.armorvalue = g_pickup_armorsmall;
1343 if(!this.max_armorvalue)
1344 this.max_armorvalue = g_pickup_armorsmall_max;
1345 StartItem(this, ITEM_ArmorSmall);
1348 spawnfunc(item_armor_medium)
1350 if(!this.armorvalue)
1351 this.armorvalue = g_pickup_armormedium;
1352 if(!this.max_armorvalue)
1353 this.max_armorvalue = g_pickup_armormedium_max;
1354 StartItem(this, ITEM_ArmorMedium);
1357 spawnfunc(item_armor_big)
1359 if(!this.armorvalue)
1360 this.armorvalue = g_pickup_armorbig;
1361 if(!this.max_armorvalue)
1362 this.max_armorvalue = g_pickup_armorbig_max;
1363 StartItem(this, ITEM_ArmorBig);
1366 spawnfunc(item_armor_mega)
1368 if(!this.armorvalue)
1369 this.armorvalue = g_pickup_armormega;
1370 if(!this.max_armorvalue)
1371 this.max_armorvalue = g_pickup_armormega_max;
1372 StartItem(this, ITEM_ArmorMega);
1375 spawnfunc(item_health_small)
1377 if(!this.max_health)
1378 this.max_health = g_pickup_healthsmall_max;
1380 this.health = g_pickup_healthsmall;
1381 StartItem(this, ITEM_HealthSmall);
1384 spawnfunc(item_health_medium)
1386 if(!this.max_health)
1387 this.max_health = g_pickup_healthmedium_max;
1389 this.health = g_pickup_healthmedium;
1390 StartItem(this, ITEM_HealthMedium);
1393 spawnfunc(item_health_big)
1395 if(!this.max_health)
1396 this.max_health = g_pickup_healthbig_max;
1398 this.health = g_pickup_healthbig;
1399 StartItem(this, ITEM_HealthBig);
1402 spawnfunc(item_health_mega)
1404 if(!this.max_health)
1405 this.max_health = g_pickup_healthmega_max;
1407 this.health = g_pickup_healthmega;
1408 StartItem(this, ITEM_HealthMega);
1411 // support old misnamed entities
1412 spawnfunc(item_armor1) { spawnfunc_item_armor_small(this); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1413 spawnfunc(item_armor25) { spawnfunc_item_armor_mega(this); }
1414 spawnfunc(item_armor_large) { spawnfunc_item_armor_mega(this); }
1415 spawnfunc(item_health1) { spawnfunc_item_health_small(this); }
1416 spawnfunc(item_health25) { spawnfunc_item_health_medium(this); }
1417 spawnfunc(item_health_large) { spawnfunc_item_health_big(this); }
1418 spawnfunc(item_health100) { spawnfunc_item_health_mega(this); }
1420 spawnfunc(item_strength)
1422 if(!this.strength_finished)
1423 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1424 StartItem(this, ITEM_Strength);
1427 spawnfunc(item_invincible)
1429 if(!this.invincible_finished)
1430 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1431 StartItem(this, ITEM_Shield);
1435 spawnfunc(item_quad) { this.classname = "item_strength";spawnfunc_item_strength(this);}
1437 void target_items_use(entity this, entity actor, entity trigger)
1439 if(actor.classname == "droppedweapon")
1441 EXACTTRIGGER_TOUCH(this, trigger);
1446 if (!IS_PLAYER(actor))
1450 if(trigger.solid == SOLID_TRIGGER)
1452 EXACTTRIGGER_TOUCH(this, trigger);
1455 IL_EACH(g_items, it.enemy == actor && it.classname == "droppedweapon",
1460 if(GiveItems(actor, 0, tokenize_console(this.netname)))
1461 centerprint(actor, this.message);
1464 spawnfunc(target_items)
1469 this.use = target_items_use;
1470 if(!this.strength_finished)
1471 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1472 if(!this.invincible_finished)
1473 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1474 if(!this.superweapons_finished)
1475 this.superweapons_finished = autocvar_g_balance_superweapons_time;
1477 n = tokenize_console(this.netname);
1478 if(argv(0) == "give")
1480 this.netname = substring(this.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1484 for(j = 0; j < n; ++j)
1486 if (argv(j) == "unlimited_ammo") this.items |= IT_UNLIMITED_AMMO;
1487 else if(argv(j) == "unlimited_weapon_ammo") this.items |= IT_UNLIMITED_WEAPON_AMMO;
1488 else if(argv(j) == "unlimited_superweapons") this.items |= IT_UNLIMITED_SUPERWEAPONS;
1489 else if(argv(j) == "strength") this.items |= ITEM_Strength.m_itemid;
1490 else if(argv(j) == "invincible") this.items |= ITEM_Shield.m_itemid;
1491 else if(argv(j) == "superweapons") this.items |= IT_SUPERWEAPON;
1492 else if(argv(j) == "jetpack") this.items |= ITEM_Jetpack.m_itemid;
1493 else if(argv(j) == "fuel_regen") this.items |= ITEM_JetpackRegen.m_itemid;
1496 FOREACH(Weapons, it != WEP_Null, {
1497 s = W_UndeprecateName(argv(j));
1500 this.weapons |= (it.m_wepset);
1501 if(this.spawnflags == 0 || this.spawnflags == 2)
1509 string itemprefix, valueprefix;
1510 if(this.spawnflags == 0)
1515 else if(this.spawnflags == 1)
1517 itemprefix = "max ";
1518 valueprefix = "max ";
1520 else if(this.spawnflags == 2)
1522 itemprefix = "min ";
1523 valueprefix = "min ";
1525 else if(this.spawnflags == 4)
1527 itemprefix = "minus ";
1528 valueprefix = "max ";
1532 error("invalid spawnflags");
1533 itemprefix = valueprefix = string_null;
1537 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1538 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1539 this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.strength_finished * boolean(this.items & ITEM_Strength.m_itemid), "strength");
1540 this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.invincible_finished * boolean(this.items & ITEM_Shield.m_itemid), "invincible");
1541 this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, this.superweapons_finished * boolean(this.items & IT_SUPERWEAPON), "superweapons");
1542 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_Jetpack.m_itemid), "jetpack");
1543 this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, boolean(this.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1544 if(this.ammo_shells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_shells), "shells");
1545 if(this.ammo_nails != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_nails), "nails");
1546 if(this.ammo_rockets != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_rockets), "rockets");
1547 if(this.ammo_cells != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_cells), "cells");
1548 if(this.ammo_plasma != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_plasma), "plasma");
1549 if(this.ammo_fuel != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.ammo_fuel), "fuel");
1550 if(this.health != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.health), "health");
1551 if(this.armorvalue != 0) this.netname = sprintf("%s %s%d %s", this.netname, valueprefix, max(0, this.armorvalue), "armor");
1552 FOREACH(Weapons, it != WEP_Null, this.netname = sprintf("%s %s%d %s", this.netname, itemprefix, !!(this.weapons & (it.m_wepset)), it.netname));
1554 this.netname = strzone(this.netname);
1555 //print(this.netname, "\n");
1557 n = tokenize_console(this.netname);
1558 for(j = 0; j < n; ++j)
1560 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(argv(j)) == it.netname, {
1567 spawnfunc(item_fuel)
1570 this.ammo_fuel = g_pickup_fuel;
1571 StartItem(this, ITEM_JetpackFuel);
1574 spawnfunc(item_fuel_regen)
1576 if(start_items & ITEM_JetpackRegen.m_itemid)
1578 spawnfunc_item_fuel(this);
1581 StartItem(this, ITEM_JetpackRegen);
1584 spawnfunc(item_jetpack)
1587 this.ammo_fuel = g_pickup_fuel_jetpack;
1588 if(start_items & ITEM_Jetpack.m_itemid)
1590 spawnfunc_item_fuel(this);
1593 StartItem(this, ITEM_Jetpack);
1596 float GiveWeapon(entity e, float wpn, float op, float val)
1599 WepSet s = WepSet_FromWeapon(Weapons_from(wpn));
1600 v0 = (e.weapons & s);
1623 v1 = (e.weapons & s);
1627 void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
1633 if(snd_decr != NULL)
1634 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1636 else if(v0 >= v0 + t)
1638 if(snd_incr != NULL)
1639 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1643 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1646 e.(rotfield) = max(e.(rotfield), time + rottime);
1648 e.(regenfield) = max(e.(regenfield), time + regentime);
1650 float GiveItems(entity e, float beginarg, float endarg)
1652 float got, i, val, op;
1660 int _switchweapon = 0;
1664 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1666 .entity weaponentity = weaponentities[slot];
1667 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1668 if(e.(weaponentity).m_switchweapon == w_getbestweapon(e, weaponentity))
1669 _switchweapon |= BIT(slot);
1673 e.strength_finished = max(0, e.strength_finished - time);
1674 e.invincible_finished = max(0, e.invincible_finished - time);
1675 e.superweapons_finished = max(0, e.superweapons_finished - time);
1679 PREGIVE(e, strength_finished);
1680 PREGIVE(e, invincible_finished);
1681 PREGIVE(e, superweapons_finished);
1682 PREGIVE(e, ammo_nails);
1683 PREGIVE(e, ammo_cells);
1684 PREGIVE(e, ammo_plasma);
1685 PREGIVE(e, ammo_shells);
1686 PREGIVE(e, ammo_rockets);
1687 PREGIVE(e, ammo_fuel);
1688 PREGIVE(e, armorvalue);
1691 for(i = beginarg; i < endarg; ++i)
1695 if(cmd == "0" || stof(cmd))
1719 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1720 got += GiveValue(e, strength_finished, op, val);
1721 got += GiveValue(e, invincible_finished, op, val);
1722 got += GiveValue(e, superweapons_finished, op, val);
1723 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1725 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1726 got += GiveValue(e, health, op, val);
1727 got += GiveValue(e, armorvalue, op, val);
1729 FOREACH(Weapons, it != WEP_Null && !(it.spawnflags & WEP_FLAG_MUTATORBLOCKED), got += GiveWeapon(e, it.m_id, op, val));
1731 got += GiveValue(e, ammo_cells, op, val);
1732 got += GiveValue(e, ammo_plasma, op, val);
1733 got += GiveValue(e, ammo_shells, op, val);
1734 got += GiveValue(e, ammo_nails, op, val);
1735 got += GiveValue(e, ammo_rockets, op, val);
1736 got += GiveValue(e, ammo_fuel, op, val);
1738 case "unlimited_ammo":
1739 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1741 case "unlimited_weapon_ammo":
1742 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1744 case "unlimited_superweapons":
1745 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1748 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1751 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1754 got += GiveValue(e, strength_finished, op, val);
1757 got += GiveValue(e, invincible_finished, op, val);
1759 case "superweapons":
1760 got += GiveValue(e, superweapons_finished, op, val);
1763 got += GiveValue(e, ammo_cells, op, val);
1766 got += GiveValue(e, ammo_plasma, op, val);
1769 got += GiveValue(e, ammo_shells, op, val);
1773 got += GiveValue(e, ammo_nails, op, val);
1776 got += GiveValue(e, ammo_rockets, op, val);
1779 got += GiveValue(e, health, op, val);
1782 got += GiveValue(e, armorvalue, op, val);
1785 got += GiveValue(e, ammo_fuel, op, val);
1788 FOREACH(Weapons, it != WEP_Null && W_UndeprecateName(cmd) == it.netname, {
1789 got += GiveWeapon(e, it.m_id, op, val);
1798 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
1799 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
1800 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND_POWERUP, SND_POWEROFF);
1801 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
1802 FOREACH(Weapons, it != WEP_Null, {
1803 POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
1804 if(!(save_weapons & (it.m_wepset)))
1805 if(e.weapons & (it.m_wepset))
1808 POSTGIVE_VALUE(e, strength_finished, 1, SND_POWERUP, SND_POWEROFF);
1809 POSTGIVE_VALUE(e, invincible_finished, 1, SND_Shield, SND_POWEROFF);
1810 //POSTGIVE_VALUE(e, superweapons_finished, 1, SND_Null, SND_Null);
1811 POSTGIVE_VALUE(e, ammo_nails, 0, SND_ITEMPICKUP, SND_Null);
1812 POSTGIVE_VALUE(e, ammo_cells, 0, SND_ITEMPICKUP, SND_Null);
1813 POSTGIVE_VALUE(e, ammo_plasma, 0, SND_ITEMPICKUP, SND_Null);
1814 POSTGIVE_VALUE(e, ammo_shells, 0, SND_ITEMPICKUP, SND_Null);
1815 POSTGIVE_VALUE(e, ammo_rockets, 0, SND_ITEMPICKUP, SND_Null);
1816 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);
1817 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);
1818 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);
1820 if(e.superweapons_finished <= 0)
1821 if(e.weapons & WEPSET_SUPERWEAPONS)
1822 e.superweapons_finished = autocvar_g_balance_superweapons_time;
1824 if(e.strength_finished <= 0)
1825 e.strength_finished = 0;
1827 e.strength_finished += time;
1828 if(e.invincible_finished <= 0)
1829 e.invincible_finished = 0;
1831 e.invincible_finished += time;
1832 if(e.superweapons_finished <= 0)
1833 e.superweapons_finished = 0;
1835 e.superweapons_finished += time;
1837 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1839 .entity weaponentity = weaponentities[slot];
1840 if(e.(weaponentity).m_weapon != WEP_Null || slot == 0)
1841 if(!(e.weapons & WepSet_FromWeapon(e.(weaponentity).m_switchweapon)))
1842 _switchweapon |= BIT(slot);
1847 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
1849 .entity weaponentity = weaponentities[slot];
1850 if(_switchweapon & BIT(slot))
1851 W_SwitchWeapon_Force(e, w_getbestweapon(e, weaponentity), weaponentity);