REM ********************************************
REM  Hero campaign by Alexsa
REM  Map 1242, Verminfeast
REM  Script for the map
REM  Version 2.00 (use of pot file by dayokay Dec2020)
REM ********************************************
REM Many spiders and bugs against the player.
REM No library or training or hatchery building; protect your 21, 21 and 63 slabs at all cost.
REM ********************************************
REM Update 1.00, august 2018: adjusted difficulty. 
REM Lowered maximal amounts of troops, wizards and fairies in particular are limited to 3 each.
REM ********************************************
LEVEL_VERSION(1)

SET_PLAYER_COLOR(PLAYER0,WHITE)
SET_PLAYER_COLOR(PLAYER_GOOD,RED)

SET_GENERATE_SPEED(500)

MAX_CREATURES(PLAYER0,15)
MAX_CREATURES(PLAYER1,30)

COMPUTER_PLAYER(PLAYER1,0)
ALLY_PLAYERS(PLAYER1,PLAYER_GOOD,1)

START_MONEY(PLAYER0,5000)
START_MONEY(PLAYER1,5000)

REM All hero pools are limited by hand.
REM The creature count tops at 25, here, since it's a hungry land.
REM No giants, since they require big training/hatchery which you don't get
REM And AI has thirty level 10 spiders/bugs... get wizards/fairies/priestesses/knights with Rebound.
ADD_CREATURE_TO_POOL(THIEF,7)
ADD_CREATURE_TO_POOL(DWARFA,7)
ADD_CREATURE_TO_POOL(MONK,7)
ADD_CREATURE_TO_POOL(BARBARIAN,7)
ADD_CREATURE_TO_POOL(ARCHER,7)
ADD_CREATURE_TO_POOL(WITCH,7)
ADD_CREATURE_TO_POOL(SAMURAI,7)
ADD_CREATURE_TO_POOL(WIZARD,3)
ADD_CREATURE_TO_POOL(KNIGHT,1)
ADD_CREATURE_TO_POOL(FAIRY,3)
ADD_CREATURE_TO_POOL(SPIDER,20)
ADD_CREATURE_TO_POOL(BUG,20)
ADD_CREATURE_TO_POOL(TENTACLE,10)
CREATURE_AVAILABLE(PLAYER0,THIEF,1,0)
CREATURE_AVAILABLE(PLAYER0,DWARFA,1,0)
CREATURE_AVAILABLE(PLAYER0,ARCHER,1,0)
CREATURE_AVAILABLE(PLAYER0,FAIRY,1,0)
CREATURE_AVAILABLE(PLAYER0,BARBARIAN,1,0)
CREATURE_AVAILABLE(PLAYER0,MONK,1,0)
CREATURE_AVAILABLE(PLAYER0,SAMURAI,1,0)
CREATURE_AVAILABLE(PLAYER0,WITCH,1,0)
CREATURE_AVAILABLE(PLAYER1,SPIDER,1,0)
CREATURE_AVAILABLE(PLAYER1,BUG,1,0)
CREATURE_AVAILABLE(PLAYER1,TENTACLE,1,0)
REM Wizard unavailable from start, needs second portal.
REM Three portals allow attracting some knights directly.
    ROOM_AVAILABLE(ALL_PLAYERS,TREASURE,1,1)
    ROOM_AVAILABLE(ALL_PLAYERS,LAIR,1,1)
    ROOM_AVAILABLE(PLAYER1,GARDEN,1,1)
    ROOM_AVAILABLE(PLAYER1,TRAINING,1,1)
    ROOM_AVAILABLE(PLAYER1,RESEARCH,1,1)
    ROOM_AVAILABLE(ALL_PLAYERS,BRIDGE,1,0)
    ROOM_AVAILABLE(ALL_PLAYERS,GUARD_POST,1,0)
    ROOM_AVAILABLE(PLAYER0,WORKSHOP,1,0)
    ROOM_AVAILABLE(PLAYER1,PRISON,1,0)
    ROOM_AVAILABLE(PLAYER1,TORTURE,1,0)
    ROOM_AVAILABLE(ALL_PLAYERS,BARRACKS,1,0)
    ROOM_AVAILABLE(ALL_PLAYERS,TEMPLE,1,0)
    ROOM_AVAILABLE(ALL_PLAYERS,SCAVENGER,1,0)

