REM Basic Settings
    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)

    SET_MUSIC("campaign_music/nier_calm.mp3")

REM Initialize campaign flags

    REM Flag0 - Water level of Yellow for level 7
    REM 0 is default - yellow has dry land
    REM 1 is bonus - yellow gets flooded
    REM SET_FLAG(PLAYER0, CAMPAIGN_FLAG0, 0)

    REM Flag1 - Water level of Blue for level 7
    REM 0 is default - blue has flooded land
    REM 1 is bonus - blue has dry land
    REM SET_FLAG(PLAYER0, CAMPAIGN_FLAG1, 0)

    REM Flag2 - Whether the player is getting bonus creatures
    REM Set in the horror level for level 3

    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 Flag4 - Whether the player gets the secret reaper from the hub for the final level
    REM 0 - Standard value, no reaper
    REM 1 - Add reaper near the heart

    REM Flag5 - NG+
    REM 0 if regular mode
    REM 1 if NG+

    REM Flag6 - The amount of regular levels beaten (explicitly MUST be in order for it to work)
    REM SET_FLAG(PLAYER0, CAMPAIGN_FLAG6, 0)

    REM Flag7 - The amount of new game+ levels beaten (explicitly MUST be in order for it to work)
    REM SET_FLAG(PLAYER0, CAMPAIGN_FLAG7, 0)

REM Initialize special boxes
    SET_BOX_TOOLTIP(1,"Show Campaign Story")
    SET_BOX_TOOLTIP(2,"End Tutorial")
    SET_BOX_TOOLTIP(3,"Show Soundtrack Note")

REM Remove most abilities from player

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

    TRAP_AVAILABLE(ALL_PLAYERS,POISON_GAS,1,0)
    DOOR_AVAILABLE(ALL_PLAYERS,WOOD,1,0)

REM Basic introduction

    QUICK_OBJECTIVE(99, "Welcome to the Sapphire Realms campaign. This optional tutorial level contains some helpful information on more advanced or obscure mechanics for newer players. Drop your Mistress on the red glowing statue in each room to get a tutorial note. The small rooms next to the statue hint at what the tutorial is about. If you want to get straight to the campaign, use the special boxes to the left of the heart to show the story and to finish the tutorial. After leaving the tutorial, you will also unlock a hub area. Look for a new node on the map, and most importantly... have fun!")

    REM Show story of the campign
    IF(PLAYER0,BOX1_ACTIVATED == 1)
        PLAY_MESSAGE(PLAYER0, SOUND, 41)
        QUICK_OBJECTIVE(98, "You have arrived near the floating island of the Trinity Sanctum. It is the forge of soul gems, used to contain the life essence of dungeon keepers like you. It's time for you, the blue Keeper Sapphire, to take over this affluent island. However, be careful. Many others want to stake their claim here, including the white Diamond hero guild, the renegade black Onyx clan, and the rival yellow Keeper Topaz. Don't trust anyone not to stab you in the back, and make this land yours.")
    ENDIF

    REM Show story of the campign
    IF(PLAYER0,BOX3_ACTIVATED == 1)
        PLAY_MESSAGE(PLAYER0, SOUND, 41)
        QUICK_OBJECTIVE(2, "This campaign includes a lot of custom music! If you want to use the custom soundtrack, please refer to the download link on this campaign's page on the KeeperFX mod workshop. If you prefer the original Dungeon Keeper soundtrack, you can play the campaign as it is, but playing it with the new soundtrack is recommended!")
    ENDIF

    REM End level when box is clicked and set the progression flags
    IF(PLAYER0,BOX2_ACTIVATED == 1)
        WIN_GAME
        LOCATE_HIDDEN_WORLD
        SET_FLAG(PLAYER0, CAMPAIGN_FLAG6, 1)
        SET_FLAG(PLAYER0, CAMPAIGN_FLAG7, 1)
    ENDIF

