From: Mario Date: Thu, 6 Jun 2013 03:18:20 +0000 (+1000) Subject: New mutator: random gravity - changes gravity randomly based on some cvars X-Git-Tag: xonotic-v0.8.0~366^2~41 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4a24706662c44dba69c46aa418ed9b1fd1bc45cd;p=xonotic%2Fxonotic-data.pk3dir.git New mutator: random gravity - changes gravity randomly based on some cvars --- diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index 66ac0b20b..7f718746a 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -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" diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index b110ecf58..71c399312 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -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; + diff --git a/qcsrc/server/miscfunctions.qc b/qcsrc/server/miscfunctions.qc index 522443b9c..e61f38754 100644 --- a/qcsrc/server/miscfunctions.qc +++ b/qcsrc/server/miscfunctions.qc @@ -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 index 000000000..6653312d9 --- /dev/null +++ b/qcsrc/server/mutators/mutator_random_gravity.qc @@ -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; +} diff --git a/qcsrc/server/mutators/mutators.qh b/qcsrc/server/mutators/mutators.qh index 0c17b7ccf..36bc04559 100644 --- a/qcsrc/server/mutators/mutators.qh +++ b/qcsrc/server/mutators/mutators.qh @@ -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); diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src index ab86e6e58..37dc1a02c 100644 --- a/qcsrc/server/progs.src +++ b/qcsrc/server/progs.src @@ -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