function assignCustomAdboardIDs()
--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM ASSIGNMENTS BELOW HERE
--------------------------------------------------------------------------------------------------------------
assignSubstitute(1,1)
assignSubstitute(2,2)
assignSubstitute(3,3)
assignSubstitute(4,4)
assignSubstitute(5,5)
assignSubstitute(7,7)
assignSubstitute(8,8)
assignSubstitute(9,9)
assignSubstitute(10,10)
assignSubstitute(11,11)
assignSubstitute(12,12)
assignSubstitute(13,13)
assignSubstitute(14,14)
assignSubstitute(15,15)
assignSubstitute(17,17)
assignSubstitute(18,18)
assignSubstitute(19,19)
assignSubstitute(21,21)
assignSubstitute(22,22)
assignSubstitute(23,23)
assignSubstitute(25,25)
assignSubstitute(28,28)
assignSubstitute(32,32)
assignSubstitute(34,34)
assignSubstitute(36,36)
assignSubstitute(38,38)
assignSubstitute(39,39)
assignSubstitute(44,44)
assignSubstitute(45,45)
assignSubstitute(46,46)
assignSubstitute(47,47)
assignSubstitute(48,48)
assignSubstitute(50,50)
assignSubstitute(52,52)
assignSubstitute(54,54)
assignSubstitute(55,55)
assignSubstitute(58,58)
assignSubstitute(59,59)
assignSubstitute(65,65)
assignSubstitute(66,66)
assignSubstitute(69,69)
assignSubstitute(70,70)
assignSubstitute(72,72)
assignSubstitute(73,73)
assignSubstitute(74,74)
assignSubstitute(78,78)
assignSubstitute(88,88)
assignSubstitute(89,89)
assignSubstitute(91,91)
assignSubstitute(94,94)
assignSubstitute(95,95)
assignSubstitute(97,97)
assignSubstitute(106,106)
assignSubstitute(109,109)
assignSubstitute(110,110)
assignSubstitute(144,144)
assignSubstitute(165,165)
assignSubstitute(169,169)
assignSubstitute(171,171)
assignSubstitute(175,175)
assignSubstitute(181,181)
assignSubstitute(189,189)
assignSubstitute(191,191)
assignSubstitute(192,192)
assignSubstitute(200,200)
assignSubstitute(217,217)
assignSubstitute(219,219)
assignSubstitute(226,226)
assignSubstitute(229,229)
assignSubstitute(231,231)
assignSubstitute(232,232)
assignSubstitute(234,234)
assignSubstitute(236,236)
assignSubstitute(237,237)
assignSubstitute(240,240)
assignSubstitute(241,241)
assignSubstitute(242,242)
assignSubstitute(243,243)
assignSubstitute(244,244)
assignSubstitute(245,245)
assignSubstitute(246,246)
assignSubstitute(247,247)
assignSubstitute(254,254)
assignSubstitute(294,294)
assignSubstitute(312,312)
assignSubstitute(315,315)
assignSubstitute(325,325)
assignSubstitute(378,378)
assignSubstitute(379,379)
assignSubstitute(448,448)
assignSubstitute(449,449)
assignSubstitute(450,450)
assignSubstitute(452,452)
assignSubstitute(453,453)
assignSubstitute(457,457)
assignSubstitute(461,461)
assignSubstitute(462,462)
assignSubstitute(479,479)
assignSubstitute(480,480)
assignSubstitute(481,481)
assignSubstitute(485,485)
assignSubstitute(573,573)
assignSubstitute(614,614)
assignSubstitute(673,673)
assignSubstitute(674,674)
assignSubstitute(896,896)
assignSubstitute(974,974)
assignSubstitute(1318,1318)
assignSubstitute(1322,1322)
assignSubstitute(1325,1325)
assignSubstitute(1327,1327)
assignSubstitute(1330,1330)
assignSubstitute(1331,1331)
assignSubstitute(1334,1334)
assignSubstitute(1335,1335)
assignSubstitute(1337,1337)
assignSubstitute(1338,1338)
assignSubstitute(1343,1343)
assignSubstitute(1352,1352)
assignSubstitute(1353,1353)
assignSubstitute(1354,1354)
assignSubstitute(1355,1355)
assignSubstitute(1356,1356)
assignSubstitute(1357,1357)
assignSubstitute(1359,1359)
assignSubstitute(1361,1361)
assignSubstitute(1362,1362)
assignSubstitute(1363,1363)
assignSubstitute(1364,1364)
assignSubstitute(1365,1365)
assignSubstitute(1369,1369)
assignSubstitute(1370,1370)
assignSubstitute(1375,1375)
assignSubstitute(1377,1377)
assignSubstitute(1386,1386)
assignSubstitute(1387,1387)
assignSubstitute(1395,1395)
assignSubstitute(1415,1415)
assignSubstitute(1792,1792)
assignSubstitute(1793,1793)
assignSubstitute(1795,1795)
assignSubstitute(1796,1796)
assignSubstitute(1799,1799)
assignSubstitute(1806,1806)
assignSubstitute(1807,1807)
assignSubstitute(1808,1808)
assignSubstitute(1809,1809)
assignSubstitute(1819,1819)
assignSubstitute(1823,1823)
assignSubstitute(1824,1824)
assignSubstitute(1837,1837)
assignSubstitute(1838,1838)
assignSubstitute(1842,1842)
assignSubstitute(1843,1843)
assignSubstitute(1853,1853)
assignSubstitute(1860,1860)
assignSubstitute(1886,1886)
assignSubstitute(1896,1896)
assignSubstitute(1906,1906)
assignSubstitute(1908,1908)
assignSubstitute(1913,1913)
assignSubstitute(1917,1917)
assignSubstitute(1919,1919)
assignSubstitute(1926,1926)
assignSubstitute(1932,1932)
assignSubstitute(1938,1938)
assignSubstitute(1939,1939)
assignSubstitute(1952,1952)
assignSubstitute(1960,1960)
assignSubstitute(1961,1961)
assignSubstitute(10029,10029)
assignSubstitute(100409,100409)
assignSubstitute(100765,100765)
assignSubstitute(100766,100766)
assignSubstitute(100767,100767)
assignSubstitute(100769,100769)
assignSubstitute(105035,105035)
assignSubstitute(110081,110081)
assignSubstitute(110227,110227)
assignSubstitute(110364,110364)
assignSubstitute(110374,110374)
assignSubstitute(110456,110456)
assignSubstitute(110556,110556)
assignSubstitute(110636,110636)
assignSubstitute(110832,110832)
assignSubstitute(111099,111099)
assignSubstitute(111108,111108)
assignSubstitute(111109,111109)
assignSubstitute(111112,111112)
assignSubstitute(111130,111130)
assignSubstitute(111271,111271)
assignSubstitute(111451,111451)
assignSubstitute(111459,111459)
assignSubstitute(111465,111465)
assignSubstitute(111466,111466)
assignSubstitute(111473,111473)
assignSubstitute(111487,111487)
--------------------------------------------------------------------------------------------------------------
--PLACE CUSTOM ASSIGNMENTS ABOVE HERE
--------------------------------------------------------------------------------------------------------------
end

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

