Advertisement
Guest User

Custom Script 11 PM 1/15

a guest
Jan 15th, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.63 KB | None | 0 0
  1. import com.nolimitscoaster.*;
  2.  
  3. /**
  4. * This script implements a Block System Controller for the Cursing Mommy Coaster.
  5. * It may look complicated, but it is not that complex actually.
  6. * The biggest complexity comes from implementing the proper way to handle manual block mode events and to control the switches.
  7. */
  8. public class BlockScript extends Script implements BlockSystemController
  9. {
  10. // Declare some constants...
  11. // These constants represents our block states, those values are user defineable
  12. private static final int STATE_BLOCK_FREE = 0;
  13. private static final int STATE_BLOCK_APPROACHING = 1;
  14. private static final int STATE_BLOCK_LEAVING = 2;
  15. private static final int STATE_BLOCK_BEFORE_TRIGGER = 3;
  16. private static final int STATE_BLOCK_BEHIND_TRIGGER = 4;
  17. private static final int STATE_BLOCK_WAITING = 5;
  18. private static final int STATE_BLOCK_WAIT_FOR_CLEAR = 6;
  19. private static final int STATE_BLOCK_WAIT_FOR_ADVANCE = 7;
  20. private static final int STATE_BLOCK_IN_STATION = 8;
  21. private static final int STATE_BLOCK_APPROACHING_B = 9;
  22. private static final int STATE_BLOCK_LEAVING_B = 10;
  23. private static final int STATE_BLOCK_BEFORE_TRIGGER_B = 11;
  24.  
  25. // The name of the script for error messages
  26. private static final String scriptName = "BlockScript";
  27.  
  28. // The coaster operation mode
  29. private static final int AUTO_MODE = 0;
  30. private static final int MANUAL_BLOCK_MODE = 1;
  31. private static final int FULL_MANUAL_MODE = 2;
  32.  
  33. // Member variables...
  34. private Coaster coaster;
  35. private Block liftBlock;
  36. private Block beforeLaunchBlock;
  37. private Block stationExitBlock;
  38. private Block stationEnterBlock;
  39. private Block reverse1Block;
  40. private Block reverse2Block;
  41. private Block beforeStationBlock;
  42. private Block storage1Block;
  43. private Block storage2Block;
  44. private Block storage3Block;
  45. private Block storage4Block;
  46. private Block storage5Block;
  47. private SpecialTrack reverse1Switch;
  48. private SpecialTrack reverse2Switch;
  49. private float reverse1BlockTime;
  50. private float reverse2BlockTime;
  51. private int mode;
  52.  
  53. /**
  54. * This method overrides the default implementation of onInit() from the Script class.
  55. * Gets called at Script startup.
  56. */
  57. public bool onInit()
  58. {
  59. String name;
  60.  
  61. // Detect the coaster this script belongs to...
  62. coaster = sim.getCoasterForEntityId(getParentEntityId());
  63. if (coaster == null)
  64. {
  65. System.err.println(scriptName + ": Not attached to coaster");
  66. return false;
  67. }
  68.  
  69. // Assign the block system controller to the coaster
  70. coaster.setBlockSystemController(this);
  71.  
  72. /////
  73.  
  74. // Get and initialize all blocks
  75.  
  76. name = "Lift";
  77. liftBlock = coaster.getBlock(name);
  78. if (!checkAndSetInitialBlockState(liftBlock, name))
  79. {
  80. return false;
  81. }
  82. liftBlock.setAdvanceFwdVisible(true); // Set buttons used on the control panel
  83.  
  84. name = "Before Launch";
  85. beforeLaunchBlock = coaster.getBlock(name);
  86. if (!checkAndSetInitialBlockState(beforeLaunchBlock, name))
  87. {
  88. return false;
  89. }
  90. beforeLaunchBlock.setAdvanceFwdVisible(true);
  91.  
  92. name = "Before Station";
  93. beforeStationBlock = coaster.getBlock(name);
  94. if (!checkAndSetInitialBlockState(beforeStationBlock, name))
  95. {
  96. return false;
  97. }
  98. beforeStationBlock.setAdvanceFwdVisible(true);
  99.  
  100. name = "Station Exit";
  101. stationExitBlock = coaster.getBlock(name);
  102. if (!checkAndSetInitialBlockState(stationExitBlock, name))
  103. {
  104. return false;
  105. }
  106. stationExitBlock.setAdvanceFwdVisible(true);
  107.  
  108. name = "Station Enter";
  109. stationEnterBlock = coaster.getBlock(name);
  110. if (!checkAndSetInitialBlockState(stationEnterBlock, name))
  111. {
  112. return false;
  113. }
  114. stationEnterBlock.setAdvanceFwdVisible(true);
  115.  
  116. name = "First Dir Change Brake";
  117. reverse1Block = coaster.getBlock(name);
  118. if (!checkAndSetInitialBlockState(reverse1Block, name))
  119. {
  120. return false;
  121. }
  122. reverse1Block.setAdvanceFwdVisible(true);
  123.  
  124. name = "Reverse 2 Brake";
  125. reverse2Block = coaster.getBlock(name);
  126. if (!checkAndSetInitialBlockState(reverse2Block, name))
  127. {
  128. return false;
  129. }
  130. reverse2Block.setAdvanceFwdVisible(true);
  131. reverse2Block.setAdvanceBwdVisible(true);
  132.  
  133. name = "Storage 1";
  134. storage1Block = coaster.getBlock(name);
  135. if (!checkAndSetInitialBlockState(storage1Block, name))
  136. {
  137. return false;
  138. }
  139. storage1Block.setAdvanceFwdVisible(true);
  140. storage1Block.setAdvanceBwdVisible(true);
  141.  
  142. name = "Storage 2";
  143. storage2Block = coaster.getBlock(name);
  144. if (!checkAndSetInitialBlockState(storage2Block, name))
  145. {
  146. return false;
  147. }
  148. storage2Block.setAdvanceFwdVisible(true);
  149.  
  150. name = "Storage 3";
  151. storage1Block = coaster.getBlock(name);
  152. if (!checkAndSetInitialBlockState(storage3Block, name))
  153. {
  154. return false;
  155. }
  156. storage3Block.setAdvanceFwdVisible(true);
  157. storage3Block.setAdvanceBwdVisible(true);
  158.  
  159. name = "Storage 4";
  160. storage1Block = coaster.getBlock(name);
  161. if (!checkAndSetInitialBlockState(storage4Block, name))
  162. {
  163. return false;
  164. }
  165. storage4Block.setAdvanceFwdVisible(true);
  166. storage4Block.setAdvanceBwdVisible(true);
  167.  
  168. name = "Storage 5";
  169. storage1Block = coaster.getBlock(name);
  170. if (!checkAndSetInitialBlockState(storage5Block, name))
  171. {
  172. return false;
  173. }
  174. storage1Block.setAdvanceFwdVisible(true);
  175.  
  176. /////
  177.  
  178. // Get and initialize switches
  179.  
  180. name = "Reverse 1 Switch";
  181. reverse1Switch = coaster.getSpecialTrack(name);
  182. if (reverse1Switch == null)
  183. {
  184. System.err.println(scriptName + ": SpecialTrack '" + name + "' not found");
  185. return false;
  186. }
  187.  
  188. name = "Reverse 2 Switch";
  189. reverse2Switch = coaster.getSpecialTrack(name);
  190. if (reverse2Switch == null)
  191. {
  192. System.err.println(scriptName + ": SpecialTrack '" + name + "' not found");
  193. return false;
  194. }
  195.  
  196. mode = AUTO_MODE;
  197.  
  198. return true;
  199. }
  200.  
  201. /**
  202. * This method overrides the default implementation of the Script class.
  203. * Gets called when the Script is about to exit.
  204. */
  205. public void onExit()
  206. {
  207. }
  208.  
  209. /**
  210. * This method overrides the default implementation of OnNextFrame() from the Script class.
  211. * Gets called for each frame.
  212. */
  213. public void onNextFrame(float tick)
  214. {
  215. if (mode != FULL_MANUAL_MODE)
  216. {
  217. // process all blocks...
  218.  
  219. processStation(stationExitBlock, stationEnterBlock);
  220. processStation(stationEnterBlock, liftBlock);
  221. processLiftBlock();
  222. processBeforeLaunchBlock();
  223. processReverse1Block();
  224. processReverse2Block();
  225. processBeforeStationBlock();
  226. processStorage1Block();
  227. processStorage2Block();
  228. processStorage3Block();
  229. processStorage4Block();
  230. processStorage5Block();
  231.  
  232. if (mode == MANUAL_BLOCK_MODE)
  233. {
  234. // update the control panel user interface
  235. updateControlPanel();
  236. }
  237. }
  238. }
  239.  
  240. /**
  241. * This method is part of the BlockSystemController interface
  242. * Gets called when the Auto Block mode gets selected on the control panel.
  243. */
  244. public void onAutoMode(Coaster c)
  245. {
  246. //System.out.println("onAutoMode");
  247. if (mode == FULL_MANUAL_MODE)
  248. {
  249. // previous mode was full manual, we need to check the new position of the trains now
  250. setInitialBlockState(liftBlock);
  251. setInitialBlockState(beforeLaunchBlock);
  252. setInitialBlockState(beforeStationBlock);
  253. setInitialBlockState(stationExitBlock);
  254. setInitialBlockState(stationEnterBlock);
  255. setInitialBlockState(reverse1Block);
  256. setInitialBlockState(reverse2Block);
  257. }
  258.  
  259. mode = AUTO_MODE;
  260. updateControlPanel();
  261. }
  262.  
  263. /**
  264. * This method is part of the BlockSystemController interface
  265. * Gets called when the Manual Block gets selected on the control panel.
  266. */
  267. public void onManualBlockMode(Coaster c)
  268. {
  269. //System.out.println("onManualBlockMode");
  270. if (mode == FULL_MANUAL_MODE)
  271. {
  272. // previous mode was full manual, we need to check the new position of the trains now
  273. setInitialBlockState(liftBlock);
  274. setInitialBlockState(beforeLaunchBlock);
  275. setInitialBlockState(beforeStationBlock);
  276. setInitialBlockState(stationExitBlock);
  277. setInitialBlockState(stationEnterBlock);
  278. setInitialBlockState(reverse1Block);
  279. setInitialBlockState(reverse2Block);
  280. setInitialBlockState(storage1Block);
  281. setInitialBlockState(storage2Block);
  282. setInitialBlockState(storage3Block);
  283. setInitialBlockState(storage4Block);
  284. setInitialBlockState(storage5Block);
  285. }
  286. mode = MANUAL_BLOCK_MODE;
  287. updateControlPanel();
  288. }
  289.  
  290. /**
  291. * This method is part of the BlockSystemController interface
  292. * Gets called when the Full Manual mode gets selected on the control panel.
  293. */
  294. public void onFullManualMode(Coaster c)
  295. {
  296. //System.out.println("onFullManualMode");
  297. mode = FULL_MANUAL_MODE;
  298. updateControlPanel();
  299. }
  300.  
  301. /**
  302. * This method is part of the BlockSystemController interface
  303. * Gets called when the user clicks on the Advance Fwd Button on the control panel.
  304. */
  305. public void onAdvanceFWDButton(Block block)
  306. {
  307. if (block == beforeLaunchBlock)
  308. {
  309. reverse1Block.setState(STATE_BLOCK_APPROACHING);
  310. beforeLaunchBlock.setState(STATE_BLOCK_LEAVING);
  311. }
  312. else if (block == liftBlock)
  313. {
  314. beforeLaunchBlock.setState(STATE_BLOCK_APPROACHING);
  315. liftBlock.setState(STATE_BLOCK_LEAVING);
  316. }
  317. else if (block == stationEnterBlock)
  318. {
  319. beforeLaunchBlock.setState(STATE_BLOCK_APPROACHING);
  320. stationEnterBlock.setState(STATE_BLOCK_LEAVING);
  321. stationEnterBlock.getSection().setStationLeaving();
  322. }
  323. else if (block == stationExitBlock)
  324. {
  325. stationEnterBlock.setState(STATE_BLOCK_APPROACHING);
  326. stationExitBlock.setState(STATE_BLOCK_LEAVING);
  327. stationExitBlock.getSection().setStationLeaving();
  328. }
  329. else if (block == beforeStationBlock)
  330. {
  331. stationExitBlock.setState(STATE_BLOCK_APPROACHING);
  332. beforeStationBlock.setState(STATE_BLOCK_LEAVING);
  333. }
  334. else if (block == reverse1Block)
  335. {
  336. reverse2Block.setState(STATE_BLOCK_APPROACHING);
  337. reverse1Block.setState(STATE_BLOCK_LEAVING);
  338. }
  339. else if (block == reverse2Block)
  340. {
  341. beforeStationBlock.setState(STATE_BLOCK_APPROACHING);
  342. reverse2Block.setState(STATE_BLOCK_LEAVING);
  343. }
  344. else if (block == storage1Block)
  345. {
  346. Train train = block.getSection().getTrainOnSection();
  347. if (train != null) train.setLashedToTrack(false);
  348. reverse2Block.setState(STATE_BLOCK_APPROACHING_B);
  349. storage1Block.setState(STATE_BLOCK_LEAVING);
  350. }
  351. else if (block == storage2Block)
  352. {
  353. Train train = block.getSection().getTrainOnSection();
  354. if (train != null) train.setLashedToTrack(false);
  355. storage1Block.setState(STATE_BLOCK_APPROACHING);
  356. storage2Block.setState(STATE_BLOCK_LEAVING);
  357. }
  358. else if (block == storage3Block)
  359. {
  360. Train train = block.getSection().getTrainOnSection();
  361. if (train != null) train.setLashedToTrack(false);
  362. storage2Block.setState(STATE_BLOCK_APPROACHING);
  363. storage3Block.setState(STATE_BLOCK_LEAVING);
  364. }
  365. else if (block == storage4Block)
  366. {
  367. Train train = block.getSection().getTrainOnSection();
  368. if (train != null) train.setLashedToTrack(false);
  369. storage3Block.setState(STATE_BLOCK_APPROACHING);
  370. storage4Block.setState(STATE_BLOCK_LEAVING);
  371. }
  372. else if (block == storage5Block)
  373. {
  374. Train train = block.getSection().getTrainOnSection();
  375. if (train != null) train.setLashedToTrack(false);
  376. storage4Block.setState(STATE_BLOCK_APPROACHING);
  377. storage5Block.setState(STATE_BLOCK_LEAVING);
  378. }
  379. }
  380.  
  381. /**
  382. * This method is part of the BlockSystemController interface
  383. * Gets called when the user clicks on the Advance Bwd Button on the control panel.
  384. */
  385. public void onAdvanceBWDButton(Block block)
  386. {
  387. if (block == reverse2Block)
  388. {
  389. storage1Block.setState(STATE_BLOCK_APPROACHING_B);
  390. reverse2Block.setState(STATE_BLOCK_LEAVING_B);
  391. }
  392. else if (block == storage1Block)
  393. {
  394. Train train = block.getSection().getTrainOnSection();
  395. if (train != null) train.setLashedToTrack(false);
  396. storage2Block.setState(STATE_BLOCK_APPROACHING_B);
  397. storage1Block.setState(STATE_BLOCK_LEAVING_B);
  398. }
  399. else if (block == storage2Block)
  400. {
  401. Train train = block.getSection().getTrainOnSection();
  402. if (train != null) train.setLashedToTrack(false);
  403. storage3Block.setState(STATE_BLOCK_APPROACHING_B);
  404. storage2Block.setState(STATE_BLOCK_LEAVING_B);
  405. }
  406. else if (block == storage3Block)
  407. {
  408. Train train = block.getSection().getTrainOnSection();
  409. if (train != null) train.setLashedToTrack(false);
  410. storage4Block.setState(STATE_BLOCK_APPROACHING_B);
  411. storage3Block.setState(STATE_BLOCK_LEAVING_B);
  412. }
  413. else if (block == storage4Block)
  414. {
  415. Train train = block.getSection().getTrainOnSection();
  416. if (train != null) train.setLashedToTrack(false);
  417. storage5Block.setState(STATE_BLOCK_APPROACHING_B);
  418. storage4Block.setState(STATE_BLOCK_LEAVING_B);
  419. }
  420. }
  421.  
  422. /**
  423. * 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.
  424. */
  425. private static bool checkAndSetInitialBlockState(Block block, String name)
  426. {
  427. if (block == null)
  428. {
  429. System.err.println(scriptName + ": Block '" + name + "' not found");
  430. return false;
  431. }
  432. registerBlockStates(block);
  433. setInitialBlockState(block);
  434. return true;
  435. }
  436.  
  437. /**
  438. * This method checks if a train is on the block or not and sets the corresponding state.
  439. */
  440. private static void setInitialBlockState(Block block)
  441. {
  442. if (block.getNumberOfTrainsOnBlock() > 0)
  443. {
  444. if (block.getSection().iStation())
  445. {
  446. block.setState(STATE_BLOCK_IN_STATION);
  447. }
  448. else
  449. {
  450. block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  451. }
  452. }
  453. else
  454. {
  455. block.setState(STATE_BLOCK_FREE);
  456. }
  457. }
  458.  
  459. /**
  460. * Adds labels for each possible state to a block.
  461. * The labels are recommended for display on the control panel, there is no other purpose.
  462. */
  463. private static void registerBlockStates(Block block)
  464. {
  465. // register the states, so that some usefull text will be shown on the block tab of the control panel
  466. block.registerState(STATE_BLOCK_FREE, "Free", Block.LAMP_OFF);
  467.  
  468. block.registerState(STATE_BLOCK_APPROACHING, "Approaching", Block.LAMP_FLASHING);
  469. block.registerState(STATE_BLOCK_APPROACHING_B, "Approaching", Block.LAMP_FLASHING);
  470.  
  471. block.registerState(STATE_BLOCK_LEAVING, "Leaving", Block.LAMP_ON);
  472. block.registerState(STATE_BLOCK_LEAVING_B, "Leaving", Block.LAMP_ON);
  473.  
  474. block.registerState(STATE_BLOCK_BEFORE_TRIGGER, "Before Trigger", Block.LAMP_ON);
  475. block.registerState(STATE_BLOCK_BEFORE_TRIGGER_B, "Before Trigger", Block.LAMP_ON);
  476.  
  477. block.registerState(STATE_BLOCK_BEHIND_TRIGGER, "Behind Trigger", Block.LAMP_ON);
  478.  
  479. block.registerState(STATE_BLOCK_WAITING, "Waiting", Block.LAMP_ON);
  480. block.registerState(STATE_BLOCK_WAIT_FOR_CLEAR, "Waiting for Clear Block", Block.LAMP_ON);
  481. block.registerState(STATE_BLOCK_WAIT_FOR_ADVANCE, "Waiting for Advance", Block.LAMP_ON);
  482.  
  483. block.registerState(STATE_BLOCK_IN_STATION, "In Station", Block.LAMP_ON);
  484. }
  485.  
  486. /**
  487. * Will update the user interface elements based on the current states
  488. */
  489. private void updateControlPanel()
  490. {
  491. liftBlock.setAdvanceFwdEnabled(liftBlock.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
  492. beforeLaunchBlock.setAdvanceFwdEnabled(beforeLaunchBlock.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
  493. stationEnterBlock.setAdvanceFwdEnabled(stationEnterBlock.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
  494. stationExitBlock.setAdvanceFwdEnabled(stationExitBlock.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
  495. beforeStationBlock.setAdvanceFwdEnabled(beforeStationBlock.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
  496. reverse1Block.setAdvanceFwdEnabled(reverse1Block.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
  497.  
  498. reverse2Block.setAdvanceFwdEnabled((reverse2Block.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE) && prepareReverse2BlockLeaving());
  499. reverse2Block.setAdvanceBwdEnabled((reverse2Block.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE) && canReverse2BlockLeaveBwd());
  500.  
  501. storage1Block.setAdvanceFwdEnabled((storage1Block.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE) && canEnterReverse2BlockFromStorage());
  502. storage1Block.setAdvanceBwdEnabled((storage1Block.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE) && (storage2Block.getState() == STATE_BLOCK_FREE));
  503.  
  504. storage2Block.setAdvanceFwdEnabled(storage2Block.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE);
  505.  
  506. reverse1Switch.setCanManualSwitchDirection((reverse1Block.getState() == STATE_BLOCK_FREE) || (reverse1Block.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE) || (reverse1Block.getState() == STATE_BLOCK_WAIT_FOR_CLEAR));
  507. reverse2Switch.setCanManualSwitchDirection((reverse2Block.getState() == STATE_BLOCK_FREE) || (reverse2Block.getState() == STATE_BLOCK_WAIT_FOR_ADVANCE) || (reverse2Block.getState() == STATE_BLOCK_WAIT_FOR_CLEAR));
  508. }
  509.  
  510. /**
  511. * A universal method to process a station block.
  512. * This method works for both stations.
  513. */
  514. private void processStation(Block stationBlock, Block nextBlock)
  515. {
  516. switch (stationBlock.getState())
  517. {
  518. case STATE_BLOCK_IN_STATION:
  519. if (stationBlock.getSection().isStationWaitingForClearBlock())
  520. {
  521. if (nextBlock.getState() == STATE_BLOCK_FREE)
  522. {
  523. stationBlock.getSection().setStationNextBlockClear();
  524. }
  525. }
  526. else if (stationBlock.getSection().isStationWaitingForAdvance())
  527. {
  528. if (mode == MANUAL_BLOCK_MODE)
  529. {
  530. if (nextBlock.getState() == STATE_BLOCK_FREE)
  531. {
  532. stationBlock.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  533. }
  534. else
  535. {
  536. stationBlock.getSection().setStationNextBlockOccupied();
  537. }
  538. }
  539. else
  540. {
  541. if (nextBlock.getState() == STATE_BLOCK_FREE)
  542. {
  543. nextBlock.setState(STATE_BLOCK_APPROACHING);
  544. stationBlock.setState(STATE_BLOCK_LEAVING);
  545. stationBlock.getSection().setStationLeaving();
  546. }
  547. else
  548. {
  549. stationBlock.getSection().setStationNextBlockOccupied();
  550. }
  551. }
  552. }
  553. break;
  554. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  555. if ((mode != MANUAL_BLOCK_MODE) || !stationBlock.getSection().isStationWaitingForAdvance() || (nextBlock.getState() != STATE_BLOCK_FREE))
  556. {
  557. stationBlock.setState(STATE_BLOCK_IN_STATION);
  558. }
  559. break;
  560. case STATE_BLOCK_LEAVING:
  561. if (stationBlock.getNumberOfTrainsOnBlock() != 0)
  562. {
  563. // Train is still on the block
  564. stationBlock.getSection().setBrakesOff();
  565. stationBlock.getSection().setTransportsStandardFwdOn();
  566. }
  567. else
  568. {
  569. // Train has left the block
  570. stationBlock.setState(STATE_BLOCK_FREE);
  571. }
  572. break;
  573. case STATE_BLOCK_FREE:
  574. stationBlock.getSection().setTransportsOff();
  575. stationBlock.getSection().setBrakesOn();
  576. break;
  577. case STATE_BLOCK_APPROACHING:
  578. if (stationBlock.getSection().isTrainOnSection())
  579. {
  580. stationBlock.getSection().setStationEntering();
  581. stationBlock.setState(STATE_BLOCK_IN_STATION);
  582. }
  583. else
  584. {
  585. stationBlock.getSection().setBrakesOff();
  586. stationBlock.getSection().setTransportsOff();
  587. }
  588. break;
  589. }
  590. }
  591.  
  592. /**
  593. * Process the lift block
  594. */
  595. private void processLiftBlock()
  596. {
  597. switch (liftBlock.getState())
  598. {
  599. case STATE_BLOCK_FREE:
  600. liftBlock.getSection().setLiftOff();
  601. break;
  602. case STATE_BLOCK_APPROACHING:
  603. if (liftBlock.getSection().isTrainOnSection())
  604. {
  605. liftBlock.setState(STATE_BLOCK_BEFORE_TRIGGER);
  606. }
  607. else
  608. {
  609. liftBlock.getSection().setLiftOff();
  610. }
  611. break;
  612. case STATE_BLOCK_BEFORE_TRIGGER:
  613. liftBlock.getSection().setLiftFwdOn();
  614. if (liftBlock.getSection().isTrainBehindLiftTrigger())
  615. {
  616. liftBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
  617. }
  618. break;
  619. case STATE_BLOCK_BEHIND_TRIGGER:
  620. if (mode == MANUAL_BLOCK_MODE)
  621. {
  622. liftBlock.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  623. }
  624. else
  625. {
  626. if ((beforeLaunchBlock.getState() == STATE_BLOCK_FREE) && (mode == AUTO_MODE))
  627. {
  628. beforeLaunchBlock.setState(STATE_BLOCK_APPROACHING);
  629. liftBlock.setState(STATE_BLOCK_LEAVING);
  630. }
  631. else
  632. {
  633. liftBlock.getSection().setLiftOff();
  634. }
  635. }
  636. break;
  637. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  638. if (mode == AUTO_MODE)
  639. {
  640. liftBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
  641. }
  642. else
  643. {
  644. liftBlock.getSection().setLiftOff();
  645. }
  646. break;
  647. case STATE_BLOCK_LEAVING:
  648. liftBlock.getSection().setLiftFwdOn();
  649. if (liftBlock.getNumberOfTrainsOnBlock() == 0)
  650. {
  651. liftBlock.setState(STATE_BLOCK_FREE);
  652. }
  653. break;
  654. case STATE_BLOCK_WAIT_FOR_CLEAR:
  655. if (liftBlock.getSection().isTrainBehindLiftTrigger())
  656. {
  657. liftBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
  658. }
  659. else
  660. {
  661. liftBlock.setState(STATE_BLOCK_BEFORE_TRIGGER);
  662. }
  663. break;
  664. }
  665. }
  666.  
  667.  
  668. /**
  669. * Process the block before the first launch section.
  670. */
  671. private void processBeforeLaunchBlock()
  672. {
  673. switch (beforeLaunchBlock.getState())
  674. {
  675. case STATE_BLOCK_FREE:
  676. beforeLaunchBlock.getSection().setTransportsOff();
  677. beforeLaunchBlock.getSection().setBrakesOn();
  678. break;
  679. case STATE_BLOCK_APPROACHING:
  680. if (beforeLaunchBlock.getSection().isTrainOnSection())
  681. {
  682. beforeLaunchBlock.setState(STATE_BLOCK_BEFORE_TRIGGER);
  683. }
  684. else
  685. {
  686. if (prepareReverse1BlockEntering())
  687. {
  688. beforeLaunchBlock.getSection().setBrakesOff();
  689. }
  690. else
  691. {
  692. beforeLaunchBlock.getSection().setBrakesOn();
  693. }
  694. beforeLaunchBlock.getSection().setTransportsOff();
  695. }
  696. break;
  697. case STATE_BLOCK_BEFORE_TRIGGER:
  698. prepareReverse1BlockEntering();
  699. beforeLaunchBlock.getSection().setBrakesTrim();
  700. beforeLaunchBlock.getSection().setTransportsStandardFwdDependingOnBrake();
  701. if (beforeLaunchBlock.getSection().isTrainBehindBrakeTrigger())
  702. {
  703. beforeLaunchBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
  704. }
  705. break;
  706. case STATE_BLOCK_BEHIND_TRIGGER:
  707. if (mode == MANUAL_BLOCK_MODE)
  708. {
  709. if (prepareReverse1BlockEntering())
  710. {
  711. beforeLaunchBlock.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  712. }
  713. else
  714. {
  715. beforeLaunchBlock.getSection().setTransportsOff();
  716. beforeLaunchBlock.getSection().setBrakesOn();
  717. }
  718. }
  719. else
  720. {
  721. if (prepareReverse1BlockEntering() && (mode == AUTO_MODE))
  722. {
  723. reverse1Block.setState(STATE_BLOCK_APPROACHING);
  724. beforeLaunchBlock.setState(STATE_BLOCK_LEAVING);
  725. }
  726. else
  727. {
  728. beforeLaunchBlock.getSection().setTransportsOff();
  729. beforeLaunchBlock.getSection().setBrakesOn();
  730. }
  731. }
  732. break;
  733. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  734. if (mode == AUTO_MODE)
  735. {
  736. beforeLaunchBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
  737. }
  738. else
  739. {
  740. if (!prepareReverse1BlockEntering())
  741. {
  742. beforeLaunchBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
  743. }
  744. else
  745. {
  746. beforeLaunchBlock.getSection().setTransportsOff();
  747. beforeLaunchBlock.getSection().setBrakesOn();
  748. }
  749. }
  750. break;
  751. case STATE_BLOCK_LEAVING:
  752. beforeLaunchBlock.getSection().setBrakesOff();
  753. beforeLaunchBlock.getSection().setTransportsLaunchFwdOn();
  754. if (beforeLaunchBlock.getNumberOfTrainsOnBlock() == 0)
  755. {
  756. beforeLaunchBlock.setState(STATE_BLOCK_FREE);
  757. }
  758. break;
  759. case STATE_BLOCK_WAIT_FOR_CLEAR:
  760. if (beforeLaunchBlock.getSection().isTrainBehindBrakeTrigger())
  761. {
  762. beforeLaunchBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
  763. }
  764. else
  765. {
  766. beforeLaunchBlock.setState(STATE_BLOCK_BEFORE_TRIGGER);
  767. }
  768. break;
  769. }
  770. }
  771.  
  772. /**
  773. * This method processes the Reverse1 block
  774. */
  775. private void processReverse1Block()
  776. {
  777. switch (reverse1Block.getState())
  778. {
  779. case STATE_BLOCK_APPROACHING:
  780. reverse1Block.getSection().setBrakesOff();
  781. reverse1Block.getSection().setTransportsOff();
  782. if (reverse1Block.getSection().isTrainOnSection())
  783. {
  784. reverse1Block.setState(STATE_BLOCK_BEFORE_TRIGGER);
  785. }
  786. break;
  787. case STATE_BLOCK_BEFORE_TRIGGER:
  788. reverse1Block.getSection().setBrakesTrim();
  789. reverse1Block.getSection().setTransportsStandardFwdDependingOnBrake();
  790. if (reverse1Block.getSection().isTrainBehindBrakeTrigger())
  791. {
  792. reverse1Block.setState(STATE_BLOCK_BEHIND_TRIGGER);
  793. }
  794. break;
  795. case STATE_BLOCK_BEHIND_TRIGGER:
  796. reverse1Block.getSection().setBrakesOn();
  797. reverse1Block.getSection().setTransportsOff();
  798. {
  799. Train train = reverse1Block.getSection().getTrainOnSection();
  800. if (train.getSpeed() == 0)
  801. {
  802. reverse1BlockTime = 0;
  803. reverse1Block.setState(STATE_BLOCK_WAITING);
  804. }
  805. }
  806. break;
  807. case STATE_BLOCK_WAITING:
  808. reverse1Block.getSection().setBrakesOn();
  809. reverse1Block.getSection().setTransportsOff();
  810. reverse1BlockTime += sim.getCurSimulationTickSec();
  811. prepareReverse1BlockLeaving();
  812. if (reverse1BlockTime >= reverse1Block.getSection().getBrakeWaitTime())
  813. {
  814. reverse1Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  815. }
  816. break;
  817. case STATE_BLOCK_WAIT_FOR_CLEAR:
  818. reverse1Block.getSection().setBrakesOn();
  819. reverse1Block.getSection().setTransportsOff();
  820. if (prepareReverse1BlockLeaving())
  821. {
  822. if (mode == MANUAL_BLOCK_MODE)
  823. {
  824. reverse1Block.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  825. }
  826. else
  827. {
  828. reverse2Block.setState(STATE_BLOCK_APPROACHING);
  829. reverse1Block.setState(STATE_BLOCK_LEAVING);
  830. }
  831. }
  832. break;
  833. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  834. reverse1Block.getSection().setBrakesOn();
  835. reverse1Block.getSection().setTransportsOff();
  836. if (!prepareReverse1BlockLeaving())
  837. {
  838. reverse1Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  839. }
  840. break;
  841. case STATE_BLOCK_LEAVING:
  842. if (reverse1Block.getSection().isTrainOnSection())
  843. {
  844. reverse1Block.getSection().setBrakesOff();
  845. reverse1Block.getSection().setTransportsLaunchBwdOn();
  846. }
  847. else
  848. {
  849. reverse1Block.getSection().setBrakesOn();
  850. reverse1Block.getSection().setTransportsOff();
  851. }
  852. if (reverse1Block.getNumberOfTrainsOnBlock() == 0)
  853. {
  854. reverse1Block.setState(STATE_BLOCK_FREE);
  855. }
  856. break;
  857. case STATE_BLOCK_FREE:
  858. reverse1Block.getSection().setBrakesOn();
  859. reverse1Block.getSection().setTransportsOff();
  860. break;
  861. }
  862. }
  863.  
  864. /**
  865. * This method processes the Reverse2 block
  866. */
  867. private void processReverse2Block()
  868. {
  869. switch (reverse2Block.getState())
  870. {
  871. case STATE_BLOCK_FREE:
  872. reverse2Block.getSection().setBrakesOn();
  873. reverse2Block.getSection().setTransportsOff();
  874. break;
  875. case STATE_BLOCK_APPROACHING:
  876. reverse2Block.getSection().setBrakesOff();
  877. reverse2Block.getSection().setTransportsOff();
  878. if (reverse2Block.getSection().isTrainOnSection())
  879. {
  880. reverse2Block.setState(STATE_BLOCK_BEFORE_TRIGGER);
  881. }
  882. break;
  883. case STATE_BLOCK_APPROACHING_B:
  884. reverse2Block.getSection().setBrakesOff();
  885. reverse2Block.getSection().setTransportsOff();
  886. if (reverse2Block.getSection().isTrainOnSection())
  887. {
  888. reverse2Block.setState(STATE_BLOCK_BEFORE_TRIGGER_B);
  889. }
  890. break;
  891. case STATE_BLOCK_BEFORE_TRIGGER:
  892. reverse2Block.getSection().setBrakesTrim();
  893. reverse2Block.getSection().setTransportsStandardBwdDependingOnBrake();
  894. if (reverse2Block.getSection().isTrainBeforeBrakeTrigger())
  895. {
  896. reverse2Block.setState(STATE_BLOCK_BEHIND_TRIGGER);
  897. }
  898. break;
  899. case STATE_BLOCK_BEFORE_TRIGGER_B:
  900. reverse2Block.getSection().setBrakesTrim();
  901. reverse2Block.getSection().setTransportsStandardFwdDependingOnBrake();
  902. if (reverse2Block.getSection().isTrainBehindBrakeTrigger())
  903. {
  904. reverse2Block.setState(STATE_BLOCK_BEHIND_TRIGGER);
  905. }
  906. break;
  907. case STATE_BLOCK_BEHIND_TRIGGER:
  908. reverse2Block.getSection().setBrakesOn();
  909. reverse2Block.getSection().setTransportsOff();
  910. {
  911. Train train = reverse2Block.getSection().getTrainOnSection();
  912. if (train.getSpeed() == 0)
  913. {
  914. reverse2Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  915. reverse2BlockTime = 0;
  916. }
  917. }
  918. break;
  919. case STATE_BLOCK_WAIT_FOR_CLEAR:
  920. // wait at least one second before we switch the track
  921. if (reverse2BlockTime >= 1.0)
  922. {
  923. if (mode == MANUAL_BLOCK_MODE)
  924. {
  925. if (prepareReverse2BlockLeaving() || canReverse2BlockLeaveBwd())
  926. {
  927. reverse2Block.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  928. }
  929. }
  930. else
  931. {
  932. if (prepareReverse2BlockLeaving())
  933. {
  934. beforeStationBlock.setState(STATE_BLOCK_APPROACHING);
  935. reverse2Block.setState(STATE_BLOCK_LEAVING);
  936. }
  937. }
  938. }
  939. else
  940. {
  941. reverse2BlockTime += sim.getCurSimulationTickSec();
  942. }
  943. reverse2Block.getSection().setBrakesOn();
  944. reverse2Block.getSection().setTransportsOff();
  945. break;
  946. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  947. if ((mode != MANUAL_BLOCK_MODE) || (!prepareReverse2BlockLeaving() && !canReverse2BlockLeaveBwd()))
  948. {
  949. reverse2Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  950. }
  951. break;
  952. case STATE_BLOCK_LEAVING:
  953. reverse2Block.getSection().setBrakesOff();
  954. reverse2Block.getSection().setTransportsStandardFwdOn();
  955. if (reverse2Block.getNumberOfTrainsOnBlock() == 0)
  956. {
  957. reverse2Block.setState(STATE_BLOCK_FREE);
  958. }
  959. break;
  960. case STATE_BLOCK_LEAVING_B:
  961. reverse2Block.getSection().setBrakesOff();
  962. reverse2Block.getSection().setTransportsStandardBwdOn();
  963. if (reverse2Block.getNumberOfTrainsOnBlock() == 0)
  964. {
  965. reverse2Block.setState(STATE_BLOCK_FREE);
  966. }
  967. break;
  968. }
  969. }
  970.  
  971. /**
  972. * This method processes the block before the stations
  973. */
  974. private void processBeforeStationBlock()
  975. {
  976. switch (beforeStationBlock.getState())
  977. {
  978. case STATE_BLOCK_FREE:
  979. beforeStationBlock.getSection().setBrakesOn();
  980. beforeStationBlock.getSection().setTransportsOff();
  981. break;
  982. case STATE_BLOCK_APPROACHING:
  983. beforeStationBlock.getSection().setBrakesOff();
  984. beforeStationBlock.getSection().setTransportsOff();
  985. if (beforeStationBlock.getSection().isTrainOnSection())
  986. {
  987. beforeStationBlock.setState(STATE_BLOCK_BEFORE_TRIGGER);
  988. }
  989. break;
  990. case STATE_BLOCK_BEFORE_TRIGGER:
  991. beforeStationBlock.getSection().setBrakesTrim();
  992. beforeStationBlock.getSection().setTransportsStandardFwdDependingOnBrake();
  993. if (beforeStationBlock.getSection().isTrainBehindBrakeTrigger())
  994. {
  995. beforeStationBlock.setState(STATE_BLOCK_BEHIND_TRIGGER);
  996. }
  997. break;
  998. case STATE_BLOCK_BEHIND_TRIGGER:
  999. if (stationExitBlock.getState() == STATE_BLOCK_FREE)
  1000. {
  1001. if (mode == MANUAL_BLOCK_MODE)
  1002. {
  1003. beforeStationBlock.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  1004. }
  1005. else
  1006. {
  1007. stationExitBlock.setState(STATE_BLOCK_APPROACHING);
  1008. beforeStationBlock.setState(STATE_BLOCK_LEAVING);
  1009. }
  1010. }
  1011. else
  1012. {
  1013. beforeStationBlock.getSection().setBrakesOn();
  1014. beforeStationBlock.getSection().setTransportsOff();
  1015. {
  1016. Train train = beforeStationBlock.getSection().getTrainOnSection();
  1017. if (train.getSpeed() == 0)
  1018. {
  1019. beforeStationBlock.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1020. }
  1021. }
  1022. }
  1023. break;
  1024. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  1025. if ((mode != MANUAL_BLOCK_MODE) || (stationExitBlock.getState() != STATE_BLOCK_FREE))
  1026. {
  1027. beforeStationBlock.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1028. }
  1029. beforeStationBlock.getSection().setBrakesOn();
  1030. beforeStationBlock.getSection().setTransportsOff();
  1031. break;
  1032. case STATE_BLOCK_WAIT_FOR_CLEAR:
  1033. if (stationExitBlock.getState() == STATE_BLOCK_FREE)
  1034. {
  1035. if (mode == MANUAL_BLOCK_MODE)
  1036. {
  1037. beforeStationBlock.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  1038. }
  1039. else
  1040. {
  1041. stationExitBlock.setState(STATE_BLOCK_APPROACHING);
  1042. beforeStationBlock.setState(STATE_BLOCK_LEAVING);
  1043. }
  1044. }
  1045. else
  1046. {
  1047. beforeStationBlock.getSection().setBrakesOn();
  1048. beforeStationBlock.getSection().setTransportsOff();
  1049. }
  1050. break;
  1051. case STATE_BLOCK_LEAVING:
  1052. beforeStationBlock.getSection().setBrakesOff();
  1053. beforeStationBlock.getSection().setTransportsStandardFwdOn();
  1054. if (beforeStationBlock.getNumberOfTrainsOnBlock() == 0)
  1055. {
  1056. beforeStationBlock.setState(STATE_BLOCK_FREE);
  1057. }
  1058. break;
  1059. }
  1060. }
  1061.  
  1062. /**
  1063. * This method processes the Storage1 block
  1064. */
  1065. private void processStorage1Block()
  1066. {
  1067. switch (storage1Block.getState())
  1068. {
  1069. case STATE_BLOCK_FREE:
  1070. storage1Block.getSection().setTransportsOff();
  1071. break;
  1072. case STATE_BLOCK_APPROACHING:
  1073. storage1Block.getSection().setTransportsOff();
  1074. if (storage1Block.getSection().isTrainOnSection())
  1075. {
  1076. storage1Block.setState(STATE_BLOCK_BEFORE_TRIGGER);
  1077. }
  1078. break;
  1079. case STATE_BLOCK_APPROACHING_B:
  1080. storage1Block.getSection().setTransportsOff();
  1081. if (storage1Block.getSection().isTrainOnSection())
  1082. {
  1083. storage1Block.setState(STATE_BLOCK_BEFORE_TRIGGER_B);
  1084. }
  1085. break;
  1086. case STATE_BLOCK_BEFORE_TRIGGER:
  1087. storage1Block.getSection().setTransportsStandardFwdOn();
  1088. if (storage1Block.getSection().isTrainBehindCenterOfSection())
  1089. {
  1090. storage1Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1091. }
  1092. break;
  1093. case STATE_BLOCK_BEFORE_TRIGGER_B:
  1094. storage1Block.getSection().setTransportsStandardBwdOn();
  1095. if (storage1Block.getSection().isTrainBeforeCenterOfSection())
  1096. {
  1097. storage1Block.getSection().getTrainOnSection().setLashedToTrack(true);
  1098. storage1Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1099. }
  1100. break;
  1101. case STATE_BLOCK_WAIT_FOR_CLEAR:
  1102. storage1Block.getSection().setTransportsOff();
  1103. if (mode == MANUAL_BLOCK_MODE)
  1104. {
  1105. if ((storage2Block.getState() == STATE_BLOCK_FREE) || canEnterReverse2BlockFromStorage())
  1106. {
  1107. storage1Block.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  1108. }
  1109. }
  1110. break;
  1111. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  1112. storage1Block.getSection().setTransportsOff();
  1113. if ((mode != MANUAL_BLOCK_MODE) || ((storage2Block.getState() != STATE_BLOCK_FREE) && !canEnterReverse2BlockFromStorage()))
  1114. {
  1115. storage1Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1116. }
  1117. break;
  1118. case STATE_BLOCK_LEAVING:
  1119. storage1Block.getSection().setTransportsStandardFwdOn();
  1120. if (!storage1Block.getSection().isTrainOnSection())
  1121. {
  1122. storage1Block.setState(STATE_BLOCK_FREE);
  1123. }
  1124. break;
  1125. case STATE_BLOCK_LEAVING_B:
  1126. storage1Block.getSection().setTransportsStandardBwdOn();
  1127. if (!storage1Block.getSection().isTrainOnSection())
  1128. {
  1129. storage1Block.setState(STATE_BLOCK_FREE);
  1130. }
  1131. break;
  1132. }
  1133. }
  1134.  
  1135. /**
  1136. * This method processes the Storage2 block
  1137. */
  1138. private void processStorage2Block()
  1139. {
  1140. switch (storage2Block.getState())
  1141. {
  1142. case STATE_BLOCK_FREE:
  1143. storage2Block.getSection().setTransportsOff();
  1144. break;
  1145. case STATE_BLOCK_APPROACHING_B:
  1146. storage2Block.getSection().setTransportsOff();
  1147. if (storage2Block.getSection().isTrainOnSection())
  1148. {
  1149. storage2Block.setState(STATE_BLOCK_BEFORE_TRIGGER_B);
  1150. }
  1151. break;
  1152. case STATE_BLOCK_BEFORE_TRIGGER_B:
  1153. storage2Block.getSection().setTransportsStandardBwdOn();
  1154. if (storage2Block.getSection().isTrainBeforeCenterOfSection())
  1155. {
  1156. storage2Block.getSection().getTrainOnSection().setLashedToTrack(true);
  1157. storage2Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1158. }
  1159. break;
  1160. case STATE_BLOCK_WAIT_FOR_CLEAR:
  1161. storage2Block.getSection().setTransportsOff();
  1162. if (mode == MANUAL_BLOCK_MODE)
  1163. {
  1164. if (storage1Block.getState() == STATE_BLOCK_FREE)
  1165. {
  1166. storage2Block.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  1167. }
  1168. }
  1169. break;
  1170. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  1171. storage2Block.getSection().setTransportsOff();
  1172. if ((mode != MANUAL_BLOCK_MODE) || (storage1Block.getState() != STATE_BLOCK_FREE))
  1173. {
  1174. storage2Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1175. }
  1176. break;
  1177. case STATE_BLOCK_LEAVING:
  1178. storage2Block.getSection().setTransportsStandardFwdOn();
  1179. if (!storage2Block.getSection().isTrainOnSection())
  1180. {
  1181. storage2Block.setState(STATE_BLOCK_FREE);
  1182. }
  1183. break;
  1184. }
  1185. }
  1186. private void processStorage3Block()
  1187. {
  1188. switch (storage3Block.getState())
  1189. {
  1190. case STATE_BLOCK_FREE:
  1191. storage3Block.getSection().setTransportsOff();
  1192. break;
  1193. case STATE_BLOCK_APPROACHING_B:
  1194. storage3Block.getSection().setTransportsOff();
  1195. if (storage3Block.getSection().isTrainOnSection())
  1196. {
  1197. storage3Block.setState(STATE_BLOCK_BEFORE_TRIGGER_B);
  1198. }
  1199. break;
  1200. case STATE_BLOCK_BEFORE_TRIGGER_B:
  1201. storage3Block.getSection().setTransportsStandardBwdOn();
  1202. if (storage3Block.getSection().isTrainBeforeCenterOfSection())
  1203. {
  1204. storage3Block.getSection().getTrainOnSection().setLashedToTrack(true);
  1205. storage3Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1206. }
  1207. break;
  1208. case STATE_BLOCK_WAIT_FOR_CLEAR:
  1209. storage3Block.getSection().setTransportsOff();
  1210. if (mode == MANUAL_BLOCK_MODE)
  1211. {
  1212. if (storage2Block.getState() == STATE_BLOCK_FREE)
  1213. {
  1214. storage3Block.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  1215. }
  1216. }
  1217. break;
  1218. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  1219. storage2Block.getSection().setTransportsOff();
  1220. if ((mode != MANUAL_BLOCK_MODE) || (storage2Block.getState() != STATE_BLOCK_FREE))
  1221. {
  1222. storage3Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1223. }
  1224. break;
  1225. case STATE_BLOCK_LEAVING:
  1226. storage3Block.getSection().setTransportsStandardFwdOn();
  1227. if (!storage3Block.getSection().isTrainOnSection())
  1228. {
  1229. storage3Block.setState(STATE_BLOCK_FREE);
  1230. }
  1231. break;
  1232. }
  1233. }
  1234. private void processStorage4Block()
  1235. {
  1236. switch (storage4Block.getState())
  1237. {
  1238. case STATE_BLOCK_FREE:
  1239. storage4Block.getSection().setTransportsOff();
  1240. break;
  1241. case STATE_BLOCK_APPROACHING_B:
  1242. storage4Block.getSection().setTransportsOff();
  1243. if (storage4Block.getSection().isTrainOnSection())
  1244. {
  1245. storage4Block.setState(STATE_BLOCK_BEFORE_TRIGGER_B);
  1246. }
  1247. break;
  1248. case STATE_BLOCK_BEFORE_TRIGGER_B:
  1249. storage4Block.getSection().setTransportsStandardBwdOn();
  1250. if (storage4Block.getSection().isTrainBeforeCenterOfSection())
  1251. {
  1252. storage4Block.getSection().getTrainOnSection().setLashedToTrack(true);
  1253. storage4Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1254. }
  1255. break;
  1256. case STATE_BLOCK_WAIT_FOR_CLEAR:
  1257. storage4Block.getSection().setTransportsOff();
  1258. if (mode == MANUAL_BLOCK_MODE)
  1259. {
  1260. if (storage3Block.getState() == STATE_BLOCK_FREE)
  1261. {
  1262. storage4Block.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  1263. }
  1264. }
  1265. break;
  1266. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  1267. storage3Block.getSection().setTransportsOff();
  1268. if ((mode != MANUAL_BLOCK_MODE) || (storage3Block.getState() != STATE_BLOCK_FREE))
  1269. {
  1270. storage4Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1271. }
  1272. break;
  1273. case STATE_BLOCK_LEAVING:
  1274. storage4Block.getSection().setTransportsStandardFwdOn();
  1275. if (!storage4Block.getSection().isTrainOnSection())
  1276. {
  1277. storage4Block.setState(STATE_BLOCK_FREE);
  1278. }
  1279. break;
  1280. }
  1281. }
  1282. private void processStorage5Block()
  1283. {
  1284. switch (storage5Block.getState())
  1285. {
  1286. case STATE_BLOCK_FREE:
  1287. storage5Block.getSection().setTransportsOff();
  1288. break;
  1289. case STATE_BLOCK_APPROACHING_B:
  1290. storage5Block.getSection().setTransportsOff();
  1291. if (storage5Block.getSection().isTrainOnSection())
  1292. {
  1293. storage5Block.setState(STATE_BLOCK_BEFORE_TRIGGER_B);
  1294. }
  1295. break;
  1296. case STATE_BLOCK_BEFORE_TRIGGER_B:
  1297. storage5Block.getSection().setTransportsStandardBwdOn();
  1298. if (storage5Block.getSection().isTrainBeforeCenterOfSection())
  1299. {
  1300. storage5Block.getSection().getTrainOnSection().setLashedToTrack(true);
  1301. storage5Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1302. }
  1303. break;
  1304. case STATE_BLOCK_WAIT_FOR_CLEAR:
  1305. storage5Block.getSection().setTransportsOff();
  1306. if (mode == MANUAL_BLOCK_MODE)
  1307. {
  1308. if (storage4Block.getState() == STATE_BLOCK_FREE)
  1309. {
  1310. storage5Block.setState(STATE_BLOCK_WAIT_FOR_ADVANCE);
  1311. }
  1312. }
  1313. break;
  1314. case STATE_BLOCK_WAIT_FOR_ADVANCE:
  1315. storage4Block.getSection().setTransportsOff();
  1316. if ((mode != MANUAL_BLOCK_MODE) || (storage4Block.getState() != STATE_BLOCK_FREE))
  1317. {
  1318. storage5Block.setState(STATE_BLOCK_WAIT_FOR_CLEAR);
  1319. }
  1320. break;
  1321. case STATE_BLOCK_LEAVING:
  1322. storage5Block.getSection().setTransportsStandardFwdOn();
  1323. if (!storage5Block.getSection().isTrainOnSection())
  1324. {
  1325. storage5Block.setState(STATE_BLOCK_FREE);
  1326. }
  1327. break;
  1328. }
  1329. }
  1330.  
  1331. /**
  1332. * This method checks if the Reverse1 block can be entered and tries to set the corresponding track switch in auto-mode.
  1333. */
  1334. private bool prepareReverse1BlockEntering()
  1335. {
  1336. if (reverse1Block.getState() == STATE_BLOCK_FREE)
  1337. {
  1338. if (reverse1Switch.getSwitchDirection() == 0)
  1339. {
  1340. return true;
  1341. }
  1342. else
  1343. {
  1344. if (mode == AUTO_MODE)
  1345. {
  1346. reverse1Switch.setSwitchDirection(0);
  1347. }
  1348. }
  1349. }
  1350. return false;
  1351. }
  1352.  
  1353. /**
  1354. * This method checks if a train on the Reverse1 block can leave the block and enter the next block.
  1355. * It tries to set the corresponding track switches in auto-mode.
  1356. */
  1357. private bool prepareReverse1BlockLeaving()
  1358. {
  1359. bool b1 = false;
  1360. bool b2 = false;
  1361. if (reverse1Switch.getSwitchDirection() == 1)
  1362. {
  1363. b1 = true;
  1364. }
  1365. else
  1366. {
  1367. if (mode == AUTO_MODE)
  1368. {
  1369. reverse1Switch.setSwitchDirection(1);
  1370. }
  1371. }
  1372. if (reverse2Block.getState() == STATE_BLOCK_FREE)
  1373. {
  1374. if (reverse2Switch.getSwitchDirection() == 0)
  1375. {
  1376. b2 = true;
  1377. }
  1378. else
  1379. {
  1380. if (mode == AUTO_MODE)
  1381. {
  1382. reverse2Switch.setSwitchDirection(0);
  1383. }
  1384. }
  1385. }
  1386. return b1 && b2;
  1387. }
  1388.  
  1389. /**
  1390. * This method checks if a train on the Reverse2 block can leave the block and enter the next block.
  1391. * It tries to set the corresponding track switch in auto-mode.
  1392. */
  1393. private bool prepareReverse2BlockLeaving()
  1394. {
  1395. if (reverse2Switch.getSwitchDirection() == 1)
  1396. {
  1397. if (beforeStationBlock.getState() == STATE_BLOCK_FREE)
  1398. {
  1399. return true;
  1400. }
  1401. }
  1402. else
  1403. {
  1404. if (mode == AUTO_MODE)
  1405. {
  1406. reverse2Switch.setSwitchDirection(1);
  1407. }
  1408. }
  1409. return false;
  1410. }
  1411.  
  1412. /**
  1413. * This method checks if a train on the Reverse2 block can leave to the storage tracks.
  1414. */
  1415. private bool canReverse2BlockLeaveBwd()
  1416. {
  1417. return (reverse2Switch.getSwitchDirection() == 2) && (storage1Block.getState() == STATE_BLOCK_FREE);
  1418. }
  1419.  
  1420. /**
  1421. * This method checks if a train on the storage track can enter the Reverse2 block
  1422. */
  1423. private bool canEnterReverse2BlockFromStorage()
  1424. {
  1425. return (reverse2Switch.getSwitchDirection() == 2) && (reverse2Block.getState() == STATE_BLOCK_FREE);
  1426. }
  1427.  
  1428. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement