Guest User

Untitled

a guest
Aug 17th, 2018
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 131.49 KB | None | 0 0
  1. Option Explicit
  2. Const VPinMAMEDriverVer = 3.571 'beta NF FastFlips 2
  3. '=======================
  4. ' VPinMAME driver core.
  5. '=======================
  6. ' 3.571 - Beta NF fastflips
  7.  
  8. ' New in 3.56 (Update by nFozzy, DJRobX, Fuzzel)
  9. ' - Add specialized sega2.vbs for Apollo 13 and GoldenEye
  10. ' - Update gts1.vbs and hankin.vbs so that the common coin keys (e.g. "5") also add coins on Gottlieb System 1 and Hankin tables
  11. ' - vpmFlips fixes / improvements
  12. ' - Fixed vpmFlips execute script error
  13. ' - Added extra error check for detecting outdated system vbs files when UseSolenoids = 2
  14. ' - Change GameOnSolenoid from 16 to 19 for Hankin
  15. ' - Fixed an execute script issue that was causing dead flippers for some system languages
  16. ' - S.A.M. fast flips support: To activate, add InitVpmFFlipsSAM to the table init.
  17. ' Should work for most games (see PinMAME whatsnew for supported sets). May need additional configuration for two-stage flipper support.
  18. ' - Whitestar fast flips support
  19. ' - Capcom fast flips support
  20. ' - Fix WPC tables that use 'cSingleLFlip' (regression from 3.55)
  21. ' - Fix script errors if using NudgePlugIn.vbs
  22. ' - Add Rubber, Ramp, Flasher, Primitive and HitTarget support to vpmToggleObj
  23. ' - Add Rubber, Primitive and HitTarget support to vpmCreateEvents
  24. '
  25. ' New in 3.55 (Update by nFozzy)
  26. ' - Prevent 'object not a collection' errors if vpmNudge.TiltObj isn't set
  27. ' - Support for double leaf flipper switches
  28. ' - For now, keybinds for these staged flippers are defined in VPMKeys.vbs. By default they are set to LeftFlipperKey and RightFlipperKey, disabling them.
  29. ' - Adapting older tables requires vpmFlips: Create upper flipper subs and point SolCallback(sULFlipper) and SolCallback(sURFlipper) to them.
  30. ' - This may break compatibility with some older WPC tables that use the 'cSingleLFlip' method (More info in WPC.vbs), note that close to no 'modern' (e.g. VP8/VP9/VPX) table uses this anyway
  31. ' - Integrated FastFlips, (new object vpmFlips): Low latency flipper response for games with pre-solid state flippers
  32. ' - Ensure 'vpmInit me' is called in the table init section
  33. ' - UseSolenoids = 2 enables and auto sets the game-on solenoid (based on GameOnSolenoid in the system .vbs script)
  34. ' - Important info on supported WPC games is documented in WPC.vbs
  35. ' - Pre-solid-state flipper games (except Zaccaria and LTD) should work perfectly. This includes Bally/Williams WPCs up to Terminator 2 / Party Zone
  36. ' - Data East / early Segas will work perfectly, unless they have ROM-controlled flipper effects
  37. ' - Fliptronics and WPC-S games (Addams Family through Jack Bot / WHO Dunnit) will work with caveats (no ROM controlled flipper effects, beware stuck balls. More info in WPC.vbs)
  38. ' - Sega Whitestar (Apollo 13 / Goldeneye / etc), WPC95 (Congo / AFM / etc), and Capcom and everything onward will not work
  39. ' - There's also a debug test command which may be useful if it's not working properly. Open the debug window (Accessible from the VP-escape menu, press the ">" button to bring up the text field) and type in 'vpmFlips.DebugTest'
  40. '
  41. ' New in 3.54 (Update by mfuegemann & nFozzy & Ninuzzu/Tom Tower & Toxie)
  42. ' - Added UltraDMD_Options.vbs to configure Ultra DMD based tables globally (see the file itself for detailed descriptions)
  43. ' - Added sam.vbs
  44. ' - Added Class1812.vbs
  45. ' - Added inder_centaur.vbs
  46. ' - Restore basic functionality of cvpmDropTarget.CreateEvents for drop targets with an animation time (e.g. VP10 and newer)
  47. ' - Minor cleanups and code unifications for all machines
  48. ' - Add keyConfigurations to VPMKeys.vbs for Taito and also remap the hardcoded keycode '13' to keySoundDiag
  49. '
  50. ' New in 3.53 (Update by Toxie)
  51. ' - Add more key mappings to help dialog
  52. '
  53. ' New in 3.52 (Update by DJRobX & Toxie)
  54. ' - Change default interval of the PinMAME timer to -1 (frame-sync'ed) if VP10.2 (or newer) is running
  55. ' - Add modulated solenoids to support ROM controlled fading flashers:
  56. ' To use, add "UseVPMModSol=True" to the table script
  57. ' Also use SolModCallback instead of SolCallback to receive level changes as input: It will be a level from 0 to 255.
  58. ' Just continue to use SolCallback if you only care about boolean values though, as it will only fire if level changes from on to off.
  59. ' Note: vpmInit MUST BE CALLED or VPM will not switch modes (if you are only getting 0 and 1 from SolModCallback then that may be the issue)
  60. '
  61. ' New in 3.51 (Update by mfuegemann & Arngrim & Toxie)
  62. ' - gts1.vbs dip fix
  63. ' - Add comments to cvpmDropTarget.CreateEvents: do not use this anymore in VP10 and above, as drop targets have an animation time nowadays
  64. ' - Change default interval of the PinMAME timer to 3 if VP10 (or newer) is running, and leave it at 1 for everything else
  65. ' - Fix missing SlingshotThreshold() when using VP8.X
  66. ' - (Controller.vbs changes)
  67. ' - now its allowed to have each toy to be set to 0 (sound effect), 1 (DOF) or 2 (both)
  68. ' - new DOF types: DOFFlippers, DOFTargets, DOFDropTargets
  69. ' - all values are now stored in the registry (HKEY_CURRENT_USER\SOFTWARE\Visual Pinball\Controller\), and can also be changed from within VP10.2 and above
  70. ' - InitializeOptions call added to the controller init, for tables that want to use this functionality during gameplay (options menu via F6)
  71. '
  72. ' New in 3.50 (Update by Toxie & mfuegemann & Arngrim)
  73. ' - Added MAC.vbs & IronBalls.vbs & Lancelot.vbs & Antar.vbs
  74. ' - (Core changes)
  75. ' - Increased NVOffset limit from 10 to 32
  76. ' - Use temporary variables for Switch() calls to workaround current PROC issues
  77. ' - Controller.vbs user-folder detection fix, and add simple PROC usage via LoadPROC (see Controller.vbs for details)
  78. ' - Add UseVPMNVRAM = true to the table script (place before LoadVPM, or otherwise calling core.vbs)
  79. ' to make changed content of NVRAM available (since last update) via the NVRAMCallback (delivers a three dimensional array with: location, new value, old value)
  80. ' (requires VPM 2.7 or newer)
  81. '
  82. ' New in 3.49 (Update by Arngrim)
  83. ' - Add new Controller.vbs to abstract DOF, B2S, VPM and EM controller loading, usage and sound/effect handling,
  84. ' see Controller.vbs header on how to use it exactly
  85. '
  86. ' New in 3.48 (Update by JimmyFingers)
  87. ' - (Core changes)
  88. ' - Changed vpmNudge.TiltObj handling to use Bumper.Threshold / Wall.SlingshotThreshold temporary value changes rather than force / SlingshotStrength changes to disable tiltobj array objects
  89. ' - There existed a bug in VP since at least the 9.x versions where the Wall.SlingshotStrength value being set by scripting during game play did change the value but the slingshot behaviour / "Slingshot Force" (from the editor) of the wall object did not change (i.e. did not have an effect); As a result the attempted disabling of bumpers and slingshots after a tilt event on supported games (that can send a relay for vpmNudge.SolGameOn ) would only work for the bumper objects
  90. ' - Using thresholds instead also now has added benefit by not actually triggering the related _Hit or _Slingshot routines so animations, sound processing, and other potential nested subroutine calls will also not activate resulting in a better tilt simulation
  91. ' Note: NudgePlugin option .vbs files were also updated as they contain and are reassigned the vpmNudge routines when invoked
  92. '
  93. ' New in 3.47 (Update by Toxie)
  94. ' - (Core changes)
  95. ' - Add UseVPMColoredDMD = true to the table script (place before LoadVPM, or otherwise calling core.vbs)
  96. ' to automatically pass the raw colored DMD data (RGB from 0..255) from VPM to VP (see VP10+ for details on how to display it)
  97. '
  98. ' New in 3.46 (Update by KieferSkunk)
  99. ' - (Core changes)
  100. ' - Added two new classes: cvpmTrough and cvpmSaucer
  101. ' - cvpmTrough takes over for cvpmBallStack in non-Saucer mode.
  102. ' - Can handle any number of balls (no more "out of bounds" errors with lots of balls)
  103. ' - Accurately simulates ball movement and switch interaction in a real trough
  104. ' - cvpmSaucer takes over for cvpmBallStack in Saucer mode.
  105. ' - cvpmBallStack is now considered "legacy" - kept for compatibility with existing tables. (No changes)
  106. ' - Updated vbsdoc.html with these new classes.
  107. ' - Added two helper functions, vpMin(a, b) and vpMax(a, b).
  108. ' - These each take two numbers (or strings) and return the lower or higher of the two (respectively).
  109. '
  110. ' New in 3.45 (Update by KieferSkunk)
  111. ' - (Core changes)
  112. ' - Rewrote cvpmDictionary as a wrapper around Microsoft's Scripting.Dictionary object.
  113. ' This provides two major benefits:
  114. ' (1) Improved performance: Keys are stored by hash/reference, not by index, and existence checks and key location are now O(1) instead of O(N) operations.
  115. ' (2) Keys and Items can now both be primitive types or objects. You can use integers, strings, etc. as keys, and you can use any object as an Item.
  116. ' Note: The only restriction is that a Key cannot be a Scripting.Dictionary or an Array.
  117. ' - cvpmTurnTable now smoothly changes speeds and directions. You can adjust the following properties to change the turntable's behavior:
  118. ' - MaxSpeed: Sets new maximum spin speed. If motor is on, turntable will smoothly accelerate to new speed.
  119. ' - SpinUp: Sets new spin-up rate. If currently accelerating, turntable will accelerate at the new rate.
  120. ' - SpinDown: Sets new spin-down rate. If currently slowing to a stop, turntable will decelerate at the new rate.
  121. ' - SpinCW: True for clockwise rotation, False for counter-clockwise. If motor is on, switching this will smoothly reverse the turntable's direction.
  122. '
  123. ' New in 3.44 (Update by Toxie)
  124. ' - (Core changes)
  125. ' - Added ability to define default ball mass (in VP Units) inside table script.
  126. ' Defaults to 1 unit if undefined. Example...
  127. ' Const BallMass = 2 '(place before LoadVPM, or otherwise calling core.vbs)
  128. ' Note that this should be used if changing the ball size via BallSize,
  129. ' as the mass is of course proportional to the radius of the ball: m=k*r^3.
  130. ' One can also use the diameter/size like in VP, so BallMass=k*BallSize^3 with k=1/125000.
  131. ' Example: BallSize = 55, so BallMass = (55*55*55)/125000 = 1.331.
  132. ' - Add UseVPMDMD = true to the table script (place before LoadVPM, or otherwise calling core.vbs)
  133. ' to automatically pass the raw DMD data (levels from 0..100) from VPM to VP (see VP10+ for details on how to display it)
  134. ' - Add toggleKeyCoinDoor in VPMKeys.vbs to choose between a real coindoor setup (e.g. cabinets) and the 'classic' on/off behaviour (e.g desktops/keyboards)
  135. ' - Add inverseKeyCoinDoor in VPMKeys.vbs to in addition choose between the behaviour of a real coindoor switch (key pressed = closed, key not pressed = open)
  136. ' or the inverted behaviour (key pressed = open, key not pressed = closed)
  137. ' - Increase maximum number of balls/conMaxBalls to 13 and conStackSw to 8 (for Apollo 13), use InitSw8() then instead of InitSw()
  138. ' - Deprecate vpmSolFlip2, as VP10 does not feature speed on flippers anymore
  139. '
  140. ' New in 3.43 (Update by Koadic)
  141. ' - (Core Changes)
  142. ' - Minor adjustment to vbs loading via LoadScript to account for files in nonstandard locations
  143. ' - Fix minor bugs when loading some tables
  144.  
  145. ' New in 3.42 (Update by Koadic)
  146. ' - (Core Changes)
  147. ' - Minor adjustment to vpmInit to unpause controller before stopping controller
  148. '
  149. ' New in 3.41 (Update by Koadic)
  150. ' - (Core Changes)
  151. ' - Modified vpmInit routine:
  152. ' Added creation of _Exit routine to vpmInit to perform Controller.Stop (will retroactively effect all tables using vpmInit call)
  153. ' Modified vpmInit to create _Paused, _UnPaused, and _Exit separately, so if any don't exit, they will be created individually
  154. ' Modified Error handling to fix bug where vmpInit might throw "Invalid procedure call or argument" error
  155. ' and cause table not to work due to improper Table_Init scripting.
  156. ' - Added 2 functions: CheckScript(file) and LoadScript(file) that can return True/False as well as the latter loading the script if true.
  157. ' These check for existance in either the Tables and Scripts directory and can return a boolean value as well as the LoadScript autoloading
  158. ' the file, as opposed to my previous methods only checking the local folder containing the table being run.
  159. ' CheckScript(file) checks for existance, and if found returns a True value
  160. ' LoadScript(file) checks for existance, and if found, loads specified file (via ExecuteGlobal GetTextFile(file)) and returns a True value
  161. ' Examples:
  162. ' If LoadScript("thefile.vbs") Then DoThisOtherThing ' If Loadscript found 'thefile' and loaded it (returned true) then do this other thing
  163. ' LoadScript("somefile.vbs") ' Checks for 'somefile' and loads it if it exists
  164. ' - Reworked CheckLEDWiz routine into generic LoadScript(file) routine to allow for better detection of script in the VP tables
  165. ' or scripts directory, not just current directory containing the table.
  166. ' - Added ability to load NudgePlugIn.vbs and if found, it will be loaded and replace current default nudging class.
  167. ' - This detection and autoloading can allow for 'on demand' replacement of other core components as well in the future.
  168. ' - Added ability to load GlobalPlugIn.vbs containing any custom scripting the user wants loaded with the core.vbs (instead of modifying the core)
  169. ' -(Other Additions)
  170. ' - Updated B2BCollision.vbs with vpmBallCreate method and renamed new file to B2B.vbs (to maintain compatiblity with tables using old file).
  171. '
  172. ' New in 3.40 (Update by Koadic)
  173. ' - (Core Changes)
  174. ' - Modified NVOffset routine to allow use of alternative controllers (like dB2S B2S.Server)
  175. ' New in 3.39 (Update by Koadic)
  176. ' - (Core Changes)
  177. ' - Hopefully fixed bug introduced in 3.37 when using a VP version older than 9.0.10
  178. ' New in 3.38 (Update by Koadic)
  179. ' - (Core Changes)
  180. ' - Added automatic detection of ledcontrol.vbs and enabling for LedWiz use, allowing concurrent use by both users and non users of an LedWiz
  181. ' New in 3.37 (Update by Koadic)
  182. ' - (Core Changes)
  183. ' - Added ability to define default ballsize (in VP Units) inside table script.
  184. ' Defaults to 50 vp units if undefined. Example...
  185. ' Const BallSize = 47 '(place before LoadVPM, or otherwise calling core.vbs)
  186. ' New in 3.36 (update courtesy of Koadic)
  187. ' - (Core Changes)
  188. ' - Added VPMVol routine for allowing setting of Global VPM Volume (normally adjustable from '~' key, but otherwise unsaveable without this)
  189. ' - (System VBS Alterations)
  190. ' - Added keyVPMVolume in VPMKeys.vbs, set to use the F12 key
  191. ' - Added call to VPMVol routine in each system's .vbs file, allowing end-user to access the new routine
  192. ' New in 3.35 (Update courtesy of Koadic)
  193. ' - (Core Changes)
  194. ' - Added NVOffset routine for allowing use of multiple nvram files per romset name
  195. ' New in 3.34 (Update by Destruk)
  196. ' - (System VBS Additions)
  197. ' - Added Play2.vbs
  198. ' New in 3.33 (Update by Destruk)
  199. ' - (System VBS Additions)
  200. ' - Added LTD.vbs
  201. ' New in 3.32 (Update by Destruk)
  202. ' - (System VBS Alterations)
  203. ' - Added Playmatic Replay setting switches
  204. ' New in 3.31 (Update by Destruk)
  205. ' - (System VBS Additions)
  206. ' - Added play1.vbs
  207. ' New in 3.30 (Update by Destruk)
  208. ' - (System VBS Additions)
  209. ' - Added zacproto.vbs
  210. ' New in 3.29 (Update by Noah)
  211. ' - (System VBS Additions)
  212. ' - Added jvh.vbs and ali.vbs by Destruk for Jac van Ham and Allied Leisure
  213. ' Corrected VPBuild Number for slingshots/bumpers and ball decals - Seeker
  214. ' New in 3.27 (Update by PD)
  215. ' - (System VBS Additions)
  216. ' - Added gts1.vbs by Inkochnito for Gottlieb System 1
  217. ' New in 3.26 (Update by PD)
  218. ' - (Core Changes)
  219. ' - Added "GICallback2" function to support Steve Ellenoff's new support in VPM for Dimming GI in WMS games
  220. ' GICallback returns numeric values 0-8 instead of a boolean 0 or 1 (on/off) like GICallback does.
  221. ' Existing tables will need to be altered to support dimming levels and need to use GICallback2 instead.
  222. ' The old GICallback is left intact so older tables are not broken by the new code
  223. '
  224. ' New in 3.25 (release 2) (Update by PD)
  225. ' - (Core Changes)
  226. ' - Restored former flipper speed due to complaints about some tables having BTTF problem returned and a resolution
  227. ' of arguments over the settings
  228. ' - New Optional Flipper Code Added (vpmSolFlip2) that let's you specify both up and down-swing speeds in the script
  229. ' plus the ability to turn flipper sounds on or off for that call
  230. ' Format: vpmSolFlip2 (Flip1obj, Flip2obj, UpSpeed, DownSpeed, SoundOn, Enable)
  231. '
  232. ' New in 3.24 (Update by PD)
  233. ' - (Core Changes)
  234. ' - Altered flipper code so the upswing defaults to your downswing (i.e. VBS no longer adds a different value)
  235. ' (This change was done due to arguments over issues now resolved)
  236. ' - I have decreased the return strength setting to be very low, though. So any downswing hits (say from a ball
  237. ' heading to the trough) won't get hit with any real power. So, assuming you have a reasonably fast upswing,
  238. ' you won't get any balls through the flipper and any balls hit by the underside won't get pegged anymore, which
  239. ' is a more realistic behavior.
  240. '
  241. ' New in 3.23 (Update by PD)
  242. ' - (System.vbs Additions)
  243. ' - SlamtTilt definitions added to AlvinG and Capcom systems
  244. ' - High Score Reset Switch Added to Williams System7 (S7.vbs)
  245. ' - Sleic.vbs system added (courtesy of Destruk)
  246. ' - Peper.vbs system added (courtesy of Destruk)
  247. ' - Juegos.vbs system added (courtesy of Destruk)
  248. '
  249. ' New in 3.22 (Update by PD)
  250. ' - (Core Changes)
  251. ' - Outhole switch handling updated so it resets correctly with an F3 reset.
  252. ' This affects mostly Gottlieb System3 games (Thanks Racerxme for pointing this out)
  253. ' - Flipper handling modified to have a low return strength setting so any balls under such flippers
  254. ' won't get hit hard. This allows the higher 'flipper fix' return speed without the associated hard hit issue.
  255. ' - (System.vbs Additions)
  256. ' -Inder.vbs test switches updated (Thanks Peter)
  257. ' -Bally.vbs swSoundDiag value changed to -6 (Thanks Racerxme)
  258. '
  259. ' New in 3.21 (Update by PD)
  260. ' -(Core Changes)
  261. ' - Attemped bug fix in the Impulse Plunger object that could cause weak plunges sometimes on full pulls
  262. '
  263. ' -(System.vbs Additions)
  264. ' -Zac1.vbs has the program enable switch added to it (Thanks TomB)
  265. ' -GamePlan.vbs has the accounting reset switch added to it (Thanks Incochnito)
  266. '
  267. ' -(Other Additions)
  268. ' -PD Light System VBS file updated to V5.5 (adds fading reel pop bumper handler and checklight function)
  269. '
  270. ' New in 3.20 (Update by PD)
  271. ' -(System.vbs Additions)
  272. ' -Apparently Atari2.vbs uses 81/83 for the flipper switches and Atar1.vbs uses 82/84 so this repairs
  273. ' the Atari2.vbs file.
  274. '
  275. ' New in 3.19 (Update by PD)
  276. ' -(System.vbs Additions)
  277. ' - Fixed the swLLFlip and swLRFlip switch numbers in the Atari1.vbs, Atari2.vbs and Atari.vbs files
  278. ' SolFlipper should now work with Atari tables using the updated file
  279. '
  280. ' New in 3.18 (Update by PD)
  281. ' -(System.vbs Additions)
  282. ' - Added Atari1.vbs and Atari2.vbs files (Thanks to Inkochnito).
  283. ' -The old Atari.vbs file is now obsolete, but included for backwards compatability with any existing tables
  284. ' that may have used it. New Tables should use the appropriate Atari1.vbs or Atari2.vbs files.
  285. '
  286. ' New in 3.17 (Update by PD)
  287. ' -(System.vbs Additions)
  288. ' -Fixed wrong switch definition in Sys80.vbs for the self-test switch. The operator menus should work now.
  289. ' (Thanks to Inkochnito for pointing it out).
  290. ' -Added inder.vbs, nuova.vbs, spinball.vbs and mrgame.vbs files (Thanks to Destruk)
  291. '
  292. ' New in 3.16 (Update by PD)
  293. ' -(System.vbs Additions)
  294. ' -Added "BeginModal" and "EndModal" statements to each system (required for latest versions of VP ( >V6.1) to
  295. ' avoid problems during the VPM "F3" reset.
  296. ' -(Other Additions)
  297. ' - PDLightSystem Core updated to version 5.4
  298. '
  299. ' New in 3.15 (Update by PD)
  300. ' -(Core Additions)
  301. ' - Added a new higher resolution Impulse Plunger Object
  302. ' (It uses a trigger to plunge the ball. It can be a variable Manual Plunger or function as an Automatic Plunger)
  303. ' (It also features random variance options and optional pull / plunge sounds)
  304. '
  305. ' -(System.vbs Additions)
  306. ' - Fixed wrong switch number for Tilt & Slam Tilt in Sega.vbs
  307. ' - Added Master CPU Enter switch to S7.vbs for Dip Switch control in Williams System7
  308. '
  309. ' -(Other Additions)
  310. ' - Added PDLightSystem.vbs (V5.3) file to archive
  311. ' (open it with a text editor to see how to use it; it's called separately like the core file)
  312. '
  313. ' New in 3.14 (Update by PD)
  314. ' -(System.vbs Additions)
  315. ' - Added latest Zac1.vbs and Zac2.vbs files to archive
  316. '
  317. ' New in 3.13 (Update by PD)
  318. ' -(Core Additions)
  319. ' - Added Destruk's code to "Add" or "Remove" a ball from the table when "B" is pressed.
  320. ' - Added "AutoplungeS" call which is the same as "Autoplunger" except it will play a specified sound when fired
  321. '
  322. ' -(System.vbs Additions)
  323. ' - Taito.vbs updated to fix service menu keys and default dip switch menu added
  324. ' - Dip Switch / Option Menu "class" code added to all table VBS scripts to ease menu coding for table authors
  325. ' - Fixed some labeling errors and organization and added a "Last Updated" version comment at the start of each file
  326. '
  327. ' New in 3.12
  328. ' - Made flipper return speed a constant conFlipRetSpeed
  329. ' - set conFlipRetSpeed to 0.137 to reduce ball thru flipper problem
  330. '
  331. ' New in 3.11
  332. ' - Added a short delay between balls in the ballstacks to ensure
  333. ' that the game registers the switches as off when balls are rolling
  334. ' in the trough. All balls should probably move at the same time but it is
  335. ' a bit tricky to implement without changing a lot of code.
  336. ' - Removed support for the wshltdlg.dll since funtionality is in VPM now
  337. ' New in 3.10
  338. ' - Public release
  339. ' Put this at the top of the table file
  340. 'LoadVPM "02000000", "xxx.VBS", 3.15
  341. 'Const cGameName = "xxxx" ' PinMAME short game name
  342. 'Const UseSolenoids = True
  343. 'Const UseLamps = True
  344. ''Standard sound
  345. 'Const SSolenoidOn = "SolOn" 'Solenoid activates
  346. 'Const SSolenoidOff = "SolOff" 'Solenoid deactivates
  347. 'Const SFlipperOn = "FlipperUp" 'Flipper activated
  348. 'Const SFlipperOff = "FlipperDown" 'Flipper deactivated
  349. 'Const SCoin = "Quarter" 'Coin inserted
  350. ''Callbacks
  351. 'Set LampCallback = GetRef("UpdateMultipleLamps")
  352. 'Set GICallback = GetRef("UpdateGI") ' Original GI Callback (returns boolean on and off values only)
  353. 'Set GICallback2 = GetRef("UpdateGI") ' New GI Callback supports Newer VPM Dimming GI and returns values numeric 0-8)
  354. 'Set MotorCallback = GetRef("UpdateMotors")
  355. '
  356. 'Sub LoadVPM(VPMver, VBSfile, VBSver)
  357. ' On Error Resume Next
  358. ' If ScriptEngineMajorVersion < 5 Then MsgBox "VB Script Engine 5.0 or higher required"
  359. ' ExecuteGlobal GetTextFile(VBSfile)
  360. ' If Err Then MsgBox "Unable to open " & VBSfile & ". Ensure that it is in the same folder as this table. " & vbNewLine & Err.Description : Err.Clear
  361. ' Set Controller = CreateObject("VPinMAME.Controller")
  362. ' If Err Then MsgBox "Can't Load VPinMAME." & vbNewLine & Err.Description
  363. ' If VPMver>"" Then If Controller.Version < VPMver Or Err Then MsgBox "VPinMAME ver " & VPMver & " required." : Err.Clear
  364. ' If VPinMAMEDriverVer < VBSver Or Err Then MsgBox VBSFile & " ver " & VBSver & " or higher required."
  365. 'End Sub
  366. '
  367. 'Sub Table_KeyDown(ByVal keycode)
  368. ' If vpmKeyDown(keycode) Then Exit Sub
  369. ' If keycode = PlungerKey Then Plunger.Pullback
  370. 'End Sub
  371. 'Sub Table_KeyUp(ByVal keycode)
  372. ' If vpmKeyUp(keycode) Then Exit Sub
  373. ' If keycode = PlungerKey Then Plunger.Fire
  374. 'End Sub
  375. '
  376. 'Const cCredits = ""
  377. 'Sub Table_Init
  378. ' vpmInit Me
  379. ' On Error Resume Next
  380. ' With Controller
  381. ' .GameName = cGameName
  382. ' If Err Then MsgBox "Can't start Game " & cGameName & vbNewLine & Err.Description : Exit Sub
  383. ' .SplashInfoLine = cCredits
  384. ' .HandleMechanics = 0
  385. ' .ShowDMDOnly = True : .ShowFrame = False : .ShowTitle = False
  386. ' .Run : If Err Then MsgBox Err.Description
  387. ' End With
  388. ' On Error Goto 0
  389. '' Nudging
  390. ' vpmNudge.TiltSwitch = swTilt
  391. ' vpmNudge.Sensitivity = 5
  392. ' vpmNudge.TiltObj = Array(Bumper1,Bumper2,LeftslingShot,RightslingShot)
  393. '' Map switches and lamps
  394. ' vpmCreateEvents colSwObjects ' collection of triggers etc
  395. ' vpmMapLights colLamps ' collection of all lamps
  396. '' Trough handler
  397. ' Set bsTrough = New cvpmBallStack
  398. ' bsTrough.InitNoTrough BallRelease, swOuthole, 90, 2
  399. ' 'or
  400. ' bsTrough.InitSw swOuthole,swTrough1,swTrough2,0,0,0,0
  401. '---------------------------------------------------------------
  402. Dim Controller ' VPinMAME Controller Object
  403. Dim vpmTimer ' Timer Object
  404. Dim vpmNudge ' Nudge handler Object
  405. Dim Lights(200) ' Put all lamps in an array for easier handling
  406. ' If more than one lamp is connected, fill this with an array of each light
  407. Dim vpmMultiLights() : ReDim vpmMultiLights(0)
  408. Private gNextMechNo : gNextMechNo = 0 ' keep track of created mech handlers (would be nice with static members)
  409.  
  410. ' Callbacks
  411. Dim SolCallback(68) ' Solenoids (parsed at Runtime)
  412. Dim SolModCallback(68) ' Solenoid modulated callbacks (parsed at Runtime)
  413. Dim SolPrevState(68) ' When modulating solenoids are in use, needed to keep positive value levels from changing boolean state
  414. Dim LampCallback ' Called after lamps are updated
  415. Dim GICallback ' Called for each changed GI String
  416. Dim GICallback2 ' Called for each changed GI String
  417. Dim MotorCallback ' Called after solenoids are updated
  418. Dim vpmCreateBall ' Called whenever a vpm class needs to create a ball
  419. Dim BSize:If IsEmpty(Eval("BallSize"))=true Then BSize=25 Else BSize = BallSize/2
  420. Dim BMass:If IsEmpty(Eval("BallMass"))=true Then BMass=1 Else BMass = BallMass
  421. Dim UseDMD:If IsEmpty(Eval("UseVPMDMD"))=true Then UseDMD=false Else UseDMD = UseVPMDMD
  422. Dim UseModSol:If IsEmpty(Eval("UseVPMModSol"))=true Then UseModSol=false Else UseModSol = UseVPMModSol
  423. Dim UseColoredDMD:If IsEmpty(Eval("UseVPMColoredDMD"))=true Then UseColoredDMD=false Else UseColoredDMD = UseVPMColoredDMD
  424. Dim UseNVRAM:If IsEmpty(Eval("UseVPMNVRAM"))=true Then UseNVRAM=false Else UseNVRAM = UseVPMNVRAM
  425. Dim NVRAMCallback
  426.  
  427. ' Assign Null Default Sub so script won't error if only one is defined in a script (should redefine in your script)
  428. Set GICallback = GetRef("NullSub")
  429. Set GICallback2 = GetRef("NullSub")
  430.  
  431. ' Game specific info
  432. Dim ExtraKeyHelp ' Help string for game specific keys
  433. Dim vpmShowDips ' Show DIPs function
  434. '-----------------------------------------------------------------------------
  435. ' These helper functions require the following objects on the table:
  436. ' PinMAMETimer : Timer object
  437. ' PulseTimer : Timer object
  438.  
  439.  
  440. ' Available classes:
  441. ' ------------------
  442. ' cvpmTimer (Object = vpmTimer)
  443. ' (Public) .PulseSwitch - pulse switch and call callback after delay (default)
  444. ' (Public) .PulseSw - pulse switch
  445. ' (Public) .AddTimer - call callback after delay
  446. ' (Public) .Reset - Re-set all ballStacks
  447. ' (Friend) .InitTimer - initialise fast or slow timer
  448. ' (Friend) .EnableUpdate - Add/remove automatic update for an instance
  449. ' (Private) .Update - called from slow timer
  450. ' (Private) .FastUpdate - called from fast timer
  451. ' (Friend) .AddResetObj - Add object that needs to catch reset
  452. '
  453. ' cvpmTrough (Create as many as needed)
  454. ' (Public) .IsTrough - Get or Set whether this trough is the default trough (first trough sets this by default)
  455. ' (Public) .Size - Get or Set total number of balls trough can hold
  456. ' (Public) .EntrySw - Set switch number for trough entry (if any) - eg. Outhole
  457. ' (Public) .AddSw - Assign a switch at a specific slot
  458. ' (Public) .InitSwitches - Set trough switches using an array, from exit slot back toward entrance.
  459. ' (Public) .InitExit - Setup exit kicker, force and direction
  460. ' (Public) .InitExitVariance - Modify exit kick direction and force (+/-, min force = 1)
  461. ' (Public) .InitEntrySounds - Sounds to play when a ball enters the trough
  462. ' (Public) .InitExitSounds - Sounds to play when the exit kicker fires
  463. ' (Public) .CreateEvents - Auto-generate hit events for VP entry kicker(s) associated with this trough
  464. ' (Public) .MaxBallsPerKick - Set maximum number of balls to kick out (default 1)
  465. ' (Public) .MaxSlotsPerKick - Set maximum slots from which to get balls when kicking out (default 1)
  466. ' (Public) .Balls - Get current balls in trough, or set initial number of balls in trough
  467. ' (Public) .BallsPending - Get number of balls waiting in trough entry
  468. ' (Public) .Reset - Reset and update all trough switches
  469. ' (Friend) .Update - Called from vpmTimer to update ball positions and switches
  470. ' (Public) .AddBall - Add a ball to the trough from a kicker. If kicker is the exit kicker, stacks ball at exit.
  471. ' (Public) .SolIn - Solenoid handler for entry solenoid
  472. ' (Public) .SolOut - Solenoid handler for exit solenoid
  473. '
  474. ' cvpmSaucer (Create as many as needed)
  475. ' (Public) .InitKicker - Setup main kicker, switch, exit direction and force (including Z force)
  476. ' (Public) .InitExitVariance - Modify kick direction and force (+/-, min force = 1)
  477. ' (Public) .InitAltKick - Set alternate direction and force (including Z force) - for saucers with two kickers
  478. ' (Public) .InitSounds - Sounds to play when a ball enters the saucer or the kicker fires
  479. ' (Public) .CreateEvents - Auto-generate hit event for VP kicker(s) associated with this saucer
  480. ' (Public) .AddBall - Add a ball to the saucer from a kicker.
  481. ' (Public) .HasBall - True if the saucer is occupied.
  482. ' (Public) .solOut - Fire the primary exit kicker. Ejects ball if one is present.
  483. ' (Public) .solOutAlt - Fire the secondary exit kicker. Ejects ball with alternate forces if present.
  484. '
  485. ' cvpmBallStack (DEPRECATED, but create as many as needed)
  486. ' (Public) .InitSw - init switches used in stack
  487. ' (Public) .InitSaucer - init saucer
  488. ' (Public) .InitNoTrough - init a single ball, no trough handler
  489. ' (Public) .InitKick - init exit kicker
  490. ' (Public) .InitAltKick - init second kickout direction
  491. ' (Public) .CreateEvents - Create addball events for kickers
  492. ' (Public) .KickZ - Z axis kickout angle (radians)
  493. ' (Public) .KickBalls - Maximum number of balls kicked out at the same time
  494. ' (Public) .KickForceVar - Initial ExitKicker Force value varies by this much (+/-, minimum force = 1)
  495. ' (Public) .KickAngleVar - ExitKicker Angle value varies by this much (+/-)
  496. ' (Public) .BallColour - Set ball colour
  497. ' (Public) .TempBallImage - Set ball image for next ball only
  498. ' (Public) .TempBallColour - Set ball colour for next ball only
  499. ' (Public) .BallImage - Set ball image
  500. ' (Public) .InitAddSnd - Sounds when ball enters stack
  501. ' (Public) .InitEntrySnd - Sounds for Entry kicker
  502. ' (Public) .InitExitSnd - Sounds for Exit kicker
  503. ' (Public) .AddBall - add ball in "kicker" to stack
  504. ' (Public) .SolIn - Solenoid handler for entry solenoid
  505. ' (Public) .EntrySol_On - entry solenoid fired
  506. ' (Public) .SolOut - Solenoid handler for exit solenoid
  507. ' (Public) .SolOutAlt - Solenoid handler for exit solenoid 2nd direction
  508. ' (Public) .ExitSol_On - exit solenoid fired
  509. ' (Public) .ExitAltSol_On - 2nd exit solenoid fired
  510. ' (Public) .Balls - get/set number of balls in stack (default)
  511. ' (Public) .BallsPending - get number of balls waiting to come in to stack
  512. ' (Public) .IsTrough - Specify that this is the main ball trough
  513. ' (Public) .Reset - reset and update all ballstack switches
  514. ' (Friend) .Update - Update ball positions (from vpmTimer class)
  515. ' Obsolete
  516. ' (Public) .SolExit - exit solenoid handler
  517. ' (Public) .SolEntry - Entry solenoid handler
  518. ' (Public) .InitProxy - Init proxy switch
  519.  
  520. ' cvpmNudge (Object = vpmNudge)
  521. ' Hopefully we can add a real pendulum simulator in the future
  522. ' (Public) .TiltSwitch - set tilt switch
  523. ' (Public) .Senitivity - Set tiltsensitivity (0-10)
  524. ' (Public) .TiltObj - Set objects affected by tilt
  525. ' (Public) .DoNudge dir,power - Nudge table
  526. ' (Public) .SolGameOn - Game On solenoid handler
  527. ' (Private) .Update - Handle tilting
  528. '
  529. ' cvpmDropTarget (create as many as needed)
  530. ' (Public) .InitDrop - initialise DropTarget bank
  531. ' (Public) .CreateEvents - Create Hit events
  532. ' (Public) .InitSnd - sound to use for targets
  533. ' (Public) .AnyUpSw - Set AnyUp switch
  534. ' (Public) .AllDownSw - Set all down switch
  535. ' (Public) .AllDown - All targets down?
  536. ' (Public) .Hit - A target had been hit
  537. ' (Public) .SolHit - Solenoid handler for dropping a target
  538. ' (Public) .SolUnHit - Solenoid handler for raising a target
  539. ' (Public) .SolDropDown - Solenoid handler for Bank down
  540. ' (Public) .SolDropUp - Solenoid handler for Bank reset
  541. ' (Public) .DropSol_On - Reset target bank
  542. ' (Friend) .SetAllDn - check alldown & anyup switches
  543. '
  544. ' cvpmMagnet (create as many as needed)
  545. ' (Public) .InitMagnet - initialise magnet
  546. ' (Public) .CreateEvents - Create Hit/Unhit events
  547. ' (Public) .Solenoid - Set solenoid that controls magnet
  548. ' (Public) .GrabCenter - Magnet grabs ball at center
  549. ' (Public) .MagnetOn - Turn magnet on and off
  550. ' (Public) .X - Move magnet
  551. ' (Public) .Y - Move magnet
  552. ' (Public) .Strength - Change strength
  553. ' (Public) .Size - Change magnet reach
  554. ' (Public) .AddBall - A ball has come within range
  555. ' (Public) .RemoveBall - A ball is out of reach for the magnet
  556. ' (Public) .Balls - Balls currently within magnets reach
  557. ' (Public) .AttractBall - attract ball to magnet
  558. ' (Private) .Update - update all balls (called from timer)
  559. ' (Private) .Reset - handle emulation reset
  560. ' Obsolete
  561. ' (Public) .Range - Change magnet reach
  562.  
  563. ' cvpmTurnTable (create as many as needed)
  564. ' (Public) .InitTurnTable - initialise turntable
  565. ' (Public) .CreateEvents - Create Hit/Unhit events
  566. ' (Public) .MaxSpeed - Maximum speed
  567. ' (Public) .SpinUp - Speedup acceleration
  568. ' (Public) .SpinDown - Retardation
  569. ' (Public) .Speed - Current speed
  570. ' (Public) .MotorOn - Motor On/Off
  571. ' (Public) .SpinCW - Control direction
  572. ' (Public) .SolMotorState - Motor on/off solenoid handler
  573. ' (Public) .AddBall - A ball has come withing range
  574. ' (Public) .RemoveBall - A ball is out of reach for the magnet
  575. ' (Public) .Balls - Balls currently within magnets reach
  576. ' (Public) .AffectBall - affect a ball
  577. ' (Private) .Update - update all balls (called from timer)
  578. ' (Private) .Reset - handle emulation reset
  579.  
  580. ' cvpmMech (create as many as needed)
  581. ' (Public) .Sol1, Sol2 - Controlling solenoids
  582. ' (Public) .MType - type of mechanics
  583. ' (Public) .Length, Steps
  584. ' (Public) .Acc, Ret - Acceleration, retardation
  585. ' (Public) .AddSw - Automatically controlled switches
  586. ' (Public) .AddPulseSw - Automatically pulsed switches
  587. ' (Public) .Callback - Update graphics function
  588. ' (Public) .Start - Start mechanics handler
  589. ' (Public) .Position - Current position
  590. ' (Public) .Speed - Current Speed
  591. ' (Private) .Update
  592. ' (Private) .Reset
  593. '
  594. ' cvpmCaptiveBall (create as many as needed)
  595. ' (Public) .InitCaptive - Initialise captive balls
  596. ' (Public) .CreateEvents - Create events for captive ball
  597. ' (Public) .ForceTrans - Amount of force tranferred to captive ball (0-1)
  598. ' (Public) .MinForce - Minimum force applied to the ball
  599. ' (Public) .NailedBalls - Number of "nailed" balls infront of captive ball
  600. ' (Public) .RestSwitch - Switch activated when ball is in rest position
  601. ' (Public) .Start - Create moving ball etc.
  602. ' (Public) .TrigHit - trigger in front of ball hit (or unhit)
  603. ' (Public) .BallHit - Wall in front of ball hit
  604. ' (Public) .BallReturn - Captive ball has returned to kicker
  605. ' (Private) .Reset
  606. '
  607. ' cvpmVLock (create as many as needed)
  608. ' (Public) .InitVLock - Initialise the visible ball stack
  609. ' (Public) .ExitDir - Balls exit angle (like kickers)
  610. ' (Public) .ExitForce - Force of balls kicked out
  611. ' (Public) .KickForceVar - Vary kickout force
  612. ' (Public) .InitSnd - Sounds to make on kickout
  613. ' (Public) .Balls - Number of balls in Lock
  614. ' (Public) .SolExit - Solenoid event
  615. ' (Public) .CreateEvents - Create events needed
  616. ' (Public) .TrigHit - called from trigger hit event
  617. ' (Public) .TrigUnhit - called from trigger unhit event
  618. ' (Public) .KickHit - called from kicier hit event
  619. '
  620. ' cvpmDips (create as many as needed) => (Dip Switch And/Or Table Options Menu)
  621. ' (Public) .AddForm - create a form (AKA dialogue)
  622. ' (Public) .AddChk - add a chckbox
  623. ' (Public) .AddChkExtra - - "" - for non-dip settings
  624. ' (Public) .AddFrame - add a frame with checkboxes or option buttons
  625. ' (Public) .AddFrameExtra - - "" - for non-dip settings
  626. ' (Public) .AddLabel - add a label (text string)
  627. ' (Public) .ViewDips - Show form
  628. ' (Public) .ViewDipsExtra - - "" - with non-dip settings
  629. '
  630. ' cvpmImpulseP (create as many as needed) => (Impulse Plunger Object using a Trigger to Plunge Manual/Auto)
  631. ' (Public) .InitImpulseP - Initialise Impulse Plunger Object (Trigger, Plunger Power, Time to Full Plunge [0 = Auto])
  632. ' (Public) .CreateEvents - Create Hit/Unhit events
  633. ' (Public) .Strength - Change plunger strength
  634. ' (Public) .Time - Change plunger time (in seconds) to full plunger strength (0 = Auto Plunger)
  635. ' (Public) .Pullback - Pull the plunger back
  636. ' (Public) .Fire - Fires / Releases the Plunger (Manual or Auto depending on Timing Value given)
  637. ' (Public) .AutoFire - Fires / Releases the Plunger at Maximum Strength +/- Random variation (i.e. Instant Auto)
  638. ' (Public) .Switch - Switch Number to activate when ball is sitting on plunger trigger (if any)
  639. ' (Public) .Random - Sets the multiplier level of random variance to add (0 = No Variance / Default)
  640. ' (Public) .InitEntrySnd - Plays Sound as Plunger is Pulled Back
  641. ' (Public) .InitExitSnd - Plays Sound as Plunger is Fired (WithBall,WithoutBall)
  642. '
  643. ' Generic solenoid handlers:
  644. ' --------------------------
  645. ' vpmSolFlipper flipObj1, flipObj2 - "flips flippers". Set unused to Nothing
  646. ' vpmSolFlip2 flipObj1, flipObj2, flipSpeedUp, flipSpeedDn, sndOn). Set unused to Nothing
  647. ' vpmSolDiverter divObj, sound - open/close diverter (flipper) with/without sound
  648. ' vpmSolWall wallObj, sound - Raise/Drop wall with/without sound
  649. ' vpmSolToggleWall wall1, wall2, sound - Toggle between two walls
  650. ' vpmSolToggleObj obj1,obj2,sound - Toggle any objects
  651. ' vpmSolAutoPlunger plungerObj, var, enabled - Autoplunger/kickback
  652. ' vpmSolAutoPlungeS plungerObj, sound, var, enabled - Autoplunger/kickback With Specified Sound To Play
  653. ' vpmSolGate obj, sound - Open/close gate
  654. ' vpmSolSound sound - Play sound only
  655. ' vpmFlasher flashObj - Flashes flasher
  656. '
  657. ' Generating events:
  658. ' ------------------
  659. ' vpmCreateEvents
  660. ' cpmCreateLights
  661. '
  662. ' Variables declared (to be filled in):
  663. ' ---------------------------------------
  664. ' SolCallback() - handler for each solenoid
  665. ' Lights() - Lamps
  666. '
  667. ' Constants used (must be defined):
  668. ' ---------------------------------
  669. ' UseSolenoids - Update solenoids
  670. ' MotorCallback - Called once every update for mechanics or custom sol handler
  671. ' UseLamps - Update lamps
  672. ' LampCallback - Sub to call after lamps are updated
  673. ' (or every update if UseLamps is false)
  674. ' GICallback - Sub to call to update GI strings
  675. ' GICallback2 - Sub to call to update GI strings
  676. ' SFlipperOn - Flipper activate sound
  677. ' SFlipperOff - Flipper deactivate sound
  678. ' SSolenoidOn - Solenoid activate sound
  679. ' SSolenoidOff - Solenoid deactivate sound
  680. ' SCoin - Coin Sound
  681. ' ExtraKeyHelp - Game specific keys in help window
  682. '
  683. ' Exported variables:
  684. ' -------------------
  685. ' vpmTimer - Timer class for PulseSwitch etc
  686. ' vpmNudge - Class for table nudge handling
  687. '-----------------------------------------------------
  688. Private Function PinMAMEInterval
  689. If VPBuildVersion >= 10200 Then
  690. PinMAMEInterval = -1 ' VP10.2 introduced special frame-sync'ed timers
  691. Else
  692. If VPBuildVersion >= 10000 Then
  693. PinMAMEInterval = 3 ' as old VP9 timers pretended to run at 1000Hz but actually did only a max of 100Hz (e.g. corresponding nowadays to interval=10), we do something inbetween for VP10+ by default
  694. Else
  695. PinMAMEInterval = 1
  696. End If
  697. End If
  698. End Function
  699.  
  700. Private Const conStackSw = 8 ' Stack switches
  701. Private Const conMaxBalls = 13 ' Because of Apollo 13
  702. Private Const conMaxTimers = 20 ' Spinners can generate a lot of timers
  703. Private Const conTimerPulse = 40 ' Timer runs at 25Hz
  704. Private Const conFastTicks = 4 ' Fast is 4 times per timer pulse
  705. Private Const conMaxSwHit = 5 ' Don't stack up more than 5 events for each switch
  706.  
  707. ' DEPRECATED Flipper constants:
  708. Private Const conFlipRetStrength = 0.01 ' Flipper return strength
  709. Private Const conFlipRetSpeed = 0.137 ' Flipper return speed
  710.  
  711. Function CheckScript(file) 'Checks Tables and Scripts directories for specified vbs file, and if it exitst, will load it.
  712. CheckScript = False
  713. On Error Resume Next
  714. Dim TablesDirectory:TablesDirectory = Left(UserDirectory,InStrRev(UserDirectory,"\",InStrRev(UserDirectory,"\")-1))&"Tables\"
  715. Dim ScriptsDirectory:ScriptsDirectory = Left(UserDirectory,InStrRev(UserDirectory,"\",InStrRev(UserDirectory,"\")-1))&"Scripts\"
  716. dim check:Set check = CreateObject("Scripting.FileSystemObject")
  717. If check.FileExists(tablesdirectory & file) Or check.FileExists(scriptsdirectory & file) Or check.FileExists(file) Then CheckScript = True
  718. On Error Goto 0
  719. End Function
  720.  
  721. Function LoadScript(file) 'Checks Tables and Scripts directories for specified vbs file, and if it exitst, will load it.
  722. LoadScript = False
  723. On Error Resume Next
  724. If CheckScript(file) Then ExecuteGlobal GetTextFile(file):LoadScript = True
  725. On Error Goto 0
  726. End Function
  727.  
  728. ' Dictionary
  729. ' At one point, Microsoft had made Scripting.Dictionary "unsafe for scripting", but it's
  730. ' been a long time since that was true. So now, to maintain compatibility with all tables
  731. ' and scripts that use cvpmDictionary, this class is now a simple wrapper around Microsoft's
  732. ' more efficient implementation.
  733. Class cvpmDictionary
  734. Private mDict
  735. Private Sub Class_Initialize : Set mDict = CreateObject("Scripting.Dictionary") : End Sub
  736.  
  737. ' DEPRECATED: MS Dictionaries are not index-based. Use "Exists" method instead.
  738. Private Function FindKey(aKey)
  739. Dim ii, key : FindKey = -1
  740. If mDict.Count > 0 Then
  741. ii = 0
  742. For Each key In mDict.Keys
  743. If key = aKey Then FindKey = ii : Exit Function
  744. Next
  745. End If
  746. End Function
  747.  
  748. Public Property Get Count : Count = mDict.Count : End Property
  749.  
  750. Public Property Get Item(aKey)
  751. Item = Empty
  752. If mDict.Exists(aKey) Then
  753. If IsObject(mDict(aKey)) Then
  754. Set Item = mDict(aKey)
  755. Else
  756. Item = mDict(aKey)
  757. End If
  758. End If
  759. End Property
  760.  
  761. Public Property Let Item(aKey, aData)
  762. If IsObject(aData) Then
  763. Set mDict(aKey) = aData
  764. Else
  765. mDict(aKey) = aData
  766. End If
  767. End Property
  768.  
  769. Public Property Set Key(aKey)
  770. ' This function is (and always has been) a no-op. Previous definition
  771. ' just looked up aKey in the keys list, and if found, set the key to itself.
  772. End Property
  773.  
  774. Public Sub Add(aKey, aItem)
  775. If IsObject(aItem) Then
  776. Set mDict(aKey) = aItem
  777. Else
  778. mDict(aKey) = aItem
  779. End If
  780. End Sub
  781.  
  782. Public Sub Remove(aKey) : mDict.Remove(aKey) : End Sub
  783. Public Sub RemoveAll : mDict.RemoveAll : End Sub
  784. Public Function Exists(aKey) : Exists = mDict.Exists(aKey) : End Function
  785. Public Function Items : Items = mDict.Items : End Function
  786. Public Function Keys : Keys = mDict.Keys : End Function
  787. End Class
  788.  
  789. '--------------------
  790. ' Timer
  791. '--------------------
  792. Class cvpmTimer
  793. Private mQue, mNow, mTimers
  794. Private mSlowUpdates, mFastUpdates, mResets, mFastTimer
  795.  
  796. Private Sub Class_Initialize
  797. ReDim mQue(conMaxTimers) : mNow = 0 : mTimers = 0
  798. Set mSlowUpdates = New cvpmDictionary
  799. Set mFastUpdates = New cvpmDictionary
  800. Set mResets = New cvpmDictionary
  801. End Sub
  802.  
  803. Public Sub InitTimer(aTimerObj, aFast)
  804. If aFast Then
  805. Set mFastTimer = aTimerObj
  806. aTimerObj.TimerInterval = conTimerPulse \ conFastTicks
  807. aTimerObj.TimerEnabled = False
  808. vpmBuildEvent aTimerObj, "Timer", "vpmTimer.FastUpdate"
  809. Else
  810. aTimerObj.Interval = conTimerPulse : aTimerObj.Enabled = True
  811. vpmBuildEvent aTimerObj, "Timer", "vpmTimer.Update"
  812. End If
  813. End Sub
  814.  
  815. Sub EnableUpdate(aClass, aFast, aEnabled)
  816. On Error Resume Next
  817. If aFast Then
  818. If aEnabled Then mFastUpdates.Add aClass, 0 : Else mFastUpdates.Remove aClass
  819. mFastTimer.TimerEnabled = mFastUpdates.Count > 0
  820. Else
  821. If aEnabled Then mSlowUpdates.Add aClass, 0 : Else mSlowUpdates.Remove aClass
  822. End If
  823. End Sub
  824.  
  825. Public Sub Reset
  826. Dim obj : For Each obj In mResets.Keys : obj.Reset : Next
  827. End Sub
  828.  
  829. Public Sub FastUpdate
  830. Dim obj : For Each obj In mFastUpdates.Keys : obj.Update : Next
  831. End Sub
  832.  
  833. Public Sub Update
  834. Dim ii, jj, sw, obj, mQuecopy
  835.  
  836. For Each obj In mSlowUpdates.Keys : obj.Update : Next
  837. If mTimers = 0 Then Exit Sub
  838. mNow = mNow + 1 : ii = 1
  839.  
  840. Do While ii <= mTimers
  841. If mQue(ii)(0) <= mNow Then
  842. If mQue(ii)(1) = 0 Then
  843. If isObject(mQue(ii)(3)) Then
  844. Call mQue(ii)(3)(mQue(ii)(2))
  845. ElseIf varType(mQue(ii)(3)) = vbString Then
  846. If mQue(ii)(3) > "" Then Execute mQue(ii)(3) & " " & mQue(ii)(2) & " "
  847. End If
  848. mTimers = mTimers - 1
  849. For jj = ii To mTimers : mQue(jj) = mQue(jj+1) : Next : ii = ii - 1
  850. ElseIf mQue(ii)(1) = 1 Then
  851. mQuecopy = mQue(ii)(2)
  852. Controller.Switch(mQuecopy) = False
  853. mQue(ii)(0) = mNow + mQue(ii)(4) : mQue(ii)(1) = 0
  854. Else '2
  855. mQuecopy = mQue(ii)(2)
  856. Controller.Switch(mQuecopy) = True
  857. mQue(ii)(1) = 1
  858. End If
  859. End If
  860. ii = ii + 1
  861. Loop
  862. End Sub
  863.  
  864. Public Sub AddResetObj(aObj) : mResets.Add aObj, 0 : End Sub
  865.  
  866. Public Sub PulseSw(aSwNo) : PulseSwitch aSwNo, 0, 0 : End Sub
  867.  
  868. Public Default Sub PulseSwitch(aSwNo, aDelay, aCallback)
  869. Dim ii, count, last
  870. count = 0
  871. For ii = 1 To mTimers
  872. If mQue(ii)(1) > 0 And mQue(ii)(2) = aSwNo Then count = count + 1 : last = ii
  873. Next
  874. If count >= conMaxSwHit Or mTimers = conMaxTimers Then Exit Sub
  875. mTimers = mTimers + 1 : mQue(mTimers) = Array(mNow, 2, aSwNo, aCallback, aDelay\conTimerPulse)
  876. If count Then mQue(mTimers)(0) = mQue(last)(0) + mQue(last)(1)
  877. End Sub
  878.  
  879. Public Sub AddTimer(aDelay, aCallback)
  880. If mTimers = conMaxTimers Then Exit Sub
  881. mTimers = mTimers + 1
  882. mQue(mTimers) = Array(mNow + aDelay \ conTimerPulse, 0, 0, aCallback)
  883. End Sub
  884.  
  885. Public Sub AddTimer2(aDelay, aCallback, aID)
  886. If mTimers = conMaxTimers Then Exit Sub
  887. mTimers = mTimers + 1
  888. mQue(mTimers) = Array(mNow + aDelay \ conTimerPulse, 0, aID, aCallback)
  889. End Sub
  890. End Class
  891.  
  892. '--------------------
  893. ' Trough
  894. '--------------------
  895. Class cvpmTrough
  896. ' Takes over for older cvpmBallStack in "trough mode". Theory of operation:
  897. ' A trough can hold up to N balls, and has N*2 "slots". A ball effectively takes
  898. ' up two slots, so no two adjacent slots (0 and 1) can be occupied at the same time.
  899. ' Switches are assigned to even slots only, which means that as balls move through
  900. ' the trough, each switch is allowed to flip between open and closed.
  901. ' Slot 0 is the exit, and can have additional balls "stacked" on it, simulating balls
  902. ' falling onto the exit kicker instead of coming in from the entrance. Extra balls
  903. ' can be queued up at the entrance, and will enter the trough only if there's room
  904. ' for them.
  905.  
  906. Private mSlot(), mSw(), mEntrySw
  907. Private mBallsInEntry, mMaxBallsPerKick, mStackExitBalls
  908. Private mExitKicker, mExitDir, mExitForce, mDirVar, mForceVar
  909. Private mSounds
  910.  
  911. ' If you want to see what the trough is doing internally, add a TextBox to your table
  912. ' named "DebugBox" (recommend Courier New or FixedSys at a small font size) and set
  913. ' this variable to true via .isDebug = True.
  914. Private mDebug
  915.  
  916. Private Sub Class_Initialize
  917. Dim ii
  918.  
  919. ReDim mSw(conMaxBalls), mSlot(conMaxBalls * 2)
  920. For ii = 0 to UBound(mSlot) : mSlot(ii) = 0 : Next ' All slots empty to start
  921. For ii = 0 to UBound(mSw) : mSw(ii) = 0 : Next ' All switches unassigned to start.
  922. mEntrySw = 0
  923.  
  924. Set mExitKicker = Nothing
  925. mExitDir = 0 : mExitForce = 1 : mDirVar = 0 : mForceVar = 0
  926. mBallsInEntry = 0 : mMaxBallsPerKick = 1 : mStackExitBalls = 1
  927.  
  928. Set mSounds = New cvpmDictionary
  929.  
  930. mDebug = False
  931.  
  932. If Not IsObject(vpmTrough) Then Set vpmTrough = Me
  933. End Sub
  934.  
  935. Public Property Let IsTrough(aYes)
  936. If aYes Then
  937. Set vpmTrough = Me
  938. ElseIf Me Is vpmTrough Then
  939. Set vpmTrough = Nothing
  940. End If
  941. End Property
  942.  
  943. Public Property Get IsTrough
  944. IsTrough = (Me Is vpmTrough)
  945. End Property
  946.  
  947. ' Initialization
  948.  
  949. Public Property Let isDebug(enabled) : mDebug = enabled : End Property
  950.  
  951. Public Property Let Size(aSize)
  952. Dim oldSize, newSize, ii
  953. oldSize = UBound(mSw)
  954. newSize = vpMax(1, aSize)
  955.  
  956. ReDim Preserve mSlot(newSize * 2)
  957. ReDim Preserve mSw(newSize)
  958. For ii = oldSize+1 To newSize : mSw(ii) = 0 : Next
  959. For ii = (oldSize*2) + 1 to (newSize*2) : mSlot(ii) = 0 : Next
  960. End Property
  961. Public Property Get Size : Size = UBound(mSw) : End Property
  962.  
  963. ' Set EntrySw = 0 if you want balls to just fall into the trough automatically.
  964. ' Set it to a real switch number to indicate that a ball is occupying an entry kicker.
  965. ' The ROM in the controller is then responsible for kicking the ball into the trough.
  966. Public Property Let EntrySw(swNo) : mEntrySw = swNo : End Property
  967.  
  968. ' Assign switches, starting from slot 0 and going to entrance.
  969. ' This sub allows you to pass in as many switches as you wish.
  970. Public Sub InitSwitches(switchArray)
  971. If Not IsArray(switchArray) Then
  972. Err.Raise 17, "cvpmTrough.InitSwitches: Input must be an array."
  973. End If
  974.  
  975. Dim ii
  976. For ii = 0 to UBound(mSw)
  977. If ii > UBound(switchArray) Then
  978. mSw(ii) = 0
  979. Else
  980. mSw(ii) = switchArray(ii)
  981. End If
  982. Next
  983. End Sub
  984.  
  985. ' Alternative: Assign a switch to a specific slot.
  986. Public Sub AddSw(slotNo, swNo)
  987. If slotNo < 0 OR slotNo > UBound(mSw) Then Exit Sub
  988. mSw(slotNo) = swNo
  989. End Sub
  990.  
  991. ' MaxBallsPerKick: Kick up to N balls total per exit kick. Balls are only kicked from Slot 0.
  992. ' StackExitBalls: Automatically stack up to N balls in Slot 0 regardless of where they came from.
  993.  
  994. ' Example: Subway where exit kicker is on the same level as the trough and a ball can
  995. ' come in from the exit: StackExitBalls = 1, MaxBallsPerKick = 2. If Slot 0 has 1
  996. ' ball and Slot 1 is occupied, only one ball will be kicked. If Slot 0 has 2 or more
  997. ' balls, it'll kick out 2 balls.
  998.  
  999. ' Example: Twilight Zone Slot Kicker: Kicker is below trough, so if a ball is in the
  1000. ' exit chute, another ball can fall into the chute as well whether it came in from the
  1001. ' exit (Slot Machine) or any other entrance (Piano, Camera). In both cases, the kicker
  1002. ' will eject 2 balls at once. Set StackExitBalls = 2, maxBallsPerKick = 2 to simulate.
  1003.  
  1004. Public Property Let MaxBallsPerKick(n) : mMaxBallsPerKick = vpMax(1, n) : End Property
  1005. Public Property Let StackExitBalls(n) : mStackExitBalls = vpMax(1, n) : End Property
  1006.  
  1007. Public Sub InitExit(aKicker, aDir, aForce)
  1008. If TypeName(aKicker) <> "Kicker" Then
  1009. Err.Raise 17, "cvpmTrough.InitExit: Cannot use object of type '" & TypeName(aKicker) & "'."
  1010. End If
  1011.  
  1012. Set mExitKicker = aKicker
  1013. mExitDir = aDir
  1014. mExitForce = vpMax(1, aForce)
  1015. End Sub
  1016.  
  1017. Public Sub InitExitVariance(aDirVar, aForceVar)
  1018. mDirVar = aDirVar
  1019. mForceVar = aForceVar
  1020. End Sub
  1021.  
  1022. ' Setup sounds
  1023. Public Sub InitEntrySounds(addSound, entrySoundEmpty, entrySoundBall)
  1024. mSounds.Item("add") = addSound
  1025. mSounds.Item("entry") = entrySoundEmpty
  1026. mSounds.Item("entryBall") = entrySoundBall
  1027. End Sub
  1028.  
  1029. Public Sub InitExitSounds(exitSoundEmpty, exitSoundBall)
  1030. mSounds.Item("exit") = exitSoundEmpty
  1031. mSounds.Item("exitBall") = exitSoundBall
  1032. End Sub
  1033.  
  1034. ' Start trough with this many balls
  1035. Public Property Let Balls(numBalls)
  1036. Dim ii, ballsAdded
  1037.  
  1038. ' First clear all slots.
  1039. For ii = 0 to UBound(mSlot) : mSlot(ii) = 0 : Next
  1040.  
  1041. ' Now put a ball in each even-numbered slot up to the number requested.
  1042. ' First, stack exit slot. (Note, we may get a negative number. vpMin/vpMax prevent that.)
  1043. mSlot(0) = vpMax(0, vpMin(mStackExitBalls, numBalls))
  1044. ballsAdded = mSlot(0)
  1045.  
  1046. ' Fill remaining slots.
  1047. For ii = 1 to vpMin(numBalls - mSlot(0), UBound(mSw))
  1048. mSlot(ii*2) = 1
  1049. ballsAdded = ballsAdded + 1
  1050. Next
  1051.  
  1052. ' If we asked to put more balls in the trough than it can handle, queue up the rest.
  1053. mBallsInEntry = vpMax(0, numBalls-ballsAdded)
  1054.  
  1055. UpdateTroughSwitches
  1056. End Property
  1057.  
  1058. Public Property Get Balls
  1059. Balls = 0
  1060. Dim ii : For ii = 0 to UBound(mSlot) : Balls = Balls + mSlot(ii) : Next
  1061. End Property
  1062.  
  1063. Public Property Get BallsPending : BallsPending = mBallsInEntry : End Property
  1064.  
  1065. ' Auto-generate events for any entry kickers (eg. outhole, TZ Camera and Piano, etc.)
  1066. ' Accepts a single kicker, an Array, or a Collection.
  1067. Public Sub CreateEvents(aName, aKicker)
  1068. Dim obj, tmp
  1069. If Not vpmCheckEvent(aName, Me) Then Exit Sub
  1070. vpmSetArray tmp, aKicker
  1071. For Each obj In tmp
  1072. If isObject(obj) Then
  1073. vpmBuildEvent obj, "Hit", aName & ".AddBall Me"
  1074. Else
  1075. vpmBuildEvent mKicker, "Hit", aName & ".AddBall Me"
  1076. End If
  1077. Next
  1078. End Sub
  1079.  
  1080. ' VPM Update management
  1081.  
  1082. Private Property Let NeedUpdate(aEnabled) : vpmTimer.EnableUpdate Me, False, aEnabled : End Property
  1083.  
  1084. Public Sub Reset
  1085. Dim mEntrySwcopy
  1086. UpdateTroughSwitches
  1087. If mEntrySw Then
  1088. mEntrySwcopy = mEntrySw
  1089. Controller.Switch(mEntrySwcopy) = (mBallsInEntry > 0)
  1090. End If
  1091. End Sub
  1092.  
  1093. Public Sub Update
  1094. NeedUpdate = AdvanceBalls
  1095. UpdateTroughSwitches
  1096. End Sub
  1097.  
  1098. ' Switch and slot management
  1099.  
  1100. Private Sub setSw(slotNo, enabled)
  1101. Dim mSwcopy
  1102. If mSw(slotNo) Then
  1103. mSwcopy = mSw(slotNo)
  1104. Controller.Switch(mSwcopy) = enabled
  1105. End If
  1106. End Sub
  1107.  
  1108. Private Sub UpdateTroughSwitches
  1109. Dim ii, mSwcopy
  1110. For ii = 0 to UBound(mSw)
  1111. If mSw(ii) Then
  1112. mSwcopy = mSw(ii)
  1113. Controller.Switch(mSwcopy) = (mSlot(ii*2) > 0)
  1114. End If
  1115. Next
  1116. If mDebug Then UpdateDebugBox
  1117. End Sub
  1118.  
  1119. Private Sub UpdateDebugBox ' Requires a textbox named DebugBox
  1120. Dim str, ii, mSwcopy
  1121. str = "Entry: " & mBallsInEntry & " (sw" & mEntrySw & " = "
  1122. If mEntrySw > 0 Then
  1123. mSwcopy = mEntrySw
  1124. str = str & Controller.Switch(mSwcopy)
  1125. Else
  1126. str = str & "n/a"
  1127. End If
  1128. str = str & ")" & vbNewLine
  1129.  
  1130. str = str & "["
  1131. For ii = UBound(mSlot) To 0 Step -1 : str = str & mSlot(ii) : Next
  1132. str = str & "]" & vbNewLine
  1133.  
  1134. str = str & "["
  1135. For ii = UBound(mSlot) To 0 Step -1
  1136. If ii Mod 2 = 0 Then
  1137. If mSw(ii\2) Then
  1138. mSwcopy = mSw(ii\2)
  1139. If Controller.Switch(mSwcopy) Then
  1140. str = str & "1"
  1141. Else
  1142. str = str & "0"
  1143. End If
  1144. Else
  1145. str = str & "-"
  1146. End If
  1147. Else
  1148. str = str & " "
  1149. End If
  1150. Next
  1151. str = str & "]"
  1152.  
  1153. DebugBox.Text = str
  1154. End Sub
  1155.  
  1156. Private Function AdvanceBalls
  1157. Dim ii, canMove, maxSlot
  1158. maxSlot = UBound(mSlot)
  1159. AdvanceBalls = False
  1160.  
  1161. ' Move balls through slots, one slot at a time.
  1162. For ii = 0 to maxSlot
  1163. If mSlot(ii) Then ' Ball in this slot.
  1164. canMove = False
  1165.  
  1166. ' Can this ball move? (Slot 0 = no)
  1167. If ii = 0 Then
  1168. ' Slot 0 never moves (except when ejected)
  1169. canMove = False
  1170. ElseIf ii = 1 Then
  1171. ' Slot 1 automatically moves to Slot 0
  1172. canMove = True
  1173. ElseIf ii = 2 Then
  1174. ' Slot 2 moves if the number of balls in slot 0 is less than the stack target.
  1175. canMove = (mSlot(0) < mStackExitBalls)
  1176. Else
  1177. ' Only move if there is no ball in ii-1 or ii-2.
  1178. canMove = (mSlot(ii-2) = 0) AND (mSlot(ii-1) = 0)
  1179. End If
  1180.  
  1181. If canMove Then
  1182. mSlot(ii) = mSlot(ii) - 1
  1183. mSlot(ii-1) = mSlot(ii-1) + 1
  1184. AdvanceBalls = True ' Mark balls as having moved.
  1185. End If
  1186. End If
  1187. Next
  1188.  
  1189. ' If balls are supposed to fall into the trough without going through a kicker,
  1190. ' see if any balls are pending and try to add one automatically if so.
  1191. If mBallsInEntry > 0 AND mEntrySw <= 0 Then
  1192. AdvanceBalls = AddBallAtEntrance OR AdvanceBalls
  1193. End If
  1194. End Function
  1195.  
  1196. ' Ball management
  1197.  
  1198. Private Function AddBallAtEntrance
  1199. Dim mSwcopy
  1200. Dim maxSlot : maxSlot = UBound(mSlot)
  1201. AddBallAtEntrance = False
  1202.  
  1203. ' Only add a ball if there's room for it at the entrance.
  1204. ' If the trough is full (or the entrance is occupied), the ball will remain
  1205. ' in the entry queue. In a kicker-gated trough, the entry switch will remain
  1206. ' pressed down, usually resulting in the machine retrying the load. In a fall-in
  1207. ' trough, the ball will just remain queued until the entrance opens up.
  1208. If mSlot(maxSlot) = 0 AND mSlot(maxSlot-1) = 0 Then
  1209. mSlot(maxSlot) = 1
  1210. mBallsInEntry = vpMax(0, mBallsInEntry - 1)
  1211. If mBallsInEntry = 0 AND mEntrySw Then
  1212. mSwcopy = mEntrySw
  1213. Controller.Switch(mSwcopy) = False
  1214. End If
  1215. AddBallAtEntrance = True
  1216. End If
  1217. End Function
  1218.  
  1219. Public Sub AddBall(aKicker)
  1220. Dim mSwcopy
  1221. Dim addDone : addDone = False
  1222. If IsObject(aKicker) Then
  1223. aKicker.DestroyBall
  1224. If aKicker Is mExitKicker Then
  1225. ' Ball fell in from exit. Stack it up on Slot 0.
  1226. mSlot(0) = mSlot(0) + 1
  1227. NeedUpdate = True
  1228. UpdateTroughSwitches
  1229. addDone = True
  1230. End If
  1231. End If
  1232.  
  1233. If Not addDone Then
  1234. ' Ball came in from entrance. Queue it up for entry.
  1235. mBallsInEntry = mBallsInEntry + 1
  1236. If mEntrySw > 0 Then
  1237. mSwcopy = mEntrySw
  1238. ' Trough has an entry kicker. Ball will not enter trough
  1239. ' until the entry solenoid is fired.
  1240. Controller.Switch(mSwcopy) = True
  1241. End If
  1242. NeedUpdate = True
  1243. End If
  1244.  
  1245. PlaySound mSounds.Item("add")
  1246. End Sub
  1247.  
  1248. ' Use solCallback(solNo) on the trough entry kicker solenoid.
  1249. Public Sub solIn(aEnabled)
  1250. If aEnabled Then
  1251. If mBallsInEntry > 0 Then
  1252. NeedUpdate = AddBallAtEntrance
  1253. PlaySound mSounds.Item("entryBall")
  1254. Else
  1255. PlaySound mSounds.Item("entry")
  1256. End If
  1257. End If
  1258. End Sub
  1259. Public Sub EntrySol_On : solIn(true) : End Sub
  1260.  
  1261. ' Use solCallback(solNo) on the trough exit kicker solenoid.
  1262. Public Sub solOut(aEnabled)
  1263. Dim iiBall, kDir, kForce, kBaseDir, ballsEjected
  1264. ballsEjected = 0
  1265.  
  1266. If aEnabled Then
  1267. For iiBall = 0 to (mMaxBallsPerKick - 1)
  1268. kDir = (mExitDir + (Rnd - 0.5) * mDirVar)
  1269. kForce = vpMax(1, mExitForce + (Rnd - 0.5) * mForceVar * (0.8 * iiBall)) ' Dampen force a bit on subsequent balls.
  1270.  
  1271. If mSlot(0) > 0 Then
  1272. ' Remove ball from this slot.
  1273. mSlot(0) = mSlot(0) - 1
  1274. If isObject(mExitKicker) Then
  1275. vpmTimer.AddTimer ballsEjected*200, "vpmCreateBall(" & mExitKicker.Name & ").Kick " &_
  1276. CInt(kDir) & "," & Replace(kForce,",",".") & ", 0 '"
  1277. End If
  1278.  
  1279. ballsEjected = ballsEjected + 1
  1280. End If
  1281. Next
  1282.  
  1283. If ballsEjected > 0 Then
  1284. PlaySound mSounds.Item("exitBall")
  1285. UpdateTroughSwitches
  1286. NeedUpdate = True
  1287. Else
  1288. PlaySound mSounds.Item("exit")
  1289. End If
  1290. End If
  1291. End Sub
  1292. Public Sub ExitSol_On : solOut(true) : End Sub
  1293. End Class
  1294.  
  1295. '--------------------
  1296. ' Saucer
  1297. '--------------------
  1298. Class cvpmSaucer
  1299. ' Takes over for older cvpmBallStack in "saucer mode".
  1300.  
  1301. Private mSw, mKicker, mExternalKicker
  1302. Private mDir(1), mForce(1), mZForce(1), mDirVar, mForceVar
  1303. Private mSounds
  1304.  
  1305. Private Sub Class_Initialize
  1306. mSw = 0
  1307.  
  1308. mKicker = 0
  1309. mExternalKicker = 0
  1310. mDir(0) = 0 : mForce(0) = 1 : mZForce(0) = 0
  1311. mDir(1) = 0 : mForce(1) = 1 : mZForce(1) = 0
  1312. mDirVar = 0 : mForceVar = 0
  1313.  
  1314. Set mSounds = New cvpmDictionary
  1315. End Sub
  1316.  
  1317. ' Initialization
  1318.  
  1319. Public Sub InitKicker(aKicker, aSw, aDir, aForce, aZForce)
  1320. If TypeName(aKicker) <> "Kicker" Then
  1321. Err.Raise 17, "cvpmSaucer.InitKicker: Cannot use object of type '" & TypeName(aKicker) & "'."
  1322. End If
  1323.  
  1324. Set mKicker = aKicker
  1325. mSw = aSw
  1326. mDir(0) = aDir
  1327. mForce(0) = vpMax(1, aForce)
  1328. mZForce(0) = vpMax(0, aZForce)
  1329. End Sub
  1330.  
  1331. Public Sub InitExitVariance(aDirVar, aForceVar)
  1332. mDirVar = aDirVar
  1333. mForceVar = aForceVar
  1334. End Sub
  1335.  
  1336. ' Alternate kick params (simulates a saucer with two kickers)
  1337. Public Sub InitAltKick(aDir, aForce, aZForce)
  1338. mDir(1) = aDir
  1339. mForce(1) = vpMax(1, aForce)
  1340. mZForce(1) = vpMax(0, aZForce)
  1341. End Sub
  1342.  
  1343. ' Setup sounds
  1344. Public Sub InitSounds(addSound, exitSoundEmpty, exitSoundBall)
  1345. mSounds.Item("add") = addSound
  1346. mSounds.Item("exit") = exitSoundEmpty
  1347. mSounds.Item("exitBall") = exitSoundBall
  1348. End Sub
  1349.  
  1350. ' Generate hit event for the kicker(s) associated with this saucer.
  1351. ' Accepts a single kicker, an Array, or a Collection.
  1352. Public Sub CreateEvents(aName, aKicker)
  1353. Dim obj, tmp
  1354. If Not vpmCheckEvent(aName, Me) Then Exit Sub
  1355. vpmSetArray tmp, aKicker
  1356. For Each obj In tmp
  1357. If isObject(obj) Then
  1358. vpmBuildEvent obj, "Hit", aName & ".AddBall Me"
  1359. Else
  1360. vpmBuildEvent mKicker, "Hit", aName & ".AddBall Me"
  1361. End If
  1362. Next
  1363. End Sub
  1364.  
  1365. ' Ball management
  1366.  
  1367. Public Sub AddBall(aKicker)
  1368. Dim mSwcopy
  1369. If isObject(aKicker) Then
  1370. If aKicker Is mKicker Then
  1371. mKicker.Enabled = False
  1372. mExternalKicker = 0
  1373. Else
  1374. aKicker.Enabled = False
  1375. Set mExternalKicker = aKicker
  1376. End If
  1377. Else
  1378. mKicker.Enabled = False
  1379. mExternalKicker = 0
  1380. End If
  1381.  
  1382. If mSw Then
  1383. mSwcopy = mSw
  1384. Controller.Switch(mSwcopy) = True
  1385. End If
  1386. PlaySound mSounds.Item("add")
  1387. End Sub
  1388.  
  1389. Public Property Get HasBall
  1390. HasBall = False
  1391. If IsObject(mExternalKicker) Then
  1392. HasBall = True
  1393. Else
  1394. HasBall = Not mKicker.Enabled
  1395. End If
  1396. End Property
  1397.  
  1398. ' SolCallback solNo, "mySaucer.solOut"
  1399. Public Sub solOut(aEnabled) : If aEnabled Then KickOut 0 : End If : End Sub
  1400. Public Sub ExitSol_On : KickOut 0 : End Sub
  1401.  
  1402. ' SolCallback solNo, "mySaucer.solOutAlt"
  1403. Public Sub solOutAlt(aEnabled) : If aEnabled Then KickOut 1 : End If : End Sub
  1404. Public Sub ExitAltSol_On : KickOut 1 : End Sub
  1405.  
  1406. Private Sub KickOut(kickIndex)
  1407. Dim mSwcopy
  1408. If HasBall Then
  1409. Dim kDir, kForce, kZForce
  1410.  
  1411. kDir = mDir(kickIndex) + (Rnd - 0.5)*mDirVar
  1412. kForce = vpMax(1, mForce(kickIndex) + (Rnd - 0.5)*mForceVar)
  1413. kZForce = mZForce(kickIndex)
  1414.  
  1415. If IsObject(mExternalKicker) Then
  1416. ' Transfer ball to internal kicker and remove relationship
  1417. vpmCreateBall mKicker
  1418. mExternalKicker.DestroyBall
  1419. mExternalKicker.Enabled = True
  1420. Else
  1421. mKicker.Enabled = True
  1422. End If
  1423.  
  1424. mKicker.Kick kDir, kForce, kZForce
  1425. If mSw Then
  1426. mSwcopy = mSw
  1427. Controller.Switch(mSwcopy) = False
  1428. End If
  1429. PlaySound mSounds.Item("exitBall")
  1430. Else
  1431. PlaySound mSounds.Item("exit")
  1432. End If
  1433. End Sub
  1434. End Class
  1435.  
  1436. '--------------------
  1437. ' BallStack (DEPRECATED/LEGACY)
  1438. ' Known issues:
  1439. ' - Adding more balls than conMaxBalls will crash the script.
  1440. ' - If there are more balls in trough than are ever used in a game (eg. Bride of Pinbot),
  1441. ' one or more trough switches will be permanently stuck down and may result in a ROM test report.
  1442. ' - Trough does not handle stacking balls at exit.
  1443. ' - Saucer mode is essentially a hack on top of the trough logic.
  1444. '--------------------
  1445. Class cvpmBallStack
  1446. Private mSw(), mEntrySw, mBalls, mBallIn, mBallPos(), mSaucer, mBallsMoving
  1447. Private mInitKicker, mExitKicker, mExitDir, mExitForce
  1448. Private mExitDir2, mExitForce2
  1449. Private mEntrySnd, mEntrySndBall, mExitSnd, mExitSndBall, mAddSnd
  1450. Public KickZ, KickBalls, KickForceVar, KickAngleVar
  1451.  
  1452. Private Sub Class_Initialize
  1453. ReDim mSw(conStackSw), mBallPos(conMaxBalls)
  1454. mBallIn = 0 : mBalls = 0 : mExitKicker = 0 : mInitKicker = 0 : mBallsMoving = False
  1455. KickBalls = 1 : mSaucer = False : mExitDir = 0 : mExitForce = 0
  1456. mExitDir2 = 0 : mExitForce2 = 0 : KickZ = 0 : KickForceVar = 0 : KickAngleVar = 0
  1457. mAddSnd = 0 : mEntrySnd = 0 : mEntrySndBall = 0 : mExitSnd = 0 : mExitSndBall = 0
  1458. vpmTimer.AddResetObj Me
  1459. End Sub
  1460.  
  1461. Private Property Let NeedUpdate(aEnabled) : vpmTimer.EnableUpdate Me, False, aEnabled : End Property
  1462.  
  1463. Private Function SetSw(aNo, aStatus)
  1464. Dim mSwcopy
  1465. SetSw = False
  1466. If HasSw(aNo) Then
  1467. mSwcopy = mSw(aNo)
  1468. Controller.Switch(mSwcopy) = aStatus
  1469. SetSw = True
  1470. End If
  1471. End Function
  1472.  
  1473. Private Function HasSw(aNo)
  1474. HasSw = False : If aNo <= conStackSw Then If mSw(aNo) Then HasSw = True
  1475. End Function
  1476.  
  1477. Public Sub Reset
  1478. Dim mSwcopy
  1479. Dim ii : If mBalls Then For ii = 1 to mBalls : SetSw mBallPos(ii), True : Next
  1480. If mEntrySw And mBallIn > 0 Then
  1481. mSwcopy = mEntrySw
  1482. Controller.Switch(mSwcopy) = True
  1483. End If
  1484. End Sub
  1485.  
  1486. Public Sub Update
  1487. Dim BallQue, ii, mSwcopy
  1488. NeedUpdate = False : BallQue = 1
  1489. For ii = 1 To mBalls
  1490. If mBallpos(ii) > BallQue Then ' next slot available
  1491. NeedUpdate = True
  1492. If HasSw(mBallPos(ii)) Then ' has switch
  1493. mSwcopy = mSw(mBallPos(ii))
  1494. If Controller.Switch(mSwcopy) Then
  1495. SetSw mBallPos(ii), False
  1496. Else
  1497. mBallPos(ii) = mBallPos(ii) - 1
  1498. SetSw mBallPos(ii), True
  1499. End If
  1500. Else ' no switch. Move ball to first switch or occupied slot
  1501. Do
  1502. mBallPos(ii) = mBallPos(ii) - 1
  1503. Loop Until SetSw(mBallPos(ii), True) Or mBallPos(ii) = BallQue
  1504. End If
  1505. End If
  1506. BallQue = mBallPos(ii) + 1
  1507. Next
  1508. End Sub
  1509.  
  1510. Public Sub AddBall(aKicker)
  1511. Dim mSwcopy
  1512. If isObject(aKicker) Then
  1513. If mSaucer Then
  1514. If aKicker Is mExitKicker Then
  1515. mExitKicker.Enabled = False : mInitKicker = 0
  1516. Else
  1517. aKicker.Enabled = False : Set mInitKicker = aKicker
  1518. End If
  1519. Else
  1520. aKicker.DestroyBall
  1521. End If
  1522. ElseIf mSaucer Then
  1523. mExitKicker.Enabled = False : mInitKicker = 0
  1524. End If
  1525. If mEntrySw Then
  1526. mSwcopy = mEntrySw
  1527. Controller.Switch(mSwcopy) = True : mBallIn = mBallIn + 1
  1528. Else
  1529. mBalls = mBalls + 1 : mBallPos(mBalls) = conStackSw + 1 : NeedUpdate = True
  1530. End If
  1531. PlaySound mAddSnd
  1532. End Sub
  1533.  
  1534. ' A bug in the script engine forces the "End If" at the end
  1535. Public Sub SolIn(aEnabled) : If aEnabled Then KickIn : End If : End Sub
  1536. Public Sub SolOut(aEnabled) : If aEnabled Then KickOut False : End If : End Sub
  1537. Public Sub SolOutAlt(aEnabled) : If aEnabled Then KickOut True : End If : End Sub
  1538. Public Sub EntrySol_On : KickIn : End Sub
  1539. Public Sub ExitSol_On : KickOut False : End Sub
  1540. Public Sub ExitAltSol_On : KickOut True : End Sub
  1541.  
  1542. Private Sub KickIn
  1543. Dim mSwcopy
  1544. If mBallIn Then PlaySound mEntrySndBall Else PlaySound mEntrySnd : Exit Sub
  1545. mBalls = mBalls + 1 : mBallIn = mBallIn - 1 : mBallPos(mBalls) = conStackSw + 1 : NeedUpdate = True
  1546. If mEntrySw And mBallIn = 0 Then
  1547. mSwcopy = mEntrySw
  1548. Controller.Switch(mSwcopy) = False
  1549. End If
  1550. End Sub
  1551.  
  1552. Private Sub KickOut(aAltSol)
  1553. Dim ii,jj, kForce, kDir, kBaseDir
  1554. If mBalls Then PlaySound mExitSndBall Else PlaySound mExitSnd : Exit Sub
  1555. If aAltSol Then kForce = mExitForce2 : kBaseDir = mExitDir2 Else kForce = mExitForce : kBaseDir = mExitDir
  1556. kForce = kForce + (Rnd - 0.5)*KickForceVar
  1557. If mSaucer Then
  1558. SetSw 1, False : mBalls = 0 : kDir = kBaseDir + (Rnd - 0.5)*KickAngleVar
  1559. If isObject(mInitKicker) Then
  1560. vpmCreateBall mExitKicker : mInitKicker.Destroyball : mInitKicker.Enabled = True
  1561. Else
  1562. mExitKicker.Enabled = True
  1563. End If
  1564. mExitKicker.Kick kDir, kForce, KickZ
  1565. Else
  1566. For ii = 1 To kickballs
  1567. If mBalls = 0 Or mBallPos(1) <> ii Then Exit For ' No more balls
  1568. For jj = 2 To mBalls ' Move balls in array
  1569. mBallPos(jj-1) = mBallPos(jj)
  1570. Next
  1571. mBallPos(mBalls) = 0 : mBalls = mBalls - 1 : NeedUpdate = True
  1572. SetSw ii, False
  1573. If isObject(mExitKicker) Then
  1574. If kForce < 1 Then kForce = 1
  1575. kDir = kBaseDir + (Rnd - 0.5)*KickAngleVar
  1576. vpmTimer.AddTimer (ii-1)*200, "vpmCreateBall(" & mExitKicker.Name & ").Kick " &_
  1577. CInt(kDir) & "," & Replace(kForce,",",".") & "," & Replace(KickZ,",",".") & " '"
  1578. End If
  1579. kForce = kForce * 0.8
  1580. Next
  1581. End If
  1582. End Sub
  1583.  
  1584. Public Sub InitSaucer(aKicker, aSw, aDir, aPower)
  1585. InitKick aKicker, aDir, aPower : mSaucer = True
  1586. If aSw Then mSw(1) = aSw Else mSw(1) = aKicker.TimerInterval
  1587. End Sub
  1588.  
  1589. Public Sub InitNoTrough(aKicker, aSw, aDir, aPower)
  1590. InitKick aKicker, aDir, aPower : Balls = 1
  1591. If aSw Then mSw(1) = aSw Else mSw(1) = aKicker.TimerInterval
  1592. If Not IsObject(vpmTrough) Then Set vpmTrough = Me
  1593. End Sub
  1594.  
  1595. Public Sub InitSw(aEntry, aSw1, aSw2, aSw3, aSw4, aSw5, aSw6, aSw7)
  1596. mEntrySw = aEntry : mSw(1) = aSw1 : mSw(2) = aSw2 : mSw(3) = aSw3 : mSw(4) = aSw4
  1597. mSw(5) = aSw5 : mSw(6) = aSw6 : mSw(7) = aSw7 : mSw(8) = 0
  1598. If Not IsObject(vpmTrough) Then Set vpmTrough = Me
  1599. End Sub
  1600.  
  1601. Public Sub InitSw8(aEntry, aSw1, aSw2, aSw3, aSw4, aSw5, aSw6, aSw7, aSw8)
  1602. mEntrySw = aEntry : mSw(1) = aSw1 : mSw(2) = aSw2 : mSw(3) = aSw3 : mSw(4) = aSw4
  1603. mSw(5) = aSw5 : mSw(6) = aSw6 : mSw(7) = aSw7 : mSw(8) = aSw8
  1604. If Not IsObject(vpmTrough) Then Set vpmTrough = Me
  1605. End Sub
  1606.  
  1607. Public Sub InitKick(aKicker, aDir, aForce)
  1608. Set mExitKicker = aKicker : mExitDir = aDir : mExitForce = aForce
  1609. End Sub
  1610.  
  1611. Public Sub CreateEvents(aName, aKicker)
  1612. Dim obj, tmp
  1613. If Not vpmCheckEvent(aName, Me) Then Exit Sub
  1614. vpmSetArray tmp, aKicker
  1615. For Each obj In tmp
  1616. If isObject(obj) Then
  1617. vpmBuildEvent obj, "Hit", aName & ".AddBall Me"
  1618. Else
  1619. vpmBuildEvent mExitKicker, "Hit", aName & ".AddBall Me"
  1620. End If
  1621. Next
  1622. End Sub
  1623.  
  1624. Public Property Let IsTrough(aIsTrough)
  1625. If aIsTrough Then
  1626. Set vpmTrough = Me
  1627. ElseIf IsObject(vpmTrough) Then
  1628. If vpmTrough Is Me Then vpmTrough = 0
  1629. End If
  1630. End Property
  1631.  
  1632. Public Property Get IsTrough : IsTrough = vpmTrough Is Me : End Property
  1633.  
  1634. Public Sub InitAltKick(aDir, aForce)
  1635. mExitDir2 = aDir : mExitForce2 = aForce
  1636. End Sub
  1637.  
  1638. Public Sub InitEntrySnd(aBall, aNoBall) : mEntrySndBall = aBall : mEntrySnd = aNoBall : End Sub
  1639. Public Sub InitExitSnd(aBall, aNoBall) : mExitSndBall = aBall : mExitSnd = aNoBall : End Sub
  1640. Public Sub InitAddSnd(aSnd) : mAddSnd = aSnd : End Sub
  1641.  
  1642. Public Property Let Balls(aBalls)
  1643. Dim ii
  1644. For ii = 1 To conStackSw
  1645. SetSw ii, False : mBallPos(ii) = conStackSw + 1
  1646. Next
  1647. If mSaucer And aBalls > 0 And mBalls = 0 Then vpmCreateBall mExitKicker
  1648. mBalls = aBalls : NeedUpdate = True
  1649. End Property
  1650.  
  1651. Public Default Property Get Balls : Balls = mBalls : End Property
  1652. Public Property Get BallsPending : BallsPending = mBallIn : End Property
  1653.  
  1654. ' Obsolete stuff
  1655. Public Sub SolEntry(aSnd1, aSnd2, aEnabled)
  1656. If aEnabled Then mEntrySndBall = aSnd1 : mEntrySnd = aSnd2 : KickIn
  1657. End Sub
  1658. Public Sub SolExit(aSnd1, aSnd2, aEnabled)
  1659. If aEnabled Then mExitSndBall = aSnd1 : mExitSnd = aSnd2 : KickOut False
  1660. End Sub
  1661. Public Sub InitProxy(aProxyPos, aSwNo) : End Sub
  1662. Public TempBallColour, TempBallImage, BallColour
  1663. Public Property Let BallImage(aImage) : vpmBallImage = aImage : End Property
  1664. End Class
  1665.  
  1666. '--------------------
  1667. ' Nudge
  1668. '--------------------
  1669. class cvpmNudge
  1670. Private mCount, mSensitivity, mNudgeTimer, mSlingBump, mForce
  1671. Public TiltSwitch
  1672.  
  1673. Private Sub Class_Initialize
  1674. mCount = 0 : TiltSwitch = 0 : mSensitivity = 5 : vpmTimer.AddResetObj Me
  1675. End sub
  1676.  
  1677. Private Property Let NeedUpdate(aEnabled) : vpmTimer.EnableUpdate Me, False, aEnabled : End Property
  1678.  
  1679. Public Property Let TiltObj(aSlingBump)
  1680. Dim ii
  1681. ReDim mForce(vpmSetArray(mSlingBump, aSlingBump))
  1682. For ii = 0 To UBound(mForce)
  1683. If TypeName(mSlingBump(ii)) = "Bumper" Then mForce(ii) = mSlingBump(ii).Threshold
  1684. If vpmVPVer >= 90 and TypeName(mSlingBump(ii)) = "Wall" Then mForce(ii) = mSlingBump(ii).SlingshotThreshold
  1685. Next
  1686. End Property
  1687.  
  1688. Public Property Let Sensitivity(aSens) : mSensitivity = (10-aSens)+1 : End property
  1689.  
  1690. Public Sub DoNudge(ByVal aDir, ByVal aForce)
  1691. aDir = aDir + (Rnd-0.5)*15*aForce : aForce = (0.6+Rnd*0.8)*aForce
  1692. Nudge aDir, aForce
  1693. If TiltSwitch = 0 Then Exit Sub ' If no switch why care
  1694. mCount = mCount + aForce * 1.2
  1695. If mCount > mSensitivity + 10 Then mCount = mSensitivity + 10
  1696. If mCount >= mSensitivity Then vpmTimer.PulseSw TiltSwitch
  1697. NeedUpdate = True
  1698. End sub
  1699.  
  1700. Public Sub Update
  1701. If mCount > 0 Then
  1702. mNudgeTimer = mNudgeTimer + 1
  1703. If mNudgeTimer > 1000\conTimerPulse Then
  1704. If mCount > mSensitivity+1 Then mCount = mCount - 1 : vpmTimer.PulseSw TiltSwitch
  1705. mCount = mCount - 1 : mNudgeTimer = 0
  1706. End If
  1707. Else
  1708. mCount = 0 : NeedUpdate = False
  1709. End If
  1710. End Sub
  1711.  
  1712. Public Sub Reset : mCount = 0 : End Sub
  1713.  
  1714. Public Sub SolGameOn(aEnabled)
  1715. if IsEmpty(mForce) then exit sub 'prevent errors if vpmNudge.TiltObj isn't set
  1716. Dim obj, ii
  1717. If aEnabled Then
  1718. ii = 0
  1719. For Each obj In mSlingBump
  1720. If TypeName(obj) = "Bumper" Then obj.Threshold = mForce(ii)
  1721. If vpmVPVer >= 90 and TypeName(obj) = "Wall" Then obj.SlingshotThreshold = mForce(ii)
  1722. ii = ii + 1
  1723. Next
  1724. Else
  1725. For Each obj In mSlingBump
  1726. If TypeName(obj) = "Bumper" Then obj.Threshold = 100
  1727. If vpmVPVer >= 90 and TypeName(obj) = "Wall" Then obj.SlingshotThreshold = 100
  1728. Next
  1729. End If
  1730. End Sub
  1731. End Class
  1732.  
  1733. '--------------------
  1734. ' DropTarget
  1735. '--------------------
  1736. Class cvpmDropTarget
  1737. Private mDropObj, mDropSw(), mDropSnd, mRaiseSnd, mSwAnyUp, mSwAllDn, mAllDn, mLink
  1738.  
  1739. Private Sub Class_Initialize
  1740. mDropSnd = 0 : mRaiseSnd = 0 : mSwAnyUp = 0 : mSwAllDn = 0 : mAllDn = False : mLink = Empty
  1741. End sub
  1742.  
  1743. Private Sub CheckAllDn(ByVal aStatus)
  1744. Dim obj
  1745. If Not IsEmpty(mLink) Then
  1746. If aStatus Then
  1747. For Each obj In mLink : aStatus = aStatus And obj.AllDown : Next
  1748. End If
  1749. For Each obj In mLink: obj.SetAllDn aStatus : Next
  1750. End If
  1751. SetAllDn aStatus
  1752. End Sub
  1753.  
  1754. Public Sub SetAllDn(aStatus)
  1755. Dim mSwcopy
  1756. If mSwAllDn Then
  1757. mSwcopy = mSwAllDn
  1758. Controller.Switch(mSwcopy) = aStatus
  1759. End If
  1760. If mSwAnyUp Then
  1761. mSwcopy = mSwAnyUp
  1762. Controller.Switch(mSwcopy) = Not aStatus
  1763. End If
  1764. End Sub
  1765.  
  1766. Public Sub InitDrop(aWalls, aSw)
  1767. Dim obj, obj2, ii
  1768. ' Fill in switch number
  1769. On Error Resume Next : ReDim mDropSw(0)
  1770. If IsArray(aSw) Then
  1771. ReDim mDropSw(UBound(aSw))
  1772. For ii = 0 To UBound(aSw) : mDropSw(ii) = aSw(ii) : Next
  1773. ElseIf aSw = 0 Or Err Then
  1774. On Error Goto 0
  1775. If vpmIsArray(aWalls) Then
  1776. ii = 0 : If IsArray(aWalls) Then ReDim mDropSw(UBound(aWalls)) Else ReDim mDropSw(aWalls.Count-1)
  1777. For Each obj In aWalls
  1778. If vpmIsArray(obj) Then
  1779. For Each obj2 In obj
  1780. If obj2.HasHitEvent Then mDropSw(ii) = obj2.TimerInterval : Exit For
  1781. Next
  1782. Else
  1783. mDropSw(ii) = obj.TimerInterval
  1784. End If
  1785. ii = ii + 1
  1786. Next
  1787. Else
  1788. mDropSw(0) = aWalls.TimerInterval
  1789. End If
  1790. Else
  1791. mDropSw(0) = aSw
  1792. End If
  1793. ' Copy walls
  1794. vpmSetArray mDropObj, aWalls
  1795. End Sub
  1796.  
  1797. Public Sub CreateEvents(aName)
  1798. Dim ii, obj1, obj2
  1799. If Not vpmCheckEvent(aName, Me) Then Exit Sub
  1800. ii = 1
  1801. For Each obj1 In mDropObj
  1802. If vpmIsArray(obj1) Then
  1803. For Each obj2 In obj1
  1804. if TypeName(obj2) = "HitTarget" Then 'if object in array is a Target, use .Dropped
  1805. vpmBuildEvent obj2, "Dropped", aName & ".Hit " & ii 'Droptarget_Dropped : DTbank.Hit 1 : End Sub
  1806. else
  1807. If obj2.HasHitEvent Then vpmBuildEvent obj2, "Hit", aName & ".Hit " & ii
  1808. End If
  1809. Next
  1810. Else
  1811. if TypeName(obj1) = "HitTarget" Then 'if object in array is a Target, use .Dropped
  1812. vpmBuildEvent obj1, "Dropped", aName & ".Hit " & ii
  1813. else
  1814. vpmBuildEvent obj1, "Hit", aName & ".Hit " & ii
  1815. End If
  1816. End If
  1817. ii = ii + 1
  1818. Next
  1819. End Sub
  1820.  
  1821. Public Property Let AnyUpSw(aSwAnyUp)
  1822. Dim mSwcopy
  1823. mSwAnyUp = aSwAnyUp
  1824. mSwcopy = mSwAnyUp
  1825. Controller.Switch(mSwcopy) = True
  1826. End Property
  1827. Public Property Let AllDownSw(aSwAllDn) : mSwAllDn = aSwAllDn : End Property
  1828. Public Property Get AllDown : AllDown = mAllDn : End Property
  1829. Public Sub InitSnd(aDrop, aRaise) : mDropSnd = aDrop : mRaiseSnd = aRaise : End Sub
  1830. Public Property Let LinkedTo(aLink)
  1831. If IsArray(aLink) Then mLink = aLink Else mLink = Array(aLink)
  1832. End Property
  1833.  
  1834. Public Sub Hit(aNo)
  1835. Dim ii, mSwcopy
  1836. vpmSolWall mDropObj(aNo-1), mDropSnd, True
  1837. mSwcopy = mDropSw(aNo-1)
  1838. Controller.Switch(mSwcopy) = True
  1839. For Each ii In mDropSw
  1840. mSwcopy = ii
  1841. If Not Controller.Switch(mSwcopy) Then Exit Sub
  1842. Next
  1843. mAllDn = True : CheckAllDn True
  1844. End Sub
  1845.  
  1846. Public Sub SolHit(aNo, aEnabled) : If aEnabled Then Hit aNo : End If : End Sub
  1847.  
  1848. Public Sub SolUnhit(aNo, aEnabled)
  1849. Dim mSwcopy
  1850. Dim ii : If Not aEnabled Then Exit Sub
  1851. PlaySound mRaiseSnd : vpmSolWall mDropObj(aNo-1), False, False
  1852. mSwcopy = mDropSw(aNo-1)
  1853. Controller.Switch(mSwcopy) = False
  1854. mAllDn = False : CheckAllDn False
  1855. End Sub
  1856.  
  1857. Public Sub SolDropDown(aEnabled)
  1858. Dim mSwcopy
  1859. Dim ii : If Not aEnabled Then Exit Sub
  1860. PlaySound mDropSnd
  1861. For Each ii In mDropObj : vpmSolWall ii, False, True : Next
  1862. For Each ii In mDropSw : mSwcopy = ii : Controller.Switch(mSwcopy) = True : Next
  1863. mAllDn = True : CheckAllDn True
  1864. End Sub
  1865.  
  1866. Public Sub SolDropUp(aEnabled)
  1867. Dim mSwcopy
  1868. Dim ii : If Not aEnabled Then Exit Sub
  1869. PlaySound mRaiseSnd
  1870. For Each ii In mDropObj : vpmSolWall ii, False, False : Next
  1871. For Each ii In mDropSw : mSwcopy = ii : Controller.Switch(mSwcopy) = False : Next
  1872. mAllDn = False : CheckAllDn False
  1873. End Sub
  1874.  
  1875. Public Sub DropSol_On : SolDropUp True : End Sub
  1876. End Class
  1877.  
  1878. '--------------------
  1879. ' Magnet
  1880. '--------------------
  1881. Class cvpmMagnet
  1882. Private mEnabled, mBalls, mTrigger
  1883. Public X, Y, Strength, Size, GrabCenter, Solenoid
  1884.  
  1885. Private Sub Class_Initialize
  1886. Size = 1 : Strength = 0 : Solenoid = 0 : mEnabled = False
  1887. Set mBalls = New cvpmDictionary
  1888. End Sub
  1889.  
  1890. Private Property Let NeedUpdate(aEnabled) : vpmTimer.EnableUpdate Me, True, aEnabled : End Property
  1891.  
  1892. Public Sub InitMagnet(aTrigger, aStrength)
  1893. Dim tmp
  1894. If vpmIsArray(aTrigger) Then Set tmp = aTrigger(0) Else Set tmp = aTrigger
  1895. X = tmp.X : Y = tmp.Y : Size = tmp.Radius : vpmTimer.InitTimer tmp, True
  1896. If IsArray(aTrigger) Then mTrigger = aTrigger Else Set mTrigger = aTrigger
  1897. Strength = aStrength : GrabCenter = aStrength > 14
  1898. End Sub
  1899.  
  1900. Public Sub CreateEvents(aName)
  1901. If vpmCheckEvent(aName, Me) Then
  1902. vpmBuildEvent mTrigger, "Hit", aName & ".AddBall ActiveBall"
  1903. vpmBuildEvent mTrigger, "UnHit", aName & ".RemoveBall ActiveBall"
  1904. End If
  1905. End Sub
  1906.  
  1907. Public Property Let MagnetOn(aEnabled) : mEnabled = aEnabled : End Property
  1908. Public Property Get MagnetOn
  1909. If Solenoid > 0 Then MagnetOn = Controller.Solenoid(Solenoid) Else MagnetOn = mEnabled
  1910. End Property
  1911.  
  1912. Public Sub AddBall(aBall)
  1913. With mBalls
  1914. If .Exists(aBall) Then .Item(aBall) = .Item(aBall) + 1 Else .Add aBall, 1 : NeedUpdate = True
  1915. End With
  1916. End Sub
  1917.  
  1918. Public Sub RemoveBall(aBall)
  1919. With mBalls
  1920. If .Exists(aBall) Then .Item(aBall) = .Item(aBall) - 1 : If .Item(aBall) <= 0 Then .Remove aBall
  1921. NeedUpdate = (.Count > 0)
  1922. End With
  1923. End Sub
  1924.  
  1925. Public Property Get Balls : Balls = mBalls.Keys : End Property
  1926.  
  1927. Public Sub Update
  1928. Dim obj
  1929. If MagnetOn Then
  1930. On Error Resume Next
  1931. For Each obj In mBalls.Keys
  1932. If obj.X < 0 Or Err Then mBalls.Remove obj Else AttractBall obj
  1933. Next
  1934. On Error Goto 0
  1935. End If
  1936. End Sub
  1937.  
  1938. Public Sub AttractBall(aBall)
  1939. Dim dX, dY, dist, force, ratio
  1940. dX = aBall.X - X : dY = aBall.Y - Y : dist = Sqr(dX*dX + dY*dY)
  1941. If dist > Size Or dist < 1 Then Exit Sub 'Just to be safe
  1942. If GrabCenter And dist < 20 Then
  1943. aBall.VelX = 0 : aBall.VelY = 0 : aBall.X = X : aBall.Y = Y
  1944. Else
  1945. ratio = dist / (1.5*Size)
  1946. force = Strength * exp(-0.2/ratio)/(ratio*ratio*56) * 1.5
  1947. aBall.VelX = (aBall.VelX - dX * force / dist) * 0.985
  1948. aBall.VelY = (aBall.VelY - dY * force / dist) * 0.985
  1949. End if
  1950. End Sub
  1951. ' obsolete
  1952. Public Property Let Range(aSize) : Size = aSize : End Property
  1953. Public Property Get Range : Range = Size : End Property
  1954. End Class
  1955.  
  1956. '--------------------
  1957. ' Turntable
  1958. '--------------------
  1959. Class cvpmTurntable
  1960. Private mX, mY, mSize, mTrigger, mBalls, mSpinUp, mSpinDown
  1961. Private mMotorOn, mSpinCW
  1962. Private mMaxSpeed, mTargetSpeed, mCurrentAccel
  1963. Public Speed
  1964.  
  1965. Private Sub Class_Initialize
  1966. Set mBalls = New cvpmDictionary
  1967. mMotorOn = False : mSpinCW = True : Speed = 0 : mSpinUp = 10 : mSpinDown = 4
  1968. AdjustTargets
  1969. End Sub
  1970.  
  1971. Private Property Let NeedUpdate(aEnabled) : vpmTimer.EnableUpdate Me, True, aEnabled : End Property
  1972.  
  1973. Public Sub InitTurntable(aTrigger, aMaxSpeed)
  1974. mX = aTrigger.X : mY = aTrigger.Y : mSize = aTrigger.Radius : vpmTimer.InitTimer aTrigger, True
  1975. mMaxSpeed = aMaxSpeed : Set mTrigger = aTrigger
  1976. AdjustTargets
  1977. End Sub
  1978.  
  1979. Public Sub CreateEvents(aName)
  1980. If vpmCheckEvent(aName, Me) Then
  1981. vpmBuildEvent mTrigger, "Hit", aName & ".AddBall ActiveBall"
  1982. vpmBuildEvent mTrigger, "UnHit", aName & ".RemoveBall ActiveBall"
  1983. End If
  1984. End Sub
  1985.  
  1986. Public Sub SolMotorState(aCW, aMotorOn)
  1987. mSpinCW = aCW
  1988. mMotorOn = aMotorOn
  1989. AdjustTargets
  1990. End Sub
  1991.  
  1992. Private Sub AdjustTargets
  1993. If mMotorOn Then
  1994. mTargetSpeed = MaxSpeed
  1995. mCurrentAccel = SpinUp
  1996. If Not mSpinCW Then mTargetSpeed = -MaxSpeed
  1997. Else
  1998. mTargetSpeed = 0
  1999. mCurrentAccel = SpinDown
  2000. End If
  2001.  
  2002. NeedUpdate = mBalls.Count Or SpinUp Or SpinDown
  2003. End Sub
  2004.  
  2005. Public Property Let MaxSpeed(newSpeed) : mMaxSpeed = newSpeed : AdjustTargets : End Property
  2006. Public Property Let SpinUp(newRate) : mSpinUp = newRate : AdjustTargets : End Property
  2007. Public Property Let SpinDown(newRate) : mSpinDown = newRate : AdjustTargets : End Property
  2008.  
  2009. Public Property Get MaxSpeed : MaxSpeed = mMaxSpeed : End Property
  2010. Public Property Get SpinUp : SpinUp = mSpinup : End Property
  2011. Public Property Get SpinDown : SpinDown = mSpinDown : End Property
  2012.  
  2013. Public Property Let MotorOn(aEnabled) : SolMotorState mSpinCW, aEnabled : End Property
  2014. Public Property Let SpinCW(aCW) : SolMotorState aCW, mMotorOn : End Property
  2015.  
  2016. Public Property Get MotorOn : MotorOn = mMotorOn : End Property
  2017. Public Property Get SpinCW : SpinCW = mSpinCW : End Property
  2018.  
  2019. Public Sub AddBall(aBall)
  2020. On Error Resume Next : mBalls.Add aBall,0 : NeedUpdate = True
  2021. End Sub
  2022. Public Sub RemoveBall(aBall)
  2023. On Error Resume Next
  2024. mBalls.Remove aBall : NeedUpdate = mBalls.Count Or SpinUp Or SpinDown
  2025. End Sub
  2026. Public Property Get Balls : Balls = mBalls.Keys : End Property
  2027.  
  2028. Public Sub Update
  2029. If Speed > mTargetSpeed Then
  2030. Speed = Speed - mCurrentAccel/100
  2031. If Speed < mTargetSpeed Then Speed = mTargetSpeed : NeedUpdate = mBalls.Count
  2032. ElseIf Speed < mTargetSpeed Then
  2033. Speed = Speed + mCurrentAccel/100
  2034. If Speed > mTargetSpeed Then Speed = mTargetSpeed : NeedUpdate = mBalls.Count
  2035. End If
  2036.  
  2037. If Speed Then
  2038. Dim obj
  2039. On Error Resume Next
  2040. For Each obj In mBalls.Keys
  2041. If obj.X < 0 Or Err Then mBalls.Remove obj Else AffectBall obj
  2042. Next
  2043. On Error Goto 0
  2044. End If
  2045. End Sub
  2046.  
  2047. Public Sub AffectBall(aBall)
  2048. Dim dX, dY, dist
  2049. dX = aBall.X - mX : dY = aBall.Y - mY : dist = Sqr(dX*dX + dY*dY)
  2050. If dist > mSize Or dist < 1 Or Speed = 0 Then Exit Sub
  2051. aBall.VelX = aBall.VelX - (dY * Speed / 8000)
  2052. aBall.VelY = aBall.VelY + (dX * Speed / 8000)
  2053. End Sub
  2054. End Class
  2055.  
  2056. '--------------------
  2057. ' Mech
  2058. '--------------------
  2059. Const vpmMechLinear = &H00
  2060. Const vpmMechNonLinear = &H01
  2061. Const vpmMechCircle = &H00
  2062. Const vpmMechStopEnd = &H02
  2063. Const vpmMechReverse = &H04
  2064. Const vpmMechOneSol = &H00
  2065. Const vpmMechOneDirSol = &H10
  2066. Const vpmMechTwoDirSol = &H20
  2067. Const vpmMechStepSol = &H40
  2068. Const vpmMechSlow = &H00
  2069. Const vpmMechFast = &H80
  2070. Const vpmMechStepSw = &H00
  2071. Const vpmMechLengthSw = &H100
  2072.  
  2073. Class cvpmMech
  2074. Public Sol1, Sol2, MType, Length, Steps, Acc, Ret
  2075. Private mMechNo, mNextSw, mSw(), mLastPos, mLastSpeed, mCallback
  2076.  
  2077. Private Sub Class_Initialize
  2078. ReDim mSw(10)
  2079. gNextMechNo = gNextMechNo + 1 : mMechNo = gNextMechNo : mNextSw = 0 : mLastPos = 0 : mLastSpeed = 0
  2080. MType = 0 : Length = 0 : Steps = 0 : Acc = 0 : Ret = 0 : vpmTimer.addResetObj Me
  2081. End Sub
  2082.  
  2083. Public Sub AddSw(aSwNo, aStart, aEnd)
  2084. mSw(mNextSw) = Array(aSwNo, aStart, aEnd, 0)
  2085. mNextSw = mNextSw + 1
  2086. End Sub
  2087.  
  2088. Public Sub AddPulseSwNew(aSwNo, aInterval, aStart, aEnd)
  2089. If Controller.Version >= "01200000" Then
  2090. mSw(mNextSw) = Array(aSwNo, aStart, aEnd, aInterval)
  2091. Else
  2092. mSw(mNextSw) = Array(aSwNo, -aInterval, aEnd - aStart + 1, 0)
  2093. End If
  2094. mNextSw = mNextSw + 1
  2095. End Sub
  2096.  
  2097. Public Sub Start
  2098. Dim sw, ii
  2099. With Controller
  2100. .Mech(1) = Sol1 : .Mech(2) = Sol2 : .Mech(3) = Length
  2101. .Mech(4) = Steps : .Mech(5) = MType : .Mech(6) = Acc : .Mech(7) = Ret
  2102. ii = 10
  2103. For Each sw In mSw
  2104. If IsArray(sw) Then
  2105. .Mech(ii) = sw(0) : .Mech(ii+1) = sw(1)
  2106. .Mech(ii+2) = sw(2) : .Mech(ii+3) = sw(3)
  2107. ii = ii + 10
  2108. End If
  2109. Next
  2110. .Mech(0) = mMechNo
  2111. End With
  2112. If IsObject(mCallback) Then mCallBack 0, 0, 0 : mLastPos = 0 : vpmTimer.EnableUpdate Me, False, True
  2113. End Sub
  2114.  
  2115. Public Property Get Position : Position = Controller.GetMech(mMechNo) : End Property
  2116. Public Property Get Speed : Speed = Controller.GetMech(-mMechNo) : End Property
  2117. Public Property Let Callback(aCallBack) : Set mCallback = aCallBack : End Property
  2118.  
  2119. Public Sub Update
  2120. Dim currPos, speed
  2121. currPos = Controller.GetMech(mMechNo)
  2122. speed = Controller.GetMech(-mMechNo)
  2123. If currPos < 0 Or (mLastPos = currPos And mLastSpeed = speed) Then Exit Sub
  2124. mCallBack currPos, speed, mLastPos : mLastPos = currPos : mLastSpeed = speed
  2125. End Sub
  2126.  
  2127. Public Sub Reset : Start : End Sub
  2128. ' Obsolete
  2129. Public Sub AddPulseSw(aSwNo, aInterval, aLength) : AddSw aSwNo, -aInterval, aLength : End Sub
  2130. End Class
  2131.  
  2132. '--------------------
  2133. ' Captive Ball
  2134. '--------------------
  2135. Class cvpmCaptiveBall
  2136. Private mBallKicked, mBallDir, mBallCos, mBallSin, mTrigHit
  2137. Private mTrig, mWall, mKickers, mVelX, mVelY, mKickNo
  2138. Public ForceTrans, MinForce, RestSwitch, NailedBalls
  2139.  
  2140. Private Sub Class_Initialize
  2141. mBallKicked = False : ForceTrans = 0.5 : mTrigHit = False : MinForce = 3 : NailedBalls = 0
  2142. vpmTimer.addResetObj Me
  2143. End Sub
  2144.  
  2145. Public Sub InitCaptive(aTrig, aWall, aKickers, aBallDir)
  2146. Set mTrig = aTrig : Set mWall = aWall
  2147. mKickNo = vpmSetArray(mKickers, aKickers)
  2148. mBallDir = aBallDir : mBallCos = Cos(aBallDir * 3.1415927/180) : mBallSin = Sin(aBallDir * 3.1415927/180)
  2149. End Sub
  2150.  
  2151. Public Sub Start
  2152. Dim mSwcopy
  2153. vpmCreateBall mKickers(mKickNo + (mKickNo <> NailedBalls))
  2154. If RestSwitch Then
  2155. mSwcopy = RestSwitch
  2156. Controller.Switch(mSwcopy) = True
  2157. End If
  2158. End Sub
  2159.  
  2160. Public Sub TrigHit(aBall)
  2161. mTrigHit = IsObject(aBall) : If mTrigHit Then mVelX = aBall.VelX : mVelY = aBall.VelY
  2162. End Sub
  2163.  
  2164. Public Sub Reset
  2165. Dim mSwcopy
  2166. If RestSwitch Then
  2167. mSwcopy = RestSwitch
  2168. Controller.Switch(mSwcopy) = True
  2169. End If
  2170. End Sub
  2171.  
  2172. Public Sub BallHit(aBall)
  2173. Dim dX, dY, force, mSwcopy
  2174. If mBallKicked Then Exit Sub ' Ball is not here
  2175. If mTrigHit Then mTrigHit = False Else mVelX = aBall.VelX : mVelY = aBall.VelY
  2176. dX = aBall.X - mKickers(0).X : dY = aBall.Y - mKickers(0).Y
  2177. force = -ForceTrans * (dY * mVelY + dX * mVelX) * (dY * mBallCos + dX * mBallSin) / (dX*dX + dY*dY)
  2178. If force < 1 Then Exit Sub
  2179. If force < MinForce Then force = MinForce
  2180. If mKickNo <> NailedBalls Then
  2181. vpmCreateBall mKickers(mKickNo)
  2182. mKickers(mKickNo-1).DestroyBall
  2183. End If
  2184. mKickers(mKickNo).Kick mBallDir, force : mBallKicked = True
  2185. If RestSwitch Then
  2186. mSwcopy = RestSwitch
  2187. Controller.Switch(mSwcopy) = False
  2188. End If
  2189. End Sub
  2190.  
  2191. Public Sub BallReturn(aKicker)
  2192. Dim mSwcopy
  2193. If mKickNo <> NailedBalls Then vpmCreateBall mKickers(mKickNo-1) : aKicker.DestroyBall
  2194. mBallKicked = False
  2195. If RestSwitch Then
  2196. mSwcopy = RestSwitch
  2197. Controller.Switch(mSwcopy) = True
  2198. End If
  2199. End Sub
  2200.  
  2201. Public Sub CreateEvents(aName)
  2202. If vpmCheckEvent(aName, Me) Then
  2203. If Not mTrig Is Nothing Then
  2204. vpmBuildEvent mTrig, "Hit", aName & ".TrigHit ActiveBall"
  2205. vpmBuildEvent mTrig, "UnHit", aName & ".TrigHit 0"
  2206. End If
  2207. vpmBuildEvent mWall, "Hit", aName & ".BallHit ActiveBall"
  2208. vpmBuildEvent mKickers(mKickNo), "Hit", aName & ".BallReturn Me"
  2209. End If
  2210. End Sub
  2211. ' Obsolete
  2212. Public BallImage, BallColour
  2213. End Class
  2214.  
  2215. '--------------------
  2216. ' Visible Locks
  2217. '--------------------
  2218. Class cvpmVLock
  2219. Private mTrig, mKick, mSw(), mSize, mBalls, mGateOpen, mRealForce, mBallSnd, mNoBallSnd
  2220. Public ExitDir, ExitForce, KickForceVar
  2221.  
  2222. Private Sub Class_Initialize
  2223. mBalls = 0 : ExitDir = 0 : ExitForce = 0 : KickForceVar = 0 : mGateOpen = False
  2224. vpmTimer.addResetObj Me
  2225. End Sub
  2226.  
  2227. Public Sub InitVLock(aTrig, aKick, aSw)
  2228. Dim ii
  2229. mSize = vpmSetArray(mTrig, aTrig)
  2230. If vpmSetArray(mKick, aKick) <> mSize Then MsgBox "cvpmVLock: Unmatched kick+trig" : Exit Sub
  2231. On Error Resume Next
  2232. ReDim mSw(mSize)
  2233. If IsArray(aSw) Then
  2234. For ii = 0 To UBound(aSw) : mSw(ii) = aSw(ii) : Next
  2235. ElseIf aSw = 0 Or Err Then
  2236. For ii = 0 To mSize: mSw(ii) = mTrig(ii).TimerInterval : Next
  2237. Else
  2238. mSw(0) = aSw
  2239. End If
  2240. End Sub
  2241.  
  2242. Public Sub InitSnd(aBall, aNoBall) : mBallSnd = aBall : mNoBallSnd = aNoBall : End Sub
  2243. Public Sub CreateEvents(aName)
  2244. Dim ii
  2245. If Not vpmCheckEvent(aName, Me) Then Exit Sub
  2246. For ii = 0 To mSize
  2247. vpmBuildEvent mTrig(ii), "Hit", aName & ".TrigHit ActiveBall," & ii+1
  2248. vpmBuildEvent mTrig(ii), "Unhit", aName & ".TrigUnhit ActiveBall," & ii+1
  2249. vpmBuildEvent mKick(ii), "Hit", aName & ".KickHit " & ii+1
  2250. Next
  2251. End Sub
  2252.  
  2253. Public Sub SolExit(aEnabled)
  2254. Dim ii, mSwcopy
  2255. mGateOpen = aEnabled
  2256. If Not aEnabled Then Exit Sub
  2257. If mBalls > 0 Then PlaySound mBallSnd : Else PlaySound mNoBallSnd : Exit Sub
  2258. For ii = 0 To mBalls-1
  2259. mKick(ii).Enabled = False
  2260. If mSw(ii) Then
  2261. mSwcopy = mSw(ii)
  2262. Controller.Switch(mSwcopy) = False
  2263. End If
  2264. Next
  2265. If ExitForce > 0 Then ' Up
  2266. mRealForce = ExitForce + (Rnd - 0.5)*KickForceVar : mKick(mBalls-1).Kick ExitDir, mRealForce
  2267. Else ' Down
  2268. mKick(0).Kick 0, 0
  2269. End If
  2270. End Sub
  2271.  
  2272. Public Sub Reset
  2273. Dim mSwcopy
  2274. Dim ii : If mBalls = 0 Then Exit Sub
  2275. For ii = 0 To mBalls-1
  2276. If mSw(ii) Then
  2277. mSwcopy = mSw(ii)
  2278. Controller.Switch(mSwcopy) = True
  2279. End If
  2280. Next
  2281. End Sub
  2282.  
  2283. Public Property Get Balls : Balls = mBalls : End Property
  2284.  
  2285. Public Property Let Balls(aBalls)
  2286. Dim mSwcopy
  2287. Dim ii : mBalls = aBalls
  2288. For ii = 0 To mSize
  2289. mSwcopy = mSw(ii)
  2290. If ii >= aBalls Then
  2291. mKick(ii).DestroyBall : If mSwcopy Then Controller.Switch(mSwcopy) = False
  2292. Else
  2293. vpmCreateBall mKick(ii) : If mSwcopy Then Controller.Switch(mSwcopy) = True
  2294. End If
  2295. Next
  2296. End Property
  2297.  
  2298. Public Sub TrigHit(aBall, aNo)
  2299. Dim mSwcopy
  2300. aNo = aNo - 1
  2301. If mSw(aNo) Then
  2302. mSwcopy = mSw(aNo)
  2303. Controller.Switch(mSwcopy) = True
  2304. End If
  2305. If aBall.VelY < -1 Then Exit Sub ' Allow small upwards speed
  2306. If aNo = mSize Then mBalls = mBalls + 1
  2307. If mBalls > aNo Then mKick(aNo).Enabled = Not mGateOpen
  2308. End Sub
  2309.  
  2310. Public Sub TrigUnhit(aBall, aNo)
  2311. Dim mSwcopy
  2312. aNo = aNo - 1
  2313. If mSw(aNo) Then
  2314. mSwcopy = mSw(aNo)
  2315. Controller.Switch(mSwcopy) = False
  2316. End If
  2317. If aBall.VelY > -1 Then
  2318. If aNo = 0 Then mBalls = mBalls - 1
  2319. If aNo < mSize Then mKick(aNo+1).Kick 0, 0
  2320. Else
  2321. If aNo = mSize Then mBalls = mBalls - 1
  2322. If aNo > 0 Then mKick(aNo-1).Kick ExitDir, mRealForce
  2323. End If
  2324. End Sub
  2325.  
  2326. Public Sub KickHit(aNo) : mKick(aNo-1).Enabled = False : End Sub
  2327. End Class
  2328.  
  2329. '--------------------
  2330. ' View Dips
  2331. '--------------------
  2332. Class cvpmDips
  2333. Private mLWF, mChkCount, mOptCount, mItems()
  2334.  
  2335. Private Sub Class_Initialize
  2336. ReDim mItems(100)
  2337. End Sub
  2338.  
  2339. Private Sub addChkBox(aType, aLeft, aTop, aWidth, aNames)
  2340. Dim ii, obj
  2341. If Not isObject(mLWF) Then Exit Sub
  2342. For ii = 0 To UBound(aNames) Step 2
  2343. Set obj = mLWF.AddCtrl("chkBox", 10+aLeft, 5+aTop+ii*7, aWidth, 14, aNames(ii))
  2344. mChkCount = mChkCount + 1 : mItems(mChkCount+mOptCount) = Array(aType, obj, mChkCount, aNames(ii+1), aNames(ii+1))
  2345. Next
  2346. End Sub
  2347.  
  2348. Private Sub addOptBox(aType, aLeft, aTop, aWidth, aHeading, aMask, aNames)
  2349. Dim ii, obj
  2350. If Not isObject(mLWF) Then Exit Sub
  2351. mLWF.AddCtrl "Frame", 10+aLeft, 5+aTop, 10+aWidth, 7*UBound(aNames)+25, aHeading
  2352. If aMask Then
  2353. For ii = 0 To UBound(aNames) Step 2
  2354. Set obj = mLWF.AddCtrl("OptBtn", 10+aLeft+5, 5+aTop+ii*7+14, aWidth, 14, aNames(ii))
  2355. mOptCount = mOptCount + 1 : mItems(mChkCount+mOptCount) = Array(aType+2,obj,mOptCount,aNames(ii+1),aMask)
  2356. Next
  2357. Else
  2358. addChkBox aType, 5+aLeft, 15+aTop, aWidth, aNames
  2359. End If
  2360. End Sub
  2361.  
  2362. Public Sub addForm(ByVal aWidth, aHeight, aName)
  2363. If aWidth < 80 Then aWidth = 80
  2364. On Error Resume Next
  2365. Set mLWF = CreateObject("VPinMAME.WSHDlg") : If Err Then Exit Sub
  2366. With mLWF
  2367. .x = -1 : .y = -1 ' : .w = aWidth : .h = aHeight+60
  2368. .Title = aName : .AddCtrl "OKBtn", -1, -1, 70, 25, "&Ok"
  2369. End With
  2370. mChkCount = 0 : mOptCount = 0
  2371. End Sub
  2372.  
  2373. Public Sub addChk(aLeft, aTop, aWidth, aNames)
  2374. addChkBox 0, aLeft, aTop, aWidth, aNames
  2375. End Sub
  2376. Public Sub addChkExtra(aLeft, aTop, aWidth, aNames)
  2377. addChkBox 1, aLeft, aTop, aWidth, aNames
  2378. End Sub
  2379. Public Sub addFrame(aLeft, aTop, aWidth, aHeading, aMask, aNames)
  2380. addOptBox 0, aLeft, aTop, aWidth, aHeading, aMask, aNames
  2381. End Sub
  2382. Public Sub addFrameExtra(aLeft, aTop, aWidth, aHeading, aMask, aNames)
  2383. addOptBox 1, aLeft, aTop, aWidth, aHeading, aMask, aNames
  2384. End Sub
  2385.  
  2386. Public Sub addLabel(aLeft, aTop, aWidth, aHeight, aCaption)
  2387. If Not isObject(mLWF) Then Exit Sub
  2388. mLWF.AddCtrl "Label", 10+aLeft, 5+aTop, aWidth, aHeight, aCaption
  2389. End Sub
  2390.  
  2391. Public Sub viewDips : viewDipsExtra 0 : End Sub
  2392. Public Function viewDipsExtra(aExtra)
  2393. Dim dips(1), ii, useDip
  2394. If Not isObject(mLWF) Then Exit Function
  2395. With Controller
  2396. dips(0) = .Dip(0) + .Dip(1)*256 + .Dip(2)*65536 + (.Dip(3) And &H7f)*&H1000000
  2397. If .Dip(3) And &H80 Then dips(0) = dips(0) Or &H80000000 'workaround for overflow error
  2398. End With
  2399. useDip = False : dips(1) = aExtra
  2400. For ii = 1 To mChkCount + mOptCount
  2401. mItems(ii)(1).Value = -((dips(mItems(ii)(0) And &H01) And mItems(ii)(4)) = mItems(ii)(3))
  2402. If (mItems(ii)(0) And &H01) = 0 Then useDip = True
  2403. Next
  2404. mLWF.Show GetPlayerHWnd
  2405. dips(0) = 0 : dips(1) = 0
  2406. For ii = 1 To mChkCount + mOptCount
  2407. If mItems(ii)(1).Value Then dips(mItems(ii)(0) And &H01) = dips(mItems(ii)(0) And &H01) Or mItems(ii)(3)
  2408. Next
  2409. If useDip Then
  2410. With Controller
  2411. .Dip(0) = (dips(0) And 255)
  2412. .Dip(1) = ((dips(0) And 65280)\256) And 255
  2413. .Dip(2) = ((dips(0) And &H00ff0000)\65536) And 255
  2414. .Dip(3) = ((dips(0) And &Hff000000)\&H01000000) And 255
  2415. End With
  2416. End If
  2417. viewDipsExtra = dips(1)
  2418. End Function
  2419. End Class
  2420.  
  2421. '--------------------
  2422. ' Impulse Plunger
  2423. '--------------------
  2424. Class cvpmImpulseP
  2425. Private mEnabled, mBalls, mTrigger, mEntrySnd, mExitSnd, MExitSndBall
  2426. Public X, Y, Strength, Res, Size, Solenoid, IMPowerOut, Time, mCount, Pull, IMPowerTrans, cFactor, Auto, RandomOut, SwitchNum, SwitchOn, BallOn
  2427.  
  2428. Private Sub Class_Initialize
  2429. Size = 1 : Strength = 0 : Solenoid = 0 : Res = 1 : IMPowerOut = 0 : Time = 0 : mCount = 0 : mEnabled = False
  2430. Pull = 0 : IMPowerTrans = 0 : Auto = False : RandomOut = 0 : SwitchOn = 0 : SwitchNum = 0 : BallOn = 0
  2431. Set mBalls = New cvpmDictionary
  2432. End Sub
  2433.  
  2434. Private Property Let NeedUpdate(aEnabled) : vpmTimer.EnableUpdate Me, True, aEnabled : End Property
  2435.  
  2436. Public Sub InitImpulseP(aTrigger, aStrength, aTime)
  2437. Dim tmp
  2438. If vpmIsArray(aTrigger) Then Set tmp = aTrigger(0) Else Set tmp = aTrigger
  2439. X = tmp.X : Y = tmp.Y : Size = tmp.Radius : vpmTimer.InitTimer tmp, True
  2440. If IsArray(aTrigger) Then mTrigger = aTrigger Else Set mTrigger = aTrigger
  2441. Strength = aStrength
  2442. Res = 500
  2443. Time = aTime
  2444. If aTime = 0 Then
  2445. Auto = True
  2446. Else
  2447. cFactor = (Res / Time) / 100
  2448. Auto = False
  2449. End If
  2450. End Sub
  2451.  
  2452. Public Sub CreateEvents(aName)
  2453. If vpmCheckEvent(aName, Me) Then
  2454. vpmBuildEvent mTrigger, "Hit", aName & ".AddBall ActiveBall"
  2455. vpmBuildEvent mTrigger, "UnHit", aName & ".RemoveBall ActiveBall"
  2456. End If
  2457. End Sub
  2458.  
  2459.  
  2460. Public Property Let PlungeOn(aEnabled) : mEnabled = aEnabled : End Property
  2461. Public Property Get PlungeOn
  2462. If Solenoid > 0 Then PlungeOn = Controller.Solenoid(Solenoid) Else PlungeOn = mEnabled
  2463. End Property
  2464.  
  2465. Public Sub AddBall(aBall)
  2466. Dim mSwcopy
  2467. With mBalls
  2468. If .Exists(aBall) Then .Item(aBall) = .Item(aBall) + 1 Else .Add aBall, 1 : NeedUpdate = True
  2469. End With
  2470. If SwitchOn = True Then
  2471. mSwcopy = SwitchNum
  2472. Controller.Switch(mSwcopy) = 1
  2473. End If
  2474. BallOn = 1
  2475. End Sub
  2476.  
  2477. Public Sub RemoveBall(aBall)
  2478. Dim mSwcopy
  2479. With mBalls
  2480. If .Exists(aBall) Then .Item(aBall) = .Item(aBall) - 1 : If .Item(aBall) <= 0 Then .Remove aBall
  2481. NeedUpdate = (.Count > 0)
  2482. End With
  2483. If SwitchOn = True Then
  2484. mSwcopy = SwitchNum
  2485. Controller.Switch(mSwcopy) = 0
  2486. End If
  2487. BallOn = 0
  2488. End Sub
  2489.  
  2490. Public Property Get Balls : Balls = mBalls.Keys : End Property
  2491.  
  2492. Public Sub Update
  2493. Dim obj
  2494. If pull = 1 and mCount < Res Then
  2495. mCount = mCount + cFactor
  2496. IMPowerTrans = mCount
  2497. NeedUpdate = True
  2498. Else
  2499. IMPowerTrans = mCount
  2500. NeedUpdate = False
  2501. End If
  2502. If PlungeOn Then
  2503. On Error Resume Next
  2504. For Each obj In mBalls.Keys
  2505. If obj.X < 0 Or Err Then : mBalls.Remove obj : Else : PlungeBall obj : End If
  2506. Next
  2507. On Error Goto 0
  2508. End If
  2509. End Sub
  2510.  
  2511. Public Sub PlungeBall(aBall)
  2512. aBall.VelY = IMPowerOut
  2513. End Sub
  2514.  
  2515. Public Sub Random(aInput) ' Random Output Varience
  2516. RandomOut = aInput
  2517. End Sub
  2518.  
  2519. Public Sub Fire ' Resets System and Transfer Power Value
  2520. If Auto = True Then
  2521. IMPowerOut = -Strength + ((Rnd) * RandomOut)
  2522. Else
  2523. IMPowerOut = -Strength * (IMPowerTrans + ((Rnd-0.5) * cFactor * RandomOut)) / Res
  2524. End If
  2525. PlungeOn = True
  2526. Update
  2527. PlungeOn = False
  2528. Pull = 0 : IMPowerOut = 0 : IMPowerTrans = 0 : mCount = 0
  2529. If BallOn = 1 Then : PlaySound mExitSndBall : Else : PlaySound mExitSnd : End If
  2530. End Sub
  2531.  
  2532. Public Sub AutoFire ' Auto-Fire Specific Call (so you don't have to change timing)
  2533. IMPowerOut = -Strength + ((Rnd) * RandomOut)
  2534. PlungeOn = True
  2535. Update
  2536. PlungeOn = False
  2537. Pull = 0 : IMPowerOut = 0 : IMPowerTrans = 0 : mCount = 0
  2538. If BallOn = 1 Then : PlaySound mExitSndBall : Else : PlaySound mExitSnd : End If
  2539. End Sub
  2540.  
  2541. Public Sub Pullback ' Pull Plunger
  2542. Pull = 0 : IMPowerOut = 0 : IMPowerTrans = 0 : mCount = 0 ' reinitialize to be sure
  2543. Pull = 1 : NeedUpdate = True
  2544. PlaySound mEntrySnd
  2545. End Sub
  2546.  
  2547. Public Sub Switch(aSw)
  2548. SwitchOn = True
  2549. SwitchNum = aSw
  2550. End Sub
  2551.  
  2552. Public Sub InitEntrySnd(aNoBall) : mEntrySnd = aNoBall : End Sub
  2553. Public Sub InitExitSnd(aBall, aNoBall) : mExitSndBall = aBall : mExitSnd = aNoBall : End Sub
  2554. End Class
  2555.  
  2556. Set vpmTimer = New cvpmTimer
  2557. If LoadScript("NudgePlugIn.vbs") Then Set vpmNudge = New cvpmNudge2 Else Set vpmNudge = New cvpmNudge
  2558.  
  2559. '-------------
  2560. 'cvpmFlips (FastFlips) 2 Beta 1
  2561. '-------------
  2562.  
  2563. 'Redesigned to better support games from the solid-state flipper era, including previously unsupported games thanks to DJrobX and Stumblor!
  2564. 'New Features:
  2565. '- Switches from script to rom control after a delay (100ms default, vpmflips.RomControlDelay)
  2566. ' -This works independently for each flipper, ex. the Thing Flip will not interfere even briefly with lower flippers
  2567. '- New Feature - vpmFlips.Enabled. vpmFlips.Enabled = True / False will enable / disable fastflips. (This does the same thing as vpmflipsSAM.RomControl)
  2568. ' -May be necessary to manually disable flippers for video mode on some games
  2569. '- New method to disable upper flippers without getting rom errors from the double action cab switches: call helper subs NoUpperLeftFlipper, NoUpperRightFlipper
  2570. ' -On SS games that reuse upper flipper COILS, call the appropriate helper subs from the table script: NoUpperLeftFlipper, NoUpperRightFlipper (for example AFM)
  2571. ' -On SS games that reuse upper flipper SWITCHES, you will still need the cSingleLFlip/cSingleRFlip lines!
  2572. ' -CSinglexFlip automatically disables flippers to retain legacy behavior
  2573. '- Initializes using pulsetimer. VpmInit Me line no longer necessary (? may change)
  2574.  
  2575. 'Todo
  2576. 'test delay - works okay but a little weird if longer than romcontroldelay
  2577. 'test more tables
  2578. 'test Red & Ted with the left side flippers
  2579. 'test region safety
  2580. 'update SAM.vbs ?
  2581.  
  2582. dim vpmFlips : set vpmFlips = New cvpmFlips2 : vpmFlips.Name = "vpmFlips"
  2583.  
  2584. Sub NoUpperLeftFlipper() : vpmFlips.FlipperSolNumber(2) = 0 : End Sub
  2585. Sub NoUpperRightFlipper() : vpmFlips.FlipperSolNumber(3) = 0 : End Sub
  2586.  
  2587. Function NullFunction(a) : End Function
  2588.  
  2589. vpmtimer.addtimer 40, "vpmFlips.Init'" 'this might be a dumb idea but it would replace the requirement for vpminit me
  2590.  
  2591. Class cvpmFlips2 'test fastflips switches to rom control after 100ms or so delay
  2592. Public Name, Delay, TiltObjects, Sol, DebugOn
  2593. Public LagCompensation 'flag for solenoid jitter (may not be a problem anymore) set private
  2594.  
  2595. Public FlipperSolNumber(3) 'Flipper Solenoid Number. By default these are set to use the Core constants. 0=left 1=right 2=Uleft 3=URight
  2596. Public ButtonState(3) 'Key Flip State 'set private
  2597. Public SolState(3) 'Rom Flip State 'set private
  2598.  
  2599. 'Public SubL, SubUL, SubR, SubUR 'may restore these to reduce nested calls. For now the script is compressed a bit.
  2600. Public FlipperSub(3) 'Set to the flipper subs by .init
  2601.  
  2602. Public FlippersEnabled 'Flipper Circuit State (from the ROM)
  2603. Public OnOff 'FastFlips Enabled. Separate from FlippersEnabled, which is the flipper circuit state 'private 'todo rename
  2604.  
  2605. Public FlipAt(3) 'Flip Time in gametime 'private
  2606. Public RomControlDelay 'Delay after flipping that Rom Controlled Flips are accepted (default 100ms)
  2607.  
  2608.  
  2609. Private Sub Class_Initialize()
  2610. dim idx :for idx = 0 to 3 :FlipperSub(idx) = "NullFunction" : OnOff=True: ButtonState(idx)=0:SolState(idx)=0: Next
  2611. Delay=0: FlippersEnabled=0: DebugOn=0 : LagCompensation=0 : Sol=0 : TiltObjects=1
  2612. RomControlDelay = 100 'RomControlDelay MS between switching to rom controlled flippers
  2613. FlipperSolNumber(0)=sLLFlipper :FlipperSolNumber(1)=sLRFlipper :FlipperSolNumber(2)=sULFlipper :FlipperSolNumber(3)=sURFlipper
  2614. End Sub
  2615.  
  2616. Sub Init() 'called by a timer, but previously was called by vpminit sub
  2617. On Error Resume Next 'If there's no usesolenoids variable present, exit
  2618. call eval(UseSolenoids) : if err then exit Sub
  2619. On Error Goto 0
  2620. err.clear
  2621.  
  2622. 'Set Solenoid
  2623. if not UseSolenoids > 1 then exit sub
  2624. On Error Resume Next
  2625. 'For some WPC games (IJ) that reuse upper flipper
  2626. 'switch numbers, and legacy fast flip code, disable
  2627. 'flippers if cSinglexFlip is set.
  2628. If not cSingleLFlip Then
  2629. if err.number = 0 then NoUpperLeftFlipper
  2630. End If
  2631. err.clear
  2632. If not cSingleRFlip Then
  2633. if err.number = 0 then NoUpperRightFlipper
  2634. End If
  2635. err.clear
  2636. if UseSolenoids > 2 then
  2637. Solenoid = UseSolenoids
  2638. else
  2639. err.clear
  2640. if IsEmpty(GameOnSolenoid) or Err then msgbox "VPMflips error: " & err.description
  2641. if err = 500 then 'Error 500 - Variable not defined
  2642. msgbox "UseSolenoids = 2 error!" & vbnewline & vbnewline & "GameOnSolenoid is not defined!" & vbnewline & _
  2643. "System may be incompatible (Check the compatibility list) or your system scripts may be out of date"
  2644. End If
  2645. Solenoid = GameOnSolenoid
  2646. End If
  2647. On Error Goto 0
  2648.  
  2649. 'Set callbacks
  2650. dim idx : for idx = 0 to 3
  2651. If IsNumeric(FlipperSolNumber(idx)) then
  2652. Callback(idx) = SolCallback(abs(FlipperSolNumber(idx)))
  2653. end If
  2654. Next
  2655.  
  2656. 'dim str
  2657. 'for idx = 0 to 3 : str = str & "Callback" & idx & ":" & Callback(idx) &vbnewline : Next
  2658. 'str = "init successful" &vbnewline& _
  2659. ' "Sol=" & Solenoid & " " & sol &vbnewline& str
  2660. 'msgbox str
  2661. ''''vpmFlips.DebugTestInit = True 'removed debug stuff for the moment
  2662. End Sub
  2663.  
  2664. 'Index based callbacks...
  2665. Public Property Let Callback(aIdx, aInput)
  2666. if Not IsEmpty(aInput) then
  2667. FlipperSub(aIDX) = aInput 'hold old flipper subs
  2668. SolCallback(FlipperSolNumber(aIdx)) = name & ".RomFlip(" & aIdx & ")="
  2669. end if
  2670. End Property
  2671. Public Property Get Callback(aIdx) : CallBack = FlipperSub(aIDX) : End Property
  2672.  
  2673. Public Property Let Enabled(ByVal aEnabled) 'improving choreography
  2674. aEnabled = cBool(aEnabled)
  2675. if aEnabled <> OnOff then 'disregard redundant updates
  2676. OnOff = aEnabled
  2677. dim idx
  2678. If aEnabled then 'Switch to ROM solenoid states or button states immediately
  2679. for idx = 0 to 3
  2680. if SolState(idx) <> ButtonState(idx) And FlippersEnabled Then Execute FlipperSub(idx) &" "& ButtonState(idx) end If
  2681. Next
  2682. Else
  2683. for idx = 0 to 3 : if ButtonState(idx) <> SolState(idx) Then Execute FlipperSub(idx) &" "& SolState(idx) end if : Next
  2684. End If
  2685. end If
  2686. End Property
  2687. Public Property Get Enabled : Enabled = OnOff : End Property
  2688.  
  2689. Public Property Let Solenoid(aInput) : if isnumeric(aInput) then Sol = abs(aInput) : end if : End Property 'set solenoid
  2690. Public Property Get Solenoid : Solenoid = sol : End Property
  2691.  
  2692. Public Property Let Flip(aIdx, ByVal aEnabled) 'Key Flip: Indexed base flip... may keep may not
  2693. aEnabled = abs(aEnabled) 'True / False is not region safe with execute. Convert to 1 or 0 instead.
  2694. ButtonState(aIDX) = aEnabled 'track flipper button states: the game-on sol flips immediately if the button is held down
  2695. 'debug.print "Key Flip " & aIdx &" @ " & gametime & " FF ON: " & OnOff & " Circuit On? " & FlippersEnabled
  2696. If OnOff and FlippersEnabled or DebugOn then
  2697. execute FlipperSub(aIdx) & " " & aEnabled
  2698. FlipAt(aIDX) = GameTime
  2699. end If
  2700. End Property
  2701.  
  2702. 'call callbacks 'legacy
  2703. Public Sub FlipL(aEnabled) : Flip(0)=aEnabled :End Sub : Public Sub FlipR(aEnabled) : Flip(1)=aEnabled :End Sub
  2704. Public Sub FlipUL(aEnabled): Flip(2)=aEnabled :End Sub : Public Sub FlipUR(aEnabled): Flip(3)=aEnabled :End Sub
  2705.  
  2706. Public Property Let RomFlip(aIdx, ByVal aEnabled)
  2707. aEnabled = abs(aEnabled)
  2708. SolState(aIdx) = aEnabled
  2709.  
  2710. If Not OnOff OR GameTime >= FlipAt(aIdx) + RomControlDelay Then
  2711. Execute FlipperSub(aIDX) & " " & aEnabled
  2712. 'tb.text = "Rom Flip " & aIdx & " state:" & aEnabled &vbnewline&_
  2713. 'GameTime & " >= " & FlipAt(aIdx) & "+" & RomControlDelay
  2714. 'debug.print "rom flip @ " & gametime & "solenoid:" & sol & ": " & FlippersEnabled
  2715. end if
  2716. End property
  2717.  
  2718. Public Sub TiltSol(ByVal aEnabled) 'Handle solenoid / Delay (if delayinit)
  2719. aEnabled = cBool(aEnabled)
  2720. If delay > 0 and not aEnabled then 'handle delay
  2721. vpmtimer.addtimer Delay, Name & ".FireDelay" & "'"
  2722. LagCompensation = 1
  2723. else
  2724. If Delay > 0 then LagCompensation = 0
  2725. EnableFlippers(aEnabled)
  2726. end If
  2727. End Sub
  2728.  
  2729. Sub FireDelay() : If LagCompensation then EnableFlippers False End If : End Sub
  2730.  
  2731. Public Sub EnableFlippers(ByVal aEnabled) 'private
  2732. aEnabled = abs(aEnabled) 'Might fix TMNT issue with vpmnudge.solgameon?
  2733. dim idx
  2734. 'If aEnabled then execute SubL &" "& ButtonState(0) :execute SubR &" "& ButtonState(1) :execute subUL &" "& ButtonState(2): execute subUR &" "& ButtonState(3)':end if
  2735. If aEnabled then : for idx = 0 to 3 : execute FlipperSub(idx) &" "& ButtonState(idx) : next : end If
  2736. FlippersEnabled = aEnabled
  2737. If TiltObjects then vpmnudge.solgameon aEnabled
  2738. If Not aEnabled then
  2739. ' execute subL & " " & 0 : execute subR & " " & 0
  2740. ' execute subUL & " " & 0 : execute subUR & " " & 0
  2741. for idx = 0 to 3 : execute FlipperSub(idx) &" "& 0 : Next
  2742. End If
  2743. End Sub
  2744.  
  2745. 'debug for finding sols
  2746. Public Sub PrintSols() : Dim x, sols: sols=controller.solenoids: for x= 0 to uBound(sols) : if sols(x) then debug.print x & ":" & sols(x) end if : Next : End Sub
  2747.  
  2748. End Class
  2749.  
  2750. '---------------------------
  2751. ' Check VP version running
  2752. '---------------------------
  2753. Private Function vpmCheckVPVer
  2754. On Error Resume Next
  2755. ' a bug in VBS?: Err object is not cleared on Exit Function
  2756. If VPBuildVersion < 0 Or Err Then vpmCheckVPVer = 50 : Err.Clear : Exit Function
  2757. If VPBuildVersion > 2806 and VPBuildVersion < 9999 Then
  2758. vpmCheckVPVer = 63
  2759. ElseIf VPBuildVersion > 2721 and VPBuildVersion < 9999 Then
  2760. vpmCheckVPVer = 61
  2761. ElseIf VPBuildVersion >= 900 and VPBuildVersion <= 999 Then
  2762. vpmCheckVPVer = 90
  2763. ElseIf VPBuildVersion >= 10000 Then
  2764. vpmCheckVPVer = 100
  2765. Else
  2766. vpmCheckVPVer = 60
  2767. End If
  2768. End Function
  2769. Private vpmVPVer : vpmVPVer = vpmCheckVPVer()
  2770. '--------------------
  2771. ' Initialise timers
  2772. '--------------------
  2773. Sub PulseTimer_Init : vpmTimer.InitTimer Me, False : End Sub
  2774. Sub PinMAMETimer_Init : Me.Interval = PinMAMEInterval : Me.Enabled = True : End Sub
  2775.  
  2776. '---------------------------------------------
  2777. ' Init function called from Table_Init event
  2778. '---------------------------------------------
  2779. Public Sub vpmInit(aTable)
  2780. Set vpmTable = aTable
  2781. If vpmVPVer >= 60 Then
  2782. On Error Resume Next
  2783. If Not IsObject(GetRef(aTable.name & "_Paused")) Or Err Then Err.Clear : vpmBuildEvent aTable, "Paused", "Controller.Pause = True"
  2784. If Not IsObject(GetRef(aTable.name & "_UnPaused")) Or Err Then Err.Clear : vpmBuildEvent aTable, "UnPaused", "Controller.Pause = False"
  2785. If Not IsObject(GetRef(aTable.name & "_Exit")) Or Err Then Err.Clear : vpmBuildEvent aTable, "Exit", "Controller.Pause = False:Controller.Stop"
  2786. End If
  2787. if UseModSol Then
  2788. If Controller.Version >= 02080000 Then
  2789. Controller.SolMask(2)=1
  2790. Else
  2791. MsgBox "Modulated Flashers/Solenoids not supported with this Visual PinMAME version (2.8 or newer is required)"
  2792. End If
  2793. End If
  2794. 'InitVpmFlips 'have vpmtimer doing this atm
  2795. End Sub
  2796.  
  2797. ' Exit function called in Table_Exit event
  2798. Public Sub vpmExit : End Sub
  2799. '------------------------------------------------------
  2800. ' All classes call this function to create a ball
  2801. ' Assign vpmCreateBall if you want a custom function
  2802. '------------------------------------------------------
  2803. Private Function vpmDefCreateBall(aKicker)
  2804. If Not IsEmpty(vpmBallImage) Then aKicker.Createball.Image = vpmBallImage Else aKicker.Createball : End If
  2805. Set vpmDefCreateBall = aKicker
  2806. End Function
  2807.  
  2808. Private Function vpmDefCreateBall2(aKicker)
  2809. If Not IsEmpty(vpmBallImage) Then aKicker.Createsizedball(BSize).Image = vpmBallImage Else aKicker.Createsizedball(BSize) : End If
  2810. Set vpmDefCreateBall2 = aKicker
  2811. End Function
  2812.  
  2813. Private Function vpmDefCreateBall3(aKicker)
  2814. If Not IsEmpty(vpmBallImage) Then
  2815. aKicker.CreateSizedBallWithMass(BSize,BMass).Image = vpmBallImage
  2816. Else
  2817. aKicker.CreateSizedBallWithMass BSize,BMass ' for whatever reason it doesn't work if using ()
  2818. End If
  2819. Set vpmDefCreateBall3 = aKicker
  2820. End Function
  2821.  
  2822. If VPBuildVersion >= 10000 Then
  2823. Set vpmCreateBall = GetRef("vpmDefCreateBall3")
  2824. ElseIf VPBuildVersion > 909 And vpmVPVer >= 90 Then
  2825. Set vpmCreateBall = GetRef("vpmDefCreateBall2")
  2826. Else
  2827. Set vpmCreateBall = GetRef("vpmDefCreateBall")
  2828. End If
  2829.  
  2830. Private vpmTrough ' Default Trough. Used to clear up missing balls
  2831. Private vpmTable ' Table object
  2832.  
  2833. '-------------------
  2834. ' Main Loop
  2835. '------------------
  2836. Private Const CHGNO = 0
  2837. Private Const CHGSTATE = 1
  2838. Private vpmTrueFalse : vpmTrueFalse = Array(" True", " False"," True")
  2839.  
  2840. Sub vpmDoSolCallback(aNo, aEnabled)
  2841. If SolCallback(aNo) <> "" Then Execute SolCallback(aNo) & vpmTrueFalse(aEnabled+1)
  2842. End Sub
  2843.  
  2844. Sub vpmDoLampUpdate(aNo, aEnabled)
  2845. On Error Resume Next : Lights(aNo).State = Abs(aEnabled)
  2846. End Sub
  2847.  
  2848. Sub PinMAMETimer_Timer
  2849. Dim ChgLamp,ChgSol,ChgGI, ii, tmp, idx, nsol, solon
  2850. Dim DMDp
  2851. Dim ChgNVRAM
  2852.  
  2853. 'Me.Enabled = False 'this was supposed to be some kind of weird mutex, disable it
  2854.  
  2855. On Error Resume Next
  2856. If UseDMD Then
  2857. DMDp = Controller.RawDmdPixels
  2858. If Not IsEmpty(DMDp) Then
  2859. DMDWidth = Controller.RawDmdWidth
  2860. DMDHeight = Controller.RawDmdHeight
  2861. DMDPixels = DMDp
  2862. End If
  2863. ElseIf UseColoredDMD Then
  2864. DMDp = Controller.RawDmdColoredPixels
  2865. If Not IsEmpty(DMDp) Then
  2866. DMDWidth = Controller.RawDmdWidth
  2867. DMDHeight = Controller.RawDmdHeight
  2868. DMDColoredPixels = DMDp
  2869. End If
  2870. End If
  2871. If UseNVRAM Then
  2872. If isObject(NVRAMCallback) Then
  2873. ChgNVRAM = Controller.ChangedNVRAM 'Controller.NVRAM would deliver everything of the NVRAM all the time as 1D array
  2874. If(Not IsEmpty(ChgNVRAM)) Then NVRAMCallback ChgNVRAM
  2875. End If
  2876. End If
  2877. If UseLamps Then ChgLamp = Controller.ChangedLamps Else LampCallback
  2878. If UseSolenoids Then ChgSol = Controller.ChangedSolenoids
  2879. If isObject(GICallback) or isObject(GICallback2) Then ChgGI = Controller.ChangedGIStrings
  2880. MotorCallback
  2881. On Error Goto 0
  2882. If Not IsEmpty(ChgLamp) Then
  2883. On Error Resume Next
  2884. For ii = 0 To UBound(ChgLamp)
  2885. idx = chgLamp(ii, 0)
  2886. If IsArray(Lights(idx)) Then
  2887. For Each tmp In Lights(idx) : tmp.State = ChgLamp(ii, 1) : Next
  2888. Else
  2889. Lights(idx).State = ChgLamp(ii, 1)
  2890. End If
  2891. Next
  2892. For Each tmp In vpmMultiLights
  2893. For ii = 1 To UBound(tmp) : tmp(ii).State = tmp(0).State : Next
  2894. Next
  2895. LampCallback
  2896. On Error Goto 0
  2897. End If
  2898. If Not IsEmpty(ChgSol) Then
  2899. For ii = 0 To UBound(ChgSol)
  2900. nsol = ChgSol(ii, 0)
  2901. tmp = SolCallback(nsol)
  2902. solon = ChgSol(ii, 1)
  2903. If solon > 1 Then solon = 1
  2904. If UseModSol Then
  2905. If solon <> SolPrevState(nsol) Then
  2906. SolPrevState(nsol) = solon
  2907. If tmp <> "" Then Execute tmp & vpmTrueFalse(solon+1)
  2908. End If
  2909. tmp = SolModCallback(nsol)
  2910. If tmp <> "" Then Execute tmp & " " & ChgSol(ii, 1)
  2911. Else
  2912. If tmp <> "" Then Execute tmp & vpmTrueFalse(solon+1)
  2913. End If
  2914. if UseSolenoids > 1 then if nsol = vpmFlips.Solenoid then vpmFlips.TiltSol solon ': msgbox solon
  2915. Next
  2916. End If
  2917. If Not IsEmpty(ChgGI) Then
  2918. For ii = 0 To UBound(ChgGI)
  2919. GICallback ChgGI(ii, 0), CBool(ChgGI(ii, 1))
  2920. GICallback2 ChgGI(ii, 0), ChgGI(ii, 1)
  2921. Next
  2922. End If
  2923.  
  2924. 'Me.Enabled = True 'this was supposed to be some kind of weird mutex, disable it
  2925. End Sub
  2926.  
  2927. '
  2928. ' Private helper functions
  2929. '
  2930. Private Sub vpmPlaySound(aEnabled, aSound)
  2931. If VarType(aSound) = vbString Then
  2932. If aEnabled Then StopSound aSound : PlaySound aSound
  2933. ElseIf aSound Then
  2934. If aEnabled Then PlaySound SSolenoidOn Else PlaySound SSolenoidOff
  2935. End If
  2936. End Sub
  2937.  
  2938. Private Sub vpmToggleObj(aObj, aEnabled)
  2939. Dim mSwcopy
  2940. Select Case TypeName(aObj)
  2941. Case "Wall", "HitTarget" aObj.IsDropped = aEnabled
  2942. Case "Bumper", "Light" aObj.State = Abs(aEnabled)
  2943. Case "Kicker", "Trigger", "Timer" aObj.Enabled = aEnabled
  2944. Case "Gate" aObj.Open = aEnabled
  2945. Case "Primitive", "Ramp", "Rubber", "Flasher" aObj.Visible = aEnabled
  2946. Case "Integer" mSwcopy = aObj : Controller.Switch(mSwcopy) = aEnabled
  2947. Case Else MsgBox "vpmToggleObj: Unhandled Object " & TypeName(aObj)
  2948. End Select
  2949. End Sub
  2950.  
  2951. Private Function vpmCheckEvent(aName, aObj)
  2952. vpmCheckEvent = True
  2953. On Error Resume Next
  2954. If Not Eval(aName) Is aObj Or Err Then MsgBox "CreateEvents: Wrong name " & aName : vpmCheckEvent = False
  2955. End Function
  2956.  
  2957. Private Sub vpmBuildEvent(aObj, aEvent, aTask)
  2958. Dim obj, str
  2959. str = "_" & aEvent & " : " & aTask & " : End Sub"
  2960. If vpmIsArray(aObj) Then
  2961. For Each obj In aObj : ExecuteGlobal "Sub " & obj.Name & str : Next
  2962. Else
  2963. ExecuteGlobal "Sub " & aObj.Name & str
  2964. End If
  2965. End Sub
  2966.  
  2967. Private Function vpmIsCollection(aObj)
  2968. vpmIsCollection = TypeName(aObj) = "Collection" Or TypeName(aObj) = "ICollection"
  2969. End Function
  2970. Private Function vpmIsArray(aObj)
  2971. vpmIsArray = IsArray(aObj) Or vpmIsCollection(aObj)
  2972. End Function
  2973.  
  2974. Private Function vpmSetArray(aTo, aFrom)
  2975. If IsArray(aFrom) Then
  2976. aTo = aFrom : vpmSetArray = UBound(aFrom)
  2977. ElseIf vpmIsCollection(aFrom) Then
  2978. Set aTo = aFrom : vpmSetArray = aFrom.Count - 1
  2979. Else
  2980. aTo = Array(aFrom) : vpmSetArray = 0
  2981. End If
  2982. End Function
  2983.  
  2984. Sub vpmCreateEvents(aHitObjs)
  2985. Dim obj
  2986. For Each obj In aHitObjs
  2987. Select Case TypeName(obj)
  2988. Case "Trigger"
  2989. vpmBuildEvent obj, "Hit", "Controller.Switch(" & Obj.TimerInterval & ") = True"
  2990. vpmBuildEvent obj, "UnHit", "Controller.Switch(" & Obj.TimerInterval & ") = False"
  2991. Case "Wall"
  2992. If obj.HasHitEvent Then
  2993. vpmBuildEvent obj, "Hit", "vpmTimer.PulseSw " & Obj.TimerInterval
  2994. Else
  2995. vpmBuildEvent obj, "SlingShot", "vpmTimer.PulseSw " & Obj.TimerInterval
  2996. End If
  2997. Case "Bumper", "Gate", "Primitive", "HitTarget", "Rubber"
  2998. vpmBuildEvent obj, "Hit", "vpmTimer.PulseSw " & Obj.TimerInterval
  2999. Case "Spinner"
  3000. vpmBuildEvent obj, "Spin", "vpmTimer.PulseSw " & Obj.TimerInterval
  3001. End Select
  3002. Next
  3003. End Sub
  3004.  
  3005. Sub vpmMapLights(aLights)
  3006. Dim obj, str, ii, idx
  3007. For Each obj In aLights
  3008. idx = obj.TimerInterval
  3009. If IsArray(Lights(idx)) Then
  3010. str = "Lights(" & idx & ") = Array("
  3011. For Each ii In Lights(idx) : str = str & ii.Name & "," : Next
  3012. ExecuteGlobal str & obj.Name & ")"
  3013. ElseIf IsObject(Lights(idx)) Then
  3014. Lights(idx) = Array(Lights(idx),obj)
  3015. Else
  3016. Set Lights(idx) = obj
  3017. End If
  3018. Next
  3019. End Sub
  3020.  
  3021. Function vpmMoveBall(aBall, aFromKick, aToKick)
  3022. With aToKick.CreateBall
  3023. If TypeName(aBall) = "IBall" Then
  3024. .Color = aBall.Color : .Image = aBall.Image
  3025. If vpmVPVer >= 60 Then
  3026. .FrontDecal = aBall.FrontDecal : .BackDecal = aBall.BackDecal
  3027. ' .UserValue = aBall.UserValue
  3028. End If
  3029. End If
  3030. End With
  3031. aFromKick.DestroyBall : Set vpmMoveBall = aToKick
  3032. End Function
  3033.  
  3034. Sub vpmAddBall
  3035. Dim Answer
  3036. If IsObject(vpmTrough) Then
  3037. Answer=MsgBox("Click YES to Add a ball to the Trough, NO Removes a ball from the Trough",vbYesNoCancel + vbQuestion)
  3038. If Answer = vbYes Then vpmTrough.AddBall 0
  3039. If Answer = vbNo Then vpmTrough.Balls=vpmTrough.Balls-1
  3040. End If
  3041. End Sub
  3042.  
  3043. '----------------------------
  3044. ' Generic solenoid handlers
  3045. '----------------------------
  3046. ' ----- Flippers ------
  3047. Sub vpmSolFlipper(aFlip1, aFlip2, aEnabled)
  3048. Dim oldStrength, oldSpeed ' only for pre-VP10
  3049. If aEnabled Then
  3050. PlaySound SFlipperOn : aFlip1.RotateToEnd : If Not aFlip2 Is Nothing Then aFlip2.RotateToEnd
  3051. Else
  3052. PlaySound SFlipperOff
  3053. If VPBuildVersion < 10000 Then
  3054. oldStrength = aFlip1.Strength : aFlip1.Strength = conFlipRetStrength
  3055. oldSpeed = aFlip1.Speed : aFlip1.Speed = conFlipRetSpeed
  3056. End If
  3057. aFlip1.RotateToStart
  3058. If VPBuildVersion < 10000 Then
  3059. aFlip1.Strength = oldStrength
  3060. aFlip1.Speed = oldSpeed
  3061. End If
  3062. If Not aFlip2 Is Nothing Then
  3063. If VPBuildVersion < 10000 Then
  3064. oldStrength = aFlip2.Strength : aFlip2.Strength = conFlipRetStrength
  3065. oldSpeed = aFlip2.Speed : aFlip2.Speed = conFlipRetSpeed
  3066. End If
  3067. aFlip2.RotateToStart
  3068. If VPBuildVersion < 10000 Then
  3069. aFlip2.Strength = oldStrength
  3070. aFlip2.Speed = oldSpeed
  3071. End If
  3072. End If
  3073. End If
  3074. End Sub
  3075.  
  3076. ' ----- Flippers With Speed Control ------
  3077. Sub vpmSolFlip2(aFlip1, aFlip2, aFlipSpeedUp, aFlipSpeedDn, aSnd, aEnabled) ' DEPRECATED, as VP10 does not feature speed on flippers anymore
  3078. Dim oldStrength, oldSpeed
  3079. If aEnabled Then
  3080. If aSnd = true then : PlaySound SFlipperOn : End If
  3081. If Not aFlipSpeedUp = 0 Then
  3082. aFlip1.Speed = aFlipSpeedUp
  3083. aFlip1.RotateToEnd
  3084. Else
  3085. aFlip1.RotateToEnd
  3086. End If
  3087. If Not aFlip2 Is Nothing Then
  3088. If Not aFlipSpeedUp = 0 Then
  3089. aFlip2.Speed = aFlipSpeedUp
  3090. aFlip2.RotateToEnd
  3091. Else
  3092. aFlip2.RotateToEnd
  3093. End If
  3094. End If
  3095. Else
  3096. If aSnd = true then : PlaySound SFlipperOff : End If
  3097. oldStrength = aFlip1.Strength
  3098. aFlip1.Strength = conFlipRetStrength
  3099. oldSpeed = aFlip1.Speed
  3100. If Not aFlipSpeedDn = 0 Then
  3101. aFlip1.Speed = aFlipSpeedDn
  3102. Else
  3103. aFlip1.Speed = conFlipRetSpeed
  3104. End If
  3105. aFlip1.RotateToStart : aFlip1.Strength = oldStrength : aFlip1.Speed = oldSpeed
  3106. If Not aFlip2 Is Nothing Then
  3107. oldStrength = aFlip2.Strength
  3108. oldSpeed = aFlip2.Speed
  3109. If Not aFlipSpeedDn = 0 Then
  3110. aFlip2.Speed = aFlipSpeedDn
  3111. Else
  3112. aFlip2.Speed = conFlipRetSpeed
  3113. End If
  3114. aFlip2.Strength = conFlipRetStrength
  3115. aFlip2.RotateToStart : aFlip2.Strength = oldStrength : aFlip2.Speed = oldSpeed
  3116. End If
  3117. End If
  3118. End Sub
  3119.  
  3120. ' ------ Diverters ------
  3121. Sub vpmSolDiverter(aDiv, aSound, aEnabled)
  3122. If aEnabled Then aDiv.RotateToEnd : Else aDiv.RotateToStart
  3123. vpmPlaySound aEnabled, aSound
  3124. End sub
  3125.  
  3126. ' ------ Walls ------
  3127. Sub vpmSolWall(aWall, aSound, aEnabled)
  3128. Dim obj
  3129. If vpmIsArray(aWall) Then
  3130. For Each obj In aWall : obj.IsDropped = aEnabled : Next
  3131. Else
  3132. aWall.IsDropped = aEnabled
  3133. End If
  3134. vpmPlaySound aEnabled, aSound
  3135. End Sub
  3136.  
  3137. Sub vpmSolToggleWall(aWall1, aWall2, aSound, aEnabled)
  3138. Dim obj
  3139. If vpmIsArray(aWall1) Then
  3140. For Each obj In aWall1 : obj.IsDropped = aEnabled : Next
  3141. Else
  3142. aWall1.IsDropped = aEnabled
  3143. End If
  3144. If vpmIsArray(aWall2) Then
  3145. For Each obj In aWall2 : obj.IsDropped = Not aEnabled : Next
  3146. Else
  3147. aWall2.IsDropped = Not aEnabled
  3148. End If
  3149. vpmPlaySound aEnabled, aSound
  3150. End Sub
  3151.  
  3152. ' ------- Autoplunger ------
  3153. Sub vpmSolAutoPlunger(aPlung, aVar, aEnabled)
  3154. Dim oldFire
  3155. If aEnabled Then
  3156. oldFire = aPlung.FireSpeed : aPlung.FireSpeed = oldFire * (100-aVar*(2*Rnd-1))/100
  3157. PlaySound SSolenoidOn : aPlung.Fire : aPlung.FireSpeed = oldFire
  3158. Else
  3159. aPlung.Pullback
  3160. End If
  3161. End Sub
  3162.  
  3163. ' --------Autoplunger with Specified Sound To Play ---------
  3164. Sub vpmSolAutoPlungeS(aPlung, aSound, aVar, aEnabled)
  3165. Dim oldFire
  3166. If aEnabled Then
  3167. oldFire = aPlung.FireSpeed : aPlung.FireSpeed = oldFire * (100-aVar*(2*Rnd-1))/100
  3168. PlaySound aSound : aPlung.Fire : aPlung.FireSpeed = oldFire
  3169. Else
  3170. aPlung.Pullback
  3171. End If
  3172. End Sub
  3173.  
  3174. ' --------- Gate -----------
  3175. Sub vpmSolGate(aGate, aSound, aEnabled)
  3176. Dim obj
  3177. If vpmIsArray(aGate) Then
  3178. For Each obj In aGate : obj.Open = aEnabled : Next
  3179. Else
  3180. aGate.Open = aEnabled
  3181. End If
  3182. vpmPlaySound aEnabled, aSound
  3183. End Sub
  3184.  
  3185. ' ------ Sound Only -------
  3186. Sub vpmSolSound(aSound, aEnabled)
  3187. If aEnabled Then StopSound aSound : PlaySound aSound
  3188. End Sub
  3189.  
  3190. ' ------- Flashers --------
  3191. Sub vpmFlasher(aFlash, aEnabled)
  3192. Dim obj
  3193. If vpmIsArray(aFlash) Then
  3194. For Each obj In aFlash : obj.State = Abs(aEnabled) : Next
  3195. Else
  3196. aFlash.State = Abs(aEnabled)
  3197. End If
  3198. End Sub
  3199.  
  3200. '---- Generic object toggle ----
  3201. Sub vpmSolToggleObj(aObj1, aObj2, aSound, aEnabled)
  3202. Dim obj
  3203. If vpmIsArray(aObj1) Then
  3204. If IsArray(aObj1(0)) Then
  3205. For Each obj In aObj1(0) : vpmToggleObj obj, aEnabled : Next
  3206. For Each obj In aObj1(1) : vpmToggleObj obj, Not aEnabled : Next
  3207. Else
  3208. For Each obj In aObj1 : vpmToggleObj obj, aEnabled : Next
  3209. End If
  3210. ElseIf Not aObj1 Is Nothing Then
  3211. vpmToggleObj aObj1, aEnabled
  3212. End If
  3213. If vpmIsArray(aObj2) Then
  3214. If IsArray(aObj2(0)) Then
  3215. For Each obj In aObj2(0) : vpmToggleObj obj, Not aEnabled : Next
  3216. For Each obj In aObj2(1) : vpmToggleObj obj, aEnabled : Next
  3217. Else
  3218. For Each obj In aObj2 : vpmToggleObj obj, Not aEnabled : Next
  3219. End If
  3220. ElseIf Not aObj2 Is Nothing Then
  3221. vpmToggleObj aObj2, Not aEnabled
  3222. End If
  3223. vpmPlaySound aEnabled, aSound
  3224. End Sub
  3225.  
  3226. '
  3227. ' Stubs to allow older games to still work
  3228. ' These will be removed one day
  3229. '
  3230. Sub SolFlipper(f1,f2,e) : vpmSolFlipper f1,f2,e : End Sub
  3231. Sub SolDiverter(d,s,e) : vpmSolDiverter d,s,e : End Sub
  3232. Sub SolSound(s,e) : vpmSolSound s,e : End Sub
  3233. Sub Flasher(f,e) : vpmFlasher f,e : End Sub
  3234. Sub SolMagnet(m,e) : vpmSolMagnet m,e : End Sub
  3235. Sub SolAutoPlunger(p,e) : vpmSolAutoPlunger p,0,e : End Sub
  3236. Function KeyDownHandler(ByVal k) : KeyDownHandler = vpmKeyDown(k) : End Function
  3237. Function KeyUpHandler(ByVal k) : KeyUpHandler = vpmKeyUp(k) : End Function
  3238. Function KeyName(ByVal k) : KeyName = vpmKeyName(k) : End Function
  3239. Sub vpmSolMagnet(m,e) : m.Enabled = e : If Not e Then m.Kick 180,1 : End If : End Sub
  3240. Dim vpmBallImage : vpmBallImage = Empty ' Default ball properties
  3241. Dim vpmBallColour
  3242.  
  3243. '-- Flipper solenoids (all games)
  3244. Const sLRFlipper = 46
  3245. Const sLLFlipper = 48
  3246. Const sURFlipper = 34
  3247. Const sULFlipper = 36
  3248.  
  3249. ' Convert keycode to readable string
  3250. Private keyNames1, keyNames2
  3251. keyNames1 = Array("Escape","1","2","3","4","5","6","7","8","9","0","Minus '-'",_
  3252. "Equals '='","Backspace","Tab","Q","W","E","R","T","Y","U","I","O","P","[","]",_
  3253. "Enter","Left Ctrl","A","S","D","F","G","H","J","K","L",";","'","`","Left Shift",_
  3254. "\","Z","X","C","V","B","N","M",",",".","/","Right Shift","*","Left Menu","Space",_
  3255. "Caps Lock","F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","NumLock","ScrlLock",_
  3256. "Numpad 7","Numpad 8","Numpad 9","Numpad -","Numpad 4","Numpad 5","Numpad 6",_
  3257. "Numpad +","Numpad 1","Numpad 2","Numpad 3","Numpad 0","Numpad .","?","?","?",_
  3258. "F11","F12","F13","F14","F15")
  3259. keyNames2 = Array("Pause","?","Home","Up","PageUp","?","Left","?","Right","?",_
  3260. "End","Down","PageDown","Insert","Delete")
  3261.  
  3262. Function vpmKeyName(ByVal aKeycode)
  3263. If aKeyCode-1 <= UBound(keyNames1) Then
  3264. vpmKeyName = keyNames1(aKeyCode-1)
  3265. ElseIf aKeyCode >= 197 And aKeyCode <= 211 Then
  3266. vpmKeyName = keyNames2(aKeyCode-197)
  3267. ElseIf aKeyCode = 184 Then
  3268. vpmKeyName = "R.Alt"
  3269. Else
  3270. vpmKeyName = "?"
  3271. End If
  3272. End Function
  3273.  
  3274. Private vpmSystemHelp
  3275. Private Sub vpmShowHelp
  3276. Dim szKeyMsg
  3277. szKeyMsg = "The following keys are defined: " & vbNewLine &_
  3278. "(American keyboard layout)" & vbNewLine &_
  3279. vbNewLine & "Visual PinMAME keys:" & vbNewLine &_
  3280. vpmKeyName(keyShowOpts) & vbTab & "Game options..." & vbNewLine &_
  3281. vpmKeyName(keyShowKeys) & vbTab & "Keyboard settings..." & vbNewLine &_
  3282. vpmKeyName(keyReset) & vbTab & "Reset emulation" & vbNewLine &_
  3283. vpmKeyName(keyFrame) & vbTab & "Toggle Display lock" & vbNewLine &_
  3284. vpmKeyName(keyDoubleSize) & vbTab & "Toggle Display size" & vbNewLine
  3285. If IsObject(vpmShowDips) Then
  3286. szKeyMsg = szKeyMsg & vpmKeyName(keyShowDips) & vbTab & "Show DIP Switch / Option Menu" & vbNewLine
  3287. End If
  3288. If IsObject(vpmTrough) Then
  3289. szKeyMsg = szKeyMsg & vpmKeyName(keyAddBall) & vbTab & "Add / Remove Ball From Table" & vbNewLine
  3290. End If
  3291. szKeyMsg = szKeyMsg & vpmKeyName(keyBangBack) & vbTab & "Bang Back" & vbNewLine &_
  3292. vbNewLine & vpmSystemHelp & vbNewLine
  3293. If ExtraKeyHelp <> "" Then
  3294. szKeyMsg = szKeyMsg & vbNewLine & "Game Specific keys:" &_
  3295. vbNewLine & ExtraKeyHelp & vbNewLine
  3296. End If
  3297. szKeyMsg = szKeyMsg & vbNewLine & "Visual Pinball keys:" & vbNewLine &_
  3298. vpmKeyName(LeftFlipperKey) & vbTab & "Left Flipper" & vbNewLine &_
  3299. vpmKeyName(RightFlipperKey) & vbTab & "Right Flipper" & vbNewLine &_
  3300. vpmKeyName(LeftMagnaSave) & vbTab & "Left Magna Save" & vbNewLine &_
  3301. vpmKeyName(RightMagnaSave) & vbTab & "Right Magna Save" & vbNewLine &_
  3302. vpmKeyName(PlungerKey) & vbTab & "Launch Ball" & vbNewLine &_
  3303. vpmKeyName(StartGameKey) & vbTab & "Start Button" & vbNewLine &_
  3304. vpmKeyName(AddCreditKey) & vbTab & "Insert Coin 1" & vbNewLine &_
  3305. vpmKeyName(AddCreditKey2) & vbTab & "Insert Coin 2" & vbNewLine &_
  3306. vpmKeyName(ExitGame) & vbTab & "Exit Game" & vbNewLine &_
  3307. vpmKeyName(MechanicalTilt) & vbTab & "Mechanical Tilt" & vbNewLine &_
  3308. vpmKeyName(LeftTiltKey) & vbTab & "Nudge from Left" & vbNewLine &_
  3309. vpmKeyName(RightTiltKey) & vbTab & "Nudge from Right" & vbNewLine &_
  3310. vpmKeyName(CenterTiltKey) & vbTab & "Nudge forward" & vbNewLine
  3311. MsgBox szKeyMsg,vbOkOnly,"Keyboard Settings..."
  3312. End Sub
  3313.  
  3314. Private Sub NullSub(no,enabled)
  3315. 'Place Holder Sub
  3316. End Sub
  3317.  
  3318. 'added thanks to Koadic
  3319. Sub NVOffset(version) ' version 2 for dB2S compatibility
  3320. Dim check,nvcheck,v,vv,nvpath,rom
  3321. Set check = CreateObject("Scripting.FileSystemObject")
  3322. Set nvcheck = CreateObject("WScript.Shell")
  3323. nvpath = nvcheck.RegRead("HKCU\Software\Freeware\Visual PinMame\globals\nvram_directory") & "\"
  3324. rom = controller.gamename
  3325. For v=1 to 32 'check up to 32 possible versions using same rom, it's overkill, but could be changed to a lower number (requested for 32 NFL variations)
  3326. If check.FileExists(nvpath & rom & " v" & v & ".txt") Then vv=v : exit For : End If
  3327. vv=0
  3328. Next
  3329. If vv=version or version = 0 Then
  3330. Exit Sub
  3331. ElseIf vv=0 Then
  3332. check.CreateTextFile nvpath & rom & " v" & version & ".txt", True
  3333. Exit Sub
  3334. Else
  3335. check.moveFile nvpath & rom & " v" & vv & ".txt", nvpath & rom & " v" & version & ".txt"
  3336. If check.FileExists(nvpath & rom & ".nv") Then
  3337. check.copyFile nvpath & rom & ".nv", nvpath & rom & " v" & vv & ".nv", True
  3338. End If
  3339. If check.FileExists(nvpath & rom & " v" & version & ".nv") Then
  3340. check.copyFile nvpath & rom & " v" & version & ".nv", nvpath & rom & ".nv", True
  3341. End If
  3342. End If
  3343. End Sub
  3344.  
  3345. Sub VPMVol
  3346. dim VolPM,VolPMNew
  3347. VolPM = Controller.Games(controller.GameName).Settings.Value("volume")
  3348. VolPMNew = InputBox ("Enter desired VPinMame Volume Level (-32 to 0)","VPinMame Volume",VolPM)
  3349. If VolPMNew = "" Then Exit Sub
  3350. If VolPMNew <=0 and VolPMNew >= -32 Then
  3351. Controller.Games(controller.GameName).Settings.Value("volume")= round(VolPMNew)
  3352. msgbox "The Visual PinMAME Global Volume is now set to " & round(VolPMNew) & "db." & VbNewLine & VbNewLine & "Please reset Visual PinMAME (F3) to apply."
  3353. Else
  3354. msgbox "Entered value is out of range. Entry must be in the range of negative 32 to 0." & VbNewLine & VbNewLine & "Visual PinMAME Global Volume will remain set at " & VolPM & "."
  3355. End If
  3356. End Sub
  3357.  
  3358. ' Simple min/max functions
  3359. Function vpMin(a, b) : If a < b Then vpMin = a Else vpMin = b : End If : End Function
  3360. Function vpMax(a, b) : If a > b Then vpMax = a Else vpMax = b : End If : End Function
  3361.  
  3362. LoadScript("ledcontrol.vbs"):Err.Clear ' Checks for existance of ledcontrol.vbs and loads it if found, if found but no ledwiz installed, clear error to allow loading of table
  3363.  
  3364. LoadScript("GlobalPlugIn.vbs") ' Checks for existance of GlobalPlugIn.vbs and loads it if found, useful for adding
  3365. ' custom scripting that can be used for all tables instead of altering the core.vbs
Add Comment
Please, Sign In to add comment