X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Fmutators%2Fmutator%2Fmultijump%2Fmultijump.qc;h=ecedc475961585184fd61bad6785d2986f00f23e;hb=fe4926b11ce3b5de1901508af3f4363de0c9ff64;hp=3ee7e020556627462c5380b4622767bf7981404c;hpb=40a875a1a47b9910ea4cf8b723fb8d8b78053d70;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/mutators/mutator/multijump/multijump.qc b/qcsrc/common/mutators/mutator/multijump/multijump.qc index 3ee7e0205..ecedc4759 100644 --- a/qcsrc/common/mutators/mutator/multijump/multijump.qc +++ b/qcsrc/common/mutators/mutator/multijump/multijump.qc @@ -1,185 +1,133 @@ -#ifdef IMPLEMENTATION +#include "multijump.qh" + +#ifdef GAMEQC + #ifdef SVQC - #include "../../../../server/antilag.qh" + #include +#endif +#include + + +#if defined(SVQC) +REGISTER_MUTATOR(multijump, cvar("g_multijump")); +#elif defined(CSQC) +REGISTER_MUTATOR(multijump, true); #endif -#include "../../../physics.qh" -.int multijump_count; +#define PHYS_MULTIJUMP(s) STAT(MULTIJUMP, s) +#define PHYS_MULTIJUMP_SPEED(s) STAT(MULTIJUMP_SPEED, s) +#define PHYS_MULTIJUMP_ADD(s) STAT(MULTIJUMP_ADD, s) +#define PHYS_MULTIJUMP_MAXSPEED(s) STAT(MULTIJUMP_MAXSPEED, s) +#define PHYS_MULTIJUMP_DODGING(s) STAT(MULTIJUMP_DODGING, s) +#define PHYS_MULTIJUMP_COUNT(s) STAT(MULTIJUMP_COUNT, s) + .bool multijump_ready; -.bool cvar_cl_multijump; #ifdef CSQC +bool autocvar_cl_multijump = true; -#define PHYS_MULTIJUMP getstati(STAT_MULTIJUMP) -#define PHYS_MULTIJUMP_SPEED getstatf(STAT_MULTIJUMP_SPEED) -#define PHYS_MULTIJUMP_ADD getstati(STAT_MULTIJUMP_ADD) -#define PHYS_MULTIJUMP_MAXSPEED STAT(MULTIJUMP_MAXSPEED) -#define PHYS_MULTIJUMP_DODGING STAT(MULTIJUMP_DODGING) - + #define PHYS_MULTIJUMP_CLIENT(s) autocvar_cl_multijump #elif defined(SVQC) +.bool cvar_cl_multijump; -int autocvar_g_multijump; -float autocvar_g_multijump_add; -float autocvar_g_multijump_speed; -float autocvar_g_multijump_maxspeed; -float autocvar_g_multijump_dodging = 1; - -#define PHYS_MULTIJUMP autocvar_g_multijump -#define PHYS_MULTIJUMP_SPEED autocvar_g_multijump_speed -#define PHYS_MULTIJUMP_ADD autocvar_g_multijump_add -#define PHYS_MULTIJUMP_MAXSPEED autocvar_g_multijump_maxspeed -#define PHYS_MULTIJUMP_DODGING autocvar_g_multijump_dodging - -.float stat_multijump; -.float stat_multijump_speed; -.float stat_multijump_add; -.float stat_multijump_maxspeed = _STAT(MULTIJUMP_MAXSPEED); -.float stat_multijump_dodging = _STAT(MULTIJUMP_DODGING); - -void multijump_UpdateStats() -{SELFPARAM(); - self.stat_multijump = PHYS_MULTIJUMP; - self.stat_multijump_speed = PHYS_MULTIJUMP_SPEED; - self.stat_multijump_add = PHYS_MULTIJUMP_ADD; - self.stat_multijump_maxspeed = PHYS_MULTIJUMP_MAXSPEED; - self.stat_multijump_dodging = PHYS_MULTIJUMP_DODGING; -} + #define PHYS_MULTIJUMP_CLIENT(s) (s).cvar_cl_multijump +#endif -void multijump_AddStats() +MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics) { - addstat(STAT_MULTIJUMP, AS_INT, stat_multijump); - addstat(STAT_MULTIJUMP_SPEED, AS_FLOAT, stat_multijump_speed); - addstat(STAT_MULTIJUMP_ADD, AS_INT, stat_multijump_add); -} + entity player = M_ARGV(0, entity); +#ifdef CSQC + player.multijump_count = PHYS_MULTIJUMP_COUNT(player); #endif + if(!PHYS_MULTIJUMP(player)) { return; } -void PM_multijump() -{SELFPARAM(); - if(!PHYS_MULTIJUMP) { return; } - - if(IS_ONGROUND(self)) - { - self.multijump_count = 0; - } + if(IS_ONGROUND(player)) + player.multijump_count = 0; } -bool PM_multijump_checkjump() -{SELFPARAM(); - if(!PHYS_MULTIJUMP) { return false; } +MUTATOR_HOOKFUNCTION(multijump, PlayerJump) +{ + entity player = M_ARGV(0, entity); -#ifdef SVQC - bool client_multijump = self.cvar_cl_multijump; -#elif defined(CSQC) - bool client_multijump = cvar("cl_multijump"); + if(!PHYS_MULTIJUMP(player)) { return; } - if(cvar("cl_multijump") > 1) - return false; // nope -#endif + int client_multijump = PHYS_MULTIJUMP_CLIENT(player); + if(client_multijump > 1) + return; // nope - if (!IS_JUMP_HELD(self) && !IS_ONGROUND(self) && client_multijump) // 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 + if (!IS_JUMP_HELD(player) && !IS_ONGROUND(player) && client_multijump) // jump button pressed this frame and we are in midair + player.multijump_ready = true; // this is necessary to check that we released the jump button and pressed it again else - self.multijump_ready = false; - - int phys_multijump = PHYS_MULTIJUMP; + player.multijump_ready = false; -#ifdef CSQC - phys_multijump = (PHYS_MULTIJUMP) ? -1 : 0; -#endif + int phys_multijump = PHYS_MULTIJUMP(player); - if(!player_multijump && self.multijump_ready && (self.multijump_count < phys_multijump || phys_multijump == -1) && self.velocity_z > PHYS_MULTIJUMP_SPEED && (!PHYS_MULTIJUMP_MAXSPEED || vlen(self.velocity) <= PHYS_MULTIJUMP_MAXSPEED)) + if(!M_ARGV(2, bool) && player.multijump_ready && (PHYS_MULTIJUMP_COUNT(player) < phys_multijump || phys_multijump == -1) && player.velocity_z > PHYS_MULTIJUMP_SPEED(player) && + (!PHYS_MULTIJUMP_MAXSPEED(player) || vdist(player.velocity, <=, PHYS_MULTIJUMP_MAXSPEED(player)))) { - if (PHYS_MULTIJUMP) + if (PHYS_MULTIJUMP(player)) { - if (!PHYS_MULTIJUMP_ADD) // in this case we make the z velocity == jumpvelocity + if (!PHYS_MULTIJUMP_ADD(player)) // in this case we make the z velocity == jumpvelocity { - if (self.velocity_z < PHYS_JUMPVELOCITY) + if (player.velocity_z < PHYS_JUMPVELOCITY(player)) { - player_multijump = true; - self.velocity_z = 0; + M_ARGV(2, bool) = true; + player.velocity_z = 0; } } else - player_multijump = true; + M_ARGV(2, bool) = true; - if(player_multijump) + if(M_ARGV(2, bool)) { - if(PHYS_MULTIJUMP_DODGING) - if(self.movement_x != 0 || self.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys + if(PHYS_MULTIJUMP_DODGING(player)) + if(player.movement_x != 0 || player.movement_y != 0) // don't remove all speed if player isnt pressing any movement keys { float curspeed; vector wishvel, wishdir; /*#ifdef SVQC 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 + vlen(vec2(player.velocity)), // current xy speed + vlen(vec2(antilag_takebackavgvelocity(player, max(player.lastteleporttime + sys_frametime, time - 0.25), time))) // average xy topspeed over the last 0.25 secs ); #elif defined(CSQC)*/ - curspeed = vlen(vec2(self.velocity)); + curspeed = vlen(vec2(player.velocity)); //#endif - makevectors(self.v_angle_y * '0 1 0'); - wishvel = v_forward * self.movement_x + v_right * self.movement_y; + makevectors(player.v_angle_y * '0 1 0'); + wishvel = v_forward * player.movement_x + v_right * player.movement_y; wishdir = normalize(wishvel); - self.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump - self.velocity_y = wishdir_y * curspeed; + player.velocity_x = wishdir_x * curspeed; // allow "dodging" at a multijump + player.velocity_y = wishdir_y * curspeed; // keep velocity_z unchanged! } - if (PHYS_MULTIJUMP > 0) + if (PHYS_MULTIJUMP(player) > 0) { - self.multijump_count += 1; + player.multijump_count += 1; } } } - self.multijump_ready = false; // require releasing and pressing the jump button again for the next jump + player.multijump_ready = false; // require releasing and pressing the jump button again for the next jump } - - return false; } #ifdef SVQC -REGISTER_MUTATOR(multijump, cvar("g_multijump")) -{ - MUTATOR_ONADD - { - multijump_AddStats(); - } - return false; -} -MUTATOR_HOOKFUNCTION(multijump, PlayerPhysics) -{ - multijump_UpdateStats(); - PM_multijump(); - - return false; -} - -MUTATOR_HOOKFUNCTION(multijump, PlayerJump) -{ - return PM_multijump_checkjump(); -} - -MUTATOR_HOOKFUNCTION(multijump, GetCvars) -{ - GetCvars_handleFloat(get_cvars_s, get_cvars_f, cvar_cl_multijump, "cl_multijump"); - return false; -} +REPLICATE(cvar_cl_multijump, bool, "cl_multijump"); MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsString) { - ret_string = strcat(ret_string, ":multijump"); - return false; + M_ARGV(0, string) = strcat(M_ARGV(0, string), ":multijump"); } MUTATOR_HOOKFUNCTION(multijump, BuildMutatorsPrettyString) { - ret_string = strcat(ret_string, ", Multi jump"); - return false; + M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Multi jump"); } #endif + #endif