From 51098482152aa555a6bd2afe9ddcf9988c39ff5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Jim=C3=A9nez?= Date: Sat, 28 Mar 2015 07:36:39 +0100 Subject: [PATCH] Changes to improve understandability of code --- OpenRA.Game/Traits/World/ActorMap.cs | 23 ++++++++++++----------- OpenRA.Game/WPos.cs | 3 +++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/Traits/World/ActorMap.cs b/OpenRA.Game/Traits/World/ActorMap.cs index b90a987052..f6b8dc4a1d 100644 --- a/OpenRA.Game/Traits/World/ActorMap.cs +++ b/OpenRA.Game/Traits/World/ActorMap.cs @@ -212,35 +212,36 @@ namespace OpenRA.Traits yield return i.Actor; } - public bool HasFreeSubCell(CPos a, bool checkTransient = true) + public bool HasFreeSubCell(CPos cell, bool checkTransient = true) { - return FreeSubCell(a, SubCell.Any, checkTransient) != SubCell.Invalid; + return FreeSubCell(cell, SubCell.Any, checkTransient) != SubCell.Invalid; } - public SubCell FreeSubCell(CPos a, SubCell preferredSubCell = SubCell.Any, bool checkTransient = true) + public SubCell FreeSubCell(CPos cell, SubCell preferredSubCell = SubCell.Any, bool checkTransient = true) { - if (preferredSubCell > SubCell.Any && !AnyUnitsAt(a, preferredSubCell, checkTransient)) + if (preferredSubCell > SubCell.Any && !AnyUnitsAt(cell, preferredSubCell, checkTransient)) return preferredSubCell; - if (!AnyUnitsAt(a)) + if (!AnyUnitsAt(cell)) return map.DefaultSubCell; for (var i = (int)SubCell.First; i < map.SubCellOffsets.Length; i++) - if (i != (int)preferredSubCell && !AnyUnitsAt(a, (SubCell)i, checkTransient)) + if (i != (int)preferredSubCell && !AnyUnitsAt(cell, (SubCell)i, checkTransient)) return (SubCell)i; + return SubCell.Invalid; } - public SubCell FreeSubCell(CPos a, SubCell preferredSubCell, Func checkIfBlocker) + public SubCell FreeSubCell(CPos cell, SubCell preferredSubCell, Func checkIfBlocker) { - if (preferredSubCell > SubCell.Any && !AnyUnitsAt(a, preferredSubCell, checkIfBlocker)) + if (preferredSubCell > SubCell.Any && !AnyUnitsAt(cell, preferredSubCell, checkIfBlocker)) return preferredSubCell; - if (!AnyUnitsAt(a)) + if (!AnyUnitsAt(cell)) return map.DefaultSubCell; for (var i = (int)SubCell.First; i < map.SubCellOffsets.Length; i++) - if (i != (int)preferredSubCell && !AnyUnitsAt(a, (SubCell)i, checkIfBlocker)) + if (i != (int)preferredSubCell && !AnyUnitsAt(cell, (SubCell)i, checkIfBlocker)) return (SubCell)i; return SubCell.Invalid; } @@ -325,7 +326,7 @@ namespace OpenRA.Traits } } - void RemoveInfluenceInner(ref InfluenceNode influenceNode, Actor toRemove) + static void RemoveInfluenceInner(ref InfluenceNode influenceNode, Actor toRemove) { if (influenceNode == null) return; diff --git a/OpenRA.Game/WPos.cs b/OpenRA.Game/WPos.cs index 024e6ab4df..c1dfc4babc 100644 --- a/OpenRA.Game/WPos.cs +++ b/OpenRA.Game/WPos.cs @@ -35,6 +35,9 @@ namespace OpenRA public static bool operator ==(WPos me, WPos other) { return me.X == other.X && me.Y == other.Y && me.Z == other.Z; } public static bool operator !=(WPos me, WPos other) { return !(me == other); } + /// + /// Returns the linear interpolation between points 'a' and 'b' + /// public static WPos Lerp(WPos a, WPos b, int mul, int div) { return a + (b - a) * mul / div; } public static WPos LerpQuadratic(WPos a, WPos b, WAngle pitch, int mul, int div)