// Token: 0x060052A0 RID: 21152 RVA: 0x00129A28 File Offset: 0x00127E28
        private bool CheckForFreeInterceptBetween(Vector3 lastExactPos, Vector3 newExactPos)
        {
            IntVec3 intVec  = lastExactPos.ToIntVec3();
            IntVec3 intVec2 = newExactPos.ToIntVec3();

            if (intVec2 == intVec)
            {
                return(false);
            }
            if (!intVec.InBounds(base.Map) || !intVec2.InBounds(base.Map))
            {
                return(false);
            }
            if (intVec2.AdjacentToCardinal(intVec))
            {
                return(this.CheckForFreeIntercept(intVec2));
            }
            if (VerbUtility.InterceptChanceFactorFromDistance(this.origin, intVec2) <= 0f)
            {
                return(false);
            }
            Vector3 vector = lastExactPos;
            Vector3 v      = newExactPos - lastExactPos;
            Vector3 b      = v.normalized * 0.2f;
            int     num    = (int)(v.MagnitudeHorizontal() / 0.2f);

            Stuffable_Projectile.checkedCells.Clear();
            int num2 = 0;

            for (; ;)
            {
                vector += b;
                IntVec3 intVec3 = vector.ToIntVec3();
                if (!Stuffable_Projectile.checkedCells.Contains(intVec3))
                {
                    if (this.CheckForFreeIntercept(intVec3))
                    {
                        break;
                    }
                    Stuffable_Projectile.checkedCells.Add(intVec3);
                }
                num2++;
                if (num2 > num)
                {
                    return(false);
                }
                if (intVec3 == intVec2)
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        private static float FriendlyFireConeTargetScoreOffset(
            IAttackTarget target,
            IAttackTargetSearcher searcher,
            Verb verb)
        {
            if (!(searcher.Thing is Pawn thing) || thing.RaceProps.intelligence < Intelligence.ToolUser || (thing.RaceProps.IsMechanoid || !(verb is Verb_Shoot verbShoot)))
            {
                return(0.0f);
            }
            ThingDef defaultProjectile = verbShoot.verbProps.defaultProjectile;

            if (defaultProjectile == null || defaultProjectile.projectile.flyOverhead)
            {
                return(0.0f);
            }
            Map        map              = thing.Map;
            ShotReport report           = ShotReport.HitReportFor((Thing)thing, verb, (LocalTargetInfo)(Thing)target);
            double     forcedMissRadius = (double)verb.verbProps.forcedMissRadius;
            IntVec3    dest1            = report.ShootLine.Dest;
            ShootLine  shootLine        = report.ShootLine;
            IntVec3    source           = shootLine.Source;
            IntVec3    vector           = dest1 - source;
            float      radius           = Mathf.Max(VerbUtility.CalculateAdjustedForcedMiss((float)forcedMissRadius, vector), 1.5f);

            shootLine = report.ShootLine;
            IEnumerable <IntVec3> intVec3s = GenRadial.RadialCellsAround(shootLine.Dest, radius, true).Where <IntVec3>((Func <IntVec3, bool>)(dest => dest.InBounds(map))).Select <IntVec3, ShootLine>((Func <IntVec3, ShootLine>)(dest => new ShootLine(report.ShootLine.Source, dest))).SelectMany <ShootLine, IntVec3>((Func <ShootLine, IEnumerable <IntVec3> >)(line => line.Points().Concat <IntVec3>(line.Dest).TakeWhile <IntVec3>((Func <IntVec3, bool>)(pos => pos.CanBeSeenOverFast(map))))).Distinct <IntVec3>();
            float num1 = 0.0f;

            foreach (IntVec3 c in intVec3s)
            {
                shootLine = report.ShootLine;
                float num2 = VerbUtility.InterceptChanceFactorFromDistance(shootLine.Source.ToVector3Shifted(), c);
                if ((double)num2 > 0.0)
                {
                    List <Thing> thingList = c.GetThingList(map);
                    for (int index = 0; index < thingList.Count; ++index)
                    {
                        Thing b = thingList[index];
                        if (b is IAttackTarget && b != target)
                        {
                            float num3 = (b != searcher ? (!(b is Pawn) ? 10f : (b.def.race.Animal ? 7f : 18f)) : 40f) * num2;
                            float num4 = !searcher.Thing.HostileTo(b) ? num3 * -1f : num3 * 0.6f;
                            num1 += num4;
                        }
                    }
                }
            }
            return(num1);
        }
        private static float FriendlyFireConeTargetScoreOffset(IAttackTarget target, IAttackTargetSearcher searcher, Verb verb)
        {
            if (!(searcher.Thing is Pawn pawn))
            {
                return(0f);
            }
            if (pawn.RaceProps.intelligence < Intelligence.ToolUser)
            {
                return(0f);
            }
            if (pawn.RaceProps.IsMechanoid)
            {
                return(0f);
            }
            if (!(verb is Verb_Shoot verb_Shoot))
            {
                return(0f);
            }
            ThingDef defaultProjectile = verb_Shoot.verbProps.defaultProjectile;

            if (defaultProjectile == null)
            {
                return(0f);
            }
            if (defaultProjectile.projectile.flyOverhead)
            {
                return(0f);
            }
            Map                     map        = pawn.Map;
            ShotReport              report     = ShotReport.HitReportFor(pawn, verb, (Thing)target);
            float                   a          = VerbUtility.CalculateAdjustedForcedMiss(verb.verbProps.forcedMissRadius, report.ShootLine.Dest - report.ShootLine.Source);
            float                   radius     = Mathf.Max(a, 1.5f);
            IntVec3                 dest2      = report.ShootLine.Dest;
            IEnumerable <IntVec3>   source     = from dest in GenRadial.RadialCellsAround(dest2, radius, true) where dest.InBounds(map) select dest;
            IEnumerable <ShootLine> source2    = from dest in source select new ShootLine(report.ShootLine.Source, dest);
            IEnumerable <IntVec3>   source3    = source2.SelectMany((ShootLine line) => line.Points().Concat(line.Dest).TakeWhile((IntVec3 pos) => pos.CanBeSeenOverFast(map)));
            IEnumerable <IntVec3>   enumerable = source3.Distinct <IntVec3>();
            float                   num        = 0f;

            foreach (IntVec3 c in enumerable)
            {
                float num2 = VerbUtility.InterceptChanceFactorFromDistance(report.ShootLine.Source.ToVector3Shifted(), c);
                if (num2 > 0f)
                {
                    List <Thing> thingList = c.GetThingList(map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        Thing thing = thingList[i];
                        if (thing is IAttackTarget && thing != target)
                        {
                            float num3;
                            if (thing == searcher)
                            {
                                num3 = 40f;
                            }
                            else if (thing is Pawn)
                            {
                                num3 = ((!thing.def.race.Animal) ? 18f : 7f);
                            }
                            else
                            {
                                num3 = 10f;
                            }
                            num3 *= num2;
                            if (searcher.Thing.HostileTo(thing))
                            {
                                num3 *= 0.6f;
                            }
                            else
                            {
                                num3 *= -1f;
                            }
                            num += num3;
                        }
                    }
                }
            }
            return(num);
        }
Esempio n. 4
0
        private static float FriendlyFireConeTargetScoreOffset(IAttackTarget target, IAttackTargetSearcher searcher, Verb verb)
        {
            Pawn pawn = searcher.Thing as Pawn;

            if (pawn == null)
            {
                return(0f);
            }
            if ((int)pawn.RaceProps.intelligence < 1)
            {
                return(0f);
            }
            if (pawn.RaceProps.IsMechanoid)
            {
                return(0f);
            }
            Verb_Shoot verb_Shoot = verb as Verb_Shoot;

            if (verb_Shoot == null)
            {
                return(0f);
            }
            ThingDef defaultProjectile = verb_Shoot.verbProps.defaultProjectile;

            if (defaultProjectile == null)
            {
                return(0f);
            }
            if (defaultProjectile.projectile.flyOverhead)
            {
                return(0f);
            }
            Map                   map        = pawn.Map;
            ShotReport            report     = ShotReport.HitReportFor(pawn, verb, (Thing)target);
            float                 radius     = Mathf.Max(VerbUtility.CalculateAdjustedForcedMiss(verb.verbProps.forcedMissRadius, report.ShootLine.Dest - report.ShootLine.Source), 1.5f);
            IEnumerable <IntVec3> enumerable = (from dest in GenRadial.RadialCellsAround(report.ShootLine.Dest, radius, useCenter: true)
                                                where dest.InBounds(map)
                                                select new ShootLine(report.ShootLine.Source, dest)).SelectMany((ShootLine line) => line.Points().Concat(line.Dest).TakeWhile((IntVec3 pos) => pos.CanBeSeenOverFast(map))).Distinct();
            float num = 0f;

            foreach (IntVec3 item in enumerable)
            {
                float num2 = VerbUtility.InterceptChanceFactorFromDistance(report.ShootLine.Source.ToVector3Shifted(), item);
                if (!(num2 <= 0f))
                {
                    List <Thing> thingList = item.GetThingList(map);
                    for (int i = 0; i < thingList.Count; i++)
                    {
                        Thing thing = thingList[i];
                        if (thing is IAttackTarget && thing != target)
                        {
                            float num3 = (thing == searcher) ? 40f : ((!(thing is Pawn)) ? 10f : (thing.def.race.Animal ? 7f : 18f));
                            num3 *= num2;
                            num3  = ((!searcher.Thing.HostileTo(thing)) ? (num3 * -1f) : (num3 * 0.6f));
                            num  += num3;
                        }
                    }
                }
            }
            return(num);
        }
Esempio n. 5
0
        private void ImpactSomething()
        {
            if (this.def.projectile.flyOverhead)
            {
                RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position);
                if (roofDef != null)
                {
                    if (roofDef.isThickRoof)
                    {
                        SoundStarter.PlayOneShot(this.def.projectile.soundHitThickRoof, new TargetInfo(base.Position, base.Map, false));
                        this.Destroy(0);
                        return;
                    }
                    if (GridsUtility.GetEdifice(base.Position, base.Map) == null || GridsUtility.GetEdifice(base.Position, base.Map).def.Fillage != FillCategory.Full)
                    {
                        RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map, null);
                    }
                }
            }
            if (!this.usedTarget.HasThing || !base.CanHit(this.usedTarget.Thing))
            {
                List <Thing> list = new List <Thing>();
                list.Clear();
                List <Thing> thingList = GridsUtility.GetThingList(base.Position, base.Map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    if ((thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant) && base.CanHit(thing))
                    {
                        list.Add(thing);
                    }
                }
                GenList.Shuffle <Thing>(list);
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    Pawn  pawn   = thing2 as Pawn;
                    float num;
                    if (pawn != null)
                    {
                        num = 0.5f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f);
                        if (PawnUtility.GetPosture(pawn) != null && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f)
                        {
                            num *= 0.2f;
                        }
                        if (this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !FactionUtility.HostileTo(pawn.Faction, this.launcher.Faction))
                        {
                            num *= VerbUtility.InterceptChanceFactorFromDistance(this.origin, base.Position);
                        }
                    }
                    else
                    {
                        num = 1.5f * thing2.def.fillPercent;
                    }
                    if (Rand.Chance(num))
                    {
                        this.Impact(GenCollection.RandomElement <Thing>(list));
                        return;
                    }
                }
                this.Impact(null);
                return;
            }
            Pawn pawn2 = this.usedTarget.Thing as Pawn;

            if (pawn2 != null && PawnUtility.GetPosture(pawn2) != null && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f && !Rand.Chance(0.2f))
            {
                this.Impact(null);
                return;
            }
            this.Impact(this.usedTarget.Thing);
        }
 // Token: 0x060052A5 RID: 21157 RVA: 0x00129F58 File Offset: 0x00128358
 private void ImpactSomething()
 {
     if (this.def.projectile.flyOverhead)
     {
         RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position);
         if (roofDef != null)
         {
             if (roofDef.isThickRoof)
             {
                 this.ThrowDebugText("hit-thick-roof", base.Position);
                 this.def.projectile.soundHitThickRoof.PlayOneShot(new TargetInfo(base.Position, base.Map, false));
                 this.Destroy(DestroyMode.Vanish);
                 return;
             }
             if (base.Position.GetEdifice(base.Map) == null || base.Position.GetEdifice(base.Map).def.Fillage != FillCategory.Full)
             {
                 RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map, null);
             }
         }
     }
     if (!this.usedTarget.HasThing || !this.CanHit(this.usedTarget.Thing))
     {
         Stuffable_Projectile.cellThingsFiltered.Clear();
         List <Thing> thingList = base.Position.GetThingList(base.Map);
         for (int i = 0; i < thingList.Count; i++)
         {
             Thing thing = thingList[i];
             if ((thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant) && this.CanHit(thing))
             {
                 Stuffable_Projectile.cellThingsFiltered.Add(thing);
             }
         }
         Stuffable_Projectile.cellThingsFiltered.Shuffle <Thing>();
         for (int j = 0; j < Stuffable_Projectile.cellThingsFiltered.Count; j++)
         {
             Thing thing2 = Stuffable_Projectile.cellThingsFiltered[j];
             float num;
             if (thing2 is Pawn pawn)
             {
                 num = 0.5f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f);
                 if (pawn.GetPosture() != PawnPosture.Standing && (this.origin - this.destination).MagnitudeHorizontalSquared() >= 20.25f)
                 {
                     num *= 0.2f;
                 }
                 if (this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !pawn.Faction.HostileTo(this.launcher.Faction))
                 {
                     num *= VerbUtility.InterceptChanceFactorFromDistance(this.origin, base.Position);
                 }
             }
             else
             {
                 num = 1.5f * thing2.def.fillPercent;
             }
             if (Rand.Chance(num))
             {
                 this.ThrowDebugText("hit-" + num.ToStringPercent(), base.Position);
                 this.Impact(Stuffable_Projectile.cellThingsFiltered.RandomElement <Thing>());
                 return;
             }
             this.ThrowDebugText("miss-" + num.ToStringPercent(), base.Position);
         }
         this.Impact(null);
         return;
     }
     if (this.usedTarget.Thing is Pawn pawn2 && pawn2.GetPosture() != PawnPosture.Standing && (this.origin - this.destination).MagnitudeHorizontalSquared() >= 20.25f && !Rand.Chance(0.2f))
     {
         this.ThrowDebugText("miss-laying", base.Position);
         this.Impact(null);
         return;
     }
     this.Impact(this.usedTarget.Thing);
 }
        // Token: 0x060052A1 RID: 21153 RVA: 0x00129B3C File Offset: 0x00127F3C
        private bool CheckForFreeIntercept(IntVec3 c)
        {
            if (this.destination.ToIntVec3() == c)
            {
                return(false);
            }
            float num = VerbUtility.InterceptChanceFactorFromDistance(this.origin, c);

            if (num <= 0f)
            {
                return(false);
            }
            bool         flag      = false;
            List <Thing> thingList = c.GetThingList(base.Map);

            for (int i = 0; i < thingList.Count; i++)
            {
                Thing thing = thingList[i];
                if (this.CanHit(thing))
                {
                    bool flag2 = false;
                    if (thing.def.Fillage == FillCategory.Full)
                    {
                        Building_Door building_Door = thing as Building_Door;
                        if (building_Door == null || !building_Door.Open)
                        {
                            this.ThrowDebugText("int-wall", c);
                            this.Impact(thing);
                            return(true);
                        }
                        flag2 = true;
                    }
                    float num2 = 0f;
                    if (thing is Pawn pawn)
                    {
                        num2 = 0.4f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f);
                        if (pawn.GetPosture() != PawnPosture.Standing)
                        {
                            num2 *= 0.1f;
                        }
                        if (this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !pawn.Faction.HostileTo(this.launcher.Faction))
                        {
                            num2 *= 0.4f;
                        }
                    }
                    else if (thing.def.fillPercent > 0.2f)
                    {
                        if (flag2)
                        {
                            num2 = 0.05f;
                        }
                        else if (this.DestinationCell.AdjacentTo8Way(c))
                        {
                            num2 = thing.def.fillPercent * 1f;
                        }
                        else
                        {
                            num2 = thing.def.fillPercent * 0.15f;
                        }
                    }
                    num2 *= num;
                    if (num2 > 1E-05f)
                    {
                        if (Rand.Chance(num2))
                        {
                            this.ThrowDebugText("int-" + num2.ToStringPercent(), c);
                            this.Impact(thing);
                            return(true);
                        }
                        flag = true;
                        this.ThrowDebugText(num2.ToStringPercent(), c);
                    }
                }
            }
            if (!flag)
            {
                this.ThrowDebugText("o", c);
            }
            return(false);
        }
