/// <summary> /// Filters the routes where the current locomotive /// is not allowed to enter the block. /// </summary> /// <param name="routeList"></param> /// <param name="locDataEcos"></param> /// <param name="locData"></param> /// <param name="feedbacks"></param> /// <returns></returns> public static RouteList FilterBy( this RouteList routeList, Locomotive locDataEcos, Locomotives.Data locData, FeedbacksData feedbacks ) { var res = new RouteList(); foreach (var it in routeList) { var targetBlock = it.Blocks[1]; var targetBlockIdentifier = targetBlock.identifier; var targetEnterSide = targetBlock.side; var targetBlockData = feedbacks.GetByBlockId(targetBlockIdentifier, targetEnterSide); if (targetBlockData == null) { continue; } // // check if the target block denies entering by the current locomotive // var useIsDenied = false; foreach (var itLoc in targetBlockData.DeniedLocomotives) { useIsDenied = itLoc.Id.Equals(locDataEcos.Name, StringComparison.Ordinal); if (useIsDenied) { break; } } if (useIsDenied) { continue; } // // check if the locomotive type is not allowed to enter the target block // targetBlockData.Settings ??= GetDefaultSettings(); if (targetBlockData.Settings.Count == 0) { continue; } var enterIsAllowed = false; foreach (var itLocSetting in locData.Settings) { var name = itLocSetting.Key; var state = itLocSetting.Value; if (targetBlockData.Settings.ContainsKey(name)) { enterIsAllowed = state == targetBlockData.Settings[name]; if (enterIsAllowed) { break; } } } if (!enterIsAllowed) { continue; } res.Add(it); } return(res); }