public PathSearch(World world, MobileInfo mobileInfo) { this.world = world; bim = world.WorldActor.Trait<BuildingInfluence>(); uim = world.WorldActor.Trait<UnitInfluence>(); cellInfo = InitCellInfo(); this.mobileInfo = mobileInfo; queue = new PriorityQueue<PathDistance>(); }
public static PathSearch FromPoint( World world, MobileInfo mi, int2 from, int2 target, bool checkForBlocked ) { var search = new PathSearch(world, mi) { heuristic = DefaultEstimator( target ), checkForBlocked = checkForBlocked }; search.AddInitialCell( world, from ); return search; }
public PathSearch(World world, MobileInfo mobileInfo, Actor self) { this.world = world; cellInfo = InitCellInfo(); this.mobileInfo = mobileInfo; this.self = self; customCost = null; queue = new PriorityQueue<PathDistance>(); }
public FindResources(Actor self) { harv = self.Trait<Harvester>(); harvInfo = self.Info.Traits.Get<HarvesterInfo>(); mobile = self.Trait<Mobile>(); mobileInfo = self.Info.Traits.Get<MobileInfo>(); resLayer = self.World.WorldActor.Trait<ResourceLayer>(); territory = self.World.WorldActor.TraitOrDefault<ResourceClaimLayer>(); pathFinder = self.World.WorldActor.Trait<IPathFinder>(); }
public Mobile(ActorInitializer init, MobileInfo info) { this.self = init.self; this.Info = info; uim = self.World.WorldActor.Trait<UnitInfluence>(); if (init.Contains<LocationInit>()) { this.__fromCell = this.__toCell = init.Get<LocationInit,int2>(); AddInfluence(); } this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing; this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0; }
public Mobile(ActorInitializer init, MobileInfo info) { this.self = init.self; this.Info = info; shroud = self.World.WorldActor.Trait<Shroud>(); uim = self.World.WorldActor.Trait<UnitInfluence>(); bim = self.World.WorldActor.Trait<BuildingInfluence>(); canShareCell = self.HasTrait<SharesCell>(); if (init.Contains<LocationInit>()) { this.__fromCell = this.__toCell = init.Get<LocationInit,int2>(); AddInfluence(); } this.Facing = init.Contains<FacingInit>() ? init.Get<FacingInit,int>() : info.InitialFacing; this.Altitude = init.Contains<AltitudeInit>() ? init.Get<AltitudeInit,int>() : 0; TerrainCost = new Dictionary<string, float>(); TerrainSpeed = new Dictionary<string, float>(); if (info.TerrainTypes.Count() != info.TerrainSpeeds.Count()) throw new InvalidOperationException("Mobile TerrainType/TerrainSpeed length mismatch"); if (info.TerrainCostOverrides != null) for (int i = 0; i < info.TerrainCostOverrides.Count(); i++) { TerrainCost.Add(info.TerrainCostOverrides[i], info.TerrainCosts[i]); } for (int i = 0; i < info.TerrainTypes.Count(); i++) { if (!TerrainCost.ContainsKey(info.TerrainTypes[i])) TerrainCost.Add(info.TerrainTypes[i], 1f/info.TerrainSpeeds[i]); TerrainSpeed.Add(info.TerrainTypes[i], info.TerrainSpeeds[i]); } }
public static PathSearch FromPoints(World world, MobileInfo mi, IEnumerable<int2> froms, int2 target, bool checkForBlocked) { var search = new PathSearch(world, mi) { heuristic = DefaultEstimator(target), checkForBlocked = checkForBlocked }; foreach (var sl in froms) search.AddInitialCell(world, sl); return search; }
public static PathSearch Search( World world, MobileInfo mi, bool checkForBlocked ) { var search = new PathSearch(world, mi) { checkForBlocked = checkForBlocked }; return search; }
public MoveOrderTargeter( MobileInfo unitType ) { this.unitType = unitType; }
public static int MovementCostForCell(MobileInfo info, World world, int2 cell) { if (!world.Map.IsInMap(cell.X,cell.Y)) return int.MaxValue; var type = world.GetTerrainType(cell); if (!info.TerrainSpeeds.ContainsKey(type)) return int.MaxValue; return info.TerrainSpeeds[type].Cost; }
public static bool CanEnterCell( MobileInfo mobileInfo, World world, UnitInfluence uim, BuildingInfluence bim, int2 cell, Actor ignoreActor, bool checkTransientActors ) { if (MovementCostForCell(mobileInfo, world, cell) == int.MaxValue) return false; // Check for buildings var building = bim.GetBuildingBlocking(cell); if (building != null && building != ignoreActor) { if (mobileInfo.Crushes == null) return false; var crushable = building.TraitsImplementing<ICrushable>(); if (crushable.Count() == 0) return false; if (!crushable.Any(b => b.CrushClasses.Intersect(mobileInfo.Crushes).Any())) return false; } // Check mobile actors var blockingActors = uim.GetUnitsAt( cell ).Where( x => x != ignoreActor ).ToList(); if (checkTransientActors && blockingActors.Count > 0) { // We can enter a cell with nonshareable units only if we can crush all of them if (mobileInfo.Crushes == null) return false; if (blockingActors.Any(a => !(a.HasTrait<ICrushable>() && a.TraitsImplementing<ICrushable>().Any(b => b.CrushClasses.Intersect(mobileInfo.Crushes).Any())))) return false; } return true; }
public static bool CanEnterCell( World world, MobileInfo mi, int2 cell, Actor ignoreActor, bool checkTransientActors ) { var bim = world.WorldActor.Trait<BuildingInfluence>(); var uim = world.WorldActor.Trait<UnitInfluence>(); return Mobile.CanEnterCell( mi, world, uim, bim, cell, ignoreActor, checkTransientActors ); }