REM ****************************************************************************
REM  Campaigns Consolidation Project for KeeperFX strategy game.
REM ****************************************************************************
REM  Script for Bonus Level - Demonspawn Hidden Realm (originally 5th bonus)
REM  Campaign: New Game +
REM  Authors:  based on Bullfrog script
REM		 KeeperFX CCP Team
REM  Date:   17 Aug 1997 - 29 jun 2020
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)
RUN_AFTER_VICTORY(1)
START_MONEY(PLAYER0,0)
SET_TRAP_CONFIGURATION(WORD_OF_POWER,Hidden,0)

IF(PLAYER0,CAMPAIGN_FLAG1 <= 0)
	REM "You have entered this realm to gain a creature for your further efforts. You got the creature from start, so you must only keep it safe. And the only way to make this place safe is to kill every hero in the realm."
	DISPLAY_OBJECTIVE(179,PLAYER0)

	BONUS_LEVEL_TIME(40000)
	SET_TIMER(PLAYER0,TIMER0)
ENDIF

IF(PLAYER0,FLAG1 < 1)
	IF(PLAYER0,TIMER0 >= 40000)
		LOSE_GAME
	ENDIF

	IF(PLAYER0,TOTAL_CREATURES == 0)
		LOSE_GAME
	ENDIF

	IF(PLAYER0,TOTAL_DIGGERS == 0)
		LOSE_GAME
	ENDIF

	IF_ACTION_POINT(1,PLAYER0)
		ROOM_AVAILABLE(ALL_PLAYERS,BRIDGE,1,1)
	ENDIF

	IF(PLAYER0,TIMER0 >= 20000)
		REM "How time flies... hurry!"
		DISPLAY_OBJECTIVE(166,PLAYER0)
	ENDIF
	
	IF(PLAYER0,CAMPAIGN_FLAG1 <= 0)
		IF(PLAYER0,DRAGON > 0)
		REM "Did you see? Your Demon Spawn has evolved to become a powerful Dragon ready to reduces your enemies into ashes!"
		DISPLAY_INFORMATION(174,ALL_PLAYERS)
		ENDIF
	ENDIF
ENDIF

REM You can only win normally if this is your first playthrough
IF(PLAYER0,CAMPAIGN_FLAG1 <= 0)
	IF(PLAYER_GOOD,TOTAL_CREATURES == 0)
		BONUS_LEVEL_TIME(0)
		SET_FLAG(PLAYER0,CAMPAIGN_FLAG1,1)
		SET_FLAG(PLAYER0,FLAG1,1)
		WIN_GAME
	ENDIF
ENDIF

REM Determine what happens after victory
IF(PLAYER0,CAMPAIGN_FLAG1 == 1)
	IF(PLAYER0,TOTAL_CREATURES == 0)
		REM If you won, and don't have creatures, you must have transferred it
		IF(PLAYER0,FLAG1 >= 1)
			SET_FLAG(PLAYER0,CAMPAIGN_FLAG1,2)
		ENDIF
	ENDIF
	REM If you did not win the level yet, but still have CF1=1, you must have won last time
	IF(PLAYER0,FLAG1 < 1)
		REM KILL ALL WHITE UNITS
		KILL_CREATURE(PLAYER_GOOD,ARCHER,MOST_EXPERIENCED,15)
		KILL_CREATURE(PLAYER_GOOD,SAMURAI,MOST_EXPERIENCED,4)
		KILL_CREATURE(PLAYER_GOOD,WIZARD,MOST_EXPERIENCED,6)
		KILL_CREATURE(PLAYER_GOOD,BARBARIAN,MOST_EXPERIENCED,8)
		KILL_CREATURE(PLAYER_GOOD,KNIGHT,MOST_EXPERIENCED,1)
		LEVEL_UP_CREATURE(PLAYER0,DEMONSPAWN,ANYWHERE,9)
		LEVEL_UP_CREATURE(PLAYER0,DEMONSPAWN,ANYWHERE,9)
		LEVEL_UP_CREATURE(PLAYER0,DRAGON,ANYWHERE,5)
		CHANGE_SLAB_OWNER(43,17,PLAYER0)
		REVEAL_MAP_LOCATION(PLAYER0,2,7)
		WIN_GAME
		IF(PLAYER0,TOTAL_CREATURES == 0)
			SET_FLAG(PLAYER0,CAMPAIGN_FLAG1,2)
		ENDIF
	ENDIF
ENDIF

IF(PLAYER0,CAMPAIGN_FLAG1 == 2)
	KILL_CREATURE(PLAYER0,IMP,MOST_EXPERIENCED,1)
	KILL_CREATURE(PLAYER0,DEMONSPAWN,MOST_EXPERIENCED,1)
	KILL_CREATURE(PLAYER_GOOD,ARCHER,MOST_EXPERIENCED,15)
	WIN_GAME
ENDIF
