REM ****************************************************************************
REM  Campaigns Consolidation Project for KeeperFX strategy game.
REM ****************************************************************************
REM  Script for Level Sleepiburgh
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)
RUN_AFTER_VICTORY(1)

SET_CREATURE_MAX_LEVEL(ALL_PLAYERS,ANY_CREATURE,8)
SET_CREATURE_MAX_LEVEL(ALL_PLAYERS,IMP,8)

REM New powers for the player:
REM   POWER_DESTROY_WALLS - researchable

SET_GENERATE_SPEED(500)

COMPUTER_PLAYER(PLAYER3,2)
COMPUTER_PLAYER(PLAYER1,2)
COMPUTER_PLAYER(PLAYER4,ROAMING)
COMPUTER_PLAYER(PLAYER6,ROAMING)

SET_COMPUTER_GLOBALS(PLAYER3,60,1,1,1,1900,1)
SET_COMPUTER_GLOBALS(PLAYER1,70,1,2,1,1700,1)

REM SET_COMPUTER_CHECKS(PLAYER3,"CHECK FOR NEUTRAL PLACES",1000,0,0,0,30000)
REM SET_COMPUTER_CHECKS(PLAYER1,"CHECK FOR NEUTRAL PLACES",1000,0,0,0,30000)

ALLY_PLAYERS(PLAYER1,PLAYER3,1)
ALLY_PLAYERS(PLAYER1,PLAYER4,1)
ALLY_PLAYERS(PLAYER3,PLAYER4,1)
ALLY_PLAYERS(PLAYER1,PLAYER_GOOD,1)
ALLY_PLAYERS(PLAYER3,PLAYER_GOOD,1)
ALLY_PLAYERS(PLAYER_GOOD,PLAYER4,1)
ALLY_PLAYERS(PLAYER6,PLAYER_GOOD,1)
ALLY_PLAYERS(PLAYER6,PLAYER4,1)

SET_PLAYER_COLOR(PLAYER6,WHITE)

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

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


ADD_CREATURE_TO_POOL(BUG,30)
ADD_CREATURE_TO_POOL(SPIDER,30)
ADD_CREATURE_TO_POOL(DEMONSPAWN,30)
ADD_CREATURE_TO_POOL(SORCEROR,25)
ADD_CREATURE_TO_POOL(TROLL,25)
ADD_CREATURE_TO_POOL(BILE_DEMON,15)
ADD_CREATURE_TO_POOL(HELL_HOUND,20)
ADD_CREATURE_TO_POOL(ORC,20)
ADD_CREATURE_TO_POOL(DARK_MISTRESS,15)
ADD_CREATURE_TO_POOL(TENTACLE,20)

REM make availability wildly different for blue and yellow

REM	Creature availability
CREATURE_AVAILABLE(PLAYER0,BUG,1,0)
CREATURE_AVAILABLE(PLAYER0,SPIDER,1,0)
CREATURE_AVAILABLE(PLAYER0,DEMONSPAWN,1,0)
CREATURE_AVAILABLE(PLAYER0,SORCEROR,1,0)
CREATURE_AVAILABLE(PLAYER0,TROLL,1,0)
CREATURE_AVAILABLE(PLAYER0,BILE_DEMON,1,0)
CREATURE_AVAILABLE(PLAYER0,HELL_HOUND,1,0)
CREATURE_AVAILABLE(PLAYER0,ORC,1,0)
CREATURE_AVAILABLE(PLAYER0,DARK_MISTRESS,1,0)
CREATURE_AVAILABLE(PLAYER0,TENTACLE,1,0)

CREATURE_AVAILABLE(PLAYER1,SPIDER,1,0)
CREATURE_AVAILABLE(PLAYER1,SORCEROR,1,0)
CREATURE_AVAILABLE(PLAYER1,DEMONSPAWN,1,0)
CREATURE_AVAILABLE(PLAYER1,BILE_DEMON,1,0)
CREATURE_AVAILABLE(PLAYER1,TENTACLE,1,0)
CREATURE_AVAILABLE(PLAYER1,ORC,1,0)
CREATURE_AVAILABLE(PLAYER1,DARK_MISTRESS,1,0)

