/* Use a specified resource (returns false if used up) */ public bool UseResource(ContractAssignee ResourceType) { ZoneInShip ThisZone = null; switch (ResourceType) { case ContractAssignee.BLUE: ThisZone = BlueZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.GREEN: ThisZone = GreenZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.RED: ThisZone = RedZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.YELLOW: ThisZone = YellowZone.gameObject.GetComponent <ZoneInShip>(); break; } if (ThisZone == null) { return(false); } ThisZone.ResourceCount -= ResourceDepletionRate[(int)ResourceType]; return(ThisZone.ResourceCount > 0.0f); }
/* Distribute resources from contracts to zones if they're low */ private void DistributeResources() { if (CurrentRainyDay != RainyDayType.MAX_TYPES) { return; //Only allow contract consumption when no rainy day issues are active } bool contractBeingWorked = false; foreach (GameObject Contract in ContractsInside) { ContractInShip ContractMeta = Contract.GetComponent <ContractInShip>(); if (ContractMeta.State == ContractState.BEING_WORKED_ON) { contractBeingWorked = true; if (!workingAudio.isPlaying) { workingAudio.Play(); } ZoneInShip ThisZone = null; switch (ContractMeta.Assignee) { case ContractAssignee.BLUE: ThisZone = BlueZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.GREEN: ThisZone = GreenZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.RED: ThisZone = RedZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.YELLOW: ThisZone = YellowZone.gameObject.GetComponent <ZoneInShip>(); break; } if (ThisZone == null) { continue; } if (ThisZone.ResourceCount >= ThisZone.ResourceMax) { continue; } ThisZone.ResourceCount += ResourceDepletionRate[(int)ContractMeta.Assignee]; ContractMeta.ResourceRemaining -= ResourceDepletionRate[(int)ContractMeta.Assignee]; if (ContractMeta.ResourceRemaining <= 0.0f) { ContractMeta.State = ContractState.OUT_OF_JUICE; } } } if (!contractBeingWorked) { workingAudio.Stop(); } }
/* Convert a zone's resources into a resource entity */ public void ConvertResourcesToEntity(ContractAssignee zoneType) { //Get the zone that this resource is coming from ZoneInShip ThisZone = null; switch (zoneType) { case ContractAssignee.BLUE: ThisZone = BlueZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.GREEN: ThisZone = GreenZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.RED: ThisZone = RedZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.YELLOW: ThisZone = YellowZone.gameObject.GetComponent <ZoneInShip>(); break; } if (ThisZone == null) { return; } //We have some resources to distribute, so spawn the entity GameObject NewResourceEntity = Instantiate(resourceObject, ResourceSpawnSpots[(int)zoneType]) as GameObject; NewResourceEntity.transform.localScale = new Vector3(1, 1, 1); NewResourceEntity.GetComponent <ContractInShip>().ResourceRemaining = ThisZone.ResourceCount; NewResourceEntity.GetComponent <ContractInShip>().ResourceMax = ThisZone.ResourceCount; NewResourceEntity.GetComponent <ContractInShip>().SetResourceAssignee(zoneType); NewResourceEntity.transform.parent = ContractSpawnSpot.transform; ContractsInside.Add(NewResourceEntity); //Depleat the resource we took ThisZone.ResourceCount = 0; }
/* Check to see if a resource is empty */ public bool ResourceIsEmpty(ContractAssignee ResourceType) { ZoneInShip ThisZone = null; switch (ResourceType) { case ContractAssignee.BLUE: ThisZone = BlueZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.GREEN: ThisZone = GreenZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.RED: ThisZone = RedZone.gameObject.GetComponent <ZoneInShip>(); break; case ContractAssignee.YELLOW: ThisZone = YellowZone.gameObject.GetComponent <ZoneInShip>(); break; } return(ThisZone == null || ThisZone.ResourceCount <= 0.0f); }