REM ****************************************************************************
REM  Free Play levels - KeeperFX
REM ****************************************************************************
REM  Script for Level 457 - My Pet Dungeon
REM  Author:  Loobinex
REM  Date:    2017-11-13
REM		modified 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; either version 2 of the License, or
REM    (at your option) any later version.
REM ****************************************************************************

LEVEL_VERSION(1)
SET_GENERATE_SPEED(750)
START_MONEY(PLAYER0,25000)

REVEAL_MAP_LOCATION(PLAYER0,-1,13)
REVEAL_MAP_LOCATION(PLAYER0,-2,13)
REVEAL_MAP_LOCATION(PLAYER0,-3,13)
REVEAL_MAP_LOCATION(PLAYER0,-4,25)

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

REM ****************************************************************************
REM Flags used:
REM  PLAYER0,FLAG0		- Has player reached 100 creatures or not
REM  PLAYER0,FLAG1~3	- Used for Hero triggers 1~3

REM Timers used:
REM   PLAYER,TIMER1~3	- Used for Hero triggers 1~3
REM   PLAYER,TIMER4		- Used for Hero-spawn infinite loop
REM   PLAYER,TIMER5		- Total time Hero-swan infinite loop active. Determines victory.

REM Action Points and Hero Gates
REM Action Point 1 - Hero trigger 1
REM Action Point 2 - Hero trigger 2
REM Action Point 3 - Hero trigger 3
REM Action Point 4 - Bridge detect
REM Action Point 5 - Hero fortress
REM Hero Gate 1 - Inside hero room 1
REM Hero Gate 2 - Inside hero room 2
REM Hero Gate 3 - Inside hero room 3
REM Hero Gate 4 - Main party spawner
REM Hero Gate 5 - Hero fortress


REM ****************************************************************************
REM Initial availability
REM ****************************************************************************
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,WORKSHOP,1,0)
ROOM_AVAILABLE(PLAYER0,BARRACKS,1,0)
ROOM_AVAILABLE(PLAYER0,GUARD_POST,1,0)
ROOM_AVAILABLE(PLAYER0,PRISON,1,0)
ROOM_AVAILABLE(PLAYER0,TORTURE,1,0)
ROOM_AVAILABLE(PLAYER0,SCAVENGER,1,0)
ROOM_AVAILABLE(PLAYER0,TEMPLE,1,0)
ROOM_AVAILABLE(PLAYER0,GRAVEYARD,1,0)
ROOM_AVAILABLE(PLAYER0,SCAVENGER,1,0)

MAGIC_AVAILABLE(PLAYER0,POWER_HAND,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_SLAP,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_IMP,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_POSSESS,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_HEAL_CREATURE,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_CALL_TO_ARMS,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_SPEED,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_PROTECT,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_LIGHTNING,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_CONCEAL,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_TIME_BOMB,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_DISEASE,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_CHICKEN,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_HOLD_AUDIENCE,1,0)
MAGIC_AVAILABLE(PLAYER0,POWER_SIGHT,1,0)

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

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,SORCEROR,1,0)
CREATURE_AVAILABLE(PLAYER0,DARK_MISTRESS,1,0)
CREATURE_AVAILABLE(PLAYER0,BILE_DEMON,1,0)
CREATURE_AVAILABLE(PLAYER0,HELL_HOUND,1,0)
CREATURE_AVAILABLE(PLAYER0,DRUID,1,0)
CREATURE_AVAILABLE(PLAYER0,MAIDEN,1,0)

TRAP_AVAILABLE(PLAYER0,ALARM,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,SENTRY,1,0)
DOOR_AVAILABLE(PLAYER0,WOOD,1,0)
DOOR_AVAILABLE(PLAYER0,BRACED,1,0)
DOOR_AVAILABLE(PLAYER0,STEEL,1,0)
DOOR_AVAILABLE(PLAYER0,MAGIC,1,0)


REM ****************************************************************************
REM Portal limit
REM ****************************************************************************

REM Portal limit increases based on number of portals, and ignores evil creatures.
IF(PLAYER0,ENTRANCE <= 9)
	IF(PLAYER0,EVIL_CREATURES >= 25)
		NEXT_COMMAND_REUSABLE
		MAX_CREATURES(PLAYER0,25)
	ENDIF
	IF(PLAYER0,EVIL_CREATURES <= 24)
		NEXT_COMMAND_REUSABLE
		MAX_CREATURES(PLAYER0,100)
	ENDIF
ENDIF
IF(PLAYER0,ENTRANCE == 18)
	IF(PLAYER0,EVIL_CREATURES >= 50)
		NEXT_COMMAND_REUSABLE
		MAX_CREATURES(PLAYER0,50)
	ENDIF
	IF(PLAYER0,EVIL_CREATURES <= 49)
		NEXT_COMMAND_REUSABLE
		MAX_CREATURES(PLAYER0,100)
	ENDIF
