REM ****************************************************************************
REM  Campaigns Consolidation Project for KeeperFX strategy game.
REM ****************************************************************************
REM  Script for Level Twin Keepers Final
REM  Campaign: Twin Keepers
REM  Authors:  Original author unknown
REM            KeeperFX CCP Team
REM            Switched to translatable objectives by dayokay Nov 2014
REM  Date:     17 Aug 2005 - 24 Aug 2020
REM  Copying and copyrights:
REM    This program is free software; you can redistribute it and/or modify
REM    it under the terms of the GNU General Public License as published by
REM    the Free Software Foundation; either version 2 of the License, or
REM    (at your option) any later version.
REM ****************************************************************************

LEVEL_VERSION(1)

START_MONEY(PLAYER0,10000)
START_MONEY(PLAYER1,10000)
START_MONEY(PLAYER2,10000)

COMPUTER_PLAYER(PLAYER1,0)
COMPUTER_PLAYER(PLAYER2,0)

ALLY_PLAYERS(PLAYER1,PLAYER2,1)

SET_GENERATE_SPEED(500)

SET_FLAG(PLAYER0,FLAG0,0)
SET_TIMER(PLAYER0,TIMER0)
SET_TIMER(PLAYER0,TIMER1)
SET_TIMER(PLAYER0,TIMER2)
SET_TIMER(PLAYER0,TIMER3)
SET_TIMER(PLAYER1,TIMER0)

MAX_CREATURES(PLAYER0,20)
MAX_CREATURES(PLAYER1,20)
MAX_CREATURES(PLAYER2,20)

ADD_CREATURE_TO_POOL(BUG,15)
ADD_CREATURE_TO_POOL(DEMONSPAWN,15)
ADD_CREATURE_TO_POOL(SPIDER,15)
ADD_CREATURE_TO_POOL(TROLL,15)
ADD_CREATURE_TO_POOL(DARK_MISTRESS,20)
ADD_CREATURE_TO_POOL(DRAGON,15)
ADD_CREATURE_TO_POOL(BILE_DEMON,15)
ADD_CREATURE_TO_POOL(ORC,20)
ADD_CREATURE_TO_POOL(TENTACLE,15)
ADD_CREATURE_TO_POOL(SORCEROR,15)
ADD_CREATURE_TO_POOL(FLY,15)
ADD_CREATURE_TO_POOL(HELL_HOUND,2)

CREATURE_AVAILABLE(ALL_PLAYERS,TROLL,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,DARK_MISTRESS,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,TENTACLE,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,ORC,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,BILE_DEMON,1,1)
CREATURE_AVAILABLE(PLAYER0,SPIDER,1,1)
CREATURE_AVAILABLE(PLAYER0,BUG,1,1)
CREATURE_AVAILABLE(PLAYER0,DEMONSPAWN,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,DRAGON,1,1)
CREATURE_AVAILABLE(PLAYER0,SORCEROR,1,1)
CREATURE_AVAILABLE(PLAYER0,FLY,1,1)

ROOM_AVAILABLE(ALL_PLAYERS,TREASURE,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,LAIR,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,GARDEN,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,TRAINING,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,RESEARCH,1,1)
ROOM_AVAILABLE(PLAYER0,BRIDGE,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,WORKSHOP,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,BARRACKS,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TORTURE,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TEMPLE,1,0)
ROOM_AVAILABLE(PLAYER0,GRAVEYARD,1,0)

MAGIC_AVAILABLE(ALL_PLAYERS,POWER_IMP,1,1)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_OBEY,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HOLD_AUDIENCE,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HEAL_CREATURE,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SPEED,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_PROTECT,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CONCEAL,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CALL_TO_ARMS,1,0)

