Map Viewer Handlers

This is a sub forum dedicated to an open source map editor.
Don't post in it about another subject

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

Forum rules
This is a sub forum dedicated to an open source map editor.
Don't post in it about another subject

Map Viewer Handlers

Postby rl-1 on Tue Jul 14, 2009 1:38 am

I have made some handlers for the files required to view a map for rose. Right now these handlers only read the data for the files, they do not write it. They are written in C#. Much thanks to xadet and Juan for helping me with my first handlers :D . As I have decided to discontinue my work on this project(namely because I cant get past rendering the heightmaps), I am releasing the handlers here :) . So here they are:

.ZON Handler.
  1.    public class ZONHandler
  2.     {
  3.         public enum BlockType
  4.         {
  5.             Block0,
  6.             SpawnPoints,
  7.             Textures,
  8.             Tiles,
  9.             Economy
  10.         }
  11.         public static string RootName(int type)
  12.         {
  13.             switch (type)
  14.             {
  15.                 case 0:
  16.                     return "Block0";
  17.                 case 1:
  18.                     return "SpawnPoints";
  19.                 case 2:
  20.                     return "Textures";
  21.                 case 3:
  22.                     return "Tiles";
  23.                 case 4:
  24.                     return "Economy";
  25.                 default:
  26.                     return "Unknown";
  27.             }
  28.         }
  29.  
  30.         public enum RotationType
  31.         {
  32.             Normal = 1,
  33.             LeftRight = 2,
  34.             TopBottom = 3,
  35.             LeftRightTopBottom = 4,
  36.             Rotate90Clockwise = 5,
  37.             Rotate90CounterClockwise = 6
  38.         }
  39.  
  40.         public struct Block
  41.         {
  42.             public Int32 Type { get; set; }
  43.             public Int32 Offset { get; set; }
  44.         }
  45.  
  46.         public class Block0
  47.         {
  48.             public struct ZonePart
  49.             {
  50.                 public byte UseMap { get; set; }
  51.                 public float PositionX { get; set; }
  52.                 public float PositionY { get; set; }
  53.             };
  54.             public Int32 ZoneType { get; set; }
  55.             public Int32 ZoneWidth { get; set; }
  56.             public Int32 ZoneHeight { get; set; }
  57.             public Int32 GridCount { get; set; }
  58.             public float GridSize { get; set; }
  59.             public Int32 XCount { get; set; }
  60.             public Int32 YCount { get; set; }
  61.             public ZonePart[,] ZoneParts { get; set; }
  62.         }
  63.  
  64.         public class SpawnPoint
  65.         {
  66.             public float PositionX { get; set; }
  67.             public float PositionZ { get; set; }
  68.             public float PositionY { get; set; }
  69.             public string Name { get; set; }
  70.         }
  71.  
  72.         public class Texture
  73.         {
  74.             public string Path { get; set; }
  75.         }
  76.  
  77.         public class Tile
  78.         {
  79.             public Int32 BaseID1 { get; set; }
  80.             public Int32 BaseID2 { get; set; }
  81.             public Int32 Offset1 { get; set; }
  82.             public Int32 Offset2 { get; set; }
  83.             public Int32 ID1
  84.             {
  85.                 get { return BaseID1 + Offset1; }
  86.             }
  87.             public Int32 ID2
  88.             {
  89.                 get { return BaseID2 + Offset2; }
  90.             }
  91.             public Int32 IsBlending { get; set; }
  92.             public RotationType Rotation { get; set; }
  93.             public Int32 TileType { get; set; }
  94.         }
  95.  
  96.         public class Economy
  97.         {
  98.             public string AreaName { get; set; }
  99.             public Int32 IsUnderground { get; set; }
  100.             public string ButtonBGM { get; set; }
  101.             public string ButtonBack { get; set; }
  102.             public Int32 CheckCount { get; set; }
  103.             public Int32 StandardPopulation { get; set; }
  104.             public Int32 StandardGrowthRate { get; set; }
  105.             public Int32 MetalConsumption { get; set; }
  106.             public Int32 StoneConsumption { get; set; }
  107.             public Int32 WoodConsumption { get; set; }
  108.             public Int32 LeatherConsumption { get; set; }
  109.             public Int32 ClothConsumption { get; set; }
  110.             public Int32 AlchemyConsumption { get; set; }
  111.             public Int32 ChemicalConsumption { get; set; }
  112.             public Int32 IndustrialConsumption { get; set; }
  113.             public Int32 MedicineConsumption { get; set; }
  114.             public Int32 FoodConsumption { get; set; }
  115.         }
  116.  
  117.         public string FilePath { get; set; }
  118.         public Int32 blockCount { get; set; }
  119.         public Block[] Blocks;
  120.  
  121.         public Block0 ZoneInfo { get; set; }
  122.         public List<SpawnPoint> SpawnPoints { get; set; }
  123.         public List<Texture> Textures { get; set; }
  124.         public List<Tile> Tiles { get; set; }
  125.         public Economy EconomyInfo { get; set; }
  126.  
  127.         public void LoadZon(string filePath)
  128.         {
  129.             BinaryReader br = new BinaryReader(File.Open(filePath, FileMode.Open));
  130.  
  131.             blockCount = br.ReadInt32();
  132.             Blocks = new Block[blockCount];
  133.             for (int i = 0; i != blockCount; i++)
  134.             {
  135.                 Blocks[i].Type = br.ReadInt32();
  136.                 Blocks[i].Offset = br.ReadInt32();
  137.             }
  138.  
  139.             for (int i = 0; i != blockCount; i++)
  140.             {
  141.                 br.BaseStream.Seek(Blocks[i].Offset, 0);
  142.  
  143.                 switch (Blocks[i].Type)
  144.                 {
  145.                     case 0:
  146.                         {
  147.                             ZoneInfo = new Block0()
  148.                             {
  149.                                 ZoneType = br.ReadInt32(),
  150.                                 ZoneWidth = br.ReadInt32(),
  151.                                 ZoneHeight = br.ReadInt32(),
  152.                                 GridCount = br.ReadInt32(),
  153.                                 GridSize = br.ReadSingle(),
  154.  
  155.                                 XCount = br.ReadInt32(),
  156.                                 YCount = br.ReadInt32()
  157.                             };
  158.  
  159.                             ZoneInfo.ZoneParts = new Block0.ZonePart[ZoneInfo.ZoneWidth, ZoneInfo.ZoneHeight];
  160.  
  161.                             for (int j = 0; j < ZoneInfo.ZoneWidth; j++)
  162.                             {
  163.                                 for (int k = 0; k < ZoneInfo.ZoneHeight; k++)
  164.                                 {
  165.                                     ZoneInfo.ZoneParts[j, k] = new Block0.ZonePart()
  166.                                     {
  167.                                         UseMap = br.ReadByte(),
  168.                                         PositionX = br.ReadSingle(),
  169.                                         PositionY = br.ReadSingle()
  170.                                     };
  171.                                 }
  172.                             }
  173.                         }
  174.                         break;
  175.                     case 1:
  176.                         {
  177.                             int spawnPointCount = br.ReadInt32();
  178.                             SpawnPoints = new List<SpawnPoint>(spawnPointCount);
  179.  
  180.                             for (int j = 0; j < spawnPointCount; j++)
  181.                             {
  182.                                 SpawnPoints.Add(new SpawnPoint()
  183.                                 {
  184.                                     PositionX = ((br.ReadSingle() + 520000.00f) / 100.00f),
  185.                                     PositionZ = br.ReadSingle() / 100.0f,
  186.                                     PositionY = 5200 + (br.ReadSingle() / 100),
  187.                                     Name = RoseFile.ReadBString(ref br)
  188.                                 });
  189.                             }
  190.                         }
  191.                         break;
  192.                     case 2:
  193.                         {
  194.                             int textureCount = br.ReadInt32();
  195.                             Textures = new List<Texture>(textureCount);
  196.  
  197.                             for (int j = 0; j < textureCount; j++)
  198.                             {
  199.                                 Textures.Add(new Texture()
  200.                                 {
  201.                                     Path = RoseFile.ReadBString(ref br)
  202.                                 });
  203.                             }
  204.                         }
  205.                         break;
  206.                     case 3:
  207.                         {
  208.                             int tileCount = br.ReadInt32();
  209.                             Tiles = new List<Tile>(tileCount);
  210.  
  211.                             for (int j = 0; j < tileCount; j++)
  212.                             {
  213.                                 Tiles.Add(new Tile()
  214.                                 {
  215.                                     BaseID1 = br.ReadInt32(),
  216.                                     BaseID2 = br.ReadInt32(),
  217.                                     Offset1 = br.ReadInt32(),
  218.                                     Offset2 = br.ReadInt32(),
  219.                                     IsBlending = br.ReadInt32(),
  220.                                     Rotation = (RotationType)br.ReadInt32(),
  221.                                     TileType = br.ReadInt32()
  222.                                 });
  223.                             }
  224.                         }
  225.                         break;
  226.                     case 4:
  227.                         {
  228.                             EconomyInfo = new Economy()
  229.                             {
  230.                                 AreaName = RoseFile.ReadBString(ref br),
  231.                                 IsUnderground = br.ReadInt32(),
  232.                                 ButtonBGM = RoseFile.ReadBString(ref br),
  233.                                 ButtonBack = RoseFile.ReadBString(ref br),
  234.                                 CheckCount = br.ReadInt32(),
  235.                                 StandardPopulation = br.ReadInt32(),
  236.                                 StandardGrowthRate = br.ReadInt32(),
  237.                                 MetalConsumption = br.ReadInt32(),
  238.                                 StoneConsumption = br.ReadInt32(),
  239.                                 WoodConsumption = br.ReadInt32(),
  240.                                 LeatherConsumption = br.ReadInt32(),
  241.                                 ClothConsumption = br.ReadInt32(),
  242.                                 AlchemyConsumption = br.ReadInt32(),
  243.                                 ChemicalConsumption = br.ReadInt32(),
  244.                                 IndustrialConsumption = br.ReadInt32(),
  245.                                 MedicineConsumption = br.ReadInt32(),
  246.                                 FoodConsumption = br.ReadInt32()
  247.                             };
  248.                         }
  249.                         break;
  250.                 }
  251.             }
  252.             br.Close();
  253.         }
  254.     }
  255.     public class RoseFile
  256.     {
  257.         public static string ReadBString(ref BinaryReader br)
  258.         {
  259.  
  260.             int strlen = br.ReadByte();
  261.  
  262.             if ((strlen > 128))
  263.             {
  264.  
  265.                 strlen = strlen | (br.ReadByte() << 7);
  266.  
  267.             }
  268.  
  269.             return System.Text.Encoding.UTF8.GetString(br.ReadBytes(strlen));
  270.  
  271.         }
  272.     }


