working on route actions:

start block of route should only be freed, if corresponding action is fired.
  however, train should not be available from previous start block after route has finished.
This commit is contained in:
Stephan Richter
2020-11-03 23:28:23 +01:00
parent a2cb3d813e
commit 596317049c
14 changed files with 183 additions and 123 deletions

View File

@@ -45,6 +45,11 @@ public abstract class Action implements Constants {
public Context(Train train) {
this.train = train;
}
public Context(Route route) {
this.route = route;
train = route.train;
}
}
public Action() {
@@ -54,6 +59,7 @@ public abstract class Action implements Constants {
public static Action create(String type) {
try {
if (type.equals("FreeStartBlock")) type = FreePreviousBlocks.class.getSimpleName();
return (Action) Class.forName(PREFIX+"."+type).getDeclaredConstructor().newInstance();
} catch (Exception e) {
e.printStackTrace();
@@ -86,7 +92,7 @@ public abstract class Action implements Constants {
ConditionalAction.class,
SetSpeed.class,
SetSignalsToStop.class,
FreeStartBlock.class,
FreePreviousBlocks.class,
FinishRoute.class,
TurnTrain.class,
StopAuto.class,

View File

@@ -121,15 +121,16 @@ public class ActionList extends Vector<Action> implements Constants{
public boolean fire(Context context) {
LOG.debug("Firing {}",this);
boolean success = true;
for (Action action : this) {
try {
action.fire(context);
success &= action.fire(context);
} catch (IOException e) {
LOG.warn("Action did not fire properly: {}",action,e);
success = false;
}
}
return true;
return success;
}
public int id() {

View File

@@ -2,11 +2,14 @@ package de.srsoftware.web4rail.actions;
import java.io.IOException;
import de.srsoftware.web4rail.Route;
public class FinishRoute extends Action {
@Override
public boolean fire(Context context) throws IOException {
context.route.finish();
Route route = context.route;
if (route != null) route.finish();
return true;
}
}

View File

@@ -2,11 +2,11 @@ package de.srsoftware.web4rail.actions;
import java.io.IOException;
public class FreeStartBlock extends Action {
public class FreePreviousBlocks extends Action {
@Override
public boolean fire(Context context) throws IOException {
context.route.freeStartBlock();
return true;
if (context.train != null) context.train.resetPreviousBlocks();
return false;
}
}

View File

@@ -1,13 +1,11 @@
package de.srsoftware.web4rail.actions;
import java.io.IOException;
import de.srsoftware.web4rail.tiles.Signal;
public class SetSignalsToStop extends Action {
@Override
public boolean fire(Context context) throws IOException {
public boolean fire(Context context) {
context.route.setSignals(Signal.STOP);
return true;
}