]> de.git.xonotic.org Git - voretournament/voretournament.git/blobdiff - data/qcsrc/server/cl_physics.qc
Port dodging from Xonotic. Double-tap a movement key to leap in that direction. Still...
[voretournament/voretournament.git] / data / qcsrc / server / cl_physics.qc
index a201643540316726cb25a6a18020336e1986256d..300f65b3a940c56a060e45ee57e0c8ccd55741df 100644 (file)
@@ -653,6 +653,89 @@ 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
+       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
@@ -1277,6 +1360,9 @@ void SV_PlayerPhysics()
                }\r
        }\r
 \r
+       // execute dodging code\r
+       dodging();\r
+\r
        if((g_cts || g_race) && self.classname != "observer") {\r
                if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {\r
                        speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');\r