//////////////////////////////////////////////////////////////////////
// FILE NAME   : SAMPLE.TWS
// AUTHOR      : Chris J. Gullette
// VERSION     : $Revision: 15 $
// DATE        : $Date: 8/23/01 7:01p $
// DESCRIPTION : This is a sample TWS (Tetris Worlds Script) game
//               definition file.  Note that each section is heavily
//               commented, and all sections must appear in the order
//               given in this file.
//               
//               
// (c) 2000-2001 Blue Planet Software.  All rights reserved.
//////////////////////////////////////////////////////////////////////

// As the name implies, this section contains general information about the game and is mandatory.
GeneralInfo
{
	PlayfieldColumns		10		// range 1-32 columns
	PlayfieldRows			20		// range 1-48 rows
	MaxMovementsPerSecond	10		// How many times can a Tetrimino move per second? Integer only!
	MaxRotationsPerSecond	5		// How many times can a Tetrimino rotate per second? Integer only!
	GameType				Levels	// Game type can be Marathon or Levels
	RemoveFromBagAfterUse			// OPTIONAL: Set this flag to remove a Tetrimino from the "bag" after
									// it has been used.  When the bag count for all Tetriminos reaches
									// zero, they will be reset to their starting values.
	NextPieceQueueSize		8		// How large is the next piece queue?
}

// The MinoSticky section defines which mino tags stick to each other.  Note that this defines
// LOGICAL stickiness.  The TWS format does not currently support visual stickiness, this may be
// added later.  This section is mandatory.
MinoSticky
{
	NotStickyBetweenPieces		// OPTIONAL: This flag prevents stickiness between tetriminos.
	0:	0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
	1:	1
	2:	2,3,4,5
	3:	3
	4:	4,5
	5:	5
	6:	6
	7:	7
	8:	8
	9:	9
	10:	10
	11:	11
	12:	12
	13:	13
	14:	14
	15:	15
}

// The Mino section defines each mino type.  At least one Mino is required, but you
// may define any number as long as each has a Name unique among Minos.
Mino
{
	Name		"Mino0"		// Name can be any string, should be unique
	Antigravity				// OPTIONAL: Set this flag to turn gravity off for this mino type.
	Tags		0			// The mino ID number ("tags") can be 0-31.  Multiple tags can be used
							// in the same Mino definition.
	AltMino		"Mino1"		// OPTIONAL: Each mino can have an alternate mino type.
	AltChance	50			// OPTIONAL: If AltMino is defined, you must also define a % chance from 0-50.
	MutateMino	"Mino1"		// OPTIONAL: Each mino can have a "mutate" mino type, switched by the "mutate
							// mino" script command.
	D0	20					// OPTIONAL: Datafields D0-D9 can be any integer (0 by default)
	D1	50
	D2	70
	D3	25
	D6	15
	D7	100
}

Mino
{
	Name "Mino1"
	Tags	1,2,3
	D1	50
	D4	75
}

// The Tetramino section defines a single tetramino type.  At least one Tetramino is required,
// but you may define any number as long as each has a Name unique among Tetraminos.
Tetramino
{
	Name "Tetramino0"	// Name can be any string, must be unique.
	NumberInBag	20		// Number in bag defines probability of appearance, range 0-25.
	ID 0				// This value is returned by the PIECE.ID property.

	// List each mino by name with its location on the 7x7 grid.
	// The center square of the grid is (0,0) by definition.
	MinoList
	{
		"Mino0" (0,0)
		"Mino0" (0,1)
		"Mino0" (0,2)
		"Mino1" (1,2)
	}
	Rot0CWOffsetList		(0,0)			// List offsets for 0 degree CW rotation
	Rot90CWOffsetList		(0,0)			// List offsets for 90 degree CW rotation
	Rot180CWOffsetList		(0,0),(1,1)		// List offsets for 180 degree CW rotation
	Rot270CWOffsetList		(0,0)			// List offsets for 270 degree CW rotation
}

// The GarbageInfo section defines both normal and special garbage.  This section is OPTIONAL.
GarbageInfo
{
	NormalMino		"Mino0"			// Which Mino is used for normal garbage?
	NormalCount		7				// How many Minos for a row of normal garbage?  Expression OK.
	SpecialMino		"Mino1"			// Which Mino is used for special garbage?		
	SpecialCount	pf.d8			// How many Minos for a row of special garbage?  Expression OK.
}

