REM ****************************************************************************
REM  Campaigns Consolidation Project for KeeperFX strategy game.
REM ****************************************************************************
REM  Script for Level Eversmile
REM  Campaign: DK Original
REM  Authors:  based on Bullfrog script
REM            KeeperFX CCP Team
REM  Date:     17 Aug 1997 - 06 Feb 2011
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 New rooms for the player:
REM   TREASURE - at start
REM   LAIR - after treasury is filled with gold
REM   GARDEN - when BUG comes
REM New creatures for the player:
REM   FLY - first creature
REM   BUG - when got at least one fly

REM Flags used:
REM  PLAYER0,FLAG2 - Gold mining; 0-no gold mined; 1-gold mined > 0.
REM  PLAYER0,FLAG1 - Rooms building; 1-treasury built AND almost all gold mined
REM  PLAYER0,FLAG0 - Progress state; 1-treasury built; 3-lair built;
REM                  4-hatchery built; 5-ready for 1st battle;
REM                  6-won 1st battle; 7-lord of the land has appeared.

SET_GENERATE_SPEED(400)

START_MONEY(PLAYER0,2500)

MAX_CREATURES(PLAYER0,7)

ADD_CREATURE_TO_POOL(FLY,3)
ADD_CREATURE_TO_POOL(BUG,12)

CREATURE_AVAILABLE(PLAYER0,FLY,1,1)

ROOM_AVAILABLE(PLAYER0,TREASURE,1,1)
ROOM_AVAILABLE(PLAYER0,LAIR,1,0)
ROOM_AVAILABLE(PLAYER0,GARDEN,1,0)

MAGIC_AVAILABLE(PLAYER0,POWER_SLAP,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_HAND,1,1)
MAGIC_AVAILABLE(PLAYER0,POWER_IMP,1,0)

SET_CREATURE_FEAR(TUNNELLER,0)
SET_CREATURE_FEAR(THIEF,0)
SET_CREATURE_FEAR(KNIGHT,0)

SET_CREATURE_MAX_LEVEL(PLAYER_GOOD,KNIGHT,1)
SET_CREATURE_MAX_LEVEL(PLAYER_GOOD,THIEF,1)
SET_CREATURE_MAX_LEVEL(PLAYER_GOOD,TUNNELLER,1)

SET_CREATURE_STRENGTH(KNIGHT,30)
SET_CREATURE_ARMOUR(KNIGHT,30)
SET_CREATURE_STRENGTH(TUNNELLER,20)
SET_CREATURE_ARMOUR(TUNNELLER,20)

CREATE_PARTY(LANDLORD)
	ADD_TO_PARTY(LANDLORD,KNIGHT,1,1000,ATTACK_ENEMIES,0)

CREATE_PARTY(THIEVES)
	ADD_TO_PARTY(THIEVES,THIEF,1,100,ATTACK_ENEMIES,0)

REM ****************************************************************************

DISPLAY_OBJECTIVE(2,PLAYER0)
TUTORIAL_FLASH_BUTTON(6,-1)

IF(PLAYER0,TREASURE >= 1)
	IF(PLAYER0,GAME_TURN > 175)
		DISPLAY_INFORMATION(3)
	ENDIF
ENDIF

IF(PLAYER0,GAME_TURN > 125)
	DISPLAY_INFORMATION(1)
ENDIF

IF(PLAYER0,TREASURE >= 9)
	DISPLAY_OBJECTIVE(4,PLAYER0)
	SET_FLAG(PLAYER0,FLAG0,1)
ENDIF

REM Started mining gold
IF(PLAYER0,TOTAL_GOLD_MINED > 0)
	SET_FLAG(PLAYER0,FLAG2,1)
ENDIF

REM Show infos during the mining; when mined go to stage FLAG0=3
IF(PLAYER0,FLAG0 >= 1)
	IF(PLAYER0,FLAG2 == 1)
		IF(PLAYER0,TOTAL_GOLD_MINED >= 1000)
			DISPLAY_INFORMATION(5)
 			IF(PLAYER0,TOTAL_GOLD_MINED >= 5000)
				DISPLAY_INFORMATION(6)
				IF(PLAYER0,TOTAL_GOLD_MINED >= 9000)
					SET_FLAG(PLAYER0,FLAG1,1)
					DISPLAY_OBJECTIVE(7,PLAYER0)
					ROOM_AVAILABLE(PLAYER0,LAIR,1,1)
					TUTORIAL_FLASH_BUTTON(8,-1)
					IF(PLAYER0,LAIR >= 9)
						DISPLAY_OBJECTIVE(8,PLAYER0)
						SET_FLAG(PLAYER0,FLAG0,3)
					ENDIF
				ENDIF
			ENDIF
		ENDIF
	ENDIF
