diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/ZCLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/ZCLogicLoop.java index c23257122..f1e21faa8 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/ZCLogicLoop.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/ZCLogicLoop.java @@ -175,6 +175,8 @@ public class ZCLogicLoop { MovementAuthority.End end = checkSwitch(section, right); if (end != null) endList.add(end); + //前方列车 + MovementAuthority.End trainEnd = checkSectionOccupied(section); // 轨道尽头/问题道岔 Section temp = section.getNextRunningSectionOf(right); if (Objects.isNull(temp)) { // 到尽头 @@ -198,22 +200,31 @@ public class ZCLogicLoop { section = temp; } - // 前方列车 - VirtualRealityTrain frontTrain = this.queryFrontTrain(train, trainList); - if (Objects.nonNull(frontTrain)) { - Section baseSection; - if (Objects.equals(frontTrain.isRight(), train.isRight())) { - baseSection = frontTrain.calculateTailPosition().getSection(); - } else { - baseSection = frontTrain.getHeadPosition().getSection(); - } - endList.add(new MovementAuthority.End(frontTrain, - MovementAuthority.EndType.FRONT_TRAIN, - baseSection)); - } +// // 前方列车 +// VirtualRealityTrain frontTrain = this.queryFrontTrain(train, trainList); +// if (Objects.nonNull(frontTrain)) { +// Section baseSection; +// if (Objects.equals(frontTrain.isRight(), train.isRight())) { +// baseSection = frontTrain.calculateTailPosition().getSection(); +// } else { +// baseSection = frontTrain.getHeadPosition().getSection(); +// } +// endList.add(new MovementAuthority.End(frontTrain, +// MovementAuthority.EndType.FRONT_TRAIN, +// baseSection)); +// } return endList; } + private MovementAuthority.End checkSectionOccupied(Section section) { + for (Section logic : section.getLogicList()) { + if (logic.isCtOccupied()) { + return new MovementAuthority.End(section, MovementAuthority.EndType.FRONT_TRAIN, null); + } + } + return null; + } + private MovementAuthority.End checkSwitch(Section tailSection, Section headSection, boolean right) { Section section = tailSection; for (int i = 0; i < 10; i++) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java index f3509f7c1..f21bd2262 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java @@ -1251,18 +1251,9 @@ public class CalculateService { if (section.isPhysical()) { return sectionPosition; } else { - int offset = 0; Section parent = section.getParent(); if (parent != null) { - for (Section logicSection : parent.getLogicList()) { - if (!logicSection.equals(section)) { - offset += logicSection.getLen(); - } else { - offset += sectionPosition.getOffset(); - break; - } - } - return new SectionPosition(parent, offset); + return new SectionPosition(parent, section.getMinOffset() + sectionPosition.getOffset()); } else { return null; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java index 1ee79c6d2..ca44cbb41 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java @@ -109,26 +109,30 @@ public class MovementAuthority { return new SectionPosition(section, offset); } case FRONT_TRAIN: { - VirtualRealityTrain train = (VirtualRealityTrain) this.device; - boolean trainRight = train.isRight(); - SectionPosition headPosition = train.getHeadPosition(); - SectionPosition tailPosition = CalculateService - .calculateNextPositionByStartAndLen(headPosition, !right, train.getLen()); - float offset; - if (Objects.equals(trainRight, right)) { // 同向,取车尾 - offset = right - ? - tailPosition.getOffset() - 2 * SimulationConstants.TRAIN_SAFE_DISTANCE - : - tailPosition.getOffset() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE; - } else { // 方向相反,取车头 - offset = right - ? - headPosition.getOffset() - 2 * SimulationConstants.TRAIN_SAFE_DISTANCE - : - headPosition.getOffset() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE; - } - return new SectionPosition(this.baseSection, offset); + Section section = (Section) this.device; + return new SectionPosition(section.getParent(), right ? section.getMinOffset() : section.getMaxOffset()); + + +// VirtualRealityTrain train = (VirtualRealityTrain) this.device; +// boolean trainRight = train.isRight(); +// SectionPosition headPosition = train.getHeadPosition(); +// SectionPosition tailPosition = CalculateService +// .calculateNextPositionByStartAndLen(headPosition, !right, train.getLen()); +// float offset; +// if (Objects.equals(trainRight, right)) { // 同向,取车尾 +// offset = right +// ? +// tailPosition.getOffset() - 2 * SimulationConstants.TRAIN_SAFE_DISTANCE +// : +// tailPosition.getOffset() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE; +// } else { // 方向相反,取车头 +// offset = right +// ? +// headPosition.getOffset() - 2 * SimulationConstants.TRAIN_SAFE_DISTANCE +// : +// headPosition.getOffset() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE; +// } +// return new SectionPosition(this.baseSection, offset); } case END_TRACK: { Section section = (Section) this.device; @@ -138,7 +142,7 @@ public class MovementAuthority { case UNLOCKED_OVERLAP: case FAULT_SWITCH: { Section section = (Section) this.device; - float offset = right ? 0 : section.getLen(); + float offset = right ? section.getLen() : 0; SectionPosition stopPosition = new SectionPosition(section, offset); return CalculateService.calculateNextPositionByStartAndLen(stopPosition, !right, 100); }