Example #1
0
        private void ApplyDelPolysForAdders(ref List <List <IntPoint> > result, List <List <IntPoint> > bumperDelPolys)
        {
            // Fix log
            RemoveDelPolyFromEveryLogInSpace(bumperDelPolys, _adders);

            result = EntraSolver.GetPolySolution(result, bumperDelPolys, ClipType.ctDifference);
        }
        public static void ReAddInverseCutPolygon(Vector2 posComp, BumperEntityPoly bumperEntity, ref List <List <IntPoint> > delPolys)
        {
            var bumpRigid     = bumperEntity.CompObj as BumpRigid;
            var bumpPosXNA    = bumpRigid.PositionXNA2D;
            var bumpPosCenter = bumpRigid.PositionXNACenter2D;

            Vector2 bP1, bP2;

            ProjectionHandler.FindBumperTwoBorderPoints(bumperEntity, out bP1, out bP2);
            Vector2 cP1 = posComp, cP2 = posComp;

            Vector2 interP;

            MathHelperModule.FindIntersection(bP1, bP2, cP1, cP2, out interP);

            Vector2 cutP = GetBumperCutStartingPoint(bumpRigid.Dir, bP1, bP2, posComp);

            if (!RigidsHelperModule.IsCloseEnough(interP,
                                                  (bumperEntity.CompObj as BumpRigid).PositionXNACenter2D,
                                                  20))
            // if the bump is not on the collision course with the rocket
            {
                // Rocket is not on a collision course with the bump, so cut down the del poly area vertically
                List <IntPoint> polyInverseCutVertical = GetInverseCutPolygon(cutP, posComp);
                delPolys = EntraSolver.GetPolySolution(delPolys, polyInverseCutVertical, ClipType.ctIntersection);
            }
        }
