include("sound/utils.nut")


/*
  Add music files below.
  The second parameter is loop start time in seconds.
  You can use fractional values for precision or -1 to disable looping.
  Loop end is always the end of the music.
*/

music <-
{
  // ambience = load_music("sound/ambience.ogg", 0)
  ambient1 = load_music("sound/music/ambient1.ogg", 0)
  flying1 = load_music("sound/music/flyingSong1.ogg", 0)

  aloop1 = load_chained_music("sound/music/Aloop1.ogg")
  aloop2 = load_chained_music("sound/music/Aloop2.ogg")
  aloop3 = load_chained_music("sound/music/Aloop3.ogg")
  aloop4 = load_chained_music("sound/music/Aloop4.ogg")
}

music_volume <-
{
  // ambience = 0.2
  aloop1 = 0.5
  aloop2 = 0.5
  aloop3 = 0.5
  aloop4 = 0.5
}

global_music_volume <- 1.0


action_loops <- split("aloop1 aloop2 aloop3 aloop4", " ")

in_combat <- false

function COMBAT_ON()
{
  in_combat=true
  return START_MUSIC(get_next_chained_music(0))()
}

function COMBAT_OFF()
{
  in_combat=false
  return NONE();
}


function get_next_chained_music(prev)
{
  if (!in_combat) return null;
  return action_loops[game_rnd()%action_loops.len()];
}


events <-
{
  enter_world=SEQ(START_MUSIC("flying1"), S2D("enter_world", 1, 0.3))
  use_portal=SEQ(COMBAT_OFF, STOP_MUSIC(), S2D("use_portal", 1))
  portal_appears=S("portal_appears", false, 1, 50)

  main_menu=START_MUSIC("ambient1")
  universe_map=START_MUSIC("ambient1")

  player_hit=R2D("player_hit1 player_hit2 player_hit3", {max=1, volume=0.5})

  start_combat=COMBAT_ON
  end_combat=SEQ(COMBAT_OFF, START_MUSIC("flying1", 3000))

  spell_appears=S("spell_appears", false, 1, 50)
  spell_loop=S("spell_loop", true, 1, 3)
  spell_discharge=R("small_discharge1 small_discharge2", {max=2, mind=3})
  pick_up_spell=S2D("pick_up_spell", 1, 0.7)

  generic_cast=R("generic_cast3", {max=5, mind=1})
  generic_missile=S("magic_missile", true, 5, 1)

  fireball_cast=R("fireball_cast1 fireball_cast2", {max=5, mind=4})
  fireball_missile=S("fireball_loop", true, 5, 15)
  fireball_hit=S("fireball_hit", false, 5, 15)
  fireball_hit_water=S("fireball_hit_water", false, 5, 4)

  meteor_cast=R("fireball_cast1 fireball_cast2", {max=5, mind=10})
  meteor_missile=S("meteor_loop", true, 5, 7)
  meteor_hit=S("meteor_hit", false, 5, 50)

  lightning_cast=R("lightning1 lightning2", {max=5, mind=10})
  thstorm_cast=R("fireball_cast1 fireball_cast2", {max=5, mind=4})
  thstorm_missile=S("thstorm_missile", true, 5, 5)
  thstorm_lightning=R("lightning1 lightning2", {max=5, mind=10})

  burn_loop=S("burn_loop", true, 3, 10)
  tree_regrows=S("tree_regrows", false, 3, 10)

  land_moving=S("tremor", true, 8, 1)

  mana_idle=R("mana1 mana2 mana3", {max=5, mind=3})

  wyvern_spawn=NONE
  // wyvern_idle =R("wyvern1 wyvern2 wyvern3", {max=5, mind=4})
  // wyvern_hit  =R("wyvern_hit1 wyvern_hit2", {max=5, mind=4})
  // wyvern_attack=S("wyvern_attack", false, 5, 5)
  wyvern_idle =R("wyvID1.ogg wyvID2.ogg wyvID3.ogg", {max=5, mind=8})
  wyvern_hit  =R("wyvDMG1.ogg wyvDMG2.ogg wyvDMG3.ogg", {max=5, mind=10})
  wyvern_attack=R("wyvCHRG1.ogg wyvCHRG2.ogg", {max=5, mind=10})

  caterpillar_spawn=NONE
  caterpillar_idle =R("wyvID1.ogg wyvID2.ogg wyvID3.ogg", {max=5, mind=8})
  caterpillar_hit  =R("wyvDMG1.ogg wyvDMG2.ogg wyvDMG3.ogg", {max=5, mind=10})
  caterpillar_attack=R("wyvCHRG1.ogg wyvCHRG2.ogg", {max=5, mind=10})

  bird_idle=R("bird1 bird2 bird3", {max=5, mind=4})
  bird_hit=R("bird_death1 bird_death2", {max=5, mind=4})

  volcano_explosion=S("volcano_explosion", false, 3, 50)
  volcano_eruption=S("eruption_loop", true, 3, 10)

  portal_loop=S("portal.ogg", true, 3, 15)

  trigger_activated=S2D("trigger.ogg", 1, 1)
}
