-- effect designed by Martini, adapted by Krys to use generic DEFAULT_SPRITES and annotated with comments

local splash -- group for murky particles

-- murky particle init function
local function splashfx(mesh) -- mesh index is passed to function

	local part = createSpritePart (splash) -- create particle of splash group
	
	part.emitterIndex = getLaraIndex() -- get Lara's tomb4 index
	part.emitterNode = mesh -- attach particle to specified mesh
	
	part.spriteIndex = 0 -- smoke sprite
	
	part.lifeSpan = 85
	
	part.fadeIn = 5
	part.fadeOut = 30
	
	part.colStart.r = randomInt (7, 12) 
	part.colStart.g = randomInt (22, 36)
	part.colStart.b = randomInt (22, 42)
	part.sizeStart = randomFloat (32, 128)
	part.sizeEnd = randomFloat (128, 140)
	
	part.rot = degToRad( randomInt(0, 360) )
	part.rotVel = randomFloat (-0.01, 0.01)
	
	part.vel.x = randomFloat (-1, 1)
	part.vel.z = randomFloat (-1, 1)
	
	part.accel.x = -part.vel.x / part.lifeSpan
	part.accel.y = 0.07
	part.accel.z = -part.vel.z / part.lifeSpan
	
	part.pos.x = randomFloat (-32, 32)
	part.pos.y = randomFloat (-32, 32)
	part.pos.z = randomFloat (-32, 32)
	
end

local bubble -- group for bubble particles

-- bubble particle init function
local function bubblefx(mesh) -- mesh index is passed to function

	local part = createSpritePart (bubble)
	
	part.emitterIndex = getLaraIndex()  -- get Lara's tomb4 index
	part.emitterNode = mesh -- attach particle to specified mesh
	
	part.spriteIndex = 13 -- bubble sprite
	
	part.lifeSpan  = 45
	
	part.fadeIn = 5
	part.fadeOut= 20
	
	part.sizeStart = 10 + randomFloat (-10, 20)
	part.sizeEnd   = part.sizeStart
	
	part.colStart.r = 45 + randomInt (-5, 60)
	part.colStart.g = 60 + randomInt (-5, 60)
	part.colStart.b = 60 + randomInt (-5, 60)
	part.colEnd   = part.colStart
	
	part.vel.y = randomFloat (1, 2)
	part.vel.x = randomFloat (-8, 8)
	part.vel.z = randomFloat (-8, 8)
	
	part.accel.x = -part.vel.x / part.lifeSpan
	part.accel.y = -part.sizeStart * 0.01
	part.accel.z = -part.vel.z / part.lifeSpan
	
	part.pos.x = randomFloat (-32, 32)
	part.pos.z = randomFloat (-32, 32)
	part.pos.y = randomFloat (-15, 15)
	
end

-- this is the main function responsible to attaching particles during specific Lara swim animations
local function swimEffects()
	
	-- check if Lara is performing a particular animation and attach effects accordingly
	
	if Lara.animNumber == 109 then -- underwater idle to swim
	
		splashfx(3) -- attach splash to left foot (mesh = 3)
		splashfx(6) -- attach splash to right foot (mesh = 6)
		splashfx(10) -- attach splash to right hand (mesh = 10)
		splashfx(13) -- attach splash to left hand (mesh = 13)
		
		bubblefx(3) -- attach bubble to left foot (mesh = 3)
		bubblefx(6) -- attach bubble to right foot (mesh = 6)
		bubblefx(10) -- attach bubble to right hand (mesh = 10)
		bubblefx(13) -- attach bubble to left hand (mesh = 13)
	end
	
	-- etc for other swim animations
	
	if Lara.animNumber == 115 then
		splashfx(3)
		splashfx(6)
		splashfx(10)
		splashfx(13)
		
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)
	end

	if Lara.animNumber == 116 then -- surface swim forward
		splashfx(3)
		splashfx(6)
		splashfx(10)
		splashfx(13)
		
		bubblefx(3)
		bubblefx(6)	
	end
	
	if Lara.animNumber == 141 then -- surface swim backward
		splashfx(3)
		splashfx(6)
		splashfx(10)
		splashfx(13)
		
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)	
	end
	
	if Lara.animNumber == 143 then -- surface swim left
		splashfx(3)
		splashfx(6)
		splashfx(10)
		splashfx(13)
		
		bubblefx(3)
		bubblefx(6)
	end
	
	if Lara.animNumber == 144 then -- surface swim right
		splashfx(3)
		splashfx(6)
		splashfx(10)
		splashfx(13)
		
		bubblefx(3)
		bubblefx(6)
	end

	if Lara.animNumber == 86 then -- underwater swim loop
		splashfx(3)
		splashfx(6)
		splashfx(10)
		splashfx(13)
		
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)
	end
	
	if Lara.animNumber == 203 then -- underwater roll start
		splashfx(3)
		splashfx(6)
		splashfx(10)
		splashfx(13)

		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)
	end
	
	if Lara.animNumber == 205 then -- underwater roll end
		splashfx(3)
		splashfx(6)
		splashfx(10)
		splashfx(13)
		
		bubblefx(3)
		bubblefx(6)
		bubblefx(10)
		bubblefx(13)	
	end

end

-- particle group creation

splash = createGroup(swimEffects, nil) -- all swim effects are managed by splash group init function swimEffects()

bubble = createGroup(nil, nil) -- bubble group with no init function