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";
27 // add more things here (health, armor)
28 default: error("requested item has no counter field name");
32 void Item_SpawnByWeaponCode(float it)
34 weapon_action(it, WR_SPAWNFUNC);
37 .float max_armorvalue;
39 void Item_Respawn (void)
41 self.model = self.mdl; // restore original model
42 self.solid = SOLID_TRIGGER; // allow it to be touched again
43 sound (self, CHAN_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
44 setorigin (self, self.origin);
46 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
47 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
50 void Item_Touch (void)
59 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
60 if (((trace_dpstartcontents | trace_dphitcontents) & DPCONTENTS_NODROP) || (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOIMPACT))
65 if (other.classname != "player")
69 if (self.solid != SOLID_TRIGGER)
71 if (self.owner == other)
74 // if nothing happens to other, just return without taking the item
76 _switchweapon = FALSE;
84 // play some cool sounds ;)
85 centerprint(other, "\n");
87 announce(other, "announcer/robotic/lastsecond.ogg");
88 else if(other.health < 50)
89 announce(other, "announcer/robotic/narrowly.ogg");
90 // sound not available
91 // else if(self.items == IT_CELLS)
92 // play2(other, "announce/robotic/ammo.ogg");
94 if (self.weapons & WEPBIT_NEX)
95 W_GiveWeapon (other, WEP_NEX, "Nex");
97 other.ammo_cells = min (other.ammo_cells + cvar("g_minstagib_ammo_drop"), 999);
105 // sound not available
106 // play2(other, "announce/robotic/extra.ogg\nplay2 announce/robotic/_lives.ogg");
107 other.armorvalue = other.armorvalue + cvar("g_minstagib_extralives");
108 sprint(other, "^3You picked up some extra lives\n");
112 if (self.strength_finished)
115 // sound not available
116 // play2(other, "announce/robotic/invisible.ogg");
117 other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
121 if (self.invincible_finished)
124 // sound not available
125 // play2(other, "announce/robotic/speed.ogg");
126 other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_strength_time");
131 if (cvar("deathmatch") == 2 || cvar("g_weapon_stay"))
133 if (self.flags & FL_WEAPON && other.weapons & self.weapons && self.classname != "droppedweapon")
135 if (other.weapons & self.weapons && self.flags & FL_TOSSED) // don't let players stack ammo by tossing weapons
139 // in case the player has autoswitch enabled do the following:
140 // if the player is using their best weapon before items are given, they
141 // probably want to switch to an even better weapon after items are given
142 if (other.autoswitch)
143 if (other.switchweapon == w_getbestweapon(other))
144 _switchweapon = TRUE;
146 if (self.ammo_shells)
147 if (other.ammo_shells < g_pickup_shells_max)
150 other.ammo_shells = min (other.ammo_shells + self.ammo_shells, g_pickup_shells_max);
153 if (other.ammo_nails < g_pickup_nails_max)
156 other.ammo_nails = min (other.ammo_nails + self.ammo_nails, g_pickup_nails_max);
158 if (self.ammo_rockets)
159 if (other.ammo_rockets < g_pickup_rockets_max)
162 other.ammo_rockets = min (other.ammo_rockets + self.ammo_rockets, g_pickup_rockets_max);
165 if (other.ammo_cells < g_pickup_cells_max)
168 other.ammo_cells = min (other.ammo_cells + self.ammo_cells, g_pickup_cells_max);
171 if (self.flags & FL_WEAPON)
172 if ((it = self.weapons - (self.weapons & other.weapons)))
175 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
177 e = get_weaponinfo(i);
179 W_GiveWeapon (other, e.weapon, self.netname);
183 if (self.strength_finished)
186 other.strength_finished = max(other.strength_finished, time) + cvar("g_balance_powerup_strength_time");
188 if (self.invincible_finished)
191 other.invincible_finished = max(other.invincible_finished, time) + cvar("g_balance_powerup_invincible_time");
193 //if (self.speed_finished)
196 // other.speed_finished = max(other.speed_finished, time) + cvar("g_balance_powerup_speed_time");
198 //if (self.slowmo_finished)
201 // other.slowmo_finished = max(other.slowmo_finished, time) + (cvar("g_balance_powerup_slowmo_time") * cvar("g_balance_powerup_slowmo_speed"));
205 if (other.health < self.max_health)
208 other.health = min(other.health + self.health, self.max_health);
209 other.pauserothealth_finished = max(other.pauserothealth_finished, time + cvar("g_balance_pause_health_rot"));
212 if (other.armorvalue < self.max_armorvalue)
215 other.armorvalue = min(other.armorvalue + self.armorvalue, self.max_armorvalue);
216 other.pauserotarmor_finished = max(other.pauserotarmor_finished, time + cvar("g_balance_pause_armor_rot"));
223 sound (other, CHAN_AUTO, self.item_pickupsound, VOL_BASE, ATTN_NORM);
229 W_SwitchWeapon_Force(self, w_getbestweapon(self));
233 if (self.classname == "droppedweapon")
235 else if(self.flags & FL_WEAPON && (cvar("deathmatch") == 2 || cvar("g_weapon_stay")))
239 self.solid = SOLID_NOT;
240 self.model = string_null;
241 self.nextthink = time + self.respawntime;
242 self.think = Item_Respawn;
243 setorigin (self, self.origin);
247 // Savage: used for item garbage-collection
248 // TODO: perhaps nice special effect?
249 void RemoveItem(void) /*FIXDECL*/
254 // pickup evaluation functions
255 // these functions decide how desirable an item is to the bots
257 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;};
259 float weapon_pickupevalfunc(entity player, entity item)
261 // if we already have the weapon, rate it 1/5th normal value
262 if ((player.weapons & item.weapons) == item.weapons)
263 return item.bot_pickupbasevalue * 0.2;
264 return item.bot_pickupbasevalue;
267 float commodity_pickupevalfunc(entity player, entity item)
271 // TODO: figure out if the player even has the weapon this ammo is for?
272 // may not affect strategy much though...
273 // find out how much more ammo/armor/health the player can hold
274 if (item.ammo_shells)
275 if (player.ammo_shells < g_pickup_shells_max)
276 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
278 if (player.ammo_nails < g_pickup_nails_max)
279 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
280 if (item.ammo_rockets)
281 if (player.ammo_rockets < g_pickup_rockets_max)
282 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
284 if (player.ammo_cells < g_pickup_cells_max)
285 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
287 if (player.armorvalue < item.max_armorvalue)
288 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
290 if (player.health < item.max_health)
291 c = c + max(0, 1 - player.health / item.max_health);
293 return item.bot_pickupbasevalue * c;
298 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
300 startitem_failed = FALSE;
302 // is it a dropped weapon?
303 if (self.classname == "droppedweapon")
305 // it's a dropped weapon
306 self.movetype = MOVETYPE_TOSS;
307 self.solid = SOLID_TRIGGER;
308 // Savage: remove thrown items after a certain period of time ("garbage collection")
309 self.think = RemoveItem;
310 self.nextthink = time + 60;
311 // don't drop if in a NODROP zone (such as lava)
312 traceline(self.origin, self.origin, MOVE_NORMAL, self);
313 if (trace_dpstartcontents & DPCONTENTS_NODROP)
315 startitem_failed = TRUE;
323 if(self.spawnflags & 1)
326 self.movetype = MOVETYPE_NONE;
328 self.movetype = MOVETYPE_TOSS;
329 self.solid = SOLID_TRIGGER;
330 // do item filtering according to game mode and other things
333 // first nudge it off the floor a little bit to avoid math errors
334 setorigin(self, self.origin + '0 0 1');
335 // set item size before we spawn a spawnfunc_waypoint
336 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
337 setsize (self, '-16 -16 0', '16 16 48');
339 setsize (self, '-16 -16 0', '16 16 32');
340 // note droptofloor returns FALSE if stuck/or would fall too far
342 waypoint_spawnforitem(self);
349 print("removed non-teamplay ", self.classname, "\n");
350 startitem_failed = TRUE;
359 print("removed non-FFA ", self.classname, "\n");
360 startitem_failed = TRUE;
368 // We aren't TA or something like that, so we keep the Q3A entities
369 print("removed non-Q3A ", self.classname, "\n");
370 startitem_failed = TRUE;
376 * can't do it that way, as it would break maps
377 * TODO make a target_give like entity another way, that perhaps has
378 * the weapon name in a key
381 // target_give not yet supported; maybe later
382 print("removed targeted ", self.classname, "\n");
383 startitem_failed = TRUE;
389 if(cvar("spawn_debug") >= 2)
392 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
394 if(otheritem.is_item)
396 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
397 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
398 error("Mapper sucks.");
404 weaponsInMap |= weaponid;
406 if(g_lms || g_instagib || g_rocketarena)
408 startitem_failed = TRUE;
412 else if (g_minstagib)
414 // don't remove dropped items and powerups
415 if (self.classname != "minstagib")
417 startitem_failed = TRUE;
422 else if ((!cvar("g_pickup_items") || g_nixnex) && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
424 startitem_failed = TRUE;
429 precache_model (itemmodel);
430 precache_sound (pickupsound);
431 precache_sound ("misc/itemrespawn.wav");
433 if((itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)) || (weaponid & WEPBIT_ALL))
434 self.target = "###item###"; // for finding the nearest item using find()
437 self.bot_pickup = TRUE;
438 self.bot_pickupevalfunc = pickupevalfunc;
439 self.bot_pickupbasevalue = pickupbasevalue;
440 self.mdl = itemmodel;
441 self.item_pickupsound = pickupsound;
442 // let mappers override respawntime
443 if (!self.respawntime)
444 self.respawntime = defaultrespawntime;
445 self.netname = itemname;
447 self.weapons = weaponid;
448 self.flags = FL_ITEM | itemflags;
449 self.touch = Item_Touch;
450 setmodel (self, self.mdl); // precision set below
451 self.effects |= EF_LOWPRECISION;
452 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
453 setsize (self, '-16 -16 0', '16 16 48');
455 setsize (self, '-16 -16 0', '16 16 32');
456 if (itemflags & FL_WEAPON)
458 // neutral team color for pickup weapons
459 self.colormap = 160 * 1024 + 160;
462 if (cvar("g_fullbrightitems"))
463 self.effects = self.effects | EF_FULLBRIGHT;
466 /* replace items in minstagib
467 * IT_STRENGTH = invisibility
468 * IT_NAILS = extra lives
469 * IT_INVINCIBLE = speed
471 void minstagib_items (float itemid)
473 // we don't want to replace dropped weapons ;)
474 if (self.classname == "droppedweapon")
476 self.ammo_cells = 25;
477 StartItem ("models/weapons/g_nex.md3",
478 "weapons/weaponpickup.wav", 15,
479 "Nex Gun", 0, WEPBIT_NEX, FL_WEAPON, generic_pickupevalfunc, 1000);
484 self.classname = "minstagib";
486 // replace rocket launchers and nex guns with ammo cells
487 if (itemid == IT_CELLS)
490 StartItem ("models/items/a_cells.md3",
491 "misc/itempickup.wav", 45,
492 "Nex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
499 itemid = IT_STRENGTH;
503 itemid = IT_INVINCIBLE;
505 // replace with invis
506 if (itemid == IT_STRENGTH)
508 self.effects = EF_ADDITIVE;
509 self.strength_finished = 30;
510 StartItem ("models/items/g_strength.md3",
511 "misc/powerup.wav", 120,
512 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
514 // replace with extra lives
515 if (itemid == IT_NAILS)
518 StartItem ("models/items/g_h100.md3",
519 "misc/megahealth.wav", 120,
520 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
523 // replace with speed
524 if (itemid == IT_INVINCIBLE)
526 self.effects = EF_ADDITIVE;
527 self.invincible_finished = 30;
528 StartItem ("models/items/g_invincible.md3",
529 "misc/powerup_shield.wav", 120,
530 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
535 float minst_no_auto_cells;
536 void minst_remove_item (void) {
537 if(minst_no_auto_cells)
541 float weaponswapping;
543 void weapon_defaultspawnfunc(float wpn, float weight)
546 var .float ammofield;
547 e = get_weaponinfo(wpn);
549 if(e.items && e.items != IT_SUPERWEAPON)
551 ammofield = Item_CounterField(e.items);
553 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(e.items)));
556 StartItem (e.model, "weapons/weaponpickup.wav", 15, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, weight);
557 if (self.modelindex) // don't precache if self was removed
558 weapon_action(e.weapon, WR_PRECACHE);
561 void spawnfunc_weapon_shotgun (void);
562 void spawnfunc_weapon_uzi (void) {
564 if(q3acompat_machineshotgunswap)
565 if(self.classname != "droppedweapon")
567 weapon_defaultspawnfunc(WEP_SHOTGUN, 2500);
570 weapon_defaultspawnfunc(WEP_UZI, 5000);
573 void spawnfunc_weapon_shotgun (void) {
575 if(q3acompat_machineshotgunswap)
576 if(self.classname != "droppedweapon")
578 weapon_defaultspawnfunc(WEP_UZI, 5000);
581 weapon_defaultspawnfunc(WEP_SHOTGUN, 2500);
584 void spawnfunc_weapon_nex (void)
588 minstagib_items(IT_CELLS);
589 self.think = minst_remove_item;
590 self.nextthink = time + cvar("sys_ticrate");
593 weapon_defaultspawnfunc(WEP_NEX, 10000);
596 void spawnfunc_weapon_rocketlauncher (void)
600 minstagib_items(IT_CELLS);
601 self.think = minst_remove_item;
602 self.nextthink = time + cvar("sys_ticrate");
605 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER, 10000);
608 void spawnfunc_item_rockets (void) {
609 if(!self.ammo_rockets)
610 self.ammo_rockets = g_pickup_rockets;
611 StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", 15, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
614 void spawnfunc_item_shells (void);
615 void spawnfunc_item_bullets (void) {
617 if(q3acompat_machineshotgunswap)
618 if(self.classname != "droppedweapon")
620 weaponswapping = TRUE;
621 spawnfunc_item_shells();
622 weaponswapping = FALSE;
627 self.ammo_nails = g_pickup_nails;
628 StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", 15, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
631 void spawnfunc_item_cells (void) {
633 self.ammo_cells = g_pickup_cells;
634 StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", 15, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
637 void spawnfunc_item_shells (void) {
639 if(q3acompat_machineshotgunswap)
640 if(self.classname != "droppedweapon")
642 weaponswapping = TRUE;
643 spawnfunc_item_bullets();
644 weaponswapping = FALSE;
648 if(!self.ammo_shells)
649 self.ammo_shells = g_pickup_shells;
650 StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", 15, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
653 void spawnfunc_item_armor_small (void) {
655 self.armorvalue = g_pickup_armorsmall;
656 if(!self.max_armorvalue)
657 self.max_armorvalue = g_pickup_armorsmall_max;
658 StartItem ("models/items/g_a1.md3", "misc/armor1.wav", 15, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, 1000);
661 void spawnfunc_item_armor_medium (void) {
663 self.armorvalue = g_pickup_armormedium;
664 if(!self.max_armorvalue)
665 self.max_armorvalue = g_pickup_armormedium_max;
666 StartItem ("models/items/g_armormedium.md3", "misc/armor1.wav", 20, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
669 void spawnfunc_item_armor_large (void) {
671 self.armorvalue = g_pickup_armorlarge;
672 if(!self.max_armorvalue)
673 self.max_armorvalue = g_pickup_armorlarge_max;
674 StartItem ("models/items/g_a25.md3", "misc/armor25.wav", 30, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
677 void spawnfunc_item_health_small (void) {
679 self.max_health = g_pickup_healthsmall_max;
681 self.health = g_pickup_healthsmall;
682 StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", 15, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, 20000);
685 void spawnfunc_item_health_medium (void) {
687 self.max_health = g_pickup_healthmedium_max;
689 self.health = g_pickup_healthmedium;
690 StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", 15, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, 20000);
693 void spawnfunc_item_health_large (void) {
695 self.max_health = g_pickup_healthlarge_max;
697 self.health = g_pickup_healthlarge;
698 StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", 20, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, 20000);
701 void spawnfunc_item_health_mega (void) {
702 if(!cvar("g_powerup_superhealth"))
705 if(g_arena && !cvar("g_arena_powerups"))
709 minstagib_items(IT_NAILS);
712 self.max_health = g_pickup_healthmega_max;
714 self.health = g_pickup_healthmega;
715 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", 30, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, 20000);
719 // support old misnamed entities
720 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Nexuiz maps it is an armor shard
721 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
722 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
723 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
724 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
726 void spawnfunc_item_strength (void) {
727 if(!cvar("g_powerup_strength"))
730 if(g_arena && !cvar("g_arena_powerups"))
734 minstagib_items(IT_STRENGTH);
736 precache_sound("weapons/strength_fire.wav");
737 self.strength_finished = 30;
738 self.effects = EF_ADDITIVE;
739 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", 120, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
743 void spawnfunc_item_invincible (void) {
744 if(!cvar("g_powerup_shield"))
747 if(g_arena && !cvar("g_arena_powerups"))
751 minstagib_items(IT_INVINCIBLE);
753 self.invincible_finished = 30;
754 self.effects = EF_ADDITIVE;
755 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", 120, "Invulnerability", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
758 //void item_speed (void) {self.speed_finished = 30;StartItem ("models/items/g_speed.md3", "misc/powerup.wav", 120, "Speed Powerup", IT_SPEED, FL_POWERUP, generic_pickupevalfunc, 10000);}
759 //void item_slowmo (void) {self.slowmo_finished = 30;StartItem ("models/items/g_slowmo.md3", "misc/powerup.wav", 120, "Slow Motion", IT_SLOWMO, FL_POWERUP, generic_pickupevalfunc, 10000);}
761 void spawnfunc_item_minst_cells (void) {
764 minst_no_auto_cells = 1;
765 minstagib_items(IT_CELLS);
772 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
774 void spawnfunc_misc_models (void)
776 SetBrushEntityModel();
779 void func_wall_use (void)
784 self.colormap = (activator.team - 1) * 0x11;
786 self.colormap = 0x00;
789 self.colormap = ceil(random() * 256) - 1;
790 self.colormap |= 1024; // RENDER_COLORMAPPED
793 void spawnfunc_func_wall (void)
795 SetBrushEntityModel();
796 self.solid = SOLID_BSP;
797 self.use = func_wall_use;