REM ****************************************************************************
REM	Free Play levels : Standard Map Pack - KeeperFX
REM ****************************************************************************
REM	Script for Level 453 - Desperation
REM	Author:  Loobinex
REM	Date:    2015-09-10
REM	updated to use pot file for messages by dayokay Jan-2021
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 ****************************************************************************

REM Brief: Player has direct contact with 3 rival keepers with a head start and it would be wise to make them attack each other. When one dies the other two will join forces. And unless there's a swift victory, some heroes will show up just when things are starting to go well for the player.

LEVEL_VERSION(1)

SET_GENERATE_SPEED(550)
MAX_CREATURES(ALL_PLAYERS,17)
START_MONEY(ALL_PLAYERS,25000)

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

REM 	Hero Gate 1~4 - Hero room

REM		PLAYER0,FLAG0	- Single Keeper defeated
REM		PLAYER1,FLAG1	- Blue has been weak
REM		PLAYER2,FLAG2	- Green has been weak
REM		PLAYER3,FLAG3	- Yellow has been weak


REM 	PLAYER0,TIMER1 	- Victory timer
REM 	PLAYER0,TIMER2 	- Spawn hero timer

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

ROOM_AVAILABLE(ALL_PLAYERS,GUARD_POST,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TREASURE,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,RESEARCH,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,WORKSHOP,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,GARDEN,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,LAIR,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,GRAVEYARD,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,PRISON,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TORTURE,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TRAINING,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,SCAVENGER,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,BARRACKS,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TEMPLE,1,0)

MAGIC_AVAILABLE(ALL_PLAYERS,POWER_POSSESS,0,0)
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_CAVE_IN,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_OBEY,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HEAL_CREATURE,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HOLD_AUDIENCE,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CHICKEN,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SPEED,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_LIGHTNING,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CONCEAL,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_PROTECT,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_DISEASE,1,0)

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

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

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

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

CREATE_PARTY(LANDLORD)
	ADD_TO_PARTY(LANDLORD,KNIGHT,10,1500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(LANDLORD,WIZARD,10,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(LANDLORD,GIANT,8,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(LANDLORD,SAMURAI,8,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(LANDLORD,DWARFA,6,250,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,DWARFA,6,250,DEFEND_PARTY,0)

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

REM	"Your chances in this realm are slim to none. Three keepers here are stronger than you are. A desperate struggle awaits you. Hurry!"
DISPLAY_OBJECTIVE(43,ALL_PLAYERS)

REM When a single Keeper is defeated, the others will ally and an objective is displayed.
IF(PLAYER1,DUNGEON_DESTROYED == 1)
	SET_FLAG(PLAYER0,FLAG0,1)
	ALLY_PLAYERS(PLAYER2,PLAYER3,1)
ENDIF
IF(PLAYER2,DUNGEON_DESTROYED == 1)
	SET_FLAG(PLAYER0,FLAG0,1)
	ALLY_PLAYERS(PLAYER1,PLAYER3,1)
ENDIF
IF(PLAYER3,DUNGEON_DESTROYED == 1)
	SET_FLAG(PLAYER0,FLAG0,1)
	ALLY_PLAYERS(PLAYER1,PLAYER2,1)
ENDIF
IF(PLAYER0,FLAG0 == 1)
	REM	"The remaining keepers have allied against you. Kill all who stand against you."
	DISPLAY_OBJECTIVE(44,ALL_PLAYERS)
ENDIF


REM Take note whenever a Keeper is almost destroyed. If he gets strong again later, the player has only himself to blame.
IF(PLAYER0,GAME_TURN >= 9000)
	IF_CONTROLS(PLAYER1,TOTAL_CREATURES <= 2)
		ADD_TO_FLAG(PLAYER0,FLAG1,1)
		REM	"Blue is desperate, kill him."
		DISPLAY_INFORMATION(45,PLAYER1)
	ENDIF
	IF_CONTROLS(PLAYER2,TOTAL_CREATURES <= 2)
		ADD_TO_FLAG(PLAYER0,FLAG1,1)
		REM	"Green is trembling in fear. Finish the job,"
		DISPLAY_INFORMATION(46,PLAYER2)
	ENDIF
	IF_CONTROLS(PLAYER3,TOTAL_CREATURES <= 2)
		ADD_TO_FLAG(PLAYER0,FLAG1,1)
		REM	"Yellow can't take much more. Strike now to end him."
		DISPLAY_INFORMATION(47,PLAYER3)
	ENDIF
ENDIF


REM After at least 27 minutes of play, check if all keepers have been weak at least once. If this is the case, wait 3 minutes and spawn the heroes.
IF(PLAYER0,GAME_TURN >= 32400)
	IF(PLAYER0,TOTAL_CREATURES >= 16)
		IF(PLAYER0,FLAG1 >= 3)
			SET_TIMER(PLAYER0,TIMER2)
		ENDIF
	ENDIF
ENDIF
IF(PLAYER0,TIMER2 >= 3520)
	REM	"Drawn to the scent of desperation, the heroes come to cleanse the land of all evil. Make sure you are the last one standing."
	DISPLAY_OBJECTIVE(48,-1)
ENDIF
IF(PLAYER0,TIMER2 >= 3600)
	ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,LANDLORD,-1,DUNGEON_HEART,0,7,250)
	REVEAL_MAP_LOCATION(PLAYER0,-1,11)
	REVEAL_MAP_LOCATION(PLAYER0,-2,11)
	REVEAL_MAP_LOCATION(PLAYER0,-3,11)
	REVEAL_MAP_LOCATION(PLAYER0,-4,11)
ENDIF

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

IF(PLAYER0,ALL_DUNGEONS_DESTROYED == 1)
	IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 0)
		SET_TIMER(PLAYER0,TIMER1)
	ENDIF
ENDIF

IF(PLAYER0,TIMER1 >= 80)
	REM	"You are victorious. About time.")
	DISPLAY_OBJECTIVE(49,ALL_PLAYERS)
	WIN_GAME
ENDIF

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