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