REM ****************************************************************************
REM  Free Play levels - KeeperFX
REM ****************************************************************************
REM  Script for Level 455 - Frozen Legion
REM  Author:  Loobinex
REM  Date:    2016-04-06
REM		updated to use pot file for messages by dayokay Jan2021
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.
REM ****************************************************************************

REM Brief: This is a tower defense level. The player has to dig a path towards the heroes which will then continue to stream in. The workshop is to be used to survive the level. After enough time is passed a graveyard becomes available, and when the player has enough vampires the level can be completed.

LEVEL_VERSION(1)
SET_GENERATE_SPEED(600)
START_MONEY(PLAYER0,10000)
MAX_CREATURES(PLAYER0,20)

SET_CREATURE_ARMOUR(DRAGON,160)
SET_CREATURE_HEALTH(DRAGON,1200)

SET_GAME_RULE(GhostConvertChance,0)
SET_GAME_RULE(BodiesForVampire,8)

REM ****************************************************************************
REM Flags used:
REM  PLAYER0,FLAG1	- 	1: Game started

REM Timers used:
REM   PLAYER0,TIMER1 		- Main timer, starts when first creature is claimed
REM   PLAYER0,TIMER2 		- Timer for first hero stream
REM   PLAYER0,TIMER3 		- Timer for second hero stream
REM   PLAYER0,TIMER4 		- Timer for third hero stream
REM   PLAYER0,TIMER5 		- Timer for fourth hero stream
REM   PLAYER0,TIMER6 		- Timer for final hero stream

REM Action Points and Hero Gates
REM Action Point  1 - Hero portal
REM Action Point  2 - Level special
REM Action Point  3 - Hero Barracks
REM Action Point  4 - Hero Library
REM Action Point  5 - Hero Graveyard
REM Action Point  6 - Magic generator

REM Herogate  1 - Gold fortress
REM Herogate  2 - Next to hero heart

REM ****************************************************************************
REM Initial availability
REM ****************************************************************************

REM Player has to dig towards the dungeon special before he can start building his dungeon.
IF(PLAYER0,FLAG1 == 1)
ROOM_AVAILABLE(PLAYER0,TREASURE,1,1)
ROOM_AVAILABLE(PLAYER0,LAIR,1,1)
ROOM_AVAILABLE(PLAYER0,GARDEN,1,1)
ROOM_AVAILABLE(PLAYER0,TRAINING,1,1)
ROOM_AVAILABLE(PLAYER0,RESEARCH,1,1)
ROOM_AVAILABLE(PLAYER0,SCAVENGER,0,0)
ROOM_AVAILABLE(PLAYER0,WORKSHOP,0,0)
ROOM_AVAILABLE(PLAYER0,GUARD_POST,1,0)
ROOM_AVAILABLE(PLAYER0,TORTURE,1,0)
ROOM_AVAILABLE(PLAYER0,BARRACKS,4,0)
ROOM_AVAILABLE(PLAYER0,GRAVEYARD,4,0)

MAGIC_AVAILABLE(PLAYER0,POWER_IMP,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_SIGHT,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_HEAL_CREATURE,0,0)
MAGIC_AVAILABLE(PLAYER0,POWER_OBEY,1,0)

CREATURE_AVAILABLE(PLAYER0,FLY,1,0)
CREATURE_AVAILABLE(PLAYER0,BUG,1,0)
CREATURE_AVAILABLE(PLAYER0,SPIDER,1,0)
CREATURE_AVAILABLE(PLAYER0,TROLL,1,0)
CREATURE_AVAILABLE(PLAYER0,ORC,1,0)
CREATURE_AVAILABLE(PLAYER0,DEMONSPAWN,1,0)
CREATURE_AVAILABLE(PLAYER0,BILE_DEMON,1,0)
CREATURE_AVAILABLE(PLAYER0,SORCEROR,1,0)
CREATURE_AVAILABLE(PLAYER0,HELL_HOUND,1,0)
CREATURE_AVAILABLE(PLAYER0,DARK_MISTRESS,1,0)

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

REM Timer starts when the first creature is claimed.
ADD_TUNNELLER_TO_LEVEL(PLAYER_GOOD,1,DUNGEON,0,5,250)
SET_TIMER(PLAYER0,TIMER1)
SET_TIMER(PLAYER0,TIMER2)
ENDIF

ADD_CREATURE_TO_POOL(FLY,DRAWFROM(0~1))
ADD_CREATURE_TO_POOL(BUG,DRAWFROM(1~2))
ADD_CREATURE_TO_POOL(SPIDER,DRAWFROM(1~3))
ADD_CREATURE_TO_POOL(TROLL,1)
ADD_CREATURE_TO_POOL(ORC,3)
ADD_CREATURE_TO_POOL(DEMONSPAWN,3)
ADD_CREATURE_TO_POOL(BILE_DEMON,0)
ADD_CREATURE_TO_POOL(SORCEROR,1)
ADD_CREATURE_TO_POOL(HELL_HOUND,2)