TRAP_AVAILABLE(PLAYER0,ALARM,1,0)
TRAP_AVAILABLE(PLAYER0,POISON_GAS,1,0)
TRAP_AVAILABLE(PLAYER0,LIGHTNING,1,0)
TRAP_AVAILABLE(PLAYER0,BOULDER,1,0)
TRAP_AVAILABLE(PLAYER0,WORD_OF_POWER,1,0)
DOOR_AVAILABLE(ALL_PLAYERS,STEEL,1,0)
DOOR_AVAILABLE(ALL_PLAYERS,MAGIC,1,0)

CREATE_PARTY(PARTY1)
    ADD_TO_PARTY(PARTY1,FAIRY,10,500,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(PARTY1,KNIGHT,10,10000,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(PARTY1,FAIRY,10,500,ATTACK_ENEMIES,0)

CREATE_PARTY(PARTY2)
    ADD_TO_PARTY(PARTY2,DWARFA,8,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY2,SAMURAI,8,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY2,ARCHER,9,500,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(PARTY3)
    ADD_TO_PARTY(PARTY3,DWARFA,5,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY3,WITCH,5,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY3,ARCHER,5,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY3,SAMURAI,5,500,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(PARTY4)
    ADD_TO_PARTY(PARTY4,SAMURAI,6,500,STEAL_SPELLS,0)
    ADD_TO_PARTY(PARTY4,THIEF,6,500,STEAL_SPELLS,0)
    ADD_TO_PARTY(PARTY4,THIEF,6,500,STEAL_SPELLS,0)
    ADD_TO_PARTY(PARTY4,ARCHER,6,500,STEAL_SPELLS,0)
    ADD_TO_PARTY(PARTY4,ARCHER,6,500,STEAL_SPELLS,0)

CREATE_PARTY(PARTY5)
    ADD_TO_PARTY(PARTY5,SAMURAI,7,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY5,DWARFA,7,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY5,WITCH,7,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY5,WITCH,7,500,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(PARTY6)
    ADD_TO_PARTY(PARTY6,DWARFA,8,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY6,DWARFA,8,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY6,FAIRY,8,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY6,FAIRY,8,500,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(PARTY7)
    ADD_TO_PARTY(PARTY7,ARCHER,8,500,STEAL_GOLD,0)
    ADD_TO_PARTY(PARTY7,ARCHER,8,500,STEAL_GOLD,0)
    ADD_TO_PARTY(PARTY7,THIEF,8,500,STEAL_GOLD,0)
    ADD_TO_PARTY(PARTY7,THIEF,8,500,STEAL_GOLD,0)

CREATE_PARTY(PARTY8)
    ADD_TO_PARTY(PARTY8,SAMURAI,8,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY8,SAMURAI,8,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY8,WITCH,8,500,ATTACK_DUNGEON_HEART,0)
    ADD_TO_PARTY(PARTY8,WITCH,8,500,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(PARTY9)
    ADD_TO_PARTY(PARTY9,FAIRY,5,500,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(PARTY9,FAIRY,5,500,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(PARTY9,FAIRY,5,500,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(PARTY9,FAIRY,5,500,ATTACK_ENEMIES,0)

DISPLAY_OBJECTIVE(22,PLAYER0)

ADD_CREATURE_TO_LEVEL(PLAYER1,VAMPIRE,-1,1,10,1000)
ADD_CREATURE_TO_LEVEL(PLAYER2,VAMPIRE,-2,1,10,1000)

IF(PLAYER1,BATTLES_LOST >= 5)
    IF(PLAYER1,HORNY == 0)
        ADD_CREATURE_TO_LEVEL(PLAYER1,HORNY,-1,1,9,1000)
    ENDIF
ENDIF

IF(PLAYER2,BATTLES_LOST >= 5)
    IF(PLAYER2,HORNY == 0)
        ADD_CREATURE_TO_LEVEL(PLAYER2,HORNY,-2,1,9,1000)
    ENDIF
ENDIF

IF(PLAYER0,FLAG0 == 0)
    IF(PLAYER1,HORNY > 0)
        IF(PLAYER2,HORNY > 0)
            NEXT_COMMAND_REUSABLE
            SET_TIMER(PLAYER1,TIMER0)
        ENDIF
    ENDIF
    IF(PLAYER1,TIMER0 > 150)
        IF(PLAYER1,HORNY == 0)
            IF(PLAYER2,HORNY > 0)
                NEXT_COMMAND_REUSABLE
                ADD_CREATURE_TO_LEVEL(PLAYER1,HORNY,-1,1,9,0)
            ENDIF
        ENDIF
        IF(PLAYER2,HORNY == 0)
            IF(PLAYER1,HORNY > 0)
                NEXT_COMMAND_REUSABLE
                ADD_CREATURE_TO_LEVEL(PLAYER2,HORNY,-2,1,9,0)
            ENDIF
        ENDIF
    ENDIF

    IF(PLAYER1,AVATAR > 0)
        SET_FLAG(PLAYER0,FLAG0,1)
    ENDIF

    IF(PLAYER2,AVATAR > 0)
        SET_FLAG(PLAYER0,FLAG0,1)
    ENDIF
ENDIF

IF(PLAYER0,FLAG0 == 1)
    IF(PLAYER1,AVATAR > 0)
        IF(PLAYER2,AVATAR > 0)
            NEXT_COMMAND_REUSABLE
            SET_TIMER(PLAYER1,TIMER0)
        ENDIF
    ENDIF
    IF(PLAYER1,TIMER0 > 150)
        IF(PLAYER1,AVATAR == 0)
            IF(PLAYER2,AVATAR > 0)
                NEXT_COMMAND_REUSABLE
                ADD_CREATURE_TO_LEVEL(PLAYER1,AVATAR,-1,1,10,0)
            ENDIF
        ENDIF
        IF(PLAYER2,AVATAR == 0)
            IF(PLAYER1,AVATAR > 0)
                NEXT_COMMAND_REUSABLE
                ADD_CREATURE_TO_LEVEL(PLAYER2,AVATAR,-2,1,10,0)
            ENDIF
        ENDIF
    ENDIF
ENDIF

IF(PLAYER1,DUNGEON_DESTROYED == 1)
    SET_FLAG(PLAYER0,FLAG0,2)
ENDIF
IF(PLAYER2,DUNGEON_DESTROYED == 1)
    SET_FLAG(PLAYER0,FLAG0,2)
ENDIF

IF(PLAYER_GOOD,DUNGEON_DESTROYED == 0)
    
    IF_ACTION_POINT(1,PLAYER0)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,DARK_MISTRESS,1,4,3,500)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,TENTACLE,3,4,4,500)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,VAMPIRE,5,4,4,500)
    ENDIF
    
    IF_ACTION_POINT(2,PLAYER0)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,DARK_MISTRESS,2,4,3,500)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,TENTACLE,4,4,4,500)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,VAMPIRE,6,4,4,500)
    ENDIF
    
    IF_ACTION_POINT(9,PLAYER0)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY3,9,1)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,ARCHER,10,4,5,1000)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,THIEF,11,4,5,1000)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,FAIRY,12,4,5,1000)
    ENDIF
    
    IF_ACTION_POINT(13,PLAYER0)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY3,13,1)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,ARCHER,14,4,5,1000)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,THIEF,15,4,5,1000)
        ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,FAIRY,16,4,5,1000)
    ENDIF
    
    IF(PLAYER_GOOD,BARBARIAN == 0)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY3,-8,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY4,18,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY5,19,1)
    ENDIF
    
    IF(PLAYER_GOOD,GIANT == 0)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY3,-7,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY4,21,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY5,22,1)
    ENDIF
    
    IF(PLAYER_GOOD,WIZARD == 0)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY6,23,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY7,24,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY8,25,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY1,29,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY2,29,1)
        ADD_TUNNELLER_TO_LEVEL(PLAYER_GOOD,-4,ACTION_POINT,31,9,500)
    ENDIF
    
    IF(PLAYER_GOOD,MONK == 0)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY6,26,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY7,27,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY8,28,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY1,29,1)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,PARTY2,29,1)
        ADD_TUNNELLER_TO_LEVEL(PLAYER_GOOD,-3,ACTION_POINT,30,9,500)
    ENDIF
    
    
