]> git.rm.cloudns.org Git - voretournament/voretournament.git/commitdiff
Cleanup and improve dodging code implementation
authorMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Wed, 16 May 2012 10:59:50 +0000 (13:59 +0300)
committerMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Wed, 16 May 2012 10:59:50 +0000 (13:59 +0300)
data/qcsrc/server/cl_client.qc
data/qcsrc/server/cl_physics.qc

index 255ebc2fd6cafc6948ca83783248adeda0d69ef5..b41bb1d06110f9aedd67ab6ba17801398635a783 100644 (file)
@@ -2027,20 +2027,13 @@ void SetZoomState(float z)
        zoomstate_set = 1;\r
 }\r
 \r
-void dodging_pressedkeys()\r
+// get pressed keys for PlayerDodge\r
+void PlayerDodge_GetPressedKeys()\r
 {\r
        float length;\r
        float tap_direction_x;\r
        float tap_direction_y;\r
-\r
-       tap_direction_x = 0;\r
-       tap_direction_y = 0;\r
-\r
        float dodge_detected;\r
-       if (!cvar("g_dodging"))\r
-               return;\r
-\r
-       dodge_detected = 0;\r
 \r
        // first check if the last dodge is far enough back in time so we can dodge again\r
        if ((time - self.last_dodging_time) < cvar("sv_dodging_delay"))\r
@@ -2094,7 +2087,6 @@ void dodging_pressedkeys()
                }\r
        }\r
 \r
-\r
        if (dodge_detected == 1) {\r
                self.last_dodging_time = time;\r
 \r
@@ -2111,16 +2103,15 @@ void dodging_pressedkeys()
                length = length + self.dodging_direction_y * self.dodging_direction_y;\r
                length = sqrt(length);\r
 \r
-               self.dodging_direction_x = self.dodging_direction_x * 1.0/length;\r
-               self.dodging_direction_y = self.dodging_direction_y * 1.0/length;\r
+               self.dodging_direction_x = self.dodging_direction_x * 1.0 / length;\r
+               self.dodging_direction_y = self.dodging_direction_y * 1.0 / length;\r
        }\r
