forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391 from TheArturZh/upstream-merge-31
Upstream merge 31
- Loading branch information
Showing
35 changed files
with
82,149 additions
and
97,934 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
Content.Server/Temperature/Components/EntityHeaterComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Content.Server.Temperature.Systems; | ||
using Content.Shared.Temperature; | ||
|
||
namespace Content.Server.Temperature.Components; | ||
|
||
/// <summary> | ||
/// Adds thermal energy to entities with <see cref="TemperatureComponent"/> placed on it. | ||
/// </summary> | ||
[RegisterComponent, Access(typeof(EntityHeaterSystem))] | ||
public sealed partial class EntityHeaterComponent : Component | ||
{ | ||
/// <summary> | ||
/// Power used when heating at the high setting. | ||
/// Low and medium are 33% and 66% respectively. | ||
/// </summary> | ||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public float Power = 2400f; | ||
|
||
/// <summary> | ||
/// Current setting of the heater. If it is off or unpowered it won't heat anything. | ||
/// </summary> | ||
[DataField] | ||
public EntityHeaterSetting Setting = EntityHeaterSetting.Off; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
Content.Server/Temperature/Systems/EntityHeaterSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using Content.Server.Power.Components; | ||
using Content.Server.Temperature.Components; | ||
using Content.Shared.Examine; | ||
using Content.Shared.Placeable; | ||
using Content.Shared.Popups; | ||
using Content.Shared.Temperature; | ||
using Content.Shared.Verbs; | ||
|
||
namespace Content.Server.Temperature.Systems; | ||
|
||
/// <summary> | ||
/// Handles <see cref="EntityHeaterComponent"/> updating and events. | ||
/// </summary> | ||
public sealed class EntityHeaterSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedAppearanceSystem _appearance = default!; | ||
[Dependency] private readonly SharedPopupSystem _popup = default!; | ||
[Dependency] private readonly TemperatureSystem _temperature = default!; | ||
|
||
private readonly int SettingCount = Enum.GetValues(typeof(EntityHeaterSetting)).Length; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<EntityHeaterComponent, ExaminedEvent>(OnExamined); | ||
SubscribeLocalEvent<EntityHeaterComponent, GetVerbsEvent<AlternativeVerb>>(OnGetVerbs); | ||
SubscribeLocalEvent<EntityHeaterComponent, PowerChangedEvent>(OnPowerChanged); | ||
} | ||
|
||
public override void Update(float deltaTime) | ||
{ | ||
var query = EntityQueryEnumerator<EntityHeaterComponent, ItemPlacerComponent, ApcPowerReceiverComponent>(); | ||
while (query.MoveNext(out var uid, out var comp, out var placer, out var power)) | ||
{ | ||
if (!power.Powered) | ||
continue; | ||
|
||
// don't divide by total entities since its a big grill | ||
// excess would just be wasted in the air but that's not worth simulating | ||
// if you want a heater thermomachine just use that... | ||
var energy = power.PowerReceived * deltaTime; | ||
foreach (var ent in placer.PlacedEntities) | ||
{ | ||
_temperature.ChangeHeat(ent, energy); | ||
} | ||
} | ||
} | ||
|
||
private void OnExamined(EntityUid uid, EntityHeaterComponent comp, ExaminedEvent args) | ||
{ | ||
if (!args.IsInDetailsRange) | ||
return; | ||
|
||
args.PushMarkup(Loc.GetString("entity-heater-examined", ("setting", comp.Setting))); | ||
} | ||
|
||
private void OnGetVerbs(EntityUid uid, EntityHeaterComponent comp, GetVerbsEvent<AlternativeVerb> args) | ||
{ | ||
if (!args.CanAccess || !args.CanInteract) | ||
return; | ||
|
||
var setting = (int) comp.Setting; | ||
setting++; | ||
setting %= SettingCount; | ||
var nextSetting = (EntityHeaterSetting) setting; | ||
|
||
args.Verbs.Add(new AlternativeVerb() | ||
{ | ||
Text = Loc.GetString("entity-heater-switch-setting", ("setting", nextSetting)), | ||
Act = () => | ||
{ | ||
ChangeSetting(uid, nextSetting, comp); | ||
_popup.PopupEntity(Loc.GetString("entity-heater-switched-setting", ("setting", nextSetting)), uid, args.User); | ||
} | ||
}); | ||
} | ||
|
||
private void OnPowerChanged(EntityUid uid, EntityHeaterComponent comp, ref PowerChangedEvent args) | ||
{ | ||
// disable heating element glowing layer if theres no power | ||
// doesn't actually turn it off since that would be annoying | ||
var setting = args.Powered ? comp.Setting : EntityHeaterSetting.Off; | ||
_appearance.SetData(uid, EntityHeaterVisuals.Setting, setting); | ||
} | ||
|
||
private void ChangeSetting(EntityUid uid, EntityHeaterSetting setting, EntityHeaterComponent? comp = null, ApcPowerReceiverComponent? power = null) | ||
{ | ||
if (!Resolve(uid, ref comp, ref power)) | ||
return; | ||
|
||
comp.Setting = setting; | ||
power.Load = SettingPower(setting, comp.Power); | ||
_appearance.SetData(uid, EntityHeaterVisuals.Setting, setting); | ||
} | ||
|
||
private float SettingPower(EntityHeaterSetting setting, float max) | ||
{ | ||
switch (setting) | ||
{ | ||
case EntityHeaterSetting.Low: | ||
return max / 3f; | ||
case EntityHeaterSetting.Medium: | ||
return max * 2f / 3f; | ||
case EntityHeaterSetting.High: | ||
return max; | ||
default: | ||
return 0f; | ||
} | ||
} | ||
} |
Oops, something went wrong.