REM Individual tutorials

    IF_ACTION_POINT (1, PLAYER0)
        QUICK_OBJECTIVE(1, "Tutorial 1 - Workshops. If you are ever strapped for cash in a realm without gems, don't forget that you can place traps and doors, and sell them to generate money. Additionally, what you can build, depends on the size of your workshop. Advanced items like Magic Doors only become available to build, when your workshop is 37 tiles big (or more).")
    ENDIF

    IF_ACTION_POINT (2, PLAYER0)
        QUICK_OBJECTIVE(3, "Tutorial 2 - Room Efficiency. An often overlooked part of rooms is their efficiency. Note the flags of the 3 libaries in this section. The first, red bar is a room's health. Rooms are taken over by depleting this bar. The second, green bar is its capacity, or how much can fit into it. The third, grey bar is room efficiency. An 'efficient' room also has more capacity, and work done inside it is generally done faster too! Efficiency is complex, but a solid rule to follow is to build square-shaped rooms, and fortifying its walls if you want work in there done fast. Note how all 3 libaries have the same amount of tiles, but their efficiency and thus its capacity varies because of the adjacent tiles. All have 1 book in them, but the capacity used is different.")
    ENDIF

    IF_ACTION_POINT (3, PLAYER0)
        QUICK_OBJECTIVE(4, "Tutorial 3 - Raised Rooms. Certain rooms, namely Guard Posts and Temples are special - their slab is raised relative to the normal ground level. When placed next to water or lava, this makes pathing impossible for non-flying creatures! This way, some land formations can be secured. Try it out with the imp and the fly in this area. The imp can't move on top of the temple/guard post, but the fly can.")
    ENDIF

    IF_ACTION_POINT (4, PLAYER0)
        QUICK_OBJECTIVE(5, "Tutorial 4 - Lair Experience. A few creatures can gain experience simply by sleeping inside their lair, when that lair is adjacent to specific blocks. The experience gain is slow, but doesn't cost money. Recruit these creatures and place them in the according lair, and use the inspect panel to check their experience gain. These three creature-block combinations exist: Tentacle-Water, Warlock-Gold, Dragon-Lava.")
    ENDIF

    IF_ACTION_POINT (5, PLAYER0)
        QUICK_OBJECTIVE(6, "Tutorial 5 - Torture Chamber. Here are two little tips for the Torture Chamber. For one, if you're short on money but need to heal your inmates, try building a hatchery near your prison. Your enemies can actually eat chickens you feed them, so try dropping some into the prison to heal your prisoners. Second, torturing your OWN creatures can be advantageous. Other creatures of the same type will work faster, and take a smaller cut during paydays while one of their kind is being tortured. Observe this with your mistress; check the info panel before and during torturing her, to see how the amount she wants for payday changes.")
    ENDIF

    IF_ACTION_POINT (6, PLAYER0)
        QUICK_OBJECTIVE(7, "Tutorial 6 - Temple. The temple is surprisingly versatile. The most obvious use is temple recipes. There are many, one of the most useful ones is for example Bug + Spider to create a mistress. However, imps can be sacrificed too, to decrease the cost of future imps! Try it out, observe the gold cost changing in the spells menu, and use it in realms where gold is scarce. Additionally, praying in the temple makes creatures happy, immune to being scavenged, cures the chicken status and disease, and even prevents Hornies from going berserk.")
    ENDIF

    IF_ACTION_POINT (7, PLAYER0)
        QUICK_OBJECTIVE(8, "Tutorial 7 - Walls. No access to Sight of Evil, but you need intel? Try to fortify walls, adjacent to blocks you want to check. If there is something behind that block, you will see that the wall has 2 edges; if nothing is behind it, then the side of the block facing outside of your dungeon has no wall there. Grab the imp and try it out. Additionally, when two dirt blocks forming a corner are adjacent to water, a path opens between them. You can walk through this little corner, see the bottom of this area. When these 2 dirt blocks are fortified, this open corner vanishes. You can use this technique to temporarily explore outside your dungeon, and still seal it afterwards.")
    ENDIF

    IF_ACTION_POINT(8, PLAYER0)
        QUICK_OBJECTIVE(9, "Tutorial 8 - Possession and Skills. Using possession is generally not necessary, but can have some strong upsides. There are some spells like the Grenade spell (the Bile Demon has it for example) which creatures have, but do not use in combat. However, in possession you can use it yourself. Other skills like the Dragon's flame breath are faster and stronger in possession. Likewise, some creatures can become even stronger when playing into their strengths, like the Bile Demon's gas. Sometimes, spells like the Grenade have interesting properties, like being able to push enemies and objects like gold bags. Try it out on the items and enemies below!")
    ENDIF

    IF_ACTION_POINT(9, PLAYER0)
        QUICK_OBJECTIVE(10, "Tutorial 9 - Creature Pool. Every realm has a maximum creature count. You can check if you've hit the limit, by checking if your keeper-icon next to your creature count on the ?-tab is flashing. Sometimes, it's advantageous to return less useful creatures like Flies or Demon Spawn back into your portal, to get under that maximum count, and to have a chance of getting a better creature.")
    ENDIF

    IF_ACTION_POINT(10, PLAYER0)
        QUICK_OBJECTIVE(11, "Tutorial 10 - Slapping. Nothing fancy to show here, but a reminder to always slap your creatures! There's no real downside and it's a massive boost to creature speed and work efficiency, or damage output if they're in combat! Unless of course you're slapping someone like a Horny, then you may want to be careful... but otherwise, never forget to slap away.")
    ENDIF

    IF_ACTION_POINT(11, PLAYER0)
        QUICK_OBJECTIVE(12, "With that, you've finished the tutorial! If you haven't done so yet, check the specials near the dungeon heart for instructions on the custom soundtrack, some other levels, and to complete the level. Otherwise, enjoy the campaign!")
    ENDIF

