#include "common.acs"
#define CURRENT_MAP 1

script 100 OPEN
{
	int i;

	ambientsound("BellRing", 127);
	printbold(s: "CREATED BY JOHN H. FRENCH");


	Light_Glow(25, 240, 64, 8);

}  // END SCRIPT 100


// CAROUSEL TELEPORTER
script 11 ( int iTid )
{
	Teleport(iTid);

	setlinetexture(iTid, SIDE_FRONT, TEXTURE_MIDDLE, "-");
	setlinetexture(iTid, SIDE_BACK, TEXTURE_MIDDLE, "-");
	setlineblocking(iTid, OFF);

}  // END SCRIPT 10 (CAROUSEL TELEPORTER)


// RESET CAGE
script 12 ( int iTid )
{
	setlinetexture(iTid, SIDE_FRONT, TEXTURE_MIDDLE, "gate02");
	setlinetexture(iTid, SIDE_BACK, TEXTURE_MIDDLE, "gate02");
	setlineblocking(iTid, ON);

}  // END SCRIPT 12 (RESET CAGE)


// FIREBALL ROOM TRAP
script 13 (void)
{
	int i;


	// CLOSE DOORS QUICKLY
	Polyobj_Move(1, 64, 0, 144);
	polywait(1);

	// FIREBALLS!!!
	i = 0;
	while ( i++ < 10 )
	{
		setlinetexture(60, SIDE_FRONT, TEXTURE_MIDDLE, "spawn09");
		delay(const: 5);
		setlinetexture(60, SIDE_FRONT, TEXTURE_MIDDLE, "spawn10");
		delay(const: 3);

		Thing_Projectile(60, T_FIREBALL1, 224, 128, 0);
		Thing_Projectile(61, T_FIREBALL1, 160, 128, 0);
		Thing_Projectile(62, T_FIREBALL1, 96, 128, 0);
		Thing_Projectile(63, T_FIREBALL1, 32, 128, 0);

		setlinetexture(60, SIDE_FRONT, TEXTURE_MIDDLE, "spawn08");
		delay(const: 10);


		setlinetexture(60, SIDE_FRONT, TEXTURE_MIDDLE, "spawn09");
		delay(const: 5);
		setlinetexture(60, SIDE_FRONT, TEXTURE_MIDDLE, "spawn10");
		delay(const: 3);

		Thing_Projectile(60, T_FIREBALL1, 0, 128, 0);
		Thing_Projectile(61, T_FIREBALL1, 64, 128, 0);
		Thing_Projectile(62, T_FIREBALL1, 128, 128, 0);
		Thing_Projectile(63, T_FIREBALL1, 192, 128, 0);

		setlinetexture(60, SIDE_FRONT, TEXTURE_MIDDLE, "spawn08");
		delay(const: 10);


		setlinetexture(60, SIDE_FRONT, TEXTURE_MIDDLE, "spawn09");
		delay(const: 5);
		setlinetexture(60, SIDE_FRONT, TEXTURE_MIDDLE, "spawn10");
		delay(const: 3);

		Thing_Projectile(60, T_FIREBALL1, 32, 128, 0);
		Thing_Projectile(61, T_FIREBALL1, 96, 128, 0);
		Thing_Projectile(62, T_FIREBALL1, 160, 128, 0);
		Thing_Projectile(63, T_FIREBALL1, 224, 128, 0);

		setlinetexture(60, SIDE_FRONT, TEXTURE_MIDDLE, "spawn08");
		delay(const: 10);
	}

	// OPEN DOORS QUICKLY
	Polyobj_Move(1, 128, 128, 144);
	polywait(1);


}  // END SCRIPT 13 (FIREBALL ROOM TRAP)


