]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/t_items.qc
wopsy
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / t_items.qc
index 11ed12129c3f6560d39c1e46ceb4445e03050661..0a3d756b74b357229311ad15de684f11a1567d42 100644 (file)
     #define ITS_POWERUP   64
 #define ISF_COLORMAP 16
 #define ISF_DROP 32
+#define ISF_ANGLES 64
 
 .float ItemStatus;
 
 #ifdef CSQC
 
-float autocvar_cl_ghost_items;
-vector autocvar_cl_ghost_items_color;
-float autocvar_cl_simple_items;
-float autocvar_cl_fullbright_items;
-vector autocvar_cl_staywep_color;
-float autocvar_cl_staywep_alpha;
-
-.float spawntime;
-.float gravity;
+var float  autocvar_cl_animate_items = 1;
+var float  autocvar_cl_ghost_items = 0.45;
+var vector autocvar_cl_ghost_items_color = '-1 -1 -1';
+float  autocvar_cl_fullbright_items;
+vector autocvar_cl_weapon_stay_color = '2 0.5 0.5';
+float  autocvar_cl_weapon_stay_alpha = 0.75;
+float  autocvar_cl_simple_items = 0;
+float  cl_simple_items;
+float  cl_ghost_items_alpha;
+
+.float  spawntime;
+.float  gravity;
 .vector colormod;
 void ItemDraw()
 {    
-    if(self.ItemStatus & ITS_ANIMATE1)
-    {
-        self.angles += '0 180 0' * frametime;
-        setorigin(self, '0 0 10' + self.oldorigin + '0 0 8' * sin(time * 2));        
-    }    
-    
-    if(self.ItemStatus & ITS_ANIMATE2)
-    {
-        self.angles += '0 -90 0' * frametime;
-        setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));        
-    }
-    
     if(self.gravity)
+    {        
         Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);
+        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(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));        
+        }    
+        
+        if(self.ItemStatus & ITS_ANIMATE2)
+        {
+            self.angles += self.move_avelocity * frametime;
+            setorigin(self, '0 0 8' + self.oldorigin + '0 0 4' * sin(time * 3));        
+        }
+    }
 }
 
 void ItemDrawSimple()
 {
     if(self.gravity)
+    {        
         Movetype_Physics_MatchServer(autocvar_cl_projectiles_sloppy);    
+        
+        if(self.move_flags & FL_ONGROUND)
+            self.gravity = 0;
+    }
 }
 
 float csqcitems_started; // remove this after a release or two
 void csqcitems_start()
 {
-    autocvar_cl_ghost_items =  bound(0, autocvar_cl_ghost_items, 1);
     if(autocvar_cl_ghost_items == 1)
-        autocvar_cl_ghost_items = 0.55;
-    
-    string _tmp = cvar_string("cl_ghost_items_color");
-    if(_tmp == "")
-        autocvar_cl_ghost_items_color = '-1 -1 -1';
-
+        cl_ghost_items_alpha = 0.55;
+    else
+        cl_ghost_items_alpha = bound(0, autocvar_cl_ghost_items, 1);
     
     csqcitems_started = TRUE;
 }
@@ -80,6 +103,14 @@ void ItemRead(float _IsNew)
         self.oldorigin = self.origin;
     }
     
