Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Miasma improvements #9022

Merged
merged 12 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Content.Client/Atmos/Miasma/FliesComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Content.Shared.Atmos.Miasma;
using Robust.Shared.GameStates;

namespace Content.Client.Atmos.Miasma;

[NetworkedComponent, RegisterComponent]
public sealed class FliesComponent : SharedFliesComponent
{ }
41 changes: 41 additions & 0 deletions Content.Client/Atmos/Miasma/FliesSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Robust.Client.GameObjects;
using Robust.Shared.Utility;

namespace Content.Client.Atmos.Miasma;

public sealed class FliesSystem : EntitySystem
{
public override void Initialize()
{
SubscribeLocalEvent<FliesComponent, ComponentStartup>(FliesAdded);
SubscribeLocalEvent<FliesComponent, ComponentShutdown>(FliesRemoved);
}

private void FliesRemoved(EntityUid uid, FliesComponent component, ComponentShutdown args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite))
return;

if (!sprite.LayerMapTryGet(FliesKey.Key, out var layer))
return;

sprite.RemoveLayer(layer);
}

private void FliesAdded(EntityUid uid, FliesComponent component, ComponentStartup args)
{
if (!TryComp<SpriteComponent>(uid, out var sprite))
return;

if (sprite.LayerMapTryGet(FliesKey.Key, out var _))
return;

var layer = sprite.AddLayer(new SpriteSpecifier.Rsi(new ResourcePath("Objects/Misc/flies.rsi"), "flies"));
sprite.LayerMapSet(FliesKey.Key, layer);
}

private enum FliesKey
{
Key,
}
}
9 changes: 4 additions & 5 deletions Content.Server/Administration/Commands/RejuvenateCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Content.Server.Atmos.Components;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Atmos.Miasma;
using Content.Server.Body.Components;
using Content.Server.Body.Systems;
using Content.Server.Disease.Components;
Expand Down Expand Up @@ -89,15 +90,13 @@ public static void PerformRejuvenate(EntityUid target)
sys.TryModifyBloodLevel(target, bloodStream.BloodSolution.AvailableVolume, bloodStream);
}

if (entMan.HasComponent<JitteringComponent>(target))
{
entMan.RemoveComponent<JitteringComponent>(target);
}

if (entMan.TryGetComponent<DiseaseCarrierComponent>(target, out var carrier))
{
EntitySystem.Get<DiseaseSystem>().CureAllDiseases(target, carrier);
}

entMan.RemoveComponent<JitteringComponent>(target);
entMan.RemoveComponent<RottingComponent>(target);
}
}
}
11 changes: 11 additions & 0 deletions Content.Server/Atmos/Miasma/FliesComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Content.Shared.Atmos.Miasma;
using Robust.Shared.GameStates;

namespace Content.Server.Atmos.Miasma;

[NetworkedComponent, RegisterComponent]
public sealed class FliesComponent : SharedFliesComponent
{
/// Need something to hold the ambient sound, at least until that system becomes more robust
public EntityUid VirtFlies;
}
100 changes: 81 additions & 19 deletions Content.Server/Atmos/Miasma/MiasmaSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
using Content.Shared.Damage;
using Content.Shared.Atmos;
using Content.Server.Atmos.EntitySystems;
using Content.Server.Temperature.Components;
using Content.Server.Temperature.Systems;
using Content.Server.Body.Components;
using Content.Server.Popups;
using Content.Shared.Examine;
using Robust.Shared.Containers;
using Robust.Shared.Player;

