示例#1
0
    void SetupRoute()
    {
        route_TaskList = Metro.INSTANCE.ShortestRoute(currentPlatform, FinalDestination);
        CommuterTask[] _TEMP = route_TaskList.ToArray();
        for (int i = 0; i < route_TaskList.Count; i++)
        {
            CommuterTask _T = _TEMP[i];
            string       _S = "route step: " + i + ",  " + _T.state;
            switch (_T.state)
            {
            case CommuterState.WALK:
                _S += ", startPlatform: " + _T.startPlatform.GetFullName();
                _S += ", endPlatform: " + _T.endPlatform.GetFullName();

                break;

            case CommuterState.QUEUE:
                _S += ", on platform: " + _T.startPlatform.GetFullName();
                break;

            case CommuterState.GET_ON_TRAIN:
                break;

            case CommuterState.WAIT_FOR_STOP:
                _S += ", waiting for stop: " + _T.endPlatform.GetFullName();
                break;

            case CommuterState.GET_OFF_TRAIN:
                _S += ", endPlatform: " + _T.endPlatform.GetFullName();
                break;
            }
            Debug.Log(_S);
        }
        NextTask();
    }
示例#2
0
    void NextTask()
    {
        if (route_TaskList.Count > 0)
        {
            currentTask = route_TaskList.Dequeue();
            if (currentTask.startPlatform != null)
            {
                currentPlatform = currentTask.startPlatform;
                Debug.Log("Current platform is now: " + currentPlatform.GetFullName());
            }

            if (currentTask.endPlatform != null)
            {
                nextPlatform = currentTask.endPlatform;
            }

            switch (currentTask.state)
            {
            case CommuterState.WALK:
                Walkway walk_A = GetNearestWalkway(t.position, currentPlatform);
                Walkway walk_B = GetNearestWalkway(walk_A.nav_END.transform.position, nextPlatform);

                currentTask.destinations = new Vector3[]
                {
                    walk_A.nav_START.transform.position,
                    walk_A.nav_END.transform.position,
                    walk_B.nav_END.transform.position,
                    walk_B.nav_START.transform.position
                };
                break;

            case CommuterState.QUEUE:
                // pick shortest queue
                stateDelay               = QUEUE_DECISION_RATE;
                carriageQueueIndex       = currentPlatform.Get_ShortestQueue();
                currentQueue             = currentPlatform.platformQueues[carriageQueueIndex];
                myQueueIndex             = currentQueue.Count;
                currentTask.destinations = new Vector3[]
                { currentPlatform.queuePoints[carriageQueueIndex].transform.position };
                break;

            case CommuterState.GET_ON_TRAIN:
                // delay movement - stagger by queueIndex
                stateDelay = QUEUE_MOVEMENT_DELAY * myQueueIndex;
                currentTask.destinationIndex = 0;
                currentTask.destinations     = new Vector3[]
                {
                    currentPlatform.queuePoints[carriageQueueIndex].transform.position,
                    currentTrainDoor.door_navPoint.transform.position, currentSeat.transform.position
                };
                break;

            case CommuterState.WAIT_FOR_STOP:
                nextPlatform = currentTask.endPlatform;
                break;

            case CommuterState.GET_OFF_TRAIN:
                t.SetParent(Metro.INSTANCE.transform);
                currentTask.destinationIndex = 0;
                currentTask.destinations     = new Vector3[]
                {
                    currentTrainDoor.door_navPoint.transform.position,
                    currentTrain.nextPlatform.queuePoints[carriageQueueIndex].transform.position
                };
                break;
            }
        }
        else
        {
            if (Metro.INSTANCE != null)
            {
                Metro.INSTANCE.Remove_Commuter(this);
            }
        }
    }
