REM ****************************************************************************
REM  Campaigns Consolidation Project for KeeperFX strategy game.
REM ****************************************************************************
REM  Script for Level Waterdream Warm
REM  Campaign: DK Original
REM  Authors:  based on Bullfrog script
REM            KeeperFX CCP Team
REM  Date:     17 Dec 1996 - 07 Sep 2014
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)

REM New rooms for the player:
REM   RESEARCH - when four basic rooms are built
REM New creatures for the player:
REM   SORCEROR - when RESEARCH is built
REM New powers for the player:
REM   POWER_SPEED - when researched

REM Flags used:
REM   PLAYER0,FLAG0 - TREASURE building status; 0-unfinished; 1-built.
REM   PLAYER0,FLAG1 - LAIR building status; 0-unfinished; 1-built.
REM   PLAYER0,FLAG2 - GARDEN building status; 0-unfinished; 1-built.
REM   PLAYER0,FLAG3 - TRAINING building status; 0-unfinished; 1-built.
REM   PLAYER0,FLAG4 - ENTRANCE claiming status; 0-unclaimed; 1-claimed.
REM   PLAYER0,FLAG6 - Progress state; 0-building basic rooms; 1-building library; 2-built RESEARCH;
REM                   3-got first SORCEROR.
REM   PLAYER0,FLAG7 - RESEARCH building status; 0-unfinished; 1-built.
REM   PLAYER_GOOD,FLAG0 - Sending waves of heroes; 0-not ready; 1-ready to start sending.
REM Timers used:
REM   PLAYER0,TIMER0 - First attack timer
REM   PLAYER0,TIMER1 - Delay after first attack
REM   PLAYER0,TIMER2 - Second attack timer
REM   PLAYER0,TIMER3 - Final attack timer (also counts delay after 2nd attack)
REM   PLAYER0,TIMER4 - Delay after final attack

SET_GENERATE_SPEED(400)

START_MONEY(PLAYER0,3000)

MAX_CREATURES(PLAYER0,8)

ADD_CREATURE_TO_POOL(BUG,10)
ADD_CREATURE_TO_POOL(FLY,10)
ADD_CREATURE_TO_POOL(DEMONSPAWN,20)
ADD_CREATURE_TO_POOL(SORCEROR,10)

SET_CREATURE_MAX_LEVEL(PLAYER_GOOD,KNIGHT,2)
SET_CREATURE_MAX_LEVEL(PLAYER_GOOD,THIEF,2)
SET_CREATURE_MAX_LEVEL(PLAYER_GOOD,DWARFA,2)
SET_CREATURE_MAX_LEVEL(PLAYER_GOOD,TUNNELLER,2)
SET_CREATURE_MAX_LEVEL(PLAYER_GOOD,ARCHER,2)

SET_CREATURE_MAX_LEVEL(PLAYER0,DEMONSPAWN,10)

SET_CREATURE_STRENGTH(KNIGHT,70)
SET_CREATURE_ARMOUR(KNIGHT,80)

CREATURE_AVAILABLE(PLAYER0,BUG,1,0)
CREATURE_AVAILABLE(PLAYER0,FLY,1,0)
CREATURE_AVAILABLE(PLAYER0,DEMONSPAWN,1,0)

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,0)

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

CREATE_PARTY(THIEVES)
	ADD_TO_PARTY(THIEVES,THIEF,1,200,STEAL_GOLD,0)
	ADD_TO_PARTY(THIEVES,ARCHER,1,200,STEAL_SPELLS,0)