namespace Content.Server.Atmos.Miasma
{
public sealed class MiasmaSystem : EntitySystem
{
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly DamageableSystem _damageableSystem = default!;

[Dependency] private readonly PopupSystem _popupSystem = default!;
/// Feel free to weak this if there are perf concerns
private float UpdateRate = 5f;

public override void Update(float frameTime)
{
Expand All @@ -26,18 +24,17 @@ public override void Update(float frameTime)
if (!perishable.Progressing)
continue;

if (TryComp<TemperatureComponent>(perishable.Owner, out var temp) && temp.CurrentTemperature < 274f)
continue;

perishable.DeathAccumulator += frameTime;
if (perishable.DeathAccumulator < perishable.RotAfter.TotalSeconds)
continue;

perishable.RotAccumulator += frameTime;
if (perishable.RotAccumulator < 1f)
if (perishable.RotAccumulator < UpdateRate) // This is where it starts to get noticable on larger animals, no need to run every second
continue;

perishable.RotAccumulator -= 1f;
perishable.RotAccumulator -= UpdateRate;

EnsureComp<FliesComponent>(perishable.Owner);

DamageSpecifier damage = new();
damage.DamageDict.Add("Blunt", 0.3); // Slowly accumulate enough to gib after like half an hour
Expand All @@ -49,21 +46,45 @@ public override void Update(float frameTime)
continue;
// We need a way to get the mass of the mob alone without armor etc in the future

float molRate = perishable.MolsPerSecondPerUnitMass * UpdateRate;

var tileMix = _atmosphereSystem.GetTileMixture(Transform(perishable.Owner).Coordinates);
if (tileMix != null)
tileMix.AdjustMoles(Gas.Miasma, perishable.MolsPerSecondPerUnitMass * physics.FixturesMass);
tileMix.AdjustMoles(Gas.Miasma, molRate * physics.FixturesMass);
}
}


public override void Initialize()
{
base.Initialize();
// Core rotting stuff
SubscribeLocalEvent<RottingComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<RottingComponent, OnTemperatureChangeEvent>(OnTempChange);
SubscribeLocalEvent<PerishableComponent, MobStateChangedEvent>(OnMobStateChanged);
SubscribeLocalEvent<PerishableComponent, BeingGibbedEvent>(OnGibbed);
SubscribeLocalEvent<PerishableComponent, ExaminedEvent>(OnExamined);
// Containers
SubscribeLocalEvent<AntiRottingContainerComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
SubscribeLocalEvent<AntiRottingContainerComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
// Fly audiovisual stuff
SubscribeLocalEvent<FliesComponent, ComponentInit>(OnFliesInit);
SubscribeLocalEvent<FliesComponent, ComponentShutdown>(OnFliesShutdown);
}

private void OnShutdown(EntityUid uid, RottingComponent component, ComponentShutdown args)
{
RemComp<FliesComponent>(uid);
if (TryComp<PerishableComponent>(uid, out var perishable))
{
perishable.DeathAccumulator = 0;
perishable.RotAccumulator = 0;
}
}

private void OnTempChange(EntityUid uid, RottingComponent component, OnTemperatureChangeEvent args)
{
bool decompose = (args.CurrentTemperature > 274f);
ToggleDecomposition(uid, decompose);
}

private void OnMobStateChanged(EntityUid uid, PerishableComponent component, MobStateChangedEvent args)
Expand All @@ -77,36 +98,77 @@ private void OnGibbed(EntityUid uid, PerishableComponent component, BeingGibbedE
if (!TryComp<PhysicsComponent>(uid, out var physics))
return;

if (component.DeathAccumulator <= component.RotAfter.TotalSeconds)
if (!component.Rotting)
return;

var molsToDump = (component.MolsPerSecondPerUnitMass * physics.FixturesMass) * component.DeathAccumulator;
var tileMix = _atmosphereSystem.GetTileMixture(Transform(uid).Coordinates);
if (tileMix != null)
tileMix.AdjustMoles(Gas.Miasma, molsToDump);

// Waste of entities to let these through
foreach (var part in args.GibbedParts)
{
EntityManager.QueueDeleteEntity(part);
}
EntityManager.DeleteEntity(part);
}

private void OnExamined(EntityUid uid, PerishableComponent component, ExaminedEvent args)
{
if (component.DeathAccumulator >= component.RotAfter.TotalSeconds)
if (component.Rotting)
args.PushMarkup(Loc.GetString("miasma-rotting"));
}

/// Containers

private void OnEntInserted(EntityUid uid, AntiRottingContainerComponent component, EntInsertedIntoContainerMessage args)
{
if (TryComp<PerishableComponent>(args.Entity, out var perishable))
perishable.Progressing = false;
ToggleDecomposition(args.Entity, false, perishable);
}

private void OnEntRemoved(EntityUid uid, AntiRottingContainerComponent component, EntRemovedFromContainerMessage args)
{
if (TryComp<PerishableComponent>(args.Entity, out var perishable))
ToggleDecomposition(args.Entity, true, perishable);
}


/// Fly stuff

private void OnFliesInit(EntityUid uid, FliesComponent component, ComponentInit args)
{
component.VirtFlies = EntityManager.SpawnEntity("AmbientSoundSourceFlies", Transform(uid).Coordinates);
Transform(component.VirtFlies).AttachParent(uid);
}

private void OnFliesShutdown(EntityUid uid, FliesComponent component, ComponentShutdown args)
{
EntityManager.DeleteEntity(component.VirtFlies);
}

/// Public functions

public void ToggleDecomposition(EntityUid uid, bool decompose, PerishableComponent? perishable = null)
{
if (!Resolve(uid, ref perishable))
return;

if (decompose == perishable.Progressing) // Saved a few cycles
return;

if (!HasComp<RottingComponent>(uid))
return;

if (!perishable.Rotting)
return;

if (decompose)
{
perishable.Progressing = true;
EnsureComp<FliesComponent>(uid);
return;
}

perishable.Progressing = false;
RemComp<FliesComponent>(uid);
}
}
}
2 changes: 2 additions & 0 deletions Content.Server/Atmos/Miasma/PerishableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public sealed class PerishableComponent : Component
/// </summary>
public TimeSpan RotAfter = TimeSpan.FromMinutes(5);

