Exemplo n.º 1
0
 private static bool CanShootAtFromCurrentPosition(
     IAttackTarget target,
     IAttackTargetSearcher searcher,
     Verb verb)
 {
     return(verb != null && verb.CanHitTargetFrom(searcher.Thing.Position, (LocalTargetInfo)target.Thing));
 }
Exemplo n.º 2
0
 private static bool CanShootAtFromCurrentPosition(IAttackTarget target, IAttackTargetSearcher searcher, Verb verb)
 {
     if (verb == null)
     {
         return(false);
     }
     return(verb.CanHitTargetFrom(searcher.Thing.Position, target.Thing));
 }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Misc.ThrowColonistAttackingMote(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate()
                {
                    Pawn pawn = base.TargetThingA as Pawn;
                    if (pawn != null)
                    {
                        this.startedIncapacitated = pawn.Downed;
                    }
                    this.pawn.pather.StopDead();
                },
                tickAction = delegate()
                {
                    if (!base.TargetA.IsValid)
                    {
                        base.EndJobWith(JobCondition.Succeeded);
                    }
                    else
                    {
                        if (base.TargetA.HasThing)
                        {
                            Pawn pawn = base.TargetA.Thing as Pawn;
                            if (base.TargetA.Thing.Destroyed || (pawn != null && !this.startedIncapacitated && pawn.Downed))
                            {
                                base.EndJobWith(JobCondition.Succeeded);
                                return;
                            }
                        }
                        if (this.numAttacksMade >= this.job.maxNumStaticAttacks && !this.pawn.stances.FullBodyBusy)
                        {
                            base.EndJobWith(JobCondition.Succeeded);
                        }
                        else if (this.pawn.TryStartAttack(base.TargetA))
                        {
                            this.numAttacksMade++;
                        }
                        else if (this.job.endIfCantShootTargetFromCurPos && !this.pawn.stances.FullBodyBusy)
                        {
                            Verb verb = this.pawn.TryGetAttackVerb(base.TargetA.Thing, !this.pawn.IsColonist);
                            if (verb == null || !verb.CanHitTargetFrom(this.pawn.Position, base.TargetA))
                            {
                                base.EndJobWith(JobCondition.Incompletable);
                            }
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Never
            });

            yield break;
        }
Exemplo n.º 4
0
            public bool MoveNext()
            {
                uint num = (uint)this.$PC;

                this.$PC = -1;
                switch (num)
                {
                case 0u:
                    this.$current = Toils_Misc.ThrowColonistAttackingMote(TargetIndex.A);
                    if (!this.$disposing)
                    {
                        this.$PC = 1;
                    }
                    return(true);

                case 1u:
                {
                    Toil init = new Toil();
                    init.initAction = delegate()
                    {
                        Pawn pawn = base.TargetThingA as Pawn;
                        if (pawn != null)
                        {
                            this.startedIncapacitated = pawn.Downed;
                        }
                        this.pawn.pather.StopDead();
                    };
                    init.tickAction = delegate()
                    {
                        if (!base.TargetA.IsValid)
                        {
                            base.EndJobWith(JobCondition.Succeeded);
                            return;
                        }
                        if (base.TargetA.HasThing)
                        {
                            Pawn pawn = base.TargetA.Thing as Pawn;
                            if (base.TargetA.Thing.Destroyed || (pawn != null && !this.startedIncapacitated && pawn.Downed))
                            {
                                base.EndJobWith(JobCondition.Succeeded);
                                return;
                            }
                        }
                        if (this.numAttacksMade >= this.job.maxNumStaticAttacks && !this.pawn.stances.FullBodyBusy)
                        {
                            base.EndJobWith(JobCondition.Succeeded);
                            return;
                        }
                        if (this.pawn.TryStartAttack(base.TargetA))
                        {
                            this.numAttacksMade++;
                        }
                        else if (this.job.endIfCantShootTargetFromCurPos && !this.pawn.stances.FullBodyBusy)
                        {
                            Verb verb = this.pawn.TryGetAttackVerb(base.TargetA.Thing, !this.pawn.IsColonist);
                            if (verb == null || !verb.CanHitTargetFrom(this.pawn.Position, base.TargetA))
                            {
                                base.EndJobWith(JobCondition.Incompletable);
                            }
                        }
                    };
                    init.defaultCompleteMode = ToilCompleteMode.Never;
                    this.$current            = init;
                    if (!this.$disposing)
                    {
                        this.$PC = 2;
                    }
                    return(true);
                }

                case 2u:
                    this.$PC = -1;
                    break;
                }
                return(false);
            }
Exemplo n.º 5
0
        private static void EvaluateCell(IntVec3 c)
        {
            if (maxRangeFromTargetSquared > 0.01f && maxRangeFromTargetSquared < 250000f && (float)(c - req.target.Position).LengthHorizontalSquared > maxRangeFromTargetSquared)
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0f, "range target");
                }
                return;
            }
            if ((double)maxRangeFromLocusSquared > 0.01 && (float)(c - req.locus).LengthHorizontalSquared > maxRangeFromLocusSquared)
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.1f, "range home");
                }
                return;
            }
            if (maxRangeFromCasterSquared > 0.01f)
            {
                rangeFromCasterToCellSquared = (c - req.caster.Position).LengthHorizontalSquared;
                if (rangeFromCasterToCellSquared > maxRangeFromCasterSquared)
                {
                    if (DebugViewSettings.drawCastPositionSearch)
                    {
                        req.caster.Map.debugDrawer.FlashCell(c, 0.2f, "range caster");
                    }
                    return;
                }
            }
            if (!c.Walkable(req.caster.Map))
            {
                return;
            }
            if (req.maxRegions > 0 && c.GetRegion(req.caster.Map).mark != inRadiusMark)
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.64f, "reg radius");
                }
                return;
            }
            if (!req.caster.Map.reachability.CanReach(req.caster.Position, c, PathEndMode.OnCell, TraverseParms.For(req.caster, Danger.Some)))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.4f, "can't reach");
                }
                return;
            }
            float num = CastPositionPreference(c);

            if (avoidGrid != null)
            {
                byte b = avoidGrid[c];
                num *= Mathf.Max(0.1f, (37.5f - (float)(int)b) / 37.5f);
            }
            if (DebugViewSettings.drawCastPositionSearch)
            {
                req.caster.Map.debugDrawer.FlashCell(c, num / 4f, num.ToString("F3"));
            }
            if (num < bestSpotPref)
            {
                return;
            }
            if (!verb.CanHitTargetFrom(c, req.target))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.6f, "can't hit");
                }
            }
            else if (!req.caster.Map.pawnDestinationReservationManager.CanReserve(c, req.caster))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, num * 0.9f, "resvd");
                }
            }
            else if (PawnUtility.KnownDangerAt(c, req.caster.Map, req.caster))
            {
                if (DebugViewSettings.drawCastPositionSearch)
                {
                    req.caster.Map.debugDrawer.FlashCell(c, 0.9f, "danger");
                }
            }
            else
            {
                bestSpot     = c;
                bestSpotPref = num;
            }
        }