REM ****************************************************************************
REM Hero Parties
REM ****************************************************************************

CREATE_PARTY(party1)
	ADD_TO_PARTY(party1,BARBARIAN,4,400,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(party1,DWARFA,3,300,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(party1,GIANT,1,100,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(party2)
	ADD_TO_PARTY(party2,WITCH,4,400,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(party2,FAIRY,4,300,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(party2,THIEF,4,1000,STEAL_GOLD,0)

CREATE_PARTY(party3)
	ADD_TO_PARTY(party3,WIZARD,4,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(party3,MONK,3,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(party3,ARCHER,2,200,STEAL_GOLD,0)
	ADD_TO_PARTY(party3,ARCHER,2,200,STEAL_GOLD,0)
	ADD_TO_PARTY(party3,ARCHER,2,200,STEAL_GOLD,0)

CREATE_PARTY(party4)
	ADD_TO_PARTY(party4,THIEF,7,1500,STEAL_GOLD,6000)
	ADD_TO_PARTY(party4,THIEF,5,2300,STEAL_GOLD,6000)
	ADD_TO_PARTY(party4,THIEF,4,1000,STEAL_GOLD,6000)

CREATE_PARTY(party5)
	ADD_TO_PARTY(party5,DWARFA,5,500,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(party5,DWARFA,5,500,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(party5,DWARFA,5,500,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(party5,DWARFA,5,500,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(party5,DWARFA,5,500,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(party5,DWARFA,5,500,ATTACK_ENEMIES,0)

CREATE_PARTY(LANDLORD)
	ADD_TO_PARTY(LANDLORD,KNIGHT,10,10000,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,SAMURAI,8,1000,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,SAMURAI,8,1000,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,WIZARD,7,750,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,WIZARD,7,750,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,WIZARD,7,750,DEFEND_PARTY,0)

REM ****************************************************************************
REM Level scripts
REM ****************************************************************************

REM Vampires will be replaced by 3 imps when you have less than 15.
IF(PLAYER0,IMP < 15)
	IF(PLAYER0,VAMPIRE >= 1)
	NEXT_COMMAND_REUSABLE
	KILL_CREATURE(PLAYER0,VAMPIRE,LEAST_EXPERIENCED,1)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER0,IMP,6,3,1,1)
	NEXT_COMMAND_REUSABLE
	PLAY_MESSAGE(PLAYER0,SOUND,496)
	REM "Your magic generator will feed off your vampires to give you a healthy number of imps. However, keep enough imps alive and you'll have an undead army to kill the heroes with."
	DISPLAY_OBJECTIVE(73,6)
	ENDIF
ENDIF

REM ****************************************************************************
REM Level starts here
REM ****************************************************************************

REM Show the starting special
REVEAL_MAP_LOCATION(PLAYER0,2,11)

REM "The heroes have gathered the biggest army you've ever seen, your creatures won't be able to put up a fight. Traps will be the key to victory here."
DISPLAY_OBJECTIVE(64,ALL_PLAYERS)

IF(PLAYER0,GAME_TURN >= 900)
	REM "The level will start when you claim your first creature."
	DISPLAY_INFORMATION(65,2)
ENDIF

REM Start the game when the special is used as intended, or if the player cheats by going for the gold.
IF(PLAYER0,TOTAL_CREATURES >= 1)
	SET_FLAG(PLAYER0,FLAG1,1)
ENDIF
IF(PLAYER0,FLAG1 == 0)
	IF(PLAYER0,TOTAL_GOLD_MINED >= 1050)
		SET_FLAG(PLAYER0,FLAG1,1)
		REM "You should have started by claiming the creature. Welcome to hard mode."
		DISPLAY_INFORMATION(66,ALL_PLAYERS)
	ENDIF
ENDIF

REM First repeating wave: weak dwarfs
IF(PLAYER0,TIMER2 >= 900)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,DWARFA,1,1,3,10)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER2)
ENDIF

REM After 8 minutes start second wave and provide access to barracks
IF(PLAYER0,TIMER1 >= 9600)
	SET_TIMER(PLAYER0,TIMER3)
	ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,party1,3,DUNGEON,0,5,450)
ENDIF
REM Second repeating wave: barbarians and archers
IF(PLAYER0,TIMER3 >= 1350)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BARBARIAN,1,1,2,15)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,ARCHER,1,1,3,16)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER3)
ENDIF

REM After 11 minutes start third wave and provide access to graveyard
IF(PLAYER0,TIMER1 >= 13200)
	SET_TIMER(PLAYER0,TIMER4)
	ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,party2,5,DUNGEON_HEART,0,5,530)
	REM "Corpses are starting to build up. Find a graveyard."
	DISPLAY_OBJECTIVE(67,ALL_PLAYERS) 
ENDIF
REM Third repeating wave: witches and fairies
IF(PLAYER0,TIMER4 >= 2330)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,WITCH,1,1,4,45)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,FAIRY,1,1,4,56)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER4)
	REM Just once:
	ADD_CREATURE_TO_POOL(TROLL,1)
ENDIF

IF(PLAYER0,GRAVEYARD >= 1)
	SET_TIMER(PLAYER0,TIMER5)
	REM "You have a fighting chance. Don't let the heroes whittle you down."
	DISPLAY_OBJECTIVE(72,ALL_PLAYERS)
ENDIF

REM Fourth repeating wave: wizards and monks. Timer has started when graveyard is claimed.
IF(PLAYER0,TIMER5 >= 4500)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,WIZARD,1,1,4,44)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,WIZARD,1,3,3,33)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,MONK,1,1,4,55)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER5)
	REM Just once:
	ADD_CREATURE_TO_POOL(ORC,2)
	ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,party3,4,DUNGEON_HEART,0,2,230)
