From 4154543005fb8c726ce21ca9e598f34a96c1082d Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Mon, 29 Mar 2010 19:35:39 +1300 Subject: [PATCH] AddActor and GetVisOrigins done; exploration done --- OpenRA.Game/Traits/World/Shroud.cs | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 8db62c4abb..3c9e6e2462 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -20,6 +20,8 @@ using OpenRA.FileFormats; using System.Collections.Generic; +using OpenRA.GameRules; +using System.Linq; namespace OpenRA.Traits { @@ -32,12 +34,14 @@ namespace OpenRA.Traits { Map map; int[,] visibleCells; + bool[,] exploredCells; Dictionary vis = new Dictionary(); public Shroud(Actor self, ShroudInfo info) { map = self.World.Map; visibleCells = new int[map.MapSize, map.MapSize]; + exploredCells = new bool[map.MapSize, map.MapSize]; self.World.ActorAdded += AddActor; self.World.ActorRemoved += RemoveActor; @@ -52,6 +56,38 @@ namespace OpenRA.Traits void AddActor(Actor a) { if (a.Owner != a.Owner.World.LocalPlayer) return; + + var v = new ActorVisibility + { + range = a.Info.Traits.Get().Sight, + vis = GetVisOrigins(a).ToArray() + }; + + foreach (var p in v.vis) + foreach (var q in a.World.FindTilesInCircle(p, v.range)) + { + ++visibleCells[q.X, q.Y]; + exploredCells[q.X, q.Y] = true; + } + + vis[a] = v; + } + + static IEnumerable GetVisOrigins(Actor a) + { + if (a.Info.Traits.Contains()) + { + var bi = a.Info.Traits.Get(); + return Footprint.Tiles(a.Info.Name, bi, a.Location); + } + else + { + var mobile = a.traits.GetOrDefault(); + if (mobile != null) + return new[] { mobile.fromCell, mobile.toCell }; + else + return new[] { (1f / Game.CellSize * a.CenterLocation).ToInt2() }; + } } void RemoveActor(Actor a)