--------------------------------------
-- Sound rules and parameters
--------------------------------------

--- helper functions

STARPULSE_VOLUME_ADJUST = 50

function MakeVariantList(prefix, maxIndex)

	out = ""

	for x = 1,maxIndex do
		out = out .. prefix .. x
		if (x < maxIndex) then out = out .. ";" end
	end
	
	return out
end

function MuteFlowers(element, muteLevel)

	element:ChangeOtherLoopVolume("dandelions", muteLevel)
	element:ChangeOtherLoopVolume("bluebell", muteLevel)
	element:ChangeOtherLoopVolume("willowherb", muteLevel)
	element:ChangeOtherLoopVolume("reed", muteLevel)
	element:ChangeOtherLoopVolume("seaweed", muteLevel)
	element:ChangeOtherLoopVolume("bogberries", muteLevel)
	element:ChangeOtherLoopVolume("white", muteLevel)
	element:ChangeOtherLoopVolume("chanterelle", muteLevel)
	element:ChangeOtherLoopVolume("anemone", muteLevel)
	element:ChangeOtherLoopVolume("pimpernel", muteLevel)
end

function MuteRain(element, incSfx)
	MuteRainX(element, incSfx, 0)
end

function MuteRainX(element, incSfx, muteLevel)
	element:ChangeOtherLoopVolume("rain drops", muteLevel)
	if (incSfx) then
		element:ChangeOtherLoopVolume("rain sfx", muteLevel)
	end
end

function MuteTerrains(element)
	MuteTerrainsX(element, muteLevel)
end

function MuteTerrainsX(element, muteLevel)
	element:ChangeOtherLoopVolume("terrain_grass", muteLevel)
	element:ChangeOtherLoopVolume("terrain_highland", muteLevel)
	element:ChangeOtherLoopVolume("terrain_ocean", muteLevel)
	element:ChangeOtherLoopVolume("terrain_snow", muteLevel)
end

function MuteAllOthers(element, incBgSfx)
	MuteAllOthersX(element, incBgSfx, 0)
end

function MuteAllOthersX(element, incBgSfx, muteLevel)
	element:ChangeOtherLoopVolume("trees", muteLevel) -- mute everything else..
	MuteTerrainsX(element, muteLevel)
	element:ChangeOtherLoopVolume("background", muteLevel)
	element:ChangeOtherLoopVolume("background B", muteLevel)
	element:ChangeOtherLoopVolume("crab loop", muteLevel)

	MuteFlowers(element, muteLevel)

	MuteRainX(element, false, muteLevel)

	if (incBgSfx) then
		element:ChangeOtherLoopVolume("background sfx", muteLevel)
	end

	element:ChangeOtherLoopVolume("moving", muteLevel)
	element:ChangeOtherLoopVolume("snow", muteLevel)
end

function SetElementTimeTags (element, timeSlots)
	--for slot in timeSlots
	for _,slot in pairs(timeSlots) 
	do
		if (type(slot) == "string")
		then -- element is just the name of a time-of-day
			element:AddTimeTag(slot, 1)
		else -- assume slot is a {name, vol} pair		
			if (type(slot) == "table") 
			then
				element:AddTimeTag(slot[1], slot[2])
			end
		end
	end
end

function SetElementAsDay (element)
	SetElementTimeTags(element, {{"dawn2", 0.5}, "dawn3", "preNoon", "noon", "postNoon", "dusk1", {"dusk2", 0.5}})
end

function SetElementAsDayAut (element)
	SetElementTimeTags(element, {{"dawn2", 0.5}, "dawn3", "preNoon", "noon", "postNoon", {"dusk1", 0.5}})
end

function SetElementAsNight (element)
	SetElementTimeTags(element, {"dusk3", "preMidnight", "midnight", "postMidnight", "dawn1"})
end

function SetElementDawnDayDuskNightVols (element, dawnVol, dayVol, duskVol, nightVol)
	SetElementTimeTags(element, {
	{"preMidnight", nightVol}, 
	{"midnight", nightVol}, 
	{"postMidnight", nightVol},
	{"dawn1", dawnVol}, 
	{"dawn2", dawnVol}, 
	{"dawn3", dawnVol}, 
	{"preNoon", dayVol}, 
	{"noon", dayVol}, 
	{"postNoon", dayVol}, 
	{"dusk1", duskVol}, 
	{"dusk2", duskVol},
	{"dusk3", duskVol}, 
	})
end


function MakeSquirrelSet (sqType, stepsets, volume)

	MakeOneShotElementVol("squirrel" .. sqType .. "_descent", 
						"sq_" .. sqType .. "_descent", 5, volume)
	MakeOneShotElementVol("squirrel" .. sqType .. "_ascent", 
						"sq_" .. sqType .. "_ascent", 5, volume)

	for _,set in pairs(stepsets) 
	do
		el = MakeOneShotElementSeq("squirrel" .. sqType .. "_step" .. set[1], 
			MakeVariantList("sq_" .. sqType .. "_" .. set[1], set[2]), 5)
		el:SetMaxVolume(volume)
	end
end

-- create and add elements
--------------------------------------

