public static AllodsMap New(int width, int height) { width += 16; height += 16; AllodsMap alm = new AllodsMap(); alm.Data.Width = (uint)width; alm.Data.Height = (uint)height; alm.Data.SolarAngle = -45.0f; alm.Data.TimeOfDay = 0; alm.Data.Darkness = 21; alm.Data.Contrast = 128; alm.Data.UseTiles = 0x1FFF; alm.Data.CountPlayers = 0; alm.Data.CountBuildings = 0; alm.Data.CountUnits = 0; alm.Data.CountTriggers = 0; alm.Data.CountSacks = 0; alm.Data.CountGroups = 0; alm.Data.CountInns = 0; alm.Data.CountShops = 0; alm.Data.CountPointers = 0; alm.Data.CountMusic = 0; alm.Data.Name = ""; alm.Data.RecPlayers = 16; alm.Data.Level = 0; alm.Data.Junk1 = 0; alm.Data.Junk2 = 0; alm.Data.Author = ""; alm.Tiles = new ushort[width * height]; alm.Heights = new sbyte[width * height]; alm.Objects = new byte[width * height]; for (int i = 0; i < width * height; i++) { alm.Tiles[i] = 0x011; // grass alm.Heights[i] = 0; alm.Objects[i] = 0; } return(alm); }
public static AllodsMap LoadFrom(string filename) { try { MemoryStream ms = ResourceManager.OpenRead(filename); BinaryReader msb = new BinaryReader(ms); // first, read in the global header uint alm_signature = msb.ReadUInt32(); uint alm_headersize = msb.ReadUInt32(); uint alm_offsetplayers = msb.ReadUInt32(); uint alm_sectioncount = msb.ReadUInt32(); uint alm_version = msb.ReadUInt32(); if ((alm_signature != 0x0052374D) || (alm_headersize != 0x14) || (alm_sectioncount < 3)) { ms.Close(); return(null); } AllodsMap alm = new AllodsMap(); bool DataLoaded = false; bool TilesLoaded = false; bool HeightsLoaded = false; bool ObjectsLoaded = false; for (uint i = 0; i < alm_sectioncount; i++) { uint sec_junk1 = msb.ReadUInt32(); uint sec_headersize = msb.ReadUInt32(); uint sec_size = msb.ReadUInt32(); uint sec_id = msb.ReadUInt32(); uint sec_junk2 = msb.ReadUInt32(); //Console.WriteLine("id = {0}, junk1 = {1}, junk2 = {2}", sec_id, sec_junk1, sec_junk2); if (sec_id == 0) { alm.Data.LoadFromStream(msb); DataLoaded = true; } else if (sec_id == 1) { if (!DataLoaded) { ms.Close(); return(null); } alm.Tiles = new ushort[alm.Data.Width * alm.Data.Height]; for (uint j = 0; j < alm.Data.Width * alm.Data.Height; j++) { alm.Tiles[j] = msb.ReadUInt16(); } TilesLoaded = true; } else if (sec_id == 2) { if (!TilesLoaded) { ms.Close(); return(null); } alm.Heights = new sbyte[alm.Data.Width * alm.Data.Height]; for (uint j = 0; j < alm.Data.Width * alm.Data.Height; j++) { alm.Heights[j] = msb.ReadSByte(); } HeightsLoaded = true; } else if (sec_id == 3) { if (!HeightsLoaded) { ms.Close(); return(null); } alm.Objects = new byte[alm.Data.Width * alm.Data.Height]; for (uint j = 0; j < alm.Data.Width * alm.Data.Height; j++) { alm.Objects[j] = msb.ReadByte(); } ObjectsLoaded = true; } else { break; } } return(alm); } catch (IOException) { return(null); } }