CREATE_PARTY(DWARVES)
	ADD_TO_PARTY(DWARVES,DWARFA,1,200,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(DWARVES,DWARFA,1,200,ATTACK_ENEMIES,0)

CREATE_PARTY(ELITE)
	ADD_TO_PARTY(ELITE,DWARFA,1,200,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(ELITE,THIEF,1,200,ATTACK_ENEMIES,0)

CREATE_PARTY(LANDLORD)
	ADD_TO_PARTY(LANDLORD,ARCHER,1,200,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,KNIGHT,1,2000,ATTACK_ENEMIES,0)

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

REM "Build a dungeon with a Treasure Room, a Lair, a Hatchery and a Training Room. Make sure they're all big enough..."
DISPLAY_OBJECTIVE(34,PLAYER0)

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

IF(PLAYER0,LAIR >= 9)
	SET_FLAG(PLAYER0,FLAG1,1)
ENDIF

IF(PLAYER0,GARDEN >= 9)
	SET_FLAG(PLAYER0,FLAG2,1)
ENDIF

IF(PLAYER0,TRAINING >= 9)
	SET_FLAG(PLAYER0,FLAG3,1)
ENDIF

IF(PLAYER0,ENTRANCE > 0)
	SET_FLAG(PLAYER0,FLAG4,1)
ENDIF

IF(PLAYER0,FLAG6 == 0)
	REM When all rooms available at start are built and entrance claimed, introduce a library
	IF(PLAYER0,FLAG0 == 1)
		IF(PLAYER0,FLAG1 == 1)
			IF(PLAYER0,FLAG2 == 1)
				IF(PLAYER0,FLAG3 == 1)
					IF(PLAYER0,FLAG4 == 1)
						SET_FLAG(PLAYER0,FLAG6,1)
					ENDIF
				ENDIF
			ENDIF
		ENDIF
	ENDIF
	REM If the player built all the rooms but some are not big enough, introduce the library after a timeout
	IF(PLAYER0,GAME_TURN > 12000)
		IF(PLAYER0,TREASURE > 0)
			IF(PLAYER0,LAIR > 0)
				IF(PLAYER0,GARDEN > 0)
					IF(PLAYER0,TRAINING > 0)
						IF(PLAYER0,ENTRANCE > 0)
							SET_FLAG(PLAYER0,FLAG6,1)
						ENDIF
					ENDIF
				ENDIF
			ENDIF
		ENDIF
	ENDIF
ENDIF

IF(PLAYER0,FLAG6 >= 1)
	REM "The time has come to build a Library. Libraries are where new devices, room designs and magic spells are researched..."
	DISPLAY_OBJECTIVE(35,PLAYER0)
	ROOM_AVAILABLE(PLAYER0,RESEARCH,1,1)
	TUTORIAL_FLASH_BUTTON(9,-1)
ENDIF

IF(PLAYER0,RESEARCH > 0)
	REM "Your new Library will attract creatures like Warlocks, who are interested in researching magic and dungeon designs..."
	DISPLAY_INFORMATION(36,ALL_PLAYERS)
	REM if the player isn't going to build large enough library, allow a timeout
	SET_TIMER(PLAYER0,TIMER6)
	IF(PLAYER0,TIMER6 > 6000)
		SET_FLAG(PLAYER0,FLAG7,1)
	ENDIF
ENDIF

IF(PLAYER0,RESEARCH >= 9)
	SET_FLAG(PLAYER0,FLAG7,1)
ENDIF

REM If the library is ready, make sure the player will get at least one SORCEROR
IF(PLAYER0,FLAG7 == 1)
	REM "That's a fine collection of parchments and tomes you've assembled. Most creatures can engage in research but Warlocks make the best..."
	DISPLAY_OBJECTIVE(37,PLAYER0)
	MAX_CREATURES(PLAYER0,12)
	CREATURE_AVAILABLE(PLAYER0,BUG,0,0)
	CREATURE_AVAILABLE(PLAYER0,FLY,0,0)
	CREATURE_AVAILABLE(PLAYER0,DEMONSPAWN,0,0)
	CREATURE_AVAILABLE(PLAYER0,SORCEROR,1,0)
	SET_FLAG(PLAYER0,FLAG6,2)
ENDIF

IF(PLAYER0,SORCEROR > 0)
	REM "The scent of arcane knowledge has lured a greedy Warlock into your dungeon. Don't forget to train your Warlocks..."
	DISPLAY_OBJECTIVE(38,PLAYER0)
	CREATURE_AVAILABLE(PLAYER0,BUG,1,0)
	CREATURE_AVAILABLE(PLAYER0,FLY,1,0)
	CREATURE_AVAILABLE(PLAYER0,DEMONSPAWN,1,0)
	CREATURE_AVAILABLE(PLAYER0,SORCEROR,1,0)
	SET_FLAG(PLAYER0,FLAG6,3)
ENDIF

REM Player has done everything we wanted. Just wait a bit before attack
IF(PLAYER0,FLAG6 >= 3)
	SET_TIMER(PLAYER0,TIMER0)
	REM The time should be spent on training, make sure the player knows that
	IF(PLAYER0,TIMER0 >= 3750)
		REM "Now would be an excellent time to train a Warlock."
		DISPLAY_OBJECTIVE(43,PLAYER0)
	ENDIF
	REM After some time, set the attack signal
	IF(PLAYER0,TIMER0 >= 5000)
		SET_FLAG(PLAYER_GOOD,FLAG0,1)
	ENDIF
ENDIF

REM If a player sticks his nose where he shouldn't, commence first attack faster
IF_ACTION_POINT(1,PLAYER0)
	SET_FLAG(PLAYER_GOOD,FLAG0,1)
ENDIF

REM If we're signaled for first attack - do it, just make sure player has creatures to defend
IF(PLAYER_GOOD,FLAG0 >= 1)
	IF(PLAYER0,TOTAL_CREATURES >= 10)
		ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,THIEVES,-1,DUNGEON,0,1,500)
		ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,DWARVES,-1,DUNGEON,0,1,2000)
		SET_TIMER(PLAYER0,TIMER1)
	ENDIF
