'Power Play (Bally 1977)
'Recreated by Kinsey and RipleYYY
'WIP Began September 24, 2001
'Current Revision: March 25, 2002
'Version 2.2
'
'Version 2.2 Info
'  Finally Have Pop Bumpers Properly Scripted.
'  Tweaked the outlanes to proper settings. You'll notice a hell of a lot less ball drains.
'  Tweaked the Slingshot settings by the flippers.
'  Better samples for StarGame and EndGame sounds.
'  Lane rollovers 100 points CON, 1000 Liberal, as per official rules.
'  Tweaked Slingshots behind the drop targets.
'  LIBERAL setting to allow for Extra Ball to be lit on 5x, as per rules.
'  Added other operator settings as outlined in the manual.
'      Added Special Mode (Replay, Extra Ball and Novelty for Specials)
'      Modify Replay Values for 3/5 Balls relating to standard settings.
'      Match ON or OFF setting. 

'Version 2.1 Info
'  Added Decals to the Drop Targets.
'  Added Front and Back Decals to the ball so it spins.
'  Modified Script for New Security Features
'    Save/Load Routines to use SaveValue and LoadValue. (Old Values will be lost.)
'    External Script now supports the new GetTextFile command.
'  New Display Game Stats Feature, available in the Operator Menu.
'    So that you can easily view the game stats. :)
'
'Version 2.0 Info
'  New Playfield pic - thanks to Plumb for finding, Stein for giving it some love. (vpt)
'  Tweaked some elasticity settings for the new playfield (vpt)
'  Adjusted text on the backglass for version and thanks info. (vpt)
'  Tweaked kicker angle for new playfield pic/design layout (script)
'  Adjusted tilt mechanism again (script)
'  Fixed the date for the original table release to 1977 (script)
'
'Version 1.0 Info
'  Adjusted the bonus countdown sound and delay (vpt)
'  Added text to multiplier lights.(vpt)
'  Adjusted tilt mechanism.(script)
'  Added replay and rule card jpgs to zip.
'  Added Williams Pinball font to zip.
'
'Operator Menu
'
' Game Saves settings after a successful game, and will reload those
'   settings when you restart it.
'
' TAB - Opens Operator Menu
'   7 - Turns Match On and Off.
'   8 - Modify Replays
'   9 - 3 or 5 Balls Per Game
'   0 - Conservative or Liberal
'   P - Switch between Replay Special, Extra Ball Special, and Novelty Special
'   S - Save Game Settings now without playing.
'
' 3 Ball Game Awards Replays at a lower score than 5 Ball Game.
' Conservative resets BOTH target banks when one is cleared, as
'   well as alternating outlane special.
' Liberal resets only cleared target bank, and lights BOTH outlane specials.
'
'Defaults to 5 ball conservative game.
'
'Default High Score is 570,000 (It is the recommended setting.)
'  But it will save your high score. Score supports millions digit, original did not. Game
'  rolls over at 10,000,000 due to the limitation of the AddCommas routine.
'
'
'Cheats
'
' There's One, but you'll have to read the script to find it.

Dim CurrentBall, Credits, NumBalls, PlayScore, MatchNumber, Bonuses
Dim Conservative, LowBalls, Tilting, Tilted, Replay(2)
Dim FreeGames, NoScoring, BallBonus, BonusHolder, Multiplier
Dim NumPlays, HighScore, GameIsOver, BeatHS, ShowHS
Dim SpecialType, AllowMatch

Function FmtScore(value)
   FmtScore = FormatNumber(value,0,-1,0,-1)
End Function

Function AddCommas(number)
'Adds commas to a number using the Williams Pinball font.
'Changes the 4th and 7th chars to the commaed versions, asc 192+
'Giving credit to Joe Entropy for this. Not sure he did it first or not,
'  But I got it from the Frontier table by him and RipleYYY (-Kinsey)
	dim s
	
	s = CStr(number)
	if Len(s) = 4 then
		s = Chr(Asc(Mid(s, 1, 1)) + 144) & Right(s, 3)
	elseif Len(s) > 4 then
		s = Left(s, Len(s)-4) & Chr(Asc(Mid(s, Len(s)-3, 1)) + 144)_
					 & Right(s, 3)
		if Len(s) = 7 then
			s = Chr(Asc(Mid(s, 1, 1)) + 144) & Right(s, 6)
		elseif Len(s) > 7 then
			s = Left(s, Len(s)-7) & Chr(Asc(Mid(s, 7, 1)) + 144)_
						 & Right(s, 6)
		end if
	end if
	AddCommas = s
End Function


Sub AddScore(nPoints)
    'If the table is tilted, score is NOT added.
    'If No scoring elementals are hit, ball is returned to player, but
    '   Not if the ball is tilted. :)
    NoScoring = 1
    If Tilted = 1 then exit sub
       PlayScore = PlayScore + nPoints
       'Table turns over at 10 million. As per original.
       If PlayScore > 10000000 then PlayScore = PlayScore - 10000000
       If PlayScore > Replay(1) and FreeGames = 0 then AddFreeGame()
       If PlayScore > Replay(2) and FreeGames = 1 then AddFreeGame()
       Score.Text = AddCommas(PlayScore)
End Sub

