REM Basics

    LEVEL_VERSION(1)
    RUN_AFTER_VICTORY(1)
    SET_GENERATE_SPEED(400)
    START_MONEY(ALL_PLAYERS,0)
    MAX_CREATURES(ALL_PLAYERS,25)

    SET_PLAYER_COLOR(PLAYER0, BLUE)

    COMPUTER_PLAYER(PLAYER5,ROAMING)

    SET_MUSIC("campaign_music/amala_theme.mp3")

    SET_TIMER(PLAYER0, TIMER0)
    REM Flag checks if the player has beat the knight
    SET_FLAG(PLAYER0, FLAG1, 0)

REM Availability

    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HAND,1,1)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SLAP,1,1)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_POSSESS,1,1)

REM Level script
        
    QUICK_OBJECTIVE(1, "Two paths. North or south. Onyx or Diamond. Choose your enemy wisely, for the other may become your ally, if just briefly. But, a special fairy accompanies you. Make use of her Rebound ability until she's strong enough to fight for herself.")

REM Prevent the fairy from wanting pay

    SET_CREATURE_CONFIGURATION(FAIRY,Pay,0)

REM Levelling up the player's fairy when you hit a certain point in the level

    IF_ACTION_POINT(1, PLAYER0)
        QUICK_MESSAGE(16, "Make good use of her new power.", SPELL_FLIGHT)
        QUICK_MESSAGE(15, "Your fairy's power has increased.", SPELL_FLIGHT)
        PLAY_MESSAGE(PLAYER0, SPEECH, 83)
        LEVEL_UP_CREATURE(PLAYER0, ANY_CREATURE, LEAST_EXPERIENCED, 4)
    ENDIF

    IF_ACTION_POINT(2, PLAYER0)
        QUICK_MESSAGE(18, "Your fairy has learned Meteorite as well.", SPELL_FLIGHT)
        LEVEL_UP_CREATURE(PLAYER0, ANY_CREATURE, LEAST_EXPERIENCED, 4)
    ENDIF

    IF_ACTION_POINT(8, PLAYER0)
        QUICK_MESSAGE(20, "Make good use of her new power.", SPELL_FLIGHT)
        QUICK_MESSAGE(21, "Your fairy's power has increased.", SPELL_FLIGHT)
        LEVEL_UP_CREATURE(PLAYER0, ANY_CREATURE, LEAST_EXPERIENCED, 4)
    ENDIF

    IF_ACTION_POINT(9, PLAYER0)
        QUICK_MESSAGE(22, "Your fairy has learned Meteorite as well.", SPELL_FLIGHT)
        LEVEL_UP_CREATURE(PLAYER0, ANY_CREATURE, LEAST_EXPERIENCED, 4)
    ENDIF

REM Logic for the special box

    SET_BOX_TOOLTIP(1,"Reset Alliance")

    REM This check makes sure that these messages don't show if the player is actually going through the dungeon properly.
    REM This way they only show at the start of the level when the player has already set the flag
    IF (PLAYER0, TIMER0 < 50)

        IF (PLAYER0, CAMPAIGN_FLAG3 == 1)
            REM Special box der Level hinzufügen
            QUICK_INFORMATION(14, "You have already allied yourself with one of the other keepers. If you wish to undo this, use this dungeon special.", 7)
            ADD_OBJECT_TO_LEVEL(SPECBOX_CUSTOM, 7, 1, PLAYER_NEUTRAL)
        ENDIF

        IF (PLAYER0, CAMPAIGN_FLAG3 == 2)
            REM Special box der Level hinzufügen
            QUICK_MESSAGE(13, "You have already allied yourself with one of the other keepers. If you wish to undo this, use this dungeon special.", 7)
            ADD_OBJECT_TO_LEVEL(SPECBOX_CUSTOM, 7, 1, PLAYER_NEUTRAL)
        ENDIF

    ENDIF

    IF (PLAYER0, BOX1_ACTIVATED == 1)
        PLAY_MESSAGE(PLAYER0,SPEECH,80)
        WIN_GAME
        QUICK_MESSAGE(2, "Your alliance with Onyx or Diamond has been voided.", SPELL_FLIGHT)
        SET_FLAG(PLAYER0, CAMPAIGN_FLAG0, 0)
    ENDIF

