private static bool TryFindAdjustedCoverInCell(IntVec3 shooterLoc, IntVec3 targetLoc, IntVec3 adjCell, Map map, out CoverInfo result)
        {
            Thing cover = adjCell.GetCover(map);
            float num2;

            if (cover != null && !(shooterLoc == targetLoc))
            {
                float angleFlat  = (shooterLoc - targetLoc).AngleFlat;
                float angleFlat2 = (adjCell - targetLoc).AngleFlat;
                float num        = GenGeo.AngleDifferenceBetween(angleFlat2, angleFlat);
                if (!targetLoc.AdjacentToCardinal(adjCell))
                {
                    num = (float)(num * 1.75);
                }
                num2 = cover.def.BaseBlockChance();
                if (num < 15.0)
                {
                    num2 = (float)(num2 * 1.0);
                    goto IL_010b;
                }
                if (num < 27.0)
                {
                    num2 = (float)(num2 * 0.800000011920929);
                    goto IL_010b;
                }
                if (num < 40.0)
                {
                    num2 = (float)(num2 * 0.60000002384185791);
                    goto IL_010b;
                }
                if (num < 52.0)
                {
                    num2 = (float)(num2 * 0.40000000596046448);
                    goto IL_010b;
                }
                if (num < 65.0)
                {
                    num2 = (float)(num2 * 0.20000000298023224);
                    goto IL_010b;
                }
                result = CoverInfo.Invalid;
                return(false);
            }
            result = CoverInfo.Invalid;
            return(false);

IL_010b:
            float lengthHorizontal = (shooterLoc - adjCell).LengthHorizontal;

            if (lengthHorizontal < 1.8999999761581421)
            {
                num2 = (float)(num2 * 0.33329999446868896);
            }
            else if (lengthHorizontal < 2.9000000953674316)
            {
                num2 = (float)(num2 * 0.66666001081466675);
            }
            result = new CoverInfo(cover, num2);
            return(true);
        }
Beispiel #2
0
        private static bool TryFindAdjustedCoverInCell(IntVec3 shooterLoc, LocalTargetInfo target, IntVec3 adjCell, Map map, out CoverInfo result)
        {
            IntVec3 cell  = target.Cell;
            Thing   cover = adjCell.GetCover(map);
            bool    result2;

            if (cover == null || cover == target.Thing || shooterLoc == cell)
            {
                result  = CoverInfo.Invalid;
                result2 = false;
            }
            else
            {
                float angleFlat  = (shooterLoc - cell).AngleFlat;
                float angleFlat2 = (adjCell - cell).AngleFlat;
                float num        = GenGeo.AngleDifferenceBetween(angleFlat2, angleFlat);
                if (!cell.AdjacentToCardinal(adjCell))
                {
                    num *= 1.75f;
                }
                float num2 = cover.def.BaseBlockChance();
                if (num < 15f)
                {
                    num2 *= 1f;
                }
                else if (num < 27f)
                {
                    num2 *= 0.8f;
                }
                else if (num < 40f)
                {
                    num2 *= 0.6f;
                }
                else if (num < 52f)
                {
                    num2 *= 0.4f;
                }
                else
                {
                    if (num >= 65f)
                    {
                        result = CoverInfo.Invalid;
                        return(false);
                    }
                    num2 *= 0.2f;
                }
                float lengthHorizontal = (shooterLoc - adjCell).LengthHorizontal;
                if (lengthHorizontal < 1.9f)
                {
                    num2 *= 0.3333f;
                }
                else if (lengthHorizontal < 2.9f)
                {
                    num2 *= 0.66666f;
                }
                result  = new CoverInfo(cover, num2);
                result2 = true;
            }
            return(result2);
        }
        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);
        }
