public bool CanEmitAnywhere() { int cell = Grid.PosToCell(base.smi.transform.GetPosition()); int cell2 = Grid.CellLeft(cell); int cell3 = Grid.CellRight(cell); int cell4 = Grid.CellAbove(cell); Element element = ElementLoader.FindElementByHash(base.smi.master.emitter.outputElement.elementHash); Element.State state = element.state; return(false || CanEmitOnCell(cell, base.smi.master.maxPressure, state) || CanEmitOnCell(cell2, base.smi.master.maxPressure, state) || CanEmitOnCell(cell3, base.smi.master.maxPressure, state) || CanEmitOnCell(cell4, base.smi.master.maxPressure, state)); }
public static Substance CreateSubstance(string name, Element.State state, KAnimFile kanim, Material material, Color32 colour, Color32 ui_colour, Color32 conduit_colour) { Substance substance = new Substance(); substance.name = name; substance.nameTag = TagManager.Create(name); substance.elementID = (SimHashes)Hash.SDBMLower(name); substance.anim = kanim; substance.colour = colour; substance.uiColour = ui_colour; substance.conduitColour = conduit_colour; substance.material = material; substance.renderedByWorld = ((state & Element.State.Solid) == Element.State.Solid); return(substance); }
public void UpdateValues() { if (Grid.IsValidCell(selectedCell)) { Mass = Grid.Mass[selectedCell]; element = Grid.Element[selectedCell]; ElementName = element.name; state = element.state; tags = element.GetMaterialCategoryTag(); temperature = Grid.Temperature[selectedCell]; diseaseIdx = Grid.DiseaseIdx[selectedCell]; diseaseCount = Grid.DiseaseCount[selectedCell]; mSelectable.SetName(Grid.Element[selectedCell].name); DetailsScreen.Instance.Trigger(-1514841199, null); UpdateStatusItem(); if (element.id == SimHashes.OxyRock) { mSelectable.AddStatusItem(Db.Get().MiscStatusItems.OxyRockEmitting, this); if (FlowRate <= 0f) { mSelectable.AddStatusItem(Db.Get().MiscStatusItems.OxyRockBlocked, this); } else { mSelectable.RemoveStatusItem(Db.Get().MiscStatusItems.OxyRockBlocked, false); } } else { mSelectable.RemoveStatusItem(Db.Get().MiscStatusItems.OxyRockEmitting, false); mSelectable.RemoveStatusItem(Db.Get().MiscStatusItems.OxyRockBlocked, false); } if (Game.Instance.GetComponent <EntombedItemVisualizer>().IsEntombedItem(selectedCell)) { mSelectable.AddStatusItem(Db.Get().MiscStatusItems.BuriedItem, this); } else { mSelectable.RemoveStatusItem(Db.Get().MiscStatusItems.BuriedItem, true); } bool on = IsExposedToSpace(selectedCell); mSelectable.ToggleStatusItem(Db.Get().MiscStatusItems.Space, on, null); } }
private void AddToSim(int cell, int particleIdx, ref int num_particles) { bool flag = false; do { Element element = Grid.Element[cell]; Element.State state = element.state & Element.State.Solid; if (state == Element.State.Solid || (Grid.Properties[cell] & 2) != 0) { cell += Grid.WidthInCells; if (!Grid.IsValidCell(cell)) { return; } } else { flag = true; } }while (!flag); ParticleProperties particleProperties = this.particleProperties[particleIdx]; SimMessages.AddRemoveSubstance(cell, particleProperties.elementIdx, CellEventLogger.Instance.FallingWaterAddToSim, particleProperties.mass, particleProperties.temperature, particleProperties.diseaseIdx, particleProperties.diseaseCount, true, -1); RemoveParticle(particleIdx, ref num_particles); float time = GetTime(); float num = lastSpawnTime[cell]; if (time - num >= minSpawnDelay) { lastSpawnTime[cell] = time; Vector3 vector = Grid.CellToPosCCC(cell, Grid.SceneLayer.TileMain); if (CameraController.Instance.IsAudibleSound(vector)) { bool flag2 = true; if (splashSounds.TryGetValue(cell, out SoundInfo value)) { value.splashCount++; if (value.splashCount > splashCountLoopThreshold) { if (value.handle == HandleVector <int> .InvalidHandle) { value.handle = LoopingSoundManager.StartSound(liquid_splash_loop, vector, true, true); } LoopingSoundManager.Get().UpdateFirstParameter(value.handle, HASH_LIQUIDDEPTH, SoundUtil.GetLiquidDepth(cell)); LoopingSoundManager.Get().UpdateSecondParameter(value.handle, HASH_LIQUIDVOLUME, GetParticleVolume(particleProperties.mass)); flag2 = false; } } else { value = default(SoundInfo); value.handle = HandleVector <int> .InvalidHandle; } value.startTime = time; splashSounds[cell] = value; if (flag2) { EventInstance instance = SoundEvent.BeginOneShot(liquid_splash_initial, vector); instance.setParameterValue("liquidDepth", SoundUtil.GetLiquidDepth(cell)); instance.setParameterValue("liquidVolume", GetParticleVolume(particleProperties.mass)); SoundEvent.EndOneShot(instance); } } } }
public void UpdateParticles(float dt) { if (!(dt <= 0f) && simUpdateDelay < 0) { offset = (offset + dt) % 360f; int num_particles = physics.Count; Vector2 vector = Physics.gravity * dt * gravityScale; for (int i = 0; i < num_particles; i++) { ParticlePhysics value = physics[i]; Vector3 vector2 = value.position; Grid.PosToXY(vector2, out int x, out int y); value.velocity += vector; Vector3 b = value.velocity * dt; Vector3 v = vector2 + b; value.position = v; physics[i] = value; Grid.PosToXY(value.position, out int _, out int y2); int num = (y <= y2) ? y2 : y; int num2 = (y <= y2) ? y : y2; for (int num3 = num; num3 >= num2; num3--) { int num4 = num3 * Grid.WidthInCells + x; int cell = (num3 + 1) * Grid.WidthInCells + x; if (!Grid.IsValidCell(num4)) { if (Grid.IsValidCell(cell)) { ParticleProperties particleProperties = this.particleProperties[i]; SpawnLiquidSplash(value.position.x, cell, particleProperties.elementIdx, false); AddToSim(cell, i, ref num_particles); } else { RemoveParticle(i, ref num_particles); } break; } Element element = Grid.Element[num4]; Element.State state = element.state & Element.State.Solid; bool flag = false; if (state == Element.State.Solid || (Grid.Properties[num4] & 2) != 0) { AddToSim(cell, i, ref num_particles); } else { switch (state) { case Element.State.Gas: flag = true; break; case Element.State.Liquid: { ParticleProperties particleProperties2 = this.particleProperties[i]; Element element2 = ElementLoader.elements[particleProperties2.elementIdx]; if (element2.id == element.id) { if (Grid.Mass[num4] <= element.defaultValues.mass) { flag = true; } else { SpawnLiquidSplash(value.position.x, cell, particleProperties2.elementIdx, false); AddToSim(num4, i, ref num_particles); } } else if (element2.molarMass > element.molarMass) { flag = true; } else { SpawnLiquidSplash(value.position.x, cell, particleProperties2.elementIdx, false); AddToSim(cell, i, ref num_particles); } break; } case Element.State.Vacuum: if (element.id == SimHashes.Vacuum) { flag = true; } else { RemoveParticle(i, ref num_particles); } break; } } if (!flag) { break; } } } float time = GetTime(); UpdateSounds(time); UpdateMistFX(Time.time); } }
public void AddParticle(Vector2 root_pos, byte elementIdx, float base_mass, float temperature, byte disease_idx, int base_disease_count, bool skip_sound = false, bool skip_decor = false, bool debug_track = false, bool disable_randomness = false) { int num = Grid.PosToCell(root_pos); if (!Grid.IsValidCell(num)) { KCrashReporter.Assert(false, "Trying to add falling water outside of the scene"); } else { if (temperature <= 0f || base_mass <= 0f) { Debug.LogError($"Unexpected water mass/temperature values added to the falling water manager T({temperature}) M({base_mass})"); } float time = GetTime(); if (!skip_sound) { if (!topSounds.TryGetValue(num, out SoundInfo value)) { value = default(SoundInfo); value.handle = LoopingSoundManager.StartSound(liquid_top_loop, root_pos, true, true); } value.startTime = time; LoopingSoundManager.Get().UpdateSecondParameter(value.handle, HASH_LIQUIDVOLUME, SoundUtil.GetLiquidVolume(base_mass)); topSounds[num] = value; } while (base_mass > 0f) { float num2 = UnityEngine.Random.value * 2f * particleMassVariation - particleMassVariation; float num3 = Mathf.Max(0f, Mathf.Min(base_mass, particleMassToSplit + num2)); float num4 = num3 / base_mass; base_mass -= num3; int disease_count = (int)(num4 * (float)base_disease_count); int frame = UnityEngine.Random.Range(0, numFrames); Vector2 b = (!disable_randomness) ? new Vector2(jitterStep * Mathf.Sin(offset), jitterStep * Mathf.Sin(offset + 17f)) : Vector2.zero; Vector2 b2 = (!disable_randomness) ? new Vector2(UnityEngine.Random.Range(0f - multipleOffsetRange.x, multipleOffsetRange.x), UnityEngine.Random.Range(0f - multipleOffsetRange.y, multipleOffsetRange.y)) : Vector2.zero; Element element = ElementLoader.elements[elementIdx]; Vector2 vector = root_pos; bool flag = !skip_decor && SpawnLiquidTopDecor(time, Grid.CellLeft(num), false, element); bool flag2 = !skip_decor && SpawnLiquidTopDecor(time, Grid.CellRight(num), true, element); Vector2 b3 = Vector2.ClampMagnitude(initialOffset + b + b2, 1f); if (flag || flag2) { if (flag && flag2) { vector += b3; vector.x += 0.5f; } else if (flag) { vector += b3; } else { vector.x += 1f - b3.x; vector.y += b3.y; } } else { vector += b3; vector.x += 0.5f; } int num5 = Grid.PosToCell(vector); Element element2 = Grid.Element[num5]; Element.State state = element2.state & Element.State.Solid; if (state == Element.State.Solid || (Grid.Properties[num5] & 2) != 0) { vector.y = Mathf.Floor(vector.y + 1f); } physics.Add(new ParticlePhysics(vector, Vector2.zero, frame, elementIdx)); particleProperties.Add(new ParticleProperties(elementIdx, num3, temperature, disease_idx, disease_count, debug_track)); } } }
private bool CanEmitOnCell(int cell, float max_pressure, Element.State expected_state) { return(Grid.Mass[cell] < max_pressure && (Grid.Element[cell].IsState(expected_state) || Grid.Element[cell].IsVacuum)); }