function tournament_runFlow()
	cfunction("debugPrintB", "tournament_runFlow", tournament_curState)		
	cfunction("debugPrintB", "TournamentID", flow_gameModeId)		
	if tournament_curState == 1 then		
		
		if flow_tutorialToShow > 0 and tournamentData[flow_gameModeId]["tutorial"] == flow_tutorialToShow then
			cfunction("addAction", "changeGameMode", gameTypesIds["TUTORIAL"])
			return 
		end
			
		tournament_curTrackInTournament = 1
		numOpp = tournamentData[flow_gameModeId]["numOpponents"]		
		cfunction("setDataOptions", "numberOfOpponents", numOpp)
		
		trackId = tournamentData[flow_gameModeId]["tracks"][tournament_curTrackInTournament]["id"]
		doFileId = tournamentData[flow_gameModeId]["tracks"][tournament_curTrackInTournament]["DOFileId"]
		wpFileId = tournamentData[flow_gameModeId]["tracks"][tournament_curTrackInTournament]["WeaponPickupFileId"]
		smepFileId = tournamentData[flow_gameModeId]["tracks"][tournament_curTrackInTournament]["SMEPickupFileId"]		
		cfunction("setDataOptions", "trackId", trackId)
		cfunction("setDataOptions", "destructiblesId", doFileId)
		cfunction("setDataOptions", "weaponPickupId", wpFileId)
		cfunction("setDataOptions", "smePickupId", smepFileId)
		
		cfunction("addAction", "startTrack", 0)		
		tournament_curState =2
	elseif tournament_curState == 2 then
		tournament_curState = 1
		cfunction("addAction", "stopTrack", 0)				
		flow_flowStateInMenu = 1
	elseif tournament_curState == 3 then
		cfunction("addAction", "stopTrack", 0)
		tournament_curTrackInTournament = tournament_curTrackInTournament + 1
		if tournament_curTrackInTournament > tournamentData[flow_gameModeId]["numTracks"] then
			cfunction("debugPrintS", "Tournament '"..tournamentData[flow_gameModeId]["name"].."' is done!")
			flow_flowStateInMenu = 1
			tournament_curState = 1
			tournament_resetFlow()
		else
			trackId = tournamentData[flow_gameModeId]["tracks"][tournament_curTrackInTournament]["id"]
			doFileId = tournamentData[flow_gameModeId]["tracks"][tournament_curTrackInTournament]["DOFileId"]
			wpFileId = tournamentData[flow_gameModeId]["tracks"][tournament_curTrackInTournament]["WeaponPickupFileId"]
			smepFileId = tournamentData[flow_gameModeId]["tracks"][tournament_curTrackInTournament]["SMEPickupFileId"]		
			cfunction("setDataOptions", "trackId", trackId)
			cfunction("setDataOptions", "destructiblesId", doFileId)
			cfunction("setDataOptions", "weaponPickupId", wpFileId)
			cfunction("setDataOptions", "smePickupId", smepFileId)
		
			cfunction("addAction", "startTrack", 0)
			tournament_curState = 2
		end	
	elseif tournament_curState == 4 then
		cfunction("addAction", "stopTrack", 0)					
		tournament_resetFlow()
		trackId = tournamentData[flow_gameModeId]["tracks"][tournament_curTrackInTournament]["id"]
		cfunction("setDataOptions", "trackId", trackId)
		cfunction("addAction", "startTrack", 0)				
		tournament_curState = 2
	elseif tournament_curState == 5 then -- in this state, the tournament was completed succesfully
		tournament_curState = 1
		cfunction("addAction", "stopTrack", 0)				
		flow_flowStateInMenu = 1
		if tournament_curTrackInTournament == tournamentData[flow_gameModeId]["numTracks"] and flow_gameModeId == numberOfTournaments and tournament_currentPoints[1] >= tournamentData[flow_gameModeId]["pointsNeeded"] then
			cfunction("addAction", "startMovie", 0)
		end
	else
		cfunction("debugPrintF", "Wrong tournament_curState: ", tournament_curState)
	end
end

function tournament_finishTrackWithPosition(iV, iP)
--	cfunction("debugPrintB", "Flow finish track for", iV)		
	--cfunction("debugPrintB", "Position", iP)		
	newPoints = tournamentDataPoints[iP]
	--cfunction("debugPrintB", "So points won is ", newPoints)
	tournament_currentPoints[iV] = tournament_currentPoints[iV]+newPoints
	--cfunction("debugPrintB", "So total points is ", tournament_currentPoints[iV])
end

function tournament_resetFlow()	
	tournament_curTrackInTournament = 1
	tournament_curState = 1
	tournament_currentPoints = {}
	for indx = 1, 16 do 
		tournament_currentPoints[indx] = 0
	end
end
