<?xml version="1.0"?>
    <!-- ESTRANGULADOR DE COMBUSTIBLE para motor de pistones YASim -->
    <!-- Manuel ACE 2025/06 -->


<PropertyList>
    <path>engineoff.ac</path> 
    
    <!-- Animación del tirador -->
    <animation>
        <name>Tirador_Animacion</name>
        <object-name>tirador</object-name> 
        <type>translate</type>
        <property>/instrumentation/engine-off-button/button-state</property> 
        <interpolation>
            <entry><ind>0</ind><dep>0.0</dep></entry> 
            <entry><ind>1</ind><dep>-0.01</dep></entry> 
        </interpolation>
        <axis>
            <x> -1 </x>
            <y>  0 </y>
            <z>  0 </z>
        </axis>
    </animation>
    
    <!-- Hacer el objeto clickeable -->
    <animation>
        <type>pick</type>
        <object-name>tirador</object-name>
        <action>
            <button>0</button>
            <repeatable>false</repeatable>
            
            <!-- Cambiar estado del botón -->
            <binding>
                <command>property-assign</command>
                <property>/instrumentation/engine-off-button/button-state</property>
                <value>1</value>
            </binding>
            
            <!-- ESTRANGULADOR DE COMBUSTIBLE -->
            <binding>
                <command>nasal</command>
                <script>
                    print("¡CLICK DETECTADO! Activando estrangulador de combustible");
                    
                    # MÉTODO 1: Cortar el suministro desde los tanques
                    # Guardar los estados originales de las bombas de combustible
                    var tank0_pump = getprop("/consumables/fuel/tank[0]/selected") or 0;
                    var tank1_pump = getprop("/consumables/fuel/tank[1]/selected") or 0;
                    var tank2_pump = getprop("/consumables/fuel/tank[2]/selected") or 0;
                    var tank3_pump = getprop("/consumables/fuel/tank[3]/selected") or 0;
                    
                    # Guardar estados originales
                    setprop("/instrumentation/engine-off-button/original-tank0-pump", tank0_pump);
                    setprop("/instrumentation/engine-off-button/original-tank1-pump", tank1_pump);
                    setprop("/instrumentation/engine-off-button/original-tank2-pump", tank2_pump);
                    setprop("/instrumentation/engine-off-button/original-tank3-pump", tank3_pump);
                    
                    # Cortar suministro de todos los tanques
                    setprop("/consumables/fuel/tank[0]/selected", 0);
                    setprop("/consumables/fuel/tank[1]/selected", 0);
                    setprop("/consumables/fuel/tank[2]/selected", 0);
                    setprop("/consumables/fuel/tank[3]/selected", 0);
                    
                    # MÉTODO 2: Forzar flujo de combustible a cero directamente
                    setprop("/engines/engine[0]/fuel-flow_pph", 0);
                    setprop("/engines/engine[0]/fuel-flow-gph", 0);
                                        
                    # Marcar que el estrangulador está activo
                    setprop("/instrumentation/engine-off-button/fuel-strangler-active", 1);
                    
                    # Crear un timer que mantenga el estrangulador activo
                    var strangler_timer = maketimer(0.05, func {
                        if(getprop("/instrumentation/engine-off-button/fuel-strangler-active")) {
                            # Mantener flujo de combustible cortado
                            setprop("/engines/engine[0]/fuel-flow_pph", 0);
                            setprop("/engines/engine[0]/fuel-flow-gph", 0);
                            setprop("/engines/engine[0]/fuel-pressure-psi", 0);
                            
                            # Asegurar que los tanques permanecen desconectados
                            setprop("/consumables/fuel/tank[0]/selected", 0);
                            setprop("/consumables/fuel/tank[1]/selected", 0);
                            setprop("/consumables/fuel/tank[2]/selected", 0);
                            setprop("/consumables/fuel/tank[3]/selected", 0);
                        }
                    });
                    
                    strangler_timer.start();
                    
                    # Guardar referencia al timer en el property tree
                    # (No podemos guardar el objeto directamente, así que usamos una marca)
                    setprop("/instrumentation/engine-off-button/timer-active", 1);
                    
                    print("=== ESTRANGULADOR ACTIVADO ===");
                    print("Tanques desconectados, flujo de combustible cortado");
                    print("Fuel flow: " ~ getprop("/engines/engine[0]/fuel-flow_pph"));
                    print("Fuel pressure: " ~ getprop("/engines/engine[0]/fuel-pressure-psi"));
                </script>
            </binding>
            
            <!-- Binding para cuando se suelta el botón -->
            <mod-up>
                <binding>
                    <command>nasal</command>
                    <script>
                        print("Botón soltado - Desactivando estrangulador");
                        
                        # PRIMERO: Resetear la animación del botón para que vuelva a su posición
                        setprop("/instrumentation/engine-off-button/button-state", 0);
                        
                        # Desactivar el estrangulador
                        setprop("/instrumentation/engine-off-button/fuel-strangler-active", 0);
                        setprop("/instrumentation/engine-off-button/timer-active", 0);
                        
                        # Restaurar el suministro de combustible de los tanques
                        var tank0_pump = getprop("/instrumentation/engine-off-button/original-tank0-pump") or 1;
                        var tank1_pump = getprop("/instrumentation/engine-off-button/original-tank1-pump") or 1;
                        var tank2_pump = getprop("/instrumentation/engine-off-button/original-tank2-pump") or 1;
                        var tank3_pump = getprop("/instrumentation/engine-off-button/original-tank3-pump") or 1;
                        
                        setprop("/consumables/fuel/tank[0]/selected", tank0_pump);
                        setprop("/consumables/fuel/tank[1]/selected", tank1_pump);
                        setprop("/consumables/fuel/tank[2]/selected", tank2_pump);
                        setprop("/consumables/fuel/tank[3]/selected", tank3_pump);
                                               
                        # Limpiar propiedades de flujo para que el motor las recalcule
                        removeChild("/engines/engine[0]/fuel-flow_pph");
                        removeChild("/engines/engine[0]/fuel-flow-gph");
                        
                        print("=== ESTRANGULADOR DESACTIVADO ===");
                        print("Suministro de combustible restaurado");
                        print("Tanques reconectados - Motor listo para funcionar");
                    </script>
                </binding>
            </mod-up>
        </action>
    </animation>
</PropertyList>