REM For tutorial 8

    CREATE_PARTY(bug_spam)
        ADD_TO_PARTY(bug_spam, BUG, 5, 0, DEFEND_LOCATION, 0)

    IF_ACTION_POINT(21, PLAYER0)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD, bug_spam, -1, 20)
    ENDIF

REM Auxiliary stuff - reveal enclosed rooms

    REVEAL_MAP_LOCATION(PLAYER0, 2, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 3, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 16, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 17, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 18, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 19, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 7, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 20, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 21, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 12, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 13, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 14, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 15, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 22, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 23, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 24, -1)
    REVEAL_MAP_LOCATION(PLAYER0, 25, -1)

REM Just an infinite timer to make creatures happy

    SET_TIMER(PLAYER0, TIMER0)
    IF (PLAYER0, TIMER0 > 0)
        CHANGE_CREATURES_ANNOYANCE(PLAYER0, ANY_CREATURE, DECREASE, 1000)
    ENDIF

REM Remove some needs from creatures

    SET_CREATURE_CONFIGURATION(DARK_MISTRESS,HungerRate,0)
    REM Mistress needs pay to see the change when torturing her
    REM SET_CREATURE_CONFIGURATION(DARK_MISTRESS,Pay,0)

    SET_CREATURE_CONFIGURATION(TROLL,HungerRate,0)
    SET_CREATURE_CONFIGURATION(TROLL,Pay,0)

    SET_CREATURE_CONFIGURATION(FLY,HungerRate,0)
    SET_CREATURE_CONFIGURATION(FLY,Pay,0)

    SET_CREATURE_CONFIGURATION(BUG,HungerRate,0)
    SET_CREATURE_CONFIGURATION(BUG,Pay,0)

    SET_CREATURE_CONFIGURATION(SPIDER,HungerRate,0)
    SET_CREATURE_CONFIGURATION(SPIDER,Pay,0)

    SET_CREATURE_CONFIGURATION(BILE_DEMON,HungerRate,0)
    SET_CREATURE_CONFIGURATION(BILE_DEMON,Pay,0)

    SET_CREATURE_CONFIGURATION(GHOST,HungerRate,0)
    SET_CREATURE_CONFIGURATION(GHOST,Pay,0)

    SET_CREATURE_CONFIGURATION(DEMONSPAWN,HungerRate,0)
    SET_CREATURE_CONFIGURATION(DEMONSPAWN,Pay,0)

    SET_CREATURE_CONFIGURATION(SORCEROR,HungerRate,0)
    SET_CREATURE_CONFIGURATION(SORCEROR,Pay,0)

    SET_CREATURE_CONFIGURATION(TENTACLE,HungerRate,0)
    SET_CREATURE_CONFIGURATION(TENTACLE,Pay,0)

    SET_CREATURE_CONFIGURATION(DRAGON,HungerRate,0)
    SET_CREATURE_CONFIGURATION(DRAGON,Pay,0)

    REM LairSize 0 would be good here but it's buggy