Sub DisplayScore()
    If CurrentBall = 0 and ShowHS = 1 then
       Hstimer.Enabled = True
       Score.Text = AddCommas(HighScore)
       HighBox.Text = "HIGH"
       kinseylight.state = 0
    End If
    If CurrentBall = 0 and ShowHS = 0 then
       Hstimer.enabled = true
       Score.Text = AddCommas(PlayScore)
       HighBox.Text = ""
       kinseylight.state = 1
    End If
    If CurrentBall > 0 then
    Score.Text = AddCommas(PlayScore)
    kinseylight.state = 1
    End If
End Sub

Sub AddFreeGame()
    'May add something later, so making it a unique sub.
    If FreeGames = 1 then FreeGames = 2
    If FreeGames = 0 then FreeGames = 1
    ReplaySpecial()
End Sub

Sub AddBonus()
    If Tilted = 1 then exit sub
    'Control Bonus Lights in this Routine.
   ' PlaySound "bell100"
    If b1k.state = 0 then 
       b1k.state = 1
       BallBonus = BallBonus + 1
       PlaySound "bell100"
       exit sub
    End If
    If b9k.state = 1 and b10k.state = 0 and b20k.state = 1 then 
       PlaySound "bell100":exit sub
    Else
       'PlaySound "bell100"
    End If
    
    If b9k.state = 1 and b10k.state = 1 and b20k.state = 0 then
       b20k.state = 1:b10k.state = 0:b9k.state = 0:b8k.state = 0:b7k.state = 0:b6k.state = 0:b5k.state = 0:b4k.state = 0:b3k.state = 0:b2k.state = 0:b1k.state = 0
    End If
    If b9k.state = 1 and b10k.state = 0 and b20k.state = 0 then
       b10k.state = 1:b9k.state = 0:b8k.state = 0:b7k.state = 0:b6k.state = 0:b5k.state = 0:b4k.state = 0:b3k.state = 0:b2k.state = 0:b1k.state = 0
    End If
    If b8k.state = 1 and b9k.state = 0 then b9k.state = 1
    If b7k.state = 1 and b8k.state = 0 then b8k.state = 1
    if b6k.state = 1 and b7k.state = 0 then b7k.state = 1
    If b5k.state = 1 and b6k.state = 0 then b6k.state = 1
    If b4k.state = 1 and b5k.state = 0 then b5k.state = 1
    If b3k.state = 1 and b4k.state = 0 then b4k.state = 1
    If b2k.state = 1 and b3k.state = 0 then b3k.state = 1
    If b1k.state = 1 and b2k.state = 0 then b2k.state = 1
    BallBonus = BallBonus + 1
    PlaySound "bell100"

End Sub

Sub AwardBonus()
    If ExtraBall.state = 0 or Tilted = 1 then CurrentBall = CurrentBall + 1
    If Tilted = 1 then
       If CurrentBall < (NumBalls + 1) then
       If GameIsOver = 0 Then
          NewBallKick.TimerInterval = 1000
          NewBallKick.TimerEnabled = True
          Exit Sub
         End If
       End If

    End If
    If Bonus2x.state = 1 then Multiplier = 2
    If Bonus3x.state = 1 then Multiplier = 3
    If Bonus5x.state = 1 then Multiplier = 5
    BonusHolder = BallBonus
    BonusTimer.Enabled = True
End Sub

Sub BonusTimer_Timer()
   
   If BallBonus > 0 then
      BonusCountDown()
      BonusTimer.Enabled = True

     Else

    If Multiplier > 1 then
       Multiplier = Multiplier - 1:BallBonus = BonusHolder:BonusTimer.Enabled = True
       Else
         If CurrentBall < (NumBalls+1) then
        BonusTimer.Enabled = False
        If GameIsOver = 0 Then
             NewBallKick.TimerInterval = 1000:NewBallKick.TimerEnabled = True
        End If
          Else
          GameOver()
          End If
      End If

  End If

End Sub    

Sub BonusCountDown()
    '29 states for the bonus.
    AddScore 1000:PlaySound "bell10":BallBonus = BallBonus - 1
    Select Case BallBonus
    Case 1
       b1k.state = 1:b2k.state = 0:b3k.state = 0:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 0
    Case 2
       b1k.state = 1:b2k.state = 1:b3k.state = 0:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 0
    Case 3
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 0
    Case 4
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 0
    Case 5
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 0
    Case 6
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 0
    Case 7
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 1:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 0
    Case 8
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 1:b8k.state = 1:b9k.state = 0:b10k.state = 0:b20k.state = 0
    Case 9
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 1:b8k.state = 1:b9k.state = 1:b10k.state = 0:b20k.state = 0
    Case 10
       b1k.state = 0:b2k.state = 0:b3k.state = 0:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 1:b20k.state = 0
    Case 11
       b1k.state = 1:b2k.state = 0:b3k.state = 0:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 1:b20k.state = 0
    Case 12
       b1k.state = 1:b2k.state = 1:b3k.state = 0:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 1:b20k.state = 0
    Case 13
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 1:b20k.state = 0
    Case 14
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 1:b20k.state = 0
    Case 15
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 1:b20k.state = 0
    Case 16
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 1:b20k.state = 0
    Case 17
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 1:b8k.state = 0:b9k.state = 0:b10k.state = 1:b20k.state = 0
    Case 18
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 1:b8k.state = 1:b9k.state = 0:b10k.state = 1:b20k.state = 0
    Case 19
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 1:b8k.state = 1:b9k.state = 1:b10k.state = 1:b20k.state = 0
    Case 20
       b1k.state = 0:b2k.state = 0:b3k.state = 0:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 1
    Case 21
       b1k.state = 1:b2k.state = 0:b3k.state = 0:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 1
    Case 22
       b1k.state = 1:b2k.state = 1:b3k.state = 0:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 1
    Case 23
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 1
    Case 24
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 1
    Case 25
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 1
    Case 26
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 1
    Case 27
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 1:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 1
    Case 28
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 1:b8k.state = 1:b9k.state = 0:b10k.state = 0:b20k.state = 1
    Case 29
       b1k.state = 1:b2k.state = 1:b3k.state = 1:b4k.state = 1:b5k.state = 1:b6k.state = 1:b7k.state = 1:b8k.state = 1:b9k.state = 1:b10k.state = 0:b20k.state = 1
    End Select
