// Use this for initialization void Awake() { deposit = new ResourceDeposit((RawResources)Random.Range(1, 6)); gameObject.name = deposit.resource.ToString() + " Asteroid"; Collections.Mineable.Add(this); mines = new List <Mine>(); }
public override void PerformTask(Task task) { ResourceDeposit resourceDepo = (task as GatherTask).GetTaskResourceDeposit(); if (!resourceDepo) { _currentGatherDelay = 0; unit.tasks.FinishTask(); return; } if (Vector2.Distance(unit.transform.position, resourceDepo.transform.position) > range) { // Get within range of resource, so assign move task to get there as a priority unit.tasks.AssignPriorityTask(new MoveTask(resourceDepo.transform.position, range)); return; } if (_currentGatherDelay > 0) { // Gather delay is active _currentGatherDelay -= Time.deltaTime; return; } unit.owner.resources.AddResources(resourceDepo.Gather(gatherYield)); _currentGatherDelay = gatherDelay; }
private IEnumerator ResourceAmountUpdate(ResourceDeposit resourceDeposit) { while (true) { amountValueText.text = Mathf.Round(resourceDeposit.AvailableResource()).ToString(); yield return(new WaitForFixedUpdate()); } }
public void ClearTargetVariables() { currentTargetDefender = null; currentTargetsSquad = null; currentTargetsHealth = null; currentTargetNode = null; currentTargetResourceDeposit = null; }
private void AddCurrentBuildingToMap() { if (currentBuilding) { Vector3 position = currentBuilding.transform.position - Vector3.up * preViewOffset; GameObject building = Instantiate(currentBuildingPrefab, position, Quaternion.identity, buildingsTransform); if (isCurrentBuildResourceExtractor) { ResourceDeposit resourceDeposit = worldMap.GetResourceDeposit(position); Debug.Assert(resourceDeposit, "Resource Deposit is null"); ResourceExtractor resourceExtractor = building.GetComponent <ResourceExtractor>(); resourceExtractor.SetDeposit(resourceDeposit); } bool isRoad = building.TryGetComponent(out RoadUpdater roadUpdater); if (isRoad) { worldMap.AddRoadToHexCell(position, building); } else { worldMap.AddBuildingToHexCell(position, building); } WorldMap.DoubleCircleOfHexCellsAround doubleCircleOfHexCellsAround = worldMap.GetDoubleCircleOfHexCellsAround(position); if (isRoad) { roadUpdater.UpdateRoad(doubleCircleOfHexCellsAround.firstCircle); } for (int i = 0; i < WorldMap.cellNeighbourAmount; ++i) { WorldMap.HexCellsAround hexCellsAround = doubleCircleOfHexCellsAround.secondCircles[i]; if ((hexCellsAround.centerCell.hexType & WorldMap.HexType.Road) == WorldMap.HexType.Road) { if (hexCellsAround.centerCell.road) { if (hexCellsAround.centerCell.road.TryGetComponent(out RoadUpdater currentRoadUpdater)) { currentRoadUpdater.UpdateRoad(hexCellsAround); } else { Debug.LogError("Game object doesn't contain road updater"); } } else { Debug.LogError("Road game object is empty"); } } } } }
public override void OnStart() { gatherer = baseModule.GetModule <GathererModule>(ModuleID.Gatherer); if (gatherer != null) { ResourceDeposit = gatherer.TargetDeposit; abortTrigger.Value = !gatherer.TryStartProcess(); } }
public void StopWorking() { if (targetResourceDeposit != null) { defenderScript.anim.SetBool("isMining", false); targetResourceDeposit.occupied = false; targetResourceDeposit.resourceNode.unoccupiedResourceDeposits.Add(targetResourceDeposit); targetResourceDeposit = null; } isWorking = false; }
private bool PlaceResource(CircularGrid grid, int layer, int slice, int prefabNumber) { GridCell parentCell = grid.GetGridCell(layer, slice); if (parentCell.Selectable == null && parentCell.ResourceDeposit == null) { ResourceDeposit deposit = Instantiate <ResourceDeposit>(this.resourceDepositPrefabs[prefabNumber]); deposit.transform.SetParent(resourceDepositHolder.transform); GridManager.Instance.AddResourceDeposit(deposit); deposit.SetParentCell(parentCell); return(true); } return(false); }
void Start() { SetLaneSpawner(); defenderSpawner = DefenderSpawner.instance; gameAssets = GameAssets.instance; int resourceDepositCount = 0; for (int i = 0; i < goldDepositCount; i++) { ResourceDeposit goldDeposit = Instantiate(gameAssets.goldDeposit, transform); resourceDepositCount++; int randomIndex = Random.Range(0, possibleDepositSpawnLocations.Count); goldDeposit.transform.localPosition = possibleDepositSpawnLocations[randomIndex]; possibleDepositSpawnLocations.Remove(possibleDepositSpawnLocations[randomIndex]); } for (int i = 0; i < resourceDepositCount; i++) { resourceDeposits.Add(transform.GetChild(i).GetComponent <ResourceDeposit>()); unoccupiedResourceDeposits.Add(resourceDeposits[i]); } // Add this node to our list of nodes defenderSpawner.AddNode(transform.position); defenderSpawner.resourceNodes.Add(this); // Choose a random sprite for (int i = 0; i < resourceDeposits.Count; i++) { if (resourceDeposits[i].resourceType == ResourceType.Gold) { int randomIndex = Random.Range(0, gameAssets.goldDepositAnimatorControllers.Count); resourceDeposits[i].anim.runtimeAnimatorController = gameAssets.goldDepositAnimatorControllers[randomIndex]; } int coinToss = Random.Range(0, 2); if (coinToss == 0) { resourceDeposits[i].sr.flipX = false; } else { resourceDeposits[i].sr.flipX = true; } } }
private static Resourcer GetResourcer(Planet planet) { var result = new ResourceDeposit[Rnd.Next(0, (int)(planet.mass * 10))]; List <int> idsRes = new List <int>(); List <int> probabRes = new List <int>(); for (int i = 0; i < Data.planetaryResourcesProbabilityArr.Length; i++) { if (Data.planetaryResourcesProbabilityArr[i].probabilityOfPlanet[planet.type] == 0) { continue; } idsRes.Add(Data.planetaryResourcesProbabilityArr[i].resurceId); probabRes.Add(Data.planetaryResourcesProbabilityArr[i].probabilityOfPlanet[planet.type]); } int[] rangeProbab = new int[probabRes.Count]; rangeProbab[0] = probabRes[0]; for (int i = 1; i < rangeProbab.Length; i++) { rangeProbab[i] = rangeProbab[i - 1] + probabRes[i]; } for (int i = 0; i < result.Length; i++) { int rnd = Rnd.Next(0, rangeProbab[rangeProbab.Length - 1]); for (int j = 0; j < rangeProbab.Length; j++) { if (rnd < rangeProbab[j]) { ResourceDeposit res = new ResourceDeposit { idResource = idsRes[j], extraction = Rnd.Next(10, 50), }; result[i] = res; break; } } } return(new Resourcer(result, planet)); }
private ResourceDeposit GetNearestResourceDeposit(Unit unit) { ResourceDeposit closestDeposit = null; float closestDist = float.MaxValue; foreach (ResourceDeposit dep in GridManager.Instance.resourceDeposits.Where(dep => dep.ParentCell.parentGrid == unit.ParentCell.parentGrid)) { if (dep.ParentCell.Selectable == null) { float distToDeposit = (dep.transform.position - unit.transform.position).sqrMagnitude; if (distToDeposit < closestDist) { closestDeposit = dep; closestDist = distToDeposit; } } } return(closestDeposit); }
private static IndustryConstruction CreateIndustryConstruction(ResourceDeposit deposit) { IndustryConstruction industryConstruction = new IndustryConstruction(); Recipe recipe; if (deposit == null) { recipe = (Recipe)productRecipeArr[Rnd.Next(0, productRecipeArr.Length - 1)]; } else { recipe = (Recipe)miningRecipesArr[deposit.idResource]; deposit.isExistConstruction = true; } industryConstruction.resourceDeposit = deposit; industryConstruction.stageProcess = 0; industryConstruction.state = EProducingState.finished; industryConstruction.recipe = recipe; return(industryConstruction); }
private void AddBuildingToAvailableResource() { foreach (WorldMap.HexCellInfo hexCellInfo in hexCellInfos) { if (WorldMap.IsResourceOnlyType(hexCellInfo.hexType)) { GameObject building = Instantiate( buildingItemList.buildingTypeItemToBuildingItems[1].buildingItems[0].buildingPrefab, hexCellInfo.position, Quaternion.identity, buildingTransform); ResourceDeposit resourceDeposit = worldMap.GetResourceDeposit(hexCellInfo.position); Debug.Assert(resourceDeposit, "Resource Deposit is null"); ResourceExtractor resourceExtractor = building.GetComponent<ResourceExtractor>(); resourceExtractor.SetDeposit(resourceDeposit); resourceExtractor.SetOwnerId(id); worldMap.AddBuildingToHexCell(hexCellInfo.position, building); return; } } }
public override void UseBaseTurn(Unit unit) { //Is there an enemy in an adjoining cell GridCell adjoiningCellContainingEnemy = GetAdjoiningCellContainingEnemy(unit); if (adjoiningCellContainingEnemy != null) { if (unit.CanPerformAction(SelectableActionType.Attack, adjoiningCellContainingEnemy, null)) { unit.PerformAction(SelectableActionType.Attack, adjoiningCellContainingEnemy, null); } } //If not currently moving anywhere... if (unit.target == null) { //See if we can build any mines before we do anything else! foreach (GridCell neighbor in unit.ParentCell.GetNeighbors()) { if (neighbor.ResourceDeposit != null && neighbor.Selectable == null && unit.CanPerformAction(SelectableActionType.Build, neighbor, "0")) { unit.PerformAction(SelectableActionType.Build, neighbor, "0"); } } //After we build mines, find the closest resource deposit in the current grid ResourceDeposit closestDeposit = GetNearestResourceDeposit(unit); //If we found a close resource deposit in the current grid that doesn't currently contain a mine if (closestDeposit != null && unit.CanPerformAction(SelectableActionType.Move, closestDeposit.ParentCell, null)) { //Move to it unit.PerformAction(SelectableActionType.Move, closestDeposit.ParentCell, null); } //If we've hit this point, we've already put mines on every resource deposit in the grid else { //Builds a Builder roughly every 20 turns because that seems right if (unit.Faction.units.Where(u => u.unitType == UnitType.Builder).ToList().Count < (GameStateManager.Instance.TotalRounds / 20) + 1) { foreach (GridCell neighbor in unit.ParentCell.GetNeighbors()) { if (neighbor.Selectable == null && unit.CanPerformAction(SelectableActionType.Build, neighbor, "1")) { unit.PerformAction(SelectableActionType.Build, neighbor, "1"); break; } } } //We want to find a square that has no resource deposits around it so we can surround the base with defenders //If any of the cells around the base has either a resource deposit //or a unit that belongs to another faction //or any friendly unit that isn't a Defender if (unit.ParentCell.GetNeighbors().Where(cell => cell.ResourceDeposit != null || (cell.Selectable != null && (((Unit)cell.Selectable).Faction != unit.Faction || ((Unit)cell.Selectable).unitType != UnitType.Defender))).ToList().Any()) { GridCell emptyCell = GetNearestEmptyCell(unit); if (unit.CanPerformAction(SelectableActionType.Move, emptyCell, null)) { unit.PerformAction(SelectableActionType.Move, emptyCell, null); } } } } }
private void SetResourcePrefabs(int aIForNPCSeed) { LimitedMinedResourceInfo[] hexTypeToLimitedMinedResourceInfo = new LimitedMinedResourceInfo[(int)WorldMap.HexType.AllResources]; foreach (LimitedMinedResourceInfo resourceInfo in limitedMinedResourceInfoList.resourceInfos) { WorldMap.HexType hexType = WorldMap.GameResourceTypeToHexType(resourceInfo.gameResourceType); hexTypeToLimitedMinedResourceInfo[(int)hexType] = resourceInfo; } int currentAIForNPCOffset = aIForNPCSeed; for (int x = 0; x < cellColumns; ++x) { for (int y = 0; y < cellRows; ++y) { WorldMap.HexCell hexCell = worldMap.worldAreaInfo.area[x, y]; if (WorldMap.IsResourceOnlyType(hexCell.hexType)) { GameResourceType gameResourceType = WorldMap.HexTypeToGameResourceType(hexCell.hexType); GameObject resourceDeposit = Instantiate(resourceDepositPrefab, worldMap.GetHexPosition(new Vector2Int(x, y)), Quaternion.identity, resourcesTransform); ResourceSprite resourceSprite = resourceDeposit.GetComponent <ResourceSprite>(); resourceSprite.InitWithGameResourceType(gameResourceType); ResourceDeposit resourceDepositScript = resourceDeposit.GetComponent <ResourceDeposit>(); LimitedMinedResourceInfo limitedMinedResourceInfo = hexTypeToLimitedMinedResourceInfo[(int)hexCell.hexType]; float resourceAmount = limitedMinedResourceInfo.minAmount + Mathf.Pow(hexCell.resourceAmount / maxPossibleResourceValuePerCell, limitedMinedResourceInfo.power) * (limitedMinedResourceInfo.maxAmount - limitedMinedResourceInfo.minAmount); resourceDepositScript.SetResourceType(gameResourceType, resourceAmount); hexCell.indexInResourceArray = (short)worldMap.resourceDepositArray.Count; worldMap.worldAreaInfo.area[x, y] = hexCell; worldMap.resourceDepositArray.Add(resourceDepositScript); worldMap.resourceDepositIndicesArray.Add(new Vector2Int(x, y)); } else if (hexCell.hexType == WorldMap.HexType.Mountain) { GameObject mountain = Instantiate(mountainPrefab, worldMap.GetHexPosition(new Vector2Int(x, y)), Quaternion.identity, mountainsTransform); EnvironmentHeightParameter environmentHeightParameter = mountain.GetComponent <EnvironmentHeightParameter>(); environmentHeightParameter.InitHeight(hexCell.resourceAmount / maxPossibleResourceValuePerCell); } else if (hexCell.hexType == WorldMap.HexType.Crater) { GameObject crater = Instantiate(craterPrefab, worldMap.GetHexPosition(new Vector2Int(x, y)), Quaternion.identity, cratersTransform); EnvironmentHeightParameter environmentHeightParameter = crater.GetComponent <EnvironmentHeightParameter>(); environmentHeightParameter.InitHeight(hexCell.resourceAmount / maxPossibleResourceValuePerCell); } else if (hexCell.hexType == WorldMap.HexType.ColonyMainBase) { GameObject mainBaseLocation = Instantiate(mainBaseLocationPrefab, worldMap.GetHexPosition(new Vector2Int(x, y)), Quaternion.identity, mainBaseLocationsTransform); ColonyTeritory colonyTeritory = mainBaseLocation.GetComponent <ColonyTeritory>(); Vector3[] positions = worldMap.GetHexRings(worldMap.GetHexPosition(new Vector2Int(x, y)), 1, colonyRaduis); bool isPlayer = worldMap.colonyMainBaseArray.Count == 0; colonyTeritory.InitAvailableHexes(new List <Vector3>(positions), isPlayer); if (!isPlayer) { AIForNPC aIForNPC = mainBaseLocation.GetComponent <AIForNPC>(); aIForNPC.worldMap = worldMap; aIForNPC.freezer = freezer; aIForNPC.colonyRaduis = colonyRaduis; aIForNPC.seed = currentAIForNPCOffset; aIForNPC.enabled = true; ++currentAIForNPCOffset; } hexCell.indexInColonyMainBaseArray = (short)worldMap.colonyMainBaseArray.Count; worldMap.worldAreaInfo.area[x, y] = hexCell; worldMap.colonyMainBaseArray.Add(mainBaseLocation); worldMap.colonyMainBaseIndicesArray.Add(new Vector2Int(x, y)); } } } }
void TargetSet(GameObject targetObject) { if(targetObject.GetComponent("ResourceDeposit")) { targetResource = targetObject.GetComponent("ResourceDeposit") as ResourceDeposit; } else if(targetObject.GetComponent("ResourceDepot")) { targetDepot = targetObject.GetComponent("ResourceDepot") as ResourceDepot; } }
public GatherTask(ResourceDeposit resourceDepo) { _resourceDepo = resourceDepo; _type = TaskType.Gather; }
public void AddResourceDeposit(ResourceDeposit deposit) { resourceDeposits.Add(deposit); }
public void onGatherOrder(OrderAction action, ResourceDeposit resource) { selectedObjects.AssignTask(action, new GatherTask(resource)); }
void AddDeposit(ResourceDeposit r) { ResourceDeposits.Add(r.resource, r); }
public void SetDeposit(ResourceDeposit deposit) { hasDeposit = true; this.deposit = deposit; resourceType = deposit.GetResourceType(); }