Exemple #1
0
        protected void reevaluationAfterForcesHaveArrivedEventHandler(object sender, EventArgs e)
        {
            clsGroundAtom refGroundAtom = ((clsGroundAtomEventArgs)e).groundAtom;

            refGroundAtom.currentSpeed = refGroundAtom.baselineSpeed;

            // if in social comparison state and not stuck stay in social comparison - things seems to be moving
            if (refGroundAtom.currentState.GetType() == typeof(SOCIAL_COMPARISON_STATE))
            {
                SOCIAL_COMPARISON_STATE sc = (SOCIAL_COMPARISON_STATE)refGroundAtom.currentState;
                bool stuck = refGroundAtom.currentSpeed <= (float)sc.baselineSpeed / 10.0;
                if (stuck)
                {
                    clsActivityMovement barrierMovement = RouteUtils.createActivityAndStart(refGroundAtom, (int)refGroundAtom.currentSpeed, null);
                    refGroundAtom.ChangeState(new GO_TO_POLICE_BARRIER_STATE(barrierMovement));
                }
            }

            if (refGroundAtom.currentState.GetType() != typeof(GO_TO_POLICE_BARRIER_STATE))
            {
                clsActivityMovement barrierMovement = RouteUtils.createActivityAndStart(refGroundAtom, (int)refGroundAtom.currentSpeed, null);
                refGroundAtom.ChangeState(new GO_TO_POLICE_BARRIER_STATE(barrierMovement));
                return;
            }
        }
Exemple #2
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            if (routeFromPoint == null)
            {
                // only go to sidewalk
                DPoint source = new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y);
                DPoint dest   = new DPoint(pointOnSidewalk.x, pointOnSidewalk.y);
                refGroundAtom.currentRoute = RouteUtils.planStraightLineRoute(source, dest, "GetOnSidewalk_" + refGroundAtom.MyName);
            }
            else
            {
                // go to sidewalk and then to a route from that sidewalk given at routeFromPoint
                List <DPoint> points = new List <DPoint>();
                points.Add(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y));
                points.Add(new DPoint(pointOnSidewalk.x, pointOnSidewalk.y));

                // add all points except first which is the point on the sidewalk
                for (int i = 0; i < routeFromPoint.Points.Count(); i++)
                {
                    points.Add(routeFromPoint.Points.ElementAt(i));;
                }

                refGroundAtom.currentRoute = RouteUtils.createTypRoute(points, "GetOnSidewalk_" + refGroundAtom.MyName);
            }
        }
Exemple #3
0
        // default event handler for death
        protected void deathDefaultEventHandler(object sender, EventArgs e)
        {
            clsGroundAtom refGroundAtom = ((clsGroundAtomEventArgs)e).groundAtom;

            refGroundAtom.ChangeState(new DEAD_STATE());
            return;
        }
Exemple #4
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            // go to a different direction
            if (refGroundAtom.currentLeg > refGroundAtom.currentRoute.arr_legs.Count)
            {
                if (routeFromPoint == null)
                {
                    refGroundAtom.ChangeState(new ADMINISTRATIVE_STATE());
                    return;
                }

                // destination waypoint is now the source waypoint
                refGroundAtom.currentStartWaypoint = refGroundAtom.currentEndWaypoint;
                int randomWaypoint = Util.random.Next(refGroundAtom.m_GameObject.travelRoutes.GetLength(1) - 1);
                if (randomWaypoint >= refGroundAtom.currentStartWaypoint)
                {
                    randomWaypoint++;
                }

                refGroundAtom.currentEndWaypoint = randomWaypoint;
                refGroundAtom.currentLeg         = 1;
                refGroundAtom.ChangeState(new REGULAR_MOVEMENT_STATE(refActivityMovement));
                refGroundAtom.reEvaluationEventHandler += reevaluationAfterEarthquakeEndedEventHandler;
                return;
            }

            base.Execute(refGroundAtom);
        }
Exemple #5
0
        // create an activity, start it and return it
        public static clsActivityMovement createActivityAndStart(clsGroundAtom atom, int speed, Route route)
        {
            clsActivityMovement activity = createActivity(atom, speed, route);
            startActivity(activity);

            return activity;
        }
Exemple #6
0
        // YD: default event handler for when an earthquake starts when not in structure
        protected void earthquakeStartedDefaultEventHandler(object sender, EventArgs e)
        {
            // default action is holding on to an immobile object, be it the ground, a fence, a car etc.
            clsGroundAtom refGroundAtom = ((clsGroundAtomEventArgs)e).groundAtom;

            // there's an earthquake. better move fast before something falls on me
            double panicSpeedMultiplier = (Util.random.NextDouble() + 1.5);

            refGroundAtom.currentSpeed = panicSpeedMultiplier * refGroundAtom.baselineSpeed;

            refGroundAtom.knowsAboutEarthquake = true;

            // there are no proxemics in non-normative conditions
            refGroundAtom.collisionRadius = 2 * clsGroundAtom.RADIUS;

            refGroundAtom.reEvaluationEventHandler += reevaluationAfterEarthquakeStartedEventHandler;

            refGroundAtom.lastRoutePoint.x = refGroundAtom.X_Route;
            refGroundAtom.lastRoutePoint.y = refGroundAtom.Y_Route;
            if (moveToSocialComparisonStateIfShould(refGroundAtom))
            {
                return;
            }

            clsActivityMovement activity = RouteUtils.createActivityAndStart(refGroundAtom, (int)refGroundAtom.currentSpeed, null);

            refGroundAtom.ChangeState(new HOLD_ON_TO_OBJECT_STATE(activity));
            return;
        }
Exemple #7
0
 public override void Enter(clsGroundAtom refGroundAtom)
 {
     refGroundAtom.currentRoute = RouteUtils.planStraightLineRoute(refActivityMovement.RouteActivity.Points.ElementAt(0),
                                                                   refActivityMovement.RouteActivity.Points.ElementAt(1),
                                                                   refActivityMovement.RouteActivity.RouteName);
     refGroundAtom.currentSpeed = refActivityMovement.Speed;
 }
Exemple #8
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            if (refGroundAtom.currentRoute == null) return;

            if (refGroundAtom.currentLeg > refGroundAtom.currentRoute.arr_legs.Count)  //-1)  // refActivityMovement.RouteActivity.Points.Count()-1)
            {
                // arrived to ground zero. Now search for casualties
                refActivityMovement.isEnded = true;
                refActivityMovement.isActive = false;
                refGroundAtom.currentRoute = null;

                DPoint groundZeroLocation = refGroundAtom.m_GameObject.getExplosionLocation();
                double groundZeroRadius = refGroundAtom.m_GameObject.getExplosionRadius();
                List<clsGroundAtom> atomsInGroundZero = refGroundAtom.m_GameObject.m_GameManager.QuadTreeGroundAtom.SearchEntities(groundZeroLocation.x, groundZeroLocation.y, groundZeroRadius, isPrecise: true);
                foreach (clsGroundAtom atom in atomsInGroundZero)
                {
                    if (atom.healthStatus.isDead || atom.healthStatus.isIncapacitated)
                    {
                        refGroundAtom.resetMovementData();
                        Route straightLine = RouteUtils.createRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y), new DPoint(atom.curr_X, atom.curr_Y));
                        clsActivityMovement extractionMovement = RouteUtils.createActivityAndStart(refGroundAtom, 5, straightLine);

                        refGroundAtom.ChangeState(new AMBULANCE_GO_TO_CASUALTY_STATE(extractionMovement, atom));

                        return;
                    }
                }

                return;
            }

            base.Execute(refGroundAtom);
        }
