3 #include "../common/items/all.qc"
8 #include "bot/waypoints.qh"
10 #include "mutators/all.qh"
12 #include "weapons/common.qh"
13 #include "weapons/selection.qh"
14 #include "weapons/weaponsystem.qh"
16 #include "../common/constants.qh"
17 #include "../common/deathtypes/all.qh"
18 #include "../common/notifications.qh"
19 #include "../common/triggers/subs.qh"
20 #include "../common/util.qh"
22 #include "../common/monsters/all.qh"
24 #include "../common/weapons/all.qh"
26 #include "../lib/warpzone/util_server.qh"
29 REGISTER_NET_LINKED(ENT_CLIENT_ITEM)
32 void ItemDraw(entity self)
36 Movetype_Physics_MatchServer(self, autocvar_cl_projectiles_sloppy);
37 if(self.move_flags & FL_ONGROUND)
38 { // For some reason move_avelocity gets set to '0 0 0' here ...
39 self.oldorigin = self.origin;
42 if(autocvar_cl_animate_items)
43 { // ... so reset it if animations are requested.
44 if(self.ItemStatus & ITS_ANIMATE1)
45 self.move_avelocity = '0 180 0';
47 if(self.ItemStatus & ITS_ANIMATE2)
48 self.move_avelocity = '0 -90 0';
52 else if (autocvar_cl_animate_items)
54 if(self.ItemStatus & ITS_ANIMATE1)
56 self.angles += self.move_avelocity * frametime;
57 setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));
60 if(self.ItemStatus & ITS_ANIMATE2)
62 self.angles += self.move_avelocity * frametime;
63 setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));
68 void ItemDrawSimple(entity this)
72 Movetype_Physics_MatchServer(self, autocvar_cl_projectiles_sloppy);
74 if(self.move_flags & FL_ONGROUND)
83 org = getpropertyvec(VF_ORIGIN);
84 if(!checkpvs(org, self)) // this makes sense as long as we don't support recursive warpzones
86 else if(self.fade_start)
87 alph = bound(0, (self.fade_end - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) / (self.fade_end - self.fade_start), 1);
90 //printf("%v <-> %v\n", view_origin, self.origin + 0.5 * (self.mins + self.maxs));
91 if(self.ItemStatus & ITS_AVAILABLE)
96 self.drawmask = MASK_NORMAL;
105 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
109 if(sf & ISF_LOCATION)
111 self.origin_x = ReadCoord();
112 self.origin_y = ReadCoord();
113 self.origin_z = ReadCoord();
114 setorigin(self, self.origin);
115 self.oldorigin = self.origin;
120 self.angles_x = ReadAngle();
121 self.angles_y = ReadAngle();
122 self.angles_z = ReadAngle();
123 self.move_angles = self.angles;
128 float use_bigsize = ReadByte();
129 setsize(self, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
132 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
134 self.ItemStatus = ReadByte();
136 if(self.ItemStatus & ITS_AVAILABLE)
139 self.colormod = self.glowmod = '1 1 1';
143 if (autocvar_cl_ghost_items_color)
145 self.alpha = autocvar_cl_ghost_items;
146 self.colormod = self.glowmod = autocvar_cl_ghost_items_color;
152 if(autocvar_cl_fullbright_items)
153 if(self.ItemStatus & ITS_ALLOWFB)
154 self.effects |= EF_FULLBRIGHT;
156 if(self.ItemStatus & ITS_STAYWEP)
158 self.colormod = self.glowmod = autocvar_cl_weapon_stay_color;
159 self.alpha = autocvar_cl_weapon_stay_alpha;
163 if(self.ItemStatus & ITS_POWERUP)
165 if(self.ItemStatus & ITS_AVAILABLE)
166 self.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
168 self.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
174 self.drawmask = MASK_NORMAL;
175 self.move_movetype = self.movetype = MOVETYPE_TOSS;
176 self.draw = ItemDraw;
177 //self.move_flags |= FL_ITEM;
179 bool use_bigsize = ReadByte();
181 self.fade_end = ReadShort();
182 self.fade_start = ReadShort();
183 if(self.fade_start && !autocvar_cl_items_nofade)
184 self.predraw = Item_PreDraw;
190 string _fn = ReadString();
192 if(autocvar_cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
194 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
195 self.draw = ItemDrawSimple;
197 if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
198 self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
199 else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
200 self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
201 else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
202 self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
203 else if(fexists(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix)))
204 self.mdl = strzone(sprintf("%s%s.mdl", _fn2, autocvar_cl_simpleitems_postfix));
207 self.draw = ItemDraw;
208 LOG_TRACE("Simple item requested for ", _fn, " but no model exists for it\n");
212 if(self.draw != ItemDrawSimple)
213 self.mdl = strzone(_fn);
217 LOG_TRACE("^1WARNING!^7 self.mdl is unset for item ", self.classname, " tell tZork aboute this!\n");
219 precache_model(self.mdl);
220 _setmodel(self, self.mdl);
222 setsize(self, '-16 -16 0', (use_bigsize) ? '16 16 48' : '16 16 32');
225 if(sf & ISF_COLORMAP)
226 self.colormap = ReadShort();
231 //self.move_angles = '0 0 0';
232 self.move_movetype = MOVETYPE_TOSS;
233 self.move_velocity_x = ReadCoord();
234 self.move_velocity_y = ReadCoord();
235 self.move_velocity_z = ReadCoord();
236 self.velocity = self.move_velocity;
237 self.move_origin = self.oldorigin;
241 self.move_time = time;
242 self.spawntime = time;
245 self.move_time = max(self.move_time, time);
248 if(autocvar_cl_animate_items)
250 if(self.ItemStatus & ITS_ANIMATE1)
251 self.move_avelocity = '0 180 0';
253 if(self.ItemStatus & ITS_ANIMATE2)
254 self.move_avelocity = '0 -90 0';
257 self.entremove = ItemRemove;
265 bool ItemSend(entity this, entity to, int sf)
272 WriteHeader(MSG_ENTITY, ENT_CLIENT_ITEM);
273 WriteByte(MSG_ENTITY, sf);
275 //WriteByte(MSG_ENTITY, self.cnt);
276 if(sf & ISF_LOCATION)
278 WriteCoord(MSG_ENTITY, self.origin.x);
279 WriteCoord(MSG_ENTITY, self.origin.y);
280 WriteCoord(MSG_ENTITY, self.origin.z);
285 WriteAngle(MSG_ENTITY, self.angles_x);
286 WriteAngle(MSG_ENTITY, self.angles_y);
287 WriteAngle(MSG_ENTITY, self.angles_z);
292 Pickup p = this.itemdef;
293 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
297 WriteByte(MSG_ENTITY, self.ItemStatus);
301 Pickup p = this.itemdef;
302 WriteByte(MSG_ENTITY, p.instanceOfPowerup || p.instanceOfHealth || p.instanceOfArmor);
303 WriteShort(MSG_ENTITY, self.fade_end);
304 WriteShort(MSG_ENTITY, self.fade_start);
307 LOG_TRACE("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n");
309 WriteString(MSG_ENTITY, self.mdl);
313 if(sf & ISF_COLORMAP)
314 WriteShort(MSG_ENTITY, self.colormap);
318 WriteCoord(MSG_ENTITY, self.velocity.x);
319 WriteCoord(MSG_ENTITY, self.velocity.y);
320 WriteCoord(MSG_ENTITY, self.velocity.z);
326 void ItemUpdate(entity this)
328 this.oldorigin = this.origin;
329 this.SendFlags |= ISF_LOCATION;
332 void UpdateItemAfterTeleport(entity this)
334 if(this.SendEntity3 == ItemSend)
338 bool have_pickup_item(entity this)
340 if(this.itemdef.instanceOfPowerup)
342 if(autocvar_g_powerups > 0)
344 if(autocvar_g_powerups == 0)
349 if(autocvar_g_pickup_items > 0)
351 if(autocvar_g_pickup_items == 0)
354 if(this.weapons || (this.items & IT_AMMO)) // no item or ammo pickups in weaponarena
361 float Item_Customize()
363 if(self.spawnshieldtime)
365 if(self.weapons & ~other.weapons)
367 self.colormod = '0 0 0';
368 self.glowmod = self.colormod;
369 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
376 self.colormod = stov(autocvar_g_ghost_items_color);
377 self.glowmod = self.colormod;
378 self.alpha = g_ghost_items;
387 void Item_Show (entity e, float mode)
389 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
390 e.ItemStatus &= ~ITS_STAYWEP;
393 // make the item look normal, and be touchable
395 e.solid = SOLID_TRIGGER;
396 e.spawnshieldtime = 1;
397 e.ItemStatus |= ITS_AVAILABLE;
401 // hide the item completely
402 e.model = string_null;
404 e.spawnshieldtime = 1;
405 e.ItemStatus &= ~ITS_AVAILABLE;
408 entity def = e.itemdef;
409 bool nostay = def.instanceOfWeaponPickup ? !!(def.m_weapon.weapons & WEPSET_SUPERWEAPONS) : false // no weapon-stay on superweapons
410 || e.team // weapon stay isn't supported for teamed weapons
412 if(def.instanceOfWeaponPickup && !nostay && g_weapon_stay)
414 // make the item translucent and not touchable
416 e.solid = SOLID_TRIGGER; // can STILL be picked up!
417 e.effects |= EF_STARDUST;
418 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
419 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
423 //setmodel(e, "null");
425 e.colormod = '0 0 0';
426 e.glowmod = e.colormod;
427 e.spawnshieldtime = 1;
428 e.ItemStatus &= ~ITS_AVAILABLE;
431 if (e.items & ITEM_Strength.m_itemid || e.items & ITEM_Shield.m_itemid)
432 e.ItemStatus |= ITS_POWERUP;
434 if (autocvar_g_nodepthtestitems)
435 e.effects |= EF_NODEPTHTEST;
438 if (autocvar_g_fullbrightitems)
439 e.ItemStatus |= ITS_ALLOWFB;
441 if (autocvar_sv_simple_items)
442 e.ItemStatus |= ITS_ALLOWSI;
444 // relink entity (because solid may have changed)
445 setorigin(e, e.origin);
446 e.SendFlags |= ISF_STATUS;
451 self.nextthink = time;
452 if(self.origin != self.oldorigin)
456 bool Item_ItemsTime_SpectatorOnly(GameItem it);
457 bool Item_ItemsTime_Allow(GameItem it, WepSet _weapons);
458 float Item_ItemsTime_UpdateTime(entity e, float t);
459 void Item_ItemsTime_SetTime(entity e, float t);
460 void Item_ItemsTime_SetTimesForAllPlayers();
466 if(self.items == ITEM_Strength.m_itemid)
467 sound (self, CH_TRIGGER, SND_STRENGTH_RESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
468 else if(self.items == ITEM_Shield.m_itemid)
469 sound (self, CH_TRIGGER, SND_SHIELD_RESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
471 sound (self, CH_TRIGGER, SND_ITEMRESPAWN, VOL_BASE, ATTEN_NORM); // play respawn sound
472 setorigin (self, self.origin);
474 if (Item_ItemsTime_Allow(self.itemdef, self.weapons))
476 float t = Item_ItemsTime_UpdateTime(self, 0);
477 Item_ItemsTime_SetTime(self, t);
478 Item_ItemsTime_SetTimesForAllPlayers();
481 self.think = Item_Think;
482 self.nextthink = time;
484 //Send_Effect(EFFECT_ITEM_RESPAWN, self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
485 Send_Effect(EFFECT_ITEM_RESPAWN, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
488 void Item_RespawnCountdown ()
490 if(self.count >= ITEM_RESPAWN_TICKS)
492 if(self.waypointsprite_attached)
493 WaypointSprite_Kill(self.waypointsprite_attached);
498 self.nextthink = time + 1;
502 MUTATOR_CALLHOOK(Item_RespawnCountdown, string_null, '0 0 0');
505 entity wi = Weapons_from(self.weapon);
506 if (wi != WEP_Null) {
507 entity wp = WaypointSprite_Spawn(WP_Weapon, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Weapon);
508 wp.wp_extra = wi.m_id;
513 entity ii = self.itemdef;
515 entity wp = WaypointSprite_Spawn(WP_Item, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_Item);
516 wp.wp_extra = ii.m_id;
521 if(self.waypointsprite_attached)
523 GameItem def = self.itemdef;
524 if (Item_ItemsTime_SpectatorOnly(def))
525 WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
526 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
530 if(self.waypointsprite_attached)
532 setself(self.waypointsprite_attached);
534 FOR_EACH_REALCLIENT(e)
535 if(self.waypointsprite_visible_for_player(e))
538 soundto(MSG_ONE, this, CH_TRIGGER, SND(ITEMRESPAWNCOUNTDOWN), VOL_BASE, ATTEN_NORM); // play respawn sound
542 WaypointSprite_Ping(self.waypointsprite_attached);
543 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
548 void Item_RespawnThink()
550 self.nextthink = time;
551 if(self.origin != self.oldorigin)
554 if(time >= self.wait)
558 void Item_ScheduleRespawnIn(entity e, float t)
560 if (Item_ItemsTime_Allow(e.itemdef, e.weapons))
562 e.think = Item_RespawnCountdown;
563 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
564 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
566 t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
567 Item_ItemsTime_SetTime(e, t);
568 Item_ItemsTime_SetTimesForAllPlayers();
572 e.think = Item_RespawnThink;
574 e.scheduledrespawntime = time + t;
579 void Item_ScheduleRespawn(entity e)
581 if(e.respawntime > 0)
584 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
586 else // if respawntime is -1, this item does not respawn
590 void Item_ScheduleInitialRespawn(entity e)
593 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
596 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
598 if (!item.(ammotype))
601 if (item.spawnshieldtime)
603 if ((player.(ammotype) < ammomax) || item.pickup_anyway > 0)
605 player.(ammotype) = bound(player.(ammotype), ammomax, player.(ammotype) + item.(ammotype));
609 else if(g_weapon_stay == 2)
611 float mi = min(item.(ammotype), ammomax);
612 if (player.(ammotype) < mi)
614 player.(ammotype) = mi;
625 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
627 case ITEM_MODE_HEALTH:
628 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
630 case ITEM_MODE_ARMOR:
631 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
639 float Item_GiveTo(entity item, entity player)
646 // if nothing happens to player, just return without taking the item
648 _switchweapon = false;
649 // in case the player has autoswitch enabled do the following:
650 // if the player is using their best weapon before items are given, they
651 // probably want to switch to an even better weapon after items are given
652 if (player.autoswitch)
653 if (PS(player).m_switchweapon == w_getbestweapon(player))
654 _switchweapon = true;
656 if (!(player.weapons & WepSet_FromWeapon(PS(player).m_switchweapon)))
657 _switchweapon = true;
659 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
660 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
661 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
662 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
663 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
664 pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max, ITEM_MODE_NONE);
665 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
666 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
668 if (item.itemdef.instanceOfWeaponPickup)
672 it &= ~player.weapons;
674 if (it || (item.spawnshieldtime && item.pickup_anyway > 0))
677 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
678 if(it & WepSet_FromWeapon(Weapons_from(i)))
680 W_DropEvent(wr_pickup, player, i, item);
681 W_GiveWeapon(player, i);
686 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
690 Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
693 if (item.strength_finished)
696 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
698 if (item.invincible_finished)
701 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
703 if (item.superweapons_finished)
706 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
711 // always eat teamed entities
718 // crude hack to enforce switching weapons
719 if(g_cts && item.itemdef.instanceOfWeaponPickup)
721 W_SwitchWeapon_Force(player, Weapons_from(item.weapon));
726 if (PS(player).m_switchweapon != w_getbestweapon(player))
727 W_SwitchWeapon_Force(player, w_getbestweapon(player));
736 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
737 if (this.classname == "droppedweapon")
739 if (ITEM_TOUCH_NEEDKILL())
746 if(!(other.flags & FL_PICKUPITEMS)
749 || (this.solid != SOLID_TRIGGER)
750 || (this.owner == other)
751 || (time < this.item_spawnshieldtime)
754 switch (MUTATOR_CALLHOOK(ItemTouch, this, other))
756 case MUT_ITEMTOUCH_RETURN: { return; }
757 case MUT_ITEMTOUCH_PICKUP: { goto pickup; }
760 if (this.classname == "droppedweapon")
762 this.strength_finished = max(0, this.strength_finished - time);
763 this.invincible_finished = max(0, this.invincible_finished - time);
764 this.superweapons_finished = max(0, this.superweapons_finished - time);
766 entity it = this.itemdef;
767 bool gave = ITEM_HANDLE(Pickup, it, this, other);
770 if (this.classname == "droppedweapon")
772 // undo what we did above
773 this.strength_finished += time;
774 this.invincible_finished += time;
775 this.superweapons_finished += time;
782 other.last_pickup = time;
784 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(this), '0 0 0', 1);
785 _sound (other, CH_TRIGGER, (this.item_pickupsound ? this.item_pickupsound : Sound_fixpath(this.item_pickupsound_ent)), VOL_BASE, ATTEN_NORM);
787 if (this.classname == "droppedweapon")
789 else if (this.spawnshieldtime)
794 RandomSelection_Init();
795 for(entity head = world; (head = findfloat(head, team, this.team)); )
797 if(head.flags & FL_ITEM)
798 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
801 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
804 e = RandomSelection_chosen_ent;
809 Item_ScheduleRespawn(e);
813 void Item_Reset(entity this)
815 Item_Show(this, !this.state);
816 setorigin(this, this.origin);
818 if (this.classname != "droppedweapon")
820 this.think = Item_Think;
821 this.nextthink = time;
823 if (this.waypointsprite_attached)
824 WaypointSprite_Kill(this.waypointsprite_attached);
826 if (this.itemdef.instanceOfPowerup || (this.weapons & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
827 Item_ScheduleInitialRespawn(this);
830 void Item_Reset_self() { SELFPARAM(); Item_Reset(this); }
836 if(self.effects & EF_NODRAW)
838 // marker for item team search
839 LOG_TRACE("Initializing item team ", ftos(self.team), "\n");
840 RandomSelection_Init();
841 for(head = world; (head = findfloat(head, team, self.team)); )
842 if(head.flags & FL_ITEM)
843 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
844 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
845 e = RandomSelection_chosen_ent;
849 for(head = world; (head = findfloat(head, team, self.team)); )
850 if(head.flags & FL_ITEM)
851 if(head.classname != "item_flag_team" && head.classname != "item_key_team")
855 // make it a non-spawned item
857 head.state = 1; // state 1 = initially hidden item
859 head.effects &= ~EF_NODRAW;
866 // Savage: used for item garbage-collection
867 // TODO: perhaps nice special effect?
870 if(wasfreed(self) || !self) { return; }
871 Send_Effect(EFFECT_ITEM_PICKUP, CENTER_OR_VIEWOFS(self), '0 0 0', 1);
875 // pickup evaluation functions
876 // these functions decide how desirable an item is to the bots
878 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
880 float weapon_pickupevalfunc(entity player, entity item)
884 // See if I have it already
885 if(item.weapons & ~player.weapons)
887 // If I can pick it up
888 if(!item.spawnshieldtime)
890 else if(player.ammo_cells || player.ammo_shells || player.ammo_plasma || player.ammo_nails || player.ammo_rockets)
892 // Skilled bots will grab more
893 c = bound(0, skill / 10, 1) * 0.5;
901 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
902 if( bot_custom_weapon && c )
904 // Find the highest position on any range
906 for (int j = 0; j < WEP_LAST ; ++j){
908 bot_weapons_far[j] == item.weapon ||
909 bot_weapons_mid[j] == item.weapon ||
910 bot_weapons_close[j] == item.weapon
921 position = WEP_LAST - position;
922 // item.bot_pickupbasevalue is overwritten here
923 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
927 return item.bot_pickupbasevalue * c;
930 float commodity_pickupevalfunc(entity player, entity item)
933 float need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
937 // Detect needed ammo
938 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
940 wi = Weapons_from(i);
942 if (!(player.weapons & (wi.m_wepset)))
945 if(wi.items & ITEM_Shells.m_itemid)
947 else if(wi.items & ITEM_Bullets.m_itemid)
949 else if(wi.items & ITEM_Rockets.m_itemid)
951 else if(wi.items & ITEM_Cells.m_itemid)
953 else if(wi.items & ITEM_Plasma.m_itemid)
955 else if(wi.items & ITEM_JetpackFuel.m_itemid)
959 // TODO: figure out if the player even has the weapon this ammo is for?
960 // may not affect strategy much though...
961 // find out how much more ammo/armor/health the player can hold
963 if (item.ammo_shells)
964 if (player.ammo_shells < g_pickup_shells_max)
965 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
968 if (player.ammo_nails < g_pickup_nails_max)
969 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
971 if (item.ammo_rockets)
972 if (player.ammo_rockets < g_pickup_rockets_max)
973 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
976 if (player.ammo_cells < g_pickup_cells_max)
977 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
979 if (item.ammo_plasma)
980 if (player.ammo_plasma < g_pickup_plasma_max)
981 c = c + max(0, 1 - player.ammo_plasma / g_pickup_plasma_max);
984 if (player.ammo_fuel < g_pickup_fuel_max)
985 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
987 if (player.armorvalue < item.max_armorvalue)
988 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
990 if (player.health < item.max_health)
991 c = c + max(0, 1 - player.health / item.max_health);
993 return item.bot_pickupbasevalue * c;
996 void Item_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
998 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1002 void _StartItem(entity this, entity def, float defaultrespawntime, float defaultrespawntimejitter)
1004 string itemname = def.m_name;
1005 Model itemmodel = def.m_model;
1006 Sound pickupsound = def.m_sound;
1007 float(entity player, entity item) pickupevalfunc = def.m_pickupevalfunc;
1008 float pickupbasevalue = def.m_botvalue;
1009 int itemflags = def.m_itemflags;
1011 startitem_failed = false;
1013 this.item_model_ent = itemmodel;
1014 this.item_pickupsound_ent = pickupsound;
1016 if(!this.respawntime) // both need to be set
1018 this.respawntime = defaultrespawntime;
1019 this.respawntimejitter = defaultrespawntimejitter;
1022 int itemid = def.m_itemid;
1023 this.items = itemid;
1024 int weaponid = def.instanceOfWeaponPickup ? def.m_weapon.m_id : 0;
1025 this.weapon = weaponid;
1029 this.fade_start = autocvar_g_items_mindist;
1030 this.fade_end = autocvar_g_items_maxdist;
1034 this.weapons = WepSet_FromWeapon(Weapons_from(weaponid));
1036 this.flags = FL_ITEM | itemflags;
1038 if(MUTATOR_CALLHOOK(FilterItem, this)) // error means we do not want the item
1040 startitem_failed = true;
1045 // is it a dropped weapon?
1046 if (this.classname == "droppedweapon")
1048 this.reset = SUB_Remove;
1049 // it's a dropped weapon
1050 this.movetype = MOVETYPE_TOSS;
1052 // Savage: remove thrown items after a certain period of time ("garbage collection")
1053 this.think = RemoveItem;
1054 this.nextthink = time + 20;
1056 this.takedamage = DAMAGE_YES;
1057 this.event_damage = Item_Damage;
1059 if(this.strength_finished || this.invincible_finished || this.superweapons_finished)
1061 // if item is worthless after a timer, have it expire then
1062 this.nextthink = max(this.strength_finished, this.invincible_finished, this.superweapons_finished);
1065 // don't drop if in a NODROP zone (such as lava)
1066 traceline(this.origin, this.origin, MOVE_NORMAL, this);
1067 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1069 startitem_failed = true;
1076 if(!have_pickup_item(this))
1078 startitem_failed = true;
1083 if(this.angles != '0 0 0')
1084 this.SendFlags |= ISF_ANGLES;
1086 this.reset = Item_Reset;
1087 // it's a level item
1088 if(this.spawnflags & 1)
1090 if (this.noalign > 0)
1091 this.movetype = MOVETYPE_NONE;
1093 this.movetype = MOVETYPE_TOSS;
1094 // do item filtering according to game mode and other things
1095 if (this.noalign <= 0)
1097 // first nudge it off the floor a little bit to avoid math errors
1098 setorigin(this, this.origin + '0 0 1');
1099 // set item size before we spawn a spawnfunc_waypoint
1100 setsize(this, def.m_mins, def.m_maxs);
1101 this.SendFlags |= ISF_SIZE;
1102 // note droptofloor returns false if stuck/or would fall too far
1104 WITH(entity, self, this, droptofloor());
1105 waypoint_spawnforitem(this);
1109 * can't do it that way, as it would break maps
1110 * TODO make a target_give like entity another way, that perhaps has
1111 * the weapon name in a key
1114 // target_give not yet supported; maybe later
1115 print("removed targeted ", this.classname, "\n");
1116 startitem_failed = true;
1122 if(autocvar_spawn_debug >= 2)
1124 for(entity otheritem = findradius(this.origin, 3); otheritem; otheritem = otheritem.chain)
1126 // why not flags & fl_item?
1127 if(otheritem.is_item)
1129 LOG_TRACE("XXX Found duplicated item: ", itemname, vtos(this.origin));
1130 LOG_TRACE(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1131 error("Mapper sucks.");
1134 this.is_item = true;
1137 weaponsInMap |= WepSet_FromWeapon(Weapons_from(weaponid));
1139 precache_model(this.model);
1140 precache_sound(this.item_pickupsound);
1142 if ( def.instanceOfPowerup
1143 || def.instanceOfWeaponPickup
1144 || (def.instanceOfHealth && def != ITEM_HealthSmall)
1145 || (def.instanceOfArmor && def != ITEM_ArmorSmall)
1146 || (itemid & (IT_KEY1 | IT_KEY2))
1147 ) this.target = "###item###"; // for finding the nearest item using find()
1149 Item_ItemsTime_SetTime(this, 0);
1152 this.bot_pickup = true;
1153 this.bot_pickupevalfunc = pickupevalfunc;
1154 this.bot_pickupbasevalue = pickupbasevalue;
1155 this.mdl = this.model ? this.model : strzone(this.item_model_ent.model_str());
1156 this.netname = itemname;
1157 this.touch = Item_Touch;
1158 setmodel(this, MDL_Null); // precision set below
1159 //this.effects |= EF_LOWPRECISION;
1161 setsize (this, this.pos1 = def.m_mins, this.pos2 = def.m_maxs);
1163 this.SendFlags |= ISF_SIZE;
1165 if (!(this.spawnflags & 1024)) {
1166 if(def.instanceOfPowerup)
1167 this.ItemStatus |= ITS_ANIMATE1;
1169 if(this.armorvalue || this.health)
1170 this.ItemStatus |= ITS_ANIMATE2;
1173 if(def.instanceOfWeaponPickup)
1175 if (this.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1176 this.colormap = 1024; // color shirt=0 pants=0 grey
1179 if (!(this.spawnflags & 1024))
1180 this.ItemStatus |= ITS_ANIMATE1;
1181 this.ItemStatus |= ISF_COLORMAP;
1185 if(this.team) // broken, no idea why.
1188 this.cnt = 1; // item probability weight
1190 this.effects |= EF_NODRAW; // marker for item team search
1191 InitializeEntity(this, Item_FindTeam, INITPRIO_FINDTARGET);
1196 Net_LinkEntity(this, !(def.instanceOfPowerup || def.instanceOfHealth || def.instanceOfArmor), 0, ItemSend);
1198 // call this hook after everything else has been done
1199 if (MUTATOR_CALLHOOK(Item_Spawn, this))
1201 startitem_failed = true;
1207 void StartItem(entity this, GameItem def)
1212 def.m_respawntime(), // defaultrespawntime
1213 def.m_respawntimejitter() // defaultrespawntimejitter
1217 spawnfunc(item_rockets)
1219 if(!this.ammo_rockets)
1220 this.ammo_rockets = g_pickup_rockets;
1221 if(!this.pickup_anyway)
1222 this.pickup_anyway = g_pickup_ammo_anyway;
1223 StartItem(this, ITEM_Rockets);
1226 spawnfunc(item_bullets)
1229 if(autocvar_sv_q3acompat_machineshotgunswap)
1230 if(this.classname != "droppedweapon")
1232 weaponswapping = true;
1233 spawnfunc_item_shells(this);
1234 weaponswapping = false;
1238 if(!this.ammo_nails)
1239 this.ammo_nails = g_pickup_nails;
1240 if(!this.pickup_anyway)
1241 this.pickup_anyway = g_pickup_ammo_anyway;
1242 StartItem(this, ITEM_Bullets);
1245 spawnfunc(item_cells)
1247 if(!this.ammo_cells)
1248 this.ammo_cells = g_pickup_cells;
1249 if(!this.pickup_anyway)
1250 this.pickup_anyway = g_pickup_ammo_anyway;
1251 StartItem(this, ITEM_Cells);
1254 spawnfunc(item_plasma)
1256 if(!this.ammo_plasma)
1257 this.ammo_plasma = g_pickup_plasma;
1258 if(!this.pickup_anyway)
1259 this.pickup_anyway = g_pickup_ammo_anyway;
1260 StartItem(this, ITEM_Plasma);
1263 spawnfunc(item_shells)
1266 if(autocvar_sv_q3acompat_machineshotgunswap)
1267 if(this.classname != "droppedweapon")
1269 weaponswapping = true;
1270 spawnfunc_item_bullets(this);
1271 weaponswapping = false;
1275 if(!this.ammo_shells)
1276 this.ammo_shells = g_pickup_shells;
1277 if(!this.pickup_anyway)
1278 this.pickup_anyway = g_pickup_ammo_anyway;
1279 StartItem(this, ITEM_Shells);
1282 spawnfunc(item_armor_small)
1284 if(!this.armorvalue)
1285 this.armorvalue = g_pickup_armorsmall;
1286 if(!this.max_armorvalue)
1287 this.max_armorvalue = g_pickup_armorsmall_max;
1288 if(!this.pickup_anyway)
1289 this.pickup_anyway = g_pickup_armorsmall_anyway;
1290 StartItem(this, ITEM_ArmorSmall);
1293 spawnfunc(item_armor_medium)
1295 if(!this.armorvalue)
1296 this.armorvalue = g_pickup_armormedium;
1297 if(!this.max_armorvalue)
1298 this.max_armorvalue = g_pickup_armormedium_max;
1299 if(!this.pickup_anyway)
1300 this.pickup_anyway = g_pickup_armormedium_anyway;
1301 StartItem(this, ITEM_ArmorMedium);
1304 spawnfunc(item_armor_big)
1306 if(!this.armorvalue)
1307 this.armorvalue = g_pickup_armorbig;
1308 if(!this.max_armorvalue)
1309 this.max_armorvalue = g_pickup_armorbig_max;
1310 if(!this.pickup_anyway)
1311 this.pickup_anyway = g_pickup_armorbig_anyway;
1312 StartItem(this, ITEM_ArmorLarge);
1315 spawnfunc(item_armor_large)
1317 if(!this.armorvalue)
1318 this.armorvalue = g_pickup_armorlarge;
1319 if(!this.max_armorvalue)
1320 this.max_armorvalue = g_pickup_armorlarge_max;
1321 if(!this.pickup_anyway)
1322 this.pickup_anyway = g_pickup_armorlarge_anyway;
1323 StartItem(this, ITEM_ArmorMega);
1326 spawnfunc(item_health_small)
1328 if(!this.max_health)
1329 this.max_health = g_pickup_healthsmall_max;
1331 this.health = g_pickup_healthsmall;
1332 if(!this.pickup_anyway)
1333 this.pickup_anyway = g_pickup_healthsmall_anyway;
1334 StartItem(this, ITEM_HealthSmall);
1337 spawnfunc(item_health_medium)
1339 if(!this.max_health)
1340 this.max_health = g_pickup_healthmedium_max;
1342 this.health = g_pickup_healthmedium;
1343 if(!this.pickup_anyway)
1344 this.pickup_anyway = g_pickup_healthmedium_anyway;
1345 StartItem(this, ITEM_HealthMedium);
1348 spawnfunc(item_health_large)
1350 if(!this.max_health)
1351 this.max_health = g_pickup_healthlarge_max;
1353 this.health = g_pickup_healthlarge;
1354 if(!this.pickup_anyway)
1355 this.pickup_anyway = g_pickup_healthlarge_anyway;
1356 StartItem(this, ITEM_HealthLarge);
1359 spawnfunc(item_health_mega)
1361 if(!this.max_health)
1362 this.max_health = g_pickup_healthmega_max;
1364 this.health = g_pickup_healthmega;
1365 if(!this.pickup_anyway)
1366 this.pickup_anyway = g_pickup_healthmega_anyway;
1367 StartItem(this, ITEM_HealthMega);
1370 // support old misnamed entities
1371 spawnfunc(item_armor1) { spawnfunc_item_armor_small(this); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1372 spawnfunc(item_armor25) { spawnfunc_item_armor_large(this); }
1373 spawnfunc(item_health1) { spawnfunc_item_health_small(this); }
1374 spawnfunc(item_health25) { spawnfunc_item_health_medium(this); }
1375 spawnfunc(item_health100) { spawnfunc_item_health_mega(this); }
1377 spawnfunc(item_strength)
1379 if(!this.strength_finished)
1380 this.strength_finished = autocvar_g_balance_powerup_strength_time;
1381 StartItem(this, ITEM_Strength);
1384 spawnfunc(item_invincible)
1386 if(!this.invincible_finished)
1387 this.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1388 StartItem(this, ITEM_Shield);
1392 spawnfunc(item_quad) { this.classname = "item_strength";spawnfunc_item_strength(this);}
1394 void target_items_use()
1396 if(activator.classname == "droppedweapon")
1403 if (!IS_PLAYER(activator))
1405 if(activator.deadflag != DEAD_NO)
1410 for(e = world; (e = find(e, classname, "droppedweapon")); )
1411 if(e.enemy == activator)
1414 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1415 centerprint(activator, self.message);
1418 spawnfunc(target_items)
1424 self.use = target_items_use;
1425 if(!self.strength_finished)
1426 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1427 if(!self.invincible_finished)
1428 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1429 if(!self.superweapons_finished)
1430 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1432 n = tokenize_console(self.netname);
1433 if(argv(0) == "give")
1435 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1439 for(i = 0; i < n; ++i)
1441 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1442 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1443 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1444 else if(argv(i) == "strength") self.items |= ITEM_Strength.m_itemid;
1445 else if(argv(i) == "invincible") self.items |= ITEM_Shield.m_itemid;
1446 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1447 else if(argv(i) == "jetpack") self.items |= ITEM_Jetpack.m_itemid;
1448 else if(argv(i) == "fuel_regen") self.items |= ITEM_JetpackRegen.m_itemid;
1451 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1453 e = Weapons_from(j);
1454 s = W_UndeprecateName(argv(i));
1457 self.weapons |= (e.m_wepset);
1458 if(self.spawnflags == 0 || self.spawnflags == 2) {
1465 LOG_INFO("target_items: invalid item ", argv(i), "\n");
1469 string itemprefix, valueprefix;
1470 if(self.spawnflags == 0)
1475 else if(self.spawnflags == 1)
1477 itemprefix = "max ";
1478 valueprefix = "max ";
1480 else if(self.spawnflags == 2)
1482 itemprefix = "min ";
1483 valueprefix = "min ";
1485 else if(self.spawnflags == 4)
1487 itemprefix = "minus ";
1488 valueprefix = "max ";
1492 error("invalid spawnflags");
1493 itemprefix = valueprefix = string_null;
1497 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1498 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1499 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * boolean(self.items & ITEM_Strength.m_itemid), "strength");
1500 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * boolean(self.items & ITEM_Shield.m_itemid), "invincible");
1501 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * boolean(self.items & IT_SUPERWEAPON), "superweapons");
1502 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & ITEM_Jetpack.m_itemid), "jetpack");
1503 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, boolean(self.items & ITEM_JetpackRegen.m_itemid), "fuel_regen");
1504 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1505 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1506 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1507 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1508 if(self.ammo_plasma != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_plasma), "plasma");
1509 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1510 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1511 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1512 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1514 e = Weapons_from(j);
1515 if(e == WEP_Null) continue;
1516 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & (e.m_wepset)), e.netname);
1519 self.netname = strzone(self.netname);
1520 //print(self.netname, "\n");
1522 n = tokenize_console(self.netname);
1523 for(i = 0; i < n; ++i)
1525 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1527 e = Weapons_from(j);
1528 if(argv(i) == e.netname)
1537 spawnfunc(item_fuel)
1540 this.ammo_fuel = g_pickup_fuel;
1541 if(!this.pickup_anyway)
1542 this.pickup_anyway = g_pickup_ammo_anyway;
1543 StartItem(this, ITEM_JetpackFuel);
1546 spawnfunc(item_fuel_regen)
1548 if(start_items & ITEM_JetpackRegen.m_itemid)
1550 spawnfunc_item_fuel(this);
1553 StartItem(this, ITEM_JetpackRegen);
1556 spawnfunc(item_jetpack)
1559 this.ammo_fuel = g_pickup_fuel_jetpack;
1560 if(start_items & ITEM_Jetpack.m_itemid)
1562 spawnfunc_item_fuel(this);
1565 StartItem(this, ITEM_Jetpack);
1568 float GiveWeapon(entity e, float wpn, float op, float val)
1571 WepSet s = WepSet_FromWeapon(Weapons_from(wpn));
1572 v0 = (e.weapons & s);
1595 v1 = (e.weapons & s);
1599 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
1606 _sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1608 else if(v0 >= v0 + t)
1611 _sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1615 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1618 e.(rotfield) = max(e.(rotfield), time + rottime);
1620 e.(regenfield) = max(e.(regenfield), time + regentime);
1622 float GiveItems(entity e, float beginarg, float endarg)
1624 float got, i, j, val, op;
1625 float _switchweapon;
1634 _switchweapon = false;
1636 if (PS(e).m_switchweapon == w_getbestweapon(e))
1637 _switchweapon = true;
1639 e.strength_finished = max(0, e.strength_finished - time);
1640 e.invincible_finished = max(0, e.invincible_finished - time);
1641 e.superweapons_finished = max(0, e.superweapons_finished - time);
1645 PREGIVE(e, strength_finished);
1646 PREGIVE(e, invincible_finished);
1647 PREGIVE(e, superweapons_finished);
1648 PREGIVE(e, ammo_nails);
1649 PREGIVE(e, ammo_cells);
1650 PREGIVE(e, ammo_plasma);
1651 PREGIVE(e, ammo_shells);
1652 PREGIVE(e, ammo_rockets);
1653 PREGIVE(e, ammo_fuel);
1654 PREGIVE(e, armorvalue);
1657 for(i = beginarg; i < endarg; ++i)
1661 if(cmd == "0" || stof(cmd))
1685 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1686 got += GiveValue(e, strength_finished, op, val);
1687 got += GiveValue(e, invincible_finished, op, val);
1688 got += GiveValue(e, superweapons_finished, op, val);
1689 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1691 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1692 got += GiveValue(e, health, op, val);
1693 got += GiveValue(e, armorvalue, op, val);
1695 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1697 wi = Weapons_from(j);
1698 if(wi == WEP_Null) continue;
1699 if (!(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED))
1700 got += GiveWeapon(e, j, op, val);
1703 got += GiveValue(e, ammo_cells, op, val);
1704 got += GiveValue(e, ammo_plasma, op, val);
1705 got += GiveValue(e, ammo_shells, op, val);
1706 got += GiveValue(e, ammo_nails, op, val);
1707 got += GiveValue(e, ammo_rockets, op, val);
1708 got += GiveValue(e, ammo_fuel, op, val);
1710 case "unlimited_ammo":
1711 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1713 case "unlimited_weapon_ammo":
1714 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1716 case "unlimited_superweapons":
1717 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1720 got += GiveBit(e, items, ITEM_Jetpack.m_itemid, op, val);
1723 got += GiveBit(e, items, ITEM_JetpackRegen.m_itemid, op, val);
1726 got += GiveValue(e, strength_finished, op, val);
1729 got += GiveValue(e, invincible_finished, op, val);
1731 case "superweapons":
1732 got += GiveValue(e, superweapons_finished, op, val);
1735 got += GiveValue(e, ammo_cells, op, val);
1738 got += GiveValue(e, ammo_plasma, op, val);
1741 got += GiveValue(e, ammo_shells, op, val);
1745 got += GiveValue(e, ammo_nails, op, val);
1748 got += GiveValue(e, ammo_rockets, op, val);
1751 got += GiveValue(e, health, op, val);
1754 got += GiveValue(e, armorvalue, op, val);
1757 got += GiveValue(e, ammo_fuel, op, val);
1760 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1762 wi = Weapons_from(j);
1763 if(cmd == wi.netname)
1765 got += GiveWeapon(e, j, op, val);
1770 LOG_INFO("give: invalid item ", cmd, "\n");
1777 POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND(ITEMPICKUP), string_null);
1778 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND(POWERUP), SND(POWEROFF));
1779 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND(POWERUP), SND(POWEROFF));
1780 POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND(ITEMPICKUP), string_null);
1781 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1783 wi = Weapons_from(j);
1784 if (wi == WEP_Null) continue;
1785 POSTGIVE_WEAPON(e, Weapons_from(j), SND(WEAPONPICKUP), string_null);
1786 if (!(save_weapons & (wi.m_wepset)))
1787 if(e.weapons & (wi.m_wepset)) {
1791 POSTGIVE_VALUE(e, strength_finished, 1, SND(POWERUP), SND(POWEROFF));
1792 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", SND(POWEROFF));
1793 POSTGIVE_VALUE(e, ammo_nails, 0, SND(ITEMPICKUP), string_null);
1794 POSTGIVE_VALUE(e, ammo_cells, 0, SND(ITEMPICKUP), string_null);
1795 POSTGIVE_VALUE(e, ammo_plasma, 0, SND(ITEMPICKUP), string_null);
1796 POSTGIVE_VALUE(e, ammo_shells, 0, SND(ITEMPICKUP), string_null);
1797 POSTGIVE_VALUE(e, ammo_rockets, 0, SND(ITEMPICKUP), string_null);
1798 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), string_null);
1799 POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND(ARMOR25), string_null);
1800 POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND(MEGAHEALTH), string_null);
1802 if(e.superweapons_finished <= 0)
1803 if(self.weapons & WEPSET_SUPERWEAPONS)
1804 e.superweapons_finished = autocvar_g_balance_superweapons_time;
1806 if(e.strength_finished <= 0)
1807 e.strength_finished = 0;
1809 e.strength_finished += time;
1810 if(e.invincible_finished <= 0)
1811 e.invincible_finished = 0;
1813 e.invincible_finished += time;
1814 if(e.superweapons_finished <= 0)
1815 e.superweapons_finished = 0;
1817 e.superweapons_finished += time;
1819 if (!(e.weapons & WepSet_FromWeapon(PS(e).m_switchweapon)))
1820 _switchweapon = true;
1822 W_SwitchWeapon_Force(e, w_getbestweapon(e));