//   FILE: Ultra Square Tetris v7.2DP.tws
// SOURCE: Ultra Square Tetris v7.2DP
//   DATE: Wed, Oct 31, 2001  12:38:22 PM


GeneralInfo
{
	PlayfieldColumns 10
	PlayfieldRows 22
	MaxMovementsPerSecond 15
	MaxRotationsPerSecond 5
	GameType Levels
	NextPieceQueueSize 8
}

MinoSticky
{
	NotStickyBetweenPieces
	0: 0
	1: 1
	2: 2
	3: 3
	4: 4
	5: 5
	6: 6
	7: 7
	20: 20
	31: 31
}

Mino
{
	Name "J color"
	Tags 0
	MutateMino "Result J color"
}

Mino
{
	Name "L color"
	Tags 1
	MutateMino "Result L color"
}

Mino
{
	Name "S color"
	Tags 2
	MutateMino "Result S color"
}

Mino
{
	Name "Z color"
	Tags 3
	MutateMino "Result Z color"
}

Mino
{
	Name "O color"
	Tags 4
	MutateMino "Result O color"
}

Mino
{
	Name "T color"
	Tags 5
	MutateMino "Result T color"
}

Mino
{
	Name "I color"
	Tags 6
	MutateMino "Result I color"
}

Mino
{
	Name "Pure Square"
	Tags 31
	MutateMino "Result Pure Square"
	D9 2.5
}

Mino
{
	Name "Combo Square"
	Tags 31
	MutateMino "Result Combo Square"
	D9 1.25
}

Mino
{
	Name "Result J color"
	Tags 24
}

Mino
{
	Name "Result L color"
	Tags 25
}

Mino
{
	Name "Result S color"
	Tags 26
}

Mino
{
	Name "Result Z color"
	Tags 27
}

Mino
{
	Name "Result O color"
	Tags 28
}

Mino
{
	Name "Result T color"
	Tags 29
}

Mino
{
	Name "Result I color"
	Tags 30
}

Mino
{
	Name "Result Pure Square"
	Tags 23
}

Mino
{
	Name "Result Combo Square"
	Tags 22
}

Mino
{
	Name "Garbage"
	Tags 20
}

Tetramino
{
	Name "J Tetrimino"
	NumberInBag 1
	ID 1
	MinoList
	{
		"J color" (-1,1)
		"J color" (-1,0)
		"J color" (0,0)
		"J color" (1,0)
	}
	Rot0CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot90CWOffsetList (0,0),(1,0),(1,-1),(0,2),(1,2)
	Rot180CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot270CWOffsetList (0,0),(-1,0),(-1,-1),(0,2),(-1,2)
}

Tetramino
{
	Name "I Tetrimino"
	NumberInBag 1
	ID 2
	MinoList
	{
		"I color" (-1,0)
		"I color" (0,0)
		"I color" (1,0)
		"I color" (2,0)
	}
	Rot0CWOffsetList (0,0),(-1,0),(2,0),(-1,0),(2,0)
	Rot90CWOffsetList (-1,0),(0,0),(0,0),(0,1),(0,-2)
	Rot180CWOffsetList (-1,1),(1,1),(-2,1),(1,0),(-2,0)
	Rot270CWOffsetList (0,1),(0,1),(0,1),(0,-1),(0,2)
}

Tetramino
{
	Name "O Tetrimino"
	NumberInBag 1
	ID 3
	MinoList
	{
		"O color" (-1,1)
		"O color" (0,1)
		"O color" (-1,0)
		"O color" (0,0)
	}
	Rot0CWOffsetList (-1,0),(-1,0),(-1,0),(-1,0),(-1,0)
	Rot90CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot180CWOffsetList (0,-1),(0,-1),(0,-1),(0,-1),(0,-1)
	Rot270CWOffsetList (-1,-1),(-1,-1),(-1,-1),(-1,-1),(-1,-1)
}