Exemple #9
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            // stop all activities if you're dead
            if (refGroundAtom.healthStatus.isDead)
            {
                refGroundAtom.isCollision = false;
                refGroundAtom.ChangeState(new DEAD_STATE());
                return;
            }
            // or incapacitated
            if (refGroundAtom.healthStatus.isIncapacitated)
            {
                refGroundAtom.isCollision = false;
                refGroundAtom.ChangeState(new INCAPACITATED_STATE());
                return;
            }

            // get next waypoint when the current waypoint is reached
            if (reachedTargetPosition(refGroundAtom))
            {
                targetPosition = CalculateNextWaypointPosition(refGroundAtom);
                return;
            }

            // perform step
            base.Execute(refGroundAtom);
        }
Exemple #10
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            // plan route to closest barrier
            Barrier closestBarrier = getClosestBarrier(refGroundAtom);
            //refGroundAtom.currentRoute = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
            //    new DPoint(closestBarrier.x, closestBarrier.y), "GoToBarrier");
            //refGroundAtom.currentRoute = await refGroundAtom.m_GameObject.m_GameManager.refTerrain.createRouteByShortestPathOnly(refGroundAtom.curr_X, refGroundAtom.curr_Y,
            //                             closestBarrier.x, closestBarrier.y);
            PointData closestRouteToBarrier = refGroundAtom.m_GameObject.lookForClosestRouteToBarrier(refGroundAtom, closestBarrier);
            typRoute  closestRoute          = closestRouteToBarrier.route;
            int       routeLength           = closestRoute.arr_legs.Count();

            refGroundAtom.resetMovementData();
            List <DPoint> routePoints = new List <DPoint>();

            routePoints.Add(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y));
            for (int i = closestRouteToBarrier.legNum; i < closestRoute.arr_legs.Count(); i++)
            {
                routePoints.Add(new DPoint(closestRoute.arr_legs[i].FromLongn, closestRoute.arr_legs[i].FromLatn));
            }

            // add last point
            routePoints.Add(new DPoint(closestRoute.arr_legs[routeLength - 1].ToLongn, closestRoute.arr_legs[routeLength - 1].ToLatn));
            typRoute routeFromAtom = RouteUtils.createTypRoute(routePoints, "GoToBarrier");

            refGroundAtom.currentRoute = routeFromAtom;
        }
Exemple #11
0
        // default event handler for incapacitation
        protected void incapacitationDefaultEventHandler(object sender, EventArgs e)
        {
            clsGroundAtom refGroundAtom = ((clsGroundAtomEventArgs)e).groundAtom;

            refGroundAtom.ChangeState(new INCAPACITATED_STATE());
            return;
        }
Exemple #12
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            typRoute route = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
                                                              new DPoint(triggerAtom.curr_X, triggerAtom.curr_Y), "help_other");

            refGroundAtom.currentRoute = route;
            refGroundAtom.resetMovementData();
        }
Exemple #13
0
        // create an activity, start it and return it
        public static clsActivityMovement createActivityAndStart(clsGroundAtom atom, double speed, Route route)
        {
            clsActivityMovement activity = createActivity(atom, speed, route);

            startActivity(activity);

            return(activity);
        }
Exemple #14
0
        public virtual void Enter(clsGroundAtom refGroundAtom)
        {
			// YD: register default event listeners
            refGroundAtom.earthquakeStartedEventHandler += earthquakeStartedDefaultEventHandler;
            refGroundAtom.earthquakeStartedEventHandler += earthquakeEndedDefaultEventHandler;
            refGroundAtom.forcesHaveArrivedEventHandler += forcesHaveArrivedDefaultEventHandler;
			// ---
        }
Exemple #15
0
 public virtual void Enter(clsGroundAtom refGroundAtom)
 {
     // YD: register default event listeners
     refGroundAtom.earthquakeStartedEventHandler += earthquakeStartedDefaultEventHandler;
     refGroundAtom.earthquakeEndedEventHandler   += earthquakeEndedDefaultEventHandler;
     refGroundAtom.forcesHaveArrivedEventHandler += forcesHaveArrivedDefaultEventHandler;
     // ---
 }
Exemple #16
0
        // YD: manage collisions like on sidewalk
        private void manageCollisions(clsGroundAtom refGroundAtom, TerrainService.Vector newPosition, out clsGroundAtom collidingAtom)
        {
            collidingAtom = null;
            List <CollisionTime> CollisionsToDelete = new List <CollisionTime>();

            foreach (var v in refGroundAtom.Collisions)
            {
                if ((refGroundAtom.m_GameObject.Ex_clockDate - v.time).TotalSeconds > 2)
                {
                    CollisionsToDelete.Add(v);
                }
            }
            foreach (var v in CollisionsToDelete)
            {
                refGroundAtom.Collisions.Remove(v);
            }

            refGroundAtom.isCollision = false;

            List <clsGroundAtom> colAtoms = refGroundAtom.m_GameObject.getQuadTreeByStructure(Structure).SearchEntities(newPosition.x, newPosition.y, refGroundAtom.collisionRadius, isPrecise: true);

            foreach (clsGroundAtom atom in colAtoms)
            {
                if (atom != refGroundAtom)
                {
                    TerrainService.Vector vDest = new TerrainService.Vector(newPosition.x, newPosition.y, 0);
                    TerrainService.Vector vMe   = new TerrainService.Vector(refGroundAtom.curr_X, refGroundAtom.curr_Y, 0);

                    TerrainService.Vector vCollision = new TerrainService.Vector(atom.curr_X, atom.curr_Y, 0);

                    TerrainService.Vector MyDirection = vDest - vMe;
                    MyDirection.normalize();
                    TerrainService.Vector CollisionDirection = vCollision - vMe;
                    CollisionDirection.normalize();
                    double dot = MyDirection * CollisionDirection;
                    if (dot >= 0.8)// 0.6)                                                  //Against  Main Direction
                    {
                        // if (atom.Collisions.Contains(refGroundAtom.MyName)) continue;

                        // Fix 03              if (atom.Collisions.Exists(v => v.name == refGroundAtom.MyName)) continue;
                        if (atom.Collisions.Exists(v => v.name == refGroundAtom.MyName))
                        {
                            continue;
                        }
                        //Fix 04 - New If
                        double d = TerrainService.MathEngine.CalcDistance(newPosition.x, newPosition.y, atom.curr_X, atom.curr_Y);
                        refGroundAtom.isCollision = true;
                        CollisionTime cTime = new CollisionTime();
                        cTime.name = atom.MyName;
                        cTime.time = refGroundAtom.m_GameObject.Ex_clockDate;
                        refGroundAtom.Collisions.Add(cTime);
                        collidingAtom = atom;
                        break;
                    }
                }
            }
        }
Exemple #17
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            // go towards trigger in a straight line
            typRoute route = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
                                                              new DPoint(triggerAtom.curr_X, triggerAtom.curr_Y), "curiosity");

            refGroundAtom.currentRoute = route;
            refGroundAtom.resetMovementData();
        }
