示例#1
0
    public void Init(Position pos, int width, int height)
    {
        SetPos(pos);
        Width = width;
        Height = height;

        //Min = new Position(_Pos.x - Width / 2, _Pos.y - Height / 2);
        //Max = new Position(Min.x + width, Min.y + height);

        _TileStateArr = new TileState[width, height];

        for (int x = 0; x < width; ++x)
        {
            for (int y = 0; y < height; ++y)
            {
                if(x == 0 || y == 0 || x == width - 1 || y == height - 1)
                {
                    _TileStateArr[x, y] = TileState.WALL;
                }
                else
                {
                    _TileStateArr[x, y] = TileState.GROUND;
                }
            }
        }

        CachedBoxCollider.size = new Vector2(width + 2, height + 2);
    }
示例#2
0
 public override void CalcFactor(TileState[,] board, ref Move move)
 {
     if (Board.IsMoveBlitz(board, move))
     {
         move.score += Score;
     }
 }
示例#3
0
        public SpaceInstance(uint InstanceId, SpaceInfo Info, SpaceModel Model)
        {
            this.uint_0                 = InstanceId;
            this.spaceInfo_0            = Info;
            this.concurrentDictionary_0 = new ConcurrentDictionary <uint, SpaceActor>();
            this.spaceModel_0           = Model;
            this.string_0               = string.Empty;
            this.list_2                 = new List <uint> {
                1, 2, 3, 4, 5, 6, 6, 8, 9, 10, 11, 12, 13, 14, 15, 0x10,
                0x11, 0x12, 0x13, 20, 0x15
            };
            this.object_2    = new object();
            this.tileState_0 = new TileState[this.spaceModel_0.Heightmap.SizeX, this.spaceModel_0.Heightmap.SizeY];
            this.list_0      = new List <SpaceActor> [this.spaceModel_0.Heightmap.SizeX, this.spaceModel_0.Heightmap.SizeY];
            SqlDatabaseClient mySqlClient = SqlDatabaseManager.GetClient();

            try
            {
                this.InitializeContestWorker(mySqlClient);
            }
            catch (Exception exception)
            {
                Output.WriteLine("[ContestMgr] An exception has been trhown while trying to start the worker. The thread was already destroyed. Stack trace:\r\n" + exception.ToString(), OutputLevel.CriticalError);
            }
            finally
            {
                if (mySqlClient != null)
                {
                    mySqlClient.Dispose();
                }
            }
            this.RegenerateRelativeHeightmap(false);
        }
示例#4
0
    public Checkerboard()
    {
        currentPlayerColor = TileState.White;

        size  = new Vector2Int(Size, Size);
        tiles = new TileState[size.x, size.y];
    }
示例#5
0
        internal void Setup()
        {
            Lines = new List <string>();

            Heightmap = Heightmap.Replace(Convert.ToChar(10).ToString(), "");
            string[] splitRawmap = Heightmap.Split("\r\n".ToCharArray());

            foreach (string s in splitRawmap)
            {
                Lines.Add(s);
            }

            this.MapSizeX = Lines[0].Length;
            this.MapSizeY = Lines.Count;

            this.mTileState   = new TileState[MapSizeX, MapSizeY];
            this.mFloorHeight = new int[MapSizeX, MapSizeY];

            for (int y = 0; y < MapSizeY; y++)
            {
                for (int x = 0; x < MapSizeX; x++)
                {
                    string value = Lines[y][x].ToString().ToLower();

                    mTileState[x, y]   = (value == "x" ? TileState.Blocked : TileState.Open);
                    mFloorHeight[x, y] = (value == "x" ? 0 : int.Parse(value));
                    RoomUnit           = new bool[x, y];
                    LogicalHeightMap   = new sbyte[x, y];
                }
            }
        }
示例#6
0
        private void DumpMapToScreen(TileState[,] map)
        {
            for (var i = 0; i < map.GetLength(1); i++)
            {
                var sb = new StringBuilder();

                for (var j = 0; j < map.GetLength(0); j++)
                {
                    switch (map[j, i])
                    {
                    case TileState.Sand:
                        sb.Append(".");
                        break;

                    case TileState.Clay:
                        sb.Append("#");
                        break;

                    case TileState.FlowingWater:
                        sb.Append("|");
                        break;

                    case TileState.StillWater:
                        sb.Append("~");
                        break;
                    }
                }

                Console.WriteLine(sb.ToString());
            }
        }