REM AI has extra Lightning, but no Call to Arms.
    MAGIC_AVAILABLE(PLAYER0,POWER_SLAP,0,0)
    MAGIC_AVAILABLE(PLAYER1,POWER_SLAP,1,1)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HAND,1,1)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_POSSESS,1,1)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_IMP,1,1)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_SPEED,1,0)
    MAGIC_AVAILABLE(PLAYER1,POWER_OBEY,1,1)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HEAL_CREATURE,1,0)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CONCEAL,1,0)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_PROTECT,1,0)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_HOLD_AUDIENCE,1,0)
    MAGIC_AVAILABLE(PLAYER1,POWER_DESTROY_WALLS,1,0)
    MAGIC_AVAILABLE(ALL_PLAYERS,POWER_CHICKEN,1,0)
    MAGIC_AVAILABLE(PLAYER0,POWER_CALL_TO_ARMS,1,0)
    MAGIC_AVAILABLE(PLAYER0,POWER_SIGHT,1,0)
    MAGIC_AVAILABLE(PLAYER1,POWER_LIGHTNING,1,0)
    MAGIC_AVAILABLE(PLAYER1,POWER_DISEASE,1,0)
REM Alarm, gas, lightning and steel door; AI uses lightning, power and magic.
TRAP_AVAILABLE(PLAYER0,ALARM,1,0)
TRAP_AVAILABLE(PLAYER0,POISON_GAS,1,0)
DOOR_AVAILABLE(PLAYER0,STEEL,1,0)
TRAP_AVAILABLE(ALL_PLAYERS,LIGHTNING,1,0)
TRAP_AVAILABLE(PLAYER1,WORD_OF_POWER,1,0)
DOOR_AVAILABLE(PLAYER1,MAGIC,1,0)


REM Only vermin and weak undead to bother you.

CREATE_PARTY(WAVE_VERMIN)
CREATE_PARTY(WAVE_SPIDERS)
CREATE_PARTY(WAVE_BEETLE)
CREATE_PARTY(WAVE_REBOUND)

ADD_TO_PARTY(WAVE_BEETLE,BUG,5,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_BEETLE,BUG,5,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_BEETLE,BUG,5,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_BEETLE,BUG,5,0,ATTACK_ROOMS,200)

ADD_TO_PARTY(WAVE_VERMIN,BUG,8,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_VERMIN,BUG,5,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_VERMIN,BUG,5,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_VERMIN,SKELETON,3,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_VERMIN,SPIDER,3,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_VERMIN,SPIDER,3,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_VERMIN,SPIDER,3,0,ATTACK_ROOMS,200)

ADD_TO_PARTY(WAVE_SPIDERS,SPIDER,5,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_SPIDERS,SPIDER,3,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_SPIDERS,SPIDER,3,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_SPIDERS,SPIDER,3,0,ATTACK_ROOMS,200)

ADD_TO_PARTY(WAVE_REBOUND,SKELETON,5,200,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_REBOUND,BUG,10,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_REBOUND,BUG,10,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_REBOUND,GHOST,8,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_REBOUND,GHOST,8,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_REBOUND,SPIDER,8,0,ATTACK_ROOMS,200)
ADD_TO_PARTY(WAVE_REBOUND,SPIDER,8,0,ATTACK_ROOMS,200)

REM Action points:

REM Hero Gates:
REM 1 At blue entrance (keep spawning with 4 hatcheries captured
REM 2 North from your heart
REM 3 South from your heart
REM 4 At hero heart
REM 5,6 north/south passes
REM 7 For transfer special

REM Startup
    SET_TIMER(PLAYER0,TIMER0)
    SET_TIMER(PLAYER1,TIMER0)
REM	QUICK_OBJECTIVE(1,"The haunted land of Verminfeast is crawling with insects. The food is scarce, and the training room and library cannot be built here. It will be necessary to capture more Hatcheries to sustain you army, even if it isn't very numerous in first place.", PLAYER0)
	DISPLAY_OBJECTIVE(85)

REM Add imps for AI if some are dead.
IF(PLAYER1,TIMER0 >= 200)
REM I removed the graveyard from the map. Keeper's vampires are way too strong for supposedly non-final level, and those persky imps keep getting in the way.
	IF(PLAYER1,IMP <= 16)
		IF(PLAYER1,IMP >= 5)
  			NEXT_COMMAND_REUSABLE
  			SET_TIMER(PLAYER1,TIMER0)
			NEXT_COMMAND_REUSABLE
			ADD_CREATURE_TO_LEVEL(PLAYER1,IMP,-4,1,3,0)
		ENDIF
	ENDIF
ENDIF

REM Hero/Good flies will keep harrassing you, like, forever. Build a lair on the way?
REM ACtually, it's probably the only way to manage the attacks without training room.
REM And building guardpost at river separating you from AI won't quite work because secret passes.
IF(PLAYER_GOOD,TIMER5 >= 500)
	IF(PLAYER_GOOD,FLY <= 10)
		NEXT_COMMAND_REUSABLE
		SET_TIMER(PLAYER_GOOD,TIMER5)
		NEXT_COMMAND_REUSABLE
		ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,FLY,-4,1,10,0)
	ENDIF