// ICE SHARD ROOM TRAP
script 14 (void)
{
	int i;


	// CLOSE DOORS QUICKLY
	Polyobj_Move(3, 64, 0, 144);
	polywait(3);

	// ICE SHARDS!!!
	i = 0;
	while ( i++ < 10 )
	{
		setlinetexture(70, SIDE_FRONT, TEXTURE_MIDDLE, "spawn06");
		delay(const: 3);
		setlinetexture(70, SIDE_FRONT, TEXTURE_MIDDLE, "spawn07");
		delay(const: 3);

		Thing_Projectile(70, T_ICESHARD, 224, 128, 0);
		Thing_Projectile(71, T_ICESHARD, 160, 128, 0);
		Thing_Projectile(72, T_ICESHARD, 96, 128, 0);
		delay(const: 2);
		Thing_Projectile(70, T_ICESHARD, 224, 128, 0);
		Thing_Projectile(71, T_ICESHARD, 160, 128, 0);
		Thing_Projectile(72, T_ICESHARD, 96, 128, 0);
		delay(const: 2);
		Thing_Projectile(70, T_ICESHARD, 224, 128, 0);
		Thing_Projectile(71, T_ICESHARD, 160, 128, 0);
		Thing_Projectile(72, T_ICESHARD, 96, 128, 0);

		setlinetexture(70, SIDE_FRONT, TEXTURE_MIDDLE, "spawn05");
		delay(const: 10);


		setlinetexture(70, SIDE_FRONT, TEXTURE_MIDDLE, "spawn06");
		delay(const: 3);
		setlinetexture(70, SIDE_FRONT, TEXTURE_MIDDLE, "spawn07");
		delay(const: 3);

		Thing_Projectile(70, T_ICESHARD, 0, 128, 0);
		Thing_Projectile(71, T_ICESHARD, 64, 128, 0);
		Thing_Projectile(72, T_ICESHARD, 128, 128, 0);
		delay(const: 2);
		Thing_Projectile(70, T_ICESHARD, 0, 128, 0);
		Thing_Projectile(71, T_ICESHARD, 64, 128, 0);
		Thing_Projectile(72, T_ICESHARD, 128, 128, 0);
		delay(const: 2);
		Thing_Projectile(70, T_ICESHARD, 0, 128, 0);
		Thing_Projectile(71, T_ICESHARD, 64, 128, 0);
		Thing_Projectile(72, T_ICESHARD, 128, 128, 0);

		setlinetexture(70, SIDE_FRONT, TEXTURE_MIDDLE, "spawn05");
		delay(const: 10);


		setlinetexture(70, SIDE_FRONT, TEXTURE_MIDDLE, "spawn06");
		delay(const: 3);
		setlinetexture(70, SIDE_FRONT, TEXTURE_MIDDLE, "spawn07");
		delay(const: 3);

		Thing_Projectile(70, T_ICESHARD, 32, 128, 0);
		Thing_Projectile(71, T_ICESHARD, 96, 128, 0);
		Thing_Projectile(72, T_ICESHARD, 160, 128, 0);
		delay(const: 2);
		Thing_Projectile(70, T_ICESHARD, 32, 128, 0);
		Thing_Projectile(71, T_ICESHARD, 96, 128, 0);
		Thing_Projectile(72, T_ICESHARD, 160, 128, 0);
		delay(const: 2);
		Thing_Projectile(70, T_ICESHARD, 32, 128, 0);
		Thing_Projectile(71, T_ICESHARD, 96, 128, 0);
		Thing_Projectile(72, T_ICESHARD, 160, 128, 0);

		setlinetexture(70, SIDE_FRONT, TEXTURE_MIDDLE, "spawn05");
		delay(const: 10);
	}

	// OPEN DOORS QUICKLY
	Polyobj_Move(3, 128, 128, 144);
	polywait(3);


}  // END SCRIPT 14 (ICE SHARD ROOM TRAP)


// CAROUSEL DOOR
int miFloorDoor;
script 19 OPEN
{
	// FIGURE NEXT SECTOR NUMBER
	miFloorDoor += 3;
	
	if ( miFloorDoor > 8 )
	{
		miFloorDoor -= 8;
	}

	// LOWER SECTOR FLOOR
	Floor_MoveToValueTimes8(miFloorDoor, 16, 0, FALSE);
	tagwait(miFloorDoor);

	delay(const: 35);

	// RAISE SECTOR FLOOR
	Floor_MoveToValueTimes8(miFloorDoor, 16, 16, FALSE);
	tagwait(miFloorDoor);

	restart;

}  // END SCRIPT 19 (CAROUSEL DOOR)


