// Gets the tiles for a single "region" (i.e. an island)
    List <Coord> GetRegionTiles(int startX, int startY)
    {
        List <Coord> tiles = new List <Coord> ();

        int[,] mapFlags = new int[width, height];
        MapTileType tileType = map[startX, startY];

        Queue <Coord> queue = new Queue <Coord> ();

        queue.Enqueue(new Coord(startX, startY));
        mapFlags [startX, startY] = 1;

        while (queue.Count > 0)
        {
            Coord tile = queue.Dequeue();
            tiles.Add(tile);

            for (int x = tile.tileX - 1; x <= tile.tileX + 1; x++)
            {
                for (int y = tile.tileY - 1; y <= tile.tileY + 1; y++)
                {
                    if (IsInMapRange(x, y) && (y == tile.tileY || x == tile.tileX))
                    {
                        if (mapFlags[x, y] == 0 && map[x, y] == tileType)
                        {
                            mapFlags[x, y] = 1;
                            queue.Enqueue(new Coord(x, y));
                        }
                    }
                }
            }
        }
        return(tiles);
    }
    /// <summary>
    /// マップタイルを装飾
    /// </summary>
    /// <param name="bmt"></param>
    public void DecoreteMapTileByDropdown(BattleMapTile bmt)
    {
        //// ドロップダウンから装飾のタイプを取得
        MapTileType mapTileType = GetDecorationTypeByDropdown();

        DecoreteMapTile(bmt, bmt.MapTileType);
    }
    // Gets all regions (i.e. all islands) in the map
    List <List <Coord> > GetRegions(MapTileType tileType)
    {
        List <List <Coord> > regions = new List <List <Coord> > ();

        int[,] mapFlags = new int[width, height];

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                if (mapFlags[x, y] == 0 && map[x, y] == tileType)
                {
                    List <Coord> newRegion = GetRegionTiles(x, y);
                    regions.Add(newRegion);

                    foreach (Coord tile in newRegion)
                    {
                        mapFlags[tile.tileX, tile.tileY] = 1;
                    }
                }
            }
        }

        return(regions);
    }
Beispiel #4
0
    MapTileType[,] GenerateRandomMapTileTypes()
    {
        MapTileType[,] tileTypes = new MapTileType[size, size];
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size; j++)
            {
                float       val  = Random.value;
                MapTileType type = MapTileType.Free;

                if (val < 0.2)
                {
                    type = MapTileType.Food;
                }

                tileTypes[i, j] = type;
            }
        }

        // Add a start tile
        tileTypes[Random.Range(0, size), Random.Range(0, size)] = MapTileType.Start;

        // Add an end tile
        //tileTypes[Random.Range(size - size / 4, size), Random.Range(0, size)] = MapTileType.End;

        return(tileTypes);
    }
Beispiel #5
0
        public void SetModel(MapTileType type)
        {
            switch (type)
            {
            case MapTileType.Grass:
                this.background_color = ConsoleColor.Green;
                break;

            case MapTileType.Tree:
                this.background_color = ConsoleColor.DarkGreen;
                break;

            case MapTileType.Stone:
                this.background_color = ConsoleColor.Gray;
                break;

            case MapTileType.Water:
                this.background_color = ConsoleColor.Blue;
                break;
                break;

            case MapTileType.Lava:
                this.background_color = ConsoleColor.Yellow;
                break;
            }
        }
Beispiel #6
0
    // Return whether a building of this category can be placed
    // on the given tile type.
    public bool IsCompatibleTileType(MapTileType tileType)
    {
        var index        = Array.IndexOf(CompatibleTileTypes, tileType);
        var isCompatible = index > -1 ? true : false;

        return(isCompatible);
    }
Beispiel #7
0
    public MapTileViewType ConvertViewType(MapTileType tileType)
    {
        switch (tileType)
        {
        case MapTileType.OCEAN:
            return(MapTileViewType.WATER01);

        case MapTileType.GRASS:
            return(MapTileViewType.GRASS05);

        case MapTileType.FOREST:
            return(MapTileViewType.GRASS21);

        case MapTileType.MOUNTAIN:
            return(MapTileViewType.DIRT06);

        case MapTileType.SAND:
            return(MapTileViewType.SAND07);

        case MapTileType.SNOW:
            return(MapTileViewType.SNOW01);

        case MapTileType.RIVER:
            return(MapTileViewType.WATER03);

        default:
            return(MapTileViewType.WATER01);
        }
    }
