]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Port race_completed to ClientState and move prevorigin to the campcheck code (only...
authorMario <mario@smbclan.net>
Sun, 16 Jul 2017 21:52:54 +0000 (07:52 +1000)
committerMario <mario@smbclan.net>
Sun, 16 Jul 2017 21:52:54 +0000 (07:52 +1000)
qcsrc/common/mutators/mutator/campcheck/sv_campcheck.qc
qcsrc/server/client.qc
qcsrc/server/client.qh
qcsrc/server/defs.qh
qcsrc/server/g_damage.qc
qcsrc/server/mutators/mutator/gamemode_race.qc
qcsrc/server/player.qc
qcsrc/server/race.qc

index 41f538b7a52f02e018c364ef1aec9b123e9a7383..52fc52466d5f93ec8203f3b104ac2b72e295dba1 100644 (file)
@@ -9,6 +9,8 @@ REGISTER_MUTATOR(campcheck, cvar("g_campcheck"));
 .float campcheck_nextcheck;
 .float campcheck_traveled_distance;
 
+.vector campcheck_prevorigin;
+
 MUTATOR_HOOKFUNCTION(campcheck, PlayerDies)
 {
        entity frag_target = M_ARGV(2, entity);
@@ -33,23 +35,19 @@ MUTATOR_HOOKFUNCTION(campcheck, Damage_Calculate)
 MUTATOR_HOOKFUNCTION(campcheck, PlayerPreThink)
 {
        entity player = M_ARGV(0, entity);
+       bool checked = false;
 
-       if(!game_stopped)
-       if(!warmup_stage) // don't consider it camping during warmup?
-       if(time >= game_starttime)
+       if(autocvar_g_campcheck_interval)
+       if(!game_stopped && !warmup_stage && time >= game_starttime)
        if(IS_PLAYER(player))
-       if(IS_REAL_CLIENT(player)) // bots may camp, but that's no reason to constantly kill them
        if(!IS_DEAD(player))
-       if(!forbidWeaponUse(player))
        if(!STAT(FROZEN, player))
        if(!PHYS_INPUT_BUTTON_CHAT(player))
-       if(autocvar_g_campcheck_interval)
+       if(IS_REAL_CLIENT(player)) // bots may camp, but that's no reason to constantly kill them
+       if(!forbidWeaponUse(player))
        {
-               vector dist;
-
                // calculate player movement (in 2 dimensions only, so jumping on one spot doesn't count as movement)
-               dist = player.prevorigin - player.origin;
-               dist.z = 0;
+               vector dist = vec2(player.campcheck_prevorigin - player.origin);
                player.campcheck_traveled_distance += fabs(vlen(dist));
 
                if((autocvar_g_campaign && !campaign_bots_may_start) || (time < game_starttime) || (round_handler_IsActive() && !round_handler_IsRoundStarted()))
@@ -72,10 +70,21 @@ MUTATOR_HOOKFUNCTION(campcheck, PlayerPreThink)
                        player.campcheck_traveled_distance = 0;
                }
 
-               return;
+               checked = true;
        }
 
-       player.campcheck_nextcheck = time + autocvar_g_campcheck_interval; // one of the above checks failed, so keep the timer up to date
+       if(!checked)
+               player.campcheck_nextcheck = time + autocvar_g_campcheck_interval; // one of the above checks failed, so keep the timer up to date
+
+       player.campcheck_prevorigin = player.origin;
+}
+
+MUTATOR_HOOKFUNCTION(campcheck, CopyBody)
+{
+       entity player = M_ARGV(0, entity);
+       entity clone = M_ARGV(1, entity);
+
+       clone.campcheck_prevorigin = player.campcheck_prevorigin;
 }
 
 MUTATOR_HOOKFUNCTION(campcheck, PlayerSpawn)
index 2bab814a2950b48ce66af8d5d4e0c52d94cdbb39..ec771b2d6232c8367f34d3babb852d3e178544c2 100644 (file)
@@ -110,7 +110,7 @@ bool ClientData_Send(entity this, entity to, int sf)
        if (IS_SPEC(e)) e = e.enemy;
 
        sf = 0;
-       if (e.race_completed)       sf |= 1; // forced scoreboard
+       if (CS(e).race_completed)       sf |= 1; // forced scoreboard
        if (CS(to).spectatee_status)    sf |= 2; // spectator ent number follows
        if (CS(e).zoomstate)            sf |= 4; // zoomed
        if (autocvar_sv_showspectators) sf |= 16; // show spectators
@@ -225,12 +225,10 @@ void PutObserverInServer(entity this)
     {
         entity spot = SelectSpawnPoint(this, true);
         if (!spot) LOG_FATAL("No spawnpoints for observers?!?");
-        this.angles = spot.angles;
-        this.angles_z = 0;
+        this.angles = vec2(spot.angles);
         this.fixangle = true;
         // offset it so that the spectator spawns higher off the ground, looks better this way
         setorigin(this, spot.origin + STAT(PL_VIEW_OFS, this));
-        this.prevorigin = this.origin;
         if (IS_REAL_CLIENT(this))
         {
             msg_entity = this;
@@ -622,7 +620,6 @@ void PutPlayerInServer(entity this)
        setorigin(this, spot.origin + '0 0 1' * (1 - this.mins.z - 24));
        // don't reset back to last position, even if new position is stuck in solid
        this.oldorigin = this.origin;
-       this.prevorigin = this.origin;
        this.lastteleporttime = time; // prevent insane speeds due to changing origin
        if(this.conveyor)
                IL_REMOVE(g_conveyed, this);
@@ -2203,8 +2200,6 @@ bool PlayerThink(entity this)
                return false;
        }
 
-       this.prevorigin = this.origin;
-
        bool have_hook = false;
        for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
        {
index 02caceb7d2d3f4fb411c49245edf8becc04e6533..bd9359cf5b61604f93bb26d4e907ed59b37e23b0 100644 (file)
@@ -94,6 +94,7 @@ CLASS(Client, Object)
     ATTRIB(Client, spectatee_status, int, this.spectatee_status);
     ATTRIB(Client, zoomstate, bool, this.zoomstate);
     ATTRIB(Client, just_joined, bool, this.just_joined);
+    ATTRIB(Client, race_completed, bool, this.race_completed);
 
     METHOD(Client, m_unwind, bool(Client this));
 
index 827f3940f7c28f2326a532d390da6fd22c444a0b..f4d78b0e8b62b303506efbc6a11487589264c35e 100644 (file)
@@ -289,8 +289,6 @@ float servertime, serverprevtime, serverframetime;
 
 .float ammo_fuel;
 
-.vector prevorigin;
-
 //flood fields
 .float nickspamtime; // time of last nick change
 .float nickspamcount;
index eb03769285197e1af591e1a9c6f5dc67d21026d3..83911eeafec9aa0b5d16120444a74b465acefbb8 100644 (file)
@@ -785,7 +785,6 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, int d
                                setorigin(targ, spot.origin + '0 0 1' * (1 - targ.mins.z - 24));
                                // don't reset back to last position, even if new position is stuck in solid
                                targ.oldorigin = targ.origin;
-                               targ.prevorigin = targ.origin;
 
                                Send_Effect(EFFECT_TELEPORT, targ.origin, '0 0 0', 1);
                        }
index 357ed226f4e96a7254c17de2d6606cafc68ede04..b1759fb6a62c2b2daafa47aed9532838ddd5d4bd 100644 (file)
@@ -73,7 +73,7 @@ float WinningCondition_Race(float fraglimit)
        c = 0;
        FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
                ++n;
-               if(it.race_completed)
+               if(CS(it).race_completed)
                        ++c;
        ));
        if(n && (n == c))