// DAYTIME CYCLE
script 20 OPEN
{
	int i;


	// WAIT FOR 2 MINUTES
	delay(const: 4200);

	
	// DARKNESS
	i = 192;
	while ( i > 32 )
	{
		i -= 16;
		Light_ChangeToValue(20, i);
		Light_ChangeToValue(22, i);
		Light_ChangeToValue(23, i - 32);
		delay(const: 350);
	}

	// DARK AND WINDY FOR 1 MINUTE
	i = 0;
	while ( i++ < 6 )
	{
		ambientsound("Wind", 127);
		delay(const: 140);

		Light_ForceLightning(0);
		delay(const: 175);
	}

	// FREEZE WATER
	thingsound(23, "FreezeDeath", 127);
	delay(const: 35);

	// ICY WATER
	changefloor(21, "F_033");
	changefloor(23, "F_033");

	// FOR 10 SECONDS
	delay(const: 525);


	// ICY FLOOR
	ambientsound("FreezeDeath", 127);
	delay(const: 35);
	changefloor(20, "F_033");

	// DARK AND ICY FOR 30 SECONDS
	i = 0;
	while ( i++ < 10 )
	{
		Light_ForceLightning(0);
		delay(const: 105);
	}

	// DAYLIGHT
	i = 32;
	while ( i < 192 )
	{
		i += 16;
		Light_ChangeToValue(20, i);
		Light_ChangeToValue(22, i);
		Light_ChangeToValue(23, i - 32);
		delay(const: 350);
	}

	// DAYLIGHT AND ICY FOR 30 SECONDS
	delay(const: 1050);

	// DAWN OF SPRING
	ambientsound("Ambient7", 127);

	// WAIT 10 SECONDS
	delay(const: 350);

	// ICE BREAKS
	thingsound(23, "FreezeShatter", 127);
	Floor_LowerInstant(const: 21, 0, 126);
	tagwait(const: 21);
	Floor_MoveToValueTimes8(const: 24, 255, 128, TRUE);
	changefloor(21, "X_005");

	// SPRAY ICE SHARDS
	Thing_ProjectileGravity(23, T_ICESHARD,
		random(0,63), random(2,20), random(0, 20));
	Thing_ProjectileGravity(23, T_ICESHARD,
		random(64,127), random(2,20), random(0, 20));
	Thing_ProjectileGravity(23, T_ICESHARD,
		random(128,191), random(2,20), random(0, 20));
	Thing_ProjectileGravity(23, T_ICESHARD,
		random(192,255), random(2,20), random(0, 20));

	// WAIT 30 SECONDS
	delay(const: 1050);

	// FLOOR TO NORMAL
	changefloor(20, "F_044");
	delay(const: 350);

	// FILL MOAT
	Floor_MoveToValueTimes8(const: 21, 8, 2, TRUE);
	Floor_RaiseAndCrush(const: 24, 8, 10);
	tagwait(const: 21);

	// WATER TO NORMAL
	changefloor(23, "X_005");

	restart;

}  // END SCRIPT 20 (DAYTIME CYCLE)


// RANDOM EARTHQUAKE AND SOUNDS
script 21 OPEN
{
	switch ( random(1, 5) )
	{
		case 1:
			// EARTHQUAKE
			Radius_Quake( random(1, 9), random(70, 255), 0, 16, 30);
			break;

		case 2:
		case 4:
			ambientsound("Ambient14", 127);
			break;

		case 3:
		case 5:
			ambientsound("Ambient15", 127);
			break;
	}

	// DELAY 10, 20, 30, 40, 50, OR 60 SECONDS
	delay( random(1, 6) * 350 );

	restart;

}  // END SCRIPT 21 (RANDOM EARTHQUAKE AND SOUNDS)


int miDeathTimer;

script 50 ( void )
{
	if ( gameskill() == SKILL_VERY_HARD )
	{
		ACS_Execute(51, CURRENT_MAP, 0, 0, 0);
		ACS_Execute(52, CURRENT_MAP, 0, 0, 0);
		ACS_Execute(53, CURRENT_MAP, 0, 0, 0);
		ACS_Execute(54, CURRENT_MAP, 0, 0, 0);
		ACS_Execute(55, CURRENT_MAP, 0, 0, 0);
		ACS_Execute(56, CURRENT_MAP, 0, 0, 0);
		ACS_Execute(57, CURRENT_MAP, 0, 0, 0);
		ACS_Execute(58, CURRENT_MAP, 0, 0, 0);
	}
}


script 51 ( void )
{
	ACS_Terminate(50, CURRENT_MAP);

	while ( TRUE )
	{
		// CHECK IF 15 MINUTES HAVE PASSED
		if ( timer() > miDeathTimer + 31500 )
		{
			ambientsound("Ambient13", 127);
			printbold(s: "TIME TO DIE");

			// WAIT SO OTHERS MAY BE KILLED
			delay(const: 140);

			DamageThing(255);

			// RESET TIMER
			miDeathTimer = timer();

			// EXIT SCRIPT
			break;
		}

		// CHECK EVERY 3 SECONDS
		delay(const: 105);
	}
}


