#![allow(dead_code)]
#![allow(long_running_const_eval)]
#![allow(unused_imports)]

use crate::character::Character::{self, *};
use crate::condition::Condition::{self, *};
use crate::entity::Entity;
use crate::item::Item::{self, *};
use crate::location::Location::{self, *};
use crate::save_point::SavePoint::{self, *};
use crate::script::Token::{self, *};
use crate::script::script;
use crate::snippet::Snippet::{self, *};
use crate::sound::Sound::{self, *};
use crate::style::Style::{self, *};

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum Label {
    Label156930,
    Label15693B,
    Label156948,
    Label156955,
    Label156963,
    Label156972,
    Label156981,
    Label156990,
    Label1569A0,
    Label1569AD,
    Label1569BA,
    Label1569C9,
    Label1569D4,
    Label1569E1,
    Label1569F0,
    Label1569FD,
    Label156A0B,
    Label156A1C,
    Label156A2C,
    Label156A3B,
    Label156A48,
    Label156A58,
    Label156A64,
    Label156A65,
    Label156A66,
    Label156A67,
    Label156A6C,
    Label156A7D,
    Label156A88,
    Label156A8F,
    Label156A9F,
    Label156AA3,
    Label156AA8,
    Label156AAF,
    Label156ABC,
    Label156AC5,
    Label156ACF,
    Label156AD9,
    Label156AE3,
    Label156AED,
    Label156AF7,
    Label156AFB,
    Label156B0B,
    Label156B1A,
    Label156B28,
    Label156B37,
    Label156B44,
    Label156B4E,
    Label156B58,
    Label156B73,
    Label156B7B,
    Label156B84,
    Label156B8C,
    Label156B95,
    Label156B9D,
    Label156BA5,
    Label156BAE,
    Label156BC6,
    Label156BDD,
    Label156BDE,
    Label156BF8,
    Label156C14,
    Label156C2C,
    Label156C5C,
    Label156C8C,
    Label156CBC,
    Label156CD2,
    Label156CEC,
    Label156CEF,
    Label156CF2,
    Label156CF5,
    Label156CF8,
    Label156CF9,
    Label156D24,
    Label156D51,
    Label156D7D,
    Label156D7E,
    Label156D7F,
    Label156DC1,
    Label156E05,
    Label156E06,
    Label156E3C,
    Label156E63,
    Label156E8A,
    Label156EA7,
    Label156EC2,
    Label156ED7,
    Label156F00,
    Label156F2E,
    Label156F51,
    Label156F7F,
    Label156FA8,
    Label156FD5,
    Label156FFC,
    Label157024,
    Label157043,
    Label15706C,
    Label15708E,
}

use self::Label::*;

const fn find_label(script: &'static [Token<Label>], label: Label) -> usize {
    let mut i = 0;
    while i < script.len() {
        match script[i] {
            Token::Label(l) if l as u8 == label as u8 => return i,
            _ => i += 1,
        };
    }
    unreachable!();
}

pub fn dialog_for_label(index: usize) -> &'static [Token<'static, Label>] {
    &SCRIPTS[INDEXED[index]..]
}

pub fn dialog(index: usize) -> &'static [Token<'static, Label>] {
    &SCRIPTS[INDEXED[index]..]
}

