Skip to content

Commit

Permalink
improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
01010100b committed Sep 8, 2021
1 parent c9ea5dd commit 05b418d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
15 changes: 7 additions & 8 deletions AoE2Lib/Bots/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ internal IEnumerable<Command> 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)
{
Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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<Command> DoProduction()
Expand Down Expand Up @@ -484,7 +483,7 @@ private IEnumerable<Command> DoProduction()
ProductionTasks.Clear();

sw.Stop();
Bot.Log.Debug($"DoProduction took {sw.ElapsedMilliseconds} ms");
Bot.Log.Info($"DoProduction took {sw.ElapsedMilliseconds} ms");
}

private void DoAutoFindUnits()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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");
}
}
}
9 changes: 8 additions & 1 deletion AoE2Lib/Bots/Position.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";
}
}
}
}
2 changes: 1 addition & 1 deletion Unary/Managers/BuildingManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tile> GetFarmPlacements()
Expand Down
9 changes: 6 additions & 3 deletions Unary/Operation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion Unary/Operations/BuildOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 05b418d

Please sign in to comment.