public static void Init(MapTheater tData) { var mixFiles = new List<String>() { String.Format("{0:s}.MIX", tData.mixName), String.Format("{0:s}MD.MIX", tData.mixName), String.Format("{0:s}.MIX", tData.isoName1), String.Format("{0:s}MD.MIX", tData.isoName2), String.Format("{0:s}.MIX", tData.Extension), }; if (CurrentTheater != tData) { if (CurrentTheater != null) { CurrentTheater.Mixes.ForEach(M => FileSystem.UnloadMIX(M)); CurrentTheater.Mixes.Clear(); } CurrentTheater = tData; IsoTileTypeClass.TheaterChanged(); foreach (var mixName in mixFiles) { var M = FileSystem.LoadMIX(mixName); if (M != null) { CurrentTheater.Mixes.Add(M); } } String PalName = String.Format("ISO{0}.PAL", CurrentTheater.Extension); var PalStream = FileSystem.LoadFile(PalName); if (PalStream != null) { isoPAL = new PAL(PalStream); } else { isoPAL = null; } PalName = String.Format("UNIT{0}.PAL", CurrentTheater.Extension); PalStream = FileSystem.LoadFile(PalName); if (PalStream != null) { unitPAL = new PAL(PalStream); } else { unitPAL = null; } PalName = "TEMPERAT.PAL"; PalStream = FileSystem.LoadFile(PalName); if (PalStream != null) { TemperatePAL = new PAL(PalStream); } else { TemperatePAL = null; } } }
public static void LoadListFromINI(MapTheater TheaterData, bool arg) { String IniName = String.Format("{0}MD.INI", TheaterData.mixName); var INIStream = FileSystem.LoadFile(IniName); var isoINI = new INI(INIStream); int negative = -1; foreach (var lookup in TilesetIndices) { isoINI.GetInteger("General", lookup.Value.Name, out lookup.Value.TilesetIndex, negative); } int tsetIdx = 0; while (true) { String TilesetSection = String.Format("TileSet{0:d4}", tsetIdx); if (!isoINI.SectionExists(TilesetSection)) { break; } var tsCfg = new TilesetConfig() { TilesInSet = -1 }; isoINI.GetInteger(TilesetSection, "TilesInSet", out tsCfg.TilesInSet, negative); if (tsCfg.TilesInSet == -1) { break; } foreach (var lookup in TilesetIndices) { if (tsetIdx == lookup.Value.TilesetIndex) { lookup.Value.TileIndex = All.Count; } } ++tsetIdx; isoINI.GetString(TilesetSection, "SetName", out tsCfg.SetName, "No Name"); isoINI.GetString(TilesetSection, "FileName", out tsCfg.FileName, "TILE"); isoINI.GetInteger(TilesetSection, "MarbleMadness", out tsCfg.MarbleMadness, 65535); isoINI.GetInteger(TilesetSection, "NonMarbleMadness", out tsCfg.NonMarbleMadness, 65535); isoINI.GetBool(TilesetSection, "Morphable", out tsCfg.Morphable, false); isoINI.GetBool(TilesetSection, "AllowToPlace", out tsCfg.AllowToPlace, true); isoINI.GetBool(TilesetSection, "AllowBurrowing", out tsCfg.AllowBurrowing, true); isoINI.GetBool(TilesetSection, "AllowTiberium", out tsCfg.AllowTiberium, false); isoINI.GetBool(TilesetSection, "RequiredForRMG", out tsCfg.RequiredForRMG, false); isoINI.GetInteger(TilesetSection, "ToSnowTheater", out tsCfg.ToSnowTheater, -1); isoINI.GetInteger(TilesetSection, "ToTemperateTheater", out tsCfg.ToTemperateTheater, -1); isoINI.GetBool(TilesetSection, "ShadowCaster", out tsCfg.ShadowCaster, false); if (tsCfg.ShadowCaster) { isoINI.GetInteger(TilesetSection, "ShadowTiles", out tsCfg.ShadowTiles, 0); } for (var i = 1; i <= tsCfg.TilesInSet; ++i) { var TileFnameBase = String.Format("{0:s}{1:d2}", tsCfg.FileName, i); var variation = 0; var exists = false; IsoTileTypeClass curTile = null; do { var TileFname = String.Format("{0:s}{1:s}.{2:s}", TileFnameBase, GetSuffix(variation), TheaterData.Extension); ++variation; var tileFile = FileSystem.LoadFile(TileFname); if (tileFile == null) { exists = false; } else { var tileVariation = new IsoTileTypeClass() { cfg = tsCfg, IndexInTileset = i, AllowBurrowing = tsCfg.AllowBurrowing, AllowTiberium = tsCfg.AllowTiberium, AllowToPlace = tsCfg.AllowToPlace, Morphable = tsCfg.Morphable, RequiredForRMG = tsCfg.RequiredForRMG, ToSnowTheater = tsCfg.ToSnowTheater, ToTemperateTheater = tsCfg.ToTemperateTheater, }; try { var tmpVariation = new TMP(tileFile); tileVariation.Tile = tmpVariation; if (curTile == null) { curTile = tileVariation; } else { curTile.NextVariation = tileVariation; } exists = true; } catch (ArgumentException) { // bleh, broken file } } if (curTile == null) { Debug.WriteLine("Failed to load tile {0}{1}", TileFname, "."); } } while (exists); All.Add(curTile); } } }
public static void Init(MapTheater tData) { var mixFiles = new List <String>() { String.Format("{0:s}.MIX", tData.mixName), String.Format("{0:s}MD.MIX", tData.mixName), String.Format("{0:s}.MIX", tData.isoName1), String.Format("{0:s}MD.MIX", tData.isoName2), String.Format("{0:s}.MIX", tData.Extension), }; if (CurrentTheater != tData) { if (CurrentTheater != null) { CurrentTheater.Mixes.ForEach(M => FileSystem.UnloadMIX(M)); CurrentTheater.Mixes.Clear(); } CurrentTheater = tData; IsoTileTypeClass.TheaterChanged(); foreach (var mixName in mixFiles) { var M = FileSystem.LoadMIX(mixName); if (M != null) { CurrentTheater.Mixes.Add(M); } } String PalName = String.Format("ISO{0}.PAL", CurrentTheater.Extension); var PalStream = FileSystem.LoadFile(PalName); if (PalStream != null) { isoPAL = new PAL(PalStream); } else { isoPAL = null; } PalName = String.Format("UNIT{0}.PAL", CurrentTheater.Extension); PalStream = FileSystem.LoadFile(PalName); if (PalStream != null) { unitPAL = new PAL(PalStream); } else { unitPAL = null; } PalName = "TEMPERAT.PAL"; PalStream = FileSystem.LoadFile(PalName); if (PalStream != null) { TemperatePAL = new PAL(PalStream); } else { TemperatePAL = null; } } }
public void Initialize(String filename = null) { if (filename != null) { MapFile = new MAP(FileSystem.LoadFile(filename)); } ClearCells(); String TheaterName = ""; MapFile.GetString("Map", "Theater", out TheaterName, ""); if (!MapTheater.Theaters.ContainsKey(TheaterName)) { throw new InvalidDataException(String.Format("Theater {0} is not recognized.", TheaterName)); } MapFile.GetInteger("Map", "Level", out BaseLevel, 0); int[] sz = new int[4]; if (MapFile.Get4Integers("Map", "Size", out sz, new int[4])) { MapSize = new Rectangle() { X = sz[0], Y = sz[1], Width = sz[2], Height = sz[3] }; MapRect = MapSize; CreateMap(); } if(MapFile.Get4Integers("Map", "LocalSize", out sz, sz)) { LocalSize = new Rectangle() { X = sz[0], Y = sz[1], Width = sz[2], Height = sz[3] }; } TheaterData = MapTheater.Theaters[TheaterName]; MapTheater.Init(TheaterData); foreach (var packedTile in MapFile.Tiles) { var x = packedTile.X; var y = packedTile.Y; var cell = GetCellAt(x, y); if (cell != null) { cell.IsoTileTypeIndex = (int)packedTile.TileTypeIndex; cell.IsoTileTypeSubIndex = (int)packedTile.TileSubtypeIndex; cell.Level = BaseLevel + packedTile.Level; } else { Debug.WriteLine("Failed to find cell at {0}x{1}", x, y); } } for(var y = 0; y < 512; ++y) { for (var x = 0; x < 512; ++x) { var cell = GetCellAt(x, y); if (cell != null) { var idx = (MapFile.Overlays[y * 512 + x] & 0xFF); if (idx != 0xFF) { cell.OverlayTypeIndex = idx; } cell.OverlayState = MapFile.OverlayStates[y * 512 + x]; } } } }
public void Initialize(String filename = null) { if (filename != null) { MapFile = new MAP(FileSystem.LoadFile(filename)); } ClearCells(); String TheaterName = ""; MapFile.GetString("Map", "Theater", out TheaterName, ""); if (!MapTheater.Theaters.ContainsKey(TheaterName)) { throw new InvalidDataException(String.Format("Theater {0} is not recognized.", TheaterName)); } MapFile.GetInteger("Map", "Level", out BaseLevel, 0); int[] sz = new int[4]; if (MapFile.Get4Integers("Map", "Size", out sz, new int[4])) { MapSize = new Rectangle() { X = sz[0], Y = sz[1], Width = sz[2], Height = sz[3] }; MapRect = MapSize; CreateMap(); } if (MapFile.Get4Integers("Map", "LocalSize", out sz, sz)) { LocalSize = new Rectangle() { X = sz[0], Y = sz[1], Width = sz[2], Height = sz[3] }; } TheaterData = MapTheater.Theaters[TheaterName]; MapTheater.Init(TheaterData); foreach (var packedTile in MapFile.Tiles) { var x = packedTile.X; var y = packedTile.Y; var cell = GetCellAt(x, y); if (cell != null) { cell.IsoTileTypeIndex = (int)packedTile.TileTypeIndex; cell.IsoTileTypeSubIndex = (int)packedTile.TileSubtypeIndex; cell.Level = BaseLevel + packedTile.Level; } else { Debug.WriteLine("Failed to find cell at {0}x{1}", x, y); } } for (var y = 0; y < 512; ++y) { for (var x = 0; x < 512; ++x) { var cell = GetCellAt(x, y); if (cell != null) { var idx = (MapFile.Overlays[y * 512 + x] & 0xFF); if (idx != 0xFF) { cell.OverlayTypeIndex = idx; } cell.OverlayState = MapFile.OverlayStates[y * 512 + x]; } } } }