private void onStateExit(BalloonState state)
    {
        switch (state)
        {
        case BalloonState.Idle:
            break;

        case BalloonState.Inflate:
            BalloonForcer.Force = _balloonDefaultForce;
            break;

        case BalloonState.Deflate:
            //TODO: check if the balloon is popped so we don't accidentally set the wrong min y here
            _targetMinYVelo = BalloonMinYVelo;

            DeflateForcer.Force = Vector2.zero;
            break;

        case BalloonState.Popped:
            _playerHasControl   = true;
            DeflateForcer.Force = Vector2.zero;
            break;

        default:
            logWarningFormat("No handler for state {0} in _onStateExit, did you forget to add it to the switch statement?", Enum.GetName(typeof(BalloonState), state));
            break;
        }
    }
        /// <summary>
        /// Determine balloon state based on latest gps location
        /// </summary>
        /// <param name="currentState"></param>
        /// <param name="newLocation"></param>
        /// <returns></returns>
        public BalloonState DetermineNewState(BalloonState currentState, GPSLocation newLocation)
        {
            BalloonState newState = currentState;

            switch (currentState)
            {
            case BalloonState.PreLaunch:
                if ((newLocation.alt >= GroundAltitudeThreshold) && (newLocation.climb >= RiseThreshold))
                {
                    newState = BalloonState.Rising;
                }
                break;

            case BalloonState.Rising:
                if ((newLocation.alt >= GroundAltitudeThreshold) && (newLocation.climb <= FallingThreshold))
                {
                    newState = BalloonState.Falling;
                }
                break;

            case BalloonState.Falling:
                if (newLocation.alt <= GroundAltitudeThreshold)
                {
                    newState = BalloonState.Landed;
                }
                break;
            }

            return(newState);
        }
        public void BalloonLandedDetection(BalloonState initialState, double altitude, BalloonState expectedState)
        {
            // arrange
            var fakeModuleClient = new FakeModuleClient();

            var telemetryMessage = CreateTelemetryMessage();

            // set gps to indicate rising balloon state
            telemetryMessage.alt = altitude;

            var balloonModule = new WeatherBalloon.BalloonModule.BalloonModule();

            balloonModule.BalloonState = initialState;

            // act
            balloonModule.Receive(telemetryMessage);
            var task = balloonModule.TransmitBalloonMessage(fakeModuleClient);

            // verify
            task.Result.ShouldBe(true);

            // Sent a Balloon message?
            fakeModuleClient.SentMessages.Count.ShouldBe(1);

            // Correct message?
            var rawMessage     = fakeModuleClient.SentMessages[0].Item2;
            var balloonMessage = MessageHelper.ParseMessage <BalloonMessage>(rawMessage);

            balloonMessage.State.ShouldBe(expectedState);
        }
        public void BalloonFallingStateDetection(double climb, double altitude, BalloonState expectedState)
        {
            // arrange
            var fakeModuleClient = new FakeModuleClient();

            var telemetryMessage = CreateTelemetryMessage();

            // set gps to indicate rising balloon state
            telemetryMessage.climb = climb;
            telemetryMessage.alt   = altitude;

            var balloonModule = new WeatherBalloon.BalloonModule.BalloonModule();

            // set the balloon state to Rising, that's the only transition to Falling.
            balloonModule.BalloonState = BalloonState.Rising;


            // act
            balloonModule.Receive(telemetryMessage);
            var task = balloonModule.TransmitBalloonMessage(fakeModuleClient);

            // verify
            task.Result.ShouldBe(true);

            // Sent a Balloon message?
            fakeModuleClient.SentMessages.Count.ShouldBe(1);

            // Sent on correct output?
            fakeModuleClient.SentMessages[0].Item1.ShouldBe(WeatherBalloon.BalloonModule.BalloonModule.BalloonOutputName);

            // Correct message?
            var rawMessage     = fakeModuleClient.SentMessages[0].Item2;
            var balloonMessage = MessageHelper.ParseMessage <BalloonMessage>(rawMessage);

            // balloon location
            balloonMessage.Location.track.ShouldBe(telemetryMessage.track);
            [email protected](telemetryMessage.@long);
            balloonMessage.Location.lat.ShouldBe(telemetryMessage.lat);
            balloonMessage.Location.mode.ShouldBe(telemetryMessage.mode);
            balloonMessage.Location.time.ShouldBe(telemetryMessage.time);
            balloonMessage.Location.speed.ShouldBe(telemetryMessage.speed);
            balloonMessage.Location.climb.ShouldBe(telemetryMessage.climb);
            balloonMessage.Temperature.ShouldBe(telemetryMessage.temp);
            balloonMessage.Pressure.ShouldBe(telemetryMessage.pressure);
            balloonMessage.Humidity.ShouldBe(telemetryMessage.humidity);


            if (expectedState == BalloonState.Rising)
            {
                balloonMessage.AveAscent.ShouldBe(telemetryMessage.climb);
                balloonMessage.AveDescent.ShouldBe(0.0);
            }
            else if (expectedState == BalloonState.Falling)
            {
                balloonMessage.AveAscent.ShouldBe(0.0);
                balloonMessage.AveDescent.ShouldBe(telemetryMessage.climb);
            }

            balloonMessage.State.ShouldBe(expectedState);
        }
