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_FUEL: return ammo_fuel;
10 case IT_5HP: return health;
11 case IT_25HP: return health;
12 case IT_HEALTH: return health;
13 case IT_ARMOR_SHARD: return armorvalue;
14 case IT_ARMOR: return armorvalue;
15 // add more things here (health, armor)
16 default: error("requested item has no counter field");
20 string Item_CounterFieldName(float it)
24 case IT_SHELLS: return "shells";
25 case IT_NAILS: return "nails";
26 case IT_ROCKETS: return "rockets";
27 case IT_CELLS: return "cells";
28 case IT_FUEL: return "fuel";
30 // add more things here (health, armor)
31 default: error("requested item has no counter field name");
35 .float max_armorvalue;
37 void Item_Respawn (void)
39 self.model = self.mdl; // restore original model
40 self.solid = SOLID_TRIGGER; // allow it to be touched again
41 sound (self, CHAN_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
42 setorigin (self, self.origin);
44 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
45 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
48 float Item_GiveTo(entity item, entity player)
56 // if nothing happens to player, just return without taking the item
58 _switchweapon = FALSE;
66 // play some cool sounds ;)
67 centerprint(player, "\n");
68 if(player.health <= 5)
69 announce(player, "announcer/robotic/lastsecond.wav");
70 else if(player.health < 50)
71 announce(player, "announcer/robotic/narrowly.wav");
72 // sound not available
73 // else if(item.items == IT_CELLS)
74 // play2(player, "announce/robotic/ammo.wav");
76 if (item.weapons & WEPBIT_MINSTANEX)
77 W_GiveWeapon (player, WEP_MINSTANEX, "Nex");
79 player.ammo_cells = min (player.ammo_cells + cvar("g_minstagib_ammo_drop"), 999);
87 // sound not available
88 // play2(player, "announce/robotic/extra.ogg\nplay2 announce/robotic/_lives.wav");
89 player.armorvalue = player.armorvalue + cvar("g_minstagib_extralives");
90 sprint(player, "^3You picked up some extra lives\n");
94 if (item.strength_finished)
97 // sound not available
98 // play2(player, "announce/robotic/invisible.wav");
99 player.strength_finished = max(player.strength_finished, time) + cvar("g_balance_powerup_strength_time");
103 if (item.invincible_finished)
106 // sound not available
107 // play2(player, "announce/robotic/speed.wav");
108 player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
113 if (g_weapon_stay == 1)
114 if not(item.flags & FL_NO_WEAPON_STAY)
115 if (item.flags & FL_WEAPON)
117 if(item.classname == "droppedweapon")
119 if (player.weapons & item.weapons) // don't let players stack ammo by tossing weapons
124 if (player.weapons & item.weapons)
129 // in case the player has autoswitch enabled do the following:
130 // if the player is using their best weapon before items are given, they
131 // probably want to switch to an even better weapon after items are given
132 if (player.autoswitch)
133 if (player.switchweapon == w_getbestweapon(player))
134 _switchweapon = TRUE;
136 if not(player.weapons & W_WeaponBit(player.switchweapon))
137 _switchweapon = TRUE;
139 if (item.ammo_shells)
140 if (player.ammo_shells < g_pickup_shells_max)
143 player.ammo_shells = min (player.ammo_shells + item.ammo_shells, g_pickup_shells_max);
146 if (player.ammo_nails < g_pickup_nails_max)
149 player.ammo_nails = min (player.ammo_nails + item.ammo_nails, g_pickup_nails_max);
151 if (item.ammo_rockets)
152 if (player.ammo_rockets < g_pickup_rockets_max)
155 player.ammo_rockets = min (player.ammo_rockets + item.ammo_rockets, g_pickup_rockets_max);
158 if (player.ammo_cells < g_pickup_cells_max)
161 player.ammo_cells = min (player.ammo_cells + item.ammo_cells, g_pickup_cells_max);
164 if (player.ammo_fuel < g_pickup_fuel_max)
167 player.ammo_fuel = min(player.ammo_fuel + item.ammo_fuel, g_pickup_fuel_max);
168 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + cvar("g_balance_pause_fuel_rot"));
171 if (item.flags & FL_WEAPON)
172 if ((it = item.weapons - (item.weapons & player.weapons)))
175 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
177 e = get_weaponinfo(i);
179 W_GiveWeapon (player, e.weapon, item.netname);
183 if((it = (item.items - (item.items & player.items) & IT_PICKUPMASK)))
189 if (item.strength_finished)
192 player.strength_finished = max(player.strength_finished, time) + cvar("g_balance_powerup_strength_time");
194 if (item.invincible_finished)
197 player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
199 //if (item.speed_finished)
202 // player.speed_finished = max(player.speed_finished, time) + cvar("g_balance_powerup_speed_time");
204 //if (item.slowmo_finished)
207 // player.slowmo_finished = max(player.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
211 if (player.health < item.max_health)
214 player.health = min(player.health + item.health, item.max_health);
215 player.pauserothealth_finished = max(player.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
218 if (player.armorvalue < item.max_armorvalue)
221 player.armorvalue = min(player.armorvalue + item.armorvalue, item.max_armorvalue);
222 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + cvar("g_balance_pause_armor_rot"));
227 // always eat teamed entities
234 sound (player, CHAN_AUTO, item.item_pickupsound, VOL_BASE, ATTN_NORM);
236 W_SwitchWeapon_Force(player, w_getbestweapon(player));
241 void Item_Touch (void)
245 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
246 if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
251 if (other.classname != "player")
255 if (self.solid != SOLID_TRIGGER)
257 if (self.owner == other)
260 if(!Item_GiveTo(self, other))
263 if (self.classname == "droppedweapon")
265 else if((self.flags & FL_WEAPON) && !(self.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
269 self.solid = SOLID_NOT;
270 self.model = string_null;
273 RandomSelection_Init();
274 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
275 RandomSelection_Add(head, 0, head.cnt, 0);
276 e = RandomSelection_chosen_ent;
280 e.nextthink = time + self.respawntime;
281 e.think = Item_Respawn;
289 if(self.effects & EF_NODRAW)
291 // marker for item team search
292 dprint("Initializing item team ", ftos(self.team), "\n");
293 RandomSelection_Init();
294 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
295 RandomSelection_Add(head, 0, head.cnt, 0);
296 e = RandomSelection_chosen_ent;
299 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
303 // make it a non-spawned item
304 head.solid = SOLID_NOT;
305 head.model = string_null;
306 head.state = 1; // state 1 = initially hidden item
308 head.effects = head.effects - (head.effects & EF_NODRAW);
317 self.model = string_null;
318 self.solid = SOLID_NOT;
322 self.model = self.mdl;
323 self.solid = SOLID_TRIGGER;
325 setorigin (self, self.origin);
326 self.think = SUB_Null;
330 // Savage: used for item garbage-collection
331 // TODO: perhaps nice special effect?
332 void RemoveItem(void)
337 // pickup evaluation functions
338 // these functions decide how desirable an item is to the bots
340 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;};
342 float weapon_pickupevalfunc(entity player, entity item)
344 // if we already have the weapon, rate it 1/5th normal value
345 if ((player.weapons & item.weapons) == item.weapons)
346 return item.bot_pickupbasevalue * 0.2;
347 return item.bot_pickupbasevalue;
350 float commodity_pickupevalfunc(entity player, entity item)
354 // TODO: figure out if the player even has the weapon this ammo is for?
355 // may not affect strategy much though...
356 // find out how much more ammo/armor/health the player can hold
357 if (item.ammo_shells)
358 if (player.ammo_shells < g_pickup_shells_max)
359 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
361 if (player.ammo_nails < g_pickup_nails_max)
362 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
363 if (item.ammo_rockets)
364 if (player.ammo_rockets < g_pickup_rockets_max)
365 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
367 if (player.ammo_cells < g_pickup_cells_max)
368 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
370 if (player.armorvalue < item.max_armorvalue)
371 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
373 if (player.health < item.max_health)
374 c = c + max(0, 1 - player.health / item.max_health);
376 return item.bot_pickupbasevalue * c;
381 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
383 startitem_failed = FALSE;
385 // is it a dropped weapon?
386 if (self.classname == "droppedweapon")
388 self.reset = SUB_Remove;
389 // it's a dropped weapon
390 self.movetype = MOVETYPE_TOSS;
391 self.solid = SOLID_TRIGGER;
392 // Savage: remove thrown items after a certain period of time ("garbage collection")
393 self.think = RemoveItem;
394 self.nextthink = time + 60;
395 // don't drop if in a NODROP zone (such as lava)
396 traceline(self.origin, self.origin, MOVE_NORMAL, self);
397 if (trace_dpstartcontents & DPCONTENTS_NODROP)
399 startitem_failed = TRUE;
406 self.reset = Item_Reset;
408 if(self.spawnflags & 1)
411 self.movetype = MOVETYPE_NONE;
413 self.movetype = MOVETYPE_TOSS;
414 self.solid = SOLID_TRIGGER;
415 // do item filtering according to game mode and other things
418 // first nudge it off the floor a little bit to avoid math errors
419 setorigin(self, self.origin + '0 0 1');
420 // set item size before we spawn a spawnfunc_waypoint
421 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
422 setsize (self, '-16 -16 0', '16 16 48');
424 setsize (self, '-16 -16 0', '16 16 32');
425 // note droptofloor returns FALSE if stuck/or would fall too far
427 waypoint_spawnforitem(self);
434 print("removed non-teamplay ", self.classname, "\n");
435 startitem_failed = TRUE;
444 print("removed non-FFA ", self.classname, "\n");
445 startitem_failed = TRUE;
453 // We aren't TA or something like that, so we keep the Q3A entities
454 print("removed non-Q3A ", self.classname, "\n");
455 startitem_failed = TRUE;
461 * can't do it that way, as it would break maps
462 * TODO make a target_give like entity another way, that perhaps has
463 * the weapon name in a key
466 // target_give not yet supported; maybe later
467 print("removed targeted ", self.classname, "\n");
468 startitem_failed = TRUE;
474 if(cvar("spawn_debug") >= 2)
477 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
479 if(otheritem.is_item)
481 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
482 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
483 error("Mapper sucks.");
489 weaponsInMap |= weaponid;
493 startitem_failed = TRUE;
497 else if (g_weaponarena && ((weaponid & WEPBIT_ALL) || (itemid & IT_AMMO)))
499 startitem_failed = TRUE;
503 else if (g_minstagib)
505 // don't remove dropped items and powerups
506 if (self.classname != "minstagib")
508 startitem_failed = TRUE;
513 else if ((!cvar("g_pickup_items") || g_nixnex) && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
515 startitem_failed = TRUE;
520 precache_model (itemmodel);
521 precache_sound (pickupsound);
522 precache_sound ("misc/itemrespawn.wav");
524 if((itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)) || (weaponid & WEPBIT_ALL))
525 self.target = "###item###"; // for finding the nearest item using find()
528 self.bot_pickup = TRUE;
529 self.bot_pickupevalfunc = pickupevalfunc;
530 self.bot_pickupbasevalue = pickupbasevalue;
531 self.mdl = itemmodel;
532 self.item_pickupsound = pickupsound;
533 // let mappers override respawntime
534 if (!self.respawntime)
535 self.respawntime = defaultrespawntime;
536 self.netname = itemname;
538 self.weapons = weaponid;
539 self.flags = FL_ITEM | itemflags;
540 self.touch = Item_Touch;
541 setmodel (self, self.mdl); // precision set below
542 self.effects |= EF_LOWPRECISION;
543 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
544 setsize (self, '-16 -16 0', '16 16 48');
546 setsize (self, '-16 -16 0', '16 16 32');
547 if(itemflags & FL_WEAPON)
548 self.modelflags |= MF_ROTATE;
550 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
551 if (itemflags & FL_WEAPON)
553 // neutral team color for pickup weapons
554 self.colormap = 1024; // color shirt=0 pants=0 grey
557 if (cvar("g_fullbrightitems"))
558 self.effects = self.effects | EF_FULLBRIGHT;
564 self.cnt = 1; // item probability weight
565 self.effects = self.effects | EF_NODRAW; // marker for item team search
566 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
570 /* replace items in minstagib
571 * IT_STRENGTH = invisibility
572 * IT_NAILS = extra lives
573 * IT_INVINCIBLE = speed
575 void minstagib_items (float itemid)
577 // we don't want to replace dropped weapons ;)
578 if (self.classname == "droppedweapon")
580 self.ammo_cells = 25;
581 StartItem ("models/weapons/g_nex.md3",
582 "weapons/weaponpickup.wav", 15,
583 "MinstaNex", 0, WEPBIT_MINSTANEX, FL_WEAPON, generic_pickupevalfunc, 1000);
588 self.classname = "minstagib";
590 // replace rocket launchers and nex guns with ammo cells
591 if (itemid == IT_CELLS)
594 StartItem ("models/items/a_cells.md3",
595 "misc/itempickup.wav", 45,
596 "Nex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
603 itemid = IT_STRENGTH;
607 itemid = IT_INVINCIBLE;
609 // replace with invis
610 if (itemid == IT_STRENGTH)
612 self.effects = EF_ADDITIVE;
613 self.strength_finished = 30;
614 StartItem ("models/items/g_strength.md3",
615 "misc/powerup.wav", g_pickup_respawntime_powerup,
616 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
618 // replace with extra lives
619 if (itemid == IT_NAILS)
622 StartItem ("models/items/g_h100.md3",
623 "misc/megahealth.wav", g_pickup_respawntime_powerup,
624 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
627 // replace with speed
628 if (itemid == IT_INVINCIBLE)
630 self.effects = EF_ADDITIVE;
631 self.invincible_finished = 30;
632 StartItem ("models/items/g_invincible.md3",
633 "misc/powerup_shield.wav", g_pickup_respawntime_powerup,
634 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
639 float minst_no_auto_cells;
640 void minst_remove_item (void) {
641 if(minst_no_auto_cells)
645 float weaponswapping;
648 void weapon_defaultspawnfunc(float wpn)
652 var .float ammofield;
657 // set the respawntime in advance (so replaced weapons can copy it)
658 if(!self.respawntime)
660 e = get_weaponinfo(wpn);
661 if(e.items == IT_SUPERWEAPON)
662 self.respawntime = g_pickup_respawntime_powerup;
664 self.respawntime = g_pickup_respawntime_weapon;
667 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
669 e = get_weaponinfo(wpn);
670 s = cvar_string(strcat("g_weaponreplace_", e.netname));
674 startitem_failed = TRUE;
677 t = tokenize_sane(s);
680 self.team = --internalteam;
682 for(i = 1; i < t; ++i)
685 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
687 e = get_weaponinfo(j);
691 copyentity(oldself, self);
692 self.classname = "replacedweapon";
693 weapon_defaultspawnfunc(j);
699 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
708 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
710 e = get_weaponinfo(j);
719 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
725 startitem_failed = TRUE;
730 e = get_weaponinfo(wpn);
732 if(e.items && e.items != IT_SUPERWEAPON)
734 ammofield = Item_CounterField(e.items);
736 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(e.items)));
740 self.flags |= FL_NO_WEAPON_STAY;
743 // weapon stay isn't supported for teamed weapons
745 self.flags |= FL_NO_WEAPON_STAY;
747 if(g_weapon_stay == 2 && self.classname != "droppedweapon")
749 self.ammo_shells = 0;
752 self.ammo_rockets = 0;
753 // weapon stay 2: don't use ammo on weapon pickups; instead
754 // initialize all ammo types to the pickup ammo unless set by g_start_ammo_*
757 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, e.bot_pickupbasevalue);
758 if (self.modelindex) // don't precache if self was removed
759 weapon_action(e.weapon, WR_PRECACHE);
762 void spawnfunc_weapon_shotgun (void);
763 void spawnfunc_weapon_uzi (void) {
764 if(q3acompat_machineshotgunswap)
765 if(self.classname != "droppedweapon")
767 weapon_defaultspawnfunc(WEP_SHOTGUN);
770 weapon_defaultspawnfunc(WEP_UZI);
773 void spawnfunc_weapon_shotgun (void) {
774 if(q3acompat_machineshotgunswap)
775 if(self.classname != "droppedweapon")
777 weapon_defaultspawnfunc(WEP_UZI);
780 weapon_defaultspawnfunc(WEP_SHOTGUN);
783 void spawnfunc_weapon_nex (void)
787 minstagib_items(IT_CELLS);
788 self.think = minst_remove_item;
789 self.nextthink = time;
792 weapon_defaultspawnfunc(WEP_NEX);
795 void spawnfunc_weapon_minstanex (void)
799 minstagib_items(IT_CELLS);
800 self.think = minst_remove_item;
801 self.nextthink = time;
804 weapon_defaultspawnfunc(WEP_MINSTANEX);
807 void spawnfunc_weapon_rocketlauncher (void)
811 minstagib_items(IT_CELLS);
812 self.think = minst_remove_item;
813 self.nextthink = time;
816 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
819 void spawnfunc_item_rockets (void) {
820 if(!self.ammo_rockets)
821 self.ammo_rockets = g_pickup_rockets;
822 StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
825 void spawnfunc_item_shells (void);
826 void spawnfunc_item_bullets (void) {
828 if(q3acompat_machineshotgunswap)
829 if(self.classname != "droppedweapon")
831 weaponswapping = TRUE;
832 spawnfunc_item_shells();
833 weaponswapping = FALSE;
838 self.ammo_nails = g_pickup_nails;
839 StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", g_pickup_respawntime_ammo, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
842 void spawnfunc_item_cells (void) {
844 self.ammo_cells = g_pickup_cells;
845 StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
848 void spawnfunc_item_shells (void) {
850 if(q3acompat_machineshotgunswap)
851 if(self.classname != "droppedweapon")
853 weaponswapping = TRUE;
854 spawnfunc_item_bullets();
855 weaponswapping = FALSE;
859 if(!self.ammo_shells)
860 self.ammo_shells = g_pickup_shells;
861 StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
864 void spawnfunc_item_armor_small (void) {
866 self.armorvalue = g_pickup_armorsmall;
867 if(!self.max_armorvalue)
868 self.max_armorvalue = g_pickup_armorsmall_max;
869 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);
872 void spawnfunc_item_armor_medium (void) {
874 self.armorvalue = g_pickup_armormedium;
875 if(!self.max_armorvalue)
876 self.max_armorvalue = g_pickup_armormedium_max;
877 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);
880 void spawnfunc_item_armor_big (void) {
882 self.armorvalue = g_pickup_armorbig;
883 if(!self.max_armorvalue)
884 self.max_armorvalue = g_pickup_armorbig_max;
885 StartItem ("models/items/g_a50.md3", "misc/armor17_5.wav", g_pickup_respawntime_long, "50 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
888 void spawnfunc_item_armor_large (void) {
890 self.armorvalue = g_pickup_armorlarge;
891 if(!self.max_armorvalue)
892 self.max_armorvalue = g_pickup_armorlarge_max;
893 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);
896 void spawnfunc_item_health_small (void) {
898 self.max_health = g_pickup_healthsmall_max;
900 self.health = g_pickup_healthsmall;
901 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);
904 void spawnfunc_item_health_medium (void) {
906 self.max_health = g_pickup_healthmedium_max;
908 self.health = g_pickup_healthmedium;
909 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);
912 void spawnfunc_item_health_large (void) {
914 self.max_health = g_pickup_healthlarge_max;
916 self.health = g_pickup_healthlarge;
917 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);
920 void spawnfunc_item_health_mega (void) {
921 if(!cvar("g_powerup_superhealth"))
924 if(g_arena && !cvar("g_arena_powerups"))
928 minstagib_items(IT_NAILS);
931 self.max_health = g_pickup_healthmega_max;
933 self.health = g_pickup_healthmega;
934 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);
938 // support old misnamed entities
939 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Nexuiz maps it is an armor shard
940 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
941 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
942 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
943 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
945 void spawnfunc_item_strength (void) {
946 if(!cvar("g_powerup_strength"))
949 if(g_arena && !cvar("g_arena_powerups"))
953 minstagib_items(IT_STRENGTH);
955 precache_sound("weapons/strength_fire.wav");
956 self.strength_finished = 30;
957 self.effects = EF_ADDITIVE;
958 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", g_pickup_respawntime_powerup, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
962 void spawnfunc_item_invincible (void) {
963 if(!cvar("g_powerup_shield"))
966 if(g_arena && !cvar("g_arena_powerups"))
970 minstagib_items(IT_INVINCIBLE);
972 self.invincible_finished = 30;
973 self.effects = EF_ADDITIVE;
974 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", g_pickup_respawntime_powerup, "Invulnerability", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
978 void spawnfunc_item_minst_cells (void) {
981 minst_no_auto_cells = 1;
982 minstagib_items(IT_CELLS);
989 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
991 void spawnfunc_misc_models (void)
993 // exists as alias name for 2.4.2 compat
994 SetBrushEntityModel();
997 void spawnfunc_func_static (void)
999 // exists as alias name for having it with brushes
1000 SetBrushEntityModel();
1003 void func_wall_use (void)
1008 self.colormap = (activator.team - 1) * 0x11;
1010 self.colormap = 0x00;
1013 self.colormap = floor(random() * 256);
1014 self.colormap |= 1024; // RENDER_COLORMAPPED
1017 void spawnfunc_func_wall (void)
1019 SetBrushEntityModel();
1021 self.solid = SOLID_BSP;
1022 self.use = func_wall_use;
1025 void spawnfunc_func_illusionary (void)
1027 SetBrushEntityModel();
1028 self.use = func_wall_use;
1031 void gamemodel_drop()
1033 if(self.spawnflags & 3 == 1) // ALIGN_ORIGIN
1035 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
1036 setorigin(self, trace_endpos);
1038 else if(self.spawnflags & 3 == 2) // ALIGN_BOTTOM
1040 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
1041 setorigin(self, trace_endpos);
1043 else if(self.spawnflags & 3 == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
1045 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
1046 setorigin(self, trace_endpos - '0 0 1' * self.mins_z);
1051 void spawnfunc_misc_gamemodel (void)
1054 self.scale = self.modelscale;
1055 SetBrushEntityModel();
1056 self.use = func_wall_use;
1058 InitializeEntity(self, gamemodel_drop, INITPRIO_DROPTOFLOOR);
1061 float target_item_func_set(float a, float b)
1071 float target_item_func_min(float a, float b)
1081 float target_item_func_max(float a, float b)
1086 float target_item_func_bitset(float a, float b)
1091 float target_item_func_and(float a, float b)
1096 float target_item_func_itembitset(float a, float b)
1098 return (a - (a & (IT_UNLIMITED_WEAPON_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | b;
1101 float target_item_func_itemand(float a, float b)
1103 return (a - (a & (IT_UNLIMITED_WEAPON_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | (a & b);
1106 float target_item_func_or(float a, float b)
1111 float target_item_func_andnot(float a, float b)
1116 float target_item_changed;
1117 void target_item_change(float binary, .float field, float(float a, float b) func, string sound_increase, string sound_decrease)
1120 n = func(activator.field, self.field);
1124 d = n & activator.field;
1125 if(d != n) // bits added?
1127 else if(d != activator.field) // bits removed?
1133 d = n - activator.field;
1137 if(sound_decrease != "")
1138 sound (activator, CHAN_AUTO, sound_decrease, VOL_BASE, ATTN_NORM);
1139 target_item_changed = 1;
1143 if(sound_increase != "")
1144 sound (activator, CHAN_AUTO, sound_increase, VOL_BASE, ATTN_NORM);
1145 target_item_changed = 1;
1147 activator.field = n;
1150 void target_items_use (void)
1153 if(activator.classname != "player")
1155 if(activator.deadflag != DEAD_NO)
1160 for(e = world; (e = find(e, classname, "droppedweapon")); )
1161 if(e.enemy == activator)
1164 float _switchweapon;
1165 _switchweapon = FALSE;
1166 if (activator.autoswitch)
1167 if (activator.switchweapon == w_getbestweapon(activator))
1168 _switchweapon = TRUE;
1170 a0 = activator.armorvalue;
1171 h0 = activator.health;
1172 target_item_changed = 0;
1174 if(self.spawnflags == 0) // SET
1176 target_item_change(0, ammo_shells, target_item_func_set, "misc/itempickup.wav", "");
1177 target_item_change(0, ammo_nails, target_item_func_set, "misc/itempickup.wav", "");
1178 target_item_change(0, ammo_rockets, target_item_func_set, "misc/itempickup.wav", "");
1179 target_item_change(0, ammo_cells, target_item_func_set, "misc/itempickup.wav", "");
1180 target_item_change(0, ammo_fuel, target_item_func_set, "misc/itempickup.wav", "");
1181 target_item_change(0, health, target_item_func_set, "misc/megahealth.wav", "");
1182 target_item_change(0, armorvalue, target_item_func_set, "misc/armor25.wav", "");
1183 target_item_change(1, items, target_item_func_itembitset, "misc/powerup.wav", "");
1184 target_item_change(1, weapons, target_item_func_bitset, "weapons/weaponpickup.wav", "");
1186 if((self.items & activator.items) & IT_STRENGTH)
1187 activator.strength_finished = time + self.strength_finished;
1188 if((self.items & activator.items) & IT_INVINCIBLE)
1189 activator.invincible_finished = time + self.invincible_finished;
1191 else if(self.spawnflags == 1) // AND/MIN
1193 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1194 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1195 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1196 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1197 target_item_change(0, ammo_fuel, target_item_func_min, "misc/itempickup.wav", "");
1198 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1199 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1200 target_item_change(1, items, target_item_func_itemand, "misc/powerup.wav", "");
1201 target_item_change(1, weapons, target_item_func_and, "weapons/weaponpickup.wav", "");
1203 if((self.items & activator.items) & IT_STRENGTH)
1204 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1205 if((self.items & activator.items) & IT_INVINCIBLE)
1206 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1208 else if(self.spawnflags == 2) // OR/MAX
1210 target_item_change(0, ammo_shells, target_item_func_max, "misc/itempickup.wav", "");
1211 target_item_change(0, ammo_nails, target_item_func_max, "misc/itempickup.wav", "");
1212 target_item_change(0, ammo_rockets, target_item_func_max, "misc/itempickup.wav", "");
1213 target_item_change(0, ammo_cells, target_item_func_max, "misc/itempickup.wav", "");
1214 target_item_change(0, ammo_fuel, target_item_func_max, "misc/itempickup.wav", "");
1215 target_item_change(0, health, target_item_func_max, "misc/megahealth.wav", "");
1216 target_item_change(0, armorvalue, target_item_func_max, "misc/armor25.wav", "");
1217 target_item_change(1, items, target_item_func_or, "misc/powerup.wav", "");
1218 target_item_change(1, weapons, target_item_func_or, "weapons/weaponpickup.wav", "");
1220 if((self.items & activator.items) & IT_STRENGTH)
1221 activator.strength_finished = max(activator.strength_finished, time + self.strength_finished);
1222 if((self.items & activator.items) & IT_INVINCIBLE)
1223 activator.invincible_finished = max(activator.invincible_finished, time + self.invincible_finished);
1225 else if(self.spawnflags == 4) // ANDNOT/MIN
1227 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1228 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1229 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1230 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1231 target_item_change(0, ammo_fuel, target_item_func_min, "misc/itempickup.wav", "");
1232 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1233 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1234 target_item_change(1, items, target_item_func_andnot, "misc/powerup.wav", "");
1235 target_item_change(1, weapons, target_item_func_andnot, "weapons/weaponpickup.wav", "");
1237 if((self.items & activator.items) & IT_STRENGTH)
1238 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1239 if((self.items & activator.items) & IT_INVINCIBLE)
1240 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1243 if not(activator.items & IT_STRENGTH)
1244 activator.strength_finished = 0;
1245 if not(activator.items & IT_INVINCIBLE)
1246 activator.invincible_finished = 0;
1248 if(activator.health > h0)
1249 activator.pauserothealth_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1250 else if(activator.health < h0)
1251 activator.pauseregen_finished = max(activator.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
1253 if(activator.armorvalue > a0)
1254 activator.pauserotarmor_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1256 if not(activator.weapons & W_WeaponBit(activator.switchweapon))
1257 _switchweapon = TRUE;
1259 W_SwitchWeapon_Force(activator, w_getbestweapon(activator));
1261 if(target_item_changed)
1262 centerprint(activator, self.message);
1265 void spawnfunc_target_items (void)
1269 self.use = target_items_use;
1270 if(!self.strength_finished)
1271 self.strength_finished = cvar("g_balance_powerup_strength_time");
1272 if(!self.invincible_finished)
1273 self.invincible_finished = cvar("g_balance_powerup_invincible_time");
1275 precache_sound("misc/itempickup.wav");
1276 precache_sound("misc/itempickup.wav");
1277 precache_sound("misc/itempickup.wav");
1278 precache_sound("misc/itempickup.wav");
1279 precache_sound("misc/megahealth.wav");
1280 precache_sound("misc/armor25.wav");
1281 precache_sound("misc/powerup.wav");
1282 precache_sound("weapons/weaponpickup.wav");
1284 n = tokenize_sane(self.netname);
1285 for(i = 0; i < n; ++i)
1287 if(argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1288 if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1289 if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1290 if(argv(i) == "strength") self.items |= IT_STRENGTH;
1291 if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1292 if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1293 if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1294 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1296 e = get_weaponinfo(j);
1297 if(argv(i) == e.netname)
1299 self.weapons |= e.weapons;
1300 if(self.spawnflags == 0 || self.spawnflags == 2)
1301 weapon_action(e.weapon, WR_PRECACHE);
1307 void spawnfunc_item_fuel(void)
1310 self.ammo_fuel = g_pickup_fuel;
1311 StartItem ("models/items/g_fuel.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "Fuel", IT_FUEL, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1314 void spawnfunc_item_fuel_regen(void)
1316 StartItem ("models/items/g_fuelregen.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, "Fuel regenerator", IT_FUEL_REGEN, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1319 void spawnfunc_item_jetpack(void)
1322 self.ammo_fuel = g_pickup_fuel_jetpack;
1323 StartItem ("models/items/g_jetpack.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, "Jet pack", IT_JETPACK, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);