]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Added Sprint mutator.
authorLyberta <lyberta@lyberta.net>
Sat, 19 May 2018 00:04:02 +0000 (03:04 +0300)
committerLyberta <lyberta@lyberta.net>
Sat, 19 May 2018 00:04:02 +0000 (03:04 +0300)
mutators.cfg
qcsrc/common/mutators/mutator/_mod.inc
qcsrc/common/mutators/mutator/_mod.qh
qcsrc/common/mutators/mutator/sprint/_mod.inc [new file with mode: 0644]
qcsrc/common/mutators/mutator/sprint/_mod.qh [new file with mode: 0644]
qcsrc/common/mutators/mutator/sprint/sv_sprint.qc [new file with mode: 0644]

index c997a807f459574846fc3de6b11af14ddbe7447b..45e2be56091b5638dbc3db4ad3675c669a17dd71 100644 (file)
@@ -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
 // =========
index 40a763c8ec04b39b9a39dfb3d8d915bf647e1324..7d32fd1ab178cbdc83a304a29887c2229df0b577 100644 (file)
@@ -33,6 +33,7 @@
 #include <common/mutators/mutator/running_guns/_mod.inc>
 #include <common/mutators/mutator/sandbox/_mod.inc>
 #include <common/mutators/mutator/spawn_near_teammate/_mod.inc>
+#include <common/mutators/mutator/sprint/_mod.inc>
 #include <common/mutators/mutator/stale_move_negation/_mod.inc>
 #include <common/mutators/mutator/superspec/_mod.inc>
 #include <common/mutators/mutator/touchexplode/_mod.inc>
index 6a9261dd41f394cd3496bf119ec6fa92e6ebb0f1..1d157580f63e8126c7d5784120b1861a5f452364 100644 (file)
@@ -33,6 +33,7 @@
 #include <common/mutators/mutator/running_guns/_mod.qh>
 #include <common/mutators/mutator/sandbox/_mod.qh>
 #include <common/mutators/mutator/spawn_near_teammate/_mod.qh>
+#include <common/mutators/mutator/sprint/_mod.qh>
 #include <common/mutators/mutator/stale_move_negation/_mod.qh>
 #include <common/mutators/mutator/superspec/_mod.qh>
 #include <common/mutators/mutator/touchexplode/_mod.qh>
diff --git a/qcsrc/common/mutators/mutator/sprint/_mod.inc b/qcsrc/common/mutators/mutator/sprint/_mod.inc
new file mode 100644 (file)
index 0000000..1f7a072
--- /dev/null
@@ -0,0 +1,4 @@
+// generated file; do not modify
+#ifdef SVQC
+    #include <common/mutators/mutator/sprint/sv_sprint.qc>
+#endif
diff --git a/qcsrc/common/mutators/mutator/sprint/_mod.qh b/qcsrc/common/mutators/mutator/sprint/_mod.qh
new file mode 100644 (file)
index 0000000..98fb481
--- /dev/null
@@ -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 (file)
index 0000000..bd6899e
--- /dev/null
@@ -0,0 +1,86 @@
+//#include <server/resources.qh>
+
+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);
+}