示例#7
0
        private void Drop(TileState[,] map, Point startPoint, int maxY)
        {
            var currentPoint = startPoint;

            while (true)
            {
                map[currentPoint.X, currentPoint.Y] = TileState.FlowingWater;
                currentPoint = new Point(currentPoint.X, currentPoint.Y + 1);

                if (currentPoint.Y > maxY)
                {
                    return;
                }

                if (map[currentPoint.X, currentPoint.Y] == TileState.FlowingWater)
                {
                    return;
                }

                if (map[currentPoint.X, currentPoint.Y] == TileState.Clay || map[currentPoint.X, currentPoint.Y] == TileState.StillWater)
                {
                    //Console.WriteLine("About to spread");
                    //DumpMapToScreen(map);
                    Spread(map, new Point(currentPoint.X, currentPoint.Y - 1), maxY);
                    return;
                }
            }
        }
示例#8
0
    public static List <int[]> FindBlockedCaptures(TileState[,] boardState, Move move)
    {
        List <int[]> blockedCaptures = new List <int[]>();

        // Check each adjacent tile for the opponent's token
        foreach (Vector2 dir in directions)
        {
            int ax = (int)(move.X + dir.x);
            int ay = (int)(move.Y + dir.y);
            // Bounds check
            if (IsInBounds(boardState, ax, ay))
            {
                //Debug.Log("Adj Tile: (" + adjTile.X + "," + adjTile.Y + ")");
                if (boardState[ax, ay] == PlayerToState(move.player))
                {
                    // Check the next tile over
                    int a2x = ax + (int)dir.x;
                    int a2y = ay + (int)dir.y;
                    if (IsInBounds(boardState, a2x, a2y))
                    {
                        // If the next tile over is owned by this player, capture the tile between them
                        if (boardState[a2x, a2y] == PlayerToState(move.opponent))
                        {
                            blockedCaptures.Add(new int[2] {
                                ax, ay
                            });
                        }
                    }
                }
            }
        }

        return(blockedCaptures);
    }
示例#9
0
 public override void CalcFactor(TileState[,] board, ref Move move)
 {
     TileState[,] newBoard = Board.MakeMove(board, move);
     if (Board.CanPlayerWin(newBoard, move.opponent))
     {
         move.score += Score;
     }
 }
示例#10
0
 public override void SetSpaceInstance(SpaceInstance Space, uint ActorId)
 {
     this.spaceInstance_0 = Space;
     this.tileState_0     = Space.Model.Heightmap.TileStates;
     this.uint_0          = ActorId;
     this.list_0          = new List <Vector3>();
     this.vector3_0       = null;
 }
示例#11
0
        public levelEditor()
        {
            InitializeComponent();

            //set toolstate to wall initially
            toolState = ToolState.Wall;
            tileState = new TileState[26, 26];
        }
示例#12
0
    IEnumerator InitStates()
    {
        states  = new TileState[Width, Height];
        visited = new bool[Width, Height];
        for (int x = 0; x < Width; x += 2)
        {
            for (int y = 0; y < Height; y += 2)
            {
                states[x, y] = TileState.Path;
            }
        }
        stack = new Stack <Pair>();
        stack.Push(new Pair(0, 0));
        visited[0, 0] = true;
        InitGrid();
        yield return(new WaitForSeconds(1));

        do
        {
            var spot      = stack.Peek();
            var possibles = new List <Pair>();
            for (int x = spot.x - 2; x <= spot.x + 2; x += 2)
            {
                for (int y = spot.y - 2; y <= spot.y + 2; y += 2)
                {
                    if (x < 0 || x >= Width || y < 0 || y >= Height)
                    {
                        continue;
                    }
                    if (visited[x, y])
                    {
                        continue;
                    }
                    if ((x == spot.x) ^ (y == spot.y))
                    {
                        possibles.Add(new Pair(x, y));
                    }
                }
            }
            if (possibles.Count == 0)
            {
                stack.Pop();
            }
            else
            {
                var chosen = possibles[Random.Range(0, possibles.Count)];
                stack.Push(chosen);
                var pathway = new Pair((spot.x + chosen.x) / 2, (spot.y + chosen.y) / 2);
                states[pathway.x, pathway.y] = TileState.Path;
                visited[chosen.x, chosen.y]  = true;
                DrawMaze();
                yield return(new WaitForSeconds(0.02f));
            }
        } while (stack.Count > 0);
        InitFruits();
        PlayerManager.instance.transform.position = grid[0, 0].transform.position;
        IsInit = true;
    }
