Beispiel #1
0
        /// <summary>
        /// Path creating and setting first location
        /// Lobby tells cleaner that there is a place to clean so based on that cleaner will get a destination to walk to and to clean
        /// </summary>
        /// <param name="destination"></param>
        /// <returns></returns>
        public List <Node> CreateGraph(LocationType destination)
        {
            Destination = destination;
            // Cleaner creates his path andreturns it
            Graph.Graph graph = new Graph.Graph();
            Path = graph.CreateNodeGraph(Location.LocationType, Destination, PathFinding, CurrentEvent.EventType);

            // if visitor changes his mind, he's steps will be reset. Step 0 is his location where he stands on, we don't want him to walk to that place
            NextStep = 1;
            return(Path);
        }
        /// <summary>
        /// the path we want the visitor to follow
        /// </summary>
        public void PathToLocationType()
        {
            if (StatusHuman != StatusHuman.WAITING || StatusHuman == StatusHuman.WAITING && CurrentEvent.EventType == HotelEventType.EVACUATE)
            {
                // We want visitor to be alive when creating a path
                if (Alive == true)
                {
                    // To set the first location
                    if (this.Location.LocationType == null)
                    {
                        foreach (var facility in PathFinding.facilities)
                        {
                            if (facility.Position.X * facility.oneDimensionSize.Width == this.Xpos && facility.Position.Y * facility.oneDimensionSize.Height == this.Ypos)
                            {
                                this.Location.SetLocationType(facility);
                            }
                        }
                    }

                    // When visitor his location is his room, he has to interact to leave it
                    if (this.Location.LocationType == this.Room)
                    {
                        this.Location.LocationType.Interact(this);
                    }

                    // If the visitor it's status is not evacuate we make a path to his wanted destination, or else he will keep walking to the destination of the evacuation
                    if (StatusHuman != StatusHuman.EVACUATE)
                    {
                        // We make a list pf paths we can later on choose which path is the fastest to walk
                        List <List <Node> > pathList = new List <List <Node> >();
                        // if visitor is in room > go to facility
                        // if firststep is true > to to facility
                        // if location is not destination && not room > go to facility
                        // if location is destination && current event is not none > go to facility
                        // if current event is evacuate > go to facility
                        // if (this.Location.LocationType == this.Room || CurrentEvent.EventType == HotelEventType.CHECK_IN || this.Location.LocationType != this.Destination && this.Location.LocationType != this.Room || this.Location.LocationType == Destination && CurrentEvent.EventType != HotelEventType.NONE || CurrentEvent.EventType == HotelEventType.EVACUATE)

                        if (CurrentEvent.EventType != HotelEventType.NONE)
                        {
                            // based on the current event we return a facility
                            foreach (var item in SearchFacility(CurrentEvent.EventType))
                            {
                                // create a new graph
                                Graph.Graph graph = new Graph.Graph();
                                // add those pahts to the multi Dimensional list
                                pathList.Add(graph.CreateNodeGraph(Location.LocationType, item, PathFinding, CurrentEvent.EventType));
                            }
                            // get the fastest path
                            TakeClosestFacility(pathList);
                        }
                        else
                        {
                            Graph.Graph graph = new Graph.Graph();
                            Path = graph.CreateNodeGraph(Location.LocationType, this.Room, PathFinding, CurrentEvent.EventType);
                        }
                        // We use this to determin if visitor is on his destination
                        Destination = Path.Last().LocationType;

                        LocationType firstElement = Path.First().LocationType;
                        if (firstElement is ElevatorShaft && CurrentEvent.EventType != HotelEventType.EVACUATE)
                        {
                            NextStep = 0;
                        }
                        else
                        {
                            // if visitor changes his mind, he's steps will be reset. Step 0 is his location where he stands on, we don't want him to walk to that place
                            NextStep = 1;
                        }

                        // Here we let the visitor walk again
                        SetWalkingStatus();
                    }
                }
            }
        }