ENDIF

REM When the hero library is claimed open up the eastern gold
IF(PLAYER_GOOD,RESEARCH <= 0)
	ROOM_AVAILABLE(PLAYER0,SCAVENGER,1,0)
	TUTORIAL_FLASH_BUTTON(14,200)
	ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,party4,-1,DUNGEON_HEART,0,5,2)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,party4,-1,1)
	ADD_CREATURE_TO_POOL(DARK_MISTRESS,1)
ENDIF

REM Every few minutes some creatures show up
IF(PLAYER0,TIMER1 >= 40000)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,WITCH,1,1,8,800)
ENDIF
IF(PLAYER0,TIMER1 >= 50000)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,DWARFA,1,12,1,100)
ENDIF
IF(PLAYER0,TIMER1 >= 60000)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,THIEF,1,3,3,333)
ENDIF
IF(PLAYER0,TIMER1 >= 70000)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,FAIRY,1,2,1,22)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,WIZARD,1,2,1,22)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,WITCH,1,2,1,22)
ENDIF
IF(PLAYER0,TIMER1 >= 80000)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,ARCHER,1,8,1,450)
ENDIF
IF(PLAYER0,TIMER1 >= 90000)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BARBARIAN,1,8,1,450)
	REM "The heroes will keep getting stronger, do something or perish."
	DISPLAY_INFORMATION(68,ALL_PLAYERS)
ENDIF
IF(PLAYER0,TIMER1 >= 100000)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,party5,1,5)
ENDIF
IF(PLAYER0,TIMER1 >= 120000)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,party5,3,3)
ENDIF
REM The player should have won by now, so stronger heroes need to be spawned.
IF(PLAYER0,TIMER1 >= 140000)
	SET_TIMER(PLAYER0,TIMER6)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,GIANT,1,6,1,650)
ENDIF
REM Final repeating wave: barbarians, archers and dwarves
IF(PLAYER0,TIMER6 >= 4000)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BARBARIAN,1,1,7,150)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,ARCHER,1,1,7,150)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,DWARFA,1,1,7,150)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER6)
	REM Just once:
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,SAMURAI,1,1,8,850)
ENDIF

REM When player starts to gain the upper hand add some more hero parties
IF(PLAYER0,TOTAL_CREATURES >= 22)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,party2,1,1)
ENDIF
IF(PLAYER0,TOTAL_CREATURES >= 23)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,party5,1,1)
ENDIF
IF(PLAYER0,TOTAL_CREATURES >= 24)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,party3,1,1)
ENDIF

REM When the player has enough vampires open up access to the dungeon heart
IF(PLAYER0,TOTAL_CREATURES >= 25)
	MAGIC_AVAILABLE(PLAYER0,POWER_CALL_TO_ARMS,1,0)
	TUTORIAL_FLASH_BUTTON(23,200)
	ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,party5,-2,DUNGEON_HEART,0,5,250)
	REM "You have the upper hand. Make a push to destroy their heart and break the attack."
	DISPLAY_OBJECTIVE(69,PLAYER_GOOD)
ENDIF

REM A brute force attack will draw out a hero party. Heart sniping will allow to beat the level without this fight.
IF_ACTION_POINT(7,PLAYER0)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,party5,-1,1)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,LANDLORD,-2,1)
	REM "End it now, kill the lord and destroy his heart to conquer this realm."
	DISPLAY_OBJECTIVE(70,PLAYER_GOOD)
ENDIF

REM ****************************************************************************
REM Win game
REM ****************************************************************************

IF(PLAYER0,ALL_DUNGEONS_DESTROYED == 1)
	IF(PLAYER_GOOD,KNIGHT <= 0)
		REM "That was easy. Victory."
		DISPLAY_OBJECTIVE(71,ALL_PLAYERS)
		WIN_GAME
	ENDIF
ENDIF

REM ****************************************************************************
REM End of file
REM ****************************************************************************
