-----------------------------------------------------------  LEVEL START ------------------------------------------------------------------------
function EVENTINITIALISE_Level()
	Game.Pause();
	-- load the building and business file
	C_RunScript("scripts\\level1\\map.lua");
	C_RunScript("scripts\\level1\\initialpref.lua");
end;

function EVENT_Level()
	-- create an initial prompt
	Interface.CreatePrompt("Level 1", "The city owns the following blocks.... Illinois Avenue ...", 1);
	Camera.SetMode(DISTRICTCAM, KENTUCKY_DISTRICT);
	C_TriggerEvent("BlockCam", REAL_SECOND*5, ILLINOIS_AVENUE);
	C_TriggerEvent("LevelAboutToFail", ((GAME_YEAR*5)-GAME_DAY));
	C_TriggerEvent("LevelFailed", GAME_YEAR*5);
	C_TriggerEvent("LevelTest", GAME_HOUR);

	C_TriggerEvent("IntroduceBusiness", GAME_DAY*2, 1);
end;

-----------------------------------------------------------  Catch game events  ------------------------------------------------------------------------
-- register the system events we wish to catch
function CATCHEVENT_InterfacePromptDismiss(a)
	if a == 1 then
		Interface.CreatePrompt("Level 1", "... North Carolina Avenue ...", 2);
		C_TriggerEvent("OrbitCam", 0, NORTH_CAROLINA);
	elseif a == 2 then
		Interface.CreatePrompt("Level 1", "... Park Place ...", 3);
		Camera.SetMode(BLOCKCAM, PARK_PLACE);
	elseif a == 3 then
		Interface.CreatePrompt("Level 1", "... and Ventnor Avenue.", 4);
		Camera.SetMode(ORBITCAM, VENTNOR_AVENUE);
	elseif a == 4 then
		Interface.CreatePrompt("Level 1", "Two blocks are available for you to develop on .... New York Avenue ...", 5);
		Camera.SetMode(BLOCKCAM, NEW_YORK_AVENUE);
	elseif a == 5 then
		Interface.CreatePrompt("Level 1", "... and Marvin Gardens. You must use your inheritance to develop these blocks and turn a tidy profit. You will be deemed successful when your net worth reaches $2,001. Oh, and by the way, you only have until 1935 to achieve this!", 6);
		Camera.SetMode(ORBITCAM, MARVIN_GARDENS);
	elseif a == 6 then
		Interface.CreatePrompt("Level 1", "You only have access to a few business types. Check the Business Browser to see which ones are available. Good Luck!", 7);
		Camera.SetMode(BLOCKCAM, MARVIN_GARDENS);
	elseif a == 7 then
		Game.Unpause();
		CATCHEVENT_InterfacePromptDismiss = nil;
 	end;
end;
	
-----------------------------------------------------------   MY EVENTS ------------------------------------------------------------------------
function EVENT_BlockCam(a)
	Camera.SetMode(BLOCKCAM, a);
end;

function EVENT_OrbitCam(a)
	Camera.SetMode(ORBITCAM, a);
end;

function EVENT_DistrictCam(a)
	Camera.SetMode(DISTRICTCAM, a);
end;

targetvalue = 2001;

function EVENT_LevelAboutToFail()
	if Player.GetMoney() >= (targetvalue*0.8) then
		Interface.CreatePrompt("Level 1 Update", "You're not too far off your target. You have one day left to increase your total cash to $2,001.");
	elseif Player.GetMoney() < (targetvalue*0.4) then
		Interface.CreatePrompt("Level 1 Update", "You have a long way to go. There's only one day left and you are way off your target of $2,001.");
	end;
end;

function EVENT_LevelFailed()
	-- called after 5 years of playing the game
	-- TODO :: Check whether the player has any businesses, and advise them to sell them off.....
	if Player.GetMoney() >= (targetvalue*0.8) then
		Interface.CreatePrompt("Level 1 Failed", "Although you are making money, it's taking too long and you have run out of time. Try again, but this time try to create a leaner, meaner business machine!");
	else
		Interface.CreatePrompt("Level 1 Failed", "You are quite a long way off your targets, and time has expired. You really must make better business decisions when you try again.");
	end;
end;

function EVENT_LevelTest()
	-- called every 5 seconds
	-- TODO :: need to check bankruptcy against GetWorth, instaed of GetMoney.
	if Player.GetMoney() >= targetvalue then
		Interface.CreatePrompt("Level 1 Completed", "Well done! You have won!!! You should move on to the next level now. You should find it more of a challenge than this one.");
	elseif Player.GetMoney() <= 0 then
		Interface.CreatePrompt("Level 1 Failed", "Oh dear, oh dear. What happened here? You're bankrupt! You are going to have to be more careful with your money next time. Still, you can always try again - it's only Monopoly money after all. Thank goodness!");
	end;	
	return REAL_SECOND*5
end;

function EVENT_IntroduceBusiness(a)
	if a == 1 then
		InitialValue.BusinessAvailable(FURNITURE_STORE);
		Interface.CreatePrompt("New Business Available", "You are now able to create a Furniture Store! Check the Business Browser for information.");
	elseif a == 2 then
		InitialValue.BusinessAvailable(RESTAURANT);
		Interface.CreatePrompt("New Business Available", "You are now able to create a Restaurant! Check the Business Browser for information.");
	elseif a == 3 then
		InitialValue.BusinessAvailable(THEATRE);
		Interface.CreatePrompt("New Business Available", "You are now able to create a Theatre! Check the Business Browser for information.");
	end;

	C_TriggerEvent("IntroduceBusiness", GAME_DAY*2, a+1);
end;