ENDIF


REM Bug Timer
IF(PLAYER0,TIMER1 >=5000)
    IF(PLAYER_GOOD,GARDEN > 9)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BUG,DRAWFROM(-2,-3),2,2,0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BUG,DRAWFROM(-2,-3),2,2,0)
    ENDIF
    IF(PLAYER_GOOD,GARDEN <= 27)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BUG,DRAWFROM(-2,-3),2,4,0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BUG,DRAWFROM(-2,-3,-5,-6),2,4,0)
    ENDIF
    IF(PLAYER_GOOD,GARDEN <= 9)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BUG,DRAWFROM(-2,-3,-5,-6),2,6,0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BUG,DRAWFROM(-2,-3,-5,-6),2,6,0)
    ENDIF
    NEXT_COMMAND_REUSABLE
    SET_TIMER(PLAYER0,TIMER1)
ENDIF

REM Spider Timer
IF(PLAYER0,TIMER2 >= 4000)
    IF(PLAYER0,ENTRANCE < 27)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,SPIDER,DRAWFROM(-2,-3),1,3,0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,SPIDER,DRAWFROM(-2,-3),1,3,0)
    ENDIF
    IF(PLAYER0,ENTRANCE >= 18)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,SPIDER,DRAWFROM(-2,-3),1,5,0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,SPIDER,DRAWFROM(-2,-3,-5,-6),1,5,0)
    ENDIF
    IF(PLAYER0,ENTRANCE >= 27)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,SPIDER,DRAWFROM(-2,-3,-5,-6),1,7,0)
	NEXT_COMMAND_REUSABLE
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,SPIDER,DRAWFROM(-2,-3,-5,-6),1,7,0)
    ENDIF
    NEXT_COMMAND_REUSABLE
    SET_TIMER(PLAYER0,TIMER2)
ENDIF


REM Third timer, parties
IF(PLAYER0,TIMER3 >= 20000)
REM Let's note it's possible to wall in and only have a single entrance to your dungeon.
REM	QUICK_OBJECTIVE(2,"My liege, the vermin infesting this lands is growing agitated. You must protect your hatcheries from their attacks, as you prepare your forces to destroy the keeper who stands on your way to Wickedridge.", PLAYER0)
	DISPLAY_OBJECTIVE(86)
    IF(PLAYER_GOOD,TRAINING <= 12)
        NEXT_COMMAND_REUSABLE
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,WAVE_BEETLE,-4,1)
    ENDIF
    IF(PLAYER_GOOD,RESEARCH <= 12)
        NEXT_COMMAND_REUSABLE
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,WAVE_SPIDERS,-4,1)
    ENDIF
    IF(PLAYER_GOOD,GARDEN >= 18)
        NEXT_COMMAND_REUSABLE
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,WAVE_VERMIN,-4,1)
    ENDIF
    IF(PLAYER_GOOD,GARDEN <= 18)
        NEXT_COMMAND_REUSABLE
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,WAVE_REBOUND,-4,1)
    ENDIF
    IF(PLAYER_GOOD,GARDEN == 0)
        NEXT_COMMAND_REUSABLE
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,WAVE_VERMIN,-4,1)
    ENDIF
    NEXT_COMMAND_REUSABLE
    SET_TIMER(PLAYER0,TIMER3)
ENDIF

REM Vermin Party attacks through northern/southern entrances. Just slow and one freezer.
IF(PLAYER0,TIMER4 >= 10000)
        NEXT_COMMAND_REUSABLE
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,WAVE_VERMIN,-5,1)
        NEXT_COMMAND_REUSABLE
        ADD_PARTY_TO_LEVEL(PLAYER_GOOD,WAVE_VERMIN,-6,1)
        NEXT_COMMAND_REUSABLE
        SET_TIMER(PLAYER0,TIMER4)
ENDIF


REM Start bug spawn after 5000 gold mined.
IF(PLAYER0,TOTAL_GOLD_MINED >= 5000)
        SET_TIMER(PLAYER0,TIMER1)
ENDIF
REM Start spider spawn after 15000 gold mined.
IF(PLAYER0,TOTAL_GOLD_MINED >= 15000)
        SET_TIMER(PLAYER0,TIMER2)
ENDIF

REM Start party attacks after first hatchery capture or lots of bugs/spiders gathered.
IF(PLAYER_GOOD,GARDEN <= 27)
	SET_FLAG(PLAYER_GOOD,FLAG1,1)
