 _LOADED["scripts/styles/poolstyle.lua"] = nil;
 
require("scripts/cpscript.lua");
require("scripts/styles/poolstyle.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 = {
		
		BlgBitmap{
			image="level/core/pool/textures/background",
			center = {x = 0, y = 0},
		},
		
		-- Animated decos
		BlgBitmap{
			image="level/core/pool/textures/deco_sun",
			transformMatrix = {x = 600, y = 20},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(CloudRightStyle),
			BlgBitmap {
				image="level/core/pool/textures/deco_cloud",
				center = {x = 63, y = 62},
				transformMatrix = {x = -63, y = 60},
				zLayer = 0,
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(CloudLeftStyle),
			BlgBitmap {
				image="level/core/pool/textures/deco_cloud",
				center = {x = 63, y = 62},
				transformMatrix = {x = 1100, y = 60},
				zLayer = 0,
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(FlockTakeoffStyle),
			BlgBitmap {
				image="level/core/beach/textures/deco_flock",
				center = {x = 28, y = 40},
				transformMatrix = {x = -30, y = 100},
				playAnim = "DoAnim",
			},
			zLayer = 10,
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(FlockSwoopStyle),
			BlgBitmap {
				image="level/core/beach/textures/deco_flock",
				center = {x = 28, y = 45},
				transformMatrix = {x = 200, y = 0},
				playAnim = "DoAnim",
			},
		},

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

		BlgMovieClip{
			repeatCount = 0,
			SetStyle(FlockSwoopStyle),
			BlgBitmap {
				image="level/core/beach/textures/deco_flock",
				center = {x = 28, y = 40},
				transformMatrix = {x = 140, y = -10},
				playAnim = "DoAnim",
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(PalmTrunkStyle),
			BlgContainer{
				transformMatrix = {x = 220, y = 160},
				BlgBitmap {
					image="level/core/pool/textures/deco_palm_trunk",
					center = {x = 27, y = 122},
					transformMatrix = {x = 0, y = 0},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf1Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_1",
						center = {x = 24, y = 70},
						transformMatrix = {x = -25, y = -116},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf2Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_2",
						center = {x = 84, y = 50},
						transformMatrix = {x = -25, y = -116},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf3Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_3",
						center = {x = 1, y = 32},
						transformMatrix = {x = -25, y = -116},
					},
				},
			},	
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(PalmTrunkStyle),
			BlgContainer{
				transformMatrix = {x = 460, y = 165, scaleX = -1},
				BlgBitmap {
					image="level/core/pool/textures/deco_palm_trunk",
					center = {x = 27, y = 122},
					transformMatrix = {x = 0, y = 0},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf1Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_1",
						center = {x = 24, y = 70},
						transformMatrix = {x = -25, y = -116},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf2Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_2",
						center = {x = 84, y = 50},
						transformMatrix = {x = -25, y = -116},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf3Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_3",
						center = {x = 1, y = 32},
						transformMatrix = {x = -25, y = -116},
					},
				},
			},	
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(PalmTrunkStyle),
			BlgContainer{
				transformMatrix = {x = 750, y = 155},
				BlgBitmap {
					image="level/core/pool/textures/deco_palm_trunk",
					center = {x = 27, y = 122},
					transformMatrix = {x = 0, y = 0},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf1Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_1",
						center = {x = 24, y = 70},
						transformMatrix = {x = -25, y = -116},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf2Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_2",
						center = {x = 84, y = 50},
						transformMatrix = {x = -25, y = -116},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf3Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_3",
						center = {x = 1, y = 32},
						transformMatrix = {x = -25, y = -116},
					},
				},
			},	
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(PalmTrunkStyle),
			BlgContainer{
				transformMatrix = {x = 950, y = 160, scaleX = -1},
				BlgBitmap {
					image="level/core/pool/textures/deco_palm_trunk",
					center = {x = 27, y = 122},
					transformMatrix = {x = 0, y = 0},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf1Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_1",
						center = {x = 24, y = 70},
						transformMatrix = {x = -25, y = -116},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf2Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_2",
						center = {x = 84, y = 50},
						transformMatrix = {x = -25, y = -116},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf3Style),				
					BlgBitmap {
						image="level/core/pool/textures/deco_palm_leaf_3",
						center = {x = 1, y = 32},
						transformMatrix = {x = -25, y = -116},
					},
				},
			},	
		},
		
		BlgBitmap{
			image="level/core/pool/textures/deco_trees_hi",
			center = {x = 512, y = 171},
			transformMatrix = {x = 512, y = 294},
		},
		
		-------------------------------------
		-- Pool Water
		BlgBitmap {
			playAnim = "Reflection01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.2,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 48, y = 320, scaleX = 3.5, scaleY = 3.5},
		},
		BlgBitmap {
			playAnim = "Reflection03",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.2,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 320, y = 288, scaleX = 3.5, scaleY = 3.5},
		},
		BlgBitmap {
			playAnim = "Reflection02",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.2,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 592, y = 420, scaleX = 3.5, scaleY = 3.5},
		},
		
		BlgBitmap {
			playAnim = "Reflection02",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.2,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = -120, y = 432, scaleX = 3.5, scaleY = 3.5},
		},
		BlgBitmap {
			playAnim = "Reflection01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.2,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 192, y = 432, scaleX = 3.5, scaleY = 3.5},
		},
		BlgBitmap {
			playAnim = "Reflection03",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.2,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 464, y = 432, scaleX = 3.5, scaleY = 3.5},
		},
		
		BlgBitmap {
			playAnim = "Waves01",
			blendMode = kBlendAdditiveAlpha,
			alpha = 0.4,
			image="level/core/beach/textures/waves",
			center = {x = 0, y = 0},
			transformMatrix = {x = 128, y = 384, scaleX = 3.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 = 464, y = 384, scaleX = 3.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 = 32, y = 536, scaleX = 3.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 = 368, y = 536, scaleX = 3.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 = 704, y = 536, scaleX = 3.0, scaleY = 2.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
		BlgBitmap{
			image="level/core/pool/textures/deco_bridge",
			center = {x = 121, y = 229},
			transformMatrix = {x = 1024, y = 780},
			zLayer = 768,
		},
		
		BlgBitmap{
			image="level/core/common/textures/beachball",
			center = {x = 11, y = 22},
			transformMatrix = {x = 490, y = 340},
		},
		
		--[[
		BlgBitmap{
			image="level/core/pool/textures/deco_plant",
			center = {x = 50, y = 86},
			transformMatrix = {x = -16, y = 528},
		},
		BlgBitmap{
			image="level/core/pool/textures/deco_plant",
			center = {x = 50, y = 86},
			transformMatrix = {x = 8, y = 504},
		},
		BlgBitmap{
			image="level/core/pool/textures/deco_plant",
			center = {x = 50, y = 86},
			transformMatrix = {x = 32, y = 480},
		},
		
		BlgBitmap{
			image="level/core/pool/textures/deco_plant",
			center = {x = 50, y = 86},
			transformMatrix = {x = 980, y = 528},
		},
		]]
	};

	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;
	PoolSunChairStyle.maxUpgradeLevel = 1;
	PoolStyle.maxUpgradeLevel = 1;
	PoolBoyStyle.maxUpgradeLevel = 1;
	PoolCookingStationStyle.maxUpgradeLevel = 1;
	PoolCombinationStationStyle.maxUpgradeLevel = 1;
	PoolDrumsStyle.maxUpgradeLevel = 1;
	PoolCymbalsStyle.maxUpgradeLevel = 1;
	PoolMarimbaStyle.maxUpgradeLevel = 1;
		
	retGroup = {

		-- Pool
		SetStyle(PoolStyle),
		Pool{
			transformMatrix = {x = 512, y = 780},
			zLayer = 0,
			upgradeID = kUpgradePool,
			upgradeLevel = 1,
		},
		
		-- Chair Drag & Drop Area
		SetStyle(DragAreaStyle),
		DragArea{
			transformMatrix = {x = 288, y = 188},
			zLayer = 0,
		},
		
		-- Chairs
		SetStyle(PoolSunChairStyle),
		PoolSunChair{
			transformMatrix = {x = 248, y = 368},
			zLayer = 367,
			name = "chair1",
			upgradeID = kUpgradePoolChair1,
			upgradeLevel = 1,
		},
		
		PoolSunChair{
			transformMatrix = {x = 344, y = 368},
			zLayer = 367,
			name = "chair2",
			upgradeID = kUpgradePoolChair2,
			upgradeLevel = 1,
		},
		PoolSunChair{
			transformMatrix = {x = 440, y = 368},
			zLayer = 367,
			name = "chair3",
			upgradeID = kUpgradePoolChair3,
			upgradeLevel = 1,
		},

		-- Dispensers
		SetStyle(PoolSuntanStationStyle),
		PoolSuntanStation{
			transformMatrix = {x = 416, y = 196},
			zLayer = 175,
			name = "suntan",
			upgradeID = kUpgradePoolDispSuntan,
			upgradeLevel = 1,
		},

		SetStyle(PoolIceCreamStationStyle),
		PoolIceCreamStation{
			transformMatrix = {x = 504, y = 196},
			zLayer = 175,
			name = "icecream",
			upgradeID = kUpgradePoolDispIceCream,
			upgradeLevel = 1,
		},

		SetStyle(PoolOrangeJuiceStationStyle),
		PoolOrangeJuiceStation{
			transformMatrix = {x = 592, y = 196},
			zLayer = 175,
			name = "orangejuice",
			upgradeID = kUpgradePoolDispOrangeJuice,
			upgradeLevel = 1,
		},
		
		SetStyle(GarbageCanStationStyle),
		GarbageCanStation{
			transformMatrix = {x = 344, y = 188},
			name = "garbage",
			zLayer = 167,
		},		
	}
	
	-- Upgrades Tier 1
	if (devLevel > 0) then
		
		BaseItemStationStyle.maxUpgradeLevel = 2;
		PoolSunChairStyle.maxUpgradeLevel = 2;
		PoolStyle.maxUpgradeLevel = 2;
		PoolBoyStyle.maxUpgradeLevel = 2;
		PoolCookingStationStyle.maxUpgradeLevel = 2;
		PoolCombinationStationStyle.maxUpgradeLevel = 2;
		PoolDrumsStyle.maxUpgradeLevel = 1;
		PoolCymbalsStyle.maxUpgradeLevel = 1;
		PoolMarimbaStyle.maxUpgradeLevel = 1;
		
		-- Deco Stations
		table.insert(retGroup, 
			SetStyle(PoolUmbrellaStyle)
		);
			
		table.insert(retGroup, 
			PoolUmbrella{
				transformMatrix = {x = 280, y = 340},
				upgradeID = kUpgradePoolDeco1,
				upgradeLevel = 0,
			}
		);
		
		table.insert(retGroup, 
			SetStyle(PoolGardenStyle)
		);
		
		table.insert(retGroup, 
			PoolGarden{
				transformMatrix = {x = 884, y = 325},
				upgradeID = kUpgradePoolDeco2,
				upgradeLevel = 0,
			}
		);
			
		table.insert(retGroup, 
			SetStyle(PoolPlantsStyle)
		);
			
		table.insert(retGroup, 
			PoolPlants{
				transformMatrix = {x = 72, y = 320},
				upgradeID = kUpgradePoolDeco3,
				upgradeLevel = 0,
			}
		);
			
		table.insert(retGroup, 
			SetStyle(PoolDrumsStyle)
		);
			
		table.insert(retGroup, 
			PoolDrums{
				transformMatrix = {x = 920, y = 200},
				upgradeID = kUpgradePoolRadio3,
				upgradeLevel = 1,
				name = "drums",
			}
		);
		
		table.insert(retGroup, 
			BlgBitmap{
				image="level/core/club/textures/female2_club",
				center = {x = 20, y = 105},
				transformMatrix = {x = 865, y = 165},
				playAnim = "Idle",
				name = "Drummer",
			}
		);
		
		table.insert(retGroup, 
			SetStyle(PoolDrumNoticeStyle)
		);
			
		table.insert(retGroup, 
			PoolDrumNotice{
				transformMatrix = {x = 920, y = 160},
				zLayer = 210,
				name = "CooldownNotice",
			}
		);
		
		table.insert(retGroup,
			BlgParticles{
				name = "DrummerParticles",
				path = "level/core/common/particles/pfx_drummer_sleep.lua",
				transformMatrix = {x = 925, y = 90},
				zLayer = 166,
			}
		);
		
	end
	
	-- Cooking Station
	if (devLevel > 1) then
	
		table.insert(retGroup, 
			SetStyle(PoolCookingStationStyle)
		);
		
		table.insert(retGroup,
			PoolCookingStation{
				transformMatrix = {x = 680, y = 196},
				zLayer = 175,
				name = "cooking",
				upgradeID = kUpgradePoolDispCooking,
				upgradeLevel = 1,
			}
		);
		
		table.insert(retGroup, 
			SetStyle(PoolCombinationStationStyle)
		);
		
		table.insert(retGroup,
			PoolCombinationStation{
				transformMatrix = {x = 768, y = 196},
				zLayer = 175,
				name = "combination",
				upgradeID = kUpgradePoolDispCombination,
				upgradeLevel = 1,
			}
		);
		
		-- drums
		table.insert(retGroup, 
			SetStyle(PoolMarimbaStyle)
		);
			
		table.insert(retGroup, 
			PoolMarimba{
				transformMatrix = {x = 850, y = 200},
				upgradeID = kUpgradePoolRadio1,
				upgradeLevel = 0,
			}
		);
			
		table.insert(retGroup, 
			SetStyle(PoolCymbalsStyle)
		);
			
		table.insert(retGroup, 
			PoolCymbals{
				transformMatrix = {x = 980, y = 200},
				upgradeID = kUpgradePoolRadio2,
				upgradeLevel = 0,
			}
		);
		
	end
	
	-- Upgrades Tier 2
	if (devLevel > 2) then
	
		BaseItemStationStyle.maxUpgradeLevel = 3;
		PoolSunChairStyle.maxUpgradeLevel = 3;
		PoolStyle.maxUpgradeLevel = 3;
		PoolBoyStyle.maxUpgradeLevel = 3;
		PoolCookingStationStyle.maxUpgradeLevel = 3;
		PoolCombinationStationStyle.maxUpgradeLevel = 3;
		PoolDrumsStyle.maxUpgradeLevel = 2;
		PoolCymbalsStyle.maxUpgradeLevel = 2;
		PoolMarimbaStyle.maxUpgradeLevel = 2;
		
		table.insert(retGroup, 
			SetStyle(PoolSunChairStyle)
		);
		
		table.insert(retGroup,
			PoolSunChair{
				transformMatrix = {x = 152, y = 368},
				zLayer = 367,
				name = "chair4",
				upgradeID = kUpgradePoolChair4,
				upgradeLevel = 0,
			}
		);
		
		table.insert(retGroup,
			PoolSunChair{
				transformMatrix = {x = 536, y = 368},
				zLayer = 367,
				name = "chair5",
				upgradeID = kUpgradePoolChair5,
				upgradeLevel = 0,			
			}
		);
		
	end
	
	-- Upgrades Tier 3
	if (devLevel > 4) then
		
		BaseItemStationStyle.maxUpgradeLevel = 4;
		PoolSunChairStyle.maxUpgradeLevel = 4;
		PoolStyle.maxUpgradeLevel = 3;
		PoolBoyStyle.maxUpgradeLevel = 4;
		PoolCookingStationStyle.maxUpgradeLevel = 4;
		PoolCombinationStationStyle.maxUpgradeLevel = 4;
		PoolDrumsStyle.maxUpgradeLevel = 2;
		PoolCymbalsStyle.maxUpgradeLevel = 2;
		PoolMarimbaStyle.maxUpgradeLevel = 2;
		
		table.insert(retGroup, 
			SetStyle(PoolSunChairStyle)
		);
		
		table.insert(retGroup,
			PoolSunChair{
				transformMatrix = {x = 56, y = 368},
				zLayer = 367,
				name = "chair6",
				upgradeID = kUpgradePoolChair6,
				upgradeLevel = 0,
			}
		);
		
	end
	
	-- Waiters
	table.insert(retGroup,
		SetStyle(PoolBoyStyle)
	);
	
	table.insert(retGroup,
		Summer{
			transformMatrix = {x = 680, y = 288},
			upgradeID = kUpgradePoolWaiter1,
			upgradeLevel = 1,
		}
	);
		
	return Group(retGroup);
	
end