openclonk/planet/Objects.ocd/Environment.ocd/Time.ocd/Moon.ocd/Script.c

83 lines
1.4 KiB
C
Raw Normal View History

2015-04-06 16:49:58 +00:00
/**
Moon
Moon which are shown in the night sky.
*/
local phase;
2015-04-06 16:49:58 +00:00
protected func Initialize()
{
2015-04-06 16:49:58 +00:00
var alpha = 0;
var time = FindObject(Find_ID(Environment_Time));
if (time && time->IsNight())
alpha = 255;
SetClrModulation(RGBa(255, 255, 255, alpha));
2012-10-13 23:38:09 +00:00
SetAction("Be");
Update();
2015-04-06 16:49:58 +00:00
this.Parallaxity = [30, 30];
return;
}
2012-10-13 23:38:09 +00:00
public func NextMoonPhase()
{
2015-04-06 16:49:58 +00:00
SetMoonPhase(phase + 1);
}
2015-04-06 16:49:58 +00:00
// Return values from 0 to 100, depending on the full-ness of the moon
2012-10-13 23:38:09 +00:00
public func GetMoonLightness()
{
2012-10-13 23:38:09 +00:00
return 100 - Abs(100 * phase / this.ActMap.Be.Length - 50);
}
2012-10-13 23:38:09 +00:00
public func GetMoonPhase()
{
return phase;
}
2015-04-06 16:49:58 +00:00
public func SetMoonPhase(int to_phase)
{
2015-04-06 16:49:58 +00:00
phase = to_phase % this.ActMap.Be.Length;
2012-10-13 23:38:09 +00:00
Update();
2015-04-06 16:49:58 +00:00
return;
2012-10-13 23:38:09 +00:00
}
2015-04-06 16:49:58 +00:00
private func Update()
{
2012-10-13 23:38:09 +00:00
SetPhase(phase);
var phases = this.ActMap.Be.Length;
2015-04-06 16:49:58 +00:00
var x = phase - phases / 2;
var height = LandscapeHeight() / (6 - (x * x) / phases);
var width = 100 + phase * (LandscapeWidth() - 200) / phases;
2012-10-13 23:38:09 +00:00
2015-04-06 16:49:58 +00:00
SetPosition(width, height);
return;
}
2015-04-06 16:49:58 +00:00
// Only appears during the night.
public func IsCelestial() { return true; }
// Not stored by itself because it's created by the time environment
2015-04-06 16:49:58 +00:00
public func SaveScenarioObject() { return false; }
2012-10-13 23:38:09 +00:00
2015-04-06 16:49:58 +00:00
/*-- Properties --*/
2012-10-13 23:38:09 +00:00
2015-04-06 16:49:58 +00:00
local ActMap = {
Be = {
Prototype = Action,
Name = "Be",
Procedure = DFA_FLOAT,
Length = 8,
Delay = 0,
X = 0,
Y = 0,
Wdt = 128,
Hgt = 128,
NextAction = "Hold"
}
2012-10-13 23:38:09 +00:00
};