End Sub

Sub DisplayBall()
    BallBox.Text = CurrentBall
End Sub

Sub AddCredit()
    If CurrentBall = 0 then PlaySound "coindrop"
    If CurrentBall > 0 then PlaySound "knocker"
    Credits = Credits + 1
    DisplayCredits()
End Sub

Sub DisplayCredits()
    If Credits > 0 then Lightcredit.state = 1
    If Credits = 0 then Lightcredit.state = 0
    If Credits < 10 then
       CreditBox.Text = "0"&Credits
    End If
    If Credits = 0 then
       CreditBox.Text = "00"
    End If
    If Credits > 9 and Credits < 41 then
       CreditBox.Text = Credits
    End If
    If Credits > 40 then
       Credits = 40
       CreditBox.Text = Credits
    End If
End Sub

Sub ReplaySpecial()
    If SpecialType = 0 then
       AddCredit():exit sub
    End If
    If SpecialType = 1 then
       LightExtraBall():exit sub
    End If        
End Sub

Sub OutlaneSpecial()
    If SpecialType = 0 then 
       PlaySound "knocker"
       AddCredit()
       Exit Sub
    End If
    If SpecialType = 1 then
       LightExtraBall()
       Exit Sub
    End If
    If SpecialType = 2 then
       AddScore 50000
       exit sub
    End If
End Sub

Sub DTSpecial()
    If SpecialType = 0 then
       PlaySound "knocker"
       AddCredit()
       Exit Sub
    End If
    If SpecialType = 1 or SpecialType = 2 then
       AddScore 50000
       exit sub
    End If
End Sub

Sub Gate1_Hit()
    PlaySound "gate"
End Sub

Sub ModifyReplays()
    If NumBalls = 3 then
       If Replay(1) = 170000 then
          Replay(1) = 190000:Replay(2) = 360000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 190000 then
          Replay(1) = 210000:Replay(2) = 380000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 210000 then 
          Replay(1) = 230000:Replay(2) = 400000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 230000 then
          Replay(1) = 250000:Replay(2) = 420000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 250000 then
          Replay(1) = 270000:Replay(2) = 440000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 270000 then
          Replay(1) = 170000:Replay(2) = 340000:ShowReplayBox():exit sub
       End If
    End If
    If NumBalls = 5 then
       If Replay(1) = 290000 then
          Replay(1) = 310000:Replay(2) = 470000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 310000 then
          Replay(1) = 330000:Replay(2) = 490000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 330000 then
          Replay(1) = 350000:Replay(2) = 510000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 350000 then
          Replay(1) = 370000:Replay(2) = 530000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 370000 then
          Replay(1) = 390000:Replay(2) = 550000:ShowReplayBox():exit sub
       End If
       If Replay(1) = 390000 then
          Replay(1) = 290000:Replay(2) = 460000:ShowReplayBox():exit sub
       End If
   End If
End Sub
       
     
Sub ShowReplayBox()
    If NumBalls = 3 then
       MsgBox "          Power Play       " & chr(13) & chr(13) & "       3 Ball Replays      " & chr(13) & Replay(1) & " and " & Replay(2)
    Else
       MsgBox "          Power Play       " & chr(13) & chr(13) & "       5 Ball Replays      " & chr(13) & Replay(1) & " and " & Replay(2)
    End If
End Sub

Sub SwitchSpecialType()
    If SpecialType = 0 then
       SpecialType = 1
       MsgBox "          Power Play       " & chr(13) & chr(13) & "  Extra Ball Special Mode  "
       exit sub
    End If
    If SpecialType = 1 then
       SpecialType = 2
       MsgBox "          Power Play       " & chr(13) & chr(13) & "    Novelty Special Mode   "
       exit sub
    End If
    If SpecialType = 2 then
       SpecialType = 0
       MsgBox "          Power Play       " & chr(13) & chr(13) & "     Replay Special Mode   "
       exit sub
    End If
End Sub
       

Sub StartGame()
    GameIsOver = 0:Credits = Credits - 1:DisplayCredits()
    CurrentBall = 1:LowerPost():PlayScore = 0:DisplayScore():FreeGames = 0
    'Default to 5 ball replay rules.
    Hstimer.enabled = false
    HighBox.text = ""
    BallBox.Text = CurrentBall:PlaySound "startgame"
    NewBallKick.TimerInterval = 1000:NewBallKick.TimerEnabled = True
    If Conservative = 0 then Bumper1.state=1:Bumper2.state=1:Bumper3.state=1
    If Conservative = 1 then Bumper1.state=0:Bumper2.state=1:Bumper3.state=1
