Skip to content

Commit 2ec516c

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 5b9dd9d + 3dd9c9e commit 2ec516c

32 files changed

+494
-104
lines changed

src/TSMapEditor/CCEngine/Theater.cs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public Theater(string name)
7777
public List<TileSet> TileSets = new List<TileSet>();
7878
public List<LATGround> LATGrounds = new List<LATGround>();
7979
public TileSet RampTileSet { get; set; }
80+
public TileSet BridgeTileSet { get; set; }
81+
public TileSet TrainBridgeTileSet { get; set; }
82+
public TileSet WoodBridgeTileSet { get; set; }
8083

8184
private const string REQUIRED_SECTION = "General";
8285

@@ -129,13 +132,25 @@ public void ReadConfigINI(string baseDirectoryPath, CCFileManager ccFileManager)
129132
InitLATGround(theaterIni, "CrystalTile", "ClearToCrystalLat", null, null, null, "Crystal");
130133
InitLATGround(theaterIni, "BlueMoldTile", "ClearToBlueMoldLat", null, null, null, "Blue Mold");
131134

132-
int rampTileSetIndex = theaterIni.GetIntValue("General", "RampBase", -1);
133-
if (rampTileSetIndex < 0 || rampTileSetIndex >= TileSets.Count)
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+
}
140+
141+
private TileSet GetTileSetFromKey(IniFile theaterIni, string key, bool optional)
142+
{
143+
int index = theaterIni.GetIntValue("General", key, -1);
144+
145+
if (index < 0 || index >= TileSets.Count)
134146
{
135-
throw new INIConfigException("Invalid value specified for RampBase= in the theater configuration file!");
147+
if (optional)
148+
return null;
149+
150+
throw new INIConfigException($"Invalid value specified for {key}= in the theater configuration file!");
136151
}
137152

138-
RampTileSet = TileSets[rampTileSetIndex];
153+
return TileSets[index];
139154
}
140155

141156
public TileSet TryGetTileSetById(int id)

src/TSMapEditor/CCEngine/TmpFile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ private RGBColor ReadRGBColorFromStream(Stream stream)
201201
public RGBColor RadarRightColor { get; set; }
202202

203203
public byte[] ColorData = new byte[Constants.TileColorBufferSize];
204-
public byte[] ZData = new byte[0];
205-
public byte[] ExtraGraphicsColorData = new byte[0];
206-
public byte[] ExtraGraphicsZData = new byte[0];
204+
public byte[] ZData = Array.Empty<byte>();
205+
public byte[] ExtraGraphicsColorData = Array.Empty<byte>();
206+
public byte[] ExtraGraphicsZData = Array.Empty<byte>();
207207
}
208208

209209
[Flags]

src/TSMapEditor/Constants.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
using Rampastring.Tools;
2-
using System;
32

