Example #1
0
    private void ScanRequests()
    {
        collidedRequestsRadius1.RemoveAll(request => request.matchedToVehicle);
        collidedRequestsRadius2.RemoveAll(request => request.matchedToVehicle);
        collidedRequestsRadius3.RemoveAll(request => request.matchedToVehicle);

        collidedRequestsRadius1.RemoveAll(request => request.beingEvaled);
        collidedRequestsRadius2.RemoveAll(request => request.beingEvaled);
        collidedRequestsRadius3.RemoveAll(request => request.beingEvaled);

        collidedRequestsRadius1.RemoveAll(request => request.requestTime < currentTime - timeRadius);
        collidedRequestsRadius2.RemoveAll(request => request.requestTime < currentTime - timeRadius);
        collidedRequestsRadius3.RemoveAll(request => request.requestTime < currentTime - timeRadius);

        if (collidedRequestsRadius1.Count > 0)
        {
            ScanRequestsFirstRadius();
            if (highestScoringRequest == null)
            {
                ScanRequestsSecondRadius();
            }
            if (highestScoringRequest == null)
            {
                ScanRequestsThirdRadius();
            }
        }
        else if (collidedRequestsRadius2.Count > 0)
        {
            ScanRequestsSecondRadius();
            if (highestScoringRequest == null)
            {
                ScanRequestsThirdRadius();
            }
        }
        else if (collidedRequestsRadius3.Count > 0)
        {
            ScanRequestsThirdRadius();
        }
        if (highestScoringRequest == null)
        {
            if (searchTime >= timeRadius)
            {
                StartScanningDemand();
            }
        }
        else
        {
            currentRequest     = highestScoringRequest;
            state              = VEHICLE_STATE.VEHICLE_GOING_TO_PICKUP;
            spriteExistTime    = 0;
            currentDestination = currentRequest.requestLocation;
            currentRequest.matchedToVehicle    = true;
            timeProjectedToArriveAtDestination = currentTime + (Vector3.Distance(gameObject.transform.position, currentDestination) * unitSize) / 0.00833333f;
            foreach (SpriteRenderer sprite in gameObject.GetComponentsInChildren <SpriteRenderer>())
            {
                sprite.enabled = sprite.gameObject.tag == "Vehicle";
            }
        }
    }
Example #2
0
 private void StartScanningRequests()
 {
     state                 = VEHICLE_STATE.VEHICLE_SCANNING_REQUESTS;
     searchTime            = 0;
     highestScore          = minimumScore;
     highestScoringRequest = null;
     currentRequest        = null;
 }
