7 #define ITS_AVAILABLE 8
10 #define ITS_POWERUP 64
11 #define ISF_COLORMAP 16
18 float autocvar_cl_ghost_items;
19 vector autocvar_cl_ghost_items_color;
20 float autocvar_cl_simple_items;
21 float autocvar_cl_fullbright_items;
22 vector autocvar_cl_staywep_color;
23 float autocvar_cl_staywep_alpha;
30 if(self.ItemStatus & ITS_ANIMATE1)
32 self.angles += '0 180 0' * frametime;
33 setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));
36 if(self.ItemStatus & ITS_ANIMATE2)
38 self.angles += '0 -90 0' * frametime;
39 setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));
43 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
49 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
52 float csqcitems_started; // remove this after a release or two
53 void csqcitems_start()
55 autocvar_cl_ghost_items = bound(0, autocvar_cl_ghost_items, 1);
56 if(autocvar_cl_ghost_items == 1)
57 autocvar_cl_ghost_items = 0.55;
59 string _tmp = cvar_string("cl_ghost_items_color");
61 autocvar_cl_ghost_items_color = '-1 -1 -1';
63 csqcitems_started = TRUE;
66 void ItemRead(float _IsNew)
68 if(!csqcitems_started)
71 float sf = ReadByte();
75 self.origin_x = ReadCoord();
76 self.origin_y = ReadCoord();
77 self.origin_z = ReadCoord();
78 setorigin(self, self.origin);
79 self.oldorigin = self.origin;
82 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
84 self.ItemStatus = ReadByte();
86 if(self.ItemStatus & ITS_AVAILABLE)
89 self.colormod = self.glowmod = '1 1 1';
93 if (autocvar_cl_ghost_items)
95 self.alpha = autocvar_cl_ghost_items;
96 self.colormod = self.glowmod = autocvar_cl_ghost_items_color;
102 if(autocvar_cl_fullbright_items)
103 if(self.ItemStatus & ITS_ALLOWFB)
104 self.effects |= EF_FULLBRIGHT;
106 if(self.ItemStatus & ITS_STAYWEP)
108 self.colormod = self.glowmod = autocvar_cl_staywep_color;
109 self.alpha = autocvar_cl_staywep_alpha;
113 if(self.ItemStatus & ITS_POWERUP)
115 if(self.ItemStatus & ITS_AVAILABLE)
116 self.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
118 self.effects &~= (EF_ADDITIVE | EF_FULLBRIGHT);
124 self.drawmask = MASK_NORMAL;
125 self.movetype = MOVETYPE_NOCLIP;
131 string _fn = ReadString();
133 if(autocvar_cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
135 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
137 if(fexists(strcat(_fn2, "_simple.md3")))
138 self.mdl = strzone(strcat(_fn2, "_simple.md3"));
139 else if(fexists(strcat(_fn2, "_simple.dpm")))
140 self.mdl = strzone(strcat(_fn2, "_simple.dpm"));
141 else if(fexists(strcat(_fn2, "_simple.iqm")))
142 self.mdl = strzone(strcat(_fn2, "_simple.iqm"));
143 else if(fexists(strcat(_fn2, "_simple.obj")))
144 self.mdl = strzone(strcat(_fn2, "_simple.obj"));
148 dprint("Simple item requested for ", _fn, " but no model exsist for it\n");
154 self.mdl = strzone(_fn);
155 self.draw = ItemDraw;
158 self.draw = ItemDrawSimple;
160 precache_model(self.mdl);
161 setmodel(self, self.mdl);
164 if(sf & ISF_COLORMAP)
165 self.colormap = ReadShort();
169 self.effects |= EF_FLAME;
171 self.move_movetype = MOVETYPE_TOSS;
172 self.move_velocity_x = ReadCoord();
173 self.move_velocity_y = ReadCoord();
174 self.move_velocity_z = ReadCoord();
175 self.velocity = self.move_velocity;
176 self.move_origin = self.oldorigin;
180 self.move_time = time;
181 self.spawntime = time;
184 self.move_time = max(self.move_time, time);
190 float autocvar_sv_simple_items;
191 float ItemSend(entity to, float sf)
198 WriteByte(MSG_ENTITY, ENT_CLIENT_ITEM);
199 WriteByte(MSG_ENTITY, sf);
202 //WriteByte(MSG_ENTITY, self.cnt);
203 if(sf & ISF_LOCATION)
205 WriteCoord(MSG_ENTITY, self.origin_x);
206 WriteCoord(MSG_ENTITY, self.origin_y);
207 WriteCoord(MSG_ENTITY, self.origin_z);
211 WriteByte(MSG_ENTITY, self.ItemStatus);
214 WriteString(MSG_ENTITY, self.mdl);
216 if(sf & ISF_COLORMAP)
217 WriteShort(MSG_ENTITY, self.colormap);
221 WriteCoord(MSG_ENTITY, self.velocity_x);
222 WriteCoord(MSG_ENTITY, self.velocity_y);
223 WriteCoord(MSG_ENTITY, self.velocity_z);
230 float have_pickup_item(void)
232 // minstagib: only allow filtered items
234 if(self.classname != "minstagib")
237 if(self.flags & FL_POWERUP)
239 if(autocvar_g_powerups > 0)
241 if(autocvar_g_powerups == 0)
252 if(autocvar_g_pickup_items > 0)
254 if(autocvar_g_pickup_items == 0)
261 if(!WEPSET_EMPTY_E(self) || (self.items & IT_AMMO))
267 #define ITEM_RESPAWN_TICKS 10
269 #define ITEM_RESPAWNTIME(i) ((i).respawntime + crandom() * (i).respawntimejitter)
270 // range: respawntime - respawntimejitter .. respawntime + respawntimejitter
271 #define ITEM_RESPAWNTIME_INITIAL(i) (ITEM_RESPAWN_TICKS + random() * ((i).respawntime + (i).respawntimejitter - ITEM_RESPAWN_TICKS))
272 // range: 10 .. respawntime + respawntimejitter
274 floatfield Item_CounterField(float it)
278 case IT_SHELLS: return ammo_shells;
279 case IT_NAILS: return ammo_nails;
280 case IT_ROCKETS: return ammo_rockets;
281 case IT_CELLS: return ammo_cells;
282 case IT_FUEL: return ammo_fuel;
283 case IT_5HP: return health;
284 case IT_25HP: return health;
285 case IT_HEALTH: return health;
286 case IT_ARMOR_SHARD: return armorvalue;
287 case IT_ARMOR: return armorvalue;
288 // add more things here (health, armor)
289 default: error("requested item has no counter field");
293 string Item_CounterFieldName(float it)
297 case IT_SHELLS: return "shells";
298 case IT_NAILS: return "nails";
299 case IT_ROCKETS: return "rockets";
300 case IT_CELLS: return "cells";
301 case IT_FUEL: return "fuel";
303 // add more things here (health, armor)
304 default: error("requested item has no counter field name");
308 .float max_armorvalue;
309 .float pickup_anyway;
311 float Item_Customize()
313 if(self.spawnshieldtime)
315 if(!WEPSET_CONTAINS_ALL_EE(other, self))
317 self.colormod = '0 0 0';
318 self.glowmod = self.colormod;
319 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
326 self.colormod = stov(autocvar_g_ghost_items_color);
327 self.glowmod = self.colormod;
328 self.alpha = g_ghost_items;
337 void Item_Show (entity e, float mode)
339 e.effects &~= EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST;
340 e.ItemStatus &~= ITS_STAYWEP;
343 // make the item look normal, and be touchable
345 e.solid = SOLID_TRIGGER;
346 e.spawnshieldtime = 1;
347 e.ItemStatus |= ITS_AVAILABLE;
351 // hide the item completely
352 e.model = string_null;
354 e.spawnshieldtime = 1;
355 e.ItemStatus &~= ITS_AVAILABLE;
357 else if((e.flags & FL_WEAPON) && !(e.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
359 // make the item translucent and not touchable
361 e.solid = SOLID_TRIGGER; // can STILL be picked up!
362 e.effects |= EF_STARDUST;
363 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
364 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
368 //setmodel(e, "null");
370 e.colormod = '0 0 0';
371 e.glowmod = e.colormod;
372 e.spawnshieldtime = 1;
373 e.ItemStatus &~= ITS_AVAILABLE;
376 if (e.items & IT_STRENGTH || e.items & IT_INVINCIBLE)
377 e.ItemStatus |= ITS_POWERUP;
379 if (autocvar_g_nodepthtestitems)
380 e.effects |= EF_NODEPTHTEST;
383 if (autocvar_g_fullbrightitems)
384 e.ItemStatus |= ITS_ALLOWFB;
386 if (autocvar_sv_simple_items)
387 e.ItemStatus |= ITS_ALLOWSI;
389 // relink entity (because solid may have changed)
390 setorigin(e, e.origin);
391 e.SendFlags |= ISF_STATUS;
394 void Item_Respawn (void)
397 if(!g_minstagib && self.items == IT_STRENGTH)
398 sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
399 else if(!g_minstagib && self.items == IT_INVINCIBLE)
400 sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
402 sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
403 setorigin (self, self.origin);
405 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
406 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
409 void Item_RespawnCountdown (void)
411 if(self.count >= ITEM_RESPAWN_TICKS)
413 if(self.waypointsprite_attached)
414 WaypointSprite_Kill(self.waypointsprite_attached);
419 self.nextthink = time + 1;
430 case IT_STRENGTH: name = "item-invis"; rgb = '0 0 1'; break;
431 case IT_NAILS: name = "item-extralife"; rgb = '1 0 0'; break;
432 case IT_INVINCIBLE: name = "item-speed"; rgb = '1 0 1'; break;
439 case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
440 case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
445 case IT_FUEL_REGEN: name = "item-fuelregen"; rgb = '1 0.5 0'; break;
446 case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
448 if(self.flags & FL_WEAPON)
450 entity wi = get_weaponinfo(self.weapon);
459 print("Unknown powerup-marked item is wanting to respawn\n");
460 localcmd(sprintf("prvm_edict server %d\n", num_for_edict(self)));
464 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
465 if(self.waypointsprite_attached)
466 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
469 sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTN_NORM); // play respawn sound
470 if(self.waypointsprite_attached)
472 WaypointSprite_Ping(self.waypointsprite_attached);
473 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
478 void Item_ScheduleRespawnIn(entity e, float t)
480 if((e.flags & FL_POWERUP) || WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
482 e.think = Item_RespawnCountdown;
483 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
488 e.think = Item_Respawn;
489 e.nextthink = time + t;
493 void Item_ScheduleRespawn(entity e)
495 if(e.respawntime > 0)
498 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
500 else // if respawntime is -1, this item does not respawn
504 void Item_ScheduleInitialRespawn(entity e)
507 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
510 float ITEM_MODE_NONE = 0;
511 float ITEM_MODE_HEALTH = 1;
512 float ITEM_MODE_ARMOR = 2;
513 float ITEM_MODE_FUEL = 3;
514 float Item_GiveAmmoTo(entity item, entity player, .float ammofield, float ammomax, float mode)
519 if (item.spawnshieldtime)
521 if ((player.ammofield < ammomax) || item.pickup_anyway)
523 player.ammofield = bound(player.ammofield, ammomax, player.ammofield + item.ammofield);
527 else if(g_weapon_stay == 2)
529 float mi = min(item.ammofield, ammomax);
530 if (player.ammofield < mi)
532 player.ammofield = mi;
543 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
545 case ITEM_MODE_HEALTH:
546 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
548 case ITEM_MODE_ARMOR:
549 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
557 float Item_GiveTo(entity item, entity player)
564 // if nothing happens to player, just return without taking the item
566 _switchweapon = FALSE;
570 float prevcells = player.ammo_cells;
572 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
573 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, 999, ITEM_MODE_NONE);
575 if(player.ammo_cells > prevcells)
577 _switchweapon = TRUE;
579 // play some cool sounds ;)
580 if (clienttype(player) == CLIENTTYPE_REAL)
582 if(player.health <= 5)
583 AnnounceTo(player, "lastsecond");
584 else if(player.health < 50)
585 AnnounceTo(player, "narrowly");
587 // sound not available
588 // else if(item.items == IT_CELLS)
589 // AnnounceTo(player, "ammo");
591 if (WEPSET_CONTAINS_EW(item, WEP_MINSTANEX))
592 W_GiveWeapon (player, WEP_MINSTANEX, item.netname);
596 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
600 sprint (player, strcat("You got the ^2", item.netname, "\n"));
607 // sound not available
608 // AnnounceTo(player, "_lives");
609 player.armorvalue = bound(player.armorvalue, 999, player.armorvalue + autocvar_g_minstagib_extralives);
610 sprint(player, "^3You picked up some extra lives\n");
614 if (item.strength_finished)
617 // sound not available
618 // AnnounceTo(player, "invisible");
619 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
623 if (item.invincible_finished)
626 // sound not available
627 // AnnounceTo(player, "speed");
628 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_strength_time;
633 // in case the player has autoswitch enabled do the following:
634 // if the player is using their best weapon before items are given, they
635 // probably want to switch to an even better weapon after items are given
636 if (player.autoswitch)
637 if (player.switchweapon == w_getbestweapon(player))
638 _switchweapon = TRUE;
640 if not(WEPSET_CONTAINS_EW(player, player.switchweapon))
641 _switchweapon = TRUE;
643 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
644 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
645 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
646 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
647 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
648 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
649 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
651 if (item.flags & FL_WEAPON)
653 WEPSET_DECLARE_A(it);
654 WEPSET_COPY_AE(it, item);
655 WEPSET_ANDNOT_AE(it, player);
657 if (!WEPSET_EMPTY_A(it) || (item.spawnshieldtime && self.pickup_anyway))
660 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
661 if(WEPSET_CONTAINS_AW(it, i))
662 W_GiveWeapon (player, i, item.netname);
666 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
670 sprint (player, strcat("You got the ^2", item.netname, "\n"));
673 if (item.strength_finished)
676 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
678 if (item.invincible_finished)
681 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
683 if (item.superweapons_finished)
686 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
691 // always eat teamed entities
699 if (player.switchweapon != w_getbestweapon(player))
700 W_SwitchWeapon_Force(player, w_getbestweapon(player));
705 void Item_Touch (void)
709 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
710 if(self.classname == "droppedweapon")
712 if (ITEM_TOUCH_NEEDKILL())
719 if (other.classname != "player")
723 if (self.solid != SOLID_TRIGGER)
725 if (self.owner == other)
728 if (self.classname == "droppedweapon")
730 self.strength_finished = max(0, self.strength_finished - time);
731 self.invincible_finished = max(0, self.invincible_finished - time);
732 self.superweapons_finished = max(0, self.superweapons_finished - time);
735 if(!Item_GiveTo(self, other))
737 if (self.classname == "droppedweapon")
739 // undo what we did above
740 self.strength_finished += time;
741 self.invincible_finished += time;
742 self.superweapons_finished += time;
747 other.last_pickup = time;
749 pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
750 sound (other, CH_TRIGGER, self.item_pickupsound, VOL_BASE, ATTN_NORM);
752 if (self.classname == "droppedweapon")
754 else if not(self.spawnshieldtime)
760 RandomSelection_Init();
761 for(head = world; (head = findfloat(head, team, self.team)); )
763 if(head.flags & FL_ITEM)
766 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
769 e = RandomSelection_chosen_ent;
774 Item_ScheduleRespawn(e);
780 Item_Show(self, !self.state);
781 setorigin (self, self.origin);
783 if(self.classname != "droppedweapon")
785 self.think = SUB_Null;
788 if(self.waypointsprite_attached)
789 WaypointSprite_Kill(self.waypointsprite_attached);
791 if((self.flags & FL_POWERUP) | WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS)) // do not spawn powerups initially!
792 Item_ScheduleInitialRespawn(self);
800 if(self.effects & EF_NODRAW)
802 // marker for item team search
803 dprint("Initializing item team ", ftos(self.team), "\n");
804 RandomSelection_Init();
805 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
806 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
807 e = RandomSelection_chosen_ent;
811 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
815 // make it a non-spawned item
817 head.state = 1; // state 1 = initially hidden item
819 head.effects &~= EF_NODRAW;
826 // Savage: used for item garbage-collection
827 // TODO: perhaps nice special effect?
828 void RemoveItem(void)
833 // pickup evaluation functions
834 // these functions decide how desirable an item is to the bots
836 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
838 float weapon_pickupevalfunc(entity player, entity item)
840 float c, j, position;
842 // See if I have it already
843 if(!WEPSET_CONTAINS_ALL_EE(player, item))
845 // If I can pick it up
846 if(!item.spawnshieldtime)
848 else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
850 // Skilled bots will grab more
851 c = bound(0, skill / 10, 1) * 0.5;
859 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
860 if( bot_custom_weapon && c )
862 // Find the highest position on any range
864 for(j = 0; j < WEP_LAST ; ++j){
866 bot_weapons_far[j] == item.weapon ||
867 bot_weapons_mid[j] == item.weapon ||
868 bot_weapons_close[j] == item.weapon
879 position = WEP_LAST - position;
880 // item.bot_pickupbasevalue is overwritten here
881 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
885 return item.bot_pickupbasevalue * c;
888 float commodity_pickupevalfunc(entity player, entity item)
890 float c, i, need_shells, need_nails, need_rockets, need_cells, need_fuel;
894 // Detect needed ammo
895 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
897 wi = get_weaponinfo(i);
899 if not(WEPSET_CONTAINS_EW(player, i))
902 if(wi.items & IT_SHELLS)
904 else if(wi.items & IT_NAILS)
906 else if(wi.items & IT_ROCKETS)
908 else if(wi.items & IT_CELLS)
910 else if(wi.items & IT_FUEL)
914 // TODO: figure out if the player even has the weapon this ammo is for?
915 // may not affect strategy much though...
916 // find out how much more ammo/armor/health the player can hold
918 if (item.ammo_shells)
919 if (player.ammo_shells < g_pickup_shells_max)
920 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
923 if (player.ammo_nails < g_pickup_nails_max)
924 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
926 if (item.ammo_rockets)
927 if (player.ammo_rockets < g_pickup_rockets_max)
928 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
931 if (player.ammo_cells < g_pickup_cells_max)
932 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
935 if (player.ammo_fuel < g_pickup_fuel_max)
936 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
938 if (player.armorvalue < item.max_armorvalue)
939 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
941 if (player.health < item.max_health)
942 c = c + max(0, 1 - player.health / item.max_health);
944 return item.bot_pickupbasevalue * c;
947 void Item_Damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
949 if(ITEM_DAMAGE_NEEDKILL(deathtype))
954 void StartItem (string itemmodel, string pickupsound, float defaultrespawntime, float defaultrespawntimejitter, string itemname, float itemid, float weaponid, float itemflags, float(entity player, entity item) pickupevalfunc, float pickupbasevalue)
956 startitem_failed = FALSE;
959 self.model = itemmodel;
961 if(self.item_pickupsound == "")
962 self.item_pickupsound = pickupsound;
964 if(!self.respawntime) // both need to be set
966 self.respawntime = defaultrespawntime;
967 self.respawntimejitter = defaultrespawntimejitter;
971 self.weapon = weaponid;
974 WEPSET_COPY_EW(self, weaponid);
976 self.flags = FL_ITEM | itemflags;
978 if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
980 startitem_failed = TRUE;
985 // is it a dropped weapon?
986 if (self.classname == "droppedweapon")
988 self.reset = SUB_Remove;
989 // it's a dropped weapon
990 self.movetype = MOVETYPE_TOSS;
992 // Savage: remove thrown items after a certain period of time ("garbage collection")
993 self.think = RemoveItem;
994 self.nextthink = time + 20;
996 self.takedamage = DAMAGE_YES;
997 self.event_damage = Item_Damage;
999 if(self.strength_finished || self.invincible_finished || self.superweapons_finished)
1002 if(WEPSET_CONTAINS_ALL_AE(WEPBIT_SUPERWEAPONS, self)) // only superweapons
1003 if(self.ammo_nails == 0)
1004 if(self.ammo_cells == 0)
1005 if(self.ammo_rockets == 0)
1006 if(self.ammo_shells == 0)
1007 if(self.ammo_fuel == 0)
1008 if(self.health == 0)
1009 if(self.armorvalue == 0)
1012 // if item is worthless after a timer, have it expire then
1013 self.nextthink = max(self.strength_finished, self.invincible_finished, self.superweapons_finished);
1016 // don't drop if in a NODROP zone (such as lava)
1017 traceline(self.origin, self.origin, MOVE_NORMAL, self);
1018 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1020 startitem_failed = TRUE;
1027 if(!have_pickup_item())
1029 startitem_failed = TRUE;
1034 self.reset = Item_Reset;
1035 // it's a level item
1036 if(self.spawnflags & 1)
1039 self.movetype = MOVETYPE_NONE;
1041 self.movetype = MOVETYPE_TOSS;
1042 // do item filtering according to game mode and other things
1045 // first nudge it off the floor a little bit to avoid math errors
1046 setorigin(self, self.origin + '0 0 1');
1047 // set item size before we spawn a spawnfunc_waypoint
1048 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1049 setsize (self, '-16 -16 0', '16 16 48');
1051 setsize (self, '-16 -16 0', '16 16 32');
1052 // note droptofloor returns FALSE if stuck/or would fall too far
1054 waypoint_spawnforitem(self);
1058 * can't do it that way, as it would break maps
1059 * TODO make a target_give like entity another way, that perhaps has
1060 * the weapon name in a key
1063 // target_give not yet supported; maybe later
1064 print("removed targeted ", self.classname, "\n");
1065 startitem_failed = TRUE;
1071 if(autocvar_spawn_debug >= 2)
1074 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
1076 // why not flags & fl_item?
1077 if(otheritem.is_item)
1079 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
1080 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1081 error("Mapper sucks.");
1084 self.is_item = TRUE;
1087 WEPSET_OR_AW(weaponsInMap, weaponid);
1089 precache_model (self.model);
1090 precache_sound (self.item_pickupsound);
1092 precache_sound ("misc/itemrespawncountdown.wav");
1093 if(!g_minstagib && itemid == IT_STRENGTH)
1094 precache_sound ("misc/strength_respawn.wav");
1095 else if(!g_minstagib && itemid == IT_INVINCIBLE)
1096 precache_sound ("misc/shield_respawn.wav");
1098 precache_sound ("misc/itemrespawn.wav");
1100 if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
1101 self.target = "###item###"; // for finding the nearest item using find()
1104 self.bot_pickup = TRUE;
1105 self.bot_pickupevalfunc = pickupevalfunc;
1106 self.bot_pickupbasevalue = pickupbasevalue;
1107 self.mdl = self.model;
1108 self.netname = itemname;
1109 self.touch = Item_Touch;
1110 setmodel(self, "null"); // precision set below
1111 //self.effects |= EF_LOWPRECISION;
1113 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1115 self.pos1 = '-16 -16 0';
1116 self.pos2 = '16 16 48';
1120 self.pos1 = '-16 -16 0';
1121 self.pos2 = '16 16 32';
1123 setsize (self, self.pos1, self.pos2);
1125 if(itemflags & FL_POWERUP)
1126 self.ItemStatus |= ITS_ANIMATE1;
1128 if(self.armorvalue || self.health)
1129 self.ItemStatus |= ITS_ANIMATE2;
1131 if(itemflags & FL_WEAPON)
1133 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1134 self.colormap = 1024; // color shirt=0 pants=0 grey
1138 self.ItemStatus |= ITS_ANIMATE1;
1139 self.ItemStatus |= ISF_COLORMAP;
1143 if(self.team) // broken, no idea why.
1146 self.cnt = 1; // item probability weight
1148 self.effects |= EF_NODRAW; // marker for item team search
1149 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
1154 Net_LinkEntity(self, FALSE, 0, ItemSend);
1157 /* replace items in minstagib
1158 * IT_STRENGTH = invisibility
1159 * IT_NAILS = extra lives
1160 * IT_INVINCIBLE = speed
1162 void minstagib_items (float itemid) // will be deleted soon.
1165 self.classname = "minstagib"; // ...?
1167 // replace rocket launchers and nex guns with ammo cells
1168 if (itemid == IT_CELLS)
1170 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1171 StartItem ("models/items/a_cells.md3",
1172 "misc/itempickup.wav", 45, 0,
1173 "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
1180 itemid = IT_STRENGTH;
1184 itemid = IT_INVINCIBLE;
1186 // replace with invis
1187 if (itemid == IT_STRENGTH)
1189 if(!self.strength_finished)
1190 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1191 StartItem ("models/items/g_strength.md3",
1192 "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1193 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1195 // replace with extra lives
1196 if (itemid == IT_NAILS)
1198 self.max_health = 1;
1199 StartItem ("models/items/g_h100.md3",
1200 "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1201 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1203 // replace with speed
1204 if (itemid == IT_INVINCIBLE)
1206 if(!self.invincible_finished)
1207 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1208 StartItem ("models/items/g_invincible.md3",
1209 "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1210 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1214 float minst_no_auto_cells;
1215 void minst_remove_item (void) {
1216 if(minst_no_auto_cells)
1220 float weaponswapping;
1223 void weapon_defaultspawnfunc(float wpn)
1227 var .float ammofield;
1233 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
1235 e = get_weaponinfo(wpn);
1237 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
1239 print("Attempted to spawn a mutator-blocked weapon; these guns will in the future require a mutator\n");
1241 objerror("Attempted to spawn a mutator-blocked weapon rejected");
1242 startitem_failed = TRUE;
1247 s = W_Apply_Weaponreplace(e.netname);
1250 MUTATOR_CALLHOOK(SetWeaponreplace);
1255 startitem_failed = TRUE;
1258 t = tokenize_console(s);
1261 self.team = --internalteam;
1263 for(i = 1; i < t; ++i)
1266 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1268 e = get_weaponinfo(j);
1272 copyentity(oldself, self);
1273 self.classname = "replacedweapon";
1274 weapon_defaultspawnfunc(j);
1280 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1285 if(t >= 1) // always the case!
1289 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1291 e = get_weaponinfo(j);
1300 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1306 startitem_failed = TRUE;
1311 e = get_weaponinfo(wpn);
1313 if(!self.respawntime)
1315 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1317 self.respawntime = g_pickup_respawntime_superweapon;
1318 self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
1322 self.respawntime = g_pickup_respawntime_weapon;
1323 self.respawntimejitter = g_pickup_respawntimejitter_weapon;
1327 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1328 if(!self.superweapons_finished)
1329 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1333 for(i = 0, j = 1; i < 24; ++i, j *= 2)
1337 ammofield = Item_CounterField(j);
1339 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
1345 if(g_pickup_weapons_anyway)
1346 self.pickup_anyway = TRUE;
1350 // no weapon-stay on superweapons
1351 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1352 f |= FL_NO_WEAPON_STAY;
1354 // weapon stay isn't supported for teamed weapons
1356 f |= FL_NO_WEAPON_STAY;
1358 // stupid minstagib hack, don't ask
1361 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1363 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
1364 if (self.modelindex) // don't precache if self was removed
1365 weapon_action(e.weapon, WR_PRECACHE);
1368 void spawnfunc_weapon_shotgun (void);
1369 void spawnfunc_weapon_uzi (void) {
1370 if(autocvar_sv_q3acompat_machineshotgunswap)
1371 if(self.classname != "droppedweapon")
1373 weapon_defaultspawnfunc(WEP_SHOTGUN);
1376 weapon_defaultspawnfunc(WEP_UZI);
1379 void spawnfunc_weapon_shotgun (void) {
1380 if(autocvar_sv_q3acompat_machineshotgunswap)
1381 if(self.classname != "droppedweapon")
1383 weapon_defaultspawnfunc(WEP_UZI);
1386 weapon_defaultspawnfunc(WEP_SHOTGUN);
1389 void spawnfunc_weapon_nex (void)
1393 minstagib_items(IT_CELLS);
1394 self.think = minst_remove_item;
1395 self.nextthink = time;
1398 weapon_defaultspawnfunc(WEP_NEX);
1401 void spawnfunc_weapon_minstanex (void)
1405 minstagib_items(IT_CELLS);
1406 self.think = minst_remove_item;
1407 self.nextthink = time;
1410 weapon_defaultspawnfunc(WEP_MINSTANEX);
1413 void spawnfunc_weapon_rocketlauncher (void)
1417 minstagib_items(IT_CELLS); // replace rocketlauncher with cells
1418 self.think = minst_remove_item;
1419 self.nextthink = time;
1422 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
1425 void spawnfunc_item_rockets (void) {
1426 if(!self.ammo_rockets)
1427 self.ammo_rockets = g_pickup_rockets;
1428 if(!self.pickup_anyway)
1429 self.pickup_anyway = g_pickup_ammo_anyway;
1430 StartItem ("models/items/a_rockets.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "rockets", IT_ROCKETS, 0, 0, commodity_pickupevalfunc, 3000);
1433 void spawnfunc_item_shells (void);
1434 void spawnfunc_item_bullets (void) {
1436 if(autocvar_sv_q3acompat_machineshotgunswap)
1437 if(self.classname != "droppedweapon")
1439 weaponswapping = TRUE;
1440 spawnfunc_item_shells();
1441 weaponswapping = FALSE;
1445 if(!self.ammo_nails)
1446 self.ammo_nails = g_pickup_nails;
1447 if(!self.pickup_anyway)
1448 self.pickup_anyway = g_pickup_ammo_anyway;
1449 StartItem ("models/items/a_bullets.mdl", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "bullets", IT_NAILS, 0, 0, commodity_pickupevalfunc, 2000);
1452 void spawnfunc_item_cells (void) {
1453 if(!self.ammo_cells)
1454 self.ammo_cells = g_pickup_cells;
1455 if(!self.pickup_anyway)
1456 self.pickup_anyway = g_pickup_ammo_anyway;
1457 StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "cells", IT_CELLS, 0, 0, commodity_pickupevalfunc, 2000);
1460 void spawnfunc_item_shells (void) {
1462 if(autocvar_sv_q3acompat_machineshotgunswap)
1463 if(self.classname != "droppedweapon")
1465 weaponswapping = TRUE;
1466 spawnfunc_item_bullets();
1467 weaponswapping = FALSE;
1471 if(!self.ammo_shells)
1472 self.ammo_shells = g_pickup_shells;
1473 if(!self.pickup_anyway)
1474 self.pickup_anyway = g_pickup_ammo_anyway;
1475 StartItem ("models/items/a_shells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "shells", IT_SHELLS, 0, 0, commodity_pickupevalfunc, 500);
1478 void spawnfunc_item_armor_small (void) {
1479 if(!self.armorvalue)
1480 self.armorvalue = g_pickup_armorsmall;
1481 if(!self.max_armorvalue)
1482 self.max_armorvalue = g_pickup_armorsmall_max;
1483 if(!self.pickup_anyway)
1484 self.pickup_anyway = g_pickup_armorsmall_anyway;
1485 StartItem ("models/items/item_armor_small.md3", "misc/armor1.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "5 Armor", IT_ARMOR_SHARD, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1488 void spawnfunc_item_armor_medium (void) {
1489 if(!self.armorvalue)
1490 self.armorvalue = g_pickup_armormedium;
1491 if(!self.max_armorvalue)
1492 self.max_armorvalue = g_pickup_armormedium_max;
1493 if(!self.pickup_anyway)
1494 self.pickup_anyway = g_pickup_armormedium_anyway;
1495 StartItem ("models/items/item_armor_medium.md3", "misc/armor10.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "25 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1498 void spawnfunc_item_armor_big (void) {
1499 if(!self.armorvalue)
1500 self.armorvalue = g_pickup_armorbig;
1501 if(!self.max_armorvalue)
1502 self.max_armorvalue = g_pickup_armorbig_max;
1503 if(!self.pickup_anyway)
1504 self.pickup_anyway = g_pickup_armorbig_anyway;
1505 StartItem ("models/items/item_armor_big.md3", "misc/armor17_5.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "50 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, 20000);
1508 void spawnfunc_item_armor_large (void) {
1509 if(!self.armorvalue)
1510 self.armorvalue = g_pickup_armorlarge;
1511 if(!self.max_armorvalue)
1512 self.max_armorvalue = g_pickup_armorlarge_max;
1513 if(!self.pickup_anyway)
1514 self.pickup_anyway = g_pickup_armorlarge_anyway;
1515 StartItem ("models/items/item_armor_large.md3", "misc/armor25.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Armor", IT_ARMOR, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1518 void spawnfunc_item_health_small (void) {
1519 if(!self.max_health)
1520 self.max_health = g_pickup_healthsmall_max;
1522 self.health = g_pickup_healthsmall;
1523 if(!self.pickup_anyway)
1524 self.pickup_anyway = g_pickup_healthsmall_anyway;
1525 StartItem ("models/items/g_h1.md3", "misc/minihealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "5 Health", IT_5HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1528 void spawnfunc_item_health_medium (void) {
1529 if(!self.max_health)
1530 self.max_health = g_pickup_healthmedium_max;
1532 self.health = g_pickup_healthmedium;
1533 if(!self.pickup_anyway)
1534 self.pickup_anyway = g_pickup_healthmedium_anyway;
1535 StartItem ("models/items/g_h25.md3", "misc/mediumhealth.wav", g_pickup_respawntime_short, g_pickup_respawntimejitter_short, "25 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1538 void spawnfunc_item_health_large (void) {
1539 if(!self.max_health)
1540 self.max_health = g_pickup_healthlarge_max;
1542 self.health = g_pickup_healthlarge;
1543 if(!self.pickup_anyway)
1544 self.pickup_anyway = g_pickup_healthlarge_anyway;
1545 StartItem ("models/items/g_h50.md3", "misc/mediumhealth.wav", g_pickup_respawntime_medium, g_pickup_respawntimejitter_medium, "50 Health", IT_25HP, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_MID);
1548 void spawnfunc_item_health_mega (void) {
1550 minstagib_items(IT_NAILS);
1552 if(!self.max_health)
1553 self.max_health = g_pickup_healthmega_max;
1555 self.health = g_pickup_healthmega;
1556 if(!self.pickup_anyway)
1557 self.pickup_anyway = g_pickup_healthmega_anyway;
1558 StartItem ("models/items/g_h100.md3", "misc/megahealth.wav", g_pickup_respawntime_long, g_pickup_respawntimejitter_long, "100 Health", IT_HEALTH, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1562 // support old misnamed entities
1563 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1564 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1565 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1566 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1567 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1569 void spawnfunc_item_strength (void) {
1571 minstagib_items(IT_STRENGTH);
1573 precache_sound("weapons/strength_fire.wav");
1574 if(!self.strength_finished)
1575 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1576 StartItem ("models/items/g_strength.md3", "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Strength Powerup", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
1580 void spawnfunc_item_invincible (void) {
1582 minstagib_items(IT_INVINCIBLE);
1584 if(!self.invincible_finished)
1585 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1586 StartItem ("models/items/g_invincible.md3", "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Shield", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, 100000);
1590 void spawnfunc_item_minst_cells (void) {
1593 minst_no_auto_cells = TRUE;
1594 minstagib_items(IT_CELLS);
1601 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1603 float GiveItems(entity e, float beginarg, float endarg);
1604 void target_items_use (void)
1606 if(activator.classname == "droppedweapon")
1613 if(activator.classname != "player")
1615 if(activator.deadflag != DEAD_NO)
1620 for(e = world; (e = find(e, classname, "droppedweapon")); )
1621 if(e.enemy == activator)
1624 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1625 centerprint(activator, self.message);
1628 void spawnfunc_target_items (void)
1633 self.use = target_items_use;
1634 if(!self.strength_finished)
1635 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1636 if(!self.invincible_finished)
1637 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1638 if(!self.superweapons_finished)
1639 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1641 precache_sound("misc/itempickup.wav");
1642 precache_sound("misc/megahealth.wav");
1643 precache_sound("misc/armor25.wav");
1644 precache_sound("misc/powerup.wav");
1645 precache_sound("misc/poweroff.wav");
1646 precache_sound("weapons/weaponpickup.wav");
1648 n = tokenize_console(self.netname);
1649 if(argv(0) == "give")
1651 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1655 for(i = 0; i < n; ++i)
1657 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1658 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1659 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1660 else if(argv(i) == "strength") self.items |= IT_STRENGTH;
1661 else if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1662 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1663 else if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1664 else if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1666 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1668 e = get_weaponinfo(j);
1669 if(argv(i) == e.netname)
1671 WEPSET_OR_EW(self, j);
1672 if(self.spawnflags == 0 || self.spawnflags == 2)
1673 weapon_action(e.weapon, WR_PRECACHE);
1678 print("target_items: invalid item ", argv(i), "\n");
1681 string itemprefix, valueprefix;
1682 if(self.spawnflags == 0)
1687 else if(self.spawnflags == 1)
1689 itemprefix = "max ";
1690 valueprefix = "max ";
1692 else if(self.spawnflags == 2)
1694 itemprefix = "min ";
1695 valueprefix = "min ";
1697 else if(self.spawnflags == 4)
1699 itemprefix = "minus ";
1700 valueprefix = "max ";
1703 error("invalid spawnflags");
1706 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1707 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1708 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * !!(self.items & IT_STRENGTH), "strength");
1709 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * !!(self.items & IT_INVINCIBLE), "invincible");
1710 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * !!(self.items & IT_SUPERWEAPON), "superweapons");
1711 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_JETPACK), "jetpack");
1712 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_FUEL_REGEN), "fuel_regen");
1713 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1714 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1715 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1716 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1717 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1718 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1719 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1720 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1722 e = get_weaponinfo(j);
1724 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, WEPSET_CONTAINS_EW(self, j), e.netname);
1727 self.netname = strzone(self.netname);
1728 //print(self.netname, "\n");
1730 n = tokenize_console(self.netname);
1731 for(i = 0; i < n; ++i)
1733 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1735 e = get_weaponinfo(j);
1736 if(argv(i) == e.netname)
1738 weapon_action(e.weapon, WR_PRECACHE);
1745 void spawnfunc_item_fuel(void)
1748 self.ammo_fuel = g_pickup_fuel;
1749 if(!self.pickup_anyway)
1750 self.pickup_anyway = g_pickup_ammo_anyway;
1751 StartItem ("models/items/g_fuel.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "Fuel", IT_FUEL, 0, 0, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1754 void spawnfunc_item_fuel_regen(void)
1756 if(start_items & IT_FUEL_REGEN)
1758 spawnfunc_item_fuel();
1761 StartItem ("models/items/g_fuelregen.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Fuel regenerator", IT_FUEL_REGEN, 0, FL_POWERUP, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1764 void spawnfunc_item_jetpack(void)
1766 if(g_grappling_hook)
1767 return; // sorry, but these two can't coexist (same button); spawn fuel instead
1769 self.ammo_fuel = g_pickup_fuel_jetpack;
1770 if(start_items & IT_JETPACK)
1772 spawnfunc_item_fuel();
1775 StartItem ("models/items/g_jetpack.md3", "misc/itempickup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup, "Jet pack", IT_JETPACK, 0, FL_POWERUP, commodity_pickupevalfunc, BOT_PICKUP_RATING_LOW);
1785 float GiveWeapon(entity e, float wpn, float op, float val)
1788 v0 = WEPSET_CONTAINS_EW(e, wpn);
1793 WEPSET_OR_EW(e, wpn);
1795 WEPSET_ANDNOT_EW(e, wpn);
1800 WEPSET_OR_EW(e, wpn);
1804 WEPSET_ANDNOT_EW(e, wpn);
1808 WEPSET_ANDNOT_EW(e, wpn);
1811 v1 = WEPSET_CONTAINS_EW(e, wpn);
1815 float GiveBit(entity e, .float fld, float bit, float op, float val)
1845 float GiveValue(entity e, .float fld, float op, float val)
1855 e.fld = max(e.fld, val); // min 100 cells = at least 100 cells
1858 e.fld = min(e.fld, val);
1871 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
1878 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTN_NORM);
1880 else if(v0 >= v0 + t)
1883 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTN_NORM);
1887 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1890 e.rotfield = max(e.rotfield, time + rottime);
1892 e.regenfield = max(e.regenfield, time + regentime);
1895 #define PREGIVE_WEAPONS(e) WEPSET_DECLARE_A(save_weapons); WEPSET_COPY_AE(save_weapons, e)
1896 #define PREGIVE(e,f) float save_##f; save_##f = (e).f
1897 #define POSTGIVE_WEAPON(e,b,snd_incr,snd_decr) GiveSound((e), WEPSET_CONTAINS_AW(save_weapons, b), WEPSET_CONTAINS_EW(e, b), 0, snd_incr, snd_decr)
1898 #define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr)
1899 #define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
1900 #define POSTGIVE_VALUE_ROT(e,f,t,rotfield,rottime,regenfield,regentime,snd_incr,snd_decr) GiveRot((e), save_##f, (e).f, rotfield, rottime, regenfield, regentime); GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
1902 float GiveItems(entity e, float beginarg, float endarg)
1904 float got, i, j, val, op;
1905 float _switchweapon;
1914 _switchweapon = FALSE;
1916 if (e.switchweapon == w_getbestweapon(e))
1917 _switchweapon = TRUE;
1919 e.strength_finished = max(0, e.strength_finished - time);
1920 e.invincible_finished = max(0, e.invincible_finished - time);
1921 e.superweapons_finished = max(0, e.superweapons_finished - time);
1925 PREGIVE(e, strength_finished);
1926 PREGIVE(e, invincible_finished);
1927 PREGIVE(e, superweapons_finished);
1928 PREGIVE(e, ammo_nails);
1929 PREGIVE(e, ammo_cells);
1930 PREGIVE(e, ammo_shells);
1931 PREGIVE(e, ammo_rockets);
1932 PREGIVE(e, ammo_fuel);
1933 PREGIVE(e, armorvalue);
1936 for(i = beginarg; i < endarg; ++i)
1940 if(cmd == "0" || stof(cmd))
1964 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1965 got += GiveValue(e, strength_finished, op, val);
1966 got += GiveValue(e, invincible_finished, op, val);
1967 got += GiveValue(e, superweapons_finished, op, val);
1968 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1970 got += GiveBit(e, items, IT_JETPACK, op, val);
1971 got += GiveValue(e, health, op, val);
1972 got += GiveValue(e, armorvalue, op, val);
1974 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1976 wi = get_weaponinfo(j);
1978 if not(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED)
1979 got += GiveWeapon(e, j, op, val);
1982 got += GiveValue(e, ammo_cells, op, val);
1983 got += GiveValue(e, ammo_shells, op, val);
1984 got += GiveValue(e, ammo_nails, op, val);
1985 got += GiveValue(e, ammo_rockets, op, val);
1986 got += GiveValue(e, ammo_fuel, op, val);
1988 case "unlimited_ammo":
1989 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1991 case "unlimited_weapon_ammo":
1992 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
1994 case "unlimited_superweapons":
1995 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
1998 got += GiveBit(e, items, IT_JETPACK, op, val);
2001 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
2004 got += GiveValue(e, strength_finished, op, val);
2007 got += GiveValue(e, invincible_finished, op, val);
2009 case "superweapons":
2010 got += GiveValue(e, superweapons_finished, op, val);
2013 got += GiveValue(e, ammo_cells, op, val);
2016 got += GiveValue(e, ammo_shells, op, val);
2020 got += GiveValue(e, ammo_nails, op, val);
2023 got += GiveValue(e, ammo_rockets, op, val);
2026 got += GiveValue(e, health, op, val);
2029 got += GiveValue(e, armorvalue, op, val);
2032 got += GiveValue(e, ammo_fuel, op, val);
2035 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2037 wi = get_weaponinfo(j);
2038 if(cmd == wi.netname)
2040 got += GiveWeapon(e, j, op, val);
2045 print("give: invalid item ", cmd, "\n");
2052 POSTGIVE_BIT(e, items, IT_FUEL_REGEN, "misc/itempickup.wav", string_null);
2053 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
2054 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
2055 POSTGIVE_BIT(e, items, IT_JETPACK, "misc/itempickup.wav", string_null);
2056 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2058 wi = get_weaponinfo(j);
2061 POSTGIVE_WEAPON(e, j, "weapons/weaponpickup.wav", string_null);
2062 if not(WEPSET_CONTAINS_AW(save_weapons, j))
2063 if(WEPSET_CONTAINS_EW(e, j))
2064 weapon_action(wi.weapon, WR_PRECACHE);
2067 POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
2068 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
2069 POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
2070 POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
2071 POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
2072 POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
2073 POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, "misc/itempickup.wav", string_null);
2074 POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, "misc/armor25.wav", string_null);
2075 POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, "misc/megahealth.wav", string_null);
2077 if(e.superweapons_finished <= 0)
2078 if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
2079 e.superweapons_finished = autocvar_g_balance_superweapons_time;
2083 e.health = bound(0, e.health, 100);
2084 e.armorvalue = bound(0, e.armorvalue, 999);
2087 if(e.strength_finished <= 0)
2088 e.strength_finished = 0;
2090 e.strength_finished += time;
2091 if(e.invincible_finished <= 0)
2092 e.invincible_finished = 0;
2094 e.invincible_finished += time;
2095 if(e.superweapons_finished <= 0)
2096 e.superweapons_finished = 0;
2098 e.superweapons_finished += time;
2100 if not(WEPSET_CONTAINS_EW(e, e.switchweapon))
2101 _switchweapon = TRUE;
2103 W_SwitchWeapon_Force(e, w_getbestweapon(e));