1 floatfield Item_CounterField(float it)
5 case IT_SHELLS: return ammo_shells;
6 case IT_NAILS: return ammo_nails;
7 case IT_ROCKETS: return ammo_rockets;
8 case IT_CELLS: return ammo_cells;
9 case IT_5HP: return health;
10 case IT_25HP: return health;
11 case IT_HEALTH: return health;
12 case IT_ARMOR_SHARD: return armorvalue;
13 case IT_ARMOR: return armorvalue;
14 // add more things here (health, armor)
15 default: error("requested item has no counter field");
19 string Item_CounterFieldName(float it)
23 case IT_SHELLS: return "shells";
24 case IT_NAILS: return "nails";
25 case IT_ROCKETS: return "rockets";
26 case IT_CELLS: return "cells";
28 // add more things here (health, armor)
29 default: error("requested item has no counter field name");
33 .float max_armorvalue;
35 void Item_Respawn (void)
37 self.model = self.mdl; // restore original model
38 self.solid = SOLID_TRIGGER; // allow it to be touched again
39 sound (self, CHAN_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
40 setorigin (self, self.origin);
42 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
43 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
46 float Item_GiveTo(entity item, entity player)
54 // if nothing happens to player, just return without taking the item
56 _switchweapon = FALSE;
64 // play some cool sounds ;)
65 centerprint(player, "\n");
66 if(player.health <= 5)
67 announce(player, "announcer/robotic/lastsecond.wav");
68 else if(player.health < 50)
69 announce(player, "announcer/robotic/narrowly.wav");
70 // sound not available
71 // else if(item.items == IT_CELLS)
72 // play2(player, "announce/robotic/ammo.wav");
74 if (item.weapons & WEPBIT_MINSTANEX)
75 W_GiveWeapon (player, WEP_MINSTANEX, "Nex");
77 player.ammo_cells = min (player.ammo_cells + cvar("g_minstagib_ammo_drop"), 999);
85 // sound not available
86 // play2(player, "announce/robotic/extra.ogg\nplay2 announce/robotic/_lives.wav");
87 player.armorvalue = player.armorvalue + cvar("g_minstagib_extralives");
88 sprint(player, "^3You picked up some extra lives\n");
92 if (item.strength_finished)
95 // sound not available
96 // play2(player, "announce/robotic/invisible.wav");
97 player.strength_finished = max(player.strength_finished, time) + cvar("g_balance_powerup_strength_time");
101 if (item.invincible_finished)
104 // sound not available
105 // play2(player, "announce/robotic/speed.wav");
106 player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
111 if (g_weapon_stay == 1)
112 if not(item.flags & FL_NO_WEAPON_STAY)
113 if (item.flags & FL_WEAPON)
115 if(item.classname == "droppedweapon")
117 if (player.weapons & item.weapons) // don't let players stack ammo by tossing weapons
122 if (player.weapons & item.weapons)
127 // in case the player has autoswitch enabled do the following:
128 // if the player is using their best weapon before items are given, they
129 // probably want to switch to an even better weapon after items are given
130 if (player.autoswitch)
131 if (player.switchweapon == w_getbestweapon(player))
132 _switchweapon = TRUE;
134 if not(player.weapons & W_WeaponBit(player.switchweapon))
135 _switchweapon = TRUE;
137 if (item.ammo_shells)
138 if (player.ammo_shells < g_pickup_shells_max)
141 player.ammo_shells = min (player.ammo_shells + item.ammo_shells, g_pickup_shells_max);
144 if (player.ammo_nails < g_pickup_nails_max)
147 player.ammo_nails = min (player.ammo_nails + item.ammo_nails, g_pickup_nails_max);
149 if (item.ammo_rockets)
150 if (player.ammo_rockets < g_pickup_rockets_max)
153 player.ammo_rockets = min (player.ammo_rockets + item.ammo_rockets, g_pickup_rockets_max);
156 if (player.ammo_cells < g_pickup_cells_max)
159 player.ammo_cells = min (player.ammo_cells + item.ammo_cells, g_pickup_cells_max);
162 if (item.flags & FL_WEAPON)
163 if ((it = item.weapons - (item.weapons & player.weapons)))
166 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
168 e = get_weaponinfo(i);
170 W_GiveWeapon (player, e.weapon, item.netname);
174 if (item.strength_finished)
177 player.strength_finished = max(player.strength_finished, time) + cvar("g_balance_powerup_strength_time");
179 if (item.invincible_finished)
182 player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
184 //if (item.speed_finished)
187 // player.speed_finished = max(player.speed_finished, time) + cvar("g_balance_powerup_speed_time");
189 //if (item.slowmo_finished)
192 // player.slowmo_finished = max(player.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
196 if (player.health < item.max_health)
199 player.health = min(player.health + item.health, item.max_health);
200 player.pauserothealth_finished = max(player.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
203 if (player.armorvalue < item.max_armorvalue)
206 player.armorvalue = min(player.armorvalue + item.armorvalue, item.max_armorvalue);
207 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + cvar("g_balance_pause_armor_rot"));
212 // always eat teamed entities
219 sound (player, CHAN_AUTO, item.item_pickupsound, VOL_BASE, ATTN_NORM);
221 W_SwitchWeapon_Force(player, w_getbestweapon(player));
226 void Item_Touch (void)
230 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
231 if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
236 if (other.classname != "player")
240 if (self.solid != SOLID_TRIGGER)
242 if (self.owner == other)
245 if(!Item_GiveTo(self, other))
248 if (self.classname == "droppedweapon")
250 else if((self.flags & FL_WEAPON) && !(self.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
254 self.solid = SOLID_NOT;
255 self.model = string_null;
258 RandomSelection_Init();
259 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
260 RandomSelection_Add(head, 0, head.cnt, 0);
261 e = RandomSelection_chosen_ent;
265 e.nextthink = time + self.respawntime;
266 e.think = Item_Respawn;
274 if(self.effects & EF_NODRAW)
276 // marker for item team search
277 dprint("Initializing item team ", ftos(self.team), "\n");
278 RandomSelection_Init();
279 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
280 RandomSelection_Add(head, 0, head.cnt, 0);
281 e = RandomSelection_chosen_ent;
284 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
288 // make it a non-spawned item
289 head.solid = SOLID_NOT;
290 head.model = string_null;
291 head.state = 1; // state 1 = initially hidden item
293 head.effects = head.effects - (head.effects & EF_NODRAW);
302 self.model = string_null;
303 self.solid = SOLID_NOT;
307 self.model = self.mdl;
308 self.solid = SOLID_TRIGGER;
310 setorigin (self, self.origin);
311 self.think = SUB_Null;
315 // Savage: used for item garbage-collection
316 // TODO: perhaps nice special effect?
317 void RemoveItem(void)
322 // pickup evaluation functions
323 // these functions decide how desirable an item is to the bots
325 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;};
327 float weapon_pickupevalfunc(entity player, entity item)
329 // if we already have the weapon, rate it 1/5th normal value
330 if ((player.weapons & item.weapons) == item.weapons)
331 return item.bot_pickupbasevalue * 0.2;
332 return item.bot_pickupbasevalue;
335 float commodity_pickupevalfunc(entity player, entity item)
339 // TODO: figure out if the player even has the weapon this ammo is for?
340 // may not affect strategy much though...
341 // find out how much more ammo/armor/health the player can hold
342 if (item.ammo_shells)
343 if (player.ammo_shells < g_pickup_shells_max)
344 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
346 if (player.ammo_nails < g_pickup_nails_max)
347 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
348 if (item.ammo_rockets)
349 if (player.ammo_rockets < g_pickup_rockets_max)
350 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
352 if (player.ammo_cells < g_pickup_cells_max)
353 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
355 if (player.armorvalue < item.max_armorvalue)
356 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
358 if (player.health < item.max_health)
359 c = c + max(0, 1 - player.health / item.max_health);
361 return item.bot_pickupbasevalue * c;
366 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
368 startitem_failed = FALSE;
370 // is it a dropped weapon?
371 if (self.classname == "droppedweapon")
373 self.reset = SUB_Remove;
374 // it's a dropped weapon
375 self.movetype = MOVETYPE_TOSS;
376 self.solid = SOLID_TRIGGER;
377 // Savage: remove thrown items after a certain period of time ("garbage collection")
378 self.think = RemoveItem;
379 self.nextthink = time + 60;
380 // don't drop if in a NODROP zone (such as lava)
381 traceline(self.origin, self.origin, MOVE_NORMAL, self);
382 if (trace_dpstartcontents & DPCONTENTS_NODROP)
384 startitem_failed = TRUE;
391 self.reset = Item_Reset;
393 if(self.spawnflags & 1)
396 self.movetype = MOVETYPE_NONE;
398 self.movetype = MOVETYPE_TOSS;
399 self.solid = SOLID_TRIGGER;
400 // do item filtering according to game mode and other things
403 // first nudge it off the floor a little bit to avoid math errors
404 setorigin(self, self.origin + '0 0 1');
405 // set item size before we spawn a spawnfunc_waypoint
406 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
407 setsize (self, '-16 -16 0', '16 16 48');
409 setsize (self, '-16 -16 0', '16 16 32');
410 // note droptofloor returns FALSE if stuck/or would fall too far
412 waypoint_spawnforitem(self);
419 print("removed non-teamplay ", self.classname, "\n");
420 startitem_failed = TRUE;
429 print("removed non-FFA ", self.classname, "\n");
430 startitem_failed = TRUE;
438 // We aren't TA or something like that, so we keep the Q3A entities
439 print("removed non-Q3A ", self.classname, "\n");
440 startitem_failed = TRUE;
446 * can't do it that way, as it would break maps
447 * TODO make a target_give like entity another way, that perhaps has
448 * the weapon name in a key
451 // target_give not yet supported; maybe later
452 print("removed targeted ", self.classname, "\n");
453 startitem_failed = TRUE;
459 if(cvar("spawn_debug") >= 2)
462 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
464 if(otheritem.is_item)
466 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
467 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
468 error("Mapper sucks.");
474 weaponsInMap |= weaponid;
478 startitem_failed = TRUE;
482 else if (g_weaponarena && ((weaponid & WEPBIT_ALL) || (itemid & IT_AMMO)))
484 startitem_failed = TRUE;
488 else if (g_minstagib)
490 // don't remove dropped items and powerups
491 if (self.classname != "minstagib")
493 startitem_failed = TRUE;
498 else if ((!cvar("g_pickup_items") || g_nixnex) && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
500 startitem_failed = TRUE;
505 precache_model (itemmodel);
506 precache_sound (pickupsound);
507 precache_sound ("misc/itemrespawn.wav");
509 if((itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)) || (weaponid & WEPBIT_ALL))
510 self.target = "###item###"; // for finding the nearest item using find()
513 self.bot_pickup = TRUE;
514 self.bot_pickupevalfunc = pickupevalfunc;
515 self.bot_pickupbasevalue = pickupbasevalue;
516 self.mdl = itemmodel;
517 self.item_pickupsound = pickupsound;
518 // let mappers override respawntime
519 if (!self.respawntime)
520 self.respawntime = defaultrespawntime;
521 self.netname = itemname;
523 self.weapons = weaponid;
524 self.flags = FL_ITEM | itemflags;
525 self.touch = Item_Touch;
526 setmodel (self, self.mdl); // precision set below
527 self.effects |= EF_LOWPRECISION;
528 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
529 setsize (self, '-16 -16 0', '16 16 48');
531 setsize (self, '-16 -16 0', '16 16 32');
532 if(itemflags & FL_WEAPON)
533 self.modelflags |= MF_ROTATE;
535 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
536 if (itemflags & FL_WEAPON)
538 // neutral team color for pickup weapons
539 self.colormap = 1024; // color shirt=0 pants=0 grey
542 if (cvar("g_fullbrightitems"))
543 self.effects = self.effects | EF_FULLBRIGHT;
549 self.cnt = 1; // item probability weight
550 self.effects = self.effects | EF_NODRAW; // marker for item team search
551 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
555 /* replace items in minstagib
556 * IT_STRENGTH = invisibility
557 * IT_NAILS = extra lives
558 * IT_INVINCIBLE = speed
560 void minstagib_items (float itemid)
562 // we don't want to replace dropped weapons ;)
563 if (self.classname == "droppedweapon")
565 self.ammo_cells = 25;
566 StartItem ("models/weapons/g_nex.md3",
567 "weapons/weaponpickup.wav", 15,
568 "MinstaNex", 0, WEPBIT_MINSTANEX, FL_WEAPON, generic_pickupevalfunc, 1000);
573 self.classname = "minstagib";
575 // replace rocket launchers and nex guns with ammo cells
576 if (itemid == IT_CELLS)
579 StartItem ("models/items/a_cells.md3",
580 "misc/itempickup.wav", 45,
581 "Nex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
588 itemid = IT_STRENGTH;
592 itemid = IT_INVINCIBLE;
594 // replace with invis
595 if (itemid == IT_STRENGTH)
597 self.effects = EF_ADDITIVE;
598 self.strength_finished = 30;
599 StartItem ("models/items/g_strength.md3",
600 "misc/powerup.wav", g_pickup_respawntime_powerup,
601 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
603 // replace with extra lives
604 if (itemid == IT_NAILS)
607 StartItem ("models/items/g_h100.md3",
608 "misc/megahealth.wav", g_pickup_respawntime_powerup,
609 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
612 // replace with speed
613 if (itemid == IT_INVINCIBLE)
615 self.effects = EF_ADDITIVE;
616 self.invincible_finished = 30;
617 StartItem ("models/items/g_invincible.md3",
618 "misc/powerup_shield.wav", g_pickup_respawntime_powerup,
619 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
624 float minst_no_auto_cells;
625 void minst_remove_item (void) {
626 if(minst_no_auto_cells)
630 float weaponswapping;
633 void weapon_defaultspawnfunc(float wpn)
637 var .float ammofield;
642 // set the respawntime in advance (so replaced weapons can copy it)
643 if(!self.respawntime)
645 e = get_weaponinfo(wpn);
646 if(e.items == IT_SUPERWEAPON)
647 self.respawntime = g_pickup_respawntime_powerup;
649 self.respawntime = g_pickup_respawntime_weapon;
652 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
654 e = get_weaponinfo(wpn);
655 s = cvar_string(strcat("g_weaponreplace_", e.netname));
659 startitem_failed = TRUE;
662 t = tokenize_sane(s);
665 self.team = --internalteam;
667 for(i = 1; i < t; ++i)
670 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
672 e = get_weaponinfo(j);
676 copyentity(oldself, self);
677 self.classname = "replacedweapon";
678 weapon_defaultspawnfunc(j);
684 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
693 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
695 e = get_weaponinfo(j);
704 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
710 startitem_failed = TRUE;
715 e = get_weaponinfo(wpn);
717 if(e.items && e.items != IT_SUPERWEAPON)
719 ammofield = Item_CounterField(e.items);
721 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(e.items)));
725 self.flags |= FL_NO_WEAPON_STAY;
728 // weapon stay isn't supported for teamed weapons
730 self.flags |= FL_NO_WEAPON_STAY;
732 if(g_weapon_stay == 2)
734 self.ammo_shells = 0;
737 self.ammo_rockets = 0;
738 // weapon stay 2: don't use ammo on weapon pickups; instead
739 // initialize all ammo types to the pickup ammo unless set by g_start_ammo_*
742 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, e.bot_pickupbasevalue);
743 if (self.modelindex) // don't precache if self was removed
744 weapon_action(e.weapon, WR_PRECACHE);
747 void spawnfunc_weapon_shotgun (void);
748 void spawnfunc_weapon_uzi (void) {
749 if(q3acompat_machineshotgunswap)
750 if(self.classname != "droppedweapon")
752 weapon_defaultspawnfunc(WEP_SHOTGUN);
755 weapon_defaultspawnfunc(WEP_UZI);
758 void spawnfunc_weapon_shotgun (void) {
759 if(q3acompat_machineshotgunswap)
760 if(self.classname != "droppedweapon")
762 weapon_defaultspawnfunc(WEP_UZI);
765 weapon_defaultspawnfunc(WEP_SHOTGUN);
768 void spawnfunc_weapon_nex (void)
772 minstagib_items(IT_CELLS);
773 self.think = minst_remove_item;
774 self.nextthink = time;
777 weapon_defaultspawnfunc(WEP_NEX);
780 void spawnfunc_weapon_minstanex (void)
784 minstagib_items(IT_CELLS);
785 self.think = minst_remove_item;
786 self.nextthink = time;
789 weapon_defaultspawnfunc(WEP_MINSTANEX);
792 void spawnfunc_weapon_rocketlauncher (void)
796 minstagib_items(IT_CELLS);
797 self.think = minst_remove_item;
798 self.nextthink = time;
801 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
804 void spawnfunc_item_rockets (void) {
805 if(!self.ammo_rockets)
806 self.ammo_rockets = g_pickup_rockets;
807 StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
810 void spawnfunc_item_shells (void);
811 void spawnfunc_item_bullets (void) {
813 if(q3acompat_machineshotgunswap)
814 if(self.classname != "droppedweapon")
816 weaponswapping = TRUE;
817 spawnfunc_item_shells();
818 weaponswapping = FALSE;
823 self.ammo_nails = g_pickup_nails;
824 StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", g_pickup_respawntime_ammo, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
827 void spawnfunc_item_cells (void) {
829 self.ammo_cells = g_pickup_cells;
830 StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
833 void spawnfunc_item_shells (void) {
835 if(q3acompat_machineshotgunswap)
836 if(self.classname != "droppedweapon")
838 weaponswapping = TRUE;
839 spawnfunc_item_bullets();
840 weaponswapping = FALSE;
844 if(!self.ammo_shells)
845 self.ammo_shells = g_pickup_shells;
846 StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
849 void spawnfunc_item_armor_small (void) {
851 self.armorvalue = g_pickup_armorsmall;
852 if(!self.max_armorvalue)
853 self.max_armorvalue = g_pickup_armorsmall_max;
854 StartItem ("models/items/g_a1.md3", "misc/armor1.wav", g_pickup_respawntime_short, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
857 void spawnfunc_item_armor_medium (void) {
859 self.armorvalue = g_pickup_armormedium;
860 if(!self.max_armorvalue)
861 self.max_armorvalue = g_pickup_armormedium_max;
862 StartItem ("models/items/g_armormedium.md3", "misc/armor10.wav", g_pickup_respawntime_medium, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
865 void spawnfunc_item_armor_big (void) {
867 self.armorvalue = g_pickup_armorbig;
868 if(!self.max_armorvalue)
869 self.max_armorvalue = g_pickup_armorbig_max;
870 StartItem ("models/items/g_a50.md3", "misc/armor17_5.wav", g_pickup_respawntime_long, "50 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
873 void spawnfunc_item_armor_large (void) {
875 self.armorvalue = g_pickup_armorlarge;
876 if(!self.max_armorvalue)
877 self.max_armorvalue = g_pickup_armorlarge_max;
878 StartItem ("models/items/g_a25.md3", "misc/armor25.wav", g_pickup_respawntime_long, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
881 void spawnfunc_item_health_small (void) {
883 self.max_health = g_pickup_healthsmall_max;
885 self.health = g_pickup_healthsmall;
886 StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", g_pickup_respawntime_short, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
889 void spawnfunc_item_health_medium (void) {
891 self.max_health = g_pickup_healthmedium_max;
893 self.health = g_pickup_healthmedium;
894 StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", g_pickup_respawntime_short, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
897 void spawnfunc_item_health_large (void) {
899 self.max_health = g_pickup_healthlarge_max;
901 self.health = g_pickup_healthlarge;
902 StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", g_pickup_respawntime_medium, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
905 void spawnfunc_item_health_mega (void) {
906 if(!cvar("g_powerup_superhealth"))
909 if(g_arena && !cvar("g_arena_powerups"))
913 minstagib_items(IT_NAILS);
916 self.max_health = g_pickup_healthmega_max;
918 self.health = g_pickup_healthmega;
919 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", g_pickup_respawntime_long, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
923 // support old misnamed entities
924 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Nexuiz maps it is an armor shard
925 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
926 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
927 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
928 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
930 void spawnfunc_item_strength (void) {
931 if(!cvar("g_powerup_strength"))
934 if(g_arena && !cvar("g_arena_powerups"))
938 minstagib_items(IT_STRENGTH);
940 precache_sound("weapons/strength_fire.wav");
941 self.strength_finished = 30;
942 self.effects = EF_ADDITIVE;
943 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", g_pickup_respawntime_powerup, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
947 void spawnfunc_item_invincible (void) {
948 if(!cvar("g_powerup_shield"))
951 if(g_arena && !cvar("g_arena_powerups"))
955 minstagib_items(IT_INVINCIBLE);
957 self.invincible_finished = 30;
958 self.effects = EF_ADDITIVE;
959 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", g_pickup_respawntime_powerup, "Invulnerability", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
963 void spawnfunc_item_minst_cells (void) {
966 minst_no_auto_cells = 1;
967 minstagib_items(IT_CELLS);
974 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
976 void spawnfunc_misc_models (void)
978 // exists as alias name for 2.4.2 compat
979 SetBrushEntityModel();
982 void spawnfunc_func_static (void)
984 // exists as alias name for having it with brushes
985 SetBrushEntityModel();
988 void func_wall_use (void)
993 self.colormap = (activator.team - 1) * 0x11;
995 self.colormap = 0x00;
998 self.colormap = floor(random() * 256);
999 self.colormap |= 1024; // RENDER_COLORMAPPED
1002 void spawnfunc_func_wall (void)
1004 SetBrushEntityModel();
1006 self.solid = SOLID_BSP;
1007 self.use = func_wall_use;
1010 void spawnfunc_func_illusionary (void)
1012 SetBrushEntityModel();
1013 self.use = func_wall_use;
1016 void gamemodel_drop()
1018 if(self.spawnflags & 3 == 1) // ALIGN_ORIGIN
1020 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
1021 setorigin(self, trace_endpos);
1023 else if(self.spawnflags & 3 == 2) // ALIGN_BOTTOM
1025 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
1026 setorigin(self, trace_endpos);
1028 else if(self.spawnflags & 3 == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
1030 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
1031 setorigin(self, trace_endpos - '0 0 1' * self.mins_z);
1036 void spawnfunc_misc_gamemodel (void)
1039 self.scale = self.modelscale;
1040 SetBrushEntityModel();
1041 self.use = func_wall_use;
1043 InitializeEntity(self, gamemodel_drop, INITPRIO_DROPTOFLOOR);
1046 float target_item_func_set(float a, float b)
1056 float target_item_func_min(float a, float b)
1066 float target_item_func_max(float a, float b)
1071 float target_item_func_bitset(float a, float b)
1076 float target_item_func_and(float a, float b)
1081 float target_item_func_itembitset(float a, float b)
1083 return (a - (a & (IT_UNLIMITED_WEAPON_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | b;
1086 float target_item_func_itemand(float a, float b)
1088 return (a - (a & (IT_UNLIMITED_WEAPON_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | (a & b);
1091 float target_item_func_or(float a, float b)
1096 float target_item_func_andnot(float a, float b)
1101 float target_item_changed;
1102 void target_item_change(float binary, .float field, float(float a, float b) func, string sound_increase, string sound_decrease)
1105 n = func(activator.field, self.field);
1109 d = n & activator.field;
1110 if(d != n) // bits added?
1112 else if(d != activator.field) // bits removed?
1118 d = n - activator.field;
1122 if(sound_decrease != "")
1123 sound (activator, CHAN_AUTO, sound_decrease, VOL_BASE, ATTN_NORM);
1124 target_item_changed = 1;
1128 if(sound_increase != "")
1129 sound (activator, CHAN_AUTO, sound_increase, VOL_BASE, ATTN_NORM);
1130 target_item_changed = 1;
1132 activator.field = n;
1135 void target_items_use (void)
1138 if(activator.classname != "player")
1140 if(activator.deadflag != DEAD_NO)
1145 for(e = world; (e = find(e, classname, "droppedweapon")); )
1146 if(e.enemy == activator)
1149 float _switchweapon;
1150 _switchweapon = FALSE;
1151 if (activator.autoswitch)
1152 if (activator.switchweapon == w_getbestweapon(activator))
1153 _switchweapon = TRUE;
1155 a0 = activator.armorvalue;
1156 h0 = activator.health;
1157 target_item_changed = 0;
1159 if(self.spawnflags == 0) // SET
1161 target_item_change(0, ammo_shells, target_item_func_set, "misc/itempickup.wav", "");
1162 target_item_change(0, ammo_nails, target_item_func_set, "misc/itempickup.wav", "");
1163 target_item_change(0, ammo_rockets, target_item_func_set, "misc/itempickup.wav", "");
1164 target_item_change(0, ammo_cells, target_item_func_set, "misc/itempickup.wav", "");
1165 target_item_change(0, health, target_item_func_set, "misc/megahealth.wav", "");
1166 target_item_change(0, armorvalue, target_item_func_set, "misc/armor25.wav", "");
1167 target_item_change(1, items, target_item_func_itembitset, "misc/powerup.wav", "");
1168 target_item_change(1, weapons, target_item_func_bitset, "weapons/weaponpickup.wav", "");
1170 if((self.items & activator.items) & IT_STRENGTH)
1171 activator.strength_finished = time + self.strength_finished;
1172 if((self.items & activator.items) & IT_INVINCIBLE)
1173 activator.invincible_finished = time + self.invincible_finished;
1175 else if(self.spawnflags == 1) // AND/MIN
1177 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1178 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1179 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1180 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1181 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1182 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1183 target_item_change(1, items, target_item_func_itemand, "misc/powerup.wav", "");
1184 target_item_change(1, weapons, target_item_func_and, "weapons/weaponpickup.wav", "");
1186 if((self.items & activator.items) & IT_STRENGTH)
1187 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1188 if((self.items & activator.items) & IT_INVINCIBLE)
1189 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1191 else if(self.spawnflags == 2) // OR/MAX
1193 target_item_change(0, ammo_shells, target_item_func_max, "misc/itempickup.wav", "");
1194 target_item_change(0, ammo_nails, target_item_func_max, "misc/itempickup.wav", "");
1195 target_item_change(0, ammo_rockets, target_item_func_max, "misc/itempickup.wav", "");
1196 target_item_change(0, ammo_cells, target_item_func_max, "misc/itempickup.wav", "");
1197 target_item_change(0, health, target_item_func_max, "misc/megahealth.wav", "");
1198 target_item_change(0, armorvalue, target_item_func_max, "misc/armor25.wav", "");
1199 target_item_change(1, items, target_item_func_or, "misc/powerup.wav", "");
1200 target_item_change(1, weapons, target_item_func_or, "weapons/weaponpickup.wav", "");
1202 if((self.items & activator.items) & IT_STRENGTH)
1203 activator.strength_finished = max(activator.strength_finished, time + self.strength_finished);
1204 if((self.items & activator.items) & IT_INVINCIBLE)
1205 activator.invincible_finished = max(activator.invincible_finished, time + self.invincible_finished);
1207 else if(self.spawnflags == 4) // ANDNOT/MIN
1209 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1210 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1211 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1212 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1213 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1214 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1215 target_item_change(1, items, target_item_func_andnot, "misc/powerup.wav", "");
1216 target_item_change(1, weapons, target_item_func_andnot, "weapons/weaponpickup.wav", "");
1218 if((self.items & activator.items) & IT_STRENGTH)
1219 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1220 if((self.items & activator.items) & IT_INVINCIBLE)
1221 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1224 if not(activator.items & IT_STRENGTH)
1225 activator.strength_finished = 0;
1226 if not(activator.items & IT_INVINCIBLE)
1227 activator.invincible_finished = 0;
1229 if(activator.health > h0)
1230 activator.pauserothealth_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1231 else if(activator.health < h0)
1232 activator.pauseregen_finished = max(activator.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
1234 if(activator.armorvalue > a0)
1235 activator.pauserotarmor_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1237 if not(activator.weapons & W_WeaponBit(activator.switchweapon))
1238 _switchweapon = TRUE;
1240 W_SwitchWeapon_Force(activator, w_getbestweapon(activator));
1242 if(target_item_changed)
1243 centerprint(activator, self.message);
1246 void spawnfunc_target_items (void)
1250 self.use = target_items_use;
1251 if(!self.strength_finished)
1252 self.strength_finished = cvar("g_balance_powerup_strength_time");
1253 if(!self.invincible_finished)
1254 self.invincible_finished = cvar("g_balance_powerup_invincible_time");
1256 precache_sound("misc/itempickup.wav");
1257 precache_sound("misc/itempickup.wav");
1258 precache_sound("misc/itempickup.wav");
1259 precache_sound("misc/itempickup.wav");
1260 precache_sound("misc/megahealth.wav");
1261 precache_sound("misc/armor25.wav");
1262 precache_sound("misc/powerup.wav");
1263 precache_sound("weapons/weaponpickup.wav");
1265 n = tokenize_sane(self.netname);
1266 for(i = 0; i < n; ++i)
1268 if(argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1269 if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1270 if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1271 if(argv(i) == "strength") self.items |= IT_STRENGTH;
1272 if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1273 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1275 e = get_weaponinfo(j);
1276 if(argv(i) == e.netname)
1278 self.weapons |= e.weapons;
1279 if(self.spawnflags == 0 || self.spawnflags == 2)
1280 weapon_action(e.weapon, WR_PRECACHE);