Beispiel #4
0
 public void UpdateRotation()
 {
     if (!this.pawn.Destroyed && !this.pawn.jobs.HandlingFacing)
     {
         if (this.pawn.pather.Moving)
         {
             if (this.pawn.pather.curPath != null && this.pawn.pather.curPath.NodesLeftCount >= 1)
             {
                 this.FaceAdjacentCell(this.pawn.pather.nextCell);
             }
         }
         else
         {
             Stance_Busy stance_Busy = this.pawn.stances.curStance as Stance_Busy;
             if (stance_Busy != null && stance_Busy.focusTarg.IsValid)
             {
                 if (stance_Busy.focusTarg.HasThing)
                 {
                     this.Face(stance_Busy.focusTarg.Thing.DrawPos);
                 }
                 else
                 {
                     this.FaceCell(stance_Busy.focusTarg.Cell);
                 }
             }
             else
             {
                 if (this.pawn.jobs.curJob != null)
                 {
                     LocalTargetInfo target = this.pawn.CurJob.GetTarget(this.pawn.jobs.curDriver.rotateToFace);
                     if (target.HasThing)
                     {
                         bool     flag     = false;
                         IntVec3  c        = default(IntVec3);
                         CellRect cellRect = target.Thing.OccupiedRect();
                         for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
                         {
                             for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                             {
                                 if (this.pawn.Position == new IntVec3(j, 0, i))
                                 {
                                     this.Face(target.Thing.DrawPos);
                                     return;
                                 }
                             }
                         }
                         for (int k = cellRect.minZ; k <= cellRect.maxZ; k++)
                         {
                             for (int l = cellRect.minX; l <= cellRect.maxX; l++)
                             {
                                 IntVec3 intVec = new IntVec3(l, 0, k);
                                 if (intVec.AdjacentToCardinal(this.pawn.Position))
                                 {
                                     this.FaceAdjacentCell(intVec);
                                     return;
                                 }
                                 if (intVec.AdjacentTo8Way(this.pawn.Position))
                                 {
                                     flag = true;
                                     c    = intVec;
                                 }
                             }
                         }
                         if (flag)
                         {
                             if (DebugViewSettings.drawPawnRotatorTarget)
                             {
                                 this.pawn.Map.debugDrawer.FlashCell(this.pawn.Position, 0.6f, "jbthing", 50);
                                 GenDraw.DrawLineBetween(this.pawn.Position.ToVector3Shifted(), c.ToVector3Shifted());
                             }
                             this.FaceAdjacentCell(c);
                         }
                         else
                         {
                             this.Face(target.Thing.DrawPos);
                         }
                         return;
                     }
                     if (this.pawn.Position.AdjacentTo8Way(target.Cell))
                     {
                         if (DebugViewSettings.drawPawnRotatorTarget)
                         {
                             this.pawn.Map.debugDrawer.FlashCell(this.pawn.Position, 0.2f, "jbloc", 50);
                             GenDraw.DrawLineBetween(this.pawn.Position.ToVector3Shifted(), target.Cell.ToVector3Shifted());
                         }
                         this.FaceAdjacentCell(target.Cell);
                         return;
                     }
                     if (target.Cell.IsValid && target.Cell != this.pawn.Position)
                     {
                         this.Face(target.Cell.ToVector3());
                         return;
                     }
                 }
                 if (this.pawn.Drafted)
                 {
                     this.pawn.Rotation = Rot4.South;
                 }
             }
         }
     }
 }