End Sub

Sub Powerplay_Init()
    LoadHS()
    If HighScore = "" or HighScore = 0 then HighScore = 570000
    If Conservative = "" then Conservative = 1
    If NumPlays = "" then NumPlays = 0
    If Credits = "" then Credits = 0
    If NumBalls = 0 then NumBalls = 5
    If SpecialType = "" then SpecialType = 0
    If AllowMatch = "" then AllowMatch = 1
    'Plenty of Legit Values for these. I chose the happy middle. :) Feel free to change the default.
        ' Legit Settings for 3 Ball Replays
        ' 170/340, 190/360, 210/380, 230/400, 250/420, 270/440
        ' Legit Settings for 5 ball Replays
    ' 290/460, 310/470, 330/490, 350/510, 370/530, 390/550, 
    If Replay(1) = 0 and NumBalls = 5 then 
            Replay(1) = 350000
            Replay(2) = 510000
        End If        
        If Replay(1) = 0 and NumBalls = 3 then 
            Replay(1) = 230000
            Replay(2) = 400000
    End If
    PlayScore = 0:CurrentBall = 0:DisplayCredits():BallBox.Text = "00":LowerPost()
    Hstimer.enabled = True
    
End Sub

Sub Match()
	Randomize
	MatchNumber = (Int(Rnd(5) * 10)) * 10
	Call Matchdisplay()
	If MatchNumber = (PlayScore Mod 100)Then
			Credits=Credits+1
			PlaySound "Knocker"
			Call DisplayCredits()
		End If	
End Sub

Sub MatchDisplay()
	If MatchNumber = 0 Then
		BallBox.Text = "00"
	else	
	BallBox.Text = MatchNumber
	
	End If
	
End Sub

Sub AddTilt()
    Tilting = Tilting + 1
    If Tilting > 3 then 
       LightTilt()
    End If
    TiltTimer.Interval = 1000
    TiltTimer.Enabled = True
End Sub

Sub TiltTimer_Timer()
    Tilting = Tilting - 1
    If Tilting < 0 then Tilting = 0
    If Tilting > 0 then 
       TiltTimer.Enabled = True
       Else
       TiltTimer.Enabled = False
    End If
End Sub

Sub LightTilt()
    Tilted = 1:NoScoring = 1:TiltBox.Text = "TILT":BallBonus = 0
    RightFlipper.RotateToStart:LeftFlipper.RotateToStart:RSlapFlip.RotateToStart:LSlapFlip.RotateToStart
    LowerPost()
End Sub    
    
Sub Powerplay_KeyDown(ByVal keycode)
    
    If keycode = PlungerKey Then
	   If CurrentBall > 0 then
	   	Plunger.PullBack
	   End If
	End If

    If Tilted = 1 then exit sub

	If keycode = LeftFlipperKey Then
	   If CurrentBall > 0 then
		LeftFlipper.RotateToEnd:LSlapFlip.RotateToEnd:PlaySound "FlipperUp"
	   End If
	End If
    
	If keycode = RightFlipperKey Then
		If CurrentBall > 0 then
		  RightFlipper.RotateToEnd:RSlapFlip.RotateToEnd:PlaySound "FlipperUp"
		End If
	End If
    
	If keycode = LeftTiltKey Then
	   If CurrentBall > 0 then
	   	Nudge 90, 3:AddTilt()
	   End If
	End If
    
	If keycode = RightTiltKey Then
	   If CurrentBall > 0 then
		Nudge 270, 3:AddTilt()
	   End If
	End If
    
	If keycode = CenterTiltKey Then
	   If CurrentBall > 0 then
		Nudge 0, 3:AddTilt()
	   End If
	End If
	
	If keycode = 15 then
	   If CurrentBall > 0 then
	        Nudge 45, 12
	        AddTilt():AddTilt():AddTilt()
	   End If
	End If
    
End Sub