-\r
-       return;\r
 }\r
 \r
 void GetPressedKeys(void) {\r
        // get keys for dodging\r
-       dodging_pressedkeys();\r
+       if(cvar("g_dodging"))\r
+               PlayerDodge_GetPressedKeys();\r
 \r
        if (self.movement_x > 0) // get if movement keys are pressed\r
        {       // forward key pressed\r
index 068f7dbd7dbf330e99cd9aceafc3a772c36195bc..9c2e34b4ab38f7e8191543fae5cde1e5f6e78148 100644 (file)
@@ -185,6 +185,84 @@ void PlayerJump (void)
        // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping)\r
 }\r
 \r
+/*\r
+=============\r
+PlayerDodge\r
+\r
+When you double-press a movement key rapidly to leap in that direction\r
+=============\r
+*/\r
+void PlayerDodge()\r
+{\r
+       float common_factor;\r
+       float new_velocity_gain;\r
+       float velocity_difference;\r
+\r
+       // make sure v_up, v_right and v_forward are sane\r
+       makevectors(self.angles);\r
+\r
+       // if we have e.g. 0.5 sec ramptime and a frametime of 0.25, then the ramp code \r
+       // will be called ramp_time/frametime times = 2 times. so, we need to \r
+       // add 0.5 * the total speed each frame until the dodge action is done..\r
+       common_factor = sys_frametime / cvar("sv_dodging_ramp_time");\r
+\r
+       // if ramp time is smaller than frametime we get problems ;D\r
+       if (common_factor > 1) \r
+               common_factor = 1;\r
+\r
+       new_velocity_gain = self.dodging_velocity_gain - (common_factor * cvar("sv_dodging_horiz_speed"));\r
+\r
+       if(cvar("g_healthsize")) // if we are smaller or larger, we jump lower or higher\r
+               new_velocity_gain *= (1 - cvar("g_healthsize_movementfactor")) + cvar("g_healthsize_movementfactor") * self.scale;\r
+       if(self.swallow_progress_prey) // cut jumping based on swallow progress for prey\r
+               new_velocity_gain *= 1 - (self.swallow_progress_prey * cvar("g_balance_vore_swallow_speed_cutspd_prey"));\r
+       if(self.swallow_progress_pred) // cut jumping based on swallow progress for preds\r
+               new_velocity_gain *= 1 - (self.swallow_progress_pred * cvar("g_balance_vore_swallow_speed_cutspd_pred"));\r
+\r
+       if (new_velocity_gain < 0)\r
+               new_velocity_gain = 0;\r
+\r
+       velocity_difference = self.dodging_velocity_gain - new_velocity_gain;\r
+\r
+       // ramp up dodging speed by adding some velocity each frame.. TODO: do it! :D\r
+       if (self.dodging_action == 1) {\r
+               //disable jump key during dodge accel phase\r
+               if (self.movement_z > 0) self.movement_z = 0;\r
+\r
+               self.velocity = \r
+                         self.velocity \r
+                       + ((self.dodging_direction_y * velocity_difference) * v_right)\r
+                       + ((self.dodging_direction_x * velocity_difference) * v_forward);\r
+\r
+               self.dodging_velocity_gain = self.dodging_velocity_gain - velocity_difference;\r
+       }\r
+\r
+       // the up part of the dodge is a single shot action\r
+       if (self.dodging_single_action == 1) {\r
+               self.flags &~= FL_ONGROUND;\r
+\r
+               self.velocity = \r
+                         self.velocity \r
+                       + (cvar("sv_dodging_up_speed") * v_up);\r
+\r
+               if (cvar("sv_dodging_sound"))\r
+                       PlayerSound(self, playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
+\r
+               setanim(self, self.anim_jump, TRUE, FALSE, TRUE);\r
+\r
+               self.dodging_single_action = 0;\r
+       }\r
+\r
+       // are we done with the dodging ramp yet?\r
+       if((self.dodging_action == 1) && ((time - self.last_dodging_time) > cvar("sv_dodging_ramp_time")))\r
+       {\r
+               // reset state so next dodge can be done correctly\r
+               self.dodging_action = 0;\r
+               self.dodging_direction_x = 0;\r
+               self.dodging_direction_y = 0;\r
+       }\r
+}\r
+\r
 void CheckWaterJump()\r
 {\r
        local vector start, end;\r
@@ -653,97 +731,6 @@ void race_send_speedaward_alltimebest(float msg)
        WriteString(msg, speedaward_alltimebest_holder);\r
 }\r
 \r
-void dodging()\r
-{\r
-       float common_factor;\r
-       float new_velocity_gain;\r
-       float velocity_difference;\r
-       float clean_up_and_do_nothing;\r
-\r
-       new_velocity_gain = 0;\r
-       clean_up_and_do_nothing = 0;\r
-\r
-       if (cvar("g_dodging") == 0)\r
-               clean_up_and_do_nothing = 1;\r
-\r
-       // when swimming, no dodging allowed..\r
-       if (self.waterlevel >= WATERLEVEL_SWIMMING)\r
-               clean_up_and_do_nothing = 1;\r
-\r
-       if (clean_up_and_do_nothing != 0) {\r
-               self.dodging_action = 0;\r
-               self.dodging_direction_x = 0;\r
-               self.dodging_direction_y = 0;\r
-               return;\r
-       }\r
-\r
-       // make sure v_up, v_right and v_forward are sane\r
-       makevectors(self.angles);\r
-\r
-       // if we have e.g. 0.5 sec ramptime and a frametime of 0.25, then the ramp code \r
-       // will be called ramp_time/frametime times = 2 times. so, we need to \r
-       // add 0.5 * the total speed each frame until the dodge action is done..\r
-       common_factor = sys_frametime / cvar("sv_dodging_ramp_time");\r
-\r
-       // if ramp time is smaller than frametime we get problems ;D\r
-       if (common_factor > 1) \r
-               common_factor = 1;\r
-\r
-       new_velocity_gain = self.dodging_velocity_gain - (common_factor * cvar("sv_dodging_horiz_speed"));\r
-\r
-       if(cvar("g_healthsize")) // if we are smaller or larger, we jump lower or higher\r
-               new_velocity_gain *= (1 - cvar("g_healthsize_movementfactor")) + cvar("g_healthsize_movementfactor") * self.scale;\r
-       if(self.swallow_progress_prey) // cut jumping based on swallow progress for prey\r
-               new_velocity_gain *= 1 - (self.swallow_progress_prey * cvar("g_balance_vore_swallow_speed_cutspd_prey"));\r
-       if(self.swallow_progress_pred) // cut jumping based on swallow progress for preds\r
-               new_velocity_gain *= 1 - (self.swallow_progress_pred * cvar("g_balance_vore_swallow_speed_cutspd_pred"));\r
-\r
-       if (new_velocity_gain < 0)\r
-               new_velocity_gain = 0;\r
-\r
-       velocity_difference = self.dodging_velocity_gain - new_velocity_gain;\r
-\r
-       // ramp up dodging speed by adding some velocity each frame.. TODO: do it! :D\r
-       if (self.dodging_action == 1) {\r
-               //disable jump key during dodge accel phase\r
-               if (self.movement_z > 0) self.movement_z = 0;\r
-\r
-               self.velocity = \r
-                         self.velocity \r
-                       + ((self.dodging_direction_y * velocity_difference) * v_right)\r
-                       + ((self.dodging_direction_x * velocity_difference) * v_forward);\r
-\r
-               self.dodging_velocity_gain = self.dodging_velocity_gain - velocity_difference;\r
-       }\r
-\r
-       // the up part of the dodge is a single shot action\r
-       if (self.dodging_single_action == 1) {\r
-               self.flags &~= FL_ONGROUND;\r
-\r
-               self.velocity = \r
-                         self.velocity \r
-                       + (cvar("sv_dodging_up_speed") * v_up);\r
-\r
-               if (cvar("sv_dodging_sound"))\r
-                       PlayerSound(self, playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND);\r
-\r
-               setanim(self, self.anim_jump, TRUE, FALSE, TRUE);\r
-\r
-               self.dodging_single_action = 0;\r
-       }\r
-\r
-       // are we done with the dodging ramp yet?\r
-       if((self.dodging_action == 1) && ((time - self.last_dodging_time) > cvar("sv_dodging_ramp_time")))\r
-       {\r
-               // reset state so next dodge can be done correctly\r
-               self.dodging_action = 0;\r
-               self.dodging_direction_x = 0;\r
-               self.dodging_direction_y = 0;\r
-       }\r
-\r
-       return;\r
-}\r
-\r
 string GetMapname(void);\r
 float speedaward_lastupdate;\r
 float speedaward_lastsent;\r
@@ -1368,8 +1355,15 @@ void SV_PlayerPhysics()
                }\r
        }\r
 \r
-       // execute dodging code\r
-       dodging();\r
+       // dodging code\r
+       if (cvar("g_dodging") == 0 || self.waterlevel >= WATERLEVEL_SWIMMING) // when swimming, no dodging allowed..\r
+       {\r
+               self.dodging_action = 0;\r
+               self.dodging_direction_x = 0;\r
+               self.dodging_direction_y = 0;\r
+       }\r
+       else\r
+               PlayerDodge();\r
 \r
        if((g_cts || g_race) && self.classname != "observer") {\r
                if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {\r