Exemple #18
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            typRoute route = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
                                                              new DPoint(targetPosition.x, targetPosition.y), "go_away_from_building");

            refGroundAtom.currentRoute = route;
            refGroundAtom.resetMovementData();
            refGroundAtom.earthquakeEndedEventHandler += earthquakeEndedExitingEventHandler;
        }
Exemple #19
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
			// YD: subscribe to event handlers
            refGroundAtom.earthquakeStartedEventHandler += earthquakeStartedInStructureEventHandler;
            refGroundAtom.earthquakeEndedEventHandler += earthquakeEndedDefaultEventHandler;
            refGroundAtom.forcesHaveArrivedEventHandler += forcesHaveArrivedDefaultEventHandler;
            refGroundAtom.incapacitationEventHandler += incapacitationDefaultEventHandler;
            refGroundAtom.deathEventHandler += deathDefaultEventHandler;
            targetPosition = CalculateNextRandomPosition(5000, refGroundAtom.curr_X, refGroundAtom.curr_Y);
        }
Exemple #20
0
        // check if atom reached target position
        public bool reachedTargetPosition(clsGroundAtom refGroundAtom)
        {
            double DeltaTimeSec            = refGroundAtom.m_GameObject.m_GameManager.GroundCycleResolution * 0.001;
            double dist                    = (refGroundAtom.currentSpeed * DeltaTimeSec / 3600) * 1000;
            double distanceFromTarget      = TerrainService.MathEngine.CalcDistance(refGroundAtom.curr_X, refGroundAtom.curr_Y, targetPosition.x, targetPosition.y);
            double azimuthToTargetPosition = Util.Azimuth2Points(refGroundAtom.curr_X, refGroundAtom.curr_Y, targetPosition.x, targetPosition.y);
            double headingDifference       = Util.getAzimuthDifferenceDegrees(refGroundAtom.currentAzimuth, azimuthToTargetPosition);

            return((distanceFromTarget < WAYPOINT_TOLERANCE * dist) && (Math.Abs(headingDifference) < 90));
        }
Exemple #21
0
 public override void Enter(clsGroundAtom refGroundAtom)
 {
     // YD: subscribe to event handlers
     refGroundAtom.earthquakeStartedEventHandler += earthquakeStartedInStructureEventHandler;
     refGroundAtom.earthquakeEndedEventHandler   += earthquakeEndedInStructureEventHandler;
     refGroundAtom.forcesHaveArrivedEventHandler += forcesHaveArrivedInStructureEventHandler;
     refGroundAtom.incapacitationEventHandler    += incapacitationDefaultEventHandler;
     refGroundAtom.deathEventHandler             += deathDefaultEventHandler;
     targetPosition = CalculateNextRandomPosition(5000, refGroundAtom.curr_X, refGroundAtom.curr_Y);
 }
Exemple #22
0
 public override async void Enter(clsGroundAtom refGroundAtom)
 {
     //refGroundAtom.currentRoute = RoutePlanner.planStraightLineRoute(refActivityMovement.RouteActivity.Points.ElementAt(0),
     //                                        refActivityMovement.RouteActivity.Points.ElementAt(1),
     //                                        refActivityMovement.RouteActivity.RouteName);
     refGroundAtom.currentRoute = await refGroundAtom.m_GameObject.m_GameManager.refTerrain.createRouteByShortestPathOnly(refActivityMovement.RouteActivity.Points.ElementAt(0).x,
         refActivityMovement.RouteActivity.Points.ElementAt(0).y,
         refActivityMovement.RouteActivity.Points.ElementAt(1).x,
         refActivityMovement.RouteActivity.Points.ElementAt(1).y);
     refGroundAtom.currentSpeed = refActivityMovement.Speed;
 }
Exemple #23
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            if (refGroundAtom.currentLeg > refGroundAtom.currentRoute.arr_legs.Count)
            {
                refActivityMovement.isEnded  = true;
                refActivityMovement.isActive = false;
                return;
            }

            base.Execute(refGroundAtom);
        }
Exemple #24
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            // update route so that the destination will be the most similar atom
            refGroundAtom.currentRoute = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
                                                                          new DPoint(mostSimilarAtom.curr_X, mostSimilarAtom.curr_Y), "RouteToMostSimilar");

            // minimize differences
            SocialComparison.correctBehaviorToMostSimilar(refGroundAtom, mostSimilarAtom, m_baselineSpeed);

            // move
            base.Execute(refGroundAtom);
        }
Exemple #25
0
        public override async void Enter(clsGroundAtom refGroundAtom)
        {
            //refGroundAtom.currentRoute = RoutePlanner.planStraightLineRoute(refActivityMovement.RouteActivity.Points.ElementAt(0),
            //                                        refActivityMovement.RouteActivity.Points.ElementAt(1),
            //                                        refActivityMovement.RouteActivity.RouteName);
            refGroundAtom.currentRoute = await refGroundAtom.m_GameObject.m_GameManager.refTerrain.createRouteByShortestPathOnly(refActivityMovement.RouteActivity.Points.ElementAt(0).x,
                                                                                                                                 refActivityMovement.RouteActivity.Points.ElementAt(0).y,
                                                                                                                                 refActivityMovement.RouteActivity.Points.ElementAt(1).x,
                                                                                                                                 refActivityMovement.RouteActivity.Points.ElementAt(1).y);

            refGroundAtom.currentSpeed = refActivityMovement.Speed;
        }
Exemple #26
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            // continue evacuating only if there are people to evacuate
            DPoint groundZeroLocation = refGroundAtom.m_GameObject.getExplosionLocation();
            double groundZeroRadius   = refGroundAtom.m_GameObject.getExplosionRadius();

            if (refGroundAtom.currentLeg > refGroundAtom.currentRoute.arr_legs.Count)  //-1)  // refActivityMovement.RouteActivity.Points.Count()-1)
            {
                List <clsGroundAtom> atomsInGroundZero = refGroundAtom.m_GameObject.m_GameManager.QuadTreeGroundAtom.SearchEntities(groundZeroLocation.x, groundZeroLocation.y, groundZeroRadius, isPrecise: true);
                bool thereAreMoreCasualties            = false;

                foreach (clsGroundAtom atom in atomsInGroundZero)
                {
                    if (atom.healthStatus.isDead || atom.healthStatus.isIncapacitated)
                    {
                        thereAreMoreCasualties = true;
                        break;
                    }
                }

                if (!thereAreMoreCasualties)
                {
                    // if there are no more casualties in ground zero no need to go there.
                    refGroundAtom.ChangeState(new AMBULANCE_ADMINISTRATIVE_STATE());
                    return;
                }

                refActivityMovement.isEnded  = true;
                refActivityMovement.isActive = false;
                refGroundAtom.currentRoute   = null;

                refGroundAtom.knowsAboutEarthquake = true;

                DPoint ambulanceStartPoint = new DPoint(34.8514473088014, 32.1008536878526);
                refGroundAtom.curr_X = ambulanceStartPoint.x;
                refGroundAtom.curr_Y = ambulanceStartPoint.y;
                Route straightLine = RouteUtils.createRoute(new DPoint(ambulanceStartPoint.x, ambulanceStartPoint.y),
                                                            refGroundAtom.m_GameObject.getExplosionLocation());
                clsActivityMovement arrivalMovement = RouteUtils.createActivityAndStart(refGroundAtom, 80, straightLine);

                refGroundAtom.ChangeState(new AMBULANCE_ARRIVAL_MOVEMENT_STATE(arrivalMovement));

                return;
            }

            base.Execute(refGroundAtom);

            // take the evacuee with me
            refCasualty.curr_X = refGroundAtom.curr_X;
            refCasualty.curr_Y = refGroundAtom.curr_Y;
        }
