示例#1
0
        /// <summary>
        /// Main iterator function for turning
        /// </summary>
        public void HandleTurnToHeading()
        {
            //Console.WriteLine("HandleTurnToHeading");

            if (PhysicsObj == null)
            {
                CancelMoveTo(WeenieError.NoPhysicsObject);
                return;
            }

            if (CurrentCommand != (uint)MotionCommand.TurnRight && CurrentCommand != (uint)MotionCommand.TurnLeft)
            {
                BeginTurnToHeading();
                return;
            }

            var pendingAction = PendingActions[0];
            var heading       = PhysicsObj.get_heading();

            if (heading_greater(heading, pendingAction.Heading, CurrentCommand))
            {
                FailProgressCount = 0;
                PhysicsObj.set_heading(pendingAction.Heading, true);

                RemovePendingActionsHead();

                var movementParams = new MovementParameters();
                movementParams.CancelMoveTo   = false;
                movementParams.HoldKeyToApply = MovementParams.HoldKeyToApply;

                _StopMotion(CurrentCommand, movementParams);

                CurrentCommand = 0;
                BeginNextNode();
                return;
            }

            var diff = heading_diff(heading, PreviousHeading, CurrentCommand);

            if (diff > PhysicsGlobals.EPSILON && diff < 180.0f)
            {
                FailProgressCount = 0;
                PreviousHeading   = heading;
            }
            else
            {
                PreviousHeading = heading;

                if (!PhysicsObj.IsInterpolating() && !PhysicsObj.IsAnimating)
                {
                    FailProgressCount++;
                }
            }
        }
示例#2
0
        public void BeginMoveForward()
        {
            if (PhysicsObj == null)
            {
                CancelMoveTo(0x8);
                return;
            }

            var dist    = GetCurrentDistance();
            var heading = PhysicsObj.Position.heading(CurrentTargetPosition) - PhysicsObj.get_heading();

            if (Math.Abs(heading) < PhysicsGlobals.EPSILON)
            {
                heading = 0.0f;
            }
            if (heading < -PhysicsGlobals.EPSILON)
            {
                heading += 360.0f;
            }

            uint    motion   = 0;
            bool    moveAway = false;
            HoldKey holdKey  = HoldKey.Invalid;

            MovementParams.get_command(dist, heading, ref motion, ref holdKey, ref moveAway);

            if (motion == 0)
            {
                PendingActions.Clear();
                BeginNextNode();
                return;
            }
            var movementParams = new MovementParameters();

            movementParams.HoldKeyToApply = holdKey;
            movementParams.CancelMoveTo   = false;
            movementParams.Speed          = MovementParams.Speed;

            var sequence = _DoMotion(motion, movementParams);

            if (sequence.ID != 0)
            {
                CancelMoveTo(sequence.ID);
                return;
            }
            CurrentCommand = motion;
            MovingAway     = moveAway;
            MovementParams.HoldKeyToApply = holdKey;
            PreviousDistance     = dist;
            PreviousDistanceTime = Timer.CurrentTime;
            OriginalDistance     = dist;
            OriginalDistanceTime = Timer.CurrentTime;
        }
示例#3
0
        public void MoveToPosition(Position position, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return;
            }

            PhysicsObj.StopCompletely(false);

            CurrentTargetPosition = position;
            SoughtObjectRadius    = 0.0f;

            var distance    = GetCurrentDistance();
            var headingDiff = PhysicsObj.Position.heading(position) - PhysicsObj.get_heading();

            if (Math.Abs(headingDiff) < PhysicsGlobals.EPSILON)
            {
                headingDiff = 0.0f;
            }
            if (headingDiff < -PhysicsGlobals.EPSILON)
            {
                headingDiff += 360.0f;
            }

            HoldKey holdKey  = HoldKey.Invalid;
            uint    command  = 0;
            bool    moveAway = false;

            movementParams.get_command(distance, headingDiff, ref command, ref holdKey, ref moveAway);

            if (command != 0)
            {
                AddTurnToHeadingNode(PhysicsObj.Position.heading(position));
                AddMoveToPositionNode();
            }

            if (MovementParams.UseFinalHeading)
            {
                AddTurnToHeadingNode(movementParams.DesiredHeading);
            }

            SoughtPosition   = position;
            StartingPosition = PhysicsObj.Position;

            MovementType             = MovementType.MoveToPosition;
            MovementParams           = movementParams;
            MovementParams.Bitfield &= 0xFFFFFF7F;

            BeginNextNode();
        }
示例#4
0
        public Sequence StopInterpretedMotion(uint motion, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return(new Sequence(8));
            }

            var sequence = new Sequence();

            if (contact_allows_move(motion))
            {
                if (StandingLongJump && (motion == 0x45000005 || motion == 0x44000007 || motion == 0x6500000F))
                {
                    if (movementParams.ModifyInterpretedState)
                    {
                        InterpretedState.RemoveMotion(motion);
                    }
                }
                else
                {
                    sequence = PhysicsObj.StopInterpretedMotion(motion, movementParams);

                    if (sequence == null)
                    {
                        add_to_queue(movementParams.ContextID, 0x41000003, 0);

                        if (movementParams.ModifyInterpretedState)
                        {
                            InterpretedState.RemoveMotion(motion);
                        }
                    }
                }
            }
            else
            {
                if (movementParams.ModifyInterpretedState)
                {
                    InterpretedState.RemoveMotion(motion);
                }
            }

            if (PhysicsObj.CurCell == null)
            {
                PhysicsObj.RemoveLinkAnimations();
            }

            return(sequence);
        }
