]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'div0/mutatorsystem' of git://git.xonotic.org/xonotic/xonotic-data.pk3di...
authorFlorian Paul Schmidt <mista.tapas@gmx.net>
Sat, 20 Mar 2010 00:50:06 +0000 (01:50 +0100)
committerFlorian Paul Schmidt <mista.tapas@gmx.net>
Sat, 20 Mar 2010 00:50:06 +0000 (01:50 +0100)
defaultXonotic.cfg
qcsrc/server/cl_client.qc
qcsrc/server/cl_physics.qc
qcsrc/server/defs.qh
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/base.qh
qcsrc/server/mutators/mutator_dodging.qc [new file with mode: 0644]
qcsrc/server/mutators/mutator_dodging.qh [new file with mode: 0644]
qcsrc/server/mutators/mutators.qh
qcsrc/server/progs.src
qcsrc/server/teamplay.qc

index d8c11a2683dde044f2519db7d1ffb21b91fd5e48..236dc0dc149af390ca3b232906d58a0f91104b24 100644 (file)
@@ -512,6 +512,14 @@ 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 sv_dodging_ramp_time 0.2
+
 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 593a0cac3263639dcaa373e0302ab186a358cc55..65091dcc7a7de96f7efec0029b4660e49ca20f0a 100644 (file)
