]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/t_items.qc
Merge branch 'master' into Mario/turrets
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / t_items.qc
index fcc8c0cf30d5d6b9c955b47618909592deaa7a45..238c6cec506240d758fb262853bb3345f7b9dbf4 100644 (file)
@@ -23,42 +23,42 @@ var float  autocvar_cl_fullbright_items = 0;
 var vector autocvar_cl_weapon_stay_color = '2 0.5 0.5';
 var float  autocvar_cl_weapon_stay_alpha = 0.75;
 var float  autocvar_cl_simple_items = 0;
-var string autocvr_cl_simpleitems_postfix = "_simple";
+var string autocvar_cl_simpleitems_postfix = "_simple";
 .float  spawntime;
 .float  gravity;
 .vector colormod;
 void ItemDraw()
-{    
+{
     if(self.gravity)
-    {        
+    {
         Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
-        if(self.move_flags & FL_ONGROUND) 
+        if(self.move_flags & FL_ONGROUND)
         { // For some reason move_avelocity gets set to '0 0 0' here ...
             self.oldorigin = self.origin;
             self.gravity = 0;
 
-            if(autocvar_cl_animate_items)   
-            { // ... so reset it if animations are requested. 
+            if(autocvar_cl_animate_items)
+            { // ... so reset it if animations are requested.
                 if(self.ItemStatus & ITS_ANIMATE1)
                     self.move_avelocity = '0 180 0';
-                
+
                 if(self.ItemStatus & ITS_ANIMATE2)
                     self.move_avelocity = '0 -90 0';
             }
         }
     }
     else if (autocvar_cl_animate_items)
-    {        
+    {
         if(self.ItemStatus & ITS_ANIMATE1)
         {
             self.angles += self.move_avelocity * frametime;
-            setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));        
-        }    
-        
+            setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));
+        }
+
         if(self.ItemStatus & ITS_ANIMATE2)
         {
             self.angles += self.move_avelocity * frametime;
-            setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));        
+            setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));
         }
     }
 }
@@ -66,9 +66,9 @@ void ItemDraw()
 void ItemDrawSimple()
 {
     if(self.gravity)
-    {        
-        Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);    
-        
+    {
+        Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
+
         if(self.move_flags & FL_ONGROUND)
             self.gravity = 0;
     }
@@ -86,19 +86,19 @@ void ItemRead(float _IsNew)
         setorigin(self, self.origin);
         self.oldorigin = self.origin;
     }
-    
-    if(sf & ISF_ANGLES) 
+
+    if(sf & ISF_ANGLES)
     {
         self.angles_x = ReadCoord();
         self.angles_y = ReadCoord();
-        self.angles_z = ReadCoord();        
+        self.angles_z = ReadCoord();
         self.move_angles = self.angles;
     }
-    
+
     if(sf & ISF_STATUS) // need to read/write status frist so model can handle simple, fb etc.
     {
-        self.ItemStatus = ReadByte();    
-        
+        self.ItemStatus = ReadByte();
+
         if(self.ItemStatus & ITS_AVAILABLE)
         {
             self.alpha = 1;
@@ -113,19 +113,19 @@ void ItemRead(float _IsNew)
             }
             else
                 self.alpha = -1;
-        }    
-        
+        }
+
         if(autocvar_cl_fullbright_items)
             if(self.ItemStatus & ITS_ALLOWFB)
                 self.effects |= EF_FULLBRIGHT;
-            
+
         if(self.ItemStatus & ITS_STAYWEP)
         {
             self.colormod = self.glowmod = autocvar_cl_weapon_stay_color;
             self.alpha = autocvar_cl_weapon_stay_alpha;
-            
+
         }
-        
+
         if(self.ItemStatus & ITS_POWERUP)
         {
             if(self.ItemStatus & ITS_AVAILABLE)
@@ -134,55 +134,55 @@ void ItemRead(float _IsNew)
                  self.effects &= ~(EF_ADDITIVE | EF_FULLBRIGHT);
         }
     }