const SCRIPTS: &[Token<Label>] = script![

Label(Label156930)
    Character(Asha) "'s Sword" End

Label(Label15693B)
    "Khan's Sword" End

Label(Label156948)
    "Shah's Sword" End

Label(Label156955)
    "Cyrus's Sword" End

Label(Label156963)
    "Caliph's Sword" End

Label(Label156972)
    "Ishtar's Sword" End

Label(Label156981)
    "Sword of Babel" End

Label(Label156990)
    "Legendary Sword" End

Label(Label1569A0)
    "Plain Shield" End

Label(Label1569AD)
    "Flame Shield" End

Label(Label1569BA)
    "Thunder Shield" End

Label(Label1569C9)
    "Ice Shield" End

Label(Label1569D4)
    "Steel Shield" End

Label(Label1569E1)
    "Rainbow Shield" End

Label(Label1569F0)
    "Magic Shield" End

Label(Label1569FD)
    "Legend Shield" End

Label(Label156A0B)
    "Traveler's Armor" End

Label(Label156A1C)
    "Warrior's Armor" End

Label(Label156A2C)
    "Knight's Armor" End

Label(Label156A3B)
    "Hero's Armor" End

Label(Label156A48)
    "Legendary Armor" End

Label(Label156A58)
    "Debug Armor" End

Label(Label156A64)
    End

Label(Label156A65)
    End

Label(Label156A66)
    End

Label(Label156A67)
    "Herb" End

Label(Label156A6C)
    "Healing Medicine" End

Label(Label156A7D)
    "Magic Lamp" End

Label(Label156A88)
    Character(Pepelogoo) " Egg" End

Label(Label156A8F)
    "Courage Crystal" End

Label(Label156A9F)
    "Key" End

Label(Label156AA3)
    "Bomb" End

Label(Label156AA8)
    "Bucket" End

Label(Label156AAF)
    "Water Bucket" End

Label(Label156ABC)
    "Gold Bar" End

Label(Label156AC5)
    Snippet(Leopard) " Statue" End

Label(Label156ACF)
    Snippet(Witch) " Statue" End

Label(Label156AD9)
    Snippet(DesertTurtle) " Statue" End

Label(Label156AE3)
    Snippet(HornedOwl) " Statue" End

Label(Label156AED)
    Snippet(Swallow) " Statue" End

Label(Label156AF7)
    "Map" End

Label(Label156AFB)
    "Earth Medallion" End

Label(Label156B0B)
    "Moon Medallion" End

Label(Label156B1A)
    "Sun Medallion" End

Label(Label156B28)
    "Wind Medallion" End

Label(Label156B37)
    "Magic Carpet" End

Label(Label156B44)
    "Big Heart" End

Label(Label156B4E)
    "Life Drop" End

Label(Label156B58)
    "Given by Asha's father." NewLine
    Snippet(StrengthPlus1) End

Label(Label156B73)
    Snippet(StrengthPlus1) Snippet(MagicalHit) " +2" End

Label(Label156B7B)
    Snippet(StrengthPlus2) Snippet(MagicalHit) " ---" End

Label(Label156B84)
    Snippet(StrengthPlus2) Snippet(MagicalHit) " +4" End

Label(Label156B8C)
    Snippet(StrengthPlus4) Snippet(MagicalHit) " ---" End

Label(Label156B95)
    Snippet(StrengthPlus4) Snippet(MagicalHit) " +8" End

Label(Label156B9D)
    Snippet(StrengthPlus1) Snippet(MagicalHit) " +8" End

Label(Label156BA5)
    Snippet(StrengthPlus8) Snippet(MagicalHit) " ---" End

Label(Label156BAE)
    "Press Down to raise." NewLine
    Snippet(DefensePlus0) End

Label(Label156BC6)
    Snippet(DefensePlus2) More NewLine
    Style(RedOnBlack) "Against flame" Style(WhiteOnBlack)
Label(Label156BDD)
    ","
Label(Label156BDE)
    NewLine
    "magical defense granted." End

Label(Label156BF8)
    Snippet(DefensePlus2) More NewLine
    Style(YellowOnBlack) "Against thunder" Style(WhiteOnBlack) Seek(Label156BDD)

Label(Label156C14)
    Snippet(DefensePlus2) More NewLine
    Style(LightBlueOnBlack) "Against ice" Style(WhiteOnBlack) Seek(Label156BDD)

Label(Label156C2C)
    Snippet(DefensePlus2) More NewLine
    Style(RedOnBlack) "Against " Style(YellowOnBlack) "non-elemental " Style(LightBlueOnBlack) "attack" Style(WhiteOnBlack) "," Seek(Label156BDE)

Label(Label156C5C)
    Snippet(DefensePlus1) More NewLine
    Style(RedOnBlack) "Against " Style(YellowOnBlack) "any elemental " Style(LightBlueOnBlack) "attack" Style(WhiteOnBlack) "," Seek(Label156BDE)

Label(Label156C8C)
    Snippet(DefensePlus2) More NewLine
    Style(RedOnBlack) "Against " Style(YellowOnBlack) "any elemental " Style(LightBlueOnBlack) "attack" Style(WhiteOnBlack) "," Seek(Label156BDE)

Label(Label156CBC)
    "Against any attack," Seek(Label156BDE)

Label(Label156CD2)
    "Made by Asha's mother." NewLine
    Snippet(EndurancePlus3) End

Label(Label156CEC)
    Snippet(EndurancePlus5) End

Label(Label156CEF)
    Snippet(EndurancePlus7) End

Label(Label156CF2)
    Snippet(EndurancePlus10) End

Label(Label156CF5)
    Snippet(EndurancePlus15) End

Label(Label156CF8)
    End

Label(Label156CF9)
    "Want to raise" NewLine
    "Pepe to Level 1?" Prompt(Condition0027) JumpIfNo(Label156D24) SetPepelogooLevel(0) End

Label(Label156D24)
    Clear
    "Want to raise" NewLine
    "Pepe to Level 2?" Prompt(Condition0027) JumpIfNo(Label156D51) SetPepelogooLevel(1) End

Label(Label156D51)
    Clear
    "Want to raise" NewLine
    "Pepe to Level 3?" Prompt(Condition0027) JumpIfNo(Label156D7D) SetPepelogooLevel(2)
Label(Label156D7D)
    End

Label(Label156D7E)
    End

Label(Label156D7F)
    "This herb restores" NewLine
    "Asha's Life a little." More CheckCanGainHearts(91) Clear
    "Use it?" Prompt(Condition0027) JumpIfNo(Label156E05) UseItem End

Label(Label156DC1)
    "This medicine fully" NewLine
    "restores Asha's Life." More CheckCanGainHearts(24) Clear
    "Drink it?" Prompt(Condition0027) JumpIfNo(Label156E05) UseItem
Label(Label156E05)
    End

Label(Label156E06)
    "You're in town now." NewLine
    SeekIfRand(32768, Label156E63)
    SeekIfRand(49152, Label156E3C)
    "*sob* Don't pick on me." End

Label(Label156E3C)
    "You shouldn't rely on" NewLine
    "others too much." End

Label(Label156E63)
    "Please use this item" NewLine
    "outside the town." End

Label(Label156E8A)
    "An egg of the mysterious" NewLine
    Character(Pepelogoo) "." End

Label(Label156EA7)
    "Enables entry into" NewLine
    "the " Location(TowerOfSilence) "." End

Label(Label156EC2)
    "Opens a locked door." End

Label(Label156ED7)
    "A bomb powerful enough" NewLine
    "to destroy stone." End

Label(Label156F00)
    "An empty bucket. It can" NewLine
    "be filled with water." End

Label(Label156F2E)
    "If you throw water on" NewLine
    "something..." End

Label(Label156F51)
    "This bar of gold can be" NewLine
    "sold at a high price." End

Label(Label156F7F)
    "Set this mysterious" NewLine
    "statue in its place." End

Label(Label156FA8)
    "A pyramid map showing" NewLine
    "your present location." End

Label(Label156FD5)
    "Opens the gate to the" NewLine
    "Handera Volcano." End

Label(Label156FFC)
    "Opens the gate to the" NewLine
    "Stream Sanctuary." End

Label(Label157024)
    "Opens the gate to the" NewLine
    "Pyramid." End

Label(Label157043)
    "Opens the gate to the" NewLine
    "Castle in the Sky." End

Label(Label15706C)
    "A mysterious carpet that" NewLine
    "can fly." End

Label(Label15708E)
    End
    ];

