Example #1
0
File: Person.cs Project: nohros/eva
        void MoveRandomly()
        {
            Region      region      = location_.Region;
            Surrounding surrounding = region.GetSurrounding(location_.Index);

            // Lets check if the room has any door, if don't, there is no reason
            // to move to anywhere.
            Rect[] doors = region.GetDoors().ToArray();
            if (doors.Length == 0)
            {
                return;
            }

            // Since we do not know the door direction, we should move randonmly to
            // a surrounding rect that is empty.
            Occupation[] occupations       = surrounding.ToArray();
            var          empty_occupations = new List <Occupation>();

            foreach (Occupation occupation in occupations)
            {
                if (occupation != null)
                {
                    if (occupation.Person == null)
                    {
                        empty_occupations.Add(occupation);
                    }
                    else if (occupation.Person != null)
                    {
                        // If there is someone close to us we can learn the exit
                        // path from it.
                        know_exits_ = occupation.Person.KnowExit;
                    }
                }
            }

            Move(region, empty_occupations);
        }
Example #2
0
File: Person.cs Project: nohros/eva
        void MoveToDoor()
        {
            Region      region      = location_.Region;
            Surrounding surrounding = region.GetSurrounding(location_.Index);

            Rect[] doors = region.GetDoors().ToArray();

            var empty_occupations = new List <Occupation>();

            // If the room has no doors there is not place to go
            if (doors.Length == 0)
            {
                return;
            }

            Rect door    = doors[0];
            Rect my_rect = region.GetRectByIndex(location_.Index);

            Occupation occupation;

            if (my_rect.IsOnRow(door))
            {
                // If we are in the same row as the door, we should move only to left
                // or right, if we are on the left side we should move to the right, if
                // we are on the right side of the door we should move to the left.
                occupation =
                    my_rect.IsOnLeft(door)
            ? surrounding.OnRight
            : surrounding.OnLeft;
                if (occupation != null)
                {
                    empty_occupations.Add(occupation);
                }
            }
            else if (my_rect.IsOnColumn(door))
            {
                // Here we know that we are not in the same row as the door, lets check
                // if we are in the same column
                occupation =
                    my_rect.IsBelow(door)
            ? surrounding.OnTop
            : surrounding.OnBottom;
                if (occupation != null)
                {
                    empty_occupations.Add(occupation);
                }
            }
            else
            {
                // We are not in the same row and not in the same column as the
                // door, we can be below or above, in any condition we can move
                // left or right...
                occupation =
                    my_rect.IsOnLeft(door)
            ? surrounding.OnRight
            : surrounding.OnLeft;
                if (occupation != null)
                {
                    empty_occupations.Add(occupation);
                }

                // ... and up or down.
                occupation =
                    my_rect.IsBelow(door)
            ? surrounding.OnTop
            : surrounding.OnBottom;
                if (occupation != null)
                {
                    empty_occupations.Add(occupation);
                }
            }

            Move(region, empty_occupations);
        }