' $Id: batmanf.vbs,v 1.8 2004/02/19 19:33:20 gcnelsb2 Exp $
'==========================================================
' Batman Forever
' Sega Pinball, Inc. 1995
'==========================================================
Option Explicit
LoadVPM "01210000", "de.vbs", 3.1

' PinMAME Romset
Const ROM = "batmanf"

Const UseSolenoids = True
Const UseLamps     = True
Const UseSync      = True
Const UseGI        = False

'Standard sound
Const SSolenoidOn  = "solon"       'Solenoid activates
Const SSolenoidOff = "soloff"      'Solenoid deactivates
Const SFlipperOn   = "FlipperUp"   'Flipper activated
Const SFlipperOff  = "FlipperDown" 'Flipper deactivated
Const SCoin        = "quarter"     'Coin inserted

'Callbacks
'Set LampCallback   = GetRef("UpdateMultipleLamps")
'Set GICallback     = GetRef("UpdateGI")
'Set MotorCallback  = GetRef("UpdateMotors")

'----------------------------------------
' Initialize Table
'----------------------------------------

Sub LoadVPM(VPMver, VBSfile, VBSver)
    On Error Resume Next
        If ScriptEngineMajorVersion < 5 Then MsgBox "VB Script Engine 5.0 or higher required"
        ExecuteGlobal CreateObject("Scripting.FileSystemObject").OpenTextFile(VBSfile, 1).ReadAll
        If Err Then MsgBox "Unable to open " & VBSfile & ". Ensure that it is in the same folder as this table. " & vbNewLine & Err.Description : Err.Clear
        Set Controller = CreateObject("VPinMAME.Controller")
        If Err Then MsgBox "Can't Load VPinMAME." & vbNewLine & Err.Description
        If VPMver>"" Then If Controller.Version < VPMver Or Err Then MsgBox "VPinMAME ver " & VPMver & " required." : Err.Clear
        If VPinMAMEDriverVer < VBSver Or Err Then MsgBox VBSFile & " ver " & VBSver & " or higher required."
    On Error Goto 0
End Sub

Sub InitVPM()
    vpmInit Me

    With Controller
        .GameName = ROM
        .SplashInfoLine = "Batman Forever"
        .ShowDMDOnly = True
        .ShowFrame = False
        .ShowTitle = False
        .HandleMechanics = 0

        On Error Resume Next
            .Run : If Err Then MsgBox Err.Description
        On Error Goto 0
    End With

    ' USA
    Controller.Dip(0) = &H00

    PinMAMETimer.Interval = PinMAMEInterval
    PinMAMETimer.Enabled = 1
End Sub


Dim bsTrough
Dim bsTroughKick
Dim bsTopEject
Dim bsVUK
Dim bsCaveLock
Dim bsCaveKick
Dim dtCave

