private void UpdateOxygenSprite(TileOWW tileOWW, float oxygenLevel) { Tile t; if (tileOWW.oxygenLevel > 0) { // Create room graphics t = Resources.Load <Tile>("TileSets/Rooms/Oxygen"); if (tileOWW.GetTileType() == "Hull") { t.color = new Color(0.227451f, 0.7294118f, 0.9960784f, tileOWW.oxygenLevel / 50); } else { t.color = new Color(0.9215686f, 0.5764706f, 0.1176471f); // TODO: Notification } tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t); tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0)); } else { // Remove tile graphics t = null; tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t); tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0)); } }
public void UpdateJob(TileOWW tileOWW) { if (tileOWW == null) { return; } RuleTile t; if (tileOWW.currentJobType != null && // Has a job ((tileOWW.installedFurnitureAltX == null && tileOWW.installedFurnitureAltY == null) || // Is the origin tile of job (tileOWW.installedFurnitureAltX == tileOWW.GetX() && tileOWW.installedFurnitureAltY == tileOWW.GetY()))) // Is the origin tile of job { // Create job graphics t = Resources.Load <RuleTile>("TileSets/Furniture/" + JobQueueController.Instance.ConvertJobTypeToFurnitureType(tileOWW.currentJobType)); tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t); tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0)); } else { // Remove tile graphics t = null; tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t); tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0)); } }
private void TileOxygen(TileOWW originTile, TileOWW nextTile) { // Base case #1 if (nextTile.GetInstalledFurniture()?.GetFurnitureType() == "Wall" || nextTile.GetInstalledFurniture()?.GetFurnitureType() == "Airlock") { return; } // Base case #2 if (!uncheckedTiles.Contains(nextTile)) { return; } // Main oxygenTileGroups[originTile].Add(nextTile); if (uncheckedTiles.Contains(nextTile)) { uncheckedTiles.Remove(nextTile); } // Base case #3 // Note we still add this tile to the group without spreading to other tiles if (nextTile.GetTileType() == "Empty") { return; } // Spread to next tiles TileOWW tileNorth = WorldController.Instance.GetWorld().GetTileAt(nextTile.GetX(), nextTile.GetY() + 1); TileOWW tileEast = WorldController.Instance.GetWorld().GetTileAt(nextTile.GetX() + 1, nextTile.GetY()); TileOWW tileSouth = WorldController.Instance.GetWorld().GetTileAt(nextTile.GetX(), nextTile.GetY() - 1); TileOWW tileWest = WorldController.Instance.GetWorld().GetTileAt(nextTile.GetX() - 1, nextTile.GetY()); if (tileNorth != null) { { TileOxygen(originTile, tileNorth); } } if (tileEast != null) { { TileOxygen(originTile, tileEast); } } if (tileSouth != null) { { TileOxygen(originTile, tileSouth); } } if (tileWest != null) { { TileOxygen(originTile, tileWest); } } }
// Overloaded method for planing single furniture jobs at once public void PlanFurniture(TileOWW furnitureTile, FurnitureType furnitureType) { if (furnitureTile != null) { // Check validity for multi-tile for (int i = 0; i < furnitureType.sizeX; i++) { for (int j = 0; j < furnitureType.sizeY; j++) { TileOWW temp = WorldController.Instance.GetWorld().GetTileAt(furnitureTile.GetX() + i, furnitureTile.GetY() + j); if (temp.currentJobType != null) { Debug.Log("Unable to place job baceause tile already had an existing job: " + temp.currentJobType); return; // Failed to place } } } Action placeFurnitureAction = delegate() { PlaceFurniture(furnitureTile, furnitureType.title); }; Job job; // Allow certain furniture to overwrite others by creating a prerequisite removal job if (furnitureTile.GetInstalledFurniture()?.GetFurnitureType() == "Wall" && furnitureType.title == "Airlock") { Action removeExistingFurnitureAction = delegate() { RemoveFurniture(furnitureTile); }; Job prerequisiteJob = new Job(removeExistingFurnitureAction, furnitureTile, 2, "Remove Wall", JobPriority.Medium); job = new Job(placeFurnitureAction, furnitureTile, furnitureType.installTime, "Build " + furnitureType.title, JobPriority.Medium, prerequisiteJob); } else { job = new Job(placeFurnitureAction, furnitureTile, furnitureType.installTime, "Build " + furnitureType.title, JobPriority.Medium); } furnitureTile.currentJobType = job.GetJobType(); JobQueueController.BuildersJobQueue.AddJob(job); // Invoice CurrencyController.Instance.DeductBankBalance(furnitureType.cost); // Multi-tile furniture items for (int i = 0; i < furnitureType.sizeX; i++) { for (int j = 0; j < furnitureType.sizeY; j++) { TileOWW temp = WorldController.Instance.GetWorld().GetTileAt(furnitureTile.GetX() + i, furnitureTile.GetY() + j); temp.currentJobType = furnitureTile.currentJobType; temp.installedFurnitureAltX = furnitureTile.GetX(); temp.installedFurnitureAltY = furnitureTile.GetY(); } } } }
public Job(Action action, TileOWW tileOWW, float jobTime, string jobType, JobPriority jobPriority, Job prerequisiteJob = null, bool tileExcludeOtherJobs = true) { this.action = action; this.tileOWW = tileOWW; this.jobTime = jobTime; this.jobType = jobType; this.prerequisiteJob = prerequisiteJob; this.tileExcludeOtherJobs = tileExcludeOtherJobs; this.jobPriority = jobPriority; // The tile won't hold a reference to this job. Likely because a character is wandering. if (tileExcludeOtherJobs == true) { tileOWW.currentJobType = jobType; } // Set default job pos jobPosX = tileOWW.GetX(); jobPosY = tileOWW.GetY(); if (jobTime < 0.1f) { Debug.LogWarning("Job time is too short! Prerequisites may be skipped"); } }
private void CreateRemoveFurnitureAction(TileOWW tile, int offsetX = 0, int offsetY = 0) { Action removeFurnitureAction = delegate() { RemoveFurniture(tile); }; Job j = new Job(removeFurnitureAction, tile, 2, "Remove " + tile.GetInstalledFurniture().GetFurnitureType(), JobPriority.Medium); j.SetAltPosition(tile.GetX() + offsetX, tile.GetY() + offsetY); tile.currentJobType = j.GetJobType(); JobQueueController.BuildersJobQueue.AddJob(j); }
// Update is called once per frame void Update() { transform.localScale = Vector3.Lerp(new Vector3(Camera.main.orthographicSize / 500, Camera.main.orthographicSize / 500, 1), transform.localScale, 0.8f); transform.localPosition = new Vector3(tile.GetX() + 0.85f, tile.GetY() + 0.5f, 0); tileType.text = tile.GetTileType(); // Installed furniture if (tile.GetInstalledFurniture() != null) { if (furniturePanelGO == null) { furniturePanelGO = Instantiate(furniturePanelPrefab, parentGO.transform); } furniturePanelGO.GetComponent <FurniturePanel>().furnitureType.text = tile.GetInstalledFurniture().GetFurnitureType(); } /* * // Installed furniture alt position * else if (tile.installedFurnitureAltX != null && tile.installedFurnitureAltY != null) * { * if (tile.installedFurnitureAltX != tile.GetX() || tile.installedFurnitureAltY != tile.GetY()) * { * if (furniturePanelGO == null) * { * furniturePanelGO = Instantiate(furniturePanelPrefab, parentGO.transform); * } * TileOWW furnitureTile = WorldController.Instance.GetWorld().GetTileAt((int)tile.installedFurnitureAltX, (int)tile.installedFurnitureAltY); * furniturePanelGO.GetComponent<FurniturePanel>().furnitureType.text = furnitureTile.GetInstalledFurniture().GetFurnitureType() + " (from alt tile)"; * } * } */ else { if (furniturePanelGO != null) { Destroy(furniturePanelGO); } } // Current job if (tile.currentJobType != null) { if (jobPanelGO == null) { jobPanelGO = Instantiate(jobPanelPrefab, parentGO.transform); } jobPanelGO.GetComponent <JobPanel>().jobType.text = tile.currentJobType; } else { if (jobPanelGO != null) { Destroy(jobPanelGO); } } }
public void UpdateRoom(TileOWW tileOWW) { RuleTile t; if (tileOWW.GetRoomType() != null) { // Create room graphics t = Resources.Load <RuleTile>("TileSets/Rooms/" + tileOWW.GetRoomType()); tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t); tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0)); } else { // Remove tile graphics t = null; tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t); tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0)); } }
// Saving Job objects not supported! Use JobSerializable instead public JobSerializable ToJobSerializable() { JobSerializable p = null; if (prerequisiteJob != null) { p = prerequisiteJob.ToJobSerializable(); } return(new JobSerializable(tileOWW.GetX(), tileOWW.GetY(), jobPosX, jobPosY, jobTime, jobType, jobPriority, tileExcludeOtherJobs, p)); }
// TODO: Return true before marking off the other tiles as checked!! private bool CheckTile(TileOWW tile, List <TileOWW> tilesToCheck) { if (tilesToCheck.Contains(tile)) { tilesToCheck.Remove(tile); bool isSuccessful = false; if (CheckTile(WorldController.Instance.GetWorld().GetTileAt(tile.GetX(), tile.GetY() + 1), tilesToCheck)) { isSuccessful = true; } if (CheckTile(WorldController.Instance.GetWorld().GetTileAt(tile.GetX(), tile.GetY() - 1), tilesToCheck)) { isSuccessful = true; } if (CheckTile(WorldController.Instance.GetWorld().GetTileAt(tile.GetX() + 1, tile.GetY()), tilesToCheck)) { isSuccessful = true; } if (CheckTile(WorldController.Instance.GetWorld().GetTileAt(tile.GetX() - 1, tile.GetY()), tilesToCheck)) { isSuccessful = true; } if (isSuccessful) { return(true); } if (tile.GetInstalledFurniture()?.GetFurnitureType() == "Charging Pad") // TODO: The validity will be horrible { return(true); } return(false); } else { return(false); } }
public void UpdateTile(TileOWW tile) { Tile t; if (!tileObjectMap.ContainsKey(tile)) { // The tile might not exist when loading a game from file t = ScriptableObject.CreateInstance <Tile>(); t.name = tile.GetX() + "_" + tile.GetY(); t.sprite = Resources.Load <Sprite>("Images/Tiles/" + tile.GetTileType()); tilemap.SetTile(new Vector3Int(tile.GetX(), tile.GetY(), 0), t); tileObjectMap.Add(tile, t); } else { t = tileObjectMap[tile]; t.sprite = Resources.Load <Sprite>("Images/Tiles/" + tile.GetTileType()); tilemap.RefreshTile(new Vector3Int(tile.GetX(), tile.GetY(), 0)); } }
public void PlaceFurniture(TileOWW tile, string furnitureType) { tile.SetInstalledFurniture(new InstalledFurniture(furnitureType)); // Add to map of furnitureType TileOWW if (!furnitureTileOWWMap.ContainsKey(furnitureType)) { furnitureTileOWWMap.Add(furnitureType, new List <TileOWW>()); } furnitureTileOWWMap[furnitureType].Add(tile); // If engines built, update ship speed // TODO: Different types of engines if (furnitureType == "Engine") { // TODO: Different speeds per engine JourneyController.Instance.shipSpeedMax = furnitureTileOWWMap[furnitureType].Count * 5; } // Multi-tile references if (!furnitureTypes.ContainsKey(furnitureType)) { Debug.LogError("This key wasnt found: " + furnitureType); } for (int i = 0; i < furnitureTypes[furnitureType].sizeX; i++) { for (int j = 0; j < furnitureTypes[furnitureType].sizeY; j++) { TileOWW temp = WorldController.Instance.GetWorld().GetTileAt(tile.GetX() + i, tile.GetY() + j); temp.currentJobType = null; temp.installedFurnitureAltX = tile.GetX(); temp.installedFurnitureAltY = tile.GetY(); emptyHullTiles.Remove(tile); } } ObjectiveController.Instance.CheckObjectives(); }
public void UpdateFurniture(TileOWW tileOWW) { RuleTile t; if (tileOWW.GetInstalledFurniture() != null) { // Create tile graphics t = Resources.Load <RuleTile>("TileSets/Furniture/" + tileOWW.GetInstalledFurniture().GetFurnitureType()); tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t); tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0)); // Pathfinding if (!tileOWW.GetIsWalkable()) { // Create NavMeshObstacle GameObject GameObject go = new GameObject(); go.name = "NavMeshBlocking: (" + tileOWW.GetX() + " ," + tileOWW.GetY() + ")"; go.transform.parent = Instance.transform; go.transform.position = new Vector3(tileOWW.GetX(), tileOWW.GetY(), 0); NavMeshObstacle nma = go.AddComponent <NavMeshObstacle>(); nma.center = new Vector3(0.5f, 0.5f); // Set parameters depending on the furniture type if (tileOWW.GetInstalledFurniture().GetFurnitureType() == "Wall") { nma.carving = true; nma.size = new Vector3(0.7f, 0.7f, 1f); } else if (tileOWW.GetInstalledFurniture().GetFurnitureType() == "Airlock") { nma.size = new Vector3(1f, 1f, 1f); go.AddComponent <AirlockDoor>(); BoxCollider2D boxCollider = go.AddComponent <BoxCollider2D>(); boxCollider.isTrigger = true; boxCollider.offset = new Vector2(0.5f, 0.5f); Rigidbody2D rigidbody = go.AddComponent <Rigidbody2D>(); rigidbody.constraints = RigidbodyConstraints2D.FreezeAll; } tileNavBlockMap.Add(tileOWW, go); } } else { // Remove tile graphics t = null; tilemap.SetTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0), t); tilemap.RefreshTile(new Vector3Int(tileOWW.GetX(), tileOWW.GetY(), 0)); if (tileNavBlockMap.ContainsKey(tileOWW)) { if (tileNavBlockMap[tileOWW] != null) { // Remove NavMeshObstacle GameObject GameObject go = tileNavBlockMap[tileOWW]; tileNavBlockMap.Remove(tileOWW); Destroy(go); } } } }
public bool CheckFurniturePreviewValid(TileOWW tile, FurnitureType furnitureType) { if (furnitureType.cost > CurrencyController.Instance.GetBankBalance()) { // Debug.Log("Couldn't affoard."); return(false); } // Check all tiles of multi-tile furniture for (int i = 0; i < furnitureType.sizeX; i++) { for (int j = 0; j < furnitureType.sizeY; j++) { TileOWW t = WorldController.Instance.GetWorld().GetTileAt(tile.GetX() + i, tile.GetY() + j); if ((t.GetTileType() == "Hull" && furnitureType.exteriorOnly) || (t.GetTileType() == "Empty" && !furnitureType.exteriorOnly)) { // Debug.Log("Interior / exterior check failed."); return(false); } if (t.installedFurnitureAltX != null || t.installedFurnitureAltY != null) { //Allow certain furniture to overwrite others if (t.GetInstalledFurniture()?.GetFurnitureType() == "Wall" && furnitureType.title == "Airlock") { return(true); } // Debug.Log("Multi-tile furniture check failed."); return(false); } if (t.GetInstalledFurniture() != null) { //Allow certain furniture to overwrite others if (t.GetInstalledFurniture().GetFurnitureType() == "Wall" && furnitureType.title == "Airlock") { return(true); } // Debug.Log("Installed furniture check failed"); return(false); } if (t.currentJobType != null) { // Debug.Log("Existing job check failed."); return(false); } } } // All checks passed, furniture is valid. return(true); }
public void RemoveFurniture(TileOWW tile) { string furnitureType = tile.GetInstalledFurniture()?.GetFurnitureType(); // 'Airlock' may be in 'Airlock Open' state if (furnitureType == "Airlock Open") { furnitureType = "Airlock"; } // Update pathfinding if (furnitureType == "Wall") { // TODO: reset all failed jobs } tile.RemoveInstalledFurniture(); // Multi-tile references for (int i = 0; i < furnitureTypes[furnitureType].sizeX; i++) { for (int j = 0; j < furnitureTypes[furnitureType].sizeY; j++) { TileOWW temp = WorldController.Instance.GetWorld().GetTileAt(tile.GetX() + i, tile.GetY() + j); temp.installedFurnitureAltX = null; temp.installedFurnitureAltY = null; if (tile.GetTileType() == "Hull") { emptyHullTiles.Add(tile); } } } // Remove from map of furnitureType TileOWW while (furnitureTileOWWMap[furnitureType].Contains(tile)) { furnitureTileOWWMap[furnitureType].Remove(tile); } ObjectiveController.Instance.CheckObjectives(); }
// Create build jobs for Hull public Tuple <List <TileOWW>, List <TileOWW>, List <TileOWW> > PreviewHull(int start_x, int end_x, int start_y, int end_y, bool includeWalls) { List <TileOWW> hull_tiles = new List <TileOWW>(); List <TileOWW> wall_tiles = new List <TileOWW>(); List <TileOWW> floor_tiles = new List <TileOWW>(); ClearPreviews(); int estimatedCost = 0; // Loop through all the tiles for (int x = start_x; x <= end_x; x++) { for (int y = start_y; y <= end_y; y++) { TileOWW t = WorldController.Instance.GetWorld().GetTileAt(x, y); if (t != null) { // Check valid // if (t.GetTileType() == "Empty") hull_tiles.Add(t); // Check outlines if including walls if (includeWalls && (t.GetX() == start_x || t.GetX() == end_x || t.GetY() == start_y || t.GetY() == end_y)) { // Check valid if (t.GetInstalledFurniture() == null && t.installedFurnitureAltX == null && // not apart of a multi-tile furniture t.installedFurnitureAltY == null) { wall_tiles.Add(t); CreatePreview(validPreviewPrefab, "Wall", x, y); estimatedCost += WALL_COST; estimatedCost += HULL_COST; } else { CreatePreview(invalidPreviewPrefab, "Wall", x, y); } } else { if (t.GetTileType() == "Empty") { floor_tiles.Add(t); CreatePreview(validPreviewPrefab, "Hull", x, y); estimatedCost += HULL_COST; } else { CreatePreview(invalidPreviewPrefab, "Hull", x, y); } } } } } // Consider materials already in stock /* * if (CargoController.Instance.unusedShipStock.ContainsKey("Hull")) { * estimatedCost -= (CargoController.Instance.unusedShipStock["Hull"] * HULL_COST); * } * * if (CargoController.Instance.unusedShipStock.ContainsKey("Wall")) * { * estimatedCost -= (CargoController.Instance.unusedShipStock["Wall"] * WALL_COST); * } */ // Display price UI InputController.Instance.currentBuildPrice = estimatedCost; // Check funds if (estimatedCost > CurrencyController.Instance.GetBankBalance()) { // reset all previews invalid ClearPreviews(); for (int x = start_x; x <= end_x; x++) { for (int y = start_y; y <= end_y; y++) { TileOWW t = WorldController.Instance.GetWorld().GetTileAt(x, y); if (t != null) { // Check outlines if (includeWalls && (t.GetX() == start_x || t.GetX() == end_x || t.GetY() == start_y || t.GetY() == end_y)) { CreatePreview(invalidPreviewPrefab, "Wall", x, y); } else { CreatePreview(invalidPreviewPrefab, "Hull", x, y); } } } } // Can NOT affoard this, so return NO valid tiles return(null); } // Can affoard this, so return valid tiles else { return(Tuple.Create(hull_tiles, wall_tiles, floor_tiles)); } }
public List <TileOWW> PreviewWall(int start_x, int end_x, int start_y, int end_y) { List <TileOWW> wall_tiles = new List <TileOWW>(); ClearPreviews(); int estimatedCost = 0; for (int x = start_x; x <= end_x; x++) { for (int y = start_y; y <= end_y; y++) { TileOWW t = WorldController.Instance.GetWorld().GetTileAt(x, y); if (t != null) { // Check outlines if (t.GetX() == start_x || t.GetX() == end_x || t.GetY() == start_y || t.GetY() == end_y) { // Check valid if (t.GetInstalledFurniture() == null && t.GetTileType() == "Hull" && t.installedFurnitureAltX == null && // not apart of a multi-tile furniture t.installedFurnitureAltY == null) { wall_tiles.Add(t); CreatePreview(validPreviewPrefab, "Wall", x, y); estimatedCost += 50; } else { CreatePreview(invalidPreviewPrefab, "Wall", x, y); } } } } } // Display price UI InputController.Instance.currentBuildPrice = estimatedCost; if (estimatedCost > CurrencyController.Instance.GetBankBalance()) { ClearPreviews(); for (int x = start_x; x <= end_x; x++) { for (int y = start_y; y <= end_y; y++) { TileOWW t = WorldController.Instance.GetWorld().GetTileAt(x, y); if (t != null) { // Check outlines if (t.GetX() == start_x || t.GetX() == end_x || t.GetY() == start_y || t.GetY() == end_y) { CreatePreview(invalidPreviewPrefab, "Wall", x, y); } } } } return(null); } else { return(wall_tiles); } }