示例#13
0
    public static bool IsTilePlayable(TileState[,] board, IndexPair index, TileState turnTo, int directionZ, int directionX, int depth)
    {
        if (index.z + (directionZ * depth) >= board.GetLength(0))
        {
            return(false);
        }
        if (index.x + (directionX * depth) >= board.GetLength(1))
        {
            return(false);
        }
        if (index.z + (directionZ * depth) < 0)
        {
            return(false);
        }
        if (index.x + (directionX * depth) < 0)
        {
            return(false);
        }
        switch (turnTo)
        {
        case TileState.Black:
            if (board[index.z + (directionZ * depth), index.x + (directionX * depth)] == TileState.Black && depth > 1)
            {
                return(true);
            }
            else if (board[index.z + (directionZ * depth), index.x + (directionX * depth)] == TileState.White)
            {
                return(IsTilePlayable(board, index, turnTo, directionZ, directionX, ++depth));
            }
            else
            {
                return(false);
            }

        case TileState.White:
            if (board[index.z + (directionZ * depth), index.x + (directionX * depth)] == TileState.White && depth > 1)
            {
                return(true);
            }
            else if (board[index.z + (directionZ * depth), index.x + (directionX * depth)] == TileState.Black)
            {
                return(IsTilePlayable(board, index, turnTo, directionZ, directionX, ++depth));
            }
            else
            {
                return(false);
            }

        case TileState.Empty:
            Debug.LogError("Empty tile should not be tested as playable.");
            break;

        default:
            break;
        }
        return(false);
    }
示例#14
0
 public override void CalcFactor(TileState[,] board, ref Move move)
 {
     if (Board.IsCornerTile(board, move.X, move.Y))
     {
         //Debug.Log("Adding " + GetType().ToString() + " to move: " + move);
         move.score += Score;
         //Debug.Log("Move(" + move.X + "," + move.Y + ")" + "score: " + move.score);
     }
 }
示例#15
0
 private void RenderMap(Rectangle[,] tiles, TileState[,] map)
 {
     for (int x = 0; x < dimension; x++)
     {
         for (int y = 0; y < dimension; y++)
         {
             RenderTile(tiles[x, y], map[x, y]);
         }
     }
 }
示例#16
0
        public Pathfinder(int RoomId, TileState[,] Tiles, double[,] HeightMap, RoomModel Model)
        {
            this.RoomId = RoomId;
            this.Tiles = Tiles;
            this.HeightMap = HeightMap;
            this.Model = Model;

            this.Lock = new ReaderWriterLock();
            this.FoundPath = false;
        }
示例#17
0
    public override void CalcFactor(TileState[,] board, ref Move move)
    {
        Move oppMove = new Move(move.X, move.Y, move.opponent);

        if (Board.IsVulnerableMove(board, oppMove))
        {
            //Debug.Log("Adding " + GetType().ToString() + " to move: " + move);
            move.score += Score;
            //Debug.Log("Move(" + move.X + "," + move.Y + ")" + "score: " + move.score);
        }
    }
示例#18
0
 public static bool CheckFull(TileState[,] boardState)
 {
     foreach (TileState t in boardState)
     {
         if (t == TileState.EMPTY)
         {
             return(false);
         }
     }
     return(true);
 }
示例#19
0
    public override void CalcFactor(TileState[,] board, ref Move move)
    {
        List <int[]> captures = Board.FindCaptures(board, move);

        for (int c = 0; c < captures.Count; c++)
        {
            //Debug.Log("Adding " + GetType().ToString() + " to move: " + move);
            move.score += Score;
            //Debug.Log("Move(" + move.X + "," + move.Y + ")" + "score: " + move.score);
        }
    }
示例#20
0
 //vytvorit si mapu
 private void CreateMap()
 {
     map = new TileState[dimension, dimension];
     for (int x = 0; x < dimension; x++)
     {
         for (int y = 0; y < dimension; y++)
         {
             map[x, y] = TileState.Empty;
         }
     }
 }