CREATURE_AVAILABLE(PLAYER3,BUG,1,0)
CREATURE_AVAILABLE(PLAYER3,DEMONSPAWN,1,0)
CREATURE_AVAILABLE(PLAYER3,TROLL,1,0)
CREATURE_AVAILABLE(PLAYER3,BILE_DEMON,1,0)
CREATURE_AVAILABLE(PLAYER3,HELL_HOUND,1,0)
CREATURE_AVAILABLE(PLAYER3,ORC,1,0)
CREATURE_AVAILABLE(PLAYER3,DARK_MISTRESS,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(PLAYER0,WORKSHOP,4,0)
ROOM_AVAILABLE(PLAYER1,WORKSHOP,1,0)
ROOM_AVAILABLE(PLAYER3,WORKSHOP,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,BARRACKS,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,GUARD_POST,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,BRIDGE,4,0)
ROOM_AVAILABLE(ALL_PLAYERS,PRISON,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TORTURE,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,TEMPLE,1,0)
ROOM_AVAILABLE(ALL_PLAYERS,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)
REM MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SIGHT,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SPEED,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CALL_TO_ARMS,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CONCEAL,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HOLD_AUDIENCE,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CAVE_IN,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HEAL_CREATURE,1,0)
REM MAGIC_AVAILABLE(ALL_PLAYERS,POWER_LIGHTNING,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_PROTECT,1,0)
MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CHICKEN,1,0)
REM MAGIC_AVAILABLE(ALL_PLAYERS,POWER_DISEASE,1,0)

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

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

REM IF(PLAYER0,TOTAL_CREATURES == 20)
REM		PRINT("I KNOW THY NAME, I WILL DESTROY THY EVIL PRESENCE. The Avatar")
REM ENDIF

IF(PLAYER1,PRISON >= 9)
	SET_CREATURE_TENDENCIES(PLAYER1,IMPRISON,1)
ENDIF
IF(PLAYER3,PRISON >= 9)
	SET_CREATURE_TENDENCIES(PLAYER1,IMPRISON,1)
ENDIF


IF(PLAYER3,DUNGEON_DESTROYED == 1)
	IF(PLAYER1,DUNGEON_DESTROYED == 1)
		REM "Only the Lord of this Land stands between you and hectares of desolation and woe. I bet you can't wait to meet him."
		DISPLAY_OBJECTIVE(111,PLAYER0)
		SET_FLAG(PLAYER_GOOD,FLAG0,1)
	ENDIF
ENDIF

REM When both computer players are defeated and hero wizards are dead, allow Lord of the Land to come
IF(PLAYER_GOOD,FLAG0 == 1)
	IF_CONTROLS(PLAYER_GOOD,WIZARD <= 0)
		ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,KNIGHT,-1,1,10,1000000)
		ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,GIANT,-1,4,7,1000)
		SET_TIMER(PLAYER0,TIMER2)
	ENDIF
ENDIF

IF(PLAYER0,TIMER2 >= 200)
	IF_CONTROLS(PLAYER_GOOD,KNIGHT <= 0)
		REM "Your continued success makes me sick. Thank you, your wickedness."
		DISPLAY_OBJECTIVE(112,PLAYER0)
		WIN_GAME
	ENDIF
ENDIF	

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

IF(PLAYER0,GAME_TURN >= 1)
	CONCEAL_MAP_RECT(PLAYER0,127,172,21,21)
	CHANGE_SLAB_TYPE(41,61,PATH)
	CHANGE_SLAB_TYPE(43,61,PATH)
	REVEAL_MAP_RECT(PLAYER0,115,187,1,1)
	REVEAL_MAP_RECT(PLAYER0,139,187,1,1)
ENDIF

SET_TIMER(PLAYER4,TIMER0)
REM main timer for conversion
IF(PLAYER4,TIMER0 >= 1250)
	NEXT_COMMAND_REUSABLE
	ADD_TO_FLAG(PLAYER4,FLAG0,1)
	NEXT_COMMAND_REUSABLE
	ADD_TO_FLAG(PLAYER4,FLAG1,1)
	NEXT_COMMAND_REUSABLE
	SET_TIMER(PLAYER4,TIMER0)
	NEXT_COMMAND_REUSABLE
	RANDOMISE_FLAG(PLAYER4,FLAG2,3)
ENDIF

IF(PLAYER4,FLAG0 == 1)
	IF(PLAYER4,FLAG1 >= 1)
		IF(PLAYER4,FLAG2 == 1)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER1,ANY_CREATURE,ANYWHERE,1,-1,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER3,ANY_CREATURE,ANYWHERE,1,-1,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER6,ANY_CREATURE,ANYWHERE,1,-1,128)
		ENDIF
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER4,FLAG1,0)
	ENDIF