Tetramino
{
	Name "S Tetrimino"
	NumberInBag 1
	ID 4
	MinoList
	{
		"S color" (0,1)
		"S color" (1,1)
		"S color" (-1,0)
		"S color" (0,0)
	}
	Rot0CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot90CWOffsetList (0,0),(1,0),(1,-1),(0,2),(1,2)
	Rot180CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot270CWOffsetList (0,0),(-1,0),(-1,-1),(0,2),(-1,2)
}

Tetramino
{
	Name "L Tetrimino"
	NumberInBag 1
	ID 5
	MinoList
	{
		"L color" (1,1)
		"L color" (-1,0)
		"L color" (0,0)
		"L color" (1,0)
	}
	Rot0CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot90CWOffsetList (0,0),(1,0),(1,-1),(0,2),(1,2)
	Rot180CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot270CWOffsetList (0,0),(-1,0),(-1,-1),(0,2),(-1,2)
}

Tetramino
{
	Name "Z Tetrimino"
	NumberInBag 1
	ID 6
	MinoList
	{
		"Z color" (-1,1)
		"Z color" (0,1)
		"Z color" (0,0)
		"Z color" (1,0)
	}
	Rot0CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot90CWOffsetList (0,0),(1,0),(1,-1),(0,2),(1,2)
	Rot180CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot270CWOffsetList (0,0),(-1,0),(-1,-1),(0,2),(-1,2)
}

Tetramino
{
	Name "T Tetrimino"
	NumberInBag 1
	ID 7
	MinoList
	{
		"T color" (0,1)
		"T color" (-1,0)
		"T color" (0,0)
		"T color" (1,0)
	}
	Rot0CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot90CWOffsetList (0,0),(1,0),(1,-1),(0,2),(1,2)
	Rot180CWOffsetList (0,0),(0,0),(0,0),(0,0),(0,0)
	Rot270CWOffsetList (0,0),(-1,0),(-1,-1),(0,2),(-1,2)
}

GarbageInfo
{
	NormalMino "Garbage"
	NormalCount 9
}

Shape
{
	Name "Perfect Square"
	Hotspot (7,8)
	ShapeCoords (4,11),(4,10),(4,9),(4,8),(5,11),(5,10),(5,9),(5,8),(6,11),(6,10),(6,9),(6,8),(7,11),(7,10),(7,9),(7,8)
}

Shape
{
	Name "T-spin 1"
	Hotspot (7,8)
	ShapeCoords (6,9),(6,7),(8,7)
}

Shape
{
	Name "T-spin 2"
	Hotspot (7,8)
	ShapeCoords (6,7),(8,9),(8,7)
}

Shape
{
	Name "Spin S 1"
	Hotspot (7,8)
	ShapeCoords (5,6),(6,8),(6,7),(8,6),(9,8),(9,7)
}

Shape
{
	Name "Spin S 2"
	Hotspot (7,8)
	ShapeCoords (4,6),(5,8),(5,7),(7,6),(8,8),(8,7)
}

Shape
{
	Name "Spin Z 1"
	Hotspot (7,8)
	ShapeCoords (5,8),(5,7),(6,6),(8,8),(8,7),(9,6)
}

Shape
{
	Name "Spin Z 2"
	Hotspot (7,8)
	ShapeCoords (6,8),(6,7),(7,6),(9,8),(9,7),(10,6)
}

Pattern
{
	Name "t-spin top"
	Triggered
	Tags 0,1,2,3,4,5,6,24,25,26,27,28,29,30,31
	Method Search
	SearchType Horizontal
	SearchCount 10
	PatternBeginScript
	{
		sound "FX_RWD02"
		set pl.d4 to 0
	}
	PatternMinoScript
	{
		set pl.d5 to mino.y
	}
}

Pattern
{
	Name "t-spin bottom"
	Triggered
	Tags 0,1,2,3,4,5,6,24,25,26,27,28,29,30,31
	Method Search
	SearchType Horizontal
	SearchCount 10
	PatternBeginScript
	{
		sound "FX_RWD01"
		set pl.d5 to 21
	}
	PatternMinoScript
	{
		if pl.d4 = -1
			set pl.d4 to mino.y
		end
	}
}

