private bool IsValidTarget(Thing t) { Pawn pawn = t as Pawn; if (pawn != null) { if (AttackVerb.ProjectileFliesOverhead()) { RoofDef roofDef = base.Map.roofGrid.RoofAt(t.Position); if (roofDef != null && roofDef.isThickRoof) { return(false); } } if (mannableComp == null) { return(!GenAI.MachinesLike(base.Faction, pawn)); } if (pawn.RaceProps.Animal && pawn.Faction == Faction.OfPlayer) { return(false); } } return(true); }
protected LocalTargetInfo TryFindNewTarget() { IAttackTargetSearcher attackTargetSearcher = TargSearcher(); Faction faction = attackTargetSearcher.Thing.Faction; float range = AttackVerb.verbProps.range; if (Rand.Value < 0.5f && AttackVerb.ProjectileFliesOverhead() && faction.HostileTo(Faction.OfPlayer) && base.Map.listerBuildings.allBuildingsColonist.Where(delegate(Building x) { float num = AttackVerb.verbProps.EffectiveMinRange(x, this); float num2 = (float)x.Position.DistanceToSquared(base.Position); return(num2 > num * num && num2 < range * range); }).TryRandomElement(out Building result)) { return(result); } TargetScanFlags targetScanFlags = TargetScanFlags.NeedThreat; if (!AttackVerb.ProjectileFliesOverhead()) { targetScanFlags |= TargetScanFlags.NeedLOSToAll; targetScanFlags |= TargetScanFlags.LOSBlockableByGas; } if (AttackVerb.IsIncendiary()) { targetScanFlags |= TargetScanFlags.NeedNonBurning; } return((Thing)AttackTargetFinder.BestShootTargetFromCurrentPosition(attackTargetSearcher, targetScanFlags, IsValidTarget)); }
protected void TryStartShootSomething(bool canBeginBurstImmediately) { if (progressBarEffecter != null) { progressBarEffecter.Cleanup(); progressBarEffecter = null; } if (!base.Spawned || (holdFire && CanToggleHoldFire) || (AttackVerb.ProjectileFliesOverhead() && base.Map.roofGrid.Roofed(base.Position)) || !AttackVerb.Available()) { ResetCurrentTarget(); return; } bool isValid = currentTargetInt.IsValid; if (forcedTarget.IsValid) { currentTargetInt = forcedTarget; } else { currentTargetInt = TryFindNewTarget(); } if (!isValid && currentTargetInt.IsValid) { SoundDefOf.TurretAcquireTarget.PlayOneShot(new TargetInfo(base.Position, base.Map)); } if (currentTargetInt.IsValid) { if (def.building.turretBurstWarmupTime > 0f) { burstWarmupTicksLeft = def.building.turretBurstWarmupTime.SecondsToTicks(); } else if (canBeginBurstImmediately) { BeginBurst(); } else { burstWarmupTicksLeft = 1; } } else { ResetCurrentTarget(); } }
protected new virtual void TryStartShootSomething(bool canBeginBurstImmediately) { if (progressBarEffecter != null) { progressBarEffecter.Cleanup(); progressBarEffecter = null; } if (!Spawned || ((bool)AccessTools.Field(typeof(Building_TurretGun), "holdFire")?.GetValue(this) && CanToggleHoldFire) || (AttackVerb.ProjectileFliesOverhead() && Map.roofGrid.Roofed(Position)) || !AttackVerb.Available()) { ResetCurrentTarget(); return; } bool isValid = currentTargetInt.IsValid || worldTarget.IsValid; if (forcedTarget.IsValid) { currentTargetInt = forcedTarget; } else { currentTargetInt = TryFindNewTarget(); } if (forcedWorldTarget.IsValid) { worldTarget = forcedWorldTarget; } else { //Find new target? } if (!isValid && (currentTargetInt.IsValid || worldTarget.IsValid)) { SoundDefOf.TurretAcquireTarget.PlayOneShot(new TargetInfo(Position, Map, false)); } if (!currentTargetInt.IsValid && !worldTarget.IsValid) { ResetCurrentTarget(); return; } if (def.building.turretBurstWarmupTime > 0f) { burstWarmupTicksLeft = def.building.turretBurstWarmupTime.SecondsToTicks(); return; } if (canBeginBurstImmediately) { BeginBurst(); return; } burstWarmupTicksLeft = 1; }