#include "zcommon.acs"

//int reflectingwater[7] = { 4,14,93,94,95,96,97 };
int tagspeeds[64][2];
bool bedTime = false;

bool floorceiling;

global int 1:KingofDenile;

//SCRIPT 01 OPEN
//{
//}

//SCRIPT 02 OPEN
//{
// Floor_RaiseToNearest(9,20);
// delay(200);
// Floor_LowerToLowest(9,20);
// restart;
//}

SCRIPT 01 OPEN
{
  ceiling_Waggle(255,128,8,0,0);	//Water Tide
  ceiling_Waggle(154,16,8,0,0);	//Water Tide
  Sector_SetColor(const:154, 0, 128, 255); // Water
  
  if(GameType () != GAME_NET_DEATHMATCH)  //Does not occur in deathmatch
  {
	  ChangeSky("NITESKY1","NITESKY1");
	  SetLineTexture(4, SIDE_FRONT, TEXTURE_MIDDLE, "NITESKY1");
	  SetLineTexture(5, SIDE_FRONT, TEXTURE_MIDDLE, "NITESKY2");
	  SetLineSpecial(6,80,2,0,0);
	  SetLineSpecial(7,80,24,0,0);
	  
	  if(KingofDenile == 1)
		ACS_Execute(25,0,0,0,0);
		//Polyobj_DoorSwing(1, 16, 64, -1);
  }
  
  if(GameType () == GAME_NET_DEATHMATCH)
  {
	  //Polyobj_DoorSwing(1, 16, 64, -1);
	  ACS_Execute(25,0,0,0,0);
  }

  //sets water color and reflection

  // for (int count = 0; count < 7; count++)
  // {
   // Sector_SetPlaneReflection(reflectingwater[count],32,0);
  // }
}