-- modulation is based on own current volume
-- element:ModulateOtherElements(ChangeVolume, -50, {"elem1", "elem2}) 


function MakeCommon()

	-- intro/outro


	-- if (GetSeason() == 0) then
		-- element = MakeLoopingElement("eyes closed", "open_tones_high");
		-- element:SetFadeTimes(0.1,10)
	-- end

	element = MakeOneShotElement("open eyes", "eyes_opening", 1)

	-- rain sfx - common
	element = MakeLoopingElement("rain sfx", "rain sfx")
	element:SetFadeTimes(2,5)
	element:ChangeOtherLoopVolume("trees", 0.5)
	element:ChangeOtherLoopVolume("blossom", 0.5)
	MuteFlowers(element, 0.5)
	
	-- variable movement on slopes sounds - different per season

	dawnSlopeVol = 0.25
	daySlopeVol = 1
	duskSlopeVol = 0.25
	nightSlopeVol = 0.25
	
	generalSlopeVol = 70
	
		
	if (GetSeason() == 0) then
		element = MakeLoopingElementQuick("slope_ascent1", "spring_slope_ascent", generalSlopeVol, 1.5, 5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		MuteTerrains(element)
		element = MakeLoopingElementQuick("slope_descent1", "spring_slope_descent", generalSlopeVol, 4, 4.5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		MuteTerrains(element)
	end
	
	if (GetSeason() == 1) then
	
		element = MakeLoopingElementQuick("slope_ascent1", "slope_ascent1", generalSlopeVol, 1, 5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		element = MakeLoopingElementQuick("slope_ascent2", "slope_ascent2", generalSlopeVol, 1.5, 5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		element = MakeLoopingElementQuick("slope_ascent3", "slope_ascent3", generalSlopeVol, 2, 5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		
		element = MakeLoopingElementQuick("slope_descent1", "slope_descent1", generalSlopeVol, 2, 5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		element = MakeLoopingElementQuick("slope_descent2", "slope_descent2", generalSlopeVol, 4, 4.5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		element = MakeLoopingElementQuick("slope_descent3", "slope_descent3", generalSlopeVol, 7, 4)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
	end
		
		
	if (GetSeason() == 2) then
		element = MakeLoopingElementQuick("slope_ascent1", "autumn_slope_ascent", generalSlopeVol, 1.5, 5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		MuteTerrains(element)
		element = MakeLoopingElementQuick("slope_descent1", "autumn_slope_descent", generalSlopeVol, 4, 4.5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		MuteTerrains(element)
	end
	
		
	if (GetSeason() == 3) then
		element = MakeLoopingElementQuick("slope_ascent1", "winter_slope_ascent", generalSlopeVol, 1.5, 5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		MuteTerrains(element)
		element = MakeLoopingElementQuick("slope_descent1", "winter_slope_descent", generalSlopeVol, 4, 4.5)
		SetElementDawnDayDuskNightVols(element,dawnSlopeVol,daySlopeVol,duskSlopeVol,nightSlopeVol)
		MuteTerrains(element)
	end
	
	-- rain music - common for now
	if (GetSeason() == 0) then
		element = MakeLoopingElement("rain drops", "rain drops")
		SetElementAsDay(element)
		element:SetFadeTimes(2,5)
		element:SetVolumeRange(0,200)
	end

	if (GetSeason() == 2) then 
		element = MakeLoopingElement("rain drops", "autumn_rain")
		SetElementAsDay(element)
		element:SetFadeTimes(2,5)
		element:SetVolumeRange(0,200)
	end

	-- creature one-shots
	--MakeOneShotElement("tempcritter_call","animals2/orn_a;animals2/orn_b;animals2/orn_d;animals2/orn_e",10)
	--MakeOneShotElement("tempcritter_respond","animals2/orn_f;animals2/orn_g;animals2/orn_h",10)
	MakeOneShotElement("wormpanic0","animals2/orn_c",3)
	MakeOneShotElement("wormpanic1","animals/animal6b",3)
	MakeOneShotElement("wormpanic2","rock_panic",5)
	MakeOneShotElement("wormpanic3","metal animal/metal_finger6",3)
	element = MakeOneShotElement("wormemerge","worm pop",10)
	--element:SetVolumeRange(0,50)

	if GetSeason() == 1 then
		SQUIRREL_VOL = 200
		
		MakeOneShotElementVol("squirrel_squeak", MakeVariantList("squirrel_squeak", 4), 5, 255)
		--MakeOneShotElementVol("squirrel_run", MakeVariantList("squirrel_run", 4), 5, SQUIRREL_VOL)
		MakeOneShotElementVol("squirrel_dance", MakeVariantList("squirrel_dance", 4), 5, SQUIRREL_VOL)
		
		el = MakeOneShotElementSeq("squirrel1_stepA", MakeVariantList("sqA", 6), 5)
		el:SetMaxVolume(SQUIRREL_VOL)
		el = MakeOneShotElementSeq("squirrel1_stepB", MakeVariantList("sqB", 9), 5)
		el:SetMaxVolume(SQUIRREL_VOL)
		el = MakeOneShotElementSeq("squirrel1_stepC", MakeVariantList("sqC", 5), 5)
		el:SetMaxVolume(SQUIRREL_VOL)
		el = MakeOneShotElementSeq("squirrel1_stepD", MakeVariantList("sqD", 7), 5)
		el:SetMaxVolume(SQUIRREL_VOL)
		
		MakeOneShotElementVol("squirrel1_descent", "squirrel_descent", 5, SQUIRREL_VOL)
		MakeOneShotElementVol("squirrel1_ascent", "squirrel_ascent", 5, SQUIRREL_VOL)
		
		-- el = MakeOneShotElementSeq("squirrel2_stepA", MakeVariantList("sq_2_A", 9), 5)
		-- el:SetMaxVolume(SQUIRREL_VOL)
		-- el = MakeOneShotElementSeq("squirrel2_stepB", MakeVariantList("sq_2_B", 7), 5)
		-- el:SetMaxVolume(SQUIRREL_VOL)
		-- el = MakeOneShotElementSeq("squirrel2_stepC", MakeVariantList("sq_2_C", 11), 5)
		-- el:SetMaxVolume(SQUIRREL_VOL)
		
		-- MakeOneShotElementVol("squirrel2_descent", "sq_2_descent", 5, SQUIRREL_VOL)
		-- MakeOneShotElementVol("squirrel2_ascent", "sq_2_ascent", 5, SQUIRREL_VOL)

		--MakeSquirrelSet("1", {{"A",6},{"B",9},{"C",5},{"D",7}}, SQUIRREL_VOL)
		MakeSquirrelSet("2", {{"A",9},{"B",7},{"C",11}}, SQUIRREL_VOL)
		MakeSquirrelSet("3", {{"A",14},{"B",6}}, SQUIRREL_VOL)
		MakeSquirrelSet("4", {{"A",8},{"B",6},{"C",6}}, SQUIRREL_VOL)
		
		MakeLoopingElementQuick("squirrel_dance_bg", "squirrel_dance_bg", 255, 0.05, 0.05)
		MakeLoopingElementQuick("squirrel_sqeak_bg", "squirrel_sqeak_bg", 255, 0.05, 0.05)
		el = MakeLoopingElementQuick("squirrel_intree", "squirrel_intree", SQUIRREL_VOL, 2, 1)
		SetElementAsDay(el)
		MakeLoopingElementQuick("squirrel_runloop", "squirrel_runloop", SQUIRREL_VOL, 1, 1)
	end
	
	if CheckAnimalInSeason("bat_roost") then
		MakeLoopingElementQuick("bats_slowest", "bats_slowest", 255, 3, 3)
		MakeLoopingElementQuick("bats_mid", "bats_mid", 255, 3, 3)
		MakeLoopingElementQuick("bats_fastest", "bats_fastest", 255, 3, 3)
	end
	
	if CheckAnimalInSeason("flashbug_swarm") then
		MakeOneShotElementSeq("firefly","fireflies/firefly1;fireflies/firefly2;fireflies/firefly3;fireflies/firefly4;fireflies/firefly5;fireflies/firefly6;fireflies/firefly3",10)
		--MakeLoopingElementQuick("firefly cluster", "firefly cluster", 100, 1, 1)
	end

	if CheckAnimalInSeason("owl") then
		MakeOneShotElement("owl","owl 1.wav;owl 2.wav;owl 3.wav;owl 4.wav;owl 5.wav;owl 6.wav;owl 7.wav;owl 8.wav",15)
		--MakeOneShotElement("owl flies","owl flies.wav;owl flies (cheesy or magic).wav",5)
	end

	if CheckAnimalInSeason("drumcrab_swarm") then
		
		if GetSeason() == 2 then
			element = MakeLoopingElement("crab loop", "autumn crabs") 
			element:SetFadeTimes(2,5)
		else
			element = MakeLoopingElement("crab loop", "cave_drum") 
			element:SetFadeTimes(2,5)
		end

		MakeOneShotElement("crab sneeze", "crab sneeze", 15)
		MakeOneShotElement("crab thud", "crab_sleeep1;crab_sleeep2;crab_sleeep3", 5)
		MakeOneShotElementVol("crab hop", MakeVariantList("crab hop", 8), 15, 100);
	end

	if CheckAnimalInSeason("frog_groupA") then
		MakeOneShotElementSeq("frog croak A", "frogA_croak_rain;frogA_croak1;frogA_croak2;frogA_croak3;frogA_croak4;frogA_croak5", 15)
		MakeOneShotElementSeq("frog croak B", "frogA_croak_rain;frogB_croak1;frogB_croak2;frogB_croak3;frogB_croak4;frogB_croak5", 15)
		MakeOneShotElementSeq("frog croak C", "frogC_croak_rain;frogC_croak1;frogC_croak2;frogC_croak3;frogC_croak4;frogC_croak5", 15)

		MakeOneShotElementSeq("frog hop A", MakeVariantList("frogA_hop", 5), 5)
		MakeOneShotElementSeq("frog hop B", MakeVariantList("frogB_shorthop", 7) ..";".. MakeVariantList("frogB_longhop", 4), 5)
		element = MakeOneShotElementSeq("frog hop C", "frogC_hop1;frogC_hop2;frogC_hop3", 5)
		--element:SetMaxVolume(70)
		MakeOneShotElementSeq("frog hop D", MakeVariantList("frogD_hop", 13), 5)
		MakeOneShotElementSeq("frog hop E", MakeVariantList("frogE_hop", 8), 5)

		MakeLoopingElement("frog rain A", "frogA_proximity") -- note these are "rain"
		MakeLoopingElement("frog rain B", "frogB_proximity") -- note these are "rain"
		MakeLoopingElement("frog prox C", "frogC_proximity")

		--MakeLoopingElement("frog rain A", "frogA_raintune")
		--MakeLoopingElement("frog rain B", "frogB_raintune")
		MakeLoopingElement("frog rain C", "frogC_raintune")
	end

	if CheckAnimalInSeason("mayfly_swarm") then
		if  GetSeason() == 2 then
			element = MakeLoopingElement("mayfly", "mayflies autumn") 
			element:SetFadeTimes(2,5)
			element:SetVolumeRange(0, 75)

			MakeOneShotElement("mayfly spasm", "dying_mayfly1;dying_mayfly2;dying_mayfly3;dying_mayfly4", 15)
		else
			element = MakeLoopingElement("mayfly", "mayflies") 
			element:SetFadeTimes(2,5)
			element:SetVolumeRange(0, 75)
		end
	end

	if CheckAnimalInSeason("guidething") then
		MakeOneShotElementSeq("guidesong",
		"foxhop/foxhop1;foxhop/foxhop2;foxhop/foxhop3;foxhop/foxhop4;foxhop/foxhop5;foxhop/foxhop6;foxhop/foxhop7;foxhop/foxhop8",
		10)
		MakeOneShotElementSeq("insect","insects/insect1a;insects/insect1b;insects/insect1c;insects/insect2a;insects/insect3a;insects/insect5a;insects/insect5b;insects/insect5c;insects/insect6a;insects/insect7a",10)

		MakeOneShotElementSeq("guiderock","rock1;rock2;rock3;rock4;rock5;rock6;rock7;rock6",10)
		
	end

	element = MakeLoopingElement("metal critter loop", "metal animal/bz_shake") 
	element:SetFadeTimes(2,5)

	if CheckAnimalInSeason("watsonfox") then
	
		MakeLoopingElementQuick("watson_proximity", "fox_proximity", 100, 2, 2)
		
		el = MakeOneShotElementSeq("watson_poke", MakeVariantList("dr_watson_poke", 2), 2)
		el:SetMaxVolume(100)
		
		el = MakeOneShotElementSeq("watson_pad", MakeVariantList("dr_watson_pad", 6), 5)
		el:SetMaxVolume(220)
	end
	
	if CheckAnimalInSeason("quail_flock1") then	
		el = MakeOneShotElement("partridge1_chirp", MakeVariantList("partridge_chirp", 4), 20)
		el:SetMaxVolume(150)
		MakeOneShotElement("partridge1_peck", MakeVariantList("partridge_peck", 6), 20)
		MakeLoopingElementQuick("partridge1_run", "partridge_run", 150, 0.5, 2.0)
		
		el = MakeOneShotElement("partridge2_chirp", MakeVariantList("partridge2_chirp", 4), 20)
		el:SetMaxVolume(150)
		MakeOneShotElement("partridge2_peck", MakeVariantList("partridge2_peck", 4), 20)
		MakeLoopingElementQuick("partridge2_run", "partridge2_run", 150, 0.5, 2.0)
	end

	if CheckAnimalInSeason("lovebird_pair") then

		prefix = "birdworms/"
		if GetSeason() == 2 then
			prefix = prefix .. "au_"
		end
		
		MakeLoopingElementQuick("birdworm_snoring", prefix .. "birdworm_snore_loop", 100, 0.5, 0.5)
		
		MakeLoopingElementQuick("birdworm_down", prefix .. "birdworm_down", 100, 0.5, 0.5)
		MakeLoopingElementQuick("birdworm_up", prefix .. "birdworm_up", 100, 0.5, 0.5)
		MakeLoopingElementQuick("birdworm_level1", prefix .. "birdworm_level1", 100, 0.5, 0.5)
		MakeLoopingElementQuick("birdworm_level2", prefix .. "birdworm_level2", 100, 0.5, 0.5)
		MakeLoopingElementQuick("birdworm_level3", prefix .. "birdworm_level3", 100, 0.5, 0.5)

	end

	if  GetSeason() == 1 then
		MakeLoopingElementQuick("sun_angry", "sun_angry", 100, 1, 2)
		MakeLoopingElementQuick("sun_blind", "sun_blind", 100, 1, 2)
	end

	-- season portal sounds
	if  GetSeason() ~= 3 then
		MakeLoopingElementQuick("portal_proximity", "stones/portal_proximity", 100, 3, 3)
	else
		element = MakeLoopingElementQuick("portal_proximity", "wintercolor3", 90, 3, 13)
		SetElementAsDay (element)
		element = MakeLoopingElementQuick("avenue_proximity", "wintercolor1", 90, 3, 13)
		SetElementAsDay (element)
	end
	--MakeLoopingElementQuick("portal_proximity_inactive", "stones/portal_proximity", 100, 3, 3)

	MakeLoopingElementQuick("magic_layer1", "stones/magic_layer1", 100, 3, 3)
	
	element = MakeLoopingElementQuick("magic_layer2", "stones/magic_layer2", 100, 3.5, 3)
	MuteAllOthers(element, false)

	MakeLoopingElementQuick("stones loop 2", "stones/stones loop 2", 100, 2.5, 3)

	element = MakeLoopingElementQuick("portal_build1", "stones/portal_build1", 100, 2.5, 3)
	MuteAllOthers(element, false)

	element = MakeLoopingElementQuick("portal_build2", "stones/portal_build2", 100, 1.5, 3)
	element:ChangeOtherLoopVolume("magic_layer1", 0.0)
	element:ChangeOtherLoopVolume("portal_build1", 0.0)
	element:ChangeOtherLoopVolume("portal_proximity", 0.0)

	MakeOneShotElement("portal_exit", "stones/portal_exit", 1)

	
	if  GetSeason() ~= 3 then		
		MakeLoopingElementQuick("meteor_bg", "meteors/meteor_fadeloop", 100, 0.5, 5)
		MakeLoopingElementQuick("meteor", "meteors/meteor_noise", 100, 0.5, 1.5)
	end
	
	if  GetSeason() == 2 then		
	
		MakeLoopingElementQuick("aurora", "aurora_layer3", 255, 1.5, 1.5);
		MakeLoopingElementQuick("aurora_lookup", "aurora_layer1", 255, 1.5, 1.5);
	
		element = MakeLoopingElement("melancholy1", "graveyard_thin")
		element:SetFadeTimes(10,10)
		SetElementAsDay (element)
		MuteAllOthers(element, false)

		element = MakeLoopingElement("melancholy2", "graveyard_thick")
		element:SetFadeTimes(3,6)
		SetElementAsDay (element)
	end
	
	-- if GetSeason() ~= 1 then
		-- element = MakeLoopingElement("spiritplace1", "machaut stones")
		-- element:SetFadeTimes(5,5)
		-- SetElementAsNight (element)
		-- MuteAllOthers(element, false)
		
		-- element = MakeLoopingElement("spiritplace2", "open_tones_low")
		-- element:SetFadeTimes(5,5)
		-- SetElementAsNight (element)

	-- end

	if  GetSeason() == 0 or GetSeason() == 1 then
		element = MakeLoopingElement("tower", "tower")
		element:SetFadeTimes(5,5)
		SetElementAsDay (element)
		element:SetVolumeRange(0, 100)
		MuteAllOthersX(element, false, 0.25)
		
		element = MakeLoopingElement("tower", "tower_night_winter")
		element:SetFadeTimes(5,5)
		SetElementAsNight (element)
		element:SetVolumeRange(0, 150)
		MuteAllOthersX(element, false, 0.25)

		element = MakeLoopingElement("village", "village")
		SetElementAsDay (element)
		element:SetFadeTimes(5,5)
		MuteAllOthers(element, false)	

	elseif  GetSeason() == 2 then		
	
		element = MakeLoopingElement("tower", "tower_night_winter")
		element:SetFadeTimes(5,5)
		SetElementAsDay (element)
		element:SetVolumeRange(0, 150)
		MuteAllOthersX(element, false, 0.25)

		element = MakeLoopingElement("village", "village")
		SetElementAsDay (element)
		element:SetFadeTimes(5,5)
		element:SetVolumeRange(0, 150)
		MuteAllOthers(element, false)	
		
	elseif  GetSeason() == 3 then

		element = MakeLoopingElementQuick("tower", "wintercolor4", 135, 5, 10)	
		SetElementAsDay (element)	
		element = MakeLoopingElementQuick("village", "wintercolor2", 135, 5, 10)
		SetElementAsDay (element)
		element = MakeLoopingElementQuick("bigtree", "bigtree_winter", 135, 5, 10)
		SetElementAsDay (element)
		--element = MakeLoopingElementQuick("melancholy1", "wintercolor2", 135, 5, 10)
		--SetElementAsDay (element)

	end

	-- terrain snow
	element = MakeLoopingElement("terrain_snow", "mountain wind")
	element:ChangeOtherLoopVolume("gusty wind", 0.25)
	element:SetFadeTimes(5,5)
	element:SetVolumeRange(0, 100)

	--element = MakeLoopingElement("gusty wind", "mountain wind")
	--element:SetFadeTimes(0.01,0.01)
	--element:SetVolumeRange(0, 100)

	-- these are in all seasons except winter due to being covered with ice/snow
	if  GetSeason() ~= 3 then

		-- water splashing
		element = MakeLoopingElement("water sfx", "water sfx")
		element:SetFadeTimes(2,2)
		element:SetVolumeRange(0, 100)
			
		element = MakeLoopingElement("terrain_ocean", "water tune")
		SetElementAsDay(element)
		element:SetFadeTimes(5,5)

		-- path
		--element = MakeLoopingElement("path", "slower path")
		--SetElementAsDay(element)
		--element:SetFadeTimes(3,2)
			
		MakeOneShotElementSeq("stone pass", MakeVariantList("stones/stone", 8),5)
		
	else
		-- disabled for now
		---MakeOneShotElement("stone pass", MakeVariantList("stones/stonebreath", 7),5)
	end



	-- village
	-- element = MakeLoopingElement("village", "cities loop - orch");
	-- element:SetFadeTimes(5,5);
	-- element:ChangeOtherLoopVolume("trees", 0.0)
	-- element:ChangeOtherLoopVolume("dandelions", 0.0)
	-- element:ChangeOtherLoopVolume("terrain_grass", 0.0)
	-- element:ChangeOtherLoopVolume("terrain_highland", 0.0)
	--- to add more here to cover all "terrain_" cues...


	-- statue stuff - may be removed/repurposed
	--element = MakeLoopingElement("statue", "reversed piano")
	--element:SetFadeTimes(10,5)

	if (GetSeason() ~= 2) then 
		element = MakeLoopingElement("starpulse 1", "poppies_layer1")
		element:SetFadeTimes(5,5)
		--SetElementTimeTags(element, {"preMidnight", "mid", "postMidnight"})
		SetElementAsNight(element)
		element:ChangeOtherLoopVolume("background", 0.0)
		element:ChangeOtherLoopVolume("background B", 0.0)
		element:SetVolumeRange(0, STARPULSE_VOLUME_ADJUST)

		element = MakeLoopingElement("starpulse 2", "poppies_layer2")
		element:SetFadeTimes(5,5)
		element:SetVolumeRange(0, STARPULSE_VOLUME_ADJUST)
	end

	if (GetSeason() == 3) then 
		element = MakeLoopingElement("in clouds", "cloudlayer_winter")
		element:SetFadeTimes(3,3)
		MuteRain(element,true)
		element:ChangeOtherLoopVolume("background", 0.0)
		element:ChangeOtherLoopVolume("background B", 0.0)
		element:SetVolumeRange(0, 50)

	else
		element = MakeLoopingElement("in clouds", "cloudlayer")	
		element:SetFadeTimes(3,3)
		MuteRain(element,true)
		element:ChangeOtherLoopVolume("background", 0.0)
		element:ChangeOtherLoopVolume("background B", 0.0)
		element:SetVolumeRange(0, 50)
	end

	
end


function MakeSpringNightLoops()
	-- night loops

	element = MakeLoopingElement("background sfx", "night/crickets")
	SetElementAsNight(element)
	element:SetFadeTimes(5,5)

	element = MakeLoopingElement("background B", "night/beethoven slow 1")
	SetElementTimeTags(element, {"dusk2"})
	element:SetFadeTimes(5,5)

	element = MakeLoopingElement("background B", "night/dense strings")
	SetElementTimeTags(element, {"dusk3"})
	element:SetFadeTimes(5,5)

	element = MakeLoopingElement("background B", "night/lo hum")
	SetElementTimeTags(element, {"preMidnight", {"midnight", 0.5}})
	element:SetFadeTimes(5,5)

	element = MakeLoopingElement("background B", "night/hi hum")
	SetElementTimeTags(element, {"preMidnight", {"midnight", 0.5}})
	element:SetFadeTimes(5,5)

	element = MakeLoopingElement("background B", "daphnis quick 2")
	SetElementTimeTags(element, {{"dawn1", 0.5}, "dawn2"})
	element:SetFadeTimes(5,5)

end

function MakeSpring()

element = MakeLoopingElementQuick("bigtree", "bigtree", 70, 3,5)
SetElementAsDay(element)
MuteAllOthers(element, true)

MakeSpringNightLoops()

-- misc loops
-- element = MakeLoopingElement("background", "chirping");
-- SetElementAsDay(element)
-- element:SetFadeTimes(5,5);

-- terrains
element = MakeLoopingElement("terrain_grass", "grass");
SetElementAsDay(element)
element:SetFadeTimes(5,5)

element = MakeLoopingElement("terrain_highland", "highlands");
SetElementAsDay(element)
element:SetFadeTimes(5,5)

-- objects

-- the system for object proximity cues will be updated soon....

element = MakeLoopingElement("trees", "trees for now")
SetElementAsDay(element)
element:SetFadeTimes(5,5)

element = MakeLoopingElement("trees", "chirping");
SetElementAsDay(element)
element:SetFadeTimes(5,5);

element = MakeLoopingElement("trees", "tree creaks")
SetElementAsNight(element)
element:SetFadeTimes(5,5)

element = MakeLoopingElement("blossom", "spring_blossoms")
SetElementAsDay(element)
MuteFlowers(element, 0)
element:SetVolumeRange(0, 80)
element:ChangeOtherLoopVolume("terrain_grass", 0)
--element:ChangeOtherLoopVolume("terrain_grass", amount)
element:SetFadeTimes(5,5)

element = MakeLoopingElement("dandelions", "yellow flowers")
SetElementAsDay(element)
element:SetFadeTimes(5,5)

--element = MakeOneShotElement("blossom_land", MakeVariantList("fly_melody", 7), 20)
--SetElementAsDay(element)
--element:SetMaxVolume(0, 70)

end

function MakeSummer()

element = MakeLoopingElementQuick("bigtree", "summer_bigtree", 110, 3,5)
SetElementTimeTags(element, {{"dawn3", 0.5}, "preNoon", "noon", "postNoon", {"dusk1", 0.5}})
MuteAllOthers(element, true)

-- summer night loops

element = MakeLoopingElement("background sfx", "night/crickets")
SetElementAsNight(element)
element:SetFadeTimes(5,5)

element = MakeLoopingElement("background B", "daphnis quick 2")
SetElementTimeTags(element, {{"dawn1", 0.5}, "dawn2"})
element:SetFadeTimes(5,5)

element = MakeLoopingElement("background B", "summer night tinkle")
SetElementTimeTags(element, {"dusk2", "dusk3", "preMidnight", {"mid", 0.5}})
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 70)

element = MakeLoopingElement("background B", "summer night pad")
SetElementTimeTags(element, {{"dusk2",0.5}, "dusk3", "preMidnight", {"mid", 0.5}})
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 70)

element = MakeLoopingElement("background B", "summer night lo")
SetElementTimeTags(element, {{"dusk2",0.33}, {"dusk3",0.66}, "preMidnight"})
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 70)

element = MakeLoopingElement("background B", "summer night hi")
SetElementTimeTags(element, {{"dusk2",0.33}, {"dusk3",0.66}, "preMidnight", {"mid", 0.5}})
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 70)

element = MakeLoopingElement("background B", "night/hi hum")
SetElementTimeTags(element, {"midnight", {"postMidnight", 0.5}})
element:SetFadeTimes(5,5)


element = MakeLoopingElement("bee_mellow", "bee_mellow") 
element:SetVolumeRange(0, 40)
element:SetFadeTimes(2,2)

element = MakeLoopingElement("bee_mad", "bee_mad") 
element:SetVolumeRange(0, 70)
element:SetFadeTimes(2,2)

element = MakeLoopingElement("cricket", "monotonous shiver") 
element:SetVolumeRange(0, 70)
element:SetFadeTimes(0.2,0.2)

------


element = MakeLoopingElement("background", "summer bass")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 70)

element = MakeLoopingElement("background", "summer drums 2")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 70)

-- element = MakeLoopingElement("background", "summer drums 3")
-- SetElementAsDay(element)
-- element:SetVolumeRange(0, 70)

element = MakeLoopingElement("dandelions", "summer flowers")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 70)


element = MakeLoopingElement("bluebell", "bluebells_plant")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 80)


element = MakeLoopingElement("willowherb", "cotton_candy_plant")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 125)


element = MakeLoopingElement("reed", "foxtails_plant")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 80)

--element = MakeLoopingElement("seaweed", "open_tones_low")
--SetElementAsDay(element)
--element:SetFadeTimes(5,5)
--element:SetVolumeRange(0, 70)

element = MakeLoopingElement("bogberries", "whitepixel_plant")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 92)

element = MakeLoopingElement("anemone", "white cup flowers")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 92)