Esempio n. 5
0
    // Use this for initialization
    void Start()
    {
        //初期化処理
        scaleCount   = 1;
        moveTime     = 1.0f;
        isMove       = true;
        isEnd        = false;
        balloonState = BalloonState.SAFETY;
        scaleRate    = scaleLimit / blastLimit;
        blastCount   = 0;
        blastTime    = originBlastTime;

        player = GameObject.Find("Player" + Random.Range(1, 5));           //プレイヤーをランダムで指定
        player.GetComponent <PlayerMove>().balloon = transform.gameObject; //プレイヤー内に自分を指定
    }
        /// <summary>
        /// Receive new GPS information
        /// </summary>
        /// <param name="message"></param>
        public void Receive(TelemetryMessage message)
        {
            lock (lockingUpdateObject)
            {
                Location.alt   = message.alt;
                Location.climb = message.climb;
                Location.lat   = message.lat;
                Location.@long = message.@long;
                Location.mode  = message.mode;
                Location.speed = message.speed;
                Location.time  = message.time;
                Location.track = message.track;

                Temperature = message.temp;
                Humidity    = message.humidity;
                Pressure    = message.pressure;

                var newState = DetermineNewState(BalloonState, Location);

                if (newState != BalloonState)
                {
                    // Did the balloon just pop?
                    if (BalloonState == BalloonState.Rising && newState == BalloonState.Falling)
                    {
                        Logger.LogInfo("Burst DETECTED!!!");

                        BurstAltitude = Location.alt;
                    }

                    Logger.LogInfo($"Transitioned Balloon State. From: {BalloonState} To: {newState}");
                    BalloonState = newState;
                }

                // Update averaged telemetry data
                if (BalloonState == BalloonState.Rising)
                {
                    ascentDataPoints++;
                    AverageAscent = ((ascentDataPoints - 1) / ascentDataPoints) * AverageAscent + (Location.climb / ascentDataPoints);
                }
                else if (BalloonState == BalloonState.Falling)
                {
                    descentDataPoints++;
                    AverageDescent = ((descentDataPoints - 1) / descentDataPoints) * AverageDescent + (Location.climb / descentDataPoints);
                }
            }
        }
    private void onStateEnter(BalloonState state)
    {
        switch (state)
        {
        case BalloonState.Idle:
            _targetMinYVelo = BalloonMinYVelo;
            break;

        case BalloonState.Inflate:
            if (_body.velocity.y < 0)
            {
                setBodyVelocityY(_body.velocity.y / 2f);
            }

            _balloonDefaultForce = BalloonForcer.Force;
            BalloonForcer.Force  = InflateForce * Vector2.up;
            break;

        case BalloonState.Deflate:
            if (_body.velocity.y > 0)
            {
                setBodyVelocityY(_body.velocity.y / 2);
            }

            _targetMinYVelo     = DeflateMinYVelo;
            DeflateForcer.Force = DeflateForce * Vector2.down;
            break;

        case BalloonState.Popped:
            _playerHasControl = false;
            _targetMinYVelo   = PoppedMinYVelo;
            // apply deflate forcer to drop with "weight"
            DeflateForcer.Force = DeflateForce * Vector2.down;
            break;

        default:
            logWarningFormat("No handler for state {0} in _onStateEnter, did you forget to add it to the switch statement?", Enum.GetName(typeof(BalloonState), state));
            break;
        }
    }
