]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mutators/mutator_random_gravity.qc
Start of uncrusticracy script, and kill trailing whitespace in all sources.
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / mutators / mutator_random_gravity.qc
1 // Random Gravity
2 //
3 // Mutator by Mario
4 // Inspired by Player 2
5
6 float gravity_delay;
7
8 MUTATOR_HOOKFUNCTION(gravity_StartFrame)
9 {
10         if(gameover || !cvar("g_random_gravity")) return FALSE;
11         if(time < gravity_delay) return FALSE;
12         if(time < game_starttime) return FALSE;
13         if(round_handler_IsActive() && !round_handler_IsRoundStarted()) return FALSE;
14
15     if(random() >= autocvar_g_random_gravity_negative_chance)
16         cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() - random() * -autocvar_g_random_gravity_negative, autocvar_g_random_gravity_max)));
17     else
18         cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() * autocvar_g_random_gravity_positive, autocvar_g_random_gravity_max)));
19
20         gravity_delay = time + autocvar_g_random_gravity_delay;
21
22         dprint("Gravity is now: ", ftos(autocvar_sv_gravity), "\n");
23
24         return FALSE;
25 }
26
27 MUTATOR_HOOKFUNCTION(gravity_BuildMutatorsString)
28 {
29         ret_string = strcat(ret_string, ":RandomGravity");
30         return 0;
31 }
32
33 MUTATOR_HOOKFUNCTION(gravity_BuildMutatorsPrettyString)
34 {
35         ret_string = strcat(ret_string, ", Random gravity");
36         return 0;
37 }
38
39 MUTATOR_DEFINITION(mutator_random_gravity)
40 {
41         MUTATOR_HOOK(SV_StartFrame, gravity_StartFrame, CBC_ORDER_ANY);
42         MUTATOR_HOOK(BuildMutatorsString, gravity_BuildMutatorsString, CBC_ORDER_ANY);
43         MUTATOR_HOOK(BuildMutatorsPrettyString, gravity_BuildMutatorsPrettyString, CBC_ORDER_ANY);
44
45         MUTATOR_ONADD
46         {
47                 cvar_settemp("sv_gravity", cvar_string("sv_gravity")); // settemp current gravity so it's restored on match end
48         }
49
50         return FALSE;
51 }