Exemple #1
0
        private bool GoToTarget(Vec2Double pos, double dist, ref UnitAction action)
        {
            var meX = (int)(_unit.Position.X * PointMaster.Divisor + 0.5);
            var meY = (int)(_unit.Position.Y * PointMaster.Divisor + 0.1);

            var targetX = (int)(pos.X * PointMaster.Divisor + 0.5);
            var targetY = (int)(pos.Y * PointMaster.Divisor + 0.1);

            var jumping = !(_pointMaster.IsPointGround(meX, meY) || _pointMaster.IsPointLadder(meX, meY)) && _unit.JumpState.Speed > 0;
            var path    = _pathFinder.FindPath(
                NavigationUtils.EncodeState(meX, meY,
                                            jumping ? (int)(_unit.JumpState.MaxTime * 60 + 0.5) : 0,
                                            jumping && !_unit.JumpState.CanCancel ? 1 : 0),
                targetX, targetY,
                (int)(dist * PointMaster.Divisor)
                );

            if (path == null || path.Count == 0)
            {
                return(false);
            }

            /*for (int i = 0; i < path.Count; ++i)
             * {
             *  var (x, y, j, p) = NavigationUtils.DecodeState(path[i]);
             *  if (i == 0)
             *  {
             *      _debug.Draw(new CustomData.Line(_unit.Position.ToVec2Double(), new Vec2Float(1f * x / PointMaster.Divisor, 1f * y / PointMaster.Divisor), 0.075f,
             *          new ColorFloat(1, 0, 1, 1)));
             *  }
             *
             *  if (i + 1 == path.Count)
             *  {
             *      _debug.Draw(new CustomData.Line(pos.ToVec2Double(), new Vec2Float(1f * x / PointMaster.Divisor, 1f * y / PointMaster.Divisor), 0.075f,
             *          new ColorFloat(0, 1, 0, 1)));
             *  }
             *  else
             *  {
             *      var (nx, ny, nj, np) = NavigationUtils.DecodeState(path[i + 1]);
             *      _debug.Draw(new CustomData.Line(
             *          new Vec2Float(1f * x / PointMaster.Divisor, 1f * y / PointMaster.Divisor),
             *          new Vec2Float(1f * nx / PointMaster.Divisor, 1f * ny / PointMaster.Divisor), 0.05f,
             *          new ColorFloat(1, 0, 0, 1)));
             *  }
             * }
             *
             * _debug.Draw(new CustomData.Line(_unit.Position.ToVec2Double(), new Vec2Float(1f * meX / PointMaster.Divisor, 1f * meY / PointMaster.Divisor), 0.1f,
             *  new ColorFloat(0, 1, 1, 1)));*/

            var(x1, y1, j1, p1) = NavigationUtils.DecodeState(path[0]);
            action.Jump         = y1 > meY || (y1 == meY && _unit.Position.Y < 1d * meY / PointMaster.Divisor);
            action.JumpDown     = y1 < meY && (_pointMaster.IsPointDrop(meX, meY) || _unit.OnLadder ||
                                               (_game.Level.Tiles[(int)_unit.Position.X]
                                                [(int)(_unit.Position.Y - 1e-3)] == Tile.Ladder));  //hack
            if (j1 == 32 && !_unit.OnGround)
            {
                action.Velocity = 0;
            }
            else
            {
                action.Velocity = (1d * x1 / PointMaster.Divisor - _unit.Position.X) * _game.Properties.TicksPerSecond;
            }

            return(true);
        }