<?xml version="1.0" encoding="UTF-8" ?>

<!-- Bombardier CRJ700 series -->
<!-- Main model, all variants -->

<PropertyList>

    <nasal>
        <!-- Nasal code executed for multiplayer models. -->
        <load>
print("--BEGIN-- CRJ700 MP model code");
var model = cmdarg();
var model_path = model.getNode("sim/model/path").getValue();
var model_name = split(".", split("/", model_path)[-1])[0];

# Animations.
var mp_export = model.getNode("sim/multiplay/generic");
var mp_export_def = io.read_properties("Aircraft/CRJ700-family/Systems/CRJ700-multiplayer.xml");
foreach (var ref; mp_export_def.getChildren("reference"))
{
    var export_prop = mp_export.getChild(ref.getNode("type").getValue(), ref.getNode("index").getValue(), 1);
    var model_prop = model.getNode(ref.getNode("property").getValue(), 1);
    model_prop.alias(export_prop);
}

# Liveries.
var model_dict = {
    "CRJ700": [
        "CRJ700",
        "CRJ700ER",
        "CRJ700LR"
    ],
    "CRJ900": [
        "CRJ900",
        "CRJ900ER",
        "CRJ900LR"
    ],
    "CRJ1000": [
        "CRJ1000",
        "CRJ1000-EuroLite",
        "CRJ1000ER"
    ]
};
var variant = model.getNode("sim/model/variant").getValue();

if (model_name == nil or variant == nil)
{
  print("CRJ700 family (MP model): model name or variant not available (",model_name,", ",variant,")");
}
else 
  var livery_update = aircraft.livery_update.new("Aircraft/CRJ700-family/Models/Liveries/"~ model_dict[model_name][variant]);

io.include("Aircraft/CRJ700-family/Nasal/CRJ700-mp-model.nas");
var CRJ700_mp = CRJ700_mp_model.new(model);
CRJ700_mp.start();

