Ejemplo n.º 1
0
    public int getApproxTravelTime(Station station)
    {
        float time=0;
        bool needToWalk = getLineTypeTo(station) == Line.Type.None;

        if (needToWalk)
        {
            float distance = Vector3.Distance(station.transform.position, this.transform.position);
            time += distance * walkCostFactor;
        }
        else
        {
            int numStations = Mathf.Abs(station.getIndex() - this.station.getIndex());

            time += station.getEnterCost(true);
            time += numStations * line().getTravelCostFactor();
            time += station.getExitCost();
        }

        return (int)time;
    }
Ejemplo n.º 2
0
    public void setStation(Station station)
    {
        float bestCaseTimeBeforeTravel = bestCaseTime;

        clearGUITexts();
        bool needToWalk = (line() == null || station.getLine() != line());
        float timeToStation = 0.0f;

        if (needToWalk)
        {
            float distance = Vector3.Distance(station.transform.position, this.transform.position);
            timeToStation += distance * walkCostFactor;;
            bestCaseTime += distance * walkCostFactorHealthyPerson;
        }
        else
        {
            int numStations = Mathf.Abs(station.getIndex() - this.station.getIndex());
            timeToStation += station.getEnterCost(false);
            timeToStation += numStations * line().getTravelCostFactor();
            timeToStation += station.getExitCost();

            //TODO: don't use "risks" of wheelchair driver
            bestCaseTime += timeToStation;
        }

        travelTime += (int)timeToStation;
        GameObject.Find("timeText").GetComponent<TimeOfDay>().addTime((int)timeToStation);

        if(needToWalk)
            stationNext = station;
        else
            stationNext = this.station.getNextOnRoute(station);

        this.station = station;
        newPos = stationNext.transform.position;

        int extratime = evaluateRisk(needToWalk);
        lastRiskTime = extratime;
        travelTime+=extratime;
        GameObject.Find("timeText").GetComponent<TimeOfDay>().addTime(extratime);

        //Vector3 position = station.transform.position;
        //position.z = this.transform.position.z;
        //this.transform.position = position;

        //is this station a target?
        if(station.isTargetStation()){
            SpriteRenderer sprite = station.GetComponent<SpriteRenderer>();
            //target marked as visited
            sprite.color = GameObject.Find("background").renderer.material.color;

            station.enabled = false;
            targetsVisited++;

            if(targetsVisited == targetCount){
                //GAME OVER! ALL TARGETS VISITED!
                /*Vector3 pos = new Vector3(Screen.width,this.transform.position.y,this.transform.position.z);
                GameObject txtGO = Instantiate(infoBox, pos, new Quaternion()) as GameObject;
                TextMesh txt = txtGO.GetComponent<TextMesh>();
                txt.fontSize=5;
                txt.text = "If you had been a healthy person \nthe journey would have taken you "+(int)bestCaseTime+" minutes";*/

                gameOver = true;
            }
        }

        float bestCaseTimeDiff = bestCaseTime - bestCaseTimeBeforeTravel;
        int moveTimeExtra = Mathf.RoundToInt(timeToStation - bestCaseTimeDiff);
        int timeDiffToBestCase = moveTimeExtra + extratime;

        if (timeDiffToBestCase > 0)
        {
            string extraTimeLabel = "";
            if (moveTimeExtra > 0)
                extraTimeLabel += "+" + moveTimeExtra;
            if (extratime > 0)
                extraTimeLabel += " +" + extratime;

            GameObject.Find("timeDiffText").guiText.text = extraTimeLabel;
        }
        else
        {
            GameObject.Find("timeDiffText").guiText.text = "";
        }
        //GameObject.Find("timeDiffText").guiText.text += " (" + (travelTime - (int)bestCaseTime) + ")";
    }