Exemple #27
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            targetPosition.x = mostSimilar.curr_X;
            targetPosition.y = mostSimilar.curr_Y;

            // minimize differences
            SocialComparison.correctBehaviorToMostSimilar(refGroundAtom, mostSimilar, m_baselineSpeed);

            TerrainService.shPoint[] pnts = Structure.Points.ToArray();

            // if most similar leads to outside of structure do social comparison outside of structure
            bool mostSimilarExitedStructure = !TerrainService.GeometryHelper.GeometryMath.isPointInPolygon(mostSimilar.curr_X, mostSimilar.curr_Y, ref pnts);

            if (mostSimilarExitedStructure)
            {
                refGroundAtom.clearStageTransitionEventSubscriptions();
                refGroundAtom.earthquakeStartedEventHandler += earthquakeStartedDefaultEventHandler;
                refGroundAtom.earthquakeEndedEventHandler   += earthquakeEndedDefaultEventHandler;
                refGroundAtom.forcesHaveArrivedEventHandler += forcesHaveArrivedDefaultEventHandler;

                clsActivityMovement moveToMostSimilar = RouteUtils.createActivityAndStart(refGroundAtom, (int)refGroundAtom.currentSpeed, null);
                refGroundAtom.resetMovementData();

                refGroundAtom.ChangeState(new SOCIAL_COMPARISON_STATE(moveToMostSimilar, mostSimilar));

                // re-assign reevaluation handler. It should not be the same outside of a structure.
                switch (refGroundAtom.m_GameObject.simulationStage)
                {
                case GameObject.SimulationStage.STAGE_2:
                    refGroundAtom.reEvaluationEventHandler += reevaluationAfterEarthquakeStartedEventHandler;
                    break;

                case GameObject.SimulationStage.STAGE_3:
                    refGroundAtom.reEvaluationEventHandler += reevaluationAfterEarthquakeEndedEventHandler;
                    break;

                case GameObject.SimulationStage.STAGE_4:
                    refGroundAtom.reEvaluationEventHandler += reevaluationAfterForcesHaveArrivedEventHandler;
                    break;

                default:
                    refGroundAtom.reEvaluationEventHandler += null;
                    break;
                }

                return;
            }

            base.Execute(refGroundAtom);
        }
Exemple #28
0
        // YD: get next waypoint to go to in structure
        internal TerrainService.Vector CalculateNextWaypointPosition(clsGroundAtom refGroundAtom)
        {
            // next point is drawn randomly
            int             numOfWaypointNeighbors = refGroundAtom.currentStructureWaypoint.neighbors.Count();
            PolygonWaypoint nextWaypoint           = refGroundAtom.currentStructureWaypoint.neighbors[Util.random.Next(numOfWaypointNeighbors)];

            targetPosition   = new TerrainService.Vector();
            targetPosition.x = nextWaypoint.x;
            targetPosition.y = nextWaypoint.y;
            refGroundAtom.currentStructureWaypoint = nextWaypoint;
            refGroundAtom.currentAzimuth           = Util.Azimuth2Points(refGroundAtom.curr_X, refGroundAtom.curr_Y,
                                                                         nextWaypoint.x, nextWaypoint.y);
            return(targetPosition);
        }
Exemple #29
0
        protected void earthquakeEndedInStructureEventHandler(object sender, EventArgs e)
        {
            clsGroundAtom refGroundAtom = ((clsGroundAtomEventArgs)e).groundAtom;

            refGroundAtom.reEvaluationEventHandler += reevaluationAfterEarthquakeEndedInStructureEventHandler;

            if (moveToSocialComparisonStateInStructureIfShould(refGroundAtom))
            {
                return;
            }

            // exit the structure
            refGroundAtom.ChangeState(new EXIT_STRUCTURE_STATE(Structure));
        }
Exemple #30
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            if (!refGroundAtom.knowsAboutEarthquake && refGroundAtom.m_GameObject.earthquakeStarted())
            {
                refGroundAtom.knowsAboutEarthquake = true;

                refGroundAtom.resetMovementData();
                Route straightLine = RouteUtils.createRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y), refGroundAtom.m_GameObject.getExplosionLocation());
                clsActivityMovement arrivalMovement = RouteUtils.createActivityAndStart(refGroundAtom, 80, straightLine);

                refGroundAtom.ChangeState(new AMBULANCE_ARRIVAL_MOVEMENT_STATE(arrivalMovement));
                return;
            }
        }
Exemple #31
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            if (!refGroundAtom.knowsAboutEarthquake && refGroundAtom.m_GameObject.earthquakeStarted())
            {
                refGroundAtom.knowsAboutEarthquake = true;

                refGroundAtom.resetMovementData();
                Route straightLine = RouteUtils.createRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y), refGroundAtom.m_GameObject.getExplosionLocation());
                clsActivityMovement arrivalMovement = RouteUtils.createActivityAndStart(refGroundAtom, 80, straightLine);

                refGroundAtom.ChangeState(new AMBULANCE_ARRIVAL_MOVEMENT_STATE(arrivalMovement));
                return;
            }
        }
Exemple #32
0
        public async override void Enter(clsGroundAtom refGroundAtom)
        {
            refGroundAtom.currentSpeed = refActivityMovement.Speed;
            //  refGroundAtom.currentRoute = new typRoute(refActivityMovement.RouteActivity);

            // Yinon Douchan: Modified next line to plan route from route_x and route_y instead of curr_x and curr_y
            typRoute R = await refGroundAtom.m_GameObject.m_GameManager.refTerrain.CreateRoute(refGroundAtom.X_Route, refGroundAtom.Y_Route, refActivityMovement.ReferencePoint.x, refActivityMovement.ReferencePoint.y, refActivityMovement.RouteActivity.RouteGuid);

            // -----------------------------------------------------------------------------------
            refGroundAtom.currentRoute = R;


            // refGroundAtom.SetRoute(refActivityMovement.RouteActivity);
            base.Enter(refGroundAtom);
        }
Exemple #33
0
        protected void forcesHaveArrivedInStructureEventHandler(object sender, EventArgs e)
        {
            clsGroundAtom refGroundAtom = ((clsGroundAtomEventArgs)e).groundAtom;

            refGroundAtom.currentSpeed              = refGroundAtom.baselineSpeed;
            refGroundAtom.reEvaluationEventHandler += reevaluationAfterForcesHaveArrivedInStructureEventHandler;

            if (moveToSocialComparisonStateInStructureIfShould(refGroundAtom))
            {
                return;
            }

            // exit the structure
            refGroundAtom.ChangeState(new EXIT_STRUCTURE_STATE(Structure));
        }
