예제 #1
0
        public int GetMovementCost(Vector2D position)
        {
            Tile tmp          = Tiles[position.x][position.y];
            int  movementCost = TileBaseType.GetBaseType(tmp.Type).MovementCost;

            movementCost += Relief.GetRelief(tmp.Relief).MovementCost;
            movementCost += Vegetation.GetVegetation(tmp.Vegetation).MovementCost;
            return(movementCost);
        }
예제 #2
0
        /// <summary>
        /// Set Tiletype bei Enum-TileBaseType; Update Texture of tile; used bei Map-Generation
        /// </summary>
        /// <param name="_tilebasetype"></param>
        /// <param name="GraphicsDevice"></param>
        /// <param name="tileMap"></param>
        public void SetTileType(TileBaseType _tilebasetype)
        {
            bool isEnvrionment;

            tileBaseType = _tilebasetype;
            switch (tileBaseType)
            {
            case TileBaseType.Mountain:
                isEnvrionment = true;
                tiletype      = TileNumber.mountain;
                break;

            case TileBaseType.Wood:
                isEnvrionment = true;
                tiletype      = TileNumber.wood;
                break;

            case TileBaseType.Water:
                isEnvrionment = true;
                tiletype      = TileNumber.flatwater;
                break;

            case TileBaseType.Enemy:
                SetAsEnemyTile();
                isEnvrionment = false;
                break;

            default:
                isEnvrionment = false; break;
            }

            if (isEnvrionment)
            {
                Color[]   data;
                Rectangle rect = GetTileSpritePosition(tiletype);

                tile_texture = new Texture2D(Globals.GraphicsDevice, rect.Width, rect.Height);
                data         = new Color[rect.Width * rect.Height];

                Globals.tileMap.GetData(0, rect, data, 0, data.Length);
                tile_texture.SetData(data);
            }
        }
예제 #3
0
        private void ConquerBestTile(List <List <Tile> > map)
        {
            //check which ressource is lowest
            TileBaseType wanted_tile = new TileBaseType();
            bool         break_value = false;
            bool         tileAdded   = false;

            if (ressources.wood < ressources.food && ressources.wood < ressources.ore)
            {
                wanted_tile = TileBaseType.Wood;
            }
            else if (ressources.food < ressources.wood && ressources.food < ressources.ore)
            {
                wanted_tile = TileBaseType.None;
            }
            else if (ressources.ore < ressources.wood && ressources.ore < ressources.food)
            {
                wanted_tile = TileBaseType.Mountain;
            }
            else
            {
                wanted_tile = TileBaseType.None;
            }

            foreach (List <Tile> row in map)
            {
                foreach (Tile tile in row)
                {
                    if (!tile.hasEnemy && tile.aNeighborisEnemy && tile.tileBaseType == wanted_tile && !tile.empty)
                    {
                        if (tile.isCitypart)
                        {
                            if (ressources.army >= tile.armystrength)
                            {
                                ressources.army -= tile.armystrength;
                                tile.SetAsEnemyTile();
                                AddTileToControll(tile);
                                break_value = true;
                                tileAdded   = true;
                                break;
                            }
                        }
                        else
                        {
                            ressources.SubRessources(buildCosts[(int)Buildcosts.addTile]);
                            tile.SetAsEnemyTile();
                            AddTileToControll(tile);
                            break_value = true;
                            tileAdded   = true;
                            break;
                        }
                    }
                }

                if (break_value)
                {
                    break;
                }
            }
            //Add any tile which is not gras if no tile with right condition is found
            if (!tileAdded)
            {
                foreach (List <Tile> row in map)
                {
                    foreach (Tile tile in row)
                    {
                        if (!tile.hasEnemy && tile.aNeighborisEnemy && !tile.empty && tile.tileBaseType != TileBaseType.None)
                        {
                            if (tile.isCitypart)
                            {
                                if (ressources.army >= tile.armystrength)
                                {
                                    ressources.army -= tile.armystrength;
                                    tile.SetAsEnemyTile();
                                    AddTileToControll(tile);
                                    break_value = true;
                                    tileAdded   = true;
                                    break;
                                }
                            }
                            else
                            {
                                ressources.SubRessources(buildCosts[(int)Buildcosts.addTile]);
                                tile.SetAsEnemyTile();
                                AddTileToControll(tile);
                                break_value = true;
                                tileAdded   = true;
                                break;
                            }
                        }
                    }

                    if (break_value)
                    {
                        break;
                    }
                }
            }

            //Add any tile if no tile with right condition is found
            if (!tileAdded)
            {
                foreach (List <Tile> row in map)
                {
                    foreach (Tile tile in row)
                    {
                        if (!tile.hasEnemy && tile.aNeighborisEnemy && !tile.empty)
                        {
                            if (tile.isCitypart)
                            {
                                if (ressources.army >= tile.armystrength)
                                {
                                    ressources.army -= tile.armystrength;
                                    tile.SetAsEnemyTile();
                                    AddTileToControll(tile);
                                    break_value = true;
                                    tileAdded   = true;
                                    break;
                                }
                            }
                            else
                            {
                                ressources.SubRessources(buildCosts[(int)Buildcosts.addTile]);
                                tile.SetAsEnemyTile();
                                AddTileToControll(tile);
                                break_value = true;
                                tileAdded   = true;
                                break;
                            }
                        }
                    }

                    if (break_value)
                    {
                        break;
                    }
                }
            }
        }