void assignQuota(float unit) { Debug.Log("Assigning quota..."); foreach (GameObject harbor in harbors) { foreach (Transform boat in harbor.transform) { BoatTileMovement b = boat.gameObject.GetComponent <BoatTileMovement>(); b.quota = b.capacity * unit; b.keepFishingQuota(grid.resourceTiles.ElementAt(UnityEngine.Random.Range(0, grid.resourceTiles.Count)).Key); } } }
public float calculateTotalCapacity() { float capacity = 0f; foreach (GameObject harbor in harbors) { foreach (Transform boat in harbor.transform) { BoatTileMovement b = boat.gameObject.GetComponent <BoatTileMovement>(); capacity += b.capacity; // * b.efficiency; } } return(capacity); }
public void getFish(GameObject vessel, float quota) { float fish = 0f; float totalFish = 0f; bool enough = false; for (int i = 0; i < boatsFishing.Count; i++) { BoatTileMovement boat = boatsFishing[i].GetComponent <BoatTileMovement>(); float maxCatch = boat.efficiency * boat.capacity * 15 > quota ? boat.efficiency * boat.capacity * 15 : quota; totalFish += maxCatch; } enough = currentResource > totalFish ? true : false; BoatTileMovement vesselComp = vessel.GetComponent <BoatTileMovement>(); if (enough) { float luck = Random.Range(currentResource / carryCapacity, ((currentResource / carryCapacity) + 1f) / 2); float maxCatch = vesselComp.efficiency * vesselComp.capacity * 15 * luck; float allowedCatch = quota; vesselComp.currentCatch = quota > maxCatch ? maxCatch : quota; currentResource -= vesselComp.currentCatch; } else { float maxCatch = currentResource / boatsFishing.Count; float allowedCatch = quota; vesselComp.currentCatch = maxCatch < quota ? maxCatch : quota; currentResource -= vesselComp.currentCatch; } boatsFishing.Remove(vessel); }