Example #1
0
    void Start()
    {
        gameMode      = GameMode.TIME_LIMIT;
        runState      = RunState.RUNNING;
        _resourceGoal = 7500f;
        _currentTime  = 0f;
        _timeGoal     = 300f;           // five-minute time limit
        _interestRate = 0.001f;
        //interestTime = 5f;
        _minBoundX       = -350;
        _maxBoundX       = 350;
        _minBoundZ       = -350;
        _maxBoundZ       = 350;
        _unitCount       = 0;
        _unitCap         = 10;
        _interceptorCost = 1000;
        _freighterCost   = 1000;
        _resonatorCost   = 1000;

        //Initializing the values that retlate this to the other script.
        //This is not the best OOP because of the forced coupling. If you have an idea for how to keep the functionality and reduce this coupling, let me know. - Moore
        player            = GameObject.FindGameObjectWithTag("Player");
        playerScript      = player.GetComponent <GenericUnitBehavior>();
        _currentResources = playerScript.ResourceLoad;
    }
    public float GatherResourcesFromSource(GameObject targetObject)
    {
        //Precondition: You should really only call this method once per calling object per update. - Moore
        float result = 0.0f;
        GenericUnitBehavior gubScript = targetObject.GetComponent <GenericUnitBehavior>();

        if (gubScript != null)
        {
            result = gubScript.TransferResourcesToSource(gameObject);
        }
        return(result);
    }
    public float TransferResourcesToSource(GameObject targetObject)
    {
        //Precondition: You should only call this once per calling object per update.

        //Check how many resources the target wants to take.
        float result                  = 0.0f;
        float amountRequested         = 0.0f;
        GenericUnitBehavior gubScript = targetObject.GetComponent <GenericUnitBehavior>();

        amountRequested = gubScript.gatheringRate * gubScript.rateModifier * Time.fixedDeltaTime;

        //Can't draw more than the capacity. - Moore
        if (gubScript.resourceCapacity < 0.0f)
        {
            ;// This is here because a negative capacity effectively means infinite capacity. It prevents the following branch from bouncing back.
        }
        else if (amountRequested + gubScript.ResourceLoad > gubScript.resourceCapacity)
        {
            amountRequested = gubScript.resourceCapacity - gubScript.ResourceLoad;
        }

        //If this request can be fulfilled in full, do so.
        if (amountRequested <= ResourceLoad)
        {
            ResourceLoad           -= amountRequested;
            gubScript.ResourceLoad += amountRequested;
        }
        else
        { //If not, give all that remains. Leave cleanup for another method to deal with. - Moore.
            amountRequested         = ResourceLoad;
            ResourceLoad           -= amountRequested;
            gubScript.ResourceLoad += amountRequested;
        }

        result = amountRequested;
        return(result);
    }
 // Use this for initialization
 void Start()
 {
     gun  = GetComponent <GenericUnitBehavior>();
     reab = GetComponentInChildren <ResonatorEffectAreaBehavior>();        //Unlike the reab in the Generic Unit Behavior, this refers to our own reab, not one from a collision. - Moore
 }
Example #5
0
 // Use this for initialization
 void Start()
 {
     gun = GetComponent <GenericUnitBehavior> ();
 }
 // Use this for initialization
 void Start()
 {
     gun = GetComponent<GenericUnitBehavior> ();
 }
    void Start()
    {
        gameMode = GameMode.TIME_LIMIT;
        runState = RunState.RUNNING;
        _resourceGoal = 7500f;
        _currentTime = 0f;
        _timeGoal = 300f;	// five-minute time limit
        _interestRate = 0.001f;
        //interestTime = 5f;
        _minBoundX = -350;
        _maxBoundX = 350;
        _minBoundZ = -350;
        _maxBoundZ = 350;
        _unitCount = 0;
        _unitCap = 10;
        _interceptorCost = 1000;
        _freighterCost = 1000;
        _resonatorCost = 1000;

        //Initializing the values that retlate this to the other script.
        //This is not the best OOP because of the forced coupling. If you have an idea for how to keep the functionality and reduce this coupling, let me know. - Moore
        player = GameObject.FindGameObjectWithTag("Player");
        playerScript = player.GetComponent<GenericUnitBehavior>();
        _currentResources = playerScript.ResourceLoad;
    }
 // Use this for initialization
 void Start()
 {
     gun = GetComponent<GenericUnitBehavior>();
     reab = GetComponentInChildren<ResonatorEffectAreaBehavior>(); //Unlike the reab in the Generic Unit Behavior, this refers to our own reab, not one from a collision. - Moore
 }