示例#5
0
        public WeenieError StopInterpretedMotion(uint motion, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return(WeenieError.NoPhysicsObject);
            }

            var result = WeenieError.None;

            if (contact_allows_move(motion))
            {
                if (StandingLongJump && (motion == (uint)MotionCommand.WalkForward || motion == (uint)MotionCommand.RunForward || motion == (uint)MotionCommand.SideStepRight))
                {
                    if (movementParams.ModifyInterpretedState)
                    {
                        InterpretedState.RemoveMotion(motion);
                    }
                }
                else
                {
                    result = PhysicsObj.StopInterpretedMotion(motion, movementParams);

                    if (result == WeenieError.None)
                    {
                        add_to_queue(movementParams.ContextID, (uint)MotionCommand.Ready, WeenieError.None);

                        if (movementParams.ModifyInterpretedState)
                        {
                            InterpretedState.RemoveMotion(motion);
                        }
                    }
                }
            }
            else
            {
                if (movementParams.ModifyInterpretedState)
                {
                    InterpretedState.RemoveMotion(motion);
                }
            }

            if (PhysicsObj.CurCell == null)
            {
                PhysicsObj.RemoveLinkAnimations();
            }

            return(result);
        }
示例#6
0
        public Sequence _StopMotion(uint motion, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return(new Sequence(8));
            }

            var minterp = PhysicsObj.get_minterp();

            if (minterp == null)
            {
                return(new Sequence(11));
            }

            minterp.adjust_motion(motion, movementParams.Speed, movementParams.HoldKeyToApply);

            return(minterp.StopInterpretedMotion(motion, movementParams));
        }
示例#7
0
        public WeenieError _StopMotion(uint motion, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return(WeenieError.NoPhysicsObject);
            }

            var minterp = PhysicsObj.get_minterp();

            if (minterp == null)
            {
                return(WeenieError.NoMotionInterpreter);
            }

            minterp.adjust_motion(ref motion, ref movementParams.Speed, movementParams.HoldKeyToApply);

            return(minterp.StopInterpretedMotion(motion, movementParams));
        }
示例#8
0
        public void HandleTurnToHeading()
        {
            if (PhysicsObj == null)
            {
                CancelMoveTo(0x8);
                return;
            }
            if (CurrentCommand != 0x6500000D && CurrentCommand != 0x6500000E)
            {
                BeginTurnToHeading();
                return;
            }
            var pendingAction = PendingActions[0];
            var heading       = PhysicsObj.get_heading();

            if (heading_greater(heading, pendingAction.Heading, CurrentCommand))
            {
                FailProgressCount = 0;
                PhysicsObj.set_heading(pendingAction.Heading, true);

                RemovePendingActionsHead();

                var movementParams = new MovementParameters();
                movementParams.CancelMoveTo   = false;
                movementParams.HoldKeyToApply = MovementParams.HoldKeyToApply;

                _StopMotion(CurrentCommand, movementParams);

                CurrentCommand = 0;
                BeginNextNode();
                return;
            }
            PreviousHeading = heading;
            var diff = heading_diff(heading, PreviousHeading, CurrentCommand);

            if (diff > PhysicsGlobals.EPSILON && diff < 180.0f)
            {
                FailProgressCount = 0;
            }
            else if (!PhysicsObj.IsInterpolating() && !PhysicsObj.motions_pending())
            {
                FailProgressCount++;
            }
        }
示例#9
0
        public void TurnToHeading(MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                MovementParams.ContextID = movementParams.ContextID;
                return;
            }

            if (movementParams.StopCompletely)
            {
                PhysicsObj.StopCompletely(false);
            }

            MovementParams        = movementParams;
            MovementParams.Sticky = false;

            SoughtPosition.Frame.set_heading(movementParams.DesiredHeading);
            MovementType = MovementType.TurnToHeading;

            PendingActions.Add(new MovementNode(MovementType.TurnToHeading, movementParams.DesiredHeading));
        }
示例#10
0
 public static void Set(MovementParameters mvp, MovementParamFlags flags)
 {
     mvp.CanWalk                = flags.HasFlag(MovementParamFlags.CanWalk);
     mvp.CanRun                 = flags.HasFlag(MovementParamFlags.CanRun);
     mvp.CanSidestep            = flags.HasFlag(MovementParamFlags.CanSidestep);
     mvp.CanWalkBackwards       = flags.HasFlag(MovementParamFlags.CanWalkBackwards);
     mvp.CanCharge              = flags.HasFlag(MovementParamFlags.CanCharge);
     mvp.FailWalk               = flags.HasFlag(MovementParamFlags.FailWalk);
     mvp.UseFinalHeading        = flags.HasFlag(MovementParamFlags.UseFinalHeading);
     mvp.Sticky                 = flags.HasFlag(MovementParamFlags.Sticky);
     mvp.MoveAway               = flags.HasFlag(MovementParamFlags.MoveAway);
     mvp.MoveTowards            = flags.HasFlag(MovementParamFlags.MoveTowards);
     mvp.UseSpheres             = flags.HasFlag(MovementParamFlags.UseSpheres);
     mvp.SetHoldKey             = flags.HasFlag(MovementParamFlags.SetHoldKey);
     mvp.Autonomous             = flags.HasFlag(MovementParamFlags.Autonomous);
     mvp.ModifyRawState         = flags.HasFlag(MovementParamFlags.ModifyRawState);
     mvp.ModifyInterpretedState = flags.HasFlag(MovementParamFlags.ModifyInterpretedState);
     mvp.CancelMoveTo           = flags.HasFlag(MovementParamFlags.CancelMoveTo);
     mvp.StopCompletely         = flags.HasFlag(MovementParamFlags.StopCompletely);
     mvp.DisableJumpDuringLink  = flags.HasFlag(MovementParamFlags.DisableJumpDuringLink);
 }
