コード例 #1
0
    bool IsConnectedCell(int tileX, int tileY)
    {
        //주변에 하나라도 붙은 기둥이 있으면 연결된 기둥
        for (int direction = (int)eMoveDirection.LEFT; direction < (int)eMoveDirection.DOWN + 1; direction++)
        {
            sPosition position;
            position.x = tileX;
            position.y = tileY;

            sPosition nextPosition = GlobalUtility.GetPositionByDirection(position, (eMoveDirection)direction);

            if (0 <= nextPosition.x && nextPosition.x < _width && 0 <= nextPosition.y && nextPosition.y < _height)
            {
                if (false == GetTileCell(nextPosition.x, nextPosition.y).IsPathfindable())
                {
                    return(true);
                }
            }
            else
            {
                return(true);    //맵 밖
            }
        }
        return(false);
    }
コード例 #2
0
ファイル: base.cs プロジェクト: bacome/imapclient
        public bool GetNZNumber(out cByteList rBytes, out uint rNumber)
        {
            var lBookmark = Position;

            rNumber = 0;

            if (!GetToken(cCharset.Digit, null, null, out rBytes))
            {
                return(false);
            }

            if (rBytes[0] == cASCII.ZERO)
            {
                Position = lBookmark; return(false);
            }

            checked
            {
                try { foreach (byte lByte in rBytes)
                      {
                          rNumber = rNumber * 10 + lByte - cASCII.ZERO;
                      }
                }
                catch { Position = lBookmark; return(false); }
            }

            return(true);
        }
コード例 #3
0
ファイル: AStar.cs プロジェクト: fire-eggs/CivOne
    protected void Neighbors(Node CurrNode, List <Node> neighbors)
    {
        int[,] aiRelPos = new int[, ] {
            { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 }
        };

        //       ii = ++ii;          // just to make som variation in sea and air routing
        for (uint i = 0; i < 8; i++)
        {
            sPosition CurPosition = CurrNode.Position;
            sPosition NewPosition;
            uint      j = (i + ii) % 8;
            NewPosition.iX = CurPosition.iX + aiRelPos[j, 0];
            NewPosition.iX = (NewPosition.iX + Map.WIDTH) % Map.WIDTH;
            NewPosition.iY = CurPosition.iY + aiRelPos[j, 1];
            if (NewPosition.iY < 0 || NewPosition.iY >= Map.HEIGHT)
            {
                continue;
            }
            Node NewNode = new Node();
            NewNode.Position         = NewPosition;
            NewNode.IsClosed         = false;
            NewNode.PreviousPosition = CurPosition;
            neighbors.Add(NewNode);
        }
    }
コード例 #4
0
ファイル: AStar.cs プロジェクト: fire-eggs/CivOne
    /*  ******************************************************************************************************** */
    private bool ChecknNighbours(sPosition position)
    {
        int  iX, iY;
        byte _owner = _unit.Owner;

        iX = position.iX;
        iY = position.iY;

        for (int iYY = -1; iYY <= 1; iYY++)
        {
            for (int iXX = -1; iXX <= 1; iXX++)
            {
                int iXXX = (iXX + iX + Map.WIDTH) % Map.WIDTH;

                ITile Nighbour = Map[iXXX, iYY + iY];
                if (Nighbour == null)
                {
                    continue;                                               // Ever happens ??
                }
                if (Nighbour.Units.Any(u => u.Owner != _owner))
                {
                    return(true);                               // enemy close
                }
            }
        }
        return(false);
    }
コード例 #5
0
    public static sPosition GetPositionByDirection(sPosition position, eMoveDirection direction)
    {
        int moveX = position.x;
        int moveY = position.y;

        switch (direction)
        {
        case eMoveDirection.LEFT:
            moveX--;
            break;

        case eMoveDirection.RIGHT:
            moveX++;
            break;

        case eMoveDirection.UP:
            moveY--;
            break;

        case eMoveDirection.DOWN:
            moveY++;
            break;
        }

        sPosition newPosition;

        newPosition.x = moveX;
        newPosition.y = moveY;

        return(newPosition);
    }