Exemple #34
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            refGroundAtom.clearAllEventSubscriptions();
            refGroundAtom.earthquakeEndedEventHandler   += earthquakeEndedInStructureEventHandler;
            refGroundAtom.forcesHaveArrivedEventHandler += forcesHaveArrivedInStructureEventHandler;
            refGroundAtom.currentStructureWaypoint       = Structure.waypointGraph.findClosestWaypoint(refGroundAtom.curr_X, refGroundAtom.curr_Y);
            exitWaypoints = Structure.waypointGraph.findExitPath(refGroundAtom.currentStructureWaypoint);
            PolygonWaypoint exitWaypoint = exitWaypoints[exitWaypoints.Count() - 1];

            exitEdgeNumber   = exitWaypoint.edgeNum;
            targetPosition   = new TerrainService.Vector();
            targetPosition.x = exitWaypoints[waypointIndex].x;
            targetPosition.y = exitWaypoints[waypointIndex].y;
            waypointIndex++;
        }
Exemple #35
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            // move towards a grabable object and a safer place
            double randomDistance = Util.random.NextDouble() * 5;
            double randomAzimuth  = Util.random.NextDouble() * 360;

            double newX, newY;

            // calculate new point
            TerrainService.MathEngine.CalcProjectedLocationNew(refGroundAtom.curr_X, refGroundAtom.curr_Y, randomAzimuth, randomDistance, out newX, out newY);

            // make it the new route
            refGroundAtom.currentRoute = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
                                                                          new DPoint(newX, newY), "HoldOnToObject");
            refGroundAtom.resetMovementData();
        }
Exemple #36
0
        protected void reevaluationAfterEarthquakeEndedInStructureEventHandler(object sender, EventArgs e)
        {
            clsGroundAtom refGroundAtom = ((clsGroundAtomEventArgs)e).groundAtom;

            // check if stuck in mutual social comparison
            if (refGroundAtom.currentState.GetType() == typeof(SOCIAL_COMPARISON_IN_STRUCTURE_STATE))
            {
                SOCIAL_COMPARISON_IN_STRUCTURE_STATE sc = (SOCIAL_COMPARISON_IN_STRUCTURE_STATE)refGroundAtom.currentState;
                bool stuck = refGroundAtom.currentSpeed <= (float)sc.baselineSpeed / 5.0;
                if (stuck)
                {
                    // don't stay in social comparison if stuck. The building is going to fall apart!
                    refGroundAtom.ChangeState(new EXIT_STRUCTURE_STATE(Structure));
                }
            }
        }
Exemple #37
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            refGroundAtom.currentSpeed = refActivityMovement.Speed;
			
			// YD: randomly choose a route to follow
            typRoute R = refGroundAtom.m_GameObject.travelRoutes[refGroundAtom.currentStartWaypoint, refGroundAtom.currentEndWaypoint];
            refGroundAtom.currentRoute = R;
            refGroundAtom.currentRegularActivity = refActivityMovement;
			
			// YD: subscribe to event handlers
            refGroundAtom.earthquakeStartedEventHandler += earthquakeStartedDefaultEventHandler;
            refGroundAtom.earthquakeEndedEventHandler += earthquakeEndedDefaultEventHandler;
            refGroundAtom.forcesHaveArrivedEventHandler += forcesHaveArrivedDefaultEventHandler;
            refGroundAtom.deathEventHandler += deathDefaultEventHandler;
            refGroundAtom.incapacitationEventHandler += incapacitationDefaultEventHandler;
        }
Exemple #38
0
        // create an activity with default fields
        public static clsActivityMovement createActivity(clsGroundAtom atom, int speed, Route route)
        {
            clsActivityMovement activity = new clsActivityMovement();
            activity.ActivityId = 0;
            activity.AtomGuid = atom.GUID;
            activity.AtomName = atom.MyName;
            activity.DurationActivity = TimeSpan.FromSeconds(1);
            activity.TimeFrom = atom.m_GameObject.Ex_clockDate;
            activity.TimeTo = activity.TimeFrom.Add(TimeSpan.FromDays(365));
            activity.StartActivityOffset = TimeSpan.Zero;
            activity.Speed = speed;
            activity.ActivityType = enumActivity.MovementActivity;
            activity.RouteActivity = route;

            if (route != null && route.Points != null && route.Points.Count() > 0)
            {
                activity.ReferencePoint = new DPoint(route.Points.ElementAt(0).x, route.Points.ElementAt(0).y);
            }

            return activity;
        }
Exemple #39
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            // stop all activities if you're dead
            if (refGroundAtom.healthStatus.isDead)
            {
                refGroundAtom.isCollision = false;
                refGroundAtom.ChangeState(new DEAD_STATE());
                return;
            }
            // or incapacitated
            if (refGroundAtom.healthStatus.isIncapacitated)
            {
                refGroundAtom.isCollision = false;
                refGroundAtom.ChangeState(new INCAPACITATED_STATE());
                return;
            }

            if (refGroundAtom.currentRoute == null)
            {
                return;
            }

            // YD: go to a different direction when reached destination
            if (refGroundAtom.currentLeg > refGroundAtom.currentRoute.arr_legs.Count)
            {
                // destination waypoint is now the source waypoint
                refGroundAtom.currentStartWaypoint = refGroundAtom.currentEndWaypoint;
                int randomWaypoint = Util.random.Next(refGroundAtom.m_GameObject.travelRoutes.GetLength(1) - 1);
                if (randomWaypoint >= refGroundAtom.currentStartWaypoint) randomWaypoint++;

                refGroundAtom.currentEndWaypoint = randomWaypoint;
                refGroundAtom.currentLeg = 1;
                refGroundAtom.ChangeState(new REGULAR_MOVEMENT_STATE(refActivityMovement));
                return;
            }

            base.Execute(refGroundAtom);
        }
Exemple #40
0
        clsGroundAtom triggerAtom; // the atom that triggered this atom's curiosity

        public CURIOSITY_MOVEMENT_STATE(clsActivityMovement ActivityMovement, clsGroundAtom triggerAtom)
            : base(ActivityMovement)
        {
            refActivityMovement = ActivityMovement;
            this.triggerAtom = triggerAtom;
        }
Exemple #41
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
			// go towards trigger in a straight line
            typRoute route = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
                                                                  new DPoint(triggerAtom.curr_X, triggerAtom.curr_Y), "curiosity");
            refGroundAtom.currentRoute = route;
            refGroundAtom.resetMovementData();
        }
Exemple #42
0
        clsGroundAtom triggerAtom; // the atom that triggered this atom's will to help

        public HELP_OTHER_STATE(clsActivityMovement ActivityMovement, clsGroundAtom triggerAtom)
            : base(ActivityMovement)
        {
            refActivityMovement = ActivityMovement;
            this.triggerAtom = triggerAtom;
        }
Exemple #43
0
 public override void Enter(clsGroundAtom refGroundAtom)
 {
     typRoute route = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
                                                           new DPoint(triggerAtom.curr_X, triggerAtom.curr_Y), "help_other");
     refGroundAtom.currentRoute = route;
     refGroundAtom.resetMovementData();
 }
Exemple #44
0
 public override void Enter(clsGroundAtom refGroundAtom)
 {
     typRoute route = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
                                                           new DPoint(targetPosition.x, targetPosition.y), "go_away_from_building");
     refGroundAtom.currentRoute = route;
     refGroundAtom.resetMovementData();
     refGroundAtom.earthquakeEndedEventHandler += earthquakeEndedExitingEventHandler;
 }
