Tree("Root") {
    Composite(Sequence) {
        BTC.InitializeSpeechManager()

        Composite(Race) {
            Composite(Sequence) {
                // Error in Speech Service: Cancel BTC Trees
                BTC.SpeechErrorOccured()
                BTC.SetBool("error")
            }

            Composite(Sequence) {
                BTC.SetVoiceName("de-DE-SeraphinaMultilingualNeural")
                RunTree("10_SBB_Zugabteil_Intro")
            }
        }

        Composite(Sequence) {
            BTC.CompareBool("error")
            // Error Handling
            BTC.AbortSpeechEventListener()
            BTC.StopSpeechIntentRecognition()
            BTC.ClearPossbileSpeechIntents()

            BTC.Show("GO.HANDMENU.SpeechButton")
            BTC.Set("TextMeshPro.HANDMENU.Option1Button", "text", "Restart")
            BTC.Show("GO.HANDMENU.Option1Button")
            BTC.Run("NamedEventTrigger.HANDMENU.Option1Button")
            BTC.Hide("GO.HANDMENU.Option1Button")
            BTC.Hide("GO.HANDMENU.SpeechButton")
            BTC.Show("GO.HANDMENU.Home")
            BTC.Hide("GO.HANDMENU.SpeechOptions")
        }                             
    }
}

Tree("10_SBB_Zugabteil_Intro") {
// --- Zugabteil - Intro ---
    Composite(Selector) {
        Composite(Sequence) {
            BTC.NoStoriesVisited()
            BTC.Show("Depthkit.VIDEOS.Exposition0Zugabte")
            BTC.Run("Depthkit.VIDEOS.Exposition0Zugabte")            

            BTC.SynthesizeText("Wir begrüssen dich auf unserer Reise in die Sprache und Kultur der italienischsprachigen Schweiz.")
            BTC.SpeechOutputEnded()

            BTC.SynthesizeText("Bitte bleib während des ganzen Ausflugs sitzen. Die Steuerung erfolgt über die Sprache und über das Smartphone, das du in der rechten Hand hältst.")
            BTC.SpeechOutputEnded()

            BTC.SynthesizeText("Solltest du dich unwohl fühlen, dann schliesse die Augen und lege die VR-Brille ab.")
            BTC.SpeechOutputEnded()

            BTC.SynthesizeText("Francesca begleitet dich bei deinen Abenteuern in die italienischsprachige Schweiz. Dabei bestimmst du, wohin deine Reise geht, indem du auf Italienisch antwortest, selbst Fragen stellst oder Entscheide triffst. Wenn Du nicht weiterweisst, dann schau auf dein Smartphone. Damit kannst Du an manchen Orten übrigens auch fotografieren.")
            BTC.SpeechOutputEnded()

            BTC.SetVoiceName("de-DE-KatjaNeural")
            BTC.Run("StudioEventEmitter.STATIC.SBBAlert")
            BTC.SynthesizeText("Nächster Halt Bellinzona, Richtung Biasca, Gleis 2, Locarno, Gleis 3, Mendrisio, Gleis 4. Gute Reise!")
            BTC.SpeechOutputEnded()

            BTC.SetVoiceName("de-DE-SeraphinaMultilingualNeural")
            BTC.SynthesizeText("In wenigen Minuten treffen wir in Bellinzona ein.")
            BTC.SpeechOutputEnded()

            BTC.SetSpeechRecognitionLanguage("it-IT")
            BTC.SetVoiceName("it-IT-FabiolaNeural")
            BTC.SynthesizeText("Tra pochi minuti arriveremo a Bellinzona. Il treno per Biasca è in partenza dal binario 2, quello per Locarno dal binario 3 e per Mendrisio dal binario 4. Buon viaggio!")
            BTC.SpeechOutputEnded()

            // --- Zugabteil - Exposition ---
            BTC.Hide("Depthkit.VIDEOS.Exposition0Zugabte")
            BTC.Show("Depthkit.VIDEOS.Exposition1Zugabte")
            BTC.Run("Depthkit.VIDEOS.Exposition1Zugabte")

            BTC.Hide("Depthkit.VIDEOS.Exposition1Zugabte")
            BTC.Show("Depthkit.VIDEOS.Exposition2Zugabte")
            BTC.Run("Depthkit.VIDEOS.Exposition2Zugabte")

            BTC.Hide("Depthkit.VIDEOS.Exposition2Zugabte")
            BTC.Show("Depthkit.VIDEOS.Exposition3Zugabte")
            BTC.Run("Depthkit.VIDEOS.Exposition3Zugabte")

            BTC.Hide("Depthkit.VIDEOS.Exposition3Zugabte")
            BTC.Show("Depthkit.VIDEOS.Exposition4Zugabte")
            BTC.Run("Depthkit.VIDEOS.Exposition4Zugabte")

            BTC.Hide("Depthkit.VIDEOS.Exposition4Zugabte")
            //BTC.Run("AudioSource.AUDIO.Exposition5Zugabte")

            RunTree("10_SBB_Zugabteil_Szenenwahl_Selection")
        }

        RunTree("10_SBB_Zugabteil_Szenenwahl_Selection")
    }
 
}

