#include "t_items.qh"
+#include "../common/items/all.qc"
+
#if defined(SVQC)
#include "_all.qh"
- #include "g_subs.qh"
#include "waypointsprites.qh"
#include "bot/bot.qh"
#include "../common/constants.qh"
#include "../common/deathtypes.qh"
#include "../common/notifications.qh"
+ #include "../common/triggers/subs.qh"
#include "../common/util.qh"
- #include "../common/monsters/monsters.qh"
+ #include "../common/monsters/all.qh"
- #include "../common/weapons/weapons.qh"
+ #include "../common/weapons/all.qh"
#include "../warpzonelib/util_server.qh"
#endif
}
}
+float it_armor_large_time;
+float it_health_mega_time;
+float it_invisible_time;
+float it_speed_time;
+float it_extralife_time;
+float it_strength_time;
+float it_shield_time;
+float it_fuelregen_time;
+float it_jetpack_time;
+float it_superweapons_time;
+
+void Item_ItemsTime_Init()
+{
+ it_armor_large_time = -1;
+ it_health_mega_time = -1;
+ it_invisible_time = -1;
+ it_speed_time = -1;
+ it_extralife_time = -1;
+ it_strength_time = -1;
+ it_shield_time = -1;
+ it_fuelregen_time = -1;
+ it_jetpack_time = -1;
+ it_superweapons_time = -1;
+}
+void Item_ItemsTime_ResetTimes()
+{
+ it_armor_large_time = (it_armor_large_time == -1) ? -1 : 0;
+ it_health_mega_time = (it_health_mega_time == -1) ? -1 : 0;
+ it_invisible_time = (it_invisible_time == -1) ? -1 : 0;
+ it_speed_time = (it_speed_time == -1) ? -1 : 0;
+ it_extralife_time = (it_extralife_time == -1) ? -1 : 0;
+ it_strength_time = (it_strength_time == -1) ? -1 : 0;
+ it_shield_time = (it_shield_time == -1) ? -1 : 0;
+ it_fuelregen_time = (it_fuelregen_time == -1) ? -1 : 0;
+ it_jetpack_time = (it_jetpack_time == -1) ? -1 : 0;
+ it_superweapons_time= (it_superweapons_time== -1) ? -1 : 0;
+}
+void Item_ItemsTime_ResetTimesForPlayer(entity e)
+{
+ e.item_armor_large_time = (it_armor_large_time == -1) ? -1 : 0;
+ e.item_health_mega_time = (it_health_mega_time == -1) ? -1 : 0;
+ e.item_invisible_time = (it_invisible_time == -1) ? -1 : 0;
+ e.item_speed_time = (it_speed_time == -1) ? -1 : 0;
+ e.item_extralife_time = (it_extralife_time == -1) ? -1 : 0;
+ e.item_strength_time = (it_strength_time == -1) ? -1 : 0;
+ e.item_shield_time = (it_shield_time == -1) ? -1 : 0;
+ e.item_fuelregen_time = (it_fuelregen_time == -1) ? -1 : 0;
+ e.item_jetpack_time = (it_jetpack_time == -1) ? -1 : 0;
+ e.item_superweapons_time= (it_superweapons_time== -1) ? -1 : 0;
+}
+void Item_ItemsTime_SetTimesForPlayer(entity e)
+{
+ e.item_armor_large_time = it_armor_large_time;
+ e.item_health_mega_time = it_health_mega_time;
+ e.item_invisible_time = it_invisible_time;
+ e.item_speed_time = it_speed_time;
+ e.item_extralife_time = it_extralife_time;
+ e.item_strength_time = it_strength_time;
+ e.item_shield_time = it_shield_time;
+ e.item_fuelregen_time = it_fuelregen_time;
+ e.item_jetpack_time = it_jetpack_time;
+ e.item_superweapons_time = it_superweapons_time;
+}
+
+void Item_ItemsTime_SetTime(entity e, float t)
+{
+ if(!autocvar_sv_itemstime)
+ return;
+
+ if(g_instagib)
+ {
+ switch(e.items)
+ {
+ case IT_STRENGTH://"item-invis"
+ it_invisible_time = t;
+ break;
+ case IT_NAILS://"item-extralife"
+ it_extralife_time = t;
+ break;
+ case IT_INVINCIBLE://"item-speed"
+ it_speed_time = t;
+ break;
+ }
+ }
+ else
+ {
+ switch(e.items)
+ {
+ case IT_HEALTH:
+ // if(e.classname == "item_health_mega") // IT_HEALTH unequivocally identifies it
+ it_health_mega_time = t;
+ break;
+ case IT_ARMOR:
+ if(e.classname == "item_armor_large") // IT_ARMOR doesn't unequivocally identifies it
+ it_armor_large_time = t;
+ break;
+ case IT_STRENGTH://"item-strength"
+ it_strength_time = t;
+ break;
+ case IT_INVINCIBLE://"item-shield"
+ it_shield_time = t;
+ break;
+ default:
+ if(e.weapons & WEPSET_SUPERWEAPONS)
+ it_superweapons_time = t;
+ }
+ }
+ switch(e.items)
+ {
+ case IT_FUEL_REGEN://"item-fuelregen"
+ it_fuelregen_time = t;
+ break;
+ case IT_JETPACK://"item-jetpack"
+ it_jetpack_time = t;
+ break;
+ }
+}
+void Item_ItemsTime_SetTimesForAllPlayers()
+{
+ entity e;
+ if(warmup_stage)
+ {
+ FOR_EACH_REALCLIENT(e)
+ Item_ItemsTime_SetTimesForPlayer(e);
+ }
+ else
+ {
+ FOR_EACH_REALCLIENT(e)
+ {
+ if(!IS_PLAYER(e))
+ Item_ItemsTime_SetTimesForPlayer(e);
+ }
+ }
+}
+
+float Item_ItemsTime_UpdateTime(entity e, float t)
+{
+ entity head;
+ bool isavailable = (t == 0);
+ if(e.weapons & WEPSET_SUPERWEAPONS)
+ {
+ for(head = world; (head = nextent(head)); )
+ {
+ if(clienttype(head) != CLIENTTYPE_NOTACLIENT || !(head.weapons & WEPSET_SUPERWEAPONS) || head.classname == "weapon_info")
+ continue;
+ if(e == head)
+ continue;
+
+ if(head.scheduledrespawntime <= time)
+ isavailable = true;
+ else if(t == 0 || head.scheduledrespawntime < t)
+ t = head.scheduledrespawntime;
+ }
+ }
+ else
+ {
+ for(head = world; (head = nextent(head)); )
+ {
+ if(head.itemdef != e.itemdef)
+ continue;
+ if(e == head)
+ continue;
+
+ if(head.scheduledrespawntime <= time)
+ isavailable = true;
+ else if(t == 0 || head.scheduledrespawntime < t)
+ t = head.scheduledrespawntime;
+ }
+ }
+ if(isavailable)
+ t = -t; // let know the client there's another available item
+ return t;
+}
+
void Item_Respawn (void)
{
Item_Show(self, 1);
sound (self, CH_TRIGGER, "misc/itemrespawn.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
setorigin (self, self.origin);
+ if(self.flags & FL_POWERUP || self.classname == "item_armor_large" || self.items == IT_HEALTH || (self.weapons & WEPSET_SUPERWEAPONS))
+ {
+ float t = Item_ItemsTime_UpdateTime(self, 0);
+ Item_ItemsTime_SetTime(self, t);
+ Item_ItemsTime_SetTimesForAllPlayers();
+ }
+
self.think = Item_Think;
self.nextthink = time;
case IT_JETPACK: name = "item-jetpack"; rgb = '0.5 0.5 0.5'; break;
case IT_STRENGTH: name = "item-strength"; rgb = '0 0 1'; break;
case IT_INVINCIBLE: name = "item-shield"; rgb = '1 0 1'; break;
+ case IT_HEALTH:
+ //if (self.classname == "item_health_mega")
+ {name = "item_health_mega"; rgb = '1 0 0';}
+ break;
+ case IT_ARMOR:
+ if (self.classname == "item_armor_large")
+ {name = "item_armor_large"; rgb = '0 1 0';}
+ break;
}
- item_name = name;
- item_color = rgb;
- MUTATOR_CALLHOOK(Item_RespawnCountdown);
+ MUTATOR_CALLHOOK(Item_RespawnCountdown, name, rgb);
name = item_name;
rgb = item_color;
if(self.flags & FL_WEAPON)
{
WaypointSprite_Spawn(name, 0, 0, self, '0 0 64', world, 0, self, waypointsprite_attached, true, RADARICON_POWERUP, rgb);
if(self.waypointsprite_attached)
+ {
+ if (self.items == IT_HEALTH || self.items == IT_ARMOR)
+ WaypointSprite_UpdateRule(self.waypointsprite_attached, 0, SPRITERULE_SPECTATOR);
WaypointSprite_UpdateBuildFinished(self.waypointsprite_attached, time + ITEM_RESPAWN_TICKS);
+ }
}
else
{
localcmd(sprintf("prvm_edict server %d\n", num_for_edict(self)));
}
}
- sound (self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
+
if(self.waypointsprite_attached)
{
+ entity e;
+ entity it = self;
+ self = self.waypointsprite_attached;
+ FOR_EACH_REALCLIENT(e)
+ if(self.waypointsprite_visible_for_player(e))
+ {
+ msg_entity = e;
+ soundto(MSG_ONE, it, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
+ }
+ self = it;
+
WaypointSprite_Ping(self.waypointsprite_attached);
//WaypointSprite_UpdateHealth(self.waypointsprite_attached, self.count);
}
+ else
+ sound(self, CH_TRIGGER, "misc/itemrespawncountdown.wav", VOL_BASE, ATTEN_NORM); // play respawn sound
}
}
void Item_ScheduleRespawnIn(entity e, float t)
{
- if((e.flags & FL_POWERUP) || (e.weapons & WEPSET_SUPERWEAPONS))
+ if((e.flags & FL_POWERUP) || (e.weapons & WEPSET_SUPERWEAPONS) || e.classname == "item_armor_large" || e.items == IT_HEALTH)
{
e.think = Item_RespawnCountdown;
e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
+ e.scheduledrespawntime = e.nextthink + ITEM_RESPAWN_TICKS;
e.count = 0;
+ t = Item_ItemsTime_UpdateTime(e, e.scheduledrespawntime);
+ Item_ItemsTime_SetTime(e, t);
+ Item_ItemsTime_SetTimesForAllPlayers();
}
else
{
e.think = Item_RespawnThink;
e.nextthink = time;
+ e.scheduledrespawntime = time + t;
e.wait = time + t;
}
}
if (time < self.item_spawnshieldtime)
return;
- switch(MUTATOR_CALLHOOK(ItemTouch))
+ switch(MUTATOR_CALLHOOK(ItemTouch, self, other))
{
case MUT_ITEMTOUCH_RETURN: { return; }
case MUT_ITEMTOUCH_PICKUP: { goto pickup; }
self.invincible_finished = max(0, self.invincible_finished - time);
self.superweapons_finished = max(0, self.superweapons_finished - time);
}
-
- if(!Item_GiveTo(self, other))
+ entity it = self.itemdef;
+ bool gave = (it && it.instanceOfPickup) ? ITEM_HANDLE(Pickup, it, self, other) : Item_GiveTo(self, other);
+ if (!gave)
{
if (self.classname == "droppedweapon")
{
if (self.classname == "droppedweapon")
remove (self);
- else if (!self.spawnshieldtime)
- return;
- else
+ else if (self.spawnshieldtime)
{
if(self.team)
{
if((itemflags & (FL_POWERUP | FL_WEAPON)) || (itemid & (IT_HEALTH | IT_ARMOR | IT_KEY1 | IT_KEY2)))
self.target = "###item###"; // for finding the nearest item using find()
+
+ Item_ItemsTime_SetTime(self, 0);
}
self.bot_pickup = true;
self.SendFlags |= ISF_ANGLES;
// call this hook after everything else has been done
- if(MUTATOR_CALLHOOK(Item_Spawn))
+ if(MUTATOR_CALLHOOK(Item_Spawn, self))
{
startitem_failed = true;
remove(self);
return;
}
}
+
+void StartItemA (entity a)
+{
+ self.itemdef = a;
+ StartItem(a.m_model, a.m_sound, a.m_respawntime(), a.m_respawntimejitter(), a.m_name, a.m_itemid, 0, a.m_itemflags, a.m_pickupevalfunc, a.m_botvalue);
+}
+
void spawnfunc_item_rockets (void) {
if(!self.ammo_rockets)
self.ammo_rockets = g_pickup_rockets;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_ammo_anyway;
- 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);
+ StartItemA (ITEM_Rockets);
}
void spawnfunc_item_bullets (void) {
self.ammo_nails = g_pickup_nails;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_ammo_anyway;
- 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);
+ StartItemA (ITEM_Bullets);
}
void spawnfunc_item_cells (void) {
self.ammo_cells = g_pickup_cells;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_ammo_anyway;
- 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);
+ StartItemA (ITEM_Cells);
}
void spawnfunc_item_plasma()
self.ammo_plasma = g_pickup_plasma;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_ammo_anyway;
- StartItem ("models/items/a_cells.md3", "misc/itempickup.wav", g_pickup_respawntime_ammo, g_pickup_respawntimejitter_ammo, "plasma", IT_PLASMA, 0, 0, commodity_pickupevalfunc, 2000);
+ StartItemA (ITEM_Plasma);
}
void spawnfunc_item_shells (void) {
self.ammo_shells = g_pickup_shells;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_ammo_anyway;
- 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);
+ StartItemA (ITEM_Shells);
}
void spawnfunc_item_armor_small (void) {
self.max_armorvalue = g_pickup_armorsmall_max;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_armorsmall_anyway;
- 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);
+ StartItemA (ITEM_ArmorSmall);
}
void spawnfunc_item_armor_medium (void) {
self.max_armorvalue = g_pickup_armormedium_max;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_armormedium_anyway;
- 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);
+ StartItemA (ITEM_ArmorMedium);
}
void spawnfunc_item_armor_big (void) {
self.max_armorvalue = g_pickup_armorbig_max;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_armorbig_anyway;
- 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);
+ StartItemA (ITEM_ArmorBig);
}
void spawnfunc_item_armor_large (void) {
self.max_armorvalue = g_pickup_armorlarge_max;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_armorlarge_anyway;
- 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);
+ StartItemA (ITEM_ArmorLarge);
}
void spawnfunc_item_health_small (void) {
self.health = g_pickup_healthsmall;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_healthsmall_anyway;
- 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);
+ StartItemA (ITEM_HealthSmall);
}
void spawnfunc_item_health_medium (void) {
self.health = g_pickup_healthmedium;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_healthmedium_anyway;
- 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);
+ StartItemA (ITEM_HealthMedium);
}
void spawnfunc_item_health_large (void) {
self.health = g_pickup_healthlarge;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_healthlarge_anyway;
- 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);
+ StartItemA (ITEM_HealthLarge);
}
void spawnfunc_item_health_mega (void) {
- if(!self.max_health)
- self.max_health = g_pickup_healthmega_max;
- if(!self.health)
- self.health = g_pickup_healthmega;
- if(!self.pickup_anyway)
- self.pickup_anyway = g_pickup_healthmega_anyway;
- 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);
+ if(!self.max_health)
+ self.max_health = g_pickup_healthmega_max;
+ if(!self.health)
+ self.health = g_pickup_healthmega;
+ if(!self.pickup_anyway)
+ self.pickup_anyway = g_pickup_healthmega_anyway;
+ StartItemA (ITEM_HealthMega);
}
// support old misnamed entities
precache_sound("weapons/strength_fire.wav");
if(!self.strength_finished)
self.strength_finished = autocvar_g_balance_powerup_strength_time;
- 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);
+ StartItemA (ITEM_Strength);
}
void spawnfunc_item_invincible (void) {
if(!self.invincible_finished)
self.invincible_finished = autocvar_g_balance_powerup_invincible_time;
- 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);
+ StartItemA (ITEM_Shield);
}
// compatibility:
self.ammo_fuel = g_pickup_fuel;
if(!self.pickup_anyway)
self.pickup_anyway = g_pickup_ammo_anyway;
- 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);
+ StartItemA (ITEM_JetpackFuel);
}
void spawnfunc_item_fuel_regen(void)
spawnfunc_item_fuel();
return;
}
- 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);
+ StartItemA (ITEM_JetpackRegen);
}
void spawnfunc_item_jetpack(void)
spawnfunc_item_fuel();
return;
}
- 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);
+ StartItemA (ITEM_Jetpack);
}
float GiveWeapon(entity e, float wpn, float op, float val)