//the DataLinker calls this method to forward a new road command from SS3 //it returns true if the command is valid /// <summary> /// This method gets called by the DataLinker and receives a new RoadCommand from SS3. /// </summary> /// <param name="command"></param> /// <returns></returns> public static bool ReceiveRoadCommand(RoadInstruction command) { if (command != null) { StreetSegment road = roads.Find(x => x.ID == command.Id); //check, if there is a road with this id if (road != null) //road should be valid { ExecuteRoadCommand(command); return(true); } } return(false); }
//this method executes the road command, i.e. adapts states and speed limits //it returns true, if the execution has been successful private static bool ExecuteRoadCommand(RoadInstruction command) { bool state = roads.Find(x => x.ID == command.Id).IsUsable; //store current state of the road bool success = false; if (command.Usable) //state should be changed { success = AdaptRoadState(command.Id, command.Usable); if (!success) { return(success); } //return, if adapting road state was not successfull } if (command.Speedlimit > 0) { success = AdaptSpeedLimit(command.Id, command.Speedlimit); if (command.Usable && !success) { AdaptRoadState(command.Id, state); } //if state has been adapted successfully, but speed limit not --> undo changes } return(success); }
/// <summary> /// This method receives a RoadInstruction from SS3 and forwards it to SS1. /// </summary> /// <param name="e">The new RoadInstruction.</param> internal static void CallReceiveRoadCommand(RoadInstruction e) { ReceiveRoadCommand?.Invoke(null, e); }
public static void SendRoadInstruction(RoadInstruction e) { SS1.CallReceiveRoadCommand(e); }
private void DataLinker_SS1_ReceiveRoadCommand(object sender, RoadInstruction e) { ReceiveRoadCommand(e); }