Le voici :
import com.nolimitscoaster.*;
/**
* This script makes a launch look more realistic, seen on real-life launched coasters
* Scripted by 8baannerd
*/
public class Launch extends Script implements BlockSystemController
{
// Declare some constants...
// These constants represents our block states, those values are user defineable
private static final int STATE_BLOCK_FREE = 0;
private static final int STATE_BLOCK_APPROACHING = 1;
private static final int STATE_BLOCK_LEAVING = 2;
private static final int STATE_BLOCK_BEFORE_TRIGGER = 3;
private static final int STATE_BLOCK_BEHIND_TRIGGER = 4;
private static final int STATE_BLOCK_WAITING = 5;
private static final int STATE_BLOCK_WAIT_FOR_CLEAR = 6;
private static final int STATE_BLOCK_WAIT_FOR_ADVANCE = 7;
private static final int STATE_BLOCK_IN_STATION = 8;
private static final int STATE_BLOCK_APPROACHING_B = 9;
private static final int STATE_BLOCK_LEAVING_B = 10;
private static final int STATE_BLOCK_BEFORE_TRIGGER_B = 11;
// The name of the script for error messages
private static final String scriptName = "BlockScript";
// The coaster operation mode
private static final int AUTO_MODE = 0;
private static final int MANUAL_BLOCK_MODE = 1;
private static final int FULL_MANUAL_MODE = 2;
// Member variables...
private Coaster HYDRAULICTEST1;
private Block stationBlock;
private Block launchBrakeBlock;
private Block launchBlock;
private float launchTime;
private int mode;
/**
* This method overrides the default implementation of onInit() from the Script class.
* Gets called at Script startup.
*/
public bool onInit()
{
String name;
// Detect the coaster this script belongs to...
coaster = sim.getCoasterForEntityId(getParentEntityId());
if (coaster == null)
{
System.err.println(scriptName + ": Not attached to coaster");
return false;
}
// Assign the block system controller to the coaster
coaster.setBlockSystemController(this);
/////
// Get and initialize all blocks
name = "Station";
stationBlock = coaster.getBlock(name);
if (!checkAndSetInitialBlockState(stationBlock, name))
{
return false;
}
stationBlock.setAdvanceFwdVisible(true); // Set buttons used on the control panel
name = "LaunchBrake";
launchBrakeBlock = coaster.getBlock(name);
if (!checkAndSetInitialBlockState(launchBrakeBlock, name))
{
return false;
}
launchBrakeBlock.setAdvanceFwdVisible(true);
name = "Launch";
launchBlock = coaster.getBlock(name);
if (!checkAndSetInitialBlockState(launchBlock, name))
{
return false;
}
launchBlock.setAdvanceFwdVisible(true);
mode = AUTO_MODE;
return true;
}
/**
* This method overrides the default implementation of the Script class.
* Gets called when the Script is about to exit.
*/
public void onExit()
{
}
/**
* This method overrides the default implementation of OnNextFrame() from the Script class.
* Gets called for each frame.
*/
public void onNextFrame(float tick)
{
if (mode != FULL_MANUAL_MODE)
{
// process all blocks...
processStation(stationBlock, launchBrakeBlock);
processlaunchBrakeBlock();
processlaunchBlock();
if (mode == MANUAL_BLOCK_MODE)
{
// update the control panel user interface
updateControlPanel();
}
}
}
/**
* This method is part of the BlockSystemController interface
* Gets called when the Auto Block mode gets selected on the control panel.
*/
public void onAutoMode(Coaster c)
{
//System.out.println("onAutoMode");
if (mode == FULL_MANUAL_MODE)
{
// previous mode was full manual, we need to check the new position of the trains now
setInitialBlockState(stationBlock);
setInitialBlockState(launchBrakeBlock);
setInitialBlockState(launchBlock);
}
mode = AUTO_MODE;
updateControlPanel();
}
/**
* This method is part of the BlockSystemController interface
* Gets called when the Manual Block gets selected on the control panel.
*/
public void onManualBlockMode(Coaster c)
{
//System.out.println("onManualBlockMode");
if (mode == FULL_MANUAL_MODE)
{
// previous mode was full manual, we need to check the new position of the trains now
setInitialBlockState(stationBlock);
setInitialBlockState(launchBrakeBlock);
setInitialBlockState(launchBlock);
}
mode = MANUAL_BLOCK_MODE;
updateControlPanel();
}
/**
* This method is part of the BlockSystemController interface
* Gets called when the Full Manual mode gets selected on the control panel.
*/
public void onFullManualMode(Coaster c)
{
//System.out.println("onFullManualMode");
mode = FULL_MANUAL_MODE;
updateControlPanel();
}
/**
* This method is part of the BlockSystemController interface
* Gets called when the user clicks on the Advance Fwd Button on the control panel.
*/
public void onAdvanceFWDButton(Block block)
{
if (block == launchBrakeBlock)
{
launchBlock.setState(STATE_BLOCK_APPROACHING);
launchBrakeBlock.setState(STATE_BLOCK_LEAVING);
}
else if (block == stationBlock)
{
launchBrakeBlock.setState(STATE_BLOCK_APPROACHING);
stationBlock.setState(STATE_BLOCK_LEAVING);
}
else if (block == launchBlock)
{
launchBlock.setState(STATE_BLOCK_LEAVING);
}
}
/**
* This method is part of the BlockSystemController interface
* Gets called when the user clicks on the Advance Bwd Button on the control panel.
*/
public void onAdvanceBWDButton(Block block)
{
}
/**
* This method checks if a block was found and registers all possible states to the block and checks if a train is on the block.
*/
private static bool checkAndSetInitialBlockState(Block block, String name)
{
if (block == null)
{
System.err.println(scriptName + ": Block '" + name + "' not found");
return false;
}
registerBlockStates(block);
setInitialBlockState(block);
return true;
}
/**
* This method checks if a train is on the block or not and sets the corresponding state.
*/
private static void setInitialBlockState(Block block)
{
if (block.getNumberOfTrainsOnBlock() > 0)
{
if (block.getSection().iStation())
{
block.setState(STATE_BLOCK_IN_STATION);
}
else
{
block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
}
}
else
{
block.setState(STATE_BLOCK_FREE);
}
}
/**
* Adds labels for each possible state to a block.
* The labels are recommended for display on the control panel, there is no other purpose.
*/
private static void registerBlockStates(Block block)
{
// register the states, so that some usefull text will be shown on the block tab of the control panel
block.registerState(STATE_BLOCK_FREE, "Free", Block.LAMP_OFF);
block.registerState(STATE_BLOCK_APPROACHING, "Approaching", Block.LAMP_FLASHING);
block.registerState(STATE_BLOCK_APPROACHING_B, "Approaching", Block.LAMP_FLASHING);
block.registerState(STATE_BLOCK_LEAVING, "Leaving", Block.LAMP_ON);
block.registerState(STATE_BLOCK_LEAVING_B, "Leaving", Block.LAMP_ON);
block.registerState(STATE_BLOCK_BEFORE_TRIGGER, "Before Trigger", Block.LAMP_ON);
block.registerState(STATE_BLOCK_BEFORE_TRIGGER_B, "Before Trigger", Block.LAMP_ON);
block.registerState(STATE_BLOCK_BEHIND_TRIGGER, "Behind Trigger", Block.LAMP_ON);
block.registerState(STATE_BLOCK_WAITING, "Waiting", Block.LAMP_ON);
block.registerState(STATE_BLOCK_WAIT_FOR_CLEAR, "Waiting for Clear Block", Block.LAMP_ON);
block.registerState(STATE_BLOCK_WAIT_FOR_ADVANCE, "Waiting for Advance", Block.LAMP_ON);
block.registerState(STATE_BLOCK_IN_STATION, "In Station", Block.LAMP_ON);
}
/**
* Will update the user interface elements based on the current states
*/
private void updateControlPanel()
{
stationBlock.setAdvanceFwdEnabled(stationBlock.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
launchBrakeBlock.setAdvanceFwdEnabled(launchBrakeBlock.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
launchBlock.setAdvanceFwdEnabled(launchBlock.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
}
/**
* A universal method to process a station block.
*/
private void processStation(Block stationBlock, Block nextBlock)
{
switch (stationBlock.getState())
{
case STATE_BLOCK_IN_STATION:
if (stationBlock.getSection().isStationWaitingForClearBlock())
{
if (nextBlock.getState() == STATE_BLOCK_FREE)
{
stationBlock.getSection().setStationNextBlockClear();
}
}
else if (stationBlock.getSection().isStationWaitingForAdvance())
{
if (mode == MANUAL_BLOCK_MODE)
{
if (nextBlock.getState() == STATE_BLOCK_FREE)
{
stationBlock.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
}
else
{
stationBlock.getSection().setStationNextBlockOccupied();
}
}
else
{
if (nextBlock.getState() == STATE_BLOCK_FREE)
{
nextBlock.setState(STATE_BLOCK_APPROACHING);
stationBlock.setState(STATE_BLOCK_LEAVING);
stationBlock.getSection().setStationLeaving();
}
else
{
stationBlock.getSection().setStationNextBlockOccupied();
}
}
}
break;
case STATE_BLOCK_WAIT_FOR_ADVANCE:
if ((mode != MANUAL_BLOCK_MODE) || !stationBlock.getSection().isStationWaitingForAdvance() || (nextBlock.getState() != STATE_BLOCK_FREE))
{
stationBlock.setState(STATE_BLOCK_IN_STATION);
}
break;
case STATE_BLOCK_LEAVING:
if (stationBlock.getNumberOfTrainsOnBlock() != 0)
{
// Train is still on the block
stationBlock.getSection().setBrakesOff();
stationBlock.getSection().setTransportsStandardFwdOn();
}
else
{
// Train has left the block
stationBlock.setState(STATE_BLOCK_FREE);
}
break;
case STATE_BLOCK_FREE:
stationBlock.getSection().setTransportsOff();
stationBlock.getSection().setBrakesOn();
break;
case STATE_BLOCK_APPROACHING:
if (stationBlock.getSection().isTrainOnSection())
{
stationBlock.getSection().setStationEntering();
stationBlock.setState(STATE_BLOCK_IN_STATION);
}
else
{
stationBlock.getSection().setBrakesOff();
stationBlock.getSection().setTransportsOff();
}
break;
}
}
/**
* Process the block before the launch section.
*/
private void processlaunchBrakeBlock()
{
switch (launchBrakeBlock.getState())
{
case STATE_BLOCK_FREE:
launchBrakeBlock.getSection().setTransportsOff();
launchBrakeBlock.getSection().setBrakesOn();
break;
case STATE_BLOCK_APPROACHING:
if (launchBrakeBlock.getSection().isTrainOnSection())
{
launchBrakeBlock.setState(STATE_BLOCK_BEFORE_TRIGGER);
}
else
{
launchBrakeBlock.getSection().setBrakesOff();
launchBrakeBlock.getSection().setTransportsOff();
}
break;
case STATE_BLOCK_BEFORE_TRIGGER:
launchBrakeBlock.getSection().setBrakesTrim();
launchBrakeBlock.getSection().setTransportsStandardFwdDependingOnBrake();
if (launchBrakeBlock.getSection().isTrainBehindBrakeTrigger())
{
launchBrakeBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
}
break;
case STATE_BLOCK_BEHIND_TRIGGER:
if (mode == MANUAL_BLOCK_MODE)
{
launchBrakeBlock.getSection().setTransportsOff();
launchBrakeBlock.getSection().setBrakesOn();
}
else if (mode == AUTO_MODE)
{
launchBrakeBlock.getSection().setTransportsOff();
launchBrakeBlock.getSection().setBrakesOn();
Train train = launchBrakeBlock.getSection().getTrainOnSection();
if (train.getSpeed() == 0)
{
launchTime = 0;
launchBrakeBlock.setState(STATE_BLOCK_WAITING);
}
}
break;
case STATE_BLOCK_WAIT_FOR_ADVANCE:
if (mode == AUTO_MODE)
{
launchBrakeBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
}
else
{
launchBrakeBlock.getSection().setTransportsOff();
launchBrakeBlock.getSection().setBrakesOn();
}
break;
case STATE_BLOCK_WAITING:
launchBrakeBlock.getSection().setBrakesOff();
launchTime += sim.getCurSimulationTickSec();
if (launchTime >= launchBrakeBlock.getSection().getBrakeWaitTime())
{
launchBrakeBlock.getSection().setBrakesOff();
launchBrakeBlock.getSection().setTransportsStandardBwdOn();
if (launchTime >= launchBrakeBlock.getSection().getBrakeWaitTime() + 1)
{
launchBrakeBlock.getSection().setTransportsOff();
launchBrakeBlock.getSection().setBrakesOn();
if (launchTime >= launchBrakeBlock.getSection().getBrakeWaitTime() + 3)
{
launchBrakeBlock.getSection().setBrakesOff();
launchBrakeBlock.getSection().setTransportsLaunchFwdOn();
launchBrakeBlock.setState(STATE_BLOCK_LEAVING);
}
}
}
break;
case STATE_BLOCK_LEAVING:
launchBlock.setState(STATE_BLOCK_APPROACHING);
launchBrakeBlock.getSection().setBrakesOff();
launchBrakeBlock.getSection().setTransportsLaunchFwdOn();
if (launchBrakeBlock.getNumberOfTrainsOnBlock() == 0)
{
launchBrakeBlock.setState(STATE_BLOCK_FREE);
}
break;
case STATE_BLOCK_WAIT_FOR_CLEAR:
if (launchBrakeBlock.getSection().isTrainBehindBrakeTrigger())
{
launchBrakeBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
}
else
{
launchBrakeBlock.setState(STATE_BLOCK_BEFORE_TRIGGER);
}
break;
}
}
/**
* This method processes the launchBlock
*/
private void processlaunchBlock()
{
switch (launchBlock.getState())
{
case STATE_BLOCK_FREE:
launchBlock.getSection().setBrakesOn();
launchBlock.getSection().setTransportsOff();
break;
case STATE_BLOCK_APPROACHING:
launchBlock.getSection().setBrakesOff();
launchBlock.getSection().setTransportsStandardFwdOn();
if (launchBlock.getSection().isTrainOnSection())
{
launchBlock.setState(STATE_BLOCK_LEAVING);
}
break;
case STATE_BLOCK_LEAVING:
launchBlock.getSection().setBrakesOff();
launchBlock.getSection().setTransportsStandardFwdOn();
if (launchBlock.getNumberOfTrainsOnBlock() == 0)
{
launchBlock.setState(STATE_BLOCK_FREE);
}
break;
}
}
}
Voilà.