Пример #1
0
 public void CivilianWasMoved(CivilianMovement c)
 {
     if (endangeredCivilians != null && endangeredCivilians.ContainsKey(c))
     {
         endangeredCivilians[c] = true;
     }
 }
Пример #2
0
 public void UpdateEndangeredCiviliansDragStates(CivilianMovement c)
 {
     // indicate to all of the cars that a civilian that might be in their list of endangereds was moved.
     foreach (CarMovement car in Cars)
     {
         car.CivilianWasMoved(c);
     }
 }
Пример #3
0
        //method to remove a civilian
        public void RemoveCivilian(CivilianMovement thisCivilian, bool replace = true)
        {
            civilianList.Remove(thisCivilian);

            Destroy(thisCivilian.gameObject);

            if (replace)
            {
                SpawnCivilian();
            }
        }
Пример #4
0
        //method to scan nearby area
        void ScanNearby()
        {
            //empty neigbor list to prevent overlap
            neighborList.Clear();

            //scan nearby area for rigidbodies
            RaycastHit2D[] results = Physics2D.CircleCastAll(
                new Vector2(position.x, position.y),
                neighborRange,
                Vector2.zero);

            //values for finding nearest waypoints
            WayPoint nearestWaypoint = null;
            float    nearestDistSqr  = float.PositiveInfinity;

            //loop through nearby rigidbodies
            for (int i = 0; i < results.Length; i++)
            {
                //this specific rigidbody
                GameObject thisHit = results[i].collider.gameObject;

                //find relevant components
                CivilianMovement thisCiv      = thisHit.GetComponent <CivilianMovement>();
                WayPoint         thisWaypoint = thisHit.GetComponent <WayPoint>();

                if (thisCiv != null)
                {
                    //if this is a civilian, add it to the neighbor list
                    neighborList.Add(thisCiv);
                }
                else if (thisWaypoint != null && thisWaypoint != prevWaypoint && nextWaypoint == null)
                {
                    //if this is a waypoint and NOT the previous waypoint, check if it's the nearest

                    //find distance to waypoint
                    float thisDistSqr = CalcDistSqr(thisWaypoint.transform.position);

                    //check if it's closer than the previous one
                    if (thisDistSqr < nearestDistSqr)
                    {
                        //make this one the closest
                        nearestWaypoint = thisWaypoint;
                        nearestDistSqr  = thisDistSqr;
                    }
                }
            }

            //if a closer waypoint was found, go to that one
            if (nearestWaypoint != null && nextWaypoint == null)
            {
                prevWaypoint = nextWaypoint;
                nextWaypoint = nearestWaypoint;
            }
        }
Пример #5
0
        //method to spawn a single civilian
        public void SpawnCivilian()
        {
            CivilianMovement civ = Instantiate(civilianPrefab, civilianParent).GetComponent <CivilianMovement>();

            WayPoint startPoint = spawnPoints[Random.Range(0, spawnPoints.Count)];

            civ.transform.position = startPoint.transform.position;

            civ.nextWaypoint = startPoint.GetNextWaypoint();
            civ.prevWaypoint = civ.nextWaypoint;

            civilianList.Add(civ);
        }
Пример #6
0
        void UpdatePotentialCivilianCollisions()
        {
            // Make a list of all the civilians in this car's path.
            RaycastHit2D[] hits = Physics2D.CircleCastAll(transform.position, killRadius, direction * 200f);

            foreach (RaycastHit2D hit in hits)
            {
                CivilianMovement c = hit.collider.GetComponent <CivilianMovement>();

                if (c == null)
                {
                    continue;
                }

                if (!endangeredCivilians.ContainsKey(c))
                {
                    endangeredCivilians.Add(c, false);
                }
            }
        }