element = MakeLoopingElement("terrain_grass", "summer synth")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 70)

element = MakeLoopingElement("terrain_highland", "summer highlands")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 95)

element = MakeLoopingElement("trees", "summer trees")
SetElementAsDay(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 70)

element = MakeLoopingElement("moving", "summer drums 1")
SetElementAsDay(element)
element:SetFadeTimes(3,2)
element:SetVolumeRange(0, 70)

end


function MakeAutumn()


element = MakeLoopingElement("background", "autumn bass")
SetElementAsDayAut(element)
element:SetFadeTimes(5,5)

--element = MakeLoopingElement("dandelions", "autumn bumpy synth")
--SetElementAsDay(element)
--element:SetFadeTimes(5,5)

element = MakeLoopingElement("trees", "autumn hi synth")
SetElementAsDayAut(element)
element:SetFadeTimes(5,5)

element = MakeLoopingElement("terrain_grass", "autumn pads")
SetElementAsDayAut(element)
element:SetFadeTimes(5,5)

element = MakeLoopingElement("terrain_highland", "autumn_highlands")
SetElementAsDayAut(element)
element:SetFadeTimes(5,5)

element = MakeLoopingElement("foxfire", "autumn bumpy synth")
SetElementAsNight(element)
element:SetFadeTimes(2,2)