ENDIF
IF(PLAYER0,ENTRANCE == 27)
	IF(PLAYER0,EVIL_CREATURES >= 75)
		NEXT_COMMAND_REUSABLE
		MAX_CREATURES(PLAYER0,75)
	ENDIF
	IF(PLAYER0,EVIL_CREATURES <= 74)
		NEXT_COMMAND_REUSABLE
		MAX_CREATURES(PLAYER0,100)
	ENDIF
ENDIF


REM ****************************************************************************
REM Additional availability
REM ****************************************************************************

IF_ACTION_POINT(4,PLAYER0)
	ROOM_AVAILABLE(PLAYER0,BRIDGE,1,0)
	TUTORIAL_FLASH_BUTTON(18,100)
	PLAY_MESSAGE(PLAYER0,SOUND,160)
ENDIF

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

CREATE_PARTY(weak)
	ADD_TO_PARTY(weak,DWARFA,3,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(weak,THIEF,3,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(weak,BARBARIAN,3,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(weak,ARCHER,3,500,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(hocus)
	ADD_TO_PARTY(hocus,WIZARD,5,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(hocus,FAIRY,5,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(hocus,WITCH,4,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(hocus,TIME_MAGE,4,500,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(strong)
	ADD_TO_PARTY(strong,GIANT,7,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(strong,SAMURAI,7,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(strong,MONK,7,500,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(LANDLORD)
	ADD_TO_PARTY(LANDLORD,AVATAR,10,5000,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(LANDLORD,KNIGHT,9,5000,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(LANDLORD,SAMURAI,8,5000,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(LANDLORD,WITCH,8,5000,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(LANDLORD,WIZARD,8,5000,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(yin)
	ADD_TO_PARTY(yin,GIANT,8,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yin,BARBARIAN,6,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yin,MONK,7,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yin,WIZARD,8,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yin,FAIRY,8,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yin,DWARFA,5,0,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(yang)
	ADD_TO_PARTY(yang,ARCHER,8,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yang,SAMURAI,7,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yang,THIEF,8,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yang,TIME_MAGE,5,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yang,FAIRY,6,0,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(yang,DWARFA,6,0,ATTACK_DUNGEON_HEART,0)
	
REM ****************************************************************************
REM Level starts here
REM ****************************************************************************

REM	"Welcome to SimDungeon. You can attract 25 evil creatures per portal. Heroes can be summoned at the spawner."
DISPLAY_OBJECTIVE(83,-4)
IF(PLAYER0,FLAG0 == 0)
	IF(PLAYER0,TOTAL_CREATURES >= 25)
		IF_AVAILABLE(PLAYER0,BRIDGE == 0)
			REM	"Find a way to build a bridge. It will help you to expand in this realm."
			DISPLAY_OBJECTIVE(84,ALL_PLAYERS)
		ENDIF
	ENDIF
	IF(PLAYER0,TOTAL_CREATURES >= 50)
		REM	"You're well on your way to an impressive dungeon. Get to one hundred units and we'll talk."
		DISPLAY_OBJECTIVE(85,ALL_PLAYERS)
	ENDIF
	IF(PLAYER0,TOTAL_CREATURES >= 74)
		IF(PLAYER0,ENTRANCE <= 18)
			REM	"There is a way to breach the white wall and take over the north-west corner of the map. Useful but optional."
			DISPLAY_OBJECTIVE(86,-5)
		ENDIF
	ENDIF
ENDIF

REM When a hero is removed, add it again through the script.
IF_CONTROLS(PLAYER_GOOD,DWARFA <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,DWARFA,-1,1,3,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,BARBARIAN <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BARBARIAN,-1,1,3,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,ARCHER <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,ARCHER,-1,1,3,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,THIEF <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,THIEF,-1,1,3,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,WIZARD <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,WIZARD,-3,1,5,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,WITCH <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,WITCH,-3,1,4,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,FAIRY <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,FAIRY,-3,1,5,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,TIME_MAGE <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,TIME_MAGE,-3,1,4,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,GIANT <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,GIANT,-2,1,7,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,SAMURAI <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,SAMURAI,-2,1,7,0)
ENDIF
IF_CONTROLS(PLAYER_GOOD,MONK <= 0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,MONK,-2,1,7,0)
ENDIF


REM When at 100 creatures, player may trigger a full invasion by selling his prison.
IF(PLAYER0,TOTAL_CREATURES >= 100)
	SET_FLAG(PLAYER0,FLAG0,1)
	REM	"You have a most impressive army. When you're done sell your prison. It will trigger an endless invasion."
	DISPLAY_OBJECTIVE(87,-5)
	PLAY_MESSAGE(PLAYER0,SOUND,116)
ENDIF
IF(PLAYER0,FLAG0 == 1)
	IF(PLAYER0,PRISON <= 0)
		ROOM_AVAILABLE(PLAYER0,PRISON,0,0)
		MAGIC_AVAILABLE(PLAYER0,POWER_HAND,0,0)
		MAGIC_AVAILABLE(PLAYER0,POWER_POSSESS,0,0)
		SET_TIMER(PLAYER0,TIMER4)
		SET_TIMER(PLAYER0,TIMER5)
		BONUS_LEVEL_TIME(36000)
		PLAY_MESSAGE(PLAYER0,SOUND,84)
		REM	"Let's see how well your dungeon really is. How long can you survive?"
		DISPLAY_OBJECTIVE(88,PLAYER0)
		ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,LANDLORD,-5,DUNGEON,0,5,500)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,weak,-4,1)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,weak,-5,1)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,strong,-4,1)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,strong,-5,1)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,hocus,-4,1)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,hocus,-5,1)
		IF(PLAYER0,TIMER4 >= 900)
			IF(PLAYER_GOOD,TOTAL_CREATURES <= 120)
				NEXT_COMMAND_REUSABLE
				ADD_PARTY_TO_LEVEL(PLAYER_GOOD,yin,-4,1)
				NEXT_COMMAND_REUSABLE
				ADD_PARTY_TO_LEVEL(PLAYER_GOOD,yin,-5,1)
				NEXT_COMMAND_REUSABLE
				ADD_PARTY_TO_LEVEL(PLAYER_GOOD,yang,-4,1)
				NEXT_COMMAND_REUSABLE
				ADD_PARTY_TO_LEVEL(PLAYER_GOOD,yang,-5,1)
				NEXT_COMMAND_REUSABLE
				SET_TIMER(PLAYER0,TIMER4)
			ENDIF
		ENDIF
	ENDIF
ENDIF

REM ****************************************************************************
REM Hero trigger - player gets to spawn heroes on demand
REM ****************************************************************************

IF(PLAYER0,FLAG1 == 0)
	IF_ACTION_POINT(1,PLAYER0)
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER0,FLAG1,1)
	ENDIF
ENDIF
IF(PLAYER0,FLAG1 == 1)
	NEXT_COMMAND_REUSABLE
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,weak,-4,1)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER1)
	NEXT_COMMAND_REUSABLE
	SET_FLAG(PLAYER0,FLAG1,2)
ENDIF
IF(PLAYER0,FLAG1 == 2)
	IF(PLAYER0,TIMER1 >= 200)
		NEXT_COMMAND_REUSABLE
		RESET_ACTION_POINT(1)
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER0,FLAG1,0)
	ENDIF
ENDIF
IF(PLAYER0,FLAG2 == 0)
	IF_ACTION_POINT(2,PLAYER0)
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER0,FLAG2,1)
	ENDIF
ENDIF
IF(PLAYER0,FLAG2 == 1)
	NEXT_COMMAND_REUSABLE
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,hocus,-4,1)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER2)
	NEXT_COMMAND_REUSABLE
	SET_FLAG(PLAYER0,FLAG2,2)
ENDIF
IF(PLAYER0,FLAG2 == 2)
	IF(PLAYER0,TIMER2 >= 200)
		NEXT_COMMAND_REUSABLE
		RESET_ACTION_POINT(2)
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER0,FLAG2,0)
	ENDIF
ENDIF
IF(PLAYER0,FLAG3 == 0)
	IF_ACTION_POINT(3,PLAYER0)
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER0,FLAG3,1)
	ENDIF
ENDIF
IF(PLAYER0,FLAG3 == 1)
	NEXT_COMMAND_REUSABLE
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,strong,-4,1)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER0,TIMER3)
	NEXT_COMMAND_REUSABLE
	SET_FLAG(PLAYER0,FLAG3,2)
ENDIF
IF(PLAYER0,FLAG3 == 2)
	IF(PLAYER0,TIMER3 >= 200)
		NEXT_COMMAND_REUSABLE
		RESET_ACTION_POINT(3)
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER0,FLAG3,0)
	ENDIF
ENDIF

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

IF(PLAYER0,TIMER5 >= 36000)
	ROOM_AVAILABLE(PLAYER0,PRISON,1,1)
	MAGIC_AVAILABLE(PLAYER0,POWER_HAND,1,1)
	MAGIC_AVAILABLE(PLAYER0,POWER_POSSESS,1,1)
	SET_FLAG(PLAYER0,FLAG0,2)
	REM	"You've done the impossible. Victory."
	DISPLAY_OBJECTIVE(89,PLAYER0)
	BONUS_LEVEL_TIME(0)
	WIN_GAME
ENDIF

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