From a9126fc9ce3dd37614961281c08fc8ab93b172cb Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 4 Nov 2009 18:18:17 +1300 Subject: [PATCH] bdebug=true will show appropriate influence for current building --- OpenRa.Game/MainWindow.cs | 1 + OpenRa.Game/Traits/Activities/Harvest.cs | 18 +++++++++++++----- OpenRa.Game/UiOverlay.cs | 13 +++++++++++-- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 11520f56b5..1de646252b 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -50,6 +50,7 @@ namespace OpenRa.Game SheetBuilder.Initialize(renderer); UiOverlay.ShowUnitDebug = settings.GetValue("udebug", false); + UiOverlay.ShowBuildDebug = settings.GetValue("bdebug", false); WorldRenderer.ShowUnitPaths = settings.GetValue("pathdebug", false); Game.Replay = settings.GetValue("replay", ""); diff --git a/OpenRa.Game/Traits/Activities/Harvest.cs b/OpenRa.Game/Traits/Activities/Harvest.cs index 4620dc5c3f..a2d9e8d8ed 100644 --- a/OpenRa.Game/Traits/Activities/Harvest.cs +++ b/OpenRa.Game/Traits/Activities/Harvest.cs @@ -41,11 +41,7 @@ namespace OpenRa.Game.Traits.Activities void PlanReturnToBase(Actor self, Mobile mobile) { /* find a proc */ - var proc = Game.world.Actors.Where( - a => a.Owner == self.Owner && - a.traits.Contains()) - .FirstOrDefault(); /* todo: *closest* proc, maybe? */ - + var proc = ChooseReturnLocation(self); if (proc == null) { Cancel(self, mobile); /* is this a sane way to cancel? */ @@ -59,6 +55,18 @@ namespace OpenRa.Game.Traits.Activities mobile.InternalSetActivity(NextActivity); } + static Actor ChooseReturnLocation(Actor self) + { + /* todo: compute paths to possible procs, taking into account enemy presence */ + /* currently, we're good at choosing close, inaccessible procs */ + + return Game.world.Actors.Where( + a => a.Owner == self.Owner && + a.traits.Contains()) + .OrderBy(p => (p.Location - self.Location).LengthSquared) + .FirstOrDefault(); + } + void PlanMoreHarvesting(Actor self, Mobile mobile) { /* find a nearby patch */ diff --git a/OpenRa.Game/UiOverlay.cs b/OpenRa.Game/UiOverlay.cs index 6a58a4d7d3..ed48b17de2 100644 --- a/OpenRa.Game/UiOverlay.cs +++ b/OpenRa.Game/UiOverlay.cs @@ -11,7 +11,8 @@ namespace OpenRa.Game SpriteRenderer spriteRenderer; Sprite buildOk, buildBlocked, unitDebug; - public static bool ShowUnitDebug = false; + public static bool ShowUnitDebug = false; + public static bool ShowBuildDebug = false; public UiOverlay(SpriteRenderer spriteRenderer) { @@ -48,7 +49,15 @@ namespace OpenRa.Game var bi = (UnitInfo.BuildingInfo)Rules.UnitInfo[placeBuilding.Name]; - var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */ + var maxDistance = bi.Adjacent + 2; /* real-ra is weird. this is 1 GAP. */ + + if (ShowBuildDebug) + for (var j = 0; j < 128; j++) + for (var i = 0; i < 128; i++) + if (Game.GetDistanceToBase(new int2(i, j), Game.LocalPlayer) < maxDistance) + if (Game.IsCellBuildable(new int2(i, j), bi.WaterBound ? UnitMovementType.Float : UnitMovementType.Wheel)) + spriteRenderer.DrawSprite(unitDebug, Game.CellSize * new float2(i, j), 0); + var tooFarFromBase = !Footprint.Tiles(bi, position).Any( t => Game.GetDistanceToBase(t, Game.LocalPlayer) < maxDistance);