示例#21
0
        //vymyslet, kam strilet
        public Coordinates RandomTarget(TileState[,] opponentMap)
        {
            Coordinates target = new Coordinates();

            do
            {
                target.X = rnd.Next(dimension);
                target.Y = rnd.Next(dimension);
            }while (opponentMap[target.X, target.Y] != TileState.Empty);

            return(target);
        }
示例#22
0
    public override void CalcFactor(TileState[,] board, ref Move move)
    {
        TileState[,] newBoard = Board.MakeMove(board, move);
        List <int[]> winningTiles;

        if (move.player == Board.GetWinner(newBoard, out winningTiles))
        {
            //Debug.Log("Adding " + GetType().ToString() + " to move: " + move);
            move.score += Score;
            //Debug.Log("Move(" + move.X + "," + move.Y + ")" + "score: " + move.score);
        }
    }
示例#23
0
 void SpawnBoard(Vector3 origin, int width, int height)
 {
     board           = new TileState[width, height];
     tileGameObjects = new GameObject[width, height];
     for (int i = 0; i < height; i++)
     {
         for (int j = 0; j < width; j++)
         {
             SpawnTile(i, j);
         }
     }
 }
示例#24
0
 //Returns a copy of a board
 public static TileState[,] CopyBoard(TileState[,] board)
 {
     TileState[,] result = new TileState[board.GetLength(0), board.GetLength(1)];
     for (int i = 0; i < board.GetLength(1); i++)
     {
         for (int j = 0; j < board.GetLength(0); j++)
         {
             result[j, i] = board[j, i];
         }
     }
     return(result);
 }
示例#25
0
 public static TileState[,] CloneBoardState(TileState[,] boardState)
 {
     TileState[,] clonedBoard = new TileState[boardState.GetLength(0), boardState.GetLength(1)];
     for (int i = 0; i < boardState.GetLength(0); i++)
     {
         for (int j = 0; j < boardState.GetLength(1); j++)
         {
             clonedBoard[i, j] = boardState[i, j];
         }
     }
     return(clonedBoard);
 }
示例#26
0
 private void Awake()
 {
     dBoard = new TileState[boardSize, boardSize];
     for (int i = 0; i < boardSize; i++)
     {
         for (int j = 0; j < boardSize; j++)
         {
             dBoard[i, j] = TileState.EMPTY;
             //Debug.Log(dBoard[i, j].ToString());
         }
     }
 }
示例#27
0
 private void initBoardRectangle(Vector2Int botLeft, Vector2Int topRight)
 {
     boardDimensions = new Vector2Int(topRight.x, topRight.y);
     boardState      = new TileState[boardDimensions.x, boardDimensions.y];
     for (int x = botLeft.x; x < topRight.x; x++)
     {
         for (int y = botLeft.y; y < topRight.y; y++)
         {
             boardState[x, y] = new TileState(tileManager.getRandomTile(), x, y);
         }
     }
 }
示例#28
0
    public static bool CompareTileState(TileState[,] board, int x, int y, TileState compareTarget)
    {
        bool match = false;

        if (IsInBounds(board, x, y))
        {
            if (board[x, y] == compareTarget)
            {
                match = true;
            }
        }
        return(match);
    }
示例#29
0
 //Returns a new board with the move played
 public static TileState[,] SimulateTurn(TileState[,] board, IndexPair index, TileState turnTo)
 {
     TileState[,] result = CopyBoard(board);
     SimulateLane(result, index, turnTo, 0, 1, 1);
     SimulateLane(result, index, turnTo, 1, 1, 1);
     SimulateLane(result, index, turnTo, 1, 0, 1);
     SimulateLane(result, index, turnTo, 1, -1, 1);
     SimulateLane(result, index, turnTo, 0, -1, 1);
     SimulateLane(result, index, turnTo, -1, -1, 1);
     SimulateLane(result, index, turnTo, -1, 0, 1);
     SimulateLane(result, index, turnTo, -1, 1, 1);
     return(result);
 }
