private void UpdatePlayerContribution(PlayerController player, TileInfection ti, double reduction) { double distance = MathUtils.Distance(player.City.X, player.City.Z, ti.X, ti.Z); double contribution = Math.Sqrt(distance) * reduction; player.infectionContribution += contribution; }
public bool IncreaseTileInfection(int x, int z, double increase) { float maxInfection = maxInfectionNoiseMap[x, z] * 100; int index = IndexOfTileInfection(x, z); if (index != -1) { if (tileInfections[index].Infection < maxInfection) { double newInfection = Math.Min(maxInfection, tileInfections[index].Infection + increase); tileInfections[index] = new TileInfection(x, z, newInfection); } else { return(false); } } else { AddNewTileInfection(x, z, increase); } return(true); }
private void UpdateTileInfectionTransparency(GameObject go, TileInfection ti) { Renderer renderer = go.GetComponent <Renderer>(); double cutoff = (100 - ti.Infection) / 100; if (cutoff <= 0) { renderer.material = fullInfectionMaterial; //When full infection, use shared material that never changes to increase performance. } else { renderer.material = partialInfectionMaterial; renderer.material.SetFloat("_Cutoff", (float)cutoff); } }
private void SpreadInfection(TileInfection fromTile, double increased) { List <Coordinate> coords = WorldController.instance.worldBuilder.GetCoordinatesNear(fromTile.X, fromTile.Z, Settings.World_Infection_SpreadDistance); Utils.Shuffle(coords); foreach (var coord in coords) { if (IncreaseTileInfection(coord.x, coord.z, increased)) { return; } } // Did not managed to spread, ignore this tile in the future _spreadingTileInfectionIndexes.Remove(IndexOfTileInfection(fromTile.X, fromTile.Z)); }
private void IncreaseOrSpreadInfection(TileInfection ti, double increased) { float maxInfection = maxInfectionNoiseMap[ti.X, ti.Z] * 100; if (ti.Infection <= 0) { return; } else if (ti.Infection >= maxInfection) { SpreadInfection(ti, increased); } else { IncreaseTileInfection(ti.X, ti.Z, increased); } }
private void SpawnOrUpdateTileInfection(TileInfection ti) { //Debug.Log("Changed infection at " + ti); if (tileInfectionGameObjects[ti.X, ti.Z] == null) { GameObject tileInfectionGO = (GameObject)Instantiate(tileInfectionPrefab, parent.transform); tileInfectionGO.transform.position = new Vector3(ti.X, tileInfectionGO.transform.position.y, ti.Z); tileInfectionGameObjects[ti.X, ti.Z] = tileInfectionGO; } if (ti.Infection <= 0) { Destroy(tileInfectionGameObjects[ti.X, ti.Z]); } else { UpdateTileInfectionTransparency(tileInfectionGameObjects[ti.X, ti.Z], ti); } }
public double DecreaseTileInfection(int x, int z, PlayerController player, int maxReduction) { int index = IndexOfTileInfection(x, z); if (index != -1) { double newTileInfectionValue = Math.Max(0, tileInfections[index].Infection - maxReduction); double reduction = tileInfections[index].Infection - newTileInfectionValue; tileInfections[index] = new TileInfection(x, z, newTileInfectionValue); _AllowAdjacentTilesToSpreadAgain(x, z); UpdatePlayerContribution(player, tileInfections[index], reduction); return(newTileInfectionValue); } else // Not found { return(0); } }