.HIM Handler
  1.    public class HIMHandler
  2.     {
  3.         public Int32 WIDTH { get; set; }
  4.         public Int32 HEIGHT { get; set; }
  5.         public Int32 gridCount { get; set; }
  6.         public float gridSize { get; set; }
  7.         public float[,] heightData { get; set; }
  8.  
  9.         public void LoadHIM(string filePath)
  10.         {
  11.  
  12.             BinaryReader br = new BinaryReader(File.Open(filePath, FileMode.Open));
  13.  
  14.             HEIGHT = br.ReadInt32();
  15.             WIDTH = br.ReadInt32();
  16.             gridCount = br.ReadInt32();
  17.             gridSize = br.ReadSingle();
  18.             heightData = new float[WIDTH, HEIGHT];
  19.  
  20.             for (int i = 0; i < WIDTH; i++)
  21.             {
  22.  
  23.                 for (int y = 0; y < HEIGHT; y++)
  24.                 {
  25.                     float height = (br.ReadSingle() / 100);
  26.                     heightData[WIDTH - 1 - i, HEIGHT - 1 - y] = height;
  27.                 }
  28.             }
  29.             br.Close();
  30.         }
  31.     }


.TIL Handler
  1. public class TILHandler
  2.     {
  3.         public Int32 width { get; set; }
  4.         public Int32 height { get; set; }
  5.         public tilData[,] TILData { get; set; }
  6.  
  7.         public struct tilData
  8.         {
  9.             public byte BrushId { get; set; }
  10.             public byte tileIndex { get; set; }
  11.             public byte tileSetNumber { get; set; }
  12.             public byte tileID { get; set; }
  13.         }
  14.  
  15.         public void LoadTIL(string filePath)
  16.         {
  17.             BinaryReader br = new BinaryReader(File.Open(filePath, FileMode.Open));
  18.             width = br.ReadInt32();
  19.             height = br.ReadInt32();
  20.             TILData = new tilData[width, height];
  21.             for (int i = 0; i < height; i++)
  22.             {
  23.                 for (int y = 0; y < width; y++)
  24.                 {
  25.                     byte BrushId = br.ReadByte();
  26.                     TILData[width - 1 - y, height - 1 - i].BrushId = BrushId;
  27.                     byte tileIndex = br.ReadByte();
  28.                     TILData[width - 1 - y, height - 1 - i].tileIndex = tileIndex;
  29.                     byte tileSetNumber = br.ReadByte();
  30.                     TILData[width - 1 - y, height - 1 - i].tileSetNumber = tileSetNumber;
  31.                     byte tileID = br.ReadByte();
  32.                     TILData[width - 1 - y, height - 1 - i].tileID = tileID;
  33.                 }
  34.             }
  35.             br.Close();
  36.         }
  37.     }


