]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/t_items.qc
Add a new key to override the initial item respawn delay
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / t_items.qc
index 4d601d4e1045e4672ff6b0a90afa4ce245eca38d..876bc6347a5e9cc8c1d4a11decca8b61f6ae4ea3 100644 (file)
@@ -114,36 +114,36 @@ void ItemDrawSimple(entity this)
     Item_SetAlpha(this);
 }
 
-void Item_PreDraw()
-{SELFPARAM();
+void Item_PreDraw(entity this)
+{
        if(warpzone_warpzones_exist)
        {
                // just incase warpzones were initialized last, reset these
-               //self.alpha = 1; // alpha is already set by the draw function
-               self.drawmask = MASK_NORMAL;
+               //this.alpha = 1; // alpha is already set by the draw function
+               this.drawmask = MASK_NORMAL;
                return;
        }
        float alph;
        vector org = getpropertyvec(VF_ORIGIN);
-       if(!checkpvs(org, self)) // this makes sense as long as we don't support recursive warpzones
+       if(!checkpvs(org, this)) // this makes sense as long as we don't support recursive warpzones
                alph = 0;
-       else if(self.fade_start)
-               alph = bound(0, (self.fade_end - vlen(org - self.origin - 0.5 * (self.mins + self.maxs))) / (self.fade_end - self.fade_start), 1);
+       else if(this.fade_start)
+               alph = bound(0, (this.fade_end - vlen(org - this.origin - 0.5 * (this.mins + this.maxs))) / (this.fade_end - this.fade_start), 1);
        else
                alph = 1;
-       //printf("%v <-> %v\n", view_origin, self.origin + 0.5 * (self.mins + self.maxs));
-       if(!hud && (self.ItemStatus & ITS_AVAILABLE))
-               self.alpha = alph;
+       //printf("%v <-> %v\n", view_origin, this.origin + 0.5 * (this.mins + this.maxs));
+       if(!hud && (this.ItemStatus & ITS_AVAILABLE))
+               this.alpha = alph;
        if(alph <= 0)
-               self.drawmask = 0;
+               this.drawmask = 0;
        else
-               self.drawmask = MASK_NORMAL;
+               this.drawmask = MASK_NORMAL;
 }
 
-void ItemRemove()
-{SELFPARAM();
-       if (self.mdl)
-               strunzone(self.mdl);
+void ItemRemove(entity this)
+{
+       if(this.mdl)
+               strunzone(this.mdl);
 }
 
 NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
@@ -205,7 +205,7 @@ NET_HANDLE(ENT_CLIENT_ITEM, bool isnew)
         self.fade_end = ReadShort();
         self.fade_start = ReadShort();
         if(self.fade_start && !autocvar_cl_items_nofade)
-               self.predraw = Item_PreDraw;
+               setpredraw(self, Item_PreDraw);
 
         if(self.mdl)
             strunzone(self.mdl);
@@ -479,7 +479,7 @@ void Item_Think()
 }
 
 bool Item_ItemsTime_SpectatorOnly(GameItem it);
-bool Item_ItemsTime_Allow(GameItem it, WepSet _weapons);
+bool Item_ItemsTime_Allow(GameItem it);
 float Item_ItemsTime_UpdateTime(entity e, float t);
 void Item_ItemsTime_SetTime(entity e, float t);
 void Item_ItemsTime_SetTimesForAllPlayers();
@@ -496,7 +496,7 @@ void Item_Respawn ()
                sound (self, CH_TRIGGER, SND_ITEMRESPAWN, VOL_BASE, ATTEN_NORM);        // play respawn sound
        setorigin (self, self.origin);
 
-    if (Item_ItemsTime_Allow(self.itemdef, self.weapons))
+    if (Item_ItemsTime_Allow(self.itemdef) || self.weapons & WEPSET_SUPERWEAPONS)
        {
                float t = Item_ItemsTime_UpdateTime(self, 0);
                Item_ItemsTime_SetTime(self, t);
@@ -582,7 +582,7 @@ void Item_RespawnThink()
 
 void Item_ScheduleRespawnIn(entity e, float t)
 {
-       if (Item_ItemsTime_Allow(e.itemdef, e.weapons))
+       if (Item_ItemsTime_Allow(e.itemdef) || e.weapons & WEPSET_SUPERWEAPONS)
        {
                e.think = Item_RespawnCountdown;
                e.nextthink = time + max(0, t - ITEM_RESPAWN_TICKS);
@@ -615,7 +615,7 @@ void Item_ScheduleRespawn(entity e)
 void Item_ScheduleInitialRespawn(entity e)
 {
        Item_Show(e, 0);
-       Item_ScheduleRespawnIn(e, game_starttime - time + ITEM_RESPAWNTIME_INITIAL(e));
+       Item_ScheduleRespawnIn(e, game_starttime - time + ((e.respawntimestart) ? e.respawntimestart : ITEM_RESPAWNTIME_INITIAL(e)));
 }
 
 float Item_GiveAmmoTo(entity item, entity player, .float ammotype, float ammomax, float mode)
@@ -707,6 +707,14 @@ float Item_GiveTo(entity item, entity player)
                }
        }
 
+       if (item.itemdef.instanceOfPowerup)
+       {
+               if ((item.itemdef == ITEM_JetpackRegen) && !(player.items & IT_FUEL_REGEN))
+                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_FUELREGEN_GOT);
+               else if ((item.itemdef == ITEM_Jetpack) && !(player.items & IT_JETPACK))
+                       Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_ITEM_JETPACK_GOT);
+       }
+
        int its;
        if((its = (item.items - (item.items & player.items)) & IT_PICKUPMASK))
        {
@@ -856,40 +864,44 @@ void Item_Reset_self() { SELFPARAM(); Item_Reset(this); }
 
 void Item_FindTeam()
 {SELFPARAM();
-       entity head, e;
+       entity e;
 
        if(self.effects & EF_NODRAW)
        {
                // marker for item team search
                LOG_TRACE("Initializing item team ", ftos(self.team), "\n");
                RandomSelection_Init();
-               for(head = world; (head = findfloat(head, team, self.team)); )
-               if(head.flags & FL_ITEM)
-               if(head.classname != "item_flag_team" && head.classname != "item_key_team")
-                       RandomSelection_Add(head, 0, string_null, head.cnt, 0);
+               FOREACH_ENTITY_FLOAT(team, self.team,
+               {
+                       if(it.flags & FL_ITEM)
+                       if(it.classname != "item_flag_team" && it.classname != "item_key_team")
+                               RandomSelection_Add(it, 0, string_null, it.cnt, 0);
+               });
+
                e = RandomSelection_chosen_ent;
                e.state = 0;
                Item_Show(e, 1);
 
-               for(head = world; (head = findfloat(head, team, self.team)); )
-               if(head.flags & FL_ITEM)
-               if(head.classname != "item_flag_team" && head.classname != "item_key_team")
+               FOREACH_ENTITY_FLOAT(team, self.team,
                {
-                       if(head != e)
+                       if(it.flags & FL_ITEM)
+                       if(it.classname != "item_flag_team" && it.classname != "item_key_team")
                        {
-                               // make it a non-spawned item
-                               Item_Show(head, -1);
-                               head.state = 1; // state 1 = initially hidden item
+                               if(it != e)
+                               {
+                                       // make it non-spawned
+                                       Item_Show(it, -1);
+                                       it.state = 1; // state 1 = initially hidden item, apparently
+                               }
+                               it.effects &= ~EF_NODRAW;
                        }
-                       head.effects &= ~EF_NODRAW;
-               }
+               });
 
                Item_Reset(self);
        }
 }
 
 // Savage: used for item garbage-collection