-    
+
     if(sf & ISF_MODEL)
     {
         self.drawmask  = MASK_NORMAL;
         self.movetype  = MOVETYPE_NOCLIP;
         self.draw       = ItemDraw;
-        
+
         if(self.mdl)
             strunzone(self.mdl);
-        
+
         self.mdl = "";
         string _fn = ReadString();
-        
+
         if(autocvar_cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
         {
             string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
             self.draw = ItemDrawSimple;
-                    
-            
-            
-            if(fexists(sprintf("%s%s.md3", _fn2, autocvr_cl_simpleitems_postfix)))
-                self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvr_cl_simpleitems_postfix));
-            else if(fexists(sprintf("%s%s.dpm", _fn2, autocvr_cl_simpleitems_postfix)))
-                self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvr_cl_simpleitems_postfix));
-            else if(fexists(sprintf("%s%s.iqm", _fn2, autocvr_cl_simpleitems_postfix)))
-                self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvr_cl_simpleitems_postfix));
-            else if(fexists(sprintf("%s%s.obj", _fn2, autocvr_cl_simpleitems_postfix)))
-                self.mdl = strzone(sprintf("%s%s.obj", _fn2, autocvr_cl_simpleitems_postfix));
+
+
+
+            if(fexists(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix)))
+                self.mdl = strzone(sprintf("%s%s.md3", _fn2, autocvar_cl_simpleitems_postfix));
+            else if(fexists(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix)))
+                self.mdl = strzone(sprintf("%s%s.dpm", _fn2, autocvar_cl_simpleitems_postfix));
+            else if(fexists(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix)))
+                self.mdl = strzone(sprintf("%s%s.iqm", _fn2, autocvar_cl_simpleitems_postfix));
+            else if(fexists(sprintf("%s%s.obj", _fn2, autocvar_cl_simpleitems_postfix)))
+                self.mdl = strzone(sprintf("%s%s.obj", _fn2, autocvar_cl_simpleitems_postfix));
             else
             {
                 self.draw = ItemDraw;
                 dprint("Simple item requested for ", _fn, " but no model exsist for it\n");
             }
         }
-        
-        if(self.draw != ItemDrawSimple)        
-            self.mdl = strzone(_fn);                
-        
-        
+
+        if(self.draw != ItemDrawSimple)
+            self.mdl = strzone(_fn);
+
+
         if(self.mdl == "")
             dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, " tell tZork aboute this!\n");
-        
+
         precache_model(self.mdl);
         setmodel(self, self.mdl);
     }
-    
+
     if(sf & ISF_COLORMAP)
         self.colormap = ReadShort();
-    
+
     if(sf & ISF_DROP)
     {
         self.gravity = 1;
@@ -193,7 +193,7 @@ void ItemRead(float _IsNew)
         self.move_velocity_z = ReadCoord();
         self.velocity = self.move_velocity;
         self.move_origin = self.oldorigin;
-        
+
         if(!self.move_time)
         {
             self.move_time = time;
@@ -202,12 +202,12 @@ void ItemRead(float _IsNew)
         else
             self.move_time = max(self.move_time, time);
     }
-        
+
     if(autocvar_cl_animate_items)
-    {        
+    {
         if(self.ItemStatus & ITS_ANIMATE1)
             self.move_avelocity = '0 180 0';
-                
+
         if(self.ItemStatus & ITS_ANIMATE2)
             self.move_avelocity = '0 -90 0';
     }
@@ -223,8 +223,8 @@ float ItemSend(entity to, float sf)
         sf |= ISF_DROP;
     else
         sf &= ~ISF_DROP;
-       
-       WriteByte(MSG_ENTITY, ENT_CLIENT_ITEM); 
+
+       WriteByte(MSG_ENTITY, ENT_CLIENT_ITEM);
        WriteByte(MSG_ENTITY, sf);
 
        //WriteByte(MSG_ENTITY, self.cnt);
@@ -234,7 +234,7 @@ float ItemSend(entity to, float sf)
         WriteCoord(MSG_ENTITY, self.origin_y);
         WriteCoord(MSG_ENTITY, self.origin_z);
     }
-    
+
     if(sf & ISF_ANGLES)
     {
         WriteCoord(MSG_ENTITY, self.angles_x);
@@ -247,14 +247,14 @@ float ItemSend(entity to, float sf)
 
     if(sf & ISF_MODEL)
     {
-        
+
         if(self.mdl == "")
             dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, "exspect a crash just aboute now\n");
-        
+
         WriteString(MSG_ENTITY, self.mdl);
     }
-        
-        
+
+
     if(sf & ISF_COLORMAP)
         WriteShort(MSG_ENTITY, self.colormap);
 
@@ -264,7 +264,7 @@ float ItemSend(entity to, float sf)
         WriteCoord(MSG_ENTITY, self.velocity_y);
         WriteCoord(MSG_ENTITY, self.velocity_z);
     }