element = MakeLoopingElement("chanterelle", "autumn_mushrooms")
SetElementAsDay(element)
--SetElementAsNight(element)
element:SetFadeTimes(2,2)

element = MakeLoopingElement("reed", "autumn_foxtails")
SetElementAsDayAut(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 80)

element = MakeLoopingElement("bogberries", "autumn_berries")
SetElementAsDayAut(element)
element:SetFadeTimes(5,5)
element:SetVolumeRange(0, 92)

element = MakeLoopingElement("trees", "tree creaks")
SetElementAsNight(element)
element:SetFadeTimes(5,5)

element = MakeLoopingElementQuick("bigtree", "autumn_bigtree_day", 135, 5, 10)
SetElementAsDay (element)

---- spirit chase loops ----

spiritVol = 255

element = MakeLoopingElementQuick("spirit_chimes", "spirit/spirit_chimes", spiritVol, 3, 3)
MuteAllOthers(element, true)
element:ChangeOtherLoopVolume("meteor_bg", 0.0)

element = MakeLoopingElementQuick("spirit_pad_drone", "spirit/spirit_pad_drone", spiritVol, 3, 3)
MuteAllOthers(element, true)
element:ChangeOtherLoopVolume("meteor_bg", 0.0)

element = MakeLoopingElementQuick("spirit_pad_swell", "spirit/spirit_pad_swell", spiritVol, 3, 3)
element = MakeLoopingElementQuick("spirit_chase", "spirit/spirit_chase", spiritVol, 3, 3)
element = MakeLoopingElementQuick("spirit_magic", "spirit/spirit_magic", spiritVol, 3, 3)