Example #3
0
 private void PickUpRequest()
 {
     currentRequest.pickedUp = true;
     state = VEHICLE_STATE.VEHICLE_GOING_TO_DESTINATION;
     distanceTravelledWithoutPassenger += Vector2.Distance(previousLocation, currentDestination);
     currentDestination = currentRequest.destination;
     timeProjectedToArriveAtDestination = currentTime + (currentRequest.tripLength * unitSize) / 0.00833333f;
     previousLocation = gameObject.transform.position;
 }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        foreach (SpriteRenderer sprite in gameObject.GetComponentsInChildren <SpriteRenderer>())
        {
            if (sprite.gameObject.tag == "Thinking_Sprite" || sprite.gameObject.tag == "Waiting_Sprite" || sprite.gameObject.tag == "Match_Success_Sprite" || sprite.gameObject.tag == "Match_Failure_Sprite")
            {
                sprite.gameObject.transform.localPosition = new Vector3(9 * Mathf.Sin(gameObject.transform.eulerAngles.z * Mathf.Deg2Rad), 16 * Mathf.Cos(gameObject.transform.eulerAngles.z * Mathf.Deg2Rad));
                sprite.gameObject.transform.rotation      = Quaternion.identity;
            }
        }
        currentTime = GameObject.FindGameObjectWithTag("Simulation_Controller").GetComponent <SimulationController>().currentTime;
        gameObject.GetComponent <CircleCollider2D>().radius = maximumSearchRadius * radiusToUnitSize;
        switch (state)
        {
        case VEHICLE_STATE.VEHICLE_SCANNING_REQUESTS:
            foreach (SpriteRenderer sprite in gameObject.GetComponentsInChildren <SpriteRenderer>())
            {
                sprite.enabled = (sprite.gameObject.tag == "Thinking_Sprite" && spriteExistTime >= spritePersistTime) || (sprite.gameObject.tag == "Match_Failure_Sprite" && spriteExistTime < spritePersistTime) || sprite.gameObject.tag == "Vehicle";
            }
            ScanRequests();
            searchTime += GameObject.FindGameObjectWithTag("Simulation_Controller").GetComponent <SimulationController>().timeStep;
            break;

        case VEHICLE_STATE.VEHICLE_GOING_TO_PICKUP:
            foreach (SpriteRenderer renderer in gameObject.GetComponentsInChildren <SpriteRenderer>())
            {
                renderer.enabled = renderer.gameObject.tag == "Vehicle" || (renderer.gameObject.tag == "Match_Success_Sprite" && spriteExistTime < spritePersistTime);
                spriteExistTime += Time.deltaTime;
            }
            if (gameObject.transform.position == currentDestination)
            {
                if (currentTime < currentRequest.requestTime)
                {
                    state = VEHICLE_STATE.VEHICLE_WAITING_AT_PICKUP;
                }
                else
                {
                    PickUpRequest();
                }
                distanceTravelledWithPassenger += currentRequest.tripLength;
            }
            else
            {
                // 3
                Vector3 vectorToTarget = currentDestination - transform.position;
                // 4
                vectorToTarget.z = 0;
                vectorToTarget.Normalize();
                float targetAngle = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;
                targetAngle                  -= 90;
                transform.rotation            = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 0, targetAngle), 1.0f);
                gameObject.transform.position = Vector3.Lerp(previousLocation, currentDestination, currentTime / timeProjectedToArriveAtDestination);
            }
            break;

        case VEHICLE_STATE.VEHICLE_WAITING_AT_PICKUP:
            if (currentTime >= currentRequest.requestTime)
            {
                PickUpRequest();
            }
            else
            {
                foreach (SpriteRenderer renderer in GetComponentsInChildren <SpriteRenderer>())
                {
                    renderer.enabled = renderer.gameObject.tag == "Waiting_Sprite" || renderer.gameObject.tag == "Vehicle";
                }
            }
            break;

        case VEHICLE_STATE.VEHICLE_GOING_TO_DESTINATION:
            foreach (SpriteRenderer renderer in gameObject.GetComponentsInChildren <SpriteRenderer>())
            {
                renderer.enabled = renderer.gameObject.tag == "Vehicle";
            }
            if (gameObject.transform.position == currentDestination)
            {
                DropOffRequest();
            }
            else
            {
                // 3
                Vector3 vectorToTarget = currentDestination - transform.position;
                // 4
                vectorToTarget.z = 0;
                vectorToTarget.Normalize();
                float targetAngle = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;
                targetAngle                  -= 90;
                transform.rotation            = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 0, targetAngle), 1.0f);
                gameObject.transform.position = Vector3.Lerp(previousLocation, currentDestination, currentTime / timeProjectedToArriveAtDestination);
            }
            break;

        case VEHICLE_STATE.VEHICLE_SCANNING_DEMAND:
            foreach (SpriteRenderer sprite in gameObject.GetComponentsInChildren <SpriteRenderer>())
            {
                sprite.enabled   = (sprite.gameObject.tag == "Thinking_Sprite" && spriteExistTime >= spritePersistTime) || (sprite.gameObject.tag == "Match_Failure_Sprite" && spriteExistTime < spritePersistTime) || sprite.gameObject.tag == "Vehicle";
                spriteExistTime += Time.deltaTime;
            }
            if (ScanDemandZones())
            {
                state           = VEHICLE_STATE.VEHICLE_GOING_TO_DEMAND_ZONE;
                spriteExistTime = 0;
            }
            else
            {
                if (searchTime >= timeRadius)
                {
                    StartScanningRequests();
                }
                else
                {
                    searchTime += GameObject.FindGameObjectWithTag("Simulation_Controller").GetComponent <SimulationController>().timeStep;
                }
            }
            break;

        case VEHICLE_STATE.VEHICLE_GOING_TO_DEMAND_ZONE:
            foreach (SpriteRenderer renderer in gameObject.GetComponentsInChildren <SpriteRenderer>())
            {
                renderer.enabled = renderer.gameObject.tag == "Vehicle";
            }
            if (gameObject.transform.position == currentDestination)
            {
                StartScanningRequests();
            }
            else
            {
                Vector3 vectorToTarget = currentDestination - transform.position;
                // 4
                vectorToTarget.z = 0;
                vectorToTarget.Normalize();
                float targetAngle = Mathf.Atan2(vectorToTarget.y, vectorToTarget.x) * Mathf.Rad2Deg;
                targetAngle                  -= 90;
                transform.rotation            = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 0, targetAngle), 1.0f);
                gameObject.transform.position = Vector3.Lerp(previousLocation, currentDestination, currentTime / timeProjectedToArriveAtDestination);
            }
            break;

        default:
            state = VEHICLE_STATE.VEHICLE_SCANNING_REQUESTS;
            break;
        }
    }
Example #5
0
 private void StartScanningDemand()
 {
     searchTime      = 0;
     spriteExistTime = 0;
     state           = VEHICLE_STATE.VEHICLE_SCANNING_DEMAND;
 }