Beispiel #1
0
        // Yinon Douchan: Only find the shortest path between two points.
        public async Task <typRoute> createRouteByShortestPathOnly(double StartX, double StartY, double ReferencePointX, double ReferencePointY)
        {
            List <DPoint> Result = new List <DPoint>();

            DPoint ReferPoint = new DPoint(ReferencePointX, ReferencePointY);
            shPath Path       = await clsRoadRoutingWebApi.FindShortPath("0", StartX, StartY, ReferencePointX, ReferencePointY, false);

            if (Path != null && Path.Points.Count > 0)
            {
                shPoint refPoint = Path.Points[Path.Points.Count - 1];
                ReferPoint = new DPoint(refPoint.x, refPoint.y);

                foreach (shPoint p in Path.Points)
                {
                    Result.Add(new DPoint(p.x, p.y));
                }
            }

            if (Result.Count == 0)
            {
                Result.Add(new DPoint(StartX, StartY));
            }
            else
            {
                if (Result[0].x != StartX || Result[0].y != StartY)
                {
                    Result.Insert(0, new DPoint(StartX, StartY));
                }
            }

            Route routeResult = new Route();

            routeResult.Points = Result;


            typRoute tRoute = new typRoute(routeResult);

            return(tRoute);
        }
Beispiel #2
0
        private void inflictDamageOnGroundAtomsInExplosion(DPoint location, double radius)
        {
            List<clsGroundAtom> atomsToDamage = m_GameManager.QuadTreeGroundAtom.SearchEntities(location.x, location.y, radius, isPrecise: true);
            double certainDeathRadius = 0.2*radius;

            foreach (clsGroundAtom atom in atomsToDamage)
            {
                // certain death when very close to event source
                double distanceToEventSource = TerrainService.MathEngine.CalcDistance(atom.curr_X, atom.curr_Y, location.x, location.y);
                if (distanceToEventSource < certainDeathRadius)
                {
                    atom.healthStatus.isDead = true;
                    continue;
                }

                // the farther the atom is from the source the less likely he is to die - use linearly decreasing death probability
                double deathProbability = 0.5*(radius - distanceToEventSource)/(radius - certainDeathRadius);
                double random = Util.random.NextDouble();
                if (random <= deathProbability) atom.healthStatus.isDead = true;

                // if he didn't die, make him injured with twice the same probability distribution
                double injuryProbability = (radius - distanceToEventSource) / (radius - certainDeathRadius);
                random = Util.random.NextDouble();
                if (random <= injuryProbability)
                {
                    atom.healthStatus.isInjured = true;
                }

                // incapacitate him with twice the same probability distribution
                double incapacitanceProbability = 0.5*(radius - distanceToEventSource) / (radius - certainDeathRadius);
                random = Util.random.NextDouble();
                if (random <= incapacitanceProbability)
                {
                    atom.healthStatus.isIncapacitated = true;
                    atom.healthStatus.isInjured = true;
                }

                if (atom.healthStatus.isIncapacitated || atom.healthStatus.isInjured)
                {
                    atom.healthStatus.injurySeverity = (radius - distanceToEventSource) / (radius - certainDeathRadius);
                }

                // make injured atoms move slower
                if (atom.healthStatus.isInjured)
                {
                    atom.currentSpeed *= (1 - atom.healthStatus.injurySeverity);
                }

                // if he didn't die or was not injured or incapacitated - he's one lucky bastard.
            }
        }
Beispiel #3
0
 // YD: Generate atoms on sidewalk randomly
 public DPoint[] getRegularMovementCoordinates()
 {
     DPoint[] travelCoordinates = new DPoint[] { new DPoint(34.848627448082, 32.0995901398799), new DPoint(34.8495876789093, 32.0996264945646),
                                                 new DPoint(34.8505747318268, 32.0996492162353),
                                                 new DPoint(34.850612282753, 32.0982768171897), new DPoint(34.8492550849915, 32.0980950409352),
                                                 new DPoint(34.8486435413361, 32.098308627997), new DPoint(34.8514652252197, 32.0996855708965),
                                                 new DPoint(34.851508140564, 32.0986403686134), new DPoint(34.8511004447937, 32.0973452100618),
                                                 new DPoint(34.8498612642288, 32.0977905648985), new DPoint(34.8485255241394, 32.0982631839831),
                                                 new DPoint(34.8479408025742, 32.0971543430385), new DPoint(34.8504567146301, 32.096090933751)};
     return travelCoordinates;
 }