ENDIF

IF(PLAYER0,TIMER2 > 2500)
        IF(PLAYER1,DUNGEON_DESTROYED == 0)
            NEXT_COMMAND_REUSABLE
            ADD_TUNNELLER_TO_LEVEL(PLAYER_GOOD,17,ACTION_POINT,31,1,20000)
        ENDIF
        IF(PLAYER2,DUNGEON_DESTROYED == 0)
            NEXT_COMMAND_REUSABLE
            ADD_TUNNELLER_TO_LEVEL(PLAYER_GOOD,20,ACTION_POINT,30,1,20000) 
        ENDIF
        NEXT_COMMAND_REUSABLE
        SET_TIMER(PLAYER0,TIMER2)
ENDIF


IF(PLAYER2,FLY == 0)
                  NEXT_COMMAND_REUSABLE
                  MAGIC_AVAILABLE(PLAYER2,POWER_HAND,1,1)
ENDIF

IF(PLAYER2,FLY == 1)
                  NEXT_COMMAND_REUSABLE
                  MAGIC_AVAILABLE(PLAYER2,POWER_HAND,0,0)
ENDIF

IF(PLAYER1,FLY == 0)
                  NEXT_COMMAND_REUSABLE
                  MAGIC_AVAILABLE(PLAYER1,POWER_HAND,1,1)