43
namespace TSMapEditor
54
{
65
public static class Constants
76
{
8-
public const string ReleaseVersion = "1.4.11";
7+
public const string ReleaseVersion = "1.5.0";
98

109
public static int CellSizeX = 48;
1110
public static int CellSizeY = 24;
1211
public const int CellSizeInLeptons = 256;
1312
public static int CellHeight => CellSizeY / 2;
13+
public static int HighBridgeHeight = 4;
1414
public static int TileColorBufferSize = 576;
1515

1616
public static int RenderPixelPadding = 50;
@@ -91,7 +91,7 @@ public static class Constants
9191
public static int MaxHouseTechLevel = 10;
9292

9393
public const int MAX_MAP_LENGTH_IN_DIMENSION = 512;
94-
public const int NO_OVERLAY = 255; // 0xFF
94+
public const int NO_OVERLAY = -1;
9595
public const int OverlayPackFormat = 80;
9696

9797
public const string NoneValue1 = "<none>";

src/TSMapEditor/Initialization/MapLoader.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
using CNCMaps.FileFormats.Encodings;
1+
using CNCMaps.FileFormats.Encodings;
22
using Microsoft.Xna.Framework;
33
using Rampastring.Tools;
44
using System;
5+
using System.Buffers.Binary;
56
using System.Collections.Generic;
67
using System.Globalization;
78
using System.Linq;
@@ -672,10 +673,12 @@ public static void ReadOverlays(IMap map, IniFile mapIni)
672673
if (overlayPackSection == null || overlayDataPackSection == null)
673674
return;
674675

676+
bool needsExtendedOverlayPack = map.Basic.NewINIFormat >= 5;
677+
675678
var stringBuilder = new StringBuilder();
676679
overlayPackSection.Keys.ForEach(kvp => stringBuilder.Append(kvp.Value));
677680
byte[] compressedData = Convert.FromBase64String(stringBuilder.ToString());
678-
byte[] uncompressedOverlayPack = new byte[Constants.MAX_MAP_LENGTH_IN_DIMENSION * Constants.MAX_MAP_LENGTH_IN_DIMENSION];
681+
byte[] uncompressedOverlayPack = new byte[Constants.MAX_MAP_LENGTH_IN_DIMENSION * Constants.MAX_MAP_LENGTH_IN_DIMENSION * (needsExtendedOverlayPack ? 2 : 1)];
679682
Format5.DecodeInto(compressedData, uncompressedOverlayPack, Constants.OverlayPackFormat);
680683

681684
stringBuilder.Clear();
@@ -693,7 +696,19 @@ public static void ReadOverlays(IMap map, IniFile mapIni)
693696
continue;
694697

695698
int overlayDataIndex = (tile.Y * Constants.MAX_MAP_LENGTH_IN_DIMENSION) + tile.X;
696-
int overlayTypeIndex = uncompressedOverlayPack[overlayDataIndex];
699+
700+
int overlayTypeIndex;
701+
if (needsExtendedOverlayPack)
702+
{
703+
ushort index = BinaryPrimitives.ReadUInt16LittleEndian(new ReadOnlySpan<byte>(uncompressedOverlayPack, overlayDataIndex * 2, 2));
704+
overlayTypeIndex = index != ushort.MaxValue ? index : Constants.NO_OVERLAY;
705+
}
706+
else
707+
{
708+
byte index = uncompressedOverlayPack[overlayDataIndex];
709+
overlayTypeIndex = index != byte.MaxValue ? index : Constants.NO_OVERLAY;
710+
}
711+
697712
if (overlayTypeIndex == Constants.NO_OVERLAY)
698713
continue;
699714

src/TSMapEditor/Initialization/MapWriter.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Microsoft.Xna.Framework.Graphics;
44
using Rampastring.Tools;
55
using System;
6+
using System.Buffers.Binary;
67
using System.Collections.Generic;
78
using System.Globalization;
89
using System.Linq;
@@ -117,9 +118,11 @@ public static void WriteOverlays(IMap map, IniFile mapIni)
117118
mapIni.RemoveSection(overlayPackSectionName);
118119
mapIni.RemoveSection(overlayDataPackSectionName);
119120

120-
var overlayArray = new byte[Constants.MAX_MAP_LENGTH_IN_DIMENSION * Constants.MAX_MAP_LENGTH_IN_DIMENSION];
121+
bool needsExtendedOverlayPack = map.Basic.NewINIFormat >= 5;
122+
123+
var overlayArray = new byte[Constants.MAX_MAP_LENGTH_IN_DIMENSION * Constants.MAX_MAP_LENGTH_IN_DIMENSION * (needsExtendedOverlayPack ? 2 : 1)];
121124
for (int i = 0; i < overlayArray.Length; i++)
122-
overlayArray[i] = Constants.NO_OVERLAY;
125+
overlayArray[i] = 0xFF; // fill the entire array with 0xFF, which will be (sbyte)-1 or (short)-1, regardless of what format we're writing in
123126

124127
var overlayDataArray = new byte[Constants.MAX_MAP_LENGTH_IN_DIMENSION * Constants.MAX_MAP_LENGTH_IN_DIMENSION];
125128

@@ -130,7 +133,11 @@ public static void WriteOverlays(IMap map, IniFile mapIni)
130133

131134
int dataIndex = (tile.Y * Constants.MAX_MAP_LENGTH_IN_DIMENSION) + tile.X;
132135

133-
overlayArray[dataIndex] = (byte)tile.Overlay.OverlayType.Index;
136+
if (needsExtendedOverlayPack)
137+
BinaryPrimitives.WriteUInt16LittleEndian(new Span<byte>(overlayArray, dataIndex * 2, 2), (ushort)tile.Overlay.OverlayType.Index);
138+
else
139+
overlayArray[dataIndex] = (byte)tile.Overlay.OverlayType.Index;
140+
134141
overlayDataArray[dataIndex] = (byte)tile.Overlay.FrameIndex;
135142
});
136143

src/TSMapEditor/Models/CellTag.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public CellTag(Point2D position, Tag tag)
1717
Tag = tag;
1818
}
1919

20+
public bool IsOnBridge() => false;
21+
2022
public Point2D Position { get; set; }
2123
public Tag Tag { get; set; }
2224

src/TSMapEditor/Models/EditorConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class EditorConfig
1414
{
1515
public EditorConfig()
1616
{
17-
EditorRulesIni = new IniFile(Environment.CurrentDirectory + "/Config/EditorRules.ini");
17+
EditorRulesIni = Helpers.ReadConfigINI("EditorRules.ini");
1818
}
1919

2020
private const string IniSystemSectionName = "INISystem";

src/TSMapEditor/Models/Foot.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ public Foot(T objectType) : base(objectType) { }
2626
/// Is this unit available for recruitment for TeamTypes that have Autocreate=yes?
2727
/// </summary>
2828
public bool AutocreateYesRecruitable { get; set; }
29+
30+
public override bool IsOnBridge() => High;
2931
}
3032
}

src/TSMapEditor/Models/GameObject.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public override int GetHashCode()
5353

5454
public virtual bool HasShadow() => false;
5555

56+
public virtual bool IsOnBridge() => false;
57+
5658
public virtual Color GetRemapColor() => Color.White;
5759
}
5860
}

src/TSMapEditor/Models/House.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public BaseNode(string structureTypeName, Point2D location)
2121
public string StructureTypeName { get; set; }
2222
public Point2D Position { get; set; }
2323

24+
public bool IsOnBridge() => false;
25+
2426
public static BaseNode FromIniString(string iniString)
2527
{
2628
if (string.IsNullOrWhiteSpace(iniString))

0 commit comments

Comments
 (0)