private void EvaluateRadiation() { for (int i = 0; i < 1024; i++) { int num = (nextEvaluatedCell + i) % Grid.CellCount; if (Grid.RadiationCount[num] >= 0) { int num2 = Mathf.RoundToInt((float)Grid.RadiationCount[num] * 100f * (Time.deltaTime * cellRatio)); if (Grid.DiseaseIdx[num] == disease_idx) { SimMessages.ModifyDiseaseOnCell(num, disease_idx, num2); } else { int num3 = Grid.DiseaseCount[num] - num2; if (num3 < 0) { SimMessages.ModifyDiseaseOnCell(num, disease_idx, num3); } else { SimMessages.ModifyDiseaseOnCell(num, Grid.DiseaseIdx[num], -num2); } } } } nextEvaluatedCell = (nextEvaluatedCell + 1024) % Grid.CellCount; }
public void AddDisease(byte disease_idx, int delta, string reason) { if (delta != 0) { if ((bool)diseaseRedirectTarget) { diseaseRedirectTarget.AddDisease(disease_idx, delta, reason); } else if (useSimDiseaseInfo) { int gameCell = Grid.PosToCell(this); SimMessages.ModifyDiseaseOnCell(gameCell, disease_idx, delta); } else if (diseaseHandle.IsValid()) { int num = GameComps.DiseaseContainers.AddDisease(diseaseHandle, disease_idx, delta); if (num <= 0) { GameComps.DiseaseContainers.Remove(base.gameObject); diseaseHandle.Clear(); } } else if (delta > 0) { diseaseHandle = GameComps.DiseaseContainers.Add(base.gameObject, disease_idx, delta); Trigger(-1689370368, true); Trigger(-283306403, null); } } }
public void DropDisease(byte disease_idx, int disease_count) { if (disease_count > 0 && disease_idx != 255) { int num = Grid.PosToCell(base.transform.GetPosition()); if (Grid.IsValidCell(num)) { SimMessages.ModifyDiseaseOnCell(num, disease_idx, disease_count); } } }
public void Sim4000ms(float dt) { var obj = gameObject; int cell; if (obj != null && Grid.IsValidCell(cell = Grid.PosToCell(obj)) && isWilted?. IsWilting() == false && disease != SimUtil.DiseaseInfo.Invalid.idx && uprooted != null) { cell = Grid.OffsetCell(cell, uprooted.monitorCell); if (Grid.IsValidCell(cell) && Grid.Solid[cell]) { // Flower is growing and on a solid cell, infect it! SimMessages.ModifyDiseaseOnCell(cell, disease, Mathf.RoundToInt( GermExposureTuning.SPORECHID_GERMS_PER_S * dt)); } } }
private void CoolContents(float dt) { if (gasStorage.items.Count != 0) { float num = float.PositiveInfinity; float num2 = 0f; float num3 = 0f; foreach (GameObject item in gasStorage.items) { PrimaryElement component = item.GetComponent <PrimaryElement>(); if (!((Object)component == (Object)null) && !(component.Mass < 0.1f) && !(component.Temperature < minCooledTemperature)) { num2 = GameUtil.GetThermalEnergy(component); if (num > num2) { num = num2; } } } foreach (GameObject item2 in gasStorage.items) { PrimaryElement component = item2.GetComponent <PrimaryElement>(); if (!((Object)component == (Object)null) && !(component.Mass < 0.1f) && !(component.Temperature < minCooledTemperature)) { float num4 = Mathf.Min(num, 10f); GameUtil.DeltaThermalEnergy(component, 0f - num4, minCooledTemperature); num3 += num4; } } float num5 = Mathf.Abs(num3 * waterKGConsumedPerKJ); Game.Instance.accumulators.Accumulate(base.smi.master.waterConsumptionAccumulator, num5); if (num5 != 0f) { liquidStorage.ConsumeAndGetDisease(GameTags.Water, num5, out SimUtil.DiseaseInfo disease_info, out float _); SimMessages.ModifyDiseaseOnCell(Grid.PosToCell(base.gameObject), disease_info.idx, disease_info.count); UpdateMeter(); } } }
public void ModifyDiseaseCount(int delta, string reason) { if ((bool)diseaseRedirectTarget) { diseaseRedirectTarget.ModifyDiseaseCount(delta, reason); } else if (useSimDiseaseInfo) { int gameCell = Grid.PosToCell(this); SimMessages.ModifyDiseaseOnCell(gameCell, byte.MaxValue, delta); } else if (delta != 0 && diseaseHandle.IsValid()) { int num = GameComps.DiseaseContainers.ModifyDiseaseCount(diseaseHandle, delta); if (num <= 0 && !forcePermanentDiseaseContainer) { Trigger(-1689370368, false); GameComps.DiseaseContainers.Remove(base.gameObject); diseaseHandle.Clear(); } } }
private void UpdateFromNeighbours(int cellPos, Element cellElement, ref int cellCount) { foreach (int pos in new int[] { Grid.CellAbove(cellPos), Grid.CellBelow(cellPos), Grid.CellLeft(cellPos), Grid.CellBelow(cellPos) }) { if (!Grid.IsValidCell(pos)) { continue; } var element = Grid.Element[pos]; if (element.state == cellElement.state) { continue; } if (Grid.DiseaseIdx[pos] != radiationIdx) { continue; } int diff = Grid.DiseaseCount[pos] - cellCount; if (diff <= 0) { continue; } var growth = radiationDisease.GetGrowthRuleForElement(element); int increase = Mathf.RoundToInt(diff * growth.diffusionScale / 2); if (increase <= 0) { continue; } SimMessages.ModifyDiseaseOnCell(pos, radiationIdx, -increase); SimMessages.ModifyDiseaseOnCell(cellPos, radiationIdx, increase); cellCount += increase; } }
public void Sim200ms(float dt) { if (mobileLamp) { lampXY = Grid.PosToXY(gameObject.transform.position); } if (alwaysOn || (operational != null && operational.IsOperational)) { if (operational != null) { operational.SetActive(true); } HashSet <GameObject> buildingsAlreadySeen = new HashSet <GameObject>(); // Delete germs in area for (int dy = aoeBottom; dy < aoeBottom + aoeHeight; dy++) { int y = lampXY.Y + dy; for (int dx = aoeLeft; dx < aoeLeft + aoeWidth; dx++) { int x = lampXY.X + dx; if (FlashReachesCell(x, y)) { int cell = Grid.XYToCell(x, y); // Delete germs in the cell byte cellGermIndex = Grid.DiseaseIdx[cell]; if (diseasesKilled.Contains(cellGermIndex)) { int cellGermCount = Grid.DiseaseCount[cell]; int cellGermsToKill = GermsToKill(cellGermCount); SimMessages.ModifyDiseaseOnCell(cell, cellGermIndex, -cellGermsToKill); } // Delete germs on pickupables in the cell var pickupablesInCell = Grid.Objects[cell, (int)ObjectLayer.Pickupables]; if (pickupablesInCell != null) { var currentPickupable = pickupablesInCell.GetComponent <Pickupable>().objectLayerListItem; while (currentPickupable != null) { var pickupable = currentPickupable.gameObject.GetComponent <Pickupable>(); currentPickupable = currentPickupable.nextItem; if (pickupable != null) { byte pickupableDiseaseIndex = pickupable.PrimaryElement.DiseaseIdx; if (diseasesKilled.Contains(pickupableDiseaseIndex)) { int pickupableGermCount = pickupable.PrimaryElement.DiseaseCount; int pickupableGermsToKill = GermsToKill(pickupableGermCount); pickupable.PrimaryElement.ModifyDiseaseCount(-pickupableGermsToKill, GermicideLampConfig.ID); } if (applySunburn) { var minion = pickupable.GetComponent <MinionIdentity>(); if (minion != null) { var sunburn = new SicknessExposureInfo(Db.Get().Sicknesses.Sunburn.Id, ModStrings.STRINGS.BUILDINGS.GERMICIDELAMP.NAME); var sicknesses = minion.GetSicknesses(); bool hasSunburn = false; if (sicknesses.IsInfected()) { foreach (SicknessInstance item in sicknesses) { if (item.ExposureInfo.sicknessID == Db.Get().Sicknesses.Sunburn.Id) { hasSunburn = true; break; } } } if (!hasSunburn) { sicknesses.Infect(sunburn); } } } } } } // Delete germs on solid conduit items in the cell var conduit = Game.Instance.solidConduitFlow.GetConduit(cell); if (!conduit.Equals(SolidConduitFlow.Conduit.Invalid())) { var conduitContents = conduit.GetContents(Game.Instance.solidConduitFlow); var conduitPickupable = Game.Instance.solidConduitFlow.GetPickupable(conduitContents.pickupableHandle); if (conduitPickupable != null) { byte conduitDiseaseIndex = conduitPickupable.PrimaryElement.DiseaseIdx; if (diseasesKilled.Contains(conduitDiseaseIndex)) { int cpuCount = conduitPickupable.PrimaryElement.DiseaseCount; int cpuGermsToKill = GermsToKill(cpuCount); conduitPickupable.PrimaryElement.ModifyDiseaseCount(-cpuGermsToKill, GermicideLampConfig.ID); } } } // Delete germs on buildings in the cell var buildingInCell = Grid.Objects[cell, (int)ObjectLayer.Building]; if (buildingInCell != null && !buildingsAlreadySeen.Contains(buildingInCell)) { var buildingElement = buildingInCell.GetComponent <PrimaryElement>(); if (buildingElement != null) { byte buildingDiseaseIndex = buildingElement.DiseaseIdx; if (diseasesKilled.Contains(buildingDiseaseIndex)) { int buildingGermCount = buildingElement.DiseaseCount; int buildingGermsToKill = GermsToKill(buildingGermCount); buildingElement.ModifyDiseaseCount(-buildingGermsToKill, GermicideLampConfig.ID); } } buildingsAlreadySeen.Add(buildingInCell); } } } } } else { if (operational != null) { operational.SetActive(false); } } }
/// <summary> /// Updates the radbolt position and checks collision. /// </summary> /// <param name="dt">The time elapsed in seconds since the last update.</param> public void MovingUpdate(float dt) { var tt = transform; if (hep.collision == HighEnergyParticle.CollisionType.None && dt > 0.0f) { Vector3 pos = tt.position, newPos = pos + EightDirectionUtil.GetNormal( hep.direction) * hep.speed * dt; int cell = Grid.PosToCell(pos), newCell = Grid.PosToCell(newPos); bool destroy = false; if (tracker != null) { tracker.radBoltTravelDistance += hep.speed * dt; } if (!FastTrackOptions.Instance.DisableSound) { hep.loopingSounds.UpdateVelocity(hep.flyingSound, newPos - pos); } if (!Grid.IsValidCell(newCell)) { PUtil.LogWarning("High energy particle moved into invalid cell {0:D}".F( newCell)); destroy = true; } else { float payload = hep.payload; if (cell != newCell) { SimMessages.ModifyDiseaseOnCell(newCell, diseaseIndex, DISEASE_PER_CELL); payload -= HighEnergyParticleConfig.PER_CELL_FALLOFF; if (partitionerEntry.IsValid()) { // GSP had to be valid for the entry to exist in the first place GameScenePartitioner.Instance.UpdatePosition(partitionerEntry, newCell); } else { CreatePartitioner(newCell); } } if (payload <= 0.0f) { destroy = true; } else { hep.payload = payload; // Use the Klei override to trigger kanim cell change update tt.SetPosition(newPos); CheckCollision(cell, pos); } } if (destroy) { hep.smi.sm.destroySimpleSignal.Trigger(hep.smi); } } }
private void UpdateConduit(ConduitFlow conduitFlow, ConduitType conduitType, int cellPos, Element cellElement, ref int cellCount) { var building = Grid.Objects[cellPos, (int)GetObjectLayer(conduitType)]; if (building == null || building.GetComponent <BuildingComplete>() == null) { return; } var pipe = building.GetComponent <PrimaryElement>(); var pipeElement = pipe.Element; int pipeCount = pipe.DiseaseIdx == radiationIdx ? pipe.DiseaseCount : 0; var content = conduitFlow.GetContents(cellPos); //string typeLog = $"{cellElement.tag}, {pipeElement.tag}"; if (content.mass > 0) { var contentElement = ElementLoader.FindElementByHash(content.element); //typeLog += $", {contentElement.tag}"; int contentCount = content.diseaseIdx == radiationIdx ? content.diseaseCount : 0; int diff = contentCount - pipeCount; var growth = diff > 0 ? radiationDisease.GetGrowthRuleForElement(contentElement) : radiationDisease.GetGrowthRuleForElement(pipeElement); float diffusionScale = Mathf.Min(growth.diffusionScale * 10, 1); int increase = Mathf.RoundToInt(diff * diffusionScale / 2); if (increase != 0) { int oldPipe = pipeCount; int oldContent = contentCount; content.diseaseCount = contentCount - increase; content.diseaseIdx = radiationIdx; conduitFlow.SetContents(cellPos, content); pipe.AddDisease(radiationIdx, increase, "Radioactivity.UpdateConduit"); pipeCount += increase; //Log.Spam($"{cellPos} increase {increase} ({diffusionScale}), content {oldContent} => {content.diseaseCount}, pipe {oldPipe} =>{pipe.DiseaseCount}"); } } if (cellElement.id != SimHashes.Vacuum && cellElement.id != SimHashes.Void) { int diff = pipeCount - cellCount; var growth = diff > 0 ? radiationDisease.GetGrowthRuleForElement(pipeElement) : radiationDisease.GetGrowthRuleForElement(cellElement); float diffusionScale = Mathf.Min(growth.diffusionScale * 10, 1); int increase = Mathf.RoundToInt(diff * diffusionScale / 2); if (increase != 0) { int oldPipe = pipeCount; int oldCell = cellCount; pipe.AddDisease(radiationIdx, -increase, "Radioactivity.UpdateConduit"); SimMessages.ModifyDiseaseOnCell(cellPos, radiationIdx, increase); cellCount += increase; //Log.Spam($"{cellPos} increase {increase} ({diffusionScale}), pipe {oldPipe} => {pipe.DiseaseCount}, grid {oldCell} => {Grid.DiseaseCount[cellPos]}"); } } //Log.Spam($"{cellPos} {typeLog}"); }