Pattern
{
	Name "J Square"
	Tags 0
	Method Shape
	ShapeName "Perfect Square"
	PatternPieceCount 4
	PatternMinoScript
	{
		set mino to "Pure Square"
		message "Pure Square!!!"
	}
	PatternEndScript
	{
		solidify
		set st1.d2 to st1.d2 + 1
		sound "FX_GOLDF"
	}
}

Pattern
{
	Name "I Square"
	Tags 6
	Method Shape
	ShapeName "Perfect Square"
	PatternPieceCount 4
	PatternMinoScript
	{
		set mino to "Pure Square"
		message "Pure Square!!!"
	}
	PatternEndScript
	{
		solidify
		set st1.d2 to st1.d2 + 1
		sound "FX_GOLDF"
	}
}

Pattern
{
	Name "O Square"
	Tags 4
	Method Shape
	ShapeName "Perfect Square"
	PatternPieceCount 4
	PatternMinoScript
	{
		set mino to "Pure Square"
		message "Pure Square!!!"
	}
	PatternEndScript
	{
		solidify
		set st1.d2 to st1.d2 + 1
		sound "FX_GOLDF"
	}
}

Pattern
{
	Name "T Square"
	Tags 5
	Method Shape
	ShapeName "Perfect Square"
	PatternPieceCount 4
	PatternMinoScript
	{
		set mino to "Pure Square"
		message "Pure Square!!!"
	}
	PatternEndScript
	{
		solidify
		set st1.d2 to st1.d2 + 1
		sound "FX_GOLDF"
	}
}

Pattern
{
	Name "L Square"
	Tags 1
	Method Shape
	ShapeName "Perfect Square"
	PatternPieceCount 4
	PatternMinoScript
	{
		set mino to "Pure Square"
		message "Pure Square!!!"
	}
	PatternEndScript
	{
		solidify
		set st1.d2 to st1.d2 + 1
		sound "FX_GOLDF"
	}
}

Pattern
{
	Name "Combo Square"
	Tags 0,1,2,3,4,5,6
	Method Shape
	ShapeName "Perfect Square"
	PatternPieceCount 4
	PatternMinoScript
	{
		set mino to "Combo Square"
		message "Combo Square!"
	}
	PatternEndScript
	{
		solidify
		set st1.d1 to st1.d1 + 1
		sound "FX_SLVRF"
	}
}

Pattern
{
	Name "Line clear"
	Tags 0,1,2,3,4,5,6,20,22,23,24,25,26,27,28,29,30,31
	Method Search
	SearchType Horizontal
	SearchCount 10
	PatternBeginScript
	{
		if mino.d9 = 2.5
			line color (0,36,154)
		end
		if mino.d9 = 1.25
			line color (118,119,0)
		end
	}
	PatternMinoScript
	{
		set pf.d0 to pf.d0 + mino.d9
		kill mino
		sound "FX_CLR01"
	}
}

Level
{
	Name "Level #1"
}

Level
{
	Name "Level #2"
}

Level
{
	Name "Level #3"
}

Level
{
	Name "Level #4"
}

Level
{
	Name "Level #5"
}

Level
{
	Name "Level #6"
}

Level
{
	Name "Level #7"
}

Level
{
	Name "Level #8"
}

Level
{
	Name "Level #9"
}

Level
{
	Name "Level #10"
}

Level
{
	Name "Level #11"
}

Level
{
	Name "Level #12"
}

Level
{
	Name "Level #13"
}

Level
{
	Name "Level #14"
}

Level
{
	Name "Level #15"
}

GenerationPhase
{
	GenerationTime ((.8-((level-1)*.007))^(level-1))/20
	PieceStartingLocation (4,0)
	GenerationBeginScript
	{
		set pf.d2 to 1
		set pf.d4 to 0
	}
	GenerationEndScript
	{
		set st0.d4 to st0.d4 + 1
	}
}

FallingPhase
{
	FallSpeed (.8-((level-1)*.007))^(level-1)
	SoftDropSpeed ((.8-((level-1)*.007))^(level-1))/20
	HardDropSpeed 0.0001
	MoveTolerance 1
}

