diff --git a/OpenRA.Game/Exts.cs b/OpenRA.Game/Exts.cs index b371f2f8a3..3cdaffdbeb 100644 --- a/OpenRA.Game/Exts.cs +++ b/OpenRA.Game/Exts.cs @@ -488,6 +488,11 @@ namespace OpenRA return int.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); } + public static byte ParseByte(string s) + { + return byte.Parse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo); + } + public static bool TryParseIntegerInvariant(string s, out int i) { return int.TryParse(s, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out i); diff --git a/OpenRA.Game/Network/Order.cs b/OpenRA.Game/Network/Order.cs index 25b9aca186..9e8c179081 100644 --- a/OpenRA.Game/Network/Order.cs +++ b/OpenRA.Game/Network/Order.cs @@ -129,7 +129,7 @@ namespace OpenRA if (flags.HasField(OrderFields.TargetIsCell)) { var cell = new CPos(r.ReadInt32(), r.ReadInt32(), r.ReadByte()); - var subCell = (SubCell)r.ReadInt32(); + var subCell = (SubCell)r.ReadByte(); if (world != null) target = Target.FromCell(world, cell, subCell); } @@ -311,7 +311,7 @@ namespace OpenRA if (fields.HasField(OrderFields.TargetIsCell)) { w.Write(Target.SerializableCell.Value); - w.Write((int)Target.SerializableSubCell); + w.Write((byte)Target.SerializableSubCell); } else w.Write(Target.SerializablePos); diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 50255f8c63..c3ef7d7ba9 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -292,7 +292,7 @@ namespace OpenRA.Traits Pair[] OccupiedCells(); } - public enum SubCell { Invalid = int.MinValue, Any = int.MinValue / 2, FullCell = 0, First = 1 } + public enum SubCell : byte { Invalid = byte.MaxValue, Any = byte.MaxValue - 1, FullCell = 0, First = 1 } public interface IPositionableInfo : IOccupySpaceInfo { diff --git a/OpenRA.Mods.Common/ActorInitializer.cs b/OpenRA.Mods.Common/ActorInitializer.cs index e3c823d975..6685509307 100644 --- a/OpenRA.Mods.Common/ActorInitializer.cs +++ b/OpenRA.Mods.Common/ActorInitializer.cs @@ -31,10 +31,10 @@ namespace OpenRA.Mods.Common public class SubCellInit : IActorInit { - [FieldFromYamlKey] readonly int value = (int)SubCell.FullCell; + [FieldFromYamlKey] readonly byte value = (byte)SubCell.FullCell; public SubCellInit() { } - public SubCellInit(int init) { value = init; } - public SubCellInit(SubCell init) { value = (int)init; } + public SubCellInit(byte init) { value = init; } + public SubCellInit(SubCell init) { value = (byte)init; } public SubCell Value(World world) { return (SubCell)value; } } diff --git a/OpenRA.Mods.Common/Traits/World/ActorMap.cs b/OpenRA.Mods.Common/Traits/World/ActorMap.cs index 7547d41b10..8837e329db 100644 --- a/OpenRA.Mods.Common/Traits/World/ActorMap.cs +++ b/OpenRA.Mods.Common/Traits/World/ActorMap.cs @@ -297,8 +297,8 @@ namespace OpenRA.Mods.Common.Traits if (!AnyActorsAt(cell)) return map.Grid.DefaultSubCell; - for (var i = (int)SubCell.First; i < map.Grid.SubCellOffsets.Length; i++) - if (i != (int)preferredSubCell && !AnyActorsAt(cell, (SubCell)i, checkIfBlocker)) + for (var i = (byte)SubCell.First; i < map.Grid.SubCellOffsets.Length; i++) + if (i != (byte)preferredSubCell && !AnyActorsAt(cell, (SubCell)i, checkIfBlocker)) return (SubCell)i; return SubCell.Invalid; } diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs index 02f700cb41..9df811f49a 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorLayer.cs @@ -237,7 +237,7 @@ namespace OpenRA.Mods.Common.Traits if (!previews.Any()) return map.Grid.DefaultSubCell; - for (var i = (int)SubCell.First; i < map.Grid.SubCellOffsets.Length; i++) + for (var i = (byte)SubCell.First; i < map.Grid.SubCellOffsets.Length; i++) if (!previews.Any(p => p.Footprint[cell] == (SubCell)i)) return (SubCell)i; diff --git a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs index d5589cb851..91ca9bc87c 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ImportLegacyMapCommand.cs @@ -415,7 +415,7 @@ namespace OpenRA.Mods.Common.UtilityCommands initDict.Add(new FacingInit(255 - facing)); if (section == "INFANTRY") - actor.Add(new SubCellInit(Exts.ParseIntegerInvariant(parts[4]))); + actor.Add(new SubCellInit(Exts.ParseByte(parts[4]))); var actorCount = map.ActorDefinitions.Count;