private static Map LoadMapData(Map map, Stream stream) { if (map.LoadMapData(stream)) return map; else return null; }
public void Serialize(Map map) { Bitmap bitmap = new Bitmap(map.SizeX, map.SizeY, PixelFormat.Format32bppArgb); byte[,] heightData = map.HeightData; short[,] clusterData = map.ClusterData; for (int y = 0; y < map.SizeY; y++) { for (int x = 0; x < map.SizeX; x++) { int color = 255 << 16; if (clusterData != null) color += clusterData[x, y]; color <<= 8; color += heightData[x, y]; bitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(color)); } } bitmap.Save(outstream, imageFormat); }
public void AddMap(Map m) { if (!mapsByName.ContainsKey(m.Name)) { availableMaps.Add(m); mapsByName.Add(m.Name, m); } }
public void Serialize(Map map) { int tileMapOffset = 124; int tileMapLen = map.TilesX * map.TilesY; int heightMapOffset = tileMapOffset + tileMapLen; int heightMapLen = map.SizeX * map.SizeY; int obj3DOffset = heightMapOffset + heightMapLen; int obj3DStructLen = 144; int obj3DNo = map.Objects3D.Count; int obj3DLen = obj3DStructLen * obj3DNo; int obj2DOffset = obj3DOffset + obj3DLen; int obj2DStructLen = 128; int obj2DNo = map.Objects2D.Count; int obj2DLen = obj2DStructLen * obj2DNo; int lightsOffset = obj2DOffset + obj2DLen; int lightsStructLen = 40; int lightsNo = map.LightSources.Count; int lightsLen = lightsStructLen * lightsNo; int particlesOffset = lightsOffset + lightsLen; int particlesStructLen = 104; int particlesNo = map.ParticleObjects.Count; int particlesLen = particlesStructLen * particlesNo; int clustersOffset = particlesOffset + particlesLen; int clustersLen = map.SizeX * map.SizeY; if (map.ClusterData == null) clustersOffset = 0; writer.Write(Encoding.ASCII.GetBytes("elmf")); writer.Write((int)map.TilesX); writer.Write((int)map.TilesY); writer.Write((int)tileMapOffset); writer.Write((int)heightMapOffset); writer.Write((int)obj3DStructLen); writer.Write((int)obj3DNo); writer.Write((int)obj3DOffset); writer.Write((int)obj2DStructLen); writer.Write((int)obj2DNo); writer.Write((int)obj2DOffset); writer.Write((int)lightsStructLen); writer.Write((int)lightsNo); writer.Write((int)lightsOffset); writer.Write((byte)map.Dungeon); writer.Write(new byte[3]); Serialize(map.AmbientColor); writer.Write((int)particlesStructLen); writer.Write((int)particlesNo); writer.Write((int)particlesOffset); writer.Write((int)clustersOffset); writer.Write(new byte[9*4]); if (writer.BaseStream.CanSeek && writer.BaseStream.Position != tileMapOffset) throw new Exception(String.Format("offset out of sync. expected {0}, is {1}", tileMapOffset, writer.BaseStream.Position)); for (int y = 0; y < map.TilesY; y++) for (int x = 0; x < map.TilesX; x++) writer.Write((byte)map.TileData[x, y]); if (writer.BaseStream.CanSeek && writer.BaseStream.Position != heightMapOffset) throw new Exception(String.Format("offset out of sync. expected {0}, is {1}", heightMapOffset, writer.BaseStream.Position)); for (int y = 0; y < map.SizeY; y++) for (int x = 0; x < map.SizeX; x++) writer.Write((byte)map.HeightData[x, y]); if (writer.BaseStream.CanSeek && writer.BaseStream.Position != obj3DOffset) throw new Exception(String.Format("offset out of sync. expected {0}, is {1}", obj3DOffset, writer.BaseStream.Position)); foreach (Object3D obj3d in map.Objects3D) Serialize(obj3d); if (writer.BaseStream.CanSeek && writer.BaseStream.Position != obj2DOffset) throw new Exception(String.Format("offset out of sync. expected {0}, is {1}", obj2DOffset, writer.BaseStream.Position)); foreach (Object2D obj2d in map.Objects2D) Serialize(obj2d); if (writer.BaseStream.CanSeek && writer.BaseStream.Position != lightsOffset) throw new Exception(String.Format("offset out of sync. expected {0}, is {1}", lightsOffset, writer.BaseStream.Position)); foreach (LightSource light in map.LightSources) Serialize(light); if (writer.BaseStream.CanSeek && writer.BaseStream.Position != particlesOffset) throw new Exception(String.Format("offset out of sync. expected {0}, is {1}", particlesOffset, writer.BaseStream.Position)); foreach (ParticleObject particle in map.ParticleObjects) Serialize(particle); if (map.ClusterData != null) { if (writer.BaseStream.CanSeek && writer.BaseStream.Position != clustersOffset) throw new Exception(String.Format("offset out of sync. expected {0}, is {1}", clustersOffset, writer.BaseStream.Position)); for (int y = 0; y < map.SizeY; y++) for (int x = 0; x < map.SizeX; x++) writer.Write((short)map.ClusterData[x, y]); } writer.Close(); }
public void Serialize(Map map) { int i; writer.WriteStartDocument(); writer.WriteComment("Eternal Lands map. Generated from " + map.Name); writer.WriteStartElement("map"); writer.WriteAttributeString("tile_x", map.TilesX.ToString()); writer.WriteAttributeString("tile_y", map.TilesY.ToString()); writer.WriteAttributeString("dungeon", map.Dungeon.ToString()); writer.WriteStartElement("ambient_color"); Serialize(map.AmbientColor); writer.WriteEndElement(); i = 0; writer.WriteStartElement("objects3d"); foreach (Object3D obj3d in map.Objects3D) { writer.WriteStartElement("object3d"); writer.WriteAttributeString("object_id", i.ToString()); Serialize(obj3d); writer.WriteEndElement(); i++; } writer.WriteEndElement(); i = 0; writer.WriteStartElement("objects2d"); foreach (Object2D obj2d in map.Objects2D) { writer.WriteStartElement("object2d"); writer.WriteAttributeString("object_id", i.ToString()); Serialize(obj2d); writer.WriteEndElement(); i++; } writer.WriteEndElement(); i = 0; writer.WriteStartElement("particles"); foreach (ParticleObject particle in map.ParticleObjects) { writer.WriteStartElement("particle"); writer.WriteAttributeString("particle_id", i.ToString()); Serialize(particle); writer.WriteEndElement(); i++; } writer.WriteEndElement(); i = 0; writer.WriteStartElement("lights"); foreach (LightSource light in map.LightSources) { writer.WriteStartElement("light"); writer.WriteAttributeString("light_id", i.ToString()); Serialize(light); writer.WriteEndElement(); i++; } writer.WriteEndElement(); writer.WriteStartElement("tile_data"); for (int y = 0; y < map.TilesY; y++) { StringWriter w = new StringWriter(); for (int x = 0; x < map.TilesX; x++) { w.Write(map.TileData[x, y].ToString("X02")); } w.WriteLine(); writer.WriteString(w.ToString()); } writer.WriteEndElement(); writer.WriteStartElement("height_data"); for (int y = 0; y < map.SizeY; y++) { StringWriter w = new StringWriter(); for (int x = 0; x < map.SizeX; x++) { w.Write(map.HeightData[x, y].ToString("X02")); } w.WriteLine(); writer.WriteString(w.ToString()); } writer.WriteEndElement(); if (map.ClusterData != null) { writer.WriteStartElement("cluster_data"); for (int y = 0; y < map.SizeY; y++) { StringWriter w = new StringWriter(); for (int x = 0; x < map.SizeX; x++) { w.Write(map.ClusterData[x, y].ToString("X04")); } w.WriteLine(); writer.WriteString(w.ToString()); } writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); writer.Close(); }