"S4L1_finish.sce"
{
	INT place_recno_e_a_ra
	INT place_recno_e_a_rb
	INT place_recno_e_a_rc
	INT place_recno_e_b
	INT place_recno_e_c
	INT place_recno_e_d
	INT place_recno_e_e
	INT place_recno_e_f
	INT place_recno_e_g
	
	INT flag_sword_reward
	INT flag_cross_reward 
	INT flag_fierbois_recue_metz

	INT flag_dead_earl
	INT flag_dead_alexander
	INT flag_dead_william
	INT flag_dead_john
	INT flag_dead_talbot
	INT flag_all_abbow_dead 
	
	INT joan_recno 

	init 
	{
		place_recno_e_a_ra = FUNC("search_place_by_name", "Large_English_Camp_E1_R1")
		place_recno_e_a_rb = FUNC("search_place_by_name", "Large_English_Camp_E1_R2")
		place_recno_e_a_rc = FUNC("search_place_by_name", "Large_English_Camp_E1_R3")
		place_recno_e_b = FUNC("search_place_by_name", "Small_English_Troops") 
		place_recno_e_c = FUNC("search_place_by_name", "Large_English_Camp_E3") 
		place_recno_e_d = FUNC("search_place_by_name", "Boulevard") 
		place_recno_e_e = FUNC("search_place_by_name", "HiddenArcher") 
		place_recno_e_f = FUNC("search_place_by_name", "Augustin") 
		place_recno_e_g = FUNC("search_place_by_name", "Tourelles") 

		joan_recno = FUNC("search_unit_by_name", "Joanna d'Arc")
	}
// ********* Main Goal ******
// *** 1 *****
	flag_sword_reward = FUNC("get_scenario_bit_flag", 1) 
	flag_cross_reward = FUNC("get_scenario_bit_flag", 2) 
	flag_fierbois_recue_metz = FUNC("get_scenario_bit_flag", 27)
	
	flag_dead_earl = FUNC("get_scenario_event_bit_flag", 19)
	flag_dead_alexander = FUNC("get_scenario_event_bit_flag", 20)
	flag_dead_william = FUNC("get_scenario_event_bit_flag", 21)
	flag_dead_john = FUNC("get_scenario_event_bit_flag", 22)
	flag_dead_talbot = FUNC("get_scenario_event_bit_flag", 23)
	flag_all_abbow_dead = FUNC("get_scenario_event_bit_flag", 24)

	if ( FUNC("get_end_condition_finish", 1) != 1 )
	{
		if( FUNC("get_place_captured", place_recno_e_g) == 1 )
		{
			FUNC("attention_call_message", "[0001N]You have captured Tourelles!")
			WAIT{ FUNC("pause_script", 4000) }	
			FUNC("set_end_condition_finish" , 1, "WIN")	
		}
	}

// *** 2 ****

	if ( FUNC("get_end_condition_finish", 2) != 1 )
	{
		if( FUNC("get_place_captured", place_recno_e_f) == 1 )
		{
			FUNC("attention_call_message", "[0002N]You have captured Saint Augustin!")
			WAIT{ FUNC("pause_script", 4000) }	
			FUNC("set_end_condition_finish" , 2, "WIN")	
		}
	}

	if ( FUNC("get_end_condition_finish", 3) != 1 )
	{
		if( flag_sword_reward  == 1 )
		{
			
			WAIT{ FUNC("pause_script", 4000) }	
			FUNC("set_end_condition_finish" , 3, "WIN")	
		}
	}

	if ( FUNC("get_end_condition_finish", 4) != 1 )
	{
		if( flag_cross_reward == 1 )
		{
			
			WAIT{ FUNC("pause_script", 4000) }	
			FUNC("set_end_condition_finish" , 4, "WIN")	
		}
	}
	
// ********* Side Goal *********
// *** 5,6 ****
	if ( FUNC("get_end_condition_finish", 5) != 1 )
	{
		if( ( FUNC("get_place_captured", place_recno_e_a_ra) && FUNC("get_place_captured", place_recno_e_a_rb) && FUNC("get_place_captured", place_recno_e_a_rc) ) && FUNC("get_place_captured", place_recno_e_b) && FUNC("get_place_captured", place_recno_e_c) && FUNC("get_place_captured", place_recno_e_d))
		{
			FUNC("attention_call_message", "[0003N]You have captured all English Camps!")
			WAIT{ FUNC("pause_script", 4000) }	
			FUNC("set_end_condition_finish" , 5, "WIN")	
		}
	}

	if ( FUNC("get_end_condition_finish", 6) != 1 )
	{
		if( FUNC("get_scenario_bit_flag", 11) && FUNC("get_scenario_bit_flag", 12) )
		{
			FUNC("attention_call_message", "[0004N]You have set free the french prisoners!")
			WAIT{ FUNC("pause_script", 4000) }	
			FUNC("set_end_condition_finish" , 6, "WIN")	
		}
	}


// ********* Lose Goal *********
// *** 7 ****

	// Joan defeat
	if ( FUNC("get_end_condition_finish", 7) != 1 )
	{
		if ( FUNC("is_unit_dead", joan_recno) == 1)
		{
			FUNC("call_gameover_msg", "[0005N]You have failed to free the path to the Loire river basin!")
			WAIT{ FUNC("pause_script", 4000) }	
			FUNC("set_end_condition_finish" , 7, "LOSE")	
		}
	}

// *** 8 ***

	if( FUNC ("get_end_condition_enabled", 8 ) )
	{ 
		if ( FUNC("get_end_condition_finish", 8) != 1 )
		{
			if ( flag_all_abbow_dead )
			{
				FUNC("attention_call_message", "[0006N]You have destroyed all six arbalests in Saint Augustin!")
				WAIT{ FUNC("pause_script", 4000) }	
				FUNC("set_end_condition_finish" , 8, "WIN")	
			}
		}
	}

	if( FUNC ("get_end_condition_enabled", 9 ) )
	{ 
		if ( FUNC("get_end_condition_finish", 9) != 1 )
		{
			if ( flag_fierbois_recue_metz )
			{
				FUNC("attention_call_message", "[0007N]You have rescued Jean de Metz!")
				WAIT{ FUNC("pause_script", 4000) }	
				FUNC("set_end_condition_finish" , 9, "WIN")	
			}
		}
	}


	if( FUNC ("get_end_condition_enabled", 10 ) )
	{ 
		if ( FUNC("get_end_condition_finish", 10) != 1 )
		{
			if( flag_dead_william )
			{
				FUNC("attention_call_message", "[0008N]You have defeated Sir William Glasdale!")
				WAIT{ FUNC("pause_script", 4000) }	
				FUNC("set_end_condition_finish" , 10, "WIN")	
			}
		}
	}


	if( FUNC ("get_end_condition_enabled", 11 ) )
	{ 
		if ( FUNC("get_end_condition_finish", 11) != 1 )
		{
			if( flag_dead_earl )
			{
				FUNC("attention_call_message", "[0009N]You have defeated William de la Pole!")
				WAIT{ FUNC("pause_script", 4000) }	
				FUNC("set_end_condition_finish" , 11, "WIN")	
			}
		}
	}

	if( FUNC ("get_end_condition_enabled", 12 ) )
	{ 
		if ( FUNC("get_end_condition_finish", 12) != 1 )
		{
			if( flag_dead_alexander )
			{
				FUNC("attention_call_message", "[0010N]You have defeated Alexander de la Pole!")
				WAIT{ FUNC("pause_script", 4000) }	
				FUNC("set_end_condition_finish" , 12, "WIN")	
			}
		}
	}



	if( FUNC ("get_end_condition_enabled", 13 ) )
	{ 
		if ( FUNC("get_end_condition_finish", 13) != 1 )
		{
			if( flag_dead_john )
			{
			//	FUNC("attention_call_message", "[0001N]You have defeated John de la Pole!")
				WAIT{ FUNC("pause_script", 4000) }	
				FUNC("set_end_condition_finish" , 13, "WIN")	
			}
		}
	}

	if( FUNC ("get_end_condition_enabled", 14 ) )
	{ 
		if ( FUNC("get_end_condition_finish", 14) != 1 )
		{
			if( flag_dead_talbot )
			{
				FUNC("attention_call_message", "[0011N]You have defeated Lord Talbot!")
				WAIT{ FUNC("pause_script", 4000) }	
				FUNC("set_end_condition_finish" , 14, "WIN")	
			}
		}
	}


//	if ( FUNC("get_end_condition_finish", 1) == 1 && FUNC("get_end_condition_finish", 2) == 1 && FUNC("get_end_condition_finish", 3) == 1 && FUNC("get_end_condition_finish", 4) == 1 ) 
//	{
	//	FUNC("set_victory_display_flag", 1)
//	}

	exit
}