Sub Powerplay_KeyUp(ByVal keycode)
    
	If keycode = PlungerKey Then
	   if CurrentBall > 0 then
		Plunger.Fire:PlaySound "plungeball"
	   End If
	End If
    
    If Tilted = 1 then exit sub

	If keycode = LeftFlipperKey Then
	   if CurrentBall > 0 then
		LeftFlipper.RotateToStart:LSlapFlip.RotateToStart:PlaySound "FlipperDown"
	   End If
	End If
    
	If keycode = RightFlipperKey Then
	   If CurrentBall > 0 then
		RightFlipper.RotateToStart:RSlapFlip.RotateToStart:PlaySound "FlipperDown"
       End If
	End If

    If keycode = AddCreditKey then
       If CurrentBall = 0 then AddCredit()
    End If
    
    if keycode = StartGameKey then
       If CurrentBall = 0 and Credits > 0 then StartGame()
    End If
    
    If keycode = 15 then
       If CurrentBall = 0 then
       MsgBox "          Power Play       " & chr(13) & chr(13) & "     Operator Controls     " & chr(13) & chr(13) & "7 : Match Toggle" & chr(13) & "8 : Modify Replay Settings" & chr(13) & "9 : Switch 3/5 Balls" & chr(13) & "0 : Liberal/Conservative" & chr(13) & "P : Switch Special Type" & chr(13) & "S - Save Settings (Without Playing a Game)" & chr(13) & chr(13) & "Power Play Game Stats" & chr(13) & chr(13) & "High Score: " & HighScore & chr(13) & "Credits: " & Credits & chr(13) & "Balls Per Game: " & NumBalls & chr(13) & "Liberal (0) /Conservative (1) :" & Conservative & chr(13) & "Special Type (1-Replay, 2-EB, 3-Novelty) : " & SpecialType & chr(13) & "Match Off(0)/On(1) : " & AllowMatch & chr(13) & "Games Played :" & NumPlays & chr(13) & "Replays at " & Replay(1) & " and " & Replay(2) & chr(13)
       End If
    End If
    
    If keycode = 8 then
       '7 - Match On/Off
       If CurrentBall = 0 then SwitchMatch()
    End If
    If keycode = 9 then
       '8 - Modify Replay Values
       If CurrentBall = 0 then ModifyReplays()
    End If
    
    If keycode = 11 then
       '0 Switches between Conservative and Liberal Mode
       If CurrentBall = 0 then SwitchDifficult()
    End If
    
    If keycode = 25 then
       'P switches between Replay, Extra Ball and Novelty Specials
       If CurrentBall = 0 then SwitchSpecialType()
    End If
    
    If keycode = 31 then
       'S - Saves Game Settings Now
       If CurrentBall = 0 then 
          savehs()
          MsgBox "          Power Play       " & chr(13) & chr(13) & "       Game Stats Saved    "
       End If
    End If
    
    If keycode = 10 then
       '9 Switches between 3 and 5 balls.
       If CurrentBall = 0 then SwitchBalls()
    End If
    
    
    if keycode = 48 then
       If CurrentBall > 1 then
          CurrentBall = CurrentBall - 1
          DisplayBall()
       End If
    End If
       
End Sub

Sub SwitchDifficult()
    If Conservative = 0 then
       Conservative = 1
       MsgBox "          Power Play       " & chr(13) & chr(13) & "Conservative Mode" & chr(13) & chr(13) & "1. Both Target Banks Advances Muliplier." & chr(13) & "2. Rotate Lane Specials." & chr(13) & "3. Rotate Pop Bumpers Lit." & chr(13) & "4. Lane rollovers score 100." & chr(13) & "5. Drop Target Extra Ball seperate."
    Else
       Conservative = 0
       MsgBox "          Power Play       " & chr(13) & chr(13) & "Liberal Mode" & chr(13) & chr(13) & "1. Single Target Bank Advances Multiplier." & chr(13) & "2. Light Both Lane Specials." & chr(13) & "3. Pop Bumpers Solid Lit." & chr(13) & "4. Lane rollovers score 1000." & chr(13) & "5. Drop Target Extra Ball liked to 5x."
    End If
End Sub

Sub SwitchBalls()
    If NumBalls = 5 then
       NumBalls = 3 : LowBalls = 1 : Replay(1) = 230000 : Replay(2) = 400000
       MsgBox "          Power Play       " & chr(13) & chr(13) & "3 Balls Per Game" & chr(13) & chr(13) & "Replays at " & Replay(1) & " and " & Replay(2)
    Else
       NumBalls = 5 : LowBalls = 0 : Replay(1) = 350000 : Replay(2) = 510000
       MsgBox "          Power Play       " & chr(13) & chr(13) & "5 Balls Per Game" & chr(13) & chr(13) & "Replays at " & Replay(1) & " and " & Replay(2)
    End If
End Sub

Sub SwitchMatch()
    If AllowMatch = 0 then
       AllowMatch = 1
       MsgBox "          Power Play       " & chr(13) & chr(13) & "    Match Routine Enabled  "
       exit sub
    End If
    If AllowMatch = 1 then
       AllowMatch = 0
       MsgBox "          Power Play       " & chr(13) & chr(13) & "    Match Routine Disabled "
       exit sub
    End If
End Sub

Sub Drain_Hit()
 Drain.DestroyBall
   If NoScoring = 0 and Tilted = 0 then
   If GameIsOver = 0 Then
      NewBallKick.TimerInterval = 1000 : NewBallKick.TimerEnabled = True : NoScoring = 0
      'Return Ball if No scoring elements hit
      Exit Sub
 End If
End If
LowerPost()
AwardBonus()
End Sub

Sub GameOver()
    CurrentBall = 0:GameIsOver = 1:RightFlipper.RotateToStart:RSlapFlip.RotateToStart
    LeftFlipper.RotateToStart:LSlapFlip.RotateToStart:PlaySound "endgame"
    If AllowMatch = 1 then
       Call Match()
    Else
       BallBox.text = "00"
    End If
    NumPlays = NumPlays + 1
    If PlayScore > HighScore then 
       HighScore = PlayScore:Credits = Credits + 3:DisplayCredits():PlaySound "knock3"
    End If
    SaveHS()
    Hstimer.enabled = true
    ResetPlayfield()
    LightAttract()
End Sub

