-- Cardinal's Guards cheat you, kill them all
function execute_missioncardguardgambling1( name )
	DEBUG_OUTPUT( name .. " started" ) ;
	
	setMissionChatString( name, "parisinnbman", getString( "cardinalsguardinn3_d6" ) ) ;
	
	local overrideSaveID = createOverrideSavePos( "france", 317, 3163 ) ;
	setOverrideSaveLevel( overrideSaveID, "parisinnb" ) ;
	
	local markerPosX = 0 ;
	local markerPosY = 0 ;
	local marker = addMarkerPosition( name, false, getString( "mcardguardgamblingm1" ), "parisinnb", markerPosX, markerPosY ) ;
		
	while( not ( getCharacterFunctionalLevel( "dartagnan" ) == "parisinnb" ) ) do
		coroutine.yield( ) ;
	end
	
	removeMarker( name, marker ) ;
	
	resetCharacterAI( "cardinalsguardinn4" ) ;
		
	makeEnemies( "dartagnan", "cardinalsguardinn1", "cardinalsguardinn2", "cardinalsguardinn3", 
		"cardinalsguardinn4", "cardinalsguardinn5", "cardinalsguardinn6", "cardinalsguardinn7" ) ;

	local markerEnemy1 = addMarkerCharacter( name, false, getString( "fightmarker" ), "cardinalsguardinn1" ) ;
	local markerEnemy2 = addMarkerCharacter( name, false, getString( "fightmarker" ), "cardinalsguardinn2" ) ;
	local markerEnemy3 = addMarkerCharacter( name, false, getString( "fightmarker" ), "cardinalsguardinn3" ) ;
	local markerEnemy4 = addMarkerCharacter( name, false, getString( "fightmarker" ), "cardinalsguardinn4" ) ;
	local markerEnemy5 = addMarkerCharacter( name, false, getString( "fightmarker" ), "cardinalsguardinn5" ) ;
	local markerEnemy6 = addMarkerCharacter( name, false, getString( "fightmarker" ), "cardinalsguardinn6" ) ;
	local markerEnemy7 = addMarkerCharacter( name, false, getString( "fightmarker" ), "cardinalsguardinn7" ) ;
	
	waitUntilDead( "cardinalsguardinn1" ) ;
	waitUntilDead( "cardinalsguardinn2" ) ;
	waitUntilDead( "cardinalsguardinn3" ) ;
	waitUntilDead( "cardinalsguardinn4" ) ;
	waitUntilDead( "cardinalsguardinn5" ) ;
	waitUntilDead( "cardinalsguardinn6" ) ;
	waitUntilDead( "cardinalsguardinn7" ) ;
	
	removeMarker( name, markerEnemy1 ) ;
	removeMarker( name, markerEnemy2 ) ;
	removeMarker( name, markerEnemy3 ) ;
	removeMarker( name, markerEnemy4 ) ;
	removeMarker( name, markerEnemy5 ) ;
	removeMarker( name, markerEnemy6 ) ;
	removeMarker( name, markerEnemy7 ) ;
	
	removeOverrideSavePos( overrideSaveID ) ;
		
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Marin the Gunsmith Missions
function createmissionmarin1enemy( missionName, level, x, y )
	local enemy = createTempCharacter( getString( "thief" ), level, x, y ) ;
	randomDressEnemy( enemy, 0.5, randomInt( 0, 99999 ) ) ;
	setMeleeWeapon( enemy, "sword_1" ) ;
	setMissionFaceCharacter( missionName, enemy, "dartagnan" ) ;
	
	return enemy ;
end

