]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/tturrets/system/system_main.qc
Move turrets death and gib to client (now zero network use for those events)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / tturrets / system / system_main.qc
index e65d3897e774435a87861a5151208963fbdd7505..fb79f5442fffd036ba08b56425209ffc9f57e6e8 100644 (file)
@@ -1,19 +1,9 @@
 #define cvar_base "g_turrets_unit_"
 
-float TNSF_UPDATE       = 2;
-float TNSF_STATUS       = 4;
-float TNSF_SETUP        = 8;
-
-float TNSF_ANG1         = 16;
-float TNSF_AVEL1        = 32;
-float TNSF_ANG2         = 64;
-float TNSF_AVEL2        = 128;
-
-float TNSF_FULL_UPDATE  = 16777215;
 float turret_send(entity to, float sf)
 {
-       WriteByte(MSG_ENTITY, ENT_CLIENT_TURRET);
-       
+       dprint("Sending update\n");
+       WriteByte(MSG_ENTITY, ENT_CLIENT_TURRET);    
        WriteByte(MSG_ENTITY, sf);
        if(sf & TNSF_SETUP)
        {
@@ -27,18 +17,22 @@ float turret_send(entity to, float sf)
            WriteAngle(MSG_ENTITY, self.angles_y);
     }
     
-    if(sf & TNSF_UPDATE)
+    if(sf & TNSF_ANG)
+    {
+        WriteShort(MSG_ENTITY, rint(self.tur_head.angles_x));
+        WriteShort(MSG_ENTITY, rint(self.tur_head.angles_y));
+    }
+    
+    if(sf & TNSF_AVEL)
     {        
-        WriteAngle(MSG_ENTITY, self.tur_head.angles_x);
-           WriteAngle(MSG_ENTITY, self.tur_head.angles_y);         
-           WriteAngle(MSG_ENTITY, self.tur_head.avelocity_x);
-           WriteAngle(MSG_ENTITY, self.tur_head.avelocity_y);
+        WriteShort(MSG_ENTITY, rint(self.tur_head.avelocity_x));
+        WriteShort(MSG_ENTITY, rint(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;
@@ -222,6 +216,7 @@ vector turret_fovsearch_random()
 ** Handles head rotation according to
 ** the units .track_type and .track_flags
 **/
+.float turret_framecounter;
 void turret_stdproc_track()
 {
     vector target_angle; // This is where we want to aim
@@ -280,8 +275,8 @@ void turret_stdproc_track()
             }
             
             // CSQC
-            if(self.SendEntity)
-                self.SendFlags  = TNSF_STATUS;
+            self.SendFlags  = TNSF_ANG;
+            
             return;
 
         case TFL_TRACKTYPE_FLUIDINERTIA:
@@ -307,12 +302,16 @@ void turret_stdproc_track()
         {
             self.tur_head.avelocity_x = 0;
             self.tur_head.angles_x = self.aim_maxpitch;
+            
+            self.SendFlags  |= TNSF_ANG;
         }
         
         if((self.tur_head.angles_x + self.tur_head.avelocity_x * self.ticrate) < -self.aim_maxpitch)
         {
             self.tur_head.avelocity_x = 0;
             self.tur_head.angles_x = -self.aim_maxpitch;
+                        
+            self.SendFlags  |= TNSF_ANG;
         }
     }
 
@@ -325,14 +324,28 @@ void turret_stdproc_track()
         {
             self.tur_head.avelocity_y = 0;
             self.tur_head.angles_y = self.aim_maxrot;
+            
+            self.SendFlags  |= TNSF_ANG;
         }
 
         if((self.tur_head.angles_y + self.tur_head.avelocity_y * self.ticrate) < -self.aim_maxrot)
         {
             self.tur_head.avelocity_y = 0;
             self.tur_head.angles_y = -self.aim_maxrot;
+            
+            self.SendFlags  |= TNSF_ANG;
         }
     }
+        
+    self.SendFlags  |= TNSF_AVEL;
+    
+    // Force a angle update every 10'th frame
+    self.turret_framecounter += 1;
+    if(self.turret_framecounter >= 10)
+    {        
+        self.SendFlags |= TNSF_ANG;
+        self.turret_framecounter = 0;
+    }            
 }
 
 
@@ -636,9 +649,10 @@ void turret_think()
     entity e;
 
     self.nextthink = time + self.ticrate;
-
+    //self.SendFlags = TNSF_UPDATE | TNSF_STATUS | TNSF_ANG | TNSF_AVEL;
+    
     // ONS uses somewhat backwards linking.
-    if (teams_matter)
+    if (teamplay)
     {
         if not (g_onslaught)
             if (self.target)
@@ -665,10 +679,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.
@@ -862,6 +872,7 @@ void turret_link()
     Net_LinkEntity(self, TRUE, 0, turret_send);
     self.think      = turret_think;
     self.nextthink  = time;
+    self.tur_head.effects = EF_NODRAW;
 }
 
 void turrets_manager_think()
@@ -892,7 +903,7 @@ void turrets_manager_think()
 * (unless you have a very good reason not to)
 * if the return value is 0, the turret should be removed.
 */
-float turret_stdproc_init (string cvar_base_name, float csqc_shared, string base, string head, float _turret_type)
+float turret_stdproc_init (string cvar_base_name, string base, string head, float _turret_type)
 {
        entity e, ee;
 
@@ -963,7 +974,7 @@ float turret_stdproc_init (string cvar_base_name, float csqc_shared, string base
         if not (self.team)
             self.team = 14; // Assume turrets are on the defending side if not explicitly set otehrwize
     }
-    else if not (teams_matter)
+    else if not (teamplay)
                self.team = MAX_SHOT_DISTANCE; // Group all turrets into the same team, so they dont kill eachother.
        else if(g_onslaught && self.targetname)
        {
@@ -1146,7 +1157,6 @@ float turret_stdproc_init (string cvar_base_name, float csqc_shared, string base
 
     self.target_validate_flags = self.target_select_flags;
 
-
 // Ammo stuff
     if not (self.ammo_max)
         self.ammo_max = self.shot_dmg * 10;
@@ -1173,8 +1183,11 @@ float turret_stdproc_init (string cvar_base_name, float csqc_shared, string base
 
 // Offsets & origins
     if (!self.tur_shotorg)   self.tur_shotorg = '50 0 50';
+    
+    if (!self.health)
+        self.health = 150;
 
-// Gane hooks
+// Game hooks
        if(MUTATOR_CALLHOOK(TurretSpawn))
                return 0;
 
@@ -1195,9 +1208,6 @@ float turret_stdproc_init (string cvar_base_name, float csqc_shared, string base
     setorigin(self.tur_head, '0 0 0');
     setattachment(self.tur_head, self, "tag_head");
 
-    if (!self.health)
-        self.health = 150;
-
     self.tur_health          = self.health;
     self.solid               = SOLID_BBOX;
     self.tur_head.solid      = SOLID_NOT;
@@ -1224,25 +1234,15 @@ float turret_stdproc_init (string cvar_base_name, float csqc_shared, string base
     else
         self.idle_aim  = '0 0 0';
 
-    // Team color
-    if (self.team == COLOR_TEAM1) self.colormod = '1.4 0.8 0.8';
-    if (self.team == COLOR_TEAM2) self.colormod = '0.8 0.8 1.4';
-
     // Attach stdprocs. override when and what needed
+    self.turret_firecheckfunc   = turret_stdproc_firecheck;
+    self.turret_firefunc        = turret_stdproc_fire;
+    self.event_damage           = turret_stdproc_damage;
+    
     if (self.turrcaps_flags & TFL_TURRCAPS_SUPPORT)
-    {
         self.turret_score_target    = turret_stdproc_targetscore_support;
-        self.turret_firecheckfunc   = turret_stdproc_firecheck;
-        self.turret_firefunc        = turret_stdproc_fire;
-        self.event_damage           = turret_stdproc_damage;
-    }
     else
-    {
         self.turret_score_target    = turret_stdproc_targetscore_generic;
-        self.turret_firecheckfunc   = turret_stdproc_firecheck;
-        self.turret_firefunc        = turret_stdproc_fire;
-        self.event_damage           = turret_stdproc_damage;
-    }
 
     self.use = turret_stdproc_use;
     self.bot_attack = TRUE;
@@ -1279,13 +1279,10 @@ float turret_stdproc_init (string cvar_base_name, float csqc_shared, string base
     }
     
        turret_stdproc_respawn();
-       
-    // Initiate the main AI loop
-    if(csqc_shared)
-        self.think     = turret_link;
-    else
-        self.think     = turret_think;
-
+           
+    if (!turret_tag_fire_update())
+        dprint("Warning: Turret ",self.classname, " faild to initialize md3 tags\n");
+    
     return 1;
 }