コード例 #6
0
    protected void SettingMovePossibleTiles()
    {
        TileMap map = GameManager.Instance.GetMap();

        map.ResetVisit(_character);

        TileCell startTileCell = map.GetTileCell(_character.GetTileX(), _character.GetTileY());

        startTileCell.SetPrevTileCell(_character, null);
        sTileHeuristicInfo startCmd;

        startCmd.tileCell  = startTileCell;
        startCmd.heuristic = 0.0f;
        _tileInfoQueue.Add(startCmd);

        while (0 != _tileInfoQueue.Count)
        {
            sTileHeuristicInfo command = _tileInfoQueue[0];
            _tileInfoQueue.RemoveAt(0);
            //가져온 커맨드의 현재 타일셀 방문 표시
            if (false == command.tileCell.IsVisited(_character))
            {
                if (_character.GetMoveRange() == command.tileCell.GetDistanceFromStart(_character))
                {
                    _tileInfoQueue.Clear();
                    return;
                }
                command.tileCell.SetVisit(_character, true);
                _movePossibleTiles.Add(command.tileCell);

                //4방향 next타일들 검사
                for (int direction = (int)eMoveDirection.LEFT; direction < (int)eMoveDirection.DOWN + 1; direction++)
                {
                    sPosition curPosition;
                    curPosition.x = command.tileCell.GetTileX();
                    curPosition.y = command.tileCell.GetTileY();
                    sPosition nextPosition = _character.GetPositionByDirection(curPosition, direction);

                    TileCell nextTileCell = map.GetTileCell(nextPosition.x, nextPosition.y);
                    // nextTileCell 방문 안했고, 움직일수 있는 타일일때
                    if (null != nextTileCell && true == nextTileCell.IsPathfindable() && false == nextTileCell.IsVisited(_character))
                    {
                        float distanceFromStart = command.tileCell.GetDistanceFromStart(_character) + nextTileCell.GetDistanceFromWeight();
                        float heuristic         = distanceFromStart;

                        if (null == nextTileCell.GetPrevTileCell(_character) || distanceFromStart < nextTileCell.GetDistanceFromStart(_character))
                        {
                            nextTileCell.SetDistanceFromStart(_character, distanceFromStart);
                            nextTileCell.SetPrevTileCell(_character, command.tileCell);

                            sTileHeuristicInfo nextCommand;
                            nextCommand.tileCell  = nextTileCell;
                            nextCommand.heuristic = heuristic;
                            PushSortmoveRangeQueue(nextCommand);
                        }
                    }
                }
            }
        }
    }
コード例 #7
0
ファイル: AStar.cs プロジェクト: EnockNitti/CivOne
    /*  ******************************************************************************************************** */
    /// Return an estimate of cost of moving from Positition to goal.
    /// Return 0 when Positition is goal.
    /// This is an estimate of sum of all costs along the path between Positition and the goal.
    protected float Heuristic(sPosition Positition)
    {
        // maybe we should't use the same value for land unit and air/sea units
        //        float fGoalF = 3.0f;
        float fGoalF = 1.0f;

        return(Distance(Positition, _GoalPosition) * fGoalF);
    }
コード例 #8
0
ファイル: base.cs プロジェクト: bacome/imapclient
 private void ZAdvance(ref sPosition pPosition)
 {
     pPosition.Byte = pPosition.Byte + 1;
     if (pPosition.Byte < pPosition.BytesLine.Count)
     {
         return;
     }
     pPosition.Byte = 0;
     ZAdvancePart(ref pPosition);
 }
コード例 #9
0
        private void LoadVertices()
        {
            var positions = new sPosition[_mesh.GetVertexCount()];

            _mesh.GetVertices(out positions);

            NativeVertices = positions;
            Vertices       = positions
                             .Select(p => new Vertex(p))
                             .ToList();
        }
コード例 #10
0
ファイル: base.cs プロジェクト: bacome/imapclient
        private bool ZGetHexEncodedByte(out byte rByte)
        {
            var lBookmark = Position;

            if (ZGetHexEncodedNibble(out int lMSN) && ZGetHexEncodedNibble(out int lLSN))
            {
                rByte = (byte)(lMSN << 4 | lLSN);
                return(true);
            }

            Position = lBookmark;
            rByte    = 0;
            return(false);
        }
