]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make csqc turrets work. moving ones still do not
authorJakob MG <jakob_mg@hotmail.com>
Mon, 11 Apr 2011 19:14:56 +0000 (21:14 +0200)
committerJakob MG <jakob_mg@hotmail.com>
Mon, 11 Apr 2011 19:14:56 +0000 (21:14 +0200)
qcsrc/client/tturrets.qc
qcsrc/server/tturrets/include/turrets_early.qh
qcsrc/server/tturrets/system/system_main.qc

index dfbaa8f55dc9acd54de41f4b66a490ec47a0ee86..46c1c59dd98fba1f3a71c65a74c08701e95a94b7 100644 (file)
@@ -26,10 +26,12 @@ void turrets_precache()
     precache_sound ("weapons/uzi_fire.wav");
 }
 
-
+//.entity tur_base;
 void turret_remove()
 {
+    dprint("Removing turret type ", ftos(self.turret_type), "\n");
     remove(self.tur_head);
+    self.tur_head = world;
 }
 
 void turret_changeteam()
@@ -38,11 +40,11 @@ void turret_changeteam()
        switch(self.team)
        {
         case COLOR_TEAM1: // Red
-            self.colormod = '1.4 0.8 0.8';
+            self.colormod = '2 0.5 0.5';
             break;
 
         case COLOR_TEAM2: // Blue
-            self.colormod = '0.8 0.8 1.4';
+            self.colormod = '0.5 0.5 2';
             break;
 
         case COLOR_TEAM3: // Yellow
@@ -58,24 +60,36 @@ void turret_changeteam()
 }
 
 void turret_head_draw()
-{
-    self.drawmask = MASK_NORMAL;    
+{    
+    float dt;
+    dt = time - self.move_time;
+    self.move_time = time;
+    if(dt <= 0)
+        return;
+    
+    self.angles += dt * self.move_avelocity;    
+    self.drawmask = MASK_NORMAL;
 }
 
 void turret_draw()
 {
+    //float dt;
+    
+    if (self.health < 127)
+    if(random() < 0.25)
+        te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
+    
     self.drawmask = MASK_NORMAL;    
 }
 
-void(entity e, entity tagentity, string tagname) setattachment = #443;
-.entity tur_base;
+//void(entity e, entity tagentity, string tagname) setattachment = #443;
 void turret_construct()
 {
     string sbase, shead;
     vector _min, _max;
     
-    self.tur_head = spawn();
-    self.tur_base = spawn();
+    if(self.tur_head == world)
+        self.tur_head = spawn();
     
     sbase = "models/turrets/base.md3";
     _min = '-32 -32 0';
@@ -92,6 +106,8 @@ void turret_construct()
             break;
         case TID_FUSION:
             shead = "models/turrets/reactor.md3";
+            _min = '-34 -34 0';
+            _max = '34 34 90';
             break;
         case TID_HELLION:
             shead = "models/turrets/hellion.md3";
@@ -117,37 +133,40 @@ void turret_construct()
         case TID_TESLA:
             sbase = "models/turrets/tesla_base.md3";
             shead = "models/turrets/tesla_head.md3";
+            _min = '-60 -60 0';
+            _max  ='60 60 128';
             break;
         case TID_WALKER:
             sbase = "models/turrets/walker_body.md3";
             shead = "models/turrets/walker_head_minigun.md3";
+            _min = '-70 -70 0';
+            _max = '70 70 95';
             break;
     }
     
     setorigin(self, self.origin);
-    setorigin(self.tur_base, self.origin);
-    
+        
     self.tur_head.classname = "turret_head";
     self.tur_head.owner   = self;
-    self.tur_base.owner   = self;
 
-    setmodel(self.tur_base, sbase);
+    setmodel(self, sbase);
     setmodel(self.tur_head, shead);
-
-    setsize(self.tur_base, _min, _max);
+    
+    self.tur_head.move_movetype = MOVETYPE_NOCLIP;
+    self.move_movetype = MOVETYPE_NOCLIP;
+    
+    setsize(self, _min, _max);
     setsize(self.tur_head, '0 0 0', '0 0 0');
-    //setattachment(self.tur_head, self.tur_base, "tag_head");
-    setorigin(self.tur_head, self.origin + '0 0 32');
-    self.health = 255;
-
-    self.solid               = SOLID_BBOX;
-    self.tur_head.solid      = SOLID_NOT;
-    //self.takedamage          = DAMAGE_AIM;
-    self.tur_base.movetype            = MOVETYPE_NOCLIP;
-    self.tur_head.movetype   = MOVETYPE_NOCLIP;    
-    self.tur_base.draw = turret_draw;
-    self.tur_head.draw = turret_head_draw;
-    self.entremove = turret_remove;
+    
+    setorigin(self.tur_head, gettaginfo(self, gettagindex(self, "tag_head")));
+    self.health             = 255;
+    self.solid              = SOLID_BBOX;
+    self.tur_head.solid     = SOLID_NOT;
+    self.movetype           = MOVETYPE_NOCLIP;
+    self.tur_head.movetype  = MOVETYPE_NOCLIP;    
+    self.draw               = turret_draw;
+    self.tur_head.draw      = turret_head_draw;
+    self.entremove          = turret_remove;
 }
 
 void ent_turret()
