/* rk_enter_orbs
*
* Initializes moon rotation on area enter
* uses day of the year & iMoonPeriod to set phase
*
* Sets moon state and sun state
* uses iMoonCycle to determine moonrise and set
* uses GetTimeHour() to determine sunrise and set
*
*/
void main()
{
string sMoonTag = "CelestialOrbMoon";
string sSunTag = "CelestialOrbSun";
object oMoon = GetObjectByTag( sMoonTag );
object oSun = GetObjectByTag( sSunTag );
object oPC = GetFirstPC();
int iYear = GetCalendarYear(); // 1340 to 32001
int iMonth = GetCalendarMonth(); // 1 to 12 inclusive
int iDay = GetCalendarDay(); // 1 to 28 inclusive
int iHour = GetTimeHour();
int iDaysSince = (iMonth-1)*28+iDay; // Days since start of year
int iHoursSince = (iDaysSince-1)*24 + iHour;
float fFacing;
// Set rotation to show phase
int iMoonPeriod = GetLocalInt( oMoon, "iMoonPeriod"); // Get moon period (in days) from the Moon orb
//Determine the modulo of (iDaysSince % iMoonPeriod) to determine percentage of current Period
int iPeriod = iDaysSince % iMoonPeriod ; // Number of days into the current Period
fFacing = 360.0 - (IntToFloat(iPeriod)/IntToFloat(iMoonPeriod) * 360.0); // Facing is percentage of iMoonPeriod * 360 degrees
AssignCommand( oMoon, SetFacing( fFacing ));
// Initialize Moon state
//Determine the modulo of (iHoursSince % iMoonCycle) to determine where we are in current cycle
int iMoonCycle = GetLocalInt( oMoon, "iMoonCycle"); // Gets the iMoonCycle (in hours) from the Moon orb
int iCycle = iHoursSince % iMoonCycle ; // Number of hours into the current cycle
// Cycle starts with moonrise, sets at iMoonCycle/2
if (iCycle < iMoonCycle/2){
// Moon is up
AssignCommand(oMoon, PlayAnimation( ANIMATION_PLACEABLE_ACTIVATE ));
}
else {
// Moon is down
AssignCommand(oMoon, PlayAnimation( ANIMATION_PLACEABLE_DEACTIVATE ));
}
// Set Sun state
if ((iHour >= 6) && (iHour<= 18)){
// Sun is up
AssignCommand(oSun, PlayAnimation( ANIMATION_PLACEABLE_ACTIVATE ));
}
else {
// Sun is down
AssignCommand(oSun, PlayAnimation( ANIMATION_PLACEABLE_DEACTIVATE ));
}
}