]> git.xonotic.org Git - voretournament/voretournament.git/commitdiff
Port dodging from Xonotic. Double-tap a movement key to leap in that direction. Still...
authorMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Wed, 16 May 2012 10:26:36 +0000 (13:26 +0300)
committerMirceaKitsune <sonichedgehog_hyperblast00@yahoo.com>
Wed, 16 May 2012 10:26:36 +0000 (13:26 +0300)
data/defaultVT.cfg
data/qcsrc/server/cl_client.qc
data/qcsrc/server/cl_physics.qc
data/qcsrc/server/defs.qh
data/qcsrc/server/miscfunctions.qc
docs/Release notes.txt
docs/TODO.txt

index db89655caed80b4661701b9b9920a7e658a6d7bf..626bdb3d5f935ba9240b602d96ac7c3175881dd3 100644 (file)
@@ -477,6 +477,19 @@ set welcome_message_time 8
 \r
 alias clearmap "disconnect"\r
 \r
+set g_dodging 1 "set to 1 to enable dodging in games"\r
+\r
+seta cl_dodging_timeout 0.2 "determines how long apart (in seconds) two taps on the same direction key are considered a dodge. use 0 to disable"\r
+\r
+set sv_dodging_wall_dodging 0 "set to 1 to allow dodging off walls. 0 to disable"\r
+set sv_dodging_delay 0.5 "determines how long a player has to wait to be able to dodge again after dodging"\r
+set sv_dodging_up_speed 200 "the jump velocity of the dodge"\r
+set sv_dodging_horiz_speed 400 "the horizontal velocity of the dodge"\r
+set sv_dodging_ramp_time 0.1 "a ramp so that the horizontal part of the dodge is added smoothly (seconds)"\r
+set sv_dodging_height_threshold 10 "the maximum height above ground where to allow dodging"\r
+set sv_dodging_wall_distance_threshold 10 "the maximum distance from a wall that still allows dodging"\r
+set sv_dodging_sound 1 "if 1 dodging makes a sound. if 0 dodging is silent"\r
+\r
 set leadlimit 0\r
 \r
 // this means that timelimit can be overidden globally and fraglimit can be overidden for each game mode: DM/TDM, Domination, CTF.\r
index dcc68204f2ce0c76a1b983973f489ed587808521..255ebc2fd6cafc6948ca83783248adeda0d69ef5 100644 (file)
@@ -2027,7 +2027,101 @@ void SetZoomState(float z)
        zoomstate_set = 1;\r
 }\r
 \r
