REM KDK Level 7

SET_GENERATE_SPEED(250)

MAX_CREATURES(PLAYER0,25)
MAX_CREATURES(PLAYER1,20)

START_MONEY(PLAYER0,3000)
START_MONEY(PLAYER1,7500)

COMPUTER_PLAYER(PLAYER1,5)
SET_COMPUTER_PROCESS(PLAYER1,"DIG TO CLOSE GOLD",0,1250,50000,5,20)
SET_COMPUTER_CHECKS(PLAYER1,"CHECK FOR NEUTRAL PLACES",15000,0,0,0,65000)
SET_COMPUTER_PROCESS(PLAYER1,"ATTACK SAFE ATTACK",-1,100,22,100,0)

SET_CREATURE_MAX_LEVEL(PLAYER0,DEMONSPAWN,10)

ADD_CREATURE_TO_POOL(BUG,20)
ADD_CREATURE_TO_POOL(FLY,20)
ADD_CREATURE_TO_POOL(DEMONSPAWN,20)
ADD_CREATURE_TO_POOL(DARK_MISTRESS,20)
ADD_CREATURE_TO_POOL(SORCEROR,30)
ADD_CREATURE_TO_POOL(TROLL,20)
ADD_CREATURE_TO_POOL(SPIDER,20)
ADD_CREATURE_TO_POOL(BILE_DEMON,10)
ADD_CREATURE_TO_POOL(ORC,10)

REM Creature_Availability
REM Give all and wait until 5 have come;
REM then change so they'll come only if attracted.

CREATURE_AVAILABLE(ALL_PLAYERS,TROLL,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,DEMONSPAWN,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,FLY,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,DARK_MISTRESS,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,SORCEROR,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,BUG,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,SPIDER,1,1)
CREATURE_AVAILABLE(ALL_PLAYERS,BILE_DEMON,1,1)

REM Room_Availability

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(ALL_PLAYERS,WORKSHOP,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,GUARD_POST,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,BRIDGE,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,PRISON,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TORTURE,1,0)

REM Spells

MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HAND,1,1)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_IMP,1,1)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SLAP,1,1)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SIGHT,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CALL_TO_ARMS,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HEAL_CREATURE,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SPEED,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_LIGHTNING,1,0)

REM doors & traps

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

REM --------------------------------------------------

REM CREATE_TEXT(1,71"YOU HAVE ARRIVED IN THE MIDDLE OF A BATTLE ALREADY STARTED.  TRY TO AVOID THE CROSSFIRE UNTIL YOU CAN ELIMINATE BOTH SIDES.")
DISPLAY_OBJECTIVE(71,PLAYER0)


IF(PLAYER0,TOTAL_CREATURES >= 5)
    SET_FLAG(PLAYER0,FLAG0,1)
ENDIF

REM change so creatures will come only if attracted by rooms
IF(PLAYER0,FLAG0 == 1)
    ADD_CREATURE_TO_LEVEL(PLAYER0,ORC,4,1,2,0)
    CREATURE_AVAILABLE(ALL_PLAYERS,TROLL,1,0)
    CREATURE_AVAILABLE(ALL_PLAYERS,DEMONSPAWN,1,0)
    CREATURE_AVAILABLE(ALL_PLAYERS,FLY,1,0)
    CREATURE_AVAILABLE(ALL_PLAYERS,DARK_MISTRESS,1,0)
    CREATURE_AVAILABLE(ALL_PLAYERS,SORCEROR,1,0)
    CREATURE_AVAILABLE(ALL_PLAYERS,BUG,1,0)
    CREATURE_AVAILABLE(ALL_PLAYERS,SPIDER,1,0)
    CREATURE_AVAILABLE(ALL_PLAYERS,BILE_DEMON,1,0)
    CREATURE_AVAILABLE(ALL_PLAYERS,ORC,1,1)
ENDIF

IF(PLAYER0,ORC > 0)
    SET_FLAG(PLAYER0,FLAG1,1)
ENDIF

IF(PLAYER0,FLAG1 == 1)
    CREATURE_AVAILABLE(ALL_PLAYERS,TROLL,1,1)
    CREATURE_AVAILABLE(ALL_PLAYERS,DEMONSPAWN,1,1)
    CREATURE_AVAILABLE(ALL_PLAYERS,FLY,1,1)
    CREATURE_AVAILABLE(ALL_PLAYERS,DARK_MISTRESS,1,1)
    CREATURE_AVAILABLE(ALL_PLAYERS,SORCEROR,1,1)
    CREATURE_AVAILABLE(ALL_PLAYERS,BUG,1,1)
    CREATURE_AVAILABLE(ALL_PLAYERS,SPIDER,1,1)
    CREATURE_AVAILABLE(ALL_PLAYERS,BILE_DEMON,1,1)
    CREATURE_AVAILABLE(ALL_PLAYERS,ORC,1,1)
    REM CREATE_TEXT(4,72"AN ORC HAS JOINED YOU AND BROUGHT WITH HIM THE PLANS TO A BARRACKS ROOM, WHEREIN YOU WILL BE ABLE TO FORM YOUR CREATURES INTO TEAMS.")
    DISPLAY_INFORMATION(72,PLAYER0)
    ROOM_AVAILABLE(PLAYER0,BARRACKS,1,1)
ENDIF