element = MakeLoopingElement("magic night", "magic/magic night")
SetElementAsNight(element)
element:SetFadeTimes(2,2)

element = MakeLoopingElement("magic night2", "magic/magic night2")
SetElementAsNight(element)
element:SetFadeTimes(2,2)

element = MakeLoopingElement("background B", "magic/magic sunset 2")
element:SetVolumeRange(0,220)
SetElementTimeTags(element, {"dusk2"})--{{"dusk2", 0.5}, "dusk3"})
element:SetFadeTimes(5,5)

element = MakeLoopingElement("background B", "magic/magic eve pulse")
SetElementTimeTags(element, {{"dusk2", 0.5}, "dusk3"})--{{"dusk2", 0.5}, "dusk3"})
element:SetFadeTimes(5,5)

element = MakeLoopingElement("background B", "magic/magic sunset")
SetElementTimeTags(element, {"dusk3"})--{{"dusk2", 0.5}, "dusk3"})
element:SetFadeTimes(5,5)

element = MakeLoopingElement("background B", "night/sunrise(daphnis2)_autumn")
SetElementTimeTags(element, {{"dawn1", 0.5}, "dawn2"})
element:SetFadeTimes(5,5)
	
vigvol = 255;
vigfadeout = 5;
element = MakeLoopingElementQuick("tower-in", "magic/night-tower-in", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("tower-out", "magic/night-tower-out", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("fairies-in", "magic/fairies-in", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("fairies-out", "magic/fairies-out", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("wood-in", "magic/wood-in", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("wood-out", "magic/wood-out", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("icy-in", "magic/icy-in", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("icy-out", "magic/icy-out", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("autumn-pulse-out", "magic/autumn-pulse-out", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("autumn-pulse-in", "magic/autumn-pulse-in", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("house-in", "magic/housevign-in", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("house-out", "magic/housevign-out", vigvol, 3, vigfadeout)
element = MakeLoopingElementQuick("rain-in", "magic/rain vign-in", vigvol, 3, vigfadeout * 0.66)
element = MakeLoopingElementQuick("rain-out", "magic/rain vign-out", vigvol, 3, vigfadeout * 0.66)

element = MakeLoopingElementQuick("fox-out", "dr_watson_loop", 100, 3, vigfadeout)

element = MakeLoopingElementQuick("bubble-out", "magic/magic dust bed", vigvol, 3, 4)

element = MakeLoopingElementQuick("postaurora-out", "night/lo hum", 100, 3, vigfadeout)

MakeLoopingElementQuick("fairies-intro", "magic/fairy intro", vigvol, 3, 5)
MakeLoopingElementQuick("ghostdustball", "magic/particle ball", vigvol, 3, 5)
MakeLoopingElementQuick("ghostdustball away", "magic/magic dust (away)", vigvol, 3, 5)
MakeLoopingElementQuick("ghostdusttrail", "magic/autumn starpulse particle jam", vigvol, 3, 5)

MakeOneShotElementVol("arpspirit", MakeVariantList("arpspirit/arp", 4), 15, 255)

MakeOneShotElementVol("guide_appear", "creature_emerge", 1, 255)

end


function MakeWinter()

element = MakeLoopingElement("winter flight 1", "monastery chant")
MuteAllOthers(element, true)
element:SetFadeTimes(0.5,3)

element = MakeOneShotElement("winter flight 2", "monastery hymn (ext)", 1)
--element:SetFadeTimes(5,5)

-- element = MakeLoopingElement("winter flight 3", "cloudlayer")
-- element:SetFadeTimes(5,5)

element = MakeLoopingElement("background", "winter bells");
SetElementAsDay(element)
element:SetFadeTimes(5,5);

element = MakeLoopingElement("background B", "winter dawn and dusk");
SetElementTimeTags(element, {{"dawn1", 0.5}, "dawn2", {"dawn3", 0.5}, {"dusk1", 0.5}, "dusk2", {"dusk3", 0.5}})
element:SetFadeTimes(5,5);

element = MakeLoopingElement("background B", "winter night cold");
SetElementAsNight(element)
element:SetFadeTimes(5,5);

element = MakeLoopingElement("trees", "winter trees")
SetElementAsDay(element)
element:SetFadeTimes(5,5)

element = MakeLoopingElement("terrain_ocean", "winter ice")
--SetElementAsDay(element)
element:SetFadeTimes(5,5)

-- snow sfx
element = MakeLoopingElement("snow", "winter snow")
element:SetFadeTimes(2,5)

end


if     GetSeason() == 0 then MakeSpring()
elseif GetSeason() == 1 then MakeSummer()
elseif GetSeason() == 2 then MakeAutumn()
else MakeWinter()
end

MakeCommon()