If you find any problems with this code, just let me know. As of now I am only certain that the .ZON and .HIM work properly. Although the .HIM doesn't read the max heights or the quad data, it works for rendering the scene. If anyone wants to pick up on this project, please feel free to! Also if you need any help understanding the handlers, just give me a PM!
rl-1
Pomic
Pomic
 
Posts: 109
Joined: Wed Oct 03, 2007 4:00 am
Location: Illinois

Re: Map Viewer Handlers

Postby Juan on Tue Jul 14, 2009 10:17 am

Nice release ;)
User avatar
Juan
Rackie
Rackie
 
Posts: 219
Joined: Fri Oct 10, 2008 6:25 pm

Re: Map Viewer Handlers

Postby T-Grave on Tue Jul 14, 2009 10:13 pm

Awesome release!

Too bad I'm too busy with osirose, moving my stuff to new house and my new temporary job to help on the map editor.

But I read in the main topic someone was already working on it and is planning on releasing it and making is os(if I remember correctly :p)
T-Grave
osiRose dev
osiRose dev
 
Posts: 211
Joined: Sun Jun 07, 2009 2:06 pm
Location: Belgium

Re: Map Viewer Handlers

Postby rl-1 on Tue Jul 14, 2009 10:19 pm

T-Grave wrote:Awesome release!

