REM	Level 444 Grail Run
REM	Author: Kix, Created on 17 Jun 2018
REM	updated to use pot file messages by dayokay Jan2021

LEVEL_VERSION(1)

START_MONEY(PLAYER0,12000)

DOOR_AVAILABLE(PLAYER0,BRACED,1,3)

ROOM_AVAILABLE(ALL_PLAYERS,TREASURE,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,LAIR,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,GARDEN,1,1)

MAGIC_AVAILABLE(PLAYER0,POWER_HAND,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_SLAP,1,1)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CALL_TO_ARMS,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_PROTECT,1,1)

CREATE_PARTY(ONE_SOUTH)
CREATE_PARTY(TWO_SOUTH)
CREATE_PARTY(THREE_SOUTH)
CREATE_PARTY(FOUR_SOUTH)
CREATE_PARTY(FINAL_SOUTH)

CREATE_PARTY(ONE_NORTH)
CREATE_PARTY(TWO_NORTH)
CREATE_PARTY(THREE_NORTH)
CREATE_PARTY(FOUR_NORTH)
CREATE_PARTY(FINAL_NORTH)

SET_CREATURE_STRENGTH(TENTACLE,160)
SET_CREATURE_HEALTH(TENTACLE,2200)

SET_CREATURE_STRENGTH(SPIDER,160)
SET_CREATURE_HEALTH(SPIDER,1750)

SET_CREATURE_STRENGTH(BUG,100)
SET_CREATURE_HEALTH(BUG,2200)

SET_CREATURE_FEAR_STRONGER(SORCEROR,9000)
SET_CREATURE_FEAR_STRONGER(WITCH,9000)
SET_CREATURE_FEAR_STRONGER(MONK,9000)
SET_CREATURE_FEAR_STRONGER(DWARFA,9000)
SET_CREATURE_FEAR_STRONGER(ARCHER,9000)
SET_CREATURE_FEAR_STRONGER(HORNY,9000)
SET_CREATURE_FEAR_STRONGER(VAMPIRE,9000)
SET_CREATURE_FEAR_STRONGER(WIZARD,9000)
SET_CREATURE_FEAR_STRONGER(BARBARIAN,9000)


rem ******** flag7 means player captured something

IF(PLAYER0,WORKSHOP>=15)
	SET_FLAG(PLAYER0,FLAG0,1)
	SET_FLAG(PLAYER0,FLAG7,1)
ENDIF
IF(PLAYER0,WORKSHOP>=30)
	SET_FLAG(PLAYER0,FLAG0,2)
ENDIF
IF(PLAYER0,WORKSHOP>=45)
	SET_FLAG(PLAYER0,FLAG0,3)
	ROOM_AVAILABLE(PLAYER0,WORKSHOP,1,1)
	TUTORIAL_FLASH_BUTTON(13,90)
ENDIF

IF(PLAYER0,TRAINING>=4)
	SET_FLAG(PLAYER0,FLAG1,1)
	SET_FLAG(PLAYER0,FLAG7,1)
ENDIF
IF(PLAYER0,TRAINING>=8)
	SET_FLAG(PLAYER0,FLAG1,2)
ENDIF
IF(PLAYER0,TRAINING>=12)
	SET_FLAG(PLAYER0,FLAG1,3)
ENDIF
IF(PLAYER0,TRAINING>=16)
	SET_FLAG(PLAYER0,FLAG1,4)
	ROOM_AVAILABLE(PLAYER0,TRAINING,1,1)
	TUTORIAL_FLASH_BUTTON(10,90)
ENDIF


IF(PLAYER0,TEMPLE>=9)
	SET_FLAG(PLAYER0,FLAG3,1)
	SET_FLAG(PLAYER0,FLAG7,1)
ENDIF
IF(PLAYER0,TEMPLE>=18)
	SET_FLAG(PLAYER0,FLAG3,2)