Esempio n. 8
0
        // Token: 0x0600000F RID: 15 RVA: 0x000026FC File Offset: 0x000008FC
        private void ImpactSomething()
        {
            var flyOverhead = def.projectile.flyOverhead;

            if (flyOverhead)
            {
                var roofDef = Map.roofGrid.RoofAt(Position);
                if (roofDef != null)
                {
                    var isThickRoof = roofDef.isThickRoof;
                    if (isThickRoof)
                    {
                        def.projectile.soundHitThickRoof.PlayOneShot(new TargetInfo(Position, Map));
                        Destroy();
                        return;
                    }

                    if (Position.GetEdifice(Map) == null ||
                        Position.GetEdifice(Map).def.Fillage != FillCategory.Full)
                    {
                        RoofCollapserImmediate.DropRoofInCells(Position, Map);
                    }
                }
            }

            if (!usedTarget.HasThing || !CanHit(usedTarget.Thing))
            {
                var list = new List <Thing>();
                list.Clear();
                var thingList = Position.GetThingList(Map);
                foreach (var thing in thingList)
                {
                    if ((thing.def.category == ThingCategory.Building ||
                         thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item ||
                         thing.def.category == ThingCategory.Plant) && CanHit(thing))
                    {
                        list.Add(thing);
                    }
                }

                list.Shuffle();
                for (var j = 0; j < list.Count; j++)
                {
                    var   thing2 = list[j];
                    float num;
                    if (thing2 is Pawn pawn)
                    {
                        num = 0.5f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f);
                        if (pawn.GetPosture() != PawnPosture.Standing &&
                            (origin - destination).MagnitudeHorizontalSquared() >= 20.25f)
                        {
                            num *= 0.2f;
                        }

                        if (launcher != null && pawn.Faction != null && launcher.Faction != null &&
                            !pawn.Faction.HostileTo(launcher.Faction))
                        {
                            num *= VerbUtility.InterceptChanceFactorFromDistance(origin, Position);
                        }
                    }
                    else
                    {
                        num = 1.5f * thing2.def.fillPercent;
                    }

                    if (!Rand.Chance(num))
                    {
                        continue;
                    }

                    Impact(list.RandomElement());
                    return;
                }

                Impact(null);
            }
            else
            {
                if (usedTarget.Thing is Pawn pawn2 && pawn2.GetPosture() != PawnPosture.Standing &&
                    (origin - destination).MagnitudeHorizontalSquared() >= 20.25f && !Rand.Chance(0.2f))
                {
                    Impact(null);
                }
        // Token: 0x0600000F RID: 15 RVA: 0x000026FC File Offset: 0x000008FC
        private void ImpactSomething()
        {
            bool flyOverhead = this.def.projectile.flyOverhead;

            if (flyOverhead)
            {
                RoofDef roofDef = base.Map.roofGrid.RoofAt(base.Position);
                bool    flag    = roofDef != null;
                if (flag)
                {
                    bool isThickRoof = roofDef.isThickRoof;
                    if (isThickRoof)
                    {
                        this.def.projectile.soundHitThickRoof.PlayOneShot(new TargetInfo(base.Position, base.Map, false));
                        this.Destroy(DestroyMode.Vanish);
                        return;
                    }
                    bool flag2 = base.Position.GetEdifice(base.Map) == null || base.Position.GetEdifice(base.Map).def.Fillage != FillCategory.Full;
                    if (flag2)
                    {
                        RoofCollapserImmediate.DropRoofInCells(base.Position, base.Map, null);
                    }
                }
            }
            bool flag3 = !this.usedTarget.HasThing || !base.CanHit(this.usedTarget.Thing);

            if (flag3)
            {
                List <Thing> list = new List <Thing>();
                list.Clear();
                List <Thing> thingList = base.Position.GetThingList(base.Map);
                for (int i = 0; i < thingList.Count; i++)
                {
                    Thing thing = thingList[i];
                    bool  flag4 = (thing.def.category == ThingCategory.Building || thing.def.category == ThingCategory.Pawn || thing.def.category == ThingCategory.Item || thing.def.category == ThingCategory.Plant) && base.CanHit(thing);
                    if (flag4)
                    {
                        list.Add(thing);
                    }
                }
                list.Shuffle <Thing>();
                for (int j = 0; j < list.Count; j++)
                {
                    Thing thing2 = list[j];
                    Pawn  pawn   = thing2 as Pawn;
                    bool  flag5  = pawn != null;
                    float num;
                    if (flag5)
                    {
                        num = 0.5f * Mathf.Clamp(pawn.BodySize, 0.1f, 2f);
                        bool flag6 = pawn.GetPosture() != PawnPosture.Standing && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f;
                        if (flag6)
                        {
                            num *= 0.2f;
                        }
                        bool flag7 = this.launcher != null && pawn.Faction != null && this.launcher.Faction != null && !pawn.Faction.HostileTo(this.launcher.Faction);
                        if (flag7)
                        {
                            num *= VerbUtility.InterceptChanceFactorFromDistance(this.origin, base.Position);
                        }
                    }
                    else
                    {
                        num = 1.5f * thing2.def.fillPercent;
                    }
                    bool flag8 = Rand.Chance(num);
                    if (flag8)
                    {
                        this.Impact(list.RandomElement <Thing>());
                        return;
                    }
                }
                this.Impact(null);
            }
            else
            {
                Pawn pawn2 = this.usedTarget.Thing as Pawn;
                bool flag9 = pawn2 != null && pawn2.GetPosture() != PawnPosture.Standing && GenGeo.MagnitudeHorizontalSquared(this.origin - this.destination) >= 20.25f && !Rand.Chance(0.2f);
                if (flag9)
                {
                    this.Impact(null);
                }
                else
                {
                    this.Impact(this.usedTarget.Thing);
                }
            }
        }