2012-05-22 20:16:48 +00:00
|
|
|
/**--
|
2010-02-26 06:18:06 +00:00
|
|
|
Time Controller
|
|
|
|
Author:Ringwall
|
|
|
|
|
|
|
|
Creates time based on the 24-hour time scheme.
|
2010-09-13 15:27:48 +00:00
|
|
|
Time is computed in minutes, which are by default
|
2010-02-26 06:18:06 +00:00
|
|
|
1/2 a second in real life (18 frames). This will
|
|
|
|
make each complete day/night cycle last 12 minutes
|
|
|
|
in real life.
|
|
|
|
--*/
|
|
|
|
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
local time;
|
2010-02-27 23:15:32 +00:00
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
// Sets the current time using a 24*60 minute clock scheme.
|
|
|
|
public func SetTime(int to_time)
|
|
|
|
{
|
|
|
|
// Set time.
|
|
|
|
time = to_time % (24 * 60);
|
|
|
|
// Adjust to time.
|
|
|
|
AdjustToTime();
|
|
|
|
return;
|
2010-02-26 06:18:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
// Returns the time in minutes.
|
|
|
|
public func GetTime()
|
2010-02-26 06:18:06 +00:00
|
|
|
{
|
2010-09-29 16:25:44 +00:00
|
|
|
return time;
|
2010-02-26 06:18:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
// Sets the number of frames per clonk-minute.
|
|
|
|
// Standard is 18 frames per minute, making a day-night cycle of 12 minutes.
|
|
|
|
// Setting minute lenght to 0 will stop day-night cycle.
|
|
|
|
public func SetCycleSpeed(int speed)
|
2010-07-06 10:29:08 +00:00
|
|
|
{
|
2010-12-27 15:27:39 +00:00
|
|
|
//GetEffect("IntTimeCycle", this).Interval = Max(0, speed);
|
2010-09-29 16:25:44 +00:00
|
|
|
RemoveEffect("IntTimeCycle", this);
|
|
|
|
AddEffect("IntTimeCycle", this, 100, Max(0, speed), this);
|
|
|
|
return;
|
2010-07-06 10:29:08 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
public func GetCycleSpeed()
|
2010-02-26 06:18:06 +00:00
|
|
|
{
|
2010-12-24 14:10:39 +00:00
|
|
|
return GetEffect("IntTimeCycle", this).Interval;
|
2010-02-26 06:18:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
local time_set;
|
2010-02-26 06:18:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
protected func Initialize()
|
|
|
|
{
|
2010-09-29 16:25:44 +00:00
|
|
|
// Only one time control object.
|
|
|
|
if (ObjectCount(Find_ID(Environment_Time)) > 1)
|
|
|
|
return RemoveObject();
|
|
|
|
|
|
|
|
time_set = {
|
|
|
|
SunriseStart = 180,
|
|
|
|
SunriseEnd = 540,
|
|
|
|
SunsetStart = 900,
|
|
|
|
SunsetEnd = 1260,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Add effect that controls time cycle.
|
|
|
|
AddEffect("IntTimeCycle", this, 100, 18, this);
|
|
|
|
|
|
|
|
// Set the time to midday (12:00).
|
|
|
|
time = 720;
|
2010-02-27 23:15:32 +00:00
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
// Create moon and stars.
|
|
|
|
if (FindObject(Find_ID(Environment_Celestial)))
|
2010-02-27 23:15:32 +00:00
|
|
|
{
|
2012-02-20 11:58:58 +00:00
|
|
|
CreateObject(Moon, LandscapeWidth() / 2, LandscapeHeight() / 6);
|
2010-02-27 23:15:32 +00:00
|
|
|
PlaceStars();
|
|
|
|
}
|
2010-09-29 16:25:44 +00:00
|
|
|
return;
|
2010-02-26 06:18:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
public func IsDay()
|
2010-02-26 06:18:06 +00:00
|
|
|
{
|
2010-09-29 16:25:44 +00:00
|
|
|
var day_start = (time_set["SunriseStart"] + time_set["SunriseEnd"]) / 2;
|
|
|
|
var day_end = (time_set["SunsetStart"] + time_set["SunsetEnd"]) / 2;
|
|
|
|
if (Inside(time, day_start, day_end))
|
|
|
|
return true;
|
|
|
|
return false;
|
2010-02-26 06:18:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
public func IsNight()
|
2010-02-26 06:18:06 +00:00
|
|
|
{
|
2010-09-29 16:25:44 +00:00
|
|
|
var night_start = (time_set["SunsetStart"] + time_set["SunsetEnd"]) / 2;
|
|
|
|
var night_end = (time_set["SunriseStart"] + time_set["SunriseEnd"]) / 2;
|
|
|
|
if (Inside(time, night_start, night_end))
|
|
|
|
return true;
|
|
|
|
return false;
|
2010-07-06 10:29:08 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
private func PlaceStars()
|
2010-07-06 10:29:08 +00:00
|
|
|
{
|
2010-09-29 16:25:44 +00:00
|
|
|
//Star Creation
|
|
|
|
var maxamount = LandscapeWidth() * LandscapeHeight() / 40000;
|
|
|
|
var amount = 0;
|
2010-07-06 10:29:08 +00:00
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
while (amount != maxamount)
|
2010-07-06 10:29:08 +00:00
|
|
|
{
|
2010-09-29 16:25:44 +00:00
|
|
|
var pos;
|
|
|
|
if (pos = FindPosInMat("Sky", 0, 0, LandscapeWidth(), LandscapeHeight()))
|
|
|
|
CreateObject(Star, pos[0], pos[1]);
|
|
|
|
amount++;
|
2010-07-06 10:29:08 +00:00
|
|
|
}
|
2010-09-29 16:25:44 +00:00
|
|
|
return;
|
2010-02-26 06:18:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
// Cycles through day and night.
|
|
|
|
protected func FxIntTimeCycleTimer(object target)
|
2010-07-06 10:29:08 +00:00
|
|
|
{
|
2010-09-29 16:25:44 +00:00
|
|
|
// Adjust to time.
|
|
|
|
AdjustToTime();
|
|
|
|
|
|
|
|
// Advance time.
|
|
|
|
time++;
|
|
|
|
time %= (24 * 60);
|
|
|
|
|
2010-07-06 10:29:08 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-05-22 20:16:48 +00:00
|
|
|
// Adjusts the sky, celestial and others to the current time. Use SetTime() at runtime, not this.
|
2010-09-29 16:25:44 +00:00
|
|
|
private func AdjustToTime()
|
2010-02-26 06:18:06 +00:00
|
|
|
{
|
2012-05-22 20:16:48 +00:00
|
|
|
var skyshade = [0,0,0,0]; //R,G,B,A
|
|
|
|
var nightcolour = [10,25,40]; //default darkest-night colour
|
|
|
|
|
|
|
|
//Darkness of night dependant on moon-phase
|
|
|
|
var satellite = FindObject(Find_ID(Moon)); //pointer to the moon
|
|
|
|
if(satellite){
|
|
|
|
var phase = satellite->GetPhase();
|
|
|
|
|
|
|
|
if(phase == 1 || phase == 5) nightcolour = [4,7,9]; //super dark when moon is crescent
|
|
|
|
else if(phase == 2 || phase == 4) nightcolour = [5,15,25]; //somewhat dark when moon is half
|
|
|
|
else nightcolour = [10,25,40]; //deep-blue when moon is full
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-29 16:25:44 +00:00
|
|
|
// Sunrise
|
|
|
|
if (Inside(time, time_set["SunriseStart"], time_set["SunriseEnd"]))
|
2010-02-27 23:15:32 +00:00
|
|
|
{
|
2012-05-22 20:16:48 +00:00
|
|
|
skyshade[0] = Sin((GetTime() - time_set["SunriseStart"]) / 4, 255 - nightcolour[0]) + nightcolour[0];
|
|
|
|
skyshade[1] = Sin((GetTime() - time_set["SunriseStart"]) / 4, 255 - nightcolour[1]) + nightcolour[1];
|
|
|
|
skyshade[2] = Sin((GetTime() - time_set["SunriseStart"]) / 4, 255 - nightcolour[2]) + nightcolour[2];
|
|
|
|
|
|
|
|
skyshade[3] = Sin((GetTime() - time_set["SunriseStart"]) / 4, 255);
|
2010-09-29 16:25:44 +00:00
|
|
|
if (time == 540)
|
2012-05-22 20:16:48 +00:00
|
|
|
if (satellite)
|
|
|
|
satellite->Phase();
|
2010-07-06 10:29:08 +00:00
|
|
|
}
|
2010-09-29 16:25:44 +00:00
|
|
|
// Day
|
|
|
|
else if (Inside(time, time_set["SunriseEnd"], time_set["SunsetStart"]))
|
2012-05-22 20:16:48 +00:00
|
|
|
{
|
|
|
|
skyshade[0] = 255;
|
|
|
|
skyshade[1] = 255;
|
|
|
|
skyshade[2] = 255;
|
|
|
|
|
|
|
|
skyshade[3] = 255;
|
|
|
|
}
|
2010-09-29 16:25:44 +00:00
|
|
|
//Sunset
|
|
|
|
else if (Inside(time, time_set["SunsetStart"], time_set["SunsetEnd"]))
|
2012-05-22 20:16:48 +00:00
|
|
|
{
|
|
|
|
skyshade[0] = 255 - Sin((GetTime() - time_set["SunsetStart"]) / 4, 255 - nightcolour[0]);
|
|
|
|
skyshade[1] = 255 - Sin((GetTime() - time_set["SunsetStart"]) / 4, 255 - nightcolour[1]);
|
|
|
|
skyshade[2] = 255 - Sin((GetTime() - time_set["SunsetStart"]) / 4, 255 - nightcolour[2]);
|
|
|
|
|
|
|
|
skyshade[3] = 255 - Sin((GetTime() - time_set["SunsetStart"]) / 4, 255);
|
|
|
|
}
|
2010-09-29 16:25:44 +00:00
|
|
|
// Night
|
|
|
|
else if (time > time_set["SunsetEnd"] || time < time_set["SunriseStart"])
|
2012-05-22 20:16:48 +00:00
|
|
|
{
|
|
|
|
skyshade[0] = nightcolour[0];
|
|
|
|
skyshade[1] = nightcolour[1];
|
|
|
|
skyshade[2] = nightcolour[2];
|
|
|
|
|
|
|
|
skyshade[3] = 0;
|
|
|
|
}
|
2010-09-29 16:25:44 +00:00
|
|
|
|
|
|
|
// Shade sky.
|
2012-05-22 20:16:48 +00:00
|
|
|
SetSkyAdjust(RGB(skyshade[0], skyshade[1], skyshade[2]));
|
2010-09-29 16:25:44 +00:00
|
|
|
|
|
|
|
// Adjust celestial objects.
|
|
|
|
for (var celestial in FindObjects(Find_Func("IsCelestial")))
|
2012-05-22 20:16:48 +00:00
|
|
|
celestial->SetObjAlpha(255 - skyshade[3]);
|
2010-09-29 16:25:44 +00:00
|
|
|
|
2012-05-22 20:16:48 +00:00
|
|
|
// Adjust clouds
|
|
|
|
for(var cloud in FindObjects(Find_ID(Cloud))){
|
|
|
|
cloud->RequestAlpha(skyshade[3]);
|
|
|
|
}
|
2010-09-29 16:25:44 +00:00
|
|
|
|
|
|
|
return;
|
2010-02-26 06:18:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-09 21:29:11 +00:00
|
|
|
local Name = "Time";
|