コード例 #11
0
ファイル: TileMap.cs プロジェクト: UJHa/-Unity-2DTileMapGame
    sPosition GetDirectionTilePosition(eMoveDirection direction, sPosition position)
    {
        switch (direction)
        {
        case eMoveDirection.LEFT: position.x--; break;

        case eMoveDirection.RIGHT: position.x++; break;

        case eMoveDirection.UP: position.y--; break;

        case eMoveDirection.DOWN: position.y++; break;
        }
        return(position);
    }
コード例 #12
0
ファイル: AStar.cs プロジェクト: fire-eggs/CivOne
    /*  ******************************************************************************************************** */
    private Node NewNode(sPosition position, sPosition previousPosition, float g, float h)
    {
        while (m_nodesCacheIndex >= m_nodesCache.Count)
        {
            m_nodesCache.Add(new Node());
        }
        Node node = m_nodesCache[m_nodesCacheIndex++];

        node.Position         = position;
        node.PreviousPosition = previousPosition;
        node.F        = g + h;
        node.G        = g;
        node.H        = h;
        node.IsClosed = false;
        return(node);
    }
コード例 #13
0
ファイル: base.cs プロジェクト: bacome/imapclient
        public bool GetQuoted(out cByteList rBytes)
        {
            var lBookmark = Position;

            if (!SkipByte(cASCII.DQUOTE))
            {
                rBytes = null; return(false);
            }

            rBytes = new cByteList();
            bool lInQuote = false;

            while (true)
            {
                byte lByte = Position.BytesLine[Position.Byte];
                ZAdvance(ref Position);

                if (lInQuote)
                {
                    rBytes.Add(lByte);
                    lInQuote = false;
                }
                else
                {
                    if (lByte == cASCII.DQUOTE)
                    {
                        return(true);
                    }

                    if (lByte == cASCII.BACKSL)
                    {
                        lInQuote = true;
                    }
                    else
                    {
                        rBytes.Add(lByte);
                    }
                }

                if (Position.AtEnd || Position.BytesLine.Literal)
                {
                    Position = lBookmark;
                    rBytes   = null;
                    return(false);
                }
            }
        }
コード例 #14
0
ファイル: base.cs プロジェクト: bacome/imapclient
        public bool GetDate(out DateTime rDate)
        {
            var lBookmark = Position;

            if (SkipByte(cASCII.DQUOTE))
            {
                if (!ZGetDate(out rDate))
                {
                    Position = lBookmark; return(false);
                }
                if (!SkipByte(cASCII.DQUOTE))
                {
                    Position = lBookmark; return(false);
                }
                return(true);
            }

            return(ZGetDate(out rDate));
        }
コード例 #15
0
    sPosition GetPositionByDirection(sPosition curPosition, eMoveDirection direction)
    {
        sPosition tilePosition = curPosition;

        switch (direction)
        {
        case eMoveDirection.LEFT:
            tilePosition.x--;
            break;

        case eMoveDirection.RIGHT:
            tilePosition.x++;
            break;

        case eMoveDirection.UP:
            tilePosition.y--;
            break;

        case eMoveDirection.DOWN:
            tilePosition.y++;
            break;
        }

        if (tilePosition.x < 0)
        {
            tilePosition.x = 0;
        }
        if (tilePosition.x > GameManager.Instance.GetMap().GetWidth() - 1)
        {
            curPosition.x = GameManager.Instance.GetMap().GetWidth() - 1;
        }
        if (tilePosition.y < 0)
        {
            tilePosition.y = 0;
        }
        if (tilePosition.y > GameManager.Instance.GetMap().GetHeight() - 1)
        {
            curPosition.y = GameManager.Instance.GetMap().GetHeight() - 1;
        }

        return(tilePosition);
    }