示例#30
0
 private void initSquareBoardRandomly(int size)
 {
     Debug.Log("Init square board randomly jack " + size);
     boardDimensions = new Vector2Int(size, size);
     boardState      = new TileState[boardDimensions.x, boardDimensions.y];
     for (int x = 0; x < boardDimensions.x; x++)
     {
         for (int y = 0; y < boardDimensions.y; y++)
         {
             boardState[x, y] = new TileState(tileManager.getRandomTile(), x, y);
         }
     }
 }
示例#31
0
 private void initLineBoardRandomly(int width, int height)
 {
     Debug.Log("Init line board");
     boardDimensions = new Vector2Int(width, height);
     boardState      = new TileState[boardDimensions.x, boardDimensions.y];
     for (int x = 0; x < boardDimensions.x; x++)
     {
         for (int y = 0; y < boardDimensions.y; y++)
         {
             boardState[x, y] = new TileState(tileManager.getRandomTile(), x, y);
         }
     }
 }
            public LogReader(string log, int player, int width, int height)
            {
                Debug.Assert(File.Exists(log));

                this.width = width;
                this.height = height;
                this.gridTopBottom = "+" + new string('-', width) + "+";

                reader = new StreamReader(log);
                playerTile = (player == 0) ? TileState.Player1 : TileState.Player2;

                // Read in the empty board.
                lastState = GetNextState();
            }
示例#33
0
    private void Generate()
    {
        m_tileStates = new TileState[mapSize.x, mapSize.y];
        for (int x = 0; x < mapSize.x; x++)
        {
            for (int y = 0; y < mapSize.y; y++)
            {
                m_tileStates[x, y] = new TileState(x, y);
            }
        }

        m_checkingTileStates.Clear();
        m_checkingTileStates.Add(m_tileStates[Random.Range(0, mapSize.x), Random.Range(0, mapSize.y)]);

        int              random;
        TileState        tileState;
        List <TileState> unobservedTileStates;

        while (m_checkingTileStates.Count != 0)
        {
            tileState = m_checkingTileStates[0];
            GetValidTileType(tileState);

            if (tileState.observed)
            {
                m_checkingTileStates.Remove(tileState);

                unobservedTileStates = GetUnobservedTileStates(tileState);
                if (unobservedTileStates.Count > 0)
                {
                    for (int i = 0; i < unobservedTileStates.Count; i++)
                    {
                        if (m_checkingTileStates.Contains(unobservedTileStates[i]))
                        {
                            continue;
                        }

                        m_checkingTileStates.Add(unobservedTileStates[i]);
                    }
                }
            }
            else
            {
                Debug.LogErrorFormat("Break at x = {0}, y = {1}", tileState.x, tileState.y);
                break;
            }
        }

        GenerateTiles();
    }
示例#34
0
        public Pathfinder(Session Session)
        {
            AvaliablePoints = new Point[]
                {
                new Point(0, -1),
                new Point(0, 1),
                new Point(1, 0),
                new Point(-1, 0),
                new Point(1, -1),
                new Point(-1, 1),
                new Point(1, 1),
                new Point(-1, -1)
                };

            this.Session = Session;

            MapSizeX = Session.Room.Model.MapSizeX;
            MapSizeY = Session.Room.Model.MapSizeY;
            Squares = Session.Room.Model.mTileState;
        }
示例#35
0
        public Pathfinder(Heightmap Map, HabboRoomObject Session)
        {
            AvaliablePoints = new Point[]
                {
                new Point(0, -1),
                new Point(0, 1),
                new Point(1, 0),
                new Point(-1, 0),
                new Point(1, -1),
                new Point(-1, 1),
                new Point(1, 1),
                new Point(-1, -1)
                };

            MapSizeX = Map.SizeX;
            MapSizeY = Map.SizeY;
            Squares = Map.TileStates;

            this.User = Session;
        }
示例#36
0
        public Heightmap(string HeightmapData)
        {
            string[] Lines = Regex.Split(HeightmapData, "\r\n");

            mSizeX = Lines[0].Length;
            mSizeY = Lines.Length;

            mTileStates = new TileState[SizeX, SizeY];
            mFloorHeight = new int[SizeX, SizeY];

            for (int y = 0; y < SizeY; y++)
            {
                for (int x = 0; x < SizeX; x++)
                {
                    string Value = Lines[y][x].ToString().ToLower();

                    mTileStates[x, y] = (Value == "x" ? TileState.Blocked : TileState.Open);
                    mFloorHeight[x, y] = (Value == "x" ? 0 : int.Parse(Value));
                }
            }
        }