ENDIF
IF(PLAYER0,TEMPLE>=27)
	SET_FLAG(PLAYER0,FLAG3,3)
	ROOM_AVAILABLE(PLAYER0,TEMPLE,1,1)
	TUTORIAL_FLASH_BUTTON(12,90)
ENDIF

IF(PLAYER0,RESEARCH>=9)
	SET_FLAG(PLAYER0,FLAG4,1)
	SET_FLAG(PLAYER0,FLAG7,1)
ENDIF
IF(PLAYER0,RESEARCH>=18)
	SET_FLAG(PLAYER0,FLAG4,2)
ENDIF
IF(PLAYER0,RESEARCH>=27)
	SET_FLAG(PLAYER0,FLAG4,3)
ENDIF
IF(PLAYER0,RESEARCH>=36)
	SET_FLAG(PLAYER0,FLAG4,4)
	ROOM_AVAILABLE(PLAYER0,RESEARCH,1,1)
	TUTORIAL_FLASH_BUTTON(9,90)
ENDIF

IF(PLAYER0,BARRACKS>=9)
	SET_FLAG(PLAYER0,FLAG6,1)
	SET_FLAG(PLAYER0,FLAG7,1)
ENDIF
IF(PLAYER0,BARRACKS>=18)
	SET_FLAG(PLAYER0,FLAG6,2)
	ROOM_AVAILABLE(PLAYER0,BARRACKS,1,1)
	TUTORIAL_FLASH_BUTTON(16,90)
ENDIF

SET_TIMER(PLAYER0,TIMER0)

IF(PLAYER0,TIMER0>650)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER0)
	
	
	
	IF(PLAYER0,IMP<5)
		NEXT_COMMAND_REUSABLE
		PLAY_MESSAGE(PLAYER0,SOUND,116)
		NEXT_COMMAND_REUSABLE
		ADD_CREATURE_TO_LEVEL(PLAYER0,IMP,-1,1,10,0)
	ENDIF
	
	IF(PLAYER0,TOTAL_CREATURES<22)
		NEXT_COMMAND_REUSABLE
		PLAY_MESSAGE(PLAYER0,SOUND,116)
		IF(PLAYER0,FLAG0==1)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,DWARFA,-1,1,4,0)
		ENDIF
		IF(PLAYER0,FLAG0==2)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,DWARFA,-1,1,7,0)
		ENDIF
		IF(PLAYER0,FLAG0==3)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,DWARFA,-1,1,10,0)
		ENDIF
		
		IF(PLAYER0,FLAG1==1)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,ARCHER,-1,1,2,0)
		ENDIF
		IF(PLAYER0,FLAG1==2)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,ARCHER,-1,1,4,0)
		ENDIF
		IF(PLAYER0,FLAG1==3)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,ARCHER,-1,1,7,0)
		ENDIF
		IF(PLAYER0,FLAG1==4)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,ARCHER,-1,1,10,0)
		ENDIF
		
		IF(PLAYER0,FLAG3==1)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,MONK,-1,1,4,0)
		ENDIF
		IF(PLAYER0,FLAG3==2)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,MONK,-1,1,7,0)
		ENDIF
		IF(PLAYER0,FLAG3==3)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,MONK,-1,1,10,0)
		ENDIF
		
		IF(PLAYER0,FLAG4==1)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,SORCEROR,-1,1,3,0)
		ENDIF
		IF(PLAYER0,FLAG4==2)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,SORCEROR,-1,1,5,0)
		ENDIF
		IF(PLAYER0,FLAG4==3)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,SORCEROR,-1,1,8,0)
		ENDIF
		IF(PLAYER0,FLAG4==4)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,SORCEROR,-1,1,10,0)
		ENDIF
		
		IF(PLAYER0,FLAG6==1)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,BARBARIAN,-1,1,5,0)
		ENDIF
		IF(PLAYER0,FLAG6==2)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER0,BARBARIAN,-1,1,9,0)
		ENDIF
	
	ENDIF
ENDIF