Beispiel #8
0
    public void ChangeCurMapTile()
    {
        curSelectMapTile = (MapTileType)mapTileSelector.value;
        if ((MapTileType)mapTileSelector.value == MapTileType.doorU ||
            (MapTileType)mapTileSelector.value == MapTileType.doorD ||
            (MapTileType)mapTileSelector.value == MapTileType.doorL ||
            (MapTileType)mapTileSelector.value == MapTileType.doorR)
        {
            doorDirSelector.gameObject.SetActive(true);
        }
        else
        {
            doorDirSelector.gameObject.SetActive(false);
        }

        if (followMouseTile != null)
        {
            Destroy(followMouseTile);
            followMouseTile = null;
        }

        if (curSelectMapTile == MapTileType.none)
        {
            return;
        }

        followMouseTile = Instantiate <GameObject>(blocksList[(int)curSelectMapTile]);
        followMouseTile.transform.position = Vector3.zero;
        followMouseTile.transform.SetParent(followMouseTile.transform);
    }
Beispiel #9
0
    public void CreateMapBlock(int height, int width, MapTileType tileType)
    {
        if (mapTileArray == null)
        {
            return;
        }

        if (drawBlocksArray[height, width] != null)
        {
            Destroy(drawBlocksArray[height, width]);
            drawBlocksArray[height, width] = null;
        }

        if (tileType == MapTileType.none)
        {
            return;
        }

        if (tileType == MapTileType.doorU ||
            tileType == MapTileType.doorD ||
            tileType == MapTileType.doorL ||
            tileType == MapTileType.doorR)
        {
            tileType = MapTileType.doorU;
        }
        GameObject tempBlock;

        tempBlock = Instantiate <GameObject>(blocksList[(int)tileType]);
        drawBlocksArray[height, width] = tempBlock;
        Vector3 blockPos = new Vector3(width, height, 0);

        tempBlock.transform.position = blockPos;
    }
Beispiel #10
0
 public MapTile(
     float height, MapTileType type, AbstractBuilding building = null
     )
 {
     Height   = height;
     Type     = type;
     Building = building;
 }
Beispiel #11
0
 public MapTileObject(int id, int x, int y, int width, int height, MapTileType tileType, MapTileBlockType mapTileBlockType)
 {
     Id = id;
     X = x;
     Y = y;
     Width = width;
     Height = height;
     MapTileType = new MapTileTypeObject(tileType.Id, tileType.Name, tileType.MovementAllowed, tileType.Background, mapTileBlockType);
 }
    /// <summary>
    /// パスリストの処理
    /// </summary>
    /// <param name="bmt"></param>
    /// <param name="movableTileList"></param>
    /// <param name="pathList"></param>
    /// <param name="currentPath"></param>
    /// <param name="moveCount"></param>
    private void ProcessPathList(
        BattleMapTile targetTile, List <BattleMapTile> movableTileList,
        List <string> pathList, string currentPath, int moveCount)
    {
        // 終点なら終了
        BattleMapTile startTile = holder.BattleMapStatus.BattleMapMoveStatus.StartMapTile;

        if (targetTile == startTile)
        {
            currentPath += targetTile.X + "," + targetTile.Y + "-" + moveCount;
            pathList.Add(currentPath);
            return;
        }

        // 移動可能かどうか
        if (movableTileList.Contains(targetTile) == false)
        {
            return;
        }

        // 該当タイルに別モンスターがいたら侵入不可
        BattleMapMonster monster        = holder.BattleMapStatus.BattleMapMoveStatus.TargetMonster;
        BattleMapMonster anotherMonster = holder.BattleMapMonsters.GetMonster(targetTile.X, targetTile.Y);

        if (anotherMonster != null && monster != anotherMonster)
        {
            return;
        }

        // 移動コストを取得
        MapTileType tileType = targetTile.MapTileType;
        int         cost     = monster.BattleStatus.BattleMapMonsterMoveCost.GetMoveCost(tileType);

        // 侵入不可の場合
        if (cost < 0)
        {
            return;
        }

        // タイルのコストごとに移動力を減少
        moveCount = moveCount - cost;

        // 移動力がなくなったら終了
        if (moveCount <= 0)
        {
            return;
        }

        // パスに追加
        currentPath += targetTile.X + "," + targetTile.Y + "_";

        // タイルごとの処理
        foreach (BattleMapTile jointTile in targetTile.JointInfo.GetJointTileList())
        {
            ProcessPathList(jointTile, movableTileList, pathList, currentPath, moveCount);
        }
    }