コード例 #16
0
ファイル: base.cs プロジェクト: bacome/imapclient
        private void ZAdvancePart(ref sPosition pPosition)
        {
            while (true)
            {
                pPosition.LineNumber = pPosition.LineNumber + 1;

                if (pPosition.LineNumber == mLines.Count)
                {
                    pPosition.AtEnd = true;
                    return;
                }

                pPosition.BytesLine = mLines[pPosition.LineNumber];

                if (pPosition.BytesLine.Count > 0 || pPosition.BytesLine.Literal)
                {
                    return;
                }
            }
        }
コード例 #17
0
 //position
 public eMoveDirection GetDirection(sPosition curPosition, sPosition toPosition)
 {
     if (toPosition.x < curPosition.x)
     {
         return(eMoveDirection.LEFT);
     }
     if (toPosition.x > curPosition.x)
     {
         return(eMoveDirection.RIGHT);
     }
     if (toPosition.y < curPosition.y)
     {
         return(eMoveDirection.UP);
     }
     if (toPosition.y > curPosition.y)
     {
         return(eMoveDirection.DOWN);
     }
     return(eMoveDirection.DOWN);
 }
コード例 #18
0
    public void Send_PositionMSG(int player, float px, float py, float pz, float dx, float dy, float dz, float sp, bool fm, bool bm, bool run, bool atk)//위치, 움직임관련 메시지
    {
        sPosition spo = new sPosition();

        spo.flag   = (char)eMSG.em_USER_POSITION;
        spo.player = player;
        spo.px     = px;
        spo.py     = py;
        spo.pz     = pz;
        spo.dx     = dx;
        spo.dy     = dy;
        spo.dz     = dz;
        spo.sp     = sp;
        spo.fm     = fm;
        spo.bm     = bm;
        spo.run    = run;
        spo.atk    = atk;
        byte[] data = StructureToByte(spo);
        Send(C_socket, data);
    }
コード例 #19
0
    public sPosition GetPositionByDirection(sPosition curPosition, int direction)
    {
        sPosition      position      = curPosition;
        eMoveDirection moveDirection = (eMoveDirection)direction;

        switch (moveDirection)
        {
        case eMoveDirection.LEFT:
            position.x--;
            if (position.x < 0)
            {
                position.x++;
            }
            break;

        case eMoveDirection.RIGHT:
            position.x++;
            if (position.x == GameManager.Instance.GetMap().GetWidth())
            {
                position.x--;
            }
            break;

        case eMoveDirection.UP:
            position.y--;
            if (position.y < 0)
            {
                position.y++;
            }
            break;

        case eMoveDirection.DOWN:
            position.y++;
            if (position.y == GameManager.Instance.GetMap().GetHeight())
            {
                position.y--;
            }
            break;
        }
        return(position);
    }
コード例 #20
0
    eMoveDirection GetDirection(sPosition curPosition, sPosition nextPosition)
    {
        if (curPosition.x < nextPosition.x)
        {
            return(eMoveDirection.RIGHT);
        }
        if (curPosition.x > nextPosition.x)
        {
            return(eMoveDirection.LEFT);
        }
        if (curPosition.y < nextPosition.y)
        {
            return(eMoveDirection.DOWN);
        }
        if (curPosition.y > nextPosition.y)
        {
            return(eMoveDirection.UP);
        }

        return(eMoveDirection.DOWN);
    }
コード例 #21
0
    public static eMoveDirection GetDirection(sPosition curPosition, sPosition nextPosition)
    {
        if (nextPosition.x > curPosition.x)
        {
            return(eMoveDirection.RIGHT);
        }
        else if (curPosition.x > nextPosition.x)
        {
            return(eMoveDirection.LEFT);
        }
        else if (curPosition.y > nextPosition.y)
        {
            return(eMoveDirection.UP);
        }
        else if (nextPosition.y > curPosition.y)
        {
            return(eMoveDirection.DOWN);
        }

        return(eMoveDirection.UP);
    }
