-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore_c_sharp.vbs
More file actions
3404 lines (3076 loc) · 130 KB
/
core_c_sharp.vbs
File metadata and controls
3404 lines (3076 loc) · 130 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Option Explicit
Const VPinMAMEDriverVer = 3.57
'=======================
' VPinMAME driver core.
'=======================
' Changes Switch calls to Controller.Switch 36, 1 instead of Controller.Switch(36) = True
' Use const PdbOffColor to set VP light color when light is off.
' New in 3.57 (Update by nFozzy, DJRobX, chepas, Gaston)
' - Beta 1 NF fastflips 2
' - Add UsePdbLeds(top of script)/ChangedPDLEDs(controller)/PDLedCallback(callback) support and PDB.vbs especially for VP-PROC
' - Added LTD3.vbs (LTD System III)
' - Added FPVPX.vbs (1.01, helpers for Future Pinball conversions)
'
' New in 3.56 (Update by nFozzy, DJRobX, Fuzzel)
' - Add specialized sega2.vbs for Apollo 13 and GoldenEye
' - 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
' - vpmFlips fixes / improvements
' - Fixed vpmFlips execute script error
' - Added extra error check for detecting outdated system vbs files when UseSolenoids = 2
' - Change GameOnSolenoid from 16 to 19 for Hankin
' - Fixed an execute script issue that was causing dead flippers for some system languages
' - S.A.M. fast flips support: To activate, add InitVpmFFlipsSAM to the table init.
' Should work for most games (see PinMAME whatsnew for supported sets). May need additional configuration for two-stage flipper support.
' - Whitestar fast flips support
' - Capcom fast flips support
' - Fix WPC tables that use 'cSingleLFlip' (regression from 3.55)
' - Fix script errors if using NudgePlugIn.vbs
' - Add Rubber, Ramp, Flasher, Primitive and HitTarget support to vpmToggleObj
' - Add Rubber, Primitive and HitTarget support to vpmCreateEvents
'
' New in 3.55 (Update by nFozzy)
' - Prevent 'object not a collection' errors if vpmNudge.TiltObj isn't set
' - Support for double leaf flipper switches
' - For now, keybinds for these staged flippers are defined in VPMKeys.vbs. By default they are set to LeftFlipperKey and RightFlipperKey, disabling them.
' - Adapting older tables requires vpmFlips: Create upper flipper subs and point SolCallback(sULFlipper) and SolCallback(sURFlipper) to them.
' - 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
' - Integrated FastFlips, (new object vpmFlips): Low latency flipper response for games with pre-solid state flippers
' - Ensure 'vpmInit me' is called in the table init section
' - UseSolenoids = 2 enables and auto sets the game-on solenoid (based on GameOnSolenoid in the system .vbs script)
' - Important info on supported WPC games is documented in WPC.vbs
' - Pre-solid-state flipper games (except Zaccaria and LTD) should work perfectly. This includes Bally/Williams WPCs up to Terminator 2 / Party Zone
' - Data East / early Segas will work perfectly, unless they have ROM-controlled flipper effects
' - 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)
' - Sega Whitestar (Apollo 13 / Goldeneye / etc), WPC95 (Congo / AFM / etc), and Capcom and everything onward will not work
' - 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'
'
' New in 3.54 (Update by mfuegemann & nFozzy & Ninuzzu/Tom Tower & Toxie)
' - Added UltraDMD_Options.vbs to configure Ultra DMD based tables globally (see the file itself for detailed descriptions)
' - Added sam.vbs
' - Added Class1812.vbs
' - Added inder_centaur.vbs
' - Restore basic functionality of cvpmDropTarget.CreateEvents for drop targets with an animation time (e.g. VP10 and newer)
' - Minor cleanups and code unifications for all machines
' - Add keyConfigurations to VPMKeys.vbs for Taito and also remap the hardcoded keycode '13' to keySoundDiag
'
' New in 3.53 (Update by Toxie)
' - Add more key mappings to help dialog
'
' New in 3.52 (Update by DJRobX & Toxie)
' - Change default interval of the PinMAME timer to -1 (frame-sync'ed) if VP10.2 (or newer) is running
' - Add modulated solenoids to support ROM controlled fading flashers:
' To use, add "UseVPMModSol=True" to the table script
' Also use SolModCallback instead of SolCallback to receive level changes as input: It will be a level from 0 to 255.
' 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.
' 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)
'
' New in 3.51 (Update by mfuegemann & Arngrim & Toxie)
' - gts1.vbs dip fix
' - Add comments to cvpmDropTarget.CreateEvents: do not use this anymore in VP10 and above, as drop targets have an animation time nowadays
' - Change default interval of the PinMAME timer to 3 if VP10 (or newer) is running, and leave it at 1 for everything else
' - Fix missing SlingshotThreshold() when using VP8.X
' - (Controller.vbs changes)
' - now its allowed to have each toy to be set to 0 (sound effect), 1 (DOF) or 2 (both)
' - new DOF types: DOFFlippers, DOFTargets, DOFDropTargets
' - 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
' - InitializeOptions call added to the controller init, for tables that want to use this functionality during gameplay (options menu via F6)
'
' New in 3.50 (Update by Toxie & mfuegemann & Arngrim)
' - Added MAC.vbs & IronBalls.vbs & Lancelot.vbs & Antar.vbs
' - (Core changes)
' - Increased NVOffset limit from 10 to 32
' - Use temporary variables for Switch() calls to workaround current PROC issues
' - Controller.vbs user-folder detection fix, and add simple PROC usage via LoadPROC (see Controller.vbs for details)
' - Add UseVPMNVRAM = true to the table script (place before LoadVPM, or otherwise calling core.vbs)
' to make changed content of NVRAM available (since last update) via the NVRAMCallback (delivers a three dimensional array with: location, new value, old value)
' (requires VPM 2.7 or newer)
'
' New in 3.49 (Update by Arngrim)
' - Add new Controller.vbs to abstract DOF, B2S, VPM and EM controller loading, usage and sound/effect handling,
' see Controller.vbs header on how to use it exactly
'
' New in 3.48 (Update by JimmyFingers)
' - (Core changes)
' - Changed vpmNudge.TiltObj handling to use Bumper.Threshold / Wall.SlingshotThreshold temporary value changes rather than force / SlingshotStrength changes to disable tiltobj array objects
' - 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
' - 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
' Note: NudgePlugin option .vbs files were also updated as they contain and are reassigned the vpmNudge routines when invoked
'
' New in 3.47 (Update by Toxie)
' - (Core changes)
' - Add UseVPMColoredDMD = true to the table script (place before LoadVPM, or otherwise calling core.vbs)
' 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)
'
' New in 3.46 (Update by KieferSkunk)
' - (Core changes)
' - Added two new classes: cvpmTrough and cvpmSaucer
' - cvpmTrough takes over for cvpmBallStack in non-Saucer mode.
' - Can handle any number of balls (no more "out of bounds" errors with lots of balls)
' - Accurately simulates ball movement and switch interaction in a real trough
' - cvpmSaucer takes over for cvpmBallStack in Saucer mode.
' - cvpmBallStack is now considered "legacy" - kept for compatibility with existing tables. (No changes)
' - Updated vbsdoc.html with these new classes.
' - Added two helper functions, vpMin(a, b) and vpMax(a, b).
' - These each take two numbers (or strings) and return the lower or higher of the two (respectively).
'
' New in 3.45 (Update by KieferSkunk)
' - (Core changes)
' - Rewrote cvpmDictionary as a wrapper around Microsoft's Scripting.Dictionary object.
' This provides two major benefits:
' (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.
' (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.
' Note: The only restriction is that a Key cannot be a Scripting.Dictionary or an Array.
' - cvpmTurnTable now smoothly changes speeds and directions. You can adjust the following properties to change the turntable's behavior:
' - MaxSpeed: Sets new maximum spin speed. If motor is on, turntable will smoothly accelerate to new speed.
' - SpinUp: Sets new spin-up rate. If currently accelerating, turntable will accelerate at the new rate.
' - SpinDown: Sets new spin-down rate. If currently slowing to a stop, turntable will decelerate at the new rate.
' - SpinCW: True for clockwise rotation, False for counter-clockwise. If motor is on, switching this will smoothly reverse the turntable's direction.
'
' New in 3.44 (Update by Toxie)
' - (Core changes)
' - Added ability to define default ball mass (in VP Units) inside table script.
' Defaults to 1 unit if undefined. Example...
' Const BallMass = 2 '(place before LoadVPM, or otherwise calling core.vbs)
' Note that this should be used if changing the ball size via BallSize,
' as the mass is of course proportional to the radius of the ball: m=k*r^3.
' One can also use the diameter/size like in VP, so BallMass=k*BallSize^3 with k=1/125000.
' Example: BallSize = 55, so BallMass = (55*55*55)/125000 = 1.331.
' - Add UseVPMDMD = true to the table script (place before LoadVPM, or otherwise calling core.vbs)
' to automatically pass the raw DMD data (levels from 0..100) from VPM to VP (see VP10+ for details on how to display it)
' - 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)
' - Add inverseKeyCoinDoor in VPMKeys.vbs to in addition choose between the behaviour of a real coindoor switch (key pressed = closed, key not pressed = open)
' or the inverted behaviour (key pressed = open, key not pressed = closed)
' - Increase maximum number of balls/conMaxBalls to 13 and conStackSw to 8 (for Apollo 13), use InitSw8() then instead of InitSw()
' - Deprecate vpmSolFlip2, as VP10 does not feature speed on flippers anymore
'
' New in 3.43 (Update by Koadic)
' - (Core Changes)
' - Minor adjustment to vbs loading via LoadScript to account for files in nonstandard locations
' - Fix minor bugs when loading some tables
' New in 3.42 (Update by Koadic)
' - (Core Changes)
' - Minor adjustment to vpmInit to unpause controller before stopping controller
'
' New in 3.41 (Update by Koadic)
' - (Core Changes)
' - Modified vpmInit routine:
' Added creation of _Exit routine to vpmInit to perform Controller.Stop (will retroactively effect all tables using vpmInit call)
' Modified vpmInit to create _Paused, _UnPaused, and _Exit separately, so if any don't exit, they will be created individually
' Modified Error handling to fix bug where vmpInit might throw "Invalid procedure call or argument" error
' and cause table not to work due to improper Table_Init scripting.
' - Added 2 functions: CheckScript(file) and LoadScript(file) that can return True/False as well as the latter loading the script if true.
' These check for existance in either the Tables and Scripts directory and can return a boolean value as well as the LoadScript autoloading
' the file, as opposed to my previous methods only checking the local folder containing the table being run.
' CheckScript(file) checks for existance, and if found returns a True value
' LoadScript(file) checks for existance, and if found, loads specified file (via ExecuteGlobal GetTextFile(file)) and returns a True value
' Examples:
' If LoadScript("thefile.vbs") Then DoThisOtherThing ' If Loadscript found 'thefile' and loaded it (returned true) then do this other thing
' LoadScript("somefile.vbs") ' Checks for 'somefile' and loads it if it exists
' - Reworked CheckLEDWiz routine into generic LoadScript(file) routine to allow for better detection of script in the VP tables
' or scripts directory, not just current directory containing the table.
' - Added ability to load NudgePlugIn.vbs and if found, it will be loaded and replace current default nudging class.
' - This detection and autoloading can allow for 'on demand' replacement of other core components as well in the future.
' - Added ability to load GlobalPlugIn.vbs containing any custom scripting the user wants loaded with the core.vbs (instead of modifying the core)
' -(Other Additions)
' - Updated B2BCollision.vbs with vpmBallCreate method and renamed new file to B2B.vbs (to maintain compatiblity with tables using old file).
'
' New in 3.40 (Update by Koadic)
' - (Core Changes)
' - Modified NVOffset routine to allow use of alternative controllers (like dB2S B2S.Server)
' New in 3.39 (Update by Koadic)
' - (Core Changes)
' - Hopefully fixed bug introduced in 3.37 when using a VP version older than 9.0.10
' New in 3.38 (Update by Koadic)
' - (Core Changes)
' - Added automatic detection of ledcontrol.vbs and enabling for LedWiz use, allowing concurrent use by both users and non users of an LedWiz
' New in 3.37 (Update by Koadic)
' - (Core Changes)
' - Added ability to define default ballsize (in VP Units) inside table script.
' Defaults to 50 vp units if undefined. Example...
' Const BallSize = 47 '(place before LoadVPM, or otherwise calling core.vbs)
' New in 3.36 (update courtesy of Koadic)
' - (Core Changes)
' - Added VPMVol routine for allowing setting of Global VPM Volume (normally adjustable from '~' key, but otherwise unsaveable without this)
' - (System VBS Alterations)
' - Added keyVPMVolume in VPMKeys.vbs, set to use the F12 key
' - Added call to VPMVol routine in each system's .vbs file, allowing end-user to access the new routine
' New in 3.35 (Update courtesy of Koadic)
' - (Core Changes)
' - Added NVOffset routine for allowing use of multiple nvram files per romset name
' New in 3.34 (Update by Destruk)
' - (System VBS Additions)
' - Added Play2.vbs
' New in 3.33 (Update by Destruk)
' - (System VBS Additions)
' - Added LTD.vbs
' New in 3.32 (Update by Destruk)
' - (System VBS Alterations)
' - Added Playmatic Replay setting switches
' New in 3.31 (Update by Destruk)
' - (System VBS Additions)
' - Added play1.vbs
' New in 3.30 (Update by Destruk)
' - (System VBS Additions)
' - Added zacproto.vbs
' New in 3.29 (Update by Noah)
' - (System VBS Additions)
' - Added jvh.vbs and ali.vbs by Destruk for Jac van Ham and Allied Leisure
' Corrected VPBuild Number for slingshots/bumpers and ball decals - Seeker
' New in 3.27 (Update by PD)
' - (System VBS Additions)
' - Added gts1.vbs by Inkochnito for Gottlieb System 1
' New in 3.26 (Update by PD)
' - (Core Changes)
' - Added "GICallback2" function to support Steve Ellenoff's new support in VPM for Dimming GI in WMS games
' GICallback returns numeric values 0-8 instead of a boolean 0 or 1 (on/off) like GICallback does.
' Existing tables will need to be altered to support dimming levels and need to use GICallback2 instead.
' The old GICallback is left intact so older tables are not broken by the new code
'
' New in 3.25 (release 2) (Update by PD)
' - (Core Changes)
' - Restored former flipper speed due to complaints about some tables having BTTF problem returned and a resolution
' of arguments over the settings
' - New Optional Flipper Code Added (vpmSolFlip2) that let's you specify both up and down-swing speeds in the script
' plus the ability to turn flipper sounds on or off for that call
' Format: vpmSolFlip2 (Flip1obj, Flip2obj, UpSpeed, DownSpeed, SoundOn, Enable)
'
' New in 3.24 (Update by PD)
' - (Core Changes)
' - Altered flipper code so the upswing defaults to your downswing (i.e. VBS no longer adds a different value)
' (This change was done due to arguments over issues now resolved)
' - I have decreased the return strength setting to be very low, though. So any downswing hits (say from a ball
' heading to the trough) won't get hit with any real power. So, assuming you have a reasonably fast upswing,
' you won't get any balls through the flipper and any balls hit by the underside won't get pegged anymore, which
' is a more realistic behavior.
'
' New in 3.23 (Update by PD)
' - (System.vbs Additions)
' - SlamtTilt definitions added to AlvinG and Capcom systems
' - High Score Reset Switch Added to Williams System7 (S7.vbs)
' - Sleic.vbs system added (courtesy of Destruk)
' - Peper.vbs system added (courtesy of Destruk)
' - Juegos.vbs system added (courtesy of Destruk)
'
' New in 3.22 (Update by PD)
' - (Core Changes)
' - Outhole switch handling updated so it resets correctly with an F3 reset.
' This affects mostly Gottlieb System3 games (Thanks Racerxme for pointing this out)
' - Flipper handling modified to have a low return strength setting so any balls under such flippers
' won't get hit hard. This allows the higher 'flipper fix' return speed without the associated hard hit issue.
' - (System.vbs Additions)
' -Inder.vbs test switches updated (Thanks Peter)
' -Bally.vbs swSoundDiag value changed to -6 (Thanks Racerxme)
'
' New in 3.21 (Update by PD)
' -(Core Changes)
' - Attemped bug fix in the Impulse Plunger object that could cause weak plunges sometimes on full pulls
'
' -(System.vbs Additions)
' -Zac1.vbs has the program enable switch added to it (Thanks TomB)
' -GamePlan.vbs has the accounting reset switch added to it (Thanks Incochnito)
'
' -(Other Additions)
' -PD Light System VBS file updated to V5.5 (adds fading reel pop bumper handler and checklight function)
'
' New in 3.20 (Update by PD)
' -(System.vbs Additions)
' -Apparently Atari2.vbs uses 81/83 for the flipper switches and Atar1.vbs uses 82/84 so this repairs
' the Atari2.vbs file.
'
' New in 3.19 (Update by PD)
' -(System.vbs Additions)
' - Fixed the swLLFlip and swLRFlip switch numbers in the Atari1.vbs, Atari2.vbs and Atari.vbs files
' SolFlipper should now work with Atari tables using the updated file
'
' New in 3.18 (Update by PD)
' -(System.vbs Additions)
' - Added Atari1.vbs and Atari2.vbs files (Thanks to Inkochnito).
' -The old Atari.vbs file is now obsolete, but included for backwards compatability with any existing tables
' that may have used it. New Tables should use the appropriate Atari1.vbs or Atari2.vbs files.
'
' New in 3.17 (Update by PD)
' -(System.vbs Additions)
' -Fixed wrong switch definition in Sys80.vbs for the self-test switch. The operator menus should work now.
' (Thanks to Inkochnito for pointing it out).
' -Added inder.vbs, nuova.vbs, spinball.vbs and mrgame.vbs files (Thanks to Destruk)
'
' New in 3.16 (Update by PD)
' -(System.vbs Additions)
' -Added "BeginModal" and "EndModal" statements to each system (required for latest versions of VP ( >V6.1) to
' avoid problems during the VPM "F3" reset.
' -(Other Additions)
' - PDLightSystem Core updated to version 5.4
'
' New in 3.15 (Update by PD)
' -(Core Additions)
' - Added a new higher resolution Impulse Plunger Object
' (It uses a trigger to plunge the ball. It can be a variable Manual Plunger or function as an Automatic Plunger)
' (It also features random variance options and optional pull / plunge sounds)
'
' -(System.vbs Additions)
' - Fixed wrong switch number for Tilt & Slam Tilt in Sega.vbs
' - Added Master CPU Enter switch to S7.vbs for Dip Switch control in Williams System7
'
' -(Other Additions)
' - Added PDLightSystem.vbs (V5.3) file to archive
' (open it with a text editor to see how to use it; it's called separately like the core file)
'
' New in 3.14 (Update by PD)
' -(System.vbs Additions)
' - Added latest Zac1.vbs and Zac2.vbs files to archive
'
' New in 3.13 (Update by PD)
' -(Core Additions)
' - Added Destruk's code to "Add" or "Remove" a ball from the table when "B" is pressed.
' - Added "AutoplungeS" call which is the same as "Autoplunger" except it will play a specified sound when fired
'
' -(System.vbs Additions)
' - Taito.vbs updated to fix service menu keys and default dip switch menu added
' - Dip Switch / Option Menu "class" code added to all table VBS scripts to ease menu coding for table authors
' - Fixed some labeling errors and organization and added a "Last Updated" version comment at the start of each file
'
' New in 3.12
' - Made flipper return speed a constant conFlipRetSpeed
' - set conFlipRetSpeed to 0.137 to reduce ball thru flipper problem
'
' New in 3.11
' - Added a short delay between balls in the ballstacks to ensure
' that the game registers the switches as off when balls are rolling
' in the trough. All balls should probably move at the same time but it is
' a bit tricky to implement without changing a lot of code.
' - Removed support for the wshltdlg.dll since funtionality is in VPM now
' New in 3.10
' - Public release
' Put this at the top of the table file
'LoadVPM "02000000", "xxx.VBS", 3.57 ' adapt 02000000 and 3.57 to the actually required minimum VPinMAME- and core scripts versions
'Const cGameName = "xxxx" ' PinMAME short game name
'Const UseSolenoids = True
'Const UseLamps = True
''Standard sound
'Const SSolenoidOn = "SolOn" 'Solenoid activates
'Const SSolenoidOff = "SolOff" 'Solenoid deactivates
'Const SFlipperOn = "FlipperUp" 'Flipper activated
'Const SFlipperOff = "FlipperDown" 'Flipper deactivated
'Const SCoin = "Quarter" 'Coin inserted
''Callbacks
'Set LampCallback = GetRef("UpdateMultipleLamps")
'Set GICallback = GetRef("UpdateGI") ' Original GI Callback (returns boolean on and off values only)
'Set GICallback2 = GetRef("UpdateGI") ' New GI Callback supports Newer VPM Dimming GI and returns values numeric 0-8)
'Set MotorCallback = GetRef("UpdateMotors")
'
'Sub LoadVPM(VPMver, VBSfile, VBSver)
' On Error Resume Next
' If ScriptEngineMajorVersion < 5 Then MsgBox "VB Script Engine 5.0 or higher required"
' ExecuteGlobal GetTextFile(VBSfile)
' If Err Then MsgBox "Unable to open " & VBSfile & ". Ensure that it is in the Scripts folder of Visual Pinball. " & vbNewLine & Err.Description : Err.Clear
' Set Controller = CreateObject("VPinMAME.Controller")
' If Err Then MsgBox "Can't Load VPinMAME." & vbNewLine & Err.Description
' If VPMver>"" Then If Controller.Version < VPMver Or Err Then MsgBox "VPinMAME ver " & VPMver & " required." : Err.Clear
' If VPinMAMEDriverVer < VBSver Or Err Then MsgBox VBSFile & " ver " & VBSver & " or higher required."
'End Sub
'
'Sub Table_KeyDown(ByVal keycode)
' If vpmKeyDown(keycode) Then Exit Sub
' If keycode = PlungerKey Then Plunger.Pullback
'End Sub
'Sub Table_KeyUp(ByVal keycode)
' If vpmKeyUp(keycode) Then Exit Sub
' If keycode = PlungerKey Then Plunger.Fire
'End Sub
'
'Const cCredits = ""
'Sub Table_Init
' vpmInit Me
' On Error Resume Next
' With Controller
' .GameName = cGameName
' If Err Then MsgBox "Can't start Game " & cGameName & vbNewLine & Err.Description : Exit Sub
' .SplashInfoLine = cCredits
' .HandleMechanics = 0
' .ShowDMDOnly = True : .ShowFrame = False : .ShowTitle = False
' .Run : If Err Then MsgBox Err.Description
' End With
' On Error Goto 0
'' Nudging
' vpmNudge.TiltSwitch = swTilt
' vpmNudge.Sensitivity = 5
' vpmNudge.TiltObj = Array(Bumper1,Bumper2,LeftslingShot,RightslingShot)
'' Map switches and lamps
' vpmCreateEvents colSwObjects ' collection of triggers etc
' vpmMapLights colLamps ' collection of all lamps
'' Trough handler
' Set bsTrough = New cvpmBallStack
' bsTrough.InitNoTrough BallRelease, swOuthole, 90, 2
' 'or
' bsTrough.InitSw swOuthole,swTrough1,swTrough2,0,0,0,0
'---------------------------------------------------------------
Dim Controller ' VPinMAME Controller Object
Dim vpmTimer ' Timer Object
Dim vpmNudge ' Nudge handler Object
Dim Lights(200) ' Put all lamps in an array for easier handling
' If more than one lamp is connected, fill this with an array of each light
Dim vpmMultiLights() : ReDim vpmMultiLights(0)
Private gNextMechNo : gNextMechNo = 0 ' keep track of created mech handlers (would be nice with static members)
' Callbacks
Dim SolCallback(68) ' Solenoids (parsed at Runtime)
Dim SolModCallback(68) ' Solenoid modulated callbacks (parsed at Runtime)
Dim SolPrevState(68) ' When modulating solenoids are in use, needed to keep positive value levels from changing boolean state
Dim LampCallback ' Called after lamps are updated
Dim PDLedCallback ' Called after leds are updated
Dim GICallback ' Called for each changed GI String
Dim GICallback2 ' Called for each changed GI String
Dim MotorCallback ' Called after solenoids are updated
Dim vpmCreateBall ' Called whenever a vpm class needs to create a ball
Dim BSize:If IsEmpty(Eval("BallSize"))=true Then BSize=25 Else BSize = BallSize/2
Dim BMass:If IsEmpty(Eval("BallMass"))=true Then BMass=1 Else BMass = BallMass
Dim UseDMD:If IsEmpty(Eval("UseVPMDMD"))=true Then UseDMD=false Else UseDMD = UseVPMDMD
Dim UseModSol:If IsEmpty(Eval("UseVPMModSol"))=true Then UseModSol=false Else UseModSol = UseVPMModSol
Dim UseColoredDMD:If IsEmpty(Eval("UseVPMColoredDMD"))=true Then UseColoredDMD=false Else UseColoredDMD = UseVPMColoredDMD
Dim UseNVRAM:If IsEmpty(Eval("UseVPMNVRAM"))=true Then UseNVRAM=false Else UseNVRAM = UseVPMNVRAM
Dim NVRAMCallback
Dim SpecialSol ' Solenoid number to check for in ChangedSolenoids. If found this sends a byte instead of a bool. This allows us to send a value 0-255 to the scripts SolCallback
' Assign Null Default Sub so script won't error if only one is defined in a script (should redefine in your script)
Set GICallback = GetRef("NullSub")
Set GICallback2 = GetRef("NullSub")
' Game specific info
Dim ExtraKeyHelp ' Help string for game specific keys
Dim vpmShowDips ' Show DIPs function
'-----------------------------------------------------------------------------
' These helper functions require the following objects on the table:
' PinMAMETimer : Timer object
' PulseTimer : Timer object
' Available classes:
' ------------------
' cvpmTimer (Object = vpmTimer)
' (Public) .PulseSwitch - pulse switch and call callback after delay (default)
' (Public) .PulseSw - pulse switch
' (Public) .AddTimer - call callback after delay
' (Public) .Reset - Re-set all ballStacks
' (Friend) .InitTimer - initialise fast or slow timer
' (Friend) .EnableUpdate - Add/remove automatic update for an instance
' (Private) .Update - called from slow timer
' (Private) .FastUpdate - called from fast timer
' (Friend) .AddResetObj - Add object that needs to catch reset
'
' cvpmTrough (Create as many as needed)
' (Public) .IsTrough - Get or Set whether this trough is the default trough (first trough sets this by default)
' (Public) .Size - Get or Set total number of balls trough can hold
' (Public) .EntrySw - Set switch number for trough entry (if any) - eg. Outhole
' (Public) .AddSw - Assign a switch at a specific slot
' (Public) .InitSwitches - Set trough switches using an array, from exit slot back toward entrance.
' (Public) .InitExit - Setup exit kicker, force and direction
' (Public) .InitExitVariance - Modify exit kick direction and force (+/-, min force = 1)
' (Public) .InitEntrySounds - Sounds to play when a ball enters the trough
' (Public) .InitExitSounds - Sounds to play when the exit kicker fires
' (Public) .CreateEvents - Auto-generate hit events for VP entry kicker(s) associated with this trough
' (Public) .MaxBallsPerKick - Set maximum number of balls to kick out (default 1)
' (Public) .MaxSlotsPerKick - Set maximum slots from which to get balls when kicking out (default 1)
' (Public) .Balls - Get current balls in trough, or set initial number of balls in trough
' (Public) .BallsPending - Get number of balls waiting in trough entry
' (Public) .Reset - Reset and update all trough switches
' (Friend) .Update - Called from vpmTimer to update ball positions and switches
' (Public) .AddBall - Add a ball to the trough from a kicker. If kicker is the exit kicker, stacks ball at exit.
' (Public) .SolIn - Solenoid handler for entry solenoid
' (Public) .SolOut - Solenoid handler for exit solenoid
'
' cvpmSaucer (Create as many as needed)
' (Public) .InitKicker - Setup main kicker, switch, exit direction and force (including Z force)
' (Public) .InitExitVariance - Modify kick direction and force (+/-, min force = 1)
' (Public) .InitAltKick - Set alternate direction and force (including Z force) - for saucers with two kickers
' (Public) .InitSounds - Sounds to play when a ball enters the saucer or the kicker fires
' (Public) .CreateEvents - Auto-generate hit event for VP kicker(s) associated with this saucer
' (Public) .AddBall - Add a ball to the saucer from a kicker.
' (Public) .HasBall - True if the saucer is occupied.
' (Public) .solOut - Fire the primary exit kicker. Ejects ball if one is present.
' (Public) .solOutAlt - Fire the secondary exit kicker. Ejects ball with alternate forces if present.
'
' cvpmBallStack (DEPRECATED, but create as many as needed)
' (Public) .InitSw - init switches used in stack
' (Public) .InitSaucer - init saucer
' (Public) .InitNoTrough - init a single ball, no trough handler
' (Public) .InitKick - init exit kicker
' (Public) .InitAltKick - init second kickout direction
' (Public) .CreateEvents - Create addball events for kickers
' (Public) .KickZ - Z axis kickout angle (radians)
' (Public) .KickBalls - Maximum number of balls kicked out at the same time
' (Public) .KickForceVar - Initial ExitKicker Force value varies by this much (+/-, minimum force = 1)
' (Public) .KickAngleVar - ExitKicker Angle value varies by this much (+/-)
' (Public) .BallColour - Set ball colour
' (Public) .TempBallImage - Set ball image for next ball only
' (Public) .TempBallColour - Set ball colour for next ball only
' (Public) .BallImage - Set ball image
' (Public) .InitAddSnd - Sounds when ball enters stack
' (Public) .InitEntrySnd - Sounds for Entry kicker
' (Public) .InitExitSnd - Sounds for Exit kicker
' (Public) .AddBall - add ball in "kicker" to stack
' (Public) .SolIn - Solenoid handler for entry solenoid
' (Public) .EntrySol_On - entry solenoid fired
' (Public) .SolOut - Solenoid handler for exit solenoid
' (Public) .SolOutAlt - Solenoid handler for exit solenoid 2nd direction
' (Public) .ExitSol_On - exit solenoid fired
' (Public) .ExitAltSol_On - 2nd exit solenoid fired
' (Public) .Balls - get/set number of balls in stack (default)
' (Public) .BallsPending - get number of balls waiting to come in to stack
' (Public) .IsTrough - Specify that this is the main ball trough
' (Public) .Reset - reset and update all ballstack switches
' (Friend) .Update - Update ball positions (from vpmTimer class)
' Obsolete
' (Public) .SolExit - exit solenoid handler
' (Public) .SolEntry - Entry solenoid handler
' (Public) .InitProxy - Init proxy switch
' cvpmNudge (Object = vpmNudge)
' Hopefully we can add a real pendulum simulator in the future
' (Public) .TiltSwitch - set tilt switch
' (Public) .Senitivity - Set tiltsensitivity (0-10)
' (Public) .TiltObj - Set objects affected by tilt
' (Public) .DoNudge dir,power - Nudge table
' (Public) .SolGameOn - Game On solenoid handler
' (Private) .Update - Handle tilting
'
' cvpmDropTarget (create as many as needed)
' (Public) .InitDrop - initialise DropTarget bank
' (Public) .CreateEvents - Create Hit events
' (Public) .InitSnd - sound to use for targets
' (Public) .AnyUpSw - Set AnyUp switch
' (Public) .AllDownSw - Set all down switch
' (Public) .AllDown - All targets down?
' (Public) .Hit - A target had been hit
' (Public) .SolHit - Solenoid handler for dropping a target
' (Public) .SolUnHit - Solenoid handler for raising a target
' (Public) .SolDropDown - Solenoid handler for Bank down
' (Public) .SolDropUp - Solenoid handler for Bank reset
' (Public) .DropSol_On - Reset target bank
' (Friend) .SetAllDn - check alldown & anyup switches
'
' cvpmMagnet (create as many as needed)
' (Public) .InitMagnet - initialise magnet
' (Public) .CreateEvents - Create Hit/Unhit events
' (Public) .Solenoid - Set solenoid that controls magnet
' (Public) .GrabCenter - Magnet grabs ball at center
' (Public) .MagnetOn - Turn magnet on and off
' (Public) .X - Move magnet
' (Public) .Y - Move magnet
' (Public) .Strength - Change strength
' (Public) .Size - Change magnet reach
' (Public) .AddBall - A ball has come within range
' (Public) .RemoveBall - A ball is out of reach for the magnet
' (Public) .Balls - Balls currently within magnets reach
' (Public) .AttractBall - attract ball to magnet
' (Private) .Update - update all balls (called from timer)
' (Private) .Reset - handle emulation reset
' Obsolete
' (Public) .Range - Change magnet reach
' cvpmTurnTable (create as many as needed)
' (Public) .InitTurnTable - initialise turntable
' (Public) .CreateEvents - Create Hit/Unhit events
' (Public) .MaxSpeed - Maximum speed
' (Public) .SpinUp - Speedup acceleration
' (Public) .SpinDown - Retardation
' (Public) .Speed - Current speed
' (Public) .MotorOn - Motor On/Off
' (Public) .SpinCW - Control direction
' (Public) .SolMotorState - Motor on/off solenoid handler
' (Public) .AddBall - A ball has come withing range
' (Public) .RemoveBall - A ball is out of reach for the magnet
' (Public) .Balls - Balls currently within magnets reach
' (Public) .AffectBall - affect a ball
' (Private) .Update - update all balls (called from timer)
' (Private) .Reset - handle emulation reset
' cvpmMech (create as many as needed)
' (Public) .Sol1, Sol2 - Controlling solenoids
' (Public) .MType - type of mechanics
' (Public) .Length, Steps
' (Public) .Acc, Ret - Acceleration, retardation
' (Public) .AddSw - Automatically controlled switches
' (Public) .AddPulseSw - Automatically pulsed switches
' (Public) .Callback - Update graphics function
' (Public) .Start - Start mechanics handler
' (Public) .Position - Current position
' (Public) .Speed - Current Speed
' (Private) .Update
' (Private) .Reset
'
' cvpmCaptiveBall (create as many as needed)
' (Public) .InitCaptive - Initialise captive balls
' (Public) .CreateEvents - Create events for captive ball
' (Public) .ForceTrans - Amount of force tranferred to captive ball (0-1)
' (Public) .MinForce - Minimum force applied to the ball
' (Public) .NailedBalls - Number of "nailed" balls infront of captive ball
' (Public) .RestSwitch - Switch activated when ball is in rest position
' (Public) .Start - Create moving ball etc.
' (Public) .TrigHit - trigger in front of ball hit (or unhit)
' (Public) .BallHit - Wall in front of ball hit
' (Public) .BallReturn - Captive ball has returned to kicker
' (Private) .Reset
'
' cvpmVLock (create as many as needed)
' (Public) .InitVLock - Initialise the visible ball stack
' (Public) .ExitDir - Balls exit angle (like kickers)
' (Public) .ExitForce - Force of balls kicked out
' (Public) .KickForceVar - Vary kickout force
' (Public) .InitSnd - Sounds to make on kickout
' (Public) .Balls - Number of balls in Lock
' (Public) .SolExit - Solenoid event
' (Public) .CreateEvents - Create events needed
' (Public) .TrigHit - called from trigger hit event
' (Public) .TrigUnhit - called from trigger unhit event
' (Public) .KickHit - called from kicier hit event
'
' cvpmDips (create as many as needed) => (Dip Switch And/Or Table Options Menu)
' (Public) .AddForm - create a form (AKA dialogue)
' (Public) .AddChk - add a chckbox
' (Public) .AddChkExtra - - "" - for non-dip settings
' (Public) .AddFrame - add a frame with checkboxes or option buttons
' (Public) .AddFrameExtra - - "" - for non-dip settings
' (Public) .AddLabel - add a label (text string)
' (Public) .ViewDips - Show form
' (Public) .ViewDipsExtra - - "" - with non-dip settings
'
' cvpmImpulseP (create as many as needed) => (Impulse Plunger Object using a Trigger to Plunge Manual/Auto)
' (Public) .InitImpulseP - Initialise Impulse Plunger Object (Trigger, Plunger Power, Time to Full Plunge [0 = Auto])
' (Public) .CreateEvents - Create Hit/Unhit events
' (Public) .Strength - Change plunger strength
' (Public) .Time - Change plunger time (in seconds) to full plunger strength (0 = Auto Plunger)
' (Public) .Pullback - Pull the plunger back
' (Public) .Fire - Fires / Releases the Plunger (Manual or Auto depending on Timing Value given)
' (Public) .AutoFire - Fires / Releases the Plunger at Maximum Strength +/- Random variation (i.e. Instant Auto)
' (Public) .Switch - Switch Number to activate when ball is sitting on plunger trigger (if any)
' (Public) .Random - Sets the multiplier level of random variance to add (0 = No Variance / Default)
' (Public) .InitEntrySnd - Plays Sound as Plunger is Pulled Back
' (Public) .InitExitSnd - Plays Sound as Plunger is Fired (WithBall,WithoutBall)
'
' Generic solenoid handlers:
' --------------------------
' vpmSolFlipper flipObj1, flipObj2 - "flips flippers". Set unused to Nothing
' vpmSolFlip2 flipObj1, flipObj2, flipSpeedUp, flipSpeedDn, sndOn). Set unused to Nothing
' vpmSolDiverter divObj, sound - open/close diverter (flipper) with/without sound
' vpmSolWall wallObj, sound - Raise/Drop wall with/without sound
' vpmSolToggleWall wall1, wall2, sound - Toggle between two walls
' vpmSolToggleObj obj1,obj2,sound - Toggle any objects
' vpmSolAutoPlunger plungerObj, var, enabled - Autoplunger/kickback
' vpmSolAutoPlungeS plungerObj, sound, var, enabled - Autoplunger/kickback With Specified Sound To Play
' vpmSolGate obj, sound - Open/close gate
' vpmSolSound sound - Play sound only
' vpmFlasher flashObj - Flashes flasher
'
' Generating events:
' ------------------
' vpmCreateEvents
' cpmCreateLights
'
' Variables declared (to be filled in):
' ---------------------------------------
' SolCallback() - handler for each solenoid
' Lights() - Lamps
'
' Constants used (must be defined):
' ---------------------------------
' UseSolenoids - Update solenoids
' MotorCallback - Called once every update for mechanics or custom sol handler
' UseLamps - Update lamps
' LampCallback - Sub to call after lamps are updated
' (or every update if UseLamps is false)
' GICallback - Sub to call to update GI strings
' GICallback2 - Sub to call to update GI strings
' SFlipperOn - Flipper activate sound
' SFlipperOff - Flipper deactivate sound
' SSolenoidOn - Solenoid activate sound
' SSolenoidOff - Solenoid deactivate sound
' SCoin - Coin Sound
' ExtraKeyHelp - Game specific keys in help window
'
' Exported variables:
' -------------------
' vpmTimer - Timer class for PulseSwitch etc
' vpmNudge - Class for table nudge handling
'-----------------------------------------------------
Private Function PinMAMEInterval
If VPBuildVersion >= 10200 Then
PinMAMEInterval = -1 ' VP10.2 introduced special frame-sync'ed timers
Else
If VPBuildVersion >= 10000 Then
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
Else
PinMAMEInterval = 1
End If
End If
End Function
Private Const conStackSw = 8 ' Stack switches
Private Const conMaxBalls = 13 ' Because of Apollo 13
Private Const conMaxTimers = 20 ' Spinners can generate a lot of timers
Private Const conTimerPulse = 40 ' Timer runs at 25Hz
Private Const conFastTicks = 4 ' Fast is 4 times per timer pulse
Private Const conMaxSwHit = 5 ' Don't stack up more than 5 events for each switch
' DEPRECATED Flipper constants:
Private Const conFlipRetStrength = 0.01 ' Flipper return strength
Private Const conFlipRetSpeed = 0.137 ' Flipper return speed
Function CheckScript(file) 'Checks Tables and Scripts directories for specified vbs file, and if it exitst, will load it.
CheckScript = False
On Error Resume Next
Dim TablesDirectory:TablesDirectory = Left(UserDirectory,InStrRev(UserDirectory,"\",InStrRev(UserDirectory,"\")-1))&"Tables\"
Dim ScriptsDirectory:ScriptsDirectory = Left(UserDirectory,InStrRev(UserDirectory,"\",InStrRev(UserDirectory,"\")-1))&"Scripts\"
Dim check:Set check = CreateObject("Scripting.FileSystemObject")
If check.FileExists(tablesdirectory & file) Or check.FileExists(scriptsdirectory & file) Or check.FileExists(file) Then CheckScript = True
On Error Goto 0
End Function
Function LoadScript(file) 'Checks Tables and Scripts directories for specified vbs file, and if it exitst, will load it.
LoadScript = False
On Error Resume Next
If CheckScript(file) Then ExecuteGlobal GetTextFile(file):LoadScript = True
On Error Goto 0
End Function
' Dictionary
' At one point, Microsoft had made Scripting.Dictionary "unsafe for scripting", but it's
' been a long time since that was true. So now, to maintain compatibility with all tables
' and scripts that use cvpmDictionary, this class is now a simple wrapper around Microsoft's
' more efficient implementation.
Class cvpmDictionary
Private mDict
Private Sub Class_Initialize : Set mDict = CreateObject("Scripting.Dictionary") : End Sub
' DEPRECATED: MS Dictionaries are not index-based. Use "Exists" method instead.
Private Function FindKey(aKey)
Dim ii, key : FindKey = -1
If mDict.Count > 0 Then
ii = 0
For Each key In mDict.Keys
If key = aKey Then FindKey = ii : Exit Function
Next
End If
End Function
Public Property Get Count : Count = mDict.Count : End Property
Public Property Get Item(aKey)
Item = Empty
If mDict.Exists(aKey) Then
If IsObject(mDict(aKey)) Then
Set Item = mDict(aKey)
Else
Item = mDict(aKey)
End If
End If
End Property
Public Property Let Item(aKey, aData)
If IsObject(aData) Then
Set mDict(aKey) = aData
Else
mDict(aKey) = aData
End If
End Property
Public Property Set Key(aKey)
' This function is (and always has been) a no-op. Previous definition
' just looked up aKey in the keys list, and if found, set the key to itself.
End Property
Public Sub Add(aKey, aItem)
If IsObject(aItem) Then
Set mDict(aKey) = aItem
Else
mDict(aKey) = aItem
End If
End Sub
Public Sub Remove(aKey) : mDict.Remove(aKey) : End Sub
Public Sub RemoveAll : mDict.RemoveAll : End Sub
Public Function Exists(aKey) : Exists = mDict.Exists(aKey) : End Function
Public Function Items : Items = mDict.Items : End Function
Public Function Keys : Keys = mDict.Keys : End Function
End Class
'--------------------
' Timer
'--------------------
Class cvpmTimer
Private mQue, mNow, mTimers
Private mSlowUpdates, mFastUpdates, mResets, mFastTimer
Private Sub Class_Initialize
ReDim mQue(conMaxTimers) : mNow = 0 : mTimers = 0
Set mSlowUpdates = New cvpmDictionary
Set mFastUpdates = New cvpmDictionary
Set mResets = New cvpmDictionary
End Sub
Public Sub InitTimer(aTimerObj, aFast)
If aFast Then
Set mFastTimer = aTimerObj
aTimerObj.TimerInterval = conTimerPulse \ conFastTicks
aTimerObj.TimerEnabled = False
vpmBuildEvent aTimerObj, "Timer", "vpmTimer.FastUpdate"
Else
aTimerObj.Interval = conTimerPulse : aTimerObj.Enabled = True
vpmBuildEvent aTimerObj, "Timer", "vpmTimer.Update"
End If
End Sub
Sub EnableUpdate(aClass, aFast, aEnabled)
On Error Resume Next
If aFast Then
If aEnabled Then mFastUpdates.Add aClass, 0 : Else mFastUpdates.Remove aClass
mFastTimer.TimerEnabled = mFastUpdates.Count > 0
Else
If aEnabled Then mSlowUpdates.Add aClass, 0 : Else mSlowUpdates.Remove aClass
End If
End Sub
Public Sub Reset
Dim obj : For Each obj In mResets.Keys : obj.Reset : Next
End Sub
Public Sub FastUpdate
Dim obj : For Each obj In mFastUpdates.Keys : obj.Update : Next
End Sub
Public Sub Update
Dim ii, jj, sw, obj, mQuecopy
For Each obj In mSlowUpdates.Keys : obj.Update : Next
If mTimers = 0 Then Exit Sub
mNow = mNow + 1 : ii = 1
Do While ii <= mTimers
If mQue(ii)(0) <= mNow Then
If mQue(ii)(1) = 0 Then
If isObject(mQue(ii)(3)) Then
Call mQue(ii)(3)(mQue(ii)(2))
ElseIf varType(mQue(ii)(3)) = vbString Then
If mQue(ii)(3) > "" Then Execute mQue(ii)(3) & " " & mQue(ii)(2) & " "
End If
mTimers = mTimers - 1
For jj = ii To mTimers : mQue(jj) = mQue(jj+1) : Next : ii = ii - 1
ElseIf mQue(ii)(1) = 1 Then
mQuecopy = mQue(ii)(2)
Controller.Switch mQuecopy, 0
mQue(ii)(0) = mNow + mQue(ii)(4) : mQue(ii)(1) = 0
Else '2
mQuecopy = mQue(ii)(2)
Controller.Switch mQuecopy, 1
mQue(ii)(1) = 1
End If
End If
ii = ii + 1
Loop
End Sub
Public Sub AddResetObj(aObj) : mResets.Add aObj, 0 : End Sub
Public Sub PulseSw(aSwNo) : PulseSwitch aSwNo, 0, 0 : End Sub
Public Default Sub PulseSwitch(aSwNo, aDelay, aCallback)
Dim ii, count, last
count = 0
For ii = 1 To mTimers
If mQue(ii)(1) > 0 And mQue(ii)(2) = aSwNo Then count = count + 1 : last = ii
Next
If count >= conMaxSwHit Or mTimers = conMaxTimers Then Exit Sub
mTimers = mTimers + 1 : mQue(mTimers) = Array(mNow, 2, aSwNo, aCallback, aDelay\conTimerPulse)
If count Then mQue(mTimers)(0) = mQue(last)(0) + mQue(last)(1)
End Sub
Public Sub AddTimer(aDelay, aCallback)
If mTimers = conMaxTimers Then Exit Sub
mTimers = mTimers + 1
mQue(mTimers) = Array(mNow + aDelay \ conTimerPulse, 0, 0, aCallback)
End Sub
Public Sub AddTimer2(aDelay, aCallback, aID)
If mTimers = conMaxTimers Then Exit Sub
mTimers = mTimers + 1
mQue(mTimers) = Array(mNow + aDelay \ conTimerPulse, 0, aID, aCallback)
End Sub
End Class
'--------------------
' Trough
'--------------------
Class cvpmTrough
' Takes over for older cvpmBallStack in "trough mode". Theory of operation:
' A trough can hold up to N balls, and has N*2 "slots". A ball effectively takes
' up two slots, so no two adjacent slots (0 and 1) can be occupied at the same time.
' Switches are assigned to even slots only, which means that as balls move through
' the trough, each switch is allowed to flip between open and closed.
' Slot 0 is the exit, and can have additional balls "stacked" on it, simulating balls
' falling onto the exit kicker instead of coming in from the entrance. Extra balls
' can be queued up at the entrance, and will enter the trough only if there's room
' for them.
Private mSlot(), mSw(), mEntrySw
Private mBallsInEntry, mMaxBallsPerKick, mStackExitBalls
Private mExitKicker, mExitDir, mExitForce, mDirVar, mForceVar
Private mSounds
' If you want to see what the trough is doing internally, add a TextBox to your table
' named "DebugBox" (recommend Courier New or FixedSys at a small font size) and set
' this variable to true via .isDebug = True.
Private mDebug
Private Sub Class_Initialize
Dim ii
ReDim mSw(conMaxBalls), mSlot(conMaxBalls * 2)
For ii = 0 to UBound(mSlot) : mSlot(ii) = 0 : Next ' All slots empty to start
For ii = 0 to UBound(mSw) : mSw(ii) = 0 : Next ' All switches unassigned to start.
mEntrySw = 0
Set mExitKicker = Nothing
mExitDir = 0 : mExitForce = 1 : mDirVar = 0 : mForceVar = 0
mBallsInEntry = 0 : mMaxBallsPerKick = 1 : mStackExitBalls = 1
Set mSounds = New cvpmDictionary
mDebug = False
If Not IsObject(vpmTrough) Then Set vpmTrough = Me
End Sub
Public Property Let IsTrough(aYes)
If aYes Then
Set vpmTrough = Me
ElseIf Me Is vpmTrough Then
Set vpmTrough = Nothing
End If
End Property
Public Property Get IsTrough
IsTrough = (Me Is vpmTrough)
End Property
' Initialization
Public Property Let isDebug(enabled) : mDebug = enabled : End Property
Public Property Let Size(aSize)
Dim oldSize, newSize, ii
oldSize = UBound(mSw)
newSize = vpMax(1, aSize)
ReDim Preserve mSlot(newSize * 2)
ReDim Preserve mSw(newSize)
For ii = oldSize+1 To newSize : mSw(ii) = 0 : Next
For ii = (oldSize*2) + 1 to (newSize*2) : mSlot(ii) = 0 : Next
End Property
Public Property Get Size : Size = UBound(mSw) : End Property
' Set EntrySw = 0 if you want balls to just fall into the trough automatically.
' Set it to a real switch number to indicate that a ball is occupying an entry kicker.
' The ROM in the controller is then responsible for kicking the ball into the trough.
Public Property Let EntrySw(swNo) : mEntrySw = swNo : End Property
' Assign switches, starting from slot 0 and going to entrance.
' This sub allows you to pass in as many switches as you wish.
Public Sub InitSwitches(switchArray)
If Not IsArray(switchArray) Then
Err.Raise 17, "cvpmTrough.InitSwitches: Input must be an array."
End If
Dim ii
For ii = 0 to UBound(mSw)
If ii > UBound(switchArray) Then
mSw(ii) = 0
Else
mSw(ii) = switchArray(ii)
End If
Next
End Sub
' Alternative: Assign a switch to a specific slot.
Public Sub AddSw(slotNo, swNo)
If slotNo < 0 OR slotNo > UBound(mSw) Then Exit Sub
mSw(slotNo) = swNo
End Sub
' MaxBallsPerKick: Kick up to N balls total per exit kick. Balls are only kicked from Slot 0.
' StackExitBalls: Automatically stack up to N balls in Slot 0 regardless of where they came from.