REM ****************************************************************************
REM  Campaigns Consolidation Project for KeeperFX strategy game.
REM ****************************************************************************
REM  Script for Bonus Level - Imp frying Hidden Realm
REM  Campaign: New game plus
REM  Authors:  based on Bullfrog script
REM            KeeperFX CCP Team
REM            Loobinex
REM  Date:   17 Aug 1997 - 24 Aug 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,120000)

MAGIC_AVAILABLE(PLAYER0,POWER_LIGHTNING,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_CAVE_IN,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_POSSESS,0,0)

SET_CREATURE_HEALTH(HELL_HOUND,10)
SET_CREATURE_HEALTH(SORCEROR,10)

IF(PLAYER0,CAMPAIGN_FLAG4 <= 0)
	IF(PLAYER0,FLAG4 <=0)
		IF(PLAYER0,GAME_TURN >= 40)
			ADD_CREATURE_TO_LEVEL(PLAYER_NEUTRAL,SORCEROR,1,1,1,0)
			SET_FLAG(PLAYER0,FLAG4,1)
		ENDIF
	ENDIF
ENDIF
IF(PLAYER0,CAMPAIGN_FLAG4 == 1)
	IF(PLAYER0,GAME_TURN >= 40)
		IF(PLAYER0,FLAG4 <=0)
			ADD_CREATURE_TO_LEVEL(PLAYER0,SORCEROR,1,1,1,0)
			SET_FLAG(PLAYER0,FLAG4,1)
		ENDIF
	ENDIF
ENDIF

IF(PLAYER0,CAMPAIGN_FLAG3 <= 2)

	REM "You must have lightning reflexes to complete the task ahead of you. Kill these Imps as quickly as you can."
	DISPLAY_OBJECTIVE(144,PLAYER0)

	SET_TIMER(PLAYER0,TIMER0)
	BONUS_LEVEL_TIME(2500)

	IF(PLAYER0,TIMER0 == 1250)
		IF(PLAYER0,FLAG1 == 0)
			REM "Half your allotted time has elapsed."
			DISPLAY_INFORMATION(145,ALL_PLAYERS)
		ENDIF
	ENDIF

	IF(PLAYER0,IMP == 0)
		REM "It is done. Tiny heaps of charred flesh smoulder where Imps once stood. You certainly had your finger on the pulse this time."
		DISPLAY_OBJECTIVE(147,PLAYER0)
		ADD_CREATURE_TO_LEVEL(PLAYER0,IMP,PLAYER0,1,1,10000)
		ROOM_AVAILABLE(ALL_PLAYERS,BRIDGE,1,1)
		MAGIC_AVAILABLE(PLAYER0,POWER_POSSESS,1,1)
		REM Using a timer to make sure add creature command will be executed
		SET_TIMER(PLAYER0,TIMER1)
		SET_FLAG(PLAYER0,FLAG1,1)
		ADD_OBJECT_TO_LEVEL(SPECBOX_TRANSFR,2,0)
	ENDIF

	IF(PLAYER0,FLAG1 == 1)
		IF(PLAYER0,CAMPAIGN_FLAG3 <= 1)
			ADD_CREATURE_TO_LEVEL(PLAYER0,HELL_HOUND,PLAYER0,1,2,10000)
		ENDIF
	ENDIF

	IF(PLAYER0,TIMER0 >= 2500)
		IF(PLAYER0,FLAG1 == 0)
			REM "You are out of time. That was a shocking performance."
			DISPLAY_OBJECTIVE(146,PLAYER0)
			LOSE_GAME 
		ENDIF
	ENDIF

	IF(PLAYER0,MONEY < 600)
		REM "You have no gold left. It pays to keep your head in such a charged environment."
		DISPLAY_OBJECTIVE(148,PLAYER0)
	ENDIF
ENDIF

IF(PLAYER0,TIMER1 >= 100)
	IF(PLAYER0,CAMPAIGN_FLAG3 <= 0)
		SET_FLAG(PLAYER0,CAMPAIGN_FLAG3,1)
	ENDIF
	WIN_GAME
	BONUS_LEVEL_TIME(0)
	IF(PLAYER0,HELL_HOUND <= 0)
		IF(PLAYER0,CREATURES_TRANSFERRED > 0)
			IF(PLAYER0,FLAG6 != 1)
				IF(PLAYER0,FLAG7 == 0)
					REM There is a creature transferred, and it's not the Hound, so it must be the Warlock.
					SET_FLAG(PLAYER0,CAMPAIGN_FLAG3,2)
					SET_FLAG(PLAYER0,FLAG7,1)
				ENDIF
			ENDIF
		ENDIF
		IF(PLAYER0,CREATURES_TRANSFERRED == 0)
			REM No Hound and nothing transferred, this means the hound has died.
			SET_FLAG(PLAYER0,FLAG7,2)
		ENDIF
	ENDIF
ENDIF

IF(PLAYER0,SORCEROR >= 1)
	SET_FLAG(PLAYER0,CAMPAIGN_FLAG4,1)
ENDIF

IF(PLAYER0,CAMPAIGN_FLAG4 >= 1)
	IF(PLAYER0,FLAG1 == 1)
		IF(PLAYER0,GAME_TURN >= 60)
			IF(PLAYER0,SORCEROR <= 0)
				IF(PLAYER0,CREATURES_TRANSFERRED > 0)
					IF(PLAYER0,FLAG7 != 1)
						IF(PLAYER0,FLAG6 == 0)
							REM There's a creature transfer, but it's not the hound, so it must be the warlock.
							SET_FLAG(PLAYER0,CAMPAIGN_FLAG4,2)
							SET_FLAG(PLAYER0,FLAG6,1)
						ENDIF
					ENDIF
				ENDIF
				IF(PLAYER0,CREATURES_TRANSFERRED == 0)
					REM The Warlock is gone, but there's no creature transfer yet, so it must have died.
					SET_FLAG(PLAYER0,FLAG6,2)
				ENDIF
			ENDIF
		ENDIF
	ENDIF
ENDIF

REM If both the hound and the sorceror are gone, the level if pointless.
IF(PLAYER0,CAMPAIGN_FLAG3 == 2)
	IF(PLAYER0,CAMPAIGN_FLAG4 >= 2)
		SET_FLAG(PLAYER0,CAMPAIGN_FLAG3,3)
	ENDIF
ENDIF
IF(PLAYER0,CAMPAIGN_FLAG3 >= 3)
	KILL_CREATURE(PLAYER0,IMP,MOST_EXPERIENCED,50)
	BONUS_LEVEL_TIME(0)
	WIN_GAME
ENDIF
