public Stance_Warmup(int ticks, LocalTargetInfo focusTarg, Verb verb) : base(ticks, focusTarg, verb) { if (focusTarg.HasThing && focusTarg.Thing is Pawn) { Pawn pawn = (Pawn)focusTarg.Thing; targetStartedDowned = pawn.Downed; if (pawn.apparel != null) { for (int i = 0; i < pawn.apparel.WornApparelCount; i++) { (pawn.apparel.WornApparel[i] as ShieldBelt)?.KeepDisplaying(); } } } if (verb != null) { if (verb.verbProps.soundAiming != null) { SoundInfo info = SoundInfo.InMap(verb.caster, MaintenanceType.PerTick); if (verb.CasterIsPawn) { info.pitchFactor = 1f / verb.CasterPawn.GetStatValue(StatDefOf.AimingDelayFactor); } sustainer = verb.verbProps.soundAiming.TrySpawnSustainer(info); } if (verb.verbProps.warmupEffecter != null && verb.Caster != null) { effecter = verb.verbProps.warmupEffecter.Spawn(verb.Caster, verb.Caster.Map); effecter.Trigger(verb.Caster, focusTarg.ToTargetInfo(verb.Caster.Map)); } } drawAimPie = verb?.verbProps.drawAimPie ?? false; }
public static bool CanReachImmediate(IntVec3 start, LocalTargetInfo target, Map map, PathEndMode peMode, Pawn pawn) { if (!target.IsValid) { return(false); } target = (LocalTargetInfo)GenPath.ResolvePathMode(pawn, target.ToTargetInfo(map), ref peMode); if (target.HasThing) { Thing thing = target.Thing; if (thing.Spawned) { if (thing.Map != map) { return(false); } goto IL_00d3; } if (pawn != null) { if (pawn.carryTracker.innerContainer.Contains(thing)) { return(true); } if (pawn.inventory.innerContainer.Contains(thing)) { return(true); } if (pawn.apparel != null && pawn.apparel.Contains(thing)) { return(true); } if (pawn.equipment != null && pawn.equipment.Contains(thing)) { return(true); } } return(false); } goto IL_00d3; IL_00d3: if (!target.HasThing || (target.Thing.def.size.x == 1 && target.Thing.def.size.z == 1)) { if (start == target.Cell) { return(true); } } else if (start.IsInside(target.Thing)) { return(true); } if (peMode == PathEndMode.Touch && TouchPathEndModeUtility.IsAdjacentOrInsideAndAllowedToTouch(start, target, map)) { return(true); } return(false); }
public static ShotReport HitReportFor(Thing caster, Verb verb, LocalTargetInfo target) { Pawn pawn = caster as Pawn; IntVec3 cell = target.Cell; ShotReport result = default(ShotReport); result.distance = (cell - caster.Position).LengthHorizontal; result.target = target.ToTargetInfo(caster.Map); float f = (float)((pawn == null) ? 0.95999997854232788 : pawn.GetStatValue(StatDefOf.ShootingAccuracy, true)); result.factorFromShooterAndDist = Mathf.Pow(f, result.distance); if (result.factorFromShooterAndDist < 0.020099999383091927) { result.factorFromShooterAndDist = 0.0201f; } result.factorFromEquipment = verb.verbProps.GetHitChanceFactor(verb.ownerEquipment, result.distance); result.covers = CoverUtility.CalculateCoverGiverSet(cell, caster.Position, caster.Map); result.coversOverallBlockChance = CoverUtility.CalculateOverallBlockChance(cell, caster.Position, caster.Map); result.coveringGas = null; ShootLine shootLine = default(ShootLine); if (verb.TryFindShootLineFromTo(verb.caster.Position, target, out shootLine)) { foreach (IntVec3 item in shootLine.Points()) { Thing gas = item.GetGas(caster.Map); if (gas != null && (result.coveringGas == null || result.coveringGas.gas.accuracyPenalty < gas.def.gas.accuracyPenalty)) { result.coveringGas = gas.def; } } } if (!caster.Position.Roofed(caster.Map) && !target.Cell.Roofed(caster.Map)) { result.factorFromWeather = caster.Map.weatherManager.CurWeatherAccuracyMultiplier; } else { result.factorFromWeather = 1f; } result.factorFromTargetSize = 1f; if (target.HasThing) { Pawn pawn2 = target.Thing as Pawn; if (pawn2 != null) { result.factorFromTargetSize = pawn2.BodySize; } else { result.factorFromTargetSize = (float)(target.Thing.def.fillPercent * 1.7000000476837158); } result.factorFromTargetSize = Mathf.Clamp(result.factorFromTargetSize, 0.5f, 2f); } result.forcedMissRadius = verb.verbProps.forcedMissRadius; return(result); }
public static ShotReport HitReportFor(Thing caster, Verb verb, LocalTargetInfo target) { IntVec3 cell = target.Cell; ShotReport result = default(ShotReport); result.distance = (cell - caster.Position).LengthHorizontal; result.target = target.ToTargetInfo(caster.Map); result.factorFromShooterAndDist = HitFactorFromShooter(caster, result.distance); result.factorFromEquipment = verb.verbProps.GetHitChanceFactor(verb.EquipmentSource, result.distance); result.covers = CoverUtility.CalculateCoverGiverSet(target, caster.Position, caster.Map); result.coversOverallBlockChance = CoverUtility.CalculateOverallBlockChance(target, caster.Position, caster.Map); result.coveringGas = null; if (verb.TryFindShootLineFromTo(verb.caster.Position, target, out result.shootLine)) { foreach (IntVec3 item in result.shootLine.Points()) { Thing gas = item.GetGas(caster.Map); if (gas != null && (result.coveringGas == null || result.coveringGas.gas.accuracyPenalty < gas.def.gas.accuracyPenalty)) { result.coveringGas = gas.def; } } } else { result.shootLine = new ShootLine(IntVec3.Invalid, IntVec3.Invalid); } if (!caster.Position.Roofed(caster.Map) || !target.Cell.Roofed(caster.Map)) { result.factorFromWeather = caster.Map.weatherManager.CurWeatherAccuracyMultiplier; } else { result.factorFromWeather = 1f; } if (target.HasThing) { Pawn pawn = target.Thing as Pawn; if (pawn != null) { result.factorFromTargetSize = pawn.BodySize; } else { result.factorFromTargetSize = target.Thing.def.fillPercent * (float)target.Thing.def.size.x * (float)target.Thing.def.size.z * 2.5f; } result.factorFromTargetSize = Mathf.Clamp(result.factorFromTargetSize, 0.5f, 2f); } else { result.factorFromTargetSize = 1f; } result.forcedMissRadius = verb.verbProps.forcedMissRadius; return(result); }
public bool CanReach(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams) { if (this.working) { Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233, false); return(false); } if (traverseParams.pawn != null) { if (!traverseParams.pawn.Spawned) { return(false); } if (traverseParams.pawn.Map != this.map) { Log.Error(string.Concat(new object[] { "Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=", traverseParams.pawn, " pawn.Map=", traverseParams.pawn.Map, " map=", this.map }), false); return(false); } } if (ReachabilityImmediate.CanReachImmediate(start, dest, this.map, peMode, traverseParams.pawn)) { return(true); } if (!dest.IsValid) { return(false); } if (dest.HasThing && dest.Thing.Map != this.map) { return(false); } if (!start.InBounds(this.map) || !dest.Cell.InBounds(this.map)) { return(false); } if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { Room room = RegionAndRoomQuery.RoomAtFast(start, this.map, RegionType.Set_Passable); if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, this.map, RegionType.Set_Passable)) { return(true); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { TraverseParms traverseParams2 = traverseParams; traverseParams2.mode = TraverseMode.PassDoors; if (this.CanReach(start, dest, peMode, traverseParams2)) { return(true); } } dest = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(this.map), ref peMode); this.working = true; bool result; try { this.pathGrid = this.map.pathGrid; this.regionGrid = this.map.regionGrid; this.reachedIndex += 1u; this.destRegions.Clear(); if (peMode == PathEndMode.OnCell) { Region region = dest.Cell.GetRegion(this.map, RegionType.Set_Passable); if (region != null && region.Allows(traverseParams, true)) { this.destRegions.Add(region); } } else if (peMode == PathEndMode.Touch) { TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, this.map, this.destRegions); } if (this.destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { this.FinalizeCheck(); result = false; } else { this.destRegions.RemoveDuplicates <Region>(); this.openQueue.Clear(); this.numRegionsOpened = 0; this.DetermineStartRegions(start); if (this.openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { this.FinalizeCheck(); result = false; } else { if (this.startingRegions.Any <Region>() && this.destRegions.Any <Region>() && this.CanUseCache(traverseParams.mode)) { BoolUnknown cachedResult = this.GetCachedResult(traverseParams); if (cachedResult == BoolUnknown.True) { this.FinalizeCheck(); result = true; return(result); } if (cachedResult == BoolUnknown.False) { this.FinalizeCheck(); result = false; return(result); } if (cachedResult != BoolUnknown.Unknown) { } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) { bool flag = this.CheckCellBasedReachability(start, dest, peMode, traverseParams); this.FinalizeCheck(); result = flag; } else { bool flag2 = this.CheckRegionBasedReachability(traverseParams); this.FinalizeCheck(); result = flag2; } } } } finally { this.working = false; } return(result); }
public bool CanReach(IntVec3 start, LocalTargetInfo dest, PathEndMode peMode, TraverseParms traverseParams) { if (working) { Log.ErrorOnce("Called CanReach() while working. This should never happen. Suppressing further errors.", 7312233); return(false); } if (traverseParams.pawn != null) { if (!traverseParams.pawn.Spawned) { return(false); } if (traverseParams.pawn.Map != map) { Log.Error(string.Concat("Called CanReach() with a pawn spawned not on this map. This means that we can't check his reachability here. Pawn's current map should have been used instead of this one. pawn=", traverseParams.pawn, " pawn.Map=", traverseParams.pawn.Map, " map=", map)); return(false); } } if (ReachabilityImmediate.CanReachImmediate(start, dest, map, peMode, traverseParams.pawn)) { return(true); } if (!dest.IsValid) { return(false); } if (dest.HasThing && dest.Thing.Map != map) { return(false); } if (!start.InBounds(map) || !dest.Cell.InBounds(map)) { return(false); } if ((peMode == PathEndMode.OnCell || peMode == PathEndMode.Touch || peMode == PathEndMode.ClosestTouch) && traverseParams.mode != TraverseMode.NoPassClosedDoorsOrWater && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { Room room = RegionAndRoomQuery.RoomAtFast(start, map); if (room != null && room == RegionAndRoomQuery.RoomAtFast(dest.Cell, map)) { return(true); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings) { TraverseParms traverseParams2 = traverseParams; traverseParams2.mode = TraverseMode.PassDoors; if (CanReach(start, dest, peMode, traverseParams2)) { return(true); } } dest = (LocalTargetInfo)GenPath.ResolvePathMode(traverseParams.pawn, dest.ToTargetInfo(map), ref peMode); working = true; try { pathGrid = map.pathGrid; regionGrid = map.regionGrid; reachedIndex++; destRegions.Clear(); switch (peMode) { case PathEndMode.OnCell: { Region region = dest.Cell.GetRegion(map); if (region != null && region.Allows(traverseParams, isDestination: true)) { destRegions.Add(region); } break; } case PathEndMode.Touch: TouchPathEndModeUtility.AddAllowedAdjacentRegions(dest, traverseParams, map, destRegions); break; } if (destRegions.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { FinalizeCheck(); return(false); } destRegions.RemoveDuplicates(); openQueue.Clear(); numRegionsOpened = 0; DetermineStartRegions(start); if (openQueue.Count == 0 && traverseParams.mode != TraverseMode.PassAllDestroyableThings && traverseParams.mode != TraverseMode.PassAllDestroyableThingsNotWater) { FinalizeCheck(); return(false); } if (startingRegions.Any() && destRegions.Any() && CanUseCache(traverseParams.mode)) { switch (GetCachedResult(traverseParams)) { case BoolUnknown.True: FinalizeCheck(); return(true); case BoolUnknown.False: FinalizeCheck(); return(false); } } if (traverseParams.mode == TraverseMode.PassAllDestroyableThings || traverseParams.mode == TraverseMode.PassAllDestroyableThingsNotWater || traverseParams.mode == TraverseMode.NoPassClosedDoorsOrWater) { bool result = CheckCellBasedReachability(start, dest, peMode, traverseParams); FinalizeCheck(); return(result); } bool result2 = CheckRegionBasedReachability(traverseParams); FinalizeCheck(); return(result2); } finally { working = false; } }