Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        // init
        wallMap              = GameObject.Find("Stage").GetComponent <WallMap>();
        smokeMap             = GameObject.Find("Smoke").GetComponent <SmokeBehavier>();
        padding              = 10;
        minObserveDistance   = 3.0f;
        accumulatedDeltaTime = 0;
        updateFPS            = 30;

        Precision       = WallMap.Precision;
        PrototypePerson = GameObject.Find("Prototype Person");
        CrowdingArea    = new Vector2[Random.Range(3, 8)];
        Crowds          = new List <Person>();
        // find crowding area

        for (int i = 0; i < CrowdingArea.Length; i++)
        {
            int ca_x = 0, ca_y = 0;
            while (wallMap.IsWall[ca_x, ca_y] || ca_x <= 0)
            {
                ca_x = Random.Range(padding, Precision - padding);
                ca_y = Random.Range(padding, Precision - padding);
            }
            CrowdingArea[i] = new Vector2(ca_x, ca_x);
            // spread people around crowding area
            int crowndNum = 4 + Random.Range(-2, 6);
            for (int n = 0; n < crowndNum; n++)
            {
                float randx = 0, randy = 0;
                while (wallMap.IsWall[(int)(randx + 0.5), (int)(randy + 0.5)] || randx <= 0)
                {
                    randx = Mathf.Clamp(ca_x + Random.value * 10, 0, Precision - 1);
                    randy = Mathf.Clamp(ca_y + Random.value * 10, 0, Precision - 1);
                }
                Vector3 pos = wallMap.PixelToWorldCoord(randx, randy) + Vector3.up;
                Crowds.Add(new Person(Instantiate(PrototypePerson, pos, Quaternion.identity)));
            }
        }
    }
Beispiel #2
0
 void UpdateInformation()
 {
     for (int n = 0; n < Crowds.Count; n++)
     {
         bool memoryAdded = false;
         // Observe
         // check if can see Fire
         for (int x = 0; x < Precision; ++x)
         {
             for (int y = 0; y < Precision; ++y)
             {
                 if (smokeMap.Fires[x, y] == 1.0f)
                 {
                     Vector3 from = Crowds[n].objT.localPosition;
                     from.y = 0;
                     Vector3 to = wallMap.PixelToWorldCoord(x, y);
                     if (Vector3.Distance(from, to) < minObserveDistance)
                     {
                         //Debug.Log("Fire check:" + from + to);
                         if (!Physics.Linecast(from, to))
                         {
                             Crowds[n].Memory.Add(new Information(EventEnum.Fire, to - from));
                             x           = Precision;
                             memoryAdded = true;
                             break;
                         }
                     }
                 }
             }
         }
         if (memoryAdded)
         {
             break;
         }
         // check if Smoke is arround
         Vector2 pixel = wallMap.WorldCoordToPixel(Crowds[n].objT.localPosition);
         int     px    = (int)pixel.x;
         int     py    = (int)pixel.y;
         for (int dx = -1; dx <= 1; ++dx)
         {
             for (int dy = -1; dy <= 1; ++dy)
             {
                 if (px + dx >= 0 && py + dy >= 0 && px + dx < Precision && py + dy < Precision)
                 {
                     if (smokeMap.SmokeDensity[px + dx, py + dy] > 0.1f)
                     {
                         Vector3 to = wallMap.PixelToWorldCoord(px + dx, py + dy);
                         Crowds[n].Memory.Add(new Information(EventEnum.Smoke, to - Crowds[n].objT.localPosition));
                         dx          = 1;
                         memoryAdded = true;
                         break;
                     }
                 }
             }
         }
         if (memoryAdded)
         {
             break;
         }
         // Try receive Alarm: if there are panic or escaping people around, it receive Alarm
         for (int m = 0; m < Crowds.Count; m++)
         {
             if (n != m)
             {
                 if (Crowds[m].State == PersonBehaviour.Escape || Crowds[m].State == PersonBehaviour.Panic)
                 {
                     Vector3 from = Crowds[m].objT.localPosition;
                     Vector3 to   = Crowds[n].objT.localPosition;
                     if (!Physics.Linecast(from, to))
                     {
                         if (Vector3.Distance(from, to) < minObserveDistance)
                         {
                             Crowds[n].Memory.Add(new Information(EventEnum.Alarm, to - from));
                             m           = Crowds.Count;
                             memoryAdded = true;
                             break;
                         }
                     }
                 }
             }
         }
         if (memoryAdded)
         {
             break;
         }
         if (Crowds[n].State == PersonBehaviour.Social)
         {
             Crowds[n].Memory.Add(new Information(EventEnum.Social));
         }
         else
         {
             Crowds[n].Memory.Add(new Information(EventEnum.None));
         }
     }
 }