ENDIF
IF_CONTROLS(PLAYER_GOOD,BUG >= 46)
	SET_FLAG(PLAYER_GOOD,FLAG1,1)
ENDIF
IF_CONTROLS(PLAYER_GOOD,SPIDER >= 22)
	SET_FLAG(PLAYER_GOOD,FLAG1,1)
ENDIF
REM Extra 8 bugs or spiders mean 5/6 are crowded, send imps.
IF_CONTROLS(PLAYER_GOOD,BUG >= 54)
	SET_FLAG(PLAYER_GOOD,FLAG2,1)
ENDIF
IF_CONTROLS(PLAYER_GOOD,SPIDER >= 30)
	SET_FLAG(PLAYER_GOOD,FLAG2,1)
ENDIF
IF(PLAYER0,TIMER0 >= 20000)
	SET_FLAG(PLAYER_GOOD,FLAG1,1)
ENDIF
IF(PLAYER_GOOD,FLAG1 >= 1)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,IMP,-2,2,3,0)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,IMP,-3,2,3,0)
	SET_TIMER(PLAYER0,TIMER3)
ENDIF
REM After three hatcheries are captured, send imps to clear the way to player.
IF(PLAYER_GOOD,GARDEN <= 9)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,IMP,-1,4,3,0)
ENDIF

REM Start attacks from secret passes after 2500 seconds
IF(PLAYER0,TIMER0 >= 50000)
	SET_FLAG(PLAYER_GOOD,FLAG2,1)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BUG,-5,5,5,0)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,BUG,-6,5,5,0)
	SET_TIMER(PLAYER0,TIMER4)
	SET_TIMER(PLAYER_GOOD,TIMER5)
ENDIF

IF(PLAYER_GOOD,FLAG2 >=1)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,IMP,-5,2,3,0)
	ADD_CREATURE_TO_LEVEL(PLAYER_GOOD,IMP,-6,2,3,0)
ENDIF

REM No skeletons or ghosts allowed for player, despite prison/torture available.
REM And by the time you can use torture chamber, enemy's likely all but dead.
IF(PLAYER0, SKELETON>=1)
	NEXT_COMMAND_REUSABLE
	KILL_CREATURE(PLAYER0,SKELETON,MOST_EXPERIENCED,1)
ENDIF
IF(PLAYER0, GHOST>=1)
	NEXT_COMMAND_REUSABLE
	KILL_CREATURE(PLAYER0,GHOST,MOST_EXPERIENCED,1)
ENDIF

IF(PLAYER1,PRISON >= 16)
	SET_CREATURE_TENDENCIES(PLAYER1,IMPRISON,1)
ENDIF
IF(PLAYER0,PRISON >= 1)
	NEXT_COMMAND_REUSABLE
	SET_CREATURE_TENDENCIES(PLAYER0,IMPRISON,0)
ENDIF

REM Capture of entrances increases the max creatures count.
REM AI always has 30 creatures, plus skeletons he's turned from your captives.

IF(PLAYER0,ENTRANCE <= 9)
    NEXT_COMMAND_REUSABLE
    MAX_CREATURES(PLAYER0,15)
ENDIF

IF(PLAYER0,ENTRANCE >= 10)
	NEXT_COMMAND_REUSABLE
	MAX_CREATURES(PLAYER0,20)
	CREATURE_AVAILABLE(PLAYER0,WIZARD,1,0)
	IF(PLAYER0,ENTRANCE >= 20)
		NEXT_COMMAND_REUSABLE
		MAX_CREATURES(PLAYER0,25)
		CREATURE_AVAILABLE(PLAYER0,KNIGHT,1,0)
	ENDIF
ENDIF

IF(PLAYER0,BRIDGE >= 1)
REM	QUICK_INFORMATION(15,"The inhabitants of Dominus do not approve of building too many bridges. Make do with shorter ones!", PLAYER0)
	DISPLAY_INFORMATION(27)
    NEXT_COMMAND_REUSABLE
    ROOM_AVAILABLE(PLAYER0,BRIDGE,0,0)
ENDIF

IF(PLAYER0,BRIDGE < 1)
	NEXT_COMMAND_REUSABLE
	ROOM_AVAILABLE(PLAYER0,BRIDGE,1,1)
ENDIF

IF(PLAYER_GOOD, DUNGEON_DESTROYED>=1)
REM	QUICK_OBJECTIVE(16,"The Verminfeast is no more crawling with itchies and insects. The road to the last bastion of evil atWickedridge is open!", PLAYER0)
	DISPLAY_OBJECTIVE(87)
	WIN_GAME
ENDIF
