Strict

Import GameStub.PieceWise

ChangeDir ( "media\adventure\" )

Local StartPieces#, FinishPieces#
Local StartSpeed#, FinishSpeed#
Local StartQuota#, FinishQuota#

Print "Tweak adventure mode values. 'My value' refers to the hard version"
Print "where nobody could get past level 4 :)"

Print "'start' is the value for temple 1."
Print "'finish' is the value for temple 10."

Print 

Print "Limitations - currently you can't define the occurance of on fire"
Print "pieces, poisoned pieces etc. You also can't interpolate through"
Print "the levels of a temple to ramp the difficulty between level 1"
Print "through 5. To do this (currently), you have to edit the"
Print "media\adventure\ files by hand. I'll address these soon.  Use this"
Print "program to find a set of rough estimates."

Print

Print "Pieces are the number of pieces to use on the game board"

Print

StartPieces = Int( Input( "Start Pieces (my value was 3)" ) )
FinishPieces = Int( Input( "Finish Pieces (my value was 6 which is the max)" ) )

Print 

Print "Speed is the time in seconds it takes for the line to move down"
Print "Actual speed this varies greatly depending on how close to dying"
Print "the player is, so this is a kind of multiplier"

Print

StartSpeed = Float( Input( "Start speed (my value was 5)" ) )
FinishSpeed = Float( Input( "Finish speed (my value was 2)" ) )

Print

Print "Quota is the number of pieces you need to pop to finish the level"

Print

StartQuota = Int( Input( "Start quota (my value was 100)" ) )
FinishQuota = Int( Input( "Finish quota (my value was 300)" ) )

 
Global Pieces:TPieceWiseFunction = TPieceWiseFunction.CreateFromArray( ..
	[[ 0.0, StartPieces ], [ 8.0, FinishPieces ]] )
	
Global Speed:TPieceWiseFunction = TPieceWiseFunction.CreateFromArray( ..
	[[ 0.0, StartSpeed ], [ 8.0, FinishSpeed ]] )
	
Global Quota:TPieceWiseFunction = TPieceWiseFunction.CreateFromArray( ..
	[[ 0.0, StartQuota ], [ 8.0, FinishQuota ]] )

Local Files:TStream[ 10 ]
Local Settings:TList[ 10 ]

Type Setting

	Field Name$
	Field Value$
	
End Type

For Local Count = 0 Until 10

	Files[ Count ] = ReadFile( Int( Count + 1 ) + ".txt" )
	Settings[ Count ] = New TList
	
	While Not Eof( Files[ Count ] )
		
		Local ln$[] = Parse( ReadLine( Files[ Count ] ), "=" )
		
		Local s:Setting = New Setting
		s.Name = Trim( ln[ 1 ] )
		s.Value = Trim( ln[ 2 ] )
		
		If ( s.Name <> "" ) And ( s.Value <> "" )
		
			Settings[ Count ].AddLast( s )
		
		EndIf
		
	Wend	
	
	CloseFile( Files[ Count ] )
	
Next

For Local Count = 0 Until 10

	Files[ Count ] = WriteFile( Int( Count + 1 ) + ".txt" ) 
	
	For Local s:Setting = EachIn Settings[ Count ]
	
		Select Lower( s.Name )
		
			Case "speed", "maxpiece", "quota"
				
				
							
			Default
				
				WriteLine Files[ Count ], s.Name + " = " + s.Value
				
		End Select
		
	Next
	
	WriteLine Files[ Count ], "MaxPiece = " + Int( Pieces.InterpolateLinearly( Count ) ) + "," + Int( Pieces.InterpolateLinearly( Count ) )
	WriteLine Files[ Count ], "Speed = " + Int( Speed.InterpolateLinearly( Count ) ) + "," + Int( Speed.InterpolateLinearly( Count ) )
	WriteLine Files[ Count ], "Quota = " + Int( Quota.InterpolateLinearly( Count ) ) + "," + Int( Quota.InterpolateLinearly( Count ) )
	
			
Next

Function Parse$[]( In$, Separator$ = "," )

	Local Loop
	Local Count = 1
	Local Out$[ 128 ]
	
	For Loop = 1 To Len( In$ )
	
		If Mid$( In$, Loop, 1 ) = Separator$
		
			Out$[ Count ] = Trim$( Out$[ Count ] )
			
			If Not ( Out$[ Count ] = "" And Separator$ = "" )
			
				Count:+1
		
			EndIf
			
		Else
		
			Out$[ Count ]:+Mid$( In$, Loop, 1 )
			
		EndIf
	
	Next
	
	Return Out$[ 0..Count+1 ]

End Function
