X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=data%2Fqcsrc%2Fserver%2Fcl_physics.qc;h=d3aa8e513ca4aaa666441adb1dfb45713808bb52;hb=5209469a2bea02bd597584236d906d4a1e4cd632;hp=bd04e84b0cfd32857b68f2625eadd54eb98e635c;hpb=6d61966a10850012aaedcc72c0c90f9136db3bfe;p=voretournament%2Fvoretournament.git diff --git a/data/qcsrc/server/cl_physics.qc b/data/qcsrc/server/cl_physics.qc index bd04e84b..d3aa8e51 100644 --- a/data/qcsrc/server/cl_physics.qc +++ b/data/qcsrc/server/cl_physics.qc @@ -29,6 +29,11 @@ float sv_warsowbunny_backtosideratio; .float wasFlying; .float spectatorspeed; +.float multijump_count; +.float multijump_ready; +.float prevjumpbutton; +.float prevlastteleporttime; + /* ============= PlayerJump @@ -39,8 +44,24 @@ When you press the jump key void PlayerJump (void) { float mjumpheight; + float doublejump; + + doublejump = FALSE; + if (cvar("sv_doublejump")) + { + tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self); + if (trace_fraction < 1 && trace_plane_normal_z > 0.7) + doublejump = TRUE; + } mjumpheight = cvar("sv_jumpvelocity"); + if(cvar("g_healthsize")) // if we are smaller or larger, we jump lower or higher + mjumpheight *= (1 - cvar("g_healthsize_movementfactor")) + cvar("g_healthsize_movementfactor") * self.scale; + if(self.swallow_progress_prey) // cut jumping based on swallow progress for prey + mjumpheight *= 1 - (self.swallow_progress_prey * cvar("g_balance_vore_swallow_speed_cutspd_prey")); + if(self.swallow_progress_pred) // cut jumping based on swallow progress for preds + mjumpheight *= 1 - (self.swallow_progress_pred * cvar("g_balance_vore_swallow_speed_cutspd_pred")); + if (self.waterlevel >= WATERLEVEL_SWIMMING) { if (self.watertype == CONTENT_WATER) @@ -53,8 +74,66 @@ void PlayerJump (void) return; } - if (!(self.flags & FL_ONGROUND)) - return; + if (cvar("g_multijump")) + { + if(self.prevlastteleporttime != self.lastteleporttime) + { + // if we teleported above the ground, require touching the ground again to multi-jump + self.multijump_ready = FALSE; + if(self.flags & FL_ONGROUND) + self.prevlastteleporttime = self.lastteleporttime; + } + else if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair + self.multijump_ready = TRUE; // this is necessary to check that we released the jump button and pressed it again + else + self.multijump_ready = FALSE; + } + + if(!doublejump && self.multijump_ready && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed")) + { + // doublejump = FALSE; // checked above in the if + if (cvar("g_multijump")) + { + if (cvar("g_multijump_add") == 0) // in this case we make the z velocity == jumpvelocity + { + if (self.velocity_z < mjumpheight) + { + doublejump = TRUE; + self.velocity_z = 0; + } + } + else + doublejump = TRUE; + + if(doublejump) + { + if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys + { + float curspeed; + vector wishvel, wishdir; + + curspeed = max( + vlen(vec2(self.velocity)), // current xy speed + vlen(vec2(antilag_takebackavgvelocity(self, max(self.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs + ); + makevectors(self.v_angle_y * '0 1 0'); + wishvel = v_forward * self.movement_x + v_right * self.movement_y; + wishdir = normalize(wishvel); + + self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump + self.velocity_y = wishdir_y * curspeed; + // keep velocity_z unchanged! + } + if (cvar("g_multijump") > 0) + self.multijump_count += 1; + } + } + self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump + } + + if (!doublejump) + if (!(self.flags & FL_ONGROUND)) + return; if(!sv_pogostick) if (!(self.flags & FL_JUMPRELEASED)) @@ -106,6 +185,82 @@ void PlayerJump (void) // value -1 is used to not use the teleport bit (workaround for tiny hitch when re-jumping) } +/* +============= +PlayerDodge + +When you double-press a movement key rapidly to leap in that direction +============= +*/ +void PlayerDodge() +{ + float common_factor; + float new_velocity_gain; + float velocity_difference; + + // make sure v_up, v_right and v_forward are sane + makevectors(self.angles); + + // if we have e.g. 0.5 sec ramptime and a frametime of 0.25, then the ramp code + // will be called ramp_time/frametime times = 2 times. so, we need to + // add 0.5 * the total speed each frame until the dodge action is done.. + common_factor = sys_frametime / cvar("sv_dodging_ramp_time"); + + // if ramp time is smaller than frametime we get problems ;D + if (common_factor > 1) + common_factor = 1; + + new_velocity_gain = self.dodging_velocity_gain - (common_factor * cvar("sv_dodging_horiz_speed")); + if (new_velocity_gain < 0) + new_velocity_gain = 0; + + velocity_difference = self.dodging_velocity_gain - new_velocity_gain; + if(cvar("g_healthsize")) // if we are smaller or larger, we jump lower or higher + velocity_difference *= (1 - cvar("g_healthsize_movementfactor")) + cvar("g_healthsize_movementfactor") * self.scale; + if(self.swallow_progress_prey) // cut jumping based on swallow progress for prey + velocity_difference *= 1 - (self.swallow_progress_prey * cvar("g_balance_vore_swallow_speed_cutspd_prey")); + if(self.swallow_progress_pred) // cut jumping based on swallow progress for preds + velocity_difference *= 1 - (self.swallow_progress_pred * cvar("g_balance_vore_swallow_speed_cutspd_pred")); + + // ramp up dodging speed by adding some velocity each frame.. TODO: do it! :D + if (self.dodging_action == 1) { + //disable jump key during dodge accel phase + if (self.movement_z > 0) self.movement_z = 0; + + self.velocity = + self.velocity + + ((self.dodging_direction_y * velocity_difference) * v_right) + + ((self.dodging_direction_x * velocity_difference) * v_forward); + + self.dodging_velocity_gain = self.dodging_velocity_gain - velocity_difference; + } + + // the up part of the dodge is a single shot action + if (self.dodging_single_action == 1) { + self.flags &~= FL_ONGROUND; + + self.velocity = + self.velocity + + (cvar("sv_dodging_up_speed") * v_up); + + if (cvar("sv_dodging_sound")) + PlayerSound(self, playersound_jump, CHAN_PLAYER, VOICETYPE_PLAYERSOUND); + + setanim(self, self.anim_jump, TRUE, FALSE, TRUE); + + self.dodging_single_action = 0; + } + + // are we done with the dodging ramp yet? + if((self.dodging_action == 1) && ((time - self.last_dodging_time) > cvar("sv_dodging_ramp_time"))) + { + // reset state so next dodge can be done correctly + self.dodging_action = 0; + self.dodging_direction_x = 0; + self.dodging_direction_y = 0; + } +} + void CheckWaterJump() { local vector start, end; @@ -428,6 +583,20 @@ void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float acce if(speedclamp) accelqw = -accelqw; + if(self.classname == "player") + { + if(cvar("g_balance_vore_load_pred_weight") > 0) // apply stomach weight + wishspeed /= 1 + (self.stomach_load / self.stomach_maxload) * cvar("g_balance_vore_load_pred_speed"); + if(cvar("g_healthsize")) // if we are smaller or larger, we run slower or faster + wishspeed *= (1 - cvar("g_healthsize_movementfactor")) + cvar("g_healthsize_movementfactor") * self.scale; + if(self.swallow_progress_prey) // cut speed based on swallow progress for prey + wishspeed *= 1 - (self.swallow_progress_prey * cvar("g_balance_vore_swallow_speed_cutspd_prey")); + if(self.swallow_progress_pred) // cut speed based on swallow progress for preds + wishspeed *= 1 - (self.swallow_progress_pred * cvar("g_balance_vore_swallow_speed_cutspd_pred")); + if(self.grabber_stunned > time && random() <= cvar("g_balance_grabber_secondary_stun_rate")) // randomly cut speed while the player is stunned + return; + } + if(cvar("sv_gameplayfix_q2airaccelerate")) wishspeed0 = wishspeed; @@ -645,7 +814,7 @@ void SV_PlayerPhysics() if (self.punchangle != '0 0 0') { - f = vlen(self.punchangle) - 15 * frametime; + f = vlen(self.punchangle) - cvar("sv_punchangle_speed") * frametime; if (f > 0) self.punchangle = normalize(self.punchangle) * f; else @@ -654,7 +823,7 @@ void SV_PlayerPhysics() if (self.punchvector != '0 0 0') { - f = vlen(self.punchvector) - 30 * frametime; + f = vlen(self.punchvector) - cvar("sv_punchvector_speed") * frametime; if (f > 0) self.punchvector = normalize(self.punchvector) * f; else @@ -697,7 +866,7 @@ void SV_PlayerPhysics() } } - if(self.predator.classname == "player" || self.fakepredator.classname == "player") + if(self.stat_eaten) return; if (self.movetype == MOVETYPE_NONE) @@ -745,8 +914,6 @@ void SV_PlayerPhysics() } maxspd_mod *= swampspd_mod; // only one common speed modder please! - if(cvar("g_balance_vore_weight_gravity") > 0) - maxspd_mod *= 1 - bound(0, self.stomach_load * cvar("g_balance_vore_weight_speed"), 1); // apply stomach weight swampspd_mod = 1; // if dead, behave differently @@ -765,6 +932,7 @@ void SV_PlayerPhysics() { self.wasFlying = 0; + if(self.classname == "player") if(self.waterlevel < WATERLEVEL_SWIMMING) if(time >= self.ladder_time) if not(self.grabber) @@ -774,10 +942,60 @@ void SV_PlayerPhysics() tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self); if not(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) { - if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) - GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND); + if(cvar("g_healthsize")) + { + if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) + { + GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND, bound(0, VOL_BASE * (1 - playersize_micro(self)), 1)); + pointparticles(particleeffectnum("ground_metal"), self.origin, '0 0 0', floor(self.scale * PARTICLE_MULTIPLIER)); + } + else + { + GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND, bound(0, VOL_BASE * (1 - playersize_micro(self)), 1)); + pointparticles(particleeffectnum("ground_dirt"), self.origin, '0 0 0', floor(self.scale * PARTICLE_MULTIPLIER)); + } + sound(self, CHAN_AUTO, "misc/macro_hitground.wav", bound(0, VOL_BASE * playersize_macro(self), 1), ATTN_NORM); + + // earthquake effect for nearby players when a macro falls + if(cvar("g_healthsize_quake_fall")) + { + entity head; + for(head = findradius(self.origin, cvar("g_healthsize_quake_fall_radius")); head; head = head.chain) + { + if not(head.classname == "player" || head.classname == "spectator") + continue; + if(head == self || head.spectatee_status == num_for_edict(self)) + continue; // not for self + if not(head.flags & FL_ONGROUND) + continue; // we only feel the ground shaking if we are sitting on it + if(head.stat_eaten) + continue; // not for prey + + float shake; + shake = vlen(head.origin - self.origin); + if(shake) + shake = 1 - bound(0, shake / cvar("g_healthsize_quake_fall_radius"), 1); + shake *= playersize_macro(self) * cvar("g_healthsize_quake_fall"); + + head.punchvector_x += crandom() * shake; + head.punchvector_y += crandom() * shake; + head.punchvector_z += crandom() * shake; + } + } + } else - GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND); + { + if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) + { + GlobalSound(globalsound_metalfall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND, VOL_BASE); + pointparticles(particleeffectnum("ground_metal"), self.origin, '0 0 0', PARTICLE_MULTIPLIER); + } + else + { + GlobalSound(globalsound_fall, CHAN_PLAYER, VOICETYPE_PLAYERSOUND, VOL_BASE); + pointparticles(particleeffectnum("ground_dirt"), self.origin, '0 0 0', PARTICLE_MULTIPLIER); + } + } } } } @@ -787,12 +1005,12 @@ void SV_PlayerPhysics() if(self.classname == "player") { - if(sv_doublejump && time - self.jumppadusetime > 2 * sys_frametime) + if(self.flags & FL_ONGROUND) { - tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self); - self.flags &~= FL_ONGROUND; - if(trace_fraction < 1 && trace_plane_normal_z > 0.7) - self.flags |= FL_ONGROUND; + if (cvar("g_multijump") > 0) + self.multijump_count = 0; + else + self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller } if (self.BUTTON_JUMP) @@ -802,6 +1020,7 @@ void SV_PlayerPhysics() if (self.waterlevel == WATERLEVEL_SWIMMING) CheckWaterJump (); + self.prevjumpbutton = self.BUTTON_JUMP; } if (self.flags & FL_WATERJUMP ) @@ -818,7 +1037,7 @@ void SV_PlayerPhysics() { RaceCarPhysics(); } - else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY) + else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY) { // noclipping or flying self.flags &~= FL_ONGROUND; @@ -902,7 +1121,7 @@ void SV_PlayerPhysics() PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0); } } - else if ((self.items & IT_JETPACK) && self.BUTTON_JETPACK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO) && self.predator.classname != "player") + else if ((self.items & IT_JETPACK) && self.BUTTON_JETPACK && (!cvar("g_jetpack_fuel") || self.ammo_fuel >= 0.01 || self.items & IT_UNLIMITED_WEAPON_AMMO) && !self.stat_eaten) { //makevectors(self.v_angle_y * '0 1 0'); makevectors(self.v_angle); @@ -1004,7 +1223,7 @@ void SV_PlayerPhysics() else if (self.flags & FL_ONGROUND) { // we get here if we ran out of ammo - if((self.items & IT_JETPACK) && self.BUTTON_JETPACK && !(buttons_prev & 32) && self.predator.classname != "player") + if((self.items & IT_JETPACK) && self.BUTTON_JETPACK && !(buttons_prev & 32) && !self.stat_eaten) sprint(self, "You don't have any fuel for the ^2Jetpack\n"); // walking @@ -1057,7 +1276,7 @@ void SV_PlayerPhysics() if (wishspeed > sv_maxspeed*maxspd_mod) wishspeed = sv_maxspeed*maxspd_mod; if (self.crouch) - wishspeed = wishspeed * 0.5; + wishspeed = wishspeed * cvar("sv_crouchvelocity"); if (time >= self.teleport_time) PM_Accelerate(wishdir, wishspeed, wishspeed, sv_accelerate*maxspd_mod, 1, 0); } @@ -1065,7 +1284,7 @@ void SV_PlayerPhysics() { float wishspeed0; // we get here if we ran out of ammo - if((self.items & IT_JETPACK) && self.BUTTON_JETPACK && !(buttons_prev & 32) && self.predator.classname != "player") + if((self.items & IT_JETPACK) && self.BUTTON_JETPACK && !(buttons_prev & 32) && !self.stat_eaten) sprint(self, "You don't have any fuel for the ^2Jetpack\n"); if(maxspd_mod < 1) @@ -1089,7 +1308,7 @@ void SV_PlayerPhysics() if (wishspeed > maxairspd) wishspeed = maxairspd; if (self.crouch) - wishspeed = wishspeed * 0.5; + wishspeed = wishspeed * cvar("sv_crouchvelocity"); if (time >= self.teleport_time) { float accelerating; @@ -1134,6 +1353,16 @@ void SV_PlayerPhysics() } } + // dodging code + if (cvar("g_dodging") == 0 || self.waterlevel >= WATERLEVEL_SWIMMING) // when swimming, no dodging allowed.. + { + self.dodging_action = 0; + self.dodging_direction_x = 0; + self.dodging_direction_y = 0; + } + else + PlayerDodge(); + if((g_cts || g_race) && self.classname != "observer") { if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) { speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');