7 #define ITS_AVAILABLE 8
10 #define ITS_POWERUP 64
11 #define ISF_COLORMAP 16
18 var float autocvar_cl_ghost_items = 1;
19 var vector autocvar_cl_ghost_items_color = '-1 -1 -1';
20 float autocvar_cl_fullbright_items;
21 vector autocvar_cl_staywep_color;
22 float autocvar_cl_staywep_alpha;
23 float autocvar_cl_simple_items;
24 float cl_simple_items;
25 float cl_ghost_items_alpha;
32 if(self.ItemStatus & ITS_ANIMATE1)
34 self.angles += '0 180 0' * frametime;
35 setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));
38 if(self.ItemStatus & ITS_ANIMATE2)
40 self.angles += '0 -90 0' * frametime;
41 setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));
45 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
51 Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
54 float csqcitems_started; // remove this after a release or two
55 void csqcitems_start()
57 if(autocvar_cl_ghost_items == 1)
58 cl_ghost_items_alpha = 0.55;
60 cl_ghost_items_alpha = bound(0, autocvar_cl_ghost_items, 1);
62 csqcitems_started = TRUE;
65 void ItemRead(float _IsNew)
67 if(!csqcitems_started)
70 float sf = ReadByte();
74 self.origin_x = ReadCoord();
75 self.origin_y = ReadCoord();
76 self.origin_z = ReadCoord();
77 setorigin(self, self.origin);
78 self.oldorigin = self.origin;
81 if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
83 self.ItemStatus = ReadByte();
85 if(self.ItemStatus & ITS_AVAILABLE)
88 self.colormod = self.glowmod = '1 1 1';
92 if (cl_ghost_items_alpha)
94 self.alpha = autocvar_cl_ghost_items;
95 self.colormod = self.glowmod = autocvar_cl_ghost_items_color;
101 if(autocvar_cl_fullbright_items)
102 if(self.ItemStatus & ITS_ALLOWFB)
103 self.effects |= EF_FULLBRIGHT;
105 if(self.ItemStatus & ITS_STAYWEP)
107 self.colormod = self.glowmod = autocvar_cl_staywep_color;
108 self.alpha = autocvar_cl_staywep_alpha;
112 if(self.ItemStatus & ITS_POWERUP)
114 if(self.ItemStatus & ITS_AVAILABLE)
115 self.effects |= (EF_ADDITIVE | EF_FULLBRIGHT);
117 self.effects &~= (EF_ADDITIVE | EF_FULLBRIGHT);
123 self.drawmask = MASK_NORMAL;
124 self.movetype = MOVETYPE_NOCLIP;
125 self.draw = ItemDraw;
131 string _fn = ReadString();
133 if(cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
135 string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
136 self.draw = ItemDrawSimple;
138 if(fexists(strcat(_fn2, "_simple.md3")))
139 self.mdl = strzone(strcat(_fn2, "_simple.md3"));
140 else if(fexists(strcat(_fn2, "_simple.dpm")))
141 self.mdl = strzone(strcat(_fn2, "_simple.dpm"));
142 else if(fexists(strcat(_fn2, "_simple.iqm")))
143 self.mdl = strzone(strcat(_fn2, "_simple.iqm"));
144 else if(fexists(strcat(_fn2, "_simple.obj")))
145 self.mdl = strzone(strcat(_fn2, "_simple.obj"));
148 self.draw = ItemDraw;
149 dprint("Simple item requested for ", _fn, " but no model exsist for it\n");
153 if(self.draw != ItemDrawSimple)
154 self.mdl = strzone(_fn);
158 dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, " tell tZork aboute this!\n");
160 precache_model(self.mdl);
161 setmodel(self, self.mdl);
164 if(sf & ISF_COLORMAP)
165 self.colormap = ReadShort();
170 self.move_movetype = MOVETYPE_TOSS;
171 self.move_velocity_x = ReadCoord();
172 self.move_velocity_y = ReadCoord();
173 self.move_velocity_z = ReadCoord();
174 self.velocity = self.move_velocity;
175 self.move_origin = self.oldorigin;
179 self.move_time = time;
180 self.spawntime = time;
183 self.move_time = max(self.move_time, time);
189 float autocvar_sv_simple_items;
190 float ItemSend(entity to, float sf)
197 WriteByte(MSG_ENTITY, ENT_CLIENT_ITEM);
198 WriteByte(MSG_ENTITY, sf);
201 //WriteByte(MSG_ENTITY, self.cnt);
202 if(sf & ISF_LOCATION)
204 WriteCoord(MSG_ENTITY, self.origin_x);
205 WriteCoord(MSG_ENTITY, self.origin_y);
206 WriteCoord(MSG_ENTITY, self.origin_z);
210 WriteByte(MSG_ENTITY, self.ItemStatus);
216 dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n");
218 WriteString(MSG_ENTITY, self.mdl);
222 if(sf & ISF_COLORMAP)
223 WriteShort(MSG_ENTITY, self.colormap);
227 WriteCoord(MSG_ENTITY, self.velocity_x);
228 WriteCoord(MSG_ENTITY, self.velocity_y);
229 WriteCoord(MSG_ENTITY, self.velocity_z);
236 float have_pickup_item(void)
238 // minstagib: only allow filtered items
240 if(self.classname != "minstagib")
243 if(self.flags & FL_POWERUP)
245 if(autocvar_g_powerups > 0)
247 if(autocvar_g_powerups == 0)
258 if(autocvar_g_pickup_items > 0)
260 if(autocvar_g_pickup_items == 0)
267 if(!WEPSET_EMPTY_E(self) || (self.items & IT_AMMO))
273 #define ITEM_RESPAWN_TICKS 10
275 #define ITEM_RESPAWNTIME(i) ((i).respawntime + crandom() * (i).respawntimejitter)
276 // range: respawntime - respawntimejitter .. respawntime + respawntimejitter
277 #define ITEM_RESPAWNTIME_INITIAL(i) (ITEM_RESPAWN_TICKS + random() * ((i).respawntime + (i).respawntimejitter - ITEM_RESPAWN_TICKS))
278 // range: 10 .. respawntime + respawntimejitter
280 floatfield Item_CounterField(float it)
284 case IT_SHELLS: return ammo_shells;
285 case IT_NAILS: return ammo_nails;
286 case IT_ROCKETS: return ammo_rockets;
287 case IT_CELLS: return ammo_cells;
288 case IT_FUEL: return ammo_fuel;
289 case IT_5HP: return health;
290 case IT_25HP: return health;
291 case IT_HEALTH: return health;
292 case IT_ARMOR_SHARD: return armorvalue;
293 case IT_ARMOR: return armorvalue;
294 // add more things here (health, armor)
295 default: error("requested item has no counter field");
299 string Item_CounterFieldName(float it)
303 case IT_SHELLS: return "shells";
304 case IT_NAILS: return "nails";
305 case IT_ROCKETS: return "rockets";
306 case IT_CELLS: return "cells";
307 case IT_FUEL: return "fuel";
309 // add more things here (health, armor)
310 default: error("requested item has no counter field name");
314 .float max_armorvalue;
315 .float pickup_anyway;
317 float Item_Customize()
319 if(self.spawnshieldtime)
321 if(!WEPSET_CONTAINS_ALL_EE(other, self))
323 self.colormod = '0 0 0';
324 self.glowmod = self.colormod;
325 self.alpha = 0.5 + 0.5 * g_ghost_items; // halfway more alpha
332 self.colormod = stov(autocvar_g_ghost_items_color);
333 self.glowmod = self.colormod;
334 self.alpha = g_ghost_items;
343 void Item_Show (entity e, float mode)
345 e.effects &~= EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST;
346 e.ItemStatus &~= ITS_STAYWEP;
349 // make the item look normal, and be touchable
351 e.solid = SOLID_TRIGGER;
352 e.spawnshieldtime = 1;
353 e.ItemStatus |= ITS_AVAILABLE;
357 // hide the item completely
358 e.model = string_null;
360 e.spawnshieldtime = 1;
361 e.ItemStatus &~= ITS_AVAILABLE;
363 else if((e.flags & FL_WEAPON) && !(e.flags & FL_NO_WEAPON_STAY) && g_weapon_stay)
365 // make the item translucent and not touchable
367 e.solid = SOLID_TRIGGER; // can STILL be picked up!
368 e.effects |= EF_STARDUST;
369 e.spawnshieldtime = 0; // field indicates whether picking it up may give you anything other than the weapon
370 e.ItemStatus |= (ITS_AVAILABLE | ITS_STAYWEP);
374 //setmodel(e, "null");
376 e.colormod = '0 0 0';
377 e.glowmod = e.colormod;
378 e.spawnshieldtime = 1;
379 e.ItemStatus &~= ITS_AVAILABLE;
382 if (e.items & IT_STRENGTH || e.items & IT_INVINCIBLE)
383 e.ItemStatus |= ITS_POWERUP;
385 if (autocvar_g_nodepthtestitems)
386 e.effects |= EF_NODEPTHTEST;
389 if (autocvar_g_fullbrightitems)
390 e.ItemStatus |= ITS_ALLOWFB;
392 if (autocvar_sv_simple_items)
393 e.ItemStatus |= ITS_ALLOWSI;
395 // relink entity (because solid may have changed)
396 setorigin(e, e.origin);
397 e.SendFlags |= ISF_STATUS;
400 float it_armor_large_time;
401 float it_health_mega_time;
402 float it_invisible_time;
404 float it_extralife_time;
405 float it_strength_time;
406 float it_shield_time;
407 float it_fuelregen_time;
408 float it_jetpack_time;
409 float it_superweapons_time;
411 void Item_ItemsTime_Init()
413 it_armor_large_time = -1;
414 it_health_mega_time = -1;
415 it_invisible_time = -1;
417 it_extralife_time = -1;
418 it_strength_time = -1;
420 it_fuelregen_time = -1;
421 it_jetpack_time = -1;
422 it_superweapons_time = -1;
424 void Item_ItemsTime_Reset()
426 it_armor_large_time = (it_armor_large_time == -1) ? -1 : 0;
427 it_health_mega_time = (it_health_mega_time == -1) ? -1 : 0;
428 it_invisible_time = (it_invisible_time == -1) ? -1 : 0;
429 it_speed_time = (it_speed_time == -1) ? -1 : 0;
430 it_extralife_time = (it_extralife_time == -1) ? -1 : 0;
431 it_strength_time = (it_strength_time == -1) ? -1 : 0;
432 it_shield_time = (it_shield_time == -1) ? -1 : 0;
433 it_fuelregen_time = (it_fuelregen_time == -1) ? -1 : 0;
434 it_jetpack_time = (it_jetpack_time == -1) ? -1 : 0;
435 it_superweapons_time= (it_superweapons_time== -1) ? -1 : 0;
437 void Item_ItemsTime_ResetForPlayer(entity e)
439 e.item_armor_large_time = (it_armor_large_time == -1) ? -1 : 0;
440 e.item_health_mega_time = (it_health_mega_time == -1) ? -1 : 0;
441 e.item_invisible_time = (it_invisible_time == -1) ? -1 : 0;
442 e.item_speed_time = (it_speed_time == -1) ? -1 : 0;
443 e.item_extralife_time = (it_extralife_time == -1) ? -1 : 0;
444 e.item_strength_time = (it_strength_time == -1) ? -1 : 0;
445 e.item_shield_time = (it_shield_time == -1) ? -1 : 0;
446 e.item_fuelregen_time = (it_fuelregen_time == -1) ? -1 : 0;
447 e.item_jetpack_time = (it_jetpack_time == -1) ? -1 : 0;
448 e.item_superweapons_time= (it_superweapons_time== -1) ? -1 : 0;
450 void Item_ItemsTime_Get(entity e)
452 e.item_armor_large_time = it_armor_large_time;
453 e.item_health_mega_time = it_health_mega_time;
454 e.item_invisible_time = it_invisible_time;
455 e.item_speed_time = it_speed_time;
456 e.item_extralife_time = it_extralife_time;
457 e.item_strength_time = it_strength_time;
458 e.item_shield_time = it_shield_time;
459 e.item_fuelregen_time = it_fuelregen_time;
460 e.item_jetpack_time = it_jetpack_time;
461 e.item_superweapons_time = it_superweapons_time;
463 float Item_ItemsTime_UpdateTime_Check(float item_time, float t)
465 if(t == 0 && item_time == -1)
467 if(time < t && (item_time <= time || t < item_time))
471 void Item_ItemsTime_UpdateTime(entity e, float t)
477 case IT_STRENGTH://"item-invis"
478 if(Item_ItemsTime_UpdateTime_Check(it_invisible_time, t))
479 it_invisible_time = t;
481 case IT_NAILS://"item-extralife"
482 if(Item_ItemsTime_UpdateTime_Check(it_extralife_time, t))
483 it_extralife_time = t;
485 case IT_INVINCIBLE://"item-speed"
486 if(Item_ItemsTime_UpdateTime_Check(it_speed_time, t))
496 //if (e.classname == "item_health_mega")
497 if(Item_ItemsTime_UpdateTime_Check(it_health_mega_time, t))
498 it_health_mega_time = t;
501 if (e.classname == "item_armor_large")
502 if(Item_ItemsTime_UpdateTime_Check(it_armor_large_time, t))
503 it_armor_large_time = t;
505 case IT_STRENGTH://"item-strength"
506 if(Item_ItemsTime_UpdateTime_Check(it_strength_time, t))
507 it_strength_time = t;
509 case IT_INVINCIBLE://"item-shield"
510 if(Item_ItemsTime_UpdateTime_Check(it_shield_time, t))
514 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
515 if(Item_ItemsTime_UpdateTime_Check(it_superweapons_time, t))
516 it_superweapons_time = t;
521 case IT_FUEL_REGEN://"item-fuelregen"
522 if(Item_ItemsTime_UpdateTime_Check(it_fuelregen_time, t))
523 it_fuelregen_time = t;
525 case IT_JETPACK://"item-jetpack"
526 if(Item_ItemsTime_UpdateTime_Check(it_jetpack_time, t))
531 void Item_ItemsTime_GetForAll()
536 FOR_EACH_REALCLIENT(e)
537 Item_ItemsTime_Get(e);
541 FOR_EACH_REALCLIENT(e)
543 if (e.classname != "player")
544 Item_ItemsTime_Get(e);
549 void Item_Respawn (void)
554 if(!g_minstagib && self.items == IT_STRENGTH)
555 sound (self, CH_TRIGGER, "misc/strength_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
556 else if(!g_minstagib && self.items == IT_INVINCIBLE)
557 sound (self, CH_TRIGGER, "misc/shield_respawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
559 sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTN_NORM); // play respawn sound
560 setorigin (self, self.origin);
562 if(self.flags & FL_POWERUP || self.classname == "item_armor_large" || self.items == IT_HEALTH || WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
564 Item_ItemsTime_UpdateTime(self, 0);
565 Item_ItemsTime_GetForAll();
568 //pointparticles(particleeffectnum("item_respawn"), self.origin + self.mins_z * '0 0 1' + '0 0 48', '0 0 0', 1);
569 pointparticles(particleeffectnum("item_respawn"), self.origin + 0.5 * (self.mins + self.maxs), '0 0 0', 1);
572 void Item_RespawnCountdown (void)
574 if(self.count >= ITEM_RESPAWN_TICKS)
576 if(self.waypointsprite_attached)
577 WaypointSprite_Kill(self.waypointsprite_attached);
582 self.nextthink = time + 1;
587 vector rgb = '1 0 1';
593 case IT_STRENGTH: name = "item-invis"; rgb = '0 0 1'; break;
594 case IT_NAILS: name = "item-extralife"; rgb = '1 0 0'; break;
595 case IT_INVINCIBLE: name = "item-speed"; rgb = '1 0 1'; break;
602 case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
603 case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
605 //if (self.classname == "item_health_mega")
606 {name = "item_health_mega"; rgb = '1 0 0';}
609 if (self.classname == "item_armor_large")
610 {name = "item_armor_large"; rgb = '0 1 0';}
616 case IT_FUEL_REGEN: name = "item-fuelregen"; rgb = '1 0.5 0'; break;
617 case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
619 if(self.flags & FL_WEAPON)
621 entity wi = get_weaponinfo(self.weapon);
630 print("Unknown powerup-marked item is wanting to respawn\n");
631 localcmd(sprintf("prvm_edict server %d\n", num_for_edict(self)));
635 WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, TRUE, RADARICON_POWERUP, rgb);
636 if(self.waypointsprite_attached)
638 if (self.items == IT_HEALTH || self.items == IT_ARMOR)
639 WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
640 WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
644 sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTN_NORM); // play respawn sound
645 if(self.waypointsprite_attached)
647 WaypointSprite_Ping(self.waypointsprite_attached);
648 //WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
653 void Item_ScheduleRespawnIn(entity e, float t)
655 if((e.flags & FL_POWERUP) || WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS) || e.classname == "item_armor_large" || e.items == IT_HEALTH)
658 e.think = Item_RespawnCountdown;
659 e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
660 e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
662 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
664 for(t = e.scheduledrespawntime, head = world; (head = nextent(head)); )
668 if(clienttype(head) == CLIENTTYPE_NOTACLIENT)
669 if(WEPSET_CONTAINS_ANY_EA(head, WEPBIT_SUPERWEAPONS))
670 if(head.classname != "weapon_info")
672 if(head.scheduledrespawntime <= time)
677 if(head.scheduledrespawntime < t)
678 t = head.scheduledrespawntime;
684 for(t = e.scheduledrespawntime, head = world; (head = find(head, classname, e.classname)); )
686 // in minstagib .classname is "minstagib" for every item
687 if(e == head || (g_minstagib && e.items != head.items))
689 if(head.scheduledrespawntime <= time)
694 if(head.scheduledrespawntime < t)
695 t = head.scheduledrespawntime;
698 Item_ItemsTime_UpdateTime(e, t);
699 Item_ItemsTime_GetForAll();
703 e.think = Item_Respawn;
704 e.nextthink = time + t;
705 e.scheduledrespawntime = e.nextthink;
709 void Item_ScheduleRespawn(entity e)
711 if(e.respawntime > 0)
714 Item_ScheduleRespawnIn(e, ITEM_RESPAWNTIME(e));
716 else // if respawntime is -1, this item does not respawn
720 void Item_ScheduleInitialRespawn(entity e)
723 Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
726 float ITEM_MODE_NONE = 0;
727 float ITEM_MODE_HEALTH = 1;
728 float ITEM_MODE_ARMOR = 2;
729 float ITEM_MODE_FUEL = 3;
730 float Item_GiveAmmoTo(entity item, entity player, .float ammofield, float ammomax, float mode)
735 if (item.spawnshieldtime)
737 if ((player.ammofield < ammomax) || item.pickup_anyway)
739 player.ammofield = bound(player.ammofield, ammomax, player.ammofield + item.ammofield);
743 else if(g_weapon_stay == 2)
745 float mi = min(item.ammofield, ammomax);
746 if (player.ammofield < mi)
748 player.ammofield = mi;
759 player.pauserotfuel_finished = max(player.pauserotfuel_finished, time + autocvar_g_balance_pause_fuel_rot);
761 case ITEM_MODE_HEALTH:
762 player.pauserothealth_finished = max(player.pauserothealth_finished, time + autocvar_g_balance_pause_health_rot);
764 case ITEM_MODE_ARMOR:
765 player.pauserotarmor_finished = max(player.pauserotarmor_finished, time + autocvar_g_balance_pause_armor_rot);
773 float Item_GiveTo(entity item, entity player)
780 // if nothing happens to player, just return without taking the item
782 _switchweapon = FALSE;
786 float prevcells = player.ammo_cells;
788 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
789 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, 999, ITEM_MODE_NONE);
791 if(player.ammo_cells > prevcells)
793 _switchweapon = TRUE;
795 // play some cool sounds ;)
796 if (clienttype(player) == CLIENTTYPE_REAL)
798 if(player.health <= 5)
799 AnnounceTo(player, "lastsecond");
800 else if(player.health < 50)
801 AnnounceTo(player, "narrowly");
803 // sound not available
804 // else if(item.items == IT_CELLS)
805 // AnnounceTo(player, "ammo");
807 if (WEPSET_CONTAINS_EW(item, WEP_MINSTANEX))
808 W_GiveWeapon (player, WEP_MINSTANEX, item.netname);
812 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
816 sprint (player, strcat("You got the ^2", item.netname, "\n"));
823 // sound not available
824 // AnnounceTo(player, "_lives");
825 player.armorvalue = bound(player.armorvalue, 999, player.armorvalue + autocvar_g_minstagib_extralives);
826 sprint(player, "^3You picked up some extra lives\n");
830 if (item.strength_finished)
833 // sound not available
834 // AnnounceTo(player, "invisible");
835 player.strength_finished = max(player.strength_finished, time) + autocvar_g_balance_powerup_strength_time;
839 if (item.invincible_finished)
842 // sound not available
843 // AnnounceTo(player, "speed");
844 player.invincible_finished = max(player.invincible_finished, time) + autocvar_g_balance_powerup_strength_time;
849 // in case the player has autoswitch enabled do the following:
850 // if the player is using their best weapon before items are given, they
851 // probably want to switch to an even better weapon after items are given
852 if (player.autoswitch)
853 if (player.switchweapon == w_getbestweapon(player))
854 _switchweapon = TRUE;
856 if not(WEPSET_CONTAINS_EW(player, player.switchweapon))
857 _switchweapon = TRUE;
859 pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
860 pickedup |= Item_GiveAmmoTo(item, player, ammo_shells, g_pickup_shells_max, ITEM_MODE_NONE);
861 pickedup |= Item_GiveAmmoTo(item, player, ammo_nails, g_pickup_nails_max, ITEM_MODE_NONE);
862 pickedup |= Item_GiveAmmoTo(item, player, ammo_rockets, g_pickup_rockets_max, ITEM_MODE_NONE);
863 pickedup |= Item_GiveAmmoTo(item, player, ammo_cells, g_pickup_cells_max, ITEM_MODE_NONE);
864 pickedup |= Item_GiveAmmoTo(item, player, health, item.max_health, ITEM_MODE_HEALTH);
865 pickedup |= Item_GiveAmmoTo(item, player, armorvalue, item.max_armorvalue, ITEM_MODE_ARMOR);
867 if (item.flags & FL_WEAPON)
869 WEPSET_DECLARE_A(it);
870 WEPSET_COPY_AE(it, item);
871 WEPSET_ANDNOT_AE(it, player);
873 if (!WEPSET_EMPTY_A(it) || (item.spawnshieldtime && self.pickup_anyway))
876 for(i = WEP_FIRST; i <= WEP_LAST; ++i)
877 if(WEPSET_CONTAINS_AW(it, i))
878 W_GiveWeapon (player, i, item.netname);
882 if((it = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
886 sprint (player, strcat("You got the ^2", item.netname, "\n"));
889 if (item.strength_finished)
892 player.strength_finished = max(player.strength_finished, time) + item.strength_finished;
894 if (item.invincible_finished)
897 player.invincible_finished = max(player.invincible_finished, time) + item.invincible_finished;
899 if (item.superweapons_finished)
902 player.superweapons_finished = max(player.superweapons_finished, time) + item.superweapons_finished;
907 // always eat teamed entities
915 if (player.switchweapon != w_getbestweapon(player))
916 W_SwitchWeapon_Force(player, w_getbestweapon(player));
921 void Item_Touch (void)
925 // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
926 if(self.classname == "droppedweapon")
928 if (ITEM_TOUCH_NEEDKILL())
935 if (other.classname != "player")
939 if (self.solid != SOLID_TRIGGER)
941 if (self.owner == other)
944 if (self.classname == "droppedweapon")
946 self.strength_finished = max(0, self.strength_finished - time);
947 self.invincible_finished = max(0, self.invincible_finished - time);
948 self.superweapons_finished = max(0, self.superweapons_finished - time);
951 if(!Item_GiveTo(self, other))
953 if (self.classname == "droppedweapon")
955 // undo what we did above
956 self.strength_finished += time;
957 self.invincible_finished += time;
958 self.superweapons_finished += time;
963 other.last_pickup = time;
965 pointparticles(particleeffectnum("item_pickup"), self.origin, '0 0 0', 1);
966 sound (other, CH_TRIGGER, self.item_pickupsound, VOL_BASE, ATTN_NORM);
968 if (self.classname == "droppedweapon")
970 else if not(self.spawnshieldtime)
976 RandomSelection_Init();
977 for(head = world; (head = findfloat(head, team, self.team)); )
979 if(head.flags & FL_ITEM)
982 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
985 e = RandomSelection_chosen_ent;
990 Item_ScheduleRespawn(e);
996 Item_Show(self, !self.state);
997 setorigin (self, self.origin);
999 if(self.classname != "droppedweapon")
1001 self.think = SUB_Null;
1004 if(self.waypointsprite_attached)
1005 WaypointSprite_Kill(self.waypointsprite_attached);
1007 if((self.flags & FL_POWERUP) | WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS)) // do not spawn powerups initially!
1008 Item_ScheduleInitialRespawn(self);
1012 void Item_FindTeam()
1016 if(self.effects & EF_NODRAW)
1018 // marker for item team search
1019 dprint("Initializing item team ", ftos(self.team), "\n");
1020 RandomSelection_Init();
1021 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
1022 RandomSelection_Add(head, 0, string_null, head.cnt, 0);
1023 e = RandomSelection_chosen_ent;
1027 for(head = world; (head = findfloat(head, team, self.team)); ) if(head.flags & FL_ITEM)
1031 // make it a non-spawned item
1032 Item_Show(head, -1);
1033 head.state = 1; // state 1 = initially hidden item
1035 head.effects &~= EF_NODRAW;
1042 // Savage: used for item garbage-collection
1043 // TODO: perhaps nice special effect?
1044 void RemoveItem(void)
1049 // pickup evaluation functions
1050 // these functions decide how desirable an item is to the bots
1052 float generic_pickupevalfunc(entity player, entity item) {return item.bot_pickupbasevalue;}
1054 float weapon_pickupevalfunc(entity player, entity item)
1056 float c, j, position;
1058 // See if I have it already
1059 if(!WEPSET_CONTAINS_ALL_EE(player, item))
1061 // If I can pick it up
1062 if(!item.spawnshieldtime)
1064 else if(player.ammo_cells || player.ammo_shells || player.ammo_nails || player.ammo_rockets)
1066 // Skilled bots will grab more
1067 c = bound(0, skill / 10, 1) * 0.5;
1075 // If custom weapon priorities for bots is enabled rate most wanted weapons higher
1076 if( bot_custom_weapon && c )
1078 // Find the highest position on any range
1080 for(j = 0; j < WEP_LAST ; ++j){
1082 bot_weapons_far[j] == item.weapon ||
1083 bot_weapons_mid[j] == item.weapon ||
1084 bot_weapons_close[j] == item.weapon
1095 position = WEP_LAST - position;
1096 // item.bot_pickupbasevalue is overwritten here
1097 return (BOT_PICKUP_RATING_LOW + ( (BOT_PICKUP_RATING_HIGH - BOT_PICKUP_RATING_LOW) * (position / WEP_LAST ))) * c;
1101 return item.bot_pickupbasevalue * c;
1104 float commodity_pickupevalfunc(entity player, entity item)
1107 float need_shells = FALSE, need_nails = FALSE, need_rockets = FALSE, need_cells = FALSE, need_fuel = FALSE;
1111 // Detect needed ammo
1112 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
1114 wi = get_weaponinfo(i);
1116 if not(WEPSET_CONTAINS_EW(player, i))
1119 if(wi.items & IT_SHELLS)
1121 else if(wi.items & IT_NAILS)
1123 else if(wi.items & IT_ROCKETS)
1124 need_rockets = TRUE;
1125 else if(wi.items & IT_CELLS)
1127 else if(wi.items & IT_FUEL)
1131 // TODO: figure out if the player even has the weapon this ammo is for?
1132 // may not affect strategy much though...
1133 // find out how much more ammo/armor/health the player can hold
1135 if (item.ammo_shells)
1136 if (player.ammo_shells < g_pickup_shells_max)
1137 c = c + max(0, 1 - player.ammo_shells / g_pickup_shells_max);
1139 if (item.ammo_nails)
1140 if (player.ammo_nails < g_pickup_nails_max)
1141 c = c + max(0, 1 - player.ammo_nails / g_pickup_nails_max);
1143 if (item.ammo_rockets)
1144 if (player.ammo_rockets < g_pickup_rockets_max)
1145 c = c + max(0, 1 - player.ammo_rockets / g_pickup_rockets_max);
1147 if (item.ammo_cells)
1148 if (player.ammo_cells < g_pickup_cells_max)
1149 c = c + max(0, 1 - player.ammo_cells / g_pickup_cells_max);
1152 if (player.ammo_fuel < g_pickup_fuel_max)
1153 c = c + max(0, 1 - player.ammo_fuel / g_pickup_fuel_max);
1154 if (item.armorvalue)
1155 if (player.armorvalue < item.max_armorvalue)
1156 c = c + max(0, 1 - player.armorvalue / item.max_armorvalue);
1158 if (player.health < item.max_health)
1159 c = c + max(0, 1 - player.health / item.max_health);
1161 return item.bot_pickupbasevalue * c;
1164 void Item_Damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
1166 if(ITEM_DAMAGE_NEEDKILL(deathtype))
1171 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)
1173 startitem_failed = FALSE;
1175 if(self.model == "")
1176 self.model = itemmodel;
1178 if(self.model == "")
1180 error(strcat("^1Tried to spawn ", itemname, " with no model!\n"));
1184 if(self.item_pickupsound == "")
1185 self.item_pickupsound = pickupsound;
1187 if(!self.respawntime) // both need to be set
1189 self.respawntime = defaultrespawntime;
1190 self.respawntimejitter = defaultrespawntimejitter;
1193 self.items = itemid;
1194 self.weapon = weaponid;
1197 WEPSET_COPY_EW(self, weaponid);
1199 self.flags = FL_ITEM | itemflags;
1201 if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
1203 startitem_failed = TRUE;
1208 // is it a dropped weapon?
1209 if (self.classname == "droppedweapon")
1211 self.reset = SUB_Remove;
1212 // it's a dropped weapon
1213 self.movetype = MOVETYPE_TOSS;
1215 // Savage: remove thrown items after a certain period of time ("garbage collection")
1216 self.think = RemoveItem;
1217 self.nextthink = time + 20;
1219 self.takedamage = DAMAGE_YES;
1220 self.event_damage = Item_Damage;
1222 if(self.strength_finished || self.invincible_finished || self.superweapons_finished)
1225 if(WEPSET_CONTAINS_ALL_AE(WEPBIT_SUPERWEAPONS, self)) // only superweapons
1226 if(self.ammo_nails == 0)
1227 if(self.ammo_cells == 0)
1228 if(self.ammo_rockets == 0)
1229 if(self.ammo_shells == 0)
1230 if(self.ammo_fuel == 0)
1231 if(self.health == 0)
1232 if(self.armorvalue == 0)
1235 // if item is worthless after a timer, have it expire then
1236 self.nextthink = max(self.strength_finished, self.invincible_finished, self.superweapons_finished);
1239 // don't drop if in a NODROP zone (such as lava)
1240 traceline(self.origin, self.origin, MOVE_NORMAL, self);
1241 if (trace_dpstartcontents & DPCONTENTS_NODROP)
1243 startitem_failed = TRUE;
1250 if(!have_pickup_item())
1252 startitem_failed = TRUE;
1257 self.reset = Item_Reset;
1258 // it's a level item
1259 if(self.spawnflags & 1)
1262 self.movetype = MOVETYPE_NONE;
1264 self.movetype = MOVETYPE_TOSS;
1265 // do item filtering according to game mode and other things
1268 // first nudge it off the floor a little bit to avoid math errors
1269 setorigin(self, self.origin + '0 0 1');
1270 // set item size before we spawn a spawnfunc_waypoint
1271 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1272 setsize (self, '-16 -16 0', '16 16 48');
1274 setsize (self, '-16 -16 0', '16 16 32');
1275 // note droptofloor returns FALSE if stuck/or would fall too far
1277 waypoint_spawnforitem(self);
1281 * can't do it that way, as it would break maps
1282 * TODO make a target_give like entity another way, that perhaps has
1283 * the weapon name in a key
1286 // target_give not yet supported; maybe later
1287 print("removed targeted ", self.classname, "\n");
1288 startitem_failed = TRUE;
1294 if(autocvar_spawn_debug >= 2)
1297 for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
1299 // why not flags & fl_item?
1300 if(otheritem.is_item)
1302 dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
1303 dprint(" vs ", otheritem.netname, vtos(otheritem.origin), "\n");
1304 error("Mapper sucks.");
1307 self.is_item = TRUE;
1310 WEPSET_OR_AW(weaponsInMap, weaponid);
1312 precache_model (self.model);
1313 precache_sound (self.item_pickupsound);
1315 precache_sound ("misc/itemrespawncountdown.wav");
1316 if(!g_minstagib && itemid == IT_STRENGTH)
1317 precache_sound ("misc/strength_respawn.wav");
1318 else if(!g_minstagib && itemid == IT_INVINCIBLE)
1319 precache_sound ("misc/shield_respawn.wav");
1321 precache_sound ("misc/itemrespawn.wav");
1323 if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
1324 self.target = "###item###"; // for finding the nearest item using find()
1326 Item_ItemsTime_UpdateTime(self, 0);
1329 self.bot_pickup = TRUE;
1330 self.bot_pickupevalfunc = pickupevalfunc;
1331 self.bot_pickupbasevalue = pickupbasevalue;
1332 self.mdl = self.model;
1333 self.netname = itemname;
1334 self.touch = Item_Touch;
1335 setmodel(self, "null"); // precision set below
1336 //self.effects |= EF_LOWPRECISION;
1338 if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
1340 self.pos1 = '-16 -16 0';
1341 self.pos2 = '16 16 48';
1345 self.pos1 = '-16 -16 0';
1346 self.pos2 = '16 16 32';
1348 setsize (self, self.pos1, self.pos2);
1350 if(itemflags & FL_POWERUP)
1351 self.ItemStatus |= ITS_ANIMATE1;
1353 if(self.armorvalue || self.health)
1354 self.ItemStatus |= ITS_ANIMATE2;
1356 if(itemflags & FL_WEAPON)
1358 if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
1359 self.colormap = 1024; // color shirt=0 pants=0 grey
1363 self.ItemStatus |= ITS_ANIMATE1;
1364 self.ItemStatus |= ISF_COLORMAP;
1368 if(self.team) // broken, no idea why.
1371 self.cnt = 1; // item probability weight
1373 self.effects |= EF_NODRAW; // marker for item team search
1374 InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
1379 Net_LinkEntity(self, FALSE, 0, ItemSend);
1382 /* replace items in minstagib
1383 * IT_STRENGTH = invisibility
1384 * IT_NAILS = extra lives
1385 * IT_INVINCIBLE = speed
1387 void minstagib_items (float itemid) // will be deleted soon.
1390 self.classname = "minstagib"; // ...?
1392 // replace rocket launchers and nex guns with ammo cells
1393 if (itemid == IT_CELLS)
1395 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1396 StartItem ("models/items/a_cells.md3",
1397 "misc/itempickup.wav", 45, 0,
1398 "MinstaNex Ammo", IT_CELLS, 0, 0, generic_pickupevalfunc, 100);
1405 itemid = IT_STRENGTH;
1409 itemid = IT_INVINCIBLE;
1411 // replace with invis
1412 if (itemid == IT_STRENGTH)
1414 if(!self.strength_finished)
1415 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1416 StartItem ("models/items/g_strength.md3",
1417 "misc/powerup.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1418 "Invisibility", IT_STRENGTH, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1420 // replace with extra lives
1421 if (itemid == IT_NAILS)
1423 self.max_health = 1;
1424 StartItem ("models/items/g_h100.md3",
1425 "misc/megahealth.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1426 "Extralife", IT_NAILS, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_HIGH);
1428 // replace with speed
1429 if (itemid == IT_INVINCIBLE)
1431 if(!self.invincible_finished)
1432 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1433 StartItem ("models/items/g_invincible.md3",
1434 "misc/powerup_shield.wav", g_pickup_respawntime_powerup, g_pickup_respawntimejitter_powerup,
1435 "Speed", IT_INVINCIBLE, 0, FL_POWERUP, generic_pickupevalfunc, BOT_PICKUP_RATING_MID);
1439 float minst_no_auto_cells;
1440 void minst_remove_item (void) {
1441 if(minst_no_auto_cells)
1445 float weaponswapping;
1448 void weapon_defaultspawnfunc(float wpn)
1452 var .float ammofield;
1458 if(self.classname != "droppedweapon" && self.classname != "replacedweapon")
1460 e = get_weaponinfo(wpn);
1462 if(e.spawnflags & WEP_FLAG_MUTATORBLOCKED)
1464 print("Attempted to spawn a mutator-blocked weapon; these guns will in the future require a mutator\n");
1466 objerror("Attempted to spawn a mutator-blocked weapon rejected");
1467 startitem_failed = TRUE;
1472 s = W_Apply_Weaponreplace(e.netname);
1475 MUTATOR_CALLHOOK(SetWeaponreplace);
1480 startitem_failed = TRUE;
1483 t = tokenize_console(s);
1486 self.team = --internalteam;
1488 for(i = 1; i < t; ++i)
1491 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1493 e = get_weaponinfo(j);
1497 copyentity(oldself, self);
1498 self.classname = "replacedweapon";
1499 weapon_defaultspawnfunc(j);
1505 print("The weapon replace list for ", oldself.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1510 if(t >= 1) // always the case!
1514 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1516 e = get_weaponinfo(j);
1525 print("The weapon replace list for ", self.classname, " contains an unknown weapon ", s, ". Skipped.\n");
1531 startitem_failed = TRUE;
1536 e = get_weaponinfo(wpn);
1538 if(!self.respawntime)
1540 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1542 self.respawntime = g_pickup_respawntime_superweapon;
1543 self.respawntimejitter = g_pickup_respawntimejitter_superweapon;
1547 self.respawntime = g_pickup_respawntime_weapon;
1548 self.respawntimejitter = g_pickup_respawntimejitter_weapon;
1552 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1553 if(!self.superweapons_finished)
1554 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1558 for(i = 0, j = 1; i < 24; ++i, j *= 2)
1562 ammofield = Item_CounterField(j);
1564 self.ammofield = cvar(strcat("g_pickup_", Item_CounterFieldName(j), "_weapon"));
1570 if(g_pickup_weapons_anyway)
1571 self.pickup_anyway = TRUE;
1575 // no weapon-stay on superweapons
1576 if(WEPSET_CONTAINS_ANY_EA(e, WEPBIT_SUPERWEAPONS))
1577 f |= FL_NO_WEAPON_STAY;
1579 // weapon stay isn't supported for teamed weapons
1581 f |= FL_NO_WEAPON_STAY;
1583 // stupid minstagib hack, don't ask
1586 self.ammo_cells = autocvar_g_minstagib_ammo_drop;
1588 StartItem(e.model, "weapons/weaponpickup.wav", self.respawntime, self.respawntimejitter, e.message, 0, e.weapon, f, weapon_pickupevalfunc, e.bot_pickupbasevalue);
1589 if (self.modelindex) // don't precache if self was removed
1590 weapon_action(e.weapon, WR_PRECACHE);
1593 void spawnfunc_weapon_shotgun (void);
1594 void spawnfunc_weapon_uzi (void) {
1595 if(autocvar_sv_q3acompat_machineshotgunswap)
1596 if(self.classname != "droppedweapon")
1598 weapon_defaultspawnfunc(WEP_SHOTGUN);
1601 weapon_defaultspawnfunc(WEP_UZI);
1604 void spawnfunc_weapon_shotgun (void) {
1605 if(autocvar_sv_q3acompat_machineshotgunswap)
1606 if(self.classname != "droppedweapon")
1608 weapon_defaultspawnfunc(WEP_UZI);
1611 weapon_defaultspawnfunc(WEP_SHOTGUN);
1614 void spawnfunc_weapon_nex (void)
1618 minstagib_items(IT_CELLS);
1619 self.think = minst_remove_item;
1620 self.nextthink = time;
1623 weapon_defaultspawnfunc(WEP_NEX);
1626 void spawnfunc_weapon_minstanex (void)
1630 minstagib_items(IT_CELLS);
1631 self.think = minst_remove_item;
1632 self.nextthink = time;
1635 weapon_defaultspawnfunc(WEP_MINSTANEX);
1638 void spawnfunc_weapon_rocketlauncher (void)
1642 minstagib_items(IT_CELLS); // replace rocketlauncher with cells
1643 self.think = minst_remove_item;
1644 self.nextthink = time;
1647 weapon_defaultspawnfunc(WEP_ROCKET_LAUNCHER);
1650 void spawnfunc_item_rockets (void) {
1651 if(!self.ammo_rockets)
1652 self.ammo_rockets = g_pickup_rockets;
1653 if(!self.pickup_anyway)
1654 self.pickup_anyway = g_pickup_ammo_anyway;
1655 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);
1658 void spawnfunc_item_shells (void);
1659 void spawnfunc_item_bullets (void) {
1661 if(autocvar_sv_q3acompat_machineshotgunswap)
1662 if(self.classname != "droppedweapon")
1664 weaponswapping = TRUE;
1665 spawnfunc_item_shells();
1666 weaponswapping = FALSE;
1670 if(!self.ammo_nails)
1671 self.ammo_nails = g_pickup_nails;
1672 if(!self.pickup_anyway)
1673 self.pickup_anyway = g_pickup_ammo_anyway;
1674 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);
1677 void spawnfunc_item_cells (void) {
1678 if(!self.ammo_cells)
1679 self.ammo_cells = g_pickup_cells;
1680 if(!self.pickup_anyway)
1681 self.pickup_anyway = g_pickup_ammo_anyway;
1682 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);
1685 void spawnfunc_item_shells (void) {
1687 if(autocvar_sv_q3acompat_machineshotgunswap)
1688 if(self.classname != "droppedweapon")
1690 weaponswapping = TRUE;
1691 spawnfunc_item_bullets();
1692 weaponswapping = FALSE;
1696 if(!self.ammo_shells)
1697 self.ammo_shells = g_pickup_shells;
1698 if(!self.pickup_anyway)
1699 self.pickup_anyway = g_pickup_ammo_anyway;
1700 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);
1703 void spawnfunc_item_armor_small (void) {
1704 if(!self.armorvalue)
1705 self.armorvalue = g_pickup_armorsmall;
1706 if(!self.max_armorvalue)
1707 self.max_armorvalue = g_pickup_armorsmall_max;
1708 if(!self.pickup_anyway)
1709 self.pickup_anyway = g_pickup_armorsmall_anyway;
1710 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);
1713 void spawnfunc_item_armor_medium (void) {
1714 if(!self.armorvalue)
1715 self.armorvalue = g_pickup_armormedium;
1716 if(!self.max_armorvalue)
1717 self.max_armorvalue = g_pickup_armormedium_max;
1718 if(!self.pickup_anyway)
1719 self.pickup_anyway = g_pickup_armormedium_anyway;
1720 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);
1723 void spawnfunc_item_armor_big (void) {
1724 if(!self.armorvalue)
1725 self.armorvalue = g_pickup_armorbig;
1726 if(!self.max_armorvalue)
1727 self.max_armorvalue = g_pickup_armorbig_max;
1728 if(!self.pickup_anyway)
1729 self.pickup_anyway = g_pickup_armorbig_anyway;
1730 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);
1733 void spawnfunc_item_armor_large (void) {
1734 if(!self.armorvalue)
1735 self.armorvalue = g_pickup_armorlarge;
1736 if(!self.max_armorvalue)
1737 self.max_armorvalue = g_pickup_armorlarge_max;
1738 if(!self.pickup_anyway)
1739 self.pickup_anyway = g_pickup_armorlarge_anyway;
1740 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);
1743 void spawnfunc_item_health_small (void) {
1744 if(!self.max_health)
1745 self.max_health = g_pickup_healthsmall_max;
1747 self.health = g_pickup_healthsmall;
1748 if(!self.pickup_anyway)
1749 self.pickup_anyway = g_pickup_healthsmall_anyway;
1750 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);
1753 void spawnfunc_item_health_medium (void) {
1754 if(!self.max_health)
1755 self.max_health = g_pickup_healthmedium_max;
1757 self.health = g_pickup_healthmedium;
1758 if(!self.pickup_anyway)
1759 self.pickup_anyway = g_pickup_healthmedium_anyway;
1760 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);
1763 void spawnfunc_item_health_large (void) {
1764 if(!self.max_health)
1765 self.max_health = g_pickup_healthlarge_max;
1767 self.health = g_pickup_healthlarge;
1768 if(!self.pickup_anyway)
1769 self.pickup_anyway = g_pickup_healthlarge_anyway;
1770 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);
1773 void spawnfunc_item_health_mega (void) {
1775 minstagib_items(IT_NAILS);
1777 if(!self.max_health)
1778 self.max_health = g_pickup_healthmega_max;
1780 self.health = g_pickup_healthmega;
1781 if(!self.pickup_anyway)
1782 self.pickup_anyway = g_pickup_healthmega_anyway;
1783 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);
1787 // support old misnamed entities
1788 void spawnfunc_item_armor1() { spawnfunc_item_armor_small(); } // FIXME: in Quake this is green armor, in Xonotic maps it is an armor shard
1789 void spawnfunc_item_armor25() { spawnfunc_item_armor_large(); }
1790 void spawnfunc_item_health1() { spawnfunc_item_health_small(); }
1791 void spawnfunc_item_health25() { spawnfunc_item_health_medium(); }
1792 void spawnfunc_item_health100() { spawnfunc_item_health_mega(); }
1794 void spawnfunc_item_strength (void) {
1796 minstagib_items(IT_STRENGTH);
1798 precache_sound("weapons/strength_fire.wav");
1799 if(!self.strength_finished)
1800 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1801 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);
1805 void spawnfunc_item_invincible (void) {
1807 minstagib_items(IT_INVINCIBLE);
1809 if(!self.invincible_finished)
1810 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1811 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);
1815 void spawnfunc_item_minst_cells (void) {
1818 minst_no_auto_cells = TRUE;
1819 minstagib_items(IT_CELLS);
1826 void spawnfunc_item_quad (void) {self.classname = "item_strength";spawnfunc_item_strength();}
1828 float GiveItems(entity e, float beginarg, float endarg);
1829 void target_items_use (void)
1831 if(activator.classname == "droppedweapon")
1838 if(activator.classname != "player")
1840 if(activator.deadflag != DEAD_NO)
1845 for(e = world; (e = find(e, classname, "droppedweapon")); )
1846 if(e.enemy == activator)
1849 if(GiveItems(activator, 0, tokenize_console(self.netname)))
1850 centerprint(activator, self.message);
1853 void spawnfunc_target_items (void)
1858 self.use = target_items_use;
1859 if(!self.strength_finished)
1860 self.strength_finished = autocvar_g_balance_powerup_strength_time;
1861 if(!self.invincible_finished)
1862 self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
1863 if(!self.superweapons_finished)
1864 self.superweapons_finished = autocvar_g_balance_superweapons_time;
1866 precache_sound("misc/itempickup.wav");
1867 precache_sound("misc/megahealth.wav");
1868 precache_sound("misc/armor25.wav");
1869 precache_sound("misc/powerup.wav");
1870 precache_sound("misc/poweroff.wav");
1871 precache_sound("weapons/weaponpickup.wav");
1873 n = tokenize_console(self.netname);
1874 if(argv(0) == "give")
1876 self.netname = substring(self.netname, argv_start_index(1), argv_end_index(-1) - argv_start_index(1));
1880 for(i = 0; i < n; ++i)
1882 if (argv(i) == "unlimited_ammo") self.items |= IT_UNLIMITED_AMMO;
1883 else if(argv(i) == "unlimited_weapon_ammo") self.items |= IT_UNLIMITED_WEAPON_AMMO;
1884 else if(argv(i) == "unlimited_superweapons") self.items |= IT_UNLIMITED_SUPERWEAPONS;
1885 else if(argv(i) == "strength") self.items |= IT_STRENGTH;
1886 else if(argv(i) == "invincible") self.items |= IT_INVINCIBLE;
1887 else if(argv(i) == "superweapons") self.items |= IT_SUPERWEAPON;
1888 else if(argv(i) == "jetpack") self.items |= IT_JETPACK;
1889 else if(argv(i) == "fuel_regen") self.items |= IT_FUEL_REGEN;
1892 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1894 e = get_weaponinfo(j);
1895 if(argv(i) == e.netname)
1897 WEPSET_OR_EW(self, j);
1898 if(self.spawnflags == 0 || self.spawnflags == 2)
1899 weapon_action(e.weapon, WR_PRECACHE);
1904 print("target_items: invalid item ", argv(i), "\n");
1908 string itemprefix, valueprefix;
1909 if(self.spawnflags == 0)
1914 else if(self.spawnflags == 1)
1916 itemprefix = "max ";
1917 valueprefix = "max ";
1919 else if(self.spawnflags == 2)
1921 itemprefix = "min ";
1922 valueprefix = "min ";
1924 else if(self.spawnflags == 4)
1926 itemprefix = "minus ";
1927 valueprefix = "max ";
1930 error("invalid spawnflags");
1933 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_WEAPON_AMMO), "unlimited_weapon_ammo");
1934 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_UNLIMITED_SUPERWEAPONS), "unlimited_superweapons");
1935 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.strength_finished * !!(self.items & IT_STRENGTH), "strength");
1936 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.invincible_finished * !!(self.items & IT_INVINCIBLE), "invincible");
1937 self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, self.superweapons_finished * !!(self.items & IT_SUPERWEAPON), "superweapons");
1938 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_JETPACK), "jetpack");
1939 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.items & IT_FUEL_REGEN), "fuel_regen");
1940 if(self.ammo_shells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_shells), "shells");
1941 if(self.ammo_nails != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_nails), "nails");
1942 if(self.ammo_rockets != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_rockets), "rockets");
1943 if(self.ammo_cells != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_cells), "cells");
1944 if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
1945 if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
1946 if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
1947 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1949 e = get_weaponinfo(j);
1951 self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, WEPSET_CONTAINS_EW(self, j), e.netname);
1954 self.netname = strzone(self.netname);
1955 //print(self.netname, "\n");
1957 n = tokenize_console(self.netname);
1958 for(i = 0; i < n; ++i)
1960 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
1962 e = get_weaponinfo(j);
1963 if(argv(i) == e.netname)
1965 weapon_action(e.weapon, WR_PRECACHE);
1972 void spawnfunc_item_fuel(void)
1975 self.ammo_fuel = g_pickup_fuel;
1976 if(!self.pickup_anyway)
1977 self.pickup_anyway = g_pickup_ammo_anyway;
1978 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);
1981 void spawnfunc_item_fuel_regen(void)
1983 if(start_items & IT_FUEL_REGEN)
1985 spawnfunc_item_fuel();
1988 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);
1991 void spawnfunc_item_jetpack(void)
1993 if(g_grappling_hook)
1994 return; // sorry, but these two can't coexist (same button); spawn fuel instead
1996 self.ammo_fuel = g_pickup_fuel_jetpack;
1997 if(start_items & IT_JETPACK)
1999 spawnfunc_item_fuel();
2002 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);
2012 float GiveWeapon(entity e, float wpn, float op, float val)
2015 v0 = WEPSET_CONTAINS_EW(e, wpn);
2020 WEPSET_OR_EW(e, wpn);
2022 WEPSET_ANDNOT_EW(e, wpn);
2027 WEPSET_OR_EW(e, wpn);
2031 WEPSET_ANDNOT_EW(e, wpn);
2035 WEPSET_ANDNOT_EW(e, wpn);
2038 v1 = WEPSET_CONTAINS_EW(e, wpn);
2042 float GiveBit(entity e, .float fld, float bit, float op, float val)
2072 float GiveValue(entity e, .float fld, float op, float val)
2082 e.fld = max(e.fld, val); // min 100 cells = at least 100 cells
2085 e.fld = min(e.fld, val);
2098 void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
2105 sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTN_NORM);
2107 else if(v0 >= v0 + t)
2110 sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTN_NORM);
2114 void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .float regenfield, float regentime)
2117 e.rotfield = max(e.rotfield, time + rottime);
2119 e.regenfield = max(e.regenfield, time + regentime);
2122 #define PREGIVE_WEAPONS(e) WEPSET_DECLARE_A(save_weapons); WEPSET_COPY_AE(save_weapons, e)
2123 #define PREGIVE(e,f) float save_##f; save_##f = (e).f
2124 #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)
2125 #define POSTGIVE_BIT(e,f,b,snd_incr,snd_decr) GiveSound((e), save_##f & (b), (e).f & (b), 0, snd_incr, snd_decr)
2126 #define POSTGIVE_VALUE(e,f,t,snd_incr,snd_decr) GiveSound((e), save_##f, (e).f, t, snd_incr, snd_decr)
2127 #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)
2129 float GiveItems(entity e, float beginarg, float endarg)
2131 float got, i, j, val, op;
2132 float _switchweapon;
2141 _switchweapon = FALSE;
2143 if (e.switchweapon == w_getbestweapon(e))
2144 _switchweapon = TRUE;
2146 e.strength_finished = max(0, e.strength_finished - time);
2147 e.invincible_finished = max(0, e.invincible_finished - time);
2148 e.superweapons_finished = max(0, e.superweapons_finished - time);
2152 PREGIVE(e, strength_finished);
2153 PREGIVE(e, invincible_finished);
2154 PREGIVE(e, superweapons_finished);
2155 PREGIVE(e, ammo_nails);
2156 PREGIVE(e, ammo_cells);
2157 PREGIVE(e, ammo_shells);
2158 PREGIVE(e, ammo_rockets);
2159 PREGIVE(e, ammo_fuel);
2160 PREGIVE(e, armorvalue);
2163 for(i = beginarg; i < endarg; ++i)
2167 if(cmd == "0" || stof(cmd))
2191 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
2192 got += GiveValue(e, strength_finished, op, val);
2193 got += GiveValue(e, invincible_finished, op, val);
2194 got += GiveValue(e, superweapons_finished, op, val);
2195 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
2197 got += GiveBit(e, items, IT_JETPACK, op, val);
2198 got += GiveValue(e, health, op, val);
2199 got += GiveValue(e, armorvalue, op, val);
2201 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2203 wi = get_weaponinfo(j);
2205 if not(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED)
2206 got += GiveWeapon(e, j, op, val);
2209 got += GiveValue(e, ammo_cells, op, val);
2210 got += GiveValue(e, ammo_shells, op, val);
2211 got += GiveValue(e, ammo_nails, op, val);
2212 got += GiveValue(e, ammo_rockets, op, val);
2213 got += GiveValue(e, ammo_fuel, op, val);
2215 case "unlimited_ammo":
2216 got += GiveBit(e, items, IT_UNLIMITED_AMMO, op, val);
2218 case "unlimited_weapon_ammo":
2219 got += GiveBit(e, items, IT_UNLIMITED_WEAPON_AMMO, op, val);
2221 case "unlimited_superweapons":
2222 got += GiveBit(e, items, IT_UNLIMITED_SUPERWEAPONS, op, val);
2225 got += GiveBit(e, items, IT_JETPACK, op, val);
2228 got += GiveBit(e, items, IT_FUEL_REGEN, op, val);
2231 got += GiveValue(e, strength_finished, op, val);
2234 got += GiveValue(e, invincible_finished, op, val);
2236 case "superweapons":
2237 got += GiveValue(e, superweapons_finished, op, val);
2240 got += GiveValue(e, ammo_cells, op, val);
2243 got += GiveValue(e, ammo_shells, op, val);
2247 got += GiveValue(e, ammo_nails, op, val);
2250 got += GiveValue(e, ammo_rockets, op, val);
2253 got += GiveValue(e, health, op, val);
2256 got += GiveValue(e, armorvalue, op, val);
2259 got += GiveValue(e, ammo_fuel, op, val);
2262 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2264 wi = get_weaponinfo(j);
2265 if(cmd == wi.netname)
2267 got += GiveWeapon(e, j, op, val);
2272 print("give: invalid item ", cmd, "\n");
2279 POSTGIVE_BIT(e, items, IT_FUEL_REGEN, "misc/itempickup.wav", string_null);
2280 POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, "misc/powerup.wav", "misc/poweroff.wav");
2281 POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, "misc/powerup.wav", "misc/poweroff.wav");
2282 POSTGIVE_BIT(e, items, IT_JETPACK, "misc/itempickup.wav", string_null);
2283 for(j = WEP_FIRST; j <= WEP_LAST; ++j)
2285 wi = get_weaponinfo(j);
2288 POSTGIVE_WEAPON(e, j, "weapons/weaponpickup.wav", string_null);
2289 if not(WEPSET_CONTAINS_AW(save_weapons, j))
2290 if(WEPSET_CONTAINS_EW(e, j))
2291 weapon_action(wi.weapon, WR_PRECACHE);
2294 POSTGIVE_VALUE(e, strength_finished, 1, "misc/powerup.wav", "misc/poweroff.wav");
2295 POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", "misc/poweroff.wav");
2296 POSTGIVE_VALUE(e, ammo_nails, 0, "misc/itempickup.wav", string_null);
2297 POSTGIVE_VALUE(e, ammo_cells, 0, "misc/itempickup.wav", string_null);
2298 POSTGIVE_VALUE(e, ammo_shells, 0, "misc/itempickup.wav", string_null);
2299 POSTGIVE_VALUE(e, ammo_rockets, 0, "misc/itempickup.wav", string_null);
2300 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);
2301 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);
2302 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);
2304 if(e.superweapons_finished <= 0)
2305 if(WEPSET_CONTAINS_ANY_EA(self, WEPBIT_SUPERWEAPONS))
2306 e.superweapons_finished = autocvar_g_balance_superweapons_time;
2310 e.health = bound(0, e.health, 100);
2311 e.armorvalue = bound(0, e.armorvalue, 999);
2314 if(e.strength_finished <= 0)
2315 e.strength_finished = 0;
2317 e.strength_finished += time;
2318 if(e.invincible_finished <= 0)
2319 e.invincible_finished = 0;
2321 e.invincible_finished += time;
2322 if(e.superweapons_finished <= 0)
2323 e.superweapons_finished = 0;
2325 e.superweapons_finished += time;
2327 if not(WEPSET_CONTAINS_EW(e, e.switchweapon))
2328 _switchweapon = TRUE;
2330 W_SwitchWeapon_Force(e, w_getbestweapon(e));