From 05b418de10f61e543727d9eddac60dcba71339bf Mon Sep 17 00:00:00 2001 From: 01010100b Date: Wed, 8 Sep 2021 10:04:25 +0200 Subject: [PATCH] improve logging --- AoE2Lib/Bots/GameState.cs | 15 +++++++-------- AoE2Lib/Bots/Position.cs | 9 ++++++++- Unary/Managers/BuildingManager.cs | 2 +- Unary/Operation.cs | 9 ++++++--- Unary/Operations/BuildOperation.cs | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/AoE2Lib/Bots/GameState.cs b/AoE2Lib/Bots/GameState.cs index 1c5a762..cb9a6e6 100644 --- a/AoE2Lib/Bots/GameState.cs +++ b/AoE2Lib/Bots/GameState.cs @@ -279,7 +279,7 @@ internal IEnumerable RequestUpdate() } sw.Stop(); - Bot.Log.Debug($"GameElement RequestUpdate took {sw.ElapsedMilliseconds} ms"); + Bot.Log.Info($"GameElement RequestUpdate took {sw.ElapsedMilliseconds} ms"); foreach (var command in FindCommands) { @@ -298,10 +298,9 @@ internal void Update() { Bot.Log.Info(""); Bot.Log.Info($"Tick {Tick} Game time {GameTime:g} with {GameTimePerTick:c} game time per tick"); - foreach (var player in Players.Where(p => p.IsValid && p.Updated)) { - Bot.Log.Debug($"Player {player.PlayerNumber} has {player.Units.Count} units and {player.Score} score"); + Bot.Log.Debug($"Player {player.PlayerNumber} has {player.Units.Count(u => u.Targetable)} units and {player.Score} score"); } var sw = new Stopwatch(); @@ -375,7 +374,7 @@ internal void Update() } sw.Stop(); - Bot.Log.Debug($"GameElement Update took {sw.ElapsedMilliseconds} ms"); + Bot.Log.Info($"GameElement Update took {sw.ElapsedMilliseconds} ms"); sw.Restart(); @@ -422,7 +421,7 @@ internal void Update() } sw.Stop(); - Bot.Log.Debug($"GameState Update took {sw.ElapsedMilliseconds} ms"); + Bot.Log.Info($"GameState Update took {sw.ElapsedMilliseconds} ms"); } private IEnumerable DoProduction() @@ -484,7 +483,7 @@ private IEnumerable DoProduction() ProductionTasks.Clear(); sw.Stop(); - Bot.Log.Debug($"DoProduction took {sw.ElapsedMilliseconds} ms"); + Bot.Log.Info($"DoProduction took {sw.ElapsedMilliseconds} ms"); } private void DoAutoFindUnits() @@ -571,7 +570,7 @@ private void DoAutoFindUnits() } sw.Stop(); - Bot.Log.Debug($"DoAutoFindUnits took {sw.ElapsedMilliseconds} ms"); + Bot.Log.Info($"DoAutoFindUnits took {sw.ElapsedMilliseconds} ms"); } private void DoAutoUpdateUnits() @@ -635,7 +634,7 @@ private void DoAutoUpdateUnits() } sw.Stop(); - Bot.Log.Debug($"DoAutoUpdateUnits took {sw.ElapsedMilliseconds} ms"); + Bot.Log.Info($"DoAutoUpdateUnits took {sw.ElapsedMilliseconds} ms"); } } } diff --git a/AoE2Lib/Bots/Position.cs b/AoE2Lib/Bots/Position.cs index 6a62338..d7d8e73 100644 --- a/AoE2Lib/Bots/Position.cs +++ b/AoE2Lib/Bots/Position.cs @@ -132,7 +132,14 @@ public override bool Equals(object obj) public override string ToString() { - return $"{X:N2},{Y:N2}"; + if (PreciseX % 100 == 0 && PreciseY % 100 == 0) + { + return $"{X:N0},{Y:N0}"; + } + else + { + return $"{X:N2},{Y:N2}"; + } } } } diff --git a/Unary/Managers/BuildingManager.cs b/Unary/Managers/BuildingManager.cs index 6e924d1..2c4a13b 100644 --- a/Unary/Managers/BuildingManager.cs +++ b/Unary/Managers/BuildingManager.cs @@ -203,7 +203,7 @@ private void DoBuildOperations() builders.Remove(builder); } - Unary.Log.Info($"Build operations: {BuildOperations.Count}"); + Unary.Log.Debug($"Build operations: {BuildOperations.Count}"); } private IEnumerable GetFarmPlacements() diff --git a/Unary/Operation.cs b/Unary/Operation.cs index 2b4fcc0..19be065 100644 --- a/Unary/Operation.cs +++ b/Unary/Operation.cs @@ -91,8 +91,11 @@ public void AddUnit(Unit unit) public void RemoveUnit(Unit unit) { - _Units.Remove(unit); - Unary.Log.Debug($"Removed unit {unit.Id} from operation {ToString()}"); + if (_Units.Contains(unit)) + { + _Units.Remove(unit); + Unary.Log.Debug($"Removed unit {unit.Id} from operation {ToString()}"); + } } public void Clear() @@ -110,7 +113,7 @@ public void Stop() public override string ToString() { - return $"{GetType().Name}({Position.PointX},{Position.PointY})"; + return $"{GetType().Name}({Position})-{GetHashCode()}"; } internal void UpdateInternal() diff --git a/Unary/Operations/BuildOperation.cs b/Unary/Operations/BuildOperation.cs index e4b6b5d..9fbcf9f 100644 --- a/Unary/Operations/BuildOperation.cs +++ b/Unary/Operations/BuildOperation.cs @@ -24,7 +24,7 @@ public BuildOperation(Unary unary, Unit building) : base(unary) public override void Update() { - Unary.Log.Debug($"Building {Building.Id}"); + Unary.Log.Debug($"Building {Building[ObjectData.BASE_TYPE]}({Building.Position})"); Building.RequestUpdate();