]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
New mutator: random gravity - changes gravity randomly based on some cvars
authorMario <mario.mario@y7mail.com>
Thu, 6 Jun 2013 03:18:20 +0000 (13:18 +1000)
committerMario <mario.mario@y7mail.com>
Thu, 6 Jun 2013 03:18:20 +0000 (13:18 +1000)
defaultXonotic.cfg
qcsrc/server/autocvars.qh
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/mutator_random_gravity.qc [new file with mode: 0644]
qcsrc/server/mutators/mutators.qh
qcsrc/server/progs.src

index 66ac0b20b23ce711a0efa48b3f022781676ecbe1..7f718746acdb7b3435b5092dac0f757d1d66f2ed 100644 (file)
@@ -1601,3 +1601,11 @@ set cl_weapon_stay_color "2 0.5 0.5" "Color of picked up weapons when g_weapon_s
 set cl_weapon_stay_alpha 0.75 "Alpha of picked up weapons when g_weapon_stay > 0"
 
 seta g_superspectate 0 "server side, allows extended spectator functions through the cmd interface. followpowerup, followstrength, followstshield or followfc [red|blue] will transfer spectation to the relevent player, if any"
+
+set g_random_gravity 0 "enable random gravity mutator"
+set g_random_gravity_delay 3 "delay between gravity changes"
+set g_random_gravity_negative_chance 0.5 "chance of gravity being a negative value"
+set g_random_gravity_min -2000 "minimum gravity"
+set g_random_gravity_max 2000 "maximum gravity"
+set g_random_gravity_positive 1000 "positive gravity multiplier"
+set g_random_gravity_negative 1000 "negative gravity multiplier"
index b110ecf5897a6d921f23f9405f1c8ccabff507e1..71c399312d3887c3577215acafb3385e48bb9fde 100644 (file)
@@ -1234,3 +1234,10 @@ float autocvar_g_touchexplode_damage;
 float autocvar_g_touchexplode_edgedamage;
 float autocvar_g_touchexplode_force;
 #define autocvar_g_bloodloss cvar("g_bloodloss")
+float autocvar_g_random_gravity_negative_chance;
+float autocvar_g_random_gravity_min;
+float autocvar_g_random_gravity_max;
+float autocvar_g_random_gravity_positive;
+float autocvar_g_random_gravity_negative;
+float autocvar_g_random_gravity_delay;
+
index 522443b9ce66416ada5071a694bf19f71080f8ff..e61f387541c8c8f1422be8c037e2565568bb9ff9 100644 (file)
@@ -921,6 +921,7 @@ void readlevelcvars(void)
        CHECK_MUTATOR_ADD("g_pinata", mutator_pinata, !cvar("g_minstagib"));
        CHECK_MUTATOR_ADD("g_midair", mutator_midair, 1);
        CHECK_MUTATOR_ADD("g_bloodloss", mutator_bloodloss, !cvar("g_minstagib"));
+       CHECK_MUTATOR_ADD("g_random_gravity", mutator_random_gravity, 1);
        CHECK_MUTATOR_ADD("g_sandbox", sandbox, 1);
        
        #undef CHECK_MUTATOR_ADD
diff --git a/qcsrc/server/mutators/mutator_random_gravity.qc b/qcsrc/server/mutators/mutator_random_gravity.qc
new file mode 100644 (file)
index 0000000..6653312
--- /dev/null
@@ -0,0 +1,61 @@
+float gravity_delay;
+float old_gravity;
+MUTATOR_HOOKFUNCTION(gravity_StartFrame)
+{
+       if(gameover)
+       {
+               if(autocvar_sv_gravity != old_gravity)
+               {
+                       cvar_set("sv_gravity", ftos(old_gravity));
+                       old_gravity = autocvar_sv_gravity; // update now so it can be changed during match end
+               }
+               
+               return FALSE;
+       }
+               
+       if(time < gravity_delay) return FALSE;
+       if(time < game_starttime) return FALSE;
+       if(round_handler_IsActive() && !round_handler_IsRoundStarted()) return FALSE;
+       
+    if(random() >= autocvar_g_random_gravity_negative_chance) 
+        cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() - random() * -autocvar_g_random_gravity_negative, autocvar_g_random_gravity_max)));
+    else
+        cvar_set("sv_gravity", ftos(bound(autocvar_g_random_gravity_min, random() * autocvar_g_random_gravity_positive, autocvar_g_random_gravity_max)));
+       
+       gravity_delay = time + autocvar_g_random_gravity_delay;
+       
+       dprint("Gravity is now: ", ftos(autocvar_sv_gravity), "\n");
+       
+       return FALSE;
+}
+
+MUTATOR_HOOKFUNCTION(gravity_BuildMutatorsString)
+{
+       ret_string = strcat(ret_string, ":RandomGravity");
+       return 0;
+}
+
+MUTATOR_HOOKFUNCTION(gravity_BuildMutatorsPrettyString)
+{
+       ret_string = strcat(ret_string, ", Random gravity");
+       return 0;
+}
+
+MUTATOR_DEFINITION(mutator_random_gravity)
+{
+       MUTATOR_HOOK(SV_StartFrame, gravity_StartFrame, CBC_ORDER_ANY);
+       MUTATOR_HOOK(BuildMutatorsString, gravity_BuildMutatorsString, CBC_ORDER_ANY);
+       MUTATOR_HOOK(BuildMutatorsPrettyString, gravity_BuildMutatorsPrettyString, CBC_ORDER_ANY);
+       
+       MUTATOR_ONADD
+       {
+               old_gravity = autocvar_sv_gravity;
+       }
+       
+       MUTATOR_ONREMOVE
+       {
+               cvar_set("sv_gravity", ftos(old_gravity));
+       }
+
+       return FALSE;
+}
index 0c17b7ccf8fe20ce1c8e3dae690813d18b4c6a17..36bc045593b75a5b508f208fda6641aec5ed21d3 100644 (file)
@@ -24,5 +24,6 @@ MUTATOR_DECLARATION(mutator_touchexplode);
 MUTATOR_DECLARATION(mutator_pinata);
 MUTATOR_DECLARATION(mutator_midair);
 MUTATOR_DECLARATION(mutator_bloodloss);
+MUTATOR_DECLARATION(mutator_random_gravity);
 
 MUTATOR_DECLARATION(sandbox);
index ab86e6e58cc5b5c5d078935afc3fdf63479f8d82..37dc1a02ceeeefe31d6dbe8d6eb3eb2227cb481a 100644 (file)
@@ -251,6 +251,7 @@ mutators/mutator_touchexplode.qc
 mutators/mutator_pinata.qc
 mutators/mutator_midair.qc
 mutators/mutator_bloodloss.qc
+mutators/mutator_random_gravity.qc
 
 ../warpzonelib/anglestransform.qc
 ../warpzonelib/mathlib.qc