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 (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, head.cnt, 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, head.cnt, 0);
272 e = RandomSelection_chosen_ent;
275 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
279 // make it a non-spawned item
280 head.solid = SOLID_NOT;
281 head.model = string_null;
282 head.state = 1; // state 1 = initially hidden item
284 head.effects = head.effects - (head.effects & EF_NODRAW);
289 // Savage: used for item garbage-collection
290 // TODO: perhaps nice special effect?
291 void RemoveItem(void)
296 // pickup evaluation functions
297 // these functions decide how desirable an item is to the bots
299 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;};
301 float weapon_pickupevalfunc(entity player, entity item)
303 // if we already have the weapon, rate it 1/5th normal value
304 if ((player.weapons & item.weapons) == item.weapons)
305 return item.bot_pickupbasevalue * 0.2;
306 return item.bot_pickupbasevalue;
309 float commodity_pickupevalfunc(entity player, entity item)
313 // TODO: figure out if the player even has the weapon this ammo is for?
314 // may not affect strategy much though...
315 // find out how much more ammo/armor/health the player can hold
316 if (item.ammo_shells)
317 if (player.ammo_shells < g_pickup_shells_max)
318 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
320 if (player.ammo_nails < g_pickup_nails_max)
321 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
322 if (item.ammo_rockets)
323 if (player.ammo_rockets < g_pickup_rockets_max)
324 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
326 if (player.ammo_cells < g_pickup_cells_max)
327 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
329 if (player.armorvalue < item.max_armorvalue)
330 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
332 if (player.health < item.max_health)
333 c = c + max(0, 1 - player.health / item.max_health);
335 return item.bot_pickupbasevalue * c;
340 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
342 startitem_failed = FALSE;
344 // is it a dropped weapon?
345 if (self.classname == "droppedweapon")
347 // it's a dropped weapon
348 self.movetype = MOVETYPE_TOSS;
349 self.solid = SOLID_TRIGGER;
350 // Savage: remove thrown items after a certain period of time ("garbage collection")
351 self.think = RemoveItem;
352 self.nextthink = time + 60;
353 // don't drop if in a NODROP zone (such as lava)
354 traceline(self.origin, self.origin, MOVE_NORMAL, self);
355 if (trace_dpstartcontents & DPCONTENTS_NODROP)
357 startitem_failed = TRUE;
365 if(self.spawnflags & 1)
368 self.movetype = MOVETYPE_NONE;
370 self.movetype = MOVETYPE_TOSS;
371 self.solid = SOLID_TRIGGER;
372 // do item filtering according to game mode and other things
375 // first nudge it off the floor a little bit to avoid math errors
376 setorigin(self, self.origin + '0 0 1');
377 // set item size before we spawn a spawnfunc_waypoint
378 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
379 setsize (self, '-16 -16 0', '16 16 48');
381 setsize (self, '-16 -16 0', '16 16 32');
382 // note droptofloor returns FALSE if stuck/or would fall too far
384 waypoint_spawnforitem(self);
391 print("removed non-teamplay ", self.classname, "\n");
392 startitem_failed = TRUE;
401 print("removed non-FFA ", self.classname, "\n");
402 startitem_failed = TRUE;
410 // We aren't TA or something like that, so we keep the Q3A entities
411 print("removed non-Q3A ", self.classname, "\n");
412 startitem_failed = TRUE;
418 * can't do it that way, as it would break maps
419 * TODO make a target_give like entity another way, that perhaps has
420 * the weapon name in a key
423 // target_give not yet supported; maybe later
424 print("removed targeted ", self.classname, "\n");
425 startitem_failed = TRUE;
431 if(cvar("spawn_debug") >= 2)
434 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
436 if(otheritem.is_item)
438 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
439 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
440 error("Mapper sucks.");
446 weaponsInMap |= weaponid;
448 if(g_lms || g_weaponarena)
450 startitem_failed = TRUE;
454 else if (g_minstagib)
456 // don't remove dropped items and powerups
457 if (self.classname != "minstagib")
459 startitem_failed = TRUE;
464 else if ((!cvar("g_pickup_items") || g_nixnex) && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
466 startitem_failed = TRUE;
471 precache_model (itemmodel);
472 precache_sound (pickupsound);
473 precache_sound ("misc/itemrespawn.wav");
475 if((itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)) || (weaponid & WEPBIT_ALL))
476 self.target = "###item###"; // for finding the nearest item using find()
479 self.bot_pickup = TRUE;
480 self.bot_pickupevalfunc = pickupevalfunc;
481 self.bot_pickupbasevalue = pickupbasevalue;
482 self.mdl = itemmodel;
483 self.item_pickupsound = pickupsound;
484 // let mappers override respawntime
485 if (!self.respawntime)
486 self.respawntime = defaultrespawntime;
487 self.netname = itemname;
489 self.weapons = weaponid;
490 self.flags = FL_ITEM | itemflags;
491 self.touch = Item_Touch;
492 setmodel (self, self.mdl); // precision set below
493 self.effects |= EF_LOWPRECISION;
494 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
495 setsize (self, '-16 -16 0', '16 16 48');
497 setsize (self, '-16 -16 0', '16 16 32');
499 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
500 if (itemflags & FL_WEAPON)
502 // neutral team color for pickup weapons
503 self.colormap = 1024; // color shirt=0 pants=0 grey
506 if (cvar("g_fullbrightitems"))
507 self.effects = self.effects | EF_FULLBRIGHT;
513 self.cnt = 1; // item probability weight
514 self.effects = self.effects | EF_NODRAW; // marker for item team search
515 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
519 /* replace items in minstagib
520 * IT_STRENGTH = invisibility
521 * IT_NAILS = extra lives
522 * IT_INVINCIBLE = speed
524 void minstagib_items (float itemid)
526 // we don't want to replace dropped weapons ;)
527 if (self.classname == "droppedweapon")
529 self.ammo_cells = 25;
530 StartItem ("models/weapons/g_nex.md3",
531 "weapons/weaponpickup.wav", 15,
532 "MinstaNex", 0, WEPBIT_MINSTANEX, FL_WEAPON, generic_pickupevalfunc, 1000);
537 self.classname = "minstagib";
539 // replace rocket launchers and nex guns with ammo cells
540 if (itemid == IT_CELLS)
543 StartItem ("models/items/a_cells.md3",
544 "misc/itempickup.wav", 45,
545 "Nex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
552 itemid = IT_STRENGTH;
556 itemid = IT_INVINCIBLE;
558 // replace with invis
559 if (itemid == IT_STRENGTH)
561 self.effects = EF_ADDITIVE;
562 self.strength_finished = 30;
563 StartItem ("models/items/g_strength.md3",
564 "misc/powerup.wav", g_pickup_respawntime_powerup,
565 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
567 // replace with extra lives
568 if (itemid == IT_NAILS)
571 StartItem ("models/items/g_h100.md3",
572 "misc/megahealth.wav", g_pickup_respawntime_powerup,
573 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
576 // replace with speed
577 if (itemid == IT_INVINCIBLE)
579 self.effects = EF_ADDITIVE;
580 self.invincible_finished = 30;
581 StartItem ("models/items/g_invincible.md3",
582 "misc/powerup_shield.wav", g_pickup_respawntime_powerup,
583 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
588 float minst_no_auto_cells;
589 void minst_remove_item (void) {
590 if(minst_no_auto_cells)
594 float weaponswapping;
597 void weapon_defaultspawnfunc(float wpn)
601 var .float ammofield;
606 // set the respawntime in advance (so replaced weapons can copy it)
607 if(!self.respawntime)
609 e = get_weaponinfo(wpn);
610 if(e.items == IT_SUPERWEAPON)
611 self.respawntime = g_pickup_respawntime_powerup;
613 self.respawntime = g_pickup_respawntime_weapon;
616 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
618 e = get_weaponinfo(wpn);
619 s = cvar_string(strcat("g_weaponreplace_", e.netname));
623 startitem_failed = TRUE;
626 t = tokenize_sane(s);
629 self.team = --internalteam;
631 for(i = 1; i < t; ++i)
634 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
636 e = get_weaponinfo(j);
640 copyentity(oldself, self);
641 self.classname = "replacedweapon";
642 weapon_defaultspawnfunc(j);
648 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
657 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
659 e = get_weaponinfo(j);
668 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
674 startitem_failed = TRUE;
679 e = get_weaponinfo(wpn);
681 if(e.items && e.items != IT_SUPERWEAPON)
683 ammofield = Item_CounterField(e.items);
685 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(e.items)));
688 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, e.bot_pickupbasevalue);
689 if (self.modelindex) // don't precache if self was removed
690 weapon_action(e.weapon, WR_PRECACHE);
693 void spawnfunc_weapon_shotgun (void);
694 void spawnfunc_weapon_uzi (void) {
695 if(q3acompat_machineshotgunswap)
696 if(self.classname != "droppedweapon")
698 weapon_defaultspawnfunc(WEP_SHOTGUN);
701 weapon_defaultspawnfunc(WEP_UZI);
704 void spawnfunc_weapon_shotgun (void) {
705 if(q3acompat_machineshotgunswap)
706 if(self.classname != "droppedweapon")
708 weapon_defaultspawnfunc(WEP_UZI);
711 weapon_defaultspawnfunc(WEP_SHOTGUN);
714 void spawnfunc_weapon_nex (void)
718 minstagib_items(IT_CELLS);
719 self.think = minst_remove_item;
720 self.nextthink = time + cvar("sys_ticrate");
723 weapon_defaultspawnfunc(WEP_NEX);
726 void spawnfunc_weapon_minstanex (void)
730 minstagib_items(IT_CELLS);
731 self.think = minst_remove_item;
732 self.nextthink = time + cvar("sys_ticrate");
735 weapon_defaultspawnfunc(WEP_MINSTANEX);
738 void spawnfunc_weapon_rocketlauncher (void)
742 minstagib_items(IT_CELLS);
743 self.think = minst_remove_item;
744 self.nextthink = time + cvar("sys_ticrate");
747 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
750 void spawnfunc_item_rockets (void) {
751 if(!self.ammo_rockets)
752 self.ammo_rockets = g_pickup_rockets;
753 StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
756 void spawnfunc_item_shells (void);
757 void spawnfunc_item_bullets (void) {
759 if(q3acompat_machineshotgunswap)
760 if(self.classname != "droppedweapon")
762 weaponswapping = TRUE;
763 spawnfunc_item_shells();
764 weaponswapping = FALSE;
769 self.ammo_nails = g_pickup_nails;
770 StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", g_pickup_respawntime_ammo, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
773 void spawnfunc_item_cells (void) {
775 self.ammo_cells = g_pickup_cells;
776 StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
779 void spawnfunc_item_shells (void) {
781 if(q3acompat_machineshotgunswap)
782 if(self.classname != "droppedweapon")
784 weaponswapping = TRUE;
785 spawnfunc_item_bullets();
786 weaponswapping = FALSE;
790 if(!self.ammo_shells)
791 self.ammo_shells = g_pickup_shells;
792 StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
795 void spawnfunc_item_armor_small (void) {
797 self.armorvalue = g_pickup_armorsmall;
798 if(!self.max_armorvalue)
799 self.max_armorvalue = g_pickup_armorsmall_max;
800 StartItem ("models/items/g_a1.md3", "misc/armor1.wav", g_pickup_respawntime_short, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, 1000);
803 void spawnfunc_item_armor_medium (void) {
805 self.armorvalue = g_pickup_armormedium;
806 if(!self.max_armorvalue)
807 self.max_armorvalue = g_pickup_armormedium_max;
808 StartItem ("models/items/g_armormedium.md3", "misc/armor10.wav", g_pickup_respawntime_medium, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
811 void spawnfunc_item_armor_large (void) {
813 self.armorvalue = g_pickup_armorlarge;
814 if(!self.max_armorvalue)
815 self.max_armorvalue = g_pickup_armorlarge_max;
816 StartItem ("models/items/g_a25.md3", "misc/armor25.wav", g_pickup_respawntime_long, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
819 void spawnfunc_item_health_small (void) {
821 self.max_health = g_pickup_healthsmall_max;
823 self.health = g_pickup_healthsmall;
824 StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", g_pickup_respawntime_short, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, 20000);
827 void spawnfunc_item_health_medium (void) {
829 self.max_health = g_pickup_healthmedium_max;
831 self.health = g_pickup_healthmedium;
832 StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", g_pickup_respawntime_short, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, 20000);
835 void spawnfunc_item_health_large (void) {
837 self.max_health = g_pickup_healthlarge_max;
839 self.health = g_pickup_healthlarge;
840 StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", g_pickup_respawntime_medium, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, 20000);
843 void spawnfunc_item_health_mega (void) {
844 if(!cvar("g_powerup_superhealth"))
847 if(g_arena && !cvar("g_arena_powerups"))
851 minstagib_items(IT_NAILS);
854 self.max_health = g_pickup_healthmega_max;
856 self.health = g_pickup_healthmega;
857 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", g_pickup_respawntime_long, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, 20000);
861 // support old misnamed entities
862 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Nexuiz maps it is an armor shard
863 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
864 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
865 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
866 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
868 void spawnfunc_item_strength (void) {
869 if(!cvar("g_powerup_strength"))
872 if(g_arena && !cvar("g_arena_powerups"))
876 minstagib_items(IT_STRENGTH);
878 precache_sound("weapons/strength_fire.wav");
879 self.strength_finished = 30;
880 self.effects = EF_ADDITIVE;
881 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", g_pickup_respawntime_powerup, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
885 void spawnfunc_item_invincible (void) {
886 if(!cvar("g_powerup_shield"))
889 if(g_arena && !cvar("g_arena_powerups"))
893 minstagib_items(IT_INVINCIBLE);
895 self.invincible_finished = 30;
896 self.effects = EF_ADDITIVE;
897 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", g_pickup_respawntime_powerup, "Invulnerability", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
901 void spawnfunc_item_minst_cells (void) {
904 minst_no_auto_cells = 1;
905 minstagib_items(IT_CELLS);
912 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
914 void spawnfunc_misc_models (void)
916 // exists as alias name for 2.4.2 compat
917 SetBrushEntityModel();
920 void spawnfunc_func_static (void)
922 // exists as alias name for having it with brushes
923 SetBrushEntityModel();
926 void func_wall_use (void)
931 self.colormap = (activator.team - 1) * 0x11;
933 self.colormap = 0x00;
936 self.colormap = floor(random() * 256);
937 self.colormap |= 1024; // RENDER_COLORMAPPED
940 void spawnfunc_func_wall (void)
942 SetBrushEntityModel();
944 self.solid = SOLID_BSP;
945 self.use = func_wall_use;
948 void spawnfunc_func_illusionary (void)
950 SetBrushEntityModel();
951 self.use = func_wall_use;
954 void gamemodel_drop()
956 if(self.spawnflags & 3 == 1) // ALIGN_ORIGIN
958 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
959 setorigin(self, trace_endpos);
961 else if(self.spawnflags & 3 == 2) // ALIGN_BOTTOM
963 tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
964 setorigin(self, trace_endpos);
966 else if(self.spawnflags & 3 == 3) // ALIGN_ORIGIN | ALIGN_BOTTOM
968 traceline(self.origin, self.origin - '0 0 4096', MOVE_NOMONSTERS, self);
969 setorigin(self, trace_endpos - '0 0 1' * self.mins_z);
974 void spawnfunc_misc_gamemodel (void)
977 self.scale = self.modelscale;
978 SetBrushEntityModel();
979 self.use = func_wall_use;
981 InitializeEntity(self, gamemodel_drop, INITPRIO_DROPTOFLOOR);
984 float target_item_func_set(float a, float b)
994 float target_item_func_min(float a, float b)
1004 float target_item_func_max(float a, float b)
1009 float target_item_func_bitset(float a, float b)
1014 float target_item_func_and(float a, float b)
1019 float target_item_func_itembitset(float a, float b)
1021 return (a - (a & (IT_UNLIMITED_WEAPON_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | b;
1024 float target_item_func_itemand(float a, float b)
1026 return (a - (a & (IT_UNLIMITED_WEAPON_AMMO | IT_STRENGTH | IT_INVINCIBLE))) | (a & b);
1029 float target_item_func_or(float a, float b)
1034 float target_item_func_andnot(float a, float b)
1039 float target_item_changed;
1040 void target_item_change(float binary, .float field, float(float a, float b) func, string sound_increase, string sound_decrease)
1043 n = func(activator.field, self.field);
1047 d = n & activator.field;
1048 if(d != n) // bits added?
1050 else if(d != activator.field) // bits removed?
1056 d = n - activator.field;
1060 if(sound_decrease != "")
1061 sound (activator, CHAN_AUTO, sound_decrease, VOL_BASE, ATTN_NORM);
1062 target_item_changed = 1;
1066 if(sound_increase != "")
1067 sound (activator, CHAN_AUTO, sound_increase, VOL_BASE, ATTN_NORM);
1068 target_item_changed = 1;
1070 activator.field = n;
1073 void target_items_use (void)
1076 if(activator.classname != "player")
1078 if(activator.deadflag != DEAD_NO)
1083 for(e = world; (e = find(e, classname, "droppedweapon")); )
1084 if(e.enemy == activator)
1087 float _switchweapon;
1088 _switchweapon = FALSE;
1089 if (activator.autoswitch)
1090 if (activator.switchweapon == w_getbestweapon(activator))
1091 _switchweapon = TRUE;
1093 a0 = activator.armorvalue;
1094 h0 = activator.health;
1095 target_item_changed = 0;
1097 if(self.spawnflags == 0) // SET
1099 target_item_change(0, ammo_shells, target_item_func_set, "misc/itempickup.wav", "");
1100 target_item_change(0, ammo_nails, target_item_func_set, "misc/itempickup.wav", "");
1101 target_item_change(0, ammo_rockets, target_item_func_set, "misc/itempickup.wav", "");
1102 target_item_change(0, ammo_cells, target_item_func_set, "misc/itempickup.wav", "");
1103 target_item_change(0, health, target_item_func_set, "misc/megahealth.wav", "");
1104 target_item_change(0, armorvalue, target_item_func_set, "misc/armor25.wav", "");
1105 target_item_change(1, items, target_item_func_itembitset, "misc/powerup.wav", "");
1106 target_item_change(1, weapons, target_item_func_bitset, "weapons/weaponpickup.wav", "");
1108 if((self.items & activator.items) & IT_STRENGTH)
1109 activator.strength_finished = time + self.strength_finished;
1110 if((self.items & activator.items) & IT_INVINCIBLE)
1111 activator.invincible_finished = time + self.invincible_finished;
1113 else if(self.spawnflags == 1) // AND/MIN
1115 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1116 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1117 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1118 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1119 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1120 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1121 target_item_change(1, items, target_item_func_itemand, "misc/powerup.wav", "");
1122 target_item_change(1, weapons, target_item_func_and, "weapons/weaponpickup.wav", "");
1124 if((self.items & activator.items) & IT_STRENGTH)
1125 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1126 if((self.items & activator.items) & IT_INVINCIBLE)
1127 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1129 else if(self.spawnflags == 2) // OR/MAX
1131 target_item_change(0, ammo_shells, target_item_func_max, "misc/itempickup.wav", "");
1132 target_item_change(0, ammo_nails, target_item_func_max, "misc/itempickup.wav", "");
1133 target_item_change(0, ammo_rockets, target_item_func_max, "misc/itempickup.wav", "");
1134 target_item_change(0, ammo_cells, target_item_func_max, "misc/itempickup.wav", "");
1135 target_item_change(0, health, target_item_func_max, "misc/megahealth.wav", "");
1136 target_item_change(0, armorvalue, target_item_func_max, "misc/armor25.wav", "");
1137 target_item_change(1, items, target_item_func_or, "misc/powerup.wav", "");
1138 target_item_change(1, weapons, target_item_func_or, "weapons/weaponpickup.wav", "");
1140 if((self.items & activator.items) & IT_STRENGTH)
1141 activator.strength_finished = max(activator.strength_finished, time + self.strength_finished);
1142 if((self.items & activator.items) & IT_INVINCIBLE)
1143 activator.invincible_finished = max(activator.invincible_finished, time + self.invincible_finished);
1145 else if(self.spawnflags == 4) // ANDNOT/MIN
1147 target_item_change(0, ammo_shells, target_item_func_min, "misc/itempickup.wav", "");
1148 target_item_change(0, ammo_nails, target_item_func_min, "misc/itempickup.wav", "");
1149 target_item_change(0, ammo_rockets, target_item_func_min, "misc/itempickup.wav", "");
1150 target_item_change(0, ammo_cells, target_item_func_min, "misc/itempickup.wav", "");
1151 target_item_change(0, health, target_item_func_min, "misc/megahealth.wav", "");
1152 target_item_change(0, armorvalue, target_item_func_min, "misc/armor25.wav", "");
1153 target_item_change(1, items, target_item_func_andnot, "misc/powerup.wav", "");
1154 target_item_change(1, weapons, target_item_func_andnot, "weapons/weaponpickup.wav", "");
1156 if((self.items & activator.items) & IT_STRENGTH)
1157 activator.strength_finished = min(activator.strength_finished, time + self.strength_finished);
1158 if((self.items & activator.items) & IT_INVINCIBLE)
1159 activator.invincible_finished = min(activator.invincible_finished, time + self.invincible_finished);
1162 if not(activator.items & IT_STRENGTH)
1163 activator.strength_finished = 0;
1164 if not(activator.items & IT_INVINCIBLE)
1165 activator.invincible_finished = 0;
1167 if(activator.health > h0)
1168 activator.pauserothealth_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1169 else if(activator.health < h0)
1170 activator.pauseregen_finished = max(activator.pauseregen_finished, time + cvar("g_balance_pause_health_regen"));
1172 if(activator.armorvalue > a0)
1173 activator.pauserotarmor_finished = max(activator.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
1175 if not(activator.weapons & W_WeaponBit(activator.switchweapon))
1176 _switchweapon = TRUE;
1178 W_SwitchWeapon_Force(activator, w_getbestweapon(activator));
1180 if(target_item_changed)
1181 centerprint(activator, self.message);
1184 void spawnfunc_target_items (void)
1188 self.use = target_items_use;
1189 if(!self.strength_finished)
1190 self.strength_finished = cvar("g_balance_powerup_strength_time");
1191 if(!self.invincible_finished)
1192 self.invincible_finished = cvar("g_balance_powerup_invincible_time");
1194 precache_sound("misc/itempickup.wav");
1195 precache_sound("misc/itempickup.wav");
1196 precache_sound("misc/itempickup.wav");
1197 precache_sound("misc/itempickup.wav");
1198 precache_sound("misc/megahealth.wav");
1199 precache_sound("misc/armor25.wav");
1200 precache_sound("misc/powerup.wav");
1201 precache_sound("weapons/weaponpickup.wav");
1203 n = tokenize_sane(self.netname);
1204 for(i = 0; i < n; ++i)
1206 if(argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1207 if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1208 if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1209 if(argv(i) == "strength") self.items |= IT_STRENGTH;
1210 if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1211 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1213 e = get_weaponinfo(j);
1214 if(argv(i) == e.netname)
1216 self.weapons |= e.weapons;
1217 if(self.spawnflags == 0 || self.spawnflags == 2)
1218 weapon_action(e.weapon, WR_PRECACHE);