Issue repair orders to Repairable units via RepairOrderGenerator
This commit is contained in:
@@ -26,21 +26,35 @@ namespace OpenRA.Mods.Common.Orders
|
|||||||
return OrderInner(world, mi);
|
return OrderInner(world, mi);
|
||||||
}
|
}
|
||||||
|
|
||||||
IEnumerable<Order> OrderInner(World world, MouseInput mi)
|
static IEnumerable<Order> OrderInner(World world, MouseInput mi)
|
||||||
{
|
{
|
||||||
if (mi.Button == MouseButton.Left)
|
if (mi.Button != MouseButton.Left)
|
||||||
{
|
yield break;
|
||||||
var underCursor = world.ScreenMap.ActorsAt(mi)
|
|
||||||
.FirstOrDefault(a => !world.FogObscures(a) && a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor)
|
|
||||||
&& a.TraitsImplementing<RepairableBuilding>().Any(t => !t.IsTraitDisabled));
|
|
||||||
|
|
||||||
if (underCursor == null)
|
var underCursor = world.ScreenMap.ActorsAt(mi)
|
||||||
yield break;
|
.FirstOrDefault(a => a.AppearsFriendlyTo(world.LocalPlayer.PlayerActor) && !world.FogObscures(a));
|
||||||
|
|
||||||
if (underCursor.Info.Traits.Contains<RepairableBuildingInfo>()
|
if (underCursor == null)
|
||||||
&& underCursor.GetDamageState() > DamageState.Undamaged)
|
yield break;
|
||||||
yield return new Order("RepairBuilding", world.LocalPlayer.PlayerActor, false) { TargetActor = underCursor };
|
|
||||||
}
|
if (underCursor.GetDamageState() == DamageState.Undamaged)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
// Repair a building.
|
||||||
|
if (underCursor.Info.Traits.Contains<RepairableBuildingInfo>())
|
||||||
|
yield return new Order("RepairBuilding", world.LocalPlayer.PlayerActor, false) { TargetActor = underCursor };
|
||||||
|
|
||||||
|
// Test for generic Repairable (used on units).
|
||||||
|
var repairable = underCursor.TraitOrDefault<Repairable>();
|
||||||
|
if (repairable == null)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
// Find a building to repair at.
|
||||||
|
var repairBuilding = repairable.FindRepairBuilding(underCursor);
|
||||||
|
if (repairBuilding == null)
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
yield return new Order("Repair", underCursor, false) { TargetActor = repairBuilding };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Tick(World world)
|
public void Tick(World world)
|
||||||
|
|||||||
@@ -108,5 +108,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Actor FindRepairBuilding(Actor self)
|
||||||
|
{
|
||||||
|
var repairBuilding = self.World.ActorsWithTrait<RepairsUnits>()
|
||||||
|
.Where(a => !a.Actor.IsDead && a.Actor.IsInWorld
|
||||||
|
&& a.Actor.Owner == self.Owner &&
|
||||||
|
info.RepairBuildings.Contains(a.Actor.Info.Name))
|
||||||
|
.OrderBy(p => (self.Location - p.Actor.Location).LengthSquared);
|
||||||
|
|
||||||
|
// Worst case FirstOrDefault() will return a TraitPair<null, null>, which is OK.
|
||||||
|
return repairBuilding.FirstOrDefault().Actor;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user