//! zinc
library ObDayCycle requires Object
{
public struct ObDayCycle extends Object
{
private static constant real transSteps = 24;
private static constant real timeDay = 5.90;
private static constant real timeNight = 17.90;
private boolean inTransition;
private real transCurrent;
private boolean isNight;
static method create() -> thistype
{
thistype this = thistype.allocate();
this.inTransition = false;
this.transCurrent = 0;
this.isNight = true;
return this;
}
method isDay() -> boolean
{
return !this.isNight;
}
private method translate()
{
real percent;
if (this.transCurrent < thistype.transSteps / 2)
percent = (1 - (this.transCurrent / thistype.transSteps)) * 100;
else
percent = (this.transCurrent / thistype.transSteps) * 100;
if (this.transCurrent == thistype.transSteps / 2)
{
if (this.isNight)
SetDayNightModels(gl_str_empty, gl_str_empty);
else
SetDayNightModels(gl_tex_dn_terrain, gl_tex_dn_units);
}
CinematicFilterGenericBJ
(
0.1, BLEND_MODE_BLEND, gl_tex_black_mask,
0, 0, 0, percent,
0, 0, 0, percent
);
this.transCurrent += 1;
if (this.transCurrent > thistype.transSteps)
{
this.transCurrent = 0;
this.inTransition = false;
}
}
method onAdd()
{
}
method update()
{
real time = GetFloatGameState(GAME_STATE_TIME_OF_DAY);
if (this.inTransition)
{
this.translate();
return;
}
if (time > thistype.timeDay && time < thistype.timeNight && this.isNight)
{
this.inTransition = true;
this.isNight = false;
}
else if (time > thistype.timeNight && !this.isNight)
{
this.inTransition = true;
this.isNight = true;
}
}
}
}
//! endzinc