REM ****************************************************************************
REM  Campaigns Consolidation Project for KeeperFX strategy game.
REM ****************************************************************************
REM  Script for Level Skybird Trill
REM  Campaign: New game plus
REM  Authors:  based on Bullfrog script
REM            KeeperFX CCP Team
REM            Loobinex
REM  Date:     17 Dec 1996 - Mai 2021
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 Flags used:
REM		PLAYER_GOOD,FLAG1	- First AVATAR alive/killed
REM		PLAYER_GOOD,FLAG2	- Second AVATAR appreared
REM Timers used:
REM		PLAYER_GOOD,TIMER0	- Final wave approaching
REM		PLAYER_GOOD,TIMER1 	- Time to notice the AVATAR is gone
REM		PLAYER1,TIMER2		- Gives you time to recover after defeating blue
REM		PLAYER0,TIMER3		- Let's the player know more is coming

SET_GENERATE_SPEED(750)

COMPUTER_PLAYER(PLAYER1,0)

SET_COMPUTER_CHECKS(PLAYER1,"CHECK FOR NEUTRAL PLACES",15000,0,0,0,195000)
SET_CREATURE_PROPERTY(AVATAR,NO_IMPRISONMENT,1)
SET_CREATURE_PROPERTY(AVATAR,NO_IMPRISONMENT,1)
SET_CREATURE_PROPERTY(AVATAR,NO_CORPSE_ROTTING,1)
SET_CREATURE_CONFIGURATION(AVATAR,CorpseVanishEffect,64)
SET_CREATURE_PROPERTY(AVATAR,LORD,1)
SET_CREATURE_PROPERTY(KNIGHT,LORD,0)

REM "CHECK FOR QUICK ATTACK", CheckEvery, AttackPercent, CTADuration, MinForAttack, LastCheck
SET_COMPUTER_CHECKS(PLAYER1,"CHECK FOR QUICK ATTACK",700,70,3000,8,122500)
SET_COMPUTER_PROCESS(PLAYER1,"ATTACK SAFE ATTACK",-1,100,335,100,0)
SET_COMPUTER_PROCESS(PLAYER1,"ATTACK PLAN 1",-1,100,335,100,0)
SET_COMPUTER_PROCESS(PLAYER1,"ATTACK PLAN 1",-1,100,335,100,0)
SET_COMPUTER_PROCESS(PLAYER1,"BUILD A GRAVEYARD ROOM",0,5,6,11,14)

START_MONEY(PLAYER0,20000)
START_MONEY(PLAYER1,2460000)

MAX_CREATURES(PLAYER0,25)
MAX_CREATURES(PLAYER1,30)

ADD_CREATURE_TO_POOL(TROLL,30)
ADD_CREATURE_TO_POOL(SORCEROR,7)
ADD_CREATURE_TO_POOL(BILE_DEMON,20)
ADD_CREATURE_TO_POOL(DARK_MISTRESS,30)
ADD_CREATURE_TO_POOL(VAMPIRE,21)
ADD_CREATURE_TO_POOL(DRAGON,21)
ADD_CREATURE_TO_POOL(HELL_HOUND,30)
ADD_CREATURE_TO_POOL(ORC,17)

REM	Creature availability
CREATURE_AVAILABLE(ALL_PLAYERS,TROLL,1,0)
CREATURE_AVAILABLE(PLAYER1,SORCEROR,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,BILE_DEMON,1,0)
CREATURE_AVAILABLE(PLAYER1,DARK_MISTRESS,1,0)
CREATURE_AVAILABLE(PLAYER1,VAMPIRE,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,DRAGON,1,0)
CREATURE_AVAILABLE(ALL_PLAYERS,HELL_HOUND,1,0)
CREATURE_AVAILABLE(PLAYER0,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,2,0)
ROOM_AVAILABLE(ALL_PLAYERS,BARRACKS,2,0)
ROOM_AVAILABLE(ALL_PLAYERS,GUARD_POST,2,0)
ROOM_AVAILABLE(PLAYER1,BRIDGE,2,0)
ROOM_AVAILABLE(PLAYER0,BRIDGE,4,0)
ROOM_AVAILABLE(ALL_PLAYERS,PRISON,2,0)
ROOM_AVAILABLE(ALL_PLAYERS,TORTURE,2,0)
ROOM_AVAILABLE(ALL_PLAYERS,SCAVENGER,2,0)
ROOM_AVAILABLE(ALL_PLAYERS,TEMPLE,2,0)
ROOM_AVAILABLE(ALL_PLAYERS,GRAVEYARD,2,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(PLAYER1,POWER_SIGHT,1,1)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_OBEY,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)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_PROTECT,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CONCEAL,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_DISEASE,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CAVE_IN,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CHICKEN,1,0)