# Animated jetways.
var jetway_dict = {
    "CRJ700": [
        -11.519, # x-m
        -1.139,  # y-m
        -1.796,  # z-m
        3        # hood-deg
    ],
    "CRJ900": [
        -13.459,
        -1.139,
        -1.796,
        3
    ],
    "CRJ1000": [
        -15.419,
        -1.139,
        -1.796,
        3
    ]
};
model.getNode("door[0]/position-x-m", 1).setDoubleValue(jetway_dict[model_name][0]);
model.getNode("door[0]/position-y-m", 1).setDoubleValue(jetway_dict[model_name][1]);
model.getNode("door[0]/position-z-m", 1).setDoubleValue(jetway_dict[model_name][2]);
model.getNode("door[0]/jetway-hood-deg", 1).setDoubleValue(jetway_dict[model_name][3]);
print("--END-- CRJ700 MP model code");
        </load>
        <unload>
            if (livery_update != nil) livery_update.stop();
            if (CRJ700_mp != nil) CRJ700_mp.stop();
        </unload>
    </nasal>

	<!-- Landing gear door animations -->
	<!-- Left -->
	<animation>
		<name>Left main gear upper door</name>
		<type>rotate</type>
		<object-name>GearLDoor1</object-name>
		<object-name>GearLDoor1Int</object-name>
		<object-name>GearLDoor2</object-name>
		<object-name>GearLDoor2Int</object-name>
		<property>gear/gear[1]/position-norm</property>
		<interpolation>
			<entry><ind>0</ind><dep>0</dep></entry>
			<entry><ind>0.2</ind><dep>0</dep></entry>
			<entry><ind>0.8</ind><dep>-90</dep></entry>
			<entry><ind>1</ind><dep>-90</dep></entry>
		</interpolation>
		<axis>
			<x>1</x>
			<y>0</y>
			<z>0</z>
		</axis>
		<center>
			<x-m>0</x-m>
			<y-m>-2.184</y-m>
			<z-m>-2.266</z-m>
		</center>
	</animation>
	<animation>
		<name>Left main gear lower door</name>
		<type>rotate</type>
		<object-name>GearLDoor2</object-name>
		<object-name>GearLDoor2Int</object-name>
		<property>gear/gear[1]/position-norm</property>
		<interpolation>
			<entry><ind>0</ind><dep>0</dep></entry>
			<entry><ind>0.4</ind><dep>-80</dep></entry>
			<entry><ind>1</ind><dep>-80</dep></entry>
		</interpolation>
		<axis>
			<x>1</x>
			<y>0</y>
			<z>0</z>
		</axis>
		<center>
			<x-m>0</x-m>
			<y-m>-1.862</y-m>
			<z-m>-2.279</z-m>
		</center>
	</animation>

	<!-- Right -->
	<animation>
		<name>Right main gear upper door</name>
		<type>rotate</type>
		<object-name>GearRDoor1</object-name>
		<object-name>GearRDoor1Int</object-name>
		<object-name>GearRDoor2</object-name>
		<object-name>GearRDoor2Int</object-name>
		<property>gear/gear[2]/position-norm</property>
		<interpolation>
			<entry><ind>0</ind><dep>0</dep></entry>
			<entry><ind>0.2</ind><dep>0</dep></entry>
			<entry><ind>0.8</ind><dep>90</dep></entry>
			<entry><ind>1</ind><dep>90</dep></entry>
		</interpolation>
		<axis>
			<x>1</x>
			<y>0</y>
			<z>0</z>
		</axis>
		<center>
			<x-m>0</x-m>
			<y-m>2.184</y-m>
			<z-m>-2.266</z-m>
		</center>
	</animation>
	<animation>
		<name>Right main gear lower door</name>
		<type>rotate</type>
		<object-name>GearRDoor2</object-name>
		<object-name>GearRDoor2Int</object-name>
		<property>gear/gear[2]/position-norm</property>
		<interpolation>
			<entry><ind>0</ind><dep>0</dep></entry>
			<entry><ind>0.4</ind><dep>80</dep></entry>
			<entry><ind>1</ind><dep>80</dep></entry>
		</interpolation>
		<axis>
			<x>1</x>
			<y>0</y>
			<z>0</z>
		</axis>
		<center>
			<x-m>0</x-m>
			<y-m>1.862</y-m>
			<z-m>-2.279</z-m>
		</center>
	</animation>


	
    <!-- Tutorial marker -->
    <model>
        <path>Aircraft/Generic/marker.xml</path>
    </model>

	<model>
		<name>cursor</name>
        <path>Aircraft/ufo/Models/cursor.ac</path>
    </model>	
    <animation>
        <type>select</type>
        <object-name>cursor</object-name>
        <condition>
			<property>sim/config/developer</property>
        </condition>
    </animation>
    <animation>
        <type>translate</type>
        <object-name>cursor</object-name>
		<property>yasim/cg-x-m</property>
		<axis>
			<x>-1</x>
			<y>0</y>
			<z>0</z>
		</axis>
	</animation>
    <animation>
        <type>translate</type>
        <object-name>cursor</object-name>
		<property>yasim/cg-y-m</property>
		<axis>
			<x>0</x>
			<y>-1</y>
			<z>0</z>
		</axis>
	</animation>
    <animation>
        <type>translate</type>
        <object-name>cursor</object-name>
		<property>yasim/cg-z-m</property>
		<axis>
			<x>0</x>
			<y>0</y>
			<z>1</z>
		</axis>
	</animation>
	
    <!-- Hide windshield in interior views -->
    <animation>
        <type>select</type>
        <object-name>CockpitWindows</object-name>
	<condition>
		<not>
			<property>/sim/current-view/internal</property>
		</not>
	</condition>
    </animation>

    <!-- Door animations -->
    <animation>
        <type>pick</type>
        <object-name>LeftDoor</object-name>
        <object-name>LeftDoorInt</object-name>
        <object-name>Stairs</object-name>
        <object-name>StairHandles</object-name>
        <action>
            <button>0</button>
            <repeatable type="bool">false</repeatable>
            <binding>
                <command>nasal</command>
                <script>
                    CRJ700.doors.pax_left.toggle();
                </script>
            </binding>
        </action>
    </animation>
    <animation>
        <type>rotate</type>
        <object-name>LeftDoor</object-name>
        <object-name>LeftDoorInt</object-name>
        <object-name>Stairs</object-name>
        <object-name>StairHandles</object-name>
        <property>sim/model/door-positions/pax-left/position-norm</property>
        <factor>150</factor>
        <axis>
            <x>1</x>
            <y>0</y>
            <z>0</z>
        </axis>
        <center>
            <x-m>0</x-m>
            <y-m>-1.139</y-m>
            <z-m>-1.796</z-m>
        </center>
    </animation>
    <animation>
        <type>pick</type>
        <object-name>RightDoor</object-name>
        <object-name>RightDoorInt</object-name>
        <action>
            <button>0</button>
            <repeatable type="bool">false</repeatable>
            <binding>
                <command>nasal</command>
                <script>
                    CRJ700.doors.fwd_service.toggle();
                </script>
            </binding>
        </action>
    </animation>
    <animation>
        <type>pick</type>
        <object-name>CargoDoorFwd</object-name>
        <action>
            <button>0</button>
            <repeatable type="bool">false</repeatable>
            <binding>
                <command>nasal</command>
                <script>
                    CRJ700.doors.fwd_cargo.toggle();
                </script>
            </binding>
        </action>
    </animation>
    <animation>
        <type>pick</type>
        <object-name>CargoDoorCtr</object-name>
        <action>
            <button>0</button>
            <repeatable type="bool">false</repeatable>
            <binding>
                <command>nasal</command>
                <script>
                    CRJ700.doors.ctr_cargo.toggle();
                </script>
            </binding>
        </action>
    </animation>
    <animation>
        <type>pick</type>
        <object-name>CargoDoorAft</object-name>
        <action>
            <button>0</button>
            <repeatable type="bool">false</repeatable>
            <binding>
                <command>nasal</command>
                <script>
                    CRJ700.doors.aft_cargo.toggle();
                </script>
            </binding>
        </action>
    </animation>

    <!-- Ram air turbine -->
    <animation>
        <type>translate</type>
        <object-name>RAT</object-name>
        <object-name>RATBlades</object-name>
        <property>systems/AC/system/gen5-position-norm</property>
        <interpolation>
            <entry><ind>1</ind><dep>0</dep></entry>
            <entry><ind>0</ind><dep>0.2</dep></entry>
        </interpolation>
        <axis>
            <x>0</x>
            <y>-0.4</y>
            <z>1</z>
        </axis>
    </animation>
    <animation>
        <type>rotate</type>
        <object-name>RAT</object-name>
        <object-name>RATBlades</object-name>
        <property>systems/AC/system/gen5-position-norm</property>
        <interpolation>
            <entry><ind>1</ind><dep>0</dep></entry>
            <entry><ind>0</ind><dep>-40</dep></entry>
        </interpolation>
        <axis>
            <x>1</x>
            <y>0</y>
            <z>0</z>
        </axis>
        <center>
            <x-m>0</x-m>
            <y-m>0.531</y-m>
            <z-m>-1.738</z-m>
        </center>
    </animation>
    <animation>
        <type>spin</type>
        <object-name>RATBlades</object-name>
        <property>systems/AC/system/gen5-rpm</property>
        <axis>
            <x>1</x>
            <y>0</y>
            <z>0</z>
        </axis>
        <center>
            <x-m>0</x-m>
            <y-m>0.67671</y-m>
            <z-m>-1.95605</z-m>
        </center>
    </animation>

	<effect>
		<inherits-from>Effects/CRJ700lightmap-hireflect</inherits-from>
		<parameters>
			<lightmap-factor-prop>sim/model/lights/wing-lightmap</lightmap-factor-prop>
			<lightmap-factor n="0">
				<use alias="../../lightmap-factor-prop" />
			</lightmap-factor>
			<lightmap-factor n="1">
				<use alias="../../lightmap-factor-prop" />
			</lightmap-factor>
			<lightmap-factor n="2">
				<use alias="../../lightmap-factor-prop" />
			</lightmap-factor>
			<texture n="3">
				<image>Effects/Lightmaps/wing-lightmap.png</image>
			</texture>
		</parameters>
		<object-name>AileronL</object-name>
		<object-name>AileronR</object-name>
		<object-name>FlapL1</object-name>
		<object-name>FlapR1</object-name>
		<object-name>FlapL2</object-name>
		<object-name>FlapR2</object-name>
		<object-name>SpoilerL1</object-name>
		<object-name>SpoilerL2</object-name>
		<object-name>SpoilerL3</object-name>
		<object-name>SpoilerL4</object-name>
		<object-name>SpoilerR1</object-name>
		<object-name>SpoilerR2</object-name>
		<object-name>SpoilerR3</object-name>
		<object-name>SpoilerR4</object-name>		
        <object-name>SlatsL</object-name>
        <object-name>SlatsR</object-name>
		<object-name>Wings.001</object-name>
		<object-name>Winglets</object-name>
	</effect>
	
    <!-- Reflection shaders -->
    <effect>
        <name>Chrome reflect</name>
        <inherits-from>Effects/CRJ700reflect</inherits-from>
        <object-name>WingChrome</object-name>
        <object-name>CockpitFrame</object-name>
        <object-name>LandingLts</object-name>
        <object-name>StairHandles</object-name>
    </effect>
    
    <!-- Rembrandt !! -->
    <effect>
        <name>REMBRANDT transparency</name>
        <inherits-from>Effects/model-transparent</inherits-from>
        <object-name>Windows</object-name>
        <object-name>CockpitWindows</object-name>
        <object-name>LandingLtLens</object-name>
    </effect>

</PropertyList>