Beispiel #4
0
        public async Task <typRoute> CreateRoute(double StartX, double StartY, double ReferencePointX, double ReferencePointY, string RouteGuid)
        {
            try
            {
                List <DPoint> Result = new List <DPoint>();

                Route  route      = TDS.DAL.RoutesDB.GetRouteByGuid(RouteGuid);
                DPoint ReferPoint = new DPoint(ReferencePointX, ReferencePointY);

                shPath Path = await clsRoadRoutingWebApi.FindShortPath("0", StartX, StartY, ReferencePointX, ReferencePointY, false);

                if (Path != null && Path.Points.Count > 0)
                {
                    shPoint refPoint = Path.Points[Path.Points.Count - 1];
                    ReferPoint = new DPoint(refPoint.x, refPoint.y);

                    foreach (shPoint p in Path.Points)
                    {
                        Result.Add(new DPoint(p.x, p.y));
                    }
                }

                if (Result.Count == 0)
                {
                    Result.Add(new DPoint(StartX, StartY));
                }
                else
                {
                    if (Result[0].x != StartX || Result[0].y != StartY)
                    {
                        Result.Insert(0, new DPoint(StartX, StartY));
                    }
                }

                int    leg      = 0;
                DPoint minP     = null;
                double mainDist = double.MaxValue;
                int    i        = -1;
                foreach (DPoint p in route.Points)
                {
                    i++;
                    // double dist = MathEngine.CalcDistanceForCompare(ReferPoint.x, ReferPoint.y, p.x, p.y);
                    double dist = MathEngine.GreatCircleDistance(ReferPoint.x, ReferPoint.y, p.x, p.y);
                    if (dist < mainDist)
                    {
                        mainDist = dist;
                        minP     = p;
                        leg      = i;
                    }
                }
                if (mainDist != 0.0)
                {
                    List <DPoint> R = route.Points.ToList <DPoint>().GetRange(leg, route.Points.Count() - leg);
                    Result.AddRange(R);
                }
                else
                {
                    if (leg < route.Points.Count() - 1) // Not Last element
                    {
                        List <DPoint> R = route.Points.ToList <DPoint>().GetRange(leg + 1, route.Points.Count() - (leg + 1));
                        Result.AddRange(R);
                    }
                }

                Route routeResult = new Route();
                routeResult.Points = Result;


                typRoute tRoute = new typRoute(routeResult);
                return(tRoute);
            }
            catch (Exception ex)
            {
            }



            return(null);
        }
Beispiel #5
0
        public  async Task<typRoute> CreateRoute(double StartX, double StartY, double ReferencePointX, double ReferencePointY, string RouteGuid)
        {

            try
            {
                List<DPoint> Result = new List<DPoint>();

                Route route = TDS.DAL.RoutesDB.GetRouteByGuid(RouteGuid);
                DPoint ReferPoint = new DPoint(ReferencePointX, ReferencePointY);

                shPath Path = await clsRoadRoutingWebApi.FindShortPath("0", StartX, StartY, ReferencePointX, ReferencePointY, false);
                if (Path != null && Path.Points.Count > 0)
                {
                    shPoint refPoint = Path.Points[Path.Points.Count - 1];
                    ReferPoint = new DPoint(refPoint.x, refPoint.y);
                   
                    foreach(shPoint p in Path.Points)
                    {
                        Result.Add(new DPoint(p.x, p.y));
                    }

                }

                if(Result.Count==0)
                {
                    Result.Add(new DPoint(StartX, StartY));
                }
                else
                {
                    if (Result[0].x != StartX || Result[0].y != StartY)
                    {
                        Result.Insert(0, new DPoint(StartX, StartY));
                    }
                }

                int leg = 0;
                DPoint minP = null;
                double mainDist = double.MaxValue;
                int i = -1;
                foreach (DPoint p in route.Points)
                {
                    i++;
                   // double dist = MathEngine.CalcDistanceForCompare(ReferPoint.x, ReferPoint.y, p.x, p.y);
                    double dist = MathEngine.GreatCircleDistance(ReferPoint.x, ReferPoint.y, p.x, p.y);
                    if (dist < mainDist)
                    {
                        mainDist = dist;
                        minP = p;
                        leg = i;
                    }
                }
                if(mainDist!=0.0)
                {
                    List<DPoint> R = route.Points.ToList<DPoint>().GetRange(leg, route.Points.Count() - leg);
                    Result.AddRange(R);
                }
                else
                {
                    if(leg<route.Points.Count()-1) // Not Last element
                    {
                        List<DPoint> R = route.Points.ToList<DPoint>().GetRange(leg+1, route.Points.Count() - (leg+1));
                        Result.AddRange(R);
                    }
                }

                Route routeResult = new Route();
                routeResult.Points = Result;


                typRoute tRoute = new typRoute(routeResult);
                return tRoute;
            }
            catch(Exception ex)
            {

            }

          

            return null;
        }
Beispiel #6
0
		// Yinon Douchan: Only find the shortest path between two points.
        public async Task<typRoute> createRouteByShortestPathOnly(double StartX, double StartY, double ReferencePointX, double ReferencePointY)
        {
            List<DPoint> Result = new List<DPoint>();

            DPoint ReferPoint = new DPoint(ReferencePointX, ReferencePointY);
            shPath Path = await clsRoadRoutingWebApi.FindShortPath("0", StartX, StartY, ReferencePointX, ReferencePointY, false);

            if (Path != null && Path.Points.Count > 0)
            {
                shPoint refPoint = Path.Points[Path.Points.Count - 1];
                ReferPoint = new DPoint(refPoint.x, refPoint.y);

                foreach (shPoint p in Path.Points)
                {
                    Result.Add(new DPoint(p.x, p.y));
                }

            }

            if (Result.Count == 0)
            {
                Result.Add(new DPoint(StartX, StartY));
            }
            else
            {
                if (Result[0].x != StartX || Result[0].y != StartY)
                {
                    Result.Insert(0, new DPoint(StartX, StartY));
                }
            }

            Route routeResult = new Route();
            routeResult.Points = Result;


            typRoute tRoute = new typRoute(routeResult);

            return tRoute;
        }