 _LOADED["scripts/styles/beachstyle.lua"] = nil;
 
require("scripts/cpscript.lua");
require("scripts/styles/beachstyle.lua");
require("scripts/styles/deco_animations.lua");

-- Creates all background elements that don't need z-sorting.
-- They're drawn below the z-sorted elements in the specified order
-------------------------------------------------------------------------
function CreateBackground()
	
	local retGroup = {
		
		-------------------------------------
		-- background
		BlgBitmap
		{
			image="level/core/beach/textures/background",
			center = {x = 0, y = 0},
		},
		
		-------------------------------------
		-- Animated decos		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(FlockSwoopStyle),
			BlgBitmap {
				image="level/core/beach/textures/deco_flock",
				center = {x = 28, y = 40},
				transformMatrix = {x = 400, y = -15},
				playAnim = "DoAnim",
			},
		},

		BlgMovieClip{
			repeatCount = 0,
			SetStyle(FlockSwoopStyle),
			BlgBitmap {
				image="level/core/beach/textures/deco_flock",
				center = {x = 28, y = 40},
				transformMatrix = {x = 440, y = -5},
				playAnim = "DoAnim",
			},
		},

		BlgMovieClip{
			repeatCount = 0,
			SetStyle(FlockSwoopStyle),
			BlgBitmap {
				image="level/core/beach/textures/deco_flock",
				center = {x = 28, y = 40},
				transformMatrix = {x = 380, y = -10},
				playAnim = "DoAnim",
			},
		},
		
		-------------------------------------
		-- Waves
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave1Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 100, y = 635, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave2Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 300, y = 660, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave3Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 500, y = 605, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave4Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 700, y = 610, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave1Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 900, y = 620, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave2Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 800, y = 615, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave3Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 600, y = 610, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave4Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 400, y = 650, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave2Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 200, y = 660, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Wave3Style),
			BlgBitmap {
				image="level/core/beach/textures/deco_wave",
				center = {x = 128, y = 96},
				transformMatrix = {x = 0, y = 655, scaleX = 1.5, scaleY = 1.25},
			},
		},
		
		-------------------------------------
		-- Sea Water
		BlgBitmap {
			playAnim = "Waves01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = -64, y = 424, scaleX = 2.0, scaleY = 2.0},
		},
		
		BlgBitmap {
			playAnim = "Waves02",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 160, y = 424, scaleX = 2.0, scaleY = 2.0},
		},
		
		BlgBitmap {
			playAnim = "Waves03",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 384, y = 424, scaleX = 2.0, scaleY = 2.0},
		},
		
		BlgBitmap {
			playAnim = "Waves01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 608, y = 424, scaleX = 2.0, scaleY = 2.0},
		},
		
		BlgBitmap {
			playAnim = "Waves02",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 832, y = 424, scaleX = 2.0, scaleY = 2.0},
		},
		
		------------------
		
		BlgBitmap {
			playAnim = "Waves03",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = -64, y = 584, scaleX = 2.0, scaleY = 2.0},
		},
		
		BlgBitmap {
			playAnim = "Waves01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 160, y = 584, scaleX = 2.0, scaleY = 2.0},
		},
		
		BlgBitmap {
			playAnim = "Waves02",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 384, y = 584, scaleX = 2.0, scaleY = 2.0},
		},
		
		BlgBitmap {
			playAnim = "Waves03",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 608, y = 584, scaleX = 2.0, scaleY = 2.0},
		},
		
		BlgBitmap {
			playAnim = "Waves01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 832, y = 584, scaleX = 2.0, scaleY = 2.0},
		},
		
		--------------------
		
		BlgBitmap {
			playAnim = "Reflection01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.09,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 400, y = 360, scaleX = 2.0, scaleY = 2.4},
		},
		
		BlgBitmap {
			playAnim = "Reflection02",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.23,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 550, y = 290, scaleX = 2.0, scaleY = 2.7},
		},
		
		BlgBitmap {
			playAnim = "Reflection03",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.26,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 700, y = 275, scaleX = 2.0, scaleY = 2.6},
		},
		
		BlgBitmap {
			playAnim = "Reflection01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.3,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 850, y = 290, scaleX = 2.0, scaleY = 2.4},
		},
		
		------------------
		
		BlgBitmap {
			playAnim = "Reflection03",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.2,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = -180, y = 360, scaleX = 4.0, scaleY = 3.0},
		},
		
		BlgBitmap {
			playAnim = "Reflection02",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.2,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 180, y = 620, scaleX = 5.0, scaleY = 3.0},
		},
		
		BlgBitmap {
			playAnim = "Reflection01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.15,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 660, y = 580, scaleX = 4.0, scaleY = 3.0},
		},
	};

	return Group(retGroup);