-        
+
     return TRUE;
 }
 
@@ -374,7 +374,7 @@ float Item_Customize()
 */
 
 void Item_Show (entity e, float mode)
-{    
+{
        e.effects &= ~(EF_ADDITIVE | EF_STARDUST | EF_FULLBRIGHT | EF_NODEPTHTEST);
        e.ItemStatus &= ~ITS_STAYWEP;
        if (mode > 0)
@@ -411,17 +411,17 @@ void Item_Show (entity e, float mode)
                e.spawnshieldtime = 1;
                e.ItemStatus &= ~ITS_AVAILABLE;
        }
-       
+
        if (e.items & IT_STRENGTH || e.items & IT_INVINCIBLE)
-           e.ItemStatus |= ITS_POWERUP;                
-       
+           e.ItemStatus |= ITS_POWERUP;
+
        if (autocvar_g_nodepthtestitems)
                e.effects |= EF_NODEPTHTEST;
-               
-    
+
+
     if (autocvar_g_fullbrightitems)
                e.ItemStatus |= ITS_ALLOWFB;
-       
+
        if (autocvar_sv_simple_items)
         e.ItemStatus |= ITS_ALLOWSI;
 
@@ -601,7 +601,7 @@ float Item_GiveTo(entity item, entity player)
        if (player.switchweapon == w_getbestweapon(player))
                _switchweapon = TRUE;
 
-       if not(player.weapons & WepSet_FromWeapon(player.switchweapon))
+       if (!(player.weapons & WepSet_FromWeapon(player.switchweapon)))
                _switchweapon = TRUE;
 
        pickedup |= Item_GiveAmmoTo(item, player, ammo_fuel, g_pickup_fuel_max, ITEM_MODE_FUEL);
@@ -651,7 +651,7 @@ float Item_GiveTo(entity item, entity player)
        }
 
 :skip
-       
+
        // always eat teamed entities
        if(item.team)
                pickedup = TRUE;
@@ -669,7 +669,7 @@ float Item_GiveTo(entity item, entity player)
 void Item_Touch (void)
 {
        entity e, head;
-       
+
        // remove the item if it's currnetly in a NODROP brush or hits a NOIMPACT surface (such as sky)
        if(self.classname == "droppedweapon")
        {
@@ -680,7 +680,7 @@ void Item_Touch (void)
                }
        }
 
-       if not(IS_PLAYER(other))
+       if (!IS_PLAYER(other))
                return;
        if (other.deadflag)
                return;
@@ -688,6 +688,8 @@ void Item_Touch (void)
                return;
        if (self.owner == other)
                return;
