From: Florian Paul Schmidt Date: Fri, 19 Mar 2010 22:36:16 +0000 (+0100) Subject: - refining the dodging code X-Git-Tag: xonotic-v0.1.0preview~680^2~29 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b891d3eb4c52c10469fdaf16461ff41493e80646;p=xonotic%2Fxonotic-data.pk3dir.git - refining the dodging code --- diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index d8c11a268..8a68ebcda 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -512,6 +512,13 @@ alias clearmap "disconnect" set g_grappling_hook 0 "let players spawn with the grappling hook which allows them to pull themselves up" +set g_dodging 0 "set to 1 to enable dodging in games" + +seta cl_dodging_timeout 0 +set sv_dodging_delay 0.5 +set sv_dodging_up_speed 200 +set sv_dodging_horiz_speed 500 + set leadlimit 0 // this means that timelimit can be overidden globally and fraglimit can be overidden for each game mode: DM/TDM, Domination, CTF, and Runematch. diff --git a/qcsrc/server/cl_physics.qc b/qcsrc/server/cl_physics.qc index 4c2280099..66dc32fcc 100644 --- a/qcsrc/server/cl_physics.qc +++ b/qcsrc/server/cl_physics.qc @@ -593,6 +593,8 @@ void SV_PlayerPhysics() float not_allowed_to_move; string c; + MUTATOR_CALLHOOK(PlayerPhysics); + if(self.PlayerPhysplug) if(self.PlayerPhysplug()) return; diff --git a/qcsrc/server/defs.qh b/qcsrc/server/defs.qh index f18c610aa..6d8838e8f 100644 --- a/qcsrc/server/defs.qh +++ b/qcsrc/server/defs.qh @@ -637,3 +637,5 @@ string deathmessage; .float cvar_cl_accuracy_data_share; .float cvar_cl_accuracy_data_receive; + +.float cvar_cl_dodging_timeout; diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index d9c5ca6eb..38c5bd03c 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -619,6 +619,7 @@ void GetCvars(float f) GetCvars_handleFloat(s, f, cvar_cl_hitsound, "cl_hitsound"); GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_share, "cl_accuracy_data_share"); GetCvars_handleFloat(s, f, cvar_cl_accuracy_data_receive, "cl_accuracy_data_receive"); + GetCvars_handleFloat(s, f, cvar_cl_dodging_timeout, "cl_dodging_timeout"); self.cvar_cl_accuracy_data_share = boolean(self.cvar_cl_accuracy_data_share); self.cvar_cl_accuracy_data_receive = boolean(self.cvar_cl_accuracy_data_receive); diff --git a/qcsrc/server/mutators/base.qh b/qcsrc/server/mutators/base.qh index c8e149014..61eb83127 100644 --- a/qcsrc/server/mutators/base.qh +++ b/qcsrc/server/mutators/base.qh @@ -53,3 +53,4 @@ MUTATOR_HOOKABLE(FilterItem); // return error to request removal, or change self MUTATOR_HOOKABLE(OnEntityPreSpawn); // return error to prevent entity spawn, or modify the entity MUTATOR_HOOKABLE(PlayerPreThink); MUTATOR_HOOKABLE(GetPressedKeys); +MUTATOR_HOOKABLE(PlayerPhysics); diff --git a/qcsrc/server/mutators/mutator_dodging.qc b/qcsrc/server/mutators/mutator_dodging.qc index f87662e4d..282ef4be2 100644 --- a/qcsrc/server/mutators/mutator_dodging.qc +++ b/qcsrc/server/mutators/mutator_dodging.qc @@ -3,36 +3,77 @@ .float last_LEFT_KEY_time; .float last_RIGHT_KEY_time; +// this indicates the last time a dodge was executed. used to check if another one is allowed +// and to ramp up the dodge acceleration in the physics hook. +.float last_dodge_time; + +// set to 1 to indicate dodging has started.. reset by physics hook after dodge has been done.. +.float dodge_action; + void dodging_Initialize() { - self.last_FORWARD_KEY_time = 0; - self.last_BACKWARD_KEY_time = 0; - self.last_RIGHT_KEY_time = 0; - self.last_LEFT_KEY_time = 0; + self.last_FORWARD_KEY_time = 0; + self.last_BACKWARD_KEY_time = 0; + self.last_RIGHT_KEY_time = 0; + self.last_LEFT_KEY_time = 0; + self.last_dodge_time = 0; + self.dodge_action = 0; +} + +MUTATOR_HOOKFUNCTION(dodging_PlayerPhysics) { + // print("physics hook\n"); + if (g_dodging == 0) + return 0; + + + + return 0; } MUTATOR_HOOKFUNCTION(dodging_GetPressedKeys) { - print("dodging_hook\n"); - print(ftos(g_dodging), "\n"); + //print("dodging_hook\n"); + + if (g_dodging == 0) + return 0; + + if (self.movement_x > 0) // get if movement keys are pressed + { // forward key pressed + if (!(self.pressedkeys & KEY_FORWARD)) { // is this a state change? + if ( + ((time - self.last_FORWARD_KEY_time) < self.cvar_cl_dodging_timeout) && + (self.lastflags & FL_ONGROUND) && + ((time - self.last_dodge_time) > cvar("sv_dodging_delay")) + ) { // are we allowed to dodge? + self.dodge_action = 1; + // self.velocity = self.velocity + (cvar("sv_dodging_horiz_speed") * v_forward) + (cvar("sv_dodging_up_speed") * v_up);//'100 0 50'; + self.last_dodge_time = time; + } + self.last_FORWARD_KEY_time = time; + } + } + return 0; } MUTATOR_DEFINITION(dodging) { // we need to be called before GetPressedKey does its thing so we can - // detect state changes.. + // detect state changes and therefore dodging actions.. MUTATOR_HOOK(GetPressedKeys, dodging_GetPressedKeys, CBC_ORDER_ANY); + // in the physics hook we actually implement the dodge.. + MUTATOR_HOOK(PlayerPhysics, dodging_PlayerPhysics, CBC_ORDER_ANY); + // this just turns on the cvar. TODO: implement :D MUTATOR_ONADD { - // g_dodging = 1; + g_dodging = 1; dodging_Initialize(); } // this just turns off the cvar. TODO: implement :D MUTATOR_ONREMOVE { - //g_dodging = 0; + g_dodging = 0; } return 0;