ENDIF

REM Show other infos when mining without treasure room built
IF(PLAYER0,FLAG0 == 0)
	IF(PLAYER0,FLAG2 == 1)
		DISPLAY_OBJECTIVE(9,PLAYER0)
		IF(PLAYER0,TOTAL_GOLD_MINED >= 1000)
			DISPLAY_INFORMATION(10)
			IF(PLAYER0,TOTAL_GOLD_MINED >= 5000)
				DISPLAY_INFORMATION(11)
				IF(PLAYER0,TOTAL_GOLD_MINED >= 9000)
					SET_FLAG(PLAYER0,FLAG1,1)
					DISPLAY_OBJECTIVE(12,PLAYER0)
				ENDIF
			ENDIF
		ENDIF
	ENDIF				
ENDIF

REM When have first creature, allow building LAIR
IF(PLAYER0,TOTAL_CREATURES >= 1)
	IF(PLAYER0,TREASURE >= 9)
		ROOM_AVAILABLE(PLAYER0,LAIR,1,1)
	ENDIF
ENDIF

REM Built LAIR
IF(PLAYER0,FLAG0 >= 3)
	IF(PLAYER0,TOTAL_CREATURES >= 1)
		DISPLAY_OBJECTIVE(13,PLAYER0)
		CREATURE_AVAILABLE(PLAYER0,FLY,1,0)
		CREATURE_AVAILABLE(PLAYER0,BUG,1,1)
		IF(PLAYER0,BUG >= 1)
			DISPLAY_OBJECTIVE(14,PLAYER0)
			CREATURE_AVAILABLE(PLAYER0,FLY,1,1)
			ROOM_AVAILABLE(PLAYER0,GARDEN,1,1)
			TUTORIAL_FLASH_BUTTON(7,-1)
			IF(PLAYER0,GARDEN >= 9)
				DISPLAY_OBJECTIVE(15,PLAYER0)
				MAGIC_AVAILABLE(PLAYER0,POWER_IMP,1,1)
				TUTORIAL_FLASH_BUTTON(21,-1)
				SET_TIMER(PLAYER0,TIMER1)
				SET_FLAG(PLAYER0,FLAG0,4)
			ENDIF
		ENDIF
	ENDIF
ENDIF

REM Built GARDEN
IF(PLAYER0,FLAG0 == 4)
	IF(PLAYER0,TOTAL_CREATURES >= 7)
		SET_FLAG(PLAYER0,FLAG0,5)
	ENDIF
ENDIF

REM Has eight or more creatures
IF(PLAYER0,FLAG0 >= 5)
	IF(PLAYER0,TIMER1 >= 600)
		DISPLAY_INFORMATION(16)
		TUTORIAL_FLASH_BUTTON(5,-1)
		IF(PLAYER0,TIMER1 >= 800)
			ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,THIEVES,1,DUNGEON,0,1,200)
			ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,THIEVES,1,DUNGEON,0,1,200)
			DISPLAY_OBJECTIVE(17,PLAYER0)
			TUTORIAL_FLASH_BUTTON(37,-1)
			IF(PLAYER_GOOD,TOTAL_CREATURES == 0)
				DISPLAY_OBJECTIVE(18,PLAYER0)
				SET_TIMER(PLAYER0,TIMER2)
				SET_FLAG(PLAYER0,FLAG0,6)
			ENDIF
		ENDIF
	ENDIF
ENDIF

REM Has won first battle
IF(PLAYER0,FLAG0 >= 6)
	IF(PLAYER0,TIMER2 >= 500)
		IF(PLAYER0,TOTAL_CREATURES >= 7)
			ADD_PARTY_TO_LEVEL(PLAYER_GOOD,LANDLORD,1,1)
			DISPLAY_OBJECTIVE(19,PLAYER0)
			SET_FLAG(PLAYER0,FLAG0,7)
		ENDIF
	ENDIF							
ENDIF								

REM END LEVEL CHECK - doesn't need a flag, as third battle is always LANDLORD,
REM however it may be better to use the flag and then test if good player has no creatures.
IF(PLAYER0,FLAG0 == 7)
	IF(PLAYER_GOOD,TOTAL_CREATURES == 0)
		DISPLAY_OBJECTIVE(20,PLAYER0)
		WIN_GAME
	ENDIF
ENDIF

REM If the player has run out of imps, somehow
IF(PLAYER0,TOTAL_IMPS == 0)
	DISPLAY_INFORMATION(21)
	MAGIC_AVAILABLE(PLAYER0,POWER_IMP,1,1)
	TUTORIAL_FLASH_BUTTON(21,-1)
ENDIF