Sub Batmanf_Init
    InitVPM

    ' Nudging
    vpmNudge.TiltSwitch = 1
    vpmNudge.Sensitivity = 5
    'vpmNudge.TiltObj = Array(Bumper1,Bumper2,LeftSling,RightSling)

    ' Switches and Lamps
    'vpmCreateEvents colSwObjects ' collection of triggers etc
    'vpmMapLights    colLamps     ' collection of all lamps

    Plunger.pullback
    Kickback.pullback

    ' 4-Ball Trough
    set bsTrough = New cvpmBallStack
    with bsTrough
        .InitSw 0,14,13,12,11,0,0,0
        .Balls=4
        .CreateEvents "bsTrough", Drain
        .InitAddSnd SSolenoidOn
        .InitEntrySnd "drain", SSolenoidOn
    end with

    ' Trough Up-Kicker
    set bsTroughKick = New cvpmBallStack
    bsTroughKick.InitSaucer TroughKicker, swTroughUp, 135, 3
    bsTroughKick.InitExitSnd "ballrel","solenoid"

    ' Cave Lock
    set bsCaveLock = New cvpmBallStack
    bsCaveLock.InitSw 0,swLock1,swLock2,swLock3,0,0,0,0
    bsCaveLock.CreateEvents "bsCaveLock", CaveLock

    ' Cave Exit Kicker
    set bsCaveKick = New cvpmBallStack
    with bsCaveKick
        .InitSaucer CaveKicker, swCaveKick, 180, 25
        .KickForceVar=1
        .InitEntrySnd "solenoid","solenoid"
        .InitExitSnd "ballrel","solenoid"
    end with

    ' Top Eject
    set bsTopEject = new cvpmBallStack
    with bsTopEject
        .InitSw 0,swTopEject,0,0,0,0,0,0
        .InitKick TopEject,85,8
        .KickForceVar=3
        .InitEntrySnd "popper", "solenoid"
        .InitExitSnd "popper", "solenoid"
        .KickBalls=3
        .CreateEvents "bsTopEject", TopEject
    end with

    ' Drop Targets C-A-V-E
    Set dtCave = New cvpmDropTarget
    with dtCave
        .InitDrop Array(Target18,Target19,Target20,Target21), Array(18,19,20,21)
        .InitSnd "flapclos","flapopen"
        .CreateEvents "dtCave"
    end with

    '' VUK
    'set bsVUK = new cvpmBallStack
    'with bsVUK
    '    .InitSaucer VUK,swVUK,0,20
    ''    .KickZ = 3.1415926/2
    '    .InitExitSnd "popper","solenoid"
    '    '.CreateEvents "bsVUK", VUK
    'end with
End Sub

sub Batmanf_KeyUp(ByVal keycode)
    If keycode = LeftFlipperKey  Then Controller.Switch(swLFlip) = False
    If keycode = RightFlipperKey Then Controller.Switch(swRFlip) = False
    If vpmKeyUp(keycode) Then Exit Sub
    If keycode=PlungerKey        Then Controller.Switch(swAutoLaunch) = 0
end sub

sub Batmanf_KeyDown(ByVal keycode)
    If keycode = RightFlipperKey Then Controller.Switch(swRFlip) = True
    If keycode = LeftFlipperKey  Then Controller.Switch(swLFlip) = True
    If vpmKeyDown(keycode) Then Exit Sub
    If keycode=PlungerKey        Then Controller.Switch(swAutoLaunch) = 1
end sub


'----------------------------------------
' Matrices - Switch/Solenoid/Lamp
'----------------------------------------

' Switches
Const swTroughUp        = 15
Const swCaveKick        = 30
Const swTopEject        = 41
Const swGunLoaded       = 44
Const swGunLocation     = 45
Const swGunHome         = 46
Const swAutoLaunch      = 49
Const swLock3           = 60
Const swLock2           = 61
Const swLock1           = 62
Const swLFlip           = 63
Const swRFlip           = 64

' Solenoids
Const sTroughLock   = 1
Const sTroughUpKick = 2
Const sAutoLaunch   = 3
Const sVUK          = 4
Const sTopEject     = 5
'6 not used
Const sDropReset    = 7
Const sKnocker      = 8
Const sCaveLock     = 9
Const sRelay        = 10
Const sGI           = 11
Const sDiverter     = 12
'13 not used
Const sGunMotor     = 14
Const sGunLaunch    = 15
Const sCaveExit     = 16
Const sLBumper      = 17
Const sBBumper      = 18
Const sRBumper      = 19
Const sLSling       = 20
Const sRSling       = 21
Const sKickback     = 22

' Flash Lamps
Const sfFlash1      = 25
Const sfFlash2      = 26
Const sfFlash3      = 27
Const sfFlash4      = 28
Const sfFlash5      = 29
Const sfFlash6      = 30
Const sfFlash7      = 31
Const sfFlash8      = 32
'Const sfFlash9     = 33
'Const sfFlash10    = 34
'

'----------------------------------------
' Solenoid Handlers
'----------------------------------------

