Skip to content

Commit

Permalink
Merge branch 'bleed' of https://github.com/OpenRA/OpenRA into color-p…
Browse files Browse the repository at this point in the history
…icker-update2
  • Loading branch information
drogoganor committed Mar 17, 2018
2 parents 806f69e + 65c42a6 commit bc2eaf1
Show file tree
Hide file tree
Showing 113 changed files with 1,470 additions and 566 deletions.
39 changes: 39 additions & 0 deletions .github/ISSUE_TEMPLATE.md
@@ -0,0 +1,39 @@
<!--
This is a guideline, which shall help to write enhancement requests or bug reports.
Fill in the placeholders below. Delete any headings and placeholders that you do not use.
Before you start check if a similar request/bug report already exists in this Github issue tracker and comment there.
When submitting a feature or enhancement request:
1. Explain briefly what the enhancement is and why you think it would be useful.
2. Provide any other necessary or useful information regarding your issue, such as (code) examples or related links.
When submitting a bug report, please follow the template below:
-->

### Issue Summary
<!-- Explanation of the issue. Expectation vs. actual behavior. -->
... ... ...

#### System Information
- **Operating System:** [e.g. Windows 10, Mac OS 10.12, Ubuntu 16.04, ...]
- **.NET / Mono Version:** [e.g. .NET 4.7.1, Mono 4.6.2, ...]
- **OpenRA Version:** [e.g. release-20180218, playtest-20180208, ...]
- **Mod:** [e.g. Red Alert, Tiberian Dawn, Dune2000, ...]

#### Additional Information:
- Steps to reproduce
1. Step
2. Step
3. ...

- Logs
<!-- If you have a log (e.g. debug.log, exception.log), zip and attach it. -->

- OpenRA Replays
<!-- You have to zip it before you can attach it. When does the issue appear [e.g. 10:33]? -->

- Screenshots & Videos
<!-- You should be able to attach screenshots by drag&drop. Videos need to be uploaded to an external platform (e.g. https://www.youtube.com, https://www.dropbox.com) -->
4 changes: 2 additions & 2 deletions OpenRA.Game/Actor.cs
Expand Up @@ -321,12 +321,12 @@ public void InflictDamage(Actor attacker, Damage damage)
health.InflictDamage(this, attacker, damage, false);
}

public void Kill(Actor attacker)
public void Kill(Actor attacker, HashSet<string> damageTypes = null)
{
if (Disposed || health == null)
return;

health.Kill(this, attacker);
health.Kill(this, attacker, damageTypes);
}

public bool CanBeViewedByPlayer(Player player)
Expand Down
20 changes: 20 additions & 0 deletions OpenRA.Game/FieldLoader.cs
Expand Up @@ -475,6 +475,23 @@ public static object GetValue(string fieldName, Type fieldType, MiniYaml yaml, M
}
else if (fieldType == typeof(bool))
return ParseYesNo(value, fieldType, fieldName);
else if (fieldType == typeof(int2[]))
{
if (value != null)
{
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length % 2 != 0)
return InvalidValueAction(value, fieldType, fieldName);

var ints = new int2[parts.Length / 2];
for (var i = 0; i < ints.Length; i++)
ints[i] = new int2(Exts.ParseIntegerInvariant(parts[2 * i]), Exts.ParseIntegerInvariant(parts[2 * i + 1]));

return ints;
}

