]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_dodging.qc
- refining the dodging code
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_dodging.qc
1 .float last_FORWARD_KEY_time;
2 .float last_BACKWARD_KEY_time;
3 .float last_LEFT_KEY_time;
4 .float last_RIGHT_KEY_time;
5
6 // this indicates the last time a dodge was executed. used to check if another one is allowed
7 // and to ramp up the dodge acceleration in the physics hook.
8 .float last_dodge_time;
9
10 // set to 1 to indicate dodging has started.. reset by physics hook after dodge has been done..
11 .float dodge_action;
12
13 void dodging_Initialize() {
14         self.last_FORWARD_KEY_time = 0;
15         self.last_BACKWARD_KEY_time = 0;
16         self.last_RIGHT_KEY_time = 0;
17         self.last_LEFT_KEY_time = 0;
18         self.last_dodge_time = 0;
19         self.dodge_action = 0;
20 }
21
22 MUTATOR_HOOKFUNCTION(dodging_PlayerPhysics) {
23         // print("physics hook\n");
24         if (g_dodging == 0)
25                 return 0;
26
27         
28
29         return 0;
30 }
31
32 MUTATOR_HOOKFUNCTION(dodging_GetPressedKeys) {
33         //print("dodging_hook\n");
34
35         if (g_dodging == 0)
36                 return 0;
37
38         if (self.movement_x > 0) // get if movement keys are pressed
39    {       // forward key pressed
40         if (!(self.pressedkeys & KEY_FORWARD)) {        // is this a state change?
41                         if (
42                                 ((time - self.last_FORWARD_KEY_time) < self.cvar_cl_dodging_timeout) &&
43                                 (self.lastflags & FL_ONGROUND) &&
44                                 ((time - self.last_dodge_time) > cvar("sv_dodging_delay"))
45                         ) { // are we allowed to dodge?
46                                 self.dodge_action = 1;
47                                 // self.velocity = self.velocity + (cvar("sv_dodging_horiz_speed") * v_forward) + (cvar("sv_dodging_up_speed") * v_up);//'100 0 50';
48                                 self.last_dodge_time = time;
49                         }
50                         self.last_FORWARD_KEY_time = time;
51                 }
52         }
53
54         return 0;
55 }
56
57 MUTATOR_DEFINITION(dodging)
58 {
59         // we need to be called before GetPressedKey does its thing so we can
60         // detect state changes and therefore dodging actions..
61         MUTATOR_HOOK(GetPressedKeys, dodging_GetPressedKeys, CBC_ORDER_ANY);
62
63         // in the physics hook we actually implement the dodge..
64         MUTATOR_HOOK(PlayerPhysics, dodging_PlayerPhysics, CBC_ORDER_ANY);
65
66         // this just turns on the cvar. TODO: implement :D
67         MUTATOR_ONADD
68         {
69                 g_dodging = 1;
70                 dodging_Initialize();
71         }
72
73         // this just turns off the cvar. TODO: implement :D
74         MUTATOR_ONREMOVE
75         {        
76                 g_dodging = 0;
77         }
78
79         return 0;
80 }