Exemplo n.º 6
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Misc.ThrowColonistAttackingMote(TargetIndex.A));

            Toil toil = new Toil();

            toil.initAction = delegate
            {
                Pawn pawn2 = base.TargetThingA as Pawn;
                if (pawn2 != null)
                {
                    startedIncapacitated = pawn2.Downed;
                }
                pawn.pather.StopDead();
            };
            toil.tickAction = delegate
            {
                if (!base.TargetA.IsValid)
                {
                    EndJobWith(JobCondition.Succeeded);
                }
                else
                {
                    if (base.TargetA.HasThing)
                    {
                        Pawn pawn = base.TargetA.Thing as Pawn;
                        if (base.TargetA.Thing.Destroyed || (pawn != null && !startedIncapacitated && pawn.Downed) || (pawn != null && pawn.IsInvisible()))
                        {
                            EndJobWith(JobCondition.Succeeded);
                            return;
                        }
                    }
                    if (numAttacksMade >= job.maxNumStaticAttacks && !base.pawn.stances.FullBodyBusy)
                    {
                        EndJobWith(JobCondition.Succeeded);
                    }
                    else if (base.pawn.TryStartAttack(base.TargetA))
                    {
                        numAttacksMade++;
                    }
                    else if (!base.pawn.stances.FullBodyBusy)
                    {
                        Verb verb = base.pawn.TryGetAttackVerb(base.TargetA.Thing, !base.pawn.IsColonist);
                        if (job.endIfCantShootTargetFromCurPos && (verb == null || !verb.CanHitTargetFrom(base.pawn.Position, base.TargetA)))
                        {
                            EndJobWith(JobCondition.Incompletable);
                        }
                        else if (job.endIfCantShootInMelee)
                        {
                            if (verb == null)
                            {
                                EndJobWith(JobCondition.Incompletable);
                            }
                            else
                            {
                                float num = verb.verbProps.EffectiveMinRange(base.TargetA, base.pawn);
                                if ((float)base.pawn.Position.DistanceToSquared(base.TargetA.Cell) < num * num && base.pawn.Position.AdjacentTo8WayOrInside(base.TargetA.Cell))
                                {
                                    EndJobWith(JobCondition.Incompletable);
                                }
                            }
                        }
                    }
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Never;
            yield return(toil);
        }
        protected override IEnumerable <Toil> MakeNewToils()
        {
            yield return(Toils_Misc.ThrowColonistAttackingMote(TargetIndex.A));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Pawn pawn = this.$this.TargetThingA as Pawn;
                    if (pawn != null)
                    {
                        this.$this.startedIncapacitated = pawn.Downed;
                    }
                    this.$this.pawn.pather.StopDead();
                },
                tickAction = delegate
                {
                    if (!this.$this.TargetA.IsValid)
                    {
                        this.$this.EndJobWith(JobCondition.Succeeded);
                        return;
                    }
                    if (this.$this.TargetA.HasThing)
                    {
                        Pawn pawn = this.$this.TargetA.Thing as Pawn;
                        if (this.$this.TargetA.Thing.Destroyed || (pawn != null && !this.$this.startedIncapacitated && pawn.Downed))
                        {
                            this.$this.EndJobWith(JobCondition.Succeeded);
                            return;
                        }
                    }
                    if (this.$this.numAttacksMade >= this.$this.job.maxNumStaticAttacks && !this.$this.pawn.stances.FullBodyBusy)
                    {
                        this.$this.EndJobWith(JobCondition.Succeeded);
                        return;
                    }
                    if (this.$this.pawn.TryStartAttack(this.$this.TargetA))
                    {
                        this.$this.numAttacksMade++;
                    }
                    else if (!this.$this.pawn.stances.FullBodyBusy)
                    {
                        Verb verb = this.$this.pawn.TryGetAttackVerb(this.$this.TargetA.Thing, !this.$this.pawn.IsColonist);
                        if (this.$this.job.endIfCantShootTargetFromCurPos && (verb == null || !verb.CanHitTargetFrom(this.$this.pawn.Position, this.$this.TargetA)))
                        {
                            this.$this.EndJobWith(JobCondition.Incompletable);
                            return;
                        }
                        if (this.$this.job.endIfCantShootInMelee)
                        {
                            if (verb == null)
                            {
                                this.$this.EndJobWith(JobCondition.Incompletable);
                                return;
                            }
                            float num = verb.verbProps.EffectiveMinRange(this.$this.TargetA, this.$this.pawn);
                            if ((float)this.$this.pawn.Position.DistanceToSquared(this.$this.TargetA.Cell) < num * num && this.$this.pawn.Position.AdjacentTo8WayOrInside(this.$this.TargetA.Cell))
                            {
                                this.$this.EndJobWith(JobCondition.Incompletable);
                                return;
                            }
                        }
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Never
            });
        }