REM Win condition

    REM Flag3 - Whether the player is allied with black or white in level 10
    REM 0 - Allied with neither
    REM 1 - Allied with black
    REM 2 - Allied with white

    REM Set flag if white is destroyed
    IF (PLAYER5, DUNGEON_DESTROYED == 1)
        QUICK_MESSAGE(3, "Let us take on the Onyx heathens together.", PLAYER_GOOD)
        QUICK_MESSAGE(4, "You will sorely regret this move...", PLAYER5)
        SET_FLAG(PLAYER0, CAMPAIGN_FLAG3, 2)
        WIN_GAME
    ENDIF

    REM Set flag if white is destroyed
    IF (PLAYER_GOOD, DUNGEON_DESTROYED == 1)
        QUICK_MESSAGE(5, "Your insolence will be punished!", PLAYER_GOOD)
        QUICK_MESSAGE(6, "Stabbing them in the back, huh? Let's work together.", PLAYER5)
        SET_FLAG(PLAYER0, CAMPAIGN_FLAG3, 1)
        WIN_GAME
    ENDIF

REM Logic for locking the other path when the player has chosen one side

    IF_ACTION_POINT(3, PLAYER0)
        QUICK_MESSAGE(8, "Are you sure?", SPELL_FLIGHT)
        QUICK_MESSAGE(7, "If you continue, you'll anger the Diamond heroes.", SPELL_FLIGHT)
    ENDIF

    IF_ACTION_POINT(4, PLAYER0)
        QUICK_MESSAGE(9, "You fool, you have made your choice then.", PLAYER_GOOD)
        CHANGE_SLAB_TYPE(41,45, PAIR_WALL, NONE)
        CHANGE_SLAB_OWNER(41, 45, PLAYER0, NONE)
    ENDIF

    IF_ACTION_POINT(5, PLAYER0)
        QUICK_MESSAGE(10, "Are you sure?", SPELL_FLIGHT)
        QUICK_MESSAGE(11, "If you move further, you'll anger the Onyx rogues.", SPELL_FLIGHT)
    ENDIF

    IF_ACTION_POINT(6, PLAYER0)
        QUICK_MESSAGE(12, "You made your choice, you will regret this.", PLAYER5)
        CHANGE_SLAB_TYPE(41,35, PAIR_WALL, NONE)
        CHANGE_SLAB_OWNER(41, 35, PLAYER0, NONE)
    ENDIF

REM Victory conditions dependant on enemy having a specific unit

    REM Black

    IF (PLAYER5, BLACK_KNIGHT > 0)
        SET_FLAG(PLAYER0, FLAG1, 1)
    ENDIF

    IF (PLAYER0, FLAG1 == 1)
        IF (PLAYER5, BLACK_KNIGHT == 0)
            SET_HEART_HEALTH(PLAYER5, 0)
        ENDIF
    ENDIF

    REM White

    IF (PLAYER_GOOD, KNIGHT > 0)
        SET_FLAG(PLAYER0, FLAG1, 2)
    ENDIF

    IF (PLAYER0, FLAG1 == 2)
        IF (PLAYER_GOOD, KNIGHT == 0)
            SET_HEART_HEALTH(PLAYER_GOOD, 0)
        ENDIF
    ENDIF

REM Loss condition

    IF (PLAYER0, TOTAL_CREATURES == 0)
        QUICK_OBJECTIVE(17, "You have lost your fairy. Be more careful next time.")
        LOSE_GAME
    ENDIF

REM Spawn enemy party - black

    CREATE_PARTY(party_black)
        ADD_TO_PARTY(party_black,BLACK_KNIGHT,8,0,ATTACK_DUNGEON_HEART,0)

        ADD_TO_PARTY(party_black,SPIDER,2,0,ATTACK_DUNGEON_HEART,0)
        ADD_TO_PARTY(party_black,SPIDER,2,0,ATTACK_DUNGEON_HEART,0)

        ADD_TO_PARTY(party_black,SKELETON,4,0,ATTACK_DUNGEON_HEART,0)
        ADD_TO_PARTY(party_black,SKELETON,4,0,ATTACK_DUNGEON_HEART,0)
        
    IF_ACTION_POINT(10, PLAYER0)
        PLAY_MESSAGE(PLAYER0, SPEECH, 19)
        ADD_PARTY_TO_LEVEL(PLAYER5, party_black, -2, 1)
    ENDIF

REM Spawn enemy party - white

    CREATE_PARTY(party_white)
        ADD_TO_PARTY(party_white,KNIGHT,8,0,ATTACK_DUNGEON_HEART,0)

        ADD_TO_PARTY(party_white,TENTACLE,5,0,ATTACK_DUNGEON_HEART,0)
        ADD_TO_PARTY(party_white,TENTACLE,5,0,ATTACK_DUNGEON_HEART,0)

        ADD_TO_PARTY(party_white,BARBARIAN,3,0,ATTACK_DUNGEON_HEART,0)
        ADD_TO_PARTY(party_white,BARBARIAN,3,0,ATTACK_DUNGEON_HEART,0) 

    IF_ACTION_POINT(11, PLAYER0)
        PLAY_MESSAGE(PLAYER0, SPEECH, 19)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD, party_white, -1, 1)
    ENDIF