示例#11
0
        public bool move_to_interpreted_state(InterpretedMotionState state)
        {
            if (PhysicsObj == null)
            {
                return(false);
            }

            RawState.CurrentStyle = state.CurrentStyle;
            PhysicsObj.cancel_moveto();

            var allowJump = motion_allows_jump(InterpretedState.ForwardCommand) == WeenieError.None ? true : false;

            InterpretedState.copy_movement_from(state);
            apply_current_movement(true, allowJump);

            var movementParams = new MovementParameters();

            foreach (var action in state.Actions)
            {
                var currentStamp = action.Stamp & 0x7FFF;
                var serverStamp  = ServerActionStamp & 0x7FFFF;

                var deltaStamp = Math.Abs(currentStamp - serverStamp);

                var diff = deltaStamp <= 0x3FFF ? serverStamp < currentStamp : currentStamp < serverStamp;

                if (diff)
                {
                    if (WeenieObj != null && WeenieObj.IsCreature() || action.Autonomous)
                    {
                        ServerActionStamp         = action.Stamp;
                        movementParams.Speed      = action.Speed;
                        movementParams.Autonomous = action.Autonomous;
                        DoInterpretedMotion(action.Action, movementParams);
                    }
                }
            }
            return(true);
        }
示例#12
0
        public Sequence StopMotion(uint motion, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return(new Sequence(8));
            }

            if (movementParams.CancelMoveTo)
            {
                PhysicsObj.cancel_moveto();
            }

            adjust_motion(motion, movementParams.Speed, movementParams.HoldKeyToApply);

            var newMotion = StopInterpretedMotion(motion, movementParams);

            if (newMotion == null && movementParams.ModifyRawState)
            {
                RawState.RemoveMotion(motion);
            }

            return(newMotion);
        }
示例#13
0
        public void MoveToObject(uint objectID, uint topLevelID, float radius, float height, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return;
            }
            PhysicsObj.StopCompletely(false);

            StartingPosition   = PhysicsObj.Position;
            SoughtObjectID     = objectID;
            SoughtObjectRadius = radius;
            SoughtObjectHeight = height;
            MovementType       = MovementType.MoveToObject;
            MovementParams     = movementParams;
            TopLevelObjectID   = topLevelID;
            Initialized        = true;
            if (PhysicsObj.ID != topLevelID)
            {
                PhysicsObj.set_target(0, TopLevelObjectID, 0.5f, 0.0f);
                return;
            }
            CleanUp();
            PhysicsObj.StopCompletely(false);
        }
示例#14
0
        /// <summary>
        /// Starts a new and discrete turn to heading node
        /// Turning while moving forward is handled in HandleMoveToPosition
        /// </summary>
        public void BeginTurnToHeading()
        {
            //Console.WriteLine("BeginTurnToHeading");

            if (PhysicsObj == null)
            {
                CancelMoveTo(WeenieError.NoPhysicsObject);
                return;
            }

            if (PendingActions.Count == 0)
            {
                return;
            }

            var  pendingAction = PendingActions[0];
            var  headingDiff   = heading_diff(pendingAction.Heading, PhysicsObj.get_heading(), (uint)MotionCommand.TurnRight);
            uint motionID      = 0;

            if (headingDiff <= 180.0f)
            {
                if (headingDiff > PhysicsGlobals.EPSILON)
                {
                    motionID = (uint)MotionCommand.TurnRight;
                }
                else
                {
                    RemovePendingActionsHead();
                    BeginNextNode();
                    return;
                }
            }
            else
            {
                if (headingDiff + PhysicsGlobals.EPSILON <= 360.0f)
                {
                    motionID = (uint)MotionCommand.TurnLeft;
                }
                else
                {
                    RemovePendingActionsHead();
                    BeginNextNode();
                    return;
                }
            }

            var movementParams = new MovementParameters();

            movementParams.CancelMoveTo = false;
            movementParams.Speed        = MovementParams.Speed; // only for turning, too fast?
            //movementParams.Speed = 1.0f;    // commented out before?
            movementParams.HoldKeyToApply = MovementParams.HoldKeyToApply;

            var result = _DoMotion(motionID, movementParams);

            if (result != WeenieError.None)
            {
                CancelMoveTo(result);
                return;
            }

            CurrentCommand  = motionID;
            PreviousHeading = headingDiff;
        }