+void dodging_pressedkeys()\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
+               return;\r
+\r
+       if (check_close_to_ground(cvar("sv_dodging_height_threshold")) != 1 \r
+               && check_close_to_wall(cvar("sv_dodging_wall_distance_threshold")) != 1)\r
+               return;\r
+\r
+       if (self.movement_x > 0) {\r
+               // is this a state change?\r
+               if (!(self.pressedkeys & KEY_FORWARD)) {\r
+                       if ((time - self.last_FORWARD_KEY_time) < self.cvar_cl_dodging_timeout) { \r
+                               tap_direction_x = 1.0;\r
+                               dodge_detected = 1;\r
+                       }\r
+                       self.last_FORWARD_KEY_time = time;\r
+               }\r
+       }\r
+\r
+       if (self.movement_x < 0) {\r
+               // is this a state change?\r
+               if (!(self.pressedkeys & KEY_BACKWARD)) {\r
+                       tap_direction_x = -1.0;\r
+                       if ((time - self.last_BACKWARD_KEY_time) < self.cvar_cl_dodging_timeout)        { \r
+                               dodge_detected = 1;\r
+                       }\r
+                       self.last_BACKWARD_KEY_time = time;\r
+               }\r
+       }\r
+\r
+       if (self.movement_y > 0) {\r
+               // is this a state change?\r
+               if (!(self.pressedkeys & KEY_RIGHT)) {\r
+                       tap_direction_y = 1.0;\r
+                       if ((time - self.last_RIGHT_KEY_time) < self.cvar_cl_dodging_timeout)   { \r
+                               dodge_detected = 1;\r
+                       }\r
+                       self.last_RIGHT_KEY_time = time;\r
+               }\r
+       }\r
+\r
+       if (self.movement_y < 0) {\r
+               // is this a state change?\r
+               if (!(self.pressedkeys & KEY_LEFT)) {\r
+                       tap_direction_y = -1.0;\r
+                       if ((time - self.last_LEFT_KEY_time) < self.cvar_cl_dodging_timeout)    { \r
+                               dodge_detected = 1;\r
+                       }\r
+                       self.last_LEFT_KEY_time = time;\r
+               }\r
+       }\r
+\r
+\r
+       if (dodge_detected == 1) {\r
+               self.last_dodging_time = time;\r
+\r
+               self.dodging_action = 1;\r
+               self.dodging_single_action = 1;\r
+\r
+               self.dodging_velocity_gain = cvar("sv_dodging_horiz_speed");\r
+\r
+               self.dodging_direction_x = tap_direction_x;\r
+               self.dodging_direction_y = tap_direction_y;\r
+\r
+               // normalize the dodging_direction vector.. (unlike UT99) XD\r
+               length =          self.dodging_direction_x * self.dodging_direction_x;\r
+               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
+       }\r
+\r
+       return;\r
+}\r
+\r
 void GetPressedKeys(void) {\r
+       // get keys for dodging\r
+       dodging_pressedkeys();\r
+\r
        if (self.movement_x > 0) // get if movement keys are pressed\r
        {       // forward key pressed\r
                self.pressedkeys |= KEY_FORWARD;\r
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
index 6871a58495c6b48a7716b90617d382ae61b4139b..85f3e5f7e5dbc4d2abf2babd6bfb3c13b3434506 100644 (file)
@@ -646,3 +646,31 @@ string deathmessage;
 \r
 .float cvar_cl_accuracy_data_share;\r
 .float cvar_cl_accuracy_data_receive;\r
+\r
+// dodging\r
+.float cvar_cl_dodging_timeout;\r
+\r
+// these are used to store the last key press time for each of the keys..\r
+.float last_FORWARD_KEY_time;\r
+.float last_BACKWARD_KEY_time;\r
+.float last_LEFT_KEY_time;\r
+.float last_RIGHT_KEY_time;\r
+\r
+// these store the movement direction at the time of the dodge action happening.\r
+.float dodging_direction_x;\r
+.float dodging_direction_y;\r
+\r
+// this indicates the last time a dodge was executed. used to check if another one is allowed\r
+// and to ramp up the dodge acceleration in the physics hook.\r
+.float last_dodging_time;\r
+\r
+// set to 1 to indicate dodging has started.. reset by physics hook after dodge has been done..\r
+.float dodging_action;\r
+\r
+// This is the velocity gain to be added over the ramp time.\r
+// It will decrease from frame to frame during dodging_action = 1\r
+// until it's 0.\r
+.float dodging_velocity_gain;\r
+\r
+// the jump part of the dodge cannot be ramped\r
+.float dodging_single_action;\r
index c22e5d53151ccb201c44e13f49330d9efa2e5f0d..3c288cac93fa15828b17c632cc7fe75f62aabf6b 100644 (file)
@@ -619,6 +619,7 @@ void GetCvars(float f)
        GetCvars_handleFloat(s, f, cvar_cl_vore_stomachmodel, "cl_vore_stomachmodel");\r
        GetCvars_handleFloat(s, f, cvar_cl_vore_swallowmodel, "cl_vore_swallowmodel");\r
        GetCvars_handleFloat(s, f, cvar_cl_vore_autodigest, "cl_vore_autodigest");\r
+       GetCvars_handleFloat(s, f, cvar_cl_dodging_timeout, "cl_dodging_timeout");\r
 \r
        self.cvar_cl_accuracy_data_share = boolean(self.cvar_cl_accuracy_data_share);\r
        self.cvar_cl_accuracy_data_receive = boolean(self.cvar_cl_accuracy_data_receive);\r
@@ -2635,3 +2636,44 @@ float playersize_macro(entity e)
                return 0;\r
        return 1 - bound(0, (e.health / cvar("g_healthsize_max") - 1) / (cvar("g_healthsize_center") / cvar("g_healthsize_max") - 1), 1);\r
 }\r
+\r
+// returns 1 if the player is close to a wall\r
+float check_close_to_wall(float threshold) {\r
+       //TODO: This check should be moved somehow for this to be a common utility\r
+       if (!cvar("sv_dodging_wall_dodging"))\r
+               return 0;\r
+\r
+       vector trace_start;\r
+       vector trace_end;\r
+\r
+       trace_start = self.origin;\r
+\r
+       trace_end = self.origin + (1000*v_right);\r
+       tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);\r
+       if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)\r
+               return 1;\r
+\r
+       trace_end = self.origin - (1000*v_right);\r
+       tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);\r
+       if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)\r
+               return 1;\r
+\r
+       trace_end = self.origin + (1000*v_forward);\r
+       tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);\r
+       if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)\r
+               return 1;\r
+\r
+       trace_end = self.origin - (1000*v_forward);\r
+       tracebox(trace_start, self.mins, self.maxs, trace_end, TRUE, self);\r
+       if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)\r
+               return 1;\r
+\r
+       return 0;\r
+}\r
+\r
+float check_close_to_ground(float threshold) {\r
+       if (self.flags & FL_ONGROUND)\r
+               return 1;\r
+\r
+       return 0;\r
+}\r
index e9134d7c6f1118c0c885e6e231ac4eec52130c69..12163ed8640c7b131e25513b9fe375bdfedc557f 100644 (file)
@@ -348,4 +348,6 @@ Features:
 \r
 - Health items are now swallowed slowly like players. The swallow speed depends on an item's health compared to the player's health, rather than a size comparison as done between players. This does not conflict with consumable items, and the two can be toggled individually. Items are still eaten by standing over them.\r
 \r
+- Ported dodging from Xonotic. Double-tap any movement key to leap in that direction. This can be combined with double jumping, and gives VT the same jumping system as Unreal Tournament 2004.\r
+\r
 Known bugs:\r
index 29326b6cc5963f00f85249569a49379c232f1b08..ffb6537a8245848a084763895d21af2de3968b49 100644 (file)
 \r
 - +0.8: Add some inclined HUD effect for more coolness, if it's possible. Maybe for the menu too\r
 \r
-- 0.8: View blur while being swallowed (same one as damage blur), as well as the screen darkening perhaps
\ No newline at end of file
+- 0.8: View blur while being swallowed (same one as damage blur), as well as the screen darkening perhaps\r
+\r
+- 0.8: Make crosshair size change based on distance of what you're looking at?\r
+\r
+- 0.8: Add dodging from Xonotic
\ No newline at end of file