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)
598 if(!g_minstagib && self.items == IT_STRENGTH)
599 sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
600 else if(!g_minstagib && self.items == IT_INVINCIBLE)
601 sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
603 sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
604 setorigin (self, self.origin);
606 if(self.flags & FL_POWERUP || self.classname == "item_armor_large" || self.items == IT_HEALTH || WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
608 Item_ItemsTime_UpdateTime(self, 0);
609 Item_ItemsTime_GetForAll();
612 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
613 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
616 void Item_RespawnCountdown (void)
618 if(self.count >= ITEM_RESPAWN_TICKS)
620 if(self.waypointsprite_attached)
621 WaypointSprite_Kill(self.waypointsprite_attached);
626 self.nextthink = time + 1;
631 vector rgb = '1 0 1';
637 case IT_STRENGTH: name = "item-invis"; rgb = '0 0 1'; break;
638 case IT_NAILS: name = "item-extralife"; rgb = '1 0 0'; break;
639 case IT_INVINCIBLE: name = "item-speed"; rgb = '1 0 1'; break;
646 case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
647 case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
649 //if (self.classname == "item_health_mega")
650 {name = "item_health_mega"; rgb = '1 0 0';}
653 if (self.classname == "item_armor_large")
654 {name = "item_armor_large"; rgb = '0 1 0';}
660 case IT_FUEL_REGEN: name = "item-fuelregen"; rgb = '1 0.5 0'; break;
661 case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
663 if(self.flags & FL_WEAPON)
665 entity wi = get_weaponinfo(self.weapon);
674 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
675 if(self.waypointsprite_attached)
677 if (self.items == IT_HEALTH || self.items == IT_ARMOR)
678 WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
679 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
684 print("Unknown powerup-marked item is wanting to respawn\n");
685 localcmd(sprintf("prvm_edict server %d\n", num_for_edict(self)));
688 sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTN_NORM); // play respawn sound
689 if(self.waypointsprite_attached)
691 WaypointSprite_Ping(self.waypointsprite_attached);
692 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
697 void Item_ScheduleRespawnIn(entity e, float t)
699 if((e.flags & FL_POWERUP) || WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS) || e.classname == "item_armor_large" || e.items == IT_HEALTH)
702 e.think = Item_RespawnCountdown;
703 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
704 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
706 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
708 for(t = e.scheduledrespawntime, head = world; (head = nextent(head)); )
712 if(clienttype(head) == CLIENTTYPE_NOTACLIENT)
713 if(WEPSET_CONTAINS_ANY_EA(head, WEPBIT_SUPERWEAPONS))
714 if(head.classname != "weapon_info")
716 if(head.scheduledrespawntime <= time)
721 if(head.scheduledrespawntime < t)
722 t = head.scheduledrespawntime;
728 for(t = e.scheduledrespawntime, head = world; (head = find(head, classname, e.classname)); )
730 // in minstagib .classname is "minstagib" for every item
731 if(e == head || (g_minstagib && e.items != head.items))
733 if(head.scheduledrespawntime <= time)
738 if(head.scheduledrespawntime < t)
739 t = head.scheduledrespawntime;
742 Item_ItemsTime_UpdateTime(e, t);
743 Item_ItemsTime_GetForAll();
747 e.think = Item_Respawn;
748 e.nextthink = time + t;
749 e.scheduledrespawntime = e.nextthink;
753 void Item_ScheduleRespawn(entity e)
755 if(e.respawntime > 0)
758 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
760 else // if respawntime is -1, this item does not respawn
764 void Item_ScheduleInitialRespawn(entity e)
767 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
770 float ITEM_MODE_NONE = 0;
771 float ITEM_MODE_HEALTH = 1;
772 float ITEM_MODE_ARMOR = 2;
773 float ITEM_MODE_FUEL = 3;
774 float Item_GiveAmmoTo(entity item, entity player, .float ammofield, float ammomax, float mode)
779 if (item.spawnshieldtime)
781 if ((player.ammofield < ammomax) || item.pickup_anyway)
783 player.ammofield = bound(player.ammofield, ammomax, player.ammofield + item.ammofield);
787 else if(g_weapon_stay == 2)
789 float mi = min(item.ammofield, ammomax);
790 if (player.ammofield < mi)
792 player.ammofield = mi;
803 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
805 case ITEM_MODE_HEALTH:
806 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
808 case ITEM_MODE_ARMOR:
809 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
817 float Item_GiveTo(entity item, entity player)
824 // if nothing happens to player, just return without taking the item
826 _switchweapon = FALSE;
830 float prevcells = player.ammo_cells;
832 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
833 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, 999, ITEM_MODE_NONE);
835 if(player.ammo_cells > prevcells)
837 _switchweapon = TRUE;
839 // play some cool sounds ;)
840 if (clienttype(player) == CLIENTTYPE_REAL)
842 if(player.health <= 5)
843 AnnounceTo(player, "lastsecond");
844 else if(player.health < 50)
845 AnnounceTo(player, "narrowly");
847 // sound not available
848 // else if(item.items == IT_CELLS)
849 // AnnounceTo(player, "ammo");
851 if (WEPSET_CONTAINS_EW(item, WEP_MINSTANEX))
852 W_GiveWeapon (player, WEP_MINSTANEX);
856 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
860 sprint (player, strcat("You got the ^2", item.netname, "\n"));
867 // sound not available
868 // AnnounceTo(player, "_lives");
869 player.armorvalue = bound(player.armorvalue, 999, player.armorvalue + autocvar_g_minstagib_extralives);
870 sprint(player, "^3You picked up some extra lives\n");
874 if (item.strength_finished)
877 // sound not available
878 // AnnounceTo(player, "invisible");
879 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
883 if (item.invincible_finished)
886 // sound not available
887 // AnnounceTo(player, "speed");
888 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_invincible_time;
893 // in case the player has autoswitch enabled do the following:
894 // if the player is using their best weapon before items are given, they
895 // probably want to switch to an even better weapon after items are given
896 if (player.autoswitch)
897 if (player.switchweapon == w_getbestweapon(player))
898 _switchweapon = TRUE;
900 if not(WEPSET_CONTAINS_EW(player, player.switchweapon))
901 _switchweapon = TRUE;
903 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
904 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
905 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
906 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
907 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
908 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
909 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
911 if (item.flags & FL_WEAPON)
913 WEPSET_DECLARE_A(it);
914 WEPSET_COPY_AE(it, item);
915 WEPSET_ANDNOT_AE(it, player);
917 if (!WEPSET_EMPTY_A(it) || (item.spawnshieldtime && self.pickup_anyway))
920 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
921 if(WEPSET_CONTAINS_AW(it, i))
922 W_GiveWeapon(player, i);
926 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
930 sprint (player, strcat("You got the ^2", item.netname, "\n"));
933 if (item.strength_finished)
936 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
938 if (item.invincible_finished)
941 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
943 if (item.superweapons_finished)
946 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
951 // always eat teamed entities
959 if (player.switchweapon != w_getbestweapon(player))
960 W_SwitchWeapon_Force(player, w_getbestweapon(player));
965 void Item_Touch (void)
969 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
970 if(self.classname == "droppedweapon")
972 if (ITEM_TOUCH_NEEDKILL())
979 if (other.classname != "player")
983 if (self.solid != SOLID_TRIGGER)
985 if (self.owner == other)
987 if(MUTATOR_CALLHOOK(ItemTouch))
990 if (self.classname == "droppedweapon")
992 self.strength_finished = max(0, self.strength_finished - time);
993 self.invincible_finished = max(0, self.invincible_finished - time);
994 self.superweapons_finished = max(0, self.superweapons_finished - time);
997 if(!Item_GiveTo(self, other))
999 if (self.classname == "droppedweapon")
1001 // undo what we did above
1002 self.strength_finished += time;
1003 self.invincible_finished += time;
1004 self.superweapons_finished += time;
1009 other.last_pickup = time;
1011 pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
1012 sound (other, CH_TRIGGER, self.item_pickupsound, VOL_BASE, ATTN_NORM);
1014 if (self.classname == "droppedweapon")
1016 else if not(self.spawnshieldtime)
1022 RandomSelection_Init();
1023 for(head = world; (head = findfloat(head, team, self.team)); )
1025 if(head.flags & FL_ITEM)
1027 Item_Show(head, -1);
1028 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
1031 e = RandomSelection_chosen_ent;
1036 Item_ScheduleRespawn(e);
1042 Item_Show(self, !self.state);
1043 setorigin (self, self.origin);
1045 if(self.classname != "droppedweapon")
1047 self.think = func_null;
1050 if(self.waypointsprite_attached)
1051 WaypointSprite_Kill(self.waypointsprite_attached);
1053 if((self.flags & FL_POWERUP) | WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS)) // do not spawn powerups initially!
1054 Item_ScheduleInitialRespawn(self);
1058 void Item_FindTeam()
1062 if(self.effects & EF_NODRAW)
1064 // marker for item team search
1065 dprint("Initializing item team ", ftos(self.team), "\n");
1066 RandomSelection_Init();
1067 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
1068 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
1069 e = RandomSelection_chosen_ent;
1073 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
1077 // make it a non-spawned item
1078 Item_Show(head, -1);
1079 head.state = 1; // state 1 = initially hidden item
1081 head.effects &~= EF_NODRAW;
1088 // Savage: used for item garbage-collection
1089 // TODO: perhaps nice special effect?
1090 void RemoveItem(void)
1095 // pickup evaluation functions
1096 // these functions decide how desirable an item is to the bots
1098 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
1100 float weapon_pickupevalfunc(entity player, entity item)
1102 float c, j, position;
1104 // See if I have it already
1105 if(!WEPSET_CONTAINS_ALL_EE(player, item))
1107 // If I can pick it up
1108 if(!item.spawnshieldtime)
1110 else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
1112 // Skilled bots will grab more
1113 c = bound(0, skill / 10, 1) * 0.5;
1121 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
1122 if( bot_custom_weapon && c )
1124 // Find the highest position on any range
1126 for(j = 0; j < WEP_LAST ; ++j){
1128 bot_weapons_far[j] == item.weapon ||
1129 bot_weapons_mid[j] == item.weapon ||
1130 bot_weapons_close[j] == item.weapon
1141 position = WEP_LAST - position;
1142 // item.bot_pickupbasevalue is overwritten here
1143 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
1147 return item.bot_pickupbasevalue * c;
1150 float commodity_pickupevalfunc(entity player, entity item)
1153 float need_shells = FALSE, need_nails = FALSE, need_rockets = FALSE, need_cells = FALSE, need_fuel = FALSE;
1157 // Detect needed ammo
1158 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
1160 wi = get_weaponinfo(i);
1162 if not(WEPSET_CONTAINS_EW(player, i))
1165 if(wi.items & IT_SHELLS)
1167 else if(wi.items & IT_NAILS)
1169 else if(wi.items & IT_ROCKETS)
1170 need_rockets = TRUE;
1171 else if(wi.items & IT_CELLS)
1173 else if(wi.items & IT_FUEL)
1177 // TODO: figure out if the player even has the weapon this ammo is for?
1178 // may not affect strategy much though...
1179 // find out how much more ammo/armor/health the player can hold
1181 if (item.ammo_shells)
1182 if (player.ammo_shells < g_pickup_shells_max)
1183 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
1185 if (item.ammo_nails)
1186 if (player.ammo_nails < g_pickup_nails_max)
1187 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
1189 if (item.ammo_rockets)
1190 if (player.ammo_rockets < g_pickup_rockets_max)
1191 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
1193 if (item.ammo_cells)
1194 if (player.ammo_cells < g_pickup_cells_max)
1195 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
1198 if (player.ammo_fuel < g_pickup_fuel_max)
1199 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
1200 if (item.armorvalue)
1201 if (player.armorvalue < item.max_armorvalue)
1202 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
1204 if (player.health < item.max_health)
1205 c = c + max(0, 1 - player.health / item.max_health);
1207 return item.bot_pickupbasevalue * c;
1210 void Item_Damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
1212 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1217 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)
1219 startitem_failed = FALSE;
1221 if(self.model == "")
1222 self.model = itemmodel;
1224 if(self.model == "")
1226 error(strcat("^1Tried to spawn ", itemname, " with no model!\n"));
1230 if(self.item_pickupsound == "")
1231 self.item_pickupsound = pickupsound;
1233 if(!self.respawntime) // both need to be set
1235 self.respawntime = defaultrespawntime;
1236 self.respawntimejitter = defaultrespawntimejitter;
1239 self.items = itemid;
1240 self.weapon = weaponid;
1243 WEPSET_COPY_EW(self, weaponid);
1245 self.flags = FL_ITEM | itemflags;
1247 if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
1249 startitem_failed = TRUE;
1254 // is it a dropped weapon?
1255 if (self.classname == "droppedweapon")
1257 self.reset = SUB_Remove;
1258 // it's a dropped weapon
1259 self.movetype = MOVETYPE_TOSS;
1261 // Savage: remove thrown items after a certain period of time ("garbage collection")
1262 self.think = RemoveItem;
1263 self.nextthink = time + 20;
1265 self.takedamage = DAMAGE_YES;
1266 self.event_damage = Item_Damage;
1268 if(self.strength_finished || self.invincible_finished || self.superweapons_finished)
1271 if(WEPSET_CONTAINS_ALL_AE(WEPBIT_SUPERWEAPONS, self)) // only superweapons
1272 if(self.ammo_nails == 0)
1273 if(self.ammo_cells == 0)
1274 if(self.ammo_rockets == 0)
1275 if(self.ammo_shells == 0)
1276 if(self.ammo_fuel == 0)
1277 if(self.health == 0)
1278 if(self.armorvalue == 0)
1281 // if item is worthless after a timer, have it expire then
1282 self.nextthink = max(self.strength_finished, self.invincible_finished, self.superweapons_finished);
1285 // don't drop if in a NODROP zone (such as lava)
1286 traceline(self.origin, self.origin, MOVE_NORMAL, self);
1287 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1289 startitem_failed = TRUE;
1296 if(!have_pickup_item())
1298 startitem_failed = TRUE;
1303 if(self.angles != '0 0 0')
1304 self.SendFlags |= ISF_ANGLES;
1306 self.reset = Item_Reset;
1307 // it's a level item
1308 if(self.spawnflags & 1)
1311 self.movetype = MOVETYPE_NONE;
1313 self.movetype = MOVETYPE_TOSS;
1314 // do item filtering according to game mode and other things
1317 // first nudge it off the floor a little bit to avoid math errors
1318 setorigin(self, self.origin + '0 0 1');
1319 // set item size before we spawn a spawnfunc_waypoint
1320 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1321 setsize (self, '-16 -16 0', '16 16 48');
1323 setsize (self, '-16 -16 0', '16 16 32');
1324 // note droptofloor returns FALSE if stuck/or would fall too far
1326 waypoint_spawnforitem(self);
1330 * can't do it that way, as it would break maps
1331 * TODO make a target_give like entity another way, that perhaps has
1332 * the weapon name in a key
1335 // target_give not yet supported; maybe later
1336 print("removed targeted ", self.classname, "\n");
1337 startitem_failed = TRUE;
1343 if(autocvar_spawn_debug >= 2)
1346 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
1348 // why not flags & fl_item?
1349 if(otheritem.is_item)
1351 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
1352 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1353 error("Mapper sucks.");
1356 self.is_item = TRUE;
1359 WEPSET_OR_AW(weaponsInMap, weaponid);
1361 precache_model (self.model);
1362 precache_sound (self.item_pickupsound);
1364 precache_sound ("misc/itemrespawncountdown.wav");
1365 if(!g_minstagib && itemid == IT_STRENGTH)
1366 precache_sound ("misc/strength_respawn.wav");
1367 else if(!g_minstagib && itemid == IT_INVINCIBLE)
1368 precache_sound ("misc/shield_respawn.wav");
1370 precache_sound ("misc/itemrespawn.wav");
1372 if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
1373 self.target = "###item###"; // for finding the nearest item using find()
1375 Item_ItemsTime_UpdateTime(self, 0);
1378 self.bot_pickup = TRUE;
1379 self.bot_pickupevalfunc = pickupevalfunc;
1380 self.bot_pickupbasevalue = pickupbasevalue;
1381 self.mdl = self.model;
1382 self.netname = itemname;
1383 self.touch = Item_Touch;
1384 setmodel(self, "null"); // precision set below
1385 //self.effects |= EF_LOWPRECISION;
1387 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1389 self.pos1 = '-16 -16 0';
1390 self.pos2 = '16 16 48';
1394 self.pos1 = '-16 -16 0';
1395 self.pos2 = '16 16 32';
1397 setsize (self, self.pos1, self.pos2);
1399 if(itemflags & FL_POWERUP)
1400 self.ItemStatus |= ITS_ANIMATE1;
1402 if(self.armorvalue || self.health)
1403 self.ItemStatus |= ITS_ANIMATE2;
1405 if(itemflags & FL_WEAPON)
1407 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1408 self.colormap = 1024; // color shirt=0 pants=0 grey
1412 self.ItemStatus |= ITS_ANIMATE1;
1413 self.ItemStatus |= ISF_COLORMAP;
1417 if(self.team) // broken, no idea why.
1420 self.cnt = 1; // item probability weight
1422 self.effects |= EF_NODRAW; // marker for item team search
1423 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
1428 Net_LinkEntity(self, FALSE, 0, ItemSend);
1430 // call this hook after everything else has been done
1431 if(MUTATOR_CALLHOOK(Item_Spawn))
1433 startitem_failed = TRUE;
1439 /* replace items in minstagib
1440 * IT_STRENGTH = invisibility
1441 * IT_NAILS = extra lives
1442 * IT_INVINCIBLE = speed
1444 void minstagib_items (float itemid) // will be deleted soon.
1447 self.classname = "minstagib"; // ...?
1449 // replace rocket launchers and nex guns with ammo cells
1450 if (itemid == IT_CELLS)
1452 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1453 StartItem ("models/items/a_cells.md3",
1454 "misc/itempickup.wav", 45, 0,
1455 "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
1462 itemid = IT_STRENGTH;
1466 itemid = IT_INVINCIBLE;
1468 // replace with invis
1469 if (itemid == IT_STRENGTH)
1471 if(!self.strength_finished)
1472 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1473 StartItem ("models/items/g_strength.md3",
1474 "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1475 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1477 // replace with extra lives
1478 if (itemid == IT_NAILS)
1480 self.max_health = 1;
1481 StartItem ("models/items/g_h100.md3",
1482 "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1483 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1485 // replace with speed
1486 if (itemid == IT_INVINCIBLE)
1488 if(!self.invincible_finished)
1489 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1490 StartItem ("models/items/g_invincible.md3",
1491 "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1492 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1496 float minst_no_auto_cells;
1497 void minst_remove_item (void) {
1498 if(minst_no_auto_cells)
1502 float weaponswapping;
1505 void weapon_defaultspawnfunc(float wpn)
1509 var .float ammofield;
1515 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
1517 e = get_weaponinfo(wpn);
1519 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
1521 print("Attempted to spawn a mutator-blocked weapon; these guns will in the future require a mutator\n");
1523 objerror("Attempted to spawn a mutator-blocked weapon rejected");
1524 startitem_failed = TRUE;
1529 s = W_Apply_Weaponreplace(e.netname);
1532 MUTATOR_CALLHOOK(SetWeaponreplace);
1537 startitem_failed = TRUE;
1540 t = tokenize_console(s);
1543 self.team = --internalteam;
1545 for(i = 1; i < t; ++i)
1548 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1550 e = get_weaponinfo(j);
1554 copyentity(oldself, self);
1555 self.classname = "replacedweapon";
1556 weapon_defaultspawnfunc(j);
1562 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1567 if(t >= 1) // always the case!
1571 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1573 e = get_weaponinfo(j);
1582 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1588 startitem_failed = TRUE;
1593 e = get_weaponinfo(wpn);
1595 if(!self.respawntime)
1597 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1599 self.respawntime = g_pickup_respawntime_superweapon;
1600 self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
1604 self.respawntime = g_pickup_respawntime_weapon;
1605 self.respawntimejitter = g_pickup_respawntimejitter_weapon;
1609 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1610 if(!self.superweapons_finished)
1611 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1615 for(i = 0, j = 1; i < 24; ++i, j *= 2)
1619 ammofield = Item_CounterField(j);
1621 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
1627 if(g_pickup_weapons_anyway)
1628 self.pickup_anyway = TRUE;
1632 // no weapon-stay on superweapons
1633 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1634 f |= FL_NO_WEAPON_STAY;
1636 // weapon stay isn't supported for teamed weapons
1638 f |= FL_NO_WEAPON_STAY;
1640 // stupid minstagib hack, don't ask
1643 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1645 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
1646 if (self.modelindex) // don't precache if self was removed
1647 weapon_action(e.weapon, WR_PRECACHE);
1650 void spawnfunc_weapon_shotgun (void);
1651 void spawnfunc_weapon_uzi (void) {
1652 if(autocvar_sv_q3acompat_machineshotgunswap)
1653 if(self.classname != "droppedweapon")
1655 weapon_defaultspawnfunc(WEP_SHOTGUN);
1658 weapon_defaultspawnfunc(WEP_UZI);
1661 void spawnfunc_weapon_shotgun (void) {
1662 if(autocvar_sv_q3acompat_machineshotgunswap)
1663 if(self.classname != "droppedweapon")
1665 weapon_defaultspawnfunc(WEP_UZI);
1668 weapon_defaultspawnfunc(WEP_SHOTGUN);
1671 void spawnfunc_weapon_nex (void)
1675 minstagib_items(IT_CELLS);
1676 self.think = minst_remove_item;
1677 self.nextthink = time;
1680 weapon_defaultspawnfunc(WEP_NEX);
1683 void spawnfunc_weapon_minstanex (void)
1687 minstagib_items(IT_CELLS);
1688 self.think = minst_remove_item;
1689 self.nextthink = time;
1692 weapon_defaultspawnfunc(WEP_MINSTANEX);
1695 void spawnfunc_weapon_rocketlauncher (void)
1699 minstagib_items(IT_CELLS); // replace rocketlauncher with cells
1700 self.think = minst_remove_item;
1701 self.nextthink = time;
1704 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
1707 void spawnfunc_item_rockets (void) {
1708 if(!self.ammo_rockets)
1709 self.ammo_rockets = g_pickup_rockets;
1710 if(!self.pickup_anyway)
1711 self.pickup_anyway = g_pickup_ammo_anyway;
1712 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);
1715 void spawnfunc_item_shells (void);
1716 void spawnfunc_item_bullets (void) {
1718 if(autocvar_sv_q3acompat_machineshotgunswap)
1719 if(self.classname != "droppedweapon")
1721 weaponswapping = TRUE;
1722 spawnfunc_item_shells();
1723 weaponswapping = FALSE;
1727 if(!self.ammo_nails)
1728 self.ammo_nails = g_pickup_nails;
1729 if(!self.pickup_anyway)
1730 self.pickup_anyway = g_pickup_ammo_anyway;
1731 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);
1734 void spawnfunc_item_cells (void) {
1735 if(!self.ammo_cells)
1736 self.ammo_cells = g_pickup_cells;
1737 if(!self.pickup_anyway)
1738 self.pickup_anyway = g_pickup_ammo_anyway;
1739 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);
1742 void spawnfunc_item_shells (void) {
1744 if(autocvar_sv_q3acompat_machineshotgunswap)
1745 if(self.classname != "droppedweapon")
1747 weaponswapping = TRUE;
1748 spawnfunc_item_bullets();
1749 weaponswapping = FALSE;
1753 if(!self.ammo_shells)
1754 self.ammo_shells = g_pickup_shells;
1755 if(!self.pickup_anyway)
1756 self.pickup_anyway = g_pickup_ammo_anyway;
1757 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);
1760 void spawnfunc_item_armor_small (void) {
1761 if(!self.armorvalue)
1762 self.armorvalue = g_pickup_armorsmall;
1763 if(!self.max_armorvalue)
1764 self.max_armorvalue = g_pickup_armorsmall_max;
1765 if(!self.pickup_anyway)
1766 self.pickup_anyway = g_pickup_armorsmall_anyway;
1767 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);
1770 void spawnfunc_item_armor_medium (void) {
1771 if(!self.armorvalue)
1772 self.armorvalue = g_pickup_armormedium;
1773 if(!self.max_armorvalue)
1774 self.max_armorvalue = g_pickup_armormedium_max;
1775 if(!self.pickup_anyway)
1776 self.pickup_anyway = g_pickup_armormedium_anyway;
1777 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);
1780 void spawnfunc_item_armor_big (void) {
1781 if(!self.armorvalue)
1782 self.armorvalue = g_pickup_armorbig;
1783 if(!self.max_armorvalue)
1784 self.max_armorvalue = g_pickup_armorbig_max;
1785 if(!self.pickup_anyway)
1786 self.pickup_anyway = g_pickup_armorbig_anyway;
1787 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);
1790 void spawnfunc_item_armor_large (void) {
1791 if(!self.armorvalue)
1792 self.armorvalue = g_pickup_armorlarge;
1793 if(!self.max_armorvalue)
1794 self.max_armorvalue = g_pickup_armorlarge_max;
1795 if(!self.pickup_anyway)
1796 self.pickup_anyway = g_pickup_armorlarge_anyway;
1797 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);
1800 void spawnfunc_item_health_small (void) {
1801 if(!self.max_health)
1802 self.max_health = g_pickup_healthsmall_max;
1804 self.health = g_pickup_healthsmall;
1805 if(!self.pickup_anyway)
1806 self.pickup_anyway = g_pickup_healthsmall_anyway;
1807 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);
1810 void spawnfunc_item_health_medium (void) {
1811 if(!self.max_health)
1812 self.max_health = g_pickup_healthmedium_max;
1814 self.health = g_pickup_healthmedium;
1815 if(!self.pickup_anyway)
1816 self.pickup_anyway = g_pickup_healthmedium_anyway;
1817 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);
1820 void spawnfunc_item_health_large (void) {
1821 if(!self.max_health)
1822 self.max_health = g_pickup_healthlarge_max;
1824 self.health = g_pickup_healthlarge;
1825 if(!self.pickup_anyway)
1826 self.pickup_anyway = g_pickup_healthlarge_anyway;
1827 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);
1830 void spawnfunc_item_health_mega (void) {
1832 minstagib_items(IT_NAILS);
1834 if(!self.max_health)
1835 self.max_health = g_pickup_healthmega_max;
1837 self.health = g_pickup_healthmega;
1838 if(!self.pickup_anyway)
1839 self.pickup_anyway = g_pickup_healthmega_anyway;
1840 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);
1844 // support old misnamed entities
1845 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1846 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1847 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1848 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1849 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1851 void spawnfunc_item_strength (void) {
1853 minstagib_items(IT_STRENGTH);
1855 precache_sound("weapons/strength_fire.wav");
1856 if(!self.strength_finished)
1857 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1858 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);
1862 void spawnfunc_item_invincible (void) {
1864 minstagib_items(IT_INVINCIBLE);
1866 if(!self.invincible_finished)
1867 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1868 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);
1872 void spawnfunc_item_minst_cells (void) {
1875 minst_no_auto_cells = TRUE;
1876 minstagib_items(IT_CELLS);
1883 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1885 float GiveItems(entity e, float beginarg, float endarg);
1886 void target_items_use (void)
1888 if(activator.classname == "droppedweapon")
1895 if(activator.classname != "player")
1897 if(activator.deadflag != DEAD_NO)
1902 for(e = world; (e = find(e, classname, "droppedweapon")); )
1903 if(e.enemy == activator)
1906 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1907 centerprint(activator, self.message);
1910 void spawnfunc_target_items (void)
1915 self.use = target_items_use;
1916 if(!self.strength_finished)
1917 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1918 if(!self.invincible_finished)
1919 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1920 if(!self.superweapons_finished)
1921 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1923 precache_sound("misc/itempickup.wav");
1924 precache_sound("misc/megahealth.wav");
1925 precache_sound("misc/armor25.wav");
1926 precache_sound("misc/powerup.wav");
1927 precache_sound("misc/poweroff.wav");
1928 precache_sound("weapons/weaponpickup.wav");
1930 n = tokenize_console(self.netname);
1931 if(argv(0) == "give")
1933 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1937 for(i = 0; i < n; ++i)
1939 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1940 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1941 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1942 else if(argv(i) == "strength") self.items |= IT_STRENGTH;
1943 else if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1944 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1945 else if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1946 else if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1949 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1951 e = get_weaponinfo(j);
1952 if(argv(i) == e.netname)
1954 WEPSET_OR_EW(self, j);
1955 if(self.spawnflags == 0 || self.spawnflags == 2)
1956 weapon_action(e.weapon, WR_PRECACHE);
1961 print("target_items: invalid item ", argv(i), "\n");
1965 string itemprefix, valueprefix;
1966 if(self.spawnflags == 0)
1971 else if(self.spawnflags == 1)
1973 itemprefix = "max ";
1974 valueprefix = "max ";
1976 else if(self.spawnflags == 2)
1978 itemprefix = "min ";
1979 valueprefix = "min ";
1981 else if(self.spawnflags == 4)
1983 itemprefix = "minus ";
1984 valueprefix = "max ";
1988 error("invalid spawnflags");
1990 itemprefix = string_null;
1991 valueprefix = string_null;
1996 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1997 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1998 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * !!(self.items & IT_STRENGTH), "strength");
1999 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * !!(self.items & IT_INVINCIBLE), "invincible");
2000 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * !!(self.items & IT_SUPERWEAPON), "superweapons");
2001 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_JETPACK), "jetpack");
2002 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_FUEL_REGEN), "fuel_regen");
2003 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
2004 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
2005 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
2006 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
2007 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
2008 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
2009 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
2010 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2012 e = get_weaponinfo(j);
2014 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, WEPSET_CONTAINS_EW(self, j), e.netname);
2017 self.netname = strzone(self.netname);
2018 //print(self.netname, "\n");
2020 n = tokenize_console(self.netname);
2021 for(i = 0; i < n; ++i)
2023 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2025 e = get_weaponinfo(j);
2026 if(argv(i) == e.netname)
2028 weapon_action(e.weapon, WR_PRECACHE);
2035 void spawnfunc_item_fuel(void)
2038 self.ammo_fuel = g_pickup_fuel;
2039 if(!self.pickup_anyway)
2040 self.pickup_anyway = g_pickup_ammo_anyway;
2041 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);
2044 void spawnfunc_item_fuel_regen(void)
2046 if(start_items & IT_FUEL_REGEN)
2048 spawnfunc_item_fuel();
2051 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);
2054 void spawnfunc_item_jetpack(void)
2056 if(g_grappling_hook)
2057 return; // sorry, but these two can't coexist (same button); spawn fuel instead
2059 self.ammo_fuel = g_pickup_fuel_jetpack;
2060 if(start_items & IT_JETPACK)
2062 spawnfunc_item_fuel();
2065 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);
2075 float GiveWeapon(entity e, float wpn, float op, float val)
2078 v0 = WEPSET_CONTAINS_EW(e, wpn);
2083 WEPSET_OR_EW(e, wpn);
2085 WEPSET_ANDNOT_EW(e, wpn);
2090 WEPSET_OR_EW(e, wpn);
2094 WEPSET_ANDNOT_EW(e, wpn);
2098 WEPSET_ANDNOT_EW(e, wpn);
2101 v1 = WEPSET_CONTAINS_EW(e, wpn);
2105 float GiveBit(entity e, .float fld, float bit, float op, float val)
2135 float GiveValue(entity e, .float fld, float op, float val)
2145 e.fld = max(e.fld, val); // min 100 cells = at least 100 cells
2148 e.fld = min(e.fld, val);
2161 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
2168 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTN_NORM);
2170 else if(v0 >= v0 + t)
2173 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTN_NORM);
2177 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
2180 e.rotfield = max(e.rotfield, time + rottime);
2182 e.regenfield = max(e.regenfield, time + regentime);
2185 #define PREGIVE_WEAPONS(e) WEPSET_DECLARE_A(save_weapons); WEPSET_COPY_AE(save_weapons, e)
2186 #define PREGIVE(e,f) float save_##f; save_##f = (e).f
2187 #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)
2188 #define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr)
2189 #define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
2190 #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)
2192 float GiveItems(entity e, float beginarg, float endarg)
2194 float got, i, j, val, op;
2195 float _switchweapon;
2204 _switchweapon = FALSE;
2206 if (e.switchweapon == w_getbestweapon(e))
2207 _switchweapon = TRUE;
2209 e.strength_finished = max(0, e.strength_finished - time);
2210 e.invincible_finished = max(0, e.invincible_finished - time);
2211 e.superweapons_finished = max(0, e.superweapons_finished - time);
2215 PREGIVE(e, strength_finished);
2216 PREGIVE(e, invincible_finished);
2217 PREGIVE(e, superweapons_finished);
2218 PREGIVE(e, ammo_nails);
2219 PREGIVE(e, ammo_cells);
2220 PREGIVE(e, ammo_shells);
2221 PREGIVE(e, ammo_rockets);
2222 PREGIVE(e, ammo_fuel);
2223 PREGIVE(e, armorvalue);
2226 for(i = beginarg; i < endarg; ++i)
2230 if(cmd == "0" || stof(cmd))
2254 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
2255 got += GiveValue(e, strength_finished, op, val);
2256 got += GiveValue(e, invincible_finished, op, val);
2257 got += GiveValue(e, superweapons_finished, op, val);
2258 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
2260 got += GiveBit(e, items, IT_JETPACK, op, val);
2261 got += GiveValue(e, health, op, val);
2262 got += GiveValue(e, armorvalue, op, val);
2264 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2266 wi = get_weaponinfo(j);
2268 if not(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED)
2269 got += GiveWeapon(e, j, op, val);
2272 got += GiveValue(e, ammo_cells, op, val);
2273 got += GiveValue(e, ammo_shells, op, val);
2274 got += GiveValue(e, ammo_nails, op, val);
2275 got += GiveValue(e, ammo_rockets, op, val);
2276 got += GiveValue(e, ammo_fuel, op, val);
2278 case "unlimited_ammo":
2279 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
2281 case "unlimited_weapon_ammo":
2282 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
2284 case "unlimited_superweapons":
2285 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
2288 got += GiveBit(e, items, IT_JETPACK, op, val);
2291 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
2294 got += GiveValue(e, strength_finished, op, val);
2297 got += GiveValue(e, invincible_finished, op, val);
2299 case "superweapons":
2300 got += GiveValue(e, superweapons_finished, op, val);
2303 got += GiveValue(e, ammo_cells, op, val);
2306 got += GiveValue(e, ammo_shells, op, val);
2310 got += GiveValue(e, ammo_nails, op, val);
2313 got += GiveValue(e, ammo_rockets, op, val);
2316 got += GiveValue(e, health, op, val);
2319 got += GiveValue(e, armorvalue, op, val);
2322 got += GiveValue(e, ammo_fuel, op, val);
2325 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2327 wi = get_weaponinfo(j);
2328 if(cmd == wi.netname)
2330 got += GiveWeapon(e, j, op, val);
2335 print("give: invalid item ", cmd, "\n");
2342 POSTGIVE_BIT(e, items, IT_FUEL_REGEN, "misc/itempickup.wav", string_null);
2343 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
2344 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
2345 POSTGIVE_BIT(e, items, IT_JETPACK, "misc/itempickup.wav", string_null);
2346 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2348 wi = get_weaponinfo(j);
2351 POSTGIVE_WEAPON(e, j, "weapons/weaponpickup.wav", string_null);
2352 if not(WEPSET_CONTAINS_AW(save_weapons, j))
2353 if(WEPSET_CONTAINS_EW(e, j))
2354 weapon_action(wi.weapon, WR_PRECACHE);
2357 POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
2358 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
2359 POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
2360 POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
2361 POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
2362 POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
2363 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);
2364 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);
2365 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);
2367 if(e.superweapons_finished <= 0)
2368 if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
2369 e.superweapons_finished = autocvar_g_balance_superweapons_time;
2373 e.health = bound(0, e.health, 100);
2374 e.armorvalue = bound(0, e.armorvalue, 999);
2377 if(e.strength_finished <= 0)
2378 e.strength_finished = 0;
2380 e.strength_finished += time;
2381 if(e.invincible_finished <= 0)
2382 e.invincible_finished = 0;
2384 e.invincible_finished += time;
2385 if(e.superweapons_finished <= 0)
2386 e.superweapons_finished = 0;
2388 e.superweapons_finished += time;
2390 if not(WEPSET_CONTAINS_EW(e, e.switchweapon))
2391 _switchweapon = TRUE;
2393 W_SwitchWeapon_Force(e, w_getbestweapon(e));