示例#37
0
文件: HeightMap.cs 项目: habb0/RevEmu
        public void SetMap(string heightmap)
        {
            string[] l = Regex.Split(heightmap, "\r\n");

            SizeX = l[0].Length;
            SizeY = l.Length;

            TileStates = new TileState[SizeX,SizeY];
            FloorHeight = new int[SizeX,SizeY];

            for (int y = 0; y < SizeY; y++)
            {
                for (int x = 0; x < SizeX; x++)
                {
                    string value = l[y][x].ToString().ToLower();

                    TileStates[x, y] = (value == "x" ? TileState.Blocked : TileState.Open);
                    FloorHeight[x, y] = (value == "x" ? 0 : int.Parse(value));
                    RoomUnit = new bool[x,y];
                    LogicalHeightMap = new sbyte[x,y];
                }
            }
        }
示例#38
0
 /* Default Constructor */
 public Tiles()
 {
     /*** Initialize Tile Grid ***/
     tile_grid = new TileState [28,36];
 }
示例#39
0
        public string GetSecondairParams()
        {
            DefaultTiles = new TileState[XLength, YLength];
            DefaultHeightMap = new double[XLength, YLength];

            StringBuilder Builder = new StringBuilder();

            for (short y = 0; y < YLength; y++)
            {
                string FixedLine = string.Empty;

                for (short x = 0; x < XLength; x++)
                {
                    string Character = Lines[y][x].ToString().Trim().ToLower();

                    double HeightMapChar = 0.0;

                    double.TryParse(Character, out HeightMapChar);

                    DefaultHeightMap[x, y] = HeightMapChar;

                    if (x == Door.X && y == Door.Y)
                    {
                        DefaultTiles[x, y] = TileState.Walkable_laststep;

                        DefaultHeightMap[x, y] = Door.Z;

                        FixedLine += Door.Z;
                    }
                    else
                    {
                        if (Character == "x")
                        {
                            DefaultTiles[x, y] = TileState.Blocked;
                        }
                        else
                        {
                            DefaultTiles[x, y] = TileState.Walkable;
                        }

                        FixedLine += Character;
                    }
                }

                Builder.AppendLine(FixedLine);
            }

            return Builder.ToString().Replace(Convert.ToChar(10).ToString(),"");
        }
示例#40
0
 public Board(int size)
 {
     int boardSize = size * 2 - 1;
     Tiles = new TileState[boardSize, boardSize];
 }
            public int GetNextMove()
            {
                TileState[,] currentState = GetNextState();

                // Return the difference.
                for (int row = 0; row < height; row++)
                {
                    for (int column = 0; column < width; column++)
                    {
                        if (lastState[row, column] == TileState.Empty
                            && currentState[row, column] == playerTile)
                        {
                            lastState = currentState;
                            return column;
                        }
                    }
                }

                Debug.Fail("Found no difference between last and current board state.");

                return -1;
            }
