Пример #1
0
 public override void UpdateDerivedPart(ActionStep.Actions action)
 {
     base.UpdateDerivedPart(action);
     if (action == ActionStep.Actions.Add)
     {
         // Need to lock //
         if (!locked)
         {
             LockOnTarget();
         }
         // Already locked //
         else
         {
             float distance = Vector3.Distance(targetBody.position, attachedBody.position);
             //Debug.LogWarning("Tractor beam on, distance - " + distance);
             Vector3 newPosition = Vector3.MoveTowards(targetBody.position, attachedBody.position, beamStrength * Time.deltaTime);
             targetBody.position = newPosition;
         }
     }
     else
     {
         if (locked)
         {
             disengageBeam();
         }
     }
 }
Пример #2
0
 public override void UpdateDerivedPart(ActionStep.Actions currentCreatureAction)
 {
     base.UpdateDerivedPart(currentCreatureAction);
     if (currentCreatureAction == ActionStep.Actions.Add)
     {
         if (target == null)
         {
             Thing targetThing = parentCreature.GetCurrentActionTarget();
             if (targetThing == null)
             {
                 Debug.LogWarning("NO target found for tractor beam");
                 verifyParticlesAreOff();
             }
             else
             {
                 target = targetThing.transform;
                 updateMainModuleStartSpeedBasedOffDistFromTarget();
                 verifyParticlesAreON();
             }
         }
         else
         {
             verifyParticlesAreON();
             updateMainModuleStartSpeedBasedOffDistFromTarget();
         }
     }
     else
     {
         verifyParticlesAreOff();
     }
 }
Пример #3
0
        public override void UpdateDerivedPart(ActionStep.Actions action)
        {
            base.UpdateDerivedPart(action);
            Vector3 percentToBrake = attachedAgent.CurrentBrakeAmountRequest;

            //Debug.LogWarning("Applying brake - " + percentToBrake);
            if (percentToBrake.x < 0)
            {
                percentToBrake.x = 0;
            }
            else if (percentToBrake.x > 100)
            {
                percentToBrake.x = 100;
            }
            if (percentToBrake.y < 0)
            {
                percentToBrake.y = 0;
            }
            else if (percentToBrake.y > 100)
            {
                percentToBrake.y = 100;
            }
            if (percentToBrake.z < 0)
            {
                percentToBrake.z = 0;
            }
            else if (percentToBrake.z > 100)
            {
                percentToBrake.z = 100;
            }

            float x = percentToBrake.x * .01f;
            float y = percentToBrake.y * .01f;
            float z = percentToBrake.z * .01f;

            Vector3 currentVelocity;

            if (!AngularBraking)
            {
                currentVelocity = bodyToBrake.velocity;
            }
            else
            {
                currentVelocity = bodyToBrake.angularVelocity;
            }
            currentVelocity.x = currentVelocity.x * (1f - x);
            currentVelocity.y = currentVelocity.y * (1f - y);
            currentVelocity.z = currentVelocity.z * (1f - z);
            if (!AngularBraking)
            {
                bodyToBrake.velocity = currentVelocity;
            }
            else
            {
                bodyToBrake.angularVelocity = currentVelocity;
            }
            Braking            = true;
            CurrentBrakeAmount = percentToBrake;
        }