示例#15
0
        public WeenieError DoInterpretedMotion(uint motion, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return(WeenieError.NoPhysicsObject);
            }

            var result = WeenieError.None;

            if (contact_allows_move(motion))
            {
                if (StandingLongJump && (motion == (uint)MotionCommand.WalkForward || motion == (uint)MotionCommand.RunForward || motion == (uint)MotionCommand.SideStepRight))
                {
                    if (movementParams.ModifyInterpretedState)
                    {
                        InterpretedState.ApplyMotion(motion, movementParams);
                    }
                }
                else
                {
                    if (motion == (uint)MotionCommand.Dead)
                    {
                        PhysicsObj.RemoveLinkAnimations();
                    }

                    result = PhysicsObj.DoInterpretedMotion(motion, movementParams);

                    if (result == WeenieError.None)
                    {
                        var jump_error_code = WeenieError.None;

                        if (movementParams.DisableJumpDuringLink)
                        {
                            jump_error_code = WeenieError.YouCantJumpFromThisPosition;
                        }
                        else
                        {
                            jump_error_code = motion_allows_jump(motion);

                            if (jump_error_code == WeenieError.None && (motion & (uint)CommandMask.Action) == 0)
                            {
                                jump_error_code = motion_allows_jump(InterpretedState.ForwardCommand);
                            }
                        }

                        add_to_queue(movementParams.ContextID, motion, jump_error_code);

                        if (movementParams.ModifyInterpretedState)
                        {
                            InterpretedState.ApplyMotion(motion, movementParams);
                        }
                    }
                }
            }
            else
            {
                if ((motion & (uint)CommandMask.Action) != 0)
                {
                    result = WeenieError.YouCantJumpWhileInTheAir;
                }

                else
                {
                    if (movementParams.ModifyInterpretedState)
                    {
                        InterpretedState.ApplyMotion(motion, movementParams);
                    }

                    result = WeenieError.None;
                }
            }

            if (PhysicsObj.CurCell == null)
            {
                PhysicsObj.RemoveLinkAnimations();
            }

            return(result);
        }
示例#16
0
        /// <summary>
        /// Main iterator function for movement
        /// </summary>
        public void HandleMoveToPosition()
        {
            //Console.WriteLine("HandleMoveToPosition");

            if (PhysicsObj == null)
            {
                CancelMoveTo(WeenieError.NoPhysicsObject);
                return;
            }

            var curPos = new Position(PhysicsObj.Position);

            var movementParams = new MovementParameters();

            movementParams.CancelMoveTo = false;

            movementParams.Speed          = MovementParams.Speed;
            movementParams.HoldKeyToApply = MovementParams.HoldKeyToApply;

            if (!PhysicsObj.IsAnimating)
            {
                var heading = MovementParams.get_desired_heading(CurrentCommand, MovingAway) + curPos.heading(CurrentTargetPosition);
                if (heading >= 360.0f)
                {
                    heading -= 360.0f;
                }

                var diff = heading - PhysicsObj.get_heading();

                if (Math.Abs(diff) < PhysicsGlobals.EPSILON)
                {
                    diff = 0.0f;
                }
                if (diff < -PhysicsGlobals.EPSILON)
                {
                    diff += 360.0f;
                }

                if (diff > 20.0f && diff < 340.0f)
                {
                    uint motionID = diff >= 180.0f ? (uint)MotionCommand.TurnLeft : (uint)MotionCommand.TurnRight;
                    if (motionID != AuxCommand)
                    {
                        _DoMotion(motionID, movementParams);
                        AuxCommand = motionID;
                    }
                }
                else
                {
                    // custom: sync for server ticrate
                    if (AuxCommand != 0)
                    {
                        PhysicsObj.set_heading(heading, true);
                    }

                    stop_aux_command(movementParams);
                }
            }
            else
            {
                stop_aux_command(movementParams);
            }

            var dist = GetCurrentDistance();

            if (!CheckProgressMade(dist))
            {
                if (!PhysicsObj.IsInterpolating() && !PhysicsObj.IsAnimating)
                {
                    FailProgressCount++;
                }
            }
            else
            {
                // custom for low monster update rate
                var inRange = false;

                if (!MovementParams.UseSpheres)
                {
                    if (dist < 1.0f && PreviousDistance < dist)
                    {
                        inRange = true;
                    }

                    PreviousDistance     = dist;
                    PreviousDistanceTime = PhysicsTimer.CurrentTime;
                }

                FailProgressCount = 0;
                if (MovingAway && dist >= MovementParams.MinDistance || !MovingAway && dist <= MovementParams.DistanceToObject || inRange)
                {
                    PendingActions.RemoveAt(0);
                    _StopMotion(CurrentCommand, movementParams);

                    CurrentCommand = 0;
                    stop_aux_command(movementParams);

                    BeginNextNode();
                }
                else
                {
                    if (StartingPosition.Distance(PhysicsObj.Position) > MovementParams.FailDistance)
                    {
                        CancelMoveTo(WeenieError.YouChargedTooFar);
                    }
                }
            }

            if (TopLevelObjectID != 0 && MovementType != MovementType.Invalid)
            {
                var velocity       = PhysicsObj.get_velocity();
                var velocityLength = velocity.Length();
                if (velocityLength > 0.1f)
                {
                    var time = dist / velocityLength;
                    if (Math.Abs(time - PhysicsObj.get_target_quantum()) > 1.0f)
                    {
                        PhysicsObj.set_target_quantum(time);
                    }
                }
            }
        }