ENDIF

IF(PLAYER0,TIMER1 > 100)
	IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 0)
		REM "The first wave of attackers lie dead. Prepare for the next assault."
		DISPLAY_OBJECTIVE(39,PLAYER0)
		SET_TIMER(PLAYER0,TIMER2)
	ENDIF
ENDIF

REM Commence the 2nd attack some time after first wave is wiped out
IF(PLAYER0,TIMER2 > 2000)
	IF(PLAYER0,TOTAL_CREATURES >= 10)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,THIEVES,-1,2)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,DWARVES,-1,2)
		SET_TIMER(PLAYER0,TIMER3)
	ENDIF
ENDIF

IF(PLAYER0,TIMER3 > 100)
	IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 0)
		REM "All is quiet again. Use this time to ready yourself for the next attacks. The enemy is only regrouping. It is not yet defeated."
		DISPLAY_OBJECTIVE(41,PLAYER0)
	ENDIF
ENDIF

REM For final attack, count the delay without waiting for a previous wave to be killed
IF(PLAYER0,TIMER3 > 2000)
	IF(PLAYER0,TOTAL_CREATURES >= 10)
		ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,ELITE,-1,DUNGEON,0,1,500)
		ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,LANDLORD,-1,DUNGEON,0,1,500)
		REM "Is that Imp playing football with a decapitated head? Stay alert, Keeper."
		DISPLAY_INFORMATION(42,ALL_PLAYERS)
		SET_TIMER(PLAYER0,TIMER4)
	ENDIF
ENDIF

REM When all are dead, win the game
IF(PLAYER0,TIMER4 > 100)
	IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 0)
		REM "Congratulations, the bloody carcasses of the fallen heroes lie with expressions of writhing agony at your creatures' feet..."
		DISPLAY_OBJECTIVE(40,PLAYER0)
		WIN_GAME
	ENDIF
ENDIF

REM Somewhere in the meantime, the player may research a spell
IF_AVAILABLE(PLAYER0,POWER_SPEED == 1)
	REM "You have researched the speed up spell. Cast it on creatures to increase their speed."
	DISPLAY_INFORMATION(44,ALL_PLAYERS)
ENDIF

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