ENDIF
IF(PLAYER4,FLAG0 == 2)
	IF(PLAYER4,FLAG1 >= 1)
		IF(PLAYER4,FLAG2 == 1)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER1,ANY_CREATURE,ANYWHERE,1,-6,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER3,ANY_CREATURE,ANYWHERE,1,-6,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER6,ANY_CREATURE,ANYWHERE,1,-6,128)
		ENDIF
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER4,FLAG1,0)
	ENDIF
ENDIF
IF(PLAYER4,FLAG0 == 3)
	IF(PLAYER4,FLAG1 >= 1)
		IF(PLAYER4,FLAG2 == 1)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER1,ANY_CREATURE,ANYWHERE,1,-2,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER3,ANY_CREATURE,ANYWHERE,1,-2,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER6,ANY_CREATURE,ANYWHERE,1,-2,128)
		ENDIF
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER4,FLAG1,0)
	ENDIF
ENDIF
IF(PLAYER4,FLAG0 == 4)
	IF(PLAYER4,FLAG1 >= 1)
		IF(PLAYER4,FLAG2 == 1)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER1,ANY_CREATURE,ANYWHERE,1,-5,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER3,ANY_CREATURE,ANYWHERE,1,-5,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER6,ANY_CREATURE,ANYWHERE,1,-5,128)
		ENDIF
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER4,FLAG1,0)
	ENDIF
ENDIF
IF(PLAYER4,FLAG0 == 5)
	IF(PLAYER4,FLAG1 >= 1)
		IF(PLAYER4,FLAG2 == 1)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER1,ANY_CREATURE,ANYWHERE,1,-3,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER3,ANY_CREATURE,ANYWHERE,1,-3,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER6,ANY_CREATURE,ANYWHERE,1,-3,128)
		ENDIF
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER4,FLAG1,0)
	ENDIF
ENDIF
IF(PLAYER4,FLAG0 == 6)
	IF(PLAYER4,FLAG1 >= 1)
		IF(PLAYER4,FLAG2 == 1)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER1,ANY_CREATURE,ANYWHERE,1,-4,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER3,ANY_CREATURE,ANYWHERE,1,-4,128)
		ENDIF
		IF(PLAYER4,FLAG2 == 2)
			NEXT_COMMAND_REUSABLE
			MOVE_CREATURE(PLAYER6,ANY_CREATURE,ANYWHERE,1,-4,128)
		ENDIF
		NEXT_COMMAND_REUSABLE
		SET_FLAG(PLAYER4,FLAG1,0)
	ENDIF
ENDIF
IF(PLAYER4,FLAG0 > 6)
	NEXT_COMMAND_REUSABLE
	SET_FLAG(PLAYER4,FLAG0,1)
ENDIF

REM stopgap solution for now (APs limited to range of 16 - once fixed I can deleted 12-15)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER1,ANY_CREATURE,AT_ACTION_POINT[11],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER1,ANY_CREATURE,AT_ACTION_POINT[12],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER1,ANY_CREATURE,AT_ACTION_POINT[13],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER1,ANY_CREATURE,AT_ACTION_POINT[14],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER1,ANY_CREATURE,AT_ACTION_POINT[15],PLAYER4)

NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER3,ANY_CREATURE,AT_ACTION_POINT[11],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER3,ANY_CREATURE,AT_ACTION_POINT[12],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER3,ANY_CREATURE,AT_ACTION_POINT[13],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER3,ANY_CREATURE,AT_ACTION_POINT[14],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER3,ANY_CREATURE,AT_ACTION_POINT[15],PLAYER4)

NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER6,ANY_CREATURE,AT_ACTION_POINT[11],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER6,ANY_CREATURE,AT_ACTION_POINT[12],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER6,ANY_CREATURE,AT_ACTION_POINT[13],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER6,ANY_CREATURE,AT_ACTION_POINT[14],PLAYER4)
NEXT_COMMAND_REUSABLE
CHANGE_CREATURE_OWNER(PLAYER6,ANY_CREATURE,AT_ACTION_POINT[15],PLAYER4)

REM Keep doors open so units can move around, then lock them when player is close.
IF_ACTION_POINT(16,PLAYER0)
	SET_DOOR(LOCKED,26,7)
	SET_DOOR(LOCKED,29,9)
	SET_DOOR(LOCKED,34,13)
	SET_DOOR(LOCKED,36,17)
	SET_DOOR(LOCKED,48,17)
	SET_DOOR(LOCKED,50,13)
	SET_DOOR(LOCKED,55,9)
	SET_DOOR(LOCKED,58,7)
