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;
44 void Item_Show (entity e, float mode)
48 // make the item look normal, and be touchable
50 e.solid = SOLID_TRIGGER;
51 e.effects &~= EF_ADDITIVE;
52 //e.colormod = '0 0 0';
56 if (e.strength_finished || e.invincible_finished)
57 e.effects = e.effects | EF_ADDITIVE | EF_FULLBRIGHT;
58 if (cvar("g_fullbrightitems"))
59 e.effects = e.effects | EF_FULLBRIGHT;
63 // hide the item completely
64 e.model = string_null;
66 e.effects &~= EF_ADDITIVE;
67 //e.colormod = '0 0 0';
72 // make the item translucent green and not touchable
75 // e.effects |= EF_ADDITIVE;
76 // we need this to prevent weird display because of
77 // missing depth sorting - or maybe not
78 //e.colormod = '0.2 1 0.2';
82 // relink entity (because solid may have changed)
83 setorigin(e, e.origin);
86 void Item_Respawn (void)
89 if(!g_minstagib && self.items == IT_STRENGTH)
90 sound (self, CHAN_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
91 else if(!g_minstagib && self.items == IT_INVINCIBLE)
92 sound (self, CHAN_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
94 sound (self, CHAN_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
95 setorigin (self, self.origin);
97 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
98 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
101 void Item_RespawnCountdown (void)
103 if(self.count >= ITEM_RESPAWN_TICKS)
105 if(self.waypointsprite_attached)
106 WaypointSprite_Kill(self.waypointsprite_attached);
111 self.nextthink = time + 1;
122 case IT_STRENGTH: name = "item-invis"; rgb = '0 0 1'; break;
123 case IT_NAILS: name = "item-extralife"; rgb = '1 0 0'; break;
124 case IT_INVINCIBLE: name = "item-speed"; rgb = '1 0 1'; break;
131 case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
132 case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
137 case IT_FUEL_REGEN: name = "item-fuelregen"; rgb = '1 0.5 0'; break;
138 case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
142 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE);
143 if(self.waypointsprite_attached)
145 WaypointSprite_UpdateTeamRadar(self.waypointsprite_attached, RADARICON_POWERUP, rgb);
146 //WaypointSprite_UpdateMaxHealth(self.waypointsprite_attached, ITEM_RESPAWN_TICKS + 1);
147 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
151 sound (self, CHAN_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTN_NORM); // play respawn sound
152 if(self.waypointsprite_attached)
154 WaypointSprite_Ping(self.waypointsprite_attached);
155 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
160 void Item_ScheduleRespawnIn(entity e, float t)
162 if(e.flags & FL_POWERUP)
164 e.think = Item_RespawnCountdown;
165 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
170 e.think = Item_Respawn;
171 e.nextthink = time + t;
175 void Item_ScheduleRespawn(entity e)
178 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
181 void Item_ScheduleInitialRespawn(entity e)
184 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
187 float Item_GiveTo(entity item, entity player)
195 // if nothing happens to player, just return without taking the item
197 _switchweapon = FALSE;
202 if (player.ammo_fuel < g_pickup_fuel_max)
205 player.ammo_fuel = min(player.ammo_fuel + item.ammo_fuel, g_pickup_fuel_max);
206 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + cvar("g_balance_pause_fuel_rot"));
208 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
212 sprint (player, strcat("You got the ^2", item.netname, "\n"));
215 _switchweapon = TRUE;
219 // play some cool sounds ;)
220 centerprint(player, "\n");
221 if (clienttype(player) == CLIENTTYPE_REAL)
223 if(player.health <= 5)
224 play2(player, "announcer/robotic/lastsecond.wav");
225 else if(player.health < 50)
226 play2(player, "announcer/robotic/narrowly.wav");
228 // sound not available
229 // else if(item.items == IT_CELLS)
230 // play2(player, "announce/robotic/ammo.wav");
232 if (item.weapons & WEPBIT_MINSTANEX)
233 W_GiveWeapon (player, WEP_MINSTANEX, "Nex");
235 player.ammo_cells = min (player.ammo_cells + cvar("g_minstagib_ammo_drop"), 999);
243 // sound not available
244 // play2(player, "announce/robotic/extra.ogg\nplay2 announce/robotic/_lives.wav");
245 player.armorvalue = player.armorvalue + cvar("g_minstagib_extralives");
246 sprint(player, "^3You picked up some extra lives\n");
250 if (item.strength_finished)
253 // sound not available
254 // play2(player, "announce/robotic/invisible.wav");
255 player.strength_finished = max(player.strength_finished, time) + cvar("g_balance_powerup_strength_time");
259 if (item.invincible_finished)
262 // sound not available
263 // play2(player, "announce/robotic/speed.wav");
264 player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
268 if (player.ammo_fuel < g_pickup_fuel_max)
271 player.ammo_fuel = min(player.ammo_fuel + item.ammo_fuel, g_pickup_fuel_max);
272 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + cvar("g_balance_pause_fuel_rot"));
278 if (g_weapon_stay == 1)
279 if not(item.flags & FL_NO_WEAPON_STAY)
280 if (item.flags & FL_WEAPON)
282 if(item.classname == "droppedweapon")
284 if (player.weapons & item.weapons) // don't let players stack ammo by tossing weapons
289 if (player.weapons & item.weapons)
294 // in case the player has autoswitch enabled do the following:
295 // if the player is using their best weapon before items are given, they
296 // probably want to switch to an even better weapon after items are given
297 if (player.autoswitch)
298 if (player.switchweapon == w_getbestweapon(player))
299 _switchweapon = TRUE;
301 if not(player.weapons & W_WeaponBit(player.switchweapon))
302 _switchweapon = TRUE;
304 if (item.ammo_shells)
305 if (player.ammo_shells < g_pickup_shells_max)
308 player.ammo_shells = min (player.ammo_shells + item.ammo_shells, g_pickup_shells_max);
311 if (player.ammo_nails < g_pickup_nails_max)
314 player.ammo_nails = min (player.ammo_nails + item.ammo_nails, g_pickup_nails_max);
316 if (item.ammo_rockets)
317 if (player.ammo_rockets < g_pickup_rockets_max)
320 player.ammo_rockets = min (player.ammo_rockets + item.ammo_rockets, g_pickup_rockets_max);
323 if (player.ammo_cells < g_pickup_cells_max)
326 player.ammo_cells = min (player.ammo_cells + item.ammo_cells, g_pickup_cells_max);
329 if (player.ammo_fuel < g_pickup_fuel_max)
332 player.ammo_fuel = min(player.ammo_fuel + item.ammo_fuel, g_pickup_fuel_max);
333 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + cvar("g_balance_pause_fuel_rot"));
336 if (item.flags & FL_WEAPON)
337 if ((it = item.weapons - (item.weapons & player.weapons)))
340 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
342 e = get_weaponinfo(i);
344 W_GiveWeapon (player, e.weapon, item.netname);
348 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
352 sprint (player, strcat("You got the ^2", item.netname, "\n"));
355 if (item.strength_finished)
358 player.strength_finished = max(player.strength_finished, time) + cvar("g_balance_powerup_strength_time");
360 if (item.invincible_finished)
363 player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
365 //if (item.speed_finished)
368 // player.speed_finished = max(player.speed_finished, time) + cvar("g_balance_powerup_speed_time");
370 //if (item.slowmo_finished)
373 // player.slowmo_finished = max(player.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
377 if (player.health < item.max_health)
380 player.health = min(player.health + item.health, item.max_health);
381 player.pauserothealth_finished = max(player.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
384 if (player.armorvalue < item.max_armorvalue)
387 player.armorvalue = min(player.armorvalue + item.armorvalue, item.max_armorvalue);
388 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + cvar("g_balance_pause_armor_rot"));
393 // always eat teamed entities
400 sound (player, CHAN_AUTO, item.item_pickupsound, VOL_BASE, ATTN_NORM);
402 if (player.switchweapon != w_getbestweapon(player))
403 W_SwitchWeapon_Force(player, w_getbestweapon(player));
408 void Item_Touch (void)
412 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
413 if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
418 if (other.classname != "player")
422 if (self.solid != SOLID_TRIGGER)
424 if (self.owner == other)
427 if(!Item_GiveTo(self, other))
430 pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
432 if (self.classname == "droppedweapon")
434 else if((self.flags & FL_WEAPON) && !(self.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
440 RandomSelection_Init();
441 for(head = world; (head = findfloat(head, team, self.team)); )
443 if(head.flags & FL_ITEM)
446 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
449 e = RandomSelection_chosen_ent;
453 Item_ScheduleRespawn(e);
461 if(self.effects & EF_NODRAW)
463 // marker for item team search
464 dprint("Initializing item team ", ftos(self.team), "\n");
465 RandomSelection_Init();
466 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
467 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
468 e = RandomSelection_chosen_ent;
472 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
476 // make it a non-spawned item
478 head.state = 1; // state 1 = initially hidden item
480 head.effects &~= EF_NODRAW;
483 if(e.flags & FL_POWERUP) // do not spawn powerups initially!
484 Item_ScheduleInitialRespawn(e);
490 Item_Show(self, !self.state);
491 setorigin (self, self.origin);
492 self.think = SUB_Null;
495 if(self.flags & FL_POWERUP) // do not spawn powerups initially!
496 Item_ScheduleInitialRespawn(self);
499 // Savage: used for item garbage-collection
500 // TODO: perhaps nice special effect?
501 void RemoveItem(void)
506 // pickup evaluation functions
507 // these functions decide how desirable an item is to the bots
509 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;};
511 float weapon_pickupevalfunc(entity player, entity item)
513 float c, i, j, position;
515 // See if I have it already
516 if(player.weapons & item.weapons == item.weapons)
518 // If I can pick it up
521 else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
523 // Skilled bots will grab more
524 c = bound(0, skill / 10, 1) * 0.5;
532 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
533 if( bot_custom_weapon && c )
535 for(i = WEP_FIRST; i < WEP_LAST ; ++i)
538 if( (get_weaponinfo(i)).weapons & item.weapons != item.weapons )
541 // Find the highest position on any range
543 for(j = 0; j < WEP_LAST ; ++j){
545 bot_weapons_far[j] == i ||
546 bot_weapons_mid[j] == i ||
547 bot_weapons_close[j] == i
558 position = WEP_LAST - position;
559 // item.bot_pickupbasevalue is overwritten here
560 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
565 return item.bot_pickupbasevalue * c;
568 float commodity_pickupevalfunc(entity player, entity item)
570 float c, i, need_shells, need_nails, need_rockets, need_cells;
574 // Detect needed ammo
575 for(i = WEP_FIRST; i < WEP_LAST ; ++i)
577 wi = get_weaponinfo(i);
579 if not(wi.weapons & player.weapons)
582 if(wi.items & IT_SHELLS)
584 else if(wi.items & IT_NAILS)
586 else if(wi.items & IT_ROCKETS)
588 else if(wi.items & IT_CELLS)
592 // TODO: figure out if the player even has the weapon this ammo is for?
593 // may not affect strategy much though...
594 // find out how much more ammo/armor/health the player can hold
596 if (item.ammo_shells)
597 if (player.ammo_shells < g_pickup_shells_max)
598 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
601 if (player.ammo_nails < g_pickup_nails_max)
602 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
604 if (item.ammo_rockets)
605 if (player.ammo_rockets < g_pickup_rockets_max)
606 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
609 if (player.ammo_cells < g_pickup_cells_max)
610 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
612 if (player.armorvalue < item.max_armorvalue*0.5)
613 c = c + max(0, 1 - player.armorvalue / (item.max_armorvalue*0.5));
615 if (player.health < item.max_health*0.5)
616 c = c + max(0, 1 - player.health / (item.max_health*0.5));
618 return item.bot_pickupbasevalue * c;
623 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)
625 startitem_failed = FALSE;
627 // is it a dropped weapon?
628 if (self.classname == "droppedweapon")
630 self.reset = SUB_Remove;
631 // it's a dropped weapon
632 self.movetype = MOVETYPE_TOSS;
633 // Savage: remove thrown items after a certain period of time ("garbage collection")
634 self.think = RemoveItem;
635 self.nextthink = time + 60;
636 // don't drop if in a NODROP zone (such as lava)
637 traceline(self.origin, self.origin, MOVE_NORMAL, self);
638 if (trace_dpstartcontents & DPCONTENTS_NODROP)
640 startitem_failed = TRUE;
647 self.reset = Item_Reset;
649 if(self.spawnflags & 1)
652 self.movetype = MOVETYPE_NONE;
654 self.movetype = MOVETYPE_TOSS;
655 // do item filtering according to game mode and other things
658 // first nudge it off the floor a little bit to avoid math errors
659 setorigin(self, self.origin + '0 0 1');
660 // set item size before we spawn a spawnfunc_waypoint
661 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
662 setsize (self, '-16 -16 0', '16 16 48');
664 setsize (self, '-16 -16 0', '16 16 32');
665 // note droptofloor returns FALSE if stuck/or would fall too far
667 waypoint_spawnforitem(self);
674 print("removed non-teamplay ", self.classname, "\n");
675 startitem_failed = TRUE;
684 print("removed non-FFA ", self.classname, "\n");
685 startitem_failed = TRUE;
693 // We aren't TA or something like that, so we keep the Q3A entities
694 print("removed non-Q3A ", self.classname, "\n");
695 startitem_failed = TRUE;
701 * can't do it that way, as it would break maps
702 * TODO make a target_give like entity another way, that perhaps has
703 * the weapon name in a key
706 // target_give not yet supported; maybe later
707 print("removed targeted ", self.classname, "\n");
708 startitem_failed = TRUE;
714 if(cvar("spawn_debug") >= 2)
717 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
719 if(otheritem.is_item)
721 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
722 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
723 error("Mapper sucks.");
729 weaponsInMap |= weaponid;
733 startitem_failed = TRUE;
737 else if (g_weaponarena && ((weaponid & WEPBIT_ALL) || (itemid & IT_AMMO)))
739 startitem_failed = TRUE;
743 else if (g_minstagib)
745 // don't remove dropped items and powerups
746 if (self.classname != "minstagib")
748 startitem_failed = TRUE;
765 if (cvar("g_nixnex_with_healtharmor"))
770 if (cvar("g_nixnex_with_powerups"))
777 startitem_failed = TRUE;
782 else if (!cvar("g_pickup_items") && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
784 startitem_failed = TRUE;
789 precache_model (itemmodel);
790 precache_sound (pickupsound);
791 precache_sound ("misc/itemrespawn.wav");
792 precache_sound ("misc/itemrespawncountdown.wav");
794 if(itemid == IT_STRENGTH)
795 precache_sound ("misc/strength_respawn.wav");
796 if(itemid == IT_INVINCIBLE)
797 precache_sound ("misc/shield_respawn.wav");
799 if((itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)) || (weaponid & WEPBIT_ALL))
800 self.target = "###item###"; // for finding the nearest item using find()
803 self.bot_pickup = TRUE;
804 self.bot_pickupevalfunc = pickupevalfunc;
805 self.bot_pickupbasevalue = pickupbasevalue;
806 self.mdl = itemmodel;
807 self.item_pickupsound = pickupsound;
808 // let mappers override respawntime
809 if(!self.respawntime) // both set
811 self.respawntime = defaultrespawntime;
812 self.respawntimejitter = defaultrespawntimejitter;
814 self.netname = itemname;
816 self.weapons = weaponid;
817 self.flags = FL_ITEM | itemflags;
818 self.touch = Item_Touch;
819 setmodel (self, self.mdl); // precision set below
820 self.effects |= EF_LOWPRECISION;
821 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
822 setsize (self, '-16 -16 0', '16 16 48');
824 setsize (self, '-16 -16 0', '16 16 32');
825 if(itemflags & FL_WEAPON)
826 self.modelflags |= MF_ROTATE;
828 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
829 if (itemflags & FL_WEAPON)
831 // neutral team color for pickup weapons
832 self.colormap = 1024; // color shirt=0 pants=0 grey
840 self.cnt = 1; // item probability weight
841 self.effects = self.effects | EF_NODRAW; // marker for item team search
842 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
844 else if(self.flags & FL_POWERUP) // do not spawn powerups initially!
845 Item_ScheduleInitialRespawn(self);
848 /* replace items in minstagib
849 * IT_STRENGTH = invisibility
850 * IT_NAILS = extra lives
851 * IT_INVINCIBLE = speed
853 void minstagib_items (float itemid)
855 // we don't want to replace dropped weapons ;)
856 if (self.classname == "droppedweapon")
858 self.ammo_cells = 25;
859 StartItem ("models/weapons/g_nex.md3",
860 "weapons/weaponpickup.wav", 15, 0,
861 "MinstaNex", 0, WEPBIT_MINSTANEX, FL_WEAPON, generic_pickupevalfunc, 1000);
866 self.classname = "minstagib";
868 // replace rocket launchers and nex guns with ammo cells
869 if (itemid == IT_CELLS)
872 StartItem ("models/items/a_cells.md3",
873 "misc/itempickup.wav", 45, 0,
874 "Nex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
881 itemid = IT_STRENGTH;
885 itemid = IT_INVINCIBLE;
887 // replace with invis
888 if (itemid == IT_STRENGTH)
890 self.strength_finished = 30;
891 StartItem ("models/items/g_strength.md3",
892 "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
893 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
895 // replace with extra lives
896 if (itemid == IT_NAILS)
899 StartItem ("models/items/g_h100.md3",
900 "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
901 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
904 // replace with speed
905 if (itemid == IT_INVINCIBLE)
907 self.invincible_finished = 30;
908 StartItem ("models/items/g_invincible.md3",
909 "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
910 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
915 float minst_no_auto_cells;
916 void minst_remove_item (void) {
917 if(minst_no_auto_cells)
921 float weaponswapping;
924 void weapon_defaultspawnfunc(float wpn)
928 var .float ammofield;
933 // set the respawntime in advance (so replaced weapons can copy it)
935 if(!self.respawntime)
937 e = get_weaponinfo(wpn);
938 if(e.items == IT_SUPERWEAPON)
940 self.respawntime = g_pickup_respawntime_powerup;
941 self.respawntimejitter = g_pickup_respawntimejitter_powerup;
945 self.respawntime = g_pickup_respawntime_weapon;
946 self.respawntimejitter = g_pickup_respawntimejitter_weapon;
950 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
952 e = get_weaponinfo(wpn);
953 s = cvar_string(strcat("g_weaponreplace_", e.netname));
957 startitem_failed = TRUE;
960 t = tokenize_console(s);
963 self.team = --internalteam;
965 for(i = 1; i < t; ++i)
968 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
970 e = get_weaponinfo(j);
974 copyentity(oldself, self);
975 self.classname = "replacedweapon";
976 weapon_defaultspawnfunc(j);
982 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
991 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
993 e = get_weaponinfo(j);
1002 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1008 startitem_failed = TRUE;
1013 e = get_weaponinfo(wpn);
1015 if(e.items && e.items != IT_SUPERWEAPON)
1017 for(i = 0, j = 1; i < 24; ++i, j *= 2)
1021 ammofield = Item_CounterField(j);
1023 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j)));
1029 self.flags |= FL_NO_WEAPON_STAY;
1032 // weapon stay isn't supported for teamed weapons
1034 self.flags |= FL_NO_WEAPON_STAY;
1036 if(g_weapon_stay == 2 && self.classname != "droppedweapon")
1038 self.ammo_shells = 0;
1039 self.ammo_nails = 0;
1040 self.ammo_cells = 0;
1041 self.ammo_rockets = 0;
1042 // weapon stay 2: don't use ammo on weapon pickups; instead
1043 // initialize all ammo types to the pickup ammo unless set by g_start_ammo_*
1046 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, e.bot_pickupbasevalue);
1047 if (self.modelindex) // don't precache if self was removed
1048 weapon_action(e.weapon, WR_PRECACHE);
1051 void spawnfunc_weapon_shotgun (void);
1052 void spawnfunc_weapon_uzi (void) {
1053 if(q3acompat_machineshotgunswap)
1054 if(self.classname != "droppedweapon")
1056 weapon_defaultspawnfunc(WEP_SHOTGUN);
1059 weapon_defaultspawnfunc(WEP_UZI);
1062 void spawnfunc_weapon_shotgun (void) {
1063 if(q3acompat_machineshotgunswap)
1064 if(self.classname != "droppedweapon")
1066 weapon_defaultspawnfunc(WEP_UZI);
1069 weapon_defaultspawnfunc(WEP_SHOTGUN);
1072 void spawnfunc_weapon_nex (void)
1076 minstagib_items(IT_CELLS);
1077 self.think = minst_remove_item;
1078 self.nextthink = time;
1081 weapon_defaultspawnfunc(WEP_NEX);
1084 void spawnfunc_weapon_minstanex (void)
1088 minstagib_items(IT_CELLS);
1089 self.think = minst_remove_item;
1090 self.nextthink = time;
1093 weapon_defaultspawnfunc(WEP_MINSTANEX);
1096 void spawnfunc_weapon_rocketlauncher (void)
1100 minstagib_items(IT_CELLS);
1101 self.think = minst_remove_item;
1102 self.nextthink = time;
1105 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
1108 void spawnfunc_item_rockets (void) {
1109 if(!self.ammo_rockets)
1110 self.ammo_rockets = g_pickup_rockets;
1111 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);
1114 void spawnfunc_item_shells (void);
1115 void spawnfunc_item_bullets (void) {
1117 if(q3acompat_machineshotgunswap)
1118 if(self.classname != "droppedweapon")
1120 weaponswapping = TRUE;
1121 spawnfunc_item_shells();
1122 weaponswapping = FALSE;
1126 if(!self.ammo_nails)
1127 self.ammo_nails = g_pickup_nails;
1128 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);
1131 void spawnfunc_item_cells (void) {
1132 if(!self.ammo_cells)
1133 self.ammo_cells = g_pickup_cells;
1134 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);
1137 void spawnfunc_item_shells (void) {
1139 if(q3acompat_machineshotgunswap)
1140 if(self.classname != "droppedweapon")
1142 weaponswapping = TRUE;
1143 spawnfunc_item_bullets();
1144 weaponswapping = FALSE;
1148 if(!self.ammo_shells)
1149 self.ammo_shells = g_pickup_shells;
1150 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);
1153 void spawnfunc_item_armor_small (void) {
1154 if(!self.armorvalue)
1155 self.armorvalue = g_pickup_armorsmall;
1156 if(!self.max_armorvalue)
1157 self.max_armorvalue = g_pickup_armorsmall_max;
1158 StartItem ("models/items/g_a1.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);
1161 void spawnfunc_item_armor_medium (void) {
1162 if(!self.armorvalue)
1163 self.armorvalue = g_pickup_armormedium;
1164 if(!self.max_armorvalue)
1165 self.max_armorvalue = g_pickup_armormedium_max;
1166 StartItem ("models/items/g_armormedium.md3", "misc/armor10.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1169 void spawnfunc_item_armor_big (void) {
1170 if(!self.armorvalue)
1171 self.armorvalue = g_pickup_armorbig;
1172 if(!self.max_armorvalue)
1173 self.max_armorvalue = g_pickup_armorbig_max;
1174 StartItem ("models/items/g_a50.md3", "misc/armor17_5.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "50 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
1177 void spawnfunc_item_armor_large (void) {
1178 if(!self.armorvalue)
1179 self.armorvalue = g_pickup_armorlarge;
1180 if(!self.max_armorvalue)
1181 self.max_armorvalue = g_pickup_armorlarge_max;
1182 StartItem ("models/items/g_a25.md3", "misc/armor25.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1185 void spawnfunc_item_health_small (void) {
1186 if(!self.max_health)
1187 self.max_health = g_pickup_healthsmall_max;
1189 self.health = g_pickup_healthsmall;
1190 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);
1193 void spawnfunc_item_health_medium (void) {
1194 if(!self.max_health)
1195 self.max_health = g_pickup_healthmedium_max;
1197 self.health = g_pickup_healthmedium;
1198 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);
1201 void spawnfunc_item_health_large (void) {
1202 if(!self.max_health)
1203 self.max_health = g_pickup_healthlarge_max;
1205 self.health = g_pickup_healthlarge;
1206 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);
1209 void spawnfunc_item_health_mega (void) {
1210 if(!cvar("g_powerup_superhealth"))
1213 if(g_arena && !cvar("g_arena_powerups"))
1217 minstagib_items(IT_NAILS);
1219 if(!self.max_health)
1220 self.max_health = g_pickup_healthmega_max;
1222 self.health = g_pickup_healthmega;
1223 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);
1227 // support old misnamed entities
1228 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Nexuiz maps it is an armor shard
1229 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1230 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1231 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1232 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1234 void spawnfunc_item_strength (void) {
1235 if(!cvar("g_powerup_strength"))
1238 if(g_arena && !cvar("g_arena_powerups"))
1242 minstagib_items(IT_STRENGTH);
1244 precache_sound("weapons/strength_fire.wav");
1245 self.strength_finished = 30;
1246 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);
1250 void spawnfunc_item_invincible (void) {
1251 if(!cvar("g_powerup_shield"))
1254 if(g_arena && !cvar("g_arena_powerups"))
1258 minstagib_items(IT_INVINCIBLE);
1260 self.invincible_finished = 30;
1261 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);
1265 void spawnfunc_item_minst_cells (void) {
1268 minst_no_auto_cells = 1;
1269 minstagib_items(IT_CELLS);
1276 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1278 float target_item_func_set(float a, float b)
1288 float target_item_func_min(float a, float b)
1298 float target_item_func_max(float a, float b)
1303 float target_item_func_bitset(float a, float b)
1308 float target_item_func_and(float a, float b)
1313 float target_item_func_itembitset(float a, float b)
1315 return (a - (a & (IT_PICKUPMASK | IT_STRENGTH | IT_INVINCIBLE))) | b;
1318 float target_item_func_itemand(float a, float b)
1320 return (a - (a & (IT_PICKUPMASK | IT_STRENGTH | IT_INVINCIBLE))) | (a & b);
1323 float target_item_func_or(float a, float b)
1328 float target_item_func_andnot(float a, float b)
1333 float target_item_changed;
1334 void target_item_change(float binary, .float field, float(float a, float b) func, string sound_increase, string sound_decrease)
1337 n = func(activator.field, self.field);
1341 d = n & activator.field;
1342 if(d != n) // bits added?
1344 else if(d != activator.field) // bits removed?
1350 d = n - activator.field;
1354 if(sound_decrease != "")
1355 sound (activator, CHAN_AUTO, sound_decrease, VOL_BASE, ATTN_NORM);
1356 target_item_changed = 1;
1360 if(sound_increase != "")
1361 sound (activator, CHAN_AUTO, sound_increase, VOL_BASE, ATTN_NORM);
1362 target_item_changed = 1;
1364 activator.field = n;
1367 void target_items_use (void)
1371 if(activator.classname == "droppedweapon")
1378 if(activator.classname != "player")
1380 if(activator.deadflag != DEAD_NO)
1385 for(e = world; (e = find(e, classname, "droppedweapon")); )
1386 if(e.enemy == activator)
1389 float _switchweapon;
1390 _switchweapon = FALSE;
1391 if (activator.autoswitch)
1392 if (activator.switchweapon == w_getbestweapon(activator))
1393 _switchweapon = TRUE;
1395 a0 = activator.armorvalue;
1396 h0 = activator.health;
1397 f0 = activator.ammo_fuel;
1398 target_item_changed = 0;
1400 if(self.spawnflags == 0) // SET
1402 target_item_change(0, ammo_shells, target_item_func_set, "misc/itempickup.wav", "");
1403 target_item_change(0, ammo_nails, target_item_func_set, "misc/itempickup.wav", "");
1404 target_item_change(0, ammo_rockets, target_item_func_set, "misc/itempickup.wav", "");
1405 target_item_change(0, ammo_cells, target_item_func_set, "misc/itempickup.wav", "");
1406 target_item_change(0, ammo_fuel, target_item_func_set, "misc/itempickup.wav", "");
1407 target_item_change(0, health, target_item_func_set, "misc/megahealth.wav", "");
1408 target_item_change(0, armorvalue, target_item_func_set, "misc/armor25.wav", "");
1409 target_item_change(1, items, target_item_func_itembitset, "misc/powerup.wav", "misc/poweroff.wav");
1410 target_item_change(1, weapons, target_item_func_bitset, "weapons/weaponpickup.wav", "");
1412 if((self.items & activator.items) & IT_STRENGTH)
1413 activator.strength_finished = time + self.strength_finished;
1414 if((self.items & activator.items) & IT_INVINCIBLE)
1415 activator.invincible_finished = time + self.invincible_finished;
1417 else if(self.spawnflags == 1) // AND/MIN
1419 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1420 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1421 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1422 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1423 target_item_change(0, ammo_fuel, target_item_func_min, "misc/itempickup.wav", "");
1424 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1425 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1426 target_item_change(1, items, target_item_func_itemand, "misc/powerup.wav", "misc/poweroff.wav");
1427 target_item_change(1, weapons, target_item_func_and, "weapons/weaponpickup.wav", "");
1429 if((self.items & activator.items) & IT_STRENGTH)
1430 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1431 if((self.items & activator.items) & IT_INVINCIBLE)
1432 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1434 else if(self.spawnflags == 2) // OR/MAX
1436 target_item_change(0, ammo_shells, target_item_func_max, "misc/itempickup.wav", "");
1437 target_item_change(0, ammo_nails, target_item_func_max, "misc/itempickup.wav", "");
1438 target_item_change(0, ammo_rockets, target_item_func_max, "misc/itempickup.wav", "");
1439 target_item_change(0, ammo_cells, target_item_func_max, "misc/itempickup.wav", "");
1440 target_item_change(0, ammo_fuel, target_item_func_max, "misc/itempickup.wav", "");
1441 target_item_change(0, health, target_item_func_max, "misc/megahealth.wav", "");
1442 target_item_change(0, armorvalue, target_item_func_max, "misc/armor25.wav", "");
1443 target_item_change(1, items, target_item_func_or, "misc/powerup.wav", "misc/poweroff.wav");
1444 target_item_change(1, weapons, target_item_func_or, "weapons/weaponpickup.wav", "");
1446 if((self.items & activator.items) & IT_STRENGTH)
1447 activator.strength_finished = max(activator.strength_finished, time + self.strength_finished);
1448 if((self.items & activator.items) & IT_INVINCIBLE)
1449 activator.invincible_finished = max(activator.invincible_finished, time + self.invincible_finished);
1451 else if(self.spawnflags == 4) // ANDNOT/MIN
1453 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1454 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1455 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1456 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1457 target_item_change(0, ammo_fuel, target_item_func_min, "misc/itempickup.wav", "");
1458 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1459 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1460 target_item_change(1, items, target_item_func_andnot, "misc/powerup.wav", "misc/poweroff.wav");
1461 target_item_change(1, weapons, target_item_func_andnot, "weapons/weaponpickup.wav", "");
1463 if((self.items & activator.items) & IT_STRENGTH)
1464 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1465 if((self.items & activator.items) & IT_INVINCIBLE)
1466 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1469 if not(activator.items & IT_STRENGTH)
1470 activator.strength_finished = 0;
1471 if not(activator.items & IT_INVINCIBLE)
1472 activator.invincible_finished = 0;
1474 if(activator.health > h0)
1475 activator.pauserothealth_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1476 else if(activator.health < h0)
1477 activator.pauseregen_finished = max(activator.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
1479 if(activator.ammo_fuel > f0)
1480 activator.pauserotfuel_finished = max(activator.pauserotfuel_finished, time + cvar("g_balance_pause_fuel_rot"));
1481 else if(activator.ammo_fuel < f0)
1482 activator.pauseregen_finished = max(activator.pauseregen_finished, time + cvar("g_balance_pause_fuel_regen"));
1484 if(activator.armorvalue > a0)
1485 activator.pauserotarmor_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1487 if not(activator.weapons & W_WeaponBit(activator.switchweapon))
1488 _switchweapon = TRUE;
1490 W_SwitchWeapon_Force(activator, w_getbestweapon(activator));
1492 if(target_item_changed)
1493 centerprint(activator, self.message);
1496 void spawnfunc_target_items (void)
1503 // items triggers cannot work in nixnex (as they change weapons/ammo)
1508 self.use = target_items_use;
1509 if(!self.strength_finished)
1510 self.strength_finished = cvar("g_balance_powerup_strength_time");
1511 if(!self.invincible_finished)
1512 self.invincible_finished = cvar("g_balance_powerup_invincible_time");
1514 precache_sound("misc/itempickup.wav");
1515 precache_sound("misc/itempickup.wav");
1516 precache_sound("misc/itempickup.wav");
1517 precache_sound("misc/itempickup.wav");
1518 precache_sound("misc/megahealth.wav");
1519 precache_sound("misc/armor25.wav");
1520 precache_sound("misc/powerup.wav");
1521 precache_sound("misc/poweroff.wav");
1522 precache_sound("weapons/weaponpickup.wav");
1524 n = tokenize_console(self.netname);
1525 for(i = 0; i < n; ++i)
1527 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1528 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1529 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1530 else if(argv(i) == "strength") self.items |= IT_STRENGTH;
1531 else if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1532 else if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1533 else if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1536 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1538 e = get_weaponinfo(j);
1539 if(argv(i) == e.netname)
1541 self.weapons |= e.weapons;
1542 if(self.spawnflags == 0 || self.spawnflags == 2)
1543 weapon_action(e.weapon, WR_PRECACHE);
1548 print("target_items: invalid item ", argv(i), "\n");
1553 void spawnfunc_item_fuel(void)
1556 self.ammo_fuel = g_pickup_fuel;
1557 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);
1560 void spawnfunc_item_fuel_regen(void)
1562 if(start_items & IT_FUEL_REGEN)
1564 spawnfunc_item_fuel();
1567 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);
1570 void spawnfunc_item_jetpack(void)
1572 if(g_grappling_hook)
1573 return; // sorry, but these two can't coexist (same button); spawn fuel instead
1575 self.ammo_fuel = g_pickup_fuel_jetpack;
1576 if(start_items & IT_JETPACK)
1578 spawnfunc_item_fuel();
1581 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);
1584 // we no longer have the seeker
1585 void spawnfunc_weapon_seeker()
1587 spawnfunc_weapon_fireball();