REM ****************************************************************************
REM  Campaigns Consolidation Project for KeeperFX strategy game.
REM ****************************************************************************
REM  Script for Level Wishvale
REM  Campaign: New game plus
REM  Authors:  based on Bullfrog script
REM            KeeperFX CCP Team
REM            Loobinex
REM  Date:     17 Dec 1996 - 14 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)

REM New rooms for the player:
REM   BARRACKS
REM New creatures for the player:
REM   ORC 

REM Timers used:
REM   PLAYER_GOOD,TIMER0 - Controls spawning ICHI party
REM   PLAYER_GOOD,TIMER1 - Controls spawning NI party
REM   PLAYER_GOOD,TIMER2 - Controls spawning SAN party
REM   PLAYER_GOOD,TIMER3 - Controls spawning YON party
REM   PLAYER_GOOD,TIMER4 - Controls spawning GO party
REM   PLAYER_GOOD,TIMER6 - Used for delay before Lord of the Land appearance

SET_GENERATE_SPEED(250)

REM Computer Player stuff
COMPUTER_PLAYER(PLAYER1,0)

START_MONEY(PLAYER0,3000)
START_MONEY(PLAYER1,7500)

MAX_CREATURES(PLAYER0,25)
MAX_CREATURES(PLAYER1,20)

ADD_CREATURE_TO_POOL(BUG,20)
ADD_CREATURE_TO_POOL(FLY,20)
ADD_CREATURE_TO_POOL(DEMONSPAWN,20)
ADD_CREATURE_TO_POOL(DARK_MISTRESS,20)
ADD_CREATURE_TO_POOL(SORCEROR,30)
ADD_CREATURE_TO_POOL(TROLL,20)
ADD_CREATURE_TO_POOL(SPIDER,20)
ADD_CREATURE_TO_POOL(BILE_DEMON,10)
ADD_CREATURE_TO_POOL(ORC,10)

REM	Creature availability
CREATURE_AVAILABLE(ALL_PLAYERS,TROLL,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,DEMONSPAWN,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,FLY,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,DARK_MISTRESS,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,SORCEROR,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,BUG,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,SPIDER,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,BILE_DEMON,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,ORC,1,0)

REM	Room availability
ROOM_AVAILABLE(ALL_PLAYERS,TREASURE,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,LAIR,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,GARDEN,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,TRAINING,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,RESEARCH,1,1)
ROOM_AVAILABLE(ALL_PLAYERS,WORKSHOP,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,GUARD_POST,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,PRISON,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TORTURE,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,BARRACKS,1,0)
ROOM_AVAILABLE(PLAYER0,BRIDGE,1,0)

REM	Spells availability
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_HEAL_CREATURE,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SPEED,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_LIGHTNING,1,0)

REM	Doors and traps availability
DOOR_AVAILABLE(ALL_PLAYERS,WOOD,1,0)
DOOR_AVAILABLE(ALL_PLAYERS,BRACED,1,0)
TRAP_AVAILABLE(ALL_PLAYERS,POISON_GAS,1,0)
TRAP_AVAILABLE(ALL_PLAYERS,LIGHTNING,1,0)