CREATE_PARTY(ICHI)
    ADD_TO_PARTY(ICHI,DWARFA,2,200,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(ICHI,DWARFA,2,200,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(ICHI,THIEF,2,200,STEAL_GOLD,0)
    ADD_TO_PARTY(ICHI,THIEF,2,200,STEAL_GOLD,0)

CREATE_PARTY(NI)
    ADD_TO_PARTY(NI,ARCHER,2,150,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(NI,ARCHER,2,150,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(NI,BARBARIAN,2,200,ATTACK_ENEMIES,0)

CREATE_PARTY(SAN)
    ADD_TO_PARTY(SAN,ARCHER,2,150,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(SAN,BARBARIAN,2,200,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(SAN,WIZARD,2,300,STEAL_SPELLS,0)

CREATE_PARTY(YON)
    ADD_TO_PARTY(YON,BARBARIAN,2,200,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(YON,BARBARIAN,2,200,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(YON,WIZARD,2,300,STEAL_SPELLS,0)

CREATE_PARTY(GO)
    ADD_TO_PARTY(GO,BARBARIAN,2,200,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(GO,BARBARIAN,2,200,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(GO,GIANT,2,400,ATTACK_ENEMIES,0)

CREATE_PARTY(KNIGHT)
    ADD_TO_PARTY(KNIGHT,BARBARIAN,2,200,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(KNIGHT,BARBARIAN,2,200,ATTACK_ENEMIES,0)
    ADD_TO_PARTY(KNIGHT,KNIGHT,4,200,ATTACK_ENEMIES,0)

SET_TIMER(PLAYER_GOOD,TIMER0)
IF(PLAYER_GOOD,FLAG0 == 0)
    IF(PLAYER_GOOD,TIMER0 > 2000)
        IF(PLAYER_GOOD,TOTAL_CREATURES <= 5)
            NEXT_COMMAND_REUSABLE
            ADD_PARTY_TO_LEVEL(PLAYER_GOOD,ICHI,-1,1)
            NEXT_COMMAND_REUSABLE
            SET_TIMER(PLAYER_GOOD,TIMER0)
        ENDIF
    ENDIF
ENDIF


SET_TIMER(PLAYER_GOOD,TIMER1)
IF(PLAYER_GOOD,FLAG0 == 0)
    IF(PLAYER_GOOD,TOTAL_CREATURES <= 5)
        IF(PLAYER_GOOD,TIMER1 > 4000)
            NEXT_COMMAND_REUSABLE
            ADD_PARTY_TO_LEVEL(PLAYER_GOOD,NI,-2,1)
            NEXT_COMMAND_REUSABLE
            SET_TIMER(PLAYER_GOOD,TIMER1)
        ENDIF
    ENDIF
ENDIF

SET_TIMER(PLAYER_GOOD,TIMER2)
IF(PLAYER_GOOD,FLAG0 == 0)
    IF(PLAYER_GOOD,TIMER2 > 7500)
        IF(PLAYER_GOOD,TOTAL_CREATURES <= 5)
            
            NEXT_COMMAND_REUSABLE
            ADD_PARTY_TO_LEVEL(PLAYER_GOOD,SAN,-3,1)
            NEXT_COMMAND_REUSABLE
            SET_TIMER(PLAYER_GOOD,TIMER2)
        ENDIF
    ENDIF
ENDIF


SET_TIMER(PLAYER_GOOD,TIMER3)
IF(PLAYER_GOOD,FLAG0 == 0)
    IF(PLAYER_GOOD,TIMER3 > 10000)
        IF(PLAYER_GOOD,TOTAL_CREATURES <= 5)
            NEXT_COMMAND_REUSABLE
            ADD_PARTY_TO_LEVEL(PLAYER_GOOD,YON,-2,1)
            NEXT_COMMAND_REUSABLE
            SET_TIMER(PLAYER_GOOD,TIMER3)
        ENDIF
    ENDIF
ENDIF


SET_TIMER(PLAYER_GOOD,TIMER4)
IF(PLAYER_GOOD,FLAG0 == 0)
    IF(PLAYER_GOOD,TIMER4 > 15000)
        IF(PLAYER_GOOD,TOTAL_CREATURES <= 5)
            NEXT_COMMAND_REUSABLE
            ADD_PARTY_TO_LEVEL(PLAYER_GOOD,GO,-1,1)
            NEXT_COMMAND_REUSABLE
            SET_TIMER(PLAYER_GOOD,TIMER4)
        ENDIF
    ENDIF
ENDIF

SET_TIMER(PLAYER_GOOD,TIMER5)

IF(PLAYER1,DUNGEON_DESTROYED == 1)
    SET_FLAG(PLAYER_GOOD,FLAG0,1)
ENDIF

IF(PLAYER_GOOD,TIMER5 >= 20000)
    SET_FLAG(PLAYER_GOOD,FLAG0,1)
    IF(PLAYER_GOOD,TOTAL_CREATURES == 0)
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,KNIGHT,-2,1)
        SET_FLAG(PLAYER_GOOD,FLAG1,1)
        REM CREATE_TEXT(10,73"THE HEROES HAVE BEED DEFEATED AND THEIR LORD ARRIVES FOR ONE LAST DESPERATE STAND.")
        DISPLAY_OBJECTIVE(73,PLAYER0)
        IF(PLAYER_GOOD,TOTAL_CREATURES == 0)
            IF(PLAYER_GOOD,FLAG0 == 0)
                REM CREATE_TEXT(74,"THE HEROES ARE DECIMATED.  NOW DESTROY THE ENEMY DUNGEON KEEPER.")
                DISPLAY_OBJECTIVE(74,PLAYER0)
            ENDIF
        ENDIF
    ENDIF
ENDIF
IF(PLAYER_GOOD,FLAG1 == 1)
    IF(PLAYER_GOOD,TOTAL_CREATURES == 0)
        IF(PLAYER1,DUNGEON_DESTROYED == 1)
            REM CREATE_TEXT(75,"YOU HAVE DEFEATED BOTH SIDES AND NOW CONTROL THE ENTIRE LAND.")
            DISPLAY_OBJECTIVE(75,PLAYER0)
            WIN_GAME
        ENDIF
    ENDIF
ENDIF
