예제 #1
0
        /// <summary>
        /// Simulates a drain, i.e. a ball entering the drain or trough directly,
        /// depending on the <see cref="TroughType"/>.
        /// </summary>
        private void DrainBall()
        {
            switch (MainComponent.Type)
            {
            case TroughType.ModernOpto:
            case TroughType.ModernMech:
                // ball rolls directly into the trough
                RollOverEntryBall(0);
                break;

            case TroughType.TwoCoilsNSwitches:
            case TroughType.TwoCoilsOneSwitch:
                if (EntrySwitch.IsSwitchEnabled)                             // if the drain slot is already occupied, queue it.
                {
                    UncountedDrainBalls++;
                }
                else                                                  // otherwise just close the entry switch
                {
                    EntrySwitch.ScheduleSwitch(true, MainComponent.RollTime / 2);
                }

                break;

            case TroughType.ClassicSingleBall:
                AddBall();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
#if UNITY_EDITOR
            RefreshUI();
#endif
        }
예제 #2
0
        /// <summary>
        /// Kicks the ball from the drain into the ball stack.
        /// </summary>
        ///
        /// <remarks>
        /// If there are any uncounted drain balls, the next ball is drained afterwards.
        /// </remarks>
        private void OnEntryCoilEnabled()
        {
            switch (MainComponent.Type)
            {
            case TroughType.ModernOpto:
            case TroughType.ModernMech:
                // modern troughs don't have an entry coil
                break;

            case TroughType.TwoCoilsNSwitches:
            case TroughType.TwoCoilsOneSwitch:
                // push the ball from the drain to the trough
                if (EntrySwitch.IsSwitchEnabled)
                {
                    EntrySwitch.SetSwitch(false);
                    RollOverEntryBall(0);
                    DrainNextUncountedBall();
                }
                break;

            case TroughType.ClassicSingleBall:
                throw new InvalidOperationException("Single ball trough does not have an entry coil.");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
#if UNITY_EDITOR
            RefreshUI();
#endif
        }
예제 #3
0
        /// <summary>
        /// Create a ball in the ball stack without triggering extra events.
        /// </summary>
        private void AddBall()
        {
            switch (MainComponent.Type)
            {
            case TroughType.ModernOpto:
            case TroughType.ModernMech:
            case TroughType.TwoCoilsNSwitches:
                if (_countedStackBalls < MainComponent.BallCount)
                {
                    _stackSwitches[_countedStackBalls].SetSwitch(true);
                    _countedStackBalls++;
                }
                else
                {
                    UncountedStackBalls++;
                }
                break;

            case TroughType.TwoCoilsOneSwitch:
                if (_countedStackBalls < MainComponent.SwitchCount - 1)
                {
                    _countedStackBalls++;
                }
                else if (_countedStackBalls == MainComponent.SwitchCount - 1)
                {
                    _countedStackBalls++;
                    StackSwitch().SetSwitch(true);
                }
                else
                {
                    UncountedStackBalls++;
                }
                break;

            case TroughType.ClassicSingleBall:
                if (!EntrySwitch.IsSwitchEnabled)
                {
                    _countedStackBalls++;                             // entry and stack is the same here
                    EntrySwitch.SetSwitch(true);
                }
                else
                {
                    UncountedStackBalls++;
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #4
0
        /// <summary>
        /// If there are any balls in the ball stack, eject one to the playfield.
        /// </summary>
        ///
        /// <remarks>
        /// This triggers any switches which the remaining balls would activate by rolling to the next position.
        /// </remarks>
        ///
        /// <returns>True if a ball was ejected, false if there were no balls in the stack to eject.</returns>
        public bool EjectBall()
        {
            if (_countedStackBalls > 0)
            {
                // open the switch of the ejected ball immediately
                switch (MainComponent.Type)
                {
                case TroughType.ModernOpto:
                case TroughType.ModernMech:
                case TroughType.TwoCoilsNSwitches:
                    if (!_stackSwitches[0].IsSwitchEnabled)
                    {
                        Logger.Warn("Ball not in eject position yet, ignoring.");
                        return(false);
                    }
                    break;

                case TroughType.TwoCoilsOneSwitch:
                    // no switches at position 0 here.
                    break;

                case TroughType.ClassicSingleBall:
                    if (!EntrySwitch.IsSwitchEnabled)
                    {
                        Logger.Warn("No ball, ignoring.");
                        return(false);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                Logger.Info("Trough: Spawning new ball.");

                _ejectKicker.CreateBall();
                _ejectCoil.OnCoil(true);

                // open the switch of the ejected ball immediately
                switch (MainComponent.Type)
                {
                case TroughType.ModernOpto:
                case TroughType.ModernMech:
                case TroughType.TwoCoilsNSwitches:
                    _stackSwitches[0].SetSwitch(false);
                    break;

                case TroughType.ClassicSingleBall:
                    EntrySwitch.SetSwitch(false);
                    break;

                    // no switches at position 0 for other types.
                }

                TriggerJamSwitch();
                RollOverStackBalls();
                RollOverNextUncountedStackBall();
#if UNITY_EDITOR
                RefreshUI();
#endif
                return(true);
            }

            return(false);
        }