function StadiumUpdate(idx)
	local as = gSportsRNA
	local state = as:GetTable("wvState")
	local stadium = as:GetTable("wvStadium", idx)

    db.stadium[idx].lightType = as:GetInt(stadium, "stadLightType")
	db.stadium[idx].stadiumID = as:GetInt(stadium, "stadID")
	db.stadium[idx].prefix = as:GetString(stadium, "stadNamePrefix")
	db.stadium[idx].pitchColor = as:GetInt(stadium, "stadLightType")
	db.stadium[idx].mowPattern = as:GetInt(stadium, "pitchMowPattern")
	db.stadium[idx].wearPattern = as:GetInt(stadium, "pitchWearPattern")
	db.stadium[idx].skyCategoryId = as:GetInt(state, "wvAttribSkyCategory")
	db.stadium[idx].skyAssetId = as:GetInt(state, "wvAttribSkyID")
	
	db.stadium[idx].adboardID = as:GetInt(stadium, "adboardID" )
	db.stadium[idx].adboardGroup = 0 --as:GetInt(stadium, "adboardGroup" )
	
	db.stadium[idx].homeKitTeamID = as:GetInt(stadium, "homeKitTeamID" )
	db.stadium[idx].homeKitTypeID = as:GetInt(stadium, "homeKitTypeID" )
	db.stadium[idx].awayKitTeamID = as:GetInt(stadium, "awayKitTeamID" )
	db.stadium[idx].awayKitTypeID = as:GetInt(stadium, "awayKitTypeID" )
	
	db.stadium[idx].isHomeFCZ = as:GetInt(stadium, "isHomeCreationZone")
	db.stadium[idx].isAwayFCZ = as:GetInt(stadium, "isAwayCreationZone")
	
	db.stadium[idx].homeTeamAssetId = as:GetInt(stadium, "homeTeamAssetId")
	db.stadium[idx].hasCzCrestImage = as:GetInt(stadium, "hasCzCrestImage")
	
	db.stadium[idx].homePrimaryColour = as:GetInt(stadium, "homePrimaryColour")
	db.stadium[idx].homeSecondaryColour = as:GetInt(stadium, "homeSecondaryColour")
	db.stadium[idx].awayPrimaryColour = as:GetInt(stadium, "awayPrimaryColour")
	db.stadium[idx].awaySecondaryColour = as:GetInt(stadium, "awaySecondaryColour")
	
	db.stadium[idx].homeBannerId = db.stadium[idx].homeKitTeamID
	db.stadium[idx].awayBannerId = db.stadium[idx].awayKitTeamID
	
	db.stadium[idx].homeBannerPrimaryColour = 0xffff0000
	db.stadium[idx].homeBannerSecondaryColour = 0xff00ff00
	db.stadium[idx].awayBannerPrimaryColour = 0xffff0000
	db.stadium[idx].awayBannerSecondaryColour = 0xff00ff00
	
	if ( db.stadium[idx].isHomeFCZ == 1 ) then
		db.stadium[idx].homeBannerId = 7500
		db.stadium[idx].homeBannerPrimaryColour = db.stadium[idx].homePrimaryColour
		db.stadium[idx].homeBannerSecondaryColour = db.stadium[idx].homeSecondaryColour
	end
	
	if ( db.stadium[idx].isAwayFCZ == 1 ) then
		db.stadium[idx].awayBannerId = 7500
		db.stadium[idx].awayBannerPrimaryColour = db.stadium[idx].awayPrimaryColour
		db.stadium[idx].awayBannerSecondaryColour = db.stadium[idx].awaySecondaryColour
	end
	
	-- some teams require to swap crowd and banners location
	local swapHomeAwayCrowd = as:GetInt(stadium, "swapHomeAwayCrowd")
	if ( swapHomeAwayCrowd == 1 ) then
		db.stadium[idx].homeBannerId, db.stadium[idx].awayBannerId = db.stadium[idx].awayBannerId, db.stadium[idx].homeBannerId
		db.stadium[idx].homeBannerPrimaryColour, db.stadium[idx].awayBannerPrimaryColour = db.stadium[idx].awayBannerPrimaryColour, db.stadium[idx].homeBannerPrimaryColour
		db.stadium[idx].homeBannerSecondaryColour, db.stadium[idx].awayBannerSecondaryColour = db.stadium[idx].awayBannerSecondaryColour, db.stadium[idx].homeBannerSecondaryColour
	end
	
	
	local wipe3d = as:GetTable("wvWipe", idx)
	
	db.wipe3d[idx].leagueID = as:GetInt(wipe3d, "leagueID")
	db.wipe3d[idx].leagueID = getTournamentGraphicsS(db.wipe3d[idx].leagueID)
	
	--initAdboardArray()
	if (idx == 0) then
	assignCustomAdboardIDs()
	end
	
	db.stadium[idx].adboardID = getAdboardID(db.stadium[idx].homeKitTeamID,db.stadium[idx].adboardID,db.wipe3d[idx].leagueID,idx,db.stadium[idx].stadiumID)
	
	db.stadium[idx].stadTexID = getTournamentStadTex(db.stadium[idx].stadiumID,db.stadium[idx].homeKitTeamID,db.wipe3d[idx].leagueID,0)
	
	db.stadium[idx].mowPattern = getMowPattern(db.stadium[idx].homeKitTeamID,db.wipe3d[idx].leagueID,db.stadium[idx].mowPattern)
	
	db.stadium[idx].wearPattern = getWearPattern(db.stadium[idx].homeKitTeamID,db.stadium[idx].wearPattern)
	
