7 #define ITS_AVAILABLE 8
10 #define ITS_POWERUP 64
11 #define ISF_COLORMAP 16
18 var float autocvar_cl_ghost_items = 1;
19 var vector autocvar_cl_ghost_items_color = '-1 -1 -1';
20 float autocvar_cl_fullbright_items;
21 vector autocvar_cl_staywep_color;
22 float autocvar_cl_staywep_alpha;
23 float autocvar_cl_simple_items;
24 float cl_simple_items;
25 float cl_ghost_items_alpha;
32 if(self.ItemStatus & ITS_ANIMATE1)
34 self.angles += '0 180 0' * frametime;
35 setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));
38 if(self.ItemStatus & ITS_ANIMATE2)
40 self.angles += '0 -90 0' * frametime;
41 setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));
45 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
51 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
54 float csqcitems_started; // remove this after a release or two
55 void csqcitems_start()
57 if(autocvar_cl_ghost_items == 1)
58 cl_ghost_items_alpha = 0.55;
60 cl_ghost_items_alpha = bound(0, autocvar_cl_ghost_items, 1);
62 csqcitems_started = TRUE;
65 void ItemRead(float _IsNew)
67 if(!csqcitems_started)
70 float sf = ReadByte();
74 self.origin_x = ReadCoord();
75 self.origin_y = ReadCoord();
76 self.origin_z = ReadCoord();
77 setorigin(self, self.origin);
78 self.oldorigin = self.origin;
81 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
83 self.ItemStatus = ReadByte();
85 if(self.ItemStatus & ITS_AVAILABLE)
88 self.colormod = self.glowmod = '1 1 1';
92 if (cl_ghost_items_alpha)
94 self.alpha = autocvar_cl_ghost_items;
95 self.colormod = self.glowmod = autocvar_cl_ghost_items_color;
101 if(autocvar_cl_fullbright_items)
102 if(self.ItemStatus & ITS_ALLOWFB)
103 self.effects |= EF_FULLBRIGHT;
105 if(self.ItemStatus & ITS_STAYWEP)
107 self.colormod = self.glowmod = autocvar_cl_staywep_color;
108 self.alpha = autocvar_cl_staywep_alpha;
112 if(self.ItemStatus & ITS_POWERUP)
114 if(self.ItemStatus & ITS_AVAILABLE)
115 self.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
117 self.effects &~= (EF_ADDITIVE | EF_FULLBRIGHT);
123 self.drawmask = MASK_NORMAL;
124 self.movetype = MOVETYPE_NOCLIP;
125 self.draw = ItemDraw;
131 string _fn = ReadString();
133 if(cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
135 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
136 self.draw = ItemDrawSimple;
138 if(fexists(strcat(_fn2, "_simple.md3")))
139 self.mdl = strzone(strcat(_fn2, "_simple.md3"));
140 else if(fexists(strcat(_fn2, "_simple.dpm")))
141 self.mdl = strzone(strcat(_fn2, "_simple.dpm"));
142 else if(fexists(strcat(_fn2, "_simple.iqm")))
143 self.mdl = strzone(strcat(_fn2, "_simple.iqm"));
144 else if(fexists(strcat(_fn2, "_simple.obj")))
145 self.mdl = strzone(strcat(_fn2, "_simple.obj"));
148 self.draw = ItemDraw;
149 dprint("Simple item requested for ", _fn, " but no model exsist for it\n");
153 if(self.draw != ItemDrawSimple)
154 self.mdl = strzone(_fn);
158 dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, " tell tZork aboute this!\n");
160 precache_model(self.mdl);
161 setmodel(self, self.mdl);
164 if(sf & ISF_COLORMAP)
165 self.colormap = ReadShort();
170 self.move_movetype = MOVETYPE_TOSS;
171 self.move_velocity_x = ReadCoord();
172 self.move_velocity_y = ReadCoord();
173 self.move_velocity_z = ReadCoord();
174 self.velocity = self.move_velocity;
175 self.move_origin = self.oldorigin;
179 self.move_time = time;
180 self.spawntime = time;
183 self.move_time = max(self.move_time, time);
189 float autocvar_sv_simple_items;
190 float ItemSend(entity to, float sf)
197 WriteByte(MSG_ENTITY, ENT_CLIENT_ITEM);
198 WriteByte(MSG_ENTITY, sf);
201 //WriteByte(MSG_ENTITY, self.cnt);
202 if(sf & ISF_LOCATION)
204 WriteCoord(MSG_ENTITY, self.origin_x);
205 WriteCoord(MSG_ENTITY, self.origin_y);
206 WriteCoord(MSG_ENTITY, self.origin_z);
210 WriteByte(MSG_ENTITY, self.ItemStatus);
216 dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n");
218 WriteString(MSG_ENTITY, self.mdl);
222 if(sf & ISF_COLORMAP)
223 WriteShort(MSG_ENTITY, self.colormap);
227 WriteCoord(MSG_ENTITY, self.velocity_x);
228 WriteCoord(MSG_ENTITY, self.velocity_y);
229 WriteCoord(MSG_ENTITY, self.velocity_z);
236 float have_pickup_item(void)
238 // minstagib: only allow filtered items
240 if(self.classname != "minstagib")
243 if(self.flags & FL_POWERUP)
245 if(autocvar_g_powerups > 0)
247 if(autocvar_g_powerups == 0)
258 if(autocvar_g_pickup_items > 0)
260 if(autocvar_g_pickup_items == 0)
267 if(!WEPSET_EMPTY_E(self) || (self.items & IT_AMMO))
273 #define ITEM_RESPAWN_TICKS 10
275 #define ITEM_RESPAWNTIME(i) ((i).respawntime + crandom() * (i).respawntimejitter)
276 // range: respawntime - respawntimejitter .. respawntime + respawntimejitter
277 #define ITEM_RESPAWNTIME_INITIAL(i) (ITEM_RESPAWN_TICKS + random() * ((i).respawntime + (i).respawntimejitter - ITEM_RESPAWN_TICKS))
278 // range: 10 .. respawntime + respawntimejitter
280 floatfield Item_CounterField(float it)
284 case IT_SHELLS: return ammo_shells;
285 case IT_NAILS: return ammo_nails;
286 case IT_ROCKETS: return ammo_rockets;
287 case IT_CELLS: return ammo_cells;
288 case IT_FUEL: return ammo_fuel;
289 case IT_5HP: return health;
290 case IT_25HP: return health;
291 case IT_HEALTH: return health;
292 case IT_ARMOR_SHARD: return armorvalue;
293 case IT_ARMOR: return armorvalue;
294 // add more things here (health, armor)
295 default: error("requested item has no counter field");
299 string Item_CounterFieldName(float it)
303 case IT_SHELLS: return "shells";
304 case IT_NAILS: return "nails";
305 case IT_ROCKETS: return "rockets";
306 case IT_CELLS: return "cells";
307 case IT_FUEL: return "fuel";
309 // add more things here (health, armor)
310 default: error("requested item has no counter field name");
314 .float max_armorvalue;
315 .float pickup_anyway;
317 float Item_Customize()
319 if(self.spawnshieldtime)
321 if(!WEPSET_CONTAINS_ALL_EE(other, self))
323 self.colormod = '0 0 0';
324 self.glowmod = self.colormod;
325 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
332 self.colormod = stov(autocvar_g_ghost_items_color);
333 self.glowmod = self.colormod;
334 self.alpha = g_ghost_items;
343 void Item_Show (entity e, float mode)
345 e.effects &~= EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST;
346 e.ItemStatus &~= ITS_STAYWEP;
349 // make the item look normal, and be touchable
351 e.solid = SOLID_TRIGGER;
352 e.spawnshieldtime = 1;
353 e.ItemStatus |= ITS_AVAILABLE;
357 // hide the item completely
358 e.model = string_null;
360 e.spawnshieldtime = 1;
361 e.ItemStatus &~= ITS_AVAILABLE;
363 else if((e.flags & FL_WEAPON) && !(e.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
365 // make the item translucent and not touchable
367 e.solid = SOLID_TRIGGER; // can STILL be picked up!
368 e.effects |= EF_STARDUST;
369 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
370 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
374 //setmodel(e, "null");
376 e.colormod = '0 0 0';
377 e.glowmod = e.colormod;
378 e.spawnshieldtime = 1;
379 e.ItemStatus &~= ITS_AVAILABLE;
382 if (e.items & IT_STRENGTH || e.items & IT_INVINCIBLE)
383 e.ItemStatus |= ITS_POWERUP;
385 if (autocvar_g_nodepthtestitems)
386 e.effects |= EF_NODEPTHTEST;
389 if (autocvar_g_fullbrightitems)
390 e.ItemStatus |= ITS_ALLOWFB;
392 if (autocvar_sv_simple_items)
393 e.ItemStatus |= ITS_ALLOWSI;
395 // relink entity (because solid may have changed)
396 setorigin(e, e.origin);
397 e.SendFlags |= ISF_STATUS;
400 void Item_Respawn (void)
403 if(!g_minstagib && self.items == IT_STRENGTH)
404 sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
405 else if(!g_minstagib && self.items == IT_INVINCIBLE)
406 sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
408 sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
409 setorigin (self, self.origin);
411 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
412 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
415 void Item_RespawnCountdown (void)
417 if(self.count >= ITEM_RESPAWN_TICKS)
419 if(self.waypointsprite_attached)
420 WaypointSprite_Kill(self.waypointsprite_attached);
425 self.nextthink = time + 1;
430 vector rgb = '1 0 1';
436 case IT_STRENGTH: name = "item-invis"; rgb = '0 0 1'; break;
437 case IT_NAILS: name = "item-extralife"; rgb = '1 0 0'; break;
438 case IT_INVINCIBLE: name = "item-speed"; rgb = '1 0 1'; break;
445 case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
446 case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
451 case IT_FUEL_REGEN: name = "item-fuelregen"; rgb = '1 0.5 0'; break;
452 case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
454 if(self.flags & FL_WEAPON)
456 entity wi = get_weaponinfo(self.weapon);
465 print("Unknown powerup-marked item is wanting to respawn\n");
466 localcmd(sprintf("prvm_edict server %d\n", num_for_edict(self)));
470 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
471 if(self.waypointsprite_attached)
472 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
475 sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTN_NORM); // play respawn sound
476 if(self.waypointsprite_attached)
478 WaypointSprite_Ping(self.waypointsprite_attached);
479 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
484 void Item_ScheduleRespawnIn(entity e, float t)
486 if((e.flags & FL_POWERUP) || WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
488 e.think = Item_RespawnCountdown;
489 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
494 e.think = Item_Respawn;
495 e.nextthink = time + t;
499 void Item_ScheduleRespawn(entity e)
501 if(e.respawntime > 0)
504 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
506 else // if respawntime is -1, this item does not respawn
510 void Item_ScheduleInitialRespawn(entity e)
513 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
516 float ITEM_MODE_NONE = 0;
517 float ITEM_MODE_HEALTH = 1;
518 float ITEM_MODE_ARMOR = 2;
519 float ITEM_MODE_FUEL = 3;
520 float Item_GiveAmmoTo(entity item, entity player, .float ammofield, float ammomax, float mode)
525 if (item.spawnshieldtime)
527 if ((player.ammofield < ammomax) || item.pickup_anyway)
529 player.ammofield = bound(player.ammofield, ammomax, player.ammofield + item.ammofield);
533 else if(g_weapon_stay == 2)
535 float mi = min(item.ammofield, ammomax);
536 if (player.ammofield < mi)
538 player.ammofield = mi;
549 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
551 case ITEM_MODE_HEALTH:
552 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
554 case ITEM_MODE_ARMOR:
555 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
563 float Item_GiveTo(entity item, entity player)
570 // if nothing happens to player, just return without taking the item
572 _switchweapon = FALSE;
576 float prevcells = player.ammo_cells;
578 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
579 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, 999, ITEM_MODE_NONE);
581 if(player.ammo_cells > prevcells)
583 _switchweapon = TRUE;
585 // play some cool sounds ;)
586 if (clienttype(player) == CLIENTTYPE_REAL)
588 if(player.health <= 5)
589 AnnounceTo(player, "lastsecond");
590 else if(player.health < 50)
591 AnnounceTo(player, "narrowly");
593 // sound not available
594 // else if(item.items == IT_CELLS)
595 // AnnounceTo(player, "ammo");
597 if (WEPSET_CONTAINS_EW(item, WEP_MINSTANEX))
598 W_GiveWeapon (player, WEP_MINSTANEX, item.netname);
602 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
606 sprint (player, strcat("You got the ^2", item.netname, "\n"));
613 // sound not available
614 // AnnounceTo(player, "_lives");
615 player.armorvalue = bound(player.armorvalue, 999, player.armorvalue + autocvar_g_minstagib_extralives);
616 sprint(player, "^3You picked up some extra lives\n");
620 if (item.strength_finished)
623 // sound not available
624 // AnnounceTo(player, "invisible");
625 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
629 if (item.invincible_finished)
632 // sound not available
633 // AnnounceTo(player, "speed");
634 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_strength_time;
639 // in case the player has autoswitch enabled do the following:
640 // if the player is using their best weapon before items are given, they
641 // probably want to switch to an even better weapon after items are given
642 if (player.autoswitch)
643 if (player.switchweapon == w_getbestweapon(player))
644 _switchweapon = TRUE;
646 if not(WEPSET_CONTAINS_EW(player, player.switchweapon))
647 _switchweapon = TRUE;
649 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
650 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
651 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
652 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
653 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
654 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
655 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
657 if (item.flags & FL_WEAPON)
659 WEPSET_DECLARE_A(it);
660 WEPSET_COPY_AE(it, item);
661 WEPSET_ANDNOT_AE(it, player);
663 if (!WEPSET_EMPTY_A(it) || (item.spawnshieldtime && self.pickup_anyway))
666 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
667 if(WEPSET_CONTAINS_AW(it, i))
668 W_GiveWeapon (player, i, item.netname);
672 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
676 sprint (player, strcat("You got the ^2", item.netname, "\n"));
679 if (item.strength_finished)
682 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
684 if (item.invincible_finished)
687 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
689 if (item.superweapons_finished)
692 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
697 // always eat teamed entities
705 if (player.switchweapon != w_getbestweapon(player))
706 W_SwitchWeapon_Force(player, w_getbestweapon(player));
711 void Item_Touch (void)
715 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
716 if(self.classname == "droppedweapon")
718 if (ITEM_TOUCH_NEEDKILL())
725 if (other.classname != "player")
729 if (self.solid != SOLID_TRIGGER)
731 if (self.owner == other)
734 if (self.classname == "droppedweapon")
736 self.strength_finished = max(0, self.strength_finished - time);
737 self.invincible_finished = max(0, self.invincible_finished - time);
738 self.superweapons_finished = max(0, self.superweapons_finished - time);
741 if(!Item_GiveTo(self, other))
743 if (self.classname == "droppedweapon")
745 // undo what we did above
746 self.strength_finished += time;
747 self.invincible_finished += time;
748 self.superweapons_finished += time;
753 other.last_pickup = time;
755 pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
756 sound (other, CH_TRIGGER, self.item_pickupsound, VOL_BASE, ATTN_NORM);
758 if (self.classname == "droppedweapon")
760 else if not(self.spawnshieldtime)
766 RandomSelection_Init();
767 for(head = world; (head = findfloat(head, team, self.team)); )
769 if(head.flags & FL_ITEM)
772 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
775 e = RandomSelection_chosen_ent;
780 Item_ScheduleRespawn(e);
786 Item_Show(self, !self.state);
787 setorigin (self, self.origin);
789 if(self.classname != "droppedweapon")
791 self.think = SUB_Null;
794 if(self.waypointsprite_attached)
795 WaypointSprite_Kill(self.waypointsprite_attached);
797 if((self.flags & FL_POWERUP) | WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS)) // do not spawn powerups initially!
798 Item_ScheduleInitialRespawn(self);
806 if(self.effects & EF_NODRAW)
808 // marker for item team search
809 dprint("Initializing item team ", ftos(self.team), "\n");
810 RandomSelection_Init();
811 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
812 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
813 e = RandomSelection_chosen_ent;
817 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
821 // make it a non-spawned item
823 head.state = 1; // state 1 = initially hidden item
825 head.effects &~= EF_NODRAW;
832 // Savage: used for item garbage-collection
833 // TODO: perhaps nice special effect?
834 void RemoveItem(void)
839 // pickup evaluation functions
840 // these functions decide how desirable an item is to the bots
842 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
844 float weapon_pickupevalfunc(entity player, entity item)
846 float c, j, position;
848 // See if I have it already
849 if(!WEPSET_CONTAINS_ALL_EE(player, item))
851 // If I can pick it up
852 if(!item.spawnshieldtime)
854 else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
856 // Skilled bots will grab more
857 c = bound(0, skill / 10, 1) * 0.5;
865 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
866 if( bot_custom_weapon && c )
868 // Find the highest position on any range
870 for(j = 0; j < WEP_LAST ; ++j){
872 bot_weapons_far[j] == item.weapon ||
873 bot_weapons_mid[j] == item.weapon ||
874 bot_weapons_close[j] == item.weapon
885 position = WEP_LAST - position;
886 // item.bot_pickupbasevalue is overwritten here
887 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
891 return item.bot_pickupbasevalue * c;
894 float commodity_pickupevalfunc(entity player, entity item)
897 float need_shells = FALSE, need_nails = FALSE, need_rockets = FALSE, need_cells = FALSE, need_fuel = FALSE;
901 // Detect needed ammo
902 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
904 wi = get_weaponinfo(i);
906 if not(WEPSET_CONTAINS_EW(player, i))
909 if(wi.items & IT_SHELLS)
911 else if(wi.items & IT_NAILS)
913 else if(wi.items & IT_ROCKETS)
915 else if(wi.items & IT_CELLS)
917 else if(wi.items & IT_FUEL)
921 // TODO: figure out if the player even has the weapon this ammo is for?
922 // may not affect strategy much though...
923 // find out how much more ammo/armor/health the player can hold
925 if (item.ammo_shells)
926 if (player.ammo_shells < g_pickup_shells_max)
927 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
930 if (player.ammo_nails < g_pickup_nails_max)
931 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
933 if (item.ammo_rockets)
934 if (player.ammo_rockets < g_pickup_rockets_max)
935 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
938 if (player.ammo_cells < g_pickup_cells_max)
939 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
942 if (player.ammo_fuel < g_pickup_fuel_max)
943 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
945 if (player.armorvalue < item.max_armorvalue)
946 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
948 if (player.health < item.max_health)
949 c = c + max(0, 1 - player.health / item.max_health);
951 return item.bot_pickupbasevalue * c;
954 void Item_Damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
956 if(ITEM_DAMAGE_NEEDKILL(deathtype))
961 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)
963 startitem_failed = FALSE;
966 self.model = itemmodel;
970 error(strcat("^1Tried to spawn ", itemname, " with no model!\n"));
974 if(self.item_pickupsound == "")
975 self.item_pickupsound = pickupsound;
977 if(!self.respawntime) // both need to be set
979 self.respawntime = defaultrespawntime;
980 self.respawntimejitter = defaultrespawntimejitter;
984 self.weapon = weaponid;
987 WEPSET_COPY_EW(self, weaponid);
989 self.flags = FL_ITEM | itemflags;
991 if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
993 startitem_failed = TRUE;
998 // is it a dropped weapon?
999 if (self.classname == "droppedweapon")
1001 self.reset = SUB_Remove;
1002 // it's a dropped weapon
1003 self.movetype = MOVETYPE_TOSS;
1005 // Savage: remove thrown items after a certain period of time ("garbage collection")
1006 self.think = RemoveItem;
1007 self.nextthink = time + 20;
1009 self.takedamage = DAMAGE_YES;
1010 self.event_damage = Item_Damage;
1012 if(self.strength_finished || self.invincible_finished || self.superweapons_finished)
1015 if(WEPSET_CONTAINS_ALL_AE(WEPBIT_SUPERWEAPONS, self)) // only superweapons
1016 if(self.ammo_nails == 0)
1017 if(self.ammo_cells == 0)
1018 if(self.ammo_rockets == 0)
1019 if(self.ammo_shells == 0)
1020 if(self.ammo_fuel == 0)
1021 if(self.health == 0)
1022 if(self.armorvalue == 0)
1025 // if item is worthless after a timer, have it expire then
1026 self.nextthink = max(self.strength_finished, self.invincible_finished, self.superweapons_finished);
1029 // don't drop if in a NODROP zone (such as lava)
1030 traceline(self.origin, self.origin, MOVE_NORMAL, self);
1031 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1033 startitem_failed = TRUE;
1040 if(!have_pickup_item())
1042 startitem_failed = TRUE;
1047 self.reset = Item_Reset;
1048 // it's a level item
1049 if(self.spawnflags & 1)
1052 self.movetype = MOVETYPE_NONE;
1054 self.movetype = MOVETYPE_TOSS;
1055 // do item filtering according to game mode and other things
1058 // first nudge it off the floor a little bit to avoid math errors
1059 setorigin(self, self.origin + '0 0 1');
1060 // set item size before we spawn a spawnfunc_waypoint
1061 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1062 setsize (self, '-16 -16 0', '16 16 48');
1064 setsize (self, '-16 -16 0', '16 16 32');
1065 // note droptofloor returns FALSE if stuck/or would fall too far
1067 waypoint_spawnforitem(self);
1071 * can't do it that way, as it would break maps
1072 * TODO make a target_give like entity another way, that perhaps has
1073 * the weapon name in a key
1076 // target_give not yet supported; maybe later
1077 print("removed targeted ", self.classname, "\n");
1078 startitem_failed = TRUE;
1084 if(autocvar_spawn_debug >= 2)
1087 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
1089 // why not flags & fl_item?
1090 if(otheritem.is_item)
1092 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
1093 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1094 error("Mapper sucks.");
1097 self.is_item = TRUE;
1100 WEPSET_OR_AW(weaponsInMap, weaponid);
1102 precache_model (self.model);
1103 precache_sound (self.item_pickupsound);
1105 precache_sound ("misc/itemrespawncountdown.wav");
1106 if(!g_minstagib && itemid == IT_STRENGTH)
1107 precache_sound ("misc/strength_respawn.wav");
1108 else if(!g_minstagib && itemid == IT_INVINCIBLE)
1109 precache_sound ("misc/shield_respawn.wav");
1111 precache_sound ("misc/itemrespawn.wav");
1113 if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
1114 self.target = "###item###"; // for finding the nearest item using find()
1117 self.bot_pickup = TRUE;
1118 self.bot_pickupevalfunc = pickupevalfunc;
1119 self.bot_pickupbasevalue = pickupbasevalue;
1120 self.mdl = self.model;
1121 self.netname = itemname;
1122 self.touch = Item_Touch;
1123 setmodel(self, "null"); // precision set below
1124 //self.effects |= EF_LOWPRECISION;
1126 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1128 self.pos1 = '-16 -16 0';
1129 self.pos2 = '16 16 48';
1133 self.pos1 = '-16 -16 0';
1134 self.pos2 = '16 16 32';
1136 setsize (self, self.pos1, self.pos2);
1138 if(itemflags & FL_POWERUP)
1139 self.ItemStatus |= ITS_ANIMATE1;
1141 if(self.armorvalue || self.health)
1142 self.ItemStatus |= ITS_ANIMATE2;
1144 if(itemflags & FL_WEAPON)
1146 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1147 self.colormap = 1024; // color shirt=0 pants=0 grey
1151 self.ItemStatus |= ITS_ANIMATE1;
1152 self.ItemStatus |= ISF_COLORMAP;
1156 if(self.team) // broken, no idea why.
1159 self.cnt = 1; // item probability weight
1161 self.effects |= EF_NODRAW; // marker for item team search
1162 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
1167 Net_LinkEntity(self, FALSE, 0, ItemSend);
1170 /* replace items in minstagib
1171 * IT_STRENGTH = invisibility
1172 * IT_NAILS = extra lives
1173 * IT_INVINCIBLE = speed
1175 void minstagib_items (float itemid) // will be deleted soon.
1178 self.classname = "minstagib"; // ...?
1180 // replace rocket launchers and nex guns with ammo cells
1181 if (itemid == IT_CELLS)
1183 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1184 StartItem ("models/items/a_cells.md3",
1185 "misc/itempickup.wav", 45, 0,
1186 "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
1193 itemid = IT_STRENGTH;
1197 itemid = IT_INVINCIBLE;
1199 // replace with invis
1200 if (itemid == IT_STRENGTH)
1202 if(!self.strength_finished)
1203 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1204 StartItem ("models/items/g_strength.md3",
1205 "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1206 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1208 // replace with extra lives
1209 if (itemid == IT_NAILS)
1211 self.max_health = 1;
1212 StartItem ("models/items/g_h100.md3",
1213 "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1214 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1216 // replace with speed
1217 if (itemid == IT_INVINCIBLE)
1219 if(!self.invincible_finished)
1220 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1221 StartItem ("models/items/g_invincible.md3",
1222 "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1223 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1227 float minst_no_auto_cells;
1228 void minst_remove_item (void) {
1229 if(minst_no_auto_cells)
1233 float weaponswapping;
1236 void weapon_defaultspawnfunc(float wpn)
1240 var .float ammofield;
1246 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
1248 e = get_weaponinfo(wpn);
1250 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
1252 print("Attempted to spawn a mutator-blocked weapon; these guns will in the future require a mutator\n");
1254 objerror("Attempted to spawn a mutator-blocked weapon rejected");
1255 startitem_failed = TRUE;
1260 s = W_Apply_Weaponreplace(e.netname);
1263 MUTATOR_CALLHOOK(SetWeaponreplace);
1268 startitem_failed = TRUE;
1271 t = tokenize_console(s);
1274 self.team = --internalteam;
1276 for(i = 1; i < t; ++i)
1279 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1281 e = get_weaponinfo(j);
1285 copyentity(oldself, self);
1286 self.classname = "replacedweapon";
1287 weapon_defaultspawnfunc(j);
1293 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1298 if(t >= 1) // always the case!
1302 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1304 e = get_weaponinfo(j);
1313 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1319 startitem_failed = TRUE;
1324 e = get_weaponinfo(wpn);
1326 if(!self.respawntime)
1328 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1330 self.respawntime = g_pickup_respawntime_superweapon;
1331 self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
1335 self.respawntime = g_pickup_respawntime_weapon;
1336 self.respawntimejitter = g_pickup_respawntimejitter_weapon;
1340 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1341 if(!self.superweapons_finished)
1342 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1346 for(i = 0, j = 1; i < 24; ++i, j *= 2)
1350 ammofield = Item_CounterField(j);
1352 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
1358 if(g_pickup_weapons_anyway)
1359 self.pickup_anyway = TRUE;
1363 // no weapon-stay on superweapons
1364 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1365 f |= FL_NO_WEAPON_STAY;
1367 // weapon stay isn't supported for teamed weapons
1369 f |= FL_NO_WEAPON_STAY;
1371 // stupid minstagib hack, don't ask
1374 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1376 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
1377 if (self.modelindex) // don't precache if self was removed
1378 weapon_action(e.weapon, WR_PRECACHE);
1381 void spawnfunc_weapon_shotgun (void);
1382 void spawnfunc_weapon_uzi (void) {
1383 if(autocvar_sv_q3acompat_machineshotgunswap)
1384 if(self.classname != "droppedweapon")
1386 weapon_defaultspawnfunc(WEP_SHOTGUN);
1389 weapon_defaultspawnfunc(WEP_UZI);
1392 void spawnfunc_weapon_shotgun (void) {
1393 if(autocvar_sv_q3acompat_machineshotgunswap)
1394 if(self.classname != "droppedweapon")
1396 weapon_defaultspawnfunc(WEP_UZI);
1399 weapon_defaultspawnfunc(WEP_SHOTGUN);
1402 void spawnfunc_weapon_nex (void)
1406 minstagib_items(IT_CELLS);
1407 self.think = minst_remove_item;
1408 self.nextthink = time;
1411 weapon_defaultspawnfunc(WEP_NEX);
1414 void spawnfunc_weapon_minstanex (void)
1418 minstagib_items(IT_CELLS);
1419 self.think = minst_remove_item;
1420 self.nextthink = time;
1423 weapon_defaultspawnfunc(WEP_MINSTANEX);
1426 void spawnfunc_weapon_rocketlauncher (void)
1430 minstagib_items(IT_CELLS); // replace rocketlauncher with cells
1431 self.think = minst_remove_item;
1432 self.nextthink = time;
1435 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
1438 void spawnfunc_item_rockets (void) {
1439 if(!self.ammo_rockets)
1440 self.ammo_rockets = g_pickup_rockets;
1441 if(!self.pickup_anyway)
1442 self.pickup_anyway = g_pickup_ammo_anyway;
1443 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);
1446 void spawnfunc_item_shells (void);
1447 void spawnfunc_item_bullets (void) {
1449 if(autocvar_sv_q3acompat_machineshotgunswap)
1450 if(self.classname != "droppedweapon")
1452 weaponswapping = TRUE;
1453 spawnfunc_item_shells();
1454 weaponswapping = FALSE;
1458 if(!self.ammo_nails)
1459 self.ammo_nails = g_pickup_nails;
1460 if(!self.pickup_anyway)
1461 self.pickup_anyway = g_pickup_ammo_anyway;
1462 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);
1465 void spawnfunc_item_cells (void) {
1466 if(!self.ammo_cells)
1467 self.ammo_cells = g_pickup_cells;
1468 if(!self.pickup_anyway)
1469 self.pickup_anyway = g_pickup_ammo_anyway;
1470 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);
1473 void spawnfunc_item_shells (void) {
1475 if(autocvar_sv_q3acompat_machineshotgunswap)
1476 if(self.classname != "droppedweapon")
1478 weaponswapping = TRUE;
1479 spawnfunc_item_bullets();
1480 weaponswapping = FALSE;
1484 if(!self.ammo_shells)
1485 self.ammo_shells = g_pickup_shells;
1486 if(!self.pickup_anyway)
1487 self.pickup_anyway = g_pickup_ammo_anyway;
1488 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);
1491 void spawnfunc_item_armor_small (void) {
1492 if(!self.armorvalue)
1493 self.armorvalue = g_pickup_armorsmall;
1494 if(!self.max_armorvalue)
1495 self.max_armorvalue = g_pickup_armorsmall_max;
1496 if(!self.pickup_anyway)
1497 self.pickup_anyway = g_pickup_armorsmall_anyway;
1498 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);
1501 void spawnfunc_item_armor_medium (void) {
1502 if(!self.armorvalue)
1503 self.armorvalue = g_pickup_armormedium;
1504 if(!self.max_armorvalue)
1505 self.max_armorvalue = g_pickup_armormedium_max;
1506 if(!self.pickup_anyway)
1507 self.pickup_anyway = g_pickup_armormedium_anyway;
1508 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);
1511 void spawnfunc_item_armor_big (void) {
1512 if(!self.armorvalue)
1513 self.armorvalue = g_pickup_armorbig;
1514 if(!self.max_armorvalue)
1515 self.max_armorvalue = g_pickup_armorbig_max;
1516 if(!self.pickup_anyway)
1517 self.pickup_anyway = g_pickup_armorbig_anyway;
1518 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);
1521 void spawnfunc_item_armor_large (void) {
1522 if(!self.armorvalue)
1523 self.armorvalue = g_pickup_armorlarge;
1524 if(!self.max_armorvalue)
1525 self.max_armorvalue = g_pickup_armorlarge_max;
1526 if(!self.pickup_anyway)
1527 self.pickup_anyway = g_pickup_armorlarge_anyway;
1528 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);
1531 void spawnfunc_item_health_small (void) {
1532 if(!self.max_health)
1533 self.max_health = g_pickup_healthsmall_max;
1535 self.health = g_pickup_healthsmall;
1536 if(!self.pickup_anyway)
1537 self.pickup_anyway = g_pickup_healthsmall_anyway;
1538 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);
1541 void spawnfunc_item_health_medium (void) {
1542 if(!self.max_health)
1543 self.max_health = g_pickup_healthmedium_max;
1545 self.health = g_pickup_healthmedium;
1546 if(!self.pickup_anyway)
1547 self.pickup_anyway = g_pickup_healthmedium_anyway;
1548 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);
1551 void spawnfunc_item_health_large (void) {
1552 if(!self.max_health)
1553 self.max_health = g_pickup_healthlarge_max;
1555 self.health = g_pickup_healthlarge;
1556 if(!self.pickup_anyway)
1557 self.pickup_anyway = g_pickup_healthlarge_anyway;
1558 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);
1561 void spawnfunc_item_health_mega (void) {
1563 minstagib_items(IT_NAILS);
1565 if(!self.max_health)
1566 self.max_health = g_pickup_healthmega_max;
1568 self.health = g_pickup_healthmega;
1569 if(!self.pickup_anyway)
1570 self.pickup_anyway = g_pickup_healthmega_anyway;
1571 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);
1575 // support old misnamed entities
1576 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1577 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1578 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1579 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1580 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1582 void spawnfunc_item_strength (void) {
1584 minstagib_items(IT_STRENGTH);
1586 precache_sound("weapons/strength_fire.wav");
1587 if(!self.strength_finished)
1588 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1589 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);
1593 void spawnfunc_item_invincible (void) {
1595 minstagib_items(IT_INVINCIBLE);
1597 if(!self.invincible_finished)
1598 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1599 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);
1603 void spawnfunc_item_minst_cells (void) {
1606 minst_no_auto_cells = TRUE;
1607 minstagib_items(IT_CELLS);
1614 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1616 float GiveItems(entity e, float beginarg, float endarg);
1617 void target_items_use (void)
1619 if(activator.classname == "droppedweapon")
1626 if(activator.classname != "player")
1628 if(activator.deadflag != DEAD_NO)
1633 for(e = world; (e = find(e, classname, "droppedweapon")); )
1634 if(e.enemy == activator)
1637 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1638 centerprint(activator, self.message);
1641 void spawnfunc_target_items (void)
1646 self.use = target_items_use;
1647 if(!self.strength_finished)
1648 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1649 if(!self.invincible_finished)
1650 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1651 if(!self.superweapons_finished)
1652 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1654 precache_sound("misc/itempickup.wav");
1655 precache_sound("misc/megahealth.wav");
1656 precache_sound("misc/armor25.wav");
1657 precache_sound("misc/powerup.wav");
1658 precache_sound("misc/poweroff.wav");
1659 precache_sound("weapons/weaponpickup.wav");
1661 n = tokenize_console(self.netname);
1662 if(argv(0) == "give")
1664 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1668 for(i = 0; i < n; ++i)
1670 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1671 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1672 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1673 else if(argv(i) == "strength") self.items |= IT_STRENGTH;
1674 else if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1675 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1676 else if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1677 else if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1680 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1682 e = get_weaponinfo(j);
1683 if(argv(i) == e.netname)
1685 WEPSET_OR_EW(self, j);
1686 if(self.spawnflags == 0 || self.spawnflags == 2)
1687 weapon_action(e.weapon, WR_PRECACHE);
1692 print("target_items: invalid item ", argv(i), "\n");
1696 string itemprefix, valueprefix;
1697 if(self.spawnflags == 0)
1702 else if(self.spawnflags == 1)
1704 itemprefix = "max ";
1705 valueprefix = "max ";
1707 else if(self.spawnflags == 2)
1709 itemprefix = "min ";
1710 valueprefix = "min ";
1712 else if(self.spawnflags == 4)
1714 itemprefix = "minus ";
1715 valueprefix = "max ";
1718 error("invalid spawnflags");
1721 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1722 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1723 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * !!(self.items & IT_STRENGTH), "strength");
1724 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * !!(self.items & IT_INVINCIBLE), "invincible");
1725 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * !!(self.items & IT_SUPERWEAPON), "superweapons");
1726 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_JETPACK), "jetpack");
1727 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_FUEL_REGEN), "fuel_regen");
1728 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1729 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1730 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1731 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1732 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1733 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1734 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1735 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1737 e = get_weaponinfo(j);
1739 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, WEPSET_CONTAINS_EW(self, j), e.netname);
1742 self.netname = strzone(self.netname);
1743 //print(self.netname, "\n");
1745 n = tokenize_console(self.netname);
1746 for(i = 0; i < n; ++i)
1748 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1750 e = get_weaponinfo(j);
1751 if(argv(i) == e.netname)
1753 weapon_action(e.weapon, WR_PRECACHE);
1760 void spawnfunc_item_fuel(void)
1763 self.ammo_fuel = g_pickup_fuel;
1764 if(!self.pickup_anyway)
1765 self.pickup_anyway = g_pickup_ammo_anyway;
1766 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);
1769 void spawnfunc_item_fuel_regen(void)
1771 if(start_items & IT_FUEL_REGEN)
1773 spawnfunc_item_fuel();
1776 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);
1779 void spawnfunc_item_jetpack(void)
1781 if(g_grappling_hook)
1782 return; // sorry, but these two can't coexist (same button); spawn fuel instead
1784 self.ammo_fuel = g_pickup_fuel_jetpack;
1785 if(start_items & IT_JETPACK)
1787 spawnfunc_item_fuel();
1790 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);
1800 float GiveWeapon(entity e, float wpn, float op, float val)
1803 v0 = WEPSET_CONTAINS_EW(e, wpn);
1808 WEPSET_OR_EW(e, wpn);
1810 WEPSET_ANDNOT_EW(e, wpn);
1815 WEPSET_OR_EW(e, wpn);
1819 WEPSET_ANDNOT_EW(e, wpn);
1823 WEPSET_ANDNOT_EW(e, wpn);
1826 v1 = WEPSET_CONTAINS_EW(e, wpn);
1830 float GiveBit(entity e, .float fld, float bit, float op, float val)
1860 float GiveValue(entity e, .float fld, float op, float val)
1870 e.fld = max(e.fld, val); // min 100 cells = at least 100 cells
1873 e.fld = min(e.fld, val);
1886 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
1893 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTN_NORM);
1895 else if(v0 >= v0 + t)
1898 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTN_NORM);
1902 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
1905 e.rotfield = max(e.rotfield, time + rottime);
1907 e.regenfield = max(e.regenfield, time + regentime);
1910 #define PREGIVE_WEAPONS(e) WEPSET_DECLARE_A(save_weapons); WEPSET_COPY_AE(save_weapons, e)
1911 #define PREGIVE(e,f) float save_##f; save_##f = (e).f
1912 #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)
1913 #define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr)
1914 #define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
1915 #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)
1917 float GiveItems(entity e, float beginarg, float endarg)
1919 float got, i, j, val, op;
1920 float _switchweapon;
1929 _switchweapon = FALSE;
1931 if (e.switchweapon == w_getbestweapon(e))
1932 _switchweapon = TRUE;
1934 e.strength_finished = max(0, e.strength_finished - time);
1935 e.invincible_finished = max(0, e.invincible_finished - time);
1936 e.superweapons_finished = max(0, e.superweapons_finished - time);
1940 PREGIVE(e, strength_finished);
1941 PREGIVE(e, invincible_finished);
1942 PREGIVE(e, superweapons_finished);
1943 PREGIVE(e, ammo_nails);
1944 PREGIVE(e, ammo_cells);
1945 PREGIVE(e, ammo_shells);
1946 PREGIVE(e, ammo_rockets);
1947 PREGIVE(e, ammo_fuel);
1948 PREGIVE(e, armorvalue);
1951 for(i = beginarg; i < endarg; ++i)
1955 if(cmd == "0" || stof(cmd))
1979 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
1980 got += GiveValue(e, strength_finished, op, val);
1981 got += GiveValue(e, invincible_finished, op, val);
1982 got += GiveValue(e, superweapons_finished, op, val);
1983 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
1985 got += GiveBit(e, items, IT_JETPACK, op, val);
1986 got += GiveValue(e, health, op, val);
1987 got += GiveValue(e, armorvalue, op, val);
1989 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1991 wi = get_weaponinfo(j);
1993 if not(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED)
1994 got += GiveWeapon(e, j, op, val);
1997 got += GiveValue(e, ammo_cells, op, val);
1998 got += GiveValue(e, ammo_shells, op, val);
1999 got += GiveValue(e, ammo_nails, op, val);
2000 got += GiveValue(e, ammo_rockets, op, val);
2001 got += GiveValue(e, ammo_fuel, op, val);
2003 case "unlimited_ammo":
2004 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
2006 case "unlimited_weapon_ammo":
2007 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
2009 case "unlimited_superweapons":
2010 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
2013 got += GiveBit(e, items, IT_JETPACK, op, val);
2016 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
2019 got += GiveValue(e, strength_finished, op, val);
2022 got += GiveValue(e, invincible_finished, op, val);
2024 case "superweapons":
2025 got += GiveValue(e, superweapons_finished, op, val);
2028 got += GiveValue(e, ammo_cells, op, val);
2031 got += GiveValue(e, ammo_shells, op, val);
2035 got += GiveValue(e, ammo_nails, op, val);
2038 got += GiveValue(e, ammo_rockets, op, val);
2041 got += GiveValue(e, health, op, val);
2044 got += GiveValue(e, armorvalue, op, val);
2047 got += GiveValue(e, ammo_fuel, op, val);
2050 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2052 wi = get_weaponinfo(j);
2053 if(cmd == wi.netname)
2055 got += GiveWeapon(e, j, op, val);
2060 print("give: invalid item ", cmd, "\n");
2067 POSTGIVE_BIT(e, items, IT_FUEL_REGEN, "misc/itempickup.wav", string_null);
2068 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
2069 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
2070 POSTGIVE_BIT(e, items, IT_JETPACK, "misc/itempickup.wav", string_null);
2071 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2073 wi = get_weaponinfo(j);
2076 POSTGIVE_WEAPON(e, j, "weapons/weaponpickup.wav", string_null);
2077 if not(WEPSET_CONTAINS_AW(save_weapons, j))
2078 if(WEPSET_CONTAINS_EW(e, j))
2079 weapon_action(wi.weapon, WR_PRECACHE);
2082 POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
2083 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
2084 POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
2085 POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
2086 POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
2087 POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
2088 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);
2089 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);
2090 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);
2092 if(e.superweapons_finished <= 0)
2093 if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
2094 e.superweapons_finished = autocvar_g_balance_superweapons_time;
2098 e.health = bound(0, e.health, 100);
2099 e.armorvalue = bound(0, e.armorvalue, 999);
2102 if(e.strength_finished <= 0)
2103 e.strength_finished = 0;
2105 e.strength_finished += time;
2106 if(e.invincible_finished <= 0)
2107 e.invincible_finished = 0;
2109 e.invincible_finished += time;
2110 if(e.superweapons_finished <= 0)
2111 e.superweapons_finished = 0;
2113 e.superweapons_finished += time;
2115 if not(WEPSET_CONTAINS_EW(e, e.switchweapon))
2116 _switchweapon = TRUE;
2118 W_SwitchWeapon_Force(e, w_getbestweapon(e));