示例#17
0
        public void Init()
        {
            MovementParams = new MovementParameters();

            PendingActions = new List <MovementNode>();
        }
示例#18
0
        public void ApplyMotion(uint motion, MovementParameters movementParams)
        {
            switch (motion)
            {
            case (uint)MotionCommand.TurnRight:
            case (uint)MotionCommand.TurnLeft:
                TurnCommand = motion;
                if (movementParams.SetHoldKey)
                {
                    TurnHoldKey = HoldKey.Invalid;
                    TurnSpeed   = movementParams.Speed;
                }
                else
                {
                    TurnHoldKey = movementParams.HoldKeyToApply;
                    TurnSpeed   = movementParams.Speed;
                }
                break;

            case (uint)MotionCommand.SideStepRight:
            case (uint)MotionCommand.SideStepLeft:
                SideStepCommand = motion;
                if (movementParams.SetHoldKey)
                {
                    SideStepHoldKey = HoldKey.Invalid;
                    SideStepSpeed   = movementParams.Speed;
                }
                else
                {
                    SideStepHoldKey = movementParams.HoldKeyToApply;
                    SideStepSpeed   = movementParams.Speed;
                }
                break;

            default:
                if ((motion & (uint)CommandMask.SubState) != 0)
                {
                    if (motion != (uint)MotionCommand.RunForward)
                    {
                        ForwardCommand = motion;
                        if (movementParams.SetHoldKey)
                        {
                            ForwardHoldKey = HoldKey.Invalid;
                            ForwardSpeed   = movementParams.Speed;
                        }
                        else
                        {
                            ForwardHoldKey = movementParams.HoldKeyToApply;
                            ForwardSpeed   = movementParams.Speed;
                        }
                    }
                }
                else if ((motion & (uint)CommandMask.Style) != 0)
                {
                    if (CurrentStyle != motion)
                    {
                        ForwardCommand = (uint)MotionCommand.Ready;
                        CurrentStyle   = motion;
                    }
                }
                else if ((motion & (uint)CommandMask.Action) != 0)
                {
                    AddAction(motion, movementParams.Speed, movementParams.ActionStamp, movementParams.Autonomous);
                }
                break;
            }
        }
示例#19
0
        public void MoveToObject(uint objectID, uint topLevelID, float radius, float height, MovementParameters movementParams)
        {
            //Console.WriteLine("MoveToObject");

            if (PhysicsObj == null)
            {
                return;
            }

            PhysicsObj.StopCompletely(false);

            StartingPosition   = new Position(PhysicsObj.Position);
            SoughtObjectID     = objectID;
            SoughtObjectRadius = radius;
            SoughtObjectHeight = height;
            MovementType       = MovementType.MoveToObject;
            TopLevelObjectID   = topLevelID;

            MovementParams = new MovementParameters(movementParams);

            Initialized = false;
            if (PhysicsObj.ID != topLevelID)
            {
                PhysicsObj.set_target(0, TopLevelObjectID, 0.5f, 0.0f);
                return;
            }
            CleanUp();
            PhysicsObj.StopCompletely(false);
        }
示例#20
0
        public void apply_interpreted_movement(bool cancelMoveTo, bool allowJump)
        {
            if (PhysicsObj == null)
            {
                return;
            }

            var movementParams = new MovementParameters();

            movementParams.SetHoldKey             = false;
            movementParams.ModifyInterpretedState = false;
            movementParams.CancelMoveTo           = cancelMoveTo;
            movementParams.DisableJumpDuringLink  = !allowJump;

            if (InterpretedState.ForwardCommand == (uint)MotionCommand.RunForward)
            {
                MyRunRate = InterpretedState.ForwardSpeed;
            }

            DoInterpretedMotion(InterpretedState.CurrentStyle, movementParams);

            if (contact_allows_move(InterpretedState.ForwardCommand))
            {
                if (!StandingLongJump)
                {
                    movementParams.Speed = InterpretedState.ForwardSpeed;
                    DoInterpretedMotion(InterpretedState.ForwardCommand, movementParams);

                    if (InterpretedState.SideStepCommand != 0)
                    {
                        movementParams.Speed = InterpretedState.SideStepSpeed;
                        DoInterpretedMotion(InterpretedState.SideStepCommand, movementParams);
                    }
                    else
                    {
                        StopInterpretedMotion((uint)MotionCommand.SideStepRight, movementParams);
                    }
                }
                else
                {
                    movementParams.Speed = 1.0f;
                    DoInterpretedMotion((uint)MotionCommand.Ready, movementParams);
                    StopInterpretedMotion((uint)MotionCommand.SideStepRight, movementParams);
                }
            }
            else
            {
                movementParams.Speed = 1.0f;
                DoInterpretedMotion((uint)MotionCommand.Falling, movementParams);
            }

            if (InterpretedState.TurnCommand != 0)
            {
                movementParams.Speed = InterpretedState.TurnSpeed;
                DoInterpretedMotion(InterpretedState.TurnCommand, movementParams);
            }
            else
            {
                var result = PhysicsObj.StopInterpretedMotion((uint)MotionCommand.TurnRight, movementParams);

                if (result == WeenieError.None)
                {
                    add_to_queue(movementParams.ContextID, (uint)MotionCommand.Ready, WeenieError.None);

                    if (movementParams.ModifyInterpretedState)
                    {
                        InterpretedState.RemoveMotion((uint)MotionCommand.TurnRight);
                    }
                }

                if (PhysicsObj.CurCell == null)
                {
                    PhysicsObj.RemoveLinkAnimations();
                }
            }
        }
