#include "zcommon.acs"
#DEFINE CRUSHDAMAGE 32

int RisingSpeed,
    ButtonCount,
    RisingCrush;
	
bool doorLock[1] = {false};
	
SCRIPT 01 OPEN	//sets line and sector specials
{
	ceiling_Waggle(255,64,8,0,0);	//Water Tide
}

//Used for locked doors that require dinky keys
SCRIPT 02 (int doorNum, int poly) // locked door
{
 If (doorLock[doorNum] == true || GameType () == GAME_NET_DEATHMATCH)
	Polyobj_DoorSwing(poly, 48, 64, 64);

 Else If (CheckInventory("DinkyKey") == 0 && doorLock[doorNum] == false && GameType () != GAME_NET_DEATHMATCH)
	Print(s:"THIS DOOR IS LOCKED");
  
 else if (CheckInventory("DinkyKey") > 0 && doorLock[doorNum] == false && GameType () != GAME_NET_DEATHMATCH)
 {
  doorLock[doorNum] = true;
  TakeInventory("DinkyKey", 1);
  ThingSound(0,"DOORUNLOCKED",127);
  delay(16);
  Polyobj_DoorSwing(poly, 48, 64, 64);
 }
}

SCRIPT 03 (int gemKey, int pillar, int pillar3d)
{
	LocalAmbientSound("SWITCH1", 127);
	switch (gemKey)
	{
		case 0:
				ChangeFloor(77, "GEMLCKB1");
				break;
		case 1:
				ChangeFloor(78, "GEMLCKC1");
				break;
		case 2:
				ChangeFloor(79, "GEMLCKR1");
				break;
		case 3:
				ChangeFloor(80, "GEMLCKG1");
				break;
		default:
				ChangeFloor(77, "GEMLCKB1");
				break;
	}
	
	ceiling_moveToValue(pillar3d,24,256,0);
	floor_moveToValue(pillar3d,24,216,0);
	floor_moveToValue(pillar,24,256,0);
}

SCRIPT 04 (int board)	//bridge Pieces fall down
{
	ceiling_moveToValue(board,64,240,1);
	floor_moveToValue(board,64,256,1);
}

SCRIPT 05 (VOID)	//raises the bridge
{
	for (int count = 34; count <= 44; count++)
	{
		tagWait(count);
		ceiling_moveToValue(count,16,0,0);
		floor_moveToValue(count,16,16,1);
	}
}

SCRIPT 06 (VOID) //activate deathtraps
{
	ACS_EXECUTE(7,0,1,0,0);
	ACS_EXECUTE(8,0,2,0,0);
	ACS_EXECUTE(9,0,0,0,0);
	ACS_EXECUTE(10,0,0,0,0);
	ACS_EXECUTE(11,0,3,4,0);
	ACS_EXECUTE(12,0,5,0,0);
	ACS_EXECUTE(13,0,6,0,0);
	ACS_EXECUTE(14,0,7,8,0);
	ACS_EXECUTE(15,0,21,22,0);
	
	Polyobj_RotateLeft(9, 128, 255);
	Polyobj_RotateLeft(10, 128, 255);
	Polyobj_RotateLeft(11, 128, 255);
	Polyobj_RotateLeft(12, 128, 255);
}

SCRIPT 07 (int poly)	//crushing walls
{
	Polyobj_Move(poly, 128, 64, 192);
	
	polywait(poly);
	delay(16);
	
	Polyobj_Move(poly, 128, 192, 192);
	
	polywait(poly);
	delay(16);
	
	restart;
}

SCRIPT 08 (int poly)	//crushing walls
{
	Polyobj_Move(poly, 128, 64, 192);
	
	polywait(poly);
	delay(16);
	
	Polyobj_Move(poly, 128, 192, 192);
	
	polywait(poly);
	delay(16);
	
	restart;
}

SCRIPT 09 (VOID) //crushing floors and ceilings
{
	Floor_RaiseAndCrush(18, 64, CRUSHDAMAGE,1);

	tagWait(18);
	delay(32);
	Floor_CrushStop(18);
	
	Floor_LowerByValue(18, 64, 112);
	
	tagWait(18);
	delay(32);
	restart;
}

SCRIPT 10 (VOID) //crushing floors and ceilings
{
	Ceiling_LowerAndCrush(19, 64, CRUSHDAMAGE,1);

	tagWait(19);
	delay(32);
	Ceiling_CrushStop(19);
	
	Ceiling_RaiseByValue(19, 64, 112);

	tagWait(19);
	delay(32);
	restart;
}

SCRIPT 11 (int poly1,int poly2)		//crushing walls
{
	Polyobj_Move(poly1, 128, 192, 64);
	Polyobj_Move(poly2, 128, 64, 64);
	
	polywait(poly1);
	polywait(poly2);
	delay(16);
	
	Polyobj_Move(poly1, 128, 64, 64);
	Polyobj_Move(poly2, 128, 192, 64);
	
	polywait(poly1);
	polywait(poly2);
	delay(16);
	
	restart;
}

SCRIPT 12 (int poly)	//crushing walls
{
	Polyobj_Move(poly, 128, 64, 192);
	
	polywait(poly);
	delay(16);
	
	Polyobj_Move(poly, 128, 192, 192);
	
	polywait(poly);
	delay(16);
	
	restart;
}