Sub LightAttract()
    kickerlight1.state=2:kickerlight2.state=2:kickerlight3.state=2:kickerlight4.state=2:kickerlight5.state=2
    lightx2.state=2:lightx3.state=2:lightx5.state=2:eblight.state=2:splight.state=2
    b1k.state=2:b2k.state=2:b3k.state=2:b4k.state=2:b5k.state=2:b6k.state=2:b7k.state=2:b8k.state=2:b9k.state=2:b10k.state=2:b20k.state=2
    loutspec.state=2:routspec.state=2:bonus2x.state=2:bonus3x.state=2:bonus5x.state=2:extraball.state=2
    leftlanelight1.state=2:leftlanelight2.state=2:leftlanelight3.state=2
    rightlanelight1.state=2:rightlanelight2.state=2:rightlanelight3.state=2
End Sub

Sub Hstimer_timer()
    If ShowHS = 0 then
       hstimer.enabled = false
       ShowHS = 1
       DisplayScore()
    Else
       hstimer.enabled = false
       ShowHS = 0
       DisplayScore()
    End If
End Sub

Sub NewBallKick_Timer()
    ResetPlayfield():NoScoring = 0:BallBonus = 1:NewBallKick.CreateBall.Image = "pinball"
    DisplayBall():b1k.state = 1:PlaySound "kickout"
    NewBallKick.Kick 45, 5:NewBallKick.TimerEnabled = False
End Sub

'Kicker Control
Sub Kicker_Hit()
    CheckKickValue():Kicker.TimerInterval = 1750:Kicker.TimerEnabled = True
End Sub

Sub Kicker_Timer()
    Randomize
    'This is the TRUE kicker angle as verified with the VPM code.
    '  I would make this user modifiable within game, but that would be unrealistic.
    Kicker.kick cint(5*rnd)+165, 5:Kicker.TimerEnabled = False:PlaySound "kickout"
End Sub

Sub CheckKickValue()
    Bonuses = Bonuses + 3:Timer1.Enabled = True
    If KickerLight1.state = 1 and KickerLight2.state = 1 and KickerLight3.state = 1 and KickerLight4.state = 1 and KickerLight5.state = 1 then
       AddScore 15000
       If LOutSpec.state = 1 or ROutSpec.state = 1 then exit sub
       If Conservative = 1 then
          LOutSpec.state = 1
       Else
          LOutSpec.state = 1:ROutSpec.state = 1
       End If
    End If
    
    If KickerLight1.state = 1 and KickerLight2.state = 1 and KickerLight3.state = 1 and KickerLight4.state = 1 and KickerLight5.state = 0 then
       AddScore 12000:LightRight():KickerLight5.state = 1
    End If
    
    If KickerLight1.state = 1 and KickerLight2.state = 1 and KickerLight3.state = 1 and KickerLight4.state = 0 and KickerLight5.state = 0 then
       AddScore 9000:KickerLight4.state = 1
    End If
    
    If KickerLight1.state = 1 and KickerLight2.state = 1 and KickerLight3.state = 0 and KickerLight4.state = 0 and KickerLight5.state = 0 then
       AddScore 6000:LightLeft():KickerLight3.state = 1
    End If
    
    If KickerLight1.state = 1 and KickerLight2.state = 0 and KickerLight3.state = 0 and KickerLight4.state = 0 and KickerLight5.state = 0 then
       AddScore 3000:KickerLight2.state = 1
    End If
End Sub

Sub ResetKickerLights()
    KickerLight1.state = 1:KickerLight2.state = 0:KickerLight3.state = 0:KickerLight4.state = 0:KickerLight5.state = 0
End Sub

Sub LightRight()
    RightLaneLight1.state = 1:RightLaneLight2.state = 1:RightLaneLight3.state = 1
End Sub

Sub ResetRightLane()
    RightLaneLight1.state = 0:RightLaneLight2.state = 0:RightLaneLight3.state = 0
End Sub

Sub LightLeft()
    LeftLaneLight1.state = 1:LeftLaneLight2.state = 1:LeftLaneLight3.state = 1
End Sub

Sub ResetLeftLane()
    LeftLaneLight1.state = 0:LeftLaneLight2.state = 0:LeftLaneLight3.state = 0
End Sub

'Bumper Control
Sub Bumper1_Hit()
    Playsound "ding4":SpecSwitch()
    If Bumper1.state = 1 then
       AddScore 1000
    Else
       AddScore 100
    End If
    If Conservative = 1 then BumpSwitch()
End Sub

Sub Bumper2_Hit()
    Playsound "ding6":SpecSwitch()
    If Bumper2.state = 1 then
       AddScore 1000
    Else
       AddScore 100
    End If
    If Conservative = 1 then BumpSwitch()
End Sub

Sub Bumper3_Hit()
    Playsound "ding6":SpecSwitch()
    If Bumper3.state = 1 then
       AddScore 1000
    Else
       AddScore 100
    End If
    If Conservative = 1 then BumpSwitch
End Sub

Sub BumpSwitch()
    If Bumper1.state = 1 then
       Bumper1.state=0:Bumper2.state=1:Bumper3.state=1
       exit sub
    Else
       Bumper1.state=1:Bumper2.state=0:Bumper3.state=0
       exit Sub
    End If
End Sub

Sub LeftSlingshot_Slingshot()
	PlaySound "Bumper":SpecSwitch():AddScore 10
End Sub

Sub RightSlingshot_Slingshot()
	PlaySound "Bumper":SpecSwitch():AddScore 10
End Sub

Sub LeftWall_Slingshot()
    PlaySound "Bumper":SpecSwitch():AddScore 10
End Sub