Tree("10_SBB_Zugabteil_Szenenwahl_Selection") {
// --- Zugabteil - Szenenwahl Selection ---
    Composite(Sequence) {
        BTC.SetBool("handmenu_active", false)

        Composite(Selector) {
            Composite(Sequence) {
                // Story A besucht
                BTC.StoryAVisited()

                Composite(Selector) {
                    Composite(Sequence) {
                        // Story A + B besucht
                        BTC.StoryBVisited()

                        Composite(Selector) {
                            Composite(Sequence) {
                                // Story A + B + C besucht
                                BTC.StoryCVisited()
                                // --- Zugabteil - Story Ende ---
                                BTC.Show("Depthkit.VIDEOS.StoryEnde1Zugabtei")
                                BTC.Run("Depthkit.VIDEOS.StoryEnde1Zugabtei")
                                BTC.Hide("Depthkit.VIDEOS.StoryEnde1Zugabtei")
                                // --- ENDE ---
                            }

                            Composite(Sequence) {
                                // Story A + B besucht
                                // Story C nicht besucht
                                // --- Zugabteil - Repetition Intro C ---
                                BTC.Show("Depthkit.VIDEOS.RepetitionIntroC1Z")
                                BTC.Run("Depthkit.VIDEOS.RepetitionIntroC1Z")
                                RunTree("10_SBB_Zugabteil_Szenenwahl")
                            }
                        }
                    }

                    Composite(Sequence) {
                        // Story A besucht
                        // Story B nicht besucht
                        BTC.StoryCVisited()

                        // Story A + C besucht
                        // Story B nicht besucht
                        // --- Zugabteil - Repetition Intro B ---
                        BTC.Show("Depthkit.VIDEOS.RepetitionIntroB1Z")
                        BTC.Run("Depthkit.VIDEOS.RepetitionIntroB1Z")
                        RunTree("10_SBB_Zugabteil_Szenenwahl")
                    }

                    Composite(Sequence) {
                        // Story A besucht
                        // Story B + C nicht besucht
                        // --- Zugabteil - Repetition Intro BC ---
                        BTC.Show("Depthkit.VIDEOS.RepetitionIntroBC1")
                        BTC.Run("Depthkit.VIDEOS.RepetitionIntroBC1")
                        RunTree("10_SBB_Zugabteil_Szenenwahl")
                    }         
                }
            }

            Composite(Sequence) {
                // Story A nicht besucht
                BTC.StoryBVisited()

                Composite(Selector) {
                    Composite(Sequence) {
                        // Story B besucht
                        // Story A nicht besucht
                        BTC.StoryCVisited()

                        // Story B + C besucht
                        // Story A nicht besucht
                        // --- Zugabteil - Repetition Intro A ---
                        BTC.Show("Depthkit.VIDEOS.RepetitionIntroA1Z")
                        BTC.Run("Depthkit.VIDEOS.RepetitionIntroA1Z")
                        RunTree("10_SBB_Zugabteil_Szenenwahl")
                    }

                    Composite(Sequence) {
                        // Story B besucht
                        // Story A + C nicht besucht
                        // --- Zugabteil - Repetition Intro AC ---
                        BTC.Show("Depthkit.VIDEOS.RepetitionIntroAC1")
                        BTC.Run("Depthkit.VIDEOS.RepetitionIntroAC1")
                        RunTree("10_SBB_Zugabteil_Szenenwahl")
                    }  
                }
            }

            Composite(Sequence) {
                // Story A + B nicht besucht
                BTC.StoryCVisited()

                // Story C besucht
                // Story A + B nicht besucht
                // --- Zugabteil - Repetition Intro AB ---
                BTC.Show("Depthkit.VIDEOS.RepetitionIntroAB1")
                BTC.Run("Depthkit.VIDEOS.RepetitionIntroAB1")
                RunTree("10_SBB_Zugabteil_Szenenwahl")
            }

            Composite(Sequence) {
                // Nichts besucht
                Composite(Selector) {
                    Composite(Sequence) {
                        BTC.CompareRepetitionVisitedCounter(0)
                        // --- Zugabteil - Intro ABC erste ---
                        BTC.Show("Depthkit.VIDEOS.IntroABCerste1Zuga")
                        BTC.Run("Depthkit.VIDEOS.IntroABCerste1Zuga")
                        RunTree("10_SBB_Zugabteil_Szenenwahl")
                    }
                    Composite(Sequence) {
                        // Erste Wiederholung
                        BTC.CompareRepetitionVisitedCounter(1)
                        // --- Zugabteil - Intro ABC zweite ---
                        BTC.Show("Depthkit.VIDEOS.IntroABCzweite1Zug")
                        BTC.Run("Depthkit.VIDEOS.IntroABCzweite1Zug")
                        RunTree("10_SBB_Zugabteil_Szenenwahl")
                    }
                    Composite(Sequence) {
                        // Zweite Wiederholung
                        BTC.CompareRepetitionVisitedCounter(2)
                        // --- Zugabteil - Intro ABC dritte ---
                        BTC.Show("Depthkit.VIDEOS.IntroABCdritte1Zug")
                        BTC.Run("Depthkit.VIDEOS.IntroABCdritte1Zug")
                        BTC.SetBool("handmenu_active")
                        RunTree("10_SBB_Zugabteil_Szenenwahl")
                    }
                }
            }
        } // First Selector
    } // Sequence
}