Example #3
0
        public static List <List <IntPoint> > GetRopePoly(SpringService service, EngineManager engineManager)
        {
            int verticalLineLength, halfFarWidth;

            SetProperHalfFarWidth(service, engineManager.CookieRB, out verticalLineLength, out halfFarWidth);
            var polySemiCircle = PolysHelper.GetShapeSemiCirclePoly(service.Masses[0].PositionXNACenter2D,
                                                                    ropeNearWidth,
                                                                    verticalLineLength,
                                                                    halfFarWidth);
            List <IntPoint> polyAdded = GetAddedGravityRectanglePoly(service, engineManager);
            var             polyFinal = EntraSolver.GetPolySolution(polySemiCircle, polyAdded, ClipType.ctUnion);

            // Cut upper rectangle
            int             cY   = (int)StaticData.EngineManager.CookieRB.PositionXNACenter2D.Y;
            List <IntPoint> poly = new List <IntPoint>()
            {
                new IntPoint(0, 0),
                new IntPoint(StaticData.LevelFarWidth, 0),
                new IntPoint(StaticData.LevelFarWidth, cY),
                new IntPoint(0, cY),
            };

            polyFinal = EntraSolver.GetPolySolution(polyFinal, poly, ClipType.ctDifference);
            return(polyFinal);
        }
        //private List<List<IntPoint>> GetDelPolysIntersection(List<List<IntPoint>> allDelPolys)
        //{
        //    if (allDelPolys.Count > 0)
        //    {
        //        List<List<IntPoint>> interPoly = new List<List<IntPoint>>();
        //        var first = allDelPolys.First();
        //        if (allDelPolys.Count == 1)
        //        {
        //            return new List<List<IntPoint>>() { first };
        //        }
        //        else
        //        {
        //            allDelPolys.RemoveAt(0);
        //            //EntraDrawer.DrawIntoFile(new Polygons(){first});
        //            //EntraDrawer.DrawIntoFile(allDelPolys);
        //            var unions = EntraSolver.GetPolyUnions(allDelPolys);
        //            interPoly = EntraSolver.GetPolySolution(first, unions, ClipType.ctIntersection);
        //            return interPoly;
        //        }
        //    }
        //    return null;
        //}

        public static List <List <IntPoint> > GetDelPolysIntersection(List <List <IntPoint> > allDelPolys)
        {
            if (allDelPolys.Count > 1)
            {
                List <List <IntPoint> > interPoly = new List <List <IntPoint> >();
                var first = allDelPolys.First();
                allDelPolys.RemoveAt(0);
                var unions = EntraSolver.GetPolyUnions(allDelPolys);
                interPoly = EntraSolver.GetPolySolution(first, unions, ClipType.ctIntersection);
                return(interPoly);
            }
            else
            {
                if (allDelPolys.Count == 1)
                {
                    return(new List <List <IntPoint> >()
                    {
                        allDelPolys.First()
                    });
                }
                else
                {
                    return(null);
                }
            }
        }
        public static void ReAddBlowerBubbleRopeTrajectoryMissingAreas(Vector2 posComp,
                                                                       BumperEntityPoly bumperEntity,
                                                                       ref List <List <IntPoint> > delPolys)
        {
            var bumpRigid     = bumperEntity.CompObj as BumpRigid;
            var bumpPosXNA    = bumpRigid.PositionXNA2D;
            var bumpPosCenter = bumpRigid.PositionXNACenter2D;

            Vector2 bP1, bP2;

            ProjectionHandler.FindBumperTwoBorderPoints(bumperEntity, out bP1, out bP2);
            Vector2 cP1 = posComp, cP2 = posComp;

            Vector2 interP;

            MathHelperModule.FindIntersection(bP1, bP2, cP1, cP2, out interP);

            Vector2 cutP = GetBumperCutStartingPoint(bumpRigid.Dir, bP1, bP2, posComp);

            if (!RigidsHelperModule.IsCloseEnough(interP,
                                                  (bumperEntity.CompObj as BumpRigid).PositionXNACenter2D,
                                                  20))
            {
                List <IntPoint> polyInverseCutVertical = GetInverseCutPolygon(cutP, posComp);
                EntraDrawer.DrawIntoFile(new List <List <IntPoint> >()
                {
                    polyInverseCutVertical
                });
                EntraDrawer.DrawIntoFile(delPolys);

                delPolys = EntraSolver.GetPolySolution(delPolys, polyInverseCutVertical, ClipType.ctIntersection);
                EntraDrawer.DrawIntoFile(delPolys);
            }
        }
Example #6
0
        public void SetOpennerNonOpenner(List <List <IntPoint> > spaceSoFar, List <CompEntityPoly> allEntitiesList,
                                         List <BumperEntityPoly> rBumpers)
        {
            var rCompsAllNew = _entraAgentSimple.AreaCompPolyHandler.GetReachServicePolys(spaceSoFar, allEntitiesList);

            All = rCompsAllNew.Where(comp => comp is RocketEntityPoly).Cast <RocketEntityPoly>().ToList();

            // Find Openner
            Openners        = new List <RocketEntityPoly>();
            CollidedBumpers = new List <BumperEntityPoly>();
            foreach (RocketEntityPoly rocketEntity in All)
            {
                bool collision = false;
                foreach (CompEntityPoly bumperEntity in rBumpers)
                {
                    var sol = EntraSolver.GetPolySolution(bumperEntity.GetDefPoly(), rocketEntity.GetAreaPoly(),
                                                          ClipType.ctIntersection);
                    if (sol.Count > 0)
                    {
                        CollidedBumpers.Add(bumperEntity as BumperEntityPoly);
                        collision = true;
                    }
                }
                if (!collision)
                {
                    Openners.Add(rocketEntity);
                }
            }
        }
