]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Experimental day-night cycle mutator
authorMario <zacjardine@y7mail.com>
Sun, 8 Feb 2015 08:29:52 +0000 (19:29 +1100)
committerMario <zacjardine@y7mail.com>
Sun, 8 Feb 2015 08:29:52 +0000 (19:29 +1100)
qcsrc/server/mutators/mutator_skycycle.qc [new file with mode: 0644]
qcsrc/server/mutators/mutators.qc
qcsrc/server/mutators/mutators.qh
qcsrc/server/mutators/mutators_include.qc

diff --git a/qcsrc/server/mutators/mutator_skycycle.qc b/qcsrc/server/mutators/mutator_skycycle.qc
new file mode 100644 (file)
index 0000000..f72ab2f
--- /dev/null
@@ -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;
+}
index 7fc13c96e1e9d754d4a98fac5eb18602782a9f30..8535f5de5956c0cfbbe53f8837c92fbfbcda97cd 100644 (file)
@@ -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
 }
index e2579e9e608c3625a3668bb60cba70dfe9198ef6..2fa9d72c3ba55ca962d6cfad70df5efab9713f18 100644 (file)
@@ -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
index dd0430251f0bf54d79b48328327a36d2d0848e7b..73e9474b2b6c9d7995ecefd5a134d9e2b41ceab8 100644 (file)
 #include "mutator_piggyback.qc"
 #include "mutator_buffs.qc"
 #include "mutator_itemeditor.qc"
+#include "mutator_skycycle.qc"