Esempio n. 8
0
    /// <summary>
    /// 色変更
    /// </summary>
    void ColorChange()
    {
        if (blastCount < 10) //1.7以下なら安全状態
        {
            balloonState = BalloonState.SAFETY;
        }

        switch (balloonState)
        {
        //1.7以下なら安全状態
        //色は緑
        case BalloonState.SAFETY:
            gameObject.GetComponent <Renderer>().material.color = new Color(34 / 255f, 195 / 255f, 80 / 255f);
            if (blastCount > 10)
            {
                balloonState = BalloonState.CAUTION;
            }
            break;

        //1.7以上なら注意状態
        //色は黄色
        case BalloonState.CAUTION:
            gameObject.GetComponent <Renderer>().material.color = new Color(255 / 255f, 241 / 255f, 15 / 255f);
            if (blastCount > 20)
            {
                balloonState = BalloonState.DANGER;
            }
            break;

        //2.4以上なら危険状態
        //色は赤
        case BalloonState.DANGER:
            gameObject.GetComponent <Renderer>().material.color = new Color(229 / 255f, 0 / 255f, 11 / 255f);
            break;
        }
    }
 public void SetState(BalloonState state)
 {
     onStateExit(_state);
     onStateEnter(state);
     _state = state;
 }
Esempio n. 10
0
        override public void Update(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            var body = Parent as GameComponent;

            global::System.Diagnostics.Debug.Assert(body != null);

            Vector3 targetVelocity = TargetPosition - body.GlobalTransform.Translation;

            if (targetVelocity.LengthSquared() > 0.0001f)
            {
                targetVelocity.Normalize();
                targetVelocity *= MaxVelocity;
            }

            Matrix m = body.LocalTransform;

            m.Translation      += targetVelocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            body.LocalTransform = m;

            body.HasMoved = true;

            switch (State)
            {
            case BalloonState.DeliveringGoods:
            {
                var voxel = new VoxelHandle(chunks, GlobalVoxelCoordinate.FromVector3(body.GlobalTransform.Translation));

                if (voxel.IsValid)
                {
                    var surfaceVoxel = VoxelHelpers.FindFirstVoxelBelow(voxel);
                    var height       = surfaceVoxel.Coordinate.Y + 1;

                    TargetPosition = new Vector3(body.GlobalTransform.Translation.X, height + 5, body.GlobalTransform.Translation.Z);

                    Vector3 diff = body.GlobalTransform.Translation - TargetPosition;

                    if (diff.LengthSquared() < 2)
                    {
                        State = BalloonState.Waiting;
                    }
                }
                else
                {
                    State = BalloonState.Leaving;
                }
            }
            break;

            case BalloonState.Leaving:
                TargetPosition = Vector3.UnitY * 100 + body.GlobalTransform.Translation;

                if (body.GlobalTransform.Translation.Y > World.WorldSizeInVoxels.Y + 2)
                {
                    Die();
                }

                break;

            case BalloonState.Waiting:
                TargetPosition = body.GlobalTransform.Translation;
                if (!WaitTimer.HasTriggered)
                {
                    var voxel = new VoxelHandle(chunks, GlobalVoxelCoordinate.FromVector3(body.GlobalTransform.Translation));

                    if (voxel.IsValid)
                    {
                        var surfaceVoxel = VoxelHelpers.FindFirstVoxelBelow(voxel);
                        var height       = surfaceVoxel.Coordinate.Y + 6;

                        TargetPosition = new Vector3(body.GlobalTransform.Translation.X, height + 0.5f * (float)Math.Sin(DwarfTime.LastTime.TotalGameTime.TotalSeconds), body.GlobalTransform.Translation.Z);
                    }
                    WaitTimer.Update(DwarfTime.LastTime);
                    break;
                }

                if (!shipmentGiven)
                {
                    shipmentGiven = true;
                }
                else
                {
                    State = BalloonState.Leaving;
                }

                break;
            }
        }