 _LOADED["scripts/styles/clubstyle.lua"] = nil;
 
require("scripts/cpscript.lua");
require("scripts/styles/clubstyle.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/club/textures/deco_sky",
			center = {x = 0, y = 0},
			transformMatrix = {x = 0, y = 0},
		},
		
		-------------------------------------	
		-- Animated Decos
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Club_Cloud1Style),
			BlgBitmap {
				--alpha = 0.5,
				image="level/core/club/textures/deco_cloud1",
				center = {x = 0, y = 0},
				transformMatrix = {x = -110.6, y = 4},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Club_Cloud2Style),
			BlgBitmap {
				--alpha = 0.5,
				image="level/core/club/textures/deco_cloud2",
				center = {x = 0, y = 0},
				transformMatrix = {x = 300, y = 6.5},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Club_Cloud3Style),
			BlgBitmap {
				--alpha = 0.5,
				image="level/core/club/textures/deco_cloud3",
				center = {x = 0, y = 0},
				transformMatrix = {x = -191.6, y = -13.6},
			},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			SetStyle(Club_Cloud4Style),
			BlgBitmap {
				--alpha = 0.5,
				image="level/core/club/textures/deco_cloud4",
				center = {x = 0, y = 0},
				transformMatrix = {x = -276, y = -2.1},
			},
		},
		
		-- foreground assets
		BlgBitmap {
			image="level/core/club/textures/deco_beach_bg",
			center = {x = 0, y = 0},
			transformMatrix = {x = 0, y = 18},
		},
		
		BlgMovieClip{
			repeatCount = 0,
			zLayer = 1024,
			SetStyle(PalmTrunkStyle),
			BlgContainer{
				transformMatrix = {x = 120, y = 220, scaleX = -1},
				BlgBitmap {
					image="level/core/club/textures/deco_palm_trunk",
					center = {x = 35, y = 218},
					transformMatrix = {x = 0, y = 0},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf1Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_1",
						center = {x = 40, y = 100},
						transformMatrix = {x = -31, y = -210},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf2Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_2",
						center = {x = 125, y = 68},
						transformMatrix = {x = -31, y = -210},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf3Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_3",
						center = {x = 4, y = 44},
						transformMatrix = {x = -31, y = -210},
					},
				},
			},	
		},
		
		BlgMovieClip{
			repeatCount = 0,
			zLayer = 1024,
			BlgContainer{
				transformMatrix = {x = 600, y = 205},
				BlgBitmap {
					image="level/core/club/textures/deco_palm_trunk",
					center = {x = 35, y = 218},
					transformMatrix = {x = 0, y = 0},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf1Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_1",
						center = {x = 40, y = 100},
						transformMatrix = {x = -31, y = -210},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf2Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_2",
						center = {x = 125, y = 68},
						transformMatrix = {x = -31, y = -210},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf3Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_3",
						center = {x = 4, y = 44},
						transformMatrix = {x = -31, y = -210},
					},
				},
			},	
		},
		
		BlgBitmap {
			image="level/core/club/textures/background",
			center = {x = 0, y = 0},
			transformMatrix = {x = 0, y = 135},
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_railing",
			center = {x = 512, y = 136},
			transformMatrix = {x = 512, y = 145},
			zLayer = 4,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_fire",
			center = {x = 0, y = 0},
			transformMatrix = {x = 594, y = -8},
			zLayer = 5,
			playAnim = "Fire2",
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_fire",
			center = {x = 0, y = 0},
			transformMatrix = {x = 494, y = -8},
			zLayer = 5,
			playAnim = "Fire1",
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_fire",
			center = {x = 0, y = 0},
			transformMatrix = {x = 394, y = -8},
			zLayer = 5,
			playAnim = "Fire3",
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_fire",
			center = {x = 0, y = 0},
			transformMatrix = {x = 292, y = -8},
			zLayer = 5,
			playAnim = "Fire2",
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_fire",
			center = {x = 0, y = 0},
			transformMatrix = {x = 194, y = -8},
			zLayer = 5,
			playAnim = "Fire1",
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_fire",
			center = {x = 0, y = 0},
			transformMatrix = {x = 92, y = -8},
			zLayer = 5,
			playAnim = "Fire2",
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_fire",
			center = {x = 0, y = 0},
			transformMatrix = {x = -8, y = -8},
			zLayer = 5,
			playAnim = "Fire3",
		},	
			
	};

	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
		
		BlgParticles {
			path = "level/core/club/particles/club_fire.lua",
			transformMatrix = {x = 18, y = 635},
			center = {x = 0, y = 0},
			zLayer = 800,
			
		},
		
		BlgParticles {
			path = "level/core/club/particles/club_fire.lua",
			transformMatrix = {x = 370, y = 650},
			center = {x = 0, y = 0},
			zLayer = 800,
			
		},
		
		BlgParticles {
			path = "level/core/club/particles/club_fire.lua",
			transformMatrix = {x = 673, y = 644},
			center = {x = 0, y = 0},
			zLayer = 800,
			
		},
		
		BlgParticles {
			path = "level/core/club/particles/club_fire.lua",
			transformMatrix = {x = 1021, y = 635},
			center = {x = 0, y = 0},
			zLayer = 800,
			
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_bridge_bottom",
			center = {x = 512, y = 134},
			transformMatrix = {x = 512, y = 768},
		},	
		
		BlgBitmap {
			image="level/core/club/textures/deco_plant",
			center = {x = 41, y = 87},
			transformMatrix = {x = 0, y = 160},
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_plant2",
			center = {x = 27, y = 85},
			transformMatrix = {x = 128, y = 160},
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_plant3",
			center = {x = 24, y = 77},
			transformMatrix = {x = 256, y = 160},
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_plant",
			center = {x = 41, y = 87},
			transformMatrix = {x = 384, y = 160},
		},
		
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 155, y = 230},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 227,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 315, y = 207},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 211,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 424, y = 196},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 196,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 597, y = 205},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 194,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 756, y = 202},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 217,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 930, y = 219},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 227,
		},
		
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 11, y = 584},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 584,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 121, y = 617},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 617,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 269, y = 656},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 656,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 455, y = 671},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 671,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 653, y = 672},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 672,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 820, y = 659},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 659,
		},
		
		BlgBitmap {
			image="level/core/club/textures/deco_groundlight",
			center = {x = 10, y = 95},
			transformMatrix = {x = 954, y = 621},
			blendMode = kBlendAdditiveAlpha,
			zLayer = 621,
		},
		
		BlgMovieClip{
			repeatCount = 0,
			zLayer = 1024,
			SetStyle(PalmTrunkStyle),
			BlgContainer{
				transformMatrix = {x = 100, y = 932, scaleX = -1},
				BlgBitmap {
					image="level/core/club/textures/deco_palm_trunk",
					center = {x = 35, y = 218},
					transformMatrix = {x = 0, y = 0},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf1Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_1",
						center = {x = 40, y = 100},
						transformMatrix = {x = -31, y = -210},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf2Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_2",
						center = {x = 125, y = 68},
						transformMatrix = {x = -31, y = -210},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf3Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_3",
						center = {x = 4, y = 44},
						transformMatrix = {x = -31, y = -210},
					},
				},
			},	
		},
		
		BlgMovieClip{
			repeatCount = 0,
			zLayer = 1024,
			BlgContainer{
				transformMatrix = {x = 924, y = 948},
				BlgBitmap {
					image="level/core/club/textures/deco_palm_trunk",
					center = {x = 35, y = 218},
					transformMatrix = {x = 0, y = 0},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf1Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_1",
						center = {x = 40, y = 100},
						transformMatrix = {x = -31, y = -210},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf2Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_2",
						center = {x = 125, y = 68},
						transformMatrix = {x = -31, y = -210},
					},
				},
				
				BlgMovieClip{
					repeatCount = 0,
					SetStyle(PalmLeaf3Style),				
					BlgBitmap {
						image="level/core/club/textures/deco_palm_leaf_3",
						center = {x = 4, y = 44},
						transformMatrix = {x = -31, y = -210},
					},
				},
			},	
		},
	};

	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;
	
	BaseItemStationStyle.maxUpgradeLevel = 1;
	ClubChairStyle.maxUpgradeLevel = 1;
	DanceFloorStyle.maxUpgradeLevel = 1;
	WaiterStyle.maxUpgradeLevel = 1;
	ClubCookingStationStyle.maxUpgradeLevel = 1;
	ClubCombinationStationStyle.maxUpgradeLevel = 1;
	ClubDrumsStyle.maxUpgradeLevel = 1;
	ClubCymbalsStyle.maxUpgradeLevel = 1;
	ClubMarimbaStyle.maxUpgradeLevel = 1;
		
	retGroup = {
	
		-------------------------------------
		-- Stations

		-- Dance Floor
		SetStyle(DanceFloorStyle),
		DanceFloor{
			transformMatrix = {x = 711, y = 621},
			zLayer = 0,
			upgradeLevel = 1,
			upgradeID = kUpgradeClubDanceFloor,
		},
		
		-- Chair Drag & Drop Area
		SetStyle(DragAreaStyle),
		DragArea{
			transformMatrix = {x = 288, y = 168},
			zLayer = 0,
		},

		-- Chairs
		SetStyle(ClubChairStyle),
		ClubChair{
			transformMatrix = {x = 56, y = 384},
			zLayer = 368,
			upgradeLevel = 1,
			upgradeID = kUpgradeClubChair1,
			name = "chair1",
		},
		ClubChair{
			transformMatrix = {x = 160, y = 384},
			zLayer = 368,
			upgradeLevel = 1,
			upgradeID = kUpgradeClubChair2,
			name = "chair2",
		},
		ClubChair{
			transformMatrix = {x = 56, y = 576},
			zLayer = 560,
			upgradeLevel = 1,
			upgradeID = kUpgradeClubChair3,
			name = "chair3",
		},
		
		-- Cuba Libre Stations
		SetStyle(CubaLibreStationStyle),
		CubaLibreStation{
			transformMatrix = {x = 416, y = 178},
			zLayer = 175,
			name = "cubaLibre",
			upgradeLevel = 1,
			upgradeID = kUpgradeClubDispCubaLibre,
		},
		
		-- Margarita Stations
		SetStyle(MargaritaStationStyle),
		MargaritaStation{
			transformMatrix = {x = 504, y = 178},
			zLayer = 175,
			name = "margarita",
			upgradeLevel = 1,
			upgradeID = kUpgradeClubDispMargarita,
		},

		-- Daiquiri Stations
		SetStyle(DaiquiriStationStyle),
		DaiquiriStation{
			transformMatrix = {x = 592, y = 178},
			zLayer = 175,
			name = "daiquiri",
			upgradeLevel = 1,
			upgradeID = kUpgradeClubDispDaiquiri,
		},
		
		SetStyle(GarbageCanStationStyle),
		GarbageCanStation{
			transformMatrix = {x = 344, y = 168},
			name = "garbage",
			zLayer = 167,
		},
		
		SetStyle(ClubDrumsStyle),
			
		ClubDrums{
			name = "drums",
			transformMatrix = {x = 920, y = 200},
			upgradeID = kUpgradeClubRadio3,
			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(ClubDrumNoticeStyle),
			
		ClubDrumNotice{
			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(ClubCombinationStationStyle)
		);
		
		table.insert(retGroup,
			ClubCombinationStation{
				transformMatrix = {x = 680, y = 178},
				zLayer = 175,
				name = "combination",
				upgradeID = kUpgradeClubDispCombination,
				upgradeLevel = 1,
			}
		);
		
	end
	
	-- Upgrades Tier 2
	if (devLevel > 1) then
	
		BaseItemStationStyle.maxUpgradeLevel = 2;
		ClubChairStyle.maxUpgradeLevel = 2;
		DanceFloorStyle.maxUpgradeLevel = 2;
		WaiterStyle.maxUpgradeLevel = 2;
		ClubCookingStationStyle.maxUpgradeLevel = 2;
		ClubCombinationStationStyle.maxUpgradeLevel = 2;
		ClubDrumsStyle.maxUpgradeLevel = 1;
		ClubCymbalsStyle.maxUpgradeLevel = 1;
		ClubMarimbaStyle.maxUpgradeLevel = 1;
		
		table.insert(retGroup, 
			SetStyle(ClubChairStyle)
		);
		
		table.insert(retGroup,
			ClubChair{
				transformMatrix = {x = 160, y = 576},
				zLayer = 560,
				upgradeLevel = 0,
				upgradeID = kUpgradeClubChair4,
				name = "chair4",
			}
		);
		
		-- Deco Stations
		table.insert(retGroup, 
			SetStyle(ClubRadioStyle)
		);
			
		table.insert(retGroup, 
			ClubRadio{
				transformMatrix = {x = 901, y = 331},
				upgradeID = kUpgradeClubDeco1,
				upgradeLevel = 0,
				zLayer = 250,
			}
		);
		
		table.insert(retGroup, 
			SetStyle(ClubFenceStyle)
		);
		
		table.insert(retGroup, 
			ClubFence{
				transformMatrix = {x = 134, y = 294},
				upgradeID = kUpgradeClubDeco2,
				upgradeLevel = 0,
			}
		);
			
		table.insert(retGroup, 
			SetStyle(ClubStoolsStyle)
		);
			
		table.insert(retGroup, 
			ClubStools{
				transformMatrix = {x = 641, y = 270},
				upgradeID = kUpgradeClubDeco3,
				upgradeLevel = 0,
				zLayer = 250,
			}
		);
		
	end
	
	-- Extra Chairs
	if (devLevel > 2) then
		
		table.insert(retGroup, 
			SetStyle(ClubChairStyle)
		);
		
		table.insert(retGroup,
			ClubChair{
				transformMatrix = {x = 264, y = 384},
				zLayer = 368,
				upgradeLevel = 0,
				upgradeID = kUpgradeClubChair5,
				name = "chair5",
			}
		);
		
		-- drums
		table.insert(retGroup, 
			SetStyle(ClubMarimbaStyle)
		);
			
		table.insert(retGroup, 
			ClubMarimba{
				transformMatrix = {x = 850, y = 200},
				upgradeID = kUpgradeClubRadio1,
				upgradeLevel = 0,
			}
		);
			
		table.insert(retGroup, 
			SetStyle(ClubCymbalsStyle)
		);
			
		table.insert(retGroup, 
			ClubCymbals{
				transformMatrix = {x = 980, y = 200},
				upgradeID = kUpgradeClubRadio2,
				upgradeLevel = 0,
			}
		);
		
	end
	
	-- Cooking station
	if (devLevel > 3) then
	
		BaseItemStationStyle.maxUpgradeLevel = 3;
		ClubChairStyle.maxUpgradeLevel = 3;
		DanceFloorStyle.maxUpgradeLevel = 3;
		WaiterStyle.maxUpgradeLevel = 3;
		ClubCookingStationStyle.maxUpgradeLevel = 3;
		ClubCombinationStationStyle.maxUpgradeLevel = 3;
		ClubDrumsStyle.maxUpgradeLevel = 2;
		ClubCymbalsStyle.maxUpgradeLevel = 2;
		ClubMarimbaStyle.maxUpgradeLevel = 2;
		
		table.insert(retGroup, 
			SetStyle(ClubCookingStationStyle)
		);
		
		table.insert(retGroup, 
			ClubCookingStation{
				transformMatrix = {x = 768, y = 178},
				zLayer = 175,
				name = "cooking",
				upgradeID = kUpgradeClubDispCooking,
				upgradeLevel = 1,
			}
		);
		
	end
	
	-- Upgrades Tier 3
	if (devLevel > 4) then
		
		BaseItemStationStyle.maxUpgradeLevel = 4;
		ClubChairStyle.maxUpgradeLevel = 4;
		DanceFloorStyle.maxUpgradeLevel = 3;
		WaiterStyle.maxUpgradeLevel = 4;
		ClubCookingStationStyle.maxUpgradeLevel = 4;
		ClubCombinationStationStyle.maxUpgradeLevel = 4;
		ClubDrumsStyle.maxUpgradeLevel = 2;
		ClubCymbalsStyle.maxUpgradeLevel = 2;
		ClubMarimbaStyle.maxUpgradeLevel = 2;
		
		table.insert(retGroup, 
			SetStyle(ClubChairStyle)
		);
		
		table.insert(retGroup,
			ClubChair{
				transformMatrix = {x = 264, y = 576},
				zLayer = 560,
				upgradeLevel = 0,
				upgradeID = kUpgradeClubChair6,
				name = "chair6",
			}
		);
		
	end

	-------------------------------------
	-- Waiters	
	table.insert(retGroup,
		SetStyle(WaiterStyle)
	);
	
	table.insert(retGroup,
		Kim{
			transformMatrix = {x = 368, y = 240},
			upgradeID = kUpgradeClubWaiter1,
			upgradeLevel = 1,
		}
	);
	
	return Group(retGroup);
	
end