-// TODO: perhaps nice special effect?
 void RemoveItem()
 {SELFPARAM();
        if(wasfreed(self) || !self) { return; }
@@ -1524,7 +1536,7 @@ spawnfunc(target_items)
                if(self.ammo_plasma != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_plasma), "plasma");
                if(self.ammo_fuel != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.ammo_fuel), "fuel");
                if(self.health != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "health");
-               if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.health), "armor");
+               if(self.armorvalue != 0) self.netname = sprintf("%s %s%d %s", self.netname, valueprefix, max(0, self.armorvalue), "armor");
                FOREACH(Weapons, it != WEP_Null, LAMBDA(self.netname = sprintf("%s %s%d %s", self.netname, itemprefix, !!(self.weapons & (it.m_wepset)), it.netname)));
        }
        self.netname = strzone(self.netname);
@@ -1605,19 +1617,19 @@ float GiveWeapon(entity e, float wpn, float op, float val)
        return (v0 != v1);
 }
 
-void GiveSound(entity e, float v0, float v1, float t, string snd_incr, string snd_decr)
+void GiveSound(entity e, float v0, float v1, float t, Sound snd_incr, Sound snd_decr)
 {
        if(v1 == v0)
                return;
        if(v1 <= v0 - t)
        {
-               if(snd_decr != "")
-                       _sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
+               if(snd_decr != NULL)
+                       sound (e, CH_TRIGGER, snd_decr, VOL_BASE, ATTEN_NORM);
        }
        else if(v0 >= v0 + t)
        {
-               if(snd_incr != "")
-                       _sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
+               if(snd_incr != NULL)
+                       sound (e, CH_TRIGGER, snd_incr, VOL_BASE, ATTEN_NORM);
        }
 }
 