Beispiel #13
0
 /*
  * SETTERS
  */
 // insert the tile in the map matrix and into the graph
 public void addTile(int x, int y, MapTileType type)
 {
     // Check map bounds
     if (this.isValidTilePosition(x, y))
     {
         TileInfo info = new TileInfo(x, y, type);
         this.mapTiles[y][x] = info;
     }
 }
    public void SetMapTile(Coord coord, MapTileType setType)
    {
        if (!IsInMapRange(coord.tileX, coord.tileY))
        {
            return;
        }

        this.map[coord.tileX, coord.tileY] = setType;
    }
Beispiel #15
0
    // insert the tile in the map matrix and into the graph
    public void addTile(int x, int y, MapTileType type)
    {
        // Check map bounds
        if (this.isValidTilePosition(x, y))
        {
            TileInfo info = new TileInfo(x, y, type, this.getMapTileTypeCost(type), this.graphIndexFromTile(x, y));
            this.mapTiles[y][x] = info;
            this.graph.setVertex(info.VertexIndex, info);

            // create graph edges
            if (this.isUsefulPosition(x, y))                    // avoid wall to create edges
            // neighborhood 4 - applied to everyone
            //float edgeWeight = 1; // ignore edge
            {
                float edgeWeight = 0;
                if (this.isUsefulPosition(x, y - 1))                  // UP
                {
                    this.graph.setAdjacency(this.graphIndexFromTile(x, y), this.graphIndexFromTile(x, y - 1), edgeWeight);
                }
                if (this.isUsefulPosition(x, y + 1))                  // DOWN
                {
                    this.graph.setAdjacency(this.graphIndexFromTile(x, y), this.graphIndexFromTile(x, y + 1), edgeWeight);
                }
                if (this.isUsefulPosition(x - 1, y))                  // LEFT
                {
                    this.graph.setAdjacency(this.graphIndexFromTile(x, y), this.graphIndexFromTile(x - 1, y), edgeWeight);
                }
                if (this.isUsefulPosition(x + 1, y))                  // RIGHT
                {
                    this.graph.setAdjacency(this.graphIndexFromTile(x, y), this.graphIndexFromTile(x + 1, y), edgeWeight);
                }
                // neighborhood 8
                if (!this.neighborhood4)
                {
                    //edgeWeight = Mathf.Sqrt( 2 );	// sqrt 1*1+1*1 // ignore edge
                    edgeWeight = 0;
                    if (this.isUsefulPosition(x - 1, y - 1))                    // UP LEFT
                    {
                        this.graph.setAdjacency(this.graphIndexFromTile(x, y), this.graphIndexFromTile(x - 1, y - 1), edgeWeight);
                    }
                    if (this.isUsefulPosition(x - 1, y + 1))                    // DOWN LEFT
                    {
                        this.graph.setAdjacency(this.graphIndexFromTile(x, y), this.graphIndexFromTile(x - 1, y + 1), edgeWeight);
                    }
                    if (this.isUsefulPosition(x + 1, y - 1))                    // UP RIGHT
                    {
                        this.graph.setAdjacency(this.graphIndexFromTile(x, y), this.graphIndexFromTile(x + 1, y - 1), edgeWeight);
                    }
                    if (this.isUsefulPosition(x + 1, y + 1))                    // DOWN RIGHT
                    {
                        this.graph.setAdjacency(this.graphIndexFromTile(x, y), this.graphIndexFromTile(x + 1, y + 1), edgeWeight);
                    }
                }
            }
        }
    }
Beispiel #16
0
 public void SetData(string title,
                     int level,
                     int camp,
                     string allianceTag    = null,
                     string allianceBanner = null,
                     long defenseUntil     = -1,
                     MapTileType type      = MapTileType.Normal,
                     bool hasPlayer        = true)
 {
 }
Beispiel #17
0
    public void Set(int x, int y, MapTileType n, bool flag = false)
    {
        if (!Inbound(x) || !Inbound(y))
        {
            return;
        }
        var index = Get(x, y);

        index.Type = flag ? index.Type | n : n;
    }
    public int GetMoveCost(MapTileType tileType)
    {
        // 存在しなければ1
        if (moveCostDictionary.ContainsKey(tileType) == false)
        {
            return(1);
        }

        return(moveCostDictionary[tileType]);
    }
        public void EditTile(MapTile tile, MapTileType newType)
        {
            int position = Tiles.IndexOf(tile);

            Tiles.RemoveAt(position);

            tile.TileType = newType;

            Tiles.Insert(position, tile);
        }