Beispiel #5
0
 public void FaceTarget(LocalTargetInfo target)
 {
     if (target.IsValid)
     {
         if (target.HasThing)
         {
             Thing thing = (!target.Thing.Spawned) ? ThingOwnerUtility.GetFirstSpawnedParentThing(target.Thing) : target.Thing;
             if (thing != null && thing.Spawned)
             {
                 bool     flag     = false;
                 IntVec3  c        = default(IntVec3);
                 CellRect cellRect = thing.OccupiedRect();
                 for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
                 {
                     for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                     {
                         if (pawn.Position == new IntVec3(j, 0, i))
                         {
                             Face(thing.DrawPos);
                             return;
                         }
                     }
                 }
                 for (int k = cellRect.minZ; k <= cellRect.maxZ; k++)
                 {
                     for (int l = cellRect.minX; l <= cellRect.maxX; l++)
                     {
                         IntVec3 intVec = new IntVec3(l, 0, k);
                         if (intVec.AdjacentToCardinal(pawn.Position))
                         {
                             FaceAdjacentCell(intVec);
                             return;
                         }
                         if (intVec.AdjacentTo8Way(pawn.Position))
                         {
                             flag = true;
                             c    = intVec;
                         }
                     }
                 }
                 if (flag)
                 {
                     if (DebugViewSettings.drawPawnRotatorTarget)
                     {
                         pawn.Map.debugDrawer.FlashCell(pawn.Position, 0.6f, "jbthing");
                         GenDraw.DrawLineBetween(pawn.Position.ToVector3Shifted(), c.ToVector3Shifted());
                     }
                     FaceAdjacentCell(c);
                 }
                 else
                 {
                     Face(thing.DrawPos);
                 }
             }
         }
         else if (pawn.Position.AdjacentTo8Way(target.Cell))
         {
             if (DebugViewSettings.drawPawnRotatorTarget)
             {
                 pawn.Map.debugDrawer.FlashCell(pawn.Position, 0.2f, "jbloc");
                 GenDraw.DrawLineBetween(pawn.Position.ToVector3Shifted(), target.Cell.ToVector3Shifted());
             }
             FaceAdjacentCell(target.Cell);
         }
         else if (target.Cell.IsValid && target.Cell != pawn.Position)
         {
             Face(target.Cell.ToVector3());
         }
     }
 }
Beispiel #6
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))
            {
                bool flag = this.CheckForFreeIntercept(intVec2);
                if (DebugViewSettings.drawInterceptChecks)
                {
                    if (flag)
                    {
                        MoteMaker.ThrowText(intVec2.ToVector3Shifted(), base.Map, "x", -1f);
                    }
                    else
                    {
                        MoteMaker.ThrowText(intVec2.ToVector3Shifted(), base.Map, "o", -1f);
                    }
                }
                return(flag);
            }
            if ((float)this.origin.ToIntVec3().DistanceToSquared(intVec2) > 16f)
            {
                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);
                    }
                    if (DebugViewSettings.drawInterceptChecks)
                    {
                        MoteMaker.ThrowText(vector, base.Map, "o", -1f);
                    }
                    num2++;
                    if (num2 > num)
                    {
                        return(false);
                    }
                    if (intVec3 == intVec2)
                    {
                        return(false);
                    }
                }
                if (DebugViewSettings.drawInterceptChecks)
                {
                    MoteMaker.ThrowText(vector, base.Map, "x", -1f);
                }
                return(true);
            }
            return(false);
        }
Beispiel #7
0
        private bool CheckForFreeInterceptBetween(Vector3 lastExactPos, Vector3 newExactPos)
        {
            IntVec3 intVec  = lastExactPos.ToIntVec3();
            IntVec3 intVec2 = newExactPos.ToIntVec3();
            bool    result;

            if (intVec2 == intVec)
            {
                result = false;
            }
            else if (!intVec.InBounds(base.Map) || !intVec2.InBounds(base.Map))
            {
                result = false;
            }
            else if (intVec2.AdjacentToCardinal(intVec))
            {
                result = this.CheckForFreeIntercept(intVec2);
            }
            else if (VerbUtility.DistanceInterceptChance(this.origin, intVec2, this.intendedTarget.Cell) > 0f)
            {
                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;
                for (;;)
                {
                    vector += b;
                    IntVec3 intVec3 = vector.ToIntVec3();
                    if (!Projectile.checkedCells.Contains(intVec3))
                    {
                        if (this.CheckForFreeIntercept(intVec3))
                        {
                            break;
                        }
                        Projectile.checkedCells.Add(intVec3);
                    }
                    num2++;
                    if (num2 > num)
                    {
                        goto Block_7;
                    }
                    if (intVec3 == intVec2)
                    {
                        goto Block_8;
                    }
                }
                return(true);

Block_7:
                return(false);

Block_8:
                result = false;
            }
            else
            {
                result = false;
            }
            return(result);
        }
Beispiel #8
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);
        }