Exemple #1
0
    /*
     * Attempt to make a transaction - validate that the participant
     * can afford it, and then call out as necessary to apply changes
     * to the environment to reflect the transaction.
     */
    private bool attemptObtain(TreatmentObtainType t)
    {
        float effectiveWaitTime = -1.0f;     // Seconds
        float effectiveCost     = -1.0f;     // Lab dollars
        bool  transactionValid  = false;

        SimManager.GameState currentSimState = simManagerComponent.currentState();

        if (t == TreatmentObtainType.PAY)
        {
            effectiveCost    = simManagerComponent.getCurrentTreatmentCost();
            transactionValid = (
                currentSimState == SimManager.GameState.RUNNING &&
                simManagerComponent.getCurrentScore() > effectiveCost
                );
        }

        else if (t == TreatmentObtainType.WAIT)
        {
            effectiveWaitTime = simManagerComponent.getCurrentTreatmentWaitTime();
            transactionValid  = currentSimState == SimManager.GameState.RUNNING;
        }


        // Only apply changes to the environment if the transaction was approved
        if (transactionValid)
        {
            if (t != TreatmentObtainType.WAIT)
            {
                disablePanels();
            }
            simManagerComponent.determinePostTreatmentActions(t, effectiveCost, effectiveWaitTime);
        }

        else
        {
            // Play a quick error sound to make them realize it didn't work
            audioManagerComponent.playSound(AudioManager.SoundType.ERROR);

            Debug.Log("Invalid treatment obtain attempt. Resetting " + t.ToString() + " bottle position.");

            if (t == TreatmentObtainType.PAY)
            {
                // Detach the pill from the hand holding it
                Valve.VR.InteractionSystem.Hand handHoldingPill = simManagerComponent.getHandScriptHoldingObj(payPill);
                if (handHoldingPill != null)
                {
                    handHoldingPill.DetachObject(payPill);
                }

                // Then, reset its position
                payPill.transform.position = new Vector3(
                    payBottleInitXPosition,
                    payBottleInitYPosition,
                    payBottleInitZPosition
                    ); payPill.transform.eulerAngles = new Vector3(0.0f, 0.0f, 0.0f);

                payBottlePositionA = payPill.transform.position;
            }

            else if (t == TreatmentObtainType.WAIT)
            {
                // Detach the pill from the hand holding it
                Valve.VR.InteractionSystem.Hand handHoldingPill = simManagerComponent.getHandScriptHoldingObj(waitPill);
                if (handHoldingPill != null)
                {
                    handHoldingPill.DetachObject(waitPill);
                }

                // Then, reset its position
                waitPill.transform.position = new Vector3(
                    waitBottleInitXPosition,
                    waitBottleInitYPosition,
                    waitBottleInitZPosition
                    ); waitPill.transform.eulerAngles = new Vector3(0.0f, 0.0f, 0.0f);

                waitBottlePositionA = waitPill.transform.position;
            }

            else
            {
                Debug.Log("Unrecognized bottle type. Not resetting position.");
            }
        }

        return(transactionValid);
    }
Exemple #2
0
    /*
     * General CSV entry into log file
     */
    public void persist(

        float globalTime,                                                                        // Total simulation runtime (any state)
        int currentDay,
        SimManager.GameState currentState,
        float headsetX,
        float headsetY,
        float headsetZ,
        int headsetXRotate,
        int headsetYRotate,
        int headsetZRotate,
        float controllerLX,
        float controllerLY,
        float controllerLZ,
        float controllerRX,
        float controllerRY,
        float controllerRZ,
        float bucketX,
        float bucketY,
        float bucketZ,
        float dayTime,                                           // Total day time (running state only)
        float totalScore,                                        // Includes deductions for payment
        float dayScore,                                          // Includes deductions for payment
        float payRate,                                           // How much 1 droplet of water is worth today
        int currentlyCarrying,                                   // Water droplets inside of the container
        int cumulativeCarrying,                                  // Amount of water carried total
        int dailyCumulativeCarrying,                             // Total amount of water carried on this day
        int cumulativeSpilled,                                   // Total amount of water spilled
        int dailyCumulativeSpilled,                              // Total amount of water spilled on this day
        int cumulativeDelivered,                                 // All drops that have reached the destination
        int todayDelivered,                                      // Above, except for today
        bool currentDayOffersPayTreatment,
        bool currentDayOffersWaitTreatment,
        float currentTreatmentPayCost,                              // Dollars
        float currentTreatmentWaitCost,                             // Seconds
        float tremorImpairmentCurrentStrength,
        float tremorImpairmentInitialStrength,
        float timeWaitedForTreatmentDay,
        float amountPayedForTreatmentDay,
        float timeWaitedForTreatmentTotal,
        float amountPayedForTreatmentTotal,
        float speed                                             // Avg speed over last second

        )
    {
        try {
            fileWriter = new System.IO.StreamWriter(Application.dataPath + "/OutputData/" + logFileName, true);
            fileWriter.WriteLine(
                string.Format(
                    TXT_OUTPUT_FMT,
                    globalTime.ToString(),
                    currentDay.ToString(),
                    dayTime.ToString(),
                    currentState.ToString(),
                    headsetX.ToString(),
                    headsetY.ToString(),
                    headsetZ.ToString(),
                    headsetXRotate.ToString(),
                    headsetYRotate.ToString(),
                    headsetZRotate.ToString(),
                    controllerLX.ToString(),
                    controllerLY.ToString(),
                    controllerLZ.ToString(),
                    controllerRX.ToString(),
                    controllerRY.ToString(),
                    controllerRZ.ToString(),
                    bucketX.ToString(),
                    bucketY.ToString(),
                    bucketZ.ToString(),
                    speed.ToString(),
                    currentlyCarrying.ToString(),
                    cumulativeCarrying.ToString(),
                    dailyCumulativeCarrying.ToString(),
                    cumulativeSpilled.ToString(),
                    dailyCumulativeSpilled.ToString(),
                    cumulativeDelivered.ToString(),
                    todayDelivered.ToString(),
                    totalScore.ToString(),
                    dayScore.ToString(),
                    payRate.ToString(),
                    currentDayOffersPayTreatment.ToString(),
                    currentDayOffersWaitTreatment.ToString(),
                    currentTreatmentPayCost.ToString(),
                    currentTreatmentWaitCost.ToString(),
                    tremorImpairmentCurrentStrength.ToString(),
                    tremorImpairmentInitialStrength.ToString(),
                    timeWaitedForTreatmentDay.ToString(),
                    amountPayedForTreatmentDay.ToString(),
                    timeWaitedForTreatmentTotal.ToString(),
                    amountPayedForTreatmentTotal.ToString()
                    )
                ); closeStreamWriter();
        }

        catch (System.Exception e) {
            Debug.Log("Persistance exception: " + e.Message + "\n" + e.StackTrace);
        }
    }