anchor.diff:  // tyto podminky jsou prubezne zobrazovany dispecerovi v potvrzovaci sekvenci
   
   procedure TJC.BarriersNCToAccept(var bariery: TList<TJCBarrier>);
  -var
  -  blk, blk2: TBlk;
  -  glob: TBlkSettings;
  -  track, lastTrack: TBlkTrack;
  -  railway: TBlkRailway;
  -  crossingZav: TJCCrossingZav;
  -  trackID: Integer;
  -  turnoutZav: TJCTurnoutZav;
  -  refugeeZav: TJCRefugeeZav;
  -  refZav: TJCRefZav;
  -begin
  -  // kontrola navestidla
  -  Blocks.GetBlkByID(Self.m_data.signalId, blk);
  -  if (not(blk as TBlkSignal).enabled) then
  -    bariery.Add(JCBarrier(barBlockDisabled, blk, blk.id));
  -
  -  // kontrola useku
  +begin
  +  // signal
  +  var signal := Blocks.GetBlkByID(Self.m_data.signalId);
  +  if (not(signal as TBlkSignal).enabled) then
  +    bariery.Add(JCBarrier(barBlockDisabled, signal));
  +
  +  // tracks
     for var i := 0 to Self.m_data.tracks.Count - 1 do
     begin
  -    trackID := Self.m_data.tracks[i];
  -    Blocks.GetBlkByID(trackID, blk);
  -    glob := blk.GetGlobalSettings();
  -
  -    // disabled
  -    if ((blk as TBlkTrack).occupied = TTrackState.disabled) then
  -      bariery.Add(JCBarrier(barBlockDisabled, blk, blk.id))
  +    var trackID := Self.m_data.tracks[i];
  +    var track := TBlkTrack(Blocks.GetBlkByID(trackID));
  +    var glob := track.GetGlobalSettings();
  +
  +    if (track.occupied = TTrackState.disabled) then
  +      bariery.Add(JCBarrier(barBlockDisabled, track))
   
       else if ((i <> Self.m_data.tracks.Count - 1) or (Self.typ <> TJCType.shunt)) then
       begin
  -      if ((blk as TBlkTrack).occupied <> TTrackState.Free) then
  -        bariery.Add(JCBarrier(barTrackOccupied, blk, blk.id));
  -    end;
  -
  -    // souprava
  -    if (((blk as TBlkTrack).IsTrain()) and (Self.typ = TJCType.Train)) then
  -      bariery.Add(JCBarrier(barTrackTrain, blk, blk.id));
  -  end;
  -
  -  // kontrola vyhybek:
  -  for turnoutZav in Self.m_data.turnouts do
  -  begin
  -    Blocks.GetBlkByID(turnoutZav.Block, blk);
  -    glob := blk.GetGlobalSettings();
  -
  -    // kontrola polohy:
  -    if (TBlkTurnout(blk).position <> turnoutZav.position) then
  -      bariery.Add(JCBarrier(barTurnoutNoPos, blk, blk.id));
  -
  -    // kontrola nouzoveho zaveru:
  -    if (not TBlkTurnout(blk).emLock) then
  -      bariery.Add(JCBarrier(barTurnoutEmLock, blk, blk.id));
  -
  -    // kontrola spojky
  -    Blocks.GetBlkByID(TBlkTurnout(blk).GetSettings.coupling, blk2);
  -    if ((blk2 <> nil) and (TBlkTurnout(blk).position <> turnoutZav.position)) then
  -    begin
  -      if (not TBlkTurnout(blk2).emLock) then
  -        bariery.Add(JCBarrier(barTurnoutEmLock, blk2, blk2.id));
  -
  -      if (TBlkTurnout(blk2).occupied = TTrackState.occupied) then
  -        bariery.Add(JCBarrier(barTrackOccupied, blk2, blk2.id));
  -    end;
  -
  -    // kontrola neprofiloveho styku pro polohu +
  -    if ((turnoutZav.position = TTurnoutPosition.plus) and (TBlkTurnout(blk).npBlokPlus <> nil)) then
  -    begin
  -      if (TBlkTrack(TBlkTurnout(blk).npBlokPlus).occupied = TTrackState.disabled) then
  -        bariery.Add(JCBarrier(barBlockDisabled, TBlkTurnout(blk).npBlokPlus, TBlkTurnout(blk).npBlokPlus.id))
  -      else if (TBlkTrack(TBlkTurnout(blk).npBlokPlus).occupied <> TTrackState.Free) then
  -        bariery.Add(JCBarrier(barTrackOccupied, TBlkTurnout(blk).npBlokPlus, TBlkTurnout(blk).npBlokPlus.id));
  -    end;
  -
  -    // kontrola neprofiloveho styku pro polohu -
  -    if ((turnoutZav.position = TTurnoutPosition.minus) and (TBlkTurnout(blk).npBlokMinus <> nil)) then
  -    begin
  -      if (TBlkTrack(TBlkTurnout(blk).npBlokMinus).occupied = TTrackState.disabled) then
  -        bariery.Add(JCBarrier(barBlockDisabled, TBlkTurnout(blk).npBlokMinus, TBlkTurnout(blk).npBlokMinus.id))
  -      else if (TBlkTrack(TBlkTurnout(blk).npBlokMinus).occupied <> TTrackState.Free) then
  -        bariery.Add(JCBarrier(barTrackOccupied, TBlkTurnout(blk).npBlokMinus, TBlkTurnout(blk).npBlokMinus.id));
  -    end;
  -  end;
  -
  -  // kontrola prejezdu
  -  for crossingZav in Self.m_data.crossings do
  -  begin
  -    Blocks.GetBlkByID(crossingZav.crossingId, blk);
  -
  -    if ((blk as TBlkCrossing).state <> TBlkCrossingBasicState.none) then
  -    begin
  -      if ((blk as TBlkCrossing).pcEmOpen) then
  -      begin
  -        bariery.Add(JCBarrier(barCrosEmOpen, blk, crossingZav.crossingId));
  +      if (track.occupied <> TTrackState.Free) then
  +        bariery.Add(JCBarrier(barTrackOccupied, track));
  +    end;
  +
  +    if ((track.IsTrain()) and (Self.typ = TJCType.Train)) then
  +      bariery.Add(JCBarrier(barTrackTrain, track));
  +  end;
  +
  +  // turnouts
  +  for var turnoutZav in Self.m_data.turnouts do
  +  begin
  +    var turnout: TBlkTurnout := TBlkTurnout(Blocks.GetBlkByID(turnoutZav.Block));
  +    var glob := turnout.GetGlobalSettings();
  +
  +    if (turnout.position <> turnoutZav.position) then
  +      bariery.Add(JCBarrier(barTurnoutNoPos, turnout));
  +
  +    if (not turnout.emLock) then
  +      bariery.Add(JCBarrier(barTurnoutEmLock, turnout));
  +
  +    var coupling := TBlkTurnout(Blocks.GetBlkByID(turnout.GetSettings.coupling));
  +    if ((coupling <> nil) and (turnout.position <> turnoutZav.position)) then
  +    begin
  +      if (not coupling.emLock) then
  +        bariery.Add(JCBarrier(barTurnoutEmLock, coupling));
  +
  +      if (coupling.occupied = TTrackState.occupied) then
  +        bariery.Add(JCBarrier(barTrackOccupied, coupling));
  +    end;
  +
  +    if ((turnoutZav.position = TTurnoutPosition.plus) and (turnout.npBlokPlus <> nil)) then
  +    begin
  +      if (TBlkTrack(turnout.npBlokPlus).occupied = TTrackState.disabled) then
  +        bariery.Add(JCBarrier(barBlockDisabled, turnout.npBlokPlus))
  +      else if (TBlkTrack(turnout.npBlokPlus).occupied <> TTrackState.Free) then
  +        bariery.Add(JCBarrier(barTrackOccupied, turnout.npBlokPlus));
  +    end;
  +
  +    if ((turnoutZav.position = TTurnoutPosition.minus) and (turnout.npBlokMinus <> nil)) then
  +    begin
  +      if (TBlkTrack(turnout.npBlokMinus).occupied = TTrackState.disabled) then
  +        bariery.Add(JCBarrier(barBlockDisabled, turnout.npBlokMinus))
  +      else if (TBlkTrack(turnout.npBlokMinus).occupied <> TTrackState.Free) then
  +        bariery.Add(JCBarrier(barTrackOccupied, turnout.npBlokMinus));
  +    end;
  +  end;
  +
  +  // crossings
  +  for var crossingZav in Self.m_data.crossings do
  +  begin
  +    var crossing := TBlkCrossing(Blocks.GetBlkByID(crossingZav.crossingId));
  +
  +    if (crossing.state <> TBlkCrossingBasicState.none) then
  +    begin
  +      if (crossing.pcEmOpen) then
  +      begin
  +        bariery.Add(JCBarrier(barCrosEmOpen, crossing));
         end else begin
  -        if ((blk as TBlkCrossing).state <> TBlkCrossingBasicState.closed) then
  -          bariery.Add(JCBarrier(barCrosNotClosed, blk, crossingZav.crossingId));
  +        if (crossing.state <> TBlkCrossingBasicState.closed) then
  +          bariery.Add(JCBarrier(barCrosNotClosed, crossing));
         end;
       end
       else
  -      bariery.Add(JCBarrier(barCrosError, blk, crossingZav.crossingId));
  -  end;
  -
  -  // kontrola odvratu
  -  for refugeeZav in Self.m_data.refuges do
  -  begin
  -    Blocks.GetBlkByID(refugeeZav.Block, blk);
  -    glob := blk.GetGlobalSettings();
  -
  -    // kontrola polohy:
  -    if (TBlkTurnout(blk).position <> refugeeZav.position) then
  -      bariery.Add(JCBarrier(barTurnoutNoPos, blk, blk.id));
  -
  -    // kontrola nouzoveho zaveru:
  -    if (not TBlkTurnout(blk).emLock) then
  -      bariery.Add(JCBarrier(barTurnoutEmLock, blk, blk.id));
  -
  -    // kontrola spojky odvratu
  -    Blocks.GetBlkByID(TBlkTurnout(blk).GetSettings.coupling, blk2);
  -    if (blk2 <> nil) then
  -    begin
  -      // kontrola spravneho uzamceni odvratu
  -      if (TBlkTurnout(blk).position <> refugeeZav.position) then
  -        if (not TBlkTurnout(blk2).emLock) then
  -          bariery.Add(JCBarrier(barTurnoutEmLock, blk2, blk2.id));
  +      bariery.Add(JCBarrier(barCrosError, crossing));
  +  end;
  +
  +  // refugees
  +  for var refugeeZav in Self.m_data.refuges do
  +  begin
  +    var refugee := TBlkTurnout(Blocks.GetBlkByID(refugeeZav.Block));
  +
  +    if (refugee.position <> refugeeZav.position) then
  +      bariery.Add(JCBarrier(barTurnoutNoPos, refugee));
  +
  +    if (not refugee.emLock) then
  +      bariery.Add(JCBarrier(barTurnoutEmLock, refugee));
  +
  +    var coupling := TBlkTurnout(Blocks.GetBlkByID(refugee.GetSettings.coupling));
  +    if (coupling <> nil) then
  +    begin
  +      if (refugee.position <> refugeeZav.position) then
  +        if (not coupling.emLock) then
  +          bariery.Add(JCBarrier(barTurnoutEmLock, coupling));
       end;
     end;
   
  
positive.code:     // Tady staci postavit jen jednu vyhybku, protoze jeji uzamceni opet zavola
      // tuto udalost.
  
      refugeeId := Self.m_state.nextTurnout - Self.m_data.turnouts.Count;
  
      Blocks.GetBlkByID(Self.m_data.refuges[refugeeId].Block, blk);
      Inc(Self.m_state.nextTurnout);
  
      TBlkTurnout(blk).SetPosition(TTurnoutPosition(Self.m_data.refuges[refugeeId].position), true, false,
        Self.TurnoutMovedNC, Self.TurnoutErrNC); // may call callback directly!
    end else if (Self.m_state.nextTurnout = Self.m_data.turnouts.Count + Self.m_data.refuges.Count) then
      Self.m_state.nextTurnout := -1;
  
negative.code: 
      if ((track.typ <> btTrack) and (track.typ <> btRT)) then
      begin
        result.Add(JCBarrier(barBlockWrongType, track));
        Exit();
      end;
    end;
  