REM ****************************************************************************
REM  Campaigns Consolidation Project for KeeperFX strategy game.
REM ****************************************************************************
REM  Script for Level Woodly Rhyme
REM  Campaign: New game plus
REM  Authors:  based on Bullfrog script
REM            KeeperFX CCP Team
REM            Loobinex
REM  Date:     17 Dec 1996 - 15 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 powers for the player:
REM   POWER_ARMAGEDDON - researchable
REM New manufacture for the player:
REM   TRAP_WORD_OF_POWER

REM Flags used:
REM   PLAYER0,FLAG0 - Computer players having Destroy Walls state; 0-don't have; 1-at least one have it.
REM   PLAYER_GOOD,FLAG5 - Action points AP2 and AP3 state; 0-neither triggered; 1-at least one was triggered by PLAYER0.
REM Timers used:
REM   PLAYER_GOOD,TIMER0 - Waves of witches counter after AP1 triggered

SET_GENERATE_SPEED(500)

REM Computer Player stuff
COMPUTER_PLAYER(PLAYER1,0)
COMPUTER_PLAYER(PLAYER2,0)

SET_COMPUTER_PROCESS(PLAYER1,"DIG TO CLOSE GOLD",0,20999,500,7,30)
SET_COMPUTER_PROCESS(PLAYER2,"DIG TO CLOSE GOLD",0,20999,500,7,30)

START_MONEY(PLAYER0,7500)
START_MONEY(PLAYER1,10000)
START_MONEY(PLAYER2,10000)

MAX_CREATURES(PLAYER0,40)
MAX_CREATURES(PLAYER1,35)
MAX_CREATURES(PLAYER2,35)

ADD_CREATURE_TO_POOL(TROLL,30)
ADD_CREATURE_TO_POOL(SORCEROR,25)
ADD_CREATURE_TO_POOL(DARK_MISTRESS,35)
ADD_CREATURE_TO_POOL(DRAGON,17)
ADD_CREATURE_TO_POOL(HELL_HOUND,15)
ADD_CREATURE_TO_POOL(VAMPIRE,3)
ADD_CREATURE_TO_POOL(ORC,25)

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

REM Doors and traps availability
TRAP_AVAILABLE(ALL_PLAYERS,ALARM,1,0)
DOOR_AVAILABLE(ALL_PLAYERS,STEEL,1,0)
TRAP_AVAILABLE(ALL_PLAYERS,BOULDER,1,0)
TRAP_AVAILABLE(ALL_PLAYERS,WORD_OF_POWER,1,0)

