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 self.switchweapon = w_getbestweapon(self);
230 if (self.switchweapon != self.weapon)
231 self.cnt = self.weapon;
235 if (self.classname == "droppedweapon")
237 else if(self.flags & FL_WEAPON && (cvar("deathmatch") == 2 || cvar("g_weapon_stay")))
241 self.solid = SOLID_NOT;
242 self.model = string_null;
243 self.nextthink = time + self.respawntime;
244 self.think = Item_Respawn;
245 setorigin (self, self.origin);
249 // Savage: used for item garbage-collection
250 // TODO: perhaps nice special effect?
251 void RemoveItem(void) /*FIXDECL*/
256 // pickup evaluation functions
257 // these functions decide how desirable an item is to the bots
259 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;};
261 float weapon_pickupevalfunc(entity player, entity item)
263 // if we already have the weapon, rate it 1/5th normal value
264 if ((player.weapons & item.weapons) == item.weapons)
265 return item.bot_pickupbasevalue * 0.2;
266 return item.bot_pickupbasevalue;
269 float commodity_pickupevalfunc(entity player, entity item)
273 // TODO: figure out if the player even has the weapon this ammo is for?
274 // may not affect strategy much though...
275 // find out how much more ammo/armor/health the player can hold
276 if (item.ammo_shells)
277 if (player.ammo_shells < g_pickup_shells_max)
278 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
280 if (player.ammo_nails < g_pickup_nails_max)
281 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
282 if (item.ammo_rockets)
283 if (player.ammo_rockets < g_pickup_rockets_max)
284 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
286 if (player.ammo_cells < g_pickup_cells_max)
287 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
289 if (player.armorvalue < item.max_armorvalue)
290 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
292 if (player.health < item.max_health)
293 c = c + max(0, 1 - player.health / item.max_health);
295 return item.bot_pickupbasevalue * c;
300 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
302 startitem_failed = FALSE;
304 // is it a dropped weapon?
305 if (self.classname == "droppedweapon")
307 // it's a dropped weapon
308 self.movetype = MOVETYPE_TOSS;
309 self.solid = SOLID_TRIGGER;
310 // Savage: remove thrown items after a certain period of time ("garbage collection")
311 self.think = RemoveItem;
312 self.nextthink = time + 60;
313 // don't drop if in a NODROP zone (such as lava)
314 traceline(self.origin, self.origin, MOVE_NORMAL, self);
315 if (trace_dpstartcontents & DPCONTENTS_NODROP)
317 startitem_failed = TRUE;
325 if(self.spawnflags & 1)
328 self.movetype = MOVETYPE_NONE;
330 self.movetype = MOVETYPE_TOSS;
331 self.solid = SOLID_TRIGGER;
332 // do item filtering according to game mode and other things
335 // first nudge it off the floor a little bit to avoid math errors
336 setorigin(self, self.origin + '0 0 1');
337 // set item size before we spawn a spawnfunc_waypoint
338 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
339 setsize (self, '-16 -16 0', '16 16 48');
341 setsize (self, '-16 -16 0', '16 16 32');
342 // note droptofloor returns FALSE if stuck/or would fall too far
344 waypoint_spawnforitem(self);
351 print("removed non-teamplay ", self.classname, "\n");
352 startitem_failed = TRUE;
361 print("removed non-FFA ", self.classname, "\n");
362 startitem_failed = TRUE;
370 // We aren't TA or something like that, so we keep the Q3A entities
371 print("removed non-Q3A ", self.classname, "\n");
372 startitem_failed = TRUE;
378 * can't do it that way, as it would break maps
379 * TODO make a target_give like entity another way, that perhaps has
380 * the weapon name in a key
383 // target_give not yet supported; maybe later
384 print("removed targeted ", self.classname, "\n");
385 startitem_failed = TRUE;
391 if(cvar("spawn_debug") >= 2)
394 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
396 if(otheritem.is_item)
398 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
399 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
400 error("Mapper sucks.");
406 weaponsInMap |= weaponid;
408 if(g_lms || g_instagib || g_rocketarena)
410 startitem_failed = TRUE;
414 else if (g_minstagib)
416 // don't remove dropped items and powerups
417 if (self.classname != "minstagib")
419 startitem_failed = TRUE;
424 else if ((!cvar("g_pickup_items") || g_nixnex) && itemid != IT_STRENGTH && itemid != IT_INVINCIBLE && itemid != IT_HEALTH)
426 startitem_failed = TRUE;
431 precache_model (itemmodel);
432 precache_sound (pickupsound);
433 precache_sound ("misc/itemrespawn.wav");
435 if((itemid & (IT_STRENGTH | IT_INVINCIBLE | IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)) || (weaponid & WEPBIT_ALL))
436 self.target = "###item###"; // for finding the nearest item using find()
439 self.bot_pickup = TRUE;
440 self.bot_pickupevalfunc = pickupevalfunc;
441 self.bot_pickupbasevalue = pickupbasevalue;
442 self.mdl = itemmodel;
443 self.item_pickupsound = pickupsound;
444 // let mappers override respawntime
445 if (!self.respawntime)
446 self.respawntime = defaultrespawntime;
447 self.netname = itemname;
449 self.weapons = weaponid;
450 self.flags = FL_ITEM | itemflags;
451 self.touch = Item_Touch;
452 setmodel (self, self.mdl); // precision set below
453 self.effects |= EF_LOWPRECISION;
454 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
455 setsize (self, '-16 -16 0', '16 16 48');
457 setsize (self, '-16 -16 0', '16 16 32');
458 if (itemflags & FL_WEAPON)
460 // neutral team color for pickup weapons
461 self.colormap = 160 * 1024 + 160;
464 if (cvar("g_fullbrightitems"))
465 self.effects = self.effects | EF_FULLBRIGHT;
468 /* replace items in minstagib
469 * IT_STRENGTH = invisibility
470 * IT_NAILS = extra lives
471 * IT_INVINCIBLE = speed
473 void minstagib_items (float itemid)
475 // we don't want to replace dropped weapons ;)
476 if (self.classname == "droppedweapon")
478 self.ammo_cells = 25;
479 StartItem ("models/weapons/g_nex.md3",
480 "weapons/weaponpickup.wav", 15,
481 "Nex Gun", 0, WEPBIT_NEX, FL_WEAPON, generic_pickupevalfunc, 1000);
486 self.classname = "minstagib";
488 // replace rocket launchers and nex guns with ammo cells
489 if (itemid == IT_CELLS)
492 StartItem ("models/items/a_cells.md3",
493 "misc/itempickup.wav", 45,
494 "Nex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
501 itemid = IT_STRENGTH;
505 itemid = IT_INVINCIBLE;
507 // replace with invis
508 if (itemid == IT_STRENGTH)
510 self.effects = EF_ADDITIVE;
511 self.strength_finished = 30;
512 StartItem ("models/items/g_strength.md3",
513 "misc/powerup.wav", 120,
514 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
516 // replace with extra lives
517 if (itemid == IT_NAILS)
520 StartItem ("models/items/g_h100.md3",
521 "misc/megahealth.wav", 120,
522 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
525 // replace with speed
526 if (itemid == IT_INVINCIBLE)
528 self.effects = EF_ADDITIVE;
529 self.invincible_finished = 30;
530 StartItem ("models/items/g_invincible.md3",
531 "misc/powerup_shield.wav", 120,
532 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 1000);
537 float minst_no_auto_cells;
538 void minst_remove_item (void) {
539 if(minst_no_auto_cells)
543 float weaponswapping;
545 void weapon_defaultspawnfunc(float wpn, float weight)
548 var .float ammofield;
549 e = get_weaponinfo(wpn);
553 ammofield = Item_CounterField(e.items);
555 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(e.items)));
558 StartItem (e.model, "weapons/weaponpickup.wav", 15, e.message, 0, e.weapons, FL_WEAPON, weapon_pickupevalfunc, weight);
559 if (self.modelindex) // don't precache if self was removed
560 weapon_action(e.weapon, WR_PRECACHE);
563 void spawnfunc_weapon_shotgun (void);
564 void spawnfunc_weapon_uzi (void) {
566 if(q3acompat_machineshotgunswap)
567 if(self.classname != "droppedweapon")
569 weapon_defaultspawnfunc(WEP_SHOTGUN, 2500);
572 weapon_defaultspawnfunc(WEP_UZI, 5000);
575 void spawnfunc_weapon_shotgun (void) {
577 if(q3acompat_machineshotgunswap)
578 if(self.classname != "droppedweapon")
580 weapon_defaultspawnfunc(WEP_UZI, 5000);
583 weapon_defaultspawnfunc(WEP_SHOTGUN, 2500);
586 void spawnfunc_weapon_nex (void)
590 minstagib_items(IT_CELLS);
591 self.think = minst_remove_item;
592 self.nextthink = time + cvar("sys_ticrate");
595 weapon_defaultspawnfunc(WEP_NEX, 10000);
598 void spawnfunc_weapon_rocketlauncher (void)
602 minstagib_items(IT_CELLS);
603 self.think = minst_remove_item;
604 self.nextthink = time + cvar("sys_ticrate");
607 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER, 10000);
610 void spawnfunc_item_rockets (void) {
611 if(!self.ammo_rockets)
612 self.ammo_rockets = g_pickup_rockets;
613 StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", 15, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
616 void spawnfunc_item_shells (void);
617 void spawnfunc_item_bullets (void) {
619 if(q3acompat_machineshotgunswap)
620 if(self.classname != "droppedweapon")
622 weaponswapping = TRUE;
623 spawnfunc_item_shells();
624 weaponswapping = FALSE;
629 self.ammo_nails = g_pickup_nails;
630 StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", 15, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
633 void spawnfunc_item_cells (void) {
635 self.ammo_cells = g_pickup_cells;
636 StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", 15, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
639 void spawnfunc_item_shells (void) {
641 if(q3acompat_machineshotgunswap)
642 if(self.classname != "droppedweapon")
644 weaponswapping = TRUE;
645 spawnfunc_item_bullets();
646 weaponswapping = FALSE;
650 if(!self.ammo_shells)
651 self.ammo_shells = g_pickup_shells;
652 StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", 15, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
655 void spawnfunc_item_armor_small (void) {
657 self.armorvalue = g_pickup_armorsmall;
658 if(!self.max_armorvalue)
659 self.max_armorvalue = g_pickup_armorsmall_max;
660 StartItem ("models/items/g_a1.md3", "misc/armor1.wav", 15, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, 1000);
663 void spawnfunc_item_armor_medium (void) {
665 self.armorvalue = g_pickup_armormedium;
666 if(!self.max_armorvalue)
667 self.max_armorvalue = g_pickup_armormedium_max;
668 StartItem ("models/items/g_armormedium.md3", "misc/armor1.wav", 20, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
671 void spawnfunc_item_armor_large (void) {
673 self.armorvalue = g_pickup_armorlarge;
674 if(!self.max_armorvalue)
675 self.max_armorvalue = g_pickup_armorlarge_max;
676 StartItem ("models/items/g_a25.md3", "misc/armor25.wav", 30, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
679 void spawnfunc_item_health_small (void) {
681 self.max_health = g_pickup_healthsmall_max;
683 self.health = g_pickup_healthsmall;
684 StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", 15, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, 20000);
687 void spawnfunc_item_health_medium (void) {
689 self.max_health = g_pickup_healthmedium_max;
691 self.health = g_pickup_healthmedium;
692 StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", 15, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, 20000);
695 void spawnfunc_item_health_large (void) {
697 self.max_health = g_pickup_healthlarge_max;
699 self.health = g_pickup_healthlarge;
700 StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", 20, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, 20000);
703 void spawnfunc_item_health_mega (void) {
704 if(!cvar("g_powerup_superhealth"))
707 if(g_arena && !cvar("g_arena_powerups"))
711 minstagib_items(IT_NAILS);
714 self.max_health = g_pickup_healthmega_max;
716 self.health = g_pickup_healthmega;
717 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", 30, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, 20000);
721 // support old misnamed entities
722 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Nexuiz maps it is an armor shard
723 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
724 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
725 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
726 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
728 void spawnfunc_item_strength (void) {
729 if(!cvar("g_powerup_strength"))
732 if(g_arena && !cvar("g_arena_powerups"))
736 minstagib_items(IT_STRENGTH);
738 precache_sound("weapons/strength_fire.wav");
739 self.strength_finished = 30;
740 self.effects = EF_ADDITIVE;
741 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", 120, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
745 void spawnfunc_item_invincible (void) {
746 if(!cvar("g_powerup_shield"))
749 if(g_arena && !cvar("g_arena_powerups"))
753 minstagib_items(IT_INVINCIBLE);
755 self.invincible_finished = 30;
756 self.effects = EF_ADDITIVE;
757 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", 120, "Invulnerability", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
760 //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);}
761 //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);}
763 void spawnfunc_item_minst_cells (void) {
766 minst_no_auto_cells = 1;
767 minstagib_items(IT_CELLS);
774 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
776 void spawnfunc_misc_models (void)
778 SetBrushEntityModel();
781 void func_wall_use (void)
786 self.colormap = (activator.team - 1) * 0x11;
788 self.colormap = 0x00;
791 self.colormap = ceil(random() * 256) - 1;
792 self.colormap |= 1024; // RENDER_COLORMAPPED
795 void spawnfunc_func_wall (void)
797 SetBrushEntityModel();
798 self.solid = SOLID_BSP;
799 self.use = func_wall_use;