Beispiel #1
0
        public bool TryFindShootLineFromTo(IntVec3 root, LocalTargetInfo targ, out ShootLine resultingLine)
        {
            if (targ.HasThing && targ.Thing.Map != caster.Map)
            {
                resultingLine = default(ShootLine);
                return(false);
            }
            if (verbProps.IsMeleeAttack || verbProps.range <= 1.42f)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(ReachabilityImmediate.CanReachImmediate(root, targ, caster.Map, PathEndMode.Touch, null));
            }
            CellRect cellRect = targ.HasThing ? targ.Thing.OccupiedRect() : CellRect.SingleCell(targ.Cell);
            float    num      = verbProps.EffectiveMinRange(targ, caster);
            float    num2     = cellRect.ClosestDistSquaredTo(root);

            if (num2 > verbProps.range * verbProps.range || num2 < num * num)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(false);
            }
            if (!verbProps.requireLineOfSight)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(true);
            }
            IntVec3 goodDest;

            if (CasterIsPawn)
            {
                if (CanHitFromCellIgnoringRange(root, targ, out goodDest))
                {
                    resultingLine = new ShootLine(root, goodDest);
                    return(true);
                }
                ShootLeanUtility.LeanShootingSourcesFromTo(root, cellRect.ClosestCellTo(root), caster.Map, tempLeanShootSources);
                for (int i = 0; i < tempLeanShootSources.Count; i++)
                {
                    IntVec3 intVec = tempLeanShootSources[i];
                    if (CanHitFromCellIgnoringRange(intVec, targ, out goodDest))
                    {
                        resultingLine = new ShootLine(intVec, goodDest);
                        return(true);
                    }
                }
            }
            else
            {
                foreach (IntVec3 item in caster.OccupiedRect())
                {
                    if (CanHitFromCellIgnoringRange(item, targ, out goodDest))
                    {
                        resultingLine = new ShootLine(item, goodDest);
                        return(true);
                    }
                }
            }
            resultingLine = new ShootLine(root, targ.Cell);
            return(false);
        }
Beispiel #2
0
        private static CellRect FindLargestRectAt(IntVec3 c, Map map, HashSet <IntVec3> processed, Predicate <IntVec3> predicate)
        {
            if (processed.Contains(c) || !predicate(c))
            {
                return(CellRect.Empty);
            }
            CellRect rect = CellRect.SingleCell(c);
            bool     flag;

            do
            {
                flag = false;
                if (rect.Width <= rect.Height)
                {
                    if (rect.maxX + 1 < map.Size.x && CanExpand(Rot4.East))
                    {
                        rect.maxX++;
                        flag = true;
                    }
                    if (rect.minX > 0 && CanExpand(Rot4.West))
                    {
                        rect.minX--;
                        flag = true;
                    }
                }
                if (rect.Height <= rect.Width)
                {
                    if (rect.maxZ + 1 < map.Size.z && CanExpand(Rot4.North))
                    {
                        rect.maxZ++;
                        flag = true;
                    }
                    if (rect.minZ > 0 && CanExpand(Rot4.South))
                    {
                        rect.minZ--;
                        flag = true;
                    }
                }
            }while (flag);
            foreach (IntVec3 item in rect)
            {
                processed.Add(item);
            }
            return(rect);

            bool CanExpand(Rot4 dir)
            {
                foreach (IntVec3 edgeCell in rect.GetEdgeCells(dir))
                {
                    IntVec3 intVec = edgeCell + dir.FacingCell;
                    if (processed.Contains(intVec) || !predicate(intVec))
                    {
                        return(false);
                    }
                }
                return(true);
            }
        }