end

function GetHomeKitAssetSrc(idx)
	if ( db.stadium[idx].isHomeFCZ == 1 ) then
		if ( db.stadium[idx].hasCzCrestImage > 0 ) then
			return "data/ugc/cz_crest/${db.stadium[?].homeTeamAssetId}.png;data/ugc/cz_crest/1.png"
		else
			return "data/sceneassets/crest/crest_${db.stadium[?].homeTeamAssetId}.rx3"
		end
	else
		return "data/ui/imgassets/crest/l${db.stadium[?].homeKitTeamID}.dds"
	end
end

function GetCrestTexName(idx)
	if ( db.stadium[idx].hasCzCrestImage > 0 ) then
		return "png"
	else
		return ""
	end
end

function StadiumAssetBind(stadium)
	local gr = gRenderables
	local lod = 0
	local priority = 0
	local banneridx = 0
	local maxbanners = 11
	local stadiumAsset = "data/sceneassets/stadium/${db.stadium[?].prefix}_${db.stadium[?].stadiumID}_${db.stadium[?].lightType}_container_${db.stadium[?].stadTexID}.rx3;data/sceneassets/stadium/${db.stadium[?].prefix}_666_1_container_0.rx3"

	-- Load all the stadium assets at a higher priority than the rest, so we can get it loaded early	
    gr:SetPriorityBoost(stadium, lod, 10)

	-- Get all assets we require in...
	gr:AddCallback(stadium, lod, "StadiumUpdate(?)")
	gr:AddAsset(stadium, lod, "shader", "data/fifarna/shader.big")

	gr:AddAsset(stadium, lod, "stadium",                          stadiumAsset, priority)
	
	-- Assets we need to intercept
	gr:AddAsset(stadium, lod, "pitchambient",                     stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "pitchnolineambient",               stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "jumbotronambient",                 stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "adboardambient",                   stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "adboardscrollingambient",          stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "adboarddigitalambient",            stadiumAsset, priority)
    gr:AddAsset(stadium, lod, "adboarddigitalglow",               stadiumAsset, priority)
    gr:AddAsset(stadium, lod, "adboarddigitalglowambient",        stadiumAsset, priority)
    gr:AddAsset(stadium, lod, "adboardsingledigitalambient",      stadiumAsset, priority)
    gr:AddAsset(stadium, lod, "adboardsingledigitalglow",         stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "adboardsingledigitalglowambient",  stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "genericadambient",                 stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "crestambient",                     stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "homeprimaryambient",               stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "homesecondaryambient",             stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "bannerhomeambient",                stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "bannerawayambient",                stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "diffuseshadow",                    stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "diffuseshadowambient",             stadiumAsset, priority)
	
	gr:AddAsset(stadium, lod, "sclockhalvesambient",              stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "sclocktimeanalogambient",          stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "sclockminutesonesambient",         stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "sclockminutestensambient",         stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "sclocksecondsonesambient",         stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "sclocksecondstensambient",         stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "sclockscorehomeonesambient",      stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "sclockscorehometensambient",       stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "sclockscoreawayonesambient",      stadiumAsset, priority)
	gr:AddAsset(stadium, lod, "sclockscoreawaytensambient",       stadiumAsset, priority)

	
	-- Stadium Banners with dynamic distribution  (Not used on Fifa)
    --local bannermat
	--for banneridx=0, maxbanners-1 do 
	--	bannermat = string.format( "banner%sambient", banneridx )
	--	gr:AddAsset(stadium, lod, bannermat,                      stadiumAsset, priority)
	--end
	
	
	-- Additional assets to load
	gr:AddAsset(stadium, lod, "mow", "data/sceneassets/pitch/pitchmowpattern_${db.stadium[?].mowPattern}_textures.rx3", priority)
	gr:AddAsset(stadium, lod, "cmn", "data/sceneassets/pitch/pitch_common_textures.rx3", priority)
	gr:AddAsset(stadium, lod, "col", "data/sceneassets/pitch/pitchcolor_${db.stadium[?].pitchColor}_textures.rx3", priority)
	gr:AddAsset(stadium, lod, "globaltex", "data/sceneassets/globaltex/globaltex_0.rx3", priority)
	gr:AddAsset(stadium, lod, "wear", "data/sceneassets/pitch/pitchwearpattern_${db.stadium[?].wearPattern}_textures.rx3", priority)
	--TODO direct it into host city texture
	gr:AddAsset(stadium, lod, "adboardsingletex", "data/sceneassets/adboard/adboard_${db.stadium[?].adboardID}_${db.stadium[?].adboardGroup}.rx3", priority)
	gr:AddAssetEx(stadium, lod, "extracttexture ${GetCrestTexName(?)}", "homecresttex", "${GetHomeKitAssetSrc(?)}")
	gr:AddAsset(stadium, lod, "homebannertex", "data/sceneassets/banner/banner_${db.stadium[?].homeBannerId}.rx3;data/sceneassets/banner/banner_0.rx3", priority)
	gr:AddAsset(stadium, lod, "awaybannertex", "data/sceneassets/banner/banner_${db.stadium[?].awayBannerId}.rx3;data/sceneassets/banner/banner_0.rx3", priority)
	gr:AddAsset(stadium, lod, "genericadtex", "data/sceneassets/genericad/genericad_${db.stadium[?].adboardID}.rx3;data/sceneassets/genericad/genericad_1.rx3", priority)
	gr:AddAsset(stadium, lod, "skytexture", "data/sceneassets/sky/sky_${db.stadium[?].skyCategoryId}_${db.stadium[?].skyAssetId}.rx3", priority)

	-- Now generate custom materials (these should be named after the shader they are to replace)
	-- Pitch 
	local part = "pitchambient"
	gr:CreateMaterial(stadium, lod, part, "hdr_pitch.fx")
	gr:SetTexture(stadium, lod, part, "textures", "noiseTexture", "globaltex", "multiFreq_noise")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "col", "grass_color")
	-- ambient should magically be populated by the original state block of the stadium
	gr:SetTexture(stadium, lod, part, "textures", "normalMap", "mow", "grass_normal")
	gr:SetTexture(stadium, lod, part, "textures", "alphamask", "wear", "grass_wear")
	gr:SetTexture(stadium, lod, part, "textures", "pitchLinesMap", "cmn", "grass_pitchlines")
	
	part = "pitchnolineambient"
	gr:CreateMaterial(stadium, lod, part, "hdr_pitchnoline.fx")
	gr:SetTexture(stadium, lod, part, "textures", "noiseTexture", "globaltex", "multiFreq_noise")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "col", "grass_color")
	-- ambient should magically be populated by the original state block of the stadium
	-- gr:SetTexture(stadium, lod, part, "textures", "normalMap", "mow", "grass_normal")
	-- gr:SetTexture(stadium, lod, part, "textures", "alphamask", "wear", "grass_wear")

	-- Render to texture jumbotron
	part = "jumbotronambient"
	-- gr:CreateMaterialFromAttribulator(stadium, lod, part, "jumbotronambient", "${AttribMaterial('jumbotronambient')}")
	gr:CreateMaterial(stadium, lod, part, "jumbotron.fx")
	gr:SetTextureFromRuntime(stadium, lod, part, "textures", "jumbotronMap", "jumbotron")
	gr:SetTexture(stadium, lod, part, "textures", "LEDTexture", "globaltex", "LED_cm")
	
	-- Stadium Adboards
	-- All of them redirected into runtime texture managed by adboard renderable
	-- The exception is adboardsingledigitalambient and adboardsingledigitalglowambient which
	-- show a completely different not switching texture all the time
	part = "adboardambient"
	gr:CreateMaterial(stadium, lod, part, "adboardambient.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "adboardsingletex", "adboard")
	
	part = "adboardscrollingambient"
	gr:CreateMaterial(stadium, lod, part, "adboardscrollingambient.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "adboardsingletex", "adboard")

	part = "adboarddigitalambient"
	gr:CreateMaterial(stadium, lod, part, "adboarddigitalambient.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "adboardsingletex", "adboard")
	gr:SetTexture(stadium, lod, part, "textures", "incandescenceMap", "globaltex", "digitalgrid_cm")	

	part = "adboarddigitalglow"
	gr:CreateMaterial(stadium, lod, part, "adboarddigitalglowambient.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "adboardsingletex", "adboard")

	part = "adboarddigitalglowambient"
	gr:CreateMaterial(stadium, lod, part, "adboarddigitalglowambient.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "adboardsingletex", "adboard")

	-- The home team crest in the stadium
	part = "crestambient"
	-- gr:CreateMaterialFromAttribulator(stadium, lod, part, "crestambient", "${AttribMaterial('crestambient')}")
	gr:CreateMaterial(stadium, lod, part, "env_Diff.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "homecresttex", "${GetCrestTexName(?)}")
	
	-- Stadium Banners
	part = "bannerhomeambient"
	gr:CreateMaterial(stadium, lod, part, "env_DiffColourSub.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "homebannertex", "banner_")
	gr:SetConstantARGB(stadium, lod, part, "global", "customColorPri", "${db.stadium[?].homeBannerPrimaryColour}")
	gr:SetConstantARGB(stadium, lod, part, "global", "customColorSec", "${db.stadium[?].homeBannerSecondaryColour}")
	
	part = "bannerawayambient"
	gr:CreateMaterial(stadium, lod, part, "env_DiffColourSub.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "awaybannertex", "banner_")
	gr:SetConstantARGB(stadium, lod, part, "global", "customColorPri", "${db.stadium[?].awayBannerPrimaryColour}")
	gr:SetConstantARGB(stadium, lod, part, "global", "customColorSec", "${db.stadium[?].awayBannerSecondaryColour}")

    ------------------------------------------------------------------------------------------------------
	-- Stadium Banners with dynamic distribution (Not used on Fifa)
	--local texname
	--for banneridx=0, maxbanners-1 do 
	--	part = string.format( "banner%sambient", banneridx )
	--	texname = string.format( "banner%s", banneridx )
	--	gr:CreateMaterial(stadium, lod, part, "env_Diff.fx")
	--	gr:SetTextureFromRuntime(stadium, lod, part, "textures", "diffuseTexture", texname)
	--end
    ------------------------------------------------------------------------------------------------------

	-- Team colours
	part = "homeprimaryambient"
	gr:CreateMaterial(stadium, lod, part, "env_DiffColour.fx")
	gr:SetConstantARGB(stadium, lod, part, "global", "envColour", "${db.stadium[?].homePrimaryColour}")
	
	part = "homesecondaryambient"
	gr:CreateMaterial(stadium, lod, part, "env_DiffColour.fx")
	gr:SetConstantARGB(stadium, lod, part, "global", "envColour", "${db.stadium[?].homeSecondaryColour}")
	
	-- Generic adboards
	part = "genericadambient"
	gr:CreateMaterial(stadium, lod, part, "env_Diff.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "genericadtex", "genericad")
	
	
	-- Flatshadow enabled geometry
	part = "diffuseshadowambient"
	gr:CreateMaterial(stadium, lod, part, "env_Diff_flatshadow.fx")

	
	-- Flatshadow enabled geometry
	part = "diffuseshadow"
	gr:CreateMaterial(stadium, lod, part, "env_Diff_flatshadow.fx")

	
	-- Dynamic Scoreclock
	part = "sclocktimeanalogambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_analog")
	
	part = "sclockhalvesambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_digits")
	
	part = "sclockminutesonesambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_digits")
	
	part = "sclockminutestensambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_digits")
	
	part = "sclocksecondsonesambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_digits")
	
	part = "sclocksecondstensambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_digits")
	
	part = "sclockscorehomeonesambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_digits")
	
	part = "sclockscorehometensambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_digits")
	
	part = "sclockscoreawayonesambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_digits")
	
	part = "sclockscoreawaytensambient"
	gr:CreateMaterial(stadium, lod, part, "uvoffset.fx")
	gr:SetTexture(stadium, lod, part, "textures", "diffuseTexture", "globaltex", "sclock_digits")
	
	