CREATE_PARTY(ICHI)
	ADD_TO_PARTY(ICHI,DWARFA,2,100,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(ICHI,DWARFA,2,100,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(ICHI,THIEF,2,300,STEAL_GOLD,0)
	ADD_TO_PARTY(ICHI,THIEF,2,300,STEAL_GOLD,0)

CREATE_PARTY(NI)
	ADD_TO_PARTY(NI,ARCHER,2,150,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(NI,ARCHER,2,150,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(NI,BARBARIAN,2,200,ATTACK_ENEMIES,0)

CREATE_PARTY(SAN)
	ADD_TO_PARTY(SAN,ARCHER,2,150,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(SAN,BARBARIAN,2,200,DEFEND_PARTY,0)
	ADD_TO_PARTY(SAN,WIZARD,2,300,ATTACK_ENEMIES,0)

CREATE_PARTY(YON)
	ADD_TO_PARTY(YON,BARBARIAN,2,200,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(YON,BARBARIAN,2,200,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(YON,WIZARD,3,300,DEFEND_PARTY,0)

CREATE_PARTY(GO)
	ADD_TO_PARTY(GO,BARBARIAN,2,200,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(GO,BARBARIAN,2,200,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(GO,GIANT,2,400,ATTACK_ENEMIES,0)

CREATE_PARTY(LANDLORD)
	ADD_TO_PARTY(LANDLORD,BARBARIAN,2,200,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,BARBARIAN,2,200,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,GIANT,3,200,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,WIZARD,3,200,DEFEND_PARTY,0)
	ADD_TO_PARTY(LANDLORD,DWARFA,2,100,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(LANDLORD,DWARFA,2,100,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(LANDLORD,KNIGHT,5,200,ATTACK_ENEMIES,0)

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

REM "It appears you have arrived in the middle of a raging battle. Perhaps it would be wise to stay out of the way until you are strong enough to eliminate both sides."
DISPLAY_OBJECTIVE(71,ALL_PLAYERS)

SET_TIMER(PLAYER_GOOD,TIMER0)

IF(PLAYER0,BRIDGE >= 1)
	ROOM_AVAILABLE(PLAYER1,BRIDGE,1,0)
ENDIF

IF(PLAYER_GOOD,FLAG0 == 0)
	IF(PLAYER_GOOD,TIMER0 > 2000)
		IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 5)
			NEXT_COMMAND_REUSABLE
			ADD_PARTY_TO_LEVEL(PLAYER_GOOD,ICHI,-1,1)
			NEXT_COMMAND_REUSABLE
			SET_TIMER(PLAYER_GOOD,TIMER0)
		ENDIF
	ENDIF
ENDIF

SET_TIMER(PLAYER_GOOD,TIMER1)

IF(PLAYER_GOOD,FLAG0 == 0)
	IF(PLAYER_GOOD,TIMER1 > 4000)
		IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 5)
			NEXT_COMMAND_REUSABLE
			ADD_PARTY_TO_LEVEL(PLAYER_GOOD,NI,-2,1)
			NEXT_COMMAND_REUSABLE
			SET_TIMER(PLAYER_GOOD,TIMER1)
		ENDIF
	ENDIF
ENDIF

SET_TIMER(PLAYER_GOOD,TIMER2)

IF(PLAYER_GOOD,FLAG0 == 0)
	IF(PLAYER_GOOD,TIMER2 > 7500)
		IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 5)
			NEXT_COMMAND_REUSABLE
			ADD_PARTY_TO_LEVEL(PLAYER_GOOD,SAN,-3,1)
			NEXT_COMMAND_REUSABLE
			SET_TIMER(PLAYER_GOOD,TIMER2)
		ENDIF
	ENDIF
ENDIF

SET_TIMER(PLAYER_GOOD,TIMER3)

IF(PLAYER_GOOD,FLAG0 == 0)
	IF(PLAYER_GOOD,TIMER3 > 10000)
		IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 5)
			NEXT_COMMAND_REUSABLE
			ADD_PARTY_TO_LEVEL(PLAYER_GOOD,YON,-2,1)
			NEXT_COMMAND_REUSABLE
			SET_TIMER(PLAYER_GOOD,TIMER3)
		ENDIF
	ENDIF
ENDIF

SET_TIMER(PLAYER_GOOD,TIMER4)

IF(PLAYER_GOOD,FLAG0 == 0)
	IF(PLAYER_GOOD,TIMER4 > 15000)
		IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 5)
			NEXT_COMMAND_REUSABLE
			ADD_PARTY_TO_LEVEL(PLAYER_GOOD,GO,-1,1)
			NEXT_COMMAND_REUSABLE
			SET_TIMER(PLAYER_GOOD,TIMER4)
		ENDIF
	ENDIF
ENDIF

REM The continuous hero parties can be stopped either by waiting enough time, or killing PLAYER1 
IF(PLAYER1,DUNGEON_DESTROYED >= 1)
	SET_FLAG(PLAYER_GOOD,FLAG0,1)
	SET_TIMER(PLAYER_GOOD,TIMER6)
ENDIF

IF(PLAYER_GOOD,GAME_TURN >= 20000)
	SET_FLAG(PLAYER_GOOD,FLAG0,1)
	SET_TIMER(PLAYER_GOOD,TIMER6)
ENDIF

REM When the parties are stopped and there are no more heroes on level, make the lord enter (with some delay)
IF(PLAYER_GOOD,TIMER6 >= 1000)
	IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 0)
		REM "I think I hear the clanking of plate armour. Yes, the Lord of the Land has finally roused himself from the fireside to find out where all his loyal servants have gone."
		DISPLAY_OBJECTIVE(73,-2)
		ADD_PARTY_TO_LEVEL(PLAYER_GOOD,LANDLORD,-2,1)
		SET_FLAG(PLAYER_GOOD,FLAG1,1)
	ENDIF
ENDIF

REM When lord is killed, direct the player to kill PLAYER1, unless it's not destroyed already; and when he is - victory
IF(PLAYER_GOOD,FLAG1 == 1)
	IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 0)
		IF(PLAYER1,DUNGEON_DESTROYED == 0)
			REM "You have turned local heroes into something of an endangered species, now make the enemy Dungeon Keeper extinct."
			DISPLAY_OBJECTIVE(74,PLAYER1)
		ENDIF
		IF(PLAYER1,DUNGEON_DESTROYED >= 1)
			REM "You have prevailed, Keeper. The bodies of your enemies litter the most forlorn alcoves of your domain, in tribute to their futile efforts to keep you at bay."
			DISPLAY_OBJECTIVE(75,ALL_PLAYERS)
			WIN_GAME
		ENDIF
	ENDIF
ENDIF

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