]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/onslaught/sv_onslaught.qc
Use the constants for player hitbox size when applicable (should fix observer hitbox)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / onslaught / sv_onslaught.qc
index 8e60bc30897a4ac897ea19c594630b68987989a3..195a3bd982819c9329de86bed31de64328455504 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; }
@@ -827,7 +878,7 @@ void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float d
        {
                if (this.isshielded)
                {
-                       // this is protected by a shield, so ignore the damage
+                       // generator is protected by a shield, so ignore the damage
                        if (time > this.pain_finished)
                                if (IS_PLAYER(attacker))
                                {
@@ -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
@@ -926,7 +979,8 @@ void ons_GeneratorReset(entity this)
        this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
        this.takedamage = DAMAGE_AIM;
        this.bot_attack = true;
-       IL_PUSH(g_bot_targets, this);
+       if(!IL_CONTAINS(g_bot_targets, this))
+               IL_PUSH(g_bot_targets, this);
        this.iscaptured = true;
        this.islinked = true;
        this.isshielded = true;
@@ -1584,7 +1638,7 @@ bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effe
 
                loc += tele_target.origin + '0 0 128' * iteration_scale;
 
-               tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
+               tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
                if(trace_fraction == 1.0 && !trace_startsolid)
                {
                        traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
@@ -1621,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;
 }
@@ -1685,7 +1740,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                {
                        if(SAME_TEAM(tmp_entity, player))
                        if(random_target)
-                               RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
+                               RandomSelection_AddEnt(tmp_entity, 1, 1);
                        else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
                                closest_target = tmp_entity;
                }
@@ -1702,7 +1757,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                                iteration_scale -= i / 10;
                                loc = closest_target.origin + '0 0 96' * iteration_scale;
                                loc += ('0 1 0' * random()) * 128 * iteration_scale;
-                               tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
+                               tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
                                if(trace_fraction == 1.0 && !trace_startsolid)
                                {
                                        traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
@@ -1732,7 +1787,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
                {
                        if(random_target)
-                               RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
+                               RandomSelection_AddEnt(tmp_entity, 1, 1);
                        else
                        {
                                if(SAME_TEAM(tmp_entity, player))
@@ -1753,7 +1808,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
                                iteration_scale -= i / 10;
                                loc = closest_target.origin + '0 0 128' * iteration_scale;
                                loc += ('0 1 0' * random()) * 256 * iteration_scale;
-                               tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
+                               tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
                                if(trace_fraction == 1.0 && !trace_startsolid)
                                {
                                        traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
@@ -1871,7 +1926,7 @@ MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
        return true;
 }
 
-MUTATOR_HOOKFUNCTION(ons, GetTeamCount)
+MUTATOR_HOOKFUNCTION(ons, CheckAllowedTeams)
 {
        // onslaught is special
        for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
@@ -2137,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);
 }