示例#3
0
    public Queue <CommuterTask> ShortestRoute(Platform _A, Platform _B)
    {
        Debug.Log("Getting from " + _A.GetFullName() + " to " + _B.GetFullName());
        foreach (Platform _P in allPlatforms)
        {
            _P.temporary_routeDistance       = 999;
            _P.temporary_accessedViaPlatform = null;
            _P.temporary_connectionType      = CommuterState.WALK;
        }

        int             steps            = 0;
        List <Platform> _ROUTE_PLATFORMS = new List <Platform>();


        // Add MAIN platform (and adjacents)
        Include_platform_if_new_or_improved(_ROUTE_PLATFORMS, _A, steps);
        foreach (Platform _ADJ in _A.adjacentPlatforms)
        {
            Include_platform_if_new_or_improved(_ROUTE_PLATFORMS, _ADJ, steps, _A);
            Include_platform_if_new_or_improved(_ROUTE_PLATFORMS, _ADJ.oppositePlatform, steps, _A);
        }

        // Add OPPOSITE platform (and adjacents)
        Include_platform_if_new_or_improved(_ROUTE_PLATFORMS, _A.oppositePlatform, steps, _A);
        foreach (Platform _ADJ in _A.oppositePlatform.adjacentPlatforms)
        {
            Include_platform_if_new_or_improved(_ROUTE_PLATFORMS, _ADJ, steps);
            Include_platform_if_new_or_improved(_ROUTE_PLATFORMS, _ADJ.oppositePlatform, steps, _A);
        }

        bool arrived = _ROUTE_PLATFORMS.Contains(_B);

        for (int i = 0; i < 100; i++)
        {
            if (arrived)
            {
                Debug.Log("Arrived at " + _B.GetFullName() + " after " + steps + " steps");
                break;
            }

            steps++;
            _ROUTE_PLATFORMS = ExpandPlatformSelection(_ROUTE_PLATFORMS, steps);
            arrived          = _ROUTE_PLATFORMS.Contains(_B);
        }


        // write the route from B -> A, then reverse it

        Platform _CURRENT_PLATFORM = _B;
        Platform _PREV_PLATFORM    = _B.temporary_accessedViaPlatform;

        Debug.Log(commuters.Count + ", start: " + _A.GetFullName() + "Dest: " + _B.GetFullName() + ",  b prev: " + _PREV_PLATFORM.GetFullName());
        List <CommuterTask> _TASK_LIST = new List <CommuterTask>();

        while (_CURRENT_PLATFORM != _A)
        {
            // if this is _B (the destination, and we arrived by rail, it's safe to get off)
            if (_CURRENT_PLATFORM == _B && _CURRENT_PLATFORM.temporary_connectionType == CommuterState.GET_OFF_TRAIN)
            {
                _TASK_LIST.Add(new CommuterTask(CommuterState.GET_OFF_TRAIN)
                {
                    endPlatform = _CURRENT_PLATFORM
                });
                _TASK_LIST.Add(new CommuterTask(CommuterState.WAIT_FOR_STOP)
                {
                    endPlatform = _CURRENT_PLATFORM
                });
            }

            // add a WALK connection
            if (_CURRENT_PLATFORM.temporary_connectionType == CommuterState.WALK)
            {
                CommuterTask _walkTask = new CommuterTask(CommuterState.WALK)
                {
                    startPlatform = _PREV_PLATFORM,
                    endPlatform   = _CURRENT_PLATFORM
                };
                _TASK_LIST.Add(_walkTask);


                if (_PREV_PLATFORM.temporary_connectionType == CommuterState.GET_OFF_TRAIN)
                {
                    _TASK_LIST.Add(new CommuterTask(CommuterState.GET_OFF_TRAIN)
                    {
                        endPlatform = _PREV_PLATFORM
                    });
                    _TASK_LIST.Add(new CommuterTask(CommuterState.WAIT_FOR_STOP)
                    {
                        endPlatform = _PREV_PLATFORM
                    });
                }
            }
            else // add a train link
            {
                if (_PREV_PLATFORM.temporary_connectionType == CommuterState.WALK)
                {
                    _TASK_LIST.Add(new CommuterTask(CommuterState.GET_ON_TRAIN));
                    _TASK_LIST.Add(new CommuterTask(CommuterState.QUEUE)
                    {
                        startPlatform = _PREV_PLATFORM
                    });
                }
            }


            // exit loop when we arrive at _A
            if (_CURRENT_PLATFORM.temporary_accessedViaPlatform != null)
            {
                _CURRENT_PLATFORM = _CURRENT_PLATFORM.temporary_accessedViaPlatform;
                _PREV_PLATFORM    = _CURRENT_PLATFORM.temporary_accessedViaPlatform;
            }
            else
            {
                break;
            }
        }

        _TASK_LIST.Reverse();
        Queue <CommuterTask> result = new Queue <CommuterTask>();

        for (int i = 0; i < _TASK_LIST.Count; i++)
        {
            result.Enqueue(_TASK_LIST[i]);
        }

        return(result);
    }