Tree("10_SBB_Zugabteil_Szenenwahl") {
// --- Zugabteil - Szenenwahl ---
    Composite(Sequence) {
        BTC.AddPossbileSpeechIntent("Zugabteil.Szenenwahl.3")
        BTC.AddPossbileSpeechIntent("Zugabteil.Szenenwahl.5")
        BTC.AddPossbileSpeechIntent("Zugabteil.Szenenwahl.7")
        BTC.StartSpeechIntentRecognition()

        Composite(Race) {
            // -- Race 1: User sagt etwas
            Composite(Sequence) {
                BTC.UserStartedSpeechInput()
                
                Composite(Selector) {
                    // -- Selector 1: Intent erkannt
                    Composite(Sequence) {
                        BTC.SpeechIntentRecognized()
                        BTC.AbortEventListener("NamedGrabEvent.INTERACTABLES.VRBrille")

                        // Intent erkannt
                        Composite(Race) {
                            Composite(Sequence) {
                                BTC.CompareIntentID("Zugabteil.Szenenwahl.3")
                                BTC.ClearPossbileSpeechIntents()
                                // Load Scene: Story A Picknicken
                                // ...
                                //BTC.SetStoryAVisited()
                                RunTree("10_SBB_Hide_Videos")
                            }
                            Composite(Sequence) {
                                BTC.CompareIntentID("Zugabteil.Szenenwahl.5")
                                BTC.ClearPossbileSpeechIntents()
                                // Load Scene: Story B Grotto
                                BTC.Run("LoadScene.NEXT.30SBB")
                            }
                            Composite(Sequence) {
                                BTC.CompareIntentID("Zugabteil.Szenenwahl.7")
                                BTC.ClearPossbileSpeechIntents()
                                // Load Scene: Story C Wandern
                                // ...
                                //BTC.SetStoryCVisited()
                                RunTree("10_SBB_Hide_Videos")
                            }
                        }
                    }

                    // -- Selector 2: Intent nicht erkannt
                    Composite(Sequence) {
                        BTC.AbortEventListener("NamedGrabEvent.INTERACTABLES.VRBrille")
                        // Fallback: nicht verstanden, wiederholen
                        // ...
                        BTC.SynthesizeText("Temo di non averla capita. Può ripetere, per favore? In alternativa, può usare l'aiuto sul cellulare che tiene nella mano sinistra.")
                        BTC.SpeechOutputEnded()

                        BTC.StartSpeechIntentRecognition()

                        Composite(Race) {
                            Composite(Sequence) {
                                // Option 1: Spracheingabe
                                BTC.UserStartedSpeechInput()
                                BTC.SpeechIntentRecognized()

                                Composite(Race) {
                                    Composite(Sequence) {
                                        BTC.CompareIntentID("Zugabteil.Szenenwahl.3")
                                        BTC.ClearPossbileSpeechIntents()
                                        // Load Scene: Story A Picknicken
                                        // ...
                                        //BTC.SetStoryAVisited()
                                        RunTree("10_SBB_Hide_Videos")
                                    }
                                    Composite(Sequence) {
                                        BTC.CompareIntentID("Zugabteil.Szenenwahl.5")
                                        BTC.ClearPossbileSpeechIntents()
                                        // Load Scene: Story B Grotto
                                        BTC.Run("LoadScene.NEXT.30SBB")
                                    }
                                    Composite(Sequence) {
                                        BTC.CompareIntentID("Zugabteil.Szenenwahl.7")
                                        BTC.ClearPossbileSpeechIntents()
                                        // Load Scene: Story C Wandern
                                        // ...
                                        //BTC.SetStoryCVisited()
                                        RunTree("10_SBB_Hide_Videos")
                                    }
                                }
                            }

                            Composite(Sequence) {
                                // Option 2: Handmenu
                                Composite(Marathon) {
                                    BTC.Show("GO.HANDMENU.SpeechButton")
                                    BTC.Set("TextMeshPro.HANDMENU.Option1Button", "text", "picnic")
                                    BTC.Show("GO.HANDMENU.Option1Button")
                                    BTC.Set("TextMeshPro.HANDMENU.Option2Button", "text", "grotto")
                                    BTC.Show("GO.HANDMENU.Option2Button")
                                    BTC.Set("TextMeshPro.HANDMENU.Option3Button", "text", "escursione")
                                    BTC.Show("GO.HANDMENU.Option3Button")
                                }

                                Composite(Race) {
                                    Composite(Sequence) {
                                        // picnic
                                        BTC.Run("NamedEventTrigger.HANDMENU.Option1Button")

                                        Composite(Marathon) {
                                            BTC.Hide("GO.HANDMENU.Option1Button")
                                            BTC.Hide("GO.HANDMENU.Option2Button")
                                            BTC.Hide("GO.HANDMENU.Option3Button")
                                            BTC.Hide("GO.HANDMENU.SpeechButton")
                                            BTC.Show("GO.HANDMENU.Home")
                                            BTC.Hide("GO.HANDMENU.SpeechOptions")
                                        }

                                        BTC.AbortSpeechEventListener()
                                        BTC.StopSpeechIntentRecognition()
                                        BTC.ClearPossbileSpeechIntents()

                                        // Load Scene: Story A Picknicken
                                        // ...
                                        //BTC.SetStoryAVisited()
                                        RunTree("10_SBB_Hide_Videos")
                                    }
                                    Composite(Sequence) {
                                        // grotto
                                        BTC.Run("NamedEventTrigger.HANDMENU.Option2Button")

                                        Composite(Marathon) {
                                            BTC.Hide("GO.HANDMENU.Option1Button")
                                            BTC.Hide("GO.HANDMENU.Option2Button")
                                            BTC.Hide("GO.HANDMENU.Option3Button")
                                            BTC.Hide("GO.HANDMENU.SpeechButton")
                                            BTC.Show("GO.HANDMENU.Home")
                                            BTC.Hide("GO.HANDMENU.SpeechOptions")
                                        }

                                        BTC.AbortSpeechEventListener()
                                        BTC.StopSpeechIntentRecognition()
                                        BTC.ClearPossbileSpeechIntents()

                                        // Load Scene: Story B Grotto
                                        BTC.Run("LoadScene.NEXT.30SBB")
                                    }
                                    Composite(Sequence) {
                                        // escursione
                                        BTC.Run("NamedEventTrigger.HANDMENU.Option3Button")

                                        Composite(Marathon) {
                                            BTC.Hide("GO.HANDMENU.Option1Button")
                                            BTC.Hide("GO.HANDMENU.Option2Button")
                                            BTC.Hide("GO.HANDMENU.Option3Button")
                                            BTC.Hide("GO.HANDMENU.SpeechButton")
                                            BTC.Show("GO.HANDMENU.Home")
                                            BTC.Hide("GO.HANDMENU.SpeechOptions")
                                        }

                                        BTC.AbortSpeechEventListener()
                                        BTC.StopSpeechIntentRecognition()
                                        BTC.ClearPossbileSpeechIntents()

                                        // Load Scene: Story C Wandern
                                        // ...
                                        //BTC.SetStoryCVisited()
                                        RunTree("10_SBB_Hide_Videos")
                                    }
                                } // Ende Race Buttons
                            } // Ende Option 2 Handmenu
                        } // Ende Race Optionen

                    } // Ende Sequence
                } // Ende Selector
            } // Ende Sequence 1

            // -- Race 2: User sagt nichts
            Composite(Sequence) {
                BTC.Wait(10)
                BTC.CompareUserSpeechInputStarted(false)
                Decorator(Inverter) {
                    BTC.CompareBool("handmenu_active")
                }
                BTC.AbortSpeechEventListener()
                BTC.StopSpeechIntentRecognition()
                BTC.ClearPossbileSpeechIntents()
                BTC.AbortEventListener("NamedGrabEvent.INTERACTABLES.VRBrille")
                BTC.IncrementRepetitionVisitedCounter()
                RunTree("10_SBB_Hide_Videos")
                RunTree("10_SBB_Zugabteil_Szenenwahl_Selection")
            }

            // -- Race 3: VR Brille in die Hand nehmen
            Composite(Sequence) {
                BTC.Run("NamedGrabEvent.INTERACTABLES.VRBrille")
                Decorator(Inverter) {
                    BTC.CompareBool("handmenu_active")
                }
                BTC.AbortSpeechEventListener()
                BTC.StopSpeechIntentRecognition()
                BTC.ClearPossbileSpeechIntents()
                BTC.IncrementRepetitionVisitedCounter()

                // --- Bilder Bergell ---
                //BTC.Run("LoadScene.NEXT.35Slideshow")
                RunTree("10_SBB_Hide_Videos")
                RunTree("10_SBB_Zugabteil_Szenenwahl_Selection")
            }

            // -- Race 4: Hand Menu
            Composite(Sequence) {
                BTC.CompareBool("handmenu_active")
                Composite(Marathon) {
                    BTC.Show("GO.HANDMENU.SpeechButton")
                    BTC.Set("TextMeshPro.HANDMENU.Option1Button", "text", "picnic")
                    BTC.Show("GO.HANDMENU.Option1Button")
                    BTC.Set("TextMeshPro.HANDMENU.Option2Button", "text", "grotto")
                    BTC.Show("GO.HANDMENU.Option2Button")
                    BTC.Set("TextMeshPro.HANDMENU.Option3Button", "text", "escursione")
                    BTC.Show("GO.HANDMENU.Option3Button")
                }

                Composite(Race) {
                    Composite(Sequence) {
                        // picnic
                        BTC.Run("NamedEventTrigger.HANDMENU.Option1Button")

                        Composite(Marathon) {
                            BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option2Button")
                            BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option3Button")
                            BTC.Hide("GO.HANDMENU.Option1Button")
                            BTC.Hide("GO.HANDMENU.Option2Button")
                            BTC.Hide("GO.HANDMENU.Option3Button")
                            BTC.Hide("GO.HANDMENU.SpeechButton")
                            BTC.Show("GO.HANDMENU.Home")
                            BTC.Hide("GO.HANDMENU.SpeechOptions")
                        }

                        BTC.AbortSpeechEventListener()
                        BTC.StopSpeechIntentRecognition()
                        BTC.ClearPossbileSpeechIntents()

                        // Load Scene: Story A Picknicken
                        // ...
                        //BTC.SetStoryAVisited()
                        RunTree("10_SBB_Hide_Videos")
                    }
                    Composite(Sequence) {
                        // grotto
                        BTC.Run("NamedEventTrigger.HANDMENU.Option2Button")

                        Composite(Marathon) {
                            BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option1Button")
                            BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option3Button")
                            BTC.Hide("GO.HANDMENU.Option1Button")
                            BTC.Hide("GO.HANDMENU.Option2Button")
                            BTC.Hide("GO.HANDMENU.Option3Button")
                            BTC.Hide("GO.HANDMENU.SpeechButton")
                            BTC.Show("GO.HANDMENU.Home")
                            BTC.Hide("GO.HANDMENU.SpeechOptions")
                        }

                        BTC.AbortSpeechEventListener()
                        BTC.StopSpeechIntentRecognition()
                        BTC.ClearPossbileSpeechIntents()

                        // Load Scene: Story B Grotto
                        BTC.Run("LoadScene.NEXT.30SBB")
                    }
                    Composite(Sequence) {
                        // escursione
                        BTC.Run("NamedEventTrigger.HANDMENU.Option3Button")

                        Composite(Marathon) {
                            BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option1Button")
                            BTC.AbortEventListener("NamedEventTrigger.HANDMENU.Option2Button")
                            BTC.Hide("GO.HANDMENU.Option1Button")
                            BTC.Hide("GO.HANDMENU.Option2Button")
                            BTC.Hide("GO.HANDMENU.Option3Button")
                            BTC.Hide("GO.HANDMENU.SpeechButton")
                            BTC.Show("GO.HANDMENU.Home")
                            BTC.Hide("GO.HANDMENU.SpeechOptions")
                        }

                        BTC.AbortSpeechEventListener()
                        BTC.StopSpeechIntentRecognition()
                        BTC.ClearPossbileSpeechIntents()

                        // Load Scene: Story C Wandern
                        // ...
                        //BTC.SetStoryCVisited()
                        RunTree("10_SBB_Hide_Videos")
                    }
                }
            }
        } // Ende Race
    }
}

Tree("10_SBB_Hide_Videos") {
    Composite(Marathon) {
        BTC.Hide("Depthkit.VIDEOS.RepetitionIntroC1Z")
        BTC.Hide("Depthkit.VIDEOS.RepetitionIntroB1Z")
        BTC.Hide("Depthkit.VIDEOS.RepetitionIntroBC1")
        BTC.Hide("Depthkit.VIDEOS.RepetitionIntroA1Z")
        BTC.Hide("Depthkit.VIDEOS.RepetitionIntroAC1")
        BTC.Hide("Depthkit.VIDEOS.RepetitionIntroAB1")
        BTC.Hide("Depthkit.VIDEOS.IntroABCerste1Zuga")
        BTC.Hide("Depthkit.VIDEOS.IntroABCzweite1Zug")
        BTC.Hide("Depthkit.VIDEOS.IntroABCdritte1Zug")
    }
}