Example #7
0
        //public bool IsOperation(PolyLog parentLog, ClipType ctOperation)
        //{
        //    List<List<IntPoint>> thisPolysUnion = GetPolysUnion(this.ApPairs);
        //    List<List<IntPoint>> parentPolysUnion = GetPolysUnion(parentLog.ApPairs);

        //    //EntraDrawer.DrawIntoFileTesting(thisPolysUnion);
        //    //EntraDrawer.DrawIntoFileTesting(parentPolysUnion);

        //    if (EntraSolver.IsPolyOperation(thisPolysUnion, parentPolysUnion, ClipType.ctIntersection))
        //    {
        //        //if (parentLog.Comp is BumperEntityPoly)
        //        {
        //            foreach (APPair apPair in parentLog.ApPairs)
        //            {
        //                if (apPair.AdderComp == this.Comp)
        //                {
        //                    return true;
        //                }
        //            }
        //        }
        //        //else
        //        //{
        //        //    if (parentLog.ApPairs[0].AdderComp == this.Comp)
        //        //    {
        //        //        return true;
        //        //    }
        //        //}
        //    }

        //    return false;
        //}

        private List <List <IntPoint> > GetPolysUnion(List <APPair> polys)
        {
            var res = new List <List <IntPoint> >();

            foreach (APPair apPair in polys)
            {
                res = EntraSolver.GetPolySolution(res, apPair.Poly, ClipType.ctUnion);
            }
            return(res);
        }
Example #8
0
        public override List <List <IntPoint> > ApplyEffect(List <List <IntPoint> > spaceSoFar, CompEntityPoly adder)
        {
            var initialPoly = this.GetAreaPoly();

            this.EntraAgentSimple.PolysLogger.Log(new PolyLog(this, initialPoly, null));

            var result = EntraSolver.GetPolySolution(initialPoly, spaceSoFar, ClipType.ctUnion);

            return(result);
        }
        public override List <List <IntPoint> > ApplyEffect(List <List <IntPoint> > spaceSoFar, CompEntityPoly adder)
        {
            List <List <IntPoint> > result = new List <List <IntPoint> >();

            var initialPoly = this.GetAreaPoly();

            //BumpersHandler.ReAddNewlyAddedBumpsAreas(ref initialPoly, this);
            this.EntraAgentSimple.PolysLogger.Log(new PolyLog(this, initialPoly, adder));

            result = EntraSolver.GetPolySolution(initialPoly, spaceSoFar, ClipType.ctUnion);
            EntraDrawer.DrawIntoFile(result);
            return(result);
        }
Example #10
0
 private void ClipPolygonsFromBorders(ref List <List <IntPoint> > polys)
 {
     if (polys != null)
     {
         if (polys.Count > 0)
         {
             // Clip with four borders
             for (int i = 0; i < 7; i += 2)
             {
                 List <IntPoint> poly = GetPlanePolygon((Direction)i);
                 polys = EntraSolver.GetPolySolution(polys, poly, ClipType.ctDifference);
             }
         }
     }
 }
Example #11
0
        public static List <List <IntPoint> > GetDefBlowerPoly(BlowerService blower)
        {
            //return PolysHelper.GetShapeSquarePoly(blower.PositionXNACenter, (blower.Height + 50)/2);
            var res = AreaCompPolyHandler.GetBlowerPoly((BlowerService)blower, StaticData.BlowerEffectAreaRadius);

            List <IntPoint> polyCut = new List <IntPoint>()
            {
                new IntPoint(-1000, (int)blower.PositionXNA.Y + StaticData.BlowerEffectAreaRadius),
                new IntPoint(+1000, (int)blower.PositionXNA.Y + StaticData.BlowerEffectAreaRadius),
                new IntPoint(+1000, 1000),
                new IntPoint(-1000, 1000),
            };

            return(EntraSolver.GetPolySolution(res, polyCut, ClipType.ctDifference));
        }
