//For the Smug Dance
//...even though it doesn't seem like it does anything
addHook("ShouldJingleContinue", function(player, musname)
	if true return end
	if musname != "MLSSBT" return end
	if player and player.mo and player.mo.skin == "dirk" and player.dirkandwhirl
		return true
	else
		return false
	end
end)

//Main Thinker	
addHook("PlayerThink", function(player)
	if player.mo and player.mo.valid
	and (player.mo.skin == "dirk" or player.mo.skin == "whirl")
	and not player.powers[pw_super]
		//Detect when we press Toss Flag
		if not (player.cmd.buttons & BT_TOSSFLAG)
			player.dirktosstapready = true
			player.dirktosstapping = false
		elseif player.dirktosstapready 
		and not (player.hugging) then
			player.dirktosstapping = true
			player.dirktosstapready = false
		else
			player.dirktosstapping = false
		end
		
		//Disallows the rest of the code in certain circumstances
		if P_PlayerInPain(player)
		or (player.pflags & PF_SLIDING)
		or (player.pflags & PF_SHIELDABILITY)
		or player.powers[pw_carry] != CR_NONE
		or player.spectator
		or player.exiting
		or player.playerstate != PST_LIVE
		or not player.mo.health
		or player.panim == PA_PAIN
		or player.mo.state == S_PLAY_FALL
		or player.powers[pw_super] == 1
		or player.iseggrobo
		or (player.dirk_frozen)
		or (player.gotflag or player.gotcrystal)
		or player.powers[pw_nocontrol]
		or player.whirltornadojump
		or player.whirlram
		or player.mo.icesurf
			if player.dirkandwhirl
				if player.mo.state == S_PLAY_CLIMB
					player.mo.state = S_PLAY_STND
				end
				player.dirkandwhirl = false
				P_RestoreMusic(player)
			end
		return end
		
		//Dirk and Whirl Dance
		if player.dirkandwhirl
			player.panim = PA_DASH
			if not P_IsObjectOnGround(player.mo)
			or player.dirktosstapping
				if player.mo.state == S_PLAY_CLIMB
					player.mo.state = S_PLAY_STND
				end
				player.dirkandwhirl = false
				P_RestoreMusic(player)
			else
				if player.mo.state != S_PLAY_CLIMB
					player.mo.state = S_PLAY_CLIMB
				end
				player.mo.tics = min($,3)
				player.pflags = $|PF_FULLSTASIS
			end
		elseif P_IsObjectOnGround(player.mo) and player.dirktosstapping
			player.dirkandwhirl = true
			P_PlayJingleMusic(player, "MLSSBT", nil, true, JT_OTHER)
		end
	else
		if player.dirkandwhirl
			if player.mo.state == S_PLAY_CLIMB
				player.mo.state = S_PLAY_STND
			end
			player.dirkandwhirl = false
			P_RestoreMusic(player)
		end
	end
end)