]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/mutators/mutator/random_gravity/random_gravity.qc
Remove unnecessary returns
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / random_gravity / random_gravity.qc
1 #ifdef IMPLEMENTATION
2 // Random Gravity
3 //
4 // Mutator by Mario
5 // Inspired by Player 2
6
7 float autocvar_g_random_gravity_negative_chance;
8 float autocvar_g_random_gravity_min;
9 float autocvar_g_random_gravity_max;
10 float autocvar_g_random_gravity_positive;
11 float autocvar_g_random_gravity_negative;
12 float autocvar_g_random_gravity_delay;
13
14 REGISTER_MUTATOR(random_gravity, cvar("g_random_gravity"))
15 {
16         MUTATOR_ONADD
17         {
18                 cvar_settemp("sv_gravity", cvar_string("sv_gravity")); // settemp current gravity so it's restored on match end
19         }
20 }
21
22 float gravity_delay;
23
24 MUTATOR_HOOKFUNCTION(random_gravity, SV_StartFrame)
25 {
26         if(gameover || !cvar("g_random_gravity")) return false;
27         if(time < gravity_delay) return false;
28         if(time < game_starttime) return false;
29         if(round_handler_IsActive() && !round_handler_IsRoundStarted()) return false;
30
31     if(random() >= autocvar_g_random_gravity_negative_chance)
32         cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() - random() * -autocvar_g_random_gravity_negative, autocvar_g_random_gravity_max)));
33     else
34         cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() * autocvar_g_random_gravity_positive, autocvar_g_random_gravity_max)));
35
36         gravity_delay = time + autocvar_g_random_gravity_delay;
37
38         LOG_TRACE("Gravity is now: ", ftos(autocvar_sv_gravity), "\n");
39 }
40
41 MUTATOR_HOOKFUNCTION(random_gravity, BuildMutatorsString)
42 {
43         M_ARGV(0, string) = strcat(M_ARGV(0, string), ":RandomGravity");
44 }
45
46 MUTATOR_HOOKFUNCTION(random_gravity, BuildMutatorsPrettyString)
47 {
48         M_ARGV(0, string) = strcat(M_ARGV(0, string), ", Random gravity");
49 }
50 #endif