コード例 #22
0
ファイル: base.cs プロジェクト: bacome/imapclient
        public bool SkipBytes(IList <byte> pBytes, bool pCaseSensitive = false)
        {
            if (Position.AtEnd)
            {
                return(false);
            }
            if (Position.BytesLine.Literal)
            {
                return(false);
            }

            var lBookmark = Position;

            int lByte = 0;

            while (true)
            {
                if (!cASCII.Compare(Position.BytesLine[Position.Byte], pBytes[lByte], pCaseSensitive))
                {
                    Position = lBookmark;
                    return(false);
                }

                ZAdvance(ref Position);
                lByte = lByte + 1;

                if (lByte == pBytes.Count)
                {
                    return(true);
                }

                if (Position.AtEnd || Position.BytesLine.Literal)
                {
                    Position = lBookmark;
                    return(false);
                }
            }
        }
コード例 #23
0
    bool IsConnectedCellOnDirection(int tileX, int tileY, eMoveDirection direction)
    {
        //진행방향으로만 붙어있는 타일 체크
        sPosition position;

        position.x = tileX;
        position.y = tileY;

        sPosition nextPosition = GlobalUtility.GetPositionByDirection(position, (eMoveDirection)direction);

        if (0 <= nextPosition.x && nextPosition.x < _width && 0 <= nextPosition.y && nextPosition.y < _height)
        {
            if (false == GetTileCell(nextPosition.x, nextPosition.y).IsPathfindable())
            {
                return(true);
            }
        }
        else
        {
            return(true);    //맵 밖
        }
        return(false);
    }