Too bad I'm too busy with osirose, moving my stuff to new house and my new temporary job to help on the map editor.

But I read in the main topic someone was already working on it and is planning on releasing it and making is os(if I remember correctly :p)

That was Kazuki and we found out he steals peoples work and calls it his own....so I dont expect him to be releasing anything(or even allowed to release anything)....
rl-1
Pomic
Pomic
 
Posts: 109
Joined: Wed Oct 03, 2007 4:00 am
Location: Illinois

Re: Map Viewer Handlers

Postby T-Grave on Tue Jul 14, 2009 10:24 pm

Oh, too bad, stealing other peoples work and calling it your own is as low as you can go...

In that case I hope someone picks up the development of this project...
rl-1, did you commit anything to the svn?
T-Grave
osiRose dev
osiRose dev
 
Posts: 211
Joined: Sun Jun 07, 2009 2:06 pm
Location: Belgium

Re: Map Viewer Handlers

Postby rl-1 on Tue Jul 14, 2009 10:33 pm

Nah, didn't really get far enough to commit anything, lol.
rl-1
Pomic
Pomic
 
Posts: 109
Joined: Wed Oct 03, 2007 4:00 am
Location: Illinois


Return to [Project] Map Editor

Who is online

Users browsing this forum: No registered users and 2 guests

cron