return InvalidValueAction(value, fieldType, fieldName);
}
else if (fieldType.IsArray && fieldType.GetArrayRank() == 1)
{
if (value == null)
Expand Down Expand Up @@ -531,6 +548,9 @@ public static object GetValue(string fieldName, Type fieldType, MiniYaml yaml, M
if (value != null)
{
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length != 2)
return InvalidValueAction(value, fieldType, fieldName);

return new int2(Exts.ParseIntegerInvariant(parts[0]), Exts.ParseIntegerInvariant(parts[1]));
}

Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Game.cs
Expand Up @@ -243,7 +243,7 @@ public static bool IsHost

public static void InitializeSettings(Arguments args)
{
Settings = new Settings(Platform.ResolvePath(Path.Combine("^", "settings.yaml")), args);
Settings = new Settings(Platform.ResolvePath(Path.Combine(Platform.SupportDirPrefix, "settings.yaml")), args);
}

public static RunStatus InitializeAndRun(string[] args)
Expand Down Expand Up @@ -528,7 +528,7 @@ static void TakeScreenshotInner()
ThreadPool.QueueUserWorkItem(_ =>
{
var mod = ModData.Manifest.Metadata;
var directory = Platform.ResolvePath("^", "Screenshots", ModData.Manifest.Id, mod.Version);
var directory = Platform.ResolvePath(Platform.SupportDirPrefix, "Screenshots", ModData.Manifest.Id, mod.Version);
Directory.CreateDirectory(directory);
var filename = TimestampedFilename(true);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Map/MapCache.cs
Expand Up @@ -70,7 +70,7 @@ public void LoadMaps()
try
{
// HACK: If the path is inside the the support directory then we may need to create it
if (name.StartsWith("^", StringComparison.Ordinal))
if (Platform.IsPathRelativeToSupportDirectory(name))
{
// Assume that the path is a directory if there is not an existing file with the same name
var resolved = Platform.ResolvePath(name);
Expand Down Expand Up @@ -144,7 +144,7 @@ public IEnumerable<Map> EnumerateMapsWithoutCaching(MapClassification classifica
name = name.Substring(1);

// Don't try to open the map directory in the support directory if it doesn't exist
if (name.StartsWith("^", StringComparison.Ordinal))
if (Platform.IsPathRelativeToSupportDirectory(name))
{
var resolved = Platform.ResolvePath(name);
if (!Directory.Exists(resolved) || !File.Exists(resolved))
Expand Down
8 changes: 6 additions & 2 deletions OpenRA.Game/Map/MapGrid.cs
Expand Up @@ -89,8 +89,12 @@ public MapGrid(MiniYaml yaml)
var defaultSubCellIndex = (byte)DefaultSubCell;
if (defaultSubCellIndex == byte.MaxValue)
DefaultSubCell = (SubCell)(SubCellOffsets.Length / 2);
else if (defaultSubCellIndex < (SubCellOffsets.Length > 1 ? 1 : 0) || defaultSubCellIndex >= SubCellOffsets.Length)
throw new InvalidDataException("Subcell default index must be a valid index into the offset triples and must be greater than 0 for mods with subcells");
else
{
var minSubCellOffset = SubCellOffsets.Length > 1 ? 1 : 0;
if (defaultSubCellIndex < minSubCellOffset || defaultSubCellIndex >= SubCellOffsets.Length)
throw new InvalidDataException("Subcell default index must be a valid index into the offset triples and must be greater than 0 for mods with subcells");
}

var makeCorners = Type == MapGridType.RectangularIsometric ?
(Func<int[], WVec[]>)IsometricCellCorners : RectangularCellCorners;
Expand Down
24 changes: 12 additions & 12 deletions OpenRA.Game/Network/Connection.cs
Expand Up @@ -60,26 +60,26 @@ public virtual ConnectionState ConnectionState
public virtual void Send(int frame, List<byte[]> orders)
{
var ms = new MemoryStream();
ms.Write(BitConverter.GetBytes(frame));
ms.WriteArray(BitConverter.GetBytes(frame));
foreach (var o in orders)
ms.Write(o);
ms.WriteArray(o);
Send(ms.ToArray());
}

public virtual void SendImmediate(List<byte[]> orders)
{
var ms = new MemoryStream();
ms.Write(BitConverter.GetBytes(0));
ms.WriteArray(BitConverter.GetBytes(0));
foreach (var o in orders)
ms.Write(o);
ms.WriteArray(o);
Send(ms.ToArray());
}

public virtual void SendSync(int frame, byte[] syncData)
{
var ms = new MemoryStream(4 + syncData.Length);
ms.Write(BitConverter.GetBytes(frame));
ms.Write(syncData);
ms.WriteArray(BitConverter.GetBytes(frame));
ms.WriteArray(syncData);
Send(ms.GetBuffer());
}

Expand Down Expand Up @@ -198,8 +198,8 @@ void NetworkConnectionReceive(object networkStreamObject)
public override void SendSync(int frame, byte[] syncData)
{
var ms = new MemoryStream(4 + syncData.Length);
ms.Write(BitConverter.GetBytes(frame));
ms.Write(syncData);
ms.WriteArray(BitConverter.GetBytes(frame));
ms.WriteArray(syncData);
queuedSyncPackets.Add(ms.GetBuffer());
}

Expand All @@ -210,13 +210,13 @@ protected override void Send(byte[] packet)
try
{
var ms = new MemoryStream();
ms.Write(BitConverter.GetBytes(packet.Length));
ms.Write(packet);
ms.WriteArray(BitConverter.GetBytes(packet.Length));
ms.WriteArray(packet);

foreach (var q in queuedSyncPackets)
{
ms.Write(BitConverter.GetBytes(q.Length));
ms.Write(q);
ms.WriteArray(BitConverter.GetBytes(q.Length));
ms.WriteArray(q);
base.Send(q);
}

Expand Down
5 changes: 0 additions & 5 deletions OpenRA.Game/Network/OrderIO.cs
Expand Up @@ -16,11 +16,6 @@ namespace OpenRA.Network
{
public static class OrderIO
{
public static void Write(this Stream s, byte[] buf)
{
s.Write(buf, 0, buf.Length);
}

public static List<Order> ToOrderList(this byte[] bytes, World world)
{
var ms = new MemoryStream(bytes, 4, bytes.Length - 4);
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Network/ReplayConnection.cs
Expand Up @@ -128,8 +128,8 @@ public ReplayConnection(string replayFilename)
public void SendSync(int frame, byte[] syncData)
{
var ms = new MemoryStream(4 + syncData.Length);
ms.Write(BitConverter.GetBytes(frame));
ms.Write(syncData);
ms.WriteArray(BitConverter.GetBytes(frame));
ms.WriteArray(syncData);
sync.Add(ms.GetBuffer());

// Store the current frame so Receive() can return the next chunk of orders.
Expand Down
4 changes: 2 additions & 2 deletions OpenRA.Game/Network/ReplayRecorder.cs
Expand Up @@ -45,7 +45,7 @@ void StartSavingReplay(byte[] initialContent)
{
var filename = chooseFilename();
var mod = Game.ModData.Manifest;
var dir = Platform.ResolvePath("^", "Replays", mod.Id, mod.Metadata.Version);
var dir = Platform.ResolvePath(Platform.SupportDirPrefix, "Replays", mod.Id, mod.Metadata.Version);

if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
Expand All @@ -63,7 +63,7 @@ void StartSavingReplay(byte[] initialContent)
catch (IOException) { }
}

file.Write(initialContent);
file.WriteArray(initialContent);
writer = new BinaryWriter(file);
}

Expand Down
25 changes: 20 additions & 5 deletions OpenRA.Game/Platform.cs
Expand Up @@ -21,6 +21,7 @@ public enum PlatformType { Unknown, Windows, OSX, Linux }

public static class Platform
{
public const string SupportDirPrefix = "^";
public static PlatformType CurrentPlatform { get { return currentPlatform.Value; } }
public static readonly Guid SessionGUID = Guid.NewGuid();

Expand Down Expand Up @@ -143,7 +144,7 @@ public static string ResolvePath(string path)
path = path.TrimEnd(' ', '\t');

// Paths starting with ^ are relative to the support dir
if (path.StartsWith("^", StringComparison.Ordinal))
if (IsPathRelativeToSupportDirectory(path))
path = SupportDir + path.Substring(1);

// Paths starting with . are relative to the game dir
Expand All @@ -162,16 +163,30 @@ public static string ResolvePath(params string[] path)
return ResolvePath(path.Aggregate(Path.Combine));
}

/// <summary>Replace the full path prefix with the special notation characters ^ or .</summary>
/// <summary>
/// Replace the full path prefix with the special notation characters ^ or .
/// and transforms \ path separators to / on Windows
/// </summary>
public static string UnresolvePath(string path)
{
if (path.StartsWith(SupportDir, StringComparison.Ordinal))
path = "^" + path.Substring(SupportDir.Length);
// Use a case insensitive comparison on windows to avoid problems
// with inconsistent drive letter case
var compare = CurrentPlatform == PlatformType.Windows ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal;
if (path.StartsWith(SupportDir, compare))
path = SupportDirPrefix + path.Substring(SupportDir.Length);

if (path.StartsWith(GameDir, StringComparison.Ordinal))
if (path.StartsWith(GameDir, compare))
path = "./" + path.Substring(GameDir.Length);

if (CurrentPlatform == PlatformType.Windows)
path = path.Replace('\\', '/');

return path;
}

public static bool IsPathRelativeToSupportDirectory(string path)
{
return path.StartsWith(SupportDirPrefix, StringComparison.Ordinal);
}
}
}
2 changes: 1 addition & 1 deletion OpenRA.Game/Server/Connection.cs
Expand Up @@ -55,7 +55,7 @@ bool ReadDataInner(Server server)
// from `socket.Receive(rx)`.
if (!Socket.Poll(0, SelectMode.SelectRead)) break;

if (0 < (len = Socket.Receive(rx)))
if ((len = Socket.Receive(rx)) > 0)
Data.AddRange(rx.Take(len));
else
{
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Server/Server.cs
Expand Up @@ -384,7 +384,7 @@ void ValidateClient(Connection newConn, string data)

if (Dedicated)
{
var motdFile = Platform.ResolvePath("^", "motd.txt");
var motdFile = Platform.ResolvePath(Platform.SupportDirPrefix, "motd.txt");
if (!File.Exists(motdFile))
File.WriteAllText(motdFile, "Welcome, have fun and good luck!");

Expand Down
8 changes: 5 additions & 3 deletions OpenRA.Game/StreamExts.cs
Expand Up @@ -81,7 +81,7 @@ public static int ReadInt32(this Stream s)

public static void Write(this Stream s, int value)
{
s.Write(BitConverter.GetBytes(value));
s.WriteArray(BitConverter.GetBytes(value));
}

public static float ReadFloat(this Stream s)
Expand Down Expand Up @@ -131,7 +131,9 @@ public static byte[] ReadAllBytes(this Stream s)
}
}

public static void Write(this Stream s, byte[] data)
// Note: renamed from Write() to avoid being aliased by
// System.IO.Stream.Write(System.ReadOnlySpan) (which is not implemented in Mono)
public static void WriteArray(this Stream s, byte[] data)
{
s.Write(data, 0, data.Length);
}
Expand Down Expand Up @@ -166,7 +168,7 @@ public static int WriteString(this Stream s, Encoding encoding, string text)
bytes = new byte[0];

s.Write(bytes.Length);
s.Write(bytes);
s.WriteArray(bytes);

return 4 + bytes.Length;
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Traits/TraitsInterfaces.cs
Expand Up @@ -42,7 +42,7 @@ public interface IHealth
bool IsDead { get; }

void InflictDamage(Actor self, Actor attacker, Damage damage, bool ignoreModifiers);
void Kill(Actor self, Actor attacker);
void Kill(Actor self, Actor attacker, HashSet<string> damageTypes);
}

// depends on the order of pips in WorldRenderer.cs!
Expand Down
7 changes: 5 additions & 2 deletions OpenRA.Mods.Cnc/Activities/Leap.cs
Expand Up @@ -10,6 +10,7 @@
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Activities;
using OpenRA.GameRules;
Expand All @@ -29,15 +30,17 @@ class Leap : Activity
WPos to;
int ticks;
WAngle angle;
HashSet<string> damageTypes;

public Leap(Actor self, Actor target, Armament a, WDist speed, WAngle angle)
public Leap(Actor self, Actor target, Armament a, WDist speed, WAngle angle, HashSet<string> damageTypes)
{
var targetMobile = target.TraitOrDefault<Mobile>();
if (targetMobile == null)
throw new InvalidOperationException("Leap requires a target actor with the Mobile trait");

this.weapon = a.Weapon;
this.angle = angle;
this.damageTypes = damageTypes;
mobile = self.Trait<Mobile>();
mobile.SetLocation(mobile.FromCell, mobile.FromSubCell, targetMobile.FromCell, targetMobile.FromSubCell);
mobile.IsMoving = true;
Expand Down Expand Up @@ -67,7 +70,7 @@ public override Activity Tick(Actor self)

self.World.ActorMap.GetActorsAt(mobile.ToCell, mobile.ToSubCell)
.Except(new[] { self }).Where(t => weapon.IsValidAgainst(t, self))
.Do(t => t.Kill(self));
.Do(t => t.Kill(self, damageTypes));

return NextActivity;
}
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs
Expand Up @@ -385,7 +385,7 @@ void CalcBigNum(uint[] n1, uint[] n2, uint[] n3, uint len)
MulBignumWord(esi, globOne, tmp, 2 * len);
if ((*edi & 0x8000) == 0)
{
if (0 != SubBigNum((uint*)esi, (uint*)esi, g1, 0, (int)len))
if (SubBigNum((uint*)esi, (uint*)esi, g1, 0, (int)len) != 0)
(*edi)--;
}
}
Expand Down

0 comments on commit bc2eaf1

Please sign in to comment.