function execute_missionmarin1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local enemyLevelName = "stgermainstorea" ;

	setMissionChatString( name, "marinlebourgeoys", getString( "mmarin0d9" ) ) ;
	setMissionChatString( name, "stgermainstoreaman", getString( "mmarin1d7" ) ) ;

	local overrideSaveID = createOverrideSavePos( "france", -7081, 943 ) ;
	setOverrideSaveLevel( overrideSaveID, enemyLevelName ) ;
	
	local markerPosX = -97 ;
	local markerPosY = 14 ;
	local marker = addMarkerPosition( name, false, getString( "mmarin1m1" ), enemyLevelName, markerPosX, markerPosY ) ;
	
	local enemy1 = createmissionmarin1enemy( name, enemyLevelName, -96, -37 ) ;
	local enemy2 = createmissionmarin1enemy( name, enemyLevelName, -183, -24 ) ;
	local enemy3 = createmissionmarin1enemy( name, enemyLevelName, -10, -15 ) ;
	local enemy4 = createmissionmarin1enemy( name, enemyLevelName, -13, 73 ) ;
	local enemy5 = createmissionmarin1enemy( name, enemyLevelName, -193, 23 ) ;
	local enemy6 = createmissionmarin1enemy( name, enemyLevelName, -195, 92 ) ;

	while( not ( getCharacterFunctionalLevel( "dartagnan" ) == enemyLevelName ) ) do
		coroutine.yield( ) ;
	end

	removeMarker( name, marker ) ;

	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missionmarin1" ) ;
	DEBUG_OUTPUT( "playercombat level " .. getHighestPlayerCombatLevel( ) ) ;
	DEBUG_OUTPUT( "saved playercombat level " .. playerCombatLevel ) ;
	local minDifficulty = 4 ;
	local maxDifficulty = 6 ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy1, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy1 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy2, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy2 ) ;
	
	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy3, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy3 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy4, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy4 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy5, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy5 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy6, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy6 ) ;
		
	lockPlayerInPlace( ) ;
	
	local tenseMusicID = addMusic( "extratense", 15 ) ;
		
	addGoalGetToPointInLevel( "dartagnan", -101, 31, enemyLevelName, false, true ) ;
	waitForNoGoal( "dartagnan" ) ;
	
	faceCharacter( "dartagnan", enemy1 ) ;
	
	local bubInd = characterSay( enemy1, true, -1, -1, true, getString( "mmarin1d1" ) ) ;
	waitForBubbleDone( bubInd ) ;
	setBubbleToBackgroundOpacity( bubInd ) ;
	local bubInd2 = characterSay( "dartagnan", false, -1, -1, true, "", getString( "mmarin1d2" ), getString( "mmarin1d3" ) ) ;
	local option = waitForBubbleOption( bubInd2 ) ;
	deleteBubble( bubInd ) ;

	removeMusic( tenseMusicID ) ;
	
	unlockPlayerInPlace( ) ;
	
	makeEnemies( "dartagnan", enemy1, enemy2, enemy3, enemy4, enemy5, enemy6 ) ;
	
	local marker1 = addMarkerCharacter( name, false, getString( "fight" ), enemy1 ) ;
	local marker2 = addMarkerCharacter( name, false, getString( "fight" ), enemy2 ) ;
	local marker3 = addMarkerCharacter( name, false, getString( "fight" ), enemy3 ) ;
	local marker4 = addMarkerCharacter( name, false, getString( "fight" ), enemy4 ) ;
	local marker5 = addMarkerCharacter( name, false, getString( "fight" ), enemy5 ) ;
	local marker6 = addMarkerCharacter( name, false, getString( "fight" ), enemy6 ) ;
	
	waitUntilDead( enemy1 ) ;
	waitUntilDead( enemy2 ) ;
	waitUntilDead( enemy3 ) ;
	waitUntilDead( enemy4 ) ;
	waitUntilDead( enemy5 ) ;
	waitUntilDead( enemy6 ) ;

	removeMarker( name, marker1 ) ;
	removeMarker( name, marker2 ) ;
	removeMarker( name, marker3 ) ;
	removeMarker( name, marker4 ) ;
	removeMarker( name, marker5 ) ;
	removeMarker( name, marker6 ) ;
	
	local marker = addMarkerCharacter( name, false, getString( "mmarin1m1" ), "stgermainstoreaman" ) ;
	waitForTalk( "dartagnan", "stgermainstoreaman", false ) ;
	
	removeMarker( name, marker ) ;
	
	lockPlayerInPlace( ) ;
	
	setMissionFaceCharacter( name, "stgermainstoreaman", "dartagnan" ) ;

	sayAndWait( "stgermainstoreaman", getString( "mmarin1d4" ) ) ;
	sayAndWait( "dartagnan", getString( "mmarin1d5" ) ) ;
	sayAndWait( "stgermainstoreaman", getString( "mmarin1d6" ) ) ;
		
	unlockPlayerInPlace( ) ;
	
	removeOverrideSavePos( overrideSaveID ) ;
	
	completeMission( name ) ;
	activateMission( "missionmarin2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionmarin2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local enemyLevelName = "stgermainhousec" ;

	setMissionChatString( name, "marinlebourgeoys", getString( "mmarin0d9" ) ) ;
	setMissionChatString( name, "stgermainhousecman1", getString( "mmarin2d4" ) ) ;
	setMissionChatString( name, "stgermainhousecman2", getString( "mmarin2d5" ) ) ;

	setMissionFaceCharacter( name, "stgermainhousecman1", "dartagnan" ) ;
	setMissionFaceCharacter( name, "stgermainhousecman2", "dartagnan" ) ;

	local overrideSaveID = createOverrideSavePos( "france", -6175, 449 ) ;
	setOverrideSaveLevel( overrideSaveID, enemyLevelName ) ;
	
	local markerPosX = -198 ;
	local markerPosY = 165 ;
	local marker = addMarkerPosition( name, false, getString( "mmarin1m1" ), enemyLevelName, markerPosX, markerPosY ) ;
	
	local enemy1 = createmissionmarin1enemy( name, enemyLevelName, -301, 33 ) ;
	local enemy2 = createmissionmarin1enemy( name, enemyLevelName, -179, 81 ) ;
	local enemy3 = createmissionmarin1enemy( name, enemyLevelName, -93, 168 ) ;
	local enemy4 = createmissionmarin1enemy( name, enemyLevelName, -209, 243 ) ;
	local enemy5 = createmissionmarin1enemy( name, enemyLevelName, -363, 270 ) ;
	local enemy6 = createmissionmarin1enemy( name, enemyLevelName, -368, 74 ) ;
	
	local francois = createTempCharacter( getString( "francois" ), enemyLevelName, -236, -50 ) ;
	randomDressEnemy( francois, 1.0, 766884 ) ;
	setMissionFaceCharacter( name, francois, "dartagnan" ) ;
	
	setMissionChatString( name, francois, getString( "mmarin2d6" ) ) ;
	
	while( not ( getCharacterFunctionalLevel( "dartagnan" ) == enemyLevelName ) ) do
		coroutine.yield( ) ;
	end

	removeMarker( name, marker ) ;

	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missionmarin1" ) ;
	DEBUG_OUTPUT( "playercombat level " .. getHighestPlayerCombatLevel( ) ) ;
	DEBUG_OUTPUT( "saved playercombat level " .. playerCombatLevel ) ;
	local minDifficulty = 5 ;
	local maxDifficulty = 7 ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy1, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy1 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy2, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy2 ) ;
	
	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy3, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy3 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy4, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy4 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy5, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy5 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy6, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy6 ) ;
		
	lockPlayerInPlace( ) ;
	
	addGoalGetToPointInLevel( "dartagnan", -279, 156, enemyLevelName, false, true ) ;
	waitForNoGoal( "dartagnan" ) ;
	
	faceCharacter( "dartagnan", francois ) ;
	
	sayAndWait( francois, getString( "mmarin2d1" ) ) ;
	sayAndWait( enemy1, getString( "mmarin2d2" ) ) ;
		
	unlockPlayerInPlace( ) ;
	
	makeEnemies( "dartagnan", enemy1, enemy2, enemy3, enemy4, enemy5, enemy6 ) ;
	
	local marker1 = addMarkerCharacter( name, false, getString( "fight" ), enemy1 ) ;
	local marker2 = addMarkerCharacter( name, false, getString( "fight" ), enemy2 ) ;
	local marker3 = addMarkerCharacter( name, false, getString( "fight" ), enemy3 ) ;
	local marker4 = addMarkerCharacter( name, false, getString( "fight" ), enemy4 ) ;
	local marker5 = addMarkerCharacter( name, false, getString( "fight" ), enemy5 ) ;
	local marker6 = addMarkerCharacter( name, false, getString( "fight" ), enemy6 ) ;
	
	waitUntilDead( enemy1 ) ;
	waitUntilDead( enemy2 ) ;
	waitUntilDead( enemy3 ) ;
	waitUntilDead( enemy4 ) ;
	waitUntilDead( enemy5 ) ;
	waitUntilDead( enemy6 ) ;

	removeMarker( name, marker1 ) ;
	removeMarker( name, marker2 ) ;
	removeMarker( name, marker3 ) ;
	removeMarker( name, marker4 ) ;
	removeMarker( name, marker5 ) ;
	removeMarker( name, marker6 ) ;
	
	minDifficulty = 7 ;
	maxDifficulty = 9 ;
		
	local enemy7 = createmissionmarin1enemy( name, "france", -6144, 452 ) ;
	placeCharacterInDoor( enemy7, "stgermainhousecin", false ) ;
	makeEnemies( "dartagnan", enemy7 ) ;
	local marker7 = addMarkerCharacter( name, false, getString( "fight" ), enemy7 ) ;
	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy7, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy7 ) ;
	wait( 0.5 ) ;
	
	local enemy8 = createmissionmarin1enemy( name, "france", -6144, 452 ) ;
	placeCharacterInDoor( enemy8, "stgermainhousecin", false ) ;
	makeEnemies( "dartagnan", enemy8 ) ;
	local marker8 = addMarkerCharacter( name, false, getString( "fight" ), enemy8 ) ;
	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy8, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy8 ) ;
	wait( 0.5 ) ;
	
	local enemy9 = createmissionmarin1enemy( name, "france", -6144, 452 ) ;
	placeCharacterInDoor( enemy9, "stgermainhousecin", false ) ;
	makeEnemies( "dartagnan", enemy9 ) ;
	local marker9 = addMarkerCharacter( name, false, getString( "fight" ), enemy9 ) ;
	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy9, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy9 ) ;
	wait( 0.5 ) ;
	
	local enemy10 = createmissionmarin1enemy( name, "france", -6144, 452 ) ;
	placeCharacterInDoor( enemy10, "stgermainhousecin", false ) ;
	makeEnemies( "dartagnan", enemy10 ) ;
	local marker10 = addMarkerCharacter( name, false, getString( "fight" ), enemy10 ) ;
	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy10, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy10 ) ;
	wait( 0.5 ) ;
	
	waitUntilDead( enemy7 ) ;
	waitUntilDead( enemy8 ) ;
	waitUntilDead( enemy9 ) ;
	waitUntilDead( enemy10 ) ;

	removeMarker( name, marker7 ) ;
	removeMarker( name, marker8 ) ;
	removeMarker( name, marker9 ) ;
	removeMarker( name, marker10 ) ;	
		
	local marker = addMarkerCharacter( name, false, getString( "mmarin1m1" ), francois ) ;
	waitForTalk( "dartagnan", francois, false ) ;
	
	removeMarker( name, marker ) ;
	
	lockPlayerInPlace( ) ;
	
	sayAndWait( francois, getString( "mmarin2d3" ) ) ;
		
	unlockPlayerInPlace( ) ;
	
	removeOverrideSavePos( overrideSaveID ) ;
	
	setBaseChatString( francois, getString( "mmarin2d3" ) ) ;
		
	autoDeleteCharacterOffScreen( francois ) ;
		
	completeMission( name ) ;
	activateMission( "missionmarin3" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionmarin3( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setMissionChatString( name, "stgermainhousecman1", getString( "mmarin2d7" ) ) ;
	setMissionChatString( name, "stgermainhousecman2", getString( "mmarin2d5" ) ) ;

	local marker = addMarkerCharacter( name, false, getString( "mmarin3m1" ), "marinlebourgeoys" ) ;
	waitForTalk( "dartagnan", "marinlebourgeoys", false ) ;
	
	removeMarker( name, marker ) ;

	lockPlayerInPlace( ) ;
	
	sayAndWait( "marinlebourgeoys", getString( "mmarin3d1" ) ) ;
		
	unlockPlayerInPlace( ) ;
	
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Cheese Producer Missions
function createmissioncheese1enemy( missionName, level, x, y )
	local enemy = createTempCharacter( getString( "cheeseenemy" ), level, x, y ) ;
	randomDressEnemy( enemy, 0.5, randomInt( 0, 99999 ) ) ;
	setMeleeWeapon( enemy, "sword_1" ) ;
	setMissionFaceCharacter( missionName, enemy, "parismarketvender1" ) ;
	
	return enemy ;
end

function execute_missioncheese1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local enemy1 = createmissioncheese1enemy( name, "france", 2206, -114 ) ;
	local enemy2 = createmissioncheese1enemy( name, "france", 2246, -161 ) ;
	local enemy3 = createmissioncheese1enemy( name, "france", 2254, -192 ) ;
	local enemy4 = createmissioncheese1enemy( name, "france", 2200, -64 ) ;
	
	setMissionChatString( name, enemy1, getString( "mcheese1d9" ) ) ;
	setMissionChatString( name, enemy2, getString( "mcheese1d10" ) ) ;
	setMissionChatString( name, enemy3, getString( "mcheese1d9" ) ) ;
	setMissionChatString( name, enemy4, getString( "mcheese1d10" ) ) ;
		
	setMissionChatString( name, "meungdman", getString( "mcheese0d11" ) ) ;
	setMissionChatString( name, "parismarketvender1", getString( "mcheese1d11" ) ) ;

	local accused = false ;
	while ( not accused ) do
		local marker = addMarkerCharacter( name, false, getString( "mcheese1m1" ), "parismarketvender1" ) ;
		waitForTalk( "dartagnan", "parismarketvender1", false ) ;
		removeMarker( name, marker ) ;
		
		setMissionFaceCharacter( name, "parismarketvender1", "dartagnan" ) ;
		
		setMissionFreezeGame( name, true ) ;
		setIgnoreFreeze( "parismarketvender1", true ) ;
		
		sayAndWait( "dartagnan", getString( "mcheese1d1" ) ) ;
		sayAndWait( "parismarketvender1", getString( "mcheese1d2" ) ) ;
		
		local bubInd = characterSay( "dartagnan", false, -1, -1, true, "", getString( "mcheese1d3" ), getString( "mcheese1d4" ), getString( "mcheese1d5" ) ) ;
		local option = waitForBubbleOption( bubInd ) ;
		if ( option == 0 or option == 1 ) then
			-- accept
			accused = true ;
			sayAndWait( "parismarketvender1", getString( "mcheese1d6" ) ) ;				
		end
		
		setMissionFreezeGame( name, false ) ;
		setIgnoreFreeze( "parismarketvender1", false ) ;
	end
		
	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missioncheese1" ) ;
	DEBUG_OUTPUT( "playercombat level " .. getHighestPlayerCombatLevel( ) ) ;
	DEBUG_OUTPUT( "saved playercombat level " .. playerCombatLevel ) ;
	local minDifficulty = 4 ;
	local maxDifficulty = 6 ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy1, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy1 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy2, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy2 ) ;
	
	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy3, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy3 ) ;

	attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy4, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy4 ) ;
	
	makeEnemies( "dartagnan", enemy1, enemy2, enemy3, enemy4 ) ;
	
	local marker1 = addMarkerCharacter( name, false, getString( "fight" ), enemy1 ) ;
	local marker2 = addMarkerCharacter( name, false, getString( "fight" ), enemy2 ) ;
	local marker3 = addMarkerCharacter( name, false, getString( "fight" ), enemy3 ) ;
	local marker4 = addMarkerCharacter( name, false, getString( "fight" ), enemy4 ) ;
	
	waitUntilDead( enemy1 ) ;
	waitUntilDead( enemy2 ) ;
	waitUntilDead( enemy3 ) ;
	waitUntilDead( enemy4 ) ;

	removeMarker( name, marker1 ) ;
	removeMarker( name, marker2 ) ;
	removeMarker( name, marker3 ) ;
	removeMarker( name, marker4 ) ;
	
	local marker = addMarkerCharacter( name, false, getString( "mcheese1m1" ), "parismarketvender1" ) ;
	waitForTalk( "dartagnan", "parismarketvender1", false ) ;
	
	removeMarker( name, marker ) ;
	
	setMissionFreezeGame( name, true ) ;
	setIgnoreFreeze( "parismarketvender1", true ) ;
	
	sayAndWait( "parismarketvender1", getString( "mcheese1d7" ) ) ;
	sayAndWait( "parismarketvender1", getString( "mcheese1d8" ) ) ;
	
	setMissionFreezeGame( name, false ) ;
	setIgnoreFreeze( "parismarketvender1", false ) ;
	
	completeMission( name ) ;
	activateMission( "missioncheese2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missioncheese2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local marker = addMarkerCharacter( name, false, getString( "mcheese2m1" ), "meungdman" ) ;
	waitForTalk( "dartagnan", "meungdman", false ) ;
	removeMarker( name, marker ) ;
	
	setMissionFaceCharacter( name, "meungdman", "dartagnan" ) ;
	
	setMissionFreezeGame( name, true ) ;
	setIgnoreFreeze( "meungdman", true ) ;
	
	sayAndWait( "dartagnan", getString( "mcheese2d1" ) ) ;
	sayAndWait( "meungdman", getString( "mcheese2d2" ) ) ;
	sayAndWait( "dartagnan", getString( "mcheese2d3" ) ) ;
	sayAndWait( "meungdman", getString( "mcheese2d4" ) ) ;
	
	setMissionFreezeGame( name, false ) ;
	setIgnoreFreeze( "meungdman", false ) ;
	
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Priest/Graveyard Keeper mission
function execute_missiongraveyard1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setMissionChatString( name, "parisman11", getString( "mgraveyard1d1" ) ) ;

	local marker = addMarkerCharacter( name, false, getString( "mgraveyard1m1" ), "parisgravedigger" ) ;
	waitForTalk( "dartagnan", "parisgravedigger", false ) ;
	removeMarker( name, marker ) ;

	setMissionFaceCharacter( name, "parisgravedigger", "dartagnan" ) ;

	setMissionFreezeGame( name, true ) ;
	setIgnoreFreeze( "parisgravedigger", true ) ;
	
	clearGoals( "parisgravedigger" ) ;
	setStateMessageIdle( "parisgravedigger" ) ;
	gBlockGoalWalkToPoint = true ;
		
	local bubInd = characterSay( "dartagnan", false, -1, -1, true, "", getString( "mgraveyard1d2" ), getString( "mgraveyard1d3" ) ) ;
	local option = waitForBubbleOption( bubInd ) ;
	if ( option == 0 ) then
		-- nice walk
		sayAndWait( "parisgravedigger", getString( "mgraveyard1d4" ) ) ;
	elseif ( option == 1 ) then
		-- what up to?
		sayAndWait( "parisgravedigger", getString( "mgraveyard1d5" ) ) ;		
	end

	sayAndWait( "parisgravedigger", getString( "mgraveyard1d6" ) ) ;		
	sayAndWait( "parisgravedigger", getString( "mgraveyard1d7" ) ) ;		
	sayAndWait( "parisgravedigger", getString( "mgraveyard1d8" ) ) ;
	
	gBlockGoalWalkToPoint = false ;
	
	setMissionFreezeGame( name, false ) ;
	setIgnoreFreeze( "parisgravedigger", false ) ;

	completeMission( name ) ;
	activateMission( "missiongraveyard2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiongraveyard2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setMissionChatString( name, "parisgravedigger", getString( "mgraveyard1d1" ) ) ;

	local meanFellow = false ;
	
	while ( not meanFellow ) do
		local marker = addMarkerCharacter( name, false, getString( "mgraveyard2m1" ), "parisman11" ) ;
		waitForTalk( "dartagnan", "parisman11", false ) ;
		removeMarker( name, marker ) ;
	
		setMissionFaceCharacter( name, "parisman11", "dartagnan" ) ;
	
		setMissionFreezeGame( name, true ) ;
		setIgnoreFreeze( "parisman11", true ) ;
	
		clearGoals( "parisman11" ) ;
		setStateMessageIdle( "parisman11" ) ;
		gBlockGoalWalkToPoint = true ;
		
		sayAndWait( "parisman11", getString( "mgraveyard2d1" ) ) ;		
	
		local bubInd = characterSay( "dartagnan", false, -1, -1, true, "", getString( "mgraveyard2d2" ), getString( "mgraveyard2d3" ) ) ;
		local option = waitForBubbleOption( bubInd ) ;
		if ( option == 0 ) then
			-- nice fellow
			sayAndWait( "parisman11", getString( "mgraveyard2d4" ) ) ;
		elseif ( option == 1 ) then
			-- mean
			meanFellow = true ;
			sayAndWait( "parisman11", getString( "mgraveyard2d5" ) ) ;
		end
		
		gBlockGoalWalkToPoint = false ;
		
		setMissionFreezeGame( name, false ) ;
		setIgnoreFreeze( "parisman11", false ) ;
	end
	
	local x, y = getCharacterPos( "parisman11" ) ;
	createMoney( "", getSideQuestBaseLootValue( ) * 2, "france", x + 10, y + 10, true ) ; -- 50
	
	completeMission( name ) ;
	activateMission( "missiongraveyard3" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiongraveyard3( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local meanFellow = false ;
	
	while ( not meanFellow ) do
		local marker = addMarkerCharacter( name, false, getString( "mgraveyard3m1" ), "parisgravedigger" ) ;
		waitForTalk( "dartagnan", "parisgravedigger", false ) ;
		removeMarker( name, marker ) ;
	
		setMissionFaceCharacter( name, "parisgravedigger", "dartagnan" ) ;
	
		setMissionFreezeGame( name, true ) ;
		setIgnoreFreeze( "parisgravedigger", true ) ;
	
		clearGoals( "parisgravedigger" ) ;
		setStateMessageIdle( "parisgravedigger" ) ;
		gBlockGoalWalkToPoint = true ;
		
		sayAndWait( "parisgravedigger", getString( "mgraveyard3d1" ) ) ;		
	
		local bubInd = characterSay( "dartagnan", false, -1, -1, true, "", getString( "mgraveyard2d2" ), getString( "mgraveyard2d3" ) ) ;
		local option = waitForBubbleOption( bubInd ) ;
		if ( option == 0 ) then
			-- nice fellow
			sayAndWait( "parisgravedigger", getString( "mgraveyard2d4" ) ) ;
		elseif ( option == 1 ) then
			-- mean
			meanFellow = true ;
			sayAndWait( "parisgravedigger", getString( "mgraveyard2d5" ) ) ;
		end
		
		gBlockGoalWalkToPoint = false ;
		
		setMissionFreezeGame( name, false ) ;
		setIgnoreFreeze( "parisgravedigger", false ) ;
	end
	
	local x, y = getCharacterPos( "parisgravedigger" ) ;
	createMoney( "", getSideQuestBaseLootValue( ) * 2, "france", x + 10, y + 10, true ) ; -- 50
	
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Fencing brothers mission
function execute_missionfencers1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missionfencers1" ) ;
	DEBUG_OUTPUT( "playercombat level " .. getHighestPlayerCombatLevel( ) ) ;
	DEBUG_OUTPUT( "saved playercombat level " .. playerCombatLevel ) ;
	local minDifficulty = 10 ;
	local maxDifficulty = 10 ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( "stgermainhouseapaul", attack, defence, attack, attack ) ;
	recalcCharacterStats( "stgermainhouseapaul" ) ;

	local marker = addMarkerCharacter( name, false, getString( "mfencers1m1" ), "stgermainhouseapaul" ) ;

	makeEnemies( "dartagnan", "stgermainhouseapaul" ) ;
	
	waitUntilDead( "stgermainhouseapaul" ) ;
	
	removeMarker( name, marker ) ;

	completeMission( name ) ;
	activateMission( "missionfencers2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionfencers2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local accepted = false ;
	
	while ( not accepted ) do
		local marker = addMarkerCharacter( name, false, getString( "mfencers2m1" ), "stgermainhouseapierre" ) ;
		waitForTalk( "dartagnan", "stgermainhouseapierre", false ) ;
		removeMarker( name, marker ) ;
	
		lockPlayerInPlace( ) ;
		
		sayAndWait( "stgermainhouseapierre", getString( "mfencers2d1" ) ) ;
		
		local bubInd = characterSay( "dartagnan", false, -1, -1, true, "", getString( "mfencers2d2" ), getString( "mfencers2d3" ) ) ;
		local option = waitForBubbleOption( bubInd ) ;
		if ( option == 0 ) then
			-- accept
			accepted = true ;
		else
			-- reject
		end
		
		unlockPlayerInPlace( ) ;
	end	

	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missionfencers1" ) ;
	DEBUG_OUTPUT( "playercombat level " .. getHighestPlayerCombatLevel( ) ) ;
	DEBUG_OUTPUT( "saved playercombat level " .. playerCombatLevel ) ;
	local minDifficulty = 20 ;
	local maxDifficulty = 20 ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( "stgermainhouseapierre", attack, defence, attack, attack ) ;
	recalcCharacterStats( "stgermainhouseapierre" ) ;

	local marker = addMarkerCharacter( name, false, getString( "mfencers2m1" ), "stgermainhouseapierre" ) ;
	
	makeEnemies( "dartagnan", "stgermainhouseapierre" ) ;
	
	waitUntilDead( "stgermainhouseapierre" ) ;
	
	removeMarker( name, marker ) ;
	
	completeMission( name ) ;
	activateMission( "missionfencers3" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionfencers3( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local accepted = false ;
	
	while ( not accepted ) do
		local marker = addMarkerCharacter( name, false, getString( "mfencers2m1" ), "stgermainhouseajacques" ) ;
		waitForTalk( "dartagnan", "stgermainhouseajacques", false ) ;
		removeMarker( name, marker ) ;
	
		lockPlayerInPlace( ) ;
		
		sayAndWait( "stgermainhouseajacques", getString( "mfencers3d1" ) ) ;
		
		local bubInd = characterSay( "dartagnan", false, -1, -1, true, "", getString( "mfencers3d2" ), getString( "mfencers3d3" ) ) ;
		local option = waitForBubbleOption( bubInd ) ;
		if ( option == 0 ) then
			-- accept
			accepted = true ;
		else
			-- reject
		end
		
		unlockPlayerInPlace( ) ;
	end	

	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missionfencers1" ) ;
	DEBUG_OUTPUT( "playercombat level " .. getHighestPlayerCombatLevel( ) ) ;
	DEBUG_OUTPUT( "saved playercombat level " .. playerCombatLevel ) ;
	local minDifficulty = 30 ;
	local maxDifficulty = 30 ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( "stgermainhouseajacques", attack, defence, attack, attack ) ;
	recalcCharacterStats( "stgermainhouseajacques" ) ;

	local marker = addMarkerCharacter( name, false, getString( "mfencers2m1" ), "stgermainhouseajacques" ) ;
	
	makeEnemies( "dartagnan", "stgermainhouseajacques" ) ;
	
	waitUntilDead( "stgermainhouseajacques" ) ;
	
	removeMarker( name, marker ) ;

	completeMission( name ) ;
	activateMission( "missionfencers4" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionfencers4( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setBoolean( "fencerschestlocked", false )

	local chestID = getClickObjectID( "fencerschest" ) ;
	local marker = addMarkerClickObject( name, false, getString( "mfencers4m1" ), chestID ) ;

	gFencersChestOpened = false ;

	while ( not gFencersChestOpened ) do
		coroutine.yield( ) ;
	end
	
	removeMarker( name, marker ) ;

	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Phillipe sends you to deliver message to mistress, father doesn't appreciate
function execute_missionfathermessage1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setInventoryItem( "letter_fathermessage1", 1 ) ;

	setMissionChatString( name, "parishousebman2", getString( "mfathermessage1d10" ) ) ;

	local marker = addMarkerCharacter( name, false, getString( "mfathermessage1m1" ), "parishouseblady1" ) ;

	local gotByFather = false ;
	
	while ( not gotByFather ) do
		while( not ( getCharacterFunctionalLevel( "dartagnan" ) == "parishouseb2" ) ) do
			coroutine.yield( ) ;
		end
		
		lockPlayerInPlace( ) ;
		
		addGoalGetToPointInLevel( "dartagnan", -26, -50, "parishouseb2", false, true ) ;
		waitForNoGoal( "dartagnan" ) ;
		
		sayAndWait( "parishousebman1", getString( "mfathermessage1d1" ) ) ;
	
		local bubInd = characterSay( "dartagnan", false, -1, -1, true, "", getString( "mfathermessage1d2" ), getString( "mfathermessage1d3" ) ) ;
		local option = waitForBubbleOption( bubInd ) ;
		if ( option == 0 ) then
			-- father kicks you out
			sayAndWait( "parishousebman1", getString( "mfathermessage1d4" ) ) ;
			addGoalGetToPointInLevel( "dartagnan", 11, -124, "parishouseb", false, true ) ;
			waitForNoGoal( "dartagnan" ) ;
		elseif ( option == 1 ) then
			-- father lets you by
			gotByFather = true ;
			sayAndWait( "parishousebman1", getString( "mfathermessage1d5" ) ) ;
		end
			
		unlockPlayerInPlace( ) ;
	end
	
	setMissionChatString( name, "parishousebman1", getString( "mfathermessage1d6" ) ) ;
	
	waitForTalk( "dartagnan", "parishouseblady1", false ) ;
	removeMarker( name, marker ) ;

	lockPlayerInPlace( ) ;
	
	setMissionFaceCharacter( name, "parishouseblady1", "dartagnan" ) ;
	sayAndWait( "dartagnan", getString( "mfathermessage1d7" ) ) ;
	playSound( "paper", 1.0 ) ;

	addHeartMaker( "parishouseblady1" ) ;
	sayAndWait( "parishouseblady1", getString( "mfathermessage1d8" ) ) ;
	removeHeartMaker( "parishouseblady1" ) ;

	playSound( "paper", 1.0 ) ;
		
	unlockPlayerInPlace( ) ;
	
	setInventoryItem( "letter_fathermessage1", 0 ) ;
		
	completeMission( name ) ;
	activateMission( "missionfathermessage2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionfathermessage2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setInventoryItem( "letter_fathermessage2", 1 ) ;

	setMissionChatString( name, "parishousebman1", getString( "mfathermessage1d6" ) ) ;
	setMissionChatString( name, "parishouseblady1", getString( "mfathermessage1d9" ) ) ;

	local marker = addMarkerCharacter( name, false, getString( "mfathermessage2m1" ), "parishousebman2" ) ;

	waitForTalk( "dartagnan", "parishousebman2", false ) ;
	removeMarker( name, marker ) ;

	setMissionFaceCharacter( name, "parishousebman2", "dartagnan" ) ;
		
	setMissionFreezeGame( name, true ) ;
	setIgnoreFreeze( "parishousebman2", true ) ;
		
	sayAndWait( "parishousebman2", getString( "mfathermessage2d1" ) ) ;
	sayAndWait( "dartagnan", getString( "mfathermessage2d2" ) ) ;
	playSound( "paper", 1.0 ) ;
	
	sayAndWait( "parishousebman2", getString( "mfathermessage2d3" ) ) ;

	setMissionFreezeGame( name, false ) ;
	setIgnoreFreeze( "parishousebman2", false ) ;

	setInventoryItem( "letter_fathermessage2", 0 ) ;
	
	completeMission( name ) ;
	activateMission( "missionfathermessage3" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionfathermessage3( name )
	DEBUG_OUTPUT( name .. " started" ) ;
	
	setMissionChatString( name, "parishousebman1", getString( "mfathermessage1d6" ) ) ;
	setMissionChatString( name, "parishouseblady1", getString( "mfathermessage1d9" ) ) ;
	setMissionChatString( name, "parishousebman2", getString( "mfathermessage3d1" ) ) ;

	local marker = addMarkerCharacter( name, false, getString( "mfathermessage3m1" ), "parishousebman2" ) ;

	wait( 30 ) ;

	waitForTalk( "dartagnan", "parishousebman2", false ) ;
	removeMarker( name, marker ) ;

	setMissionFaceCharacter( name, "parishousebman2", "dartagnan" ) ;
		
	setMissionFreezeGame( name, true ) ;
	setIgnoreFreeze( "parishousebman2", true ) ;
	
	addHeartMaker( "parishousebman2" ) ;
	sayAndWait( "parishousebman2", getString( "mfathermessage3d2" ) ) ;
	removeHeartMaker( "parishousebman2" ) ;

	playSound( "paper", 1.0 ) ;
	
	setMissionFreezeGame( name, false ) ;
	setIgnoreFreeze( "parishousebman2", false ) ;
	
	completeMission( name ) ;
	activateMission( "missionfathermessage4" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function createmissionfatherenemy( missionName, level, x, y )
	local enemy = createTempCharacter( getString( "mercenary" ), level, x, y ) ;
	randomDressEnemy( enemy, 0.0, randomInt( 0, 99999 ) ) ;
	setMeleeWeapon( enemy, "sword_1" ) ;
	
	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missionfathermessage1" ) ;
	local minDifficulty = -35 ;
	local maxDifficulty = -35 ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy ) ;
	placeCharacterInDoor( enemy, "parishousebstairsup", false ) ;
	makeEnemies( enemy, "dartagnan" ) ;
	
	local marker = addMarkerCharacter( missionName, false, getString( "fight" ), enemy ) ;
		
	return enemy ;
end

function getNumAlive( enemies )
	local numAlive = 0 ;
	for key, value in pairs( enemies ) do
		if ( isCharacterAlive( value ) ) then
			numAlive = numAlive + 1 ;
		end
	end
	
	return numAlive ;
end

function waitUntilAllDead( enemies )
	while ( getNumAlive( enemies ) > 0 ) do
		coroutine.yield( ) ;
	end
end

function execute_missionfathermessage4( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setInventoryItem( "letter_fathermessage3", 1 ) ;

	setMissionChatString( name, "parishousebman2", getString( "mfathermessage1d10" ) ) ;
	setMissionChatFunction( name, "parishousebman1", "chat_nothing" ) ; --  father doesn't say anything while fighting

	local overrideSaveID = createOverrideSavePos( "parishouseb", 58, 97 ) ;
	setOverrideSaveLevel( overrideSaveID, "parishouseb2" ) ;
	
	local marker = addMarkerCharacter( name, false, getString( "mfathermessage1m1" ), "parishouseblady1" ) ;

	while( not ( getCharacterFunctionalLevel( "dartagnan" ) == "parishouseb2" ) ) do
		coroutine.yield( ) ;
	end

	removeMarker( name, marker ) ;

	lockPlayerInPlace( ) ;
		
	addGoalGetToPointInLevel( "dartagnan", -26, -50, "parishouseb2", false, true ) ;
	waitForNoGoal( "dartagnan" ) ;
	
	sayAndWait( "parishousebman1", getString( "mfathermessage4d1" ) ) ;
	sayAndWait( "parishousebman1", getString( "mfathermessage4d2" ) ) ;

	setMissionChatString( name, "parishouseblady1", getString( "mfathermessage4d2_1" ) ) ;

	unlockPlayerInPlace( ) ;
	
	addGoalGetToPointInLevel( "parishousebman1", -177, -137, "parishouseb2", false, true ) ;

	local combatLocalMusicID = addLocalMusicInner( "combat", "parishouseb2", -100000, -100000, 100000, 100000, 15 ) ;

	-- fight with enemies coming up stairs
	local enemies = {} ;
	
	local totalEnemies = 25 ;
	local i = 1 ;
	while ( i <= totalEnemies ) do
		table.insert( enemies, createmissionfatherenemy( name, "parishouseb", 3, -104 ) ) ;
		wait( 1 ) ;

		while ( getNumAlive( enemies ) >= 2 ) do
			coroutine.yield( ) ;
		end
			
		i = i + 1 ;
	end

	waitUntilAllDead( enemies ) ;

	removeLocalMusic( "parishouseb2", combatLocalMusicID ) ;

	lockPlayerInPlace( ) ;

	setStateMessageIdle( "dartagnan" ) ;
	setMissionFaceCharacter( name, "dartagnan", "parishousebman1" ) ;
	setMissionFaceCharacter( name, "parishousebman1", "dartagnan" ) ;
	addGoalGetToPointInLevel( "dartagnan", -54, -53, "parishouseb2", false, true ) ;
	addGoalGetToPointInLevel( "parishousebman1", -14, -53, "parishouseb2", false, true ) ;
	waitForNoGoal( "dartagnan" ) ;
	waitForNoGoal( "parishousebman1" ) ;
	
	sayAndWait( "parishousebman1", getString( "mfathermessage4d3" ) ) ;

	addGoalGetToPointInLevel( "parishousebman1", 2, -113, "parishouseb", false, true ) ;
	waitForNoGoal( "parishousebman1" ) ;
	
	placeCharacterInDoor( "parishousebman2", "parishousebstairsup", false ) ;
	setMissionFaceCharacter( name, "parishousebman2", "dartagnan" ) ;
	addGoalGetToPointInLevel( "parishousebman2", -14, -53, "parishouseb2", false, true ) ;

	setMissionFaceCharacter( name, "dartagnan", "parishousebman2" ) ;
	
	waitForNoGoal( "parishousebman2" ) ;


	sayAndWait( "parishousebman2", getString( "mfathermessage4d4" ) ) ;

	setMissionFaceCharacter( name, "parishousebman2", "parishouseblady1" ) ;
	setMissionFaceCharacter( name, "parishouseblady1", "parishousebman2" ) ;
	addGoalGetToPointInLevel( "parishouseblady1", -177, -19, "parishouseb2", false, true ) ;
	addGoalGetToPointInLevel( "parishousebman2", -137, -19, "parishouseb2", false, true ) ;
	
	waitForNoGoal( "parishouseblady1" ) ;
	waitForNoGoal( "parishousebman2" ) ;

	
	addHeartMaker( "parishousebman2" ) ;
	addHeartMaker( "parishouseblady1" ) ;
	sayAndWait( "parishousebman2", getString( "mfathermessage4d5" ) ) ;
	removeHeartMaker( "parishousebman2" ) ;
	removeHeartMaker( "parishouseblady1" ) ;

	setMissionFaceCharacter( name, "parishousebman2", "dartagnan" ) ;
	sayAndWait( "parishousebman2", getString( "mfathermessage4d6" ) ) ;
	
	unlockPlayerInPlace( ) ;
	
	removeOverrideSavePos( overrideSaveID ) ;

	createMoney( "", getSideQuestBaseLootValue( ) * 6, "parishouseb2", -92, -30, true ) ; -- 300

	setInventoryItem( "letter_fathermessage3", 0 ) ;
		
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Dungeon mission
function missiondungeonLockOut1( )
	--local bubInd = characterThink( "dartagnan", true, -1, 100.0, true, getString( "mdungeon1d1" ) ) ;
	--autoDeleteBubble( bubInd ) ;
	local bubInd = characterThink( "dartagnan", true, -1, -1, true, getString( "mdungeon1d1" ) ) ;
	waitForBubbleClosed( bubInd ) ;
end

function createmissiondungeonenemy( missionName, level, x, y )
	local enemy = createTempCharacter( getString( "criminal" ), level, x, y ) ;
	randomDressEnemy( enemy, 0.5, randomInt( 0, 99999 ) ) ;
	setMeleeWeapon( enemy, "sword_1" ) ;
	setMissionFaceCharacter( missionName, enemy, "dartagnan" ) ;
	
	return enemy ;
end

function dungeonLevelExecute( name, dungeonLevel, stairsToLock, difficulty )
	setMissionChatString( name, "dungeonman1", getString( "mdungeon2d1" ) ) ;
	
	local overrideSaveID = createOverrideSavePos( "france", -6967, 712 ) ;
	setOverrideSaveLevel( overrideSaveID, "stgermaindungeon1" ) ;
	setOverrideSaveLevel( overrideSaveID, "stgermaindungeon2" ) ;
	setOverrideSaveLevel( overrideSaveID, "stgermaindungeon3" ) ;
	setOverrideSaveLevel( overrideSaveID, "stgermaindungeon4" ) ;
	setOverrideSaveLevel( overrideSaveID, "stgermaindungeon5" ) ;
	setOverrideSaveLevel( overrideSaveID, "stgermaindungeon6" ) ;
	setOverrideSaveLevel( overrideSaveID, "stgermaindungeon7" ) ;
	
	local doorLockOutside = addDoorLock( name, "", false, "stgermaindungeonout" ) ;
	
	local doorLockStairs = -1 ;
	if ( stairsToLock ~= "" ) then
		doorLockStairs = addDoorLock( name, "missiondungeonLockOut1", true, stairsToLock ) ;
	end
	
	local marker = addMarkerPosition( name, false, getString( "mdungeon1m1" ), dungeonLevel, -53, 114 ) ;
		
	local enemy1 = createmissiondungeonenemy( name, dungeonLevel, -160, 51 ) ;
	local enemy2 = createmissiondungeonenemy( name, dungeonLevel, -61, 83 ) ;
	local enemy3 = createmissiondungeonenemy( name, dungeonLevel, 64, 79 ) ;
	local enemy4 = createmissiondungeonenemy( name, dungeonLevel, -185, 174 ) ;
	local enemy5 = createmissiondungeonenemy( name, dungeonLevel, -54, 145 ) ;
	local enemy6 = createmissiondungeonenemy( name, dungeonLevel, 73, 222 ) ;
	
	while( not ( getCharacterFunctionalLevel( "dartagnan" ) == dungeonLevel ) ) do
		coroutine.yield( ) ;
	end
	
	removeMarker( name, marker ) ;
	
	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missiondungeon1" ) ;
	local minDifficulty = difficulty ;
	local maxDifficulty = difficulty ;
	
	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	
	setStatsCalculatorStatic( enemy1, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy1 ) ;

	setStatsCalculatorStatic( enemy2, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy2 ) ;

	setStatsCalculatorStatic( enemy3, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy3 ) ;

	setStatsCalculatorStatic( enemy4, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy4 ) ;

	setStatsCalculatorStatic( enemy5, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy5 ) ;

	setStatsCalculatorStatic( enemy6, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy6 ) ;

	makeEnemies( "dartagnan", enemy1, enemy2, enemy3, enemy4, enemy5, enemy6 ) ;
	
	local marker1 = addMarkerCharacter( name, false, getString( "fight" ), enemy1 ) ;
	local marker2 = addMarkerCharacter( name, false, getString( "fight" ), enemy2 ) ;
	local marker3 = addMarkerCharacter( name, false, getString( "fight" ), enemy3 ) ;
	local marker4 = addMarkerCharacter( name, false, getString( "fight" ), enemy4 ) ;
	local marker5 = addMarkerCharacter( name, false, getString( "fight" ), enemy5 ) ;
	local marker6 = addMarkerCharacter( name, false, getString( "fight" ), enemy6 ) ;
	
	waitUntilDead( enemy1 ) ;
	waitUntilDead( enemy2 ) ;
	waitUntilDead( enemy3 ) ;
	waitUntilDead( enemy4 ) ;
	waitUntilDead( enemy5 ) ;
	waitUntilDead( enemy6 ) ;

	removeMarker( name, marker1 ) ;
	removeMarker( name, marker2 ) ;
	removeMarker( name, marker3 ) ;
	removeMarker( name, marker4 ) ;
	removeMarker( name, marker5 ) ;
	removeMarker( name, marker6 ) ;

	removeOverrideSavePos( overrideSaveID ) ;

	if ( stairsToLock ~= "" ) then
		removeDoorLock( doorLockStairs ) ;
	end
	
	removeDoorLock( doorLockOutside ) ;
end

function execute_missiondungeon1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	dungeonLevelExecute( name, "stgermaindungeon1", "stgermaindungeon1stairsd", 2 ) ;
	
	completeMission( name ) ;
	activateMission( "missiondungeon2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiondungeon2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	dungeonLevelExecute( name, "stgermaindungeon2", "stgermaindungeon2stairsd", 4 ) ;

	completeMission( name ) ;
	activateMission( "missiondungeon3" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiondungeon3( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	dungeonLevelExecute( name, "stgermaindungeon3", "stgermaindungeon3stairsd", 6 ) ;

	completeMission( name ) ;
	activateMission( "missiondungeon4" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiondungeon4( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	dungeonLevelExecute( name, "stgermaindungeon4", "stgermaindungeon4stairsd", 8 ) ;

	completeMission( name ) ;
	activateMission( "missiondungeon5" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiondungeon5( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	dungeonLevelExecute( name, "stgermaindungeon5", "stgermaindungeon5stairsd", 10 ) ;

	completeMission( name ) ;
	activateMission( "missiondungeon6" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiondungeon6( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	dungeonLevelExecute( name, "stgermaindungeon6", "stgermaindungeon6stairsd", 12 ) ;

	completeMission( name ) ;
	activateMission( "missiondungeon7" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiondungeon7( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	dungeonLevelExecute( name, "stgermaindungeon7", "", 14 ) ;

	completeMission( name ) ;
	activateMission( "missiondungeon8" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiondungeon8( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local doorLockOutside = addDoorLock( name, "", false, "stgermaindungeonout" ) ;
	
	setMissionChatString( name, "dungeonman1", getString( "mdungeon2d1" ) ) ;
	
	setBoolean( "dungeonchestlocked", false )

	local chestID = getClickObjectID( "dungeonchest" ) ;
	local marker = addMarkerClickObject( name, false, getString( "mdungeon1m1" ), chestID ) ;

	gDungeonChestOpened = false ;

	while ( not gDungeonChestOpened ) do
		coroutine.yield( ) ;
	end
	
	removeMarker( name, marker ) ;

	removeDoorLock( doorLockOutside ) ;

	completeMission( name ) ;
	activateMission( "missiondungeon9" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missiondungeon9( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local doorLockOutside = addDoorLock( name, "", false, "stgermaindungeonout" ) ;

	setMissionChatString( name, "dungeonman1", getString( "mdungeon2d1" ) ) ;

	local marker = addMarkerCharacter( name, false, getString( "mdungeon2m1" ), "dungeonman1" ) ;

	waitForTalk( "dartagnan", "dungeonman1", false ) ;
	
	removeMarker( name, marker ) ;
	
	lockPlayerInPlace( ) ;
	
	setMissionFaceCharacter( name, "dungeonman1", "dartagnan" ) ;
	setMissionFaceCharacter( name, "dartagnan", "dungeonman1" ) ;

	sayAndWait( "dungeonman1", getString( "mdungeon2d1" ) ) ;
	sayAndWait( "dartagnan", getString( "mdungeon2d2" ) ) ;
	sayAndWait( "dungeonman1", getString( "mdungeon2d3" ) ) ;
	sayAndWait( "dungeonman1", getString( "mdungeon2d4" ) ) ;
	
	if ( numOfItemType( "familywine" ) >= 1 ) then
		local bubInd = characterSay( "dartagnan", false, -1, -1, true, "", getString( "mdungeon2d5" ), getString( "mdungeon2d6" ) ) ;
		local option = waitForBubbleOption( bubInd ) ;
		if ( option == 0 ) then
			-- give bottle back
			sayAndWait( "dungeonman1", getString( "mdungeon2d7" ) ) ;
			setInventoryItem( "familywine", 0 ) ;
			createMoney( "", 2, "crevecoeurhouseb", -71, 7, true ) ;
		else
			-- don't give bottle
			sayAndWait( "dungeonman1", getString( "mdungeon2d8" ) ) ;
		end
	else
		sayAndWait( "dartagnan", getString( "mdungeon2d6" ) ) ;
		sayAndWait( "dungeonman1", getString( "mdungeon2d8" ) ) ;
	end
	
	addGoalGetToPointInLevel( "dungeonman1", 5111, -8680, "france", false, true ) ;
	
	while ( isCharacterOnScreen( "dungeonman1" ) ) do
		coroutine.yield( ) ;
	end
	
	clearGoals( "dungeonman1" ) ;
			
	unlockPlayerInPlace( ) ;

	removeDoorLock( doorLockOutside ) ;
	
	--setInventoryItem( "familywine", 0 ) ;
	
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Tarbes inventor wants gun part from London. Go get it, but it explodes when you give it to him
function execute_missioninventor1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setMissionChatString( name, "tarbescman", getString( "minventor0d13" ) ) ;

	local marker = addMarkerCharacter( name, false, getString( "minventor1m1" ), "londonhousefman" ) ;
	waitForTalk( "dartagnan", "londonhousefman", false ) ;
	
	removeMarker( name, marker ) ;
	
	lockPlayerInPlace( ) ;
	
	setMissionFaceCharacter( name, "londonhousefman", "dartagnan" ) ;
	setMissionFaceCharacter( name, "dartagnan", "londonhousefman" ) ;

	sayAndWait( "dartagnan", getString( "minventor1d1" ) ) ;
	sayAndWait( "londonhousefman", getString( "minventor1d2" ) ) ;
		
	playSound( "equipgun", 1.0 ) ;
		
	unlockPlayerInPlace( ) ;
	
	setInventoryItem( "inventor_last_part", 1 ) ;
		
	completeMission( name ) ;
	activateMission( "missioninventor2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missioninventor2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setInventoryItem( "inventor_last_part", 1 ) ;
	
	local marker = addMarkerCharacter( name, false, getString( "minventor2m1" ), "tarbescman" ) ;
	waitForTalk( "dartagnan", "tarbescman", false ) ;
	
	removeMarker( name, marker ) ;
	
	lockPlayerInPlace( ) ;
	
	gTarbescmanDontMumble = true ;
	
	sayAndWait( "tarbescman", getString( "minventor0d13" ) ) ;
	sayAndWait( "dartagnan", getString( "minventor2d1" ) ) ;
	playSound( "equipgun", 1.0 ) ;
	
	sayAndWait( "tarbescman", getString( "minventor2d2" ) ) ;
	playSound( "blacksmith", 0.4 ) ;
	wait( 0.3 ) ;
	playSound( "blacksmith", 0.4 ) ;
	wait( 1 ) ;
	sayAndWait( "tarbescman", getString( "minventor2d3" ) ) ;
	playSound( "blacksmith", 0.4 ) ;
	wait( 0.3 ) ;
	playSound( "blacksmith", 0.4 ) ;
	wait( 1 ) ;
	sayAndWait( "tarbescman", getString( "minventor2d4" ) ) ;
	wait( 2 ) ;
	sayAndWait( "tarbescman", getString( "minventor2d5" ) ) ;
	wait( 1 ) ;

	-- create explosion
	local x, y = getCharacterPos( "tarbescman" ) ;
	createInventorExplosionParticles( x, y - 30 ) ;
	dress_tarbescmanB( "tarbescman" ) ;
	playPositionSound( "explosion", 1.0, "tarbeshousec2", x, y ) ;
		
	wait( 5 ) ;

	sayAndWait( "tarbescman", getString( "minventor2d6" ) ) ;
	sayAndWait( "tarbescman", getString( "minventor2d7" ) ) ;
	sayAndWait( "tarbescman", getString( "minventor2d7_5" ) ) ;

	gTarbescmanDontMumble = false ;

	unlockPlayerInPlace( ) ;
	
	setInventoryItem( "inventor_last_part", 0 ) ;
	
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Fight Rochefort after end of game
function execute_missionrochefort1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local overrideSaveID = createOverrideSavePos( "france", 2, -1023 ) ;
	setOverrideSaveLevel( overrideSaveID, "cardinalhouse" ) ;
	
	local marker = addMarkerCharacter( name, false, getString( "mrochefort1m1" ), "rochefort" ) ;
	
	local closeDist = 500.0 ;
	while ( distanceBetweenCharacters( "dartagnan", "rochefort" ) > closeDist ) do
		coroutine.yield( ) ;
	end
	
	setStatsCalculatorStatic( "rochefort", 58, 58, 58, 58 ) ; -- 50, 50, 50, 50
	recalcCharacterStats( "rochefort" ) ;
		
	makeEnemies( "dartagnan", "rochefort" ) ;
	
	waitUntilDead( "rochefort" ) ;

	makeNotEnemies( "dartagnan", "rochefort" ) ;

	setStateMessageIdle( "dartagnan" ) ;
	lockPlayerInPlace( ) ;

	wait( 2 ) ;
	
	reviveCharacter( "rochefort" ) ;
	giveHealth( "rochefort", 1000 ) ;
	
	wait( 2 ) ;

	setMissionFaceCharacter( name, "rochefort", "dartagnan" ) ;
	setMissionFaceCharacter( name, "dartagnan", "rochefort" ) ;

	sayAndWait( "rochefort", getString( "mrochefort1d1" ) ) ;
		
	unlockPlayerInPlace( ) ;
	
	removeMarker( name, marker ) ;
	
	removeOverrideSavePos( overrideSaveID ) ;
	
	addGoalGetToPointInLevel( "rochefort", getRochefortBPosX( ), getRochefortBPosY( ), getRochefortBLevel( ), false, true ) ;
					
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Guardsman says that he is one day away from retirement, then gets shot. Avenge him
function createmissionretirement1( missionName, level, x, y )
	local enemy = createTempCharacter( getString( "outlaw" ), level, x, y ) ;
	randomDressEnemy( enemy, 0.5, randomInt( 0, 99999 ) ) ;
	setMeleeWeapon( enemy, "sword_1" ) ;
	setMissionFaceCharacter( missionName, enemy, "dartagnan" ) ;
	
	return enemy ;
end

function execute_missionretirement1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setMissionChatString( name, "parisguardsman8", getString( "mretirement1d1" ) ) ;
	
	local enemy1 = createmissionretirement1( name, "france", -3575, 2384 ) ;
	randomDressEnemy( enemy1, 0.0, 469 ) ;
	
	local enemy2 = createmissionretirement1( name, "france", -3658, 2420 ) ;
	local enemy3 = createmissionretirement1( name, "france", -3735, 2423 ) ;
	local enemy4 = createmissionretirement1( name, "france", -3677, 2529 ) ;
	local enemy5 = createmissionretirement1( name, "france", -3746, 2582 ) ;
		
	local marker1 = addMarkerCharacter( name, false, getString( "mretirement1m1" ), enemy1 ) ;
	waitForTalk( "dartagnan", enemy1, false ) ;
	
	removeMarker( name, marker1 ) ;


	setMissionFreezeGame( name, true ) ;
	setIgnoreFreeze( enemy1, true ) ;
	
	sayAndWait( "dartagnan", getString( "mretirement1d2" ) ) ;
	
	setMissionFreezeGame( name, false ) ;
	setIgnoreFreeze( enemy1, false ) ;

	
	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missionretirement1" ) ;
	local minDifficulty = 6 ;
	local maxDifficulty = 9 ;
	
	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy1, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy1 ) ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy2, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy2 ) ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy3, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy3 ) ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy4, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy4 ) ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy5, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy5 ) ;

	local marker1 = addMarkerCharacter( name, false, getString( "fight" ), enemy1 ) ;
	local marker2 = addMarkerCharacter( name, false, getString( "fight" ), enemy2 ) ;
	local marker3 = addMarkerCharacter( name, false, getString( "fight" ), enemy3 ) ;
	local marker4 = addMarkerCharacter( name, false, getString( "fight" ), enemy4 ) ;
	local marker5 = addMarkerCharacter( name, false, getString( "fight" ), enemy5 ) ;

	makeEnemies( "dartagnan", enemy1, enemy2, enemy3, enemy4, enemy5 ) ;

	waitUntilDead( enemy1 ) ;
	waitUntilDead( enemy2 ) ;
	waitUntilDead( enemy3 ) ;
	waitUntilDead( enemy4 ) ;
	waitUntilDead( enemy5 ) ;

	removeMarker( name, marker1 ) ;
	removeMarker( name, marker2 ) ;
	removeMarker( name, marker3 ) ;
	removeMarker( name, marker4 ) ;
	removeMarker( name, marker5 ) ;

	completeMission( name ) ;
	activateMission( "missionretirement2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionretirement2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local marker1 = addMarkerCharacter( name, false, getString( "mretirement2m1" ), "parisguardsman8" ) ;
	waitForTalk( "dartagnan", "parisguardsman8", false ) ;
	
	removeMarker( name, marker1 ) ;


	setMissionFreezeGame( name, true ) ;
	
	sayAndWait( "parisguardsman8", getString( "mretirement1d1" ) ) ;
	sayAndWait( "dartagnan", getString( "mretirement2d1" ) ) ;
	sayAndWait( "parisguardsman8", getString( "mretirement2d2" ) ) ;
	
	setMissionFreezeGame( name, false ) ;
	
	
	local x, y = getCharacterPos( "parisguardsman8" ) ;
	--local rewardValue = getRewardLootValueForceJackpot( 5 ) ;
	--rewardValue = rewardValue / 2 ; -- money a bit too much so divide by 2?
	createMoney( "", getSideQuestBaseLootValue( ) * 8, "france", x - 20, y - 20, true ) ;
	
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- single puppy - find puppy... but find wrong one, have to find another puppy.
function execute_missionsinglepuppy1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setMissionChatString( name, "stcloudhouseclady1", getString( "msinglepuppy0d5" ) ) ;

	local marker = addMarkerPosition( name, false, getString( "msinglepuppy1m1" ), "france", -4350, 2606 ) ;
		
	createItem( "", "puppy_1", "france", -4311, 2750, false ) ;
	
	while ( numOfItemType( "puppy_1" ) < 1 ) do
		coroutine.yield( ) ;
	end
	
	removeMarker( name, marker ) ;
	
	completeMission( name ) ;
	activateMission( "missionsinglepuppy2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionsinglepuppy2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local marker = addMarkerCharacter( name, false, getString( "msinglepuppy2m1" ), "stcloudhouseclady1" ) ;
	waitForTalk( "dartagnan", "stcloudhouseclady1", false ) ;
	
	removeMarker( name, marker ) ;
	
	lockPlayerInPlace( ) ;
	setMissionFaceCharacter( name, "stcloudhouseclady1", "dartagnan" ) ;
	
	sayAndWait( "stcloudhouseclady1", getString( "msinglepuppy2d1" ) ) ;
	setToggleVisElsVisible( "puppy_1", true ) ;

	sayAndWait( "stcloudhouseclady1", getString( "msinglepuppy2d2" ) ) ;

	unlockPlayerInPlace( ) ;
	
	setInventoryItem( "puppy_1", 0 ) ;
		
	completeMission( name ) ;
	activateMission( "missionsinglepuppy3" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionsinglepuppy3( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setMissionChatString( name, "stcloudhouseclady1", getString( "msinglepuppy0d5" ) ) ;

	local marker = addMarkerPosition( name, false, getString( "msinglepuppy1m1" ), "france", -4350, 2606 ) ;
		
	createItem( "", "puppy_2", "france", -4922, 2101, false ) ;
	
	while ( numOfItemType( "puppy_2" ) < 1 ) do
		coroutine.yield( ) ;
	end
	
	removeMarker( name, marker ) ;
	
	completeMission( name ) ;
	activateMission( "missionsinglepuppy4" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionsinglepuppy4( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local marker = addMarkerCharacter( name, false, getString( "msinglepuppy2m1" ), "stcloudhouseclady1" ) ;
	waitForTalk( "dartagnan", "stcloudhouseclady1", false ) ;
	
	removeMarker( name, marker ) ;
	
	lockPlayerInPlace( ) ;
	setMissionFaceCharacter( name, "stcloudhouseclady1", "dartagnan" ) ;
	
	setToggleVisElsVisible( "puppy_2", true ) ;
	sayAndWait( "stcloudhouseclady1", getString( "msinglepuppy4d1" ) ) ;

	unlockPlayerInPlace( ) ;
	
	setInventoryItem( "puppy_2", 0 ) ;

	--local rewardValue = getRewardLootValueForceJackpot( 1 ) ;
	--rewardValue = rewardValue / 2 ; -- money a bit too much so divide by 2?
	createMoney( "", getSideQuestBaseLootValue( ) * 7, "stcloudhousec", 191, -6, true ) ;
	
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- multi puppy - find 6 different puppies (one hidden inside a chest)
function execute_missionmultipuppy1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	gPuppyChestLocked = false ;
	
	-- make sure chest is closed and clickable
	local chestID = getClickObjectID( "puppychest" ) ;
	setClickObjectTileState( chestID, 1 ) ;
	setClickObjectHighlightable( chestID, true ) ;
	
	setInventoryItem( "puppy_3", 0 ) ;
	setInventoryItem( "puppy_4", 0 ) ;
	setInventoryItem( "puppy_5", 0 ) ;
	setInventoryItem( "puppy_6", 0 ) ;
	setInventoryItem( "puppy_7", 0 ) ;
	setInventoryItem( "puppy_8", 0 ) ;

	setMissionChatString( name, "calaishousedman", getString( "mmultipuppy0d4" ) ) ;

	local marker = addMarkerPosition( name, false, getString( "mmultipuppy1m1" ), "france", 5372, -18772 ) ;
		
	createItem( "", "puppy_3", "france", 5093, -18392, false ) ;
	createItem( "", "puppy_4", "france", 4591, -19288, false ) ;
	createItem( "", "puppy_5", "france", 6632, -18818, false ) ;
	createItem( "", "puppy_6", "france", 4192, -17008, false ) ;
	createItem( "", "puppy_7", "calaishousee2", 39, -47, false ) ;
	
	while ( ( numOfItemType( "puppy_3" ) < 1 ) or 
			( numOfItemType( "puppy_4" ) < 1 ) or 
			( numOfItemType( "puppy_5" ) < 1 ) or 
			( numOfItemType( "puppy_6" ) < 1 ) or 
			( numOfItemType( "puppy_7" ) < 1 ) or 
			( numOfItemType( "puppy_8" ) < 1 ) ) do
		coroutine.yield( ) ;
	end
	
	removeMarker( name, marker ) ;
	
	gPuppyChestLocked = true ;
		
	completeMission( name ) ;
	activateMission( "missionmultipuppy2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionmultipuppy2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	resetCharacterAI( "calaishousedman" ) ;
	setStateMessageIdle( "calaishousedman" ) ;
	
	local marker = addMarkerCharacter( name, false, getString( "mmultipuppy2m1" ), "calaishousedman" ) ;
	waitForTalk( "dartagnan", "calaishousedman", false ) ;
	
	removeMarker( name, marker ) ;
	
	lockPlayerInPlace( ) ;
	setMissionFaceCharacter( name, "calaishousedman", "dartagnan" ) ;
	
	setToggleVisElsVisible( "puppy_3", true ) ;
	setToggleVisElsVisible( "puppy_4", true ) ;
	sayAndWait( "calaishousedman", getString( "mmultipuppy2d1" ) ) ;

	unlockPlayerInPlace( ) ;
	
	setInventoryItem( "puppy_3", 0 ) ;
	setInventoryItem( "puppy_4", 0 ) ;
	setInventoryItem( "puppy_5", 0 ) ;
	setInventoryItem( "puppy_6", 0 ) ;
	setInventoryItem( "puppy_7", 0 ) ;
	setInventoryItem( "puppy_8", 0 ) ;

	local posX, posY = getCharacterPos( "calaishousedman" ) ;
	--local rewardValue = getRewardLootValueForceJackpot( 1 ) ;
	--rewardValue = rewardValue / 2 ; -- money a bit too much so divide by 2?
	createMoney( "", getSideQuestBaseLootValue( ) * 8, "calaishoused", posX + 10, posY + 10, true ) ;
		
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- baguette delivery to London
function execute_missionbaguettedelivery1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setInventoryItem( "baguette_fresh", 0 ) ;
	setInventoryItem( "baguette_stale", 0 ) ;

	setMissionChatString( name, "parismarketvender9", getString( "mbaguettedelivery1d2" ) ) ;
	setMissionFaceCharacter( name, "parismarketvender9", "dartagnan" ) ;
	
	local deliverySuccess = false ;
	local firstTimeThrough = true ;
	
	while ( not deliverySuccess ) do
			
		local marker = addMarkerCharacter( name, false, getString( "mbaguettedelivery1m1" ), "parismarketvender9" ) ;
		waitForTalk( "dartagnan", "parismarketvender9", false ) ;
		removeMarker( name, marker ) ;
		
		setMissionFreezeGame( name, true ) ;
		
		if ( not firstTimeThrough ) then
			sayAndWait( "parismarketvender9", getString( "mbaguettedelivery1d4" ) ) ;
		end
		
		sayAndWait( "parismarketvender9", getString( "mbaguettedelivery1d1" ) ) ;
			
		setMissionFreezeGame( name, false ) ;
		
		setInventoryItem( "baguette_stale", 0 ) ;
		setInventoryItem( "baguette_fresh", 1 ) ;
		
		-- ride to London
			
		-- label for timer
		gBaguetteRaceTimerLabel = addLabel( ) ;
		setLabelFont( gBaguetteRaceTimerLabel, "title_font" ) ;
		setLabelColour( gBaguetteRaceTimerLabel, gLightTextR, gLightTextG, gLightTextB, gLightTextA ) ;
		setLabelShadow( gBaguetteRaceTimerLabel, true, 2, 2 ) ;
		setLabelShadowColour( gBaguetteRaceTimerLabel, gLightTextShadowR, gLightTextShadowG, gLightTextShadowB, gLightTextShadowA ) ;
		setWindowAlign( gBaguetteRaceTimerLabel, "right", "top" ) ;
		setWindowPos( gBaguetteRaceTimerLabel, 20, 20 ) ;
		
		gBaguetteRaceTimer = 165 ;
		
		activateScriptMessage( "runBaguetteRaceTimer" ) ;
		coroutine.yield( ) ;
		
		local marker = addMarkerCharacter( name, false, getString( "mbaguettedelivery1m2" ), "londonhousecman" ) ;
		
		local waitingTalkNum = setWaitingForTalk( "dartagnan", "londonhousecman", false ) ;
		local talkSuccess = false ;
	
		while ( gBaguetteRaceTimerOn ) do
			coroutine.yield( ) ;
			if ( hasWaitingTalkOccured( waitingTalkNum ) ) then
				setDoneWaitingTalk( waitingTalkNum ) ;
				talkSuccess = true ;
				deliverySuccess = true ;
				gBaguetteRaceTimerOn = false ;
			end
		end
		
		if ( not talkSuccess ) then
			setDoneWaitingTalk( waitingTalkNum ) ;
			firstTimeThrough = false ;
			
			setInventoryItem( "baguette_fresh", 0 ) ;
			setInventoryItem( "baguette_stale", 1 ) ;
		end

		removeMarker( name, marker ) ;
	
		gBaguetteRaceTimerOn = false ;
		gBaguetteRaceTimerLabel = safeRemoveWindow( gBaguetteRaceTimerLabel ) ;
	end
	
	lockPlayerInPlace( ) ;
	setMissionFaceCharacter( name, "londonhousecman", "dartagnan" ) ;
	
	sayAndWait( "londonhousecman", getString( "mbaguettedelivery1d5" ) ) ;
	
	setMissionFaceNone( name, "londonhousecman" ) ;
	unlockPlayerInPlace( ) ;
	
	setInventoryItem( "baguette_stale", 0 ) ;
	setInventoryItem( "baguette_fresh", 0 ) ;
	

	completeMission( name ) ;
	activateMission( "missionbaguettedelivery2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function runBaguetteRaceTimer( )
	gBaguetteRaceTimerOn = true ;
	local lastDisplay = 0 ;

	while ( gBaguetteRaceTimerOn ) do
		if ( not isFrozenOrLocked( ) ) then
			gBaguetteRaceTimer = gBaguetteRaceTimer - getDeltaT( ) ;
		end
		
		local displayTimer = math.ceil( gBaguetteRaceTimer ) ;
		if ( displayTimer < 0 ) then
			displayTimer = 0 ;
		end
		
		if ( not ( displayTimer == lastDisplay ) ) then
			-- timer clicked
			local volume = 0.4 ;
			if ( displayTimer <= 10 ) then
				volume = 0.8 ;
			end
			playSound( "timer", volume ) ;
		end
		
		if ( displayTimer == 0 ) then
			setLabelText( gBaguetteRaceTimerLabel, "0" ) ; -- lua puts -0 otherwise
		else 
			setLabelText( gBaguetteRaceTimerLabel, displayTimer ) ;
		end
		
		if ( gBaguetteRaceTimer < -0.5 ) then
			gBaguetteRaceTimerOn = false ;
		end
		
		lastDisplay = displayTimer ;
		coroutine.yield( ) ;
	end
end

function execute_missionbaguettedelivery2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local marker = addMarkerCharacter( name, false, getString( "mbaguettedelivery2m1" ), "parismarketvender9" ) ;
	waitForTalk( "dartagnan", "parismarketvender9", false ) ;
	removeMarker( name, marker ) ;
	
	setMissionFreezeGame( name, true ) ;
	
	sayAndWait( "parismarketvender9", getString( "mbaguettedelivery2d1" ) ) ;
		
	setMissionFreezeGame( name, false ) ;	

	createMoney( "", getSideQuestBaseLootValue( ) * 6, "france", 2093, -36, true ) ; -- 500
	
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Blow up weapons store in London
function execute_missionespionage1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setMissionChatString( name, "frenchspy1", getString( "mespionage2d1" ) ) ;

	setToggleVisElsVisible( "espbarrel", true ) ;
	
	local barrelID = getClickObjectID( "explodebarrel1" ) ;
	setClickObjectHighlightable( barrelID, true ) ;
	
	local marker = addMarkerClickObject( name, false, getString( "mespionage1m1" ), barrelID ) ;
	
	gEspionageBarrelIgnited = false ;
	
	while ( not gEspionageBarrelIgnited ) do
		coroutine.yield( ) ;
	end
	
	removeMarker( name, marker ) ;
	
	-- time and then explode
	wait( 2 ) ;
	
	-- player could get killed here, might not have saved in a while (because not in combat)
	saveIfNotInDangerOrDead( ) ;
	
	local killDamageDist = 150.0 ; 
	local damageDist = 250.0 ;
	if ( distanceToPoint( "dartagnan", "england", -4205, -5038 ) < killDamageDist ) then
		forceTakeDamage( "dartagnan", 200 ) ;
	end
	if ( distanceToPoint( "dartagnan", "england", -4205, -5038 ) < damageDist ) then
		takeDamage( "dartagnan", 100 ) ;
	end
	
	local explosionX = -4225 ;
	local explosionY = -5053 ;
	createBuilding1ExplosionParticles( explosionX, explosionY ) ;
	playPositionSound( "explosion", 1.0, "england", explosionX, explosionY ) ;
	setToggleVisElsVisible( "espbarrel", false ) ;
	setToggleVisElsVisible( "esp1", false ) ;

	wait( 3 ) ;

	completeMission( name ) ;
	activateMission( "missionespionage2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionespionage2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local marker = addMarkerCharacter( name, false, getString( "mespionage2m1" ), "frenchspy1" ) ;
	waitForTalk( "dartagnan", "frenchspy1", false ) ;
	removeMarker( name, marker ) ;
	
	setMissionFaceCharacter( name, "dartagnan", "frenchspy1" ) ;
	
	setMissionFreezeGame( name, true ) ;
	setIgnoreFreeze( "frenchspy1", true ) ;
		
	sayAndWait( "dartagnan", getString( "mespionage2d2" ) ) ;
	sayAndWait( "frenchspy1", getString( "mespionage2d3" ) ) ;
	
	local x, y = getCharacterPos( "frenchspy1" ) ;
	--local rewardValue = getRewardLootValueForceJackpot( 1 ) ;
	--rewardValue = rewardValue / 2 ; -- money a bit too much so divide by 2?
	createMoney( "", getSideQuestBaseLootValue( ) * 6, "england", x, y + 20, true ) ;
	
	addGoalGetToPointInLevel( "frenchspy1", 4828, -18953, "france", false, true ) ;
	
	while ( isCharacterOnScreen( "frenchspy1" ) ) do
		coroutine.yield( ) ;
	end
	
	clearGoals( "frenchspy1" ) ;
	setStateMessageIdle( "frenchspy1" ) ;
		
	setMissionFreezeGame( name, false ) ;
	setIgnoreFreeze( "frenchspy1", false ) ;
	
	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Lazy Guardsman gets you to do bounty hunt for him
function createmissionguardsmanbounty1( missionName, level, x, y )
	local enemy = createTempCharacter( getString( "outlaw" ), level, x, y ) ;
	randomDressEnemy( enemy, 0.5, randomInt( 0, 99999 ) ) ;
	setMeleeWeapon( enemy, "sword_1" ) ;
	setMissionFaceCharacter( missionName, enemy, "dartagnan" ) ;
	
	return enemy ;
end

function execute_missionguardsmanbounty1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	setMissionChatString( name, "parisguardsman14", getString( "mguardsmanbounty2d1" ) ) ;
	
	local enemy1 = createmissionretirement1( name, "france", -282, -3930 ) ;
	local enemy2 = createmissionretirement1( name, "france", -344, -3986 ) ;
	local enemy3 = createmissionretirement1( name, "france", -239, -4032 ) ;
	local enemy4 = createmissionretirement1( name, "france", -410, -3977 ) ;
	local enemy5 = createmissionretirement1( name, "france", -401, -4059 ) ;
		
	local marker1 = addMarkerCharacter( name, false, getString( "mguardsmanbounty1m1" ), enemy1 ) ;
	waitForTalk( "dartagnan", enemy1, false ) ;
	
	removeMarker( name, marker1 ) ;

	setMissionFreezeGame( name, true ) ;
	setIgnoreFreeze( enemy1, true ) ;
	
	sayAndWait( "dartagnan", getString( "mguardsmanbounty1d1" ) ) ;
	sayAndWait( enemy1, getString( "mguardsmanbounty1d2" ) ) ;
	
	setMissionFreezeGame( name, false ) ;
	setIgnoreFreeze( enemy1, false ) ;

	
	local playerCombatLevel = getSavedHighestPlayerCombatLevel( "missionguardsmanbounty1" ) ;
	local minDifficulty = 6 ;
	local maxDifficulty = 9 ;
	
	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy1, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy1 ) ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy2, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy2 ) ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy3, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy3 ) ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy4, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy4 ) ;

	local attack, defence, dressLevel = getRandomEncStatsForCombatLevel( minDifficulty, maxDifficulty, playerCombatLevel ) ;
	setStatsCalculatorStatic( enemy5, attack, defence, attack, attack ) ;
	recalcCharacterStats( enemy5 ) ;

	local marker1 = addMarkerCharacter( name, false, getString( "fight" ), enemy1 ) ;
	local marker2 = addMarkerCharacter( name, false, getString( "fight" ), enemy2 ) ;
	local marker3 = addMarkerCharacter( name, false, getString( "fight" ), enemy3 ) ;
	local marker4 = addMarkerCharacter( name, false, getString( "fight" ), enemy4 ) ;
	local marker5 = addMarkerCharacter( name, false, getString( "fight" ), enemy5 ) ;

	makeEnemies( "dartagnan", enemy1, enemy2, enemy3, enemy4, enemy5 ) ;

	waitUntilDead( enemy1 ) ;
	waitUntilDead( enemy2 ) ;
	waitUntilDead( enemy3 ) ;
	waitUntilDead( enemy4 ) ;
	waitUntilDead( enemy5 ) ;

	removeMarker( name, marker1 ) ;
	removeMarker( name, marker2 ) ;
	removeMarker( name, marker3 ) ;
	removeMarker( name, marker4 ) ;
	removeMarker( name, marker5 ) ;

	completeMission( name ) ;
	activateMission( "missionguardsmanbounty2" ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

function execute_missionguardsmanbounty2( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	local marker1 = addMarkerCharacter( name, false, getString( "mguardsmanbounty2m1" ), "parisguardsman14" ) ;
	waitForTalk( "dartagnan", "parisguardsman14", false ) ;
	
	removeMarker( name, marker1 ) ;


	setMissionFreezeGame( name, true ) ;
	
	sayAndWait( "parisguardsman14", getString( "mguardsmanbounty2d1" ) ) ;
	sayAndWait( "dartagnan", getString( "mguardsmanbounty2d2" ) ) ;
	sayAndWait( "parisguardsman14", getString( "mguardsmanbounty2d3" ) ) ;
	
	setMissionFreezeGame( name, false ) ;
	
	
	local x, y = getCharacterPos( "parisguardsman14" ) ;
	--local rewardValue = getRewardLootValueForceJackpot( 1 ) ;
	--rewardValue = rewardValue / 2 ; -- money a bit too much so divide by 2?
	createMoney( "", getSideQuestBaseLootValue( ) * 7, "france", x - 20, y - 20, true ) ;

	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end

-- Aquire flint lock for rich guy who wants one
function chat_parishouseamanflintlock( name, chatWith )
	if ( hasEquippedItemType( "pistol_flintlock_1" ) ) then
		-- player has bought item but has it equipped
		sayAndWait( name, getString( "maquireflintlock1d1_5" ) ) ;
	else
		sayAndWait( name, getString( "maquireflintlock1d1" ) ) ;
	end
end

function execute_missionaquireflintlock1( name )
	DEBUG_OUTPUT( name .. " started" ) ;

	--setMissionChatString( name, "parishouseaman", getString( "maquireflintlock1d1" ) ) ;
	setMissionChatFunction( name, "parishouseaman", "chat_parishouseamanflintlock" ) ;
	
	local talkedToGuy = false ;
	while ( not talkedToGuy ) do
		local marker1 = addMarkerCharacter( name, false, getString( "maquireflintlock1m1" ), "marinlebourgeoys" ) ;
	
		while ( not hasUnequippedItemType( "pistol_flintlock_1" ) ) do
			coroutine.yield( ) ;
		end
		
		removeMarker( name, marker1 ) ;
	
		local marker1 = addMarkerCharacter( name, false, getString( "maquireflintlock1m2" ), "parishouseaman" ) ;
	
		local waitingTalkNum = setWaitingForTalk( "dartagnan", "parishouseaman", false ) ;
		while ( not hasWaitingTalkOccured( waitingTalkNum ) and hasUnequippedItemType( "pistol_flintlock_1" ) ) do
			coroutine.yield( ) ;
		end
		setDoneWaitingTalk( waitingTalkNum ) ;

		removeMarker( name, marker1 ) ;
		
		if ( hasUnequippedItemType( "pistol_flintlock_1" ) ) then
			-- talked to parishouseaman
			talkedToGuy = true ;
		end
	end
	
	lockPlayerInPlace( ) ;
	
	sayAndWait( "parishouseaman", getString( "maquireflintlock1d2" ) ) ;
	sayAndWait( "parishouseaman", getString( "maquireflintlock1d3" ) ) ;
	sayAndWait( "parishouseaman", getString( "maquireflintlock1d4" ) ) ;
	
	removeUnequippedItemType( "pistol_flintlock_1" ) ;
	
	unlockPlayerInPlace( ) ;

	completeMission( name ) ;
	DEBUG_OUTPUT( name .. " done" ) ;
end