Exemple #45
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            exitBuilding(refGroundAtom);

            base.Execute(refGroundAtom);

            // check if current waypoint has been reached
            double distanceFromWaypoint = TerrainService.MathEngine.CalcDistance(refGroundAtom.curr_X, refGroundAtom.curr_Y,
                                                    refGroundAtom.currentStructureWaypoint.x, refGroundAtom.currentStructureWaypoint.y);
            if (reachedTargetPosition(refGroundAtom) && waypointIndex < exitWaypoints.Count()) {
                refGroundAtom.currentStructureWaypoint = exitWaypoints[waypointIndex];
                targetPosition.x = exitWaypoints[waypointIndex].x;
                targetPosition.y = exitWaypoints[waypointIndex].y;
                refGroundAtom.currentAzimuth = Util.Azimuth2Points(refGroundAtom.curr_X, refGroundAtom.curr_Y,
                                                                   targetPosition.x, targetPosition.y);
                waypointIndex++;
            }
        }
Exemple #46
0
        private void exitBuilding(clsGroundAtom refGroundAtom)
        {
            double distanceToExit = TerrainService.MathEngine.CalcDistance(refGroundAtom.curr_X, refGroundAtom.curr_Y, targetPosition.x, targetPosition.y);
            double DeltaTimeSec = refGroundAtom.m_GameObject.m_GameManager.GroundCycleResolution * 0.001;
            double targetAzimuth = Util.Azimuth2Points(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, targetPosition.x, targetPosition.y);
            double stepDistanceInMeters = 1000 * (refGroundAtom.currentSpeed * DeltaTimeSec / 3600);

            TerrainService.Vector NewPosition = new TerrainService.Vector();
            TerrainService.MathEngine.CalcProjectedLocationNew(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, targetAzimuth, stepDistanceInMeters, out NewPosition.x, out NewPosition.y);
            TerrainService.GeometryHelper.Edge CrossedEdge = new TerrainService.GeometryHelper.Edge();
            TerrainService.shPoint[] Pnts = Structure.Points.ToArray();
            bool isCross = TerrainService.GeometryHelper.GeometryMath.isPolygonBorderCross(refGroundAtom.curr_X, refGroundAtom.curr_Y, NewPosition.x, NewPosition.y, ref Pnts, ref CrossedEdge);

            // reached exit - go away from building, you don't want it to fall on you
            if (isCross)
            {
                // calculate displacement vector
                TerrainService.Vector currentDirection = NewPosition - new TerrainService.Vector(refGroundAtom.curr_X, refGroundAtom.curr_Y, 0);

                // calculate edge vector
                TerrainService.Vector edgePointVector0 = new TerrainService.Vector(CrossedEdge.org.x, CrossedEdge.org.y, 0);
                TerrainService.Vector edgePointVector1 = new TerrainService.Vector(CrossedEdge.dest.x, CrossedEdge.dest.y, 0);
                TerrainService.Vector edgeVector = edgePointVector1 - edgePointVector0;

                // now calculate the perpendicular to the edge
                TerrainService.Vector projectionOnEdge = edgeVector * (currentDirection * edgeVector) / (edgeVector * edgeVector);
                TerrainService.Vector perpendicular = currentDirection - projectionOnEdge;

                // and normalize it
                perpendicular.normalize();

                // get the azimuth perpendicular to the edge
                double perpendicularAzimuth = Util.Azimuth2Points(0, 0, perpendicular.x, perpendicular.y) + Util.random.NextDouble() * 120 - 30;

                // distance to go away from building
                double distanceMeters = 15 * Util.random.NextDouble() + 10;

                TerrainService.Vector targetLocation = new TerrainService.Vector();
                TerrainService.MathEngine.CalcProjectedLocationNew(refGroundAtom.curr_X, refGroundAtom.curr_Y, perpendicularAzimuth, distanceMeters, out targetLocation.x, out targetLocation.y);

                clsActivityMovement goAwayActivity = RouteUtils.createActivityAndStart(refGroundAtom, (int)refGroundAtom.currentSpeed, null);
                refGroundAtom.ChangeState(new GO_AWAY_FROM_BUILDING_STATE(goAwayActivity, targetLocation, Structure, exitEdgeNumber));
                return;
            }
        }
Exemple #47
0
        private Barrier getClosestBarrier(clsGroundAtom refGroundAtom)
        {
            Barrier closest = null;
            double minDistance = Double.PositiveInfinity;

            foreach (Barrier barrier in refGroundAtom.m_GameObject.getPoliceBarrierCoordinates())
            {
                double distance = TerrainService.MathEngine.CalcDistance(refGroundAtom.curr_X, refGroundAtom.curr_Y, barrier.x, barrier.y);
                if (distance < minDistance) {
                    minDistance = distance;
                    closest = barrier;
                }
            }

            return closest;
        }
Exemple #48
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            if (refGroundAtom.currentRoute == null) return;

            if (refGroundAtom.currentLeg > refGroundAtom.currentRoute.arr_legs.Count)
            {
                refActivityMovement.isEnded = true;
                refActivityMovement.isActive = false;
                return;
            }

            base.Execute(refGroundAtom);
        }
Exemple #49
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            // plan route to closest barrier
            Barrier closestBarrier = getClosestBarrier(refGroundAtom);
            //refGroundAtom.currentRoute = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
            //    new DPoint(closestBarrier.x, closestBarrier.y), "GoToBarrier");
            //refGroundAtom.currentRoute = await refGroundAtom.m_GameObject.m_GameManager.refTerrain.createRouteByShortestPathOnly(refGroundAtom.curr_X, refGroundAtom.curr_Y,
            //                             closestBarrier.x, closestBarrier.y);
            PointData closestRouteToBarrier = refGroundAtom.m_GameObject.lookForClosestRouteToBarrier(refGroundAtom, closestBarrier);
            typRoute closestRoute = closestRouteToBarrier.route;
            int routeLength = closestRoute.arr_legs.Count();
            refGroundAtom.resetMovementData();
            List<DPoint> routePoints = new List<DPoint>();
            routePoints.Add(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y));
            for (int i = closestRouteToBarrier.legNum; i < closestRoute.arr_legs.Count(); i++)
            {
                routePoints.Add(new DPoint(closestRoute.arr_legs[i].FromLongn, closestRoute.arr_legs[i].FromLatn));
            }

            // add last point
            routePoints.Add(new DPoint(closestRoute.arr_legs[routeLength - 1].ToLongn, closestRoute.arr_legs[routeLength - 1].ToLatn));
            typRoute routeFromAtom = RouteUtils.createTypRoute(routePoints, "GoToBarrier");
            refGroundAtom.currentRoute = routeFromAtom;
        }
Exemple #50
0
        private int getClosestExitPoint(clsGroundAtom refGroundAtom, clsPolygon Structure)
        {
            DPoint[] coordinates = refGroundAtom.m_GameObject.getRegularMovementCoordinates();
            DPoint minPoint = null;
            int minIndex = 0;

            for (int i = 0; i < coordinates.Count(); i++)
            {
                DPoint coordinate = coordinates[i];
                if (minPoint == null || TerrainService.MathEngine.CalcDistance(refGroundAtom.curr_X, refGroundAtom.curr_Y, coordinate.x, coordinate.y) <
                                      TerrainService.MathEngine.CalcDistance(refGroundAtom.curr_X, refGroundAtom.curr_Y, minPoint.x, minPoint.y))
                {
                    minPoint = coordinate;
                    minIndex = i;
                }
            }

            return minIndex;
        }
