public static IPathSearch Search(World world, LocomotorInfo li, Actor self, bool checkForBlocked, Func <CPos, bool> goalCondition) { var graph = new PathGraph(LayerPoolForWorld(world), li, self, world, checkForBlocked); var search = new PathSearch(graph); search.isGoal = goalCondition; search.heuristic = loc => 0; return(search); }
public FindResources(Actor self) { harv = self.Trait <Harvester>(); harvInfo = self.Info.TraitInfo <HarvesterInfo>(); mobile = self.Trait <Mobile>(); locomotorInfo = mobile.Info.LocomotorInfo; claimLayer = self.World.WorldActor.Trait <ResourceClaimLayer>(); pathFinder = self.World.WorldActor.Trait <IPathFinder>(); domainIndex = self.World.WorldActor.Trait <DomainIndex>(); }
public FindAndDeliverResources(Actor self, Actor deliverActor = null) { harv = self.Trait <Harvester>(); harvInfo = self.Info.TraitInfo <HarvesterInfo>(); mobile = self.Trait <Mobile>(); locomotorInfo = mobile.Info.LocomotorInfo; claimLayer = self.World.WorldActor.Trait <ResourceClaimLayer>(); pathFinder = self.World.WorldActor.Trait <IPathFinder>(); domainIndex = self.World.WorldActor.Trait <DomainIndex>(); this.deliverActor = deliverActor; }
bool ValidTransitionCell(CPos cell, LocomotorInfo li) { var terrainType = world.Map.GetTerrainInfo(cell).Type; var wli = (WaspLocomotorInfo)li; if (!wli.TransitionTerrainTypes.Contains(terrainType) && wli.TransitionTerrainTypes.Any()) { return(false); } return(true); }
public PathGraph(CellInfoLayerPool layerPool, LocomotorInfo li, Actor actor, World world, bool checkForBlocked) { pooledLayer = layerPool.Get(); groundInfo = pooledLayer.GetLayer(); locomotorInfo = li; var layers = world.GetCustomMovementLayers().Values .Where(cml => cml.EnabledForActor(actor.Info, locomotorInfo)); foreach (var cml in layers) { customLayerInfo[cml.Index] = Pair.New(cml, pooledLayer.GetLayer()); } World = world; worldMovementInfo = locomotorInfo.GetWorldMovementInfo(world); Actor = actor; LaneBias = 1; checkConditions = checkForBlocked ? CellConditions.TransientActors : CellConditions.None; checkTerrainHeight = world.Map.Grid.MaximumTerrainHeight > 0; }
public static IPathSearch FromPoints(World world, LocomotorInfo li, Actor self, IEnumerable <CPos> froms, CPos target, bool checkForBlocked) { var graph = new PathGraph(LayerPoolForWorld(world), li, self, world, checkForBlocked); var search = new PathSearch(graph) { heuristic = DefaultEstimator(target) }; search.isGoal = loc => { var locInfo = search.Graph[loc]; return(locInfo.EstimatedTotal - locInfo.CostSoFar == 0); }; foreach (var sl in froms.Where(sl => world.Map.Contains(sl))) { search.AddInitialCell(sl); } return(search); }
public static IPathSearch FromPoint(World world, LocomotorInfo li, Actor self, CPos from, CPos target, bool checkForBlocked) { var graph = new PathGraph(LayerPoolForWorld(world), li, self, world, checkForBlocked); var search = new PathSearch(graph) { heuristic = DefaultEstimator(target) }; search.isGoal = loc => { var locInfo = search.Graph[loc]; return(locInfo.EstimatedTotal - locInfo.CostSoFar == 0); }; if (world.Map.Contains(from)) { search.AddInitialCell(from); } return(search); }
int ICustomMovementLayer.ExitMovementCost(ActorInfo a, LocomotorInfo li, CPos cell) { var wli = (WaspLocomotorInfo)li; return(ValidTransitionCell(cell, wli) ? wli.TransitionCost : int.MaxValue); }
bool ICustomMovementLayer.EnabledForActor(ActorInfo a, LocomotorInfo li) { return(li is WaspLocomotorInfo); }