Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
01010100b committed Nov 14, 2021
1 parent bec9db5 commit f7e9909
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
8 changes: 3 additions & 5 deletions AoE2Lib/Bots/GameElements/Unit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ public Unit GetTarget()

var id = this[ObjectData.TARGET_ID];

try
if (Bot.GameState.TryGetUnit(id, out Unit unit))
{
var target = Bot.GameState.GetUnit(id);

return target;
return unit;
}
catch (ArgumentOutOfRangeException)
else
{
return null;
}
Expand Down
12 changes: 8 additions & 4 deletions AoE2Lib/Bots/GameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,19 @@ public UnitType GetUnitType(int id)
return UnitTypes[id];
}

public Unit GetUnit(int id)
public bool TryGetUnit(int id, out Unit unit)
{
if (Units.TryGetValue(id, out Unit unit))
if (Units.TryGetValue(id, out Unit u))
{
return unit;
unit = u;

return true;
}
else
{
throw new ArgumentOutOfRangeException(nameof(id));
unit = null;

return false;
}
}

Expand Down
1 change: 0 additions & 1 deletion Unary/Managers/UnitsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ private void UpdateControllers()
var controllers = GetControllers<UnitController>();
foreach (var controller in controllers)
{
controller.Unit.RequestUpdate();
if (controller.Unit.Targetable)
{
controller.Update();
Expand Down
2 changes: 1 addition & 1 deletion Unary/UnitControllers/IdlerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected override void Tick()
{
if (Unit[ObjectData.CMDID] == (int)CmdId.VILLAGER)
{
if (Unary.UnitsManager.GetControllers<HunterController>().Count == 0)
if (Unary.UnitsManager.GetControllers<HunterController>().Count < 3 && Unary.UnitsManager.GetControllers<GathererController>().Count > 0)
{
new HunterController(Unit, Unary);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ private void ChooseDeer()
{
Deer = deer[0];
}
else
{
Deer = null;
}
}

private void PushDeer()
Expand Down
7 changes: 5 additions & 2 deletions Unary/UnitControllers/MilitaryControllers/ScoutController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ protected override void MilitaryTick()

if (deer > 0)
{
new DeerPusherController(Unit, Unary);
if (Unary.UnitsManager.GetControllers<DeerPusherController>().Count == 0)
{
new DeerPusherController(Unit, Unary);

return;
return;
}
}

if (State == null)
Expand Down

0 comments on commit f7e9909

Please sign in to comment.