diff --git a/isometric-park-fna/Engines/BuildToolEngine.cs b/isometric-park-fna/Engines/BuildToolEngine.cs --- a/isometric-park-fna/Engines/BuildToolEngine.cs +++ b/isometric-park-fna/Engines/BuildToolEngine.cs @@ -6,6 +6,7 @@ using Microsoft.Xna.Framework.Input; using Encompass; +using JM.LinqFaster; using isometricparkfna.Messages; using isometricparkfna.Components; @@ -18,7 +19,9 @@ // typeof(SelectedComponent), typeof(PreserveComponent))] [Reads(typeof(SelectedComponent), - typeof(AreaComponent))] + typeof(ContractStatusComponent), + typeof(AreaComponent), + typeof(PreserveComponent))] public class BuildToolEngine : Engine { private CellMap Map; @@ -43,6 +46,26 @@ } public override void Update(double dt) { + var occupied = new List(); + foreach (var (entity, status) in ReadEntities() + .WhereF((e) => HasComponent(e)) + .SelectWhereF((e) => (e, GetComponent(e)), + (e) => ((e.Item2.status != ContractStatus.Broken) + && (e.Item2.status != ContractStatus.Rejected) + && (e.Item2.status != ContractStatus.Expired) + && (e.Item2.status != ContractStatus.Completed) + && (e.Item2.status != ContractStatus.Proposed)) + )) { + var entitySquares = GetComponent(entity).squares; + occupied.AddRange(entitySquares); + } + foreach (var entity in ReadEntities() + .WhereF((e) => HasComponent(e))) { + var entitySquares = GetComponent(entity).squares; + occupied.AddRange(entitySquares); + } + + foreach (ref readonly var message in ReadMessages()) { @@ -77,7 +100,10 @@ foreach (var i in step_until(area.squares[0].X, end_x)) { foreach (var j in step_until(area.squares[0].Y, end_y)) { - newSquares.Add(new Vector2(i, j)); + var newSquare = new Vector2(i, j); + if (!occupied.Contains(newSquare)) { + newSquares.Add(newSquare); + } } }