IF(PLAYER0,FLAG7>0)
	SET_TIMER(PLAYER0,TIMER1)
	REM	QUICK_OBJECTIVE(2,"As you got your first room, heroes have started gathering their troops and will be here soon. The more heroes are wiped out, the stronger the groups they will form.",ALL_PLAYERS)
	DISPLAY_OBJECTIVE(103,ALL_PLAYERS)
IF(PLAYER0,TIMER1>4500)
	IF(PLAYER0,BATTLES_WON<100)
		REM	QUICK_OBJECTIVE(3,"First party has arrived! They seem to go lightly on on you. For now...",ALL_PLAYERS)
		DISPLAY_OBJECTIVE(104,ALL_PLAYERS)
		NEXT_COMMAND_REUSABLE
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,ONE_NORTH,-2,3)
		NEXT_COMMAND_REUSABLE
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,ONE_SOUTH,-3,1)
	ENDIF
	
	
	IF(PLAYER0,BATTLES_WON>=100)
		IF(PLAYER0,BATTLES_WON<200)
		REM	QUICK_OBJECTIVE(4,"Seeing their previous efforts went in vain heroes formed a new group.",ALL_PLAYERS)
		DISPLAY_OBJECTIVE(105,ALL_PLAYERS)
		NEXT_COMMAND_REUSABLE
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,TWO_NORTH,-2,2)
		NEXT_COMMAND_REUSABLE
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,TWO_SOUTH,-3,1)
	ENDIF
	ENDIF
	
	IF(PLAYER0,BATTLES_WON>=200)
	IF(PLAYER0,BATTLES_WON<270)
		REM	QUICK_OBJECTIVE(5,"Heroes arrived again, this time with modified creatures to aid them! Careful, as these are definitely tougher than any common dungeon creatures!",ALL_PLAYERS)
		DISPLAY_OBJECTIVE(106,ALL_PLAYERS)
		NEXT_COMMAND_REUSABLE
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,THREE_NORTH,-2,3)
		NEXT_COMMAND_REUSABLE
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,THREE_SOUTH,-3,1)
	ENDIF
	ENDIF
	
	IF(PLAYER0,BATTLES_WON>=270)
	IF(PLAYER0,BATTLES_WON<315)
		REM	QUICK_OBJECTIVE(6,"Heroes formed a new group again. If this attempt fails, the avatar will come and take care of you.",ALL_PLAYERS)
		DISPLAY_OBJECTIVE(107,ALL_PLAYERS)
		NEXT_COMMAND_REUSABLE
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,FOUR_NORTH,-2,2)
		NEXT_COMMAND_REUSABLE
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,FOUR_SOUTH,-3,1)
	ENDIF
	ENDIF
	
	
	
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER1)
	NEXT_COMMAND_REUSABLE
	BONUS_LEVEL_TIME(4500)
	
	IF(PLAYER0,BATTLES_WON>=315)
		PLAY_MESSAGE(PLAYER0,SPEECH,106)
		REM	QUICK_OBJECTIVE(7,"It's time to prove yourself, Keeper. Clear the last wave and the land is yours!",ALL_PLAYERS)
		DISPLAY_OBJECTIVE(108,ALL_PLAYERS)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,FINAL_NORTH,-2,1)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,FINAL_SOUTH,-3,1)
		SET_TIMER(PLAYER0,TIMER2)
		NEXT_COMMAND_REUSABLE
		BONUS_LEVEL_TIME(0)
	ENDIF
	
ENDIF
ENDIF

IF(PLAYER0,TIMER2>60)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER2)
	IF(PLAYER_GOOD,AVATAR==0)
		IF(PLAYER_GOOD,KNIGHT==0)
			REM	QUICK_OBJECTIVE(8,"Humiliating defeat for the heroes. Congratulations!",ALL_PLAYERS)
			DISPLAY_OBJECTIVE(109,ALL_PLAYERS)
			WIN_GAME
		ENDIF
	ENDIF
