From: Mario Date: Sun, 8 Feb 2015 08:29:52 +0000 (+1100) Subject: Experimental day-night cycle mutator X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=5d605f952d8d976d2bafe056f34811501bb65ba5;p=xonotic%2Fxonotic-data.pk3dir.git Experimental day-night cycle mutator --- diff --git a/qcsrc/server/mutators/mutator_skycycle.qc b/qcsrc/server/mutators/mutator_skycycle.qc new file mode 100644 index 000000000..f72ab2f8a --- /dev/null +++ b/qcsrc/server/mutators/mutator_skycycle.qc @@ -0,0 +1,334 @@ +float g_skycycle; +float g_skycycle_started; +float skycycle_time; +float skycycle_timebetween; +float skycycle_timestart; +//float skycycle_timecurrent; +//float skycycle_timenext; +float skycycle_epoch; +float skycycle_intensity_realmax; //Max (Less than Goal if you want long days/nights) +float skycycle_intensity_realmin; //Min (More than Goal if you want long days/nights) +float skycycle_intensity_max; //Goal +float skycycle_intensity_min; //Goal +float skycycle_intensity_current; +float skycycle_ambient_realmax; //Max (Less than Goal if you want long days/nights) +float skycycle_ambient_realmin; //Min (More than Goal if you want long days/nights) +float skycycle_ambient_max; //Goal +float skycycle_ambient_min; //Goal +float skycycle_ambient_current; +float skycycle_skybox; +float skycycle_skybox_number; +float autocvar_g_skycycle_intensity_realmax; +float autocvar_g_skycycle_intensity_realmin; +float autocvar_g_skycycle_ambient_realmax; +float autocvar_g_skycycle_ambient_realmin; +float autocvar_g_skycycle_startatnight; +float autocvar_g_skycycle_startattime; +float autocvar_g_skycycle_timelock; +string autocvar_g_skycycle_nightsky; +string autocvar_g_skycycle_dusksky; +string autocvar_g_skycycle_daysky; +string skycycle_nightsky; +string skycycle_dusksky; +string skycycle_daysky; +float skycycle_nightsky_max; +float skycycle_dusksky_max; +.float skycycle_playernextthink; + +float autocvar_g_skycycle_time; +float autocvar_g_skycycle_timebetween; +float autocvar_g_skycycle_intensity_max; +float autocvar_g_skycycle_intensity_min; +float autocvar_g_skycycle_ambient_max; +float autocvar_g_skycycle_ambient_min; +float autocvar_g_skycycle_nightsky_max; +float autocvar_g_skycycle_dusksky_max; +float autocvar_g_skycycle_skybox; + + +void SkyCycle_Set() +{ + skycycle_time = autocvar_g_skycycle_time; + skycycle_timebetween = autocvar_g_skycycle_timebetween; + skycycle_intensity_max = autocvar_g_skycycle_intensity_max; + skycycle_intensity_min = autocvar_g_skycycle_intensity_min; + skycycle_ambient_max = autocvar_g_skycycle_ambient_max; + skycycle_ambient_min = autocvar_g_skycycle_ambient_min; + skycycle_intensity_realmax = autocvar_g_skycycle_intensity_realmax; + skycycle_intensity_realmin = autocvar_g_skycycle_intensity_realmin; + skycycle_ambient_realmax = autocvar_g_skycycle_ambient_realmax; + skycycle_ambient_realmin = autocvar_g_skycycle_ambient_realmin; + skycycle_nightsky = autocvar_g_skycycle_nightsky; + skycycle_dusksky = autocvar_g_skycycle_dusksky; + skycycle_daysky = autocvar_g_skycycle_daysky; + skycycle_nightsky_max = autocvar_g_skycycle_nightsky_max; + skycycle_dusksky_max = autocvar_g_skycycle_dusksky_max; + skycycle_skybox = autocvar_g_skycycle_skybox; + skycycle_skybox_number = 0; + + entity e; + FOR_EACH_REALCLIENT(e) + e.skycycle_playernextthink = time; +} + +void SkyCycle_Restart() +{ + skycycle_timestart = time; +} + +void SkyCycle_Lighten() +{ + //print("Lighten\n"); + float d, m; + m = skycycle_intensity_max - skycycle_intensity_min; + d = + skycycle_intensity_min + + (m * + ((time - skycycle_timestart) / skycycle_time)); + + skycycle_intensity_current = d; + + m = skycycle_ambient_max - skycycle_ambient_min; + d = + skycycle_ambient_min + + (m * + ((time - skycycle_timestart) / skycycle_time)); + + skycycle_ambient_current = d; +} + +void SkyCycle_Darken() +{ + //print("Darken\n"); + float d, m; + m = skycycle_intensity_max - skycycle_intensity_min; + d = + skycycle_intensity_max - + (m * + ((time - skycycle_timestart) / skycycle_time)); + + skycycle_intensity_current = d; + + m = skycycle_ambient_max - skycycle_ambient_min; + d = + skycycle_ambient_max - + (m * + ((time - skycycle_timestart) / skycycle_time)); + + skycycle_ambient_current = d; +} + +void SkyCycle_Run() +{ + //print("SkyCycle Run\n"); + if (time - skycycle_timestart > skycycle_time) + { + //Restart + SkyCycle_Restart(); + if (skycycle_epoch == 1) + skycycle_epoch = 0; + else + skycycle_epoch = 1; + } + else + { + if (skycycle_epoch == 1) + SkyCycle_Lighten(); + else + SkyCycle_Darken(); + } + if (autocvar_g_skycycle_timelock) + //Advance start time at same pace if timelock is set + skycycle_timestart += skycycle_timebetween; + + self.nextthink = time + skycycle_timebetween; +} + +void SkyCycle_Spawn() +{ + SkyCycle_Set(); + entity e; + + e = spawn(); + e.think = SkyCycle_Run; + e.nextthink = time; //Start Right Away + skycycle_epoch = 0; + SkyCycle_Restart(); + + //print("spawning sky cycle\n"); +} + +void SkyCycle_SendPlayer(float checkboxnum) +{ + //print("sending sky stuff\n"); + //print(strcat("maxintensity ", ftos(skycycle_intensity_realmax), "\n")); + //print(strcat("maxambient", ftos(skycycle_ambient_realmax), "\n")); + //print(strcat("intensity ", ftos(skycycle_intensity_current), "\n")); + //print(strcat("ambient ", ftos(skycycle_ambient_current), "\n")); + stuffcmd(self, strcat("cl_cmd settemp r_fakelight_intensity ", ftos(skycycle_intensity_current), "\n")); + stuffcmd(self, strcat("cl_cmd settemp r_ambient ", ftos(skycycle_ambient_current), "\n")); + + if (skycycle_skybox) + { + if (skycycle_intensity_current < skycycle_nightsky_max) + { + if ((skycycle_skybox_number == 2) && (checkboxnum)) + { + //Do nothing + } + else + { + if (checkboxnum) + { + //Send to all players + entity e; + FOR_EACH_REALCLIENT(e) + stuffcmd(e, strcat("loadsky ", skycycle_nightsky, "\n")); + } + else + { + stuffcmd(self, strcat("loadsky ", skycycle_nightsky, "\n")); + } + skycycle_skybox_number = 2; + } + } + else if(skycycle_intensity_current < skycycle_dusksky_max) + { + if((skycycle_skybox_number == 1) && (checkboxnum)) + { + //Do nothing + } + else + { + if(checkboxnum) + { + //Send to all players + entity e; + FOR_EACH_REALCLIENT(e) + stuffcmd(e, strcat("loadsky ", skycycle_dusksky, "\n")); + } + else + { + stuffcmd(self, strcat("loadsky ", skycycle_dusksky, "\n")); + } + skycycle_skybox_number = 1; + } + } + else + { + if((skycycle_skybox_number == 0) && (checkboxnum)) + { + //Do nothing + } + else + { + if(checkboxnum) + { + //Send to all players + entity e; + FOR_EACH_REALCLIENT(e) + stuffcmd(e, strcat("loadsky ", skycycle_daysky, "\n")); + } + else + { + stuffcmd(self, strcat("loadsky ", skycycle_daysky, "\n")); + } + skycycle_skybox_number = 0; + } + } + } +} + + +MUTATOR_HOOKFUNCTION(skycycle_PlayerPreThink) +{ + if (g_skycycle) + if (time > self.skycycle_playernextthink) + { + SkyCycle_SendPlayer(1); + self.skycycle_playernextthink = time + 1; + } + return false; +} + +MUTATOR_HOOKFUNCTION(skycycle_PlayerSpawn) +{ + stuffcmd(self, "cl_cmd settemp r_fakelight 2\n"); + + SkyCycle_SendPlayer(0); + return false; +} + +MUTATOR_HOOKFUNCTION(skycycle_StartFrame) +{ + if(skycycle_ambient_realmin > skycycle_ambient_current) + skycycle_ambient_current = autocvar_g_skycycle_ambient_realmin; + + if(skycycle_intensity_realmin > skycycle_intensity_current) + skycycle_intensity_current = autocvar_g_skycycle_intensity_realmin; + + if(skycycle_ambient_realmax < skycycle_ambient_current) + skycycle_ambient_current = autocvar_g_skycycle_ambient_realmax; + + if(skycycle_intensity_realmax < skycycle_intensity_current) + skycycle_intensity_current = autocvar_g_skycycle_intensity_realmax; + + return false; +} + +MUTATOR_HOOKFUNCTION(skycycle_ResetMap) +{ + SkyCycle_Restart(); + return false; +} + +MUTATOR_HOOKFUNCTION(skycycle_BuildMutatorsString) +{ + ret_string = strcat(ret_string, ":skycycle"); + return false; +} + +MUTATOR_HOOKFUNCTION(skycycle_BuildMutatorsPrettyString) +{ + ret_string = strcat(ret_string, ", Sky Cycle"); + return false; +} + +void skycycle_Init() +{ + SkyCycle_Spawn(); + + if(autocvar_g_skycycle_startatnight) + skycycle_epoch = 1; + + if(autocvar_g_skycycle_startattime) + skycycle_timestart = time - (skycycle_time * autocvar_g_skycycle_startattime); + + g_skycycle_started = 1; +} + +MUTATOR_DEFINITION(mutator_skycycle) +{ + MUTATOR_HOOK(PlayerSpawn, skycycle_PlayerSpawn, CBC_ORDER_ANY); + MUTATOR_HOOK(PlayerPreThink, skycycle_PlayerPreThink, CBC_ORDER_ANY); + MUTATOR_HOOK(SV_StartFrame, skycycle_StartFrame, CBC_ORDER_ANY); + MUTATOR_HOOK(reset_map_global, skycycle_ResetMap, CBC_ORDER_ANY); + MUTATOR_HOOK(BuildMutatorsString, skycycle_BuildMutatorsString, CBC_ORDER_ANY); + MUTATOR_HOOK(BuildMutatorsPrettyString, skycycle_BuildMutatorsPrettyString, CBC_ORDER_ANY); + + // this just turns on the cvar. + MUTATOR_ONADD + { + g_skycycle = 1; + serverflags |= SERVERFLAG_ALLOW_FULLBRIGHT; + InitializeEntity(world, skycycle_Init, INITPRIO_GAMETYPE); + } + + // this just turns off the cvar. + MUTATOR_ONREMOVE + { + g_skycycle = 0; + } + + return 0; +} diff --git a/qcsrc/server/mutators/mutators.qc b/qcsrc/server/mutators/mutators.qc index 7fc13c96e..8535f5de5 100644 --- a/qcsrc/server/mutators/mutators.qc +++ b/qcsrc/server/mutators/mutators.qc @@ -41,6 +41,7 @@ void mutators_add() CHECK_MUTATOR_ADD("g_piggyback", mutator_piggyback, 1); CHECK_MUTATOR_ADD("g_buffs", mutator_buffs, !g_nexball && !g_race && !g_cts); CHECK_MUTATOR_ADD("g_itemeditor", mutator_itemeditor, cvar("g_pickup_items") && !g_ca); + CHECK_MUTATOR_ADD("g_skycycle", mutator_skycycle, 1); #undef CHECK_MUTATOR_ADD } diff --git a/qcsrc/server/mutators/mutators.qh b/qcsrc/server/mutators/mutators.qh index e2579e9e6..2fa9d72c3 100644 --- a/qcsrc/server/mutators/mutators.qh +++ b/qcsrc/server/mutators/mutators.qh @@ -50,7 +50,7 @@ MUTATOR_DECLARATION(mutator_random_vehicles); MUTATOR_DECLARATION(mutator_piggyback); MUTATOR_DECLARATION(mutator_buffs); MUTATOR_DECLARATION(mutator_itemeditor); - +MUTATOR_DECLARATION(mutator_skycycle); MUTATOR_DECLARATION(sandbox); #endif diff --git a/qcsrc/server/mutators/mutators_include.qc b/qcsrc/server/mutators/mutators_include.qc index dd0430251..73e9474b2 100644 --- a/qcsrc/server/mutators/mutators_include.qc +++ b/qcsrc/server/mutators/mutators_include.qc @@ -130,3 +130,4 @@ #include "mutator_piggyback.qc" #include "mutator_buffs.qc" #include "mutator_itemeditor.qc" +#include "mutator_skycycle.qc"