Exemple #51
0
        private void goToRegularMovement(clsGroundAtom refGroundAtom)
        {
            clsActivityMovement backToNormal = RouteUtils.createActivityAndStart(refGroundAtom, (int)refGroundAtom.currentSpeed, null);
            clsPolygonOpeningEscapePoint escapePoint = Structure.EscapePoints[exitEdgeNumber];

            PointData closestPoint = refGroundAtom.m_GameObject.lookForClosestRegularRoute(refGroundAtom);
            Route route = RouteUtils.typRouteToRoute(closestPoint.route);
            List<DPoint> trimmedRoutePoints = new List<DPoint>();
            for (int i = closestPoint.legNum; i < route.Points.Count(); i++)
                trimmedRoutePoints.Add(route.Points.ElementAt(i));
            route.Points = trimmedRoutePoints;
            refGroundAtom.currentStartWaypoint = closestPoint.routeIndex1;
            refGroundAtom.currentEndWaypoint = closestPoint.routeIndex2;
            refGroundAtom.resetMovementData();
            refGroundAtom.ChangeState(new GET_ON_SIDEWALK(backToNormal, new DPoint(escapePoint.x, escapePoint.y), route));
        }
Exemple #52
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            if (refGroundAtom.currentLeg > refGroundAtom.currentRoute.arr_legs.Count)
            {
                refActivityMovement.isEnded = true;
                refActivityMovement.isActive = false;

                if (refGroundAtom.m_GameObject.earthquakeEnded())
                {
                    List<clsGroundAtom> atomsNearby = refGroundAtom.m_GameObject.m_GameManager.QuadTreeGroundAtom.SearchEntities(refGroundAtom.curr_X, refGroundAtom.curr_Y, 50, isPrecise: true);
                    List<clsGroundAtom> casualtiesNearby = new List<clsGroundAtom>();
                    // should the atom be curious?
                    foreach (clsGroundAtom atom in atomsNearby)
                    {
                        if (atom.healthStatus.isIncapacitated || atom.healthStatus.isDead)
                        {
                            casualtiesNearby.Add(atom);
                        }
                    }

                    // decide whether to flock towards casualties
                    if (casualtiesNearby.Count() > 0)
                    {
                        double randomAction = Util.random.NextDouble();
                        int randomCasualty = Util.random.Next(casualtiesNearby.Count());
                        clsActivityMovement curiousityActivity = RouteUtils.createActivityAndStart(refGroundAtom, (int)refGroundAtom.currentSpeed, null);

                        if (randomAction < 0.3)
                        {
                            refGroundAtom.ChangeState(new CURIOSITY_MOVEMENT_STATE(curiousityActivity, casualtiesNearby[randomCasualty]));
                        }
                        else if (randomAction >= 0.3 && randomAction < 0.8)
                        {
                            refGroundAtom.ChangeState(new HELP_OTHER_STATE(curiousityActivity, casualtiesNearby[randomCasualty]));
                        }
                        else
                        {
                            goToRegularMovement(refGroundAtom);
                        }
                    }
                    else
                    {
                        goToRegularMovement(refGroundAtom);
                    }
                }

                return;
            }

            base.Execute(refGroundAtom);
        }
Exemple #53
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            // move towards a grabable object and a safer place
            double randomDistance = Util.random.NextDouble() * 5;
            double randomAzimuth = Util.random.NextDouble() * 360;

            double newX, newY;
            // calculate new point
            TerrainService.MathEngine.CalcProjectedLocationNew(refGroundAtom.curr_X, refGroundAtom.curr_Y, randomAzimuth, randomDistance, out newX, out newY);

            // make it the new route
            refGroundAtom.currentRoute = RouteUtils.planStraightLineRoute(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y),
                                                                            new DPoint(newX, newY), "HoldOnToObject");
            refGroundAtom.resetMovementData();
        }
Exemple #54
0
        public override void Enter(clsGroundAtom refGroundAtom)
        {
            if (routeFromPoint == null)
            {
                // only go to sidewalk
                DPoint source = new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y);
                DPoint dest = new DPoint(pointOnSidewalk.x, pointOnSidewalk.y);
                refGroundAtom.currentRoute = RouteUtils.planStraightLineRoute(source, dest, "GetOnSidewalk_" + refGroundAtom.MyName);
            }
            else
            {
                // go to sidewalk and then to a route from that sidewalk given at routeFromPoint
                List<DPoint> points = new List<DPoint>();
                points.Add(new DPoint(refGroundAtom.curr_X, refGroundAtom.curr_Y));
                points.Add(new DPoint(pointOnSidewalk.x, pointOnSidewalk.y));

                // add all points except first which is the point on the sidewalk
                for (int i = 0; i < routeFromPoint.Points.Count(); i++)
                {
                    points.Add(routeFromPoint.Points.ElementAt(i)); ;
                }

                refGroundAtom.currentRoute = RouteUtils.createTypRoute(points, "GetOnSidewalk_" + refGroundAtom.MyName);
            }
        }
Exemple #55
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            // go to a different direction
            if (refGroundAtom.currentLeg > refGroundAtom.currentRoute.arr_legs.Count)
            {
                if (routeFromPoint == null)
                {
                    refGroundAtom.ChangeState(new ADMINISTRATIVE_STATE());
                    return;
                }

                // destination waypoint is now the source waypoint
                refGroundAtom.currentStartWaypoint = refGroundAtom.currentEndWaypoint;
                int randomWaypoint = Util.random.Next(refGroundAtom.m_GameObject.travelRoutes.GetLength(1) - 1);
                if (randomWaypoint >= refGroundAtom.currentStartWaypoint) randomWaypoint++;

                refGroundAtom.currentEndWaypoint = randomWaypoint;
                refGroundAtom.currentLeg = 1;
                refGroundAtom.ChangeState(new REGULAR_MOVEMENT_STATE(refActivityMovement));
                return;
            }

            base.Execute(refGroundAtom);
        }
Exemple #56
0
 public override void Enter(clsGroundAtom refGroundAtom)
 {
     base.Enter(refGroundAtom);
     refGroundAtom.clearAllEventSubscriptions();
 }
