<?xml version="1.0" ?>

<Scene name="EngineRoom" zbase="236" zfactor="0.303">
	<Object type="LBAMap" name="EngineRoom_walk" filename="EngineRoom.lba" x="0" y="0"/>
	
	<Audio source="maszlow_interior"/>
	<Audio source="engine_room"/>
	
	<if t="$luna_scene == $active_scene and $current_character == brawe and $diversion_type == 0">
		<Action color="D0AB1E" type="Multiple" rollover="RO_LUNA">
			<Action multiple="look" type="CommandCharacter" chr="brawe">
				<Job type="SetVar" var="approach_target" value="luna"/>
				<Job type="CallAction" ref="ui.ApproachCharacter"/>
				<Job type="CallAction" ref="ui.FaceCharacter"/>
				<Job type="Say" key="BRAWE_LOOK_AT_LUNA_IN_SHIP_01"/>
			</Action>
			<Action multiple="talk" type="CommandCharacter" chr="brawe">
				<Job type="SetVar" var="approach_target" value="luna"/>
				<Job type="CallAction" ref="ui.ApproachCharacter"/>
				<Job type="CallAction" ref="ui.FaceCharacter"/>
				<Job type="Dialog" dialog="the_replicator_root"/>
			</Action>
		</Action>
	</if>

	<if t="not $diversion_type == 0">
		<if t="$diversion_type == 1">
			<Object type="Character2D" chr="luna" x="280" y="150" direction="SW"/>
		</if>
		<if t="$diversion_type == 2">
			<Object type="Character2D" chr="luna" x="310" y="195" direction="NE"/>
		</if>

		<if t="$brawe_scene == $active_scene">
			<Object type="Character2D" chr="brawe" x="0" y="0"/>
				<!-- <Property name="position_if:$prev_scene == ship.Cockpit" value="255,150,S"/> -->
				<!-- <Property name="position_if:$prev_scene == ship.Router" value="295,160,E"/> -->
		</if>

		<if t="$diversion_type == 1">
			<if t="not $diversion_init">
				<Object type="Character2D" chr="kralek" x="302" y="210" direction="NW"/>
			<else>
				<Object type="Character2D" chr="kralek" x="0" y="0"/>
			</else>
			</if>
		</if>
		<if t="$diversion_type == 2">
			<if t="not $diversion_init">
				<Object type="Character2D" chr="kralek" x="280" y="150" direction="SE"/>
			<else>
				<Object type="Character2D" chr="kralek" x="0" y="0"/>
			</else>
			</if>
		</if>

		<if t="not $diversion_init">
			<Action type="CommandCharacter" chr="luna">
				<Job condition="$diversion_type == 1" type="SetOrientation" direction="SW"/> <!-- engine -->
				<Job condition="$diversion_type == 2" type="SetOrientation" direction="NE"/> <!-- router -->
			</Action>
			<Action type="CommandCharacter" chr="kralek">
				<Job condition="$diversion_type == 1" type="SetOrientation" direction="NW"/> <!-- engine -->
				<Job condition="$diversion_type == 1" type="Say" key="KRALEK_EXPLAINS_ENGINE_01"/> <!-- engine -->
				<Job condition="$diversion_type == 2" type="SetOrientation" direction="SE"/> <!-- router -->
				<Job condition="$diversion_type == 2" type="Say" key="KRALEK_EXPLAINS_ROUTER_01"/> <!-- router -->
				<Job type="SetVar" var="diversion_time_countdown" value="32" reset="0"/>
				<Job type="SetVar" var="diversion_init" value="1" reset="0"/>
				<Job type="SetVar" var="kralek_in_engine_room" value="1" reset="0"/>
				<Job type="SetVar" var="ship_diversion_timer_enabled" value="1" reset="0"/>
				
				<Job type="SetVar" var="luna_items" value="$items" reset="0"/>
				<Job type="SetVar" var="items" value="$brawe_items" reset="0"/>
				<Job type="SetVar" var="current_character" value="brawe" reset="0"/>
				
				<Job type="UnlockScene"/>
				<Job condition="not $brawe_scene == ship.EngineRoom" type="SwitchScene" scene="$brawe_scene"/>
				<Job condition="$brawe_scene == ship.EngineRoom" type="ResetScene"/>
			</Action>
		</if>


		<if t="$current_character == brawe">
			<Action color="FFFF00" type="CommandCharacter" chr="brawe" rollover="RO_ENGINE_2_CARGO|u">
				<Job type="Move" x="230" y="140"/>
				<Job type="SetOrientation" direction="NW"/>
				<Job condition="$ship_diversion_timer_enabled" type="IncVar" var="diversion_time_countdown" value="1" reset="0"/>
				<Job type="SwitchScene" scene="CargoHold" pos="517,260,W"/>
			</Action>
			
			<Action condition="$diversion_type == 2" color="00FF00" type="Reference" ref="M::engine_room_kralek_actions" rollover="RO_KRALEK"/>
			<Action condition="$diversion_type == 2" color="00A651" type="Reference" ref="M::engine_room_kralek_actions" rollover="RO_KRALEK"/>
			
			<Action condition="$diversion_type == 1" color="0000FF" type="Reference" ref="M::engine_room_kralek_actions" rollover="RO_KRALEK"/>
			<Action condition="$diversion_type == 1" color="00A651" type="Reference" ref="M::engine_room_kralek_actions" rollover="RO_KRALEK"/>

			<Action name="M::engine_room_kralek_actions" type="ItemAction">
			
				<Action itemaction="noitem" type="Multiple">
					<Action multiple="look" type="CommandCharacter" chr="brawe">
						<Job condition="$diversion_type == 2" type="Move" x="260" y="140"/>
						<Job condition="$diversion_type == 2" type="SetOrientation" direction="SE"/>
						<Job condition="$diversion_type == 2" type="IncVar" var="diversion_time_countdown" value="1" reset="0"/>
						<Job condition="$diversion_type == 2" type="SetVar" var="ship_diversion_timer_enabled" value="0"/>						
						<Job type="Say" key="LOOKED_AT_KRALEK_DIVERSION_IN_PROGRESS_01"/>
						<Job condition="$diversion_type == 2" type="Dialog" dialog="SEQ_BRAWE_KRALEK_ENGINE_ROOM" value="0"/>	
					</Action>
					<Action multiple="use" type="CommandCharacter" chr="brawe">
						<Job condition="$diversion_type == 2" type="Move" x="260" y="140"/>
						<Job condition="$diversion_type == 2" type="SetOrientation" direction="SE"/>						
						<Job condition="$diversion_type == 2" type="IncVar" var="diversion_time_countdown" value="1" reset="0"/>
						<Job condition="$diversion_type == 2" type="SetVar" var="ship_diversion_timer_enabled" value="0"/>
						<Job type="Say" key="USE_KRALEK_DIVERSION_IN_PROGRESS_01"/>
						<Job condition="$diversion_type == 2" type="Dialog" dialog="SEQ_BRAWE_KRALEK_ENGINE_ROOM" value="0"/>						
					</Action>
				</Action>
				
				<Action itemaction="hammer" type="CommandCharacter" chr="brawe">
					<Job condition="$diversion_type == 1" type="IncVar" var="diversion_time_countdown" value="1" reset="0"/>
					<Job condition="$diversion_type == 2" type="LockScene"/>
					<Job type="SetVar" var="ship_diversion_timer_enabled" value="0" reset="0"/>
					<Job condition="$diversion_type == 1" type="CallAction" ref="M::kralek_sees_hammer"/>
					<Job condition="$diversion_type == 2" type="Move" x="260" y="140"/>
					<Job condition="$diversion_type == 2" type="SetOrientation" direction="SE"/>
					<Job condition="$diversion_type == 2" type="Animate" ani="Take"/>
					<Job condition="$diversion_type == 2" type="SetVar" var="kralek_knocked_in_mazslow" value="1" reset="0"/>
					<Job condition="$diversion_type == 2" type="SetVar" var="kralek_knocked_luna_comment" value="1" reset="0"/>
					<Job condition="$diversion_type == 2" type="Say" key="HIT_KRALEK_WITH_HAMMER_SUCCESS_01" nowait="1"/>
					<Job condition="$diversion_type == 2" type="Animate" ani="TakeBack"/>
					<Job condition="$diversion_type == 2" type="SetVar" var="current_character" value="brawe" reset="0"/>
					<Job condition="$diversion_type == 2" type="SetVar" var="hint15_kralek" value="0" reset="0"/>
					<Job condition="$diversion_type == 2" type="SetVar" var="diversion_type" value="0"/>
				</Action>

			</Action>

			<Action name="M::kralek_sees_hammer" type="CommandCharacter" chr="kralek">
				<Job type="Say" key="HIT_KRALEK_WITH_HAMMER_FAIL_01"/>
				<Job type="SetVar" var="ship_diversion_timer_enabled" value="1"/>
			</Action>
		</if>

		<!-- DISTRACTION TIMER -->

		<if t="$ship_diversion_timer_enabled">
			<if t="$diversion_time_countdown } 0">
				<Animator type="DelayedAction" time="1">
					<Action type="IncVar" var="diversion_time_countdown" value="-1"/>
				</Animator>

			<else> <!-- on timeout -->
				<Action type="Composite">
					<Action type="LockScene"/>
					<Action type="EndDialog"/>
					<Action type="ClearJobs" chr="brawe"/>
					<Action type="DebugPrint" text="On timeout (EngineRoom)"/>
					<Action type="SetVar" var="ship_diversion_timer_enabled" value="0" reset="0"/>
					<Action type="SetVar" var="ship_switch_back_to" value="$prev_scene" reset="0"/>
					<Action type="CommandCharacter" chr="luna">
						<Job condition="$diversion_type == 1" type="SetOrientation" direction="SE"/>
						<Job condition="$diversion_type == 2" type="SetOrientation" direction="N"/>
					</Action>
					<Action type="CommandCharacter" chr="kralek">
						<Job condition="not $ship_changing_course" type="Say" key="KRALEK_DUTY_CALLS_01"/>
						<Job condition="$ship_changing_course" type="Say" key="KRALEK_SHIP_CHANGING_COURSE_01"/>
						<Job type="SetVar" var="diversion_type" value="-1" reset="0"/>
						<Job type="Move" x="180" y="120"/>
						<Job type="SetOrientation" direction="N"/>
						<Job type="SetVar" var="kralek_in_engine_room" value="0" reset="0"/>
						<Job type="SetVar" var="switchable_characters" value="brawe,luna" reset="0"/>
						<Job type="SwitchScene" scene="ship.Cockpit"/>
					</Action>
				</Action>
			</else>
			</if>
		</if>

		<!-- **************** -->
	<else>

		<if t="$kralek_knocked_in_mazslow">
			<Object type="ImageBox" image="Kralek" x="248" y="89" />
		</if>

		<if t="$brawe_scene == ship.EngineRoom or $prev_scene == ship.Router">
			<Object type="Character2D" chr="brawe" x="0" y="0"/>
				<!-- TODO <Property name="position_if:$prev_scene == ship.CargoHold" value="240,140,SE"/> -->
				<!-- TODO <Property name="position_if:$prev_scene == ship.Cockpit" value="255,150,S"/> -->
				<!-- TODO <Property name="position_if:$prev_scene == ship.Router" value="295,160,E"/> -->
				<!-- TODO <Property name="position_if:$prev_scene == ship.EngineRoom" value="260,140,SE"/> --> <!-- kralek knocked in mazslow -->
			<!-- TODO </Object> -->
		</if>

		<if t="$luna_scene == $active_scene">
			<Object type="Character2D" chr="luna" x="0" y="0"/>
			<if t="$kralek_knocked_luna_comment">
				<Action type="CommandCharacter" chr="luna">
					<Job type="SetOrientation" direction="N"/>
					<Job type="Pause" time="0.5"/>
					<Job type="Say" key="LUNA_KRALEK_KNOCKED_01"/>
					<Job type="UnlockScene"/>
					<Job type="SetVar" var="kralek_knocked_luna_comment" value="0" reset="0"/>
				</Action>
			</if>
		</if>

		<Action color="FFFF00" type="CommandCharacter" chr="$current_character" rollover="RO_ENGINE_2_CARGO|u">
			<Job type="Move" x="230" y="140"/>
			<Job type="SetOrientation" direction="NW"/>
			<Job condition="$ship_diversion_timer_enabled" type="IncVar" var="diversion_time_countdown" value="1" reset="0"/>
			<Job type="SwitchScene" scene="CargoHold" pos="517,260,W"/>
		</Action>
		<Action color="FF0033" condition="$current_character == brawe and not $router_solved" type="CommandCharacter" chr="$current_character" rollover="RO_ENGINE_2_ROUTER|r">
			<Job type="Move" x="320" y="150"/>
			<Job type="SetOrientation" direction="NE"/>
			<!--<Job type="Animate" ani="Take"/>-->
			<Job type="SwitchScene" scene="Router"/>
		</Action>
		<Action color="FF0033" condition="$current_character == brawe and $router_solved" type="CommandCharacter" chr="$current_character" rollover="RO_ENGINE_2_ROUTER">
			<Job type="Move" x="320" y="150"/>
			<Job type="SetOrientation" direction="NE"/>
			<Job type="Say" key="ROUTER_ALREADY_SOLVED"/>
		</Action>

		<if t="$current_character == luna and $luna_scene == $active_scene and $diversion_type == 0">
			<Object type="Character2D" chr="luna" x="0" y="0"/>
				<!-- TODO <Property name="position_if:$prev_scene == ship.CargoHold" value="245,140,S"/> -->
				<!-- TODO <Property name="position_if:$prev_scene == ship.Cockpit" value="255,150,S"/> --> <!-- nakon sto Kralek ode u cutsceni -->
			<!-- </Object> -->
		</if>

	
		<if t="$picked_up_aliens == 0">
			<Action color="FF00FF" type="Multiple" rollover="RO_TERRA">
				<Action multiple="look" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="275" y="245"/>
					<Job type="SetOrientation" direction="SW"/>
					<Job type="Say" key="TERRA_LOOK_01"/>
				</Action>
				<Action multiple="use" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="275" y="245"/>
					<Job type="SetOrientation" direction="SW"/>
					<Job type="Say" key="TERRA_USE_01"/>
				</Action>
			</Action>
			
			<Action color="FF0099" type="Multiple" rollover="RO_JAMA">
				<Action multiple="look" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="275" y="245"/>
					<Job type="SetOrientation" direction="SE"/>
					<Job type="Say" key="JAMA_LOOK_01"/>
				</Action>
				<Action multiple="use" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="275" y="245"/>
					<Job type="SetOrientation" direction="SE"/>
					<Job type="Say" key="JAMA_USE_01"/>
				</Action>
			</Action>
			
		<else>		
			<Action color="FF00FF" type="Multiple" rollover="RO_TERRA">
				<Action multiple="look" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="275" y="245"/>
					<Job type="SetOrientation" direction="SW"/>
					<Job type="Say" key="TERRA_AFTER_JAMA_LOOK_01"/>
				</Action>
				<Action multiple="use" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="275" y="245"/>
					<Job type="SetOrientation" direction="SW"/>
					<Job type="Say" key="TERRA_AFTER_JAMA_USE_01"/>
				</Action>
			</Action>
			
			<Action color="FF0099" type="Multiple" rollover="RO_JAMA">
				<Action multiple="look" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="275" y="245"/>
					<Job type="SetOrientation" direction="SE"/>
					<Job type="Say" key="JAMA_AFTER_JAMA_LOOK_01"/>
				</Action>
				<Action multiple="use" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="275" y="245"/>
					<Job type="SetOrientation" direction="SE"/>
					<Job type="Say" key="JAMA_AFTER_JAMA_USE_01"/>
				</Action>
			</Action>
		
		</else>
		</if>
		

		<Action color="660099" condition="$current_character == brawe" type="Composite" rollover="RO_ENGINE">
			<Action condition="$current_character == brawe" type="Multiple">
				<Action multiple="look" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="265" y="200"/>
					<Job type="SetOrientation" direction="SW"/>
					<Job type="Say" key="ENGINE_LOOK_01"/>
				</Action>
				<Action multiple="use" type="CommandCharacter" chr="$current_character">
					<Job type="Move" x="265" y="200"/>
					<Job type="SetOrientation" direction="SW"/>
					<Job type="Say" key="ENGINE_USE_01"/>
				</Action>
			</Action>
			<Action condition="$current_character == luna" type="CommandCharacter" chr="luna">
				<Job type="Move" x="265" y="200"/>
				<Job type="SetOrientation" direction="SW"/>
			</Action>
		</Action>
	</else>
	</if>

	<if t="$router_cutscene == 1">
		<Action type="CommandCharacter" chr="brawe">
			<Job type="DebugPrint" text="Now in EngineRoom, started cutscene..."/>
            <Job type="Say" key="ROUTER_SOLVING"/>
			<Job type="Pause" time="0.5"/>
			<Job type="SwitchScene" scene="ship.Cockpit"/>
		</Action>
	</if>

	<if t="$router_cutscene == 2">
		<Action type="CommandCharacter" chr="brawe">
            <Job type="Say" key="ROUTER_SOLVED"/>
			<Job type="Pause" time="1"/>
		    <Job type="SetVar" var="router_cutscene" value="0" reset="0"/>
			<Job type="SetVar" var="hint3_translator" value="0" reset="0"/>
			<Job type="UnlockScene"/>
		</Action>
	</if>

    <Object type="ImageBox" image="EngineRoom-Foreground" x="0" y="0" />
	<Object type="ImageBox" image="Glass" x="46" y="5" />

</Scene>