SolCallback(sTroughLock)   = "SolLockout"
SolCallback(sTroughUpKick) = "bsTroughKick.SolOut"
SolCallback(sAutoLaunch)   = "vpmSolAutoPlunger Plunger,0,"
SolCallback(sTopEject)     = "bsTopEject.SolOut"
SolCallback(sKickback)     = "vpmSolAutoPlunger Kickback,10,"
'SolCallback(sVUK)          = "bsVUK.SolOut"
SolCallback(sVUK)          = "SolVUK"
SolCallback(sCaveLock)     = "SolCaveLock"
SolCallback(sCaveExit)     = "bsCaveKick.SolOut"
SolCallback(sDropReset)    = "dtCave.SolDropUp"

SolCallback(sLRFlipper)    = "vpmSolFlipper RightFlipper,UpperFlipper,"
SolCallback(sLLFlipper)    = "vpmSolFlipper LeftFlipper,Nothing,"
SolCallback(sKnocker)      = "vpmSolSound ""knocker"","
SolCallback(sLSling)       = "vpmSolSound ""lsling"","
SolCallback(sRSling)       = "vpmSolSound ""rsling"","
SolCallback(sRBumper)      = "vpmSolSound ""jet1"","
SolCallback(sLBumper)      = "vpmSolSound ""jet1"","
SolCallback(sBBumper)      = "vpmSolSound ""jet1"","

'sRelay
'sGI
'sDiverter
'sGunMotor
'sGunLaunch

'------------------------------
' Solenoid Functions
'------------------------------

Sub SolLockout(Enabled)
    If Enabled Then
        bsTrough.ExitSol_On
        bsTroughKick.AddBall 0
        vpmCreateBall TroughKicker
    End If
End Sub

Sub SolCaveLock(Enabled)
    If Enabled Then
        bsCaveLock.ExitSol_On
        bsCaveKick.AddBall 0
        vpmCreateBall CaveKicker
    End If
End Sub

Sub SolVUK(Enabled)
    if Enabled Then
        VUK.DestroyBall
        VUKramp.CreateBall
        VUKramp.Kick 315,9

        Controller.Switch(32) = False
        VUK.Enabled=True
    End If
End Sub


'----------------------------------------
' Switch Handlers
'----------------------------------------

Sub LeftSling_Slingshot:vpmTimer.PulseSwitch(35),0,"":End Sub
Sub RightSling_Slingshot:vpmTimer.PulseSwitch(36),0,"":End Sub

' Shooter Lane
Sub Switch16_Hit(): Controller.Switch(16)=1: End Sub
Sub Switch16_UnHit(): Controller.Switch(16)=0: End Sub

' Right Orbit
Sub Switch48_Hit(): Controller.Switch(48)=1: End Sub
Sub Switch48_UnHit(): Controller.Switch(48)=0: End Sub

' Left Orbit
Sub Switch47_Hit():   Controller.Switch(47)=1: End Sub
Sub Switch47_UnHit(): Controller.Switch(47)=0: End Sub

'Left Outlane
Sub Switch33_Hit()
    if ActiveBall.VelY > 7 AND Light45.State = LightStateOn then
        ActiveBall.VelY=7
        ActiveBall.VelX=0
    end if
    Controller.Switch(33)=1
End Sub
Sub Switch33_UnHit(): Controller.Switch(33)=0: End Sub

' Ramp Triggers
Sub TriggerRamp1_Hit(): ActiveBall.VelY=2: End Sub
Sub TriggerRamp2_Hit(): ActiveBall.VelY=2: End Sub

' Left Ramp Enter
Sub Switch52_Hit():   Controller.Switch(52)=1: End Sub
Sub Switch52_UnHit(): Controller.Switch(52)=0: End Sub

' Left Ramp Exit
Sub Switch53_Hit():   Controller.Switch(53)=1: End Sub
Sub Switch53_UnHit(): Controller.Switch(53)=0: End Sub

' Middle Ramp Exit
Sub Switch54_Hit():   Controller.Switch(54)=1: End Sub
Sub Switch54_UnHit(): Controller.Switch(54)=0: End Sub

' Right Ramp Enter
Sub Switch55_Hit():   Controller.Switch(55)=1: End Sub
Sub Switch55_UnHit(): Controller.Switch(55)=0: End Sub