end



teamAdboards = {}
tournamentAdboards = {}
stadiumAdboards = {}
genericAdboards = {}

teamTournament = {}

tournamentTeamAdboards = {}
tournamentStadiumAdboards = {}


function getAdboardID(team,ad,tourn,idx,stad)

if (globalAdboardsID ~= nil) then
return globalAdboardsID
end

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

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

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

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

if (stadiumAdboards[stad] ~= nil) then
return stadiumAdboards[stad]
end

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

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

return 1
end

function assignAdboard(team,ad)
teamAdboards[team] = ad
end

function assignTeamAdboard(team,ad)

if (type(ad) == "number") then
teamAdboards[team] = ad
else
teamAdboards[team] = ad[math.random(#ad)]
end

end

function assignTournamentAdboard(tourn,ad)

if (type(ad) == "number") then
tournamentAdboards[tourn] = ad
else
tournamentAdboards[tourn] = ad[math.random(#ad)]
end

end

function assignStadiumAdboard(stad,ad)

if (type(ad) == "number") then
stadiumAdboards[stad] = ad
else
stadiumAdboards[stad] = ad[math.random(#ad)]
end

end

globalAdboardsID = nil

function useGlobalAdboard(ad)
globalAdboardsEnabled = true

if (type(ad) == "number") then
globalAdboardsID = ad
else
globalAdboardsID = ad[math.random(#ad)]
end

end

tournStadTex = {}
teamStadTex = {}

function assignTournamentStadTex(stad,tourn,id)

if (tournStadTex[stad] == nil) then
tournStadTex[stad] = {}
end

tournStadTex[stad][tourn] = id
end

function getTournamentStadTex(stad,home,tourn,id)

if (teamStadTex[stad] ~= nil) then
if (teamStadTex[stad][home] ~= nil) then
return teamStadTex[stad][home]
end
end

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

return id
end


arenaModeAdboard = nil

function setArenaModeAdboard(id)

if (type(ad) == "number") then
arenaModeAdboard = id
else
arenaModeAdboard = id[math.random(#ad)]
end

end


frTourn = -1
gloTourn = nil

function useTournamentGraphicsInFriendly(id)
frTourn = id
end

function useGlobalTournamentGraphics(id)
gloTourn = id
end

function getTournamentGraphicsS(id)

if (gloTourn ~= nil) then
return gloTourn
end

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

return id
end


mowPatturns = {}

function assignMowPattern(team,mow)
mowPatturns[team] = mow
end

function getMowPattern(team,tourn,mow)

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

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

return mow
end

tournamentMowPatturns = {}

function assignTournamentMowPattern(tourn,mow)
tournamentMowPatturns[tourn] = mow
end


function assignTournamentTeamAdboard(team,tourn,ad)

if (tournamentTeamAdboards[team] == nil) then
tournamentTeamAdboards[team] = {}
end

if (type(ad) == "number") then
tournamentTeamAdboards[team][tourn] = ad
else
tournamentTeamAdboards[team][tourn] = ad[math.random(#ad)]
end

end

function assignTournamentStadiumAdboard(stad,tourn,ad)

if (tournamentStadiumAdboards[stad] == nil) then
tournamentStadiumAdboards[stad] = {}
end

if (type(ad) == "number") then
tournamentStadiumAdboards[stad][tourn] = ad
else
tournamentStadiumAdboards[stad][tourn] = ad[math.random(#ad)]
end

end


wearPatturns = {}

function assignWearPattern(team,mow)
wearPatturns[team] = mow
end

function getWearPattern(team,mow)

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

return mow
end


function assignTeamStadTex(stad,tourn,id)

if (teamStadTex[stad] == nil) then
teamStadTex[stad] = {}
end

teamStadTex[stad][tourn] = id
end


--assignCustomAdboardIDs()

--Revolution Mod 13 1.3
--Edited by scouser09