CREATE_PARTY(ARCHERS)
	ADD_TO_PARTY(ARCHERS,ARCHER,4,500,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(ARCHERS,ARCHER,4,500,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(ARCHERS,ARCHER,4,500,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(ARCHERS,ARCHER,4,500,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(ARCHERS,WIZARD,5,600,ATTACK_ENEMIES,0)

CREATE_PARTY(DWARVES)
	ADD_TO_PARTY(DWARVES,DWARFA,4,800,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(DWARVES,DWARFA,4,800,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(DWARVES,DWARFA,4,800,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(DWARVES,DWARFA,4,800,ATTACK_ENEMIES,0)

CREATE_PARTY(WITCHES)
	ADD_TO_PARTY(WITCHES,WITCH,6,1800,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(WITCHES,WITCH,6,1800,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(WITCHES,WITCH,6,1800,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(WITCHES,WITCH,6,1800,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(WITCHES,WITCH,6,1800,ATTACK_ENEMIES,0)

CREATE_PARTY(BARBS)
	ADD_TO_PARTY(BARBS,BARBARIAN,5,900,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(BARBS,BARBARIAN,5,900,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(BARBS,BARBARIAN,5,900,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(BARBS,BARBARIAN,5,900,ATTACK_ENEMIES,0)
	ADD_TO_PARTY(BARBS,BARBARIAN,5,900,ATTACK_ENEMIES,0)
	
REM ****************************************************************************

REM "You seem to have started a trend. Two other Dungeon Keepers also have designs on this dark domain. Expect no quarter from your rivals."
DISPLAY_OBJECTIVE(113,ALL_PLAYERS)

REM Wait enough game turns to make sure the player will have enough creatures from portal
IF(PLAYER0,GAME_TURN >= 14000)
	REM If the player has lost creatures, he must've dug to water with heroes
	IF_CONTROLS(PLAYER1,TOTAL_CREATURES <= 14)
		IF(PLAYER1,DUNGEON_DESTROYED == 0)
			REM "Can you see how vulnerable one of your opponents has become? Then kill him."
			DISPLAY_INFORMATION(114,PLAYER1)
			MAX_CREATURES(PLAYER2,40)
			ADD_CREATURE_TO_LEVEL(PLAYER2,VAMPIRE,PLAYER2,1,5,0)
		ENDIF
	ENDIF
ENDIF

REM Again, wait enough game turns to make sure the player will have enough creatures from portal
IF(PLAYER0,GAME_TURN >= 16000)
    REM If the player has lost creatures, he must've digged to water with heroes
	IF_CONTROLS(PLAYER2,TOTAL_CREATURES <= 14)
		IF(PLAYER2,DUNGEON_DESTROYED == 0)
			REM "I spy a keeper with hardly any creatures left under his control. I spy a Keeper who's about to die."
			DISPLAY_INFORMATION(115,PLAYER2)
			MAX_CREATURES(PLAYER1,40)
			ADD_CREATURE_TO_LEVEL(PLAYER1,VAMPIRE,PLAYER1,1,5,0)
		ENDIF
	ENDIF
ENDIF

REM Do not let computer players get too many Warlocks
If (PLAYER1,SORCEROR > 2)
	CREATURE_AVAILABLE(PLAYER1,SORCEROR,0,0)
ENDIF
If (PLAYER2,SORCEROR > 2)
	CREATURE_AVAILABLE(PLAYER2,SORCEROR,0,0)
ENDIF

REM Show a message when any of computer players discovers POWER_DESTROY_WALLS
IF(PLAYER0,FLAG0 == 0)
	IF_AVAILABLE(PLAYER1,POWER_DESTROY_WALLS >= 1)
		REM "One of your opponents has developed a spell that can break through fortified walls. Typical. Be on your guard."
		DISPLAY_INFORMATION(118,ALL_PLAYERS)
		SET_FLAG(PLAYER0,FLAG0,1)
	ENDIF
	IF_AVAILABLE(PLAYER2,POWER_DESTROY_WALLS >= 1)
		DISPLAY_INFORMATION(118,ALL_PLAYERS)
		SET_FLAG(PLAYER0,FLAG0,1)
	ENDIF
ENDIF


REM Action points AP2 and AP3 are exclusive - add ARCHERS and BARBS only when first of those is reached

IF_ACTION_POINT(2,PLAYER0)
	SET_FLAG(PLAYER_GOOD,FLAG5,1)
ENDIF

IF_ACTION_POINT(3,PLAYER0)
	SET_FLAG(PLAYER_GOOD,FLAG5,1)
ENDIF

IF(PLAYER_GOOD,FLAG5 == 1)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,ARCHERS,2,1)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,BARBS,2,1)
ENDIF

REM Action point AP1 triggers delayed waves of WITCHES

IF_ACTION_POINT(1,PLAYER0)
	SET_TIMER(PLAYER_GOOD,TIMER0)
ENDIF

IF(PLAYER_GOOD,TIMER0 >= 500)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,DWARVES,4,1)
ENDIF

IF(PLAYER_GOOD,TIMER0 >= 1000)
	ADD_PARTY_TO_LEVEL(PLAYER_GOOD,WITCHES,5,1)
ENDIF

REM To win, both computers must be defeated and all good creatures killed or captured
IF(PLAYER1,DUNGEON_DESTROYED == 1)
	IF(PLAYER2,DUNGEON_DESTROYED == 1)
		IF_CONTROLS(PLAYER_GOOD,TOTAL_CREATURES <= 0)
			WIN_GAME
		ENDIF
	ENDIF
ENDIF

REM Access to transfer special revoked when a creature is killed before all heroes are destroyed.
IF(PLAYER0,BATTLES_LOST >= 1)
	SET_FLAG(PLAYER0,FLAG7,1)
ENDIF
IF(PLAYER1,BATTLES_LOST >= 1)
	SET_FLAG(PLAYER0,FLAG7,1)
ENDIF
IF(PLAYER2,BATTLES_LOST >= 1)
	SET_FLAG(PLAYER0,FLAG7,1)
ENDIF
IF(PLAYER_GOOD,TOTAL_CREATURES >= 1)
	IF(PLAYER0,FLAG7 >= 1)
		IF_SLAB_OWNER(27,82,PLAYER_GOOD)
			CHANGE_SLAB_TYPE(27,82,HARD)
			PLAY_MESSAGE(PLAYER0,SOUND,927)
			REVEAL_MAP_RECT(PLAYER0,81,246,1,1)
		ENDIF
	ENDIF
ENDIF

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