ENDIF

IF(PLAYER1,FLY == 1)
                  NEXT_COMMAND_REUSABLE
                  MAGIC_AVAILABLE(PLAYER1,POWER_HAND,0,0)
ENDIF

IF(PLAYER0,TIMER3 > 5000)
     IF(PLAYER2,DUNGEON_DESTROYED == 0)
         NEXT_COMMAND_REUSABLE
             IF(PLAYER2,FLY == 0)
                  NEXT_COMMAND_REUSABLE
                  ADD_CREATURE_TO_LEVEL(PLAYER2,FLY,30,1,9,100)
             ENDIF
     ENDIF
     IF(PLAYER1,DUNGEON_DESTROYED == 0)
        IF(PLAYER1,FLY == 0)
             NEXT_COMMAND_REUSABLE
             ADD_CREATURE_TO_LEVEL(PLAYER1,FLY,31,1,10,100)
             NEXT_COMMAND_REUSABLE
             MAGIC_AVAILABLE(PLAYER1,POWER_HAND,0,0)
        ENDIF
    ENDIF
    NEXT_COMMAND_REUSABLE
    SET_TIMER(PLAYER0,TIMER3)
ENDIF

IF(PLAYER_GOOD,DUNGEON_DESTROYED == 1)
    DISPLAY_OBJECTIVE(23,PLAYER0)
    ADD_TUNNELLER_TO_LEVEL(PLAYER_GOOD,-9,DUNGEON_HEART,0,9,500)
    ADD_TUNNELLER_TO_LEVEL(PLAYER_GOOD,-9,DUNGEON_HEART,0,9,500)
    ROOM_AVAILABLE(PLAYER1,BRIDGE,1,1)
    ROOM_AVAILABLE(PLAYER2,BRIDGE,1,1)
ENDIF

IF(PLAYER0,ALL_DUNGEONS_DESTROYED == 1)
    DISPLAY_OBJECTIVE(25,PLAYER0)
    REVEAL_MAP_RECT(PLAYER0,127,127,254,254)
    WIN_GAME
ENDIF

IF(PLAYER0,DUNGEON_DESTROYED == 1)
    DISPLAY_OBJECTIVE(26,PLAYER0)
    ALLY_PLAYERS(PLAYER1,PLAYER2,0)
    REVEAL_MAP_RECT(PLAYER0,127,127,254,254)
ENDIF