Beispiel #20
0
    private static GameObject GetPrefab(MapTileType _type)
    {
        switch (_type)
        {
        case MapTileType.Grass: return(m_grassPrefab);

        case MapTileType.Water: return(m_waterPrefab);
        }
        return(null);
    }
Beispiel #21
0
 /*
  * SETTERS
  */
 // set the cost for a given type
 public void setMapTileTypeCost(MapTileType type, float cost)
 {
     if (this.mapTileTypeCost.ContainsKey(type) && type != MapTileType.Wall && type != MapTileType.NotDefined)
     {
         this.mapTileTypeCost[type] = cost;
     }
     else
     {
         this.mapTileTypeCost.Add(type, cost);
     }
 }
Beispiel #22
0
 // returns the cost for a given type
 public float getMapTileTypeCost(MapTileType type)
 {
     if (this.mapTileTypeCost.ContainsKey(type))
     {
         return(this.mapTileTypeCost[type]);
     }
     else
     {
         return(float.MaxValue);
     }
 }
 public IsCompatibleTileTypeTestCase(
     string description,
     MapTileType[] compatibleTileTypes,
     MapTileType tileType,
     bool expectedIsCompatible
     )
 {
     Description          = description;
     CompatibleTileTypes  = compatibleTileTypes;
     TileType             = tileType;
     ExpectedIsCompatible = expectedIsCompatible;
 }
Beispiel #24
0
        public void AddMapTileTypes(string name, int mapValue, int xOffset, int yOffset)
        {
            MapTileType mapTileType = new MapTileType();

            mapTileType.Name     = name;
            mapTileType.MapValue = mapValue;
            mapTileType.XOffset  = xOffset;
            mapTileType.YOffset  = yOffset;

            mapTileTypes.Add(mapValue, mapTileType);

            usedValues.Add(mapValue);
        }
Beispiel #25
0
    public MapTile[] PassableNeighboringTilesOfTypeForAgent(MapTileType type, Agent agent)
    {
        ArrayList neighborList = new ArrayList();

        foreach (MapTile tile in PassableNeighboringTilesForAgent(agent))
        {
            if (tile.type == type)
            {
                neighborList.Add(tile);
            }
        }
        return(neighborList.ToArray(typeof(MapTile)) as MapTile[]);
    }
Beispiel #26
0
    public static MapTile CreateTile(Transform _parent, int _x, int _y, int _seed)
    {
        MapTileType type    = _seed < 80 ? MapTileType.Grass : MapTileType.Water;
        GameObject  tileObj = Instantiate <GameObject>(GetPrefab(type), _parent);

        tileObj.name = "_tile_" + _x + "_" + _y + "_" + type.ToString();
        tileObj.transform.position = new Vector3(_x - m_mapXMiddle, 0, _y - m_mapYMiddle);
        MapTile newTile = tileObj.AddComponent <MapTile>();

        newTile.TileType = type;
        newTile.Position = new Position(_x, _y);
        newTile.Walkable = type == MapTileType.Grass;
        return(newTile);
    }
Beispiel #27
0
 public void PutArea(int height, int width, int objHeight, int objWidth, MapTileType tileType)
 {
     for (int iHeight = height; iHeight < height + objHeight; iHeight++)
     {
         for (int iWidth = width; iWidth < width + objWidth; iWidth++)
         {
             if (iHeight == height && iWidth == width)
             {
                 continue;
             }
             mapTileArray[iHeight, iWidth] = tileType;
         }
     }
 }