示例#42
0
        /// <summary>
        /// (Re)generates the relative heightmap for this room. Neccessary after furniture updates.
        /// </summary>
        public void RegenerateRelativeHeightmap(bool Broadcast = false)
        {
            lock (mItems) {
                mGuestsCanPlaceStickies = false;

                mFurniMap = new uint[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
                mStackHeight = new double[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
                mStackTopItemHeight = new double[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
                mUserMovementNodes = new UserMovementNode[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
                mTileEffects = new RoomTileEffect[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];
                mRedirectGrid = new Vector2[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];

                for (int y = 0; y < mCachedModel.Heightmap.SizeY; y++) {
                    for (int x = 0; x < mCachedModel.Heightmap.SizeX; x++) {
                        mStackHeight [x, y] = mCachedModel.Heightmap.FloorHeight [x, y];
                        mStackTopItemHeight [x, y] = 0;
                        mUserMovementNodes [x, y] = UserMovementNode.Walkable;
                        mTileEffects [x, y] = new RoomTileEffect ();
                        mRedirectGrid [x, y] = null;
                    }
                }

                bool[,] AnyItemInStack = new bool[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];

                foreach (Item Item in mItems.Values) {
                    if (Item.Definition.StackingBehavior == ItemStackingBehavior.Ignore) {
                        continue;
                    }

                    double TotalItemStackHeight = Item.RoomPosition.Z + Math.Round (Item.Definition.Height, 1);
                    List<Vector2> AffectedTiles = CalculateAffectedTiles (Item, Item.RoomPosition.GetVector2 (), Item.RoomRotation);

                    RoomTileEffect Effect = new RoomTileEffect ();
                    UserMovementNode MovementNode = UserMovementNode.Blocked;

                    switch (Item.Definition.Behavior) {
                    case ItemBehavior.Seat:
                    case ItemBehavior.LoveShuffler:

                        Effect = new RoomTileEffect (RoomTileEffectType.Sit, Item.RoomRotation,
                                new Vector2 (Item.RoomPosition.X, Item.RoomPosition.Y), Item.Definition.Height, 0,
                                Item.DefinitionId);
                        MovementNode = UserMovementNode.WalkableEndOfRoute;
                        break;

                    case ItemBehavior.Bed:

                        Effect = new RoomTileEffect (RoomTileEffectType.Lay, Item.RoomRotation,
                                new Vector2 (Item.RoomPosition.X, Item.RoomPosition.Y), Item.Definition.Height, 0,
                                Item.DefinitionId);
                        MovementNode = UserMovementNode.WalkableEndOfRoute;
                        break;

                    case ItemBehavior.Gate:

                        MovementNode = Item.Flags == "1" ? UserMovementNode.Walkable : UserMovementNode.Blocked;
                        break;

                    case ItemBehavior.AvatarEffectGenerator:

                        Effect = new RoomTileEffect (RoomTileEffectType.Effect, 0, Item.RoomPosition.GetVector2 (), 0,
                                Item.Definition.BehaviorData, Item.DefinitionId);
                        break;

                    case ItemBehavior.StickyPole:

                        mGuestsCanPlaceStickies = true;
                        break;

                    }

                    foreach (Vector2 Tile in AffectedTiles) {
                        if (TotalItemStackHeight >= mStackHeight [Tile.X, Tile.Y]) {
                            if (Item.Definition.Walkable == ItemWalkableMode.Always) {
                                MovementNode = UserMovementNode.Walkable;
                            } else if (Item.Definition.Walkable == ItemWalkableMode.Limited) {
                                MovementNode = (AnyItemInStack [Tile.X, Tile.Y] && mUserMovementNodes [Tile.X, Tile.Y] != UserMovementNode.Walkable) ? UserMovementNode.Blocked : UserMovementNode.Walkable;
                            }

                            mStackHeight [Tile.X, Tile.Y] = TotalItemStackHeight;
                            mStackTopItemHeight [Tile.X, Tile.Y] = Item.Definition.Height;
                            mUserMovementNodes [Tile.X, Tile.Y] = MovementNode;
                            mTileEffects [Tile.X, Tile.Y] = Effect;
                            mFurniMap [Tile.X, Tile.Y] = Item.Id;

                            if (Item.Definition.Behavior == ItemBehavior.Bed) {
                                if (Item.RoomRotation == 2 || Item.RoomRotation == 6) {
                                    mRedirectGrid [Tile.X, Tile.Y] = new Vector2 (Item.RoomPosition.X, Tile.Y);
                                }

                                if (Item.RoomRotation == 0 || Item.RoomRotation == 4) {
                                    mRedirectGrid [Tile.X, Tile.Y] = new Vector2 (Tile.X, Item.RoomPosition.Y);
                                }
                            } else {
                                mRedirectGrid [Tile.X, Tile.Y] = null;
                            }

                            AnyItemInStack [Tile.X, Tile.Y] = true;
                        }
                    }
                }

                foreach (StaticObject Object in mStaticObjects) {
                    mStackHeight [Object.Position.X, Object.Position.Y] = mCachedModel.Heightmap.FloorHeight [Object.Position.X, Object.Position.Y] + 1.0;
                    mStackTopItemHeight [Object.Position.X, Object.Position.Y] = 1.0;
                    mUserMovementNodes [Object.Position.X, Object.Position.Y] = (Object.IsSeat ? UserMovementNode.WalkableEndOfRoute : UserMovementNode.Blocked);

                    if (Object.IsSeat) {
                        mTileEffects [Object.Position.X, Object.Position.Y] = new RoomTileEffect (RoomTileEffectType.Sit, Object.Rotation, Object.Position, 1.0);
                    }
                }

                lock (mTileStates) {
                    StringBuilder RelativeHeightmap = new StringBuilder ();
                    mTileStates = new TileState[mCachedModel.Heightmap.SizeX, mCachedModel.Heightmap.SizeY];

                    for (int y = 0; y < mCachedModel.Heightmap.SizeY; y++) {
                        for (int x = 0; x < mCachedModel.Heightmap.SizeX; x++) {
                            if (mInfo.Type == RoomType.Flat && mCachedModel.DoorPosition.X == x && mCachedModel.DoorPosition.Y == y) {
                                mTileStates [x, y] = TileState.Door;
                                RelativeHeightmap.Append (mCachedModel.DoorPosition.Z);
                                continue;
                            }

                            if (mCachedModel.Heightmap.TileStates [x, y] == TileState.Blocked) {
                                mTileStates [x, y] = TileState.Blocked;
                                RelativeHeightmap.Append ('x');
                                continue;
                            }

                            mTileStates [x, y] = TileState.Open;
                            RelativeHeightmap.Append (mCachedModel.Heightmap.FloorHeight [x, y]);
                        }

                        RelativeHeightmap.Append (Convert.ToChar (13));
                    }

                    lock (mRelativeHeightmap) {
                        string NewRelativeMap = RelativeHeightmap.ToString ();

                        if (NewRelativeMap != mRelativeHeightmap) {
                            mRelativeHeightmap = RelativeHeightmap.ToString ();

                            if (Broadcast) {
                                BroadcastMessage (RoomRelativeHeightmapComposer.Compose (mRelativeHeightmap));
                            }
                        }
                    }
                }
            }
        }
示例#43
0
        internal void Setup()
        {
            Lines = new List<string>();

            Heightmap = Heightmap.Replace(Convert.ToChar(10).ToString(), "");
            string[] splitRawmap = Heightmap.Split("\r\n".ToCharArray());

            foreach (string s in splitRawmap)
            {
                Lines.Add(s);
            }

            this.MapSizeX = Lines[0].Length;
            this.MapSizeY = Lines.Count;

            this.mTileState = new TileState[MapSizeX, MapSizeY];
            this.mFloorHeight = new int[MapSizeX, MapSizeY];

            for (int y = 0; y < MapSizeY; y++)
            {
                for (int x = 0; x < MapSizeX; x++)
                {
                    string value = Lines[y][x].ToString().ToLower();

                    mTileState[x, y] = (value == "x" ? TileState.Blocked : TileState.Open);
                    mFloorHeight[x, y] = (value == "x" ? 0 : int.Parse(value));
                    RoomUnit = new bool[x, y];
                    LogicalHeightMap = new sbyte[x, y];
                }
            }
        }
        public void GenerateMatrix()
        {
            this.Matrix = new TileState[GetRoom().GetRoomModel().XLength, GetRoom().GetRoomModel().YLength];
            this.HeightMap = new double[GetRoom().GetRoomModel().XLength, GetRoom().GetRoomModel().YLength];

            for (short y = 0; y < GetRoom().GetRoomModel().YLength; y++)
            {
                for (short x = 0; x < GetRoom().GetRoomModel().XLength; x++)
                {
                    HeightMap[x, y] = GetRoom().GetRoomModel().DefaultHeightMap[x, y];

                    iPoint Point = new iPoint(x, y);

                    if (GetFloorItemsOnTile(Point).Count > 0)
                    {
                        foreach (Item Item in GetFloorItemsOnTile(Point))
                        {
                            if (!Item.GetBaseItem().EnableSit)
                            {
                                HeightMap[x, y] += Item.GetBaseItem().LengthZ;
                            }

                            if (Item.GetBaseItem().EnableSit)
                            {
                                Matrix[x, y] = TileState.Walkable_laststep;
                            }
                            else if (Item.GetBaseItem().EnableWalk)
                            {
                                Matrix[x, y] = TileState.Walkable;
                            }
                            else
                            {
                                Matrix[x, y] = TileState.Blocked;
                            }
                        }
                    }
                    else
                    {
                        Matrix[x, y] = GetRoom().GetRoomModel().DefaultTiles[x, y];
                    }
                }
            }
        }