pub const INDEXED: &[usize] = &[
    find_label(SCRIPTS, Label156930),
    find_label(SCRIPTS, Label15693B),
    find_label(SCRIPTS, Label156948),
    find_label(SCRIPTS, Label156955),
    find_label(SCRIPTS, Label156963),
    find_label(SCRIPTS, Label156972),
    find_label(SCRIPTS, Label156981),
    find_label(SCRIPTS, Label156990),
    find_label(SCRIPTS, Label1569A0),
    find_label(SCRIPTS, Label1569AD),
    find_label(SCRIPTS, Label1569BA),
    find_label(SCRIPTS, Label1569C9),
    find_label(SCRIPTS, Label1569D4),
    find_label(SCRIPTS, Label1569E1),
    find_label(SCRIPTS, Label1569F0),
    find_label(SCRIPTS, Label1569FD),
    find_label(SCRIPTS, Label156A0B),
    find_label(SCRIPTS, Label156A1C),
    find_label(SCRIPTS, Label156A2C),
    find_label(SCRIPTS, Label156A3B),
    find_label(SCRIPTS, Label156A48),
    find_label(SCRIPTS, Label156A58),
    find_label(SCRIPTS, Label156A58),
    find_label(SCRIPTS, Label156A58),
    find_label(SCRIPTS, Label156A64),
    find_label(SCRIPTS, Label156A65),
    find_label(SCRIPTS, Label156A66),
    find_label(SCRIPTS, Label156A67),
    find_label(SCRIPTS, Label156A6C),
    find_label(SCRIPTS, Label156A7D),
    find_label(SCRIPTS, Label156A88),
    find_label(SCRIPTS, Label156A8F),
    find_label(SCRIPTS, Label156A9F),
    find_label(SCRIPTS, Label156AA3),
    find_label(SCRIPTS, Label156AA8),
    find_label(SCRIPTS, Label156AAF),
    find_label(SCRIPTS, Label156ABC),
    find_label(SCRIPTS, Label156AC5),
    find_label(SCRIPTS, Label156ACF),
    find_label(SCRIPTS, Label156AD9),
    find_label(SCRIPTS, Label156AE3),
    find_label(SCRIPTS, Label156AED),
    find_label(SCRIPTS, Label156AF7),
    find_label(SCRIPTS, Label156AFB),
    find_label(SCRIPTS, Label156B0B),
    find_label(SCRIPTS, Label156B1A),
    find_label(SCRIPTS, Label156B28),
    find_label(SCRIPTS, Label156B37),
    find_label(SCRIPTS, Label156B44),
    find_label(SCRIPTS, Label156B44),
    find_label(SCRIPTS, Label156B44),
    find_label(SCRIPTS, Label156B44),
    find_label(SCRIPTS, Label156B44),
    find_label(SCRIPTS, Label156B44),
    find_label(SCRIPTS, Label156B44),
    find_label(SCRIPTS, Label156B44),
    find_label(SCRIPTS, Label156B4E),
    find_label(SCRIPTS, Label156B58),
    find_label(SCRIPTS, Label156B58),
    find_label(SCRIPTS, Label156B58),
    find_label(SCRIPTS, Label156B58),
    find_label(SCRIPTS, Label156B58),
    find_label(SCRIPTS, Label156B58),
    find_label(SCRIPTS, Label156B58),
    find_label(SCRIPTS, Label156B58),
    find_label(SCRIPTS, Label156B58),
    find_label(SCRIPTS, Label156B73),
    find_label(SCRIPTS, Label156B7B),
    find_label(SCRIPTS, Label156B84),
    find_label(SCRIPTS, Label156B8C),
    find_label(SCRIPTS, Label156B95),
    find_label(SCRIPTS, Label156B9D),
    find_label(SCRIPTS, Label156BA5),
    find_label(SCRIPTS, Label156BAE),
    find_label(SCRIPTS, Label156BC6),
    find_label(SCRIPTS, Label156BF8),
    find_label(SCRIPTS, Label156C14),
    find_label(SCRIPTS, Label156C2C),
    find_label(SCRIPTS, Label156C5C),
    find_label(SCRIPTS, Label156C8C),
    find_label(SCRIPTS, Label156CBC),
    find_label(SCRIPTS, Label156CD2),
    find_label(SCRIPTS, Label156CEC),
    find_label(SCRIPTS, Label156CEF),
    find_label(SCRIPTS, Label156CF2),
    find_label(SCRIPTS, Label156CF5),
    find_label(SCRIPTS, Label156CF8),
    find_label(SCRIPTS, Label156CF8),
    find_label(SCRIPTS, Label156CF9),
    find_label(SCRIPTS, Label156D7E),
    find_label(SCRIPTS, Label156D7E),
    find_label(SCRIPTS, Label156D7E),
    find_label(SCRIPTS, Label156D7F),
    find_label(SCRIPTS, Label156DC1),
    find_label(SCRIPTS, Label156E06),
    find_label(SCRIPTS, Label156E8A),
    find_label(SCRIPTS, Label156EA7),
    find_label(SCRIPTS, Label156EC2),
    find_label(SCRIPTS, Label156ED7),
    find_label(SCRIPTS, Label156F00),
    find_label(SCRIPTS, Label156F2E),
    find_label(SCRIPTS, Label156F51),
    find_label(SCRIPTS, Label156F7F),
    find_label(SCRIPTS, Label156F7F),
    find_label(SCRIPTS, Label156F7F),
    find_label(SCRIPTS, Label156F7F),
    find_label(SCRIPTS, Label156F7F),
    find_label(SCRIPTS, Label156FA8),
    find_label(SCRIPTS, Label156FD5),
    find_label(SCRIPTS, Label156FFC),
    find_label(SCRIPTS, Label157024),
    find_label(SCRIPTS, Label157043),
    find_label(SCRIPTS, Label15706C),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
    find_label(SCRIPTS, Label15708E),
];