//gorgon encounter
SCRIPT 02(VOID)
{
	 str classFace = "SQAR";
	 LocalAmbientSound("misc/chat", 127);
	 switch (PlayerClass(PlayerNumber()))
	 {
		case CLASS_ADULT_MALE_AKHET :
			classFace = "SQAR";
			break;
		case CLASS_ADULT_FEMALE_AKHET :
			classFace = "SINE";
			break;
		default:
			classFace = "SQAR";
			break;
	 } 
	 
	 SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
	 //SetPlayerProperty(0,1,PROP_INVULNERABILITY);
	 LocalAmbientSound("misc/chat", 127);
	 
	 messageBox_PortraitBold("Oh, hello.\nWho are you?","BILFONT","SWIRL",0,CR_TAN);
	 int buttons;
	 bool ok = false;
	 delay(8);
			
	 while (ok == false)
	 {
		buttons = GetPlayerInput(-1, INPUT_BUTTONS);
		if (buttons & BT_USE)
			ok = true;
		delay(1);
	 }
	 messageBox_Clear();
	 
	 ok = false;
	 delay(8);
	 
	 LocalAmbientSound("menu/change", 127);
	 switch (PlayerClass(PlayerNumber()))
	 {
		case CLASS_ADULT_MALE_AKHET :
			//MESSAGE
			messageBox_PortraitBold("My name is Square.\nWho... what are you?","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
	 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("My name is Swirl.\nThis is my sister, Eclair,\nand our friend Creamhorn.\nWe're gorgons.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Hi cutie!","BILFONT","ECLAIR",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Hello.","BILFONT","CRMHORN",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("What are you doing here?","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("I'm an Akhet from the south.\nA race called the Breadmonsters came to Potassium\nand they mean to take over.  But if I can\nbeat their prince, Lord Bananabread, they might just stop.","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Breadmonsters!","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("You know them?","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Yes.\nIn the Gorgon-Breadmonster wars on Fiber,\na lot of the women were sent here to be safe.\nBreadmonsters are a malicious race.  They don't like women,\nand their numbers grow so fast they constantly\nfight for more land.  That's how we got here.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("There's only three of you then?\nWhat happened to the rest of you?","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Well...","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("...  A-hem!","BILFONT","CRMHORN",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Oh, you look so tired.\nYou should spend the night here.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("But Lord Bananabread hid his mortality\nin the underworld.  I heard that you knew\nof some of Potassium's secret passages...","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("We'll talk about it some more in the morning.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("You can sleep with me and Swirl in our bed!","BILFONT","ECLAIR",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Eclair....","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Umm, I'm sorry.\nI just couldn't do that.","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("What?\nI'm not pretty enough for you?!","BILFONT","ECLAIR",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("No, that's not it at all.\nYou're very beautiful for a green alien.\nI'm just not that kind of guy.","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Looks like you're bunking with us tonight,\nCreamhorn.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Ugh.","BILFONT","CRMHORN",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//**************************
			//END
			//**************************
			break;
		case CLASS_ADULT_FEMALE_AKHET :
			messageBox_PortraitBold("I'm Sine!\nThis is an interesting place you've got here.","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
	 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("My name is Swirl.\nThis is my sister, Eclair,\nand our friend Creamhorn.\nWe're gorgons.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Oh, another girl.  That's no fun.","BILFONT","ECLAIR",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
	 
			ok = false;
			delay(8);
	 
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("No kidding.\nYou're telling me.","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Hello.","BILFONT","CRMHORN",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("What are you doing here?","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("I'm an Akhet from the south.\nA race called the Breadmonsters came to Potassium\nand they mean to take over.  But if I can\nbeat their prince, Lord Bananabread, they might just stop.","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Breadmonsters!","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("You know them?","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Yes.\nIn the Gorgon-Breadmonster wars on Fiber,\na lot of the women were sent here to be safe.\nBreadmonsters are a malicious race.  They don't like women,\nand their numbers grow so fast they constantly\nfight for more land.  That's how we got here.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("There's only three of you then?\nWhat happened to the rest of you?","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Well...","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("...  A-hem!","BILFONT","CRMHORN",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Oh, you look so tired.\nYou should spend the night here.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("But Lord Bananabread hid his mortality\nin the underworld.  I heard that you knew\nof some of Potassium's secret passages...","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("We'll talk about it some more in the morning.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Oh... I guess it can wait.\nWhere do I sleep?","BILFONT",classFace,0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("In that bed there.\nLooks like you're bunking with us tonight,\nCreamhorn.","BILFONT","SWIRL",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			delay(8);
			
			//MESSAGE
			LocalAmbientSound("menu/change", 127);
			messageBox_PortraitBold("Ugh.","BILFONT","CRMHORN",0,CR_TAN);
			
			while (ok == false)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				if (buttons & BT_USE)
					ok = true;
				delay(1);
			}
			messageBox_Clear();
			 
			ok = false;
			
			//*******************
			//END
			//*******************
			break;
		default:
			messageBox_PortraitBold("","BILFONT",classFace,0,CR_TAN);
			messageBox_Clear();
			break;
	 } 

	 //end dialogue
	 messageBox_Clear();
	 SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);

	 bedTime = true;
}

SCRIPT 03 (int bridgeTag, int gemTag, int gemKey)
{
	LocalAmbientSound("SWITCH1", 127);
	switch (gemKey)
	{
		case 0:
				ChangeFloor(gemTag, "GEMLCKC1");
				SetLineBlocking(1, BLOCK_NOTHING);
				break;
		case 1:
				ChangeFloor(gemTag, "GEMLCKG1");
				SetLineBlocking(2, BLOCK_NOTHING);
				break;
		case 2:
				ChangeFloor(gemTag, "GEMLCKY1");
				SetLineBlocking(3, BLOCK_NOTHING);
				break;
		default:
	}
	FloorAndCeiling_RaiseByValue(bridgeTag,16,20);
}

SCRIPT 04 (VOID)
{
 FloorAndCeiling_RaiseByValue(13,48,178);
 TagWait(13);
 delay(35*3);
 FloorAndCeiling_LowerByValue(13,48,178);
 TagWait(13);
}

SCRIPT 05 (VOID)
{
 Ceiling_RaiseByValue(17,48,604);
 FloorAndCeiling_RaiseByValue(18,48,604);
 TagWait(17);
 TagWait(18);
 delay(35*4);
 Ceiling_LowerByValue(17,48,604);
 FloorAndCeiling_LowerByValue(18,48,604);
}

SCRIPT 06 (VOID)
{
 FloorAndCeiling_LowerByValue(27,48,160);
 Floor_LowerByValue(8,48,160);
 TagWait(8);
 TagWait(27);
 delay(35*8);
 FloorAndCeiling_RaiseByValue(27,48,160);
 Floor_RaiseByValue(8,48,160);
}

SCRIPT 07 OPEN
{
 for (int count = 0; count < 64; count++)
 {
  switch (GameSkill ())
  {
  case SKILL_VERY_EASY: tagspeeds[count][0] = random(4,16);
  			tagspeeds[count][1] = 0;
			break;

  case SKILL_EASY: 	tagspeeds[count][0] = random(8,20);
  			tagspeeds[count][1] = 0;
			break;

  case SKILL_NORMAL: 	tagspeeds[count][0] = random(12,24);
  			tagspeeds[count][1] = 0;
			break;

  case SKILL_HARD: 	tagspeeds[count][0] = random(16,28);
  			tagspeeds[count][1] = 0;
			break;

  case SKILL_VERY_HARD: tagspeeds[count][0] = random(20,32);
  			tagspeeds[count][1] = 0;
			break;
  }
 }
}

SCRIPT 08 (VOID)
{
 for (int count = 1; count < 64; count++)
 {
  Pillar_BuildAndCrush(count+27, tagspeeds[count][0], tagspeeds[count][1], 1);
  Pillar_Open(count+28, tagspeeds[count][0], 80, 80);
  count++;
 }

 for (count = 0; count < 64; count++)
 {
 TagWait(count+28);
 }

 for (count = 1; count < 64; count++)
 {
  Pillar_Open(count+27, tagspeeds[count][0], 80, 80);
  Pillar_BuildAndCrush(count+28, tagspeeds[count][0], tagspeeds[count][1], 1);
  count++;
 }

 for (count = 0; count < 64; count++)
 {
 TagWait(count+28);
 }

 restart;
}

SCRIPT 09 (VOID)
{
	Floor_RaiseByValue(123,16,200);
	Ceiling_RaiseByValue(128,16,200);
	Floor_RaiseByValue(128,16,200);
}

SCRIPT 10 OPEN
{
	delay(64);
	Floor_RaiseByValue(146,16,256);
	Ceiling_RaiseByValue(146,16,256);
	tagWait(146);
	delay(64);
	Floor_LowerByValue(146,16,256);
	Ceiling_LowerByValue(146,16,256);
	tagWait(146);
	restart;
}

//moving platforms
SCRIPT 11 (VOID)
{
	delay(64);
	Floor_RaiseByValue(147,16,256);
	Ceiling_RaiseByValue(147,16,256);
	tagWait(147);
	delay(64);
	Floor_LowerByValue(147,16,256);
	Ceiling_LowerByValue(147,16,256);
	tagWait(147);
	restart;
}

SCRIPT 12 (VOID)
{
	delay(64);
	Floor_MoveToValue(133,16,640);
	Floor_MoveToValue(131,16,620);
	Ceiling_MoveToValue(131,16,640);
	tagWait(133);
	tagWait(131);
	delay(64);
	Floor_MoveToValue(133,16,184);
	Floor_MoveToValue(131,16,164);
	Ceiling_MoveToValue(131,16,184);
	tagWait(133);
	tagWait(131);
	restart;
}

SCRIPT 13 (VOID)
{
	delay(64);
	Floor_MoveToValue(157,16,184);
	Floor_MoveToValue(159,16,164);
	Ceiling_MoveToValue(159,16,184);
	tagWait(157);
	tagWait(159);
	Floor_MoveToValue(157,16,640);
	Floor_MoveToValue(159,16,620);
	Ceiling_MoveToValue(159,16,640);
	tagWait(157);
	tagWait(159);
	delay(64);
	restart;
}

//puts each player to sleep in bed for the night
SCRIPT 14 ENTER
{
	while(TRUE)
	{
		if(bedTime == true)
		{
			SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
			setmusic("");
			fadeto(0,0,0,1.0,1.250);
			delay(48);
			
			giveInventory("StatusSleep",1);
			teleportOther(1000+PlayerNumber(),162+PlayerNumber(),0);
			setActorState(1000+PlayerNumber(),"pain.sleep");
			
			door_Open(171,16);
			daylight();
			delay(144);
			giveInventory("HealthBonus",255);
			giveInventory("GodAmmo",1023);
			takeInventory("StatusSleep",1);
			
			Spawn("Apple",getActorX(191), getActorY(191), getActorZ(191),0,0);
			Spawn("Apple",getActorX(192), getActorY(192), getActorZ(192),0,0);
			
			//let the gorgons talk
			thing_setSpecial(151,80,15,0,0);
			thing_setSpecial(152,80,16,0,0);
			thing_setSpecial(153,80,17,0,0);
			setActorState(152,"sleeping");
			teleportOther(151,183,0);
			teleportOther(152,184,0);
			teleportOther(153,185,0);
			
			fadeto(0,0,0,0.0,1.250);

			delay(48);
			setActorState(1000+PlayerNumber(),"restore");
			setmusic("*");
			SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
			bedTime = false;
		}
		delay(1);
		restart;
	}
}

//Swirl's Speech
SCRIPT 15 (VOID)
{
 str classFace = "SQAR";
 LocalAmbientSound("misc/chat", 127);
 switch (PlayerClass(PlayerNumber()))
 {
 	case CLASS_ADULT_MALE_AKHET :
		classFace = "SQAR";
		break;
	case CLASS_ADULT_FEMALE_AKHET :
		classFace = "SINE";
		break;
	default:
		classFace = "SQAR";
		break;
 } 
 
 SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
 
 //MESSAGE
 LocalAmbientSound("misc/chat", 127);
 messageBox_Portrait("Good morning!","BILFONT","SWIRL",0,CR_TAN);
 
 int buttons;
 bool ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("There's some breakfast for you on the dresser.","BILFONT","SWIRL",0,CR_TAN);
 
 ok = false;
 delay(8);
 
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("Crunchy red things?","BILFONT",classFace,0,CR_TAN);
 
 ok = false;
 delay(8);
 
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("Heehee.\nThey're called apples.","BILFONT","SWIRL",0,CR_TAN);
 
 ok = false;
 delay(8);
 
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("Thanks.","BILFONT",classFace,0,CR_TAN);
 
 ok = false;
 delay(8);
 
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
  
 //end dialogue
 messageBox_Clear();
 SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
}

//Eclair's Speech
SCRIPT 16 (VOID)
{
 SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
 LocalAmbientSound("misc/chat", 127);
 messageBox_Portrait(".........\n..... boys....\n...\n.... there's enough of me for all of you....\n.... snrk!","BILFONT","ECLAIR",0,CR_TAN);
 
 int buttons;
 bool ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
  
 //end dialogue
 messageBox_Clear();
 SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
}

//Creamhorn's Speech
SCRIPT 17 (VOID)
{
 str classFace = "SQAR";
 LocalAmbientSound("misc/chat", 127);
 switch (PlayerClass(PlayerNumber()))
 {
 	case CLASS_ADULT_MALE_AKHET :
		classFace = "SQAR";
		break;
	case CLASS_ADULT_FEMALE_AKHET :
		classFace = "SINE";
		break;
	default:
		classFace = "SQAR";
		break;
 } 
 
 SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
 
 //MESSAGE
 LocalAmbientSound("misc/chat", 127);
 messageBox_Portrait("There is a secret tunnel on the island to the northeast.\nIt will take you to the land where you can\nfind the maw of Potassium, the entrance linking\nthe overworld with the underworld.","BILFONT","CRMHORN",0,CR_TAN);
 
 int buttons;
 bool ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("But we locked it off.  You need three\nspecial gemkeys to raise the bridge to\nthe island.  The gems are hidden all around\nthe hyostyle.","BILFONT","CRMHORN",0,CR_TAN);
 
 ok = false;
 delay(8);
 
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("Why would you block off the island?","BILFONT",classFace,0,CR_TAN);
 
 ok = false;
 delay(8);
 
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("... uh... no reason.\nWe can't just let ANYBODY in the tunnels,\nyou know.","BILFONT","CRMHORN",0,CR_TAN);
 
 ok = false;
 delay(8);
 
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("We had barred areas where mean creatures\nwere trying to get in.  You can unlock them\nby pulling the switches across the bridge.","BILFONT","CRMHORN",0,CR_TAN);
 
 ok = false;
 delay(8);
 
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
  
 //end dialogue
 messageBox_Clear();
 SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
}

//Scytheclops is defeated
SCRIPT 18 (VOID)
{
	SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
	localsetmusic("");
	
	//MESSAGE
	LocalAmbientSound("FANFARE", 127);
	messageBox_Plain("YOU WIN!","BILFONT",0,CR_TAN);
 
	int buttons;
	bool ok = false;
	delay(8);
	
	while (ok == false)
	{
		buttons = GetPlayerInput(-1, INPUT_BUTTONS);
		if (buttons & BT_USE)
			ok = true;
		delay(1);
	}
	messageBox_Clear();
	localsetmusic("EPIC");
	
	//MESSAGE
	LocalAmbientSound("menu/change", 127);
	messageBox_Plain("THIS IS NOT AN RPG!","BILFONT",0,CR_TAN);

	ok = false;
	delay(8);
	
	while (ok == false)
	{
		buttons = GetPlayerInput(-1, INPUT_BUTTONS);
		if (buttons & BT_USE)
			ok = true;
		delay(1);
	}
	messageBox_Clear();
	
	//MESSAGE
	LocalAmbientSound("menu/change", 127);
	messageBox_Plain("YOU DID NOT GAIN ANY EXP!","BILFONT",0,CR_TAN);

	ok = false;
	delay(8);
	
	while (ok == false)
	{
		buttons = GetPlayerInput(-1, INPUT_BUTTONS);
		if (buttons & BT_USE)
			ok = true;
		delay(1);
	}
	messageBox_Clear();
	
	//MESSAGE
	LocalAmbientSound("menu/change", 127);
	messageBox_Plain("YOU DIDN'T GET ANY MONEY!","BILFONT",0,CR_TAN);

	ok = false;
	delay(8);
	
	while (ok == false)
	{
		buttons = GetPlayerInput(-1, INPUT_BUTTONS);
		if (buttons & BT_USE)
			ok = true;
		delay(1);
	}
	messageBox_Clear();
	
	//MESSAGE
	LocalAmbientSound("menu/change", 127);
	messageBox_Plain("YOU DON'T GET A LEVEL UP!","BILFONT",0,CR_TAN);

	ok = false;
	delay(8);
	
	while (ok == false)
	{
		buttons = GetPlayerInput(-1, INPUT_BUTTONS);
		if (buttons & BT_USE)
			ok = true;
		delay(1);
	}
	messageBox_Clear();
	ok = false;
  
	//end dialogue
	messageBox_Clear();
	SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
 
	setmusic("*");
	setLineSpecial(7,0);
	setActorState(152,"spawn");
	teleportOther(151,178,0);
	teleportOther(152,179,0);
	teleportOther(153,180,0);
	thing_setSpecial(151,80,20,0,0);
	thing_setSpecial(152,80,21,0,0);
	thing_setSpecial(153,80,22,0,0);
	
	door_Open(181,16);
	door_Open(182,16);
}

//Used for locked doors that open via polyobjects.
//Speed determines direction (positive = clockwise, negative = counter)
SCRIPT 19 (int poly)
{
	Polyobj_DoorSwing(poly,16,64,-1);
}

//Swirl's second speech
SCRIPT 20 (VOID)
{
 str classFace = "SQAR";
 LocalAmbientSound("misc/chat", 127);
 switch (PlayerClass(PlayerNumber()))
 {
 	case CLASS_ADULT_MALE_AKHET :
		classFace = "SQAR";
		break;
	case CLASS_ADULT_FEMALE_AKHET :
		classFace = "SINE";
		break;
	default:
		classFace = "SQAR";
		break;
 } 
 
 SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
 
 //MESSAGE
 LocalAmbientSound("misc/chat", 127);
 messageBox_Portrait("We're so sorry for what we did.\nWe didn't tell you the whole story.","BILFONT","SWIRL",0,CR_TAN);
 
 int buttons;
 bool ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("Our patron god Poseidon was angered at us\nfor leaving our homeworld.\nHe sent scytheclopes to ravage the island.\nWe werethe only survivors.","BILFONT","SWIRL",0,CR_TAN);

 ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("But one of the scytheclopes stayed.\nHe made us his prisoners on this island, and he\nwouldn't eat us only as long as we could bring him offerings.","BILFONT","SWIRL",0,CR_TAN);

 ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("I didn't want to do it, but Creamhorn\nthought we could trick you into being a sacrifice.\nBut you killed him!\nWe're so grateful to you for ridding us of him.","BILFONT","SWIRL",0,CR_TAN);

 ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //MESSAGE
 LocalAmbientSound("menu/change", 127);
 messageBox_Portrait("We didn't lie about the underground tunnels.\nIt's in that building over there.\nI unlocked the door for you.","BILFONT","SWIRL",0,CR_TAN);

 ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //END
 SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
}

//*******************
//Eclair's second speech
//*******************
SCRIPT 21 (VOID)
{
 str classFace = "SQAR";
 LocalAmbientSound("misc/chat", 127);
 switch (PlayerClass(PlayerNumber()))
 {
 	case CLASS_ADULT_MALE_AKHET :
		classFace = "SQAR";
		break;
	case CLASS_ADULT_FEMALE_AKHET :
		classFace = "SINE";
		break;
	default:
		classFace = "SQAR";
		break;
 } 
 
 SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
 
 //MESSAGE
 LocalAmbientSound("misc/chat", 127);
 messageBox_Portrait("Thank you so much.","BILFONT","ECLAIR",0,CR_TAN);
 
 int buttons;
 bool ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //END
 SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
}

//Creamhorn's second speech
SCRIPT 22 (VOID)
{
 str classFace = "SQAR";
 LocalAmbientSound("misc/chat", 127);
 switch (PlayerClass(PlayerNumber()))
 {
 	case CLASS_ADULT_MALE_AKHET :
		classFace = "SQAR";
		break;
	case CLASS_ADULT_FEMALE_AKHET :
		classFace = "SINE";
		break;
	default:
		classFace = "SQAR";
		break;
 } 
 
 SetPlayerProperty(0,1,PROP_TOTALLYFROZEN);
 
 //MESSAGE
 LocalAmbientSound("misc/chat", 127);
 messageBox_Portrait("GASP!\n\nYou.... you survived!","BILFONT","CRMHORN",0,CR_TAN);
 
 int buttons;
 bool ok = false;
 delay(8);
 while (ok == false)
 {
    buttons = GetPlayerInput(-1, INPUT_BUTTONS);
    if (buttons & BT_USE)
       ok = true;
    delay(1);
 }
 messageBox_Clear();
 
 //END
 SetPlayerProperty(0,0,PROP_TOTALLYFROZEN);
}

//look in the mirror
SCRIPT 23 (VOID)
{
 str classFace = "SQAR";
 str classFaceWink = "SQARWINK";
 int color = CR_PURPLE;
 
 int buttons;
 bool ok = false;
 delay(8);
 
 LocalAmbientSound("misc/chat", 127);
 switch (PlayerClass(PlayerNumber()))
 {
 	case CLASS_ADULT_MALE_AKHET :
		classFace = "SQAR";
		classFaceWink = "SQARWINK";
		color = CR_PURPLE;
		break;
	case CLASS_ADULT_FEMALE_AKHET :
		classFace = "SINE";
		classFaceWink = "SINEWINK";
		color = CR_GREEN;
		break;
	default:
		classFace = "SQAR";
		classFaceWink = "SQARWINK";
		color = CR_PURPLE;
		break;
 } 
 SetPlayerProperty(0,1,PROP_TOTALLYFROZEN); 
 messageBox_Portrait("So beautiful!","BILFONT",classFace,0,CR_TAN);
 
 while (ok == false)
	    {
			buttons = GetPlayerInput(-1, INPUT_BUTTONS);
			if (buttons & BT_USE)
				ok = true;
			delay(1);
	    }

 LocalAmbientSound("DING", 127);
 setPortrait(classFaceWink);
 
 ok = false;
 delay(8);
 
 while (ok == false)
	    {
			buttons = GetPlayerInput(-1, INPUT_BUTTONS);
			if (buttons & BT_USE)
				ok = true;
			delay(1);
	    }

 messageBox_Clear();
 SetPlayerProperty(0,0,PROP_TOTALLYFROZEN); 
}

SCRIPT 24 (VOID)
{
	Door_Close(181,128);
	localsetmusic("TIPTOE");
}

//Open the secret door
SCRIPT 25 (VOID)
{
	Polyobj_DoorSwing(1, 16, 64, -1);
}

function void daylight(VOID)
{
   ChangeSky("SEASKY01","SEASKY01");
   SetLineTexture(4, SIDE_FRONT, TEXTURE_MIDDLE, "SEASKY01");
   SetLineTexture(5, SIDE_FRONT, TEXTURE_MIDDLE, "SEASKY01");
}