Beispiel #3
0
 public static void GetAdjacentCorners(LocalTargetInfo target, out IntVec3 BL, out IntVec3 TL, out IntVec3 TR, out IntVec3 BR)
 {
     if (target.HasThing)
     {
         GenAdj.GetAdjacentCorners(target.Thing.OccupiedRect(), out BL, out TL, out TR, out BR);
     }
     else
     {
         GenAdj.GetAdjacentCorners(CellRect.SingleCell(target.Cell), out BL, out TL, out TR, out BR);
     }
 }
 private static void GetPawnsStandingAtOrAboutToStandAt(IntVec3 at, Map map, out int pawnsCount, out int pawnsWithLowerIdCount, out bool forPawnFound, Pawn forPawn)
 {
     pawnsCount            = 0;
     pawnsWithLowerIdCount = 0;
     forPawnFound          = false;
     CellRect.CellRectIterator iterator = CellRect.SingleCell(at).ExpandedBy(1).GetIterator();
     while (!iterator.Done())
     {
         IntVec3 current = iterator.Current;
         if (current.InBounds(map))
         {
             List <Thing> thingList = current.GetThingList(map);
             for (int i = 0; i < thingList.Count; i++)
             {
                 Pawn pawn = thingList[i] as Pawn;
                 if (pawn != null)
                 {
                     if (pawn.GetPosture() == PawnPosture.Standing)
                     {
                         if (current != at)
                         {
                             if (!pawn.pather.MovingNow || pawn.pather.nextCell != pawn.pather.Destination.Cell || pawn.pather.Destination.Cell != at)
                             {
                                 goto IL_132;
                             }
                         }
                         else if (pawn.pather.MovingNow)
                         {
                             goto IL_132;
                         }
                         if (pawn == forPawn)
                         {
                             forPawnFound = true;
                         }
                         pawnsCount++;
                         if (pawn.thingIDNumber < forPawn.thingIDNumber)
                         {
                             pawnsWithLowerIdCount++;
                         }
                     }
                 }
                 IL_132 :;
             }
         }
         iterator.MoveNext();
     }
 }
 private static void GetPawnsStandingAtOrAboutToStandAt(IntVec3 at, Map map, out int pawnsCount, out int pawnsWithLowerIdCount, out bool forPawnFound, Pawn forPawn)
 {
     pawnsCount            = 0;
     pawnsWithLowerIdCount = 0;
     forPawnFound          = false;
     foreach (IntVec3 item in CellRect.SingleCell(at).ExpandedBy(1))
     {
         if (!item.InBounds(map))
         {
             continue;
         }
         List <Thing> thingList = item.GetThingList(map);
         for (int i = 0; i < thingList.Count; i++)
         {
             Pawn pawn = thingList[i] as Pawn;
             if (pawn == null || pawn.GetPosture() != 0)
             {
                 continue;
             }
             if (item != at)
             {
                 if (!pawn.pather.MovingNow || pawn.pather.nextCell != pawn.pather.Destination.Cell || pawn.pather.Destination.Cell != at)
                 {
                     continue;
                 }
             }
             else if (pawn.pather.MovingNow)
             {
                 continue;
             }
             if (pawn == forPawn)
             {
                 forPawnFound = true;
             }
             pawnsCount++;
             if (pawn.thingIDNumber < forPawn.thingIDNumber)
             {
                 pawnsWithLowerIdCount++;
             }
         }
     }
 }
        public bool TryFindShootLineFromTo(IntVec3 root, LocalTargetInfo targ, out ShootLine resultingLine)
        {
            if (targ.HasThing && targ.Thing.Map != this.caster.Map)
            {
                resultingLine = default(ShootLine);
                return(false);
            }
            if (this.verbProps.IsMeleeAttack || this.verbProps.range <= 1.42f)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(ReachabilityImmediate.CanReachImmediate(root, targ, this.caster.Map, PathEndMode.Touch, null));
            }
            CellRect cellRect = (!targ.HasThing) ? CellRect.SingleCell(targ.Cell) : targ.Thing.OccupiedRect();
            float    num      = this.verbProps.EffectiveMinRange(targ, this.caster);
            float    num2     = cellRect.ClosestDistSquaredTo(root);

            if (num2 > this.verbProps.range * this.verbProps.range || num2 < num * num)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(false);
            }
            if (!this.verbProps.requireLineOfSight)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(true);
            }
            if (this.CasterIsPawn)
            {
                IntVec3 dest;
                if (this.CanHitFromCellIgnoringRange(root, targ, out dest))
                {
                    resultingLine = new ShootLine(root, dest);
                    return(true);
                }
                ShootLeanUtility.LeanShootingSourcesFromTo(root, cellRect.ClosestCellTo(root), this.caster.Map, Verb.tempLeanShootSources);
                for (int i = 0; i < Verb.tempLeanShootSources.Count; i++)
                {
                    IntVec3 intVec = Verb.tempLeanShootSources[i];
                    if (this.CanHitFromCellIgnoringRange(intVec, targ, out dest))
                    {
                        resultingLine = new ShootLine(intVec, dest);
                        return(true);
                    }
                }
            }
            else
            {
                CellRect.CellRectIterator iterator = this.caster.OccupiedRect().GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 intVec2 = iterator.Current;
                    IntVec3 dest;
                    if (this.CanHitFromCellIgnoringRange(intVec2, targ, out dest))
                    {
                        resultingLine = new ShootLine(intVec2, dest);
                        return(true);
                    }
                    iterator.MoveNext();
                }
            }
            resultingLine = new ShootLine(root, targ.Cell);
            return(false);
        }