+    if(sf & ISF_ANGLES) 
+    {
+        self.angles_x = ReadCoord();
+        self.angles_y = 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();    
@@ -91,7 +122,7 @@ void ItemRead(float _IsNew)
         }
         else
         {
-            if (autocvar_cl_ghost_items)
+            if (cl_ghost_items_alpha)
             {
                 self.alpha = autocvar_cl_ghost_items;
                 self.colormod = self.glowmod = autocvar_cl_ghost_items_color;
@@ -106,11 +137,10 @@ void ItemRead(float _IsNew)
             
         if(self.ItemStatus & ITS_STAYWEP)
         {
-            self.colormod = self.glowmod = autocvar_cl_staywep_color;
-            self.alpha = autocvar_cl_staywep_alpha;
+            self.colormod = self.glowmod = autocvar_cl_weapon_stay_color;
+            self.alpha = autocvar_cl_weapon_stay_alpha;
             
         }
-            
         
         if(self.ItemStatus & ITS_POWERUP)
         {
@@ -119,13 +149,13 @@ void ItemRead(float _IsNew)
             else
                  self.effects &~= (EF_ADDITIVE | EF_FULLBRIGHT);
         }
-            
     }
     
-    if(sf & ISF_MODEL) // handle simple items, fullbright and so on here
+    if(sf & ISF_MODEL)
     {
         self.drawmask  = MASK_NORMAL;
         self.movetype  = MOVETYPE_NOCLIP;
+        self.draw       = ItemDraw;
         
         if(self.mdl)
             strunzone(self.mdl);
@@ -133,11 +163,11 @@ void ItemRead(float _IsNew)
         self.mdl = "";
         string _fn = ReadString();
         
-        if(autocvar_cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
+        if(cl_simple_items && (self.ItemStatus & ITS_ALLOWSI))
         {
-            
             string _fn2 = substring(_fn, 0 , strlen(_fn) -4);
-                        
+            self.draw = ItemDrawSimple;
+                    
             if(fexists(strcat(_fn2, "_simple.md3")))
                 self.mdl = strzone(strcat(_fn2, "_simple.md3"));
             else if(fexists(strcat(_fn2, "_simple.dpm")))
@@ -148,18 +178,17 @@ void ItemRead(float _IsNew)
                 self.mdl = strzone(strcat(_fn2, "_simple.obj"));
             else
             {
-                self.mdl = "";
+                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.mdl == "")
-        {
-            self.mdl       = strzone(_fn);
-            self.draw      = ItemDraw;
-        }
-        else
-            self.draw      = ItemDrawSimple;
+            dprint("^1WARNING!^7 self.mdl is unset for item ", self.classname, " tell tZork aboute this!\n");
         
         precache_model(self.mdl);
         setmodel(self, self.mdl);
@@ -170,8 +199,8 @@ void ItemRead(float _IsNew)
     
     if(sf & ISF_DROP)
     {
-        self.effects |= EF_FLAME;
         self.gravity = 1;
+        self.move_angles = '0 0 0';
         self.move_movetype = MOVETYPE_TOSS;
         self.move_velocity_x = ReadCoord();
         self.move_velocity_y = ReadCoord();
@@ -187,8 +216,17 @@ 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';
+    }
 }
+
 #endif
 
 #ifdef SVQC
@@ -203,7 +241,6 @@ float ItemSend(entity to, float sf)
        WriteByte(MSG_ENTITY, ENT_CLIENT_ITEM); 
        WriteByte(MSG_ENTITY, sf);
 
-        
        //WriteByte(MSG_ENTITY, self.cnt);
     if(sf & ISF_LOCATION)
     {
@@ -211,12 +248,26 @@ 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);
+        WriteCoord(MSG_ENTITY, self.angles_y);
+        WriteCoord(MSG_ENTITY, self.angles_z);
+    }
 
     if(sf & ISF_STATUS)
         WriteByte(MSG_ENTITY, self.ItemStatus);
 
     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);
@@ -370,7 +421,7 @@ void Item_Show (entity e, float mode)
        }
        else
        {
-               setmodel(e, "null");
+               //setmodel(e, "null");
                e.solid = SOLID_NOT;
                e.colormod = '0 0 0';
                e.glowmod = e.colormod;
@@ -426,7 +477,7 @@ void Item_RespawnCountdown (void)
                if(self.count == 1)
                {
                        string name;
-                       vector rgb;
+                       vector rgb = '1 0 1';
                        name = string_null;
                        if(g_minstagib)
                        {
@@ -892,7 +943,8 @@ float weapon_pickupevalfunc(entity player, entity item)
 
 float commodity_pickupevalfunc(entity player, entity item)
 {
-       float c, i, need_shells, need_nails, need_rockets, need_cells, need_fuel;
+       float c, i;
+       float need_shells = FALSE, need_nails = FALSE, need_rockets = FALSE, need_cells = FALSE, need_fuel = FALSE;
        entity wi;
        c = 0;
 
@@ -962,8 +1014,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;
@@ -975,6 +1035,7 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
 
        if(weaponid)
                WEPSET_COPY_EW(self, weaponid);
+       
        self.flags = FL_ITEM | itemflags;
 
        if(MUTATOR_CALLHOOK(FilterItem)) // error means we do not want the item
@@ -1032,6 +1093,9 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
                        remove (self);
                        return;
                }
+               
+               if(self.angles != '0 0 0')
+            self.SendFlags |= ISF_ANGLES;
 
                self.reset = Item_Reset;
                // it's a level item
@@ -1075,6 +1139,7 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
                        entity otheritem;
                        for(otheritem = findradius(self.origin, 3); otheritem; otheritem = otheritem.chain)
                        {
+                           // why not flags & fl_item?
                                if(otheritem.is_item)
                                {
                                        dprint("XXX Found duplicated item: ", itemname, vtos(self.origin));
@@ -1108,13 +1173,20 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
        self.mdl = self.model;
        self.netname = itemname;
        self.touch = Item_Touch;
-       setmodel (self, self.mdl); // precision set below
-       self.effects |= EF_LOWPRECISION;
+       setmodel(self, "null"); // precision set below
+       //self.effects |= EF_LOWPRECISION; 
        
        if((itemflags & FL_POWERUP) || self.health || self.armorvalue)
-           setsize (self, '-16 -16 0', '16 16 48');
+    {
+        self.pos1 = '-16 -16 0';
+        self.pos2 = '16 16 48';
+    }
        else
-               setsize (self, '-16 -16 0', '16 16 32');
+    {
+        self.pos1 = '-16 -16 0';
+        self.pos2 = '16 16 32';
+    }
+    setsize (self, self.pos1, self.pos2);
     
     if(itemflags & FL_POWERUP) 
         self.ItemStatus |= ITS_ANIMATE1;
@@ -1126,28 +1198,26 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
        {
                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;
        }
 
        self.state = 0;
-       if(self.team)
+       if(self.team) // broken, no idea why.
        {
                if(!self.cnt)
                        self.cnt = 1; // item probability weight
-               self.effects = self.effects | EF_NODRAW; // marker for item team search
+                       
+               self.effects |= EF_NODRAW; // marker for item team search
                InitializeEntity(self, Item_FindTeam, INITPRIO_FINDTARGET);
        }
        else
                Item_Reset();
         
     Net_LinkEntity(self, FALSE, 0, ItemSend);
-
-    if(self.classname == "droppedweapon")
-        self.gravity = 1;
-        //self.SendFlags &~= ISF_DROP;
-
 }
 
 /* replace items in minstagib
@@ -1155,10 +1225,10 @@ void StartItem (string itemmodel, string pickupsound, float defaultrespawntime,
  * IT_NAILS     = extra lives
  * IT_INVINCIBLE = speed
  */
-void minstagib_items (float itemid)
+void minstagib_items (float itemid) // will be deleted soon.
 {
        float rnd;
-       self.classname = "minstagib";
+       self.classname = "minstagib"; // ...?
 
        // replace rocket launchers and nex guns with ammo cells
        if (itemid == IT_CELLS)
@@ -1586,7 +1656,7 @@ void spawnfunc_item_invincible (void) {
 void spawnfunc_item_minst_cells (void) {
        if (g_minstagib)
        {
-               minst_no_auto_cells = 1;
+               minst_no_auto_cells = TRUE;
                minstagib_items(IT_CELLS);
        }
        else
@@ -1659,19 +1729,21 @@ void spawnfunc_target_items (void)
                        else if(argv(i) == "jetpack")                self.items |= IT_JETPACK;
                        else if(argv(i) == "fuel_regen")             self.items |= IT_FUEL_REGEN;
                        else
-                       for(j = WEP_FIRST; j <= WEP_LAST; ++j)
                        {
-                               e = get_weaponinfo(j);
-                               if(argv(i) == e.netname)
+                               for(j = WEP_FIRST; j <= WEP_LAST; ++j)
                                {
-                                       WEPSET_OR_EW(self, j);
-                                       if(self.spawnflags == 0 || self.spawnflags == 2)
-                                               weapon_action(e.weapon, WR_PRECACHE);
-                                       break;
+                                       e = get_weaponinfo(j);
+                                       if(argv(i) == e.netname)
+                                       {
+                                               WEPSET_OR_EW(self, j);
+                                               if(self.spawnflags == 0 || self.spawnflags == 2)
+                                                       weapon_action(e.weapon, WR_PRECACHE);
+                                               break;
+                                       }
                                }
+                               if(j > WEP_LAST)
+                                       print("target_items: invalid item ", argv(i), "\n");
                        }
-                       if(j > WEP_LAST)
-                               print("target_items: invalid item ", argv(i), "\n");
                }
 
                string itemprefix, valueprefix;