@@ -1775,26 +1787,26 @@ float GiveItems(entity e, float beginarg, float endarg)
                op = OP_SET;
        }
 
-       POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND(ITEMPICKUP), string_null);
-       POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND(POWERUP), SND(POWEROFF));
-       POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND(POWERUP), SND(POWEROFF));
-       POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND(ITEMPICKUP), string_null);
+       POSTGIVE_BIT(e, items, ITEM_JetpackRegen.m_itemid, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_BIT(e, items, IT_UNLIMITED_SUPERWEAPONS, SND_POWERUP, SND_POWEROFF);
+       POSTGIVE_BIT(e, items, IT_UNLIMITED_WEAPON_AMMO, SND_POWERUP, SND_POWEROFF);
+       POSTGIVE_BIT(e, items, ITEM_Jetpack.m_itemid, SND_ITEMPICKUP, SND_Null);
        FOREACH(Weapons, it != WEP_Null, LAMBDA(
-               POSTGIVE_WEAPON(e, it, SND(WEAPONPICKUP), string_null);
+               POSTGIVE_WEAPON(e, it, SND_WEAPONPICKUP, SND_Null);
                if(!(save_weapons & (it.m_wepset)))
                        if(e.weapons & (it.m_wepset))
                                it.wr_init(it);
        ));
-       POSTGIVE_VALUE(e, strength_finished, 1, SND(POWERUP), SND(POWEROFF));
-       POSTGIVE_VALUE(e, invincible_finished, 1, "misc/powerup_shield.wav", SND(POWEROFF));
-       POSTGIVE_VALUE(e, ammo_nails, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE(e, ammo_cells, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE(e, ammo_plasma, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE(e, ammo_shells, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE(e, ammo_rockets, 0, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND(ITEMPICKUP), string_null);
-       POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND(ARMOR25), string_null);
-       POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND(MEGAHEALTH), string_null);
+       POSTGIVE_VALUE(e, strength_finished, 1, SND_POWERUP, SND_POWEROFF);
+       POSTGIVE_VALUE(e, invincible_finished, 1, SND_Shield, SND_POWEROFF);
+       POSTGIVE_VALUE(e, ammo_nails, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE(e, ammo_cells, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE(e, ammo_plasma, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE(e, ammo_shells, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE(e, ammo_rockets, 0, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE_ROT(e, ammo_fuel, 1, pauserotfuel_finished, autocvar_g_balance_pause_fuel_rot, pauseregen_finished, autocvar_g_balance_pause_fuel_regen, SND_ITEMPICKUP, SND_Null);
+       POSTGIVE_VALUE_ROT(e, armorvalue, 1, pauserotarmor_finished, autocvar_g_balance_pause_armor_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_ARMOR25, SND_Null);
+       POSTGIVE_VALUE_ROT(e, health, 1, pauserothealth_finished, autocvar_g_balance_pause_health_rot, pauseregen_finished, autocvar_g_balance_pause_health_regen, SND_MEGAHEALTH, SND_Null);
 
        if(e.superweapons_finished <= 0)
                if(self.weapons & WEPSET_SUPERWEAPONS)