6 #define ITS_AVAILABLE 4
10 #define ISF_COLORMAP 16
15 float csqcitems_started;
17 float autocvar_cl_ghost_items;
18 vector autocvar_cl_ghost_items_color;
19 float autocvar_cl_simple_items;
24 if(self.ItemStatus & ITS_ANIMATE1)
26 self.angles += '0 180 0' * frametime;
27 setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));
30 if(self.ItemStatus & ITS_ANIMATE2)
32 self.angles += '0 -90 0' * frametime;
33 setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));
42 void csqcitems_start()
44 autocvar_cl_ghost_items = bound(0, autocvar_cl_ghost_items, 1);
45 if(autocvar_cl_ghost_items == 1)
46 autocvar_cl_ghost_items = 0.55;
48 string _tmp = cvar_string("cl_ghost_items_color");
50 autocvar_cl_ghost_items_color = '-1 -1 -1';
53 csqcitems_started = TRUE;
56 void ItemRead(float _IsNew)
58 if(!csqcitems_started)
63 float sf = ReadByte();
67 self.origin_x = ReadCoord();
68 self.origin_y = ReadCoord();
69 self.origin_z = ReadCoord();
70 setorigin(self, self.origin);
71 self.oldorigin = self.origin;
74 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
76 self.ItemStatus = ReadByte();
78 if(self.ItemStatus & ITS_AVAILABLE)
81 self.colormod = '1 1 1';
85 if (autocvar_cl_ghost_items)
87 self.alpha = autocvar_cl_ghost_items;
88 self.colormod = autocvar_cl_ghost_items_color;
95 if(sf & ISF_MODEL) // handle simple items, fullbright and so on here
100 self.draw = ItemDraw;
101 self.drawmask = MASK_NORMAL;
102 self.movetype = MOVETYPE_NOCLIP;
103 self.mdl = strzone(ReadString());
104 setmodel(self, self.mdl);
107 if(sf & ISF_VELOCITY)
109 self.move_origin_x = ReadCoord();
110 self.move_origin_y = ReadCoord();
111 self.move_origin_z = ReadCoord();
112 self.move_velocity_x = ReadCoord();
113 self.move_velocity_y = ReadCoord();
114 self.move_velocity_z = ReadCoord();
117 if(sf & ISF_COLORMAP)
118 self.colormap = ReadShort();
124 float ItemSend(entity to, float sf)
126 WriteByte(MSG_ENTITY, ENT_CLIENT_ITEM);
128 WriteByte(MSG_ENTITY, sf);
130 //WriteByte(MSG_ENTITY, self.cnt);
131 if(sf & ISF_LOCATION)
133 WriteCoord(MSG_ENTITY, self.origin_x);
134 WriteCoord(MSG_ENTITY, self.origin_y);
135 WriteCoord(MSG_ENTITY, self.origin_z);
139 WriteByte(MSG_ENTITY, self.ItemStatus);
142 WriteString(MSG_ENTITY, self.mdl);
148 float have_pickup_item(void)
150 // minstagib: only allow filtered items
152 if(self.classname != "minstagib")
155 if(self.flags & FL_POWERUP)
157 if(autocvar_g_powerups > 0)
159 if(autocvar_g_powerups == 0)
170 if(autocvar_g_pickup_items > 0)
172 if(autocvar_g_pickup_items == 0)
179 if((self.weapons & WEPBIT_ALL) || (self.items & IT_AMMO))
185 #define ITEM_RESPAWN_TICKS 10
187 #define ITEM_RESPAWNTIME(i) ((i).respawntime + crandom() * (i).respawntimejitter)
188 // range: respawntime - respawntimejitter .. respawntime + respawntimejitter
189 #define ITEM_RESPAWNTIME_INITIAL(i) (ITEM_RESPAWN_TICKS + random() * ((i).respawntime + (i).respawntimejitter - ITEM_RESPAWN_TICKS))
190 // range: 10 .. respawntime + respawntimejitter
192 floatfield Item_CounterField(float it)
196 case IT_SHELLS: return ammo_shells;
197 case IT_NAILS: return ammo_nails;
198 case IT_ROCKETS: return ammo_rockets;
199 case IT_CELLS: return ammo_cells;
200 case IT_FUEL: return ammo_fuel;
201 case IT_5HP: return health;
202 case IT_25HP: return health;
203 case IT_HEALTH: return health;
204 case IT_ARMOR_SHARD: return armorvalue;
205 case IT_ARMOR: return armorvalue;
206 // add more things here (health, armor)
207 default: error("requested item has no counter field");
211 string Item_CounterFieldName(float it)
215 case IT_SHELLS: return "shells";
216 case IT_NAILS: return "nails";
217 case IT_ROCKETS: return "rockets";
218 case IT_CELLS: return "cells";
219 case IT_FUEL: return "fuel";
221 // add more things here (health, armor)
222 default: error("requested item has no counter field name");
226 .float max_armorvalue;
227 .float pickup_anyway;
229 float Item_Customize()
231 if(self.spawnshieldtime)
233 if(self.weapons != (self.weapons & other.weapons))
235 self.colormod = '0 0 0';
236 self.glowmod = self.colormod;
237 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
244 self.colormod = stov(autocvar_g_ghost_items_color);
245 self.glowmod = self.colormod;
246 self.alpha = g_ghost_items;
255 void Item_Show (entity e, float mode)
257 e.effects &~= EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST;
260 // make the item look normal, and be touchable
262 e.solid = SOLID_TRIGGER;
263 e.colormod = '0 0 0';
264 self.glowmod = self.colormod;
267 e.spawnshieldtime = 1;
268 self.ItemStatus |= ITS_AVAILABLE;
272 // hide the item completely
273 e.model = string_null;
275 e.colormod = '0 0 0';
276 self.glowmod = self.colormod;
280 e.spawnshieldtime = 1;
281 self.ItemStatus &~= ITS_AVAILABLE;
283 else if((e.flags & FL_WEAPON) && !(e.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
285 // make the item translucent and not touchable
287 e.solid = SOLID_TRIGGER; // can STILL be picked up!
288 e.colormod = '0 0 0';
289 self.glowmod = self.colormod;
290 e.effects |= EF_STARDUST;
293 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
294 self.ItemStatus |= ITS_AVAILABLE;
298 // hide the item completely
299 //e.model = string_null;
302 e.colormod = '0 0 0';
303 e.glowmod = e.colormod;
306 e.spawnshieldtime = 1;
307 self.ItemStatus &~= ITS_AVAILABLE;
310 if (e.items & (IT_STRENGTH | IT_INVINCIBLE))
312 e.effects |= EF_ADDITIVE | EF_FULLBRIGHT;
313 self.ItemStatus |= ITS_POWERUP;
316 if (autocvar_g_nodepthtestitems)
317 e.effects |= EF_NODEPTHTEST;
319 if (autocvar_g_fullbrightitems)
321 e.effects |= EF_FULLBRIGHT;
322 self.ItemStatus |= ITS_ALLOWFB;
325 // relink entity (because solid may have changed)
326 setorigin(e, e.origin);
327 self.SendFlags |= ISF_STATUS;
331 void Item_Respawn (void)
334 if(!g_minstagib && self.items == IT_STRENGTH)
335 sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
336 else if(!g_minstagib && self.items == IT_INVINCIBLE)
337 sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
339 sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
340 setorigin (self, self.origin);
342 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
343 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
346 void Item_RespawnCountdown (void)
348 if(self.count >= ITEM_RESPAWN_TICKS)
350 if(self.waypointsprite_attached)
351 WaypointSprite_Kill(self.waypointsprite_attached);
356 self.nextthink = time + 1;
367 case IT_STRENGTH: name = "item-invis"; rgb = '0 0 1'; break;
368 case IT_NAILS: name = "item-extralife"; rgb = '1 0 0'; break;
369 case IT_INVINCIBLE: name = "item-speed"; rgb = '1 0 1'; break;
376 case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
377 case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
382 case IT_FUEL_REGEN: name = "item-fuelregen"; rgb = '1 0.5 0'; break;
383 case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
385 if(self.flags & FL_WEAPON)
387 entity wi = get_weaponinfo(self.weapon);
396 print("Unknown powerup-marked item is wanting to respawn\n");
397 localcmd(sprintf("prvm_edict server %d\n", num_for_edict(self)));
401 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
402 if(self.waypointsprite_attached)
403 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
406 sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTN_NORM); // play respawn sound
407 if(self.waypointsprite_attached)
409 WaypointSprite_Ping(self.waypointsprite_attached);
410 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
415 void Item_ScheduleRespawnIn(entity e, float t)
417 if((e.flags & FL_POWERUP) || (e.weapons & WEPBIT_SUPERWEAPONS))
419 e.think = Item_RespawnCountdown;
420 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
425 e.think = Item_Respawn;
426 e.nextthink = time + t;
430 void Item_ScheduleRespawn(entity e)
432 if(e.respawntime > 0)
435 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
437 else // if respawntime is -1, this item does not respawn
441 void Item_ScheduleInitialRespawn(entity e)
444 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
447 float ITEM_MODE_NONE = 0;
448 float ITEM_MODE_HEALTH = 1;
449 float ITEM_MODE_ARMOR = 2;
450 float ITEM_MODE_FUEL = 3;
451 float Item_GiveAmmoTo(entity item, entity player, .float ammofield, float ammomax, float mode)
456 if (item.spawnshieldtime)
458 if ((player.ammofield < ammomax) || item.pickup_anyway)
460 player.ammofield = bound(player.ammofield, ammomax, player.ammofield + item.ammofield);
464 else if(g_weapon_stay == 2)
466 float mi = min(item.ammofield, ammomax);
467 if (player.ammofield < mi)
469 player.ammofield = mi;
480 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
482 case ITEM_MODE_HEALTH:
483 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
485 case ITEM_MODE_ARMOR:
486 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
494 float Item_GiveTo(entity item, entity player)
502 // if nothing happens to player, just return without taking the item
504 _switchweapon = FALSE;
508 float prevcells = player.ammo_cells;
510 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
511 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, 999, ITEM_MODE_NONE);
513 if(player.ammo_cells > prevcells)
515 _switchweapon = TRUE;
517 // play some cool sounds ;)
518 if (clienttype(player) == CLIENTTYPE_REAL)
520 if(player.health <= 5)
521 AnnounceTo(player, "lastsecond");
522 else if(player.health < 50)
523 AnnounceTo(player, "narrowly");
525 // sound not available
526 // else if(item.items == IT_CELLS)
527 // AnnounceTo(player, "ammo");
529 if (item.weapons & WEPBIT_MINSTANEX)
530 W_GiveWeapon (player, WEP_MINSTANEX, item.netname);
534 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
538 sprint (player, strcat("You got the ^2", item.netname, "\n"));
545 // sound not available
546 // AnnounceTo(player, "_lives");
547 player.armorvalue = bound(player.armorvalue, 999, player.armorvalue + autocvar_g_minstagib_extralives);
548 sprint(player, "^3You picked up some extra lives\n");
552 if (item.strength_finished)
555 // sound not available
556 // AnnounceTo(player, "invisible");
557 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
561 if (item.invincible_finished)
564 // sound not available
565 // AnnounceTo(player, "speed");
566 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_strength_time;
571 // in case the player has autoswitch enabled do the following:
572 // if the player is using their best weapon before items are given, they
573 // probably want to switch to an even better weapon after items are given
574 if (player.autoswitch)
575 if (player.switchweapon == w_getbestweapon(player))
576 _switchweapon = TRUE;
578 if not(player.weapons & W_WeaponBit(player.switchweapon))
579 _switchweapon = TRUE;
581 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
582 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
583 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
584 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
585 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
586 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
587 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
589 if (item.flags & FL_WEAPON)
590 if ((it = item.weapons - (item.weapons & player.weapons)) || (item.spawnshieldtime && self.pickup_anyway))
593 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
595 e = get_weaponinfo(i);
597 W_GiveWeapon (player, e.weapon, item.netname);
601 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
605 sprint (player, strcat("You got the ^2", item.netname, "\n"));
608 if (item.strength_finished)
611 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
613 if (item.invincible_finished)
616 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
618 if (item.superweapons_finished)
621 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
626 // always eat teamed entities
634 if (player.switchweapon != w_getbestweapon(player))
635 W_SwitchWeapon_Force(player, w_getbestweapon(player));
640 void Item_Touch (void)
644 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
645 if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
650 if (other.classname != "player")
654 if (self.solid != SOLID_TRIGGER)
656 if (self.owner == other)
659 if (self.classname == "droppedweapon")
661 self.strength_finished = max(0, self.strength_finished - time);
662 self.invincible_finished = max(0, self.invincible_finished - time);
663 self.superweapons_finished = max(0, self.superweapons_finished - time);
666 if(!Item_GiveTo(self, other))
668 if (self.classname == "droppedweapon")
670 // undo what we did above
671 self.strength_finished += time;
672 self.invincible_finished += time;
673 self.superweapons_finished += time;
678 other.last_pickup = time;
680 pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
681 sound (other, CH_TRIGGER, self.item_pickupsound, VOL_BASE, ATTN_NORM);
683 if (self.classname == "droppedweapon")
685 else if not(self.spawnshieldtime)
691 RandomSelection_Init();
692 for(head = world; (head = findfloat(head, team, self.team)); )
694 if(head.flags & FL_ITEM)
697 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
700 e = RandomSelection_chosen_ent;
705 Item_ScheduleRespawn(e);
711 Item_Show(self, !self.state);
712 setorigin (self, self.origin);
714 if(self.classname != "droppedweapon")
716 self.think = SUB_Null;
719 if(self.waypointsprite_attached)
720 WaypointSprite_Kill(self.waypointsprite_attached);
722 if((self.flags & FL_POWERUP) | (self.weapons & WEPBIT_SUPERWEAPONS)) // do not spawn powerups initially!
723 Item_ScheduleInitialRespawn(self);
731 if(self.effects & EF_NODRAW)
733 // marker for item team search
734 dprint("Initializing item team ", ftos(self.team), "\n");
735 RandomSelection_Init();
736 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
737 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
738 e = RandomSelection_chosen_ent;
742 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
746 // make it a non-spawned item
748 head.state = 1; // state 1 = initially hidden item
750 head.effects &~= EF_NODRAW;
757 // Savage: used for item garbage-collection
758 // TODO: perhaps nice special effect?
759 void RemoveItem(void)
764 // pickup evaluation functions
765 // these functions decide how desirable an item is to the bots
767 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
769 float weapon_pickupevalfunc(entity player, entity item)
771 float c, i, j, position;
773 // See if I have it already
774 if(player.weapons & item.weapons == item.weapons)
776 // If I can pick it up
777 if(!item.spawnshieldtime)
779 else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
781 // Skilled bots will grab more
782 c = bound(0, skill / 10, 1) * 0.5;
790 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
791 if( bot_custom_weapon && c )
793 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
796 if( (get_weaponinfo(i)).weapons & item.weapons != item.weapons )
799 // Find the highest position on any range
801 for(j = 0; j < WEP_LAST ; ++j){
803 bot_weapons_far[j] == i ||
804 bot_weapons_mid[j] == i ||
805 bot_weapons_close[j] == i
816 position = WEP_LAST - position;
817 // item.bot_pickupbasevalue is overwritten here
818 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
823 return item.bot_pickupbasevalue * c;
826 float commodity_pickupevalfunc(entity player, entity item)
828 float c, i, need_shells, need_nails, need_rockets, need_cells, need_fuel;
832 // Detect needed ammo
833 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
835 wi = get_weaponinfo(i);
837 if not(wi.weapons & player.weapons)
840 if(wi.items & IT_SHELLS)
842 else if(wi.items & IT_NAILS)
844 else if(wi.items & IT_ROCKETS)
846 else if(wi.items & IT_CELLS)
848 else if(wi.items & IT_FUEL)
852 // TODO: figure out if the player even has the weapon this ammo is for?
853 // may not affect strategy much though...
854 // find out how much more ammo/armor/health the player can hold
856 if (item.ammo_shells)
857 if (player.ammo_shells < g_pickup_shells_max)
858 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
861 if (player.ammo_nails < g_pickup_nails_max)
862 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
864 if (item.ammo_rockets)
865 if (player.ammo_rockets < g_pickup_rockets_max)
866 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
869 if (player.ammo_cells < g_pickup_cells_max)
870 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
873 if (player.ammo_fuel < g_pickup_fuel_max)
874 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
876 if (player.armorvalue < item.max_armorvalue)
877 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
879 if (player.health < item.max_health)
880 c = c + max(0, 1 - player.health / item.max_health);
882 return item.bot_pickupbasevalue * c;
887 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)
889 startitem_failed = FALSE;
892 self.weapons = weaponid;
893 self.flags = FL_ITEM | itemflags;
895 // is it a dropped weapon?
896 if (self.classname == "droppedweapon")
898 self.reset = SUB_Remove;
899 // it's a dropped weapon
900 self.movetype = MOVETYPE_TOSS;
902 // Savage: remove thrown items after a certain period of time ("garbage collection")
903 self.think = RemoveItem;
904 self.nextthink = time + 20;
906 if(self.strength_finished || self.invincible_finished || self.superweapons_finished)
909 if(self.weapons == (self.weapons & WEPBIT_SUPERWEAPONS)) // only superweapons
910 if(self.ammo_nails == 0)
911 if(self.ammo_cells == 0)
912 if(self.ammo_rockets == 0)
913 if(self.ammo_shells == 0)
914 if(self.ammo_fuel == 0)
916 if(self.armorvalue == 0)
919 // if item is worthless after a timer, have it expire then
920 self.nextthink = max(self.strength_finished, self.invincible_finished, self.superweapons_finished);
923 // don't drop if in a NODROP zone (such as lava)
924 traceline(self.origin, self.origin, MOVE_NORMAL, self);
925 if (trace_dpstartcontents & DPCONTENTS_NODROP)
927 startitem_failed = TRUE;
934 if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
936 startitem_failed = TRUE;
941 if(!have_pickup_item())
943 startitem_failed = TRUE;
949 itemmodel = self.model;
950 if(self.item_pickupsound != "")
951 pickupsound = self.item_pickupsound;
953 self.reset = Item_Reset;
955 if(self.spawnflags & 1)
958 self.movetype = MOVETYPE_NONE;
960 self.movetype = MOVETYPE_TOSS;
961 // do item filtering according to game mode and other things
964 // first nudge it off the floor a little bit to avoid math errors
965 setorigin(self, self.origin + '0 0 1');
966 // set item size before we spawn a spawnfunc_waypoint
967 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
968 setsize (self, '-16 -16 0', '16 16 48');
970 setsize (self, '-16 -16 0', '16 16 32');
971 // note droptofloor returns FALSE if stuck/or would fall too far
973 waypoint_spawnforitem(self);
977 * can't do it that way, as it would break maps
978 * TODO make a target_give like entity another way, that perhaps has
979 * the weapon name in a key
982 // target_give not yet supported; maybe later
983 print("removed targeted ", self.classname, "\n");
984 startitem_failed = TRUE;
990 if(autocvar_spawn_debug >= 2)
993 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
995 if(otheritem.is_item)
997 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
998 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
999 error("Mapper sucks.");
1002 self.is_item = TRUE;
1005 weaponsInMap |= weaponid;
1007 precache_model (itemmodel);
1008 precache_sound (pickupsound);
1010 precache_sound ("misc/itemrespawncountdown.wav");
1011 if(!g_minstagib && itemid == IT_STRENGTH)
1012 precache_sound ("misc/strength_respawn.wav");
1013 else if(!g_minstagib && itemid == IT_INVINCIBLE)
1014 precache_sound ("misc/shield_respawn.wav");
1016 precache_sound ("misc/itemrespawn.wav");
1018 if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
1019 self.target = "###item###"; // for finding the nearest item using find()
1022 self.bot_pickup = TRUE;
1023 self.bot_pickupevalfunc = pickupevalfunc;
1024 self.bot_pickupbasevalue = pickupbasevalue;
1025 self.mdl = itemmodel;
1026 self.item_pickupsound = pickupsound;
1028 self.weapon = WEP_FIRST + log2of(lowestbit(self.weapons));
1031 // let mappers override respawntime
1032 if(!self.respawntime) // both set
1034 self.respawntime = defaultrespawntime;
1035 self.respawntimejitter = defaultrespawntimejitter;
1037 self.netname = itemname;
1038 self.touch = Item_Touch;
1039 setmodel (self, self.mdl); // precision set below
1040 self.effects |= EF_LOWPRECISION;
1042 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1043 setsize (self, '-16 -16 0', '16 16 48');
1045 setsize (self, '-16 -16 0', '16 16 32');
1047 if(itemflags & FL_POWERUP)
1048 self.ItemStatus |= ITS_ANIMATE1;
1050 if(self.armorvalue || self.health)
1051 self.ItemStatus |= ITS_ANIMATE2;
1053 if(itemflags & FL_WEAPON)
1055 self.ItemStatus |= ITS_ANIMATE1;
1056 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1057 self.colormap = 1024; // color shirt=0 pants=0 grey
1064 self.cnt = 1; // item probability weight
1065 self.effects = self.effects | EF_NODRAW; // marker for item team search
1066 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
1071 if(self.classname == "droppedweapon")
1074 Net_LinkEntity(self, FALSE, 0, ItemSend);
1078 /* replace items in minstagib
1079 * IT_STRENGTH = invisibility
1080 * IT_NAILS = extra lives
1081 * IT_INVINCIBLE = speed
1083 void minstagib_items (float itemid)
1086 self.classname = "minstagib";
1088 // replace rocket launchers and nex guns with ammo cells
1089 if (itemid == IT_CELLS)
1091 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1092 StartItem ("models/items/a_cells.md3",
1093 "misc/itempickup.wav", 45, 0,
1094 "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
1101 itemid = IT_STRENGTH;
1105 itemid = IT_INVINCIBLE;
1107 // replace with invis
1108 if (itemid == IT_STRENGTH)
1110 if(!self.strength_finished)
1111 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1112 StartItem ("models/items/g_strength.md3",
1113 "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1114 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1116 // replace with extra lives
1117 if (itemid == IT_NAILS)
1119 self.max_health = 1;
1120 StartItem ("models/items/g_h100.md3",
1121 "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1122 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1124 // replace with speed
1125 if (itemid == IT_INVINCIBLE)
1127 if(!self.invincible_finished)
1128 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1129 StartItem ("models/items/g_invincible.md3",
1130 "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1131 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1135 float minst_no_auto_cells;
1136 void minst_remove_item (void) {
1137 if(minst_no_auto_cells)
1141 float weaponswapping;
1144 void weapon_defaultspawnfunc(float wpn)
1148 var .float ammofield;
1154 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
1156 e = get_weaponinfo(wpn);
1157 s = cvar_string(strcat("g_weaponreplace_", e.netname));
1161 startitem_failed = TRUE;
1164 t = tokenize_console(s);
1167 self.team = --internalteam;
1169 for(i = 1; i < t; ++i)
1172 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1174 e = get_weaponinfo(j);
1178 copyentity(oldself, self);
1179 self.classname = "replacedweapon";
1180 weapon_defaultspawnfunc(j);
1186 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1195 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1197 e = get_weaponinfo(j);
1206 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1212 startitem_failed = TRUE;
1217 e = get_weaponinfo(wpn);
1219 if(!self.respawntime)
1221 if(e.weapons & WEPBIT_SUPERWEAPONS)
1223 self.respawntime = g_pickup_respawntime_superweapon;
1224 self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
1228 self.respawntime = g_pickup_respawntime_weapon;
1229 self.respawntimejitter = g_pickup_respawntimejitter_weapon;
1233 if(e.weapons & WEPBIT_SUPERWEAPONS)
1234 if(!self.superweapons_finished)
1235 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1239 for(i = 0, j = 1; i < 24; ++i, j *= 2)
1243 ammofield = Item_CounterField(j);
1245 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
1251 if(g_pickup_weapons_anyway)
1252 self.pickup_anyway = TRUE;
1256 // no weapon-stay on superweapons
1257 if(e.weapons & WEPBIT_SUPERWEAPONS)
1258 f |= FL_NO_WEAPON_STAY;
1260 // weapon stay isn't supported for teamed weapons
1262 f |= FL_NO_WEAPON_STAY;
1264 // stupid minstagib hack, don't ask
1267 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1269 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapons, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
1270 if (self.modelindex) // don't precache if self was removed
1271 weapon_action(e.weapon, WR_PRECACHE);
1274 void spawnfunc_weapon_shotgun (void);
1275 void spawnfunc_weapon_uzi (void) {
1276 if(autocvar_sv_q3acompat_machineshotgunswap)
1277 if(self.classname != "droppedweapon")
1279 weapon_defaultspawnfunc(WEP_SHOTGUN);
1282 weapon_defaultspawnfunc(WEP_UZI);
1285 void spawnfunc_weapon_shotgun (void) {
1286 if(autocvar_sv_q3acompat_machineshotgunswap)
1287 if(self.classname != "droppedweapon")
1289 weapon_defaultspawnfunc(WEP_UZI);
1292 weapon_defaultspawnfunc(WEP_SHOTGUN);
1295 void spawnfunc_weapon_nex (void)
1299 minstagib_items(IT_CELLS);
1300 self.think = minst_remove_item;
1301 self.nextthink = time;
1304 weapon_defaultspawnfunc(WEP_NEX);
1307 void spawnfunc_weapon_minstanex (void)
1311 minstagib_items(IT_CELLS);
1312 self.think = minst_remove_item;
1313 self.nextthink = time;
1316 weapon_defaultspawnfunc(WEP_MINSTANEX);
1319 void spawnfunc_weapon_rocketlauncher (void)
1323 minstagib_items(IT_CELLS); // replace rocketlauncher with cells
1324 self.think = minst_remove_item;
1325 self.nextthink = time;
1328 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
1331 void spawnfunc_item_rockets (void) {
1332 if(!self.ammo_rockets)
1333 self.ammo_rockets = g_pickup_rockets;
1334 if(!self.pickup_anyway)
1335 self.pickup_anyway = g_pickup_ammo_anyway;
1336 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);
1339 void spawnfunc_item_shells (void);
1340 void spawnfunc_item_bullets (void) {
1342 if(autocvar_sv_q3acompat_machineshotgunswap)
1343 if(self.classname != "droppedweapon")
1345 weaponswapping = TRUE;
1346 spawnfunc_item_shells();
1347 weaponswapping = FALSE;
1351 if(!self.ammo_nails)
1352 self.ammo_nails = g_pickup_nails;
1353 if(!self.pickup_anyway)
1354 self.pickup_anyway = g_pickup_ammo_anyway;
1355 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);
1358 void spawnfunc_item_cells (void) {
1359 if(!self.ammo_cells)
1360 self.ammo_cells = g_pickup_cells;
1361 if(!self.pickup_anyway)
1362 self.pickup_anyway = g_pickup_ammo_anyway;
1363 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);
1366 void spawnfunc_item_shells (void) {
1368 if(autocvar_sv_q3acompat_machineshotgunswap)
1369 if(self.classname != "droppedweapon")
1371 weaponswapping = TRUE;
1372 spawnfunc_item_bullets();
1373 weaponswapping = FALSE;
1377 if(!self.ammo_shells)
1378 self.ammo_shells = g_pickup_shells;
1379 if(!self.pickup_anyway)
1380 self.pickup_anyway = g_pickup_ammo_anyway;
1381 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);
1384 void spawnfunc_item_armor_small (void) {
1385 if(!self.armorvalue)
1386 self.armorvalue = g_pickup_armorsmall;
1387 if(!self.max_armorvalue)
1388 self.max_armorvalue = g_pickup_armorsmall_max;
1389 if(!self.pickup_anyway)
1390 self.pickup_anyway = g_pickup_armorsmall_anyway;
1391 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);
1394 void spawnfunc_item_armor_medium (void) {
1395 if(!self.armorvalue)
1396 self.armorvalue = g_pickup_armormedium;
1397 if(!self.max_armorvalue)
1398 self.max_armorvalue = g_pickup_armormedium_max;
1399 if(!self.pickup_anyway)
1400 self.pickup_anyway = g_pickup_armormedium_anyway;
1401 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);
1404 void spawnfunc_item_armor_big (void) {
1405 if(!self.armorvalue)
1406 self.armorvalue = g_pickup_armorbig;
1407 if(!self.max_armorvalue)
1408 self.max_armorvalue = g_pickup_armorbig_max;
1409 if(!self.pickup_anyway)
1410 self.pickup_anyway = g_pickup_armorbig_anyway;
1411 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);
1414 void spawnfunc_item_armor_large (void) {
1415 if(!self.armorvalue)
1416 self.armorvalue = g_pickup_armorlarge;
1417 if(!self.max_armorvalue)
1418 self.max_armorvalue = g_pickup_armorlarge_max;
1419 if(!self.pickup_anyway)
1420 self.pickup_anyway = g_pickup_armorlarge_anyway;
1421 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);
1424 void spawnfunc_item_health_small (void) {
1425 if(!self.max_health)
1426 self.max_health = g_pickup_healthsmall_max;
1428 self.health = g_pickup_healthsmall;
1429 if(!self.pickup_anyway)
1430 self.pickup_anyway = g_pickup_healthsmall_anyway;
1431 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);
1434 void spawnfunc_item_health_medium (void) {
1435 if(!self.max_health)
1436 self.max_health = g_pickup_healthmedium_max;
1438 self.health = g_pickup_healthmedium;
1439 if(!self.pickup_anyway)
1440 self.pickup_anyway = g_pickup_healthmedium_anyway;
1441 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);
1444 void spawnfunc_item_health_large (void) {
1445 if(!self.max_health)
1446 self.max_health = g_pickup_healthlarge_max;
1448 self.health = g_pickup_healthlarge;
1449 if(!self.pickup_anyway)
1450 self.pickup_anyway = g_pickup_healthlarge_anyway;
1451 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);
1454 void spawnfunc_item_health_mega (void) {
1456 minstagib_items(IT_NAILS);
1458 if(!self.max_health)
1459 self.max_health = g_pickup_healthmega_max;
1461 self.health = g_pickup_healthmega;
1462 if(!self.pickup_anyway)
1463 self.pickup_anyway = g_pickup_healthmega_anyway;
1464 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);
1468 // support old misnamed entities
1469 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1470 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1471 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1472 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1473 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1475 void spawnfunc_item_strength (void) {
1477 minstagib_items(IT_STRENGTH);
1479 precache_sound("weapons/strength_fire.wav");
1480 if(!self.strength_finished)
1481 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1482 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);
1486 void spawnfunc_item_invincible (void) {
1488 minstagib_items(IT_INVINCIBLE);
1490 if(!self.invincible_finished)
1491 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1492 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);
1496 void spawnfunc_item_minst_cells (void) {
1499 minst_no_auto_cells = 1;
1500 minstagib_items(IT_CELLS);
1507 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1509 float GiveItems(entity e, float beginarg, float endarg);
1510 void target_items_use (void)
1512 if(activator.classname == "droppedweapon")
1519 if(activator.classname != "player")
1521 if(activator.deadflag != DEAD_NO)
1526 for(e = world; (e = find(e, classname, "droppedweapon")); )
1527 if(e.enemy == activator)
1530 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1531 centerprint(activator, self.message);
1534 void spawnfunc_target_items (void)
1539 self.use = target_items_use;
1540 if(!self.strength_finished)
1541 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1542 if(!self.invincible_finished)
1543 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1544 if(!self.superweapons_finished)
1545 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1547 precache_sound("misc/itempickup.wav");
1548 precache_sound("misc/megahealth.wav");
1549 precache_sound("misc/armor25.wav");
1550 precache_sound("misc/powerup.wav");
1551 precache_sound("misc/poweroff.wav");
1552 precache_sound("weapons/weaponpickup.wav");
1554 n = tokenize_console(self.netname);
1555 if(argv(0) == "give")
1557 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1561 for(i = 0; i < n; ++i)
1563 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1564 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1565 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1566 else if(argv(i) == "strength") self.items |= IT_STRENGTH;
1567 else if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1568 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1569 else if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1570 else if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1572 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1574 e = get_weaponinfo(j);
1575 if(argv(i) == e.netname)
1577 self.weapons |= e.weapons;
1578 if(self.spawnflags == 0 || self.spawnflags == 2)
1579 weapon_action(e.weapon, WR_PRECACHE);
1584 print("target_items: invalid item ", argv(i), "\n");
1587 string itemprefix, valueprefix;
1588 if(self.spawnflags == 0)
1593 else if(self.spawnflags == 1)
1595 itemprefix = "max ";
1596 valueprefix = "max ";
1598 else if(self.spawnflags == 2)
1600 itemprefix = "min ";
1601 valueprefix = "min ";
1603 else if(self.spawnflags == 4)
1605 itemprefix = "minus ";
1606 valueprefix = "max ";
1609 error("invalid spawnflags");
1612 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1613 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1614 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * !!(self.items & IT_STRENGTH), "strength");
1615 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * !!(self.items & IT_INVINCIBLE), "invincible");
1616 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * !!(self.items & IT_SUPERWEAPON), "superweapons");
1617 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_JETPACK), "jetpack");
1618 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_FUEL_REGEN), "fuel_regen");
1619 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1620 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1621 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1622 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1623 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1624 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1625 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1626 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1628 e = get_weaponinfo(j);
1630 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & e.weapons), e.netname);
1633 self.netname = strzone(self.netname);
1634 //print(self.netname, "\n");
1636 n = tokenize_console(self.netname);
1637 for(i = 0; i < n; ++i)
1639 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1641 e = get_weaponinfo(j);
1642 if(argv(i) == e.netname)
1644 weapon_action(e.weapon, WR_PRECACHE);
1651 void spawnfunc_item_fuel(void)
1654 self.ammo_fuel = g_pickup_fuel;
1655 if(!self.pickup_anyway)
1656 self.pickup_anyway = g_pickup_ammo_anyway;
1657 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);
1660 void spawnfunc_item_fuel_regen(void)
1662 if(start_items & IT_FUEL_REGEN)
1664 spawnfunc_item_fuel();
1667 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);
1670 void spawnfunc_item_jetpack(void)
1672 if(g_grappling_hook)
1673 return; // sorry, but these two can't coexist (same button); spawn fuel instead
1675 self.ammo_fuel = g_pickup_fuel_jetpack;
1676 if(start_items & IT_JETPACK)
1678 spawnfunc_item_fuel();
1681 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);
1691 float GiveBit(entity e, .float fld, float bit, float op, float val)
1721 float GiveValue(entity e, .float fld, float op, float val)
1731 e.fld = max(e.fld, val); // min 100 cells = at least 100 cells
1734 e.fld = min(e.fld, val);
1747 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
1754 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTN_NORM);
1756 else if(v0 >= v0 + t)
1759 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTN_NORM);
1763 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1766 e.rotfield = max(e.rotfield, time + rottime);
1768 e.regenfield = max(e.regenfield, time + regentime);
1771 #define PREGIVE(e,f) float save_##f; save_##f = (e).f
1772 #define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr)
1773 #define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
1774 #define POSTGIVE_VALUE_ROT(e,f,t,rotfield,rottime,regenfield,regentime,snd_incr,snd_decr) GiveRot((e), save_##f, (e).f, rotfield, rottime, regenfield, regentime); GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
1776 float GiveItems(entity e, float beginarg, float endarg)
1778 float got, i, j, val, op;
1779 float _switchweapon;
1788 _switchweapon = FALSE;
1790 if (e.switchweapon == w_getbestweapon(e))
1791 _switchweapon = TRUE;
1793 e.strength_finished = max(0, e.strength_finished - time);
1794 e.invincible_finished = max(0, e.invincible_finished - time);
1795 e.superweapons_finished = max(0, e.superweapons_finished - time);
1798 PREGIVE(e, weapons);
1799 PREGIVE(e, strength_finished);
1800 PREGIVE(e, invincible_finished);
1801 PREGIVE(e, superweapons_finished);
1802 PREGIVE(e, ammo_nails);
1803 PREGIVE(e, ammo_cells);
1804 PREGIVE(e, ammo_shells);
1805 PREGIVE(e, ammo_rockets);
1806 PREGIVE(e, ammo_fuel);
1807 PREGIVE(e, armorvalue);
1810 for(i = beginarg; i < endarg; ++i)
1814 if(cmd == "0" || stof(cmd))
1838 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1839 got += GiveValue(e, strength_finished, op, val);
1840 got += GiveValue(e, invincible_finished, op, val);
1841 got += GiveValue(e, superweapons_finished, op, val);
1842 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1844 got += GiveBit(e, items, IT_JETPACK, op, val);
1845 got += GiveValue(e, health, op, val);
1846 got += GiveValue(e, armorvalue, op, val);
1848 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1850 wi = get_weaponinfo(j);
1852 got += GiveBit(e, weapons, wi.weapons, op, val);
1855 got += GiveValue(e, ammo_cells, op, val);
1856 got += GiveValue(e, ammo_shells, op, val);
1857 got += GiveValue(e, ammo_nails, op, val);
1858 got += GiveValue(e, ammo_rockets, op, val);
1859 got += GiveValue(e, ammo_fuel, op, val);
1861 case "unlimited_ammo":
1862 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1864 case "unlimited_weapon_ammo":
1865 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1867 case "unlimited_superweapons":
1868 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1871 got += GiveBit(e, items, IT_JETPACK, op, val);
1874 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1877 got += GiveValue(e, strength_finished, op, val);
1880 got += GiveValue(e, invincible_finished, op, val);
1882 case "superweapons":
1883 got += GiveValue(e, superweapons_finished, op, val);
1886 got += GiveValue(e, ammo_cells, op, val);
1889 got += GiveValue(e, ammo_shells, op, val);
1893 got += GiveValue(e, ammo_nails, op, val);
1896 got += GiveValue(e, ammo_rockets, op, val);
1899 got += GiveValue(e, health, op, val);
1902 got += GiveValue(e, armorvalue, op, val);
1905 got += GiveValue(e, ammo_fuel, op, val);
1908 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1910 wi = get_weaponinfo(j);
1911 if(cmd == wi.netname)
1913 got += GiveBit(e, weapons, wi.weapons, op, val);
1918 print("give: invalid item ", cmd, "\n");
1925 POSTGIVE_BIT(e, items, IT_FUEL_REGEN, "misc/itempickup.wav", string_null);
1926 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
1927 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
1928 POSTGIVE_BIT(e, items, IT_JETPACK, "misc/itempickup.wav", string_null);
1929 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1931 wi = get_weaponinfo(j);
1934 POSTGIVE_BIT(e, weapons, wi.weapons, "weapons/weaponpickup.wav", string_null);
1935 if not(save_weapons & wi.weapons)
1936 if(e.weapons & wi.weapons)
1937 weapon_action(wi.weapon, WR_PRECACHE);
1940 POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
1941 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
1942 POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
1943 POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
1944 POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
1945 POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
1946 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);
1947 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);
1948 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);
1950 if(e.superweapons_finished <= 0)
1951 if(self.weapons & WEPBIT_SUPERWEAPONS)
1952 e.superweapons_finished = autocvar_g_balance_superweapons_time;
1956 e.health = bound(0, e.health, 100);
1957 e.armorvalue = bound(0, e.armorvalue, 999);
1960 if(e.strength_finished <= 0)
1961 e.strength_finished = 0;
1963 e.strength_finished += time;
1964 if(e.invincible_finished <= 0)
1965 e.invincible_finished = 0;
1967 e.invincible_finished += time;
1968 if(e.superweapons_finished <= 0)
1969 e.superweapons_finished = 0;
1971 e.superweapons_finished += time;
1973 if not(e.weapons & W_WeaponBit(e.switchweapon))
1974 _switchweapon = TRUE;
1976 W_SwitchWeapon_Force(e, w_getbestweapon(e));