コード例 #24
0
ファイル: TileMap.cs プロジェクト: UJHa/-Unity-2DTileMapGame
 private bool IsConnectedCell(sPosition position)
 {
     //주변에 하나라도 붙은 블럭 있음녀 연결된 블럭
     for (int direction = (int)eMoveDirection.LEFT; direction < (int)eMoveDirection.DOWN + 1; direction++)
     {
         sPosition curPosition;
         curPosition.x = position.x;
         curPosition.y = position.y;
         sPosition searchPosition = GetDirectionTilePosition((eMoveDirection)direction, curPosition);
         if (0 <= searchPosition.x && searchPosition.x < _width && 0 <= searchPosition.y && searchPosition.y < _height)
         {
             if (false == GetTileCell(searchPosition.x, searchPosition.y).IsPathfindable())
             {
                 return(true);
             }
         }
         else
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #25
0
ファイル: base.cs プロジェクト: bacome/imapclient
        public bool GetNumber(out cByteList rBytes, out uint rNumber, int pMinLength = 1, int pMaxLength = int.MaxValue)
        {
            var lBookmark = Position;

            rNumber = 0;

            if (!GetToken(cCharset.Digit, null, null, out rBytes, pMinLength, pMaxLength))
            {
                return(false);
            }

            checked
            {
                try { foreach (byte lByte in rBytes)
                      {
                          rNumber = rNumber * 10 + lByte - cASCII.ZERO;
                      }
                }
                catch { Position = lBookmark; return(false); }
            }

            return(true);
        }
コード例 #26
0
ファイル: base.cs プロジェクト: bacome/imapclient
        public bool GetNumber(out ulong rNumber)
        {
            var lBookmark = Position;

            rNumber = 0;

            if (!GetToken(cCharset.Digit, null, null, out var lBytes))
            {
                return(false);
            }

            checked
            {
                try { foreach (byte lByte in lBytes)
                      {
                          rNumber = rNumber * 10 + lByte - cASCII.ZERO;
                      }
                }
                catch { Position = lBookmark; return(false); }
            }

            return(true);
        }
コード例 #27
0
    sPosition GetPositionByDirection(sPosition curPosition, eMoveDirection direction)
    {
        sPosition newPosition = curPosition;

        switch (direction)
        {
        case eMoveDirection.LEFT:
            newPosition.x--;
            break;

        case eMoveDirection.RIGHT:
            newPosition.x++;
            break;

        case eMoveDirection.UP:
            newPosition.y--;
            break;

        case eMoveDirection.DOWN:
            newPosition.y++;
            break;
        }
        return(newPosition);
    }
コード例 #28
0
ファイル: base.cs プロジェクト: bacome/imapclient
        private cByteList ZGetFromAsBytes(sPosition pFrom)
        {
            cByteList lBytes = new cByteList();

            while (pFrom.LineNumber < Position.LineNumber)
            {
                for (int i = pFrom.Byte; i < pFrom.BytesLine.Count; i++)
                {
                    lBytes.Add(pFrom.BytesLine[i]);
                }
                pFrom.Byte = 0;
                ZAdvancePart(ref pFrom);
            }

            if (pFrom.LineNumber == Position.LineNumber)
            {
                for (int i = pFrom.Byte; i < Position.Byte; i++)
                {
                    lBytes.Add(pFrom.BytesLine[i]);
                }
            }

            return(lBytes);
        }
コード例 #29
0
ファイル: base.cs プロジェクト: bacome/imapclient
        private bool ZGetDate(out DateTime rDate, int pMinDayLength = 1, int pMaxDayLength = 2)
        {
            rDate = new DateTime();

            var lBookmark = Position;

            if (!GetNumber(out _, out uint lDay, pMinDayLength, pMaxDayLength))
            {
                return(false);
            }
            if (lDay < 1 || lDay > 31)
            {
                Position = lBookmark; return(false);
            }
            if (!SkipByte(cASCII.HYPEN))
            {
                Position = lBookmark; return(false);
            }
            if (!ZGetMonth(out var lMonth))
            {
                Position = lBookmark; return(false);
            }
            if (!SkipByte(cASCII.HYPEN))
            {
                Position = lBookmark; return(false);
            }
            if (!GetNumber(out _, out uint lYear, 4, 4))
            {
                Position = lBookmark; return(false);
            }

            try { rDate = new DateTime((int)lYear, lMonth, (int)lDay, 0, 0, 0, DateTimeKind.Utc); }
            catch { Position = lBookmark; return(false); }

            return(true);
        }
コード例 #30
0
    public void FindPath(eFindMode mode, eFindMethod method)
    {
        bool isViewRange = (eFindMode.VIEW_MOVERANGE == mode || eFindMode.VIEW_ATTACKRANGE == mode);

        while (0 != _pathfindingQueue.Count)
        {
            sPathCommand command = _pathfindingQueue[0];
            _pathfindingQueue.RemoveAt(0);

            if (false == command.tileCell.IsVisit())
            {
                command.tileCell.Visit();

                //FIND TARGET
                if (eFindMode.FIND_PATH == mode)
                {
                    if ((_targetTileCell.GetTileX() == command.tileCell.GetTileX()) &&
                        (_targetTileCell.GetTileY() == command.tileCell.GetTileY()))
                    {
                        _reverseTileCell = _targetTileCell;
                        return;
                    }
                }


                for (eMoveDirection direction = 0; direction <= eMoveDirection.DOWN; direction++)
                {
                    sPosition curPosition;
                    curPosition.x = command.tileCell.GetTileX();
                    curPosition.y = command.tileCell.GetTileY();
                    sPosition nextPosition = GlobalUtility.GetPositionByDirection(curPosition, direction);

                    TileMap  map          = GameManager.Instance.GetMap();
                    TileCell nextTileCell = map.GetTileCell(nextPosition.x, nextPosition.y);

                    if (CheckPrecondition(mode, nextTileCell, _targetTileCell))
                    {
                        float distanceFromStart = command.tileCell.GetDistanceFromStart()
                                                  + command.tileCell.GetDistanceWeight();
                        float heuristic = CalcHeuristic(method, distanceFromStart,
                                                        command.tileCell, nextTileCell, _targetTileCell);

                        if (isViewRange && (_range < distanceFromStart))
                        {
                            return;
                        }

                        if (null == nextTileCell.GetPrevTileCell())
                        {
                            nextTileCell.SetDistanceFromStart(distanceFromStart);
                            nextTileCell.SetPrevTileCell(command.tileCell);

                            sPathCommand newCommand;
                            newCommand.tileCell  = nextTileCell;
                            newCommand.heuristic = heuristic;
                            PushCommand(newCommand);

                            //검색범위를 그려준다.
                            if (isViewRange)
                            {
                                DrawSearchTile(nextTileCell);
                            }
                        }
                    }
                }
            }
        }
    }