]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'terencehill/ons_camera' into 'master'
authorMario <zacjardine@y7mail.com>
Fri, 21 Oct 2016 01:17:46 +0000 (01:17 +0000)
committerMario <zacjardine@y7mail.com>
Fri, 21 Oct 2016 01:17:46 +0000 (01:17 +0000)
Onslaught: improve generator's explosion view

* Make use of .clientcamera showing the exploding generator, this way vis is checked correctly
* Find best suitable angles for the generator's camera (particularly useful in runningmanctf)

See merge request !377

qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc
qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc

index a30dd7d07e1c2da7b91a20edf9478d4a15e8e0d4..afbd31842978a332d81c4a3d914a2202799fddae 100644 (file)
@@ -1,7 +1,31 @@
 #include "onslaught.qh"
 
+#ifndef MENUQC
+REGISTER_NET_LINKED(ENT_ONSCAMERA)
+#endif
+
 #ifdef CSQC
 
+entity generator_camera;
+NET_HANDLE(ENT_ONSCAMERA, bool isnew)
+{
+       this.origin_x = ReadCoord();
+       this.origin_y = ReadCoord();
+       this.origin_z = ReadCoord();
+       setorigin(this, this.origin);
+
+       this.angles_x = ReadAngle();
+       this.angles_y = ReadAngle();
+       this.angles_z = ReadAngle();
+
+       this.drawmask  = MASK_NORMAL;
+       setmodel(this, MDL_Null); // give it a size for clientcamera
+       setsize(this, '-1 -1 -1', '1 1 1');
+
+       generator_camera = this;
+       return true;
+}
+
 REGISTER_MUTATOR(cl_ons, true);
 
 float ons_roundlost;
@@ -35,7 +59,7 @@ MUTATOR_HOOKFUNCTION(cl_ons, CustomizeEventchase)
 {
        if(ons_roundlost)
        {
-               M_ARGV(0, vector) = generator_origin;
+               M_ARGV(0, vector) = generator_camera.origin;
                M_ARGV(1, vector) = autocvar_cl_eventchase_generator_viewoffset;
                M_ARGV(0, float) = autocvar_cl_eventchase_generator_distance;
                return true;
index c2b865f79ebec6dc4458b1f5363611c0ffdfa04e..572611c5d3f874169b7312c224888758d64f26a3 100644 (file)
@@ -28,11 +28,27 @@ float autocvar_g_onslaught_spawn_choose;
 float autocvar_g_onslaught_click_radius;
 
 void FixSize(entity e);
+entity cam;
 
 // =======================
 // CaptureShield Functions
 // =======================
 
+bool clientcamera_send(entity this, entity to, int sf)
+{
+       WriteHeader(MSG_ENTITY, ENT_ONSCAMERA);
+
+       WriteCoord(MSG_ENTITY, this.origin_x);
+       WriteCoord(MSG_ENTITY, this.origin_y);
+       WriteCoord(MSG_ENTITY, this.origin_z);
+
+       WriteAngle(MSG_ENTITY, this.angles_x);
+       WriteAngle(MSG_ENTITY, this.angles_y);
+       WriteAngle(MSG_ENTITY, this.angles_z);
+
+       return true;
+}
+
 bool ons_CaptureShield_Customize(entity this, entity client)
 {
        entity e = WaypointSprite_getviewentity(client);
@@ -817,6 +833,41 @@ void ons_Generator_UpdateSprite(entity e)
        }
 }
 
+void ons_camSetup(entity this)
+{
+       vector dir;
+       vector ang = '0 0 0';
+       vector best_ang = '0 0 0';
+       float best_trace_fraction = 0;
+       while(ang.y < 360)
+       {
+               dir = eX * cos(ang.y * DEG2RAD) + eY * sin(ang.y * DEG2RAD);
+               dir *= 500;
+               traceline(this.origin, this.origin - dir, MOVE_WORLDONLY, this);
+               if(trace_fraction > best_trace_fraction)
+               {
+                       best_trace_fraction = trace_fraction;
+                       best_ang = ang;
+                       if(trace_fraction == 1)
+                               break;
+               }
+               ang.y += 90;
+               if(ang.y == 360)
+                       ang.y = 45;
+       }
+       cam.origin = this.origin;
+       setorigin(cam, cam.origin);
+       cam.angles = best_ang;
+       Net_LinkEntity(cam, false, 0, clientcamera_send);
+
+       FOREACH_CLIENT(true, it.clientcamera = cam;);
+
+       WriteByte(MSG_ALL, SVC_SETVIEWANGLES);
+       WriteAngle(MSG_ALL, cam.angles_x);
+       WriteAngle(MSG_ALL, cam.angles_y);
+       WriteAngle(MSG_ALL, cam.angles_z);
+}
+
 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
 {
        if(damage <= 0) { return; }
@@ -877,6 +928,8 @@ void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float d
                //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
 
                onslaught_updatelinks();
+
+               ons_camSetup(this);
        }
 
        // Throw some flaming gibs on damage, more damage = more chance for gib
@@ -1622,6 +1675,7 @@ MUTATOR_HOOKFUNCTION(ons, reset_map_global)
                STAT(ROUNDLOST, it) = false;
                it.ons_deathloc = '0 0 0';
                PutClientInServer(it);
+               it.clientcamera = it;
        });
        return false;
 }
@@ -2138,5 +2192,7 @@ void ons_Initialize()
        g_onslaught = true;
        ons_captureshield_force = autocvar_g_onslaught_shield_force;
 
+       cam = new(objective_camera);
+
        InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);
 }