Exemplo n.º 1
0
        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);

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

            while (true)
            {
                vector += b;
                IntVec3 intVec3 = vector.ToIntVec3();
                if (!Projectile.checkedCells.Contains(intVec3))
                {
                    if (this.CheckForFreeIntercept(intVec3))
                    {
                        break;
                    }
                    Projectile.checkedCells.Add(intVec3);
                }
                num2++;
                if (num2 > num)
                {
                    return(false);
                }
                if (intVec3 == intVec2)
                {
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        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))
            {
                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))
                    {
                        Projectile.cellThingsFiltered.Add(thing);
                    }
                }
                Projectile.cellThingsFiltered.Shuffle <Thing>();
                for (int j = 0; j < Projectile.cellThingsFiltered.Count; j++)
                {
                    Thing thing2 = Projectile.cellThingsFiltered[j];
                    Pawn  pawn   = thing2 as Pawn;
                    float num;
                    if (pawn != null)
                    {
                        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(Projectile.cellThingsFiltered.RandomElement <Thing>());
                        return;
                    }
                    this.ThrowDebugText("miss-" + num.ToStringPercent(), base.Position);
                }
                this.Impact(null);
                return;
            }
            Pawn pawn2 = this.usedTarget.Thing as Pawn;

            if (pawn2 != null && 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);
        }
Exemplo n.º 3
0
        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;
                    Pawn  pawn = thing as Pawn;
                    if (pawn != null)
                    {
                        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);
        }
Exemplo n.º 4
0
        private bool CheckForFreeInterceptBetween(Vector3 lastExactPos, Vector3 newExactPos)
        {
            if (lastExactPos == newExactPos)
            {
                return(false);
            }
            List <Thing> list = base.Map.listerThings.ThingsInGroup(ThingRequestGroup.ProjectileInterceptor);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].TryGetComp <CompProjectileInterceptor>().CheckIntercept(this, lastExactPos, newExactPos))
                {
                    Destroy();
                    return(true);
                }
            }
            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(CheckForFreeIntercept(intVec2));
            }
            if (VerbUtility.InterceptChanceFactorFromDistance(origin, intVec2) <= 0f)
            {
                return(false);
            }
            Vector3 vect   = lastExactPos;
            Vector3 v      = newExactPos - lastExactPos;
            Vector3 vector = v.normalized * 0.2f;
            int     num    = (int)(v.MagnitudeHorizontal() / 0.2f);

            checkedCells.Clear();
            int     num2 = 0;
            IntVec3 intVec3;

            do
            {
                vect   += vector;
                intVec3 = vect.ToIntVec3();
                if (!checkedCells.Contains(intVec3))
                {
                    if (CheckForFreeIntercept(intVec3))
                    {
                        return(true);
                    }
                    checkedCells.Add(intVec3);
                }
                num2++;
                if (num2 > num)
                {
                    return(false);
                }
            }while (!(intVec3 == intVec2));
            return(false);
        }