Example #12
0
 private void ApplyAddPolysForAdders(ref List <List <IntPoint> > result, List <List <IntPoint> > bumperDelPolys,
                                     bool withAdd)
 {
     if (withAdd)
     {
         foreach (CompEntityPoly adder in _adders)
         {
             var bumpAddPoly = this.GetAreaPoly(adder);
             EntraDrawer.DrawIntoFile(bumpAddPoly);
             bumpAddPoly = EntraSolver.GetPolySolution(bumpAddPoly, bumperDelPolys, ClipType.ctDifference);
             AddToLog(bumpAddPoly, adder);
             EntraDrawer.DrawIntoFile(bumpAddPoly);
             result = EntraSolver.GetPolySolution(result, bumpAddPoly, ClipType.ctUnion);
         }
     }
 }
Example #13
0
        private void RemoveDelPolyFromEveryLogInSpace(List <List <IntPoint> > bumperDelPolys, List <CompEntityPoly> adders)
        {
            List <PolyLog> polys = this.EntraAgentSimple.PolysLogger.GetLog();

            foreach (PolyLog polyLog in polys)
            {
                foreach (CompEntityPoly adder in adders)
                {
                    if (polyLog.Comp == adder)
                    {
                        foreach (APPair apPair in polyLog.ApPairs)
                        {
                            apPair.Poly = EntraSolver.GetPolySolution(apPair.Poly, bumperDelPolys, ClipType.ctDifference);
                        }
                    }
                }
            }
        }
