public PathSearch(World world, MobileInfo mobileInfo) { this.world = world; uim = world.WorldActor.Trait<UnitInfluence>(); cellInfo = InitCellInfo(); this.mobileInfo = mobileInfo; queue = new PriorityQueue<PathDistance>(); }
public PathSearch(World world) { cellInfo = InitCellInfo(); queue = new PriorityQueue<PathDistance>(); buildingInfluence = world.WorldActor.traits.Get<BuildingInfluence>(); unitInfluence = world.WorldActor.traits.Get<UnitInfluence>(); }
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>(); this.PxPosition = Util.CenterOfCell(fromCell); } 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; uim = self.World.WorldActor.Trait<UnitInfluence>(); __toSubCell = __fromSubCell = info.SharesCell ? SubCell.Center : SubCell.FullCell; if (init.Contains<SubCellInit>()) { this.__fromSubCell = this.__toSubCell = init.Get<SubCellInit, SubCell>(); } if (init.Contains<LocationInit>()) { this.__fromCell = this.__toCell = init.Get<LocationInit, int2>(); this.PxPosition = Util.CenterOfCell(fromCell) + info.SubCellOffsets[__fromSubCell]; } 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 bool CanEnterCell(World world, UnitInfluence uim, int2 cell, Actor ignoreActor, bool checkTransientActors) { if (MovementCostForCell(world, cell) == int.MaxValue) return false; if (SharesCell && uim.HasFreeSubCell(cell)) return true; var blockingActors = uim.GetUnitsAt(cell).Where(x => x != ignoreActor).ToList(); if (checkTransientActors && blockingActors.Count > 0) { // Non-sharable unit can enter a cell with shareable units only if it can crush all of them if (Crushes == null) return false; if (blockingActors.Any(a => !(a.HasTrait<ICrushable>() && a.TraitsImplementing<ICrushable>().Any(b => b.CrushClasses.Intersect(Crushes).Any())))) return false; } return true; }
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; }