// A Sequence section defines a single sequence of Tetraminos.  Sequences are OPTIONAL,
// but you may define any number as long as each has a Name unique among Sequences.
Sequence
{
	Name			"Sequence0"								// Name of the sequence.
	TetraminoList	"Tetramino0","Tetramino0","Tetramino0"	// A list of Tetramino names.
}

// A Shape section contains a user-defined shape, up to 16x16 in size.  Shapes are OPTIONAL,
// but you may define any number as long as each has a Name unique among Shapes.  Note that
// the points in a Shape are in a 16x16 grid where the lower left corner of the grid is (0,0)
// and the upper right is (15,15).
Shape
{
	Name		"Shape0"				// Name of the shape, any string.
	Hotspot		(7,7)					// Location of the shape hotspot (which is not part of the
										// shape unless included in the ShapeCoords list).
	ShapeCoords	(7,7),(8,7),(9,7),(9,8)	// ShapeCoords contains a list of x,y coordinates for each
										// mino in a shape.
}

// A Pattern section is used to define a matchable pattern based on either pre-defined search
// types or user-defined shapes.  Examples for each follow.  You must have at least one Pattern,
// but you may define as many as you like as long as each has a Name unique among Patterns.  Also
// note that you should not use Search-specific fields in a Shape-based Pattern, and vice versa.
Pattern		// Search pattern
{
	Name				"Pattern0"		// Name of the pattern, any string.
	Triggered							// OPTIONAL:  Patterns execute automatically during the
										// Pattern phase by default.  Set this flag if the Pattern
										// should only execute when triggered by a run-time script.
	Tags				0,1,2,3			// OPTIONAL: Which Mino tags can match in this pattern?  If
										// this list is not present, all tags can match this pattern.
										// If "Tags" is present, you must list at least one tag value.
	Method				Search			// For a search pattern, set Method to Search.
	SearchType			Horizontal		// SEARCH-SPECIFIC: SearchType can be Horizontal, Vertical,
										// DiagNESW, DiagNWSE, Square, FloodFill4D, FloodFill8D, or
										// Ribbon.
	SearchCount			10				// SEARCH-SPECIFIC: Defines the minimum number of Minos required
										// for a successful match.  Any expression is OK.
	PatternPieceCount	5				// OPTIONAL: PatternPieceCount must be a positive integer.  When
										// a potential match is found, the number of unique piece IDs
										// in that pattern is counted.  If it matches this number, then
										// (and only then) the pattern is a match.
	PatternBeginScript	{}				// OPTIONAL: This script runs when a pattern is matched.
	PatternMinoScript	{}				// OPTIONAL: This script runs on each Mino after the BeginScript.
	PatternEndScript	{}				// OPTIONAL: This script runs after all MinoScripts have finished.
}

// This is an example of a shape pattern.  Note: no "Triggered" keyword means automatic execution,
// and no "Tags" list means ALL tags may be part of this pattern.
Pattern
{
	Name				"Pattern1"
	Method				Shape			// For a shape pattern, set Method to Shape.
	ShapeName			"Shape0"		// SHAPE-SPECIFIC: What Shape should be used for this pattern?
	PatternPieceCount	3				// OPTIONAL
	PatternBeginScript	{}				// OPTIONAL
	PatternMinoScript	{}				// OPTIONAL
	PatternEndScript	{}				// OPTIONAL
}

// A Trash section contains an instance of user-defined trash.  Trash is OPTIONAL, but you may define
// any number of Trash sections as long as each has a name unique among Trash.
Trash
{
	Name	"Trash0"					// The name of this Trash, any string.
	Height	2							// How tall is the trash?  Must be an integer > 0.
	MinoList							// A list of minos in the trash.  We need coords and type.
	{									// For each coordinate pair, X < Height (trash height) and
		"Mino0" (0,0)					// Y < well width.
		"Mino0" (0,1)
		"Mino0" (0,2)
		"Mino1" (1,2)
	}
}

// A Level section contains script and trash info for a single level.  Levels are OPTIONAL, but you
// may define any number of them as long as each has a unique Name among Levels.  Note that Levels
// will be used in the order that you define them here, no matter what the name.
Level
{
	Name				"Level #1"	// The name of this Level, any string.
	LevelTrash			"Trash0"	// OPTIONAL: What Trash should be inserted at level start?
	LevelStartScript	{}			// OPTIONAL: Execute this script at level start.
	LevelEndScript		{}			// OPTIONAL: Execute this script at level end.
}

