示例#1
0
 private static Game ParseBicFile(string path)
 {
     throw new Exception("Parsing .bic files is not yet fully implemented. (The map dimensions are hardcoded. Try asking Novice nicely for help.)");
     BinaryReader reader = null;
     try
     {
         Game game = new Game();
         reader = new BinaryReader(new FileStream(path, FileMode.Open));
         int i = 0;
         try
         {
             while (true)
             {
                 byte b = reader.ReadByte();
                 if ("TILE".IndexOf((char)b) == i)
                     i++;
                 else
                     i = 0;
                 if (i > 3)
                 {
                     i = 0;
                     int tileCount = reader.ReadInt32();
                     Map map = new Map();
                     map.Width = 200;
                     map.Height = 100;
                     map.SetDimensions(map.Width, map.Height);
                     game.Map = map;
                     for (int y = map.Height-1; y >= 0; y--)
                     {
                         for (int xx = 0; xx < map.Width; xx++)
                         {
                             Tile tile = new Tile();
                             if (xx * 2 >= map.Width)
                                 tile.X = xx * 2 - map.Width + 1;
                             else
                                 tile.X = xx * 2;
                             tile.Y = y;
                             tile.PlotType = PlotTypes.FLAT;
                             int tileByteCount = reader.ReadInt32();
                             int riverInfo = reader.ReadInt16();
                             int resource = reader.ReadInt32();
                             byte image = reader.ReadByte();
                             byte file = reader.ReadByte();
                             int unknown = reader.ReadInt16();
                             byte overlays = reader.ReadByte();
                             byte terrain = reader.ReadByte();
                             /*
                                 0a byte binary flags as indicated in overview
                                 0b nibble terrain: 0 = desert, 1 = plains, 2 = grassland,
                                 3 = tundra, 4 = floodplain, 5 = hills,
                                 6 = mountain, 7 = forest, 8 = jungle,
                                 9 = coast, a = sea, b = ocean
                                 nibble basic terrain: only 0,1,2,3,9,a,b
                              */
                             int terrainType = (int)(terrain / 16);
                             int basicTerrain = terrain % 16;
                             switch (terrainType)
                             {
                                 case 0:
                                     tile.Terrain = TerrainTypes.TERRAIN_DESERT;
                                     break;
                                 case 1:
                                     tile.Terrain = TerrainTypes.TERRAIN_PLAINS;
                                     break;
                                 case 2:
                                     tile.Terrain = TerrainTypes.TERRAIN_GRASS;
                                     break;
                                 case 3:
                                     tile.Terrain = TerrainTypes.TERRAIN_TUNDRA;
                                     break;
                                 case 4:
                                     tile.Terrain = TerrainTypes.TERRAIN_DESERT;
                                     tile.FeatureType = FeatureTypes.FEATURE_FLOOD_PLAINS;
                                     break;
                                 case 5:
                                     tile.PlotType = PlotTypes.HILL;
                                     tile.Terrain = TerrainTypes.TERRAIN_GRASS;
                                     break;
                                 case 6:
                                     tile.PlotType = PlotTypes.PEAK;
                                     tile.Terrain = TerrainTypes.TERRAIN_GRASS;
                                     break;
                                 case 7:
                                     tile.FeatureType = FeatureTypes.FEATURE_FOREST;
                                     tile.Terrain = TerrainTypes.TERRAIN_GRASS;
                                     break;
                                 case 8:
                                     tile.FeatureType = FeatureTypes.FEATURE_JUNGLE;
                                     tile.Terrain = TerrainTypes.TERRAIN_GRASS;
                                     break;
                                 case 9:
                                     tile.Terrain = TerrainTypes.TERRAIN_COAST;
                                     break;
                                 case 10:
                                 case 11:
                                     tile.Terrain = TerrainTypes.TERRAIN_OCEAN;
                                     break;
                                 default:
                                     tile.Terrain = TerrainTypes.TERRAIN_GRASS;
                                     break;
                             }
                             switch (basicTerrain)
                             {
                                 case 0:
                                     tile.Terrain = TerrainTypes.TERRAIN_DESERT;
                                     break;
                                 case 1:
                                     tile.Terrain = TerrainTypes.TERRAIN_PLAINS;
                                     break;
                                 case 2:
                                     tile.Terrain = TerrainTypes.TERRAIN_GRASS;
                                     break;
                                 case 3:
                                     tile.Terrain = TerrainTypes.TERRAIN_TUNDRA;
                                     break;
                                 case 9:
                                     tile.Terrain = TerrainTypes.TERRAIN_COAST;
                                     break;
                                 case 10:
                                 case 11:
                                     tile.Terrain = TerrainTypes.TERRAIN_OCEAN;
                                     break;
                                 default:
                                     break;
                             }
                             int bonuses = reader.ReadInt16();
                             int barbCamp = reader.ReadInt16();
                             int unknown2 = reader.ReadInt32();
                             int continent = reader.ReadInt16();
                             //byte unknown3 = reader.ReadByte();
                             game.Map.SetTile(tile.X, tile.Y, tile);
                         }
                     }
                 }
             }
         }
         catch (EndOfStreamException)
         {
         }
         return game;
     }
     catch (Exception e)
     {
         throw new Exception(string.Format("Exception reading map from file {0}. Error was: {1}", path, e.Message), e);
     }
     finally
     {
         if (reader != null) reader.Close();
     }
 }