LockPhase
{
	MovementRestartsClock
	Duration 0.5
}

PatternPhase
{
	PatternBeginScript
	{
		set pl.d4 to -1
		set pl.d5 to -1
	}
}

IteratePhase
{
	PrimaryIterator
	{
		IteratorExpression pl.d4 != -1
		MinoIteratorScript
		{
			if mino.y > pl.d5
				exit
			end
			if mino.y < pl.d4
				exit
			end
			mutate mino
			sound "FX_LOCK"
		}
	}
	IterateEndScript
	{
		if pl.d4 != -1
			set gravity to 1
		end
		set pl.d6 to 0
	}
}

EliminatePhase
{
	FallSpeed 0.05
	LineCollapsedScript
	{
		set ph.d0 to ph.d0 + 1
	}
	StartFallingScript
	{
		set goal to goal - pf.d0
		set pf.d0 to 0
		if ph.d0 = 1
		line color (109,0,23)
		end
		if ph.d0 = 2
		line color (39,0,87)
		end
		if ph.d0 = 3
		line color (116,55,0)
		end
		if ph.d0 >= 4
		line color (0,91,56)
		end
	}
	GroupLandedScript
	{
		sound "FX_LNE01"
	}
	EliminateEndScript
	{
		set st2.d8 to goal
		if ph.d0 = 1
		 if pf.d4
		  set goal to goal - 1
		set st2.d9 to st2.d8 - goal
				message "T-spin"
		 end
			sound "FX_MTRS1"
		 set goal to goal -1
		set st2.d9 to st2.d8 - goal
		set st0.d0 to st0.d0 + 1
		message "Single"
		end
		if ph.d0 = 2
		 if pf.d4
		  set goal to goal - 3
		set st2.d9 to st2.d8 - goal
				message "T-spin"
		 end
			sound "FX_MTRS2"
			set goal to goal -3
		set st2.d9 to st2.d8 - goal
		set st0.d1 to st0.d1 + 1
		message "Double"
			send "Attack1"
		end
		if ph.d0 = 3
			sound "FX_MTRS3"
			set goal to goal -5
		set st2.d9 to st2.d8 - goal
		set st0.d2 to st0.d2 + 1
		message "Triple"
			send "Attack2"
		end
		if ph.d0 >= 4
			sound "FX_MTRS4"
		 set goal to goal -8
		set st2.d9 to st2.d8 - goal
		set st0.d3 to st0.d3 + 1
		message "Tetris!"
			send "Attack3"
		end
		if goal < 0
		 set goal to 0
		end
	}
}

SolidifyPhase
{
}

GravityPhase
{
	FallSpeed 0.05
	GroupLandedScript
	{
		sound "FX_LOCK"
	}
	GravityEndScript
	{
		set gravity to 0
	}
}

CompletionPhase
{
	CompletionBeginScript
	{
		if goal <= 0
			next level
			if level < 15
				sound "FX_LEVEL"
		 message "LEVEL UP!"
			end
		end
	}
}

