1 #define ITEM_RESPAWN_TICKS 10
3 #define ITEM_RESPAWNTIME(i) ((i).respawntime + crandom() * (i).respawntimejitter)
4 // range: respawntime - respawntimejitter .. respawntime + respawntimejitter
5 #define ITEM_RESPAWNTIME_INITIAL(i) (ITEM_RESPAWN_TICKS + random() * ((i).respawntime + (i).respawntimejitter - ITEM_RESPAWN_TICKS))
6 // range: 10 .. respawntime + respawntimejitter
8 floatfield Item_CounterField(float it)
12 case IT_SHELLS: return ammo_shells;
13 case IT_NAILS: return ammo_nails;
14 case IT_ROCKETS: return ammo_rockets;
15 case IT_CELLS: return ammo_cells;
16 case IT_FUEL: return ammo_fuel;
17 case IT_5HP: return health;
18 case IT_25HP: return health;
19 case IT_HEALTH: return health;
20 case IT_ARMOR_SHARD: return armorvalue;
21 case IT_ARMOR: return armorvalue;
22 // add more things here (health, armor)
23 default: error("requested item has no counter field");
27 string Item_CounterFieldName(float it)
31 case IT_SHELLS: return "shells";
32 case IT_NAILS: return "nails";
33 case IT_ROCKETS: return "rockets";
34 case IT_CELLS: return "cells";
35 case IT_FUEL: return "fuel";
37 // add more things here (health, armor)
38 default: error("requested item has no counter field name");
42 .float max_armorvalue;
45 float Item_Customize()
47 if(self.spawnshieldtime)
49 if(self.weapons != (self.weapons & other.weapons))
51 self.colormod = '0 0 0';
52 self.glowmod = self.colormod;
53 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
60 self.colormod = stov(autocvar_g_ghost_items_color);
61 self.glowmod = self.colormod;
62 self.alpha = g_ghost_items;
70 void Item_Show (entity e, float mode)
72 e.effects &~= EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST;
75 // make the item look normal, and be touchable
77 e.solid = SOLID_TRIGGER;
79 self.glowmod = self.colormod;
81 e.customizeentityforclient = func_null;
83 e.spawnshieldtime = 1;
87 // hide the item completely
88 e.model = string_null;
91 self.glowmod = self.colormod;
93 e.customizeentityforclient = func_null;
95 e.spawnshieldtime = 1;
97 else if((e.flags & FL_WEAPON) && (g_weapon_stay == 3))
99 // make the item translucent and not touchable
101 e.solid = SOLID_TRIGGER; // can STILL be picked up!
102 e.colormod = '0 0 0';
103 self.glowmod = self.colormod;
104 e.effects |= EF_STARDUST;
105 e.customizeentityforclient = Item_Customize;
107 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
109 else if(g_ghost_items)
111 // make the item translucent and not touchable
114 e.colormod = stov(autocvar_g_ghost_items_color);
115 e.glowmod = e.colormod;
116 e.alpha = g_ghost_items;
117 e.customizeentityforclient = func_null;
119 e.spawnshieldtime = 1;
123 // hide the item completely
124 e.model = string_null;
126 e.colormod = '0 0 0';
127 e.glowmod = e.colormod;
129 e.customizeentityforclient = func_null;
131 e.spawnshieldtime = 1;
134 if (e.strength_finished || e.invincible_finished)
135 e.effects |= EF_ADDITIVE | EF_FULLBRIGHT;
136 if (autocvar_g_nodepthtestitems)
137 e.effects |= EF_NODEPTHTEST;
138 if (autocvar_g_fullbrightitems)
139 e.effects |= EF_FULLBRIGHT;
141 // relink entity (because solid may have changed)
142 setorigin(e, e.origin);
145 float it_armor_large_time;
146 float it_health_mega_time;
147 float it_strength_time;
148 float it_invisible_time;
149 float it_extralife_time;
151 float it_shield_time;
152 float it_fuelregen_time;
153 float it_jetpack_time;
155 void Item_ClearItemsTime()
157 self.item_armor_large_time = 0;
158 self.item_health_mega_time = 0;
159 self.item_strength_time = 0;
160 self.item_invisible_time = 0;
161 self.item_extralife_time = 0;
162 self.item_speed_time = 0;
163 self.item_shield_time = 0;
164 self.item_fuelregen_time = 0;
165 self.item_jetpack_time = 0;
167 void Item_GetItemsTime(entity e)
169 e.item_armor_large_time = it_armor_large_time;
170 e.item_health_mega_time = it_health_mega_time;
171 e.item_strength_time = it_strength_time;
172 e.item_invisible_time = it_invisible_time;
173 e.item_extralife_time = it_extralife_time;
174 e.item_speed_time = it_speed_time;
175 e.item_shield_time = it_shield_time;
176 e.item_fuelregen_time = it_fuelregen_time;
177 e.item_jetpack_time = it_jetpack_time;
179 void Item_UpdateTime(entity e, float t)
185 case IT_STRENGTH://"item-invis"
186 if (it_invisible_time > time && t > it_invisible_time)
188 it_invisible_time = t;
190 case IT_NAILS://"item-extralife"
191 if (it_extralife_time > time && t > it_extralife_time)
193 it_extralife_time = t;
195 case IT_INVINCIBLE://"item-speed"
196 if (it_speed_time > time && t > it_speed_time)
207 if (e.classname == "item_health_mega")
209 if (it_health_mega_time > time && t > it_health_mega_time)
211 it_health_mega_time = t;
215 if (e.classname == "item_armor_large")
217 if (it_armor_large_time > time && t > it_armor_large_time)
219 it_armor_large_time = t;
222 case IT_STRENGTH://"item-strength"
223 if (it_strength_time > time && t > it_strength_time)
225 it_strength_time = t;
227 case IT_INVINCIBLE://"item-shield"
228 if (it_shield_time > time && t > it_shield_time)
236 case IT_FUEL_REGEN://"item-fuelregen"
237 if (it_fuelregen_time > time && t > it_fuelregen_time)
239 it_fuelregen_time = t;
241 case IT_JETPACK://"item-jetpack"
242 if (it_jetpack_time > time && t > it_jetpack_time)
249 void Item_Respawn (void)
254 if(!g_minstagib && self.items == IT_STRENGTH)
255 sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
256 else if(!g_minstagib && self.items == IT_INVINCIBLE)
257 sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
259 sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
260 setorigin (self, self.origin);
262 if (self.flags & FL_POWERUP || self.classname == "item_armor_large" || self.classname == "item_health_mega")
264 for(t = 0, head = world; (head = find(head, classname, self.classname)); )
266 // in minstagib .classname is "minstagib" for every item
267 if (g_minstagib && self.items != head.items)
269 if (head.scheduledrespawntime > time)
270 if (t == 0 || head.scheduledrespawntime < t)
271 t = head.scheduledrespawntime;
273 Item_UpdateTime(self, t);
274 FOR_EACH_REALCLIENT(head)
276 if (head.classname != "player")
277 Item_GetItemsTime(head);
281 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
282 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
285 void Item_RespawnCountdown (void)
287 if(self.count >= ITEM_RESPAWN_TICKS)
289 if(self.waypointsprite_attached)
290 WaypointSprite_Kill(self.waypointsprite_attached);
295 self.nextthink = time + 1;
306 case IT_STRENGTH: name = "item-invis"; rgb = '0 0 1'; break;
307 case IT_NAILS: name = "item-extralife"; rgb = '1 0 0'; break;
308 case IT_INVINCIBLE: name = "item-speed"; rgb = '1 0 1'; break;
315 case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
316 case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
318 if (self.classname == "item_health_mega")
319 {name = "item_health_mega"; rgb = '1 0 0';}
322 if (self.classname == "item_armor_large")
323 {name = "item_armor_large"; rgb = '0 1 0';}
329 case IT_FUEL_REGEN: name = "item-fuelregen"; rgb = '1 0.5 0'; break;
330 case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
334 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
335 if(self.waypointsprite_attached)
337 if (self.items == IT_HEALTH || self.items == IT_ARMOR)
338 WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
339 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
343 sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTN_NORM); // play respawn sound
344 if(self.waypointsprite_attached)
346 WaypointSprite_Ping(self.waypointsprite_attached);
347 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
352 void Item_ScheduleRespawnIn(entity e, float t)
354 if(e.flags & FL_POWERUP || self.classname == "item_armor_large" || self.classname == "item_health_mega")
356 e.think = Item_RespawnCountdown;
357 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
358 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
363 e.think = Item_Respawn;
364 e.nextthink = time + t;
365 e.scheduledrespawntime = e.nextthink;
367 Item_UpdateTime(e, e.scheduledrespawntime);
368 FOR_EACH_REALCLIENT(e)
370 if (e.classname != "player")
371 Item_GetItemsTime(e);
375 void Item_ScheduleRespawn(entity e)
377 if(e.respawntime > 0)
380 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
382 else // if respawntime is -1, this item does not respawn
386 void Item_ScheduleInitialRespawn(entity e)
389 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
392 float Item_GiveTo(entity item, entity player)
400 // if nothing happens to player, just return without taking the item
402 _switchweapon = FALSE;
406 if(item.spawnshieldtime)
409 if (player.ammo_fuel < g_pickup_fuel_max)
412 player.ammo_fuel = bound(player.ammo_fuel, g_pickup_fuel_max, player.ammo_fuel + item.ammo_fuel);
413 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
415 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
419 sprint (player, strcat("You got the ^2", item.netname, "\n"));
422 _switchweapon = TRUE;
426 // play some cool sounds ;)
427 if (clienttype(player) == CLIENTTYPE_REAL)
429 if(player.health <= 5)
430 AnnounceTo(player, "lastsecond");
431 else if(player.health < 50)
432 AnnounceTo(player, "narrowly");
434 // sound not available
435 // else if(item.items == IT_CELLS)
436 // AnnounceTo(player, "ammo");
438 if (item.weapons & WEPBIT_MINSTANEX)
439 W_GiveWeapon (player, WEP_MINSTANEX, item.netname);
441 player.ammo_cells = bound(player.ammo_cells, 999, player.ammo_cells + autocvar_g_minstagib_ammo_drop);
449 // sound not available
450 // AnnounceTo(player, "_lives");
451 player.armorvalue = bound(player.armorvalue, 999, player.armorvalue + autocvar_g_minstagib_extralives);
452 sprint(player, "^3You picked up some extra lives\n");
456 if (item.strength_finished)
459 // sound not available
460 // AnnounceTo(player, "invisible");
461 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
465 if (item.invincible_finished)
468 // sound not available
469 // AnnounceTo(player, "speed");
470 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_strength_time;
476 if (g_weapon_stay == 1)
477 if not(item.flags & FL_NO_WEAPON_STAY)
478 if (item.flags & FL_WEAPON)
480 if(item.classname == "droppedweapon")
482 if (player.weapons & item.weapons) // don't let players stack ammo by tossing weapons
487 if (player.weapons & item.weapons)
492 // in case the player has autoswitch enabled do the following:
493 // if the player is using their best weapon before items are given, they
494 // probably want to switch to an even better weapon after items are given
495 if (player.autoswitch)
496 if (player.switchweapon == w_getbestweapon(player))
497 _switchweapon = TRUE;
499 if not(player.weapons & W_WeaponBit(player.switchweapon))
500 _switchweapon = TRUE;
502 if(item.spawnshieldtime)
504 if (item.ammo_shells)
505 if ((player.ammo_shells < g_pickup_shells_max) || item.pickup_anyway)
508 player.ammo_shells = bound(player.ammo_shells, g_pickup_shells_max, player.ammo_shells + item.ammo_shells);
511 if ((player.ammo_nails < g_pickup_nails_max) || item.pickup_anyway)
514 player.ammo_nails = bound(player.ammo_nails, g_pickup_nails_max, player.ammo_nails + item.ammo_nails);
516 if (item.ammo_rockets)
517 if ((player.ammo_rockets < g_pickup_rockets_max) || item.pickup_anyway)
520 player.ammo_rockets = bound(player.ammo_rockets, g_pickup_rockets_max, player.ammo_rockets + item.ammo_rockets);
523 if ((player.ammo_cells < g_pickup_cells_max) || item.pickup_anyway)
526 player.ammo_cells = bound(player.ammo_cells, g_pickup_cells_max, player.ammo_cells + item.ammo_cells);
529 if ((player.ammo_fuel < g_pickup_fuel_max) || item.pickup_anyway)
532 player.ammo_fuel = bound(player.ammo_fuel, g_pickup_fuel_max, player.ammo_fuel + item.ammo_fuel);
533 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
537 if (item.flags & FL_WEAPON)
538 if ((it = item.weapons - (item.weapons & player.weapons)) || (g_pickup_weapons_anyway && g_weapon_stay == 0))
541 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
543 e = get_weaponinfo(i);
545 W_GiveWeapon (player, e.weapon, item.netname);
549 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
553 sprint (player, strcat("You got the ^2", item.netname, "\n"));
556 if(item.spawnshieldtime)
558 if (item.strength_finished)
561 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
563 if (item.invincible_finished)
566 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_invincible_time;
570 if ((player.health < item.max_health) || item.pickup_anyway)
573 player.health = bound(player.health, item.max_health, player.health + item.health);
574 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
577 if ((player.armorvalue < item.max_armorvalue) || item.pickup_anyway)
580 player.armorvalue = bound(player.armorvalue, item.max_armorvalue, player.armorvalue + item.armorvalue);
581 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
587 // always eat teamed entities
594 sound (player, CH_TRIGGER, item.item_pickupsound, VOL_BASE, ATTN_NORM);
596 if (player.switchweapon != w_getbestweapon(player))
597 W_SwitchWeapon_Force(player, w_getbestweapon(player));
602 void Item_Touch (void)
606 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
607 if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
612 if (other.classname != "player")
616 if (self.solid != SOLID_TRIGGER)
618 if (self.owner == other)
621 if(!Item_GiveTo(self, other))
624 other.last_pickup = time;
626 pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
628 if (self.classname == "droppedweapon")
630 else if not(self.spawnshieldtime)
632 else if((self.flags & FL_WEAPON) && !(self.flags & FL_NO_WEAPON_STAY) && (g_weapon_stay == 1 || g_weapon_stay == 2))
638 RandomSelection_Init();
639 for(head = world; (head = findfloat(head, team, self.team)); )
641 if(head.flags & FL_ITEM)
644 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
647 e = RandomSelection_chosen_ent;
651 Item_ScheduleRespawn(e);
659 if(self.effects & EF_NODRAW)
661 // marker for item team search
662 dprint("Initializing item team ", ftos(self.team), "\n");
663 RandomSelection_Init();
664 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
665 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
666 e = RandomSelection_chosen_ent;
670 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
674 // make it a non-spawned item
676 head.state = 1; // state 1 = initially hidden item
678 head.effects &~= EF_NODRAW;
681 if(e.flags & FL_POWERUP) // do not spawn powerups initially!
682 Item_ScheduleInitialRespawn(e);
688 Item_Show(self, !self.state);
689 setorigin (self, self.origin);
690 self.think = SUB_Null;
693 if(self.flags & FL_POWERUP) // do not spawn powerups initially!
694 Item_ScheduleInitialRespawn(self);
697 // Savage: used for item garbage-collection
698 // TODO: perhaps nice special effect?
699 void RemoveItem(void)
704 // pickup evaluation functions
705 // these functions decide how desirable an item is to the bots
707 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
709 float weapon_pickupevalfunc(entity player, entity item)
711 float c, i, j, position;
713 // See if I have it already
714 if(player.weapons & item.weapons == item.weapons)
716 // If I can pick it up
717 if(g_weapon_stay == 1 || g_weapon_stay == 2 || !item.spawnshieldtime)
719 else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
721 // Skilled bots will grab more
722 c = bound(0, skill / 10, 1) * 0.5;
730 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
731 if( bot_custom_weapon && c )
733 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
736 if( (get_weaponinfo(i)).weapons & item.weapons != item.weapons )
739 // Find the highest position on any range
741 for(j = 0; j < WEP_LAST ; ++j){
743 bot_weapons_far[j] == i ||
744 bot_weapons_mid[j] == i ||
745 bot_weapons_close[j] == i
756 position = WEP_LAST - position;
757 // item.bot_pickupbasevalue is overwritten here
758 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
763 return item.bot_pickupbasevalue * c;
766 float commodity_pickupevalfunc(entity player, entity item)
768 float c, i, need_shells, need_nails, need_rockets, need_cells;
772 // Detect needed ammo
773 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
775 wi = get_weaponinfo(i);
777 if not(wi.weapons & player.weapons)
780 if(wi.items & IT_SHELLS)
782 else if(wi.items & IT_NAILS)
784 else if(wi.items & IT_ROCKETS)
786 else if(wi.items & IT_CELLS)
790 // TODO: figure out if the player even has the weapon this ammo is for?
791 // may not affect strategy much though...
792 // find out how much more ammo/armor/health the player can hold
794 if (item.ammo_shells)
795 if (player.ammo_shells < g_pickup_shells_max)
796 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
799 if (player.ammo_nails < g_pickup_nails_max)
800 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
802 if (item.ammo_rockets)
803 if (player.ammo_rockets < g_pickup_rockets_max)
804 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
807 if (player.ammo_cells < g_pickup_cells_max)
808 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
810 if (player.armorvalue < item.max_armorvalue)
811 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
813 if (player.health < item.max_health)
814 c = c + max(0, 1 - player.health / item.max_health);
816 return item.bot_pickupbasevalue * c;
821 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)
823 startitem_failed = FALSE;
826 self.weapons = weaponid;
828 // is it a dropped weapon?
829 if (self.classname == "droppedweapon")
831 self.reset = SUB_Remove;
832 // it's a dropped weapon
833 self.movetype = MOVETYPE_TOSS;
834 // Savage: remove thrown items after a certain period of time ("garbage collection")
835 self.think = RemoveItem;
836 self.nextthink = time + 60;
837 // don't drop if in a NODROP zone (such as lava)
838 traceline(self.origin, self.origin, MOVE_NORMAL, self);
839 if (trace_dpstartcontents & DPCONTENTS_NODROP)
841 startitem_failed = TRUE;
848 if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
850 startitem_failed = TRUE;
855 self.reset = Item_Reset;
857 if(self.spawnflags & 1)
860 self.movetype = MOVETYPE_NONE;
862 self.movetype = MOVETYPE_TOSS;
863 // do item filtering according to game mode and other things
866 // first nudge it off the floor a little bit to avoid math errors
867 setorigin(self, self.origin + '0 0 1');
868 // set item size before we spawn a spawnfunc_waypoint
869 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
870 setsize (self, '-16 -16 0', '16 16 48');
872 setsize (self, '-16 -16 0', '16 16 32');
873 // note droptofloor returns FALSE if stuck/or would fall too far
875 waypoint_spawnforitem(self);
879 * can't do it that way, as it would break maps
880 * TODO make a target_give like entity another way, that perhaps has
881 * the weapon name in a key
884 // target_give not yet supported; maybe later
885 print("removed targeted ", self.classname, "\n");
886 startitem_failed = TRUE;
892 if(autocvar_spawn_debug >= 2)
895 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
897 if(otheritem.is_item)
899 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
900 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
901 error("Mapper sucks.");
909 startitem_failed = TRUE;
913 else if (g_weaponarena && ((weaponid & WEPBIT_ALL) || (itemid & IT_AMMO)))
915 startitem_failed = TRUE;
919 else if (g_minstagib)
921 // don't remove dropped items and powerups
922 if (self.classname != "minstagib")
924 startitem_failed = TRUE;
929 else if (!autocvar_g_pickup_items && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
931 startitem_failed = TRUE;
936 weaponsInMap |= weaponid;
938 precache_model (itemmodel);
939 precache_sound (pickupsound);
941 precache_sound ("misc/itemrespawncountdown.wav");
942 if(!g_minstagib && itemid == IT_STRENGTH)
943 precache_sound ("misc/strength_respawn.wav");
944 else if(!g_minstagib && itemid == IT_INVINCIBLE)
945 precache_sound ("misc/shield_respawn.wav");
947 precache_sound ("misc/itemrespawn.wav");
949 if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
950 self.target = "###item###"; // for finding the nearest item using find()
953 self.bot_pickup = TRUE;
954 self.bot_pickupevalfunc = pickupevalfunc;
955 self.bot_pickupbasevalue = pickupbasevalue;
956 self.mdl = itemmodel;
957 self.item_pickupsound = pickupsound;
958 // let mappers override respawntime
959 if(!self.respawntime) // both set
961 self.respawntime = defaultrespawntime;
962 self.respawntimejitter = defaultrespawntimejitter;
964 self.netname = itemname;
965 self.flags = FL_ITEM | itemflags;
966 self.touch = Item_Touch;
967 setmodel (self, self.mdl); // precision set below
968 self.effects |= EF_LOWPRECISION;
969 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
970 setsize (self, '-16 -16 0', '16 16 48');
972 setsize (self, '-16 -16 0', '16 16 32');
973 if(itemflags & FL_WEAPON)
974 self.modelflags |= MF_ROTATE;
976 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
977 if (itemflags & FL_WEAPON)
979 // neutral team color for pickup weapons
980 self.colormap = 1024; // color shirt=0 pants=0 grey
988 self.cnt = 1; // item probability weight
989 self.effects = self.effects | EF_NODRAW; // marker for item team search
990 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
992 else if(self.flags & FL_POWERUP) // do not spawn powerups initially!
993 Item_ScheduleInitialRespawn(self);
996 /* replace items in minstagib
997 * IT_STRENGTH = invisibility
998 * IT_NAILS = extra lives
999 * IT_INVINCIBLE = speed
1001 void minstagib_items (float itemid)
1004 self.classname = "minstagib";
1006 // replace rocket launchers and nex guns with ammo cells
1007 if (itemid == IT_CELLS)
1009 self.ammo_cells = 1;
1010 StartItem ("models/items/a_cells.md3",
1011 "misc/itempickup.wav", 45, 0,
1012 "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
1019 itemid = IT_STRENGTH;
1023 itemid = IT_INVINCIBLE;
1025 // replace with invis
1026 if (itemid == IT_STRENGTH)
1028 self.strength_finished = 30;
1029 StartItem ("models/items/g_strength.md3",
1030 "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1031 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1033 // replace with extra lives
1034 if (itemid == IT_NAILS)
1036 self.max_health = 1;
1037 StartItem ("models/items/g_h100.md3",
1038 "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1039 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1041 // replace with speed
1042 if (itemid == IT_INVINCIBLE)
1044 self.invincible_finished = 30;
1045 StartItem ("models/items/g_invincible.md3",
1046 "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1047 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1051 float minst_no_auto_cells;
1052 void minst_remove_item (void) {
1053 if(minst_no_auto_cells)
1057 float weaponswapping;
1060 void weapon_defaultspawnfunc(float wpn)
1064 var .float ammofield;
1069 // set the respawntime in advance (so replaced weapons can copy it)
1071 if(!self.respawntime)
1073 e = get_weaponinfo(wpn);
1074 if(e.items == IT_SUPERWEAPON)
1076 self.respawntime = g_pickup_respawntime_powerup;
1077 self.respawntimejitter = g_pickup_respawntimejitter_powerup;
1081 self.respawntime = g_pickup_respawntime_weapon;
1082 self.respawntimejitter = g_pickup_respawntimejitter_weapon;
1086 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
1088 e = get_weaponinfo(wpn);
1089 s = cvar_string(strcat("g_weaponreplace_", e.netname));
1093 startitem_failed = TRUE;
1096 t = tokenize_console(s);
1099 self.team = --internalteam;
1101 for(i = 1; i < t; ++i)
1104 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1106 e = get_weaponinfo(j);
1110 copyentity(oldself, self);
1111 self.classname = "replacedweapon";
1112 weapon_defaultspawnfunc(j);
1118 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1127 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1129 e = get_weaponinfo(j);
1138 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1144 startitem_failed = TRUE;
1149 e = get_weaponinfo(wpn);
1151 if(e.items && e.items != IT_SUPERWEAPON)
1153 for(i = 0, j = 1; i < 24; ++i, j *= 2)
1157 ammofield = Item_CounterField(j);
1159 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
1165 self.flags |= FL_NO_WEAPON_STAY;
1168 // weapon stay isn't supported for teamed weapons
1170 self.flags |= FL_NO_WEAPON_STAY;
1172 if(g_weapon_stay == 2 && self.classname != "droppedweapon")
1174 self.ammo_shells = 0;
1175 self.ammo_nails = 0;
1176 self.ammo_cells = 0;
1177 self.ammo_rockets = 0;
1178 // weapon stay 2: don't use ammo on weapon pickups; instead
1179 // initialize all ammo types to the pickup ammo unless set by g_start_ammo_*
1182 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, e.bot_pickupbasevalue);
1183 if (self.modelindex) // don't precache if self was removed
1184 weapon_action(e.weapon, WR_PRECACHE);
1187 void spawnfunc_weapon_shotgun (void);
1188 void spawnfunc_weapon_uzi (void) {
1189 if(autocvar_sv_q3acompat_machineshotgunswap)
1190 if(self.classname != "droppedweapon")
1192 weapon_defaultspawnfunc(WEP_SHOTGUN);
1195 weapon_defaultspawnfunc(WEP_UZI);
1198 void spawnfunc_weapon_shotgun (void) {
1199 if(autocvar_sv_q3acompat_machineshotgunswap)
1200 if(self.classname != "droppedweapon")
1202 weapon_defaultspawnfunc(WEP_UZI);
1205 weapon_defaultspawnfunc(WEP_SHOTGUN);
1208 void spawnfunc_weapon_nex (void)
1212 minstagib_items(IT_CELLS);
1213 self.think = minst_remove_item;
1214 self.nextthink = time;
1217 weapon_defaultspawnfunc(WEP_NEX);
1220 void spawnfunc_weapon_minstanex (void)
1224 minstagib_items(IT_CELLS);
1225 self.think = minst_remove_item;
1226 self.nextthink = time;
1229 weapon_defaultspawnfunc(WEP_MINSTANEX);
1232 void spawnfunc_weapon_rocketlauncher (void)
1236 minstagib_items(IT_CELLS); // replace rocketlauncher with cells
1237 self.think = minst_remove_item;
1238 self.nextthink = time;
1241 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
1244 void spawnfunc_item_rockets (void) {
1245 if(!self.ammo_rockets)
1246 self.ammo_rockets = g_pickup_rockets;
1247 if(!self.pickup_anyway)
1248 self.pickup_anyway = g_pickup_ammo_anyway;
1249 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);
1252 void spawnfunc_item_shells (void);
1253 void spawnfunc_item_bullets (void) {
1255 if(autocvar_sv_q3acompat_machineshotgunswap)
1256 if(self.classname != "droppedweapon")
1258 weaponswapping = TRUE;
1259 spawnfunc_item_shells();
1260 weaponswapping = FALSE;
1264 if(!self.ammo_nails)
1265 self.ammo_nails = g_pickup_nails;
1266 if(!self.pickup_anyway)
1267 self.pickup_anyway = g_pickup_ammo_anyway;
1268 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);
1271 void spawnfunc_item_cells (void) {
1272 if(!self.ammo_cells)
1273 self.ammo_cells = g_pickup_cells;
1274 if(!self.pickup_anyway)
1275 self.pickup_anyway = g_pickup_ammo_anyway;
1276 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);
1279 void spawnfunc_item_shells (void) {
1281 if(autocvar_sv_q3acompat_machineshotgunswap)
1282 if(self.classname != "droppedweapon")
1284 weaponswapping = TRUE;
1285 spawnfunc_item_bullets();
1286 weaponswapping = FALSE;
1290 if(!self.ammo_shells)
1291 self.ammo_shells = g_pickup_shells;
1292 if(!self.pickup_anyway)
1293 self.pickup_anyway = g_pickup_ammo_anyway;
1294 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);
1297 void spawnfunc_item_armor_small (void) {
1298 if(!self.armorvalue)
1299 self.armorvalue = g_pickup_armorsmall;
1300 if(!self.max_armorvalue)
1301 self.max_armorvalue = g_pickup_armorsmall_max;
1302 if(!self.pickup_anyway)
1303 self.pickup_anyway = g_pickup_armorsmall_anyway;
1304 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);
1307 void spawnfunc_item_armor_medium (void) {
1308 if(!self.armorvalue)
1309 self.armorvalue = g_pickup_armormedium;
1310 if(!self.max_armorvalue)
1311 self.max_armorvalue = g_pickup_armormedium_max;
1312 if(!self.pickup_anyway)
1313 self.pickup_anyway = g_pickup_armormedium_anyway;
1314 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);
1317 void spawnfunc_item_armor_big (void) {
1318 if(!self.armorvalue)
1319 self.armorvalue = g_pickup_armorbig;
1320 if(!self.max_armorvalue)
1321 self.max_armorvalue = g_pickup_armorbig_max;
1322 if(!self.pickup_anyway)
1323 self.pickup_anyway = g_pickup_armorbig_anyway;
1324 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);
1327 void spawnfunc_item_armor_large (void) {
1328 if(!self.armorvalue)
1329 self.armorvalue = g_pickup_armorlarge;
1330 if(!self.max_armorvalue)
1331 self.max_armorvalue = g_pickup_armorlarge_max;
1332 if(!self.pickup_anyway)
1333 self.pickup_anyway = g_pickup_armorlarge_anyway;
1334 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);
1337 void spawnfunc_item_health_small (void) {
1338 if(!self.max_health)
1339 self.max_health = g_pickup_healthsmall_max;
1341 self.health = g_pickup_healthsmall;
1342 if(!self.pickup_anyway)
1343 self.pickup_anyway = g_pickup_healthsmall_anyway;
1344 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);
1347 void spawnfunc_item_health_medium (void) {
1348 if(!self.max_health)
1349 self.max_health = g_pickup_healthmedium_max;
1351 self.health = g_pickup_healthmedium;
1352 if(!self.pickup_anyway)
1353 self.pickup_anyway = g_pickup_healthmedium_anyway;
1354 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);
1357 void spawnfunc_item_health_large (void) {
1358 if(!self.max_health)
1359 self.max_health = g_pickup_healthlarge_max;
1361 self.health = g_pickup_healthlarge;
1362 if(!self.pickup_anyway)
1363 self.pickup_anyway = g_pickup_healthlarge_anyway;
1364 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);
1367 void spawnfunc_item_health_mega (void) {
1368 if(!autocvar_g_powerup_superhealth)
1371 if((g_arena || g_ca) && !autocvar_g_arena_powerups)
1375 minstagib_items(IT_NAILS);
1377 if(!self.max_health)
1378 self.max_health = g_pickup_healthmega_max;
1380 self.health = g_pickup_healthmega;
1381 if(!self.pickup_anyway)
1382 self.pickup_anyway = g_pickup_healthmega_anyway;
1383 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);
1387 // support old misnamed entities
1388 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1389 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1390 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1391 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1392 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1394 void spawnfunc_item_strength (void) {
1395 if(!autocvar_g_powerup_strength)
1398 if((g_arena || g_ca) && !autocvar_g_arena_powerups)
1402 minstagib_items(IT_STRENGTH);
1404 precache_sound("weapons/strength_fire.wav");
1405 self.strength_finished = 30;
1406 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);
1410 void spawnfunc_item_invincible (void) {
1411 if(!autocvar_g_powerup_shield)
1414 if((g_arena || g_ca) && !autocvar_g_arena_powerups)
1418 minstagib_items(IT_INVINCIBLE);
1420 self.invincible_finished = 30;
1421 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);
1425 void spawnfunc_item_minst_cells (void) {
1428 minst_no_auto_cells = 1;
1429 minstagib_items(IT_CELLS);
1436 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1438 float GiveItems(entity e, float beginarg, float endarg);
1439 void target_items_use (void)
1441 if(activator.classname == "droppedweapon")
1448 if(activator.classname != "player")
1450 if(activator.deadflag != DEAD_NO)
1455 for(e = world; (e = find(e, classname, "droppedweapon")); )
1456 if(e.enemy == activator)
1459 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1460 centerprint(activator, self.message);
1463 void spawnfunc_target_items (void)
1468 self.use = target_items_use;
1469 if(!self.strength_finished)
1470 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1471 if(!self.invincible_finished)
1472 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1474 precache_sound("misc/itempickup.wav");
1475 precache_sound("misc/megahealth.wav");
1476 precache_sound("misc/armor25.wav");
1477 precache_sound("misc/powerup.wav");
1478 precache_sound("misc/poweroff.wav");
1479 precache_sound("weapons/weaponpickup.wav");
1481 n = tokenize_console(self.netname);
1482 if(argv(0) == "give")
1484 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1488 for(i = 0; i < n; ++i)
1490 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1491 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1492 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1493 else if(argv(i) == "strength") self.items |= IT_STRENGTH;
1494 else if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1495 else if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1496 else if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1498 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1500 e = get_weaponinfo(j);
1501 if(argv(i) == e.netname)
1503 self.weapons |= e.weapons;
1504 if(self.spawnflags == 0 || self.spawnflags == 2)
1505 weapon_action(e.weapon, WR_PRECACHE);
1510 print("target_items: invalid item ", argv(i), "\n");
1513 string itemprefix, valueprefix;
1514 if(self.spawnflags == 0)
1519 else if(self.spawnflags == 1)
1521 itemprefix = "max ";
1522 valueprefix = "max ";
1524 else if(self.spawnflags == 2)
1526 itemprefix = "min ";
1527 valueprefix = "min ";
1529 else if(self.spawnflags == 4)
1531 itemprefix = "minus ";
1532 valueprefix = "max ";
1535 error("invalid spawnflags");
1538 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1539 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1540 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * !!(self.items & IT_STRENGTH), "strength");
1541 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * !!(self.items & IT_INVINCIBLE), "invincible");
1542 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_JETPACK), "jetpack");
1543 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_FUEL_REGEN), "fuel_regen");
1544 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1545 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1546 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1547 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1548 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1549 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1550 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1551 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1553 e = get_weaponinfo(j);
1555 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & e.weapons), e.netname);
1558 self.netname = strzone(self.netname);
1559 //print(self.netname, "\n");
1561 n = tokenize_console(self.netname);
1562 for(i = 0; i < n; ++i)
1564 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1566 e = get_weaponinfo(j);
1567 if(argv(i) == e.netname)
1569 weapon_action(e.weapon, WR_PRECACHE);
1576 void spawnfunc_item_fuel(void)
1579 self.ammo_fuel = g_pickup_fuel;
1580 if(!self.pickup_anyway)
1581 self.pickup_anyway = g_pickup_ammo_anyway;
1582 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);
1585 void spawnfunc_item_fuel_regen(void)
1587 if(start_items & IT_FUEL_REGEN)
1589 spawnfunc_item_fuel();
1592 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);
1595 void spawnfunc_item_jetpack(void)
1597 if(g_grappling_hook)
1598 return; // sorry, but these two can't coexist (same button); spawn fuel instead
1600 self.ammo_fuel = g_pickup_fuel_jetpack;
1601 if(start_items & IT_JETPACK)
1603 spawnfunc_item_fuel();
1606 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);
1616 float GiveBit(entity e, .float fld, float bit, float op, float val)
1646 float GiveValue(entity e, .float fld, float op, float val)
1656 e.fld = max(e.fld, val); // min 100 cells = at least 100 cells
1659 e.fld = min(e.fld, val);
1672 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
1679 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTN_NORM);
1681 else if(v0 >= v0 + t)
1684 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTN_NORM);
1688 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1691 e.rotfield = max(e.rotfield, time + rottime);
1693 e.regenfield = max(e.regenfield, time + regentime);
1696 #define PREGIVE(e,f) float save_##f; save_##f = (e).f
1697 #define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr)
1698 #define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
1699 #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)
1701 float GiveItems(entity e, float beginarg, float endarg)
1703 float got, i, j, val, op;
1704 float _switchweapon;
1713 _switchweapon = FALSE;
1715 if (e.switchweapon == w_getbestweapon(e))
1716 _switchweapon = TRUE;
1718 e.strength_finished = max(0, e.strength_finished - time);
1719 e.invincible_finished = max(0, e.invincible_finished - time);
1722 PREGIVE(e, weapons);
1723 PREGIVE(e, strength_finished);
1724 PREGIVE(e, invincible_finished);
1725 PREGIVE(e, ammo_nails);
1726 PREGIVE(e, ammo_cells);
1727 PREGIVE(e, ammo_shells);
1728 PREGIVE(e, ammo_rockets);
1729 PREGIVE(e, ammo_fuel);
1730 PREGIVE(e, armorvalue);
1733 for(i = beginarg; i < endarg; ++i)
1737 if(cmd == "0" || stof(cmd))
1761 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1762 got += GiveValue(e, strength_finished, op, time);
1763 got += GiveValue(e, invincible_finished, op, time);
1764 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1766 got += GiveBit(e, items, IT_JETPACK, op, val);
1767 got += GiveValue(e, health, op, val);
1768 got += GiveValue(e, armorvalue, op, val);
1770 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1772 wi = get_weaponinfo(j);
1774 got += GiveBit(e, weapons, wi.weapons, op, val);
1777 got += GiveValue(e, ammo_cells, op, val);
1778 got += GiveValue(e, ammo_shells, op, val);
1779 got += GiveValue(e, ammo_nails, op, val);
1780 got += GiveValue(e, ammo_rockets, op, val);
1781 got += GiveValue(e, ammo_fuel, op, val);
1783 case "unlimited_ammo":
1784 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1786 case "unlimited_weapon_ammo":
1787 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1789 case "unlimited_superweapons":
1790 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1793 got += GiveBit(e, items, IT_JETPACK, op, val);
1796 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1799 got += GiveValue(e, strength_finished, op, val);
1802 got += GiveValue(e, invincible_finished, op, val);
1805 got += GiveValue(e, ammo_cells, op, val);
1808 got += GiveValue(e, ammo_shells, op, val);
1812 got += GiveValue(e, ammo_nails, op, val);
1815 got += GiveValue(e, ammo_rockets, op, val);
1818 got += GiveValue(e, health, op, val);
1821 got += GiveValue(e, armorvalue, op, val);
1824 got += GiveValue(e, ammo_fuel, op, val);
1827 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1829 wi = get_weaponinfo(j);
1830 if(cmd == wi.netname)
1832 got += GiveBit(e, weapons, wi.weapons, op, val);
1837 print("give: invalid item ", cmd, "\n");
1844 POSTGIVE_BIT(e, items, IT_FUEL_REGEN, "misc/itempickup.wav", string_null);
1845 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
1846 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
1847 POSTGIVE_BIT(e, items, IT_JETPACK, "misc/itempickup.wav", string_null);
1848 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1850 wi = get_weaponinfo(j);
1853 POSTGIVE_BIT(e, weapons, wi.weapons, "weapons/weaponpickup.wav", string_null);
1854 if not(save_weapons & wi.weapons)
1855 if(e.weapons & wi.weapons)
1856 weapon_action(wi.weapon, WR_PRECACHE);
1859 POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
1860 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
1861 POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
1862 POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
1863 POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
1864 POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
1865 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);
1866 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);
1867 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);
1871 e.health = bound(0, e.health, 100);
1872 e.armorvalue = bound(0, e.armorvalue, 999);
1875 if(e.strength_finished <= 0)
1876 e.strength_finished = 0;
1878 e.strength_finished += time;
1879 if(e.invincible_finished <= 0)
1880 e.invincible_finished = 0;
1882 e.invincible_finished += time;
1884 if not(e.weapons & W_WeaponBit(e.switchweapon))
1885 _switchweapon = TRUE;
1887 W_SwitchWeapon_Force(e, w_getbestweapon(e));