Example #1
0
    /// <summary>
    /// Based on the next DesireType, selects a RoomObject that will address that Desire
    /// </summary>
    /// <param name="selectNewDesire">True if you want to select a new desire type to address.
    ///                               False to use last desire type</param>
    private void startMakeNextPath(bool selectNewDesire = true)
    {
        //call this first to start clean up old path info before making new one
        clearPathfindingData();

        //Get next desire type to address
        if (selectNewDesire || nextDesireType == DesireType.none)
        {
            nextDesireType = getDesireTypeToAddress();
        }

        //Get objects that can address this desire type
        objectsToTarget = getRoomObjectsToTarget(nextDesireType);

        //Get the rooms that house those objects
        List <Room> roomsToTarget = RoomObject.GetRoomsOfRoomObjects(objectsToTarget);
        Room        currentRoom   = roomMan.GetRoomWithPoint(Controls.GetPosAsVector3Int(transform));

        //If we are already in one of the rooms with those objects, remove them from the room list,
        //and add the object to the object list
        List <RoomObject> objectsToTargetInCurrentRoom = new List <RoomObject>();

        if (currentRoom != null && roomsToTarget.Contains(currentRoom))
        {
            roomsToTarget.Remove(currentRoom);
            foreach (RoomObject obj in objectsToTarget)
            {
                if (obj.GetRoom() == currentRoom)
                {
                    objectsToTargetInCurrentRoom.Add(obj);
                }
            }
        }

        //Create paths to other rooms and to the objects in the current room
        pathMan.GetPathsToRoomsAndObjects(this, roomsToTarget, objectsToTargetInCurrentRoom);

        pathState = PathState.WaitingForPath;
    }