index e3201c4e50769dcc5f949320ee52a57f43ec629d..e34826cabcad0966b03af6d1b58a2a4774a343c2 100644 (file)
@@ -111,7 +111,6 @@ void CopyBody(entity this, float keepvelocity)
        //clone.weapon = this.weapon;
        setorigin(clone, this.origin);
        setsize(clone, this.mins, this.maxs);
-       clone.prevorigin = this.origin;
        clone.reset = SUB_Remove;
        clone._ps = this._ps;
 
index 0654c5dc74115ba7c8cc68d96bd75d098337b2c7..a17e8d745c551e45e2bf81a8325fc835913da694 100644 (file)
@@ -378,7 +378,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
 
        if(tvalid)
        if(cp == race_timed_checkpoint) // finish line
-       if (!e.race_completed)
+       if (!CS(e).race_completed)
        {
                float s;
                if(g_race_qualifying)
@@ -404,7 +404,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
 
                        if(race_completing)
                        {
-                               e.race_completed = 1;
+                               CS(e).race_completed = 1;
                                MAKE_INDEPENDENT_PLAYER(e);
                                Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_FINISHED, e.netname);
                                ClientData_Touch(e);
@@ -1030,9 +1030,9 @@ spawnfunc(target_stopTimer) { spawnfunc_target_checkpoint(this); }
 
 void race_AbandonRaceCheck(entity p)
 {
-       if(race_completing && !p.race_completed)
+       if(race_completing && !CS(p).race_completed)
        {
-               p.race_completed = 1;
+               CS(p).race_completed = 1;
                MAKE_INDEPENDENT_PLAYER(p);
                Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_RACE_ABANDONED, p.netname);
                ClientData_Touch(p);
@@ -1170,7 +1170,7 @@ float race_GetFractionalLapCount(entity e)
 
        float l;
        l = PlayerScore_Add(e, SP_RACE_LAPS, 0);
-       if(e.race_completed)
+       if(CS(e).race_completed)
                return l; // not fractional
 
        vector o0, o1;