void Update() { if (GameMaster.gameSpeed == 0) { return; } float t = Time.deltaTime * GameMaster.gameSpeed; //WORKSITES if (deletedWorksites.Count > 0) { foreach (int i in deletedWorksites) { worksites.RemoveAt(i); } deletedWorksites.Clear(); } if (worksite_addlist.Count > 0) { foreach (Worksite w in worksite_addlist) { worksites.Add(w); } worksite_addlist.Clear(); } if (worksites.Count > 0) { foreach (Worksite w in worksites) { w.WorkUpdate(t); } } // ENERGY CONSUMPTION if (energySurplus > 0) { if (accumulateEnergy) { energyStored += energySurplus * Time.deltaTime * GameMaster.gameSpeed; if (energyStored > totalEnergyCapacity) { energyStored = totalEnergyCapacity; } } } else { energyStored += energySurplus * Time.deltaTime * GameMaster.gameSpeed; if (energyStored < 0) { // отключение потребителей энергии до выравнивания UIController.current.MakeAnnouncement(Localization.GetAnnouncementString(GameAnnouncements.PowerFailure)); energyStored = 0; int i = powerGrid.Count - 1; while (i >= 0 && energySurplus < 0) { if (powerGrid[i].energySurplus < 0) { ElementPowerSwitch(i, false); } i--; } } } // STARVATION PROBLEM float foodSupplyHappiness = 1; if (starvationTimer > 0) { starvationTimer -= t; if (starvationTimer < 0) { starvationTimer = starvationTime; } float pc = starvationTimer / starvationTime; foodSupplyHappiness = FOOD_PROBLEM_HAPPINESS_LIMIT * pc; if (pc < 0.5f) { pc /= 2f; KillCitizens((int)(citizenCount * (1 - pc))); } } else { float monthFoodReserves = citizenCount * FOOD_CONSUMPTION * GameMaster.DAYS_IN_WEEK * GameMaster.WEEKS_IN_MONTH; foodSupplyHappiness = FOOD_PROBLEM_HAPPINESS_LIMIT + (1 - FOOD_PROBLEM_HAPPINESS_LIMIT) * (storage.standartResources[ResourceType.FOOD_ID] / monthFoodReserves); } //HOUSING PROBLEM housingTimer -= t; if (housingTimer <= 0) { if (totalLivespace < citizenCount) { int tentsCount = (citizenCount - totalLivespace) / 4; if (tentsCount > 0) { int step = 1, xpos, zpos; xpos = hq.basement.pos.x; zpos = hq.basement.pos.z; Chunk colonyChunk = hq.basement.myChunk; while (step < Chunk.CHUNK_SIZE / 2 && tentsCount > 0) { for (int n = 0; n < (step * 2 + 1); n++) { SurfaceBlock correctSurface = colonyChunk.GetSurfaceBlock(xpos + step - n, zpos + step); if (correctSurface == null) { correctSurface = colonyChunk.GetSurfaceBlock(xpos + step - n, zpos - step); } if (correctSurface != null) { List <PixelPosByte> positions = correctSurface.GetRandomCells(tentsCount); if (positions.Count > 0) { tentsCount -= positions.Count; for (int j = 0; j < positions.Count; j++) { House tent = Structure.GetNewStructure(Structure.HOUSE_0_ID) as House; tent.SetBasement(correctSurface, positions[j]); } } } } step++; } } } housingTimer = HOUSING_TIME; } float housingHappiness = 1; if (housingLevel == 0) { housingHappiness = HOUSE_PROBLEM_HAPPINESS_LIMIT; } else { if (totalLivespace < citizenCount) { float demand = citizenCount - totalLivespace; housingHappiness = HOUSE_PROBLEM_HAPPINESS_LIMIT + (1 - HOUSE_PROBLEM_HAPPINESS_LIMIT) * (1 - demand / ((float)(citizenCount))); } else { housingHappiness = housingLevel / 5f; } } //HEALTHCARE if (health_coefficient < 1 && hospitals_coefficient > 0) { health_coefficient += hospitals_coefficient * t * gears_coefficient * 0.001f; } float healthcareHappiness = HEALTHCARE_PROBLEM_HAPPINESS_LIMIT + (1 - HEALTHCARE_PROBLEM_HAPPINESS_LIMIT) * hospitals_coefficient; healthcareHappiness *= health_coefficient; // HAPPINESS CALCULATION happiness_coefficient = 1; if (housingHappiness < happiness_coefficient) { happiness_coefficient = housingHappiness; } if (healthcareHappiness < happiness_coefficient) { happiness_coefficient = healthcareHappiness; } if (foodSupplyHappiness < happiness_coefficient) { happiness_coefficient = foodSupplyHappiness; } // BIRTHRATE if (birthrateCoefficient != 0) { if (birthrateCoefficient > 0) { realBirthrate = birthrateCoefficient * Hospital.hospital_birthrate_coefficient * health_coefficient * happiness_coefficient * (1 + storage.standartResources[ResourceType.FOOD_ID] / 500f) * t; if (peopleSurplus > 1) { int newborns = (int)peopleSurplus; AddCitizens(newborns); peopleSurplus -= newborns; } } else { realBirthrate = birthrateCoefficient * (1.1f - health_coefficient) * t; if (peopleSurplus < -1) { deathCredit++; peopleSurplus++; } } } peopleSurplus += realBirthrate; }
public void SpreadMinerals(SurfaceBlock surface) { if (surface == null) { return; } int maxObjectsCount = SurfaceBlock.INNER_RESOLUTION * SurfaceBlock.INNER_RESOLUTION / 2, positionsLeft; List <PixelPosByte> positions = surface.GetRandomCells(maxObjectsCount); if (positions.Count == 0) { return; } maxObjectsCount = positions.Count; positionsLeft = maxObjectsCount; List <HarvestableResource> allBoulders = new List <HarvestableResource>(); int containersCount = 0; if (Random.value < metalK_abundance * 10) { containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalK_abundance * Random.value); if (containersCount != 0) { int i = 0; while (i < containersCount && positionsLeft > 0) { HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource; hr.SetResources(ResourceType.metal_K_ore, 1 + Random.value * 100 * metalK_abundance); allBoulders.Add(hr); positionsLeft--; i++; } } } if (Random.value < metalM_abundance * 10 && positionsLeft > 0) { containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalM_abundance * Random.value); if (containersCount != 0) { int i = 0; while (i < containersCount && positionsLeft > 0) { HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource; hr.SetResources(ResourceType.metal_M_ore, 1 + Random.value * 100 * metalM_abundance); allBoulders.Add(hr); positionsLeft--; i++; } } } if (Random.value < metalE_abundance * 10 && positionsLeft > 0) { containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalE_abundance * Random.value); if (containersCount != 0) { int i = 0; while (i < containersCount && positionsLeft > 0) { HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource; hr.SetResources(ResourceType.metal_E_ore, 1 + Random.value * 100 * metalE_abundance); allBoulders.Add(hr); positionsLeft--; i++; } } } if (Random.value < metalN_abundance * 10 && positionsLeft > 0) { containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalN_abundance * Random.value); if (containersCount != 0) { int i = 0; while (i < containersCount && positionsLeft > 0) { HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource; hr.SetResources(ResourceType.metal_N_ore, 1 + Random.value * 100 * metalN_abundance); allBoulders.Add(hr); positionsLeft--; i++; } } } if (Random.value < metalP_abundance * 10 && positionsLeft > 0) { containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalP_abundance * Random.value); if (containersCount != 0) { int i = 0; while (i < containersCount && positionsLeft > 0) { HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource; hr.SetResources(ResourceType.metal_P_ore, 1 + Random.value * 100 * metalP_abundance); allBoulders.Add(hr); positionsLeft--; i++; } } } if (Random.value < metalS_abundance * 10 && positionsLeft > 0) { containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalS_abundance * Random.value); if (containersCount != 0) { int i = 0; while (i < containersCount && positionsLeft > 0) { HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource; hr.SetResources(ResourceType.metal_S_ore, 1 + Random.value * 100 * metalS_abundance); allBoulders.Add(hr); positionsLeft--; i++; } } } if (Random.value < mineralF_abundance * 4 && positionsLeft > 0) { containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.mineralF_abundance * Random.value); if (containersCount != 0) { int i = 0; while (i < containersCount && positionsLeft > 0) { HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource; hr.SetResources(ResourceType.mineral_F, 1 + Random.value * 100 * mineralF_abundance); allBoulders.Add(hr); positionsLeft--; i++; } } } if (Random.value < mineralL_abundance * 4 && positionsLeft > 0) { containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.mineralL_abundance * Random.value); if (containersCount != 0) { int i = 0; while (i < containersCount && positionsLeft > 0) { HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource; hr.SetResources(ResourceType.mineral_L, 1 + Random.value * 100 * mineralL_abundance); allBoulders.Add(hr); positionsLeft--; i++; } } } if (allBoulders.Count > 0) { for (int n = 0; n < allBoulders.Count; n++) { allBoulders[n].SetBasement(surface, positions[n]); } } maxObjectsCount = SurfaceBlock.INNER_RESOLUTION * SurfaceBlock.INNER_RESOLUTION - surface.surfaceObjects.Count; maxObjectsCount /= 2; maxObjectsCount = (int)(maxObjectsCount * Random.value); if (maxObjectsCount > 0) { int count = 0; if (surface.material_id == ResourceType.STONE_ID) { count = (int)(maxObjectsCount * (0.05f + Random.value * 0.05f)); } else { count = (int)(Random.value * 0.08f); } List <PixelPosByte> points = surface.GetRandomCells(count); if (points.Count > 0) { foreach (PixelPosByte p in points) { HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource; hr.SetResources(ResourceType.Stone, 4 + Random.value * 10); hr.SetBasement(surface, p); } } } }