public bool Rotting => (DeathAccumulator > RotAfter.TotalSeconds);

/// <summary>
/// Gasses are released every second.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions Content.Shared/Atmos/Miasma/SharedFliesComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Content.Shared.Atmos.Miasma;
public abstract class SharedFliesComponent : Component
{

}
Binary file added Resources/Audio/Ambience/Temporary/flies.ogg
Binary file not shown.
1 change: 1 addition & 0 deletions Resources/Audio/Ambience/Temporary/license.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flies.ogg taken from https://freesound.org/people/telezon/sounds/321870/ licensed under CC-0
4 changes: 2 additions & 2 deletions Resources/Prototypes/Catalog/Cargo/cargo_livestock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
sprite: Mobs/Animals/cow.rsi
state: cow
product: CrateNPCCow
cost: 1000
cost: 3200
category: Livestock
group: market

Expand Down Expand Up @@ -129,7 +129,7 @@
cost: 1500
category: Livestock
group: market

- type: cargoProduct
name: "mice crate"
id: LivestockMouse
Expand Down
12 changes: 12 additions & 0 deletions Resources/Prototypes/Entities/Effects/ambient_sounds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- type: entity
id: AmbientSoundSourceFlies
noSpawn: true
components:
- type: AmbientSound
volume: -5
range: 3
sound:
path: /Audio/Ambience/Temporary/flies.ogg
- type: Tag
tags:
- HideContextMenu
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- type: Construction
graph: CrateGenericSteel
node: crategenericsteel
- type: AntiRottingContainer

- type: entity
id: CrateHydroponics
Expand Down
Binary file added Resources/Textures/Objects/Misc/flies.rsi/flies.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions Resources/Textures/Objects/Misc/flies.rsi/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": 1,
"license": "CC-BY-NC-SA-3.0",
"copyright": "Created by github user @elijahrane",
"size": {
"x": 32,
"y": 32
},
"states": [
{
"name": "flies",
"directions": 1,
"delays": [
[
0.2,
0.2,
0.2,
0.2
]
]
}
]
}