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.ogg");
68 else if(player.health < 50)
69 announce(player, "announcer/robotic/narrowly.ogg");
70 // sound not available
71 // else if(item.items == IT_CELLS)
72 // play2(player, "announce/robotic/ammo.ogg");
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.ogg");
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.ogg");
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.ogg");
106 player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
111 if (cvar("deathmatch") == 2 || cvar("g_weapon_stay"))
113 if (item.flags & FL_WEAPON && player.weapons & item.weapons && item.classname != "droppedweapon")
115 if (player.weapons & item.weapons && item.flags & FL_TOSSED) // don't let players stack ammo by tossing weapons
119 // in case the player has autoswitch enabled do the following:
120 // if the player is using their best weapon before items are given, they
121 // probably want to switch to an even better weapon after items are given
122 if (player.autoswitch)
123 if (player.switchweapon == w_getbestweapon(player))
124 _switchweapon = TRUE;
126 if not(player.weapons & W_WeaponBit(player.switchweapon))
127 _switchweapon = TRUE;
129 if (item.ammo_shells)
130 if (player.ammo_shells < g_pickup_shells_max)
133 player.ammo_shells = min (player.ammo_shells + item.ammo_shells, g_pickup_shells_max);
136 if (player.ammo_nails < g_pickup_nails_max)
139 player.ammo_nails = min (player.ammo_nails + item.ammo_nails, g_pickup_nails_max);
141 if (item.ammo_rockets)
142 if (player.ammo_rockets < g_pickup_rockets_max)
145 player.ammo_rockets = min (player.ammo_rockets + item.ammo_rockets, g_pickup_rockets_max);
148 if (player.ammo_cells < g_pickup_cells_max)
151 player.ammo_cells = min (player.ammo_cells + item.ammo_cells, g_pickup_cells_max);
154 if (item.flags & FL_WEAPON)
155 if ((it = item.weapons - (item.weapons & player.weapons)))
158 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
160 e = get_weaponinfo(i);
162 W_GiveWeapon (player, e.weapon, item.netname);
166 if (item.strength_finished)
169 player.strength_finished = max(player.strength_finished, time) + cvar("g_balance_powerup_strength_time");
171 if (item.invincible_finished)
174 player.invincible_finished = max(player.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
176 //if (item.speed_finished)
179 // player.speed_finished = max(player.speed_finished, time) + cvar("g_balance_powerup_speed_time");
181 //if (item.slowmo_finished)
184 // player.slowmo_finished = max(player.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
188 if (player.health < item.max_health)
191 player.health = min(player.health + item.health, item.max_health);
192 player.pauserothealth_finished = max(player.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
195 if (player.armorvalue < item.max_armorvalue)
198 player.armorvalue = min(player.armorvalue + item.armorvalue, item.max_armorvalue);
199 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + cvar("g_balance_pause_armor_rot"));
203 // always eat teamed entities
210 sound (player, CHAN_AUTO, item.item_pickupsound, VOL_BASE, ATTN_NORM);
212 W_SwitchWeapon_Force(player, w_getbestweapon(player));
217 void Item_Touch (void)
221 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
222 if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
227 if (other.classname != "player")
231 if (self.solid != SOLID_TRIGGER)
233 if (self.owner == other)
236 if(!Item_GiveTo(self, other))
239 if (self.classname == "droppedweapon")
241 else if((self.flags & FL_WEAPON) && !self.team && (cvar("deathmatch") == 2 || cvar("g_weapon_stay")))
245 self.solid = SOLID_NOT;
246 self.model = string_null;
249 RandomSelection_Init();
250 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
251 RandomSelection_Add(head, 0, 1, 0);
252 e = RandomSelection_chosen_ent;
256 e.nextthink = time + self.respawntime;
257 e.think = Item_Respawn;
265 if(self.effects & EF_NODRAW)
267 // marker for item team search
268 dprint("Initializing item team ", ftos(self.team), "\n");
269 RandomSelection_Init();
270 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
271 RandomSelection_Add(head, 0, 1, 0);
272 e = RandomSelection_chosen_ent;
274 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
278 // make it a non-spawned item
279 head.solid = SOLID_NOT;
280 head.model = string_null;
282 head.effects = head.effects - (head.effects & EF_NODRAW);
287 // Savage: used for item garbage-collection
288 // TODO: perhaps nice special effect?
289 void RemoveItem(void) /*FIXDECL*/
294 // pickup evaluation functions
295 // these functions decide how desirable an item is to the bots
297 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;};
299 float weapon_pickupevalfunc(entity player, entity item)
301 // if we already have the weapon, rate it 1/5th normal value
302 if ((player.weapons & item.weapons) == item.weapons)
303 return item.bot_pickupbasevalue * 0.2;
304 return item.bot_pickupbasevalue;
307 float commodity_pickupevalfunc(entity player, entity item)
311 // TODO: figure out if the player even has the weapon this ammo is for?
312 // may not affect strategy much though...
313 // find out how much more ammo/armor/health the player can hold
314 if (item.ammo_shells)
315 if (player.ammo_shells < g_pickup_shells_max)
316 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
318 if (player.ammo_nails < g_pickup_nails_max)
319 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
320 if (item.ammo_rockets)
321 if (player.ammo_rockets < g_pickup_rockets_max)
322 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
324 if (player.ammo_cells < g_pickup_cells_max)
325 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
327 if (player.armorvalue < item.max_armorvalue)
328 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
330 if (player.health < item.max_health)
331 c = c + max(0, 1 - player.health / item.max_health);
333 return item.bot_pickupbasevalue * c;
338 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
340 startitem_failed = FALSE;
342 // is it a dropped weapon?
343 if (self.classname == "droppedweapon")
345 // it's a dropped weapon
346 self.movetype = MOVETYPE_TOSS;
347 self.solid = SOLID_TRIGGER;
348 // Savage: remove thrown items after a certain period of time ("garbage collection")
349 self.think = RemoveItem;
350 self.nextthink = time + 60;
351 // don't drop if in a NODROP zone (such as lava)
352 traceline(self.origin, self.origin, MOVE_NORMAL, self);
353 if (trace_dpstartcontents & DPCONTENTS_NODROP)
355 startitem_failed = TRUE;
363 if(self.spawnflags & 1)
366 self.movetype = MOVETYPE_NONE;
368 self.movetype = MOVETYPE_TOSS;
369 self.solid = SOLID_TRIGGER;
370 // do item filtering according to game mode and other things
373 // first nudge it off the floor a little bit to avoid math errors
374 setorigin(self, self.origin + '0 0 1');
375 // set item size before we spawn a spawnfunc_waypoint
376 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
377 setsize (self, '-16 -16 0', '16 16 48');
379 setsize (self, '-16 -16 0', '16 16 32');
380 // note droptofloor returns FALSE if stuck/or would fall too far
382 waypoint_spawnforitem(self);
389 print("removed non-teamplay ", self.classname, "\n");
390 startitem_failed = TRUE;
399 print("removed non-FFA ", self.classname, "\n");
400 startitem_failed = TRUE;
408 // We aren't TA or something like that, so we keep the Q3A entities
409 print("removed non-Q3A ", self.classname, "\n");
410 startitem_failed = TRUE;
416 * can't do it that way, as it would break maps
417 * TODO make a target_give like entity another way, that perhaps has
418 * the weapon name in a key
421 // target_give not yet supported; maybe later
422 print("removed targeted ", self.classname, "\n");
423 startitem_failed = TRUE;
429 if(cvar("spawn_debug") >= 2)
432 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
434 if(otheritem.is_item)
436 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
437 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
438 error("Mapper sucks.");
444 weaponsInMap |= weaponid;
446 if(g_lms || g_rocketarena)
448 startitem_failed = TRUE;
452 else if (g_minstagib)
454 // don't remove dropped items and powerups
455 if (self.classname != "minstagib")
457 startitem_failed = TRUE;
462 else if ((!cvar("g_pickup_items") || g_nixnex) && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
464 startitem_failed = TRUE;
469 precache_model (itemmodel);
470 precache_sound (pickupsound);
471 precache_sound ("misc/itemrespawn.wav");
473 if((itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)) || (weaponid & WEPBIT_ALL))
474 self.target = "###item###"; // for finding the nearest item using find()
477 self.bot_pickup = TRUE;
478 self.bot_pickupevalfunc = pickupevalfunc;
479 self.bot_pickupbasevalue = pickupbasevalue;
480 self.mdl = itemmodel;
481 self.item_pickupsound = pickupsound;
482 // let mappers override respawntime
483 if (!self.respawntime)
484 self.respawntime = defaultrespawntime;
485 self.netname = itemname;
487 self.weapons = weaponid;
488 self.flags = FL_ITEM | itemflags;
489 self.touch = Item_Touch;
490 setmodel (self, self.mdl); // precision set below
491 self.effects |= EF_LOWPRECISION;
492 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
493 setsize (self, '-16 -16 0', '16 16 48');
495 setsize (self, '-16 -16 0', '16 16 32');
496 if (itemflags & FL_WEAPON)
498 // neutral team color for pickup weapons
499 self.colormap = 160 * 1024 + 160;
502 if (cvar("g_fullbrightitems"))
503 self.effects = self.effects | EF_FULLBRIGHT;
507 self.effects = self.effects | EF_NODRAW; // marker for item team search
508 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
512 /* replace items in minstagib
513 * IT_STRENGTH = invisibility
514 * IT_NAILS = extra lives
515 * IT_INVINCIBLE = speed
517 void minstagib_items (float itemid)
519 // we don't want to replace dropped weapons ;)
520 if (self.classname == "droppedweapon")
522 self.ammo_cells = 25;
523 StartItem ("models/weapons/g_nex.md3",
524 "weapons/weaponpickup.wav", 15,
525 "MinstaNex", 0, WEPBIT_MINSTANEX, FL_WEAPON, generic_pickupevalfunc, 1000);
530 self.classname = "minstagib";
532 // replace rocket launchers and nex guns with ammo cells
533 if (itemid == IT_CELLS)
536 StartItem ("models/items/a_cells.md3",
537 "misc/itempickup.wav", 45,
538 "Nex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
545 itemid = IT_STRENGTH;
549 itemid = IT_INVINCIBLE;
551 // replace with invis
552 if (itemid == IT_STRENGTH)
554 self.effects = EF_ADDITIVE;
555 self.strength_finished = 30;
556 StartItem ("models/items/g_strength.md3",
557 "misc/powerup.wav", g_pickup_respawntime_powerup,
558 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
560 // replace with extra lives
561 if (itemid == IT_NAILS)
564 StartItem ("models/items/g_h100.md3",
565 "misc/megahealth.wav", g_pickup_respawntime_powerup,
566 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
569 // replace with speed
570 if (itemid == IT_INVINCIBLE)
572 self.effects = EF_ADDITIVE;
573 self.invincible_finished = 30;
574 StartItem ("models/items/g_invincible.md3",
575 "misc/powerup_shield.wav", g_pickup_respawntime_powerup,
576 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
581 float minst_no_auto_cells;
582 void minst_remove_item (void) {
583 if(minst_no_auto_cells)
587 float weaponswapping;
590 void weapon_defaultspawnfunc(float wpn)
594 var .float ammofield;
599 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
601 s = cvar_string(strcat("g_weaponreplace_", ftos(wpn)));
605 self.team = --internalteam;
606 for(i = 1; i < t; ++i)
610 copyentity(oldself, self);
611 self.classname = "replacedweapon";
612 weapon_defaultspawnfunc(stof(argv(i)));
614 print("replaced by ", argv(i), "\n");
621 e = get_weaponinfo(wpn);
623 t = g_pickup_respawntime_short;
625 if(e.items && e.items != IT_SUPERWEAPON)
627 ammofield = Item_CounterField(e.items);
629 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(e.items)));
632 if(e.items == IT_SUPERWEAPON)
633 t = g_pickup_respawntime_powerup;
635 StartItem(e.model, "weapons/weaponpickup.wav", t, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, e.bot_pickupbasevalue);
636 if (self.modelindex) // don't precache if self was removed
637 weapon_action(e.weapon, WR_PRECACHE);
640 void spawnfunc_weapon_shotgun (void);
641 void spawnfunc_weapon_uzi (void) {
642 if(q3acompat_machineshotgunswap)
643 if(self.classname != "droppedweapon")
645 weapon_defaultspawnfunc(WEP_SHOTGUN);
648 weapon_defaultspawnfunc(WEP_UZI);
651 void spawnfunc_weapon_shotgun (void) {
652 if(q3acompat_machineshotgunswap)
653 if(self.classname != "droppedweapon")
655 weapon_defaultspawnfunc(WEP_UZI);
658 weapon_defaultspawnfunc(WEP_SHOTGUN);
661 void spawnfunc_weapon_nex (void)
665 minstagib_items(IT_CELLS);
666 self.think = minst_remove_item;
667 self.nextthink = time + cvar("sys_ticrate");
670 weapon_defaultspawnfunc(WEP_NEX);
673 void spawnfunc_weapon_minstanex (void)
677 minstagib_items(IT_CELLS);
678 self.think = minst_remove_item;
679 self.nextthink = time + cvar("sys_ticrate");
682 weapon_defaultspawnfunc(WEP_MINSTANEX);
685 void spawnfunc_weapon_rocketlauncher (void)
689 minstagib_items(IT_CELLS);
690 self.think = minst_remove_item;
691 self.nextthink = time + cvar("sys_ticrate");
694 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
697 void spawnfunc_item_rockets (void) {
698 if(!self.ammo_rockets)
699 self.ammo_rockets = g_pickup_rockets;
700 StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", g_pickup_respawntime_short, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
703 void spawnfunc_item_shells (void);
704 void spawnfunc_item_bullets (void) {
706 if(q3acompat_machineshotgunswap)
707 if(self.classname != "droppedweapon")
709 weaponswapping = TRUE;
710 spawnfunc_item_shells();
711 weaponswapping = FALSE;
716 self.ammo_nails = g_pickup_nails;
717 StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", g_pickup_respawntime_short, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
720 void spawnfunc_item_cells (void) {
722 self.ammo_cells = g_pickup_cells;
723 StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_short, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
726 void spawnfunc_item_shells (void) {
728 if(q3acompat_machineshotgunswap)
729 if(self.classname != "droppedweapon")
731 weaponswapping = TRUE;
732 spawnfunc_item_bullets();
733 weaponswapping = FALSE;
737 if(!self.ammo_shells)
738 self.ammo_shells = g_pickup_shells;
739 StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", g_pickup_respawntime_short, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
742 void spawnfunc_item_armor_small (void) {
744 self.armorvalue = g_pickup_armorsmall;
745 if(!self.max_armorvalue)
746 self.max_armorvalue = g_pickup_armorsmall_max;
747 StartItem ("models/items/g_a1.md3", "misc/armor1.wav", g_pickup_respawntime_short, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, 1000);
750 void spawnfunc_item_armor_medium (void) {
752 self.armorvalue = g_pickup_armormedium;
753 if(!self.max_armorvalue)
754 self.max_armorvalue = g_pickup_armormedium_max;
755 StartItem ("models/items/g_armormedium.md3", "misc/armor1.wav", g_pickup_respawntime_medium, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
758 void spawnfunc_item_armor_large (void) {
760 self.armorvalue = g_pickup_armorlarge;
761 if(!self.max_armorvalue)
762 self.max_armorvalue = g_pickup_armorlarge_max;
763 StartItem ("models/items/g_a25.md3", "misc/armor25.wav", g_pickup_respawntime_long, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
766 void spawnfunc_item_health_small (void) {
768 self.max_health = g_pickup_healthsmall_max;
770 self.health = g_pickup_healthsmall;
771 StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", g_pickup_respawntime_short, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, 20000);
774 void spawnfunc_item_health_medium (void) {
776 self.max_health = g_pickup_healthmedium_max;
778 self.health = g_pickup_healthmedium;
779 StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", g_pickup_respawntime_short, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, 20000);
782 void spawnfunc_item_health_large (void) {
784 self.max_health = g_pickup_healthlarge_max;
786 self.health = g_pickup_healthlarge;
787 StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", g_pickup_respawntime_medium, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, 20000);
790 void spawnfunc_item_health_mega (void) {
791 if(!cvar("g_powerup_superhealth"))
794 if(g_arena && !cvar("g_arena_powerups"))
798 minstagib_items(IT_NAILS);
801 self.max_health = g_pickup_healthmega_max;
803 self.health = g_pickup_healthmega;
804 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", g_pickup_respawntime_long, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, 20000);
808 // support old misnamed entities
809 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Nexuiz maps it is an armor shard
810 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
811 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
812 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
813 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
815 void spawnfunc_item_strength (void) {
816 if(!cvar("g_powerup_strength"))
819 if(g_arena && !cvar("g_arena_powerups"))
823 minstagib_items(IT_STRENGTH);
825 precache_sound("weapons/strength_fire.wav");
826 self.strength_finished = 30;
827 self.effects = EF_ADDITIVE;
828 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", g_pickup_respawntime_powerup, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
832 void spawnfunc_item_invincible (void) {
833 if(!cvar("g_powerup_shield"))
836 if(g_arena && !cvar("g_arena_powerups"))
840 minstagib_items(IT_INVINCIBLE);
842 self.invincible_finished = 30;
843 self.effects = EF_ADDITIVE;
844 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", g_pickup_respawntime_powerup, "Invulnerability", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
848 void spawnfunc_item_minst_cells (void) {
851 minst_no_auto_cells = 1;
852 minstagib_items(IT_CELLS);
859 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
861 void spawnfunc_misc_models (void)
863 SetBrushEntityModel();
866 void func_wall_use (void)
871 self.colormap = (activator.team - 1) * 0x11;
873 self.colormap = 0x00;
876 self.colormap = ceil(random() * 256) - 1;
877 self.colormap |= 1024; // RENDER_COLORMAPPED
880 void spawnfunc_func_wall (void)
882 SetBrushEntityModel();
883 self.solid = SOLID_BSP;
884 self.use = func_wall_use;
887 float target_item_func_set(float a, float b)
897 float target_item_func_min(float a, float b)
907 float target_item_func_max(float a, float b)
912 float target_item_func_bitset(float a, float b)
917 float target_item_func_and(float a, float b)
922 float target_item_func_itembitset(float a, float b)
924 return (b - (b & (IT_UNLIMITED_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | a;
927 float target_item_func_itemand(float a, float b)
929 return (b - (b & (IT_UNLIMITED_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | (a & b);
932 float target_item_func_or(float a, float b)
937 float target_item_func_andnot(float a, float b)
942 float target_item_changed;
943 void target_item_change(float binary, .float field, float(float a, float b) func, string sound_increase, string sound_decrease)
946 n = func(activator.field, self.field);
950 d = n & activator.field;
951 if(d != n) // bits added?
953 else if(d != activator.field) // bits removed?
959 d = n - activator.field;
963 if(sound_decrease != "")
964 sound (activator, CHAN_AUTO, sound_decrease, VOL_BASE, ATTN_NORM);
965 target_item_changed = 1;
969 if(sound_increase != "")
970 sound (activator, CHAN_AUTO, sound_increase, VOL_BASE, ATTN_NORM);
971 target_item_changed = 1;
976 void target_items_use (void)
979 if(activator.classname != "player")
981 if(activator.deadflag != DEAD_NO)
986 for(e = world; (e = find(e, classname, "droppedweapon")); )
987 if(e.enemy == activator)
991 _switchweapon = FALSE;
992 if (activator.autoswitch)
993 if (activator.switchweapon == w_getbestweapon(activator))
994 _switchweapon = TRUE;
996 a0 = activator.armorvalue;
997 h0 = activator.health;
998 target_item_changed = 0;
1000 if(self.spawnflags == 0) // SET
1002 target_item_change(0, ammo_shells, target_item_func_set, "misc/itempickup.wav", "");
1003 target_item_change(0, ammo_nails, target_item_func_set, "misc/itempickup.wav", "");
1004 target_item_change(0, ammo_rockets, target_item_func_set, "misc/itempickup.wav", "");
1005 target_item_change(0, ammo_cells, target_item_func_set, "misc/itempickup.wav", "");
1006 target_item_change(0, health, target_item_func_set, "misc/megahealth.wav", "");
1007 target_item_change(0, armorvalue, target_item_func_set, "misc/armor25.wav", "");
1008 target_item_change(1, items, target_item_func_itembitset, "misc/powerup.wav", "");
1009 target_item_change(1, weapons, target_item_func_bitset, "weapons/weaponpickup.wav", "");
1011 if((self.items & activator.items) & IT_STRENGTH)
1012 activator.strength_finished = time + self.strength_finished;
1013 if((self.items & activator.items) & IT_INVINCIBLE)
1014 activator.invincible_finished = time + self.invincible_finished;
1016 else if(self.spawnflags == 1) // AND/MIN
1018 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1019 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1020 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1021 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1022 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1023 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1024 target_item_change(1, items, target_item_func_itemand, "misc/powerup.wav", "");
1025 target_item_change(1, weapons, target_item_func_and, "weapons/weaponpickup.wav", "");
1027 if((self.items & activator.items) & IT_STRENGTH)
1028 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1029 if((self.items & activator.items) & IT_INVINCIBLE)
1030 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1032 else if(self.spawnflags == 2) // OR/MAX
1034 target_item_change(0, ammo_shells, target_item_func_max, "misc/itempickup.wav", "");
1035 target_item_change(0, ammo_nails, target_item_func_max, "misc/itempickup.wav", "");
1036 target_item_change(0, ammo_rockets, target_item_func_max, "misc/itempickup.wav", "");
1037 target_item_change(0, ammo_cells, target_item_func_max, "misc/itempickup.wav", "");
1038 target_item_change(0, health, target_item_func_max, "misc/megahealth.wav", "");
1039 target_item_change(0, armorvalue, target_item_func_max, "misc/armor25.wav", "");
1040 target_item_change(1, items, target_item_func_or, "misc/powerup.wav", "");
1041 target_item_change(1, weapons, target_item_func_or, "weapons/weaponpickup.wav", "");
1043 if((self.items & activator.items) & IT_STRENGTH)
1044 activator.strength_finished = max(activator.strength_finished, time + self.strength_finished);
1045 if((self.items & activator.items) & IT_INVINCIBLE)
1046 activator.invincible_finished = max(activator.invincible_finished, time + self.invincible_finished);
1048 else if(self.spawnflags == 4) // ANDNOT/MIN
1050 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1051 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1052 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1053 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1054 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1055 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1056 target_item_change(1, items, target_item_func_andnot, "misc/powerup.wav", "");
1057 target_item_change(1, weapons, target_item_func_andnot, "weapons/weaponpickup.wav", "");
1059 if((self.items & activator.items) & IT_STRENGTH)
1060 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1061 if((self.items & activator.items) & IT_INVINCIBLE)
1062 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1065 if not(activator.items & IT_STRENGTH)
1066 activator.strength_finished = 0;
1067 if not(activator.items & IT_INVINCIBLE)
1068 activator.invincible_finished = 0;
1070 if(activator.health > h0)
1071 activator.pauserothealth_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1072 else if(activator.health < h0)
1073 activator.pauseregen_finished = max(activator.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
1075 if(activator.armorvalue > a0)
1076 activator.pauserotarmor_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1078 if not(activator.weapons & W_WeaponBit(activator.switchweapon))
1079 _switchweapon = TRUE;
1081 W_SwitchWeapon_Force(activator, w_getbestweapon(activator));
1083 if(target_item_changed)
1084 centerprint(activator, self.message);
1087 void spawnfunc_target_items (void)
1091 self.use = target_items_use;
1092 if(!self.strength_finished)
1093 self.strength_finished = cvar("g_balance_powerup_strength_time");
1094 if(!self.invincible_finished)
1095 self.invincible_finished = cvar("g_balance_powerup_invincible_time");
1097 precache_sound("misc/itempickup.wav");
1098 precache_sound("misc/itempickup.wav");
1099 precache_sound("misc/itempickup.wav");
1100 precache_sound("misc/itempickup.wav");
1101 precache_sound("misc/megahealth.wav");
1102 precache_sound("misc/armor25.wav");
1103 precache_sound("misc/powerup.wav");
1104 precache_sound("weapons/weaponpickup.wav");
1106 n = tokenize(self.netname);
1107 for(i = 0; i < n; ++i)
1109 if(argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1110 if(argv(i) == "strength") self.items |= IT_STRENGTH;
1111 if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1112 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1114 e = get_weaponinfo(j);
1115 if(argv(i) == e.netname)
1117 self.weapons |= e.weapons;
1118 if(self.spawnflags == 0 || self.spawnflags == 2)
1119 weapon_action(e.weapon, WR_PRECACHE);