// All info for the Generation Phase.  Mandatory, only one instance of this section.
GenerationPhase
{
	GenerationTime			1		// Generation time in seconds, expression OK.
	PieceStartingLocation	(0,0)	// Where is a new piece placed on the playfield?
	GenerationBeginScript	{}		// OPTIONAL: Begin phase script.
	GenerationEndScript		{}		// OPTIONAL: End phase script.
}

// All info for the Falling Phase.  Mandatory, only one instance of this section.
FallingPhase
{
	PiecesFallSmoothly				// OPTIONAL: If set, pieces fall smoothly (visually).
	FallSpeed				1		// Normal fall speed in sec/line, expression OK
	SoftDropSpeed			1		// Soft drop speed in sec/line, expression OK
	HardDropSpeed			1		// Hard drop speed in sec/line, expression OK
	MoveTolerance			0		// Expression OK, not currently in use!
	FallingBeginScript		{}		// OPTIONAL: Begin phase script.
	FallingEndScript		{}		// OPTIONAL: End phase script.
}

// All info for the Lock Phase.  Mandatory, only one instance of this section.
LockPhase
{
	MovementRestartsClock			// OPTIONAL: Set this flag to restart the lock phase
									// if the active piece moves.
	Duration				5		// Seconds before lockdown occurs, expression OK
	LockBeginScript			{}		// OPTIONAL: Begin phase script.
	LockEndScript			{}		// OPTIONAL: End phase script.
}

// All info for the Pattern Phase.  Mandatory, only one instance of this section.
PatternPhase
{
	PatternBeginScript		{}		// OPTIONAL: Begin phase script.
	PatternEndScript		{}		// OPTIONAL: End phase script.
}

// All info for the Iterate Phase.  Mandatory, only one instance of this section.
IteratePhase
{
	IterateBeginScript		{}		// OPTIONAL: Begin phase script.
	PrimaryIterator					// OPTIONAL: Defines the primary iterator.
	{
		IteratorExpression	pf.d1	// OPTIONAL: If this expression exists, it must evaluate
									// to non-zero in order to execute this iterator.
		IteratorTags		0,1,2,3	// OPTIONAL: Only Minos that match this tag list are iterated.
		MinoIteratorScript	{}		// The iteration script run for each matching Mino.
	}
	SecondaryIterator				// OPTIONAL: Defines the secondary iterator.
	{
		IteratorExpression	3
		IteratorTags		0,1,2,3
		MinoIteratorScript	{}
	}
	IterateEndScript		{}		// OPTIONAL: End phase script.
}

// All info for the Eliminate Phase.  Mandatory, only one instance of this section.
EliminatePhase
{
	FallSpeed				1		// Seconds per line, expression OK
	DontCollapseEmptyLines			// OPTIONAL: If this tag is set, empty lines will not be collapsed.
	EliminateBeginScript	{}		// OPTIONAL: Begin phase script.
	LineCollapsedScript		{}		// OPTIONAL: Execute this script after a line is collapsed.
	StartFallingScript		{}		// OPTIONAL: Executed when pieces start falling due to a line collapse.
	GroupLandedScript		{}		// OPTIONAL: Fired when a group of pieces lands.
	EliminateEndScript		{}		// OPTIONAL: End phase script.
}

// All info for the Solidify Phase.  Mandatory, only one instance of this section.
SolidifyPhase
{
	IteratorTags			0,1,2	// OPTIONAL: The MinoIteratorScript will be executed for each mino
									// with a tag that is in this list.  If you leave out IteratorTags,
									// the script will be run on ALL minos.
	SolidifyBeginScript		{}		// OPTIONAL: Begin phase script.
	MinoIteratorScript		{}		// OPTIONAL: This script is run on each Mino that matches the
									// IteratorTags (or all Minos if IteratorTags does not exist).
	SolidifyEndScript		{}		// OPTIONAL: End phase script.
}

// All info for the Gravity Phase.  Mandatory, only one instance of this section.
GravityPhase
{
	GravityEnabled					// OPTIONAL: Set this flag to turn gravity on by default.
	FallSpeed				1.0		// Seconds per line, expression OK.
	GravityBeginScript		{}		// OPTIONAL: Begin phase script.
	GroupLandedScript		{}		// OPTIONAL: Fired when a group of pieces lands.
	GravityEndScript		{}		// OPTIONAL: End phase script.
}

