public void BuildBuilding(Building building) { float baseHeight = GetTileAtPosition(building.coveredTiles [0]).transform.position.y; if (!GameManager.isLoadingFromSave) { List <ResourcePickup> resourcesToConsume = new List <ResourcePickup> (); foreach (Vector2 pos in building.coveredTiles) { resourcesToConsume.Add(ResourcePickup.GetAtPosition(pos)); tiles [pos].MoveTile(baseHeight); } ConsumeResources(resourcesToConsume); } else { foreach (Vector2 pos in building.coveredTiles) { tiles [pos].MoveTile(baseHeight); } } building.Build(); buildings.Add(building); if (building is ProductionBuilding) { Transform pad = (building as ProductionBuilding).pad; if (pad != null) { Vector2 pos2D = PosToV2(pad.position); pads.Add(pos2D, pad.position.y); } } }
IEnumerator BuildBuilding(Building building) { isBuilding = true; buildBar.transform.position = building.gameObject.transform.position - new Vector3(building.info.anchorOffset.x, 0, building.info.anchorOffset.y); buildBar.gameObject.SetActive(true); barUI.transform.localScale = new Vector3(0, 1, 1); float endTime = Time.time + buildTime; while (isBuilding && (Time.time < endTime)) { float timeLeft = endTime - Time.time; barUI.transform.localScale = new Vector3(1 - (timeLeft / buildTime), 1, 1); yield return(null); } if (isBuilding) { if (building.state == Building.BuildingState.Blueprint) { blueprints.Remove(ResourcePickup.GetAtPosition(building.coveredTiles [0])); tm.BuildBuilding(building); } else if (building.state == Building.BuildingState.Inactive) { tm.BreakDownBuilding(building); } } isBuilding = false; buildBar.gameObject.SetActive(false); SavedGame.UpdateBuildings(); }
public void MoveTile(float newHeight) { tile.transform.position = new Vector3(tile.transform.position.x, newHeight, tile.transform.position.z); Vector2 posV2 = TerrainManager.PosToV2(tile.transform.position); if (ResourcePickup.IsAtPosition(posV2)) { ResourcePickup resource = ResourcePickup.GetAtPosition(posV2); float resourceHeight = TerrainManager.instance.PadAtPosition(posV2).GetValueOrDefault(tile.transform.position.y); for (int i = 0; i < resource.gameObjects.Count; i++) { resource.gameObjects[i].transform.position = new Vector3(resource.gameObjects[i].transform.position.x, resourceHeight + (TerrainManager.instance.stackHeight * i), resource.gameObjects[i].transform.transform.position.z); } resource.UpdatePosition(); } }
public void PickUpPickup() { Vector2 playerPos = TerrainManager.PosToV2(playerTransform.position); if (ResourcePickup.IsAtPosition(playerPos)) { CollectResource(ResourcePickup.GetAtPosition(playerPos)); } else if (WeaponPickup.IsAtPosition(playerPos)) { PickupWeapon(WeaponPickup.GetAtPosition(playerPos)); } else if (AugmentPickup.IsAtPosition(playerPos)) { PickupAugment(AugmentPickup.GetAtPosition(playerPos)); } }
public virtual void ProduceResources() { turnsUntilNextResource = turnWaitPerResource; for (int i = 0; i < resourcesProducedPerCycle; i++) { if (hasLimitedSupply && supply <= 0) { break; } if (exceedsPadCapacity) { break; } TerrainManager.instance.SpawnResource(position: spawnPos, info: ResourceInfo.GetInfoFromType(resourceType), island: island); if (hasLimitedSupply) { supply -= 1; } } if (movesResources) { ResourcePickup.GetAtPosition(TerrainManager.PosToV2(spawnPos)).AnimateMove(productionCenter.position, false, resourcesProducedPerCycle); } SavedGame.UpdateBuildingSupply(this); if (!autoCycles) { state = BuildingState.Waiting; } if (hasLimitedSupply && supply <= 0) { Deactivate(); } }
public ResourcePickup SpawnResource(Vector3 position, ResourceInfo info, Island island, bool initialSpawn = false) { Vector2 posV2 = PosToV2(position); if (island == null || WeaponPickup.IsAtPosition(posV2)) { return(null); } float startingHeight; GameObject buildingObj = GetBuildingAtPosition(posV2); if (buildingObj != null) { Building building = buildingObj.GetComponent <Building> (); startingHeight = building.height + GetTileAtPosition(posV2).transform.position.y; if (building is ProductionBuilding) { (building as ProductionBuilding).SpawnTop(); } } else { startingHeight = PadAtPosition(posV2).GetValueOrDefault(position.y); } List <Vector2> allDirections = new List <Vector2> () { Vector2.zero, Vector2.right, Vector2.up, Vector2.left, Vector2.down }; foreach (Vector2 direction in allDirections) { Vector2 posToCheck = posV2 + direction; // island = tiles [posToCheck].island; if (GetTileAtPosition(posToCheck) != null) { float posHeightOffset = GetTileAtPosition(posToCheck).transform.position.y - GetTileAtPosition(posV2).transform.position.y; if (ResourcePickup.IsAtPosition(posToCheck)) { ResourcePickup curResource = ResourcePickup.GetAtPosition(posToCheck); // print ("Dir: " + direction + " Resource At Pos, Type: " + curResource.info.type); if (curResource.info.type == info.type) { GameObject resourceGO = CreateResource(info, island.transform); resourceGO.transform.position = new Vector3(posToCheck.x, 0f, posToCheck.y); curResource.gameObjects.Add(resourceGO); resourceGO.transform.Translate(Vector3.up * ((stackHeight * (curResource.gameObjects.Count - 1)) + startingHeight + posHeightOffset)); if (!initialSpawn && !GameManager.isLoadingFromSave) { UpdateResources(); SavedGame.UpdatePickups(); } return(curResource); } } else { // print ("Dir: " + direction + " creating new resource"); GameObject resourceGO = CreateResource(info, island.transform); float height = 0f; if (GetTileAtPosition(posToCheck)) { height = GetTileAtPosition(posToCheck).transform.position.y; } resourceGO.transform.position = new Vector3(posToCheck.x, 0f, posToCheck.y); ResourcePickup resource = new ResourcePickup(info, resourceGO, island); pickups.Add(posToCheck, resource); island.pickups.Add(resource); resourceGO.transform.Translate(Vector3.up * (startingHeight + posHeightOffset)); if (!initialSpawn && !GameManager.isLoadingFromSave) { SavedGame.UpdatePickups(); UpdateResources(); } return(resource); } } else { // print ("Dir: " + direction + " no tile at pos:" + posToCheck); } } return(null); }
Craftable GetCraftableForResource(ResourcePickup anchorResource, out Vector3 spawnPos) { ResourceInfo.ResourceType tileType = tm.tiles[anchorResource.position].resourceType; List <Crafting.Recipe> possibleRecipes = GetPossibleRecipes(new Stack(anchorResource.info.type, tileType, anchorResource.gameObjects.Count)); bool hasRecipe = false; Crafting.Recipe confirmedRecipe = new Crafting.Recipe(); List <ResourcePickup> affectedResources = new List <ResourcePickup> (); foreach (var recipe in possibleRecipes) { int correct = 0; for (int y = 0; y < recipe.resources.GetLength(1); y++) { for (int x = 0; x < recipe.resources.GetLength(0); x++) { Vector2 posToCheck = new Vector2(anchorResource.position.x + x, anchorResource.position.y + y); if (ResourcePickup.IsAtPosition(posToCheck) && tm.PadAtPosition(posToCheck) == null) { ResourcePickup resourceAtPos = ResourcePickup.GetAtPosition(posToCheck); if (resourceAtPos.island.buildable) { if (resourceAtPos.info.type == recipe.resources [x, y].resourceType && resourceAtPos.gameObjects.Count == recipe.resources [x, y].count) { // check tile ResourceInfo.ResourceType curTileType = tm.tiles [posToCheck].resourceType; if (curTileType == recipe.resources [x, y].tileType) { affectedResources.Add(resourceAtPos); correct++; } } } } } } if (correct >= recipe.resources.Length) { hasRecipe = true; confirmedRecipe = recipe; break; } } if (hasRecipe) { Craftable craftableInfo = craftableInfos [confirmedRecipe.name]; spawnPos = anchorResource.gameObjects[0].transform.position + new Vector3(craftableInfo.anchorOffset.x, 0, craftableInfo.anchorOffset.y); if (confirmedRecipe.type != Recipe.RecipeType.Building) { tm.ConsumeResources(affectedResources); } return(craftableInfo); } else { spawnPos = Vector3.zero; return(null); } }