ENDIF


IF(PLAYER0,BRIDGE > 0)

ENDIF
IF(PLAYER0,ELDER_DWARF > 0)
	REM text saying "oh he teaches you :)"
	TRAP_AVAILABLE(PLAYER0,ARROW,1,0)
	TRAP_AVAILABLE(PLAYER0,HAIL,1,0)
	TRAP_AVAILABLE(PLAYER0,LANDMINE,1,0)
	TRAP_AVAILABLE(PLAYER0,TNT,1,0)
	REM permanently update campaign flag for these.
ENDIF


rem add to the random timer - if player has more than 0 of


REM To add
REM 
REM Message when bridge above TR collapses
REM Message when you get a bridge
REM Message when you get a workshop
REM Message when you successfully convert a creature (or rather, fail)
REM 
REM Main gimmick is that instead of Keepers or the LOTL that are the main boss here, instead it's a Priestess who
REM has learnt how to control them all via scavenging/hypnosis/whatever.
REM Enemy Keepers will largely ignore you somehow, and occasionally one of their creatures will vanish (convert+teleport to hero base)
REM Maybe I fudge this by...hmm there's no way to have a one-way alliance is there? Maybe I make some creatures belong to dummy keepers???
REM Anyway, the same seems to be the case for some of the heroes too...
REM 
REM The two enemy Keepers aren't that bad actually, partly cause their creatures keep getting siphoned away. 
REM Thought was something like - make the keepers relatively passive i.e. can't pick up and drop creatures or cast spells.
REM Want to kill off the two Keepers "without her noticing", whatever tf that means.
REM Maybe once you kill both Keepers, she notices and starts attacking???
REM But idk if you're crazy and kill her first, the other two keepers go back to normal.
REM 
REM Bonus objective is to destroy the control crystals (8 of them?) - requires some tnt traps.
REM These can be made once you recruit both elder dwarves - this also unlocks all hero traps you hadn't unlocked thus far.
REM "their wiles allowed them to hide away before them succumbed to temptation"
REM
REM Anyway, 

REM hit AP 8, unlock 2 doors (41,17), (43,17) and spawn 2 dwarves, 2 archers, 1 warlock on AP 2 and 3.
REM hit AP 4, spawn 2 dspawn, 2 thief, 2 barb at AP 4
REM hit AP 5, spawn 2 dspawn, 2 thief, 2 barb at AP 5
REM hit AP 9, spawn 2 thief, 2 dwarf, 2 beetle, 2 troll at AP 9
REM hit AP 19, spawn 2 thief, 2 dwarf, 2 beetle, 2 troll at AP 10

REM hit AP 6, spawn 2 spiders, 2 giants, 2 tentacle, 2 hound at AP 6
REM hit AP 7, spawn 2 spiders, 2 giants, 2 tentacle, 2 hound at AP 7

REM hit AP 12, spawn 2 hound, 2 troll, 2 tents, (1 archer, 1 barb, 1 fairy)*purple, (1 archer, 1 barb, 1 fairy)*white at AP -2
REM hit AP 13, spawn 2 hound, 2 troll, 2 tents, (1 archer, 1 barb, 1 fairy)*purple, (1 archer, 1 barb, 1 fairy)*white at AP -5

REM main scavenging concept - every X turns (5000 turns a.k.a 4 minutes and a bit), it goes from 1 to 6 i.e. after 30000 turns it loops back.
REM 1 - steal from blue, 2 - steal from heroes on map, 3 - steal from green, 4 - steal from heroes on map, 5 - steal from blue, 6 - steal from green.
REM when the associated crystal is destroyed, that number does not happen any more.
REM might need to make heroes on map a different colour so it's easier to figure out how to steal.
REM basically - blue and green won't ever get too powerful
REM and the heroes on the map will slowly decrease over time, making the midgame easier but the endgame harder.
REM will dump the converted creatures out of HGs 1,2,3,4,5,6.

REM need to ally white and purple, blue and purple, yellow and purple.
REM maybe make other heroes a different colour (orange?) so it's easier to track who's stolen from
REM and make orange look like white

REM also make any creature captured convert quickly without revealing info (or give them 100% death change) or something
REM (and imply lesser undead are immune)

REM also give blue and yellow limited distinct creature pools