' Right Ramp Exit
Sub Switch56_Hit():   Controller.Switch(56)=1: End Sub
Sub Switch56_UnHit(): Controller.Switch(56)=0: End Sub

' U Turn Ramp
Sub Switch40_Hit():   Controller.Switch(40)=1: End Sub
Sub Switch40_UnHit(): Controller.Switch(40)=0: End Sub

' Top Lane Left
Sub Switch22_Hit():   Controller.Switch(22)=1: End Sub
Sub Switch22_UnHit(): Controller.Switch(22)=0: End Sub

' Top Lane Middle
Sub Switch23_Hit():   Controller.Switch(23)=1: End Sub
Sub Switch23_UnHit(): Controller.Switch(23)=0: End Sub

' Top Lane Right
Sub Switch24_Hit():   Controller.Switch(24)=1: End Sub
Sub Switch24_UnHit(): Controller.Switch(24)=0: End Sub

' Bumpers
Sub Bumper1_Hit(): vpmtimer.pulsesw 57: End Sub
Sub Bumper2_Hit(): vpmtimer.pulsesw 58: End Sub
Sub Bumper3_Hit(): vpmtimer.pulsesw 59: End Sub

'VUK
Sub VUK_Hit(): Controller.Switch(32)=1: End Sub

' Left Return Lane
Sub Switch34_Hit():   Controller.Switch(34)=1: End Sub
Sub Switch34_UnHit(): Controller.Switch(34)=0: End Sub

' Right Return Lane Inside
Sub Switch37_Hit():   Controller.Switch(37)=1: End Sub
Sub Switch37_UnHit(): Controller.Switch(37)=0: End Sub

' Right Return Lane Outside
Sub Switch38_Hit():   Controller.Switch(38)=1: End Sub
Sub Switch38_UnHit(): Controller.Switch(38)=0: End Sub

' Right Outlane
Sub Switch39_Hit():   Controller.Switch(39)=1: End Sub
Sub Switch39_UnHit(): Controller.Switch(39)=0: End Sub

' Stand-Up Targets
Sub Target25_Hit(): vpmtimer.pulsesw 25: End Sub 'Left Ramp (L)
Sub Target26_Hit(): vpmtimer.pulsesw 26: End Sub 'Left Ramp (R)
Sub Target27_Hit(): vpmtimer.pulsesw 27: End Sub 'VUK
Sub Target28_Hit(): vpmtimer.pulsesw 28: End Sub 'Right Ramp (L)
Sub Target29_Hit(): vpmtimer.pulsesw 29: End Sub 'Right Ramp (R)
Sub Target42_Hit(): vpmtimer.pulsesw 42: End Sub 'Top Good Heads
Sub Target43_Hit(): vpmtimer.pulsesw 43: End Sub 'Top Bad Heads
Sub Target50_Hit(): vpmtimer.pulsesw 50: End Sub 'Right Good Heads
Sub Target51_Hit(): vpmtimer.pulsesw 51: End Sub 'Right Bad Heads

' Lights
set Lights(1)=Light1
set Lights(2)=Light2
set Lights(3)=Light3
set Lights(4)=Light4
set Lights(5)=Light5
set Lights(6)=Light6
set Lights(7)=Light7
set Lights(8)=Light8
set Lights(17)=Light17
set Lights(22)=Light22
set Lights(23)=Light23
set Lights(24)=Light24
set Lights(25)=Light25
set Lights(26)=Light26
set Lights(27)=Light27
set Lights(28)=Light28
set Lights(29)=Light29
set Lights(30)=Light30
set Lights(31)=Light31
set Lights(32)=Light32
set Lights(39)=Light39
set Lights(40)=Light40
set Lights(41)=Light41
set Lights(42)=Light42
set Lights(43)=Light43
set Lights(44)=Light44
set Lights(45)=Light45
set Lights(46)=Light46
set Lights(47)=Light47
set Lights(48)=Light48
set Lights(51)=Light51
set Lights(54)=Light54
set Lights(55)=Light55
set Lights(56)=Light56
set Lights(62)=Light62