Пример #4
0
 private bool arrayContains(ActionStep.Actions action, ActionStep.Actions[] list)
 {
     foreach (ActionStep.Actions singleAction in list)
     {
         if (singleAction == action)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
 private bool animateDuringThis(ActionStep.Actions action)
 {
     foreach (ActionStep.Actions animatedAction in AnimateDuring)
     {
         if (action == animatedAction)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #6
0
 public override void UpdateDerivedPart(ActionStep.Actions action)
 {
     if (attachedBody.isKinematic)
     {
         return;
     }
     if (attachedAgent.locomotionType == CreatureLocomotionType.Flight)
     {
         Flight(action);
     }
     else if (attachedAgent.locomotionType == CreatureLocomotionType.StandardForwardBack)
     {
         ProcessStandardForwardBack();
     }
 }
Пример #7
0
 public override void UpdateDerivedPart(ActionStep.Actions currentCreatureAction)
 {
     if (!animateDuringThis(currentCreatureAction))
     {
         if (!visibleIfNotAnimating && visible)
         {
             SetVisibility(false);
         }
         return;
     }
     if (animationType == PartAnimationType.Movement)
     {
         animateMovement();
     }
 }
Пример #8
0
        public static float GetMaxAllowedTime(ActionStep.Actions action)
        {
            float maxAllowed = 30f; // Default to 30 seconds

            if (action == ActionStep.Actions.Eat)
            {
                maxAllowed = 60f; // 1 minute
            }
            else if (action == ActionStep.Actions.Land)
            {
                maxAllowed = 60f; // one minute
            }
            else if (action == ActionStep.Actions.Sleep)
            {
                maxAllowed = float.MaxValue;
            }
            return(maxAllowed);
        }
Пример #9
0
        public override void UpdateDerivedPart(ActionStep.Actions action)
        {
            base.UpdateDerivedPart(action);
            if (attachedAgent.locomotionType == CreatureLocomotionType.Flight)
            {
                if (attachedAgent.IsLanding())
                {
                    RightRotation();
                    return;
                }
            }
            Quaternion newRotation;
            Vector3    _direction = (attachedAgent.Destination - parentCreature.transform.position).normalized;

            if (_direction != Vector3.zero)
            {
                Quaternion _lookRotation = Quaternion.LookRotation(_direction);
                newRotation = Quaternion.Slerp(parentCreature.transform.rotation, _lookRotation,
                                               attachedAgent.turnSpeed);
                parentCreature.transform.rotation = newRotation;
            }
        }
Пример #10
0
 private void Flight(ActionStep.Actions currentCreatureAction)
 {
     if (currentCreatureAction == ActionStep.Actions.MoveTo)
     {
         EngineMovementVariables engineZ = engineMovementVariables[(int)Direction.Z];
         EngineMovementVariables engineY = engineMovementVariables[(int)Direction.Y];
         EngineMovementVariables engineX = engineMovementVariables[(int)Direction.X];
         Vector3 relativeVel             = attachedBody.transform.InverseTransformDirection(attachedBody.velocity);
         float   distFromGround          = attachedAgent.GetDistanceBeforeCollision(CreatureUtilities.RayCastDirection.DOWN);
         float   distanceFromFirstZHit   = attachedAgent.GetDistanceBeforeCollision(
             CreatureUtilities.RayCastDirection.FORWARD);
         float objectBlockDistance   = miscVariables[MiscVariables.AgentMiscVariables.Part_Flight_Halt_Forward_Movement_If_Object_Is_Distance];
         bool  objectBlockingForward = distanceFromFirstZHit < objectBlockDistance;
         //Debug.LogWarning("Distance from first z- " + distanceFromFirstZHit);
         MovementState stateToSetY = MovementState.IDLE;
         // Moving down or close to ground, throttle up //
         if (relativeVel.y < -.5f || distFromGround < attachedAgent.GetSustainHeight())
         {
             stateToSetY = MovementState.FORWARD;
         }
         else if (distFromGround == Mathf.Infinity)
         {
             if (attachedBody.position.y < Area.MinimumHeight)
             {
                 stateToSetY = MovementState.FORWARD;
             }
             else if (attachedBody.position.y > Area.MaximumHeight)
             {
                 stateToSetY = MovementState.IDLE;
             }
         }
         // Moving up, throttle idle
         else if (relativeVel.y > .5f)
         {
             stateToSetY = MovementState.IDLE;
         }
         else
         {
             stateToSetY = MovementState.IDLE;
         }
         if (engineY.CurrentState != stateToSetY)
         {
             engineY.SetState(stateToSetY);
         }
         // Don't move forward if we're blocked //
         if (engineZ.CurrentState != MovementState.FORWARD && !objectBlockingForward)
         {
             engineZ.SetState(MovementState.FORWARD);
         }
         if (objectBlockingForward)
         {
             float distanceRight = attachedAgent.GetDistanceBeforeCollision(CreatureUtilities.RayCastDirection.RIGHT);
             float distanceLeft  = attachedAgent.GetDistanceBeforeCollision(CreatureUtilities.RayCastDirection.LEFT);
             if (engineX.CurrentState == MovementState.IDLE)
             {
                 bool goRight = distanceLeft < distanceRight;
                 if (goRight)
                 {
                     engineX.SetState(MovementState.FORWARD);
                 }
                 else
                 {
                     engineX.SetState(MovementState.REVERSE);
                 }
             }
             if (engineZ.CurrentState == MovementState.FORWARD)
             {
                 engineZ.SetState(MovementState.IDLE);
             }
             else if (engineZ.CurrentState == MovementState.IDLE &&
                      distanceFromFirstZHit < .5f)
             {
                 engineZ.SetState(MovementState.REVERSE);
             }
             else if (engineZ.CurrentState == MovementState.REVERSE &&
                      distanceFromFirstZHit >= .5f)
             {
                 engineZ.SetState(MovementState.IDLE);
             }
         }
         else
         {
             if (engineX.CurrentState != MovementState.IDLE)
             {
                 engineX.SetState(MovementState.IDLE);
             }
         }
     }
 }
Пример #11
0
 public override void UpdateDerivedPart(ActionStep.Actions action)
 {
     base.UpdateDerivedPart(action);
 }
Пример #12
0
        public override void UpdateDerivedPart(ActionStep.Actions action)
        {
            base.UpdateDerivedPart(action);
            if (action == ActionStep.Actions.MoveTo)
            {
                // Currently Deactivated //
                if (!Activated)
                {
                    bool activate = false;

                    // STUCK //
                    if (attachedAgent.IsStuck())
                    {
                        if (ignoreStuckFor <= 0)
                        {
                            activate = true;
                        }
                    }
                    // Not stuck //
                    else if (!attachedAgent.IsStuck())
                    {
                        // Check for imminent collision //
                        float beforeCollision       = attachedAgent.GetTimeBeforeCollision();
                        float collisionProblem      = miscVariables[MiscVariables.AgentMiscVariables.Agent_Brake_If_Colliding_In];
                        float velocityNeededToBrake = miscVariables[MiscVariables.AgentMiscVariables.Part_Flight_Max_Vel_Mag_Before_Brake];
                        if (Mathf.Abs(beforeCollision) <= collisionProblem && Mathf.Abs(beforeCollision) != Mathf.Infinity &&
                            beforeCollision > .01f &&
                            attachedBody.velocity.magnitude > velocityNeededToBrake)
                        {
                            activate = true;
                        }
                        // Check for spinning //
                        else if (attachedBody.angularVelocity.magnitude >
                                 miscVariables[MiscVariables.AgentMiscVariables.Part_Flight_Angular_Velocity_Brake_When_Over])
                        {
                            activate = true;
                        }
                        // Check if we're going in the wrong direction if we're not stopped //
                        else if (attachedBody.velocity.magnitude >
                                 miscVariables[MiscVariables.AgentMiscVariables.Part_Flight_Brake_When_Going_Wrong_Direction_If_Vel])
                        {
                            Vector3 turnNeeded = getDifferenceFromLookAtTargetRotationViaVelocity().eulerAngles;

                            if ((turnNeeded.x > 45 && turnNeeded.x < 315) ||
                                (turnNeeded.z > 45 && turnNeeded.z < 315))
                            {
                                activate = true;
                            }
                        }
                    }
                    if (ignoreStuckFor > 0)
                    {
                        ignoreStuckFor -= Time.deltaTime;
                        //Debug.LogWarning("Sleeping - " + sleepFor);
                    }
                    if (activate)
                    {
                        ActivateShield();
                    }
                }
                // Currently Activated //
                else
                {
                    if (action == ActionStep.Actions.MoveTo)
                    {
                        // Make sure we are pointing in the right direction before deactivating //
                        Vector3 turnNeeded = getDifferenceFromLookAtTargetRotation().eulerAngles;
                        if (turnNeeded.magnitude < 1f || turnNeeded.magnitude > 359)
                        {
                            DeActivateShield();
                            GotoSleep(.15f);
                        }
                    }
                }
            }
            else
            {
                if (!Activated)
                {
                    bool activate = false;
                    for (int count = 0; count < _OnDuringTheseActions.Length; count++)
                    {
                        if (_OnDuringTheseActions[count] == action)
                        {
                            activate = true;
                            break;
                        }
                    }
                    if (activate)
                    {
                        ActivateShield();
                    }
                }
            }
        }
Пример #13
0
 // Implemented in more derived classes //
 public virtual void UpdateDerivedPart(ActionStep.Actions action)
 {
 }