ENDIF



REM ******************************************************************************************************************

REM	QUICK_OBJECTIVE(1,"You are in possession of very unusual hero gate located to the east of your dungeon heart. It attracts units from other realms based on your dungeon room pool. Get rooms to attract more and stronger units to help you. Barracks=Barbarians, Workshop=Dwarves, Library=Warlocks, Temple=Monks, Training Rooms=Archers. New units arrive in groups and will only arrive if you have less than 22 of units. Withstand the hero waves, defeat the avatar along with his guards and this land is yours!",ALL_PLAYERS)
DISPLAY_OBJECTIVE(110,PLAYER0)


ADD_TO_PARTY(ONE_NORTH,BARBARIAN,4,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(ONE_NORTH,MONK,4,0,ATTACK_DUNGEON_HEART,0)

ADD_TO_PARTY(ONE_SOUTH,BARBARIAN,3,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(ONE_SOUTH,DWARFA,2,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(ONE_SOUTH,DWARFA,2,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(ONE_SOUTH,ARCHER,3,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(ONE_SOUTH,ARCHER,3,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(ONE_SOUTH,WIZARD,2,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(ONE_SOUTH,WIZARD,2,0,ATTACK_DUNGEON_HEART,0)

ADD_TO_PARTY(TWO_NORTH,GIANT,7,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(TWO_NORTH,THIEF,7,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(TWO_NORTH,BARBARIAN,7,0,ATTACK_DUNGEON_HEART,0)

ADD_TO_PARTY(TWO_SOUTH,BARBARIAN,6,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(TWO_SOUTH,DWARFA,5,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(TWO_SOUTH,DWARFA,5,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(TWO_SOUTH,THIEF,5,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(TWO_SOUTH,THIEF,5,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(TWO_SOUTH,FAIRY,5,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(TWO_SOUTH,FAIRY,5,0,ATTACK_DUNGEON_HEART,0)

ADD_TO_PARTY(THREE_NORTH,SPIDER,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(THREE_NORTH,SPIDER,10,0,ATTACK_DUNGEON_HEART,0)


ADD_TO_PARTY(THREE_SOUTH,SAMURAI,6,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(THREE_SOUTH,SAMURAI,6,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(THREE_SOUTH,SAMURAI,6,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(THREE_SOUTH,SAMURAI,6,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(THREE_SOUTH,SAMURAI,6,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(THREE_SOUTH,WIZARD,6,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(THREE_SOUTH,WIZARD,6,0,ATTACK_DUNGEON_HEART,0)

ADD_TO_PARTY(FOUR_NORTH,SPIDER,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FOUR_NORTH,TENTACLE,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FOUR_NORTH,BUG,10,0,ATTACK_DUNGEON_HEART,0)


ADD_TO_PARTY(FOUR_SOUTH,KNIGHT,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FOUR_SOUTH,DWARFA,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FOUR_SOUTH,SAMURAI,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FOUR_SOUTH,ARCHER,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FOUR_SOUTH,MONK,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FOUR_SOUTH,WIZARD,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FOUR_SOUTH,WITCH,10,0,ATTACK_DUNGEON_HEART,0)

ADD_TO_PARTY(FINAL_NORTH,AVATAR,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_NORTH,KNIGHT,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_NORTH,KNIGHT,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_NORTH,SAMURAI,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_NORTH,SAMURAI,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_NORTH,WIZARD,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_NORTH,MONK,10,0,ATTACK_DUNGEON_HEART,0)

ADD_TO_PARTY(FINAL_SOUTH,AVATAR,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_SOUTH,KNIGHT,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_SOUTH,KNIGHT,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_SOUTH,BARBARIAN,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_SOUTH,GIANT,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_SOUTH,FAIRY,10,0,ATTACK_DUNGEON_HEART,0)
ADD_TO_PARTY(FINAL_SOUTH,WITCH,10,0,ATTACK_DUNGEON_HEART,0)
