]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
- refining the dodging code
authorFlorian Paul Schmidt <mista.tapas@gmx.net>
Fri, 19 Mar 2010 22:36:16 +0000 (23:36 +0100)
committerFlorian Paul Schmidt <mista.tapas@gmx.net>
Fri, 19 Mar 2010 22:36:16 +0000 (23:36 +0100)
defaultXonotic.cfg
qcsrc/server/cl_physics.qc
qcsrc/server/defs.qh
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/base.qh
qcsrc/server/mutators/mutator_dodging.qc

index d8c11a2683dde044f2519db7d1ffb21b91fd5e48..8a68ebcdad3b173791fa119fa5d6f4f0612576a4 100644 (file)
@@ -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.
index 4c2280099dc2f0b08e5e86de9466c898c733913b..66dc32fcce2593eb3f570309679bcddc25303d9d 100644 (file)
@@ -593,6 +593,8 @@ void SV_PlayerPhysics()
        float not_allowed_to_move;
        string c;
 
+       MUTATOR_CALLHOOK(PlayerPhysics);
+
     if(self.PlayerPhysplug)
         if(self.PlayerPhysplug())
             return;
index f18c610aa84cefc431f77b9b2150467f2d98aa7a..6d8838e8fd98a750e94120c87ec4fc9a7b6bbc05 100644 (file)
@@ -637,3 +637,5 @@ string deathmessage;
 
 .float cvar_cl_accuracy_data_share;
 .float cvar_cl_accuracy_data_receive;
+
+.float cvar_cl_dodging_timeout;
index d9c5ca6ebca8ff3072669c679020a39bf5a84c3f..38c5bd03c624c22117d084dcd36d90a9c53c833d 100644 (file)
@@ -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);
index c8e14901483680842138b5ecf868c58382fc2882..61eb83127a2fa592b8c6c9f12e7ef43398fa9a74 100644 (file)
@@ -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);
index f87662e4d099693b68e2a1e1b87d31fbc70bd976..282ef4be24640dfe5475b616874d4a9f9fc93f58 100644 (file)
@@ -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;