SCRIPT 13 (int poly)	//crushing walls
{
	Polyobj_Move(poly, 128, 64, 192);
	
	polywait(poly);
	delay(16);
	
	Polyobj_Move(poly, 128, 192, 192);
	
	polywait(poly);
	delay(16);
	
	restart;
}

SCRIPT 14 (int poly1,int poly2)		//crushing walls
{
	Polyobj_Move(poly1, 128, 192, 64);
	Polyobj_Move(poly2, 128, 64, 64);
	
	polywait(poly1);
	polywait(poly2);
	delay(16);
	
	Polyobj_Move(poly1, 128, 64, 64);
	Polyobj_Move(poly2, 128, 192, 64);
	
	polywait(poly1);
	polywait(poly2);
	delay(16);
	
	restart;
}

//Crushing Pillars
SCRIPT 15 (int ceilingTag1, int ceilingTag2)
{
	tagWait(ceilingTag2);
	delay(32);
	
	Ceiling_LowerAndCrush(ceilingTag1, 64, CRUSHDAMAGE,1);

	tagWait(ceilingTag1);
	delay(32);
	
	Ceiling_CrushStop(ceilingTag1);
	Ceiling_RaiseByValue(ceilingTag1, 64, 112);

	tagWait(ceilingTag1);
	delay(32);
	
	Ceiling_LowerAndCrush(ceilingTag2, 64, CRUSHDAMAGE,1);

	tagWait(ceilingTag2);
	delay(32);
	
	Ceiling_CrushStop(ceilingTag2);
	Ceiling_RaiseByValue(ceilingTag2, 64, 112);
	restart;
}

//Rising Floor
SCRIPT 16 (VOID)
{
	tagWait(81);
	delay(64);
	Floor_RaiseToLowestCeiling(81, 12);
	tagWait(81);
	delay(64);
	Floor_MoveToValue(81,80,256,1);
	restart;
}

//open locked door
SCRIPT 17(VOID)
{
	PolyObj_DoorSwing(27,16,64,-1);
}

SCRIPT 18(VOID)
{
	floor_MoveToValue(31,16,480);
}

/*
SCRIPT 16 (int ceilingTag) //crushing floors and ceilings
{
	Ceiling_LowerAndCrush(ceilingTag, 64, CRUSHDAMAGE,1);

	tagWait(ceilingTag);
	delay(32);
	ACS_EXECUTE(17,0,ceilingTag,0,0);
}

SCRIPT 17 (int ceilingTag)	//raise ceilings back
{
	Ceiling_CrushStop(ceilingTag);
	
	Ceiling_RaiseByValue(ceilingTag, 64, 112);

	tagWait(ceilingTag);
	delay(32);
	ACS_EXECUTE(16,0,ceilingTag,0,0);
}
*/

/*
SCRIPT 06 (VOID)
{
 Switch (GameSkill ())
 {
  case SKILL_VERY_EASY: RisingSpeed = random(4,8);
			Ceiling_RaiseByValue(8,16,32);
			RisingCrush=4;
			ButtonCount=1;
			break;

  case SKILL_EASY: 	RisingSpeed = random(6,12);
			Ceiling_RaiseByValue(7,16,32);
			Ceiling_RaiseByValue(8,16,32);
			RisingCrush=8;
			ButtonCount=2;
			break;

  case SKILL_NORMAL: 	RisingSpeed = random(8,16);
			Ceiling_RaiseByValue(7,16,32);
			Ceiling_RaiseByValue(8,16,32);
			Ceiling_RaiseByValue(9,16,32);
			RisingCrush=12;
			ButtonCount=3;
			break;

  case SKILL_HARD: 	RisingSpeed = random(10,20);
			Ceiling_RaiseByValue(6,16,32);
			Ceiling_RaiseByValue(7,16,32);
			Ceiling_RaiseByValue(9,16,32);
			Ceiling_RaiseByValue(10,16,32);
			RisingCrush=16;
			ButtonCount=4;
			break;

  case SKILL_VERY_HARD: RisingSpeed = random(12,24);
			Ceiling_RaiseByValue(6,16,32);
			Ceiling_RaiseByValue(7,16,32);
			Ceiling_RaiseByValue(8,16,32);
			Ceiling_RaiseByValue(9,16,32);
			Ceiling_RaiseByValue(10,16,32);
			RisingCrush=20;
			ButtonCount=5;
			break;
  }
}

SCRIPT 07 (VOID)
{
 Floor_RaiseAndCrush(5,RisingSpeed,RisingCrush);
}

SCRIPT 08 (VOID)
{
 ButtonCount--;
 if (ButtonCount==0)
 {
  ACS_Terminate(2,7);
  Floor_CrushStop(5);
  Floor_LowerToLowest(5,RisingSpeed);
  TagWait(5);
  Floor_LowerByValue(5,RisingSpeed,72);
 }
}

SCRIPT 09 (int LiftTag)
{
 FloorAndCeiling_RaiseByValue(LiftTag,24,224);
 TagWait(LiftTag);
 Delay(35*3);
  FloorAndCeiling_LowerByValue(LiftTag,24,224);
}
*/
