Split Locomotor trait from Mobile

Add GrantConditionOn*Layer traits

This allows to
- drop some booleans from Locomotor
- drop a good part of the subterranean- and jumpjet-specific code/hacks from Mobile
- grant more than 1 condition per layer type (via multiple traits)
- easily add more traits of this kind for other layers
This commit is contained in:
reaperrr
2018-03-14 20:51:16 +01:00
committed by abcdefg30
parent f453d9c148
commit 81343926b6
29 changed files with 813 additions and 475 deletions

View File

@@ -41,16 +41,16 @@ namespace OpenRA.Mods.Common.AI
CPos FindNextResource(Actor actor, Harvester harv)
{
var mobileInfo = actor.Info.TraitInfo<MobileInfo>();
var passable = (uint)mobileInfo.GetMovementClass(world.Map.Rules.TileSet);
var locomotorInfo = actor.Info.TraitInfo<MobileInfo>().LocomotorInfo;
var passable = (uint)locomotorInfo.GetMovementClass(World.Map.Rules.TileSet);
Func<CPos, bool> isValidResource = cell =>
domainIndex.IsPassable(actor.Location, cell, mobileInfo, passable) &&
domainIndex.IsPassable(actor.Location, cell, locomotorInfo, passable) &&
harv.CanHarvestCell(actor, cell) &&
claimLayer.CanClaimCell(actor, cell);
var path = pathfinder.FindPath(
PathSearch.Search(world, mobileInfo, actor, true, isValidResource)
PathSearch.Search(world, locomotorInfo, actor, true, isValidResource)
.WithCustomCost(loc => world.FindActorsInCircle(world.Map.CenterOfCell(loc), ai.Info.HarvesterEnemyAvoidanceRadius)
.Where(u => !u.IsDead && actor.Owner.Stances[u.Owner] == Stance.Enemy)
.Sum(u => Math.Max(WDist.Zero.Length, ai.Info.HarvesterEnemyAvoidanceRadius.Length - (world.Map.CenterOfCell(loc) - u.CenterPosition).Length)))

View File

@@ -30,12 +30,12 @@ namespace OpenRA.Mods.Common.AI
// (Way better than finding a nearest target which is likely to be on Ground)
// You might be tempted to move these lookups into Activate() but that causes null reference exception.
var domainIndex = first.World.WorldActor.Trait<DomainIndex>();
var mobileInfo = first.Info.TraitInfo<MobileInfo>();
var passable = (uint)mobileInfo.GetMovementClass(first.World.Map.Rules.TileSet);
var locomotorInfo = first.Info.TraitInfo<MobileInfo>().LocomotorInfo;
var passable = (uint)locomotorInfo.GetMovementClass(first.World.Map.Rules.TileSet);
var navalProductions = owner.World.ActorsHavingTrait<Building>().Where(a
=> owner.Bot.Info.BuildingCommonNames.NavalProduction.Contains(a.Info.Name)
&& domainIndex.IsPassable(first.Location, a.Location, mobileInfo, passable)
&& domainIndex.IsPassable(first.Location, a.Location, locomotorInfo, passable)
&& a.AppearsHostileTo(first));
if (navalProductions.Any())