From: Lyberta Date: Sat, 19 May 2018 00:04:02 +0000 (+0300) Subject: Added Sprint mutator. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=58216899941c71986db9dc6905df303990108939;p=xonotic%2Fxonotic-data.pk3dir.git Added Sprint mutator. --- diff --git a/mutators.cfg b/mutators.cfg index c997a807f..45e2be560 100644 --- a/mutators.cfg +++ b/mutators.cfg @@ -3,6 +3,14 @@ // ========================= +// ======== +// sprint +// ======== +set g_sprint 0 "whether to enable sprint" +set g_sprint_speed_multiplier 1.5 "speed multiplier of sprinting" +set g_sprint_in_air 1 "whether to increase air acceleration too" +set g_sprint_cost 10 "amount of fuel that sprinting costs per second" + // ========= // dodging // ========= diff --git a/qcsrc/common/mutators/mutator/_mod.inc b/qcsrc/common/mutators/mutator/_mod.inc index 40a763c8e..7d32fd1ab 100644 --- a/qcsrc/common/mutators/mutator/_mod.inc +++ b/qcsrc/common/mutators/mutator/_mod.inc @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/_mod.qh b/qcsrc/common/mutators/mutator/_mod.qh index 6a9261dd4..1d157580f 100644 --- a/qcsrc/common/mutators/mutator/_mod.qh +++ b/qcsrc/common/mutators/mutator/_mod.qh @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/qcsrc/common/mutators/mutator/sprint/_mod.inc b/qcsrc/common/mutators/mutator/sprint/_mod.inc new file mode 100644 index 000000000..1f7a0724b --- /dev/null +++ b/qcsrc/common/mutators/mutator/sprint/_mod.inc @@ -0,0 +1,4 @@ +// generated file; do not modify +#ifdef SVQC + #include +#endif diff --git a/qcsrc/common/mutators/mutator/sprint/_mod.qh b/qcsrc/common/mutators/mutator/sprint/_mod.qh new file mode 100644 index 000000000..98fb4815c --- /dev/null +++ b/qcsrc/common/mutators/mutator/sprint/_mod.qh @@ -0,0 +1 @@ +// generated file; do not modify diff --git a/qcsrc/common/mutators/mutator/sprint/sv_sprint.qc b/qcsrc/common/mutators/mutator/sprint/sv_sprint.qc new file mode 100644 index 000000000..bd6899e87 --- /dev/null +++ b/qcsrc/common/mutators/mutator/sprint/sv_sprint.qc @@ -0,0 +1,86 @@ +//#include + +string autocvar_g_sprint = "0"; ///< Whether to enable sprint. +float autocvar_g_sprint_speed_multiplier; ///< Speed multiplier of sprinting. +bool autocvar_g_sprint_in_air; ///< Whether to increase air acceleration too. +/// \brief Amount of fuel that sprinting costs per second. +float autocvar_g_sprint_cost; + +.bool m_is_sprinting; ///< Whether player is sprinting. + +REGISTER_MUTATOR(sprint, expr_evaluate(autocvar_g_sprint)); + +MUTATOR_HOOKFUNCTION(sprint, BuildMutatorsString) +{ + M_ARGV(0, string) = strcat(M_ARGV(0, string), ":sprint"); +} + +MUTATOR_HOOKFUNCTION(sprint, BuildMutatorsPrettyString) +{ + M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Sprint"); +} + +MUTATOR_HOOKFUNCTION(sprint, BuildGameplayTipsString) +{ + M_ARGV(0, string) = strcat(M_ARGV(0, string), "\n\n^3Sprint^8 is enabled, press the dodge button to sprint\n"); +} + +MUTATOR_HOOKFUNCTION(sprint, SetStartItems) +{ + if (autocvar_g_sprint_cost > 0) + { + start_items |= ITEM_JetpackRegen.m_itemid; + start_ammo_fuel = max(start_ammo_fuel, cvar("g_balance_fuel_rotstable")); + warmup_start_ammo_fuel = start_ammo_fuel; + } +} + +MUTATOR_HOOKFUNCTION(sprint, GetPressedKeys) +{ + entity player = M_ARGV(0, entity); + if (PHYS_INPUT_BUTTON_DODGE(player)) + { + player.m_is_sprinting = true; + } + else + { + player.m_is_sprinting = false; + } +} + +MUTATOR_HOOKFUNCTION(sprint, PlayerPhysics_UpdateStats) +{ + entity player = M_ARGV(0, entity); + if (!player.m_is_sprinting) + { + return; + } + float cost = 0; + float fuel = 0; + if (autocvar_g_sprint_cost > 0) + { + cost = autocvar_g_sprint_cost * frametime; + fuel = GetResourceAmount(player, RESOURCE_FUEL); + if (fuel < cost) + { + player.m_is_sprinting = false; + return; + } + + } + if (!IS_ONGROUND(player) && !autocvar_g_sprint_in_air) + { + return; + } + STAT(MOVEVARS_HIGHSPEED, player) *= autocvar_g_sprint_speed_multiplier; + if (autocvar_g_sprint_cost <= 0) + { + return; + } + if ((PHYS_INPUT_MOVEVALUES(player).x == 0) && + (PHYS_INPUT_MOVEVALUES(player).y == 0)) + { + return; + } + SetResourceAmount(player, RESOURCE_FUEL, fuel - cost); +}