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 .vector dodging_direction;
14 // this indicates the last time a dodge was executed. used to check if another one is allowed
15 // and to ramp up the dodge acceleration in the physics hook.
16 .float last_dodging_time;
18 // This is the velocity gain to be added over the ramp time.
19 // It will decrease from frame to frame during dodging_action = 1
21 .float dodging_velocity_gain;
23 MUTATOR_HOOKFUNCTION(dodging_GetCvars) {
24 GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_dodging_timeout, "cl_dodging_timeout");
28 MUTATOR_HOOKFUNCTION(dodging_PlayerPhysics) {
29 // print("dodging_PlayerPhysics\n");
32 float new_velocity_gain;
33 float velocity_difference;
34 float clean_up_and_do_nothing;
35 float horiz_speed = autocvar_sv_dodging_horiz_speed;
38 horiz_speed = autocvar_sv_dodging_horiz_speed_frozen;
40 if (self.deadflag != DEAD_NO)
43 new_velocity_gain = 0;
44 clean_up_and_do_nothing = 0;
47 clean_up_and_do_nothing = 1;
49 // when swimming, no dodging allowed..
50 if (self.waterlevel >= WATERLEVEL_SWIMMING)
51 clean_up_and_do_nothing = 1;
53 if (clean_up_and_do_nothing != 0) {
54 self.dodging_action = 0;
55 self.dodging_direction_x = 0;
56 self.dodging_direction_y = 0;
60 // make sure v_up, v_right and v_forward are sane
61 makevectors(self.angles);
63 // if we have e.g. 0.5 sec ramptime and a frametime of 0.25, then the ramp code
64 // will be called ramp_time/frametime times = 2 times. so, we need to
65 // add 0.5 * the total speed each frame until the dodge action is done..
66 common_factor = sys_frametime / autocvar_sv_dodging_ramp_time;
68 // if ramp time is smaller than frametime we get problems ;D
69 if (common_factor > 1)
72 new_velocity_gain = self.dodging_velocity_gain - (common_factor * horiz_speed);
73 if (new_velocity_gain < 0)
74 new_velocity_gain = 0;
76 velocity_difference = self.dodging_velocity_gain - new_velocity_gain;
78 // ramp up dodging speed by adding some velocity each frame.. TODO: do it! :D
79 if (self.dodging_action == 1) {
80 //disable jump key during dodge accel phase
81 if (self.movement.z > 0) self.movement_z = 0;
85 + ((self.dodging_direction.y * velocity_difference) * v_right)
86 + ((self.dodging_direction.x * velocity_difference) * v_forward);
88 self.dodging_velocity_gain = self.dodging_velocity_gain - velocity_difference;
91 // the up part of the dodge is a single shot action
92 if (self.dodging_single_action == 1) {
93 self.flags &= ~FL_ONGROUND;
97 + (autocvar_sv_dodging_up_speed * v_up);
99 if (autocvar_sv_dodging_sound == 1)
100 PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
102 animdecide_setaction(self, ANIMACTION_JUMP, true);
104 self.dodging_single_action = 0;
107 // are we done with the dodging ramp yet?
108 if((self.dodging_action == 1) && ((time - self.last_dodging_time) > autocvar_sv_dodging_ramp_time))
110 // reset state so next dodge can be done correctly
111 self.dodging_action = 0;
112 self.dodging_direction_x = 0;
113 self.dodging_direction_y = 0;
120 // returns 1 if the player is close to a wall
121 float check_close_to_wall(float threshold) {
122 if (autocvar_sv_dodging_wall_dodging == 0)
128 trace_start = self.origin;
130 trace_end = self.origin + (1000*v_right);
131 tracebox(trace_start, self.mins, self.maxs, trace_end, true, self);
132 if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)
135 trace_end = self.origin - (1000*v_right);
136 tracebox(trace_start, self.mins, self.maxs, trace_end, true, self);
137 if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)
140 trace_end = self.origin + (1000*v_forward);
141 tracebox(trace_start, self.mins, self.maxs, trace_end, true, self);
142 if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)
145 trace_end = self.origin - (1000*v_forward);
146 tracebox(trace_start, self.mins, self.maxs, trace_end, true, self);
147 if (trace_fraction < 1 && vlen (self.origin - trace_endpos) < threshold)
153 float check_close_to_ground(float threshold) {
154 if (self.flags & FL_ONGROUND)
161 MUTATOR_HOOKFUNCTION(dodging_GetPressedKeys) {
162 // print("dodging_PlayerPhysics\n");
165 vector tap_direction = '0 0 0';
167 float frozen_dodging, frozen_no_doubletap;
168 frozen_dodging = (self.frozen && autocvar_sv_dodging_frozen);
169 frozen_no_doubletap = (frozen_dodging && !autocvar_sv_dodging_frozen_doubletap);
171 float dodge_detected;
177 // first check if the last dodge is far enough back in time so we can dodge again
178 if ((time - self.last_dodging_time) < autocvar_sv_dodging_delay)
181 if (check_close_to_ground(autocvar_sv_dodging_height_threshold) != 1
182 && check_close_to_wall(autocvar_sv_dodging_wall_distance_threshold) != 1)
185 if (self.movement.x > 0) {
186 // is this a state change?
187 if (!(self.pressedkeys & KEY_FORWARD) || frozen_no_doubletap) {
188 if ((time - self.last_FORWARD_KEY_time) < self.cvar_cl_dodging_timeout) {
189 tap_direction.x = 1.0;
192 self.last_FORWARD_KEY_time = time;
196 if (self.movement.x < 0) {
197 // is this a state change?
198 if (!(self.pressedkeys & KEY_BACKWARD) || frozen_no_doubletap) {
199 tap_direction.x = -1.0;
200 if ((time - self.last_BACKWARD_KEY_time) < self.cvar_cl_dodging_timeout) {
203 self.last_BACKWARD_KEY_time = time;
207 if (self.movement.y > 0) {
208 // is this a state change?
209 if (!(self.pressedkeys & KEY_RIGHT) || frozen_no_doubletap) {
210 tap_direction.y = 1.0;
211 if ((time - self.last_RIGHT_KEY_time) < self.cvar_cl_dodging_timeout) {
214 self.last_RIGHT_KEY_time = time;
218 if (self.movement.y < 0) {
219 // is this a state change?
220 if (!(self.pressedkeys & KEY_LEFT) || frozen_no_doubletap) {
221 tap_direction.y = -1.0;
222 if ((time - self.last_LEFT_KEY_time) < self.cvar_cl_dodging_timeout) {
225 self.last_LEFT_KEY_time = time;
229 if (dodge_detected == 1) {
230 self.last_dodging_time = time;
232 self.dodging_action = 1;
233 self.dodging_single_action = 1;
235 self.dodging_velocity_gain = autocvar_sv_dodging_horiz_speed;
237 self.dodging_direction_x = tap_direction.x;
238 self.dodging_direction_y = tap_direction.y;
240 // normalize the dodging_direction vector.. (unlike UT99) XD
241 length = self.dodging_direction.x * self.dodging_direction.x;
242 length = length + self.dodging_direction.y * self.dodging_direction.y;
243 length = sqrt(length);
245 self.dodging_direction_x = self.dodging_direction.x * 1.0/length;
246 self.dodging_direction_y = self.dodging_direction.y * 1.0/length;
252 MUTATOR_DEFINITION(mutator_dodging)
254 // we need to be called before GetPressedKey does its thing so we can
255 // detect state changes and therefore dodging actions..
256 MUTATOR_HOOK(GetPressedKeys, dodging_GetPressedKeys, CBC_ORDER_ANY);
258 // in the physics hook we actually implement the dodge..
259 MUTATOR_HOOK(PlayerPhysics, dodging_PlayerPhysics, CBC_ORDER_ANY);
261 // get timeout information from the client, so the client can configure it..
262 MUTATOR_HOOK(GetCvars, dodging_GetCvars, CBC_ORDER_ANY);
264 // this just turns on the cvar.
270 // this just turns off the cvar.
271 MUTATOR_ONROLLBACK_OR_REMOVE