REM	Doors and traps availability
TRAP_AVAILABLE(ALL_PLAYERS,POISON_GAS,1,0)
DOOR_AVAILABLE(ALL_PLAYERS,STEEL,1,0)
TRAP_AVAILABLE(PLAYER1,BOULDER,1,0)
DOOR_AVAILABLE(ALL_PLAYERS,MAGIC,1,0)
TRAP_AVAILABLE(ALL_PLAYERS,LIGHTNING,1,0)
TRAP_AVAILABLE(ALL_PLAYERS,WORD_OF_POWER,1,0)

CREATE_PARTY(RPG)
	ADD_TO_PARTY(RPG,WIZARD,10,300,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(RPG,BARBARIAN,10,300,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(RPG,KNIGHT,10,300,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(RPG,WITCH,10,300,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(BIG_BOY)
	ADD_TO_PARTY(BIG_BOY,AVATAR,10,300,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(BRUTES)
	ADD_TO_PARTY(BRUTES,GIANT,10,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(BRUTES,GIANT,10,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(BRUTES,BARBARIAN,10,500,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(BRUTES,BARBARIAN,10,500,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(MAGICIANS)
	ADD_TO_PARTY(MAGICIANS,WIZARD,10,550,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(MAGICIANS,FAIRY,10,550,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(MAGICIANS,WITCH,10,550,ATTACK_DUNGEON_HEART,0)
	ADD_TO_PARTY(MAGICIANS,SAMURAI,10,550,ATTACK_DUNGEON_HEART,0)

CREATE_PARTY(DWARVES)
	ADD_TO_PARTY(DWARVES,DWARFA,9,650,STEAL_GOLD,0)
	ADD_TO_PARTY(DWARVES,DWARFA,9,650,STEAL_GOLD,0)
	ADD_TO_PARTY(DWARVES,THIEF,9,3000,STEAL_GOLD,0)
	ADD_TO_PARTY(DWARVES,THIEF,9,3000,STEAL_GOLD,0)

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

REM "This realm is begging to be plunged into darkness. The Avatar himself has a castle here. Another Keeper also seeks his soul. This could get messy."
DISPLAY_OBJECTIVE(134,ALL_PLAYERS)

IF(PLAYER0,GAME_TURN >= 150)
	REM "You will meet your nemesis, the Avatar, in this subterranean place. This is your ultimate test. Remember, mercy is for losers."
	DISPLAY_INFORMATION(167,PLAYER_GOOD)
	PLAY_MESSAGE(PLAYER0,SPEECH,107)
ENDIF

IF(PLAYER0,GAME_TURN >= 2400)
	ADD_CREATURE_TO_LEVEL(PLAYER1,VAMPIRE,PLAYER1,1,10,666)
ENDIF

REM Avatar is imprisoned by PLAYER1 from the start, but let's play dumb
IF(PLAYER_GOOD,FLAG1 == 0)
	IF(PLAYER1,DUNGEON_DESTROYED == 0)
		IF(PLAYER_GOOD,DUNGEON_DESTROYED == 1)
			REM "You have destroyed the Avatar's castle but your rival has already taken the Avatar prisoner. Be that as it may, only the Keeper with the blackest heart can destroy this legendary hero, so ransack your rival's dungeon and take the prize."
			DISPLAY_OBJECTIVE(135,PLAYER_GOOD)
		ENDIF
	ENDIF
ENDIF

REM If the blue heart is taking significant damage, give him some bridges to put up a fight
IF(PLAYER1,HEART_HEALTH <= 22000)
	IF_SLAB_OWNER(33,22,PLAYER1)
		IF_SLAB_TYPE(33,23,WATER)
			CHANGE_SLAB_TYPE(33,23,BRIDGE_FRAME)
			CHANGE_SLAB_OWNER(33,23,PLAYER1)
		ENDIF
		IF_SLAB_TYPE(33,24,WATER)
			CHANGE_SLAB_TYPE(33,24,BRIDGE_FRAME)
			CHANGE_SLAB_OWNER(33,24,PLAYER1)
		ENDIF
		SET_DOOR(UNLOCKED,33,21)
	ENDIF
	IF_SLAB_OWNER(35,22,PLAYER1)
		IF_SLAB_TYPE(35,23,WATER)
			CHANGE_SLAB_TYPE(35,23,BRIDGE_FRAME)
			CHANGE_SLAB_OWNER(35,23,PLAYER1)
		ENDIF
		IF_SLAB_TYPE(35,24,WATER)
			CHANGE_SLAB_TYPE(35,24,BRIDGE_FRAME)
			CHANGE_SLAB_OWNER(35,24,PLAYER1)
		ENDIF
		SET_DOOR(UNLOCKED,35,21)
	ENDIF
	IF_SLAB_OWNER(70,16,PLAYER1)
		IF_SLAB_TYPE(71,16,LAVA)
			CHANGE_SLAB_TYPE(71,16,BRIDGE_FRAME)
			CHANGE_SLAB_OWNER(71,16,PLAYER1)
		ENDIF
	ENDIF
	IF_SLAB_OWNER(74,16,PLAYER1)
		IF_SLAB_TYPE(75,16,LAVA)
			CHANGE_SLAB_TYPE(75,16,BRIDGE_FRAME)
			CHANGE_SLAB_OWNER(75,16,PLAYER1)
		ENDIF
		IF_SLAB_TYPE(76,16,LAVA)
			CHANGE_SLAB_TYPE(76,16,BRIDGE_FRAME)
			CHANGE_SLAB_OWNER(76,16,PLAYER1)
		ENDIF
	ENDIF
ENDIF

REM Taking down the AVATAR******************************************************
REM ****************************************************************************

REM When the 30 units average level 8, open a magic door
IF(PLAYER1,TIMES_LEVELUP_CREATURE >= 210)
	IF_SLAB_OWNER(33,21,PLAYER1)
		SET_DOOR(UNLOCKED,33,21)
	ENDIF
ENDIF

REM After 12 paydays when CHECK FOR QUICK ATTACK is enabled, open a door
IF(PLAYER1,GAME_TURN > 122500)
	IF_SLAB_OWNER(35,21,PLAYER1)
		SET_DOOR(UNLOCKED,35,21)
	ENDIF
ENDIF

IF(PLAYER1,BATTLES_WON > 0)
	SET_DOOR(UNLOCKED,64,13)
ENDIF

IF(PLAYER_GOOD,FLAG1 == 0)
	IF_CONTROLS(PLAYER_GOOD,AVATAR <= 0)
		REM Make sure the second avatar can be captured
		SET_CREATURE_PROPERTY(AVATAR,NO_IMPRISONMENT,0)
		SET_TIMER(PLAYER_GOOD,TIMER1)
		SET_FLAG(PLAYER_GOOD,FLAG1,1)
	ENDIF
ENDIF

IF(PLAYER_GOOD,TIMER1 > 90)
	IF(PLAYER1,DUNGEON_DESTROYED <= 0)
		REM "Marvellous, Keeper! The Avatar and all his pathetic army are finally dead! There's only one Keeper to get rid of before becoming the absolute master! So, what are you waiting for?"
		DISPLAY_OBJECTIVE(173,PLAYER1)
	ENDIF
ENDIF

IF(PLAYER_GOOD,TIMER1 > 150)
	REM "What trickery is this? The Avatar's body has vanished!"
	PLAY_MESSAGE(PLAYER0,SPEECH,108)
	REM Make sure the second avatar has a normal corpse
	SET_CREATURE_PROPERTY(AVATAR,NO_CORPSE_ROTTING,0)
	SET_CREATURE_CONFIGURATION(AVATAR,CorpseVanishEffect,0)
	ROOM_AVAILABLE(PLAYER0,BRIDGE,1,1)
ENDIF

REM Taking down PLAYER1*********************************************************
REM ****************************************************************************

IF(PLAYER1,DUNGEON_DESTROYED == 1)
	ROOM_AVAILABLE(PLAYER0,BRIDGE,1,1)
	TRAP_AVAILABLE(PLAYER0,BOULDER,1,0)
	SET_TIMER(PLAYER1,TIMER2)
	IF(PLAYER_GOOD,FLAG1 == 0)
		REM "You got rid of that Keeper easily. Now all that stands between you and total world domination is that ponce in shining armour. Let's get him."
		DISPLAY_OBJECTIVE(169,PLAYER1)
	ENDIF
ENDIF

REM AVATAR and PLAYER1 defeated. Final wave approaching.************************
REM ****************************************************************************

REM	More time in case PLAYER1 has been defeated last.
IF(PLAYER_GOOD,FLAG1 == 1)
	IF(PLAYER1,DUNGEON_DESTROYED == 1)
		SET_TIMER(PLAYER0,TIMER3)
		IF(PLAYER1,TIMER2 >= 900)
			SET_TIMER(PLAYER_GOOD,TIMER0)
		ENDIF
	ENDIF
ENDIF

REM All defeated. Let the player know more is coming.
IF(PLAYER0,TIMER3 >= 100)
	REM "The Avatar and his allies are defeated, yet his power over this land lingers. Prepare thyself..."
	DISPLAY_OBJECTIVE(168,PLAYER_GOOD)
ENDIF

IF(PLAYER_GOOD,TIMER0 >= 700)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,MAGICIANS,-1,1)
	ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,BRUTES,-2,DUNGEON,0,10,100)
	ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,DWARVES,DRAWFROM(-3,-6),DUNGEON,0,10,100)
	ADD_TUNNELLER_PARTY_TO_LEVEL(PLAYER_GOOD,DWARVES,DRAWFROM(-3,-6),DUNGEON,0,10,100)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,BRUTES,DRAWFROM(1,2,3,4),1)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,MAGICIANS,DRAWFROM(1,2,3,4),1)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,BRUTES,DRAWFROM(1,2,3,4),1)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,DWARVES,DRAWFROM(1,2,3,4),1)
ENDIF

IF(PLAYER_GOOD,TIMER0 >= 833)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,DWARVES,3,1)
	SET_FLAG(PLAYER_GOOD,FLAG2,1)
ENDIF

IF(PLAYER_GOOD,TIMER0 >= 1066)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,DWARVES,3,1)
	SET_FLAG(PLAYER_GOOD,FLAG2,1)
ENDIF

IF(PLAYER_GOOD,TIMER0 >= 1166)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,DWARVES,3,1)
	SET_FLAG(PLAYER_GOOD,FLAG2,1)
ENDIF

REM The Avatar is resurrected(Big_Boy)
IF(PLAYER_GOOD,TIMER0 >= 1300)
	REM "What is this? The Avatar lives!"
	DISPLAY_OBJECTIVE(171,3)
	PLAY_MESSAGE(PLAYER0,SPEECH,92)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,RPG,3,1)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,BIG_BOY,3,1)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,MAGICIANS,2,1)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,BRUTES,4,1)
ENDIF

IF(PLAYER_GOOD,TIMER0 >= 1466)
	REM "The Avatar has been resurrected by loyal lieutenants in hiding. But their act has revealed them to us, here in this realm. Now the Avatar rallies all those who would stand against you. It's time you gave this self-righteous oaf a proper kicking, master."
	DISPLAY_OBJECTIVE(136,3)
	SET_FLAG(PLAYER_GOOD,FLAG2,1)
ENDIF

IF(PLAYER_GOOD,FLAG2 == 1)
	IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES == 0)
		IF(PLAYER_GOOD,DUNGEON_DESTROYED == 1)
			REM "Finally, you stand unchallenged. The world is yours to waste and despoil. I bet you have never felt so bad."
			DISPLAY_OBJECTIVE(172,ALL_PLAYERS)
			REM "You are victorious! All hail the new lord of shadows!"
			PLAY_MESSAGE(PLAYER0,SPEECH,109)
			WIN_GAME
		ENDIF
	ENDIF
ENDIF

REM "You have failed. This is a grim day for evil."
HEART_LOST_OBJECTIVE(163,PLAYER0)

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