@@ -2049,6 +2049,7 @@ void SetZoomState(float z)
 }
 
 void GetPressedKeys(void) {
+       MUTATOR_CALLHOOK(GetPressedKeys);
        if (self.movement_x > 0) // get if movement keys are pressed
        {       // forward key pressed
                self.pressedkeys |= KEY_FORWARD;
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 e80025a676e30e27fe43b44838d40b0fabec59d8..6d8838e8fd98a750e94120c87ec4fc9a7b6bbc05 100644 (file)
@@ -17,7 +17,7 @@ float require_spawnfunc_prefix; // if this float exists, only functions with spa
 
 float ctf_score_value(string parameter);
 
-float g_dm, g_domination, g_ctf, g_tdm, g_keyhunt, g_onslaught, g_assault, g_arena, g_ca, g_lms, g_runematch, g_race, g_nexball, g_cts;
+float g_dm, g_domination, g_ctf, g_tdm, g_keyhunt, g_onslaught, g_assault, g_arena, g_ca, g_lms, g_runematch, g_race, g_nexball, g_cts, g_dodging;
 float g_cloaked, g_footsteps, g_jump_grunt, g_grappling_hook, g_laserguided_missile, g_midair, g_minstagib, g_pinata, g_norecoil, g_vampire, g_minstagib_invis_alpha, g_bloodloss;
 float g_warmup_limit;
 float g_warmup_allguns;
@@ -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 11ea2f6645d5bac0a5db844b92caf9684ef06bee..61eb83127a2fa592b8c6c9f12e7ef43398fa9a74 100644 (file)
@@ -52,3 +52,5 @@ MUTATOR_HOOKABLE(BuildMutatorsPrettyString); string ret_string;
 MUTATOR_HOOKABLE(FilterItem); // return error to request removal, or change self.items or self.weapons
 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
new file mode 100644 (file)
index 0000000..d9520c0
--- /dev/null
@@ -0,0 +1,165 @@
+
+// these are used to store the last key press time for each of the keys..
+.float last_FORWARD_KEY_time;
+.float last_BACKWARD_KEY_time;
+.float last_LEFT_KEY_time;
+.float last_RIGHT_KEY_time;
+
+// these store the movement direction at the time of the dodge action happening.
+.float dodging_direction_x;
+.float dodging_direction_y;
+
+// 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_dodging_time;
+
+// set to 1 to indicate dodging has started.. reset by physics hook after dodge has been done..
+.float dodging_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_dodging_time = 0;
+       self.dodging_action = 0;
+       self.dodging_direction_x = 0;
+       self.dodging_direction_y = 0;
+}
+
+MUTATOR_HOOKFUNCTION(dodging_PlayerPhysics) {
+       makevectors(self.angles);
+       // print("physics hook\n");
+       if (g_dodging == 0)
+               return 0;
+
+       // ramp up dodging speed by adding some velocity each frame.. TODO: do it! :D
+       if (self.dodging_action == 1) {
+               self.velocity = 
+                         self.velocity 
+                       + ((self.dodging_direction_y * cvar("sv_dodging_horiz_speed")) * v_right) 
+                       + ((self.dodging_direction_x * cvar("sv_dodging_horiz_speed")) * v_forward) 
+                       + (cvar("sv_dodging_up_speed") * v_up);
+
+               // reset state so next dodge can be done correctly
+               self.dodging_action = 0;
+               self.dodging_direction_x = 0;
+               self.dodging_direction_y = 0;
+       }
+
+       // are we done with the dodging ramp yet?
+       if((self.dodging_action == 1) && ((time - self.last_dodging_time) > cvar("sv_dodging_ramp_time")))
+               self.dodging_action = 0;
+
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(dodging_GetPressedKeys) {
+       float length;
+       float dodge_detected;
+       //print("dodging_hook\n");
+
+       if (g_dodging == 0)
+               return 0;
+
+       dodge_detected = 0;
+
+       // common checks
+       if ((time - self.last_dodging_time) < cvar("sv_dodging_delay"))
+               return 0;
+
+       if (!(self.lastflags & FL_ONGROUND))
+               return 0;
+
+
+       if (self.movement_x > 0) {
+               // is this a state change?
+               if (!(self.pressedkeys & KEY_FORWARD)) {
+                       if ((time - self.last_FORWARD_KEY_time) < self.cvar_cl_dodging_timeout) { 
+                               dodge_detected = 1;
+                               self.dodging_action = 1;
+                               self.dodging_direction_x = 1.0;
+                               self.last_dodging_time = time;
+                       }
+                       self.last_FORWARD_KEY_time = time;
+               }
+       }
+
+       if (self.movement_x < 0) {
+               // is this a state change?
+               if (!(self.pressedkeys & KEY_BACKWARD)) {
+                       if ((time - self.last_BACKWARD_KEY_time) < self.cvar_cl_dodging_timeout)        { 
+                               dodge_detected = 1;
+                               self.dodging_action = 1;
+                               self.dodging_direction_x = -1.0;
+                               self.last_dodging_time = time;
+                       }
+                       self.last_BACKWARD_KEY_time = time;
+               }
+       }
+
+       if (self.movement_y > 0) {
+               // is this a state change?
+               if (!(self.pressedkeys & KEY_RIGHT)) {
+                       if ((time - self.last_RIGHT_KEY_time) < self.cvar_cl_dodging_timeout)   { 
+                               dodge_detected = 1;
+                               self.dodging_action = 1;
+                               self.dodging_direction_y = 1.0;
+                               self.last_dodging_time = time;
+                       }
+                       self.last_RIGHT_KEY_time = time;
+               }
+       }
+
+       if (self.movement_y < 0) {
+               // is this a state change?
+               if (!(self.pressedkeys & KEY_LEFT)) {
+                       if ((time - self.last_LEFT_KEY_time) < self.cvar_cl_dodging_timeout)    { 
+                               dodge_detected = 1;
+                               self.dodging_action = 1;
+                               self.dodging_direction_y = -1.0;
+                               self.last_dodging_time = time;
+                       }
+                       self.last_LEFT_KEY_time = time;
+               }
+       }
+
+
+
+       if (dodge_detected == 1) {
+               // normalize the dodging_direction vector.. 
+               length = length + self.dodging_direction_x * self.dodging_direction_x;
+               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;
+       }
+
+       return 0;
+}
+
+MUTATOR_DEFINITION(dodging)
+{
+       // we need to be called before GetPressedKey does its thing so we can
+       // 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.
+       MUTATOR_ONADD
+       {
+               g_dodging = 1;
+               dodging_Initialize();
+       }
+
+       // this just turns off the cvar.
+       MUTATOR_ONREMOVE
+       {        
+               g_dodging = 0;
+       }
+
+       return 0;
+}
\ No newline at end of file
diff --git a/qcsrc/server/mutators/mutator_dodging.qh b/qcsrc/server/mutators/mutator_dodging.qh
new file mode 100644 (file)
index 0000000..ab0c014
--- /dev/null
@@ -0,0 +1 @@
+//
\ No newline at end of file
index bbaad86c2dad8278c1a500030e179d849a1d78c8..da14483a4d40fa52e10fb198b65af8fe109e10dd 100644 (file)
@@ -1,3 +1,5 @@
 MUTATOR_DECLARATION(gamemode_keyhunt);
 
 MUTATOR_DECLARATION(mutator_nix);
+
+MUTATOR_DECLARATION(dodging);
index 8b9014071e8fccbd07a1e70f6158be5d46c788b2..b325251cfd611ffdcf70b97112a5f1ff879ccacb 100644 (file)
@@ -23,6 +23,7 @@ defs.qh               // Should rename this, it has fields and globals
 mutators/base.qh
 mutators/mutators.qh
 mutators/gamemode_keyhunt.qh // TODO fix this
+mutators/mutator_dodging.qh
 
 //// tZork Turrets ////
 tturrets/include/turrets_early.qh
@@ -173,6 +174,7 @@ cheats.qc
 mutators/base.qc
 mutators/gamemode_keyhunt.qc
 mutators/mutator_nix.qc
+mutators/mutator_dodging.qc
 
 ../warpzonelib/anglestransform.qc
 ../warpzonelib/mathlib.qc
index 4e1c16728c36cad00c6da719f7279f962e337976..b251869984c2b4de12ca36402775fa515dcc3eae 100644 (file)
@@ -208,6 +208,10 @@ void InitGameplayMode()
        fraglimit_override = cvar("fraglimit_override");
        leadlimit_override = cvar("leadlimit_override");
 
+       g_dodging = cvar("g_dodging");
+       if(g_dodging)
+               MUTATOR_ADD(dodging);
+       
        if(g_dm)
        {
                game = GAME_DEATHMATCH;