4 #include "autocvars.qh"
5 #include "constants.qh"
8 #include "mutators/mutators_include.qh"
10 #include "weapons/weaponsystem.qh"
12 #include "../common/constants.qh"
13 #include "../common/deathtypes.qh"
14 #include "../common/notifications.qh"
15 #include "../common/util.qh"
17 #include "../common/monsters/monsters.qh"
19 #include "../common/weapons/weapons.qh"
21 #include "../dpdefs/dpextensions.qh"
22 #include "../dpdefs/progsdefs.qh"
24 #include "../warpzonelib/util_server.qh"
32 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
33 if(self.move_flags & FL_ONGROUND)
34 { // For some reason move_avelocity gets set to '0 0 0' here ...
35 self.oldorigin = self.origin;
38 if(autocvar_cl_animate_items)
39 { // ... so reset it if animations are requested.
40 if(self.ItemStatus & ITS_ANIMATE1)
41 self.move_avelocity = '0 180 0';
43 if(self.ItemStatus & ITS_ANIMATE2)
44 self.move_avelocity = '0 -90 0';
48 else if (autocvar_cl_animate_items)
50 if(self.ItemStatus & ITS_ANIMATE1)
52 self.angles += self.move_avelocity * frametime;
53 setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));
56 if(self.ItemStatus & ITS_ANIMATE2)
58 self.angles += self.move_avelocity * frametime;
59 setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));
68 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
70 if(self.move_flags & FL_ONGROUND)
75 void ItemRead(float _IsNew)
81 self.origin_x = ReadCoord();
82 self.origin_y = ReadCoord();
83 self.origin_z = ReadCoord();
84 setorigin(self, self.origin);
85 self.oldorigin = self.origin;
90 self.angles_x = ReadCoord();
91 self.angles_y = ReadCoord();
92 self.angles_z = ReadCoord();
93 self.move_angles = self.angles;
98 self.mins_x = ReadCoord();
99 self.mins_y = ReadCoord();
100 self.mins_z = ReadCoord();
101 self.maxs_x = ReadCoord();
102 self.maxs_y = ReadCoord();
103 self.maxs_z = ReadCoord();
104 setsize(self, self.mins, self.maxs);
107 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
109 self.ItemStatus = ReadByte();
111 if(self.ItemStatus & ITS_AVAILABLE)
114 self.colormod = self.glowmod = '1 1 1';
118 if (autocvar_cl_ghost_items_color)
120 self.alpha = autocvar_cl_ghost_items;
121 self.colormod = self.glowmod = autocvar_cl_ghost_items_color;
127 if(autocvar_cl_fullbright_items)
128 if(self.ItemStatus & ITS_ALLOWFB)
129 self.effects |= EF_FULLBRIGHT;
131 if(self.ItemStatus & ITS_STAYWEP)
133 self.colormod = self.glowmod = autocvar_cl_weapon_stay_color;
134 self.alpha = autocvar_cl_weapon_stay_alpha;
138 if(self.ItemStatus & ITS_POWERUP)
140 if(self.ItemStatus & ITS_AVAILABLE)
141 self.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
143 self.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
149 self.drawmask = MASK_NORMAL;
150 self.movetype = MOVETYPE_TOSS;
151 self.draw = ItemDraw;
157 string _fn = ReadString();
159 if(autocvar_cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
161 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
162 self.draw = ItemDrawSimple;
166 if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
167 self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
168 else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
169 self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
170 else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
171 self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
172 else if(fexists(sprintf("%s%s.obj", _fn2, autocvar_cl_simpleitems_postfix)))
173 self.mdl = strzone(sprintf("%s%s.obj", _fn2, autocvar_cl_simpleitems_postfix));
176 self.draw = ItemDraw;
177 dprint("Simple item requested for ", _fn, " but no model exsist for it\n");
181 if(self.draw != ItemDrawSimple)
182 self.mdl = strzone(_fn);
186 dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, " tell tZork aboute this!\n");
188 precache_model(self.mdl);
189 setmodel(self, self.mdl);
192 if(sf & ISF_COLORMAP)
193 self.colormap = ReadShort();
198 //self.move_angles = '0 0 0';
199 self.move_movetype = MOVETYPE_TOSS;
200 self.move_velocity_x = ReadCoord();
201 self.move_velocity_y = ReadCoord();
202 self.move_velocity_z = ReadCoord();
203 self.velocity = self.move_velocity;
204 self.move_origin = self.oldorigin;
208 self.move_time = time;
209 self.spawntime = time;
212 self.move_time = max(self.move_time, time);
215 if(autocvar_cl_animate_items)
217 if(self.ItemStatus & ITS_ANIMATE1)
218 self.move_avelocity = '0 180 0';
220 if(self.ItemStatus & ITS_ANIMATE2)
221 self.move_avelocity = '0 -90 0';
228 bool ItemSend(entity to, int sf)
235 WriteByte(MSG_ENTITY, ENT_CLIENT_ITEM);
236 WriteByte(MSG_ENTITY, sf);
238 //WriteByte(MSG_ENTITY, self.cnt);
239 if(sf & ISF_LOCATION)
241 WriteCoord(MSG_ENTITY, self.origin.x);
242 WriteCoord(MSG_ENTITY, self.origin.y);
243 WriteCoord(MSG_ENTITY, self.origin.z);
248 WriteCoord(MSG_ENTITY, self.angles.x);
249 WriteCoord(MSG_ENTITY, self.angles.y);
250 WriteCoord(MSG_ENTITY, self.angles.z);
255 WriteCoord(MSG_ENTITY, self.mins.x);
256 WriteCoord(MSG_ENTITY, self.mins.y);
257 WriteCoord(MSG_ENTITY, self.mins.z);
258 WriteCoord(MSG_ENTITY, self.maxs.x);
259 WriteCoord(MSG_ENTITY, self.maxs.y);
260 WriteCoord(MSG_ENTITY, self.maxs.z);
264 WriteByte(MSG_ENTITY, self.ItemStatus);
270 dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n");
272 WriteString(MSG_ENTITY, self.mdl);
276 if(sf & ISF_COLORMAP)
277 WriteShort(MSG_ENTITY, self.colormap);
281 WriteCoord(MSG_ENTITY, self.velocity.x);
282 WriteCoord(MSG_ENTITY, self.velocity.y);
283 WriteCoord(MSG_ENTITY, self.velocity.z);
289 void ItemUpdate(entity item)
291 item.SendFlags |= ISF_LOCATION;
294 float have_pickup_item(void)
296 if(self.flags & FL_POWERUP)
298 if(autocvar_g_powerups > 0)
300 if(autocvar_g_powerups == 0)
305 if(autocvar_g_pickup_items > 0)
307 if(autocvar_g_pickup_items == 0)
310 if(self.weapons || (self.items & IT_AMMO)) // no item or ammo pickups in weaponarena
317 float Item_Customize()
319 if(self.spawnshieldtime)
321 if(self.weapons & ~other.weapons)
323 self.colormod = '0 0 0';
324 self.glowmod = self.colormod;
325 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
332 self.colormod = stov(autocvar_g_ghost_items_color);
333 self.glowmod = self.colormod;
334 self.alpha = g_ghost_items;
343 void Item_Show (entity e, float mode)
345 e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
346 e.ItemStatus &= ~ITS_STAYWEP;
349 // make the item look normal, and be touchable
351 e.solid = SOLID_TRIGGER;
352 e.spawnshieldtime = 1;
353 e.ItemStatus |= ITS_AVAILABLE;
357 // hide the item completely
358 e.model = string_null;
360 e.spawnshieldtime = 1;
361 e.ItemStatus &= ~ITS_AVAILABLE;
363 else if((e.flags & FL_WEAPON) && !(e.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
365 // make the item translucent and not touchable
367 e.solid = SOLID_TRIGGER; // can STILL be picked up!
368 e.effects |= EF_STARDUST;
369 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
370 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
374 //setmodel(e, "null");
376 e.colormod = '0 0 0';
377 e.glowmod = e.colormod;
378 e.spawnshieldtime = 1;
379 e.ItemStatus &= ~ITS_AVAILABLE;
382 if (e.items & IT_STRENGTH || e.items & IT_INVINCIBLE)
383 e.ItemStatus |= ITS_POWERUP;
385 if (autocvar_g_nodepthtestitems)
386 e.effects |= EF_NODEPTHTEST;
389 if (autocvar_g_fullbrightitems)
390 e.ItemStatus |= ITS_ALLOWFB;
392 if (autocvar_sv_simple_items)
393 e.ItemStatus |= ITS_ALLOWSI;
395 // relink entity (because solid may have changed)
396 setorigin(e, e.origin);
397 e.SendFlags |= ISF_STATUS;
402 self.nextthink = time;
403 if(self.origin != self.oldorigin)
405 self.oldorigin = self.origin;
410 void Item_Respawn (void)
414 if(self.items == IT_STRENGTH)
415 sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
416 else if(self.items == IT_INVINCIBLE)
417 sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
419 sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
420 setorigin (self, self.origin);
422 self.think = Item_Think;
423 self.nextthink = time;
425 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
426 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
429 void Item_RespawnCountdown (void)
431 if(self.count >= ITEM_RESPAWN_TICKS)
433 if(self.waypointsprite_attached)
434 WaypointSprite_Kill(self.waypointsprite_attached);
439 self.nextthink = time + 1;
444 vector rgb = '1 0 1';
448 case IT_FUEL_REGEN: name = "item-fuelregen"; rgb = '1 0.5 0'; break;
449 case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
450 case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
451 case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
455 MUTATOR_CALLHOOK(Item_RespawnCountdown);
458 if(self.flags & FL_WEAPON)
460 entity wi = get_weaponinfo(self.weapon);
469 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_POWERUP, rgb);
470 if(self.waypointsprite_attached)
471 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
475 print("Unknown powerup-marked item is wanting to respawn\n");
476 localcmd(sprintf("prvm_edict server %d\n", num_for_edict(self)));
479 sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
480 if(self.waypointsprite_attached)
482 WaypointSprite_Ping(self.waypointsprite_attached);
483 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
488 void Item_RespawnThink()
490 self.nextthink = time;
491 if(self.origin != self.oldorigin)
493 self.oldorigin = self.origin;
497 if(time >= self.wait)
501 void Item_ScheduleRespawnIn(entity e, float t)
503 if((e.flags & FL_POWERUP) || (e.weapons & WEPSET_SUPERWEAPONS))
505 e.think = Item_RespawnCountdown;
506 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
511 e.think = Item_RespawnThink;
517 void Item_ScheduleRespawn(entity e)
519 if(e.respawntime > 0)
522 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
524 else // if respawntime is -1, this item does not respawn
528 void Item_ScheduleInitialRespawn(entity e)
531 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
534 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
536 if (!item.(ammotype))
539 if (item.spawnshieldtime)
541 if ((player.(ammotype) < ammomax) || item.pickup_anyway)
543 player.(ammotype) = bound(player.(ammotype), ammomax, player.(ammotype) + item.(ammotype));
547 else if(g_weapon_stay == 2)
549 float mi = min(item.(ammotype), ammomax);
550 if (player.(ammotype) < mi)
552 player.(ammotype) = mi;
563 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
565 case ITEM_MODE_HEALTH:
566 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
568 case ITEM_MODE_ARMOR:
569 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
577 float Item_GiveTo(entity item, entity player)
584 // if nothing happens to player, just return without taking the item
586 _switchweapon = false;
587 // in case the player has autoswitch enabled do the following:
588 // if the player is using their best weapon before items are given, they
589 // probably want to switch to an even better weapon after items are given
590 if (player.autoswitch)
591 if (player.switchweapon == w_getbestweapon(player))
592 _switchweapon = true;
594 if (!(player.weapons & WepSet_FromWeapon(player.switchweapon)))
595 _switchweapon = true;
597 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
598 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
599 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
600 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
601 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
602 pickedup |= Item_GiveAmmoTo(item, player, ammo_plasma, g_pickup_plasma_max, ITEM_MODE_NONE);
603 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
604 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
606 if (item.flags & FL_WEAPON)
610 it &= ~player.weapons;
612 if (it || (item.spawnshieldtime && item.pickup_anyway))
615 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
616 if(it & WepSet_FromWeapon(i))
618 W_DropEvent(WR_PICKUP, player, i, item);
619 W_GiveWeapon(player, i);
624 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
628 Send_Notification(NOTIF_ONE, player, MSG_INFO, INFO_ITEM_WEAPON_GOT, item.netname);
631 if (item.strength_finished)
634 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
636 if (item.invincible_finished)
639 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
641 if (item.superweapons_finished)
644 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
649 // always eat teamed entities
657 if (player.switchweapon != w_getbestweapon(player))
658 W_SwitchWeapon_Force(player, w_getbestweapon(player));
663 void Item_Touch (void)
667 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
668 if(self.classname == "droppedweapon")
670 if (ITEM_TOUCH_NEEDKILL())
677 if (!IS_PLAYER(other))
683 if (self.solid != SOLID_TRIGGER)
685 if (self.owner == other)
687 if (time < self.item_spawnshieldtime)
690 switch(MUTATOR_CALLHOOK(ItemTouch))
692 case MUT_ITEMTOUCH_RETURN: { return; }
693 case MUT_ITEMTOUCH_PICKUP: { goto pickup; }
696 if (self.classname == "droppedweapon")
698 self.strength_finished = max(0, self.strength_finished - time);
699 self.invincible_finished = max(0, self.invincible_finished - time);
700 self.superweapons_finished = max(0, self.superweapons_finished - time);
703 if(!Item_GiveTo(self, other))
705 if (self.classname == "droppedweapon")
707 // undo what we did above
708 self.strength_finished += time;
709 self.invincible_finished += time;
710 self.superweapons_finished += time;
717 other.last_pickup = time;
719 pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
720 sound (other, CH_TRIGGER, self.item_pickupsound, VOL_BASE, ATTEN_NORM);
722 if (self.classname == "droppedweapon")
724 else if (!self.spawnshieldtime)
730 RandomSelection_Init();
731 for(head = world; (head = findfloat(head, team, self.team)); )
733 if(head.flags & FL_ITEM)
736 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
739 e = RandomSelection_chosen_ent;
744 Item_ScheduleRespawn(e);
750 Item_Show(self, !self.state);
751 setorigin (self, self.origin);
753 if(self.classname != "droppedweapon")
755 self.think = Item_Think;
756 self.nextthink = time;
758 if(self.waypointsprite_attached)
759 WaypointSprite_Kill(self.waypointsprite_attached);
761 if((self.flags & FL_POWERUP) || (self.weapons & WEPSET_SUPERWEAPONS)) // do not spawn powerups initially!
762 Item_ScheduleInitialRespawn(self);
770 if(self.effects & EF_NODRAW)
772 // marker for item team search
773 dprint("Initializing item team ", ftos(self.team), "\n");
774 RandomSelection_Init();
775 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
776 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
777 e = RandomSelection_chosen_ent;
781 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
785 // make it a non-spawned item
787 head.state = 1; // state 1 = initially hidden item
789 head.effects &= ~EF_NODRAW;
796 // Savage: used for item garbage-collection
797 // TODO: perhaps nice special effect?
798 void RemoveItem(void)
803 // pickup evaluation functions
804 // these functions decide how desirable an item is to the bots
806 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
808 float weapon_pickupevalfunc(entity player, entity item)
812 // See if I have it already
813 if(item.weapons & ~player.weapons)
815 // If I can pick it up
816 if(!item.spawnshieldtime)
818 else if(player.ammo_cells || player.ammo_shells || player.ammo_plasma || player.ammo_nails || player.ammo_rockets)
820 // Skilled bots will grab more
821 c = bound(0, skill / 10, 1) * 0.5;
829 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
830 if( bot_custom_weapon && c )
832 // Find the highest position on any range
834 for (int j = 0; j < WEP_LAST ; ++j){
836 bot_weapons_far[j] == item.weapon ||
837 bot_weapons_mid[j] == item.weapon ||
838 bot_weapons_close[j] == item.weapon
849 position = WEP_LAST - position;
850 // item.bot_pickupbasevalue is overwritten here
851 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
855 return item.bot_pickupbasevalue * c;
858 float commodity_pickupevalfunc(entity player, entity item)
861 float need_shells = false, need_nails = false, need_rockets = false, need_cells = false, need_plasma = false, need_fuel = false;
865 // Detect needed ammo
866 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
868 wi = get_weaponinfo(i);
870 if (!(player.weapons & WepSet_FromWeapon(i)))
873 if(wi.items & IT_SHELLS)
875 else if(wi.items & IT_NAILS)
877 else if(wi.items & IT_ROCKETS)
879 else if(wi.items & IT_CELLS)
881 else if(wi.items & IT_PLASMA)
883 else if(wi.items & IT_FUEL)
887 // TODO: figure out if the player even has the weapon this ammo is for?
888 // may not affect strategy much though...
889 // find out how much more ammo/armor/health the player can hold
891 if (item.ammo_shells)
892 if (player.ammo_shells < g_pickup_shells_max)
893 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
896 if (player.ammo_nails < g_pickup_nails_max)
897 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
899 if (item.ammo_rockets)
900 if (player.ammo_rockets < g_pickup_rockets_max)
901 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
904 if (player.ammo_cells < g_pickup_cells_max)
905 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
907 if (item.ammo_plasma)
908 if (player.ammo_plasma < g_pickup_plasma_max)
909 c = c + max(0, 1 - player.ammo_plasma / g_pickup_plasma_max);
912 if (player.ammo_fuel < g_pickup_fuel_max)
913 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
915 if (player.armorvalue < item.max_armorvalue)
916 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
918 if (player.health < item.max_health)
919 c = c + max(0, 1 - player.health / item.max_health);
921 return item.bot_pickupbasevalue * c;
924 void Item_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
926 if(ITEM_DAMAGE_NEEDKILL(deathtype))
930 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, float defaultrespawntimejitter, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
932 startitem_failed = false;
935 self.model = itemmodel;
939 error(strcat("^1Tried to spawn ", itemname, " with no model!\n"));
943 if(self.item_pickupsound == "")
944 self.item_pickupsound = pickupsound;
946 if(!self.respawntime) // both need to be set
948 self.respawntime = defaultrespawntime;
949 self.respawntimejitter = defaultrespawntimejitter;
953 self.weapon = weaponid;
956 self.weapons = WepSet_FromWeapon(weaponid);
958 self.flags = FL_ITEM | itemflags;
960 if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
962 startitem_failed = true;
967 // is it a dropped weapon?
968 if (self.classname == "droppedweapon")
970 self.reset = SUB_Remove;
971 // it's a dropped weapon
972 self.movetype = MOVETYPE_TOSS;
974 // Savage: remove thrown items after a certain period of time ("garbage collection")
975 self.think = RemoveItem;
976 self.nextthink = time + 20;
978 self.takedamage = DAMAGE_YES;
979 self.event_damage = Item_Damage;
981 if(self.strength_finished || self.invincible_finished || self.superweapons_finished)
984 if(!(self.weapons & ~WEPSET_SUPERWEAPONS)) // only superweapons
985 if(self.ammo_nails == 0)
986 if(self.ammo_cells == 0)
987 if(self.ammo_rockets == 0)
988 if(self.ammo_shells == 0)
989 if(self.ammo_fuel == 0)
991 if(self.armorvalue == 0)
994 // if item is worthless after a timer, have it expire then
995 self.nextthink = max(self.strength_finished, self.invincible_finished, self.superweapons_finished);
998 // don't drop if in a NODROP zone (such as lava)
999 traceline(self.origin, self.origin, MOVE_NORMAL, self);
1000 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1002 startitem_failed = true;
1009 if(!have_pickup_item())
1011 startitem_failed = true;
1016 self.reset = Item_Reset;
1017 // it's a level item
1018 if(self.spawnflags & 1)
1021 self.movetype = MOVETYPE_NONE;
1023 self.movetype = MOVETYPE_TOSS;
1024 // do item filtering according to game mode and other things
1027 // first nudge it off the floor a little bit to avoid math errors
1028 setorigin(self, self.origin + '0 0 1');
1029 // set item size before we spawn a spawnfunc_waypoint
1030 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1031 setsize (self, '-16 -16 0', '16 16 48');
1033 setsize (self, '-16 -16 0', '16 16 32');
1035 // note droptofloor returns false if stuck/or would fall too far
1037 waypoint_spawnforitem(self);
1041 * can't do it that way, as it would break maps
1042 * TODO make a target_give like entity another way, that perhaps has
1043 * the weapon name in a key
1046 // target_give not yet supported; maybe later
1047 print("removed targeted ", self.classname, "\n");
1048 startitem_failed = true;
1054 if(autocvar_spawn_debug >= 2)
1057 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
1059 // why not flags & fl_item?
1060 if(otheritem.is_item)
1062 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
1063 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1064 error("Mapper sucks.");
1067 self.is_item = true;
1070 weaponsInMap |= WepSet_FromWeapon(weaponid);
1072 precache_model (self.model);
1073 precache_sound (self.item_pickupsound);
1075 precache_sound ("misc/itemrespawncountdown.wav");
1076 if(itemid == IT_STRENGTH)
1077 precache_sound ("misc/strength_respawn.wav");
1078 else if(itemid == IT_INVINCIBLE)
1079 precache_sound ("misc/shield_respawn.wav");
1081 precache_sound ("misc/itemrespawn.wav");
1083 if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
1084 self.target = "###item###"; // for finding the nearest item using find()
1087 self.bot_pickup = true;
1088 self.bot_pickupevalfunc = pickupevalfunc;
1089 self.bot_pickupbasevalue = pickupbasevalue;
1090 self.mdl = self.model;
1091 self.netname = itemname;
1092 self.touch = Item_Touch;
1093 setmodel(self, "null"); // precision set below
1094 //self.effects |= EF_LOWPRECISION;
1096 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1098 self.pos1 = '-16 -16 0';
1099 self.pos2 = '16 16 48';
1103 self.pos1 = '-16 -16 0';
1104 self.pos2 = '16 16 32';
1106 setsize (self, self.pos1, self.pos2);
1108 if(itemflags & FL_POWERUP)
1109 self.ItemStatus |= ITS_ANIMATE1;
1111 if(self.armorvalue || self.health)
1112 self.ItemStatus |= ITS_ANIMATE2;
1114 if(itemflags & FL_WEAPON)
1116 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1117 self.colormap = 1024; // color shirt=0 pants=0 grey
1121 self.ItemStatus |= ITS_ANIMATE1;
1122 self.ItemStatus |= ISF_COLORMAP;
1126 if(self.team) // broken, no idea why.
1129 self.cnt = 1; // item probability weight
1131 self.effects |= EF_NODRAW; // marker for item team search
1132 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
1137 Net_LinkEntity(self, false, 0, ItemSend);
1139 self.SendFlags |= ISF_SIZE;
1141 self.SendFlags |= ISF_ANGLES;
1143 // call this hook after everything else has been done
1144 if(MUTATOR_CALLHOOK(Item_Spawn))
1146 startitem_failed = true;
1151 void spawnfunc_item_rockets (void) {
1152 if(!self.ammo_rockets)
1153 self.ammo_rockets = g_pickup_rockets;
1154 if(!self.pickup_anyway)
1155 self.pickup_anyway = g_pickup_ammo_anyway;
1156 StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
1159 void spawnfunc_item_shells (void);
1160 void spawnfunc_item_bullets (void) {
1162 if(autocvar_sv_q3acompat_machineshotgunswap)
1163 if(self.classname != "droppedweapon")
1165 weaponswapping = true;
1166 spawnfunc_item_shells();
1167 weaponswapping = false;
1171 if(!self.ammo_nails)
1172 self.ammo_nails = g_pickup_nails;
1173 if(!self.pickup_anyway)
1174 self.pickup_anyway = g_pickup_ammo_anyway;
1175 StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
1178 void spawnfunc_item_cells (void) {
1179 if(!self.ammo_cells)
1180 self.ammo_cells = g_pickup_cells;
1181 if(!self.pickup_anyway)
1182 self.pickup_anyway = g_pickup_ammo_anyway;
1183 StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
1186 void spawnfunc_item_plasma()
1188 if(!self.ammo_plasma)
1189 self.ammo_plasma = g_pickup_plasma;
1190 if(!self.pickup_anyway)
1191 self.pickup_anyway = g_pickup_ammo_anyway;
1192 StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "plasma", IT_PLASMA, 0, 0, commodity_pickupevalfunc, 2000);
1195 void spawnfunc_item_shells (void) {
1197 if(autocvar_sv_q3acompat_machineshotgunswap)
1198 if(self.classname != "droppedweapon")
1200 weaponswapping = true;
1201 spawnfunc_item_bullets();
1202 weaponswapping = false;
1206 if(!self.ammo_shells)
1207 self.ammo_shells = g_pickup_shells;
1208 if(!self.pickup_anyway)
1209 self.pickup_anyway = g_pickup_ammo_anyway;
1210 StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
1213 void spawnfunc_item_armor_small (void) {
1214 if(!self.armorvalue)
1215 self.armorvalue = g_pickup_armorsmall;
1216 if(!self.max_armorvalue)
1217 self.max_armorvalue = g_pickup_armorsmall_max;
1218 if(!self.pickup_anyway)
1219 self.pickup_anyway = g_pickup_armorsmall_anyway;
1220 StartItem ("models/items/item_armor_small.md3", "misc/armor1.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1223 void spawnfunc_item_armor_medium (void) {
1224 if(!self.armorvalue)
1225 self.armorvalue = g_pickup_armormedium;
1226 if(!self.max_armorvalue)
1227 self.max_armorvalue = g_pickup_armormedium_max;
1228 if(!self.pickup_anyway)
1229 self.pickup_anyway = g_pickup_armormedium_anyway;
1230 StartItem ("models/items/item_armor_medium.md3", "misc/armor10.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1233 void spawnfunc_item_armor_big (void) {
1234 if(!self.armorvalue)
1235 self.armorvalue = g_pickup_armorbig;
1236 if(!self.max_armorvalue)
1237 self.max_armorvalue = g_pickup_armorbig_max;
1238 if(!self.pickup_anyway)
1239 self.pickup_anyway = g_pickup_armorbig_anyway;
1240 StartItem ("models/items/item_armor_big.md3", "misc/armor17_5.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "50 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
1243 void spawnfunc_item_armor_large (void) {
1244 if(!self.armorvalue)
1245 self.armorvalue = g_pickup_armorlarge;
1246 if(!self.max_armorvalue)
1247 self.max_armorvalue = g_pickup_armorlarge_max;
1248 if(!self.pickup_anyway)
1249 self.pickup_anyway = g_pickup_armorlarge_anyway;
1250 StartItem ("models/items/item_armor_large.md3", "misc/armor25.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1253 void spawnfunc_item_health_small (void) {
1254 if(!self.max_health)
1255 self.max_health = g_pickup_healthsmall_max;
1257 self.health = g_pickup_healthsmall;
1258 if(!self.pickup_anyway)
1259 self.pickup_anyway = g_pickup_healthsmall_anyway;
1260 StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1263 void spawnfunc_item_health_medium (void) {
1264 if(!self.max_health)
1265 self.max_health = g_pickup_healthmedium_max;
1267 self.health = g_pickup_healthmedium;
1268 if(!self.pickup_anyway)
1269 self.pickup_anyway = g_pickup_healthmedium_anyway;
1270 StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1273 void spawnfunc_item_health_large (void) {
1274 if(!self.max_health)
1275 self.max_health = g_pickup_healthlarge_max;
1277 self.health = g_pickup_healthlarge;
1278 if(!self.pickup_anyway)
1279 self.pickup_anyway = g_pickup_healthlarge_anyway;
1280 StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1283 void spawnfunc_item_health_mega (void) {
1284 if(!self.max_health)
1285 self.max_health = g_pickup_healthmega_max;
1287 self.health = g_pickup_healthmega;
1288 if(!self.pickup_anyway)
1289 self.pickup_anyway = g_pickup_healthmega_anyway;
1290 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1293 // support old misnamed entities
1294 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1295 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1296 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1297 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1298 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1300 void spawnfunc_item_strength (void) {
1301 precache_sound("weapons/strength_fire.wav");
1302 if(!self.strength_finished)
1303 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1304 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
1307 void spawnfunc_item_invincible (void) {
1308 if(!self.invincible_finished)
1309 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1310 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Shield", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
1314 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1316 void target_items_use (void)
1318 if(activator.classname == "droppedweapon")
1325 if (!IS_PLAYER(activator))
1327 if(activator.deadflag != DEAD_NO)
1332 for(e = world; (e = find(e, classname, "droppedweapon")); )
1333 if(e.enemy == activator)
1336 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1337 centerprint(activator, self.message);
1340 void spawnfunc_target_items (void)
1346 self.use = target_items_use;
1347 if(!self.strength_finished)
1348 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1349 if(!self.invincible_finished)
1350 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1351 if(!self.superweapons_finished)
1352 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1354 precache_sound("misc/itempickup.wav");
1355 precache_sound("misc/megahealth.wav");
1356 precache_sound("misc/armor25.wav");
1357 precache_sound("misc/powerup.wav");
1358 precache_sound("misc/poweroff.wav");
1359 precache_sound("weapons/weaponpickup.wav");
1361 n = tokenize_console(self.netname);
1362 if(argv(0) == "give")
1364 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1368 for(i = 0; i < n; ++i)
1370 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1371 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1372 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1373 else if(argv(i) == "strength") self.items |= IT_STRENGTH;
1374 else if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1375 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1376 else if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1377 else if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1380 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1382 e = get_weaponinfo(j);
1383 s = W_UndeprecateName(argv(i));
1386 self.weapons |= WepSet_FromWeapon(j);
1387 if(self.spawnflags == 0 || self.spawnflags == 2)
1388 WEP_ACTION(e.weapon, WR_INIT);
1393 print("target_items: invalid item ", argv(i), "\n");
1397 string itemprefix, valueprefix;
1398 if(self.spawnflags == 0)
1403 else if(self.spawnflags == 1)
1405 itemprefix = "max ";
1406 valueprefix = "max ";
1408 else if(self.spawnflags == 2)
1410 itemprefix = "min ";
1411 valueprefix = "min ";
1413 else if(self.spawnflags == 4)
1415 itemprefix = "minus ";
1416 valueprefix = "max ";
1420 error("invalid spawnflags");
1421 itemprefix = valueprefix = string_null;
1425 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1426 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1427 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * !!(self.items & IT_STRENGTH), "strength");
1428 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * !!(self.items & IT_INVINCIBLE), "invincible");
1429 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * !!(self.items & IT_SUPERWEAPON), "superweapons");
1430 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_JETPACK), "jetpack");
1431 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_FUEL_REGEN), "fuel_regen");
1432 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1433 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1434 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1435 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1436 if(self.ammo_plasma != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_plasma), "plasma");
1437 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1438 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1439 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1440 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1442 e = get_weaponinfo(j);
1444 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & WepSet_FromWeapon(j)), e.netname);
1447 self.netname = strzone(self.netname);
1448 //print(self.netname, "\n");
1450 n = tokenize_console(self.netname);
1451 for(i = 0; i < n; ++i)
1453 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1455 e = get_weaponinfo(j);
1456 if(argv(i) == e.netname)
1458 WEP_ACTION(e.weapon, WR_INIT);
1465 void spawnfunc_item_fuel(void)
1468 self.ammo_fuel = g_pickup_fuel;
1469 if(!self.pickup_anyway)
1470 self.pickup_anyway = g_pickup_ammo_anyway;
1471 StartItem ("models/items/g_fuel.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "Fuel", IT_FUEL, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1474 void spawnfunc_item_fuel_regen(void)
1476 if(start_items & IT_FUEL_REGEN)
1478 spawnfunc_item_fuel();
1481 StartItem ("models/items/g_fuelregen.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Fuel regenerator", IT_FUEL_REGEN, 0, FL_POWERUP, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1484 void spawnfunc_item_jetpack(void)
1487 self.ammo_fuel = g_pickup_fuel_jetpack;
1488 if(start_items & IT_JETPACK)
1490 spawnfunc_item_fuel();
1493 StartItem ("models/items/g_jetpack.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Jet pack", IT_JETPACK, 0, FL_POWERUP, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1496 float GiveWeapon(entity e, float wpn, float op, float val)
1499 v0 = (e.weapons & WepSet_FromWeapon(wpn));
1504 e.weapons |= WepSet_FromWeapon(wpn);
1506 e.weapons &= ~WepSet_FromWeapon(wpn);
1511 e.weapons |= WepSet_FromWeapon(wpn);
1515 e.weapons &= ~WepSet_FromWeapon(wpn);
1519 e.weapons &= ~WepSet_FromWeapon(wpn);
1522 v1 = (e.weapons & WepSet_FromWeapon(wpn));
1526 float GiveBit(entity e, .float fld, float bit, float op, float val)
1529 v0 = (e.(fld) & bit);
1552 v1 = (e.(fld) & bit);
1556 float GiveValue(entity e, .float fld, float op, float val)
1566 e.(fld) = max(e.(fld), val); // min 100 cells = at least 100 cells
1569 e.(fld) = min(e.(fld), val);
1582 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
1589 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
1591 else if(v0 >= v0 + t)
1594 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
1598 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1601 e.(rotfield) = max(e.(rotfield), time + rottime);
1603 e.(regenfield) = max(e.(regenfield), time + regentime);
1605 float GiveItems(entity e, float beginarg, float endarg)
1607 float got, i, j, val, op;
1608 float _switchweapon;
1617 _switchweapon = false;
1619 if (e.switchweapon == w_getbestweapon(e))
1620 _switchweapon = true;
1622 e.strength_finished = max(0, e.strength_finished - time);
1623 e.invincible_finished = max(0, e.invincible_finished - time);
1624 e.superweapons_finished = max(0, e.superweapons_finished - time);
1628 PREGIVE(e, strength_finished);
1629 PREGIVE(e, invincible_finished);
1630 PREGIVE(e, superweapons_finished);
1631 PREGIVE(e, ammo_nails);
1632 PREGIVE(e, ammo_cells);
1633 PREGIVE(e, ammo_plasma);
1634 PREGIVE(e, ammo_shells);
1635 PREGIVE(e, ammo_rockets);
1636 PREGIVE(e, ammo_fuel);
1637 PREGIVE(e, armorvalue);
1640 for(i = beginarg; i < endarg; ++i)
1644 if(cmd == "0" || stof(cmd))
1668 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1669 got += GiveValue(e, strength_finished, op, val);
1670 got += GiveValue(e, invincible_finished, op, val);
1671 got += GiveValue(e, superweapons_finished, op, val);
1672 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1674 got += GiveBit(e, items, IT_JETPACK, op, val);
1675 got += GiveValue(e, health, op, val);
1676 got += GiveValue(e, armorvalue, op, val);
1678 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1680 wi = get_weaponinfo(j);
1682 if (!(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED))
1683 got += GiveWeapon(e, j, op, val);
1686 got += GiveValue(e, ammo_cells, op, val);
1687 got += GiveValue(e, ammo_plasma, op, val);
1688 got += GiveValue(e, ammo_shells, op, val);
1689 got += GiveValue(e, ammo_nails, op, val);
1690 got += GiveValue(e, ammo_rockets, op, val);
1691 got += GiveValue(e, ammo_fuel, op, val);
1693 case "unlimited_ammo":
1694 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1696 case "unlimited_weapon_ammo":
1697 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1699 case "unlimited_superweapons":
1700 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1703 got += GiveBit(e, items, IT_JETPACK, op, val);
1706 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1709 got += GiveValue(e, strength_finished, op, val);
1712 got += GiveValue(e, invincible_finished, op, val);
1714 case "superweapons":
1715 got += GiveValue(e, superweapons_finished, op, val);
1718 got += GiveValue(e, ammo_cells, op, val);
1721 got += GiveValue(e, ammo_plasma, op, val);
1724 got += GiveValue(e, ammo_shells, op, val);
1728 got += GiveValue(e, ammo_nails, op, val);
1731 got += GiveValue(e, ammo_rockets, op, val);
1734 got += GiveValue(e, health, op, val);
1737 got += GiveValue(e, armorvalue, op, val);
1740 got += GiveValue(e, ammo_fuel, op, val);
1743 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1745 wi = get_weaponinfo(j);
1746 if(cmd == wi.netname)
1748 got += GiveWeapon(e, j, op, val);
1753 print("give: invalid item ", cmd, "\n");
1760 POSTGIVE_BIT(e, items, IT_FUEL_REGEN, "misc/itempickup.wav", string_null);
1761 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
1762 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
1763 POSTGIVE_BIT(e, items, IT_JETPACK, "misc/itempickup.wav", string_null);
1764 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1766 wi = get_weaponinfo(j);
1769 POSTGIVE_WEAPON(e, j, "weapons/weaponpickup.wav", string_null);
1770 if (!(save_weapons & WepSet_FromWeapon(j)))
1771 if(e.weapons & WepSet_FromWeapon(j))
1772 WEP_ACTION(wi.weapon, WR_INIT);
1775 POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
1776 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
1777 POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
1778 POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
1779 POSTGIVE_VALUE(e, ammo_plasma, 0, "misc/itempickup.wav", string_null);
1780 POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
1781 POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
1782 POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, "misc/itempickup.wav", string_null);
1783 POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, "misc/armor25.wav", string_null);
1784 POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, "misc/megahealth.wav", string_null);
1786 if(e.superweapons_finished <= 0)
1787 if(self.weapons & WEPSET_SUPERWEAPONS)
1788 e.superweapons_finished = autocvar_g_balance_superweapons_time;
1790 if(e.strength_finished <= 0)
1791 e.strength_finished = 0;
1793 e.strength_finished += time;
1794 if(e.invincible_finished <= 0)
1795 e.invincible_finished = 0;
1797 e.invincible_finished += time;
1798 if(e.superweapons_finished <= 0)
1799 e.superweapons_finished = 0;
1801 e.superweapons_finished += time;
1803 if (!(e.weapons & WepSet_FromWeapon(e.switchweapon)))
1804 _switchweapon = true;
1806 W_SwitchWeapon_Force(e, w_getbestweapon(e));