script 52 ( void )
{
	ACS_Terminate(50, CURRENT_MAP);

	while ( TRUE )
	{
		// CHECK IF 15 MINUTES HAVE PASSED
		if ( timer() > miDeathTimer + 31500 )
		{
			ambientsound("Ambient13", 127);
			printbold(s: "TIME TO DIE");

			// WAIT SO OTHERS MAY BE KILLED
			delay(const: 140);

			DamageThing(255);

			// RESET TIMER
			miDeathTimer = timer();

			// EXIT SCRIPT
			break;
		}

		// CHECK EVERY 3 SECONDS
		delay(const: 105);
	}
}


script 53 ( void )
{
	ACS_Terminate(50, CURRENT_MAP);

	while ( TRUE )
	{
		// CHECK IF 15 MINUTES HAVE PASSED
		if ( timer() > miDeathTimer + 31500 )
		{
			ambientsound("Ambient13", 127);
			printbold(s: "TIME TO DIE");

			// WAIT SO OTHERS MAY BE KILLED
			delay(const: 140);

			DamageThing(255);

			// RESET TIMER
			miDeathTimer = timer();

			// EXIT SCRIPT
			break;
		}

		// CHECK EVERY 3 SECONDS
		delay(const: 105);
	}
}


script 54 ( void )
{
	ACS_Terminate(50, CURRENT_MAP);

	while ( TRUE )
	{
		// CHECK IF 15 MINUTES HAVE PASSED
		if ( timer() > miDeathTimer + 31500 )
		{
			ambientsound("Ambient13", 127);
			printbold(s: "TIME TO DIE");

			// WAIT SO OTHERS MAY BE KILLED
			delay(const: 140);

			DamageThing(255);

			// RESET TIMER
			miDeathTimer = timer();

			// EXIT SCRIPT
			break;
		}

		// CHECK EVERY 3 SECONDS
		delay(const: 105);
	}
}


script 55 ( void )
{
	ACS_Terminate(50, CURRENT_MAP);

	while ( TRUE )
	{
		// CHECK IF 15 MINUTES HAVE PASSED
		if ( timer() > miDeathTimer + 31500 )
		{
			ambientsound("Ambient13", 127);
			printbold(s: "TIME TO DIE");

			// WAIT SO OTHERS MAY BE KILLED
			delay(const: 140);

			DamageThing(255);

			// RESET TIMER
			miDeathTimer = timer();

			// EXIT SCRIPT
			break;
		}

		// CHECK EVERY 3 SECONDS
		delay(const: 105);
	}
}


script 56 ( void )
{
	ACS_Terminate(50, CURRENT_MAP);

	while ( TRUE )
	{
		// CHECK IF 15 MINUTES HAVE PASSED
		if ( timer() > miDeathTimer + 31500 )
		{
			ambientsound("Ambient13", 127);
			printbold(s: "TIME TO DIE");

			// WAIT SO OTHERS MAY BE KILLED
			delay(const: 140);

			DamageThing(255);

			// RESET TIMER
			miDeathTimer = timer();

			// EXIT SCRIPT
			break;
		}

		// CHECK EVERY 3 SECONDS
		delay(const: 105);
	}
}


script 57 ( void )
{
	ACS_Terminate(50, CURRENT_MAP);

	while ( TRUE )
	{
		// CHECK IF 15 MINUTES HAVE PASSED
		if ( timer() > miDeathTimer + 31500 )
		{
			ambientsound("Ambient13", 127);
			printbold(s: "TIME TO DIE");

			// WAIT SO OTHERS MAY BE KILLED
			delay(const: 140);

			DamageThing(255);

			// RESET TIMER
			miDeathTimer = timer();

			// EXIT SCRIPT
			break;
		}

		// CHECK EVERY 3 SECONDS
		delay(const: 105);
	}
}


script 58 ( void )
{
	ACS_Terminate(50, CURRENT_MAP);

	while ( TRUE )
	{
		// CHECK IF 15 MINUTES HAVE PASSED
		if ( timer() > miDeathTimer + 31500 )
		{
			ambientsound("Ambient13", 127);
			printbold(s: "TIME TO DIE");

			// WAIT SO OTHERS MAY BE KILLED
			delay(const: 140);

			DamageThing(255);

			// RESET TIMER
			miDeathTimer = timer();

			// EXIT SCRIPT
			break;
		}

		// CHECK EVERY 3 SECONDS
		delay(const: 105);
	}
}
