/*

EFF-ZERO BOOST, by Angular

Sets the base boost power stupid high according to a map header.

Slap this in your map SOC to use 'em:
---
Lua.fzero = 1 <- Run this dumb thing
Lua.fzerospeed = 150 <- Strength of boost power, % of original speed [so 100 = 100%; no change, 150 = 150% speed, pretty fast]
---

Also includes recharge vfx for certain sectors. Be sure to set it to 9, or whatever. Currently there's no other mechanical effects, we just think it looks neat. marge.png

Originally for Marsh's F-Zero maps - as if you think F-Zero's getting another game. I know. I cry too.

*/

freeslot("sfx_fzchg", "sfx_fzchgl") --bwoooooooop

local p, pks, fzBase, newx, newy, newz, newangle, bwoopMo
local ccoriginal = FRACUNIT
local bwoopFreq = 6 --make smaller for more bwoops

local function fZero_boost(mo)
	if not(mo and mo.valid and mo.player) then return end
	
	p = mo.player
	pks = mo.player.kartstuff
	
    if mapheaderinfo[gamemap] and mapheaderinfo[gamemap].fzero then
		
		--boostpower is dangerous
		if mapheaderinfo[gamemap].fzerospeed 
		
			ccoriginal = FRACUNIT
			fzBase = mapheaderinfo[gamemap].fzerospeed*FRACUNIT/100
		
			pks[k_accelboost] = max($, mapheaderinfo[gamemap].fzero/15) --Accel adjust
		
			--this takes places in the playerthinker so i'll handle stacking in other places
			
			if pks[k_bananadrag] > TICRATE 
				fzBase = (4*FRACUNIT)/5 -- Forced vanilla value
				ccoriginal = fzBase 
			end
					
			if pks[k_offroad] > 0 and not(pks[k_invincibilitytimer] or pks[k_hyudorotimer] or pks[k_sneakertimer]) 
				fzBase = FixedDiv(ccoriginal, pks[k_offroad] + FRACUNIT) 
			end
				
			pks[k_boostpower] = fzBase --Complete rewrite
			--print("YOU GOT BOOST POWER " .. fzBase)
			
		end
		
		--recharge panels! these could be an actual mechanic in the future. you heard it here first.
		if P_PlayerTouchingSectorSpecial(p, 1, 9) then
			
			--hacky sfx
			if not(mo.recharge) then
				mo.recharge = true
				S_StartSound(mo, sfx_fzchg)
			else
				if not(S_SoundPlaying(mo, sfx_fzchg) or S_SoundPlaying(mo, sfx_fzchgl)) then
					S_StartSound(mo, sfx_fzchgl)
				end
			end
			
			--Let's steal the respawn VFX from hardcode but minus all the respawn mechanics lol
			if leveltime%bwoopFreq == 0 then
				
				--I feel like I've lost innocence knowing this is just 8 mobjs that fly up what the fuck
				for i = 0, 8 do

					newangle = FixedAngle(((360/8)*i)*FRACUNIT);
					newx = mo.x + P_ReturnThrustX(mo, newangle, 31<<FRACBITS)
					newy = mo.y + P_ReturnThrustY(mo, newangle, 31<<FRACBITS)
					if (mo.eflags & MFE_VERTICALFLIP)
						newz = mo.z + mo.height
					else
						newz = mo.z
					end
					bwoopMo = P_SpawnMobj(newx, newy, newz, MT_DEZLASER);
					if (mo.eflags & MFE_VERTICALFLIP)
						bwoopMo.eflags = $ & MFE_VERTICALFLIP
					end
					bwoopMo.target = mo
					bwoopMo.fzero = true --differentiates itself in the mobjthinker
					bwoopMo.angle = newangle+ANGLE_90
					bwoopMo.xOff, bwoopMo.yOff = mo.x - bwoopMo.x, mo.y - bwoopMo.y
					bwoopMo.momz = (8<<FRACBITS) * P_MobjFlip(mo)
					P_SetScale(bwoopMo, bwoopMo.target.scale)
					
				end
			
			end
			
		else
			mo.recharge = false
			S_StopSoundByID(mo, sfx_fzchgl)
			S_StopSoundByID(mo, sfx_fzchg)
		end
		
	end
	
end

addHook("MobjThinker", fZero_boost, MT_PLAYER)

--oh god dammit
local function fzero_Follow(mo) 
	if mo and mo.valid and mo.fzero and mo.target
		P_TeleportMove(mo, mo.target.x + mo.xOff, mo.target.y + mo.yOff, mo.z)
		--make interp cry or show up in front of you? up to you.
		--mo.momx, mo.momy = mo.target.momx, mo.target.momy
	end
end

addHook("MobjThinker", fzero_Follow, MT_DEZLASER)