2 .float cvar_cl_dodging_timeout;
5 // these are used to store the last key press time for each of the keys..
6 .float last_FORWARD_KEY_time;
7 .float last_BACKWARD_KEY_time;
8 .float last_LEFT_KEY_time;
9 .float last_RIGHT_KEY_time;
11 // these store the movement direction at the time of the dodge action happening.
12 .float dodging_direction_x;
13 .float dodging_direction_y;
15 // this indicates the last time a dodge was executed. used to check if another one is allowed
16 // and to ramp up the dodge acceleration in the physics hook.
17 .float last_dodging_time;
19 // set to 1 to indicate dodging has started.. reset by physics hook after dodge has been done..
20 .float dodging_action;
22 // the jump part of the dodge cannot be ramped
23 .float dodging_single_action;
25 void dodging_Initialize() {
26 // print("dodging_Initialize\n");
28 self.last_FORWARD_KEY_time = 0;
29 self.last_BACKWARD_KEY_time = 0;
30 self.last_RIGHT_KEY_time = 0;
31 self.last_LEFT_KEY_time = 0;
32 self.last_dodging_time = 0;
33 self.dodging_action = 0;
34 self.dodging_single_action = 0;
35 self.dodging_direction_x = 0;
36 self.dodging_direction_y = 0;
39 MUTATOR_HOOKFUNCTION(dodging_GetCvars) {
40 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_dodging_timeout, "cl_dodging_timeout");
44 MUTATOR_HOOKFUNCTION(dodging_PlayerPhysics) {
45 // print("dodging_PlayerPhysics\n");
49 // is dodging enabled at all? if not, do nothing..
53 // make sure v_up, v_right and v_forward are sane
54 makevectors(self.angles);
56 // if we have e.g. 0.5 sec ramptime and a frametime of 0.25, then the ramp code
57 // will be called ramp_time/frametime times = 2 times. so, we need to
58 // add 0.5 * the total speed each frame until the dodge action is done..
59 common_factor = sys_frametime / cvar("sv_dodging_ramp_time");
61 // if ramp time is smaller than frametime we get problems ;D
62 if (common_factor > 1)
66 // ramp up dodging speed by adding some velocity each frame.. TODO: do it! :D
67 if (self.dodging_action == 1) {
70 + (common_factor * (self.dodging_direction_y * cvar("sv_dodging_horiz_speed")) * v_right)
71 + (common_factor * (self.dodging_direction_x * cvar("sv_dodging_horiz_speed")) * v_forward);
74 // the up part of the dodge is a single shot action
75 if (self.dodging_single_action == 1) {
78 + (cvar("sv_dodging_up_speed") * v_up);
80 self.dodging_single_action = 0;
83 // are we done with the dodging ramp yet?
84 if((self.dodging_action == 1) && ((time - self.last_dodging_time) > cvar("sv_dodging_ramp_time")))
86 // reset state so next dodge can be done correctly
87 self.dodging_action = 0;
88 self.dodging_direction_x = 0;
89 self.dodging_direction_y = 0;
95 MUTATOR_HOOKFUNCTION(dodging_GetPressedKeys) {
96 // print("dodging_PlayerPhysics\n");
106 // first check if the last dodge is far enough back in time so we can dodge again
107 if ((time - self.last_dodging_time) < cvar("sv_dodging_delay"))
110 // check if our feet are on the ground :D
111 if (!(self.lastflags & FL_ONGROUND))
116 // self.cvar_cl_dodging_timeout = 0.2;
118 if (self.movement_x > 0) {
119 // is this a state change?
120 if (!(self.pressedkeys & KEY_FORWARD)) {
121 if ((time - self.last_FORWARD_KEY_time) < self.cvar_cl_dodging_timeout) {
123 self.dodging_direction_x = 1.0;
124 self.last_dodging_time = time;
126 self.last_FORWARD_KEY_time = time;
130 if (self.movement_x < 0) {
131 // is this a state change?
132 if (!(self.pressedkeys & KEY_BACKWARD)) {
133 if ((time - self.last_BACKWARD_KEY_time) < self.cvar_cl_dodging_timeout) {
135 self.dodging_direction_x = -1.0;
136 self.last_dodging_time = time;
138 self.last_BACKWARD_KEY_time = time;
142 if (self.movement_y > 0) {
143 // is this a state change?
144 if (!(self.pressedkeys & KEY_RIGHT)) {
145 if ((time - self.last_RIGHT_KEY_time) < self.cvar_cl_dodging_timeout) {
147 self.dodging_direction_y = 1.0;
148 self.last_dodging_time = time;
150 self.last_RIGHT_KEY_time = time;
154 if (self.movement_y < 0) {
155 // is this a state change?
156 if (!(self.pressedkeys & KEY_LEFT)) {
157 if ((time - self.last_LEFT_KEY_time) < self.cvar_cl_dodging_timeout) {
159 self.dodging_direction_y = -1.0;
160 self.last_dodging_time = time;
162 self.last_LEFT_KEY_time = time;
168 if (dodge_detected == 1) {
169 self.dodging_action = 1;
170 self.dodging_single_action = 1;
172 // normalize the dodging_direction vector.. (unlike UT99) XD
173 length = length + self.dodging_direction_x * self.dodging_direction_x;
174 length = length + self.dodging_direction_y * self.dodging_direction_y;
175 length = sqrt(length);
177 self.dodging_direction_x = self.dodging_direction_x * 1.0/length;
178 self.dodging_direction_y = self.dodging_direction_y * 1.0/length;
184 MUTATOR_DEFINITION(dodging)
186 // we need to be called before GetPressedKey does its thing so we can
187 // detect state changes and therefore dodging actions..
188 MUTATOR_HOOK(GetPressedKeys, dodging_GetPressedKeys, CBC_ORDER_ANY);
190 // in the physics hook we actually implement the dodge..
191 MUTATOR_HOOK(PlayerPhysics, dodging_PlayerPhysics, CBC_ORDER_ANY);
193 MUTATOR_HOOK(GetCvars, dodging_GetCvars, CBC_ORDER_ANY);
195 // this just turns on the cvar.
199 dodging_Initialize();
202 // this just turns off the cvar.