Sub RightWall_Slingshot()
    PlaySound "Bumper":SpecSwitch():AddScore 10
End Sub

Sub OuterWall_Slingshot()
    PlaySound "Bumper":SpecSwitch():AddScore 50
End Sub

'Left Target Bank Control
Sub LeftBank1_Hit()
    LeftBank1.IsDropped = True:CheckLeftBank()
End Sub

Sub LeftBank2_Hit()
    LeftBank2.IsDropped = True:CheckLeftBank()
End Sub

Sub LeftBank3_Hit()
    LeftBank3.IsDropped = True:CheckLeftBank()
End Sub

Sub LeftBank4_Hit()
    LeftBank4.IsDropped = True:CheckLeftBank()
End Sub

Sub LeftBank4_Timer()
    LeftBank4.TimerEnabled = False:PlaySound "reset3":LeftBankReset():TargetBonus()
    If Conservative = 1 then RightBankReset()
End Sub

Sub CheckLeftBank()
    AddScore 300:PlaySound "dropbling"
    If LeftBank1.IsDropped and LeftBank2.IsDropped and LeftBank3.IsDropped and LeftBank4.Isdropped then
       LeftBank4.TimerInterval = 1000:LeftBank4.TimerEnabled = True
       Bonuses = Bonuses + 3:Timer1.Enabled = True
    End If
End Sub

Sub Timer1_Timer()
    AddBonus():Bonuses = Bonuses - 1
    If Bonuses > 0 then
       Timer1.Enabled = True
    Else
       Timer1.Enabled = False
    end If
End Sub
    

Sub LeftBankReset()
    LeftBank1.IsDropped = False:LeftBank2.IsDropped = False:LeftBank3.IsDropped = False:LeftBank4.IsDropped = False
End Sub

'Right Target Bank Control
Sub RightBank1_Hit()
    RightBank1.IsDropped = True:CheckRightBank()
End Sub

Sub RightBank2_Hit()
    RightBank2.IsDropped = True:CheckRightBank()
End Sub

Sub RightBank3_Hit()
    RightBank3.IsDropped = True:CheckRightBank()
End Sub

Sub RightBank4_Hit()
    RightBank4.IsDropped = True:CheckRightBank()
End Sub

Sub RightBank4_Timer()
    RightBank4.TimerEnabled = False:PlaySound "reset3":RightBankReset():TargetBonus()
    If Conservative = 1 then LeftBankReset()
End Sub

Sub CheckRightBank()
    AddScore 300:PlaySound "dropbling"
    If RightBank1.IsDropped and RightBank2.IsDropped and RightBank3.IsDropped and RightBank4.Isdropped then
       RightBank4.TimerInterval = 1000:RightBank4.TimerEnabled = True:Bonuses = Bonuses + 3:Timer1.Enabled = True
    End If
End Sub

Sub RightBankReset()
    RightBank1.IsDropped = False:RightBank2.IsDropped = False:RightBank3.IsDropped = False:RightBank4.IsDropped = False
End Sub

Sub TargetBonus()
    If SpLight.state = 1 then
       DTSpecial():exit sub
    End If
    If EBLight.state = 1 then
       If SpecialType = 0 or SpecialType = 1 then
          LightExtraBall():SpLight.state = 1:exit Sub
       End If
       If SpecialType = 2 then
          AddScore 50000:SpLight.state=1:exit sub
       End If
          
    End If
    If LightX5.state = 1 then
       If Conservative = 1 then
          Bonus5x.state = 1:EBLight.state = 1:exit sub
       Else
          If Conservative = 0 then 
             Bonus5x.state=1:EBLight.state=1
             If SpecialType = 0 or SpecialType = 1 then
                LightExtraBall():SpLight.state=1
             End If
             If SpecialType = 2 then
                AddScore 50000:SpLight.state=1
             End If
          Exit Sub
          End If
       End If
    End If
    If LightX3.state = 1 then
          Bonus3x.state = 1:LightX5.state = 1:exit sub
    End If
    If LightX2.state = 1 then
       Bonus2x.state = 1:LightX3.state = 1:exit sub
    End If
End Sub

Sub LightExtraBall()
    If ExtraBall.state = 1 then
       AddScore 50000
    End If
    ExtraBall.state = 1
End Sub

Sub ResetTargetLights()
    LightX2.state = 1:LightX3.state = 0:LightX5.state = 0:EBLight.state = 0:SPLight.state = 0
End Sub

Sub ResetMultiplierLights()
    Bonus2x.state = 0:Bonus3x.state = 0:Bonus5x.state = 0:ExtraBall.state = 0:Multiplier = 1
End Sub

Sub ResetBonusLights()
    b1k.state = 1:b2k.state = 0:b3k.state = 0:b4k.state = 0:b5k.state = 0:b6k.state = 0:b7k.state = 0:b8k.state = 0:b9k.state = 0:b10k.state = 0:b20k.state = 0
End Sub

Sub ResetPlayfield()
    RightBankReset():LeftBankReset():ResetKickerLights():ResetRightLane()
    ResetLeftLane():ResetBonusLights():ResetSpecialLanes():ResetTilt()
    ResetTargetLights():ResetMultiplierLights()
End Sub

Sub ResetTilt()
    Tilted = 0:Tilting = 0:TiltBox.Text = ""
End Sub

Sub RaisePost()
    If Tilted = 0 then Post.IsDropped = False
    