// All info for the Completion Phase.  Mandatory, only one instance of this section.
CompletionPhase
{
	CompletionBeginScript	{}		// OPTIONAL: Begin phase script.
	CompletionEndScript		{}		// OPTIONAL: End phase script.
}

// This section contains a number of scripts that are executed when certain events occur on the
// active piece.  All scripts are optional (though the EventScripts section itself is not), and
// scripts may appear in any order within the section.  The name of each script should be self-
// explanatory.
EventScripts
{
	GameStartScript			{}
	MinosPushedOffTopScript	{}
	LevelStartScript		{}
	LevelEndScript			{}
	PieceGenerationScript	{}
	MoveSuccessfulScript	{}
	MoveFailedScript		{}
	RotateSuccessfulScript	{}
	RotateFailedScript		{}
	HardDropStartScript		{}
	HardDropStepScript		{}
	SoftDropStartScript		{}
	SoftDropStepScript		{}
	FallStepScript			{}
	TouchdownScript			{}
	LockdownScript			{}
	GameSecondScript		{}
	LevelSecondScript
	{
		* this is a comment

		score level+5
		kill mino

		if playfield.d1 = 0
			if phase.d1 = 2
				exit
			end
			next level
			game win
			reset bag "tetramino0"
		end

		set playfield.d2 to phase.d0

		if phase.d0 = 1
			score level+2
			game lose
		else
			set phase.d0 to phase.d0 + 1
			kill mino
			set bag "tetramino0" to 0
			set playfield.d0 to playfield.d0 + 1
		end

		reset bag "tetramino0"
		send "BigGarbage"
		game win
	}

	// I've used the last script to show you what a run-time script looks like.  This isn't a
	// real script that you would use, and it probably doesn't do anything useful, it just shows
	// script syntax.  For a complete listing of all commands that are available, start with the
	// Tetrion Editor documentation.  Note the following differences apply when writing run-time
	// scripts in the TWS format:
	//
	// - All strings (e.g. names) must be quoted.
	// - C++ style comments (such as this one) or *-type comments may be used anywhere in the file,
	//   not just within run-time scripts.
	// - All run-time script commands as listed in version 2.0d58 (4/27/01) of the Editor document
	//   have been implemented with the following exceptions: HEIGHT, TOUCH, PHASE TIME, ITERATE,
	//   MINO.MARK, MINO.MARK2, MINO.FRESH, MINO.ID, SET MINO USING STICKY, SET MINO USING "shape",
	//   KILL MINO USING STICKY, KILL MINO USING "shape", MARK MINO USING STICKY, MARK MINO USING
	//   "shape", MARK MINO2 USING STICKY, MARK MINO2 USING "shape", SET BAG, RESET BAG.  I will
	//   implement these as time permits and on an as-needed basis.
	// - I have added the following run-time script commands to the TWS format:
	//     stop sound "name"	-	If the named sound is playing, this command stops it.
	//     stop all sounds		-	Stop all currently playing sounds.
	//     preload sound "name"	-	Preload the named sound, but don't start playing it.
	//     unload sound "name"	-	Unload the named sound, let it finish playing if needed.
	//     unload all sounds	-	Unload all preloaded sounds.
	//     mino mood <exp>		-	Set the mino character mood to the value of the expression.
	//     mino intensity X		-	Set the mino character intensity to X ("low", "medium" or "high").
	//     trace "string"		-	Print any string to the debug output.
	//     trace <exp> "string"	-	Print the value of the given expression, followed by the string,
	//								to debug output.
}

// The CustomEvent section contains (you guessed it) a custom game event.  This section is OPTIONAL,
// but you may define as many custom events as you like, provided each has a name unique among custom
// events.
CustomEvent
{
	Name		"BigGarbage"			// What is the name of the custom event?
	TriggerType	GameTime	30			// Custom events can be triggered in three ways:
										// Manual - fires by manual trigger only
										// GameTime <exp> - fires once when the game time equals the expression
										// LevelTime <exp> - fires once when the level time equals the expression
	Script								// This is the script triggered when the event occurs.
	{
		mix garbage 3*level
	}
}
