import com.nolimitscoaster.*;
/**
* This script simulates a simple light, that switches on when the sun sets
*/
public class AutomateLight extends Script implements TrackTriggerListener
{
private static final String c_aLightSourceName = "thelight";
private static final String sCoastername = "Mystic Manor";
private static final double timeLight = 18000;
private static double startTime;
private static bool isLigthing;
private SceneObjectLight light;
private SceneObject sceneObject;
private Coaster coaster;
public bool onInit()
{
sceneObject = sim.getSceneObjectForEntityId(getParentEntityId());
light = sceneObject.getLightForName(c_aLightSourceName);
coaster = sim.getCoaster(sCoastername);
TrackTrigger trackTriggerStart = coaster.getTrackTrigger("Salle1");
if (light == null)
{
System.err.println("Scene object has no light with name '" + c_aLightSourceName + "'");
return false;
}
light.setEnabled(false);
isLigthing = false;
TrackTriggerListener trackTriggerListener = this;
trackTriggerStart.addTrackTriggerListener(trackTriggerListener);
return true;
}
public void onNextFrame(float tick)
{
if (isLigthing) {
double currentTime = System.currentTimeMillis();
double elapsedTime = currentTime - startTime;
if (elapsedTime > timeLight) {
light.setEnabled(false);
isLigthing = false;
}
}
}
public void onTrainEntering(TrackTrigger trigger, Train train) {
light.setEnabled(true);
isLigthing = true;
startTime = System.currentTimeMillis();
}
public void onTrainLeaving(TrackTrigger trigger, Train train) {
}
}