示例#21
0
 public MovementStruct(MovementType type, uint motion, MovementParameters movementParams)
 {
     Type   = type;
     Motion = motion;
     Params = movementParams;
 }
示例#22
0
        public void ApplyMotion(uint motion, MovementParameters movementParams)
        {
            switch (motion)
            {
            case 0x6500000D:
            case 0x6500000E:
                TurnCommand = motion;
                if (movementParams.SetHoldKey)
                {
                    TurnHoldKey = HoldKey.Invalid;
                    TurnSpeed   = movementParams.Speed;
                }
                else
                {
                    TurnHoldKey = movementParams.HoldKeyToApply;
                    TurnSpeed   = movementParams.Speed;
                }
                break;

            case 0x6500000F:
            case 0x65000010:
                SideStepCommand = motion;
                if (movementParams.SetHoldKey)
                {
                    SideStepHoldKey = HoldKey.Invalid;
                    SideStepSpeed   = movementParams.Speed;
                }
                else
                {
                    SideStepHoldKey = movementParams.HoldKeyToApply;
                    SideStepSpeed   = movementParams.Speed;
                }
                break;

            default:
                if ((motion & 0x40000000) != 0)
                {
                    if (motion != 0x44000007)
                    {
                        ForwardCommand = motion;
                        if (movementParams.SetHoldKey)
                        {
                            ForwardHoldKey = HoldKey.Invalid;
                            ForwardSpeed   = movementParams.Speed;
                        }
                        else
                        {
                            ForwardHoldKey = movementParams.HoldKeyToApply;
                            ForwardSpeed   = movementParams.Speed;
                        }
                    }
                }
                else if ((motion & 0x80000000) != 0)
                {
                    if (CurrentStyle != motion)
                    {
                        ForwardCommand = 0x41000003;
                        CurrentStyle   = motion;
                    }
                }
                else if ((motion & 0x10000000) != 0)
                {
                    AddAction(motion, movementParams.Speed, movementParams.ActionStamp, movementParams.Autonomous);
                }
                break;
            }
        }
示例#23
0
        /// <summary>
        /// Main iterator function for movement
        /// </summary>
        public void HandleMoveToPosition()
        {
            //Console.WriteLine("HandleMoveToPosition");

            if (PhysicsObj == null)
            {
                CancelMoveTo(WeenieError.NoPhysicsObject);
                return;
            }

            var curPos = new Position(PhysicsObj.Position);

            var movementParams = new MovementParameters();

            movementParams.Speed = MovementParams.Speed;
            //movementParams.Speed = 1.0f;    // commented out?
            var flags = (MovementParamFlags)0xFFFF7FFF;

            movementParams.Flags          = movementParams.Flags & flags; // ??
            movementParams.HoldKeyToApply = MovementParams.HoldKeyToApply;

            if (!PhysicsObj.motions_pending())
            {
                var heading = MovementParams.get_desired_heading(CurrentCommand, MovingAway) + curPos.heading(CurrentTargetPosition);
                if (heading >= 360.0f)
                {
                    heading -= 360.0f;
                }

                var diff = heading - PhysicsObj.get_heading();

                if (Math.Abs(diff) < PhysicsGlobals.EPSILON)
                {
                    diff = 0.0f;
                }
                if (diff < -PhysicsGlobals.EPSILON)
                {
                    diff += 360.0f;
                }

                if (diff > 20.0f && diff < 340.0f)
                {
                    uint motionID = diff >= 180.0f ? (uint)MotionCommand.TurnLeft : (uint)MotionCommand.TurnRight;
                    if (motionID != AuxCommand)
                    {
                        _DoMotion(motionID, movementParams);
                        AuxCommand = motionID;
                    }
                }
                else
                {
                    stop_aux_command(movementParams);
                }
            }
            else
            {
                stop_aux_command(movementParams);
            }

            var dist = GetCurrentDistance();

            if (!CheckProgressMade(dist))
            {
                if (!PhysicsObj.IsInterpolating() && !PhysicsObj.motions_pending())
                {
                    FailProgressCount++;
                }
            }
            else
            {
                FailProgressCount = 0;
                if (MovingAway && dist >= MovementParams.MinDistance || !MovingAway && dist <= MovementParams.DistanceToObject)
                {
                    PendingActions.RemoveAt(0);
                    _StopMotion(CurrentCommand, movementParams);

                    CurrentCommand = 0;
                    stop_aux_command(movementParams);

                    BeginNextNode();
                }
                else
                {
                    if (StartingPosition.Distance(PhysicsObj.Position) > MovementParams.FailDistance)
                    {
                        CancelMoveTo(WeenieError.YouChargedTooFar);
                    }
                }
            }

            if (TopLevelObjectID != 0 && MovementType != MovementType.Invalid)
            {
                var velocity       = PhysicsObj.get_velocity();
                var velocityLength = velocity.Length();
                if (velocityLength > 0.1f)
                {
                    var time = dist / velocityLength;
                    if (Math.Abs(time - PhysicsObj.get_target_quantum()) > 1.0f)
                    {
                        PhysicsObj.set_target_quantum(time);
                    }
                }
            }
        }