end

-- Creates all z-sorted level decorations.
-- Creation order doesn't matter since all elements are z-sorted
-- on level startup.
-------------------------------------------------------------------------
function CreateDecos()
	
	local retGroup = {
	
		-------------------------------------
		-- Decorations
		
	};

	return Group(retGroup);
end

-- Creates all decorations and background elements based on the time of the day (level number within a 5-level set)
-- All elements created this way are z-sorted.
-------------------------------------------------------------------------
function CreateTimedDecos(timeOfDay)
	
	local retGroup;
	
	if(timeOfDay == 1) then
	
		retGroup = {
		};
		
		return Group(retGroup);
	end
	
	if (timeOfDay == 2) then
	
		retGroup = {
		};
		
		return Group(retGroup);
	end
	
	if (timeOfDay == 3) then
	
		retGroup = {
		};
		
		return Group(retGroup);
	end
	
	if (timeOfDay == 4) then
	
		retGroup = {
		};
		
		return Group(retGroup);
	end
	
	if (timeOfDay == 5) then
	
		retGroup = {
		};
		
		return Group(retGroup);
	end
	
end


-- Creates all gameplay elements for the level
-- devLevel determines up to what point will any advanced stations will be created
-------------------------------------------------------------------------
function CreateStations(devLevel)

	local retGroup;
	
	-- set the max upgrade level to 1 by default
	BaseItemStationStyle.maxUpgradeLevel = 1;
	BeachSunChairStyle.maxUpgradeLevel = 1;
	SeaStyle.maxUpgradeLevel = 1;
	BeachCookingStationStyle.maxUpgradeLevel = 1;
	BeachCombinationStationStyle.maxUpgradeLevel = 1;
	LifeGuardStyle.maxUpgradeLevel = 1;
	BeachDrumsStyle.maxUpgradeLevel = 1;
	BeachCymbalsStyle.maxUpgradeLevel = 1;
	BeachMarimbaStyle.maxUpgradeLevel = 1;
		
	retGroup = {

		-- Sea
		SetStyle(SeaStyle),
		Sea{
			transformMatrix = {x = 544, y = 720},
			zLayer = 0,
			upgradeID = kUpgradeBeachSea,
			upgradeLevel = 1,
		},
		
		-- Chair Drag & Drop Area
		SetStyle(DragAreaStyle),
		DragArea{
			transformMatrix = {x = 288, y = 168},
			zLayer = 0,
		},
		
		-- Chairs
		SetStyle(BeachSunChairStyle),
		BeachSunChair{
			transformMatrix = {x = 272, y = 384},
			zLayer = 383,
			name = "chair1",
			upgradeID = kUpgradeBeachChair1,
			upgradeLevel = 1,
		},
		BeachSunChair{
			transformMatrix = {x = 360, y = 384},
			zLayer = 383,
			name = "chair2",
			upgradeID = kUpgradeBeachChair2,
			upgradeLevel = 1,
		},
		BeachSunChair{
			transformMatrix = {x = 448, y = 384},
			zLayer = 383,
			name = "chair3",
			upgradeID = kUpgradeBeachChair3,
			upgradeLevel = 1,
		},

		-- Dispensers
		SetStyle(BeachSuntanStationStyle),
		BeachSuntanStation{
			transformMatrix = {x = 416, y = 177},
			zLayer = 175,
			name = "suntan",
			upgradeID = kUpgradeBeachDispSuntan,
			upgradeLevel = 1,
		},

		SetStyle(BeachIceCreamStationStyle),
		BeachIceCreamStation{
			transformMatrix = {x = 504, y = 177},
			zLayer = 175,
			name = "icecream",
			upgradeID = kUpgradeBeachDispIceCream,
			upgradeLevel = 1,
		},

		SetStyle(BeachOrangeJuiceStationStyle),
		BeachOrangeJuiceStation{
			transformMatrix = {x = 592, y = 177},
			zLayer = 175,
			name = "orangejuice",
			upgradeID = kUpgradeBeachDispOrangeJuice,
			upgradeLevel = 1,
		},
		
		SetStyle(GarbageCanStationStyle),
		GarbageCanStation{
			transformMatrix = {x = 344, y = 168},
			name = "garbage",
			zLayer = 167,
		},		
		
		SetStyle(BeachDrumsStyle),
			
		BeachDrums{
			name = "drums",
			transformMatrix = {x = 920, y = 200},
			upgradeID = kUpgradeBeachRadio3,
			upgradeLevel = 1,
		},
	
		BlgBitmap{
			image="level/core/club/textures/female2_club",
			center = {x = 20, y = 105},
			transformMatrix = {x = 865, y = 165},
			playAnim = "Idle",
			name = "Drummer",
		},
		
		SetStyle(BeachDrumNoticeStyle),
		
		BeachDrumNotice{
			transformMatrix = {x = 920, y = 160},
			zLayer = 210,
			name = "CooldownNotice",
		},
		
		BlgParticles{
			name = "DrummerParticles",
			path = "level/core/common/particles/pfx_drummer_sleep.lua",
			transformMatrix = {x = 925, y = 90},
			zLayer = 166,
		}
	}
	
	-- Upgrades Tier 1
	if (devLevel > 0) then
		
		table.insert(retGroup, 
			SetStyle(BeachCookingStationStyle)
		);
		
		table.insert(retGroup,
			BeachCookingStation{
				transformMatrix = {x = 680, y = 177},
				zLayer = 175,
				name = "cooking",
				upgradeID = kUpgradeBeachDispCooking,
				upgradeLevel = 1,
			}
		);
		
	end
	
	-- Cooking Station
	if (devLevel > 1) then
		
		BaseItemStationStyle.maxUpgradeLevel = 2;
		BeachSunChairStyle.maxUpgradeLevel = 2;
		SeaStyle.maxUpgradeLevel = 2;
		BeachCookingStationStyle.maxUpgradeLevel = 2;
		BeachCombinationStationStyle.maxUpgradeLevel = 2;
		LifeGuardStyle.maxUpgradeLevel = 2;
		BeachDrumsStyle.maxUpgradeLevel = 1;
		BeachCymbalsStyle.maxUpgradeLevel = 1;
		BeachMarimbaStyle.maxUpgradeLevel = 1;
		
		-- Deco Stations
		table.insert(retGroup, 
			SetStyle(BeachUmbrellaStyle)
		);
			
		table.insert(retGroup, 
			BeachUmbrella{
				transformMatrix = {x = 54, y = 406},
				upgradeID = kUpgradeBeachDeco1,
				upgradeLevel = 0,
				zLayer = 381,
			}
		);
		
		table.insert(retGroup, 
			SetStyle(BeachTentStyle)
		);
		
		table.insert(retGroup, 
			BeachTent{
				transformMatrix = {x = 158, y = 214},
				upgradeID = kUpgradeBeachDeco2,
				upgradeLevel = 0,
				zLayer = 1,
			}
		);
			
		table.insert(retGroup, 
			SetStyle(BeachFountainStyle)
		);
			
		table.insert(retGroup, 
			BeachFountain{
				transformMatrix = {x = 830, y = 352},
				upgradeID = kUpgradeBeachDeco3,
				upgradeLevel = 0,
			}
		);
		
	end
	
	-- Upgrades Tier 2
	if (devLevel > 2) then
		
		table.insert(retGroup, 
			SetStyle(BeachSunChairStyle)
		);
		
		table.insert(retGroup,
			BeachSunChair{
				transformMatrix = {x = 184, y = 384},
				zLayer = 383,
				name = "chair4",
				upgradeID = kUpgradeBeachChair4,
				upgradeLevel = 0,
			}
		);
		
		table.insert(retGroup,
			BeachSunChair{
				transformMatrix = {x = 536, y = 384},
				zLayer = 383,
				name = "chair5",
				upgradeID = kUpgradeBeachChair5,
				upgradeLevel = 0,
			}
		);
		
		-- drums
		table.insert(retGroup, 
			SetStyle(BeachMarimbaStyle)
		);
			
		table.insert(retGroup, 
			BeachMarimba{
				transformMatrix = {x = 850, y = 200},
				upgradeID = kUpgradeBeachRadio1,
				upgradeLevel = 0,
			}
		);
			
		table.insert(retGroup, 
			SetStyle(BeachCymbalsStyle)
		);
			
		table.insert(retGroup, 
			BeachCymbals{
				transformMatrix = {x = 980, y = 200},
				upgradeID = kUpgradeBeachRadio2,
				upgradeLevel = 0,
			}
		);
		
	end
	
	-- Upgrades Tier 3
	if (devLevel > 3) then
		
		BaseItemStationStyle.maxUpgradeLevel = 3;
		BeachSunChairStyle.maxUpgradeLevel = 3;
		SeaStyle.maxUpgradeLevel = 3;
		BeachCookingStationStyle.maxUpgradeLevel = 3;
		BeachCombinationStationStyle.maxUpgradeLevel = 3;
		LifeGuardStyle.maxUpgradeLevel = 3;
		BeachDrumsStyle.maxUpgradeLevel = 2;
		BeachCymbalsStyle.maxUpgradeLevel = 2;
		BeachMarimbaStyle.maxUpgradeLevel = 2;
		
		table.insert(retGroup, 
			SetStyle(BeachCombinationStationStyle)
		);
		
		table.insert(retGroup,
			BeachCombinationStation{
				transformMatrix = {x = 768, y = 177},
				zLayer = 175,
				name = "combination",
				upgradeID = kUpgradeBeachDispCombination,
				upgradeLevel = 1,
			}
		);
	end
	
	if (devLevel > 4) then
	
		BaseItemStationStyle.maxUpgradeLevel = 4;
		BeachSunChairStyle.maxUpgradeLevel = 4;
		SeaStyle.maxUpgradeLevel = 3;
		BeachCookingStationStyle.maxUpgradeLevel = 4;
		BeachCombinationStationStyle.maxUpgradeLevel = 4;
		LifeGuardStyle.maxUpgradeLevel = 3;
		BeachDrumsStyle.maxUpgradeLevel = 2;
		BeachCymbalsStyle.maxUpgradeLevel = 2;
		BeachMarimbaStyle.maxUpgradeLevel = 2;
		
		table.insert(retGroup, 
			SetStyle(BeachSunChairStyle)
		);
		
		table.insert(retGroup,
			BeachSunChair{
				transformMatrix = {x = 96, y = 384},
				zLayer = 383,
				name = "chair6",
				upgradeID = kUpgradeBeachChair6,
				upgradeLevel = 0,
			}
		);
		
	end
	
	-- Waiters
	table.insert(retGroup,
		SetStyle(LifeGuardStyle)
	);
	
	table.insert(retGroup,
		Mick{
			transformMatrix = {x = 592, y = 304},
			upgradeID = kUpgradeBeachWaiter1,
			upgradeLevel = 1,
		}
	);
	
	return Group(retGroup);
	
end