+       if (time < self.item_spawnshieldtime)
+               return;
 
        switch(MUTATOR_CALLHOOK(ItemTouch))
        {
@@ -723,7 +725,7 @@ void Item_Touch (void)
 
        if (self.classname == "droppedweapon")
                remove (self);
-       else if not(self.spawnshieldtime)
+       else if (!self.spawnshieldtime)
                return;
        else
        {
@@ -869,7 +871,7 @@ float commodity_pickupevalfunc(entity player, entity item)
        {
                wi = get_weaponinfo(i);
 
-               if not(player.weapons & WepSet_FromWeapon(i))
+               if (!(player.weapons & WepSet_FromWeapon(i)))
                        continue;
 
                if(wi.items & IT_SHELLS)
@@ -930,16 +932,16 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
 
        if(self.model == "")
                self.model = itemmodel;
-       
+
        if(self.model == "")
     {
         error(strcat("^1Tried to spawn ", itemname, " with no model!\n"));
         return;
     }
-        
+
        if(self.item_pickupsound == "")
                self.item_pickupsound = pickupsound;
-       
+
        if(!self.respawntime) // both need to be set
        {
                self.respawntime = defaultrespawntime;
@@ -951,7 +953,7 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
 
        if(weaponid)
                self.weapons = WepSet_FromWeapon(weaponid);
-       
+
        self.flags = FL_ITEM | itemflags;
 
        if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
@@ -1009,7 +1011,7 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
                        remove (self);
                        return;
                }
-               
+
                if(self.angles != '0 0 0')
             self.SendFlags |= ISF_ANGLES;
 
@@ -1090,8 +1092,8 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
        self.netname = itemname;
        self.touch = Item_Touch;
        setmodel(self, "null"); // precision set below
-       //self.effects |= EF_LOWPRECISION; 
-       
+       //self.effects |= EF_LOWPRECISION;
+
        if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
     {
         self.pos1 = '-16 -16 0';
@@ -1103,20 +1105,20 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
         self.pos2 = '16 16 32';
     }
     setsize (self, self.pos1, self.pos2);
-    
-    if(itemflags & FL_POWERUP) 
+
+    if(itemflags & FL_POWERUP)
         self.ItemStatus |= ITS_ANIMATE1;
-       
+
        if(self.armorvalue || self.health)
         self.ItemStatus |= ITS_ANIMATE2;
-       
+
        if(itemflags & FL_WEAPON)
        {
                if (self.classname != "droppedweapon") // if dropped, colormap is already set up nicely
             self.colormap = 1024; // color shirt=0 pants=0 grey
         else
             self.gravity = 1;
-            
+
                self.ItemStatus |= ITS_ANIMATE1;
                self.ItemStatus |= ISF_COLORMAP;
        }
@@ -1126,13 +1128,13 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
        {
                if(!self.cnt)
                        self.cnt = 1; // item probability weight
-                       
+
                self.effects |= EF_NODRAW; // marker for item team search
                InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
        }
        else
                Item_Reset();
-        
+
     Net_LinkEntity(self, FALSE, 0, ItemSend);
 
        // call this hook after everything else has been done
@@ -1486,7 +1488,7 @@ void target_items_use (void)
                return;
        }
 
-       if not(IS_PLAYER(activator))
+       if (!IS_PLAYER(activator))
                return;
        if(activator.deadflag != DEAD_NO)
                return;
@@ -1803,7 +1805,7 @@ float GiveItems(entity e, float beginarg, float endarg)
        e.strength_finished = max(0, e.strength_finished - time);
        e.invincible_finished = max(0, e.invincible_finished - time);
        e.superweapons_finished = max(0, e.superweapons_finished - time);
-       
+
        PREGIVE(e, items);
        PREGIVE_WEAPONS(e);
        PREGIVE(e, strength_finished);
@@ -1859,7 +1861,7 @@ float GiveItems(entity e, float beginarg, float endarg)
                                {
                                        wi = get_weaponinfo(j);
                                        if(wi.weapon)
-                                               if not(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED)
+                                               if (!(wi.spawnflags & WEP_FLAG_MUTATORBLOCKED))
                                                        got += GiveWeapon(e, j, op, val);
                                }
                        case "allammo":
@@ -1943,7 +1945,7 @@ float GiveItems(entity e, float beginarg, float endarg)
                if(wi.weapon)
                {
                        POSTGIVE_WEAPON(e, j, "weapons/weaponpickup.wav", string_null);
-                       if not(save_weapons & WepSet_FromWeapon(j))
+                       if (!(save_weapons & WepSet_FromWeapon(j)))
                                if(e.weapons & WepSet_FromWeapon(j))
                                        weapon_action(wi.weapon, WR_PRECACHE);
                }
@@ -1975,7 +1977,7 @@ float GiveItems(entity e, float beginarg, float endarg)
        else
                e.superweapons_finished += time;
 
-       if not(e.weapons & WepSet_FromWeapon(e.switchweapon))
+       if (!(e.weapons & WepSet_FromWeapon(e.switchweapon)))
                _switchweapon = TRUE;
        if(_switchweapon)
                W_SwitchWeapon_Force(e, w_getbestweapon(e));