EventScripts
{
	GameStartScript
	{
		sound "FX_LEVEL"
		set ghost to 1
		set st0.d0 to 0
		set st0.d1 to 0
		set st0.d2 to 0
		set st0.d3 to 0
		set st0.d4 to 0
		set st0.d5 to 0
		set st0.d7 to 0
		set st0.d8 to 0
		set st1.d1 to 0
		set st1.d2 to 0
		line color (30,30,30)
	}
	LevelStartScript
	{
		mino intensity high
		set pf.d3 to 0
		set goal to (10*level)
		set pf.d7 to 0
	}
	LevelEndScript
	{
		if level >= 15
			win
		end
	}
	MoveSuccessfulScript
	{
		sound "FX_FALL"
		set st0.d5 to st0.d5 + 1
	}
	MoveFailedScript
	{
		sound "FX_LND01"
		set st0.d5 to st0.d5 + 1
	}
	RotateSuccessfulScript
	{
		sound "FX_RTA01"
		set st0.d5 to st0.d5 + 1
	}
	RotateFailedScript
	{
		sound "FX_LND01"
		set st0.d5 to st0.d5 + 1
	}
	HardDropStartScript
	{
		sound "FX_HRDDP"
		set st0.d5 to st0.d5 + 1
		set pf.d2 to 0
	}
	SoftDropStepScript
	{
		sound "FX_FALL"
		set st0.d5 to st0.d5 + 1
	}
	FallStepScript
	{
		sound "FX_FALL"
	}
	TouchdownScript
	{
		if pf.d2
		 sound "FX_LND01"
		end
	}
	LockdownScript
	{
		if pf.d2
		 sound "FX_LCK01"
		end
		if piece.id = 7
			if spin
				shape "T-spin 1" at piece.x, piece.y
				if result = 1
		  	if piece.dir = 3
			  	pattern "t-spin top" at piece.x,piece.y-1
				  pattern "t-spin bottom" at piece.x,piece.y
			  else
				  pattern "t-spin top" at piece.x,piece.y
				  pattern "t-spin bottom" at piece.x,piece.y+1
			  end
		   if level < 6
		    sound "VO_TSPIN"
		   else
		    sound "FX_RWD01"
		   end
		   set goal to goal -1 
					set pf.d4 to 1
				else
					shape "T-spin 2" at piece.x, piece.y
					if result = 1
		  	if piece.dir = 3
			  	pattern "t-spin top" at piece.x,piece.y-1
				  pattern "t-spin bottom" at piece.x,piece.y
			  else
				  pattern "t-spin top" at piece.x,piece.y
				  pattern "t-spin bottom" at piece.x,piece.y+1
			  end
		    if level < 6
		     sound "VO_TSPIN"
		    else
		     sound "FX_RWD01"
		    end
		    set goal to goal -1 
						set pf.d4 to 1
					end
				end
			end
		end
	}
	GameSecondScript
	{
		set st0.d8 to game time
	}
	LevelSecondScript
	{
		set st0.d7 to level time
	}
}

CustomEvent
{
	Name "Attack1"
	TriggerType Manual
	Script
	{
		set pl.d0 to pl.d0 + 4
		mix garbage
		garbage 1
		sound "FX_GAR01"
	}
}

CustomEvent
{
	Name "Attack2"
	TriggerType Manual
	Script
	{
		set pl.d0 to pl.d0 + 4
		mix garbage
		garbage 2
		sound "FX_GAR02"
	}
}

CustomEvent
{
	Name "Attack3"
	TriggerType Manual
	Script
	{
		set pl.d0 to pl.d0 + 4
		mix garbage
		garbage 4
		sound "FX_GAR03"
	}
}

CustomEvent
{
	Name "Countdown"
	TriggerType LevelTime 109
	Script
	{
		message "COUNTDOWN!"
	}
}

CustomEvent
{
	Name "10"
	TriggerType LevelTime 110
	Script
	{
		sound "FX_TIC10"
	}
}

CustomEvent
{
	Name "9"
	TriggerType LevelTime 111
	Script
	{
		sound "FX_TIC09"
	}
}

CustomEvent
{
	Name "8"
	TriggerType LevelTime 112
	Script
	{
		sound "FX_TIC08"
	}
}

CustomEvent
{
	Name "7"
	TriggerType LevelTime 113
	Script
	{
		sound "FX_TIC07"
	}
}

CustomEvent
{
	Name "6"
	TriggerType LevelTime 114
	Script
	{
		sound "FX_TIC06"
	}
}

CustomEvent
{
	Name "5"
	TriggerType LevelTime 115
	Script
	{
		sound "FX_TIC05"
	}
}

CustomEvent
{
	Name "4"
	TriggerType LevelTime 116
	Script
	{
		sound "FX_TIC04"
	}
}

CustomEvent
{
	Name "3"
	TriggerType LevelTime 117
	Script
	{
		sound "FX_TIC03"
	}
}

CustomEvent
{
	Name "2"
	TriggerType LevelTime 118
	Script
	{
		sound "FX_TIC02"
	}
}

CustomEvent
{
	Name "1"
	TriggerType LevelTime 119
	Script
	{
		sound "FX_TIC01"
	}
}