示例#2
0
 public override MapState Execute(MapState state, Selection selection)
 {
     if (KeepInside)
     {
         int minx = int.MaxValue, miny = int.MaxValue, maxx = int.MinValue, maxy = int.MinValue;
         foreach (var tile in state.ActiveLayer.Map.GetAllTiles())
         {
             if (!tile.IsEmpty)
             {
                 minx = Math.Min(minx, tile.X);
                 miny = Math.Min(miny, tile.Y);
                 maxx = Math.Max(maxx, tile.X);
                 maxy = Math.Max(maxy, tile.Y);
             }
         }
         if (minx + DeltaX < 0) DeltaX = -minx;
         if (miny + DeltaY < 0) DeltaY = -miny;
         if (maxx + DeltaX >= state.ActiveLayer.Map.Width) DeltaX = state.ActiveLayer.Map.Width - 1 - maxx;
         if (maxy + DeltaY >= state.ActiveLayer.Map.Height) DeltaY = state.ActiveLayer.Map.Height - 1 - maxy;
     }
     if (DeltaX != 0 || DeltaY != 0)
     {
         Map m = new Map();
         m.SetDimensions(state.ActiveLayer.Map.Width, state.ActiveLayer.Map.Height);
         foreach (var t in state.ActiveLayer.Map.GetAllTiles())
         {
             m.SetTile(t.X, t.Y, new Tile() { IsEmpty = true });
         }
         foreach (var t in state.ActiveLayer.Map.GetAllTiles())
         {
             var x = t.X + DeltaX;
             var y = t.Y + DeltaY;
             if(x >= 0 && y >= 0 && x < m.Width && y < m.Height)
                 m.SetTile(x, y, t);
         }
         state.ActiveLayer.Map = m;
     }
     return state;
 }
示例#3
0
 public static Map RotateCW(Map thisMap)
 {
     Map map = new Map();
     map.SetDimensions(thisMap.Height, thisMap.Width);
     map.IsHorizontalWrap = thisMap.IsVerticalWrap;
     map.IsVerticalWrap = thisMap.IsHorizontalWrap;
     map.UnparsedData = new List<string>(thisMap.UnparsedData);
     foreach (Tile t in thisMap.GetAllTiles())
     {
         map.SetTile(t.Y, map.Height - 1 - t.X, (Tile)t.Clone());
     }
     Map map2 = (Map)map.Clone();
     foreach (Tile t in map2.GetAllTiles())
     {
         t.IsWOfRiver = false;
         t.IsNOfRiver = false;
     }
     foreach (Tile t in map.GetAllTiles())
     {
         if (t.IsNOfRiver)
         {
             Tile w = map2.GetNeighbour(t.X, t.Y, HorizontalNeighbour.West, VerticalNeighbour.None);
             if (w != null)
             {
                 w.IsWOfRiver = true;
                 if (t.RiverWEDirection == RiverDirection.WEST_TO_EAST)
                     w.RiverNSDirection = RiverDirection.NORTH_TO_SOUTH;
                 else
                     w.RiverNSDirection = RiverDirection.SOUTH_TO_NORTH;
             }
         }
         if (t.IsWOfRiver)
         {
             Tile tt = map2.GetTile(t.X, t.Y);
             tt.IsNOfRiver = true;
             if (t.RiverNSDirection == RiverDirection.NORTH_TO_SOUTH)
                 tt.RiverWEDirection = RiverDirection.EAST_TO_WEST;
             else
                 tt.RiverWEDirection = RiverDirection.WEST_TO_EAST;
         }
     }
     return map2;
 }