@@ -156,8 +175,9 @@ void ent_turret()
     sf = ReadByte();
 
        if(sf & TNSF_SETUP)
-       {
+       {           
            self.turret_type = ReadByte();
+           dprint("Constructing turret type ", ftos(self.turret_type), "\n");
                    
            self.origin_x = ReadCoord();
            self.origin_y = ReadCoord();
@@ -171,20 +191,38 @@ void ent_turret()
     
     if(sf & TNSF_ANG)
     {
-        self.tur_head.angles_x = ReadAngle();
-        self.tur_head.angles_y = ReadAngle();
+        if(sf & TNSF_FAR)
+        {            
+            self.tur_head.move_angles_x = ReadShort();
+            self.tur_head.move_angles_y = ReadShort();
+        }
+        else
+        {
+            self.tur_head.move_angles_x = ReadAngle();
+            self.tur_head.move_angles_y = ReadAngle();
+        }        
+        self.tur_head.angles = self.angles + self.tur_head.move_angles;
     }
     
     if(sf & TNSF_AVEL)
-    {        
-        self.tur_head.avelocity_x = ReadAngle();
-        self.tur_head.avelocity_y = ReadAngle();
+    {
+        if(sf & TNSF_FAR)
+        {
+            self.tur_head.move_avelocity_x = ReadShort();
+            self.tur_head.move_avelocity_y = ReadShort();            
+        }
+        else
+        {            
+            self.tur_head.move_avelocity_x = ReadAngle();
+            self.tur_head.move_avelocity_y = ReadAngle();
+        }        
     }
     
     if(sf & TNSF_STATUS)
-    {
+    {        
         float _team;
         _team = ReadByte();
+        _team -= 1; // /&)=(%&#)&%)/#&)=½!!!½!!". thanks.
         self.health = ReadByte();
         if(_team != self.team)
         {
index 8c1278e1074a09268b19d54ed77189132707e84e..5b2bac46703e875179f49c60a0ae23b637b4a294 100644 (file)
@@ -488,6 +488,7 @@ float TNSF_STATUS       = 4;
 float TNSF_SETUP        = 8;
 float TNSF_ANG          = 16;
 float TNSF_AVEL         = 32;
+float TNSF_FAR          = 64;
 float TNSF_FULL_UPDATE  = 16777215;
 
 #endif // TTURRETS_ENABLED
index 702af575844250f3972fd90935a6412fa481d310..eb9c05dfe09e4833df259adc572219b4c8c0f10b 100644 (file)
@@ -2,6 +2,11 @@
 
 float turret_send(entity to, float sf)
 {
+    float dist;
+    dist = vlen(self.origin - to.origin);
+    if(dist > 1024) // When far away, write angles/avelocity as short insted of angle.
+        sf |= TNSF_FAR;
+        
        WriteByte(MSG_ENTITY, ENT_CLIENT_TURRET);
        
        WriteByte(MSG_ENTITY, sf);
@@ -18,21 +23,37 @@ float turret_send(entity to, float sf)
     }
     
     if(sf & TNSF_ANG)
-    {        
-        WriteAngle(MSG_ENTITY, self.tur_head.angles_x);
-           WriteAngle(MSG_ENTITY, self.tur_head.angles_y);         
+    {
+        if(sf & TNSF_FAR)
+        {
+            WriteShort(MSG_ENTITY, rint(self.tur_head.angles_x));
+            WriteShort(MSG_ENTITY, rint(self.tur_head.angles_y));
+        }
+        else
+        {            
+            WriteAngle(MSG_ENTITY, self.tur_head.angles_x);
+            WriteAngle(MSG_ENTITY, self.tur_head.angles_y);        
+        }
     }
     
     if(sf & TNSF_AVEL)
     {        
-           WriteAngle(MSG_ENTITY, self.tur_head.avelocity_x);
-           WriteAngle(MSG_ENTITY, self.tur_head.avelocity_y);
+        if(sf & TNSF_FAR)
+        {
+            WriteShort(MSG_ENTITY, rint(self.tur_head.avelocity_x));
+            WriteShort(MSG_ENTITY, rint(self.tur_head.avelocity_y));
+        }
+        else
+        {
+            WriteAngle(MSG_ENTITY, self.tur_head.avelocity_x);
+            WriteAngle(MSG_ENTITY, self.tur_head.avelocity_y);            
+        }
     }
     
     if(sf & TNSF_STATUS)
     {        
         WriteByte(MSG_ENTITY, self.team);
-        WriteByte(MSG_ENTITY, rint((self.health / self.tur_health) * 255));
+        WriteByte(MSG_ENTITY, rint((self.health / self.tur_health) * 255)); // Send health as 0-255 insted of real value, where 255 = 100%
     }
     
        return TRUE;
@@ -305,7 +326,7 @@ void turret_stdproc_track()
             self.tur_head.angles_x = self.aim_maxpitch;
             
             if(self.SendEntity)
-                self.SendFlags  |= TNSF_ANG | TNSF_AVEL;
+                self.SendFlags  |= TNSF_ANG;
         }
         
         if((self.tur_head.angles_x + self.tur_head.avelocity_x * self.ticrate) < -self.aim_maxpitch)
@@ -314,7 +335,7 @@ void turret_stdproc_track()
             self.tur_head.angles_x = -self.aim_maxpitch;
             
             if(self.SendEntity)
-                self.SendFlags  |= TNSF_ANG | TNSF_AVEL;
+                self.SendFlags  |= TNSF_ANG;
         }
     }
 
@@ -329,7 +350,7 @@ void turret_stdproc_track()
             self.tur_head.angles_y = self.aim_maxrot;
             
             if(self.SendEntity)
-                self.SendFlags  |= TNSF_ANG | TNSF_AVEL;
+                self.SendFlags  |= TNSF_ANG;
         }
 
         if((self.tur_head.angles_y + self.tur_head.avelocity_y * self.ticrate) < -self.aim_maxrot)
@@ -338,23 +359,22 @@ void turret_stdproc_track()
             self.tur_head.angles_y = -self.aim_maxrot;
             
             if(self.SendEntity)
-                self.SendFlags  |= TNSF_ANG | TNSF_AVEL;
+                self.SendFlags  |= TNSF_ANG;
         }
     }
-    
+        
     if(self.SendEntity)
     {        
+        self.SendFlags  |= TNSF_AVEL;
+        
+        // Push a angle update every 10'th frame
         self.turret_framecounter += 1;
-        if(self.turret_framecounter >= 4)
+        if(self.turret_framecounter >= 10)
         {
-            self.SendFlags  |= TNSF_ANG | TNSF_AVEL;
+            self.SendFlags  |= TNSF_ANG;
             self.turret_framecounter = 0;
-        }
-        else
-            self.SendFlags |= TNSF_AVEL;
-    }
-            
-
+        }            
+    }            
 }
 
 
@@ -658,7 +678,7 @@ void turret_think()
     entity e;
 
     self.nextthink = time + self.ticrate;
-    self.SendFlags = TNSF_UPDATE | TNSF_STATUS | TNSF_ANG | TNSF_AVEL;
+    //self.SendFlags = TNSF_UPDATE | TNSF_STATUS | TNSF_ANG | TNSF_AVEL;
     
     // ONS uses somewhat backwards linking.
     if (teams_matter)
@@ -688,10 +708,6 @@ void turret_think()
     if not (self.spawnflags & TSF_NO_AMMO_REGEN)
     if (self.ammo < self.ammo_max)
         self.ammo = min(self.ammo + self.ammo_recharge, self.ammo_max);
-
-    if (self.health < (self.tur_health * 0.5))
-               if(random() < 0.25)
-                       te_spark(self.origin + '0 0 40', randomvec() * 256 + '0 0 256', 16);
                        
     // Inactive turrets needs to run the think loop,
     // So they can handle animation and wake up if need be.