Use out var syntax
This commit is contained in:
@@ -560,8 +560,7 @@ namespace OpenRA
|
|||||||
/// <returns>The invalid token ID.</returns>
|
/// <returns>The invalid token ID.</returns>
|
||||||
public int RevokeCondition(int token)
|
public int RevokeCondition(int token)
|
||||||
{
|
{
|
||||||
string condition;
|
if (!conditionTokens.TryGetValue(token, out var condition))
|
||||||
if (!conditionTokens.TryGetValue(token, out condition))
|
|
||||||
throw new InvalidOperationException("Attempting to revoke condition with invalid token {0} for {1}.".F(token, this));
|
throw new InvalidOperationException("Attempting to revoke condition with invalid token {0} for {1}.".F(token, this));
|
||||||
|
|
||||||
conditionTokens.Remove(token);
|
conditionTokens.Remove(token);
|
||||||
@@ -594,8 +593,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
Actor a, b;
|
if (!left.TryGetClrValue(out Actor a) || !right.TryGetClrValue(out Actor b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return a == b;
|
return a == b;
|
||||||
|
|||||||
@@ -89,9 +89,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
CPos a;
|
if (!left.TryGetClrValue(out CPos a) || !right.TryGetClrValue(out CVec b))
|
||||||
CVec b;
|
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
throw new LuaException("Attempted to call CPos.Add(CPos, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call CPos.Add(CPos, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
|
|
||||||
return new LuaCustomClrObject(a + b);
|
return new LuaCustomClrObject(a + b);
|
||||||
@@ -99,21 +97,18 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
CPos a;
|
|
||||||
var rightType = right.WrappedClrType();
|
var rightType = right.WrappedClrType();
|
||||||
if (!left.TryGetClrValue(out a))
|
if (!left.TryGetClrValue(out CPos a))
|
||||||
throw new LuaException("Attempted to call CPos.Subtract(CPos, (CPos|CVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name));
|
throw new LuaException("Attempted to call CPos.Subtract(CPos, (CPos|CVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name));
|
||||||
|
|
||||||
if (rightType == typeof(CPos))
|
if (rightType == typeof(CPos))
|
||||||
{
|
{
|
||||||
CPos b;
|
right.TryGetClrValue(out CPos b);
|
||||||
right.TryGetClrValue(out b);
|
|
||||||
return new LuaCustomClrObject(a - b);
|
return new LuaCustomClrObject(a - b);
|
||||||
}
|
}
|
||||||
else if (rightType == typeof(CVec))
|
else if (rightType == typeof(CVec))
|
||||||
{
|
{
|
||||||
CVec b;
|
right.TryGetClrValue(out CVec b);
|
||||||
right.TryGetClrValue(out b);
|
|
||||||
return new LuaCustomClrObject(a - b);
|
return new LuaCustomClrObject(a - b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,8 +117,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
CPos a, b;
|
if (!left.TryGetClrValue(out CPos a) || !right.TryGetClrValue(out CPos b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return a == b;
|
return a == b;
|
||||||
|
|||||||
@@ -75,8 +75,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
CVec a, b;
|
if (!left.TryGetClrValue(out CVec a) || !right.TryGetClrValue(out CVec b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
throw new LuaException("Attempted to call CVec.Add(CVec, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call CVec.Add(CVec, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
|
|
||||||
return new LuaCustomClrObject(a + b);
|
return new LuaCustomClrObject(a + b);
|
||||||
@@ -84,8 +83,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
CVec a, b;
|
if (!left.TryGetClrValue(out CVec a) || !right.TryGetClrValue(out CVec b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
throw new LuaException("Attempted to call CVec.Subtract(CVec, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call CVec.Subtract(CVec, CVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
|
|
||||||
return new LuaCustomClrObject(a - b);
|
return new LuaCustomClrObject(a - b);
|
||||||
@@ -98,8 +96,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
CVec a, b;
|
if (!left.TryGetClrValue(out CVec a) || !right.TryGetClrValue(out CVec b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return a == b;
|
return a == b;
|
||||||
|
|||||||
@@ -125,8 +125,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k, Func<K, V> createFn)
|
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k, Func<K, V> createFn)
|
||||||
{
|
{
|
||||||
V ret;
|
if (!d.TryGetValue(k, out var ret))
|
||||||
if (!d.TryGetValue(k, out ret))
|
|
||||||
d.Add(k, ret = createFn(k));
|
d.Add(k, ret = createFn(k));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -353,8 +352,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static int IntegerDivisionRoundingAwayFromZero(int dividend, int divisor)
|
public static int IntegerDivisionRoundingAwayFromZero(int dividend, int divisor)
|
||||||
{
|
{
|
||||||
int remainder;
|
var quotient = Math.DivRem(dividend, divisor, out var remainder);
|
||||||
var quotient = Math.DivRem(dividend, divisor, out remainder);
|
|
||||||
if (remainder == 0)
|
if (remainder == 0)
|
||||||
return quotient;
|
return quotient;
|
||||||
return quotient + (Math.Sign(dividend) == Math.Sign(divisor) ? 1 : -1);
|
return quotient + (Math.Sign(dividend) == Math.Sign(divisor) ? 1 : -1);
|
||||||
@@ -405,8 +403,7 @@ namespace OpenRA
|
|||||||
// Check for a key conflict:
|
// Check for a key conflict:
|
||||||
if (d.ContainsKey(key))
|
if (d.ContainsKey(key))
|
||||||
{
|
{
|
||||||
List<string> dupKeyMessages;
|
if (!dupKeys.TryGetValue(key, out var dupKeyMessages))
|
||||||
if (!dupKeys.TryGetValue(key, out dupKeyMessages))
|
|
||||||
{
|
{
|
||||||
// Log the initial conflicting value already inserted:
|
// Log the initial conflicting value already inserted:
|
||||||
dupKeyMessages = new List<string>();
|
dupKeyMessages = new List<string>();
|
||||||
|
|||||||
@@ -121,8 +121,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
ret = null;
|
ret = null;
|
||||||
|
|
||||||
MiniYaml yaml;
|
if (!md.TryGetValue(yamlName, out var yaml))
|
||||||
if (!md.TryGetValue(yamlName, out yaml))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ret = GetValue(field.Name, field.FieldType, yaml, field);
|
ret = GetValue(field.Name, field.FieldType, yaml, field);
|
||||||
@@ -185,37 +184,32 @@ namespace OpenRA
|
|||||||
|
|
||||||
if (fieldType == typeof(int))
|
if (fieldType == typeof(int))
|
||||||
{
|
{
|
||||||
int res;
|
if (Exts.TryParseIntegerInvariant(value, out var res))
|
||||||
if (Exts.TryParseIntegerInvariant(value, out res))
|
|
||||||
return res;
|
return res;
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
else if (fieldType == typeof(ushort))
|
else if (fieldType == typeof(ushort))
|
||||||
{
|
{
|
||||||
ushort res;
|
if (ushort.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out var res))
|
||||||
if (ushort.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
|
|
||||||
return res;
|
return res;
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fieldType == typeof(long))
|
if (fieldType == typeof(long))
|
||||||
{
|
{
|
||||||
long res;
|
if (long.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out var res))
|
||||||
if (long.TryParse(value, NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out res))
|
|
||||||
return res;
|
return res;
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
else if (fieldType == typeof(float))
|
else if (fieldType == typeof(float))
|
||||||
{
|
{
|
||||||
float res;
|
if (value != null && float.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var res))
|
||||||
if (value != null && float.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
|
|
||||||
return res * (value.Contains('%') ? 0.01f : 1f);
|
return res * (value.Contains('%') ? 0.01f : 1f);
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
else if (fieldType == typeof(decimal))
|
else if (fieldType == typeof(decimal))
|
||||||
{
|
{
|
||||||
decimal res;
|
if (value != null && decimal.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var res))
|
||||||
if (value != null && decimal.TryParse(value.Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
|
|
||||||
return res * (value.Contains('%') ? 0.01m : 1m);
|
return res * (value.Contains('%') ? 0.01m : 1m);
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
@@ -227,16 +221,14 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
else if (fieldType == typeof(Color))
|
else if (fieldType == typeof(Color))
|
||||||
{
|
{
|
||||||
Color color;
|
if (value != null && Color.TryParse(value, out var color))
|
||||||
if (value != null && Color.TryParse(value, out color))
|
|
||||||
return color;
|
return color;
|
||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
else if (fieldType == typeof(Hotkey))
|
else if (fieldType == typeof(Hotkey))
|
||||||
{
|
{
|
||||||
Hotkey res;
|
if (Hotkey.TryParse(value, out var res))
|
||||||
if (Hotkey.TryParse(value, out res))
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
@@ -247,8 +239,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
else if (fieldType == typeof(WDist))
|
else if (fieldType == typeof(WDist))
|
||||||
{
|
{
|
||||||
WDist res;
|
if (WDist.TryParse(value, out var res))
|
||||||
if (WDist.TryParse(value, out res))
|
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
@@ -260,8 +251,7 @@ namespace OpenRA
|
|||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
if (parts.Length == 3)
|
if (parts.Length == 3)
|
||||||
{
|
{
|
||||||
WDist rx, ry, rz;
|
if (WDist.TryParse(parts[0], out var rx) && WDist.TryParse(parts[1], out var ry) && WDist.TryParse(parts[2], out var rz))
|
||||||
if (WDist.TryParse(parts[0], out rx) && WDist.TryParse(parts[1], out ry) && WDist.TryParse(parts[2], out rz))
|
|
||||||
return new WVec(rx, ry, rz);
|
return new WVec(rx, ry, rz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -281,8 +271,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
for (var i = 0; i < vecs.Length; ++i)
|
for (var i = 0; i < vecs.Length; ++i)
|
||||||
{
|
{
|
||||||
WDist rx, ry, rz;
|
if (WDist.TryParse(parts[3 * i], out var rx) && WDist.TryParse(parts[3 * i + 1], out var ry) && WDist.TryParse(parts[3 * i + 2], out var rz))
|
||||||
if (WDist.TryParse(parts[3 * i], out rx) && WDist.TryParse(parts[3 * i + 1], out ry) && WDist.TryParse(parts[3 * i + 2], out rz))
|
|
||||||
vecs[i] = new WVec(rx, ry, rz);
|
vecs[i] = new WVec(rx, ry, rz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,8 +287,7 @@ namespace OpenRA
|
|||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
if (parts.Length == 3)
|
if (parts.Length == 3)
|
||||||
{
|
{
|
||||||
WDist rx, ry, rz;
|
if (WDist.TryParse(parts[0], out var rx) && WDist.TryParse(parts[1], out var ry) && WDist.TryParse(parts[2], out var rz))
|
||||||
if (WDist.TryParse(parts[0], out rx) && WDist.TryParse(parts[1], out ry) && WDist.TryParse(parts[2], out rz))
|
|
||||||
return new WPos(rx, ry, rz);
|
return new WPos(rx, ry, rz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -308,8 +296,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
else if (fieldType == typeof(WAngle))
|
else if (fieldType == typeof(WAngle))
|
||||||
{
|
{
|
||||||
int res;
|
if (Exts.TryParseIntegerInvariant(value, out var res))
|
||||||
if (Exts.TryParseIntegerInvariant(value, out res))
|
|
||||||
return new WAngle(res);
|
return new WAngle(res);
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
@@ -320,8 +307,7 @@ namespace OpenRA
|
|||||||
var parts = value.Split(',');
|
var parts = value.Split(',');
|
||||||
if (parts.Length == 3)
|
if (parts.Length == 3)
|
||||||
{
|
{
|
||||||
int rr, rp, ry;
|
if (Exts.TryParseIntegerInvariant(parts[0], out var rr) && Exts.TryParseIntegerInvariant(parts[1], out var rp) && Exts.TryParseIntegerInvariant(parts[2], out var ry))
|
||||||
if (Exts.TryParseIntegerInvariant(parts[0], out rr) && Exts.TryParseIntegerInvariant(parts[1], out rp) && Exts.TryParseIntegerInvariant(parts[2], out ry))
|
|
||||||
return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry));
|
return new WRot(new WAngle(rr), new WAngle(rp), new WAngle(ry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -360,8 +346,7 @@ namespace OpenRA
|
|||||||
var vecs = new CVec[parts.Length / 2];
|
var vecs = new CVec[parts.Length / 2];
|
||||||
for (var i = 0; i < vecs.Length; i++)
|
for (var i = 0; i < vecs.Length; i++)
|
||||||
{
|
{
|
||||||
int rx, ry;
|
if (int.TryParse(parts[2 * i], out var rx) && int.TryParse(parts[2 * i + 1], out var ry))
|
||||||
if (int.TryParse(parts[2 * i], out rx) && int.TryParse(parts[2 * i + 1], out ry))
|
|
||||||
vecs[i] = new CVec(rx, ry);
|
vecs[i] = new CVec(rx, ry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,8 +400,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
else if (fieldType == typeof(bool))
|
else if (fieldType == typeof(bool))
|
||||||
{
|
{
|
||||||
bool result;
|
if (bool.TryParse(value.ToLowerInvariant(), out var result))
|
||||||
if (bool.TryParse(value.ToLowerInvariant(), out result))
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
@@ -509,8 +493,7 @@ namespace OpenRA
|
|||||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
float xx = 0;
|
float xx = 0;
|
||||||
float yy = 0;
|
float yy = 0;
|
||||||
float res;
|
if (float.TryParse(parts[0].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var res))
|
||||||
if (float.TryParse(parts[0].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
|
|
||||||
xx = res * (parts[0].Contains('%') ? 0.01f : 1f);
|
xx = res * (parts[0].Contains('%') ? 0.01f : 1f);
|
||||||
if (float.TryParse(parts[1].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
|
if (float.TryParse(parts[1].Replace("%", ""), NumberStyles.Float, NumberFormatInfo.InvariantInfo, out res))
|
||||||
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
|
yy = res * (parts[1].Contains('%') ? 0.01f : 1f);
|
||||||
@@ -524,13 +507,11 @@ namespace OpenRA
|
|||||||
if (value != null)
|
if (value != null)
|
||||||
{
|
{
|
||||||
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
var parts = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
float x = 0;
|
float.TryParse(parts[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var x);
|
||||||
float y = 0;
|
float.TryParse(parts[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out var y);
|
||||||
float z = 0;
|
|
||||||
float.TryParse(parts[0], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out x);
|
|
||||||
float.TryParse(parts[1], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out y);
|
|
||||||
|
|
||||||
// z component is optional for compatibility with older float2 definitions
|
// z component is optional for compatibility with older float2 definitions
|
||||||
|
float z = 0;
|
||||||
if (parts.Length > 2)
|
if (parts.Length > 2)
|
||||||
float.TryParse(parts[2], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out z);
|
float.TryParse(parts[2], NumberStyles.Float, NumberFormatInfo.InvariantInfo, out z);
|
||||||
|
|
||||||
@@ -575,8 +556,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
else if (fieldType == typeof(DateTime))
|
else if (fieldType == typeof(DateTime))
|
||||||
{
|
{
|
||||||
DateTime dt;
|
if (DateTime.TryParseExact(value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out var dt))
|
||||||
if (DateTime.TryParseExact(value, "yyyy-MM-dd HH-mm-ss", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out dt))
|
|
||||||
return dt;
|
return dt;
|
||||||
return InvalidValueAction(value, fieldType, fieldName);
|
return InvalidValueAction(value, fieldType, fieldName);
|
||||||
}
|
}
|
||||||
@@ -726,8 +706,7 @@ namespace OpenRA
|
|||||||
if (translations == null)
|
if (translations == null)
|
||||||
return key;
|
return key;
|
||||||
|
|
||||||
string value;
|
if (!translations.TryGetValue(key, out var value))
|
||||||
if (!translations.TryGetValue(key, out value))
|
|
||||||
return key;
|
return key;
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
|
|||||||
@@ -67,15 +67,12 @@ namespace OpenRA.FileSystem
|
|||||||
return new Folder(resolvedPath);
|
return new Folder(resolvedPath);
|
||||||
|
|
||||||
// Children of another package require special handling
|
// Children of another package require special handling
|
||||||
IReadOnlyPackage parent;
|
if (TryGetPackageContaining(filename, out var parent, out var subPath))
|
||||||
string subPath = null;
|
|
||||||
if (TryGetPackageContaining(filename, out parent, out subPath))
|
|
||||||
return parent.OpenPackage(subPath, this);
|
return parent.OpenPackage(subPath, this);
|
||||||
|
|
||||||
// Try and open it normally
|
// Try and open it normally
|
||||||
IReadOnlyPackage package;
|
|
||||||
var stream = Open(filename);
|
var stream = Open(filename);
|
||||||
if (TryParsePackage(stream, filename, out package))
|
if (TryParsePackage(stream, filename, out var package))
|
||||||
return package;
|
return package;
|
||||||
|
|
||||||
// No package loaders took ownership of the stream, so clean it up
|
// No package loaders took ownership of the stream, so clean it up
|
||||||
@@ -97,8 +94,7 @@ namespace OpenRA.FileSystem
|
|||||||
{
|
{
|
||||||
name = name.Substring(1);
|
name = name.Substring(1);
|
||||||
|
|
||||||
Manifest mod;
|
if (!installedMods.TryGetValue(name, out var mod))
|
||||||
if (!installedMods.TryGetValue(name, out mod))
|
|
||||||
throw new InvalidOperationException("Could not load mod '{0}'. Available mods: {1}".F(name, installedMods.Keys.JoinWith(", ")));
|
throw new InvalidOperationException("Could not load mod '{0}'. Available mods: {1}".F(name, installedMods.Keys.JoinWith(", ")));
|
||||||
|
|
||||||
package = mod.Package;
|
package = mod.Package;
|
||||||
@@ -122,8 +118,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
public void Mount(IReadOnlyPackage package, string explicitName = null)
|
public void Mount(IReadOnlyPackage package, string explicitName = null)
|
||||||
{
|
{
|
||||||
var mountCount = 0;
|
if (mountedPackages.TryGetValue(package, out var mountCount))
|
||||||
if (mountedPackages.TryGetValue(package, out mountCount))
|
|
||||||
{
|
{
|
||||||
// Package is already mounted
|
// Package is already mounted
|
||||||
// Increment the mount count and bump up the file loading priority
|
// Increment the mount count and bump up the file loading priority
|
||||||
@@ -149,8 +144,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
public bool Unmount(IReadOnlyPackage package)
|
public bool Unmount(IReadOnlyPackage package)
|
||||||
{
|
{
|
||||||
var mountCount = 0;
|
if (!mountedPackages.TryGetValue(package, out var mountCount))
|
||||||
if (!mountedPackages.TryGetValue(package, out mountCount))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (--mountCount <= 0)
|
if (--mountCount <= 0)
|
||||||
@@ -211,8 +205,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
public Stream Open(string filename)
|
public Stream Open(string filename)
|
||||||
{
|
{
|
||||||
Stream s;
|
if (!TryOpen(filename, out var s))
|
||||||
if (!TryOpen(filename, out s))
|
|
||||||
throw new FileNotFoundException("File not found: {0}".F(filename), filename);
|
throw new FileNotFoundException("File not found: {0}".F(filename), filename);
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
@@ -238,8 +231,7 @@ namespace OpenRA.FileSystem
|
|||||||
var explicitSplit = filename.IndexOf('|');
|
var explicitSplit = filename.IndexOf('|');
|
||||||
if (explicitSplit > 0)
|
if (explicitSplit > 0)
|
||||||
{
|
{
|
||||||
IReadOnlyPackage explicitPackage;
|
if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out var explicitPackage))
|
||||||
if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage))
|
|
||||||
{
|
{
|
||||||
s = explicitPackage.GetStream(filename.Substring(explicitSplit + 1));
|
s = explicitPackage.GetStream(filename.Substring(explicitSplit + 1));
|
||||||
if (s != null)
|
if (s != null)
|
||||||
@@ -274,12 +266,9 @@ namespace OpenRA.FileSystem
|
|||||||
{
|
{
|
||||||
var explicitSplit = filename.IndexOf('|');
|
var explicitSplit = filename.IndexOf('|');
|
||||||
if (explicitSplit > 0)
|
if (explicitSplit > 0)
|
||||||
{
|
if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out var explicitPackage))
|
||||||
IReadOnlyPackage explicitPackage;
|
|
||||||
if (explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage))
|
|
||||||
if (explicitPackage.Contains(filename.Substring(explicitSplit + 1)))
|
if (explicitPackage.Contains(filename.Substring(explicitSplit + 1)))
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return fileIndex.ContainsKey(filename);
|
return fileIndex.ContainsKey(filename);
|
||||||
}
|
}
|
||||||
@@ -293,8 +282,7 @@ namespace OpenRA.FileSystem
|
|||||||
if (explicitSplit < 0)
|
if (explicitSplit < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
IReadOnlyPackage explicitPackage;
|
if (!explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out var explicitPackage))
|
||||||
if (!explicitMounts.TryGetValue(filename.Substring(0, explicitSplit), out explicitPackage))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (installedMods[modID].Package == explicitPackage)
|
if (installedMods[modID].Package == explicitPackage)
|
||||||
@@ -321,8 +309,7 @@ namespace OpenRA.FileSystem
|
|||||||
|
|
||||||
if (parentPath.StartsWith("$", StringComparison.Ordinal))
|
if (parentPath.StartsWith("$", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
Manifest mod;
|
if (!installedMods.TryGetValue(parentPath.Substring(1), out var mod))
|
||||||
if (!installedMods.TryGetValue(parentPath.Substring(1), out mod))
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (!(mod.Package is Folder))
|
if (!(mod.Package is Folder))
|
||||||
|
|||||||
@@ -58,17 +58,15 @@ namespace OpenRA.FileSystem
|
|||||||
return new Folder(resolvedPath);
|
return new Folder(resolvedPath);
|
||||||
|
|
||||||
// Zip files loaded from Folders (and *only* from Folders) can be read-write
|
// Zip files loaded from Folders (and *only* from Folders) can be read-write
|
||||||
IReadWritePackage readWritePackage;
|
if (ZipFileLoader.TryParseReadWritePackage(resolvedPath, out var readWritePackage))
|
||||||
if (ZipFileLoader.TryParseReadWritePackage(resolvedPath, out readWritePackage))
|
|
||||||
return readWritePackage;
|
return readWritePackage;
|
||||||
|
|
||||||
// Other package types can be loaded normally
|
// Other package types can be loaded normally
|
||||||
IReadOnlyPackage package;
|
|
||||||
var s = GetStream(filename);
|
var s = GetStream(filename);
|
||||||
if (s == null)
|
if (s == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (context.TryParsePackage(s, filename, out package))
|
if (context.TryParsePackage(s, filename, out var package))
|
||||||
return package;
|
return package;
|
||||||
|
|
||||||
s.Dispose();
|
s.Dispose();
|
||||||
|
|||||||
@@ -81,12 +81,11 @@ namespace OpenRA.FileSystem
|
|||||||
return new ZipFolder(this, filename);
|
return new ZipFolder(this, filename);
|
||||||
|
|
||||||
// Other package types can be loaded normally
|
// Other package types can be loaded normally
|
||||||
IReadOnlyPackage package;
|
|
||||||
var s = GetStream(filename);
|
var s = GetStream(filename);
|
||||||
if (s == null)
|
if (s == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (context.TryParsePackage(s, filename, out package))
|
if (context.TryParsePackage(s, filename, out var package))
|
||||||
return package;
|
return package;
|
||||||
|
|
||||||
s.Dispose();
|
s.Dispose();
|
||||||
|
|||||||
@@ -355,8 +355,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
ExternalMods = new ExternalMods();
|
ExternalMods = new ExternalMods();
|
||||||
|
|
||||||
Manifest currentMod;
|
if (modID != null && Mods.TryGetValue(modID, out var currentMod))
|
||||||
if (modID != null && Mods.TryGetValue(modID, out currentMod))
|
|
||||||
{
|
{
|
||||||
var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location);
|
var launchPath = args.GetValue("Engine.LaunchPath", Assembly.GetEntryAssembly().Location);
|
||||||
|
|
||||||
@@ -367,8 +366,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
ExternalMods.Register(Mods[modID], launchPath, ModRegistration.User);
|
ExternalMods.Register(Mods[modID], launchPath, ModRegistration.User);
|
||||||
|
|
||||||
ExternalMod activeMod;
|
if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out var activeMod))
|
||||||
if (ExternalMods.TryGetValue(ExternalMod.MakeKey(Mods[modID]), out activeMod))
|
|
||||||
ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User);
|
ExternalMods.ClearInvalidRegistrations(activeMod, ModRegistration.User);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -133,9 +133,7 @@ namespace OpenRA
|
|||||||
/// <summary>Gets the player information for the specified runtime player instance.</summary>
|
/// <summary>Gets the player information for the specified runtime player instance.</summary>
|
||||||
public Player GetPlayer(OpenRA.Player runtimePlayer)
|
public Player GetPlayer(OpenRA.Player runtimePlayer)
|
||||||
{
|
{
|
||||||
Player player;
|
playersByRuntime.TryGetValue(runtimePlayer, out var player);
|
||||||
|
|
||||||
playersByRuntime.TryGetValue(runtimePlayer, out player);
|
|
||||||
|
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,8 +41,7 @@ namespace OpenRA.GameRules
|
|||||||
|
|
||||||
public void Load(IReadOnlyFileSystem fileSystem)
|
public void Load(IReadOnlyFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
Stream stream;
|
if (!fileSystem.TryOpen(Filename, out var stream))
|
||||||
if (!fileSystem.TryOpen(Filename, out stream))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -50,8 +49,7 @@ namespace OpenRA.GameRules
|
|||||||
Exists = true;
|
Exists = true;
|
||||||
foreach (var loader in Game.ModData.SoundLoaders)
|
foreach (var loader in Game.ModData.SoundLoaders)
|
||||||
{
|
{
|
||||||
ISoundFormat soundFormat;
|
if (loader.TryParseSound(stream, out var soundFormat))
|
||||||
if (loader.TryParseSound(stream, out soundFormat))
|
|
||||||
{
|
{
|
||||||
Length = (int)soundFormat.LengthInSeconds;
|
Length = (int)soundFormat.LengthInSeconds;
|
||||||
soundFormat.Dispose();
|
soundFormat.Dispose();
|
||||||
|
|||||||
@@ -137,8 +137,7 @@ namespace OpenRA.GameRules
|
|||||||
|
|
||||||
static object LoadProjectile(MiniYaml yaml)
|
static object LoadProjectile(MiniYaml yaml)
|
||||||
{
|
{
|
||||||
MiniYaml proj;
|
if (!yaml.ToDictionary().TryGetValue("Projectile", out var proj))
|
||||||
if (!yaml.ToDictionary().TryGetValue("Projectile", out proj))
|
|
||||||
return null;
|
return null;
|
||||||
var ret = Game.CreateObject<IProjectileInfo>(proj.Value + "Info");
|
var ret = Game.CreateObject<IProjectileInfo>(proj.Value + "Info");
|
||||||
FieldLoader.Load(ret, proj);
|
FieldLoader.Load(ret, proj);
|
||||||
|
|||||||
@@ -160,8 +160,7 @@ namespace OpenRA.Graphics
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rectangle mi;
|
if (!collection.Regions.TryGetValue(imageName, out var mi))
|
||||||
if (!collection.Regions.TryGetValue(imageName, out mi))
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// Cache the sprite
|
// Cache the sprite
|
||||||
|
|||||||
@@ -47,15 +47,13 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
if (d.ContainsKey("X"))
|
if (d.ContainsKey("X"))
|
||||||
{
|
{
|
||||||
int x;
|
Exts.TryParseIntegerInvariant(d["X"].Value, out var x);
|
||||||
Exts.TryParseIntegerInvariant(d["X"].Value, out x);
|
|
||||||
Hotspot = Hotspot.WithX(x);
|
Hotspot = Hotspot.WithX(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (d.ContainsKey("Y"))
|
if (d.ContainsKey("Y"))
|
||||||
{
|
{
|
||||||
int y;
|
Exts.TryParseIntegerInvariant(d["Y"].Value, out var y);
|
||||||
Exts.TryParseIntegerInvariant(d["Y"].Value, out y);
|
|
||||||
Hotspot = Hotspot.WithY(y);
|
Hotspot = Hotspot.WithY(y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,19 +38,16 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public IPalette GetPalette(string name)
|
public IPalette GetPalette(string name)
|
||||||
{
|
{
|
||||||
MutablePalette mutable;
|
if (modifiablePalettes.TryGetValue(name, out var mutable))
|
||||||
if (modifiablePalettes.TryGetValue(name, out mutable))
|
|
||||||
return mutable.AsReadOnly();
|
return mutable.AsReadOnly();
|
||||||
ImmutablePalette immutable;
|
if (palettes.TryGetValue(name, out var immutable))
|
||||||
if (palettes.TryGetValue(name, out immutable))
|
|
||||||
return immutable;
|
return immutable;
|
||||||
throw new InvalidOperationException("Palette `{0}` does not exist".F(name));
|
throw new InvalidOperationException("Palette `{0}` does not exist".F(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetPaletteIndex(string name)
|
public int GetPaletteIndex(string name)
|
||||||
{
|
{
|
||||||
int ret;
|
if (!indices.TryGetValue(name, out var ret))
|
||||||
if (!indices.TryGetValue(name, out ret))
|
|
||||||
throw new InvalidOperationException("Palette `{0}` does not exist".F(name));
|
throw new InvalidOperationException("Palette `{0}` does not exist".F(name));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -160,10 +160,8 @@ namespace OpenRA.Graphics
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Shadows are rendered at twice the resolution to reduce artifacts
|
// Shadows are rendered at twice the resolution to reduce artifacts
|
||||||
Size spriteSize, shadowSpriteSize;
|
CalculateSpriteGeometry(tl, br, 1, out var spriteSize, out var spriteOffset);
|
||||||
int2 spriteOffset, shadowSpriteOffset;
|
CalculateSpriteGeometry(stl, sbr, 2, out var shadowSpriteSize, out var shadowSpriteOffset);
|
||||||
CalculateSpriteGeometry(tl, br, 1, out spriteSize, out spriteOffset);
|
|
||||||
CalculateSpriteGeometry(stl, sbr, 2, out shadowSpriteSize, out shadowSpriteOffset);
|
|
||||||
|
|
||||||
if (sheetBuilderForFrame == null)
|
if (sheetBuilderForFrame == null)
|
||||||
sheetBuilderForFrame = new SheetBuilder(SheetType.BGRA, AllocateSheet);
|
sheetBuilderForFrame = new SheetBuilder(SheetType.BGRA, AllocateSheet);
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public Color GetRemappedColor(Color original, int index)
|
public Color GetRemappedColor(Color original, int index)
|
||||||
{
|
{
|
||||||
Color c;
|
return remapColors.TryGetValue(index, out var c)
|
||||||
return remapColors.TryGetValue(index, out c)
|
|
||||||
? c : original;
|
? c : original;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,12 +70,10 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public ISpriteSequence GetSequence(string unitName, string sequenceName)
|
public ISpriteSequence GetSequence(string unitName, string sequenceName)
|
||||||
{
|
{
|
||||||
UnitSequences unitSeq;
|
if (!sequences.Value.TryGetValue(unitName, out var unitSeq))
|
||||||
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
|
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
||||||
|
|
||||||
ISpriteSequence seq;
|
if (!unitSeq.Value.TryGetValue(sequenceName, out var seq))
|
||||||
if (!unitSeq.Value.TryGetValue(sequenceName, out seq))
|
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have a sequence named `{1}`".F(unitName, sequenceName));
|
throw new InvalidOperationException("Unit `{0}` does not have a sequence named `{1}`".F(unitName, sequenceName));
|
||||||
|
|
||||||
return seq;
|
return seq;
|
||||||
@@ -88,8 +86,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public bool HasSequence(string unitName, string sequenceName)
|
public bool HasSequence(string unitName, string sequenceName)
|
||||||
{
|
{
|
||||||
UnitSequences unitSeq;
|
if (!sequences.Value.TryGetValue(unitName, out var unitSeq))
|
||||||
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
|
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
||||||
|
|
||||||
return unitSeq.Value.ContainsKey(sequenceName);
|
return unitSeq.Value.ContainsKey(sequenceName);
|
||||||
@@ -97,8 +94,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public IEnumerable<string> Sequences(string unitName)
|
public IEnumerable<string> Sequences(string unitName)
|
||||||
{
|
{
|
||||||
UnitSequences unitSeq;
|
if (!sequences.Value.TryGetValue(unitName, out var unitSeq))
|
||||||
if (!sequences.Value.TryGetValue(unitName, out unitSeq))
|
|
||||||
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName));
|
||||||
|
|
||||||
return unitSeq.Value.Keys;
|
return unitSeq.Value.Keys;
|
||||||
@@ -115,8 +111,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
var key = node.Value.ToLines(node.Key).JoinWith("|");
|
var key = node.Value.ToLines(node.Key).JoinWith("|");
|
||||||
|
|
||||||
UnitSequences t;
|
if (sequenceCache.TryGetValue(key, out var t))
|
||||||
if (sequenceCache.TryGetValue(key, out t))
|
|
||||||
items.Add(node.Key, t);
|
items.Add(node.Key, t);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,8 +76,7 @@ namespace OpenRA.Graphics
|
|||||||
var allSprites = sprites.GetOrAdd(filename);
|
var allSprites = sprites.GetOrAdd(filename);
|
||||||
var sprite = allSprites.FirstOrDefault();
|
var sprite = allSprites.FirstOrDefault();
|
||||||
|
|
||||||
ISpriteFrame[] unloaded;
|
if (!unloadedFrames.TryGetValue(filename, out var unloaded))
|
||||||
if (!unloadedFrames.TryGetValue(filename, out unloaded))
|
|
||||||
unloaded = null;
|
unloaded = null;
|
||||||
|
|
||||||
// This is the first time that the file has been requested
|
// This is the first time that the file has been requested
|
||||||
@@ -85,8 +84,7 @@ namespace OpenRA.Graphics
|
|||||||
// the loaded cache (initially empty)
|
// the loaded cache (initially empty)
|
||||||
if (sprite == null)
|
if (sprite == null)
|
||||||
{
|
{
|
||||||
TypeDictionary fileMetadata = null;
|
unloaded = FrameLoader.GetFrames(fileSystem, filename, loaders, out var fileMetadata);
|
||||||
unloaded = FrameLoader.GetFrames(fileSystem, filename, loaders, out fileMetadata);
|
|
||||||
unloadedFrames[filename] = unloaded;
|
unloadedFrames[filename] = unloaded;
|
||||||
metadata[filename] = fileMetadata;
|
metadata[filename] = fileMetadata;
|
||||||
|
|
||||||
@@ -125,8 +123,7 @@ namespace OpenRA.Graphics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TypeDictionary FrameMetadata(string filename)
|
public TypeDictionary FrameMetadata(string filename)
|
||||||
{
|
{
|
||||||
TypeDictionary fileMetadata;
|
if (!metadata.TryGetValue(filename, out var fileMetadata))
|
||||||
if (!metadata.TryGetValue(filename, out fileMetadata))
|
|
||||||
{
|
{
|
||||||
FrameLoader.GetFrames(fileSystem, filename, loaders, out fileMetadata);
|
FrameLoader.GetFrames(fileSystem, filename, loaders, out fileMetadata);
|
||||||
metadata[filename] = fileMetadata;
|
metadata[filename] = fileMetadata;
|
||||||
@@ -142,8 +139,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public FrameCache(IReadOnlyFileSystem fileSystem, ISpriteLoader[] loaders)
|
public FrameCache(IReadOnlyFileSystem fileSystem, ISpriteLoader[] loaders)
|
||||||
{
|
{
|
||||||
TypeDictionary metadata;
|
frames = new Cache<string, ISpriteFrame[]>(filename => FrameLoader.GetFrames(fileSystem, filename, loaders, out var metadata));
|
||||||
frames = new Cache<string, ISpriteFrame[]>(filename => FrameLoader.GetFrames(fileSystem, filename, loaders, out metadata));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISpriteFrame[] this[string filename] { get { return frames[filename]; } }
|
public ISpriteFrame[] this[string filename] { get { return frames[filename]; } }
|
||||||
@@ -165,11 +161,10 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public static ISpriteFrame[] GetFrames(Stream stream, ISpriteLoader[] loaders, out TypeDictionary metadata)
|
public static ISpriteFrame[] GetFrames(Stream stream, ISpriteLoader[] loaders, out TypeDictionary metadata)
|
||||||
{
|
{
|
||||||
ISpriteFrame[] frames;
|
|
||||||
metadata = null;
|
metadata = null;
|
||||||
|
|
||||||
foreach (var loader in loaders)
|
foreach (var loader in loaders)
|
||||||
if (loader.TryParseSprite(stream, out frames, out metadata))
|
if (loader.TryParseSprite(stream, out var frames, out metadata))
|
||||||
return frames;
|
return frames;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -118,8 +118,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public Sprite TileSprite(TerrainTile r, int? variant = null)
|
public Sprite TileSprite(TerrainTile r, int? variant = null)
|
||||||
{
|
{
|
||||||
TheaterTemplate template;
|
if (!templates.TryGetValue(r.Type, out var template))
|
||||||
if (!templates.TryGetValue(r.Type, out template))
|
|
||||||
return missingTile;
|
return missingTile;
|
||||||
|
|
||||||
if (r.Index >= template.Stride)
|
if (r.Index >= template.Stride)
|
||||||
|
|||||||
@@ -50,8 +50,7 @@ namespace OpenRA
|
|||||||
return () => keys[name];
|
return () => keys[name];
|
||||||
|
|
||||||
// Try and parse as a hardcoded definition
|
// Try and parse as a hardcoded definition
|
||||||
Hotkey key;
|
if (!Hotkey.TryParse(name, out var key))
|
||||||
if (!Hotkey.TryParse(name, out key))
|
|
||||||
key = Hotkey.Invalid;
|
key = Hotkey.Invalid;
|
||||||
|
|
||||||
return () => key;
|
return () => key;
|
||||||
@@ -59,8 +58,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public void Set(string name, Hotkey value)
|
public void Set(string name, Hotkey value)
|
||||||
{
|
{
|
||||||
HotkeyDefinition definition;
|
if (!definitions.TryGetValue(name, out var definition))
|
||||||
if (!definitions.TryGetValue(name, out definition))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
keys[name] = value;
|
keys[name] = value;
|
||||||
|
|||||||
@@ -32,11 +32,9 @@ namespace OpenRA
|
|||||||
|
|
||||||
var parts = s.Split(' ');
|
var parts = s.Split(' ');
|
||||||
|
|
||||||
Keycode key;
|
if (!Enum<Keycode>.TryParse(parts[0], true, out var key))
|
||||||
if (!Enum<Keycode>.TryParse(parts[0], true, out key))
|
|
||||||
{
|
{
|
||||||
int c;
|
if (!int.TryParse(parts[0], out var c))
|
||||||
if (!int.TryParse(parts[0], out c))
|
|
||||||
return false;
|
return false;
|
||||||
key = (Keycode)c;
|
key = (Keycode)c;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -498,8 +498,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public static string DisplayString(Keycode k)
|
public static string DisplayString(Keycode k)
|
||||||
{
|
{
|
||||||
string ret;
|
if (!KeyNames.TryGetValue(k, out var ret))
|
||||||
if (!KeyNames.TryGetValue(k, out ret))
|
|
||||||
return k.ToString();
|
return k.ToString();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -96,8 +96,7 @@ namespace OpenRA
|
|||||||
// TODO: Use fieldloader
|
// TODO: Use fieldloader
|
||||||
MapFolders = YamlDictionary(yaml, "MapFolders");
|
MapFolders = YamlDictionary(yaml, "MapFolders");
|
||||||
|
|
||||||
MiniYaml packages;
|
if (yaml.TryGetValue("Packages", out var packages))
|
||||||
if (yaml.TryGetValue("Packages", out packages))
|
|
||||||
Packages = packages.ToDictionary(x => x.Value).AsReadOnly();
|
Packages = packages.ToDictionary(x => x.Value).AsReadOnly();
|
||||||
|
|
||||||
Rules = YamlList(yaml, "Rules");
|
Rules = YamlList(yaml, "Rules");
|
||||||
@@ -217,9 +216,8 @@ namespace OpenRA
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public T Get<T>(ObjectCreator oc) where T : IGlobalModData
|
public T Get<T>(ObjectCreator oc) where T : IGlobalModData
|
||||||
{
|
{
|
||||||
MiniYaml data;
|
|
||||||
var t = typeof(T);
|
var t = typeof(T);
|
||||||
if (!yaml.TryGetValue(t.Name, out data))
|
if (!yaml.TryGetValue(t.Name, out var data))
|
||||||
{
|
{
|
||||||
// Lazily create the default values if not explicitly defined.
|
// Lazily create the default values if not explicitly defined.
|
||||||
return (T)oc.CreateBasic(t);
|
return (T)oc.CreateBasic(t);
|
||||||
|
|||||||
@@ -185,14 +185,13 @@ namespace OpenRA
|
|||||||
|
|
||||||
public virtual void Initialize(Dictionary<string, object> values)
|
public virtual void Initialize(Dictionary<string, object> values)
|
||||||
{
|
{
|
||||||
object value;
|
|
||||||
foreach (var field in GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
foreach (var field in GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
||||||
{
|
{
|
||||||
var sa = field.GetCustomAttributes<FieldLoader.SerializeAttribute>(false).DefaultIfEmpty(FieldLoader.SerializeAttribute.Default).First();
|
var sa = field.GetCustomAttributes<FieldLoader.SerializeAttribute>(false).DefaultIfEmpty(FieldLoader.SerializeAttribute.Default).First();
|
||||||
if (!sa.Serialize)
|
if (!sa.Serialize)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (values.TryGetValue(field.Name, out value))
|
if (values.TryGetValue(field.Name, out var value))
|
||||||
field.SetValue(this, value);
|
field.SetValue(this, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,8 +131,7 @@ namespace OpenRA
|
|||||||
// Enumerate map directories
|
// Enumerate map directories
|
||||||
foreach (var kv in modData.Manifest.MapFolders)
|
foreach (var kv in modData.Manifest.MapFolders)
|
||||||
{
|
{
|
||||||
MapClassification packageClassification;
|
if (!Enum.TryParse(kv.Value, out MapClassification packageClassification))
|
||||||
if (!Enum.TryParse(kv.Value, out packageClassification))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!classification.HasFlag(packageClassification))
|
if (!classification.HasFlag(packageClassification))
|
||||||
|
|||||||
@@ -233,8 +233,7 @@ namespace OpenRA
|
|||||||
newData.GridType = gridType;
|
newData.GridType = gridType;
|
||||||
newData.Class = classification;
|
newData.Class = classification;
|
||||||
|
|
||||||
MiniYaml temp;
|
if (yaml.TryGetValue("MapFormat", out var temp))
|
||||||
if (yaml.TryGetValue("MapFormat", out temp))
|
|
||||||
{
|
{
|
||||||
var format = FieldLoader.GetValue<int>("MapFormat", temp.Value);
|
var format = FieldLoader.GetValue<int>("MapFormat", temp.Value);
|
||||||
if (format != Map.SupportedMapFormat)
|
if (format != Map.SupportedMapFormat)
|
||||||
@@ -269,8 +268,7 @@ namespace OpenRA
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Actor definitions may change if the map format changes
|
// Actor definitions may change if the map format changes
|
||||||
MiniYaml actorDefinitions;
|
if (yaml.TryGetValue("Actors", out var actorDefinitions))
|
||||||
if (yaml.TryGetValue("Actors", out actorDefinitions))
|
|
||||||
{
|
{
|
||||||
var spawns = new List<CPos>();
|
var spawns = new List<CPos>();
|
||||||
foreach (var kv in actorDefinitions.Nodes.Where(d => d.Value.Value == "mpspawn"))
|
foreach (var kv in actorDefinitions.Nodes.Where(d => d.Value.Value == "mpspawn"))
|
||||||
@@ -293,8 +291,7 @@ namespace OpenRA
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Player definitions may change if the map format changes
|
// Player definitions may change if the map format changes
|
||||||
MiniYaml playerDefinitions;
|
if (yaml.TryGetValue("Players", out var playerDefinitions))
|
||||||
if (yaml.TryGetValue("Players", out playerDefinitions))
|
|
||||||
{
|
{
|
||||||
newData.Players = new MapPlayers(playerDefinitions.Nodes);
|
newData.Players = new MapPlayers(playerDefinitions.Nodes);
|
||||||
newData.PlayerCount = newData.Players.Players.Count(x => x.Value.Playable);
|
newData.PlayerCount = newData.Players.Players.Count(x => x.Value.Playable);
|
||||||
@@ -331,8 +328,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
MiniYaml LoadRuleSection(Dictionary<string, MiniYaml> yaml, string section)
|
MiniYaml LoadRuleSection(Dictionary<string, MiniYaml> yaml, string section)
|
||||||
{
|
{
|
||||||
MiniYaml node;
|
if (!yaml.TryGetValue(section, out var node))
|
||||||
if (!yaml.TryGetValue(section, out node))
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
|
|||||||
@@ -72,8 +72,7 @@ namespace OpenRA
|
|||||||
tileInfo = new TerrainTileInfo[Size.X * Size.Y];
|
tileInfo = new TerrainTileInfo[Size.X * Size.Y];
|
||||||
foreach (var node in nodes)
|
foreach (var node in nodes)
|
||||||
{
|
{
|
||||||
int key;
|
if (!int.TryParse(node.Key, out var key) || key < 0 || key >= tileInfo.Length)
|
||||||
if (!int.TryParse(node.Key, out key) || key < 0 || key >= tileInfo.Length)
|
|
||||||
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
|
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
|
||||||
|
|
||||||
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
|
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
|
||||||
@@ -86,8 +85,7 @@ namespace OpenRA
|
|||||||
var i = 0;
|
var i = 0;
|
||||||
foreach (var node in nodes)
|
foreach (var node in nodes)
|
||||||
{
|
{
|
||||||
int key;
|
if (!int.TryParse(node.Key, out var key) || key != i++)
|
||||||
if (!int.TryParse(node.Key, out key) || key != i++)
|
|
||||||
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
|
throw new InvalidDataException("Invalid tile key '{0}' on template '{1}' of tileset '{2}'.".F(node.Key, Id, tileSet.Id));
|
||||||
|
|
||||||
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
|
tileInfo[key] = LoadTileInfo(tileSet, node.Value);
|
||||||
@@ -216,8 +214,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public byte GetTerrainIndex(string type)
|
public byte GetTerrainIndex(string type)
|
||||||
{
|
{
|
||||||
byte index;
|
if (terrainIndexByType.TryGetValue(type, out var index))
|
||||||
if (terrainIndexByType.TryGetValue(type, out index))
|
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
throw new InvalidDataException("Tileset '{0}' lacks terrain type '{1}'".F(Id, type));
|
throw new InvalidDataException("Tileset '{0}' lacks terrain type '{1}'".F(Id, type));
|
||||||
@@ -225,8 +222,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public byte GetTerrainIndex(TerrainTile r)
|
public byte GetTerrainIndex(TerrainTile r)
|
||||||
{
|
{
|
||||||
TerrainTemplateInfo tpl;
|
if (!Templates.TryGetValue(r.Type, out var tpl))
|
||||||
if (!Templates.TryGetValue(r.Type, out tpl))
|
|
||||||
return defaultWalkableTerrainIndex;
|
return defaultWalkableTerrainIndex;
|
||||||
|
|
||||||
if (tpl.Contains(r.Index))
|
if (tpl.Contains(r.Index))
|
||||||
@@ -241,8 +237,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public TerrainTileInfo GetTileInfo(TerrainTile r)
|
public TerrainTileInfo GetTileInfo(TerrainTile r)
|
||||||
{
|
{
|
||||||
TerrainTemplateInfo tpl;
|
if (!Templates.TryGetValue(r.Type, out var tpl))
|
||||||
if (!Templates.TryGetValue(r.Type, out tpl))
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return tpl.Contains(r.Index) ? tpl[r.Index] : null;
|
return tpl.Contains(r.Index) ? tpl[r.Index] : null;
|
||||||
|
|||||||
@@ -339,8 +339,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
if (n.Key == "Inherits" || n.Key.StartsWith("Inherits@", StringComparison.Ordinal))
|
if (n.Key == "Inherits" || n.Key.StartsWith("Inherits@", StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
MiniYaml parent;
|
if (!tree.TryGetValue(n.Value.Value, out var parent))
|
||||||
if (!tree.TryGetValue(n.Value.Value, out parent))
|
|
||||||
throw new YamlException(
|
throw new YamlException(
|
||||||
"{0}: Parent type `{1}` not found".F(n.Location, n.Value.Value));
|
"{0}: Parent type `{1}` not found".F(n.Location, n.Value.Value));
|
||||||
|
|
||||||
@@ -428,9 +427,8 @@ namespace OpenRA
|
|||||||
|
|
||||||
foreach (var key in allKeys)
|
foreach (var key in allKeys)
|
||||||
{
|
{
|
||||||
MiniYamlNode existingNode, overrideNode;
|
existingDict.TryGetValue(key, out var existingNode);
|
||||||
existingDict.TryGetValue(key, out existingNode);
|
overrideDict.TryGetValue(key, out var overrideNode);
|
||||||
overrideDict.TryGetValue(key, out overrideNode);
|
|
||||||
|
|
||||||
var loc = overrideNode == null ? default(MiniYamlNode.SourceLocation) : overrideNode.Location;
|
var loc = overrideNode == null ? default(MiniYamlNode.SourceLocation) : overrideNode.Location;
|
||||||
var comment = (overrideNode ?? existingNode).Comment;
|
var comment = (overrideNode ?? existingNode).Comment;
|
||||||
|
|||||||
@@ -167,28 +167,22 @@ namespace OpenRA.Network
|
|||||||
|
|
||||||
// Games advertised using the old API calculated the play time locally
|
// Games advertised using the old API calculated the play time locally
|
||||||
if (State == 2 && PlayTime < 0)
|
if (State == 2 && PlayTime < 0)
|
||||||
{
|
if (DateTime.TryParse(Started, out var startTime))
|
||||||
DateTime startTime;
|
|
||||||
if (DateTime.TryParse(Started, out startTime))
|
|
||||||
PlayTime = (int)(DateTime.UtcNow - startTime).TotalSeconds;
|
PlayTime = (int)(DateTime.UtcNow - startTime).TotalSeconds;
|
||||||
}
|
|
||||||
|
|
||||||
ExternalMod external;
|
|
||||||
var externalKey = ExternalMod.MakeKey(Mod, Version);
|
var externalKey = ExternalMod.MakeKey(Mod, Version);
|
||||||
if (Game.ExternalMods.TryGetValue(externalKey, out external) && external.Version == Version)
|
if (Game.ExternalMods.TryGetValue(externalKey, out var external) && external.Version == Version)
|
||||||
IsCompatible = true;
|
IsCompatible = true;
|
||||||
|
|
||||||
// Games advertised using the old API used local mod metadata
|
// Games advertised using the old API used local mod metadata
|
||||||
if (string.IsNullOrEmpty(ModTitle))
|
if (string.IsNullOrEmpty(ModTitle))
|
||||||
{
|
{
|
||||||
Manifest mod;
|
|
||||||
|
|
||||||
if (external != null && external.Version == Version)
|
if (external != null && external.Version == Version)
|
||||||
{
|
{
|
||||||
// Use external mod registration to populate the section header
|
// Use external mod registration to populate the section header
|
||||||
ModTitle = external.Title;
|
ModTitle = external.Title;
|
||||||
}
|
}
|
||||||
else if (Game.Mods.TryGetValue(Mod, out mod))
|
else if (Game.Mods.TryGetValue(Mod, out var mod))
|
||||||
{
|
{
|
||||||
// Use internal mod data to populate the section header, but
|
// Use internal mod data to populate the section header, but
|
||||||
// on-connect switching must use the external mod plumbing.
|
// on-connect switching must use the external mod plumbing.
|
||||||
|
|||||||
@@ -107,8 +107,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
case TargetType.Actor:
|
case TargetType.Actor:
|
||||||
{
|
{
|
||||||
Actor targetActor;
|
if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out var targetActor))
|
||||||
if (world != null && TryGetActorFromUInt(world, r.ReadUInt32(), out targetActor))
|
|
||||||
target = Target.FromActor(targetActor);
|
target = Target.FromActor(targetActor);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -118,8 +117,7 @@ namespace OpenRA
|
|||||||
var playerActorID = r.ReadUInt32();
|
var playerActorID = r.ReadUInt32();
|
||||||
var frozenActorID = r.ReadUInt32();
|
var frozenActorID = r.ReadUInt32();
|
||||||
|
|
||||||
Actor playerActor;
|
if (world == null || !TryGetActorFromUInt(world, playerActorID, out var playerActor))
|
||||||
if (world == null || !TryGetActorFromUInt(world, playerActorID, out playerActor))
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (playerActor.Owner.FrozenActorLayer == null)
|
if (playerActor.Owner.FrozenActorLayer == null)
|
||||||
|
|||||||
@@ -149,8 +149,7 @@ namespace OpenRA.Network
|
|||||||
void CheckSync(byte[] packet)
|
void CheckSync(byte[] packet)
|
||||||
{
|
{
|
||||||
var frame = BitConverter.ToInt32(packet, 0);
|
var frame = BitConverter.ToInt32(packet, 0);
|
||||||
byte[] existingSync;
|
if (syncForFrame.TryGetValue(frame, out var existingSync))
|
||||||
if (syncForFrame.TryGetValue(frame, out existingSync))
|
|
||||||
{
|
{
|
||||||
if (packet.Length != existingSync.Length)
|
if (packet.Length != existingSync.Length)
|
||||||
OutOfSync(frame);
|
OutOfSync(frame);
|
||||||
|
|||||||
@@ -250,8 +250,7 @@ namespace OpenRA.Network
|
|||||||
|
|
||||||
public bool OptionOrDefault(string id, bool def)
|
public bool OptionOrDefault(string id, bool def)
|
||||||
{
|
{
|
||||||
LobbyOptionState option;
|
if (LobbyOptions.TryGetValue(id, out var option))
|
||||||
if (LobbyOptions.TryGetValue(id, out option))
|
|
||||||
return option.IsEnabled;
|
return option.IsEnabled;
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
@@ -259,8 +258,7 @@ namespace OpenRA.Network
|
|||||||
|
|
||||||
public string OptionOrDefault(string id, string def)
|
public string OptionOrDefault(string id, string def)
|
||||||
{
|
{
|
||||||
LobbyOptionState option;
|
if (LobbyOptions.TryGetValue(id, out var option))
|
||||||
if (LobbyOptions.TryGetValue(id, out option))
|
|
||||||
return option.Value;
|
return option.Value;
|
||||||
|
|
||||||
return def;
|
return def;
|
||||||
|
|||||||
@@ -190,9 +190,8 @@ namespace OpenRA.Network
|
|||||||
var request = HandshakeRequest.Deserialize(order.TargetString);
|
var request = HandshakeRequest.Deserialize(order.TargetString);
|
||||||
|
|
||||||
var externalKey = ExternalMod.MakeKey(request.Mod, request.Version);
|
var externalKey = ExternalMod.MakeKey(request.Mod, request.Version);
|
||||||
ExternalMod external;
|
if ((request.Mod != mod.Id || request.Version != mod.Metadata.Version) &&
|
||||||
if ((request.Mod != mod.Id || request.Version != mod.Metadata.Version)
|
Game.ExternalMods.TryGetValue(externalKey, out var external))
|
||||||
&& Game.ExternalMods.TryGetValue(externalKey, out external))
|
|
||||||
{
|
{
|
||||||
// The ConnectionFailedLogic will prompt the user to switch mods
|
// The ConnectionFailedLogic will prompt the user to switch mods
|
||||||
orderManager.ServerExternalMod = external;
|
orderManager.ServerExternalMod = external;
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ namespace OpenRA
|
|||||||
// We can't check the internal name of the assembly, so we'll work off the data instead
|
// We can't check the internal name of the assembly, so we'll work off the data instead
|
||||||
var hash = CryptoUtil.SHA1Hash(File.ReadAllBytes(resolvedPath));
|
var hash = CryptoUtil.SHA1Hash(File.ReadAllBytes(resolvedPath));
|
||||||
|
|
||||||
Assembly assembly;
|
if (!ResolvedAssemblies.TryGetValue(hash, out var assembly))
|
||||||
if (!ResolvedAssemblies.TryGetValue(hash, out assembly))
|
|
||||||
{
|
{
|
||||||
assembly = Assembly.LoadFile(resolvedPath);
|
assembly = Assembly.LoadFile(resolvedPath);
|
||||||
ResolvedAssemblies.Add(hash, assembly);
|
ResolvedAssemblies.Add(hash, assembly);
|
||||||
|
|||||||
@@ -253,8 +253,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
Player a, b;
|
if (!left.TryGetClrValue(out Player a) || !right.TryGetClrValue(out Player b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return a == b;
|
return a == b;
|
||||||
|
|||||||
@@ -47,14 +47,9 @@ namespace OpenRA.Primitives
|
|||||||
BitSetIndex bits = 0;
|
BitSetIndex bits = 0;
|
||||||
|
|
||||||
lock (Bits)
|
lock (Bits)
|
||||||
{
|
|
||||||
foreach (var value in values)
|
foreach (var value in values)
|
||||||
{
|
if (Bits.TryGetValue(value, out var valueBit))
|
||||||
BitSetIndex valueBit;
|
|
||||||
if (Bits.TryGetValue(value, out valueBit))
|
|
||||||
bits |= valueBit;
|
bits |= valueBit;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bits;
|
return bits;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,10 +124,10 @@ namespace OpenRA.Primitives
|
|||||||
if (value.Length != 6 && value.Length != 8)
|
if (value.Length != 6 && value.Length != 8)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
byte red, green, blue, alpha = 255;
|
byte alpha = 255;
|
||||||
if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out red)
|
if (!byte.TryParse(value.Substring(0, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var red)
|
||||||
|| !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out green)
|
|| !byte.TryParse(value.Substring(2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var green)
|
||||||
|| !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out blue))
|
|| !byte.TryParse(value.Substring(4, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out var blue))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (value.Length == 8
|
if (value.Length == 8
|
||||||
|
|||||||
@@ -50,14 +50,9 @@ namespace OpenRA.Primitives
|
|||||||
long bits = 0;
|
long bits = 0;
|
||||||
|
|
||||||
lock (Bits)
|
lock (Bits)
|
||||||
{
|
|
||||||
foreach (var value in values)
|
foreach (var value in values)
|
||||||
{
|
if (Bits.TryGetValue(value, out var valueBit))
|
||||||
long valueBit;
|
|
||||||
if (Bits.TryGetValue(value, out valueBit))
|
|
||||||
bits |= valueBit;
|
bits |= valueBit;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return bits;
|
return bits;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,8 +120,7 @@ namespace OpenRA.Primitives
|
|||||||
/// <param name="count">The length of the segment.</param>
|
/// <param name="count">The length of the segment.</param>
|
||||||
public static Stream CreateWithoutOwningStream(Stream stream, long offset, int count)
|
public static Stream CreateWithoutOwningStream(Stream stream, long offset, int count)
|
||||||
{
|
{
|
||||||
Stream parentStream;
|
var nestedOffset = offset + GetOverallNestedOffset(stream, out var parentStream);
|
||||||
var nestedOffset = offset + GetOverallNestedOffset(stream, out parentStream);
|
|
||||||
|
|
||||||
// Special case FileStream - instead of creating an in-memory copy,
|
// Special case FileStream - instead of creating an in-memory copy,
|
||||||
// just reference the portion of the on-disk file that we need to save memory.
|
// just reference the portion of the on-disk file that we need to save memory.
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
public bool Remove(T item)
|
public bool Remove(T item)
|
||||||
{
|
{
|
||||||
Rectangle bounds;
|
if (!itemBounds.TryGetValue(item, out var bounds))
|
||||||
if (!itemBounds.TryGetValue(item, out bounds))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
MutateBins(item, bounds, removeItem);
|
MutateBins(item, bounds, removeItem);
|
||||||
@@ -91,8 +90,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
void MutateBins(T actor, Rectangle bounds, Action<Dictionary<T, Rectangle>, T, Rectangle> action)
|
void MutateBins(T actor, Rectangle bounds, Action<Dictionary<T, Rectangle>, T, Rectangle> action)
|
||||||
{
|
{
|
||||||
int minRow, maxRow, minCol, maxCol;
|
BoundsToBinRowsAndCols(bounds, out var minRow, out var maxRow, out var minCol, out var maxCol);
|
||||||
BoundsToBinRowsAndCols(bounds, out minRow, out maxRow, out minCol, out maxCol);
|
|
||||||
|
|
||||||
for (var row = minRow; row < maxRow; row++)
|
for (var row = minRow; row < maxRow; row++)
|
||||||
for (var col = minCol; col < maxCol; col++)
|
for (var col = minCol; col < maxCol; col++)
|
||||||
@@ -110,8 +108,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
public IEnumerable<T> InBox(Rectangle box)
|
public IEnumerable<T> InBox(Rectangle box)
|
||||||
{
|
{
|
||||||
int minRow, maxRow, minCol, maxCol;
|
BoundsToBinRowsAndCols(box, out var minRow, out var maxRow, out var minCol, out var maxCol);
|
||||||
BoundsToBinRowsAndCols(box, out minRow, out maxRow, out minCol, out maxCol);
|
|
||||||
|
|
||||||
// We want to return any items intersecting the box.
|
// We want to return any items intersecting the box.
|
||||||
// If the box covers multiple bins, we must handle items that are contained in multiple bins and avoid
|
// If the box covers multiple bins, we must handle items that are contained in multiple bins and avoid
|
||||||
|
|||||||
@@ -61,8 +61,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
object Get(Type t, bool throwsIfMissing)
|
object Get(Type t, bool throwsIfMissing)
|
||||||
{
|
{
|
||||||
List<object> ret;
|
if (!data.TryGetValue(t, out var ret))
|
||||||
if (!data.TryGetValue(t, out ret))
|
|
||||||
{
|
{
|
||||||
if (throwsIfMissing)
|
if (throwsIfMissing)
|
||||||
throw new InvalidOperationException("TypeDictionary does not contain instance of type `{0}`".F(t));
|
throw new InvalidOperationException("TypeDictionary does not contain instance of type `{0}`".F(t));
|
||||||
@@ -76,8 +75,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
public IEnumerable<T> WithInterface<T>()
|
public IEnumerable<T> WithInterface<T>()
|
||||||
{
|
{
|
||||||
List<object> objs;
|
if (data.TryGetValue(typeof(T), out var objs))
|
||||||
if (data.TryGetValue(typeof(T), out objs))
|
|
||||||
return objs.Cast<T>();
|
return objs.Cast<T>();
|
||||||
return new T[0];
|
return new T[0];
|
||||||
}
|
}
|
||||||
@@ -94,8 +92,7 @@ namespace OpenRA.Primitives
|
|||||||
|
|
||||||
void InnerRemove(Type t, object val)
|
void InnerRemove(Type t, object val)
|
||||||
{
|
{
|
||||||
List<object> objs;
|
if (!data.TryGetValue(t, out var objs))
|
||||||
if (!data.TryGetValue(t, out objs))
|
|
||||||
return;
|
return;
|
||||||
objs.Remove(val);
|
objs.Remove(val);
|
||||||
if (objs.Count == 0)
|
if (objs.Count == 0)
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ namespace OpenRA.Scripting
|
|||||||
|
|
||||||
public static string LuaDocString(this Type t)
|
public static string LuaDocString(this Type t)
|
||||||
{
|
{
|
||||||
string ret;
|
if (!LuaTypeNameReplacements.TryGetValue(t.Name, out var ret))
|
||||||
if (!LuaTypeNameReplacements.TryGetValue(t.Name, out ret))
|
|
||||||
ret = t.Name;
|
ret = t.Name;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,8 +111,7 @@ namespace OpenRA.Scripting
|
|||||||
if (IsSetProperty)
|
if (IsSetProperty)
|
||||||
{
|
{
|
||||||
var pi = (PropertyInfo)Member;
|
var pi = (PropertyInfo)Member;
|
||||||
object clrValue;
|
if (!value.TryGetClrValue(pi.PropertyType, out var clrValue))
|
||||||
if (!value.TryGetClrValue(pi.PropertyType, out clrValue))
|
|
||||||
throw new LuaException("Unable to convert '{0}' to Clr type '{1}'".F(value.WrappedClrType().Name, pi.PropertyType));
|
throw new LuaException("Unable to convert '{0}' to Clr type '{1}'".F(value.WrappedClrType().Name, pi.PropertyType));
|
||||||
|
|
||||||
pi.SetValue(Target, clrValue, null);
|
pi.SetValue(Target, clrValue, null);
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ namespace OpenRA.Scripting
|
|||||||
get
|
get
|
||||||
{
|
{
|
||||||
var name = keyValue.ToString();
|
var name = keyValue.ToString();
|
||||||
ScriptMemberWrapper wrapper;
|
if (!members.TryGetValue(name, out var wrapper))
|
||||||
if (!members.TryGetValue(name, out wrapper))
|
|
||||||
throw new LuaException(MemberNotFoundError(name));
|
throw new LuaException(MemberNotFoundError(name));
|
||||||
|
|
||||||
return wrapper.Get(runtime);
|
return wrapper.Get(runtime);
|
||||||
@@ -61,8 +60,7 @@ namespace OpenRA.Scripting
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
var name = keyValue.ToString();
|
var name = keyValue.ToString();
|
||||||
ScriptMemberWrapper wrapper;
|
if (!members.TryGetValue(name, out var wrapper))
|
||||||
if (!members.TryGetValue(name, out wrapper))
|
|
||||||
throw new LuaException(MemberNotFoundError(name));
|
throw new LuaException(MemberNotFoundError(name));
|
||||||
|
|
||||||
wrapper.Set(runtime, value);
|
wrapper.Set(runtime, value);
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ namespace OpenRA.Scripting
|
|||||||
{
|
{
|
||||||
public static Type WrappedClrType(this LuaValue value)
|
public static Type WrappedClrType(this LuaValue value)
|
||||||
{
|
{
|
||||||
object inner;
|
if (value.TryGetClrObject(out var inner))
|
||||||
if (value.TryGetClrObject(out inner))
|
|
||||||
return inner.GetType();
|
return inner.GetType();
|
||||||
|
|
||||||
return value.GetType();
|
return value.GetType();
|
||||||
@@ -27,16 +26,13 @@ namespace OpenRA.Scripting
|
|||||||
|
|
||||||
public static bool TryGetClrValue<T>(this LuaValue value, out T clrObject)
|
public static bool TryGetClrValue<T>(this LuaValue value, out T clrObject)
|
||||||
{
|
{
|
||||||
object temp;
|
var ret = value.TryGetClrValue(typeof(T), out object temp);
|
||||||
var ret = value.TryGetClrValue(typeof(T), out temp);
|
|
||||||
clrObject = ret ? (T)temp : default(T);
|
clrObject = ret ? (T)temp : default(T);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool TryGetClrValue(this LuaValue value, Type t, out object clrObject)
|
public static bool TryGetClrValue(this LuaValue value, Type t, out object clrObject)
|
||||||
{
|
{
|
||||||
object temp;
|
|
||||||
|
|
||||||
// Is t a nullable?
|
// Is t a nullable?
|
||||||
// If yes, get the underlying type
|
// If yes, get the underlying type
|
||||||
var nullable = Nullable.GetUnderlyingType(t);
|
var nullable = Nullable.GetUnderlyingType(t);
|
||||||
@@ -44,7 +40,7 @@ namespace OpenRA.Scripting
|
|||||||
t = nullable;
|
t = nullable;
|
||||||
|
|
||||||
// Value wraps a CLR object
|
// Value wraps a CLR object
|
||||||
if (value.TryGetClrObject(out temp))
|
if (value.TryGetClrObject(out var temp))
|
||||||
{
|
{
|
||||||
if (temp.GetType() == t)
|
if (temp.GetType() == t)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -99,8 +99,7 @@ namespace OpenRA.Server
|
|||||||
// Non-blocking sends are free to send only part of the data
|
// Non-blocking sends are free to send only part of the data
|
||||||
while (start < length)
|
while (start < length)
|
||||||
{
|
{
|
||||||
SocketError error;
|
var sent = s.Send(data, start, length - start, SocketFlags.None, out var error);
|
||||||
var sent = s.Send(data, start, length - start, SocketFlags.None, out error);
|
|
||||||
if (error == SocketError.WouldBlock)
|
if (error == SocketError.WouldBlock)
|
||||||
{
|
{
|
||||||
Log.Write("server", "Non-blocking send of {0} bytes failed. Falling back to blocking send.", length - start);
|
Log.Write("server", "Non-blocking send of {0} bytes failed. Falling back to blocking send.", length - start);
|
||||||
@@ -716,8 +715,7 @@ namespace OpenRA.Server
|
|||||||
break;
|
break;
|
||||||
case "Pong":
|
case "Pong":
|
||||||
{
|
{
|
||||||
long pingSent;
|
if (!OpenRA.Exts.TryParseInt64Invariant(o.TargetString, out var pingSent))
|
||||||
if (!OpenRA.Exts.TryParseInt64Invariant(o.TargetString, out pingSent))
|
|
||||||
{
|
{
|
||||||
Log.Write("server", "Invalid order pong payload: {0}", o.TargetString);
|
Log.Write("server", "Invalid order pong payload: {0}", o.TargetString);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -295,8 +295,7 @@ namespace OpenRA
|
|||||||
yamlCache = MiniYaml.FromFile(settingsFile, false);
|
yamlCache = MiniYaml.FromFile(settingsFile, false);
|
||||||
foreach (var yamlSection in yamlCache)
|
foreach (var yamlSection in yamlCache)
|
||||||
{
|
{
|
||||||
object settingsSection;
|
if (yamlSection.Key != null && Sections.TryGetValue(yamlSection.Key, out var settingsSection))
|
||||||
if (yamlSection.Key != null && Sections.TryGetValue(yamlSection.Key, out settingsSection))
|
|
||||||
LoadSectionYaml(yamlSection.Value, settingsSection);
|
LoadSectionYaml(yamlSection.Value, settingsSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,11 +66,10 @@ namespace OpenRA
|
|||||||
|
|
||||||
using (var stream = fileSystem.Open(filename))
|
using (var stream = fileSystem.Open(filename))
|
||||||
{
|
{
|
||||||
ISoundFormat soundFormat;
|
|
||||||
foreach (var loader in loaders)
|
foreach (var loader in loaders)
|
||||||
{
|
{
|
||||||
stream.Position = 0;
|
stream.Position = 0;
|
||||||
if (loader.TryParseSound(stream, out soundFormat))
|
if (loader.TryParseSound(stream, out var soundFormat))
|
||||||
{
|
{
|
||||||
var source = loadFormat(soundFormat);
|
var source = loadFormat(soundFormat);
|
||||||
soundFormat.Dispose();
|
soundFormat.Dispose();
|
||||||
|
|||||||
@@ -668,8 +668,7 @@ namespace OpenRA.Support
|
|||||||
|
|
||||||
static int ParseSymbol(string symbol, IReadOnlyDictionary<string, int> symbols)
|
static int ParseSymbol(string symbol, IReadOnlyDictionary<string, int> symbols)
|
||||||
{
|
{
|
||||||
int value;
|
symbols.TryGetValue(symbol, out var value);
|
||||||
symbols.TryGetValue(symbol, out value);
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -310,8 +310,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public FrozenActor FromID(uint id)
|
public FrozenActor FromID(uint id)
|
||||||
{
|
{
|
||||||
FrozenActor fa;
|
if (!frozenActorsById.TryGetValue(id, out var fa))
|
||||||
if (!frozenActorsById.TryGetValue(id, out fa))
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return fa;
|
return fa;
|
||||||
|
|||||||
@@ -253,8 +253,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void RemoveSource(object key)
|
public void RemoveSource(object key)
|
||||||
{
|
{
|
||||||
ShroudSource state;
|
if (!sources.TryGetValue(key, out var state))
|
||||||
if (!sources.TryGetValue(key, out state))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var puv in state.ProjectedCells)
|
foreach (var puv in state.ProjectedCells)
|
||||||
|
|||||||
@@ -221,19 +221,16 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WAngle a, b;
|
if (!left.TryGetClrValue(out WAngle a))
|
||||||
int c;
|
|
||||||
|
|
||||||
if (!left.TryGetClrValue(out a))
|
|
||||||
throw new LuaException("Attempted to call WAngle.Add(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call WAngle.Add(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
|
|
||||||
if (right.TryGetClrValue(out c))
|
if (right.TryGetClrValue(out int c))
|
||||||
{
|
{
|
||||||
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
|
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
|
||||||
return new LuaCustomClrObject(a + FromFacing(c));
|
return new LuaCustomClrObject(a + FromFacing(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (right.TryGetClrValue(out b))
|
if (right.TryGetClrValue(out WAngle b))
|
||||||
return new LuaCustomClrObject(a + b);
|
return new LuaCustomClrObject(a + b);
|
||||||
|
|
||||||
throw new LuaException("Attempted to call WAngle.Add(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call WAngle.Add(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
@@ -241,19 +238,16 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WAngle a, b;
|
if (!left.TryGetClrValue(out WAngle a))
|
||||||
int c;
|
|
||||||
|
|
||||||
if (!left.TryGetClrValue(out a))
|
|
||||||
throw new LuaException("Attempted to call WAngle.Subtract(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call WAngle.Subtract(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
|
|
||||||
if (right.TryGetClrValue(out c))
|
if (right.TryGetClrValue(out int c))
|
||||||
{
|
{
|
||||||
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
|
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
|
||||||
return new LuaCustomClrObject(a - FromFacing(c));
|
return new LuaCustomClrObject(a - FromFacing(c));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (right.TryGetClrValue(out b))
|
if (right.TryGetClrValue(out WAngle b))
|
||||||
return new LuaCustomClrObject(a - b);
|
return new LuaCustomClrObject(a - b);
|
||||||
|
|
||||||
throw new LuaException("Attempted to call WAngle.Subtract(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call WAngle.Subtract(WAngle, WAngle) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
@@ -261,8 +255,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WAngle a, b;
|
if (!left.TryGetClrValue(out WAngle a) || !right.TryGetClrValue(out WAngle b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return a == b;
|
return a == b;
|
||||||
|
|||||||
@@ -114,9 +114,7 @@ namespace OpenRA
|
|||||||
#region Scripting interface
|
#region Scripting interface
|
||||||
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WDist a;
|
if (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))
|
||||||
WDist b;
|
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
throw new LuaException("Attempted to call WDist.Add(WDist, WDist) with invalid arguments.");
|
throw new LuaException("Attempted to call WDist.Add(WDist, WDist) with invalid arguments.");
|
||||||
|
|
||||||
return new LuaCustomClrObject(a + b);
|
return new LuaCustomClrObject(a + b);
|
||||||
@@ -124,9 +122,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WDist a;
|
if (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))
|
||||||
WDist b;
|
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
throw new LuaException("Attempted to call WDist.Subtract(WDist, WDist) with invalid arguments.");
|
throw new LuaException("Attempted to call WDist.Subtract(WDist, WDist) with invalid arguments.");
|
||||||
|
|
||||||
return new LuaCustomClrObject(a - b);
|
return new LuaCustomClrObject(a - b);
|
||||||
@@ -134,9 +130,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WDist a;
|
if (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))
|
||||||
WDist b;
|
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
throw new LuaException("Attempted to call WDist.Equals(WDist, WDist) with invalid arguments.");
|
throw new LuaException("Attempted to call WDist.Equals(WDist, WDist) with invalid arguments.");
|
||||||
|
|
||||||
return a == b;
|
return a == b;
|
||||||
|
|||||||
@@ -82,9 +82,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WPos a;
|
if (!left.TryGetClrValue(out WPos a) || !right.TryGetClrValue(out WVec b))
|
||||||
WVec b;
|
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
throw new LuaException("Attempted to call WPos.Add(WPos, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call WPos.Add(WPos, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
|
|
||||||
return new LuaCustomClrObject(a + b);
|
return new LuaCustomClrObject(a + b);
|
||||||
@@ -92,21 +90,18 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WPos a;
|
|
||||||
var rightType = right.WrappedClrType();
|
var rightType = right.WrappedClrType();
|
||||||
if (!left.TryGetClrValue(out a))
|
if (!left.TryGetClrValue(out WPos a))
|
||||||
throw new LuaException("Attempted to call WPos.Subtract(WPos, (WPos|WVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name));
|
throw new LuaException("Attempted to call WPos.Subtract(WPos, (WPos|WVec)) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, rightType.Name));
|
||||||
|
|
||||||
if (rightType == typeof(WPos))
|
if (rightType == typeof(WPos))
|
||||||
{
|
{
|
||||||
WPos b;
|
right.TryGetClrValue(out WPos b);
|
||||||
right.TryGetClrValue(out b);
|
|
||||||
return new LuaCustomClrObject(a - b);
|
return new LuaCustomClrObject(a - b);
|
||||||
}
|
}
|
||||||
else if (rightType == typeof(WVec))
|
else if (rightType == typeof(WVec))
|
||||||
{
|
{
|
||||||
WVec b;
|
right.TryGetClrValue(out WVec b);
|
||||||
right.TryGetClrValue(out b);
|
|
||||||
return new LuaCustomClrObject(a - b);
|
return new LuaCustomClrObject(a - b);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,8 +110,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WPos a, b;
|
if (!left.TryGetClrValue(out WPos a) || !right.TryGetClrValue(out WPos b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return a == b;
|
return a == b;
|
||||||
|
|||||||
@@ -158,8 +158,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public Int32Matrix4x4 AsMatrix()
|
public Int32Matrix4x4 AsMatrix()
|
||||||
{
|
{
|
||||||
Int32Matrix4x4 mtx;
|
AsMatrix(out var mtx);
|
||||||
AsMatrix(out mtx);
|
|
||||||
return mtx;
|
return mtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public WVec Rotate(WRot rot)
|
public WVec Rotate(WRot rot)
|
||||||
{
|
{
|
||||||
Int32Matrix4x4 mtx;
|
rot.AsMatrix(out var mtx);
|
||||||
rot.AsMatrix(out mtx);
|
|
||||||
return Rotate(ref mtx);
|
return Rotate(ref mtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,8 +110,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Add(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WVec a, b;
|
if (!left.TryGetClrValue(out WVec a) || !right.TryGetClrValue(out WVec b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
throw new LuaException("Attempted to call WVec.Add(WVec, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call WVec.Add(WVec, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
|
|
||||||
return new LuaCustomClrObject(a + b);
|
return new LuaCustomClrObject(a + b);
|
||||||
@@ -120,8 +118,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Subtract(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WVec a, b;
|
if (!left.TryGetClrValue(out WVec a) || !right.TryGetClrValue(out WVec b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
throw new LuaException("Attempted to call WVec.Subtract(WVec, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
throw new LuaException("Attempted to call WVec.Subtract(WVec, WVec) with invalid arguments ({0}, {1})".F(left.WrappedClrType().Name, right.WrappedClrType().Name));
|
||||||
|
|
||||||
return new LuaCustomClrObject(a - b);
|
return new LuaCustomClrObject(a - b);
|
||||||
@@ -134,8 +131,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
public LuaValue Equals(LuaRuntime runtime, LuaValue left, LuaValue right)
|
||||||
{
|
{
|
||||||
WVec a, b;
|
if (!left.TryGetClrValue(out WVec a) || !right.TryGetClrValue(out WVec b))
|
||||||
if (!left.TryGetClrValue(out a) || !right.TryGetClrValue(out b))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return a == b;
|
return a == b;
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ namespace OpenRA.Widgets
|
|||||||
|
|
||||||
public static bool TryGet<T>(string key, out T result)
|
public static bool TryGet<T>(string key, out T result)
|
||||||
{
|
{
|
||||||
string s;
|
if (!data.TryGetValue(key, out var s))
|
||||||
if (!data.TryGetValue(key, out s))
|
|
||||||
{
|
{
|
||||||
result = default(T);
|
result = default(T);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public Widget LoadWidget(WidgetArgs args, Widget parent, string w)
|
public Widget LoadWidget(WidgetArgs args, Widget parent, string w)
|
||||||
{
|
{
|
||||||
MiniYamlNode ret;
|
if (!widgets.TryGetValue(w, out var ret))
|
||||||
if (!widgets.TryGetValue(w, out ret))
|
|
||||||
throw new InvalidDataException("Cannot find widget with Id `{0}`".F(w));
|
throw new InvalidDataException("Cannot find widget with Id `{0}`".F(w));
|
||||||
|
|
||||||
return LoadWidget(args, parent, ret);
|
return LoadWidget(args, parent, ret);
|
||||||
|
|||||||
@@ -486,8 +486,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
public Actor GetActorById(uint actorId)
|
public Actor GetActorById(uint actorId)
|
||||||
{
|
{
|
||||||
Actor a;
|
if (actors.TryGetValue(actorId, out var a))
|
||||||
if (actors.TryGetValue(actorId, out a))
|
|
||||||
return a;
|
return a;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,8 +80,7 @@ namespace OpenRA.Mods.Cnc.Activities
|
|||||||
if (IsCanceling)
|
if (IsCanceling)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool targetIsHiddenActor;
|
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
|
||||||
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
||||||
{
|
{
|
||||||
lastVisibleTarget = Target.FromTargetPositions(target);
|
lastVisibleTarget = Target.FromTargetPositions(target);
|
||||||
|
|||||||
@@ -98,8 +98,7 @@ namespace OpenRA.Mods.Cnc.AudioLoaders
|
|||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
|
|
||||||
CheckVocHeader(stream);
|
CheckVocHeader(stream);
|
||||||
int sampleRate;
|
Preload(stream, out blocks, out totalSamples, out var sampleRate);
|
||||||
Preload(stream, out blocks, out totalSamples, out sampleRate);
|
|
||||||
SampleRate = sampleRate;
|
SampleRate = sampleRate;
|
||||||
Rewind();
|
Rewind();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,10 +48,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
|
|||||||
|
|
||||||
List<PackageEntry> entries;
|
List<PackageEntry> entries;
|
||||||
if (isEncrypted)
|
if (isEncrypted)
|
||||||
{
|
entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out var unused);
|
||||||
long unused;
|
|
||||||
entries = ParseHeader(DecryptHeader(s, 4, out dataStart), 0, out unused);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart);
|
entries = ParseHeader(s, isCncMix ? 0 : 4, out dataStart);
|
||||||
|
|
||||||
@@ -93,9 +90,8 @@ namespace OpenRA.Mods.Cnc.FileSystem
|
|||||||
{
|
{
|
||||||
var classicHash = PackageEntry.HashFilename(filename, PackageHashType.Classic);
|
var classicHash = PackageEntry.HashFilename(filename, PackageHashType.Classic);
|
||||||
var crcHash = PackageEntry.HashFilename(filename, PackageHashType.CRC32);
|
var crcHash = PackageEntry.HashFilename(filename, PackageHashType.CRC32);
|
||||||
PackageEntry e;
|
|
||||||
|
|
||||||
if (entries.TryGetValue(classicHash, out e))
|
if (entries.TryGetValue(classicHash, out var e))
|
||||||
classicIndex.Add(filename, e);
|
classicIndex.Add(filename, e);
|
||||||
|
|
||||||
if (entries.TryGetValue(crcHash, out e))
|
if (entries.TryGetValue(crcHash, out e))
|
||||||
@@ -187,8 +183,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
|
|||||||
|
|
||||||
public Stream GetStream(string filename)
|
public Stream GetStream(string filename)
|
||||||
{
|
{
|
||||||
PackageEntry e;
|
if (!index.TryGetValue(filename, out var e))
|
||||||
if (!index.TryGetValue(filename, out e))
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return GetContent(e);
|
return GetContent(e);
|
||||||
@@ -210,12 +205,11 @@ namespace OpenRA.Mods.Cnc.FileSystem
|
|||||||
|
|
||||||
public IReadOnlyPackage OpenPackage(string filename, FS context)
|
public IReadOnlyPackage OpenPackage(string filename, FS context)
|
||||||
{
|
{
|
||||||
IReadOnlyPackage package;
|
|
||||||
var childStream = GetStream(filename);
|
var childStream = GetStream(filename);
|
||||||
if (childStream == null)
|
if (childStream == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (context.TryParsePackage(childStream, filename, out package))
|
if (context.TryParsePackage(childStream, filename, out var package))
|
||||||
return package;
|
return package;
|
||||||
|
|
||||||
childStream.Dispose();
|
childStream.Dispose();
|
||||||
@@ -237,9 +231,8 @@ namespace OpenRA.Mods.Cnc.FileSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load the global mix database
|
// Load the global mix database
|
||||||
Stream mixDatabase;
|
|
||||||
var allPossibleFilenames = new HashSet<string>();
|
var allPossibleFilenames = new HashSet<string>();
|
||||||
if (context.TryOpen("global mix database.dat", out mixDatabase))
|
if (context.TryOpen("global mix database.dat", out var mixDatabase))
|
||||||
using (var db = new XccGlobalDatabase(mixDatabase))
|
using (var db = new XccGlobalDatabase(mixDatabase))
|
||||||
foreach (var e in db.Entries)
|
foreach (var e in db.Entries)
|
||||||
allPossibleFilenames.Add(e);
|
allPossibleFilenames.Add(e);
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
string filename;
|
if (names.TryGetValue(Hash, out var filename))
|
||||||
if (names.TryGetValue(Hash, out filename))
|
|
||||||
return "{0} - offset 0x{1:x8} - length 0x{2:x8}".F(filename, Offset, Length);
|
return "{0} - offset 0x{1:x8} - length 0x{2:x8}".F(filename, Offset, Length);
|
||||||
else
|
else
|
||||||
return "0x{0:x8} - offset 0x{1:x8} - length 0x{2:x8}".F(Hash, Offset, Length);
|
return "0x{0:x8} - offset 0x{1:x8} - length 0x{2:x8}".F(Hash, Offset, Length);
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
|
|||||||
|
|
||||||
public Stream GetStream(string filename)
|
public Stream GetStream(string filename)
|
||||||
{
|
{
|
||||||
Entry entry;
|
if (!index.TryGetValue(filename, out var entry))
|
||||||
if (!index.TryGetValue(filename, out entry))
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return SegmentStream.CreateWithoutOwningStream(stream, entry.Offset, (int)entry.Length);
|
return SegmentStream.CreateWithoutOwningStream(stream, entry.Offset, (int)entry.Length);
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ namespace OpenRA.Mods.Cnc.Graphics
|
|||||||
: base(modData)
|
: base(modData)
|
||||||
{
|
{
|
||||||
var metadata = modData.Manifest.Get<SpriteSequenceFormat>().Metadata;
|
var metadata = modData.Manifest.Get<SpriteSequenceFormat>().Metadata;
|
||||||
MiniYaml yaml;
|
if (metadata.TryGetValue("DefaultSpriteExtension", out var yaml))
|
||||||
if (metadata.TryGetValue("DefaultSpriteExtension", out yaml))
|
|
||||||
DefaultSpriteExtension = yaml.Value;
|
DefaultSpriteExtension = yaml.Value;
|
||||||
|
|
||||||
if (metadata.TryGetValue("TilesetExtensions", out yaml))
|
if (metadata.TryGetValue("TilesetExtensions", out yaml))
|
||||||
@@ -51,8 +50,7 @@ namespace OpenRA.Mods.Cnc.Graphics
|
|||||||
{
|
{
|
||||||
var tsId = tileSet.Id;
|
var tsId = tileSet.Id;
|
||||||
|
|
||||||
MiniYaml yaml;
|
if (d.TryGetValue("TilesetOverrides", out var yaml))
|
||||||
if (d.TryGetValue("TilesetOverrides", out yaml))
|
|
||||||
{
|
{
|
||||||
var tsNode = yaml.Nodes.FirstOrDefault(n => n.Key == tsId);
|
var tsNode = yaml.Nodes.FirstOrDefault(n => n.Key == tsId);
|
||||||
if (tsNode != null)
|
if (tsNode != null)
|
||||||
@@ -70,8 +68,7 @@ namespace OpenRA.Mods.Cnc.Graphics
|
|||||||
|
|
||||||
if (LoadField(d, "UseTilesetCode", false))
|
if (LoadField(d, "UseTilesetCode", false))
|
||||||
{
|
{
|
||||||
string code;
|
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out var code))
|
||||||
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out code))
|
|
||||||
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
|
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,8 +76,7 @@ namespace OpenRA.Mods.Cnc.Graphics
|
|||||||
{
|
{
|
||||||
var useTilesetExtension = LoadField(d, "UseTilesetExtension", false);
|
var useTilesetExtension = LoadField(d, "UseTilesetExtension", false);
|
||||||
|
|
||||||
string tilesetExtension;
|
if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out var tilesetExtension))
|
||||||
if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out tilesetExtension))
|
|
||||||
return spriteName + tilesetExtension;
|
return spriteName + tilesetExtension;
|
||||||
|
|
||||||
return spriteName + loader.DefaultSpriteExtension;
|
return spriteName + loader.DefaultSpriteExtension;
|
||||||
|
|||||||
@@ -235,8 +235,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
if (disguisedAsToken != Actor.InvalidConditionToken)
|
if (disguisedAsToken != Actor.InvalidConditionToken)
|
||||||
disguisedAsToken = self.RevokeCondition(disguisedAsToken);
|
disguisedAsToken = self.RevokeCondition(disguisedAsToken);
|
||||||
|
|
||||||
string disguisedAsCondition;
|
if (info.DisguisedAsConditions.TryGetValue(AsActor.Name, out var disguisedAsCondition))
|
||||||
if (info.DisguisedAsConditions.TryGetValue(AsActor.Name, out disguisedAsCondition))
|
|
||||||
disguisedAsToken = self.GrantCondition(disguisedAsCondition);
|
disguisedAsToken = self.GrantCondition(disguisedAsCondition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
{
|
{
|
||||||
var damageSubTicks = (int)(damage.Value * 100L * Info.DamageMultiplier / Info.DamageDivisor);
|
var damageSubTicks = (int)(damage.Value * 100L * Info.DamageMultiplier / Info.DamageDivisor);
|
||||||
|
|
||||||
SupportPowerInstance spi;
|
if (spm.Powers.TryGetValue(Info.OrderName, out var spi))
|
||||||
if (spm.Powers.TryGetValue(Info.OrderName, out spi))
|
|
||||||
{
|
{
|
||||||
var dspi = spi as GrantPrerequisiteChargeDrainPower.DischargeableSupportPowerInstance;
|
var dspi = spi as GrantPrerequisiteChargeDrainPower.DischargeableSupportPowerInstance;
|
||||||
if (dspi != null)
|
if (dspi != null)
|
||||||
|
|||||||
@@ -36,10 +36,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
{
|
{
|
||||||
WeaponInfo weaponInfo;
|
|
||||||
|
|
||||||
var weaponToLower = Weapon.ToLowerInvariant();
|
var weaponToLower = Weapon.ToLowerInvariant();
|
||||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weaponInfo))
|
if (!rules.Weapons.TryGetValue(weaponToLower, out var weaponInfo))
|
||||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||||
|
|
||||||
WeaponInfo = weaponInfo;
|
WeaponInfo = weaponInfo;
|
||||||
|
|||||||
@@ -65,15 +65,13 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
{
|
{
|
||||||
WeaponInfo thumpDamageWeapon;
|
|
||||||
WeaponInfo detonationWeapon;
|
|
||||||
var thumpDamageWeaponToLower = (ThumpDamageWeapon ?? string.Empty).ToLowerInvariant();
|
var thumpDamageWeaponToLower = (ThumpDamageWeapon ?? string.Empty).ToLowerInvariant();
|
||||||
var detonationWeaponToLower = (DetonationWeapon ?? string.Empty).ToLowerInvariant();
|
var detonationWeaponToLower = (DetonationWeapon ?? string.Empty).ToLowerInvariant();
|
||||||
|
|
||||||
if (!rules.Weapons.TryGetValue(thumpDamageWeaponToLower, out thumpDamageWeapon))
|
if (!rules.Weapons.TryGetValue(thumpDamageWeaponToLower, out var thumpDamageWeapon))
|
||||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(thumpDamageWeaponToLower));
|
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(thumpDamageWeaponToLower));
|
||||||
|
|
||||||
if (!rules.Weapons.TryGetValue(detonationWeaponToLower, out detonationWeapon))
|
if (!rules.Weapons.TryGetValue(detonationWeaponToLower, out var detonationWeapon))
|
||||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(detonationWeaponToLower));
|
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(detonationWeaponToLower));
|
||||||
|
|
||||||
ThumpDamageWeaponInfo = thumpDamageWeapon;
|
ThumpDamageWeaponInfo = thumpDamageWeapon;
|
||||||
|
|||||||
@@ -66,9 +66,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
{
|
{
|
||||||
WeaponInfo weapon;
|
|
||||||
var weaponToLower = (Weapon ?? string.Empty).ToLowerInvariant();
|
var weaponToLower = (Weapon ?? string.Empty).ToLowerInvariant();
|
||||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||||
|
|
||||||
WeaponInfo = weapon;
|
WeaponInfo = weapon;
|
||||||
|
|||||||
@@ -52,9 +52,8 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
public override object Create(ActorInitializer init) { return new IonCannonPower(init.Self, this); }
|
public override object Create(ActorInitializer init) { return new IonCannonPower(init.Self, this); }
|
||||||
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
public override void RulesetLoaded(Ruleset rules, ActorInfo ai)
|
||||||
{
|
{
|
||||||
WeaponInfo weapon;
|
|
||||||
var weaponToLower = (Weapon ?? string.Empty).ToLowerInvariant();
|
var weaponToLower = (Weapon ?? string.Empty).ToLowerInvariant();
|
||||||
if (!rules.Weapons.TryGetValue(weaponToLower, out weapon))
|
if (!rules.Weapons.TryGetValue(weaponToLower, out var weapon))
|
||||||
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
throw new YamlException("Weapons Ruleset does not contain an entry '{0}'".F(weaponToLower));
|
||||||
|
|
||||||
WeaponInfo = weapon;
|
WeaponInfo = weapon;
|
||||||
|
|||||||
@@ -404,8 +404,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
if (overlayType == 0xFF)
|
if (overlayType == 0xFF)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string actorType;
|
if (OverlayToActor.TryGetValue(overlayType, out var actorType))
|
||||||
if (OverlayToActor.TryGetValue(overlayType, out actorType))
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(actorType))
|
if (string.IsNullOrEmpty(actorType))
|
||||||
continue;
|
continue;
|
||||||
@@ -416,19 +415,13 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
// Only import the top-left cell of multi-celled overlays
|
// Only import the top-left cell of multi-celled overlays
|
||||||
var aboveType = overlayPack[overlayIndex[cell - new CVec(1, 0)]];
|
var aboveType = overlayPack[overlayIndex[cell - new CVec(1, 0)]];
|
||||||
if (shape.Width > 1 && aboveType != 0xFF)
|
if (shape.Width > 1 && aboveType != 0xFF)
|
||||||
{
|
if (OverlayToActor.TryGetValue(aboveType, out var a) && a == actorType)
|
||||||
string a;
|
|
||||||
if (OverlayToActor.TryGetValue(aboveType, out a) && a == actorType)
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
var leftType = overlayPack[overlayIndex[cell - new CVec(0, 1)]];
|
var leftType = overlayPack[overlayIndex[cell - new CVec(0, 1)]];
|
||||||
if (shape.Height > 1 && leftType != 0xFF)
|
if (shape.Height > 1 && leftType != 0xFF)
|
||||||
{
|
if (OverlayToActor.TryGetValue(leftType, out var a) && a == actorType)
|
||||||
string a;
|
|
||||||
if (OverlayToActor.TryGetValue(leftType, out a) && a == actorType)
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ar = new ActorReference(actorType)
|
var ar = new ActorReference(actorType)
|
||||||
@@ -437,8 +430,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
new OwnerInit("Neutral")
|
new OwnerInit("Neutral")
|
||||||
};
|
};
|
||||||
|
|
||||||
DamageState damageState;
|
if (OverlayToHealth.TryGetValue(overlayType, out var damageState))
|
||||||
if (OverlayToHealth.TryGetValue(overlayType, out damageState))
|
|
||||||
{
|
{
|
||||||
var health = 100;
|
var health = 100;
|
||||||
if (damageState == DamageState.Critical)
|
if (damageState == DamageState.Critical)
|
||||||
@@ -484,8 +476,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
var dy = rx + ry - fullSize.X - 1;
|
var dy = rx + ry - fullSize.X - 1;
|
||||||
var cell = new MPos(dx / 2, dy).ToCPos(map);
|
var cell = new MPos(dx / 2, dy).ToCPos(map);
|
||||||
|
|
||||||
int wpindex;
|
var ar = new ActorReference((!int.TryParse(kv.Key, out var wpindex) || wpindex > 7) ? "waypoint" : "mpspawn");
|
||||||
var ar = new ActorReference((!int.TryParse(kv.Key, out wpindex) || wpindex > 7) ? "waypoint" : "mpspawn");
|
|
||||||
ar.Add(new LocationInit(cell));
|
ar.Add(new LocationInit(cell));
|
||||||
ar.Add(new OwnerInit("Neutral"));
|
ar.Add(new OwnerInit("Neutral"));
|
||||||
|
|
||||||
@@ -598,8 +589,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
|
|
||||||
foreach (var node in lightingTypes)
|
foreach (var node in lightingTypes)
|
||||||
{
|
{
|
||||||
float val;
|
if (node.Value != null && parsed.TryGetValue(node.Key, out var val) && ((node.Key == "Level" && val != 0) || (node.Key != "Level" && val != 1.0f)))
|
||||||
if (node.Value != null && parsed.TryGetValue(node.Key, out val) && ((node.Key == "Level" && val != 0) || (node.Key != "Level" && val != 1.0f)))
|
|
||||||
lightingNodes.Add(new MiniYamlNode(node.Value, FieldSaver.FormatValue(val)));
|
lightingNodes.Add(new MiniYamlNode(node.Value, FieldSaver.FormatValue(val)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -265,9 +265,8 @@ namespace OpenRA.Mods.Cnc.UtilityCommands
|
|||||||
else
|
else
|
||||||
Console.WriteLine("\t\tFacings: 8");
|
Console.WriteLine("\t\tFacings: 8");
|
||||||
|
|
||||||
int length, stride;
|
int.TryParse(splitting[2], out var stride);
|
||||||
int.TryParse(splitting[2], out stride);
|
int.TryParse(splitting[1], out var length);
|
||||||
int.TryParse(splitting[1], out length);
|
|
||||||
if (stride != 0 && stride != length)
|
if (stride != 0 && stride != length)
|
||||||
Console.WriteLine("\t\tStride: " + stride);
|
Console.WriteLine("\t\tStride: " + stride);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,8 +164,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool targetIsHiddenActor;
|
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
|
||||||
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
||||||
lastVisibleTarget = Target.FromTargetPositions(target);
|
lastVisibleTarget = Target.FromTargetPositions(target);
|
||||||
|
|
||||||
|
|||||||
@@ -90,8 +90,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (attackAircraft.IsTraitPaused)
|
if (attackAircraft.IsTraitPaused)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool targetIsHiddenActor;
|
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
|
||||||
attackAircraft.SetRequestedTarget(self, target, forceAttack);
|
attackAircraft.SetRequestedTarget(self, target, forceAttack);
|
||||||
hasTicked = true;
|
hasTicked = true;
|
||||||
|
|
||||||
@@ -239,8 +238,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
// Cancel the run if the target become invalid (e.g. killed) while visible
|
// Cancel the run if the target become invalid (e.g. killed) while visible
|
||||||
var targetWasVisibleActor = targetIsVisibleActor;
|
var targetWasVisibleActor = targetIsVisibleActor;
|
||||||
bool targetIsHiddenActor;
|
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
|
||||||
targetIsVisibleActor = target.Type == TargetType.Actor && !targetIsHiddenActor;
|
targetIsVisibleActor = target.Type == TargetType.Actor && !targetIsHiddenActor;
|
||||||
|
|
||||||
if (targetWasVisibleActor && !target.IsValidFor(self))
|
if (targetWasVisibleActor && !target.IsValidFor(self))
|
||||||
@@ -284,8 +282,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
// Strafe attacks target the ground below the original target
|
// Strafe attacks target the ground below the original target
|
||||||
// Update the position if we seen the target move; keep the previous one if it dies or disappears
|
// Update the position if we seen the target move; keep the previous one if it dies or disappears
|
||||||
bool targetIsHiddenActor;
|
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
|
||||||
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
||||||
attackAircraft.SetRequestedTarget(self, Target.FromTargetPositions(target), true);
|
attackAircraft.SetRequestedTarget(self, Target.FromTargetPositions(target), true);
|
||||||
|
|
||||||
|
|||||||
@@ -55,8 +55,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (IsCanceling)
|
if (IsCanceling)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool targetIsHiddenActor;
|
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
|
||||||
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
||||||
lastVisibleTarget = Target.FromTargetPositions(target);
|
lastVisibleTarget = Target.FromTargetPositions(target);
|
||||||
|
|
||||||
|
|||||||
@@ -96,8 +96,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool targetIsHiddenActor;
|
target = RecalculateTarget(self, out var targetIsHiddenActor);
|
||||||
target = RecalculateTarget(self, out targetIsHiddenActor);
|
|
||||||
|
|
||||||
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
// StartCapture returns false when a capture delay is enabled
|
// StartCapture returns false when a capture delay is enabled
|
||||||
// We wait until it returns true before allowing entering the target
|
// We wait until it returns true before allowing entering the target
|
||||||
Captures captures;
|
if (!manager.StartCapture(self, enterActor, enterCaptureManager, out var captures))
|
||||||
if (!manager.StartCapture(self, enterActor, enterCaptureManager, out captures))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!captures.Info.ConsumedByCapture)
|
if (!captures.Info.ConsumedByCapture)
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
public override bool Tick(Actor self)
|
public override bool Tick(Actor self)
|
||||||
{
|
{
|
||||||
// Update our view of the target
|
// Update our view of the target
|
||||||
bool targetIsHiddenActor;
|
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
|
||||||
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
||||||
lastVisibleTarget = Target.FromTargetPositions(target);
|
lastVisibleTarget = Target.FromTargetPositions(target);
|
||||||
|
|
||||||
|
|||||||
@@ -51,8 +51,7 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
if (IsCanceling)
|
if (IsCanceling)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
bool targetIsHiddenActor;
|
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
|
||||||
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
||||||
lastVisibleTarget = Target.FromTargetPositions(target);
|
lastVisibleTarget = Target.FromTargetPositions(target);
|
||||||
|
|
||||||
|
|||||||
@@ -88,9 +88,8 @@ namespace OpenRA.Mods.Common.Activities
|
|||||||
|
|
||||||
public override bool Tick(Actor self)
|
public override bool Tick(Actor self)
|
||||||
{
|
{
|
||||||
bool targetIsHiddenActor;
|
|
||||||
var oldTargetLocation = lastVisibleTargetLocation;
|
var oldTargetLocation = lastVisibleTargetLocation;
|
||||||
target = target.Recalculate(self.Owner, out targetIsHiddenActor);
|
target = target.Recalculate(self.Owner, out var targetIsHiddenActor);
|
||||||
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
if (!targetIsHiddenActor && target.Type == TargetType.Actor)
|
||||||
{
|
{
|
||||||
lastVisibleTarget = Target.FromTargetPositions(target);
|
lastVisibleTarget = Target.FromTargetPositions(target);
|
||||||
|
|||||||
@@ -57,10 +57,7 @@ namespace OpenRA.Mods.Common
|
|||||||
public bool IsValid(Color askedColor, out Color forbiddenColor, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors, HashSet<string> errorMessages = null)
|
public bool IsValid(Color askedColor, out Color forbiddenColor, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors, HashSet<string> errorMessages = null)
|
||||||
{
|
{
|
||||||
// Validate color against HSV
|
// Validate color against HSV
|
||||||
float h, s, v;
|
askedColor.ToAhsv(out var a, out var h, out var s, out var v);
|
||||||
int a;
|
|
||||||
|
|
||||||
askedColor.ToAhsv(out a, out h, out s, out v);
|
|
||||||
if (s < HsvSaturationRange[0] || s > HsvSaturationRange[1] || v < HsvValueRange[0] || v > HsvValueRange[1])
|
if (s < HsvSaturationRange[0] || s > HsvSaturationRange[1] || v < HsvValueRange[0] || v > HsvValueRange[1])
|
||||||
{
|
{
|
||||||
if (errorMessages != null)
|
if (errorMessages != null)
|
||||||
@@ -95,9 +92,8 @@ namespace OpenRA.Mods.Common
|
|||||||
{
|
{
|
||||||
if (TeamColorPresets.Any())
|
if (TeamColorPresets.Any())
|
||||||
{
|
{
|
||||||
Color forbidden;
|
|
||||||
foreach (var c in TeamColorPresets.Shuffle(random))
|
foreach (var c in TeamColorPresets.Shuffle(random))
|
||||||
if (IsValid(c, out forbidden, terrainColors, playerColors))
|
if (IsValid(c, out var forbidden, terrainColors, playerColors))
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,7 +103,6 @@ namespace OpenRA.Mods.Common
|
|||||||
public Color RandomValidColor(MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors)
|
public Color RandomValidColor(MersenneTwister random, IEnumerable<Color> terrainColors, IEnumerable<Color> playerColors)
|
||||||
{
|
{
|
||||||
Color color;
|
Color color;
|
||||||
Color forbidden;
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
var h = random.Next(255) / 255f;
|
var h = random.Next(255) / 255f;
|
||||||
@@ -115,7 +110,7 @@ namespace OpenRA.Mods.Common
|
|||||||
var v = float2.Lerp(HsvValueRange[0], HsvValueRange[1], random.NextFloat());
|
var v = float2.Lerp(HsvValueRange[0], HsvValueRange[1], random.NextFloat());
|
||||||
color = Color.FromAhsv(h, s, v);
|
color = Color.FromAhsv(h, s, v);
|
||||||
}
|
}
|
||||||
while (!IsValid(color, out forbidden, terrainColors, playerColors));
|
while (!IsValid(color, out var forbidden, terrainColors, playerColors));
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
@@ -124,8 +119,7 @@ namespace OpenRA.Mods.Common
|
|||||||
{
|
{
|
||||||
var errorMessages = new HashSet<string>();
|
var errorMessages = new HashSet<string>();
|
||||||
|
|
||||||
Color forbiddenColor;
|
if (IsValid(askedColor, out var forbiddenColor, terrainColors, playerColors, errorMessages))
|
||||||
if (IsValid(askedColor, out forbiddenColor, terrainColors, playerColors, errorMessages))
|
|
||||||
return askedColor;
|
return askedColor;
|
||||||
|
|
||||||
// Vector between the 2 colors
|
// Vector between the 2 colors
|
||||||
|
|||||||
@@ -147,8 +147,7 @@ namespace OpenRA.Mods.Common.Commands
|
|||||||
var orderString = toAll ? "DevGiveCashAll" : "DevGiveCash";
|
var orderString = toAll ? "DevGiveCashAll" : "DevGiveCash";
|
||||||
var giveCashOrder = new Order(orderString, world.LocalPlayer.PlayerActor, false);
|
var giveCashOrder = new Order(orderString, world.LocalPlayer.PlayerActor, false);
|
||||||
|
|
||||||
int cash;
|
int.TryParse(arg, out var cash);
|
||||||
int.TryParse(arg, out cash);
|
|
||||||
giveCashOrder.ExtraData = (uint)cash;
|
giveCashOrder.ExtraData = (uint)cash;
|
||||||
|
|
||||||
world.IssueOrder(giveCashOrder);
|
world.IssueOrder(giveCashOrder);
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ namespace OpenRA.Mods.Common.Commands
|
|||||||
|
|
||||||
foreach (var key in console.Commands.Keys)
|
foreach (var key in console.Commands.Keys)
|
||||||
{
|
{
|
||||||
string description;
|
if (!helpDescriptions.TryGetValue(key, out var description))
|
||||||
if (!helpDescriptions.TryGetValue(key, out description))
|
|
||||||
description = "no description available.";
|
description = "no description available.";
|
||||||
|
|
||||||
Game.Debug("{0}: {1}", key, description);
|
Game.Debug("{0}: {1}", key, description);
|
||||||
|
|||||||
@@ -62,8 +62,7 @@ namespace OpenRA.Mods.Common.FileFormats
|
|||||||
return null;
|
return null;
|
||||||
var sectionName = m.Groups[1].Value.ToLowerInvariant();
|
var sectionName = m.Groups[1].Value.ToLowerInvariant();
|
||||||
|
|
||||||
IniSection ret;
|
if (!sections.TryGetValue(sectionName, out var ret))
|
||||||
if (!sections.TryGetValue(sectionName, out ret))
|
|
||||||
sections.Add(sectionName, ret = new IniSection(sectionName));
|
sections.Add(sectionName, ret = new IniSection(sectionName));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -102,8 +101,7 @@ namespace OpenRA.Mods.Common.FileFormats
|
|||||||
|
|
||||||
public IniSection GetSection(string s, bool allowFail)
|
public IniSection GetSection(string s, bool allowFail)
|
||||||
{
|
{
|
||||||
IniSection section;
|
if (sections.TryGetValue(s.ToLowerInvariant(), out var section))
|
||||||
if (sections.TryGetValue(s.ToLowerInvariant(), out section))
|
|
||||||
return section;
|
return section;
|
||||||
|
|
||||||
if (allowFail)
|
if (allowFail)
|
||||||
@@ -136,8 +134,7 @@ namespace OpenRA.Mods.Common.FileFormats
|
|||||||
|
|
||||||
public string GetValue(string key, string defaultValue)
|
public string GetValue(string key, string defaultValue)
|
||||||
{
|
{
|
||||||
string s;
|
return values.TryGetValue(key, out var s) ? s : defaultValue;
|
||||||
return values.TryGetValue(key, out s) ? s : defaultValue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
|
public IEnumerator<KeyValuePair<string, string>> GetEnumerator()
|
||||||
|
|||||||
@@ -394,8 +394,7 @@ namespace OpenRA.Mods.Common.FileFormats
|
|||||||
|
|
||||||
public void ExtractFile(string filename, Stream output, Action<int> onProgress = null)
|
public void ExtractFile(string filename, Stream output, Action<int> onProgress = null)
|
||||||
{
|
{
|
||||||
FileDescriptor file;
|
if (!index.TryGetValue(filename, out var file))
|
||||||
if (!index.TryGetValue(filename, out file))
|
|
||||||
throw new FileNotFoundException(filename);
|
throw new FileNotFoundException(filename);
|
||||||
|
|
||||||
ExtractFile(file, output, onProgress);
|
ExtractFile(file, output, onProgress);
|
||||||
|
|||||||
@@ -109,8 +109,7 @@ namespace OpenRA.Mods.Common.FileSystem
|
|||||||
|
|
||||||
public Stream GetStream(string filename)
|
public Stream GetStream(string filename)
|
||||||
{
|
{
|
||||||
Entry e;
|
if (!index.TryGetValue(filename, out var e))
|
||||||
if (!index.TryGetValue(filename, out e))
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
s.Seek(dataStart + e.Offset, SeekOrigin.Begin);
|
s.Seek(dataStart + e.Offset, SeekOrigin.Begin);
|
||||||
|
|||||||
@@ -53,10 +53,9 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
var sequences = new Dictionary<string, ISpriteSequence>();
|
var sequences = new Dictionary<string, ISpriteSequence>();
|
||||||
var nodes = node.Value.ToDictionary();
|
var nodes = node.Value.ToDictionary();
|
||||||
|
|
||||||
MiniYaml defaults;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (nodes.TryGetValue("Defaults", out defaults))
|
if (nodes.TryGetValue("Defaults", out var defaults))
|
||||||
{
|
{
|
||||||
nodes.Remove("Defaults");
|
nodes.Remove("Defaults");
|
||||||
foreach (var n in nodes)
|
foreach (var n in nodes)
|
||||||
@@ -123,8 +122,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
|
|
||||||
protected static T LoadField<T>(Dictionary<string, MiniYaml> d, string key, T fallback)
|
protected static T LoadField<T>(Dictionary<string, MiniYaml> d, string key, T fallback)
|
||||||
{
|
{
|
||||||
MiniYaml value;
|
if (d.TryGetValue(key, out var value))
|
||||||
if (d.TryGetValue(key, out value))
|
|
||||||
return FieldLoader.GetValue<T>(key, value.Value);
|
return FieldLoader.GetValue<T>(key, value.Value);
|
||||||
|
|
||||||
return fallback;
|
return fallback;
|
||||||
@@ -174,8 +172,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
|
|
||||||
Func<int, IEnumerable<int>> getUsedFrames = frameCount =>
|
Func<int, IEnumerable<int>> getUsedFrames = frameCount =>
|
||||||
{
|
{
|
||||||
MiniYaml length;
|
if (d.TryGetValue("Length", out var length) && length.Value == "*")
|
||||||
if (d.TryGetValue("Length", out length) && length.Value == "*")
|
|
||||||
Length = Frames != null ? Frames.Length : frameCount - Start;
|
Length = Frames != null ? Frames.Length : frameCount - Start;
|
||||||
else
|
else
|
||||||
Length = LoadField(d, "Length", 1);
|
Length = LoadField(d, "Length", 1);
|
||||||
@@ -244,8 +241,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
return usedFrames;
|
return usedFrames;
|
||||||
};
|
};
|
||||||
|
|
||||||
MiniYaml combine;
|
if (d.TryGetValue("Combine", out var combine))
|
||||||
if (d.TryGetValue("Combine", out combine))
|
|
||||||
{
|
{
|
||||||
var combined = Enumerable.Empty<Sprite>();
|
var combined = Enumerable.Empty<Sprite>();
|
||||||
foreach (var sub in combine.Nodes)
|
foreach (var sub in combine.Nodes)
|
||||||
@@ -262,8 +258,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
|
|
||||||
Func<int, IEnumerable<int>> subGetUsedFrames = subFrameCount =>
|
Func<int, IEnumerable<int>> subGetUsedFrames = subFrameCount =>
|
||||||
{
|
{
|
||||||
MiniYaml subLengthYaml;
|
if (sd.TryGetValue("Length", out var subLengthYaml) && subLengthYaml.Value == "*")
|
||||||
if (sd.TryGetValue("Length", out subLengthYaml) && subLengthYaml.Value == "*")
|
|
||||||
subLength = subFrames != null ? subFrames.Length : subFrameCount - subStart;
|
subLength = subFrames != null ? subFrames.Length : subFrameCount - subStart;
|
||||||
else
|
else
|
||||||
subLength = LoadField(sd, "Length", 1);
|
subLength = LoadField(sd, "Length", 1);
|
||||||
|
|||||||
@@ -25,8 +25,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
: base(modData)
|
: base(modData)
|
||||||
{
|
{
|
||||||
var metadata = modData.Manifest.Get<SpriteSequenceFormat>().Metadata;
|
var metadata = modData.Manifest.Get<SpriteSequenceFormat>().Metadata;
|
||||||
MiniYaml yaml;
|
if (metadata.TryGetValue("DefaultSpriteExtension", out var yaml))
|
||||||
if (metadata.TryGetValue("DefaultSpriteExtension", out yaml))
|
|
||||||
DefaultSpriteExtension = yaml.Value;
|
DefaultSpriteExtension = yaml.Value;
|
||||||
|
|
||||||
if (metadata.TryGetValue("TilesetExtensions", out yaml))
|
if (metadata.TryGetValue("TilesetExtensions", out yaml))
|
||||||
@@ -51,8 +50,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
{
|
{
|
||||||
var tsId = tileSet.Id;
|
var tsId = tileSet.Id;
|
||||||
|
|
||||||
MiniYaml yaml;
|
if (d.TryGetValue("TilesetOverrides", out var yaml))
|
||||||
if (d.TryGetValue("TilesetOverrides", out yaml))
|
|
||||||
{
|
{
|
||||||
var tsNode = yaml.Nodes.FirstOrDefault(n => n.Key == tsId);
|
var tsNode = yaml.Nodes.FirstOrDefault(n => n.Key == tsId);
|
||||||
if (tsNode != null)
|
if (tsNode != null)
|
||||||
@@ -70,8 +68,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
|
|
||||||
if (LoadField(d, "UseTilesetCode", false))
|
if (LoadField(d, "UseTilesetCode", false))
|
||||||
{
|
{
|
||||||
string code;
|
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out var code))
|
||||||
if (loader.TilesetCodes.TryGetValue(ResolveTilesetId(tileSet, d), out code))
|
|
||||||
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
|
spriteName = spriteName.Substring(0, 1) + code + spriteName.Substring(2, spriteName.Length - 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,8 +76,7 @@ namespace OpenRA.Mods.Common.Graphics
|
|||||||
{
|
{
|
||||||
var useTilesetExtension = LoadField(d, "UseTilesetExtension", false);
|
var useTilesetExtension = LoadField(d, "UseTilesetExtension", false);
|
||||||
|
|
||||||
string tilesetExtension;
|
if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out var tilesetExtension))
|
||||||
if (useTilesetExtension && loader.TilesetExtensions.TryGetValue(ResolveTilesetId(tileSet, d), out tilesetExtension))
|
|
||||||
return spriteName + tilesetExtension;
|
return spriteName + tilesetExtension;
|
||||||
|
|
||||||
return spriteName + loader.DefaultSpriteExtension;
|
return spriteName + loader.DefaultSpriteExtension;
|
||||||
|
|||||||
@@ -89,9 +89,8 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
var type = modData.ObjectCreator.FindType(widgetType + "Widget");
|
var type = modData.ObjectCreator.FindType(widgetType + "Widget");
|
||||||
var keyNames = checkMethods.SelectMany(m => (IEnumerable<string>)type.GetMethod(m).Invoke(null, new object[] { node, emitError, emitWarning }));
|
var keyNames = checkMethods.SelectMany(m => (IEnumerable<string>)type.GetMethod(m).Invoke(null, new object[] { node, emitError, emitWarning }));
|
||||||
|
|
||||||
Hotkey unused;
|
|
||||||
foreach (var name in keyNames)
|
foreach (var name in keyNames)
|
||||||
if (!namedKeys.Contains(name) && !Hotkey.TryParse(name, out unused))
|
if (!namedKeys.Contains(name) && !Hotkey.TryParse(name, out var unused))
|
||||||
emitError("{0} refers to a Key named `{1}` that does not exist".F(node.Location, name));
|
emitError("{0} refers to a Key named `{1}` that does not exist".F(node.Location, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,8 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
if (string.IsNullOrEmpty(notification))
|
if (string.IsNullOrEmpty(notification))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
SoundInfo soundInfo;
|
if (string.IsNullOrEmpty(type) || !rules.Notifications.TryGetValue(type.ToLowerInvariant(), out var soundInfo) ||
|
||||||
if (string.IsNullOrEmpty(type) || !rules.Notifications.TryGetValue(type.ToLowerInvariant(), out soundInfo) ||
|
!soundInfo.Notifications.ContainsKey(notification))
|
||||||
!soundInfo.Notifications.ContainsKey(notification))
|
|
||||||
emitError("Undefined notification reference {0}.{1} detected at {2} for {3}".F(
|
emitError("Undefined notification reference {0}.{1} detected at {2} for {3}".F(
|
||||||
type ?? "(null)", notification, traitInfo.GetType().Name, actorInfo.Key));
|
type ?? "(null)", notification, traitInfo.GetType().Name, actorInfo.Key));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,8 +95,7 @@ namespace OpenRA.Mods.Common.Lint
|
|||||||
if (!playerNames.Contains(ownerName))
|
if (!playerNames.Contains(ownerName))
|
||||||
emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName));
|
emitError("Actor {0} is owned by unknown player {1}.".F(kv.Key, ownerName));
|
||||||
|
|
||||||
RequiresSpecificOwnersInfo info;
|
if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out var info))
|
||||||
if (actorsWithRequiredOwner.TryGetValue(kv.Value.Value, out info))
|
|
||||||
if (!info.ValidOwnerNames.Contains(ownerName))
|
if (!info.ValidOwnerNames.Contains(ownerName))
|
||||||
emitError("Actor {0} owner {1} is not one of ValidOwnerNames: {2}".F(kv.Key, ownerName, info.ValidOwnerNames.JoinWith(", ")));
|
emitError("Actor {0} owner {1} is not one of ValidOwnerNames: {2}".F(kv.Key, ownerName, info.ValidOwnerNames.JoinWith(", ")));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,7 @@ namespace OpenRA.Mods.Common.LoadScreens
|
|||||||
public override void StartGame(Arguments args)
|
public override void StartGame(Arguments args)
|
||||||
{
|
{
|
||||||
var modId = args.GetValue("Content.Mod", null);
|
var modId = args.GetValue("Content.Mod", null);
|
||||||
Manifest selectedMod;
|
if (modId == null || !Game.Mods.TryGetValue(modId, out var selectedMod))
|
||||||
if (modId == null || !Game.Mods.TryGetValue(modId, out selectedMod))
|
|
||||||
throw new InvalidOperationException("Invalid or missing Content.Mod argument.");
|
throw new InvalidOperationException("Invalid or missing Content.Mod argument.");
|
||||||
|
|
||||||
var content = selectedMod.Get<ModContent>(Game.ModData.ObjectCreator);
|
var content = selectedMod.Get<ModContent>(Game.ModData.ObjectCreator);
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ namespace OpenRA.Mods.Common.Pathfinder
|
|||||||
|
|
||||||
public List<CPos> Retrieve(string key)
|
public List<CPos> Retrieve(string key)
|
||||||
{
|
{
|
||||||
CachedPath cached;
|
if (cachedPaths.TryGetValue(key, out var cached))
|
||||||
if (cachedPaths.TryGetValue(key, out cached))
|
|
||||||
{
|
{
|
||||||
if (IsExpired(cached))
|
if (IsExpired(cached))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -218,9 +218,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check for blocking actors
|
// Check for blocking actors
|
||||||
WPos blockedPos;
|
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, tailPos, headPos, info.Width, out var blockedPos))
|
||||||
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, tailPos, headPos,
|
|
||||||
info.Width, out blockedPos))
|
|
||||||
{
|
{
|
||||||
headPos = blockedPos;
|
headPos = blockedPos;
|
||||||
target = headPos;
|
target = headPos;
|
||||||
|
|||||||
@@ -205,9 +205,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
|
|
||||||
// Check for walls or other blocking obstacles
|
// Check for walls or other blocking obstacles
|
||||||
var shouldExplode = false;
|
var shouldExplode = false;
|
||||||
WPos blockedPos;
|
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width, out var blockedPos))
|
||||||
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width,
|
|
||||||
out blockedPos))
|
|
||||||
{
|
{
|
||||||
pos = blockedPos;
|
pos = blockedPos;
|
||||||
shouldExplode = true;
|
shouldExplode = true;
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
{
|
{
|
||||||
// Check for blocking actors
|
// Check for blocking actors
|
||||||
WPos blockedPos;
|
|
||||||
if (info.Blockable)
|
if (info.Blockable)
|
||||||
{
|
{
|
||||||
// If GuidedTarget has become invalid due to getting killed the same tick,
|
// If GuidedTarget has become invalid due to getting killed the same tick,
|
||||||
@@ -77,7 +76,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
target = Target.FromPos(args.PassiveTarget);
|
target = Target.FromPos(args.PassiveTarget);
|
||||||
|
|
||||||
if (BlocksProjectiles.AnyBlockingActorsBetween(world, args.Source, target.CenterPosition,
|
if (BlocksProjectiles.AnyBlockingActorsBetween(world, args.Source, target.CenterPosition,
|
||||||
info.Width, out blockedPos))
|
info.Width, out var blockedPos))
|
||||||
target = Target.FromPos(blockedPos);
|
target = Target.FromPos(blockedPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -158,9 +158,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(source);
|
target = args.Weapon.TargetActorCenter ? args.GuidedTarget.CenterPosition : args.GuidedTarget.Positions.PositionClosestTo(source);
|
||||||
|
|
||||||
// Check for blocking actors
|
// Check for blocking actors
|
||||||
WPos blockedPos;
|
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target, info.Width, out var blockedPos))
|
||||||
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, source, target,
|
|
||||||
info.Width, out blockedPos))
|
|
||||||
{
|
{
|
||||||
target = blockedPos;
|
target = blockedPos;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -849,9 +849,7 @@ namespace OpenRA.Mods.Common.Projectiles
|
|||||||
|
|
||||||
// Check for walls or other blocking obstacles
|
// Check for walls or other blocking obstacles
|
||||||
var shouldExplode = false;
|
var shouldExplode = false;
|
||||||
WPos blockedPos;
|
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width, out var blockedPos))
|
||||||
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, lastPos, pos, info.Width,
|
|
||||||
out blockedPos))
|
|
||||||
{
|
{
|
||||||
pos = blockedPos;
|
pos = blockedPos;
|
||||||
shouldExplode = true;
|
shouldExplode = true;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user