End Sub

Sub LowerPost()
    Post.IsDropped = True
End Sub

Sub MidTarg_Hit()
    RaisePost():AddBonus():AddScore 300:PlaySound "ding5"
End Sub

Sub KickerTrigger_Hit()
    RaisePost():AddBonus():SpecSwitch():AddScore 300
End Sub

Sub LeftInlane_Hit()
    LowerPost():SpecSwitch()::PlaySound "ding5":AddScore 300
End Sub

Sub RightInlane_Hit()
    LowerPost():SpecSwitch():PlaySound "ding5":AddScore 300
End Sub

Sub RightOutlane_Hit()
    PlaySound "Outlane":AddScore 1000
    If ROutSpec.state = 1 then OutlaneSpecial()
End Sub

Sub LeftOutlane_Hit()
    PlaySound "Outlane":AddScore 1000
    If LOutSpec.state = 1 then OutlaneSpecial()
End Sub

Sub SpecSwitch()
    If ROutSpec.state = 0 and LOutSpec.state = 0 then exit sub
    If ROutSpec.state = 1 and LOutSpec.state = 1 then exit sub 'Liberal Set
    If ROutSpec.state = 1 and LOutSpec.state = 0 then
       ROutSpec.state = 0:LOutSpec.state = 1:Exit Sub
    End If
    If LOutSpec.state = 1 and ROutSpec.state = 0 then
       ROutSpec.state = 1:LOutSpec.state = 0:Exit Sub
    End if
End Sub

Sub ResetSpecialLanes()
    ROutSpec.state = 0:LOutSpec.state = 0
End Sub

Sub LeftLane1_Hit()
    If LeftLaneLight1.state = 1 then 
       AddBonus()
    Else
       PlaySound "ding5"
    End If
    If Conservative = 0 then 
           AddScore 1000
        Else
           AddScore 100
    End If
End Sub

Sub LeftLane2_Hit()
    If LeftLaneLight2.state = 1 then 
       AddBonus()
    Else
       PlaySound "ding5"
    End If
    If Conservative = 0 then 
       AddScore 1000
    Else
       AddScore 100
    End If
End Sub

Sub LeftLane3_Hit()
    If LeftLaneLight3.state = 1 then 
       AddBonus()
    Else
       PlaySound "ding5"
    End If
    If Conservative = 0 then 
           AddScore 1000
        Else
           AddScore 100
    End If
End Sub

Sub RightLane1_Hit()
    If RightLaneLight1.state = 1 then 
       AddBonus()
    Else
       PlaySound "ding5"
    End If
    If Conservative = 0 then 
           AddScore 1000
        Else
           AddScore 100
    End If
End Sub

Sub RightLane2_Hit()
    If RightLaneLight2.state = 1 then 
       AddBonus()
    Else
       PlaySound "ding5"
    End If
    If Conservative = 0 then 
           AddScore 1000
        Else
           AddScore 100
    End If
End Sub

Sub RightLane3_Hit()
    If RightLaneLight3.state = 1 then 
       AddBonus()
    Else
       Playsound "ding5"
    End If
    If Conservative = 0 then 
           AddScore 1000
        Else
           AddScore 100
    End If
End Sub

Sub LowTrig1_hit()
    AddScore 100:LowerPost():PlaySound "ding5"
End Sub

Sub LowTrig2_hit()
    AddScore 100:LowerPost():PlaySound "ding5"
End Sub

Sub Trigger1_Hit()
    AddScore 1000:AddBonus()
End Sub

sub savehs
    SaveValue "PowerPlay", "HighScore", HighScore
    SaveValue "PowerPlay", "Credits", Credits
    SaveValue "PowerPlay", "NumBalls", NumBalls
    SaveValue "PowerPlay", "Conservative", Conservative
    SaveValue "PowerPlay", "NumPlays", NumPlays
    SaveValue "PowerPlay", "Replay1", Replay(1)
    SaveValue "PowerPlay", "Replay2", Replay(2)
    SaveValue "PowerPlay", "SpecialType", SpecialType
    SaveValue "PowerPlay", "AllowMatch", AllowMatch
end sub

sub loadhs
    dim Value
    Value = LoadValue("PowerPlay", "HighScore")
    If (Value <> "") Then HighScore = CDbl(Value) End If
    Value = LoadValue("PowerPlay", "Credits")
    If (Value <> "") Then Credits = CDbl(Value) End If
    Value = LoadValue("PowerPlay", "NumBalls")
    If (Value <> "") Then NumBalls = CDbl(Value) End If
    Value = LoadValue("PowerPlay", "Conservative")
    If (Value <> "") Then Conservative = CDbl(Value) End If
    Value = LoadValue("PowerPlay", "NumPlays")
    If (Value <> "") Then NumPlays = CDbl(Value) End If
    Value = LoadValue("PowerPlay", "Replay1")
    If (Value <> "") Then Replay(1) = CDbl(Value) End If
    Value = LoadValue("PowerPlay", "Replay2")
    If (Value <> "") Then Replay(2) = CDbl(Value) End If
    Value = LoadValue("PowerPlay", "SpecialType")
    If (Value <> "") Then SpecialType = CDbl(Value) End If
    Value = LoadValue("PowerPlay", "AllowMatch")
    If (Value <> "") Then AllowMatch = CDbl(Value) End If
end sub