Implement SupportPower.CellsMatching.

This commit is contained in:
Zimmermann Gyula
2018-05-22 06:29:58 +02:00
committed by atlimit8
parent d531d6f3ef
commit 485faac294

View File

@@ -9,6 +9,8 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
@@ -191,5 +193,17 @@ namespace OpenRA.Mods.Common.Traits
var speech = isAllied ? Info.LaunchSpeechNotification : Info.IncomingSpeechNotification;
Game.Sound.PlayNotification(Self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName);
}
public IEnumerable<CPos> CellsMatching(CPos location, string footprint, CVec dimensions)
{
var index = 0;
var fp = footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
var x = location.X - (dimensions.X - 1) / 2;
var y = location.Y - (dimensions.Y - 1) / 2;
for (var j = 0; j < dimensions.Y; j++)
for (var i = 0; i < dimensions.X; i++)
if (fp[index++] == 'x')
yield return new CPos(x + i, y + j);
}
}
}