function assignCustomBallIDs()
--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM  ASSIGNMENTS BELOW HERE
--------------------------------------------------------------------------------------------------------------




--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM ASSIGNMENTS ABOVE HERE
--------------------------------------------------------------------------------------------------------------
end

--------------------------------------------------------------------------------------------------------------

function BallUpdate(idx)
	local as = gSportsRNA
	local state = as:GetTable("wvState")
	local ball = as:GetTable("wvBall", idx)
	
	local wipe3d = as:GetTable("wvWipe", idx)
	local stadium = as:GetTable("wvStadium", idx)

	db.ball[idx].model = as:GetInt(ball, "ballModel") 
	db.ball[idx].envLighting = as:GetInt(state, "wvAttribEnvLighting")
	db.ball[idx].stadLightID = as:GetInt(state, "wvAttribStadLightID")
	db.ball[idx].stadiumID = as:GetInt(state, "wvAttribStadID")
	
	assignCustomBallIDs()
	
	db.wipe3d[idx].leagueID = as:GetInt(wipe3d, "leagueID")
	db.wipe3d[idx].leagueID = getTournamentGraphicsB(db.wipe3d[idx].leagueID)
	db.stadium[idx].homeKitTeamID = as:GetInt(stadium, "homeKitTeamID" )
	local weather = as:GetInt(state, "wvAttribStadWeather" )
	
	db.ball[idx].model = getBallID(db.stadium[idx].homeKitTeamID,db.ball[idx].model,db.wipe3d[idx].leagueID,idx,weather)
	
end

function BallAssetBind(ball)
	local gr = gRenderables
   	local lod = 0

	gr:AddCallback(ball, lod, "BallUpdate(?)")
	gr:AddAsset(ball, lod, "shader", "data/fifarna/shader.big")
	gr:AddAsset(ball, lod, "ballmesh", "data/sceneassets/ball/ball_${db.ball[?].model}.rx3")
	gr:AddAsset(ball, lod, "balltex", "data/sceneassets/ball/ball_${db.ball[?].model}_textures.rx3")
	gr:AddAsset(ball, lod, "charcmn", "data/sceneassets/charactercmn/charactercmn_${db.ball[?].envLighting}.rx3")	
	gr:CreateMaterialFromAttribulator(ball, lod, "ballmesh", "ball", "${AttribMaterial('ball')}" )
	gr:SetTexture(ball, lod, "ballmesh", "textures", "diffuseTexture", "balltex", "ball_cm")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "normalMap", "balltex", "ball_nm")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "envDiffuseTexture", "charcmn", "envd_")
	gr:SetTexture(ball, lod, "ballmesh", "textures", "envSpecTexture", "charcmn", "envs_")
	gr:SetTextureFromRuntime(ball, lod, "ballmesh", "textures", "coverageMap", "covmap_${db.ball[?].stadiumID}_${db.ball[?].stadLightID}")
	return ball
end


teamBalls = {}
tournamentBalls = {}

function getBallID(team,ball,tourn,idx,weatherID)

if (globalBallID ~= nil) then
return globalBallID
end

if ((idx == 0) and (arenaModeBall ~= nil)) then
return arenaModeBall
end

if ((weatherID == 2) and (tournamentBallsSnow[tourn] ~= nil)) then
return tournamentBallsSnow[tourn]
end

if (isWinter and (tournamentBallsWinter[tourn] ~= nil)) then
return tournamentBallsWinter[tourn]
end

if (tournamentBalls[tourn] ~= nil) then
return tournamentBalls[tourn]
end

if ((weatherID == 2) and (teamBallsSnow[team] ~= nil)) then
return teamBallsSnow[team]
end

if (isWinter and (teamBallsWinter[team] ~= nil)) then
return teamBallsWinter[team]
end

if (teamBalls[team] ~= nil) then
return teamBalls[team]
end

return ball
end




function assignTeamBall(team,ad)
teamBalls[team] = ad
end

function assignTournamentBall(tourn,ad)
tournamentBalls[tourn] = ad
end

globalBallID = nil

function useGlobalBall(id)
globalBallID = id
end


arenaModeBall = nil

function setArenaModeBall(id)
arenaModeBall = id
end


teamBallsSnow = {}
tournamentBallsSnow = {}

function assignTeamBallSnow(team,ad)
teamBallsSnow[team] = ad
end

function assignTournamentBallSnow(tourn,ad)
tournamentBallsSnow[tourn] = ad
end


frTourn = -1
gloTourn = nil

-- function useTournamentGraphicsInFriendly(id)
-- frTourn = id
-- end

-- function useGlobalTournamentGraphics(id)
-- gloTourn = id
-- end

function getTournamentGraphicsB(id)

if (gloTourn ~= nil) then
return gloTourn
end

if (id == -1) then
return frTourn
end

return id
end


isWinter = false

teamBallsWinter = {}
tournamentBallsWinter = {}

function assignTeamBallWinter(team,ad)
teamBallsWinter[team] = ad
end

function assignTournamentBallWinter(tourn,ad)
tournamentBallsWinter[tourn] = ad
end

function useWinterBalls()
isWinter = true
end


--assignCustomBallIDs()

--Revolution Mod 13 1.2
--Edited by scouser09