Exemple #57
0
        private void MoveInStructure(clsGroundAtom refGroundAtom,int DeltaTime)
        {
            double DeltaTimeSec = DeltaTime * 0.001;
            double dist = refGroundAtom.currentSpeed * DeltaTimeSec / 3600;

            double oldX = refGroundAtom.curr_X;
            double oldY = refGroundAtom.curr_Y;

            // YD - fixed bug where atoms in building travel way to fast than they should be.
            // Details: In the third line below addition of distance in meters to position in coordinates!
            //TerrainService.Vector vt = targetPosition - refGroundAtom.currPosition;
            //vt.normalize();
            //TerrainService.Vector NewPosition = refGroundAtom.currPosition + (vt * dist); 
            ////.........

            TerrainService.Vector vt = targetPosition - refGroundAtom.currPosition;
            double targetDist = TerrainService.MathEngine.CalcDistance(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, targetPosition.x, targetPosition.y);
            double targetAzimuth = Util.Azimuth2Points(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, targetPosition.x, targetPosition.y);
            TerrainService.Vector NewPosition = new TerrainService.Vector();
            TerrainService.MathEngine.CalcProjectedLocationNew(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, targetAzimuth, 1000 * dist, out NewPosition.x, out NewPosition.y);
            // ----------------------------------------------------------------------------------------

            // check if in collision
            clsGroundAtom collidingAtom = null;
            manageCollisions(refGroundAtom, NewPosition, out collidingAtom);

            TerrainService.GeometryHelper.Edge CrossedEdge = new TerrainService.GeometryHelper.Edge();
            TerrainService.shPoint[] Pnts = Structure.Points.ToArray();
            // step aside in case of collision
            if (!refGroundAtom.isCollision)
            {
                // draw avoidance side randomly to when collision will occur
                int random = Util.random.Next(2) * 2 - 1;
                refGroundAtom.Offset_Azimuth = 90 * random;
            }
            if (refGroundAtom.isCollision)
            {
				// choose side to step to according to social comparison theory
                clsGroundAtom mostSimilar = SocialComparison.findMostSimilarInStructure(refGroundAtom, Structure);

                if (mostSimilar != null)
                {
                    TerrainService.Vector headingVector = new TerrainService.Vector();
                    headingVector.x = targetPosition.x - refGroundAtom.curr_X;
                    headingVector.y = targetPosition.y - refGroundAtom.curr_Y;
                    TerrainService.Vector vectorToMostSimilar = new TerrainService.Vector();
                    vectorToMostSimilar.x = mostSimilar.curr_X - refGroundAtom.curr_X;
                    vectorToMostSimilar.y = mostSimilar.curr_Y - refGroundAtom.curr_Y;
                    bool mostSimilarIsToTheLeft = (headingVector ^ vectorToMostSimilar).norm() > 0;
                    if (mostSimilarIsToTheLeft) refGroundAtom.Offset_Azimuth = 90;
                    else refGroundAtom.Offset_Azimuth = -90;
                }

                List<CollisionTime> collisions = refGroundAtom.Collisions;
                double azimuthToCollidingAtom = Util.Azimuth2Points(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, collidingAtom.currPosition.x, collidingAtom.currPosition.y);
                TerrainService.MathEngine.CalcProjectedLocationNew(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, azimuthToCollidingAtom + refGroundAtom.Offset_Azimuth, 1000 * dist, out NewPosition.x, out NewPosition.y);
            }

            bool isCross = TerrainService.GeometryHelper.GeometryMath.isPolygonBorderCross(refGroundAtom.curr_X, refGroundAtom.curr_Y, NewPosition.x, NewPosition.y, ref Pnts, ref CrossedEdge);
            if (isCross)
            {
               CrossedEdge.rot90();
               TerrainService.Vector orig = new TerrainService.Vector(CrossedEdge.org.x, CrossedEdge.org.y,0);
               TerrainService.Vector dest = new TerrainService.Vector(CrossedEdge.dest.x, CrossedEdge.dest.y, 0);
               TerrainService.Vector n = dest - orig;
               
                n.normalize();

            

               TerrainService.Vector NewD = vt - 2 * (vt * n) * n;
               NewD.normalize();
            
               TerrainService.Vector NewDirect = NewD * 5000;

         
		 		// YD: calculate new target position according to next waypoint and not randomly
                //targetPosition = NewDirect;
               targetPosition = CalculateNextWaypointPosition(refGroundAtom);
			   // ---

                // YD: Bug fix for moving too fast in buildings
                //vt = targetPosition - refGroundAtom.currPosition;
                //vt.normalize();
                //NewPosition = refGroundAtom.currPosition + (vt * dist);

                vt = targetPosition - refGroundAtom.currPosition;
                targetDist = TerrainService.MathEngine.CalcDistance(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, targetPosition.x, targetPosition.y) / 1000;
                targetAzimuth = Util.Azimuth2Points(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, targetPosition.x, targetPosition.y);
                TerrainService.MathEngine.CalcProjectedLocationNew(refGroundAtom.currPosition.x, refGroundAtom.currPosition.y, targetAzimuth, 1000 * dist, out NewPosition.x, out NewPosition.y);
                // ---------------------------------------------------------------------------------

                //refGroundAtom.currPosition = NewPosition;
                //refGroundAtom.curr_X = refGroundAtom.currPosition.x;
                //refGroundAtom.curr_Y = refGroundAtom.currPosition.y;

               // return;
            }
          

            refGroundAtom.currPosition = NewPosition;
			// YD: get current azimuth
            refGroundAtom.currentAzimuth = Util.Azimuth2Points(refGroundAtom.curr_X, refGroundAtom.curr_Y, NewPosition.x, NewPosition.y);
            refGroundAtom.curr_X = refGroundAtom.currPosition.x;
            refGroundAtom.curr_Y = refGroundAtom.currPosition.y;



            bool isIn = TerrainService.GeometryHelper.GeometryMath.isPointInPolygon(refGroundAtom.curr_X, refGroundAtom.curr_Y, ref Pnts);
            if (isIn == false)
            {
                System.Random Rnd = new Random();
                while (true)
                {
                    double vRnd = Rnd.NextDouble();
                    double randX = Structure.minX + (Structure.maxX - Structure.minX) * vRnd;
                    vRnd = Rnd.NextDouble();
                    double randY = Structure.minY + (Structure.maxY - Structure.minY) * vRnd;
                    bool inPolygon = TerrainService.GeometryHelper.GeometryMath.isPointInPolygon(randX, randY, ref  Pnts);
                    if (inPolygon == true)
                    {
                        refGroundAtom.curr_X = randX;
                        refGroundAtom.curr_Y = randY;
                        refGroundAtom.currPosition = new TerrainService.Vector(randX, randY, 0);
						// YD: calculate new target position according to next waypoint and not randomly
                        //targetPosition = CalculateNextRandomPosition(5000, refGroundAtom.curr_X, refGroundAtom.curr_Y);
                        targetPosition = CalculateNextWaypointPosition(refGroundAtom);
						// ---
                        break;
                    }
                }
            }

			// YD: since there are more than once structure, update possition according to the right structure's quadtree
            refGroundAtom.m_GameObject.getQuadTreeByStructure(Structure).PositionUpdate(refGroundAtom);
            
        }
Exemple #58
0
 public override void Execute(clsGroundAtom refGroundAtom)
 {
     // For now, do nothing. You're dead.
 }
Exemple #59
0
        public override void Execute(clsGroundAtom refGroundAtom)
        {
            if (refGroundAtom.m_GameObject.earthquakeEnded())
            {
                if (!earthquakeEnded)
                {
                    earthquakeEnded = true;
                    earthquakeEndedClockTime = refGroundAtom.m_GameObject.Ex_clockDate;
                }
            }

            if (refGroundAtom.currentLeg > refGroundAtom.currentRoute.arr_legs.Count)
            {
                refActivityMovement.isEnded = true;
                refActivityMovement.isActive = false;
                return;
            }
            base.Execute(refGroundAtom);
        }
Exemple #60
0
 public override void Execute(clsGroundAtom refGroundAtom)
 {
     // For now, do nothing. You're incapacitated but hey, you're still alive! Maybe call for help?
 }