Beispiel #28
0
        public static bool IsSolid(this MapTileType tileType)
        {
            switch (tileType)
            {
            case MapTileType.Earth:
            case MapTileType.Stone:
            case MapTileType.Gold:
            case MapTileType.Gems:
            case MapTileType.Wall:
                return(true);

            default:
                return(false);
            }
        }
    /// <summary>
    /// 移動チェック
    /// </summary>
    /// <param name="monster"></param>
    /// <param name="targetTile"></param>
    /// <param name="moveCount"></param>
    /// <param name="movableTileSet"></param>
    private void CheckMove(
        BattleMapMonster monster, BattleMapTile targetTile, int moveCount, HashSet <BattleMapTile> movableTileSet)
    {
        // 該当タイルに別モンスターがいたら侵入不可
        BattleMapMonster anotherMonster = holder.BattleMapMonsters.GetMonster(targetTile.X, targetTile.Y);

        if (anotherMonster != null && monster != anotherMonster)
        {
            return;
        }

        // マスクしてあったら侵入不可
        BattleMapTileMaskGroup group = holder.BattleMap.BattleMapTileMaskGroup[monster.GetTeamIndex()];
        BattleMapTileMask      mask  = group.BattleMapTileMask[targetTile.X, targetTile.Y];

        if (mask.Mask)
        {
            return;
        }

        // 移動コストを取得
        MapTileType tileType = targetTile.MapTileType;
        int         cost     = monster.BattleStatus.BattleMapMonsterMoveCost.GetMoveCost(tileType);

        // 侵入不可の場合
        if (cost < 0)
        {
            return;
        }

        // このタイルを移動可能に追加
        movableTileSet.Add(targetTile);

        // タイルのコストごとに移動力を減少
        moveCount = moveCount - cost;

        // 移動力がなくなったら終了
        if (moveCount <= 0)
        {
            return;
        }

        // タイルごとの処理
        foreach (BattleMapTile jointTile in targetTile.JointInfo.GetJointTileList())
        {
            CheckMove(monster, jointTile, moveCount, movableTileSet);
        }
    }
Beispiel #30
0
        public MapTile(MapTileType type, int Xp, int Yp, int Zp)
        {
            XPos = Xp;
            YPos = Yp;
            ZPos = Zp;
            myType = type;

            if(myType == MapTileType.TILE_FLOOR)
            {
                Graphic = new Image(Assets.GFX_TEST_TILE);
            }
            if(myType == MapTileType.TILE_WALL)
            {
                Graphic = new Image(Assets.GFX_TEST_WALL);
            }
        }
Beispiel #31
0
        public static int getTileWidth(MapTileType Type)
        {
            switch (Type)
            {
            case MapTileType.Tile5m: return(1);

            case MapTileType.Tile10m: return(2);

            case MapTileType.Tile20m: return(4);

            case MapTileType.Tile30m: return(6);

            case MapTileType.Tile40m: return(8);

            case MapTileType.Tile80m: return(16);
                // TODO  all other sizes
            }
            return(-1); // this should never happen!
        }
Beispiel #32
0
    public bool CheckCanPutBlock(int height, int width, MapTileType tileType)
    {
        int objHeight = 1;
        int objWidth  = 1;

        switch (tileType)
        {
        case MapTileType.doorU:
        case MapTileType.doorD:
        case MapTileType.doorL:
        case MapTileType.doorR:
            objHeight = 3;
            objWidth  = 2;
            break;

        case MapTileType.box22:
            objHeight = 2;
            objWidth  = 2;
            break;

        case MapTileType.box33:
            objHeight = 3;
            objWidth  = 3;
            break;

        default:
            break;
        }

        for (int iHeight = height; iHeight < height + objHeight; iHeight++)
        {
            for (int iWidth = width; iWidth < width + objWidth; iWidth++)
            {
                if (mapTileArray[iHeight, iWidth] != MapTileType.none)
                {
                    return(false);
                }
            }
        }

        return(true);
    }
Beispiel #33
0
        public void ChangeType(MapTileType newType)
        {
            myType = newType;

            if (myType == MapTileType.TILE_FLOOR)
            {
                Graphic = new Image(Assets.GFX_TEST_TILE);
            }
            if (myType == MapTileType.TILE_WALL)
            {
                Graphic = new Image(Assets.GFX_TEST_WALL);
            }

            if(myType == MapTileType.TILE_EMPTY)
            {
                IsSolid = false;
            }
            else
            {
                IsSolid = true;
            }
        }
Beispiel #34
0
 public void Set(int x, int y, MapTileType n, bool flag = false)
 {
     if (!Inbound(x) || !Inbound(y))
     {
         return;
     }
     var index = Get(x, y);
     index.Type = flag ? index.Type | n : n;
 }
Beispiel #35
0
 public MapTile(int worldx,int worldy,MapTileType type)
 {
     this.WorldX = worldx;
     this.WorldY = worldy;
     this.Type = type;
     //this.ScreenSprite = new RectangleF(ViewX, ViewY, ViewX + TileSize, ViewY + TileSize);
 }
 public void Delete(MapTileType mapTileType)
 {
     db.MapTileTypes.DeleteOnSubmit(mapTileType);
 }
 public void Add(MapTileType mapTileType)
 {
     db.MapTileTypes.InsertOnSubmit(mapTileType);
 }