示例#24
0
        public WeenieError DoMotion(uint motion, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return(WeenieError.NoPhysicsObject);
            }

            // movementparams ref?
            var currentParams = new MovementParameters();

            currentParams.CopySome(movementParams);

            var currentMotion = motion;

            if (movementParams.CancelMoveTo)
            {
                PhysicsObj.cancel_moveto();
            }

            if (movementParams.SetHoldKey)
            {
                SetHoldKey(movementParams.HoldKeyToApply, movementParams.CancelMoveTo);
            }

            adjust_motion(ref currentMotion, ref currentParams.Speed, movementParams.HoldKeyToApply);

            if (InterpretedState.CurrentStyle != (uint)MotionCommand.NonCombat)
            {
                switch (motion)
                {
                case (uint)MotionCommand.Crouch:
                    return(WeenieError.CantCrouchInCombat);

                case (uint)MotionCommand.Sitting:
                    return(WeenieError.CantSitInCombat);

                case (uint)MotionCommand.Sleeping:
                    return(WeenieError.CantLieDownInCombat);
                }

                if ((motion & (uint)CommandMask.ChatEmote) != 0)
                {
                    return(WeenieError.CantChatEmoteInCombat);
                }
            }

            if ((motion & (uint)CommandMask.Action) != 0)
            {
                if (InterpretedState.GetNumActions() >= 6)
                {
                    return(WeenieError.TooManyActions);
                }
            }
            var result = DoInterpretedMotion(currentMotion, currentParams);

            if (result == WeenieError.None && movementParams.ModifyRawState)
            {
                RawState.ApplyMotion(motion, movementParams);
            }

            return(result);
        }
示例#25
0
        public Sequence DoInterpretedMotion(uint motion, MovementParameters movementParams)
        {
            if (PhysicsObj == null)
            {
                return(new Sequence(8));
            }

            var sequence = new Sequence();

            if (contact_allows_move(motion))
            {
                if (StandingLongJump && (motion == 0x45000005 || motion == 0x44000007 || motion == 0x6500000F))
                {
                    if (movementParams.ModifyInterpretedState)
                    {
                        InterpretedState.ApplyMotion(motion, movementParams);
                    }
                }
                else
                {
                    if (motion == 0x40000011)
                    {
                        PhysicsObj.RemoveLinkAnimations();
                    }

                    sequence = PhysicsObj.DoInterpretedMotion(motion, movementParams);

                    if (sequence == null)
                    {
                        var jump_error_code = 0;

                        if (movementParams.DisableJumpDuringLink)
                        {
                            jump_error_code = 0x48;
                        }
                        else
                        {
                            jump_error_code = motion_allows_jump(motion);

                            if (jump_error_code == 0 && (motion & 0x10000000) != 0)
                            {
                                jump_error_code = motion_allows_jump(InterpretedState.ForwardCommand);
                            }
                        }

                        add_to_queue(movementParams.ContextID, motion, jump_error_code);

                        if (movementParams.ModifyInterpretedState)
                        {
                            InterpretedState.ApplyMotion(motion, movementParams);
                        }
                    }
                }
            }
            else
            {
                if ((motion & 0x10000000) != 0)
                {
                    sequence.ID = 0x24;
                }

                else if (movementParams.ModifyInterpretedState)
                {
                    InterpretedState.ApplyMotion(motion, movementParams);
                }
            }

            if (PhysicsObj != null && PhysicsObj.CurCell == null)
            {
                PhysicsObj.RemoveLinkAnimations();
            }

            return(sequence);
        }
示例#26
0
        public void apply_interpreted_movement(bool cancelMoveTo, bool allowJump)
        {
            if (PhysicsObj == null)
            {
                return;
            }

            var movementParams = new MovementParameters();

            if (cancelMoveTo)
            {
                movementParams.CancelMoveTo = true;
            }
            if (!allowJump)
            {
                movementParams.DisableJumpDuringLink = true;
            }

            if (InterpretedState.ForwardCommand == 0x44000007)
            {
                MyRunRate = InterpretedState.ForwardSpeed;
            }

            DoInterpretedMotion(InterpretedState.CurrentStyle, movementParams);

            if (contact_allows_move(InterpretedState.ForwardCommand))
            {
                if (!StandingLongJump)
                {
                    movementParams.Speed = InterpretedState.ForwardSpeed;
                    DoInterpretedMotion(InterpretedState.ForwardCommand, movementParams);

                    if (InterpretedState.SideStepCommand != 0)
                    {
                        movementParams.Speed = InterpretedState.SideStepSpeed;
                        DoInterpretedMotion(InterpretedState.SideStepCommand, movementParams);
                    }
                    else
                    {
                        StopInterpretedMotion(0x6500000F, movementParams);
                    }
                }
                else
                {
                    movementParams.Speed = 1.0f;
                    DoInterpretedMotion(0x41000003, movementParams);
                    StopInterpretedMotion(0x6500000F, movementParams);
                }
            }
            else
            {
                movementParams.Speed = 1.0f;
                DoInterpretedMotion(0x40000015, movementParams);
            }

            if (InterpretedState.TurnCommand != 0)
            {
                movementParams.Speed = InterpretedState.TurnSpeed;
                DoInterpretedMotion(InterpretedState.TurnCommand, movementParams);
            }
            else
            {
                if (StopInterpretedMotion(0x6500000D, movementParams) != null)
                {
                    add_to_queue(movementParams.ContextID, 0x41000003, 0);

                    if (movementParams.ModifyInterpretedState)
                    {
                        InterpretedState.RemoveMotion(0x6500000D);
                    }
                }

                if (PhysicsObj.CurCell == null)
                {
                    PhysicsObj.RemoveLinkAnimations();
                }
            }
        }
示例#27
0
        public static MovementParamFlags Get(MovementParameters mvp)
        {
            var flags = new MovementParamFlags();

            if (mvp.CanWalk)
            {
                flags |= MovementParamFlags.CanWalk;
            }
            if (mvp.CanRun)
            {
                flags |= MovementParamFlags.CanRun;
            }
            if (mvp.CanSidestep)
            {
                flags |= MovementParamFlags.CanSidestep;
            }
            if (mvp.CanWalkBackwards)
            {
                flags |= MovementParamFlags.CanWalkBackwards;
            }
            if (mvp.CanCharge)
            {
                flags |= MovementParamFlags.CanCharge;
            }
            if (mvp.FailWalk)
            {
                flags |= MovementParamFlags.FailWalk;
            }
            if (mvp.UseFinalHeading)
            {
                flags |= MovementParamFlags.UseFinalHeading;
            }
            if (mvp.Sticky)
            {
                flags |= MovementParamFlags.Sticky;
            }
            if (mvp.MoveAway)
            {
                flags |= MovementParamFlags.MoveAway;
            }
            if (mvp.MoveTowards)
            {
                flags |= MovementParamFlags.MoveTowards;
            }
            if (mvp.UseSpheres)
            {
                flags |= MovementParamFlags.UseSpheres;
            }
            if (mvp.SetHoldKey)
            {
                flags |= MovementParamFlags.SetHoldKey;
            }
            if (mvp.Autonomous)
            {
                flags |= MovementParamFlags.Autonomous;
            }
            if (mvp.ModifyRawState)
            {
                flags |= MovementParamFlags.ModifyRawState;
            }
            if (mvp.ModifyInterpretedState)
            {
                flags |= MovementParamFlags.ModifyInterpretedState;
            }
            if (mvp.CancelMoveTo)
            {
                flags |= MovementParamFlags.CancelMoveTo;
            }
            if (mvp.StopCompletely)
            {
                flags |= MovementParamFlags.StopCompletely;
            }
            if (mvp.DisableJumpDuringLink)
            {
                flags |= MovementParamFlags.DisableJumpDuringLink;
            }

            return(flags);
        }
示例#28
0
        public void HandleMoveToPosition()
        {
            if (PhysicsObj == null)
            {
                CancelMoveTo(0x8);
                return;
            }
            var curPos = PhysicsObj.Position;

            var movementParams = new MovementParameters();

            movementParams.Speed          = MovementParams.Speed;
            movementParams.Bitfield      &= 0xFFFF7FFF;
            movementParams.HoldKeyToApply = MovementParams.HoldKeyToApply;

            if (!PhysicsObj.motions_pending())
            {
                var heading = MovementParams.get_desired_heading(CurrentCommand, MovingAway) + curPos.heading(CurrentTargetPosition);
                if (heading >= 360.0f)
                {
                    heading -= 360.0f;
                }

                var diff = heading - PhysicsObj.get_heading();

                if (Math.Abs(diff) < PhysicsGlobals.EPSILON)
                {
                    diff = 0.0f;
                }
                if (diff < -PhysicsGlobals.EPSILON)
                {
                    diff += 360.0f;
                }

                if (diff > 20.0f && diff < 340.0f)
                {
                    uint motionID = (uint)(diff >= 180.0f ? 0x6500000E : 0x6500000D);
                    if (motionID != AuxCommand)
                    {
                        _DoMotion(motionID, movementParams);
                        AuxCommand = motionID;
                    }
                }
                else
                {
                    stop_aux_command(movementParams);
                }
            }
            else
            {
                stop_aux_command(movementParams);
            }

            var dist = GetCurrentDistance();

            if (!CheckProgressMade(dist))
            {
                if (!PhysicsObj.IsInterpolating() && !PhysicsObj.motions_pending())
                {
                    FailProgressCount++;
                }
            }
            else
            {
                FailProgressCount = 0;
                if (MovingAway && dist >= MovementParams.MinDistance && MovingAway || !MovingAway && dist <= MovementParams.DistanceToObject)
                {
                    PendingActions.RemoveAt(0);
                    _StopMotion(CurrentCommand, movementParams);

                    CurrentCommand = 0;
                    stop_aux_command(movementParams);

                    BeginNextNode();
                }
                else
                {
                    if (StartingPosition.Distance(PhysicsObj.Position) > MovementParams.FailDistance)
                    {
                        CancelMoveTo(0x3D);
                    }
                }
            }
            if (TopLevelObjectID != 0 && MovementType != MovementType.Invalid)
            {
                var velocity       = PhysicsObj.get_velocity();
                var velocityLength = velocity.Length();
                if (velocityLength > 0.1f)
                {
                    var time = dist / velocityLength;
                    if (Math.Abs(time - PhysicsObj.get_target_quantum()) > 1.0f)
                    {
                        PhysicsObj.set_target_quantum(time);
                    }
                }
            }
        }