7 #define ITS_AVAILABLE 8
10 #define ITS_POWERUP 64
11 #define ISF_COLORMAP 16
19 var float autocvar_cl_animate_items = 1;
20 var float autocvar_cl_ghost_items = 0.45;
21 var vector autocvar_cl_ghost_items_color = '-1 -1 -1';
22 var float autocvar_cl_fullbright_items = 0;
23 var vector autocvar_cl_weapon_stay_color = '2 0.5 0.5';
24 var float autocvar_cl_weapon_stay_alpha = 0.75;
25 var float autocvar_cl_simple_items = 0;
26 var string autocvr_cl_simpleitems_postfix = "_simple";
34 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
35 if(self.move_flags & FL_ONGROUND)
36 { // For some reason move_avelocity gets set to '0 0 0' here ...
37 self.oldorigin = self.origin;
40 if(autocvar_cl_animate_items)
41 { // ... so reset it if animations are requested.
42 if(self.ItemStatus & ITS_ANIMATE1)
43 self.move_avelocity = '0 180 0';
45 if(self.ItemStatus & ITS_ANIMATE2)
46 self.move_avelocity = '0 -90 0';
50 else if (autocvar_cl_animate_items)
52 if(self.ItemStatus & ITS_ANIMATE1)
54 self.angles += self.move_avelocity * frametime;
55 setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));
58 if(self.ItemStatus & ITS_ANIMATE2)
60 self.angles += self.move_avelocity * frametime;
61 setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));
70 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
72 if(self.move_flags & FL_ONGROUND)
77 void ItemRead(float _IsNew)
79 float sf = ReadByte();
83 self.origin_x = ReadCoord();
84 self.origin_y = ReadCoord();
85 self.origin_z = ReadCoord();
86 setorigin(self, self.origin);
87 self.oldorigin = self.origin;
92 self.angles_x = ReadCoord();
93 self.angles_y = ReadCoord();
94 self.angles_z = ReadCoord();
95 self.move_angles = self.angles;
98 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
100 self.ItemStatus = ReadByte();
102 if(self.ItemStatus & ITS_AVAILABLE)
105 self.colormod = self.glowmod = '1 1 1';
109 if (autocvar_cl_ghost_items_color)
111 self.alpha = autocvar_cl_ghost_items;
112 self.colormod = self.glowmod = autocvar_cl_ghost_items_color;
118 if(autocvar_cl_fullbright_items)
119 if(self.ItemStatus & ITS_ALLOWFB)
120 self.effects |= EF_FULLBRIGHT;
122 if(self.ItemStatus & ITS_STAYWEP)
124 self.colormod = self.glowmod = autocvar_cl_weapon_stay_color;
125 self.alpha = autocvar_cl_weapon_stay_alpha;
129 if(self.ItemStatus & ITS_POWERUP)
131 if(self.ItemStatus & ITS_AVAILABLE)
132 self.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
134 self.effects &~= (EF_ADDITIVE | EF_FULLBRIGHT);
140 self.drawmask = MASK_NORMAL;
141 self.movetype = MOVETYPE_NOCLIP;
142 self.draw = ItemDraw;
148 string _fn = ReadString();
150 if(autocvar_cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
152 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
153 self.draw = ItemDrawSimple;
157 if(fexists(sprintf("%s%s.md3", _fn2, autocvr_cl_simpleitems_postfix)))
158 self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvr_cl_simpleitems_postfix));
159 else if(fexists(sprintf("%s%s.dpm", _fn2, autocvr_cl_simpleitems_postfix)))
160 self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvr_cl_simpleitems_postfix));
161 else if(fexists(sprintf("%s%s.iqm", _fn2, autocvr_cl_simpleitems_postfix)))
162 self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvr_cl_simpleitems_postfix));
163 else if(fexists(sprintf("%s%s.obj", _fn2, autocvr_cl_simpleitems_postfix)))
164 self.mdl = strzone(sprintf("%s%s.obj", _fn2, autocvr_cl_simpleitems_postfix));
167 self.draw = ItemDraw;
168 dprint("Simple item requested for ", _fn, " but no model exsist for it\n");
172 if(self.draw != ItemDrawSimple)
173 self.mdl = strzone(_fn);
177 dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, " tell tZork aboute this!\n");
179 precache_model(self.mdl);
180 setmodel(self, self.mdl);
183 if(sf & ISF_COLORMAP)
184 self.colormap = ReadShort();
189 self.move_angles = '0 0 0';
190 self.move_movetype = MOVETYPE_TOSS;
191 self.move_velocity_x = ReadCoord();
192 self.move_velocity_y = ReadCoord();
193 self.move_velocity_z = ReadCoord();
194 self.velocity = self.move_velocity;
195 self.move_origin = self.oldorigin;
199 self.move_time = time;
200 self.spawntime = time;
203 self.move_time = max(self.move_time, time);
206 if(autocvar_cl_animate_items)
208 if(self.ItemStatus & ITS_ANIMATE1)
209 self.move_avelocity = '0 180 0';
211 if(self.ItemStatus & ITS_ANIMATE2)
212 self.move_avelocity = '0 -90 0';
219 float autocvar_sv_simple_items;
220 float ItemSend(entity to, float sf)
227 WriteByte(MSG_ENTITY, ENT_CLIENT_ITEM);
228 WriteByte(MSG_ENTITY, sf);
230 //WriteByte(MSG_ENTITY, self.cnt);
231 if(sf & ISF_LOCATION)
233 WriteCoord(MSG_ENTITY, self.origin_x);
234 WriteCoord(MSG_ENTITY, self.origin_y);
235 WriteCoord(MSG_ENTITY, self.origin_z);
240 WriteCoord(MSG_ENTITY, self.angles_x);
241 WriteCoord(MSG_ENTITY, self.angles_y);
242 WriteCoord(MSG_ENTITY, self.angles_z);
246 WriteByte(MSG_ENTITY, self.ItemStatus);
252 dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n");
254 WriteString(MSG_ENTITY, self.mdl);
258 if(sf & ISF_COLORMAP)
259 WriteShort(MSG_ENTITY, self.colormap);
263 WriteCoord(MSG_ENTITY, self.velocity_x);
264 WriteCoord(MSG_ENTITY, self.velocity_y);
265 WriteCoord(MSG_ENTITY, self.velocity_z);
272 float have_pickup_item(void)
274 // minstagib: only allow filtered items
276 if(self.classname != "minstagib")
279 if(self.flags & FL_POWERUP)
281 if(autocvar_g_powerups > 0)
283 if(autocvar_g_powerups == 0)
294 if(autocvar_g_pickup_items > 0)
296 if(autocvar_g_pickup_items == 0)
303 if(!WEPSET_EMPTY_E(self) || (self.items & IT_AMMO))
309 #define ITEM_RESPAWN_TICKS 10
311 #define ITEM_RESPAWNTIME(i) ((i).respawntime + crandom() * (i).respawntimejitter)
312 // range: respawntime - respawntimejitter .. respawntime + respawntimejitter
313 #define ITEM_RESPAWNTIME_INITIAL(i) (ITEM_RESPAWN_TICKS + random() * ((i).respawntime + (i).respawntimejitter - ITEM_RESPAWN_TICKS))
314 // range: 10 .. respawntime + respawntimejitter
316 floatfield Item_CounterField(float it)
320 case IT_SHELLS: return ammo_shells;
321 case IT_NAILS: return ammo_nails;
322 case IT_ROCKETS: return ammo_rockets;
323 case IT_CELLS: return ammo_cells;
324 case IT_FUEL: return ammo_fuel;
325 case IT_5HP: return health;
326 case IT_25HP: return health;
327 case IT_HEALTH: return health;
328 case IT_ARMOR_SHARD: return armorvalue;
329 case IT_ARMOR: return armorvalue;
330 // add more things here (health, armor)
331 default: error("requested item has no counter field");
334 // should never happen
339 string Item_CounterFieldName(float it)
343 case IT_SHELLS: return "shells";
344 case IT_NAILS: return "nails";
345 case IT_ROCKETS: return "rockets";
346 case IT_CELLS: return "cells";
347 case IT_FUEL: return "fuel";
349 // add more things here (health, armor)
350 default: error("requested item has no counter field name");
353 // should never happen
358 .float max_armorvalue;
359 .float pickup_anyway;
361 float Item_Customize()
363 if(self.spawnshieldtime)
365 if(!WEPSET_CONTAINS_ALL_EE(other, self))
367 self.colormod = '0 0 0';
368 self.glowmod = self.colormod;
369 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
376 self.colormod = stov(autocvar_g_ghost_items_color);
377 self.glowmod = self.colormod;
378 self.alpha = g_ghost_items;
387 void Item_Show (entity e, float mode)
389 e.effects &~= EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST;
390 e.ItemStatus &~= ITS_STAYWEP;
393 // make the item look normal, and be touchable
395 e.solid = SOLID_TRIGGER;
396 e.spawnshieldtime = 1;
397 e.ItemStatus |= ITS_AVAILABLE;
401 // hide the item completely
402 e.model = string_null;
404 e.spawnshieldtime = 1;
405 e.ItemStatus &~= ITS_AVAILABLE;
407 else if((e.flags & FL_WEAPON) && !(e.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
409 // make the item translucent and not touchable
411 e.solid = SOLID_TRIGGER; // can STILL be picked up!
412 e.effects |= EF_STARDUST;
413 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
414 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
418 //setmodel(e, "null");
420 e.colormod = '0 0 0';
421 e.glowmod = e.colormod;
422 e.spawnshieldtime = 1;
423 e.ItemStatus &~= ITS_AVAILABLE;
426 if (e.items & IT_STRENGTH || e.items & IT_INVINCIBLE)
427 e.ItemStatus |= ITS_POWERUP;
429 if (autocvar_g_nodepthtestitems)
430 e.effects |= EF_NODEPTHTEST;
433 if (autocvar_g_fullbrightitems)
434 e.ItemStatus |= ITS_ALLOWFB;
436 if (autocvar_sv_simple_items)
437 e.ItemStatus |= ITS_ALLOWSI;
439 // relink entity (because solid may have changed)
440 setorigin(e, e.origin);
441 e.SendFlags |= ISF_STATUS;
444 float it_armor_large_time;
445 float it_health_mega_time;
446 float it_invisible_time;
448 float it_extralife_time;
449 float it_strength_time;
450 float it_shield_time;
451 float it_fuelregen_time;
452 float it_jetpack_time;
453 float it_superweapons_time;
455 void Item_ItemsTime_Init()
457 it_armor_large_time = -1;
458 it_health_mega_time = -1;
459 it_invisible_time = -1;
461 it_extralife_time = -1;
462 it_strength_time = -1;
464 it_fuelregen_time = -1;
465 it_jetpack_time = -1;
466 it_superweapons_time = -1;
468 void Item_ItemsTime_Reset()
470 it_armor_large_time = (it_armor_large_time == -1) ? -1 : 0;
471 it_health_mega_time = (it_health_mega_time == -1) ? -1 : 0;
472 it_invisible_time = (it_invisible_time == -1) ? -1 : 0;
473 it_speed_time = (it_speed_time == -1) ? -1 : 0;
474 it_extralife_time = (it_extralife_time == -1) ? -1 : 0;
475 it_strength_time = (it_strength_time == -1) ? -1 : 0;
476 it_shield_time = (it_shield_time == -1) ? -1 : 0;
477 it_fuelregen_time = (it_fuelregen_time == -1) ? -1 : 0;
478 it_jetpack_time = (it_jetpack_time == -1) ? -1 : 0;
479 it_superweapons_time= (it_superweapons_time== -1) ? -1 : 0;
481 void Item_ItemsTime_ResetForPlayer(entity e)
483 e.item_armor_large_time = (it_armor_large_time == -1) ? -1 : 0;
484 e.item_health_mega_time = (it_health_mega_time == -1) ? -1 : 0;
485 e.item_invisible_time = (it_invisible_time == -1) ? -1 : 0;
486 e.item_speed_time = (it_speed_time == -1) ? -1 : 0;
487 e.item_extralife_time = (it_extralife_time == -1) ? -1 : 0;
488 e.item_strength_time = (it_strength_time == -1) ? -1 : 0;
489 e.item_shield_time = (it_shield_time == -1) ? -1 : 0;
490 e.item_fuelregen_time = (it_fuelregen_time == -1) ? -1 : 0;
491 e.item_jetpack_time = (it_jetpack_time == -1) ? -1 : 0;
492 e.item_superweapons_time= (it_superweapons_time== -1) ? -1 : 0;
494 void Item_ItemsTime_Get(entity e)
496 e.item_armor_large_time = it_armor_large_time;
497 e.item_health_mega_time = it_health_mega_time;
498 e.item_invisible_time = it_invisible_time;
499 e.item_speed_time = it_speed_time;
500 e.item_extralife_time = it_extralife_time;
501 e.item_strength_time = it_strength_time;
502 e.item_shield_time = it_shield_time;
503 e.item_fuelregen_time = it_fuelregen_time;
504 e.item_jetpack_time = it_jetpack_time;
505 e.item_superweapons_time = it_superweapons_time;
507 float Item_ItemsTime_UpdateTime_Check(float item_time, float t)
509 if(t == 0 && item_time == -1)
511 if(time < t && (item_time <= time || t < item_time))
515 void Item_ItemsTime_UpdateTime(entity e, float t)
521 case IT_STRENGTH://"item-invis"
522 if(Item_ItemsTime_UpdateTime_Check(it_invisible_time, t))
523 it_invisible_time = t;
525 case IT_NAILS://"item-extralife"
526 if(Item_ItemsTime_UpdateTime_Check(it_extralife_time, t))
527 it_extralife_time = t;
529 case IT_INVINCIBLE://"item-speed"
530 if(Item_ItemsTime_UpdateTime_Check(it_speed_time, t))
540 //if (e.classname == "item_health_mega")
541 if(Item_ItemsTime_UpdateTime_Check(it_health_mega_time, t))
542 it_health_mega_time = t;
545 if (e.classname == "item_armor_large")
546 if(Item_ItemsTime_UpdateTime_Check(it_armor_large_time, t))
547 it_armor_large_time = t;
549 case IT_STRENGTH://"item-strength"
550 if(Item_ItemsTime_UpdateTime_Check(it_strength_time, t))
551 it_strength_time = t;
553 case IT_INVINCIBLE://"item-shield"
554 if(Item_ItemsTime_UpdateTime_Check(it_shield_time, t))
558 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
559 if(Item_ItemsTime_UpdateTime_Check(it_superweapons_time, t))
560 it_superweapons_time = t;
565 case IT_FUEL_REGEN://"item-fuelregen"
566 if(Item_ItemsTime_UpdateTime_Check(it_fuelregen_time, t))
567 it_fuelregen_time = t;
569 case IT_JETPACK://"item-jetpack"
570 if(Item_ItemsTime_UpdateTime_Check(it_jetpack_time, t))
575 void Item_ItemsTime_GetForAll()
580 FOR_EACH_REALCLIENT(e)
581 Item_ItemsTime_Get(e);
585 FOR_EACH_REALCLIENT(e)
587 if (e.classname != "player")
588 Item_ItemsTime_Get(e);
593 void Item_Respawn (void)
596 if(!g_minstagib && self.items == IT_STRENGTH)
597 sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
598 else if(!g_minstagib && self.items == IT_INVINCIBLE)
599 sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
601 sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
602 setorigin (self, self.origin);
604 if(self.flags & FL_POWERUP || self.classname == "item_armor_large" || self.items == IT_HEALTH || WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
606 Item_ItemsTime_UpdateTime(self, 0);
607 Item_ItemsTime_GetForAll();
610 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
611 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
614 void Item_RespawnCountdown (void)
616 if(self.count >= ITEM_RESPAWN_TICKS)
618 if(self.waypointsprite_attached)
619 WaypointSprite_Kill(self.waypointsprite_attached);
624 self.nextthink = time + 1;
629 vector rgb = '1 0 1';
635 case IT_STRENGTH: name = "item-invis"; rgb = '0 0 1'; break;
636 case IT_NAILS: name = "item-extralife"; rgb = '1 0 0'; break;
637 case IT_INVINCIBLE: name = "item-speed"; rgb = '1 0 1'; break;
644 case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
645 case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
647 //if (self.classname == "item_health_mega")
648 {name = "item_health_mega"; rgb = '1 0 0';}
651 if (self.classname == "item_armor_large")
652 {name = "item_armor_large"; rgb = '0 1 0';}
658 case IT_FUEL_REGEN: name = "item-fuelregen"; rgb = '1 0.5 0'; break;
659 case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
661 if(self.flags & FL_WEAPON)
663 entity wi = get_weaponinfo(self.weapon);
672 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
673 if(self.waypointsprite_attached)
675 if (self.items == IT_HEALTH || self.items == IT_ARMOR)
676 WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
677 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
682 print("Unknown powerup-marked item is wanting to respawn\n");
683 localcmd(sprintf("prvm_edict server %d\n", num_for_edict(self)));
686 sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTN_NORM); // play respawn sound
687 if(self.waypointsprite_attached)
689 WaypointSprite_Ping(self.waypointsprite_attached);
690 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
695 void Item_ScheduleRespawnIn(entity e, float t)
697 if((e.flags & FL_POWERUP) || WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS) || e.classname == "item_armor_large" || e.items == IT_HEALTH)
700 e.think = Item_RespawnCountdown;
701 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
702 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
704 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
706 for(t = e.scheduledrespawntime, head = world; (head = nextent(head)); )
710 if(clienttype(head) == CLIENTTYPE_NOTACLIENT)
711 if(WEPSET_CONTAINS_ANY_EA(head, WEPBIT_SUPERWEAPONS))
712 if(head.classname != "weapon_info")
714 if(head.scheduledrespawntime <= time)
719 if(head.scheduledrespawntime < t)
720 t = head.scheduledrespawntime;
726 for(t = e.scheduledrespawntime, head = world; (head = find(head, classname, e.classname)); )
728 // in minstagib .classname is "minstagib" for every item
729 if(e == head || (g_minstagib && e.items != head.items))
731 if(head.scheduledrespawntime <= time)
736 if(head.scheduledrespawntime < t)
737 t = head.scheduledrespawntime;
740 Item_ItemsTime_UpdateTime(e, t);
741 Item_ItemsTime_GetForAll();
745 e.think = Item_Respawn;
746 e.nextthink = time + t;
747 e.scheduledrespawntime = e.nextthink;
751 void Item_ScheduleRespawn(entity e)
753 if(e.respawntime > 0)
756 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
758 else // if respawntime is -1, this item does not respawn
762 void Item_ScheduleInitialRespawn(entity e)
765 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
768 float ITEM_MODE_NONE = 0;
769 float ITEM_MODE_HEALTH = 1;
770 float ITEM_MODE_ARMOR = 2;
771 float ITEM_MODE_FUEL = 3;
772 float Item_GiveAmmoTo(entity item, entity player, .float ammofield, float ammomax, float mode)
777 if (item.spawnshieldtime)
779 if ((player.ammofield < ammomax) || item.pickup_anyway)
781 player.ammofield = bound(player.ammofield, ammomax, player.ammofield + item.ammofield);
785 else if(g_weapon_stay == 2)
787 float mi = min(item.ammofield, ammomax);
788 if (player.ammofield < mi)
790 player.ammofield = mi;
801 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
803 case ITEM_MODE_HEALTH:
804 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
806 case ITEM_MODE_ARMOR:
807 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
815 float Item_GiveTo(entity item, entity player)
822 // if nothing happens to player, just return without taking the item
824 _switchweapon = FALSE;
828 float prevcells = player.ammo_cells;
830 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
831 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, 999, ITEM_MODE_NONE);
833 if(player.ammo_cells > prevcells)
835 _switchweapon = TRUE;
837 // play some cool sounds ;)
838 if (clienttype(player) == CLIENTTYPE_REAL)
840 if(player.health <= 5)
841 AnnounceTo(player, "lastsecond");
842 else if(player.health < 50)
843 AnnounceTo(player, "narrowly");
845 // sound not available
846 // else if(item.items == IT_CELLS)
847 // AnnounceTo(player, "ammo");
849 if (WEPSET_CONTAINS_EW(item, WEP_MINSTANEX))
850 W_GiveWeapon (player, WEP_MINSTANEX);
854 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
858 sprint (player, strcat("You got the ^2", item.netname, "\n"));
865 // sound not available
866 // AnnounceTo(player, "_lives");
867 player.armorvalue = bound(player.armorvalue, 999, player.armorvalue + autocvar_g_minstagib_extralives);
868 sprint(player, "^3You picked up some extra lives\n");
872 if (item.strength_finished)
875 // sound not available
876 // AnnounceTo(player, "invisible");
877 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
881 if (item.invincible_finished)
884 // sound not available
885 // AnnounceTo(player, "speed");
886 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_invincible_time;
891 // in case the player has autoswitch enabled do the following:
892 // if the player is using their best weapon before items are given, they
893 // probably want to switch to an even better weapon after items are given
894 if (player.autoswitch)
895 if (player.switchweapon == w_getbestweapon(player))
896 _switchweapon = TRUE;
898 if not(WEPSET_CONTAINS_EW(player, player.switchweapon))
899 _switchweapon = TRUE;
901 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
902 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
903 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
904 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
905 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
906 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
907 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
909 if (item.flags & FL_WEAPON)
911 WEPSET_DECLARE_A(it);
912 WEPSET_COPY_AE(it, item);
913 WEPSET_ANDNOT_AE(it, player);
915 if (!WEPSET_EMPTY_A(it) || (item.spawnshieldtime && self.pickup_anyway))
918 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
919 if(WEPSET_CONTAINS_AW(it, i))
920 W_GiveWeapon(player, i);
924 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
928 sprint (player, strcat("You got the ^2", item.netname, "\n"));
931 if (item.strength_finished)
934 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
936 if (item.invincible_finished)
939 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
941 if (item.superweapons_finished)
944 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
949 // always eat teamed entities
957 if (player.switchweapon != w_getbestweapon(player))
958 W_SwitchWeapon_Force(player, w_getbestweapon(player));
963 void Item_Touch (void)
967 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
968 if(self.classname == "droppedweapon")
970 if (ITEM_TOUCH_NEEDKILL())
977 if (other.classname != "player")
981 if (self.solid != SOLID_TRIGGER)
983 if (self.owner == other)
985 if(MUTATOR_CALLHOOK(ItemTouch))
988 if (self.classname == "droppedweapon")
990 self.strength_finished = max(0, self.strength_finished - time);
991 self.invincible_finished = max(0, self.invincible_finished - time);
992 self.superweapons_finished = max(0, self.superweapons_finished - time);
995 if(!Item_GiveTo(self, other))
997 if (self.classname == "droppedweapon")
999 // undo what we did above
1000 self.strength_finished += time;
1001 self.invincible_finished += time;
1002 self.superweapons_finished += time;
1007 other.last_pickup = time;
1009 pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
1010 sound (other, CH_TRIGGER, self.item_pickupsound, VOL_BASE, ATTN_NORM);
1012 if (self.classname == "droppedweapon")
1014 else if not(self.spawnshieldtime)
1020 RandomSelection_Init();
1021 for(head = world; (head = findfloat(head, team, self.team)); )
1023 if(head.flags & FL_ITEM)
1025 Item_Show(head, -1);
1026 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
1029 e = RandomSelection_chosen_ent;
1034 Item_ScheduleRespawn(e);
1040 Item_Show(self, !self.state);
1041 setorigin (self, self.origin);
1043 if(self.classname != "droppedweapon")
1045 self.think = func_null;
1048 if(self.waypointsprite_attached)
1049 WaypointSprite_Kill(self.waypointsprite_attached);
1051 if((self.flags & FL_POWERUP) | WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS)) // do not spawn powerups initially!
1052 Item_ScheduleInitialRespawn(self);
1056 void Item_FindTeam()
1060 if(self.effects & EF_NODRAW)
1062 // marker for item team search
1063 dprint("Initializing item team ", ftos(self.team), "\n");
1064 RandomSelection_Init();
1065 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
1066 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
1067 e = RandomSelection_chosen_ent;
1071 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
1075 // make it a non-spawned item
1076 Item_Show(head, -1);
1077 head.state = 1; // state 1 = initially hidden item
1079 head.effects &~= EF_NODRAW;
1086 // Savage: used for item garbage-collection
1087 // TODO: perhaps nice special effect?
1088 void RemoveItem(void)
1093 // pickup evaluation functions
1094 // these functions decide how desirable an item is to the bots
1096 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
1098 float weapon_pickupevalfunc(entity player, entity item)
1100 float c, j, position;
1102 // See if I have it already
1103 if(!WEPSET_CONTAINS_ALL_EE(player, item))
1105 // If I can pick it up
1106 if(!item.spawnshieldtime)
1108 else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
1110 // Skilled bots will grab more
1111 c = bound(0, skill / 10, 1) * 0.5;
1119 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
1120 if( bot_custom_weapon && c )
1122 // Find the highest position on any range
1124 for(j = 0; j < WEP_LAST ; ++j){
1126 bot_weapons_far[j] == item.weapon ||
1127 bot_weapons_mid[j] == item.weapon ||
1128 bot_weapons_close[j] == item.weapon
1139 position = WEP_LAST - position;
1140 // item.bot_pickupbasevalue is overwritten here
1141 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
1145 return item.bot_pickupbasevalue * c;
1148 float commodity_pickupevalfunc(entity player, entity item)
1151 float need_shells = FALSE, need_nails = FALSE, need_rockets = FALSE, need_cells = FALSE, need_fuel = FALSE;
1155 // Detect needed ammo
1156 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
1158 wi = get_weaponinfo(i);
1160 if not(WEPSET_CONTAINS_EW(player, i))
1163 if(wi.items & IT_SHELLS)
1165 else if(wi.items & IT_NAILS)
1167 else if(wi.items & IT_ROCKETS)
1168 need_rockets = TRUE;
1169 else if(wi.items & IT_CELLS)
1171 else if(wi.items & IT_FUEL)
1175 // TODO: figure out if the player even has the weapon this ammo is for?
1176 // may not affect strategy much though...
1177 // find out how much more ammo/armor/health the player can hold
1179 if (item.ammo_shells)
1180 if (player.ammo_shells < g_pickup_shells_max)
1181 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
1183 if (item.ammo_nails)
1184 if (player.ammo_nails < g_pickup_nails_max)
1185 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
1187 if (item.ammo_rockets)
1188 if (player.ammo_rockets < g_pickup_rockets_max)
1189 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
1191 if (item.ammo_cells)
1192 if (player.ammo_cells < g_pickup_cells_max)
1193 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
1196 if (player.ammo_fuel < g_pickup_fuel_max)
1197 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
1198 if (item.armorvalue)
1199 if (player.armorvalue < item.max_armorvalue)
1200 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
1202 if (player.health < item.max_health)
1203 c = c + max(0, 1 - player.health / item.max_health);
1205 return item.bot_pickupbasevalue * c;
1208 void Item_Damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
1210 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1215 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)
1217 startitem_failed = FALSE;
1219 if(self.model == "")
1220 self.model = itemmodel;
1222 if(self.model == "")
1224 error(strcat("^1Tried to spawn ", itemname, " with no model!\n"));
1228 if(self.item_pickupsound == "")
1229 self.item_pickupsound = pickupsound;
1231 if(!self.respawntime) // both need to be set
1233 self.respawntime = defaultrespawntime;
1234 self.respawntimejitter = defaultrespawntimejitter;
1237 self.items = itemid;
1238 self.weapon = weaponid;
1241 WEPSET_COPY_EW(self, weaponid);
1243 self.flags = FL_ITEM | itemflags;
1245 if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
1247 startitem_failed = TRUE;
1252 // is it a dropped weapon?
1253 if (self.classname == "droppedweapon")
1255 self.reset = SUB_Remove;
1256 // it's a dropped weapon
1257 self.movetype = MOVETYPE_TOSS;
1259 // Savage: remove thrown items after a certain period of time ("garbage collection")
1260 self.think = RemoveItem;
1261 self.nextthink = time + 20;
1263 self.takedamage = DAMAGE_YES;
1264 self.event_damage = Item_Damage;
1266 if(self.strength_finished || self.invincible_finished || self.superweapons_finished)
1269 if(WEPSET_CONTAINS_ALL_AE(WEPBIT_SUPERWEAPONS, self)) // only superweapons
1270 if(self.ammo_nails == 0)
1271 if(self.ammo_cells == 0)
1272 if(self.ammo_rockets == 0)
1273 if(self.ammo_shells == 0)
1274 if(self.ammo_fuel == 0)
1275 if(self.health == 0)
1276 if(self.armorvalue == 0)
1279 // if item is worthless after a timer, have it expire then
1280 self.nextthink = max(self.strength_finished, self.invincible_finished, self.superweapons_finished);
1283 // don't drop if in a NODROP zone (such as lava)
1284 traceline(self.origin, self.origin, MOVE_NORMAL, self);
1285 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1287 startitem_failed = TRUE;
1294 if(!have_pickup_item())
1296 startitem_failed = TRUE;
1301 if(self.angles != '0 0 0')
1302 self.SendFlags |= ISF_ANGLES;
1304 self.reset = Item_Reset;
1305 // it's a level item
1306 if(self.spawnflags & 1)
1309 self.movetype = MOVETYPE_NONE;
1311 self.movetype = MOVETYPE_TOSS;
1312 // do item filtering according to game mode and other things
1315 // first nudge it off the floor a little bit to avoid math errors
1316 setorigin(self, self.origin + '0 0 1');
1317 // set item size before we spawn a spawnfunc_waypoint
1318 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1319 setsize (self, '-16 -16 0', '16 16 48');
1321 setsize (self, '-16 -16 0', '16 16 32');
1322 // note droptofloor returns FALSE if stuck/or would fall too far
1324 waypoint_spawnforitem(self);
1328 * can't do it that way, as it would break maps
1329 * TODO make a target_give like entity another way, that perhaps has
1330 * the weapon name in a key
1333 // target_give not yet supported; maybe later
1334 print("removed targeted ", self.classname, "\n");
1335 startitem_failed = TRUE;
1341 if(autocvar_spawn_debug >= 2)
1344 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
1346 // why not flags & fl_item?
1347 if(otheritem.is_item)
1349 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
1350 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1351 error("Mapper sucks.");
1354 self.is_item = TRUE;
1357 WEPSET_OR_AW(weaponsInMap, weaponid);
1359 precache_model (self.model);
1360 precache_sound (self.item_pickupsound);
1362 precache_sound ("misc/itemrespawncountdown.wav");
1363 if(!g_minstagib && itemid == IT_STRENGTH)
1364 precache_sound ("misc/strength_respawn.wav");
1365 else if(!g_minstagib && itemid == IT_INVINCIBLE)
1366 precache_sound ("misc/shield_respawn.wav");
1368 precache_sound ("misc/itemrespawn.wav");
1370 if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
1371 self.target = "###item###"; // for finding the nearest item using find()
1373 Item_ItemsTime_UpdateTime(self, 0);
1376 self.bot_pickup = TRUE;
1377 self.bot_pickupevalfunc = pickupevalfunc;
1378 self.bot_pickupbasevalue = pickupbasevalue;
1379 self.mdl = self.model;
1380 self.netname = itemname;
1381 self.touch = Item_Touch;
1382 setmodel(self, "null"); // precision set below
1383 //self.effects |= EF_LOWPRECISION;
1385 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1387 self.pos1 = '-16 -16 0';
1388 self.pos2 = '16 16 48';
1392 self.pos1 = '-16 -16 0';
1393 self.pos2 = '16 16 32';
1395 setsize (self, self.pos1, self.pos2);
1397 if(itemflags & FL_POWERUP)
1398 self.ItemStatus |= ITS_ANIMATE1;
1400 if(self.armorvalue || self.health)
1401 self.ItemStatus |= ITS_ANIMATE2;
1403 if(itemflags & FL_WEAPON)
1405 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1406 self.colormap = 1024; // color shirt=0 pants=0 grey
1410 self.ItemStatus |= ITS_ANIMATE1;
1411 self.ItemStatus |= ISF_COLORMAP;
1415 if(self.team) // broken, no idea why.
1418 self.cnt = 1; // item probability weight
1420 self.effects |= EF_NODRAW; // marker for item team search
1421 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
1426 Net_LinkEntity(self, FALSE, 0, ItemSend);
1428 // call this hook after everything else has been done
1429 if(MUTATOR_CALLHOOK(Item_Spawn))
1431 startitem_failed = TRUE;
1437 /* replace items in minstagib
1438 * IT_STRENGTH = invisibility
1439 * IT_NAILS = extra lives
1440 * IT_INVINCIBLE = speed
1442 void minstagib_items (float itemid) // will be deleted soon.
1445 self.classname = "minstagib"; // ...?
1447 // replace rocket launchers and nex guns with ammo cells
1448 if (itemid == IT_CELLS)
1450 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1451 StartItem ("models/items/a_cells.md3",
1452 "misc/itempickup.wav", 45, 0,
1453 "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
1460 itemid = IT_STRENGTH;
1464 itemid = IT_INVINCIBLE;
1466 // replace with invis
1467 if (itemid == IT_STRENGTH)
1469 if(!self.strength_finished)
1470 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1471 StartItem ("models/items/g_strength.md3",
1472 "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1473 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1475 // replace with extra lives
1476 if (itemid == IT_NAILS)
1478 self.max_health = 1;
1479 StartItem ("models/items/g_h100.md3",
1480 "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1481 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1483 // replace with speed
1484 if (itemid == IT_INVINCIBLE)
1486 if(!self.invincible_finished)
1487 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1488 StartItem ("models/items/g_invincible.md3",
1489 "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1490 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1494 float minst_no_auto_cells;
1495 void minst_remove_item (void) {
1496 if(minst_no_auto_cells)
1500 float weaponswapping;
1503 void weapon_defaultspawnfunc(float wpn)
1507 var .float ammofield;
1513 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
1515 e = get_weaponinfo(wpn);
1517 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
1519 print("Attempted to spawn a mutator-blocked weapon; these guns will in the future require a mutator\n");
1521 objerror("Attempted to spawn a mutator-blocked weapon rejected");
1522 startitem_failed = TRUE;
1527 s = W_Apply_Weaponreplace(e.netname);
1530 MUTATOR_CALLHOOK(SetWeaponreplace);
1535 startitem_failed = TRUE;
1538 t = tokenize_console(s);
1541 self.team = --internalteam;
1543 for(i = 1; i < t; ++i)
1546 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1548 e = get_weaponinfo(j);
1552 copyentity(oldself, self);
1553 self.classname = "replacedweapon";
1554 weapon_defaultspawnfunc(j);
1560 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1565 if(t >= 1) // always the case!
1569 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1571 e = get_weaponinfo(j);
1580 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1586 startitem_failed = TRUE;
1591 e = get_weaponinfo(wpn);
1593 if(!self.respawntime)
1595 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1597 self.respawntime = g_pickup_respawntime_superweapon;
1598 self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
1602 self.respawntime = g_pickup_respawntime_weapon;
1603 self.respawntimejitter = g_pickup_respawntimejitter_weapon;
1607 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1608 if(!self.superweapons_finished)
1609 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1613 for(i = 0, j = 1; i < 24; ++i, j *= 2)
1617 ammofield = Item_CounterField(j);
1619 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
1625 if(g_pickup_weapons_anyway)
1626 self.pickup_anyway = TRUE;
1630 // no weapon-stay on superweapons
1631 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1632 f |= FL_NO_WEAPON_STAY;
1634 // weapon stay isn't supported for teamed weapons
1636 f |= FL_NO_WEAPON_STAY;
1638 // stupid minstagib hack, don't ask
1641 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1643 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
1644 if (self.modelindex) // don't precache if self was removed
1645 weapon_action(e.weapon, WR_PRECACHE);
1648 void spawnfunc_weapon_shotgun (void);
1649 void spawnfunc_weapon_uzi (void) {
1650 if(autocvar_sv_q3acompat_machineshotgunswap)
1651 if(self.classname != "droppedweapon")
1653 weapon_defaultspawnfunc(WEP_SHOTGUN);
1656 weapon_defaultspawnfunc(WEP_UZI);
1659 void spawnfunc_weapon_shotgun (void) {
1660 if(autocvar_sv_q3acompat_machineshotgunswap)
1661 if(self.classname != "droppedweapon")
1663 weapon_defaultspawnfunc(WEP_UZI);
1666 weapon_defaultspawnfunc(WEP_SHOTGUN);
1669 void spawnfunc_weapon_nex (void)
1673 minstagib_items(IT_CELLS);
1674 self.think = minst_remove_item;
1675 self.nextthink = time;
1678 weapon_defaultspawnfunc(WEP_NEX);
1681 void spawnfunc_weapon_minstanex (void)
1685 minstagib_items(IT_CELLS);
1686 self.think = minst_remove_item;
1687 self.nextthink = time;
1690 weapon_defaultspawnfunc(WEP_MINSTANEX);
1693 void spawnfunc_weapon_rocketlauncher (void)
1697 minstagib_items(IT_CELLS); // replace rocketlauncher with cells
1698 self.think = minst_remove_item;
1699 self.nextthink = time;
1702 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
1705 void spawnfunc_item_rockets (void) {
1706 if(!self.ammo_rockets)
1707 self.ammo_rockets = g_pickup_rockets;
1708 if(!self.pickup_anyway)
1709 self.pickup_anyway = g_pickup_ammo_anyway;
1710 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);
1713 void spawnfunc_item_shells (void);
1714 void spawnfunc_item_bullets (void) {
1716 if(autocvar_sv_q3acompat_machineshotgunswap)
1717 if(self.classname != "droppedweapon")
1719 weaponswapping = TRUE;
1720 spawnfunc_item_shells();
1721 weaponswapping = FALSE;
1725 if(!self.ammo_nails)
1726 self.ammo_nails = g_pickup_nails;
1727 if(!self.pickup_anyway)
1728 self.pickup_anyway = g_pickup_ammo_anyway;
1729 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);
1732 void spawnfunc_item_cells (void) {
1733 if(!self.ammo_cells)
1734 self.ammo_cells = g_pickup_cells;
1735 if(!self.pickup_anyway)
1736 self.pickup_anyway = g_pickup_ammo_anyway;
1737 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);
1740 void spawnfunc_item_shells (void) {
1742 if(autocvar_sv_q3acompat_machineshotgunswap)
1743 if(self.classname != "droppedweapon")
1745 weaponswapping = TRUE;
1746 spawnfunc_item_bullets();
1747 weaponswapping = FALSE;
1751 if(!self.ammo_shells)
1752 self.ammo_shells = g_pickup_shells;
1753 if(!self.pickup_anyway)
1754 self.pickup_anyway = g_pickup_ammo_anyway;
1755 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);
1758 void spawnfunc_item_armor_small (void) {
1759 if(!self.armorvalue)
1760 self.armorvalue = g_pickup_armorsmall;
1761 if(!self.max_armorvalue)
1762 self.max_armorvalue = g_pickup_armorsmall_max;
1763 if(!self.pickup_anyway)
1764 self.pickup_anyway = g_pickup_armorsmall_anyway;
1765 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);
1768 void spawnfunc_item_armor_medium (void) {
1769 if(!self.armorvalue)
1770 self.armorvalue = g_pickup_armormedium;
1771 if(!self.max_armorvalue)
1772 self.max_armorvalue = g_pickup_armormedium_max;
1773 if(!self.pickup_anyway)
1774 self.pickup_anyway = g_pickup_armormedium_anyway;
1775 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);
1778 void spawnfunc_item_armor_big (void) {
1779 if(!self.armorvalue)
1780 self.armorvalue = g_pickup_armorbig;
1781 if(!self.max_armorvalue)
1782 self.max_armorvalue = g_pickup_armorbig_max;
1783 if(!self.pickup_anyway)
1784 self.pickup_anyway = g_pickup_armorbig_anyway;
1785 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);
1788 void spawnfunc_item_armor_large (void) {
1789 if(!self.armorvalue)
1790 self.armorvalue = g_pickup_armorlarge;
1791 if(!self.max_armorvalue)
1792 self.max_armorvalue = g_pickup_armorlarge_max;
1793 if(!self.pickup_anyway)
1794 self.pickup_anyway = g_pickup_armorlarge_anyway;
1795 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);
1798 void spawnfunc_item_health_small (void) {
1799 if(!self.max_health)
1800 self.max_health = g_pickup_healthsmall_max;
1802 self.health = g_pickup_healthsmall;
1803 if(!self.pickup_anyway)
1804 self.pickup_anyway = g_pickup_healthsmall_anyway;
1805 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);
1808 void spawnfunc_item_health_medium (void) {
1809 if(!self.max_health)
1810 self.max_health = g_pickup_healthmedium_max;
1812 self.health = g_pickup_healthmedium;
1813 if(!self.pickup_anyway)
1814 self.pickup_anyway = g_pickup_healthmedium_anyway;
1815 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);
1818 void spawnfunc_item_health_large (void) {
1819 if(!self.max_health)
1820 self.max_health = g_pickup_healthlarge_max;
1822 self.health = g_pickup_healthlarge;
1823 if(!self.pickup_anyway)
1824 self.pickup_anyway = g_pickup_healthlarge_anyway;
1825 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);
1828 void spawnfunc_item_health_mega (void) {
1830 minstagib_items(IT_NAILS);
1832 if(!self.max_health)
1833 self.max_health = g_pickup_healthmega_max;
1835 self.health = g_pickup_healthmega;
1836 if(!self.pickup_anyway)
1837 self.pickup_anyway = g_pickup_healthmega_anyway;
1838 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);
1842 // support old misnamed entities
1843 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1844 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1845 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1846 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1847 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1849 void spawnfunc_item_strength (void) {
1851 minstagib_items(IT_STRENGTH);
1853 precache_sound("weapons/strength_fire.wav");
1854 if(!self.strength_finished)
1855 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1856 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);
1860 void spawnfunc_item_invincible (void) {
1862 minstagib_items(IT_INVINCIBLE);
1864 if(!self.invincible_finished)
1865 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1866 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);
1870 void spawnfunc_item_minst_cells (void) {
1873 minst_no_auto_cells = TRUE;
1874 minstagib_items(IT_CELLS);
1881 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1883 float GiveItems(entity e, float beginarg, float endarg);
1884 void target_items_use (void)
1886 if(activator.classname == "droppedweapon")
1893 if(activator.classname != "player")
1895 if(activator.deadflag != DEAD_NO)
1900 for(e = world; (e = find(e, classname, "droppedweapon")); )
1901 if(e.enemy == activator)
1904 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1905 centerprint(activator, self.message);
1908 void spawnfunc_target_items (void)
1913 self.use = target_items_use;
1914 if(!self.strength_finished)
1915 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1916 if(!self.invincible_finished)
1917 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1918 if(!self.superweapons_finished)
1919 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1921 precache_sound("misc/itempickup.wav");
1922 precache_sound("misc/megahealth.wav");
1923 precache_sound("misc/armor25.wav");
1924 precache_sound("misc/powerup.wav");
1925 precache_sound("misc/poweroff.wav");
1926 precache_sound("weapons/weaponpickup.wav");
1928 n = tokenize_console(self.netname);
1929 if(argv(0) == "give")
1931 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1935 for(i = 0; i < n; ++i)
1937 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1938 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1939 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1940 else if(argv(i) == "strength") self.items |= IT_STRENGTH;
1941 else if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1942 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1943 else if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1944 else if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1947 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1949 e = get_weaponinfo(j);
1950 if(argv(i) == e.netname)
1952 WEPSET_OR_EW(self, j);
1953 if(self.spawnflags == 0 || self.spawnflags == 2)
1954 weapon_action(e.weapon, WR_PRECACHE);
1959 print("target_items: invalid item ", argv(i), "\n");
1963 string itemprefix, valueprefix;
1964 if(self.spawnflags == 0)
1969 else if(self.spawnflags == 1)
1971 itemprefix = "max ";
1972 valueprefix = "max ";
1974 else if(self.spawnflags == 2)
1976 itemprefix = "min ";
1977 valueprefix = "min ";
1979 else if(self.spawnflags == 4)
1981 itemprefix = "minus ";
1982 valueprefix = "max ";
1986 error("invalid spawnflags");
1988 itemprefix = string_null;
1989 valueprefix = string_null;
1994 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1995 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1996 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * !!(self.items & IT_STRENGTH), "strength");
1997 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * !!(self.items & IT_INVINCIBLE), "invincible");
1998 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * !!(self.items & IT_SUPERWEAPON), "superweapons");
1999 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_JETPACK), "jetpack");
2000 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_FUEL_REGEN), "fuel_regen");
2001 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
2002 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
2003 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
2004 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
2005 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
2006 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
2007 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
2008 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2010 e = get_weaponinfo(j);
2012 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, WEPSET_CONTAINS_EW(self, j), e.netname);
2015 self.netname = strzone(self.netname);
2016 //print(self.netname, "\n");
2018 n = tokenize_console(self.netname);
2019 for(i = 0; i < n; ++i)
2021 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2023 e = get_weaponinfo(j);
2024 if(argv(i) == e.netname)
2026 weapon_action(e.weapon, WR_PRECACHE);
2033 void spawnfunc_item_fuel(void)
2036 self.ammo_fuel = g_pickup_fuel;
2037 if(!self.pickup_anyway)
2038 self.pickup_anyway = g_pickup_ammo_anyway;
2039 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);
2042 void spawnfunc_item_fuel_regen(void)
2044 if(start_items & IT_FUEL_REGEN)
2046 spawnfunc_item_fuel();
2049 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);
2052 void spawnfunc_item_jetpack(void)
2054 if(g_grappling_hook)
2055 return; // sorry, but these two can't coexist (same button); spawn fuel instead
2057 self.ammo_fuel = g_pickup_fuel_jetpack;
2058 if(start_items & IT_JETPACK)
2060 spawnfunc_item_fuel();
2063 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);
2073 float GiveWeapon(entity e, float wpn, float op, float val)
2076 v0 = WEPSET_CONTAINS_EW(e, wpn);
2081 WEPSET_OR_EW(e, wpn);
2083 WEPSET_ANDNOT_EW(e, wpn);
2088 WEPSET_OR_EW(e, wpn);
2092 WEPSET_ANDNOT_EW(e, wpn);
2096 WEPSET_ANDNOT_EW(e, wpn);
2099 v1 = WEPSET_CONTAINS_EW(e, wpn);
2103 float GiveBit(entity e, .float fld, float bit, float op, float val)
2133 float GiveValue(entity e, .float fld, float op, float val)
2143 e.fld = max(e.fld, val); // min 100 cells = at least 100 cells
2146 e.fld = min(e.fld, val);
2159 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
2166 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTN_NORM);
2168 else if(v0 >= v0 + t)
2171 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTN_NORM);
2175 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
2178 e.rotfield = max(e.rotfield, time + rottime);
2180 e.regenfield = max(e.regenfield, time + regentime);
2183 #define PREGIVE_WEAPONS(e) WEPSET_DECLARE_A(save_weapons); WEPSET_COPY_AE(save_weapons, e)
2184 #define PREGIVE(e,f) float save_##f; save_##f = (e).f
2185 #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)
2186 #define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr)
2187 #define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
2188 #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)
2190 float GiveItems(entity e, float beginarg, float endarg)
2192 float got, i, j, val, op;
2193 float _switchweapon;
2202 _switchweapon = FALSE;
2204 if (e.switchweapon == w_getbestweapon(e))
2205 _switchweapon = TRUE;
2207 e.strength_finished = max(0, e.strength_finished - time);
2208 e.invincible_finished = max(0, e.invincible_finished - time);
2209 e.superweapons_finished = max(0, e.superweapons_finished - time);
2213 PREGIVE(e, strength_finished);
2214 PREGIVE(e, invincible_finished);
2215 PREGIVE(e, superweapons_finished);
2216 PREGIVE(e, ammo_nails);
2217 PREGIVE(e, ammo_cells);
2218 PREGIVE(e, ammo_shells);
2219 PREGIVE(e, ammo_rockets);
2220 PREGIVE(e, ammo_fuel);
2221 PREGIVE(e, armorvalue);
2224 for(i = beginarg; i < endarg; ++i)
2228 if(cmd == "0" || stof(cmd))
2252 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
2253 got += GiveValue(e, strength_finished, op, val);
2254 got += GiveValue(e, invincible_finished, op, val);
2255 got += GiveValue(e, superweapons_finished, op, val);
2256 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
2258 got += GiveBit(e, items, IT_JETPACK, op, val);
2259 got += GiveValue(e, health, op, val);
2260 got += GiveValue(e, armorvalue, op, val);
2262 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2264 wi = get_weaponinfo(j);
2266 if not(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED)
2267 got += GiveWeapon(e, j, op, val);
2270 got += GiveValue(e, ammo_cells, op, val);
2271 got += GiveValue(e, ammo_shells, op, val);
2272 got += GiveValue(e, ammo_nails, op, val);
2273 got += GiveValue(e, ammo_rockets, op, val);
2274 got += GiveValue(e, ammo_fuel, op, val);
2276 case "unlimited_ammo":
2277 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
2279 case "unlimited_weapon_ammo":
2280 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
2282 case "unlimited_superweapons":
2283 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
2286 got += GiveBit(e, items, IT_JETPACK, op, val);
2289 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
2292 got += GiveValue(e, strength_finished, op, val);
2295 got += GiveValue(e, invincible_finished, op, val);
2297 case "superweapons":
2298 got += GiveValue(e, superweapons_finished, op, val);
2301 got += GiveValue(e, ammo_cells, op, val);
2304 got += GiveValue(e, ammo_shells, op, val);
2308 got += GiveValue(e, ammo_nails, op, val);
2311 got += GiveValue(e, ammo_rockets, op, val);
2314 got += GiveValue(e, health, op, val);
2317 got += GiveValue(e, armorvalue, op, val);
2320 got += GiveValue(e, ammo_fuel, op, val);
2323 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2325 wi = get_weaponinfo(j);
2326 if(cmd == wi.netname)
2328 got += GiveWeapon(e, j, op, val);
2333 print("give: invalid item ", cmd, "\n");
2340 POSTGIVE_BIT(e, items, IT_FUEL_REGEN, "misc/itempickup.wav", string_null);
2341 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
2342 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
2343 POSTGIVE_BIT(e, items, IT_JETPACK, "misc/itempickup.wav", string_null);
2344 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2346 wi = get_weaponinfo(j);
2349 POSTGIVE_WEAPON(e, j, "weapons/weaponpickup.wav", string_null);
2350 if not(WEPSET_CONTAINS_AW(save_weapons, j))
2351 if(WEPSET_CONTAINS_EW(e, j))
2352 weapon_action(wi.weapon, WR_PRECACHE);
2355 POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
2356 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
2357 POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
2358 POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
2359 POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
2360 POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
2361 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);
2362 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);
2363 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);
2365 if(e.superweapons_finished <= 0)
2366 if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
2367 e.superweapons_finished = autocvar_g_balance_superweapons_time;
2371 e.health = bound(0, e.health, 100);
2372 e.armorvalue = bound(0, e.armorvalue, 999);
2375 if(e.strength_finished <= 0)
2376 e.strength_finished = 0;
2378 e.strength_finished += time;
2379 if(e.invincible_finished <= 0)
2380 e.invincible_finished = 0;
2382 e.invincible_finished += time;
2383 if(e.superweapons_finished <= 0)
2384 e.superweapons_finished = 0;
2386 e.superweapons_finished += time;
2388 if not(WEPSET_CONTAINS_EW(e, e.switchweapon))
2389 _switchweapon = TRUE;
2391 W_SwitchWeapon_Force(e, w_getbestweapon(e));