' (c) ANAWIKI GAMES 2006-08
' design: Roman Budzowski
' 
 
Strict


?Win32
Import "roalp.o"
?


?Win32
Import axe.jasper
Import redi.maxmod
?MacOs
Include "src/MaxModMac.bmx"
Include "src/jasperMac.bmx"
?

Global notifyPlayer = True, timePlayed = MilliSecs(), maxLevels = 0

SeedRnd MilliSecs()
AppTitle$ = "Runes of Avalon 2"

Include "src/tsconfig.bmx"

Include "src/timerdemo.bmx"
Include "src/common.bmx"
Include "src/runeManager.bmx"
Include "src/blocksManager.bmx"
Include "src/boardManager.bmx"
'Include "src/levelManager-file.bmx"
'Include "src/levelSequenceManager-file.bmx"
Include "src/levelManager.bmx"
Include "src/levelSequenceManager.bmx"
Include "src/pointsManager.bmx"
Include "src/slidesManager.bmx"
Include "src/captionsManager.bmx"
Include "src/soundManager.bmx"
Include "src/sparksEngine2.bmx"
Include "src/cometEngine.bmx"
Include "src/graphicsInit.bmx"
Include "src/options.bmx"
Include "src/magicSphereEmiter.bmx"
Include "src/initTypes.bmx"
Include "src/loadingScreen.bmx"
Include "src/puzzleManager.bmx"
Include "src/hiscores.bmx"
Include "src/titleScreen.bmx"
Include "src/runiqueLoop.bmx"
Include "src/galleryManager.bmx"
Include "src/profileManager.bmx"
Include "src/acl_profile.bmx"
Include "src/volcanoEmiter.bmx"
Include "src/bonusManager.bmx"
Include "src/mapManager.bmx"
Include "src/ringGame.bmx"
Include "src/tutorial.bmx"
Include "src/timeManager.bmx"
Include "src/bossManager.bmx"
Include "src/story.bmx"
Include "src/globalSnd.bmx"
Include "src/bbTSC.bmx"
Include "src/acl/acl.bmx"
Include "src/viewport.bmx"
Include "src/texturedPoly.bmx"

If(Not CheckLPFiles())
	Notify "Files corrupted"
	End
EndIf

GetDataFolders()

?MacOS
Include "src/timerek.bmx"
?
profile = TProfileManager.Create(myDocsFolder+"/profiles")
hiscore = THiscores.Create(myDocsFolder+"/data/hiscores.dat")

'GetOSVersion()
Global demoTimer:TDemoTimer = New TDemoTimer, demoToDemo = False

OnEnd saveOnEnd
profile.UpdateList()

options.Load()
SetGraphicsMode(options.screenMode)
InitMaxModStream()
PollSystem()
HideMouse()

loading.setup()
loading.fadeInBg()
loading.loadEverything()
mouse.loadCursor("gfx/gui/kursor.png",  14, 6)
loading.PortalScreens()
deltaTime = TDeltaTime.Create(60.0)

If(profile.profiles.count()) LoadProfile()

Global readFromProfile
Global saveToProfile
Global menuQuit
Local showMap = False

'#Region Repeat
Repeat
	demoTimer.checkDemoExpire()
	titleScreen.Prepare()
	titleScreen.show()
	
	Select(titleScreen.action)
		Case(3)
			Local ms=MilliSecs()
			ClearProfile(True)
			LoadProfile()
			readFromProfile = False
			saveToProfile = True
			showStory(1, True)
			tutorial.show() 
		Case(1) 
			LoadProfile()
			readFromProfile = True
			saveToProfile = True
	End Select
		
	Local showMap = False
	If(sequencer.seqNo > sequencer.Last)
		showStory(2)
		saveToProfile = False
	EndIf

	
	While Not quit And gameState And sequencer.levelExists()
		sequencer.setupLevel()
		 		 		
		'gra wlasciwa
		
		If(gameState = 1 Or gameState = -3) 
			If sequencer.seqNo = 9 Then tutorial.show2() 
			Select(sequencer.levelType) 
				Case(2) menuQuit = puzzle.show(readFromProfile)
				Case(3) menuQuit = ringGame.Play(readFromProfile)
				Default menuQuit = goRunique(readFromProfile); level.stopAndFreeMusic()
			End Select
			If board.gameOver Then menuQuit = True
			If(menuQuit)
				saveToProfile = False
				Exit
			EndIf
			gameState=2
			SaveProfile()
		EndIf
		
		'mapa
		If(gameState=2)
			If(sequencer.seqNo>=sequencer.Last)
				titleScreen.forceHiscores = True
				showStory(2)
				saveToProfile = False
				Exit
			EndIf
			menuQuit = map.show(sequencer.seqNo)
			If(menuQuit)
				saveOptions()
				saveToProfile = False
				Exit
			EndIf
			gameState = 1
		EndIf
		
		sequencer.nextLevel()
		readFromProfile = False	
	Wend

Forever
'#EndRegion

Function showDemoOver()
End Function

Function killDemo()
End Function

End