Example #14
0
        public override List <List <IntPoint> > ApplyEffect(List <List <IntPoint> > spaceSoFar, CompEntityPoly adder)
        {
            List <List <IntPoint> > result = new List <List <IntPoint> >();
            var initialPoly = this.GetAreaPoly();

            EntraDrawer.DrawIntoFile(initialPoly);

            if (adder is BlowerEntityPoly)
            {
                AddBlowersEffect(ref initialPoly);
            }
            EntraDrawer.DrawIntoFile(initialPoly);
            this.EntraAgentSimple.PolysLogger.Log(new PolyLog(this, initialPoly, adder));

            result = EntraSolver.GetPolySolution(initialPoly, spaceSoFar, ClipType.ctUnion);
            EntraDrawer.DrawIntoFile(result);
            return(result);
        }
        public List <List <IntPoint> > ApplyCloseBumpersFix(List <BumperEntityPoly> rBumpers, List <List <IntPoint> > spaceSoFar,
                                                            out List <BumperEntityPoly> bumpersOfGroups)
        {
            bumpersOfGroups = new List <BumperEntityPoly>();
            List <List <BumperEntityPoly> > closeGroups = GroupizeCloseBumpers(rBumpers);

            foreach (List <BumperEntityPoly> group in closeGroups)
            {
                foreach (BumperEntityPoly bumper in group)
                {
                    spaceSoFar = EntraSolver.GetPolySolution(spaceSoFar, ((BumperEntityPoly)bumper).DelPoly, ClipType.ctDifference);
                }
            }
            List <BumperEntityPoly> groups = new List <BumperEntityPoly>();

            closeGroups.ForEach(groups.AddRange);
            bumpersOfGroups = groups;
            return(spaceSoFar);
        }
        public static void RemoveRocketsPolysIntersectionWithPlanes(RocketCarrierService rocket,
                                                                    ref List <List <IntPoint> > poly)
        {
            Vector2 rP1, rP2;

            ProjectionHandler.FindRocketTwoBorderPoints(rocket, out rP1, out rP2);

            Vector2 rPosCenter = new Vector2((rP1.X + rP2.X) / 2, (rP1.Y + rP2.Y) / 2);

            for (int i = 0; i < 7; i += 2)
            {
                var cDir = (Direction)i;
                //if (CompIsOnDirToBump(compPos, rPosCenter, cDir))
                //{
                Vector2 planeP1, planeP2;
                GetPlanePoints(cDir, out planeP1, out planeP2);

                Vector2 interP;
                MathHelperModule.FindIntersection(planeP1, planeP2, rP1, rP2, out interP);

                if (interP.X <= StaticData.LevelFarWidth && interP.X >= 0 &&
                    interP.Y <= StaticData.LevelFarHeight && interP.Y >= 0)
                {
                    // Rocket is not on a collision course with the bump,
                    // so cut down the del poly area vertically
                    List <IntPoint> polyInverseCutVertical = GetInverseCutPolygon(interP, rocket.PositionXNACenter2D);

                    EntraDrawer.DrawIntoFile(new List <List <IntPoint> >()
                    {
                        polyInverseCutVertical
                    });

                    poly = EntraSolver.GetPolySolution(poly, polyInverseCutVertical,
                                                       ClipType.ctIntersection);
                    EntraDrawer.DrawIntoFile(poly);
                }
                // }
            }
        }
        public static void ReAddRocketTrajectoryMissingAreas(RocketEntityPoly rocketEntityPoly,
                                                             BumperEntityPoly bumperEntity,
                                                             ref List <List <IntPoint> > delPolys)
        {
            var bumpRigid     = bumperEntity.CompObj as BumpRigid;
            var bumpPosXNA    = bumpRigid.PositionXNA2D;
            var bumpPosCenter = bumpRigid.PositionXNACenter2D;

            Vector2 bP1, bP2;

            ProjectionHandler.FindBumperTwoBorderPoints(bumperEntity, out bP1, out bP2);
            Vector2 rP1, rP2;

            ProjectionHandler.FindRocketTwoBorderPoints(rocketEntityPoly, out rP1, out rP2);

            Vector2 interP;

            MathHelperModule.FindIntersection(bP1, bP2, rP1, rP2, out interP);

            Vector2 cutP = GetBumperCutStartingPoint(bumpRigid.Dir, bP1, bP2,
                                                     (rocketEntityPoly.CompObj as RocketCarrierService).PositionXNACenter2D);

            if (!RigidsHelperModule.IsCloseEnough(interP,
                                                  (bumperEntity.CompObj as BumpRigid).PositionXNACenter2D,
                                                  20))
            // if the bump is not on the collision course with the rocket
            {
                // Rocket is not on a collision course with the bump, so cut down the del poly area vertically
                List <IntPoint> polyInverseCutVertical = GetInverseCutPolygon(cutP, rocketEntityPoly);

                EntraDrawer.DrawIntoFile(new List <List <IntPoint> >()
                {
                    polyInverseCutVertical
                });

                delPolys = EntraSolver.GetPolySolution(delPolys, polyInverseCutVertical, ClipType.ctIntersection);
                EntraDrawer.DrawIntoFile(delPolys);
            }
        }
        public static void AddBumpsAreaForBubble(ref List <List <IntPoint> > initialPoly, BumperEntityPoly bumper,
                                                 BubbleEntityPoly bubble)
        {
            BubbleService bubbleService = bubble.CompObj as BubbleService;
            Vector2       bubblePos     = bubbleService.PositionXNACenter;
            //var coveredBumps = BumpersHandler.GetCoveredBumpers(bubble, initialPoly);

            int fR  = AreaCompPolyHandler.fR;
            int nR  = AreaCompPolyHandler.nR;
            int dfR = AreaCompPolyHandler.dfR;
            //foreach (BumperEntityPoly bumper in coveredBumps)
            {
                BumpRigid       bump  = bumper.CompObj as BumpRigid;
                Vector2         bPos  = bump.PositionXNACenter2D;
                CookieDirection abDir = AreaCompPolyHandler.GetABCookieDirection(bubblePos, bPos);
                CookieDirection rlDir = AreaCompPolyHandler.GetRLCookieDirection(bubblePos, bPos);

                switch (bump.Dir)
                {
                case Direction.East:
                case Direction.West:
                    if (abDir == CookieDirection.FromBottom)
                    {
                        if (rlDir == CookieDirection.FromRight)
                        {
                            initialPoly = EntraSolver.GetPolySolution(initialPoly,
                                                                      new List <IntPoint>()
                            {
                                new IntPoint((int)bPos.X, (int)bPos.Y + 900),
                                new IntPoint((int)bPos.X - fR, (int)bPos.Y + 900),
                                new IntPoint((int)bPos.X - fR, (int)bPos.Y - 900),
                                new IntPoint((int)bPos.X, (int)bPos.Y - 900)
                            },
                                                                      ClipType.ctUnion);
                        }
                        else
                        {
                            //initialPoly = EntraSolver.GetPolySolution(initialPoly,
                            //                                          new Polygon()
                            //                                              {
                            //                                                  new IntPoint((int) bPos.X,
                            //                                                               (int) bPos.Y - 900),
                            //                                                  new IntPoint((int) bPos.X + fR,
                            //                                                               (int) bPos.Y - 900),
                            //                                                  new IntPoint((int) bPos.X + fR,
                            //                                                               (int) bPos.Y + nR),
                            //                                                  new IntPoint((int) bPos.X - 20,
                            //                                                               (int) bPos.Y + nR),
                            //                                                  new IntPoint((int) bPos.X - 20,
                            //                                                               (int) bPos.Y + 20),
                            //                                              },
                            //                                          ClipType.ctUnion);
                            initialPoly = EntraSolver.GetPolySolution(initialPoly,
                                                                      new List <IntPoint>()
                            {
                                new IntPoint((int)bPos.X,
                                             (int)bPos.Y - 900),
                                new IntPoint((int)bPos.X + fR,
                                             (int)bPos.Y - 900),
                                new IntPoint((int)bPos.X + fR,
                                             (int)bPos.Y + 900),
                                new IntPoint((int)bPos.X,
                                             (int)bPos.Y + 900)
                            },
                                                                      ClipType.ctUnion);
                        }
                    }
                    else
                    {
                        // the bubble is above the bumps so don't add anything
                    }
                    break;

                case Direction.South:
                case Direction.North:
                    break;

                case Direction.NorthWest:
                case Direction.SouthEast:
                    if (abDir == CookieDirection.FromBottom)     // From Right and Left are the same
                    {
                        initialPoly = EntraSolver.GetPolySolution(initialPoly,
                                                                  new List <IntPoint>()
                        {
                            new IntPoint((int)bPos.X,
                                         (int)bPos.Y + 900),
                            new IntPoint((int)bPos.X - fR,
                                         (int)bPos.Y + 900),
                            new IntPoint((int)bPos.X - fR,
                                         (int)bPos.Y - 900),
                            new IntPoint((int)bPos.X,
                                         (int)bPos.Y - 900)
                        },
                                                                  ClipType.ctUnion);
                    }
                    break;

                case Direction.NorthEast:
                case Direction.SouthWest:
                    if (abDir == CookieDirection.FromBottom)     // From Right and Left are the same
                    {
                        //var poly = new Polygon()
                        //    {
                        //        new IntPoint((int) bPos.X, (int) bPos.Y - 900),
                        //        new IntPoint((int) bPos.X + fR,
                        //                     (int) bPos.Y - 900),
                        //        new IntPoint((int) bPos.X + fR, (int) bPos.Y),
                        //        new IntPoint((int) bPos.X, (int) bPos.Y),
                        //    };
                        //EntraDrawer.DrawIntoFile(poly);
                        //initialPoly = EntraSolver.GetPolySolution(initialPoly,
                        //                                            poly,
                        //                                              ClipType.ctUnion);
                        var poly = new List <IntPoint>()
                        {
                            new IntPoint((int)bPos.X,
                                         (int)bPos.Y - 900),
                            new IntPoint((int)bPos.X + fR,
                                         (int)bPos.Y - 900),
                            new IntPoint((int)bPos.X + fR,
                                         (int)bPos.Y + 900),
                            new IntPoint((int)bPos.X,
                                         (int)bPos.Y + 900),
                        };
                        initialPoly = EntraSolver.GetPolySolution(initialPoly, poly, ClipType.ctUnion);
                        EntraDrawer.DrawIntoFile(poly);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }