local drop_speed = FRACUNIT * 1030 / 100

local function Dropdash_Initialize(player)
  local mobj = player.mo
  player.OpenTricks.Dropdash = {["fall_time"] = 0, ["last_fall_time"] = 0, ["mini"] = 0}
end

local function Dropdash_Thinker(player)
  local mobj = player.mo

  if not mobj or not mobj.valid
    return
  end
  
  player.OpenTricks.Dropdash.last_fall_time = player.OpenTricks.Dropdash.fall_time
  
  OpenTricks_AutoMiniBoost(player, player.OpenTricks.Dropdash)
  
  if P_IsObjectOnGround(mobj)
    player.OpenTricks.Dropdash.fall_time = 0
  elseif player.OpenTricks.combo -- if was in the air and had any combo...
    player.OpenTricks.Dropdash.fall_time = $ + 1
  end
end

local function Dropdash_Success(player)
  local mobj = player.mo
  if (mobj.flags2 & MF2_OBJECTFLIP)
    mobj.momz = max(0, $) + drop_speed * player.OpenTricks.combo
  else
    mobj.momz = min(0, $) - drop_speed * player.OpenTricks.combo
  end
end

local function Dropdash_Landing(player)
  local mobj = player.mo
  S_StartSound(mobj, sfx_s23c)
  player.OpenTricks.Dropdash.mini = $ + ((30 + player.OpenTricks.Dropdash.last_fall_time) * (player.OpenTricks.combo ^ 2))
end

OPENTRICKS_ADD_FOURICONS("dropdash", "fall hard, go fast", "TRXTGN3", "TRXTGN4", "TRXTGN4", "TRXTGN16", false, Dropdash_Initialize, Dropdash_Thinker, Dropdash_Success, Dropdash_Landing)