Skip to content

Commit 325453b

Browse files
committed
Handle RA2/YR WoodBridgeSet if present
1 parent 8aff05b commit 325453b

2 files changed

Lines changed: 27 additions & 14 deletions

File tree

src/TSMapEditor/CCEngine/Theater.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public Theater(string name)
7979
public TileSet RampTileSet { get; set; }
8080
public TileSet BridgeTileSet { get; set; }
8181
public TileSet TrainBridgeTileSet { get; set; }
82+
public TileSet WoodBridgeTileSet { get; set; }
8283

8384
private const string REQUIRED_SECTION = "General";
8485

@@ -131,21 +132,25 @@ public void ReadConfigINI(string baseDirectoryPath, CCFileManager ccFileManager)
131132
InitLATGround(theaterIni, "CrystalTile", "ClearToCrystalLat", null, null, null, "Crystal");
132133
InitLATGround(theaterIni, "BlueMoldTile", "ClearToBlueMoldLat", null, null, null, "Blue Mold");
133134

134-
int rampTileSetIndex = theaterIni.GetIntValue("General", "RampBase", -1);
135-
if (rampTileSetIndex < 0 || rampTileSetIndex >= TileSets.Count)
136-
throw new INIConfigException("Invalid value specified for RampBase= in the theater configuration file!");
135+
RampTileSet = GetTileSetFromKey(theaterIni, "RampBase", false);
136+
BridgeTileSet = GetTileSetFromKey(theaterIni, "BridgeSet", false);
137+
TrainBridgeTileSet = GetTileSetFromKey(theaterIni, "TrainBridgeSet", false);
138+
WoodBridgeTileSet = GetTileSetFromKey(theaterIni, "WoodBridgeSet", true); // Wood bridges are optional as they do not exist in TS
139+
}
137140

138-
int bridgeTileSetIndex = theaterIni.GetIntValue("General", "BridgeSet", -1);
139-
if (bridgeTileSetIndex < 0 || bridgeTileSetIndex >= TileSets.Count)
140-
throw new INIConfigException("Invalid value specified for BridgeSet= in the theater configuration file!");
141+
private TileSet GetTileSetFromKey(IniFile theaterIni, string key, bool optional)
142+
{
143+
int index = theaterIni.GetIntValue("General", key, -1);
141144

142-
int trainBridgeTileSetIndex = theaterIni.GetIntValue("General", "TrainBridgeSet", -1);
143-
if (trainBridgeTileSetIndex < 0 || trainBridgeTileSetIndex >= TileSets.Count)
144-
throw new INIConfigException("Invalid value specified for TrainBridgeSet= in the theater configuration file!");
145+
if (index < 0 || index >= TileSets.Count)
146+
{
147+
if (optional)
148+
return null;
149+
150+
throw new INIConfigException($"Invalid value specified for {key}= in the theater configuration file!");
151+
}
145152

146-
RampTileSet = TileSets[rampTileSetIndex];
147-
BridgeTileSet = TileSets[bridgeTileSetIndex];
148-
TrainBridgeTileSet = TileSets[trainBridgeTileSetIndex];
153+
return TileSets[index];
149154
}
150155

151156
public TileSet TryGetTileSetById(int id)

src/TSMapEditor/Rendering/MapView.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,13 +655,21 @@ public void DrawTerrainTile(MapTile tile)
655655

656656
if (tile.TileImage == null)
657657
{
658+
var theater = TheaterGraphics.Theater;
659+
658660
// Hardcode variant 0 for bridges and train bridges so they don't appear damaged
659661
// Ideally we'd need to check HasDamagedData in the subcell's TmpImage, but that
660-
// would be very messy... gg, Westwood.
661-
if (TheaterGraphics.Theater.BridgeTileSet.ContainsTile(tile.TileIndex) || TheaterGraphics.Theater.TrainBridgeTileSet.ContainsTile(tile.TileIndex))
662+
// would be very messy..
663+
if (theater.BridgeTileSet.ContainsTile(tile.TileIndex) ||
664+
theater.TrainBridgeTileSet.ContainsTile(tile.TileIndex) ||
665+
(theater.WoodBridgeTileSet != null && theater.WoodBridgeTileSet.ContainsTile(tile.TileIndex)))
666+
{
662667
tile.TileImage = TheaterGraphics.GetTileGraphics(tile.TileIndex, 0);
668+
}
663669
else
670+
{
664671
tile.TileImage = TheaterGraphics.GetTileGraphics(tile.TileIndex);
672+
}
665673
}
666674

667675
TileImage tileImage;

0 commit comments

Comments
 (0)