From: deltanedas <39013340+deltanedas@users.noreply.github.com> Date: Mon, 2 Oct 2023 00:17:50 +0000 (+0100) Subject: Electric grill (#20661) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=3488e577d96322ef58a1675c062531090ef76720;p=space-station-14.git Electric grill (#20661) --------- Co-authored-by: deltanedas <@deltanedas:kde.org> --- diff --git a/Content.Server/Temperature/Components/EntityHeaterComponent.cs b/Content.Server/Temperature/Components/EntityHeaterComponent.cs new file mode 100644 index 0000000000..3a162c20e3 --- /dev/null +++ b/Content.Server/Temperature/Components/EntityHeaterComponent.cs @@ -0,0 +1,24 @@ +using Content.Server.Temperature.Systems; +using Content.Shared.Temperature; + +namespace Content.Server.Temperature.Components; + +/// +/// Adds thermal energy to entities with placed on it. +/// +[RegisterComponent, Access(typeof(EntityHeaterSystem))] +public sealed partial class EntityHeaterComponent : Component +{ + /// + /// Power used when heating at the high setting. + /// Low and medium are 33% and 66% respectively. + /// + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float Power = 2400f; + + /// + /// Current setting of the heater. If it is off or unpowered it won't heat anything. + /// + [DataField] + public EntityHeaterSetting Setting = EntityHeaterSetting.Off; +} diff --git a/Content.Server/Temperature/Systems/EntityHeaterSystem.cs b/Content.Server/Temperature/Systems/EntityHeaterSystem.cs new file mode 100644 index 0000000000..6da774ba07 --- /dev/null +++ b/Content.Server/Temperature/Systems/EntityHeaterSystem.cs @@ -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; + +/// +/// Handles updating and events. +/// +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(OnExamined); + SubscribeLocalEvent>(OnGetVerbs); + SubscribeLocalEvent(OnPowerChanged); + } + + public override void Update(float deltaTime) + { + var query = EntityQueryEnumerator(); + 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 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; + } + } +} diff --git a/Content.Shared/Temperature/SharedEntityHeater.cs b/Content.Shared/Temperature/SharedEntityHeater.cs new file mode 100644 index 0000000000..597104e1ba --- /dev/null +++ b/Content.Shared/Temperature/SharedEntityHeater.cs @@ -0,0 +1,21 @@ +using Robust.Shared.Serialization; + +namespace Content.Shared.Temperature; + +[Serializable, NetSerializable] +public enum EntityHeaterVisuals +{ + Setting +} + +/// +/// What heat the heater is set to, if on at all. +/// +[Serializable, NetSerializable] +public enum EntityHeaterSetting +{ + Off, + Low, + Medium, + High +} diff --git a/Resources/Locale/en-US/temperature/entity-heater.ftl b/Resources/Locale/en-US/temperature/entity-heater.ftl new file mode 100644 index 0000000000..a809d508e7 --- /dev/null +++ b/Resources/Locale/en-US/temperature/entity-heater.ftl @@ -0,0 +1,3 @@ +entity-heater-examined = It is set to [color=gray]{$setting}[/color] +entity-heater-switch-setting = Switch to {$setting} +entity-heater-switched-setting = Switched to {$setting} diff --git a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml index 9ecd8c36f1..9c60e72535 100644 --- a/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml +++ b/Resources/Prototypes/Entities/Objects/Devices/Circuitboards/Machine/production.yml @@ -710,6 +710,20 @@ materialRequirements: Glass: 1 +- type: entity + parent: BaseMachineCircuitboard + id: ElectricGrillMachineCircuitboard + name: electric grill machine board + description: A machine printed circuit board for an electric grill. + components: + - type: MachineBoard + prototype: KitchenElectricGrill + requirements: + Capacitor: 4 + materialRequirements: + Glass: 2 + Cable: 5 + - type: entity id: StasisBedMachineCircuitboard parent: BaseMachineCircuitboard diff --git a/Resources/Prototypes/Entities/Structures/Machines/grill.yml b/Resources/Prototypes/Entities/Structures/Machines/grill.yml new file mode 100644 index 0000000000..dbd31b3eae --- /dev/null +++ b/Resources/Prototypes/Entities/Structures/Machines/grill.yml @@ -0,0 +1,35 @@ +- type: entity + parent: BaseHeaterMachine + id: KitchenElectricGrill + name: electric grill + description: A microwave? No, a real man cooks steaks on a grill! + components: + - type: Sprite + # TODO: draw a sprite + sprite: Structures/Machines/electric_grill.rsi + drawdepth: SmallObjects + snapCardinals: true + layers: + - state: icon + - map: ["enum.EntityHeaterVisuals.Setting"] + shader: unshaded + visible: false + - type: ApcPowerReceiver + powerLoad: 0 # off by default + - type: EntityHeater + - type: ItemPlacer + maxEntities: 4 # big grill, many steaks + whitelist: + components: + - Temperature + - type: PlaceableSurface + - type: Machine + board: ElectricGrillMachineCircuitboard + - type: GenericVisualizer + visuals: + enum.EntityHeaterVisuals.Setting: + enum.EntityHeaterVisuals.Setting: + Off: { visible: false } + Low: { visible: true, state: low } + Medium: { visible: true, state: medium } + High: { visible: true, state: high } diff --git a/Resources/Prototypes/Entities/Structures/Machines/hotplate.yml b/Resources/Prototypes/Entities/Structures/Machines/hotplate.yml index c5ed1de80c..3f2dc05a30 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/hotplate.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/hotplate.yml @@ -1,8 +1,8 @@ +# heats an entity or solution placed on it - type: entity - id: ChemistryHotplate + abstract: true parent: [ BaseMachinePowered, ConstructibleMachine ] - name: hotplate - description: "The descendent of the microwaves, our newest invention in beaker heating technology: the hotplate!" + id: BaseHeaterMachine components: - type: Transform anchored: true @@ -19,6 +19,20 @@ - MidImpassable - LowImpassable hard: false + - type: ApcPowerReceiver + powerLoad: 300 + - type: Appearance + - type: ContainerContainer + containers: + machine_board: !type:Container + machine_parts: !type:Container + +- type: entity + parent: BaseHeaterMachine + id: ChemistryHotplate + name: hotplate + description: "The descendent of the microwaves, our newest invention in beaker heating technology: the hotplate!" + components: - type: Sprite sprite: Structures/Machines/hotplate.rsi drawdepth: SmallObjects @@ -28,15 +42,6 @@ - state: on map: ["enum.SolutionHeaterVisuals.IsOn"] shader: unshaded - - type: ApcPowerReceiver - powerLoad: 300 - - type: ItemMapper - sprite: Structures/Machines/hotplate.rsi - mapLayers: - beaker: - whitelist: - components: - - FitsInDispenser - type: SolutionHeater - type: ItemPlacer whitelist: @@ -47,11 +52,6 @@ positionOffset: 0, 0.25 - type: Machine board: HotplateMachineCircuitboard - - type: Appearance - - type: ContainerContainer - containers: - machine_board: !type:Container - machine_parts: !type:Container - type: GenericVisualizer visuals: enum.SolutionHeaterVisuals.IsOn: diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml index f0d774c1fd..45cdc33a10 100644 --- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml +++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml @@ -324,6 +324,7 @@ - ReagentGrinderMachineCircuitboard - HotplateMachineCircuitboard - MicrowaveMachineCircuitboard + - ElectricGrillMachineCircuitboard - FatExtractorMachineCircuitboard - SheetifierMachineCircuitboard - UniformPrinterMachineCircuitboard diff --git a/Resources/Prototypes/Recipes/Lathes/electronics.yml b/Resources/Prototypes/Recipes/Lathes/electronics.yml index ebb187121b..bc54c78ca1 100644 --- a/Resources/Prototypes/Recipes/Lathes/electronics.yml +++ b/Resources/Prototypes/Recipes/Lathes/electronics.yml @@ -517,6 +517,14 @@ Steel: 100 Glass: 900 +- type: latheRecipe + id: ElectricGrillMachineCircuitboard + result: ElectricGrillMachineCircuitboard + completetime: 4 + materials: + Steel: 100 + Glass: 900 + - type: latheRecipe id: FatExtractorMachineCircuitboard result: FatExtractorMachineCircuitboard diff --git a/Resources/Prototypes/Research/civilianservices.yml b/Resources/Prototypes/Research/civilianservices.yml index b0de5d319b..9208775094 100644 --- a/Resources/Prototypes/Research/civilianservices.yml +++ b/Resources/Prototypes/Research/civilianservices.yml @@ -75,6 +75,7 @@ recipeUnlocks: #remove all of these once we have more kitchen equipment - MicrowaveMachineCircuitboard - ReagentGrinderMachineCircuitboard + - ElectricGrillMachineCircuitboard - BoozeDispenserMachineCircuitboard - SodaDispenserMachineCircuitboard diff --git a/Resources/Textures/Structures/Machines/electric_grill.rsi/high.png b/Resources/Textures/Structures/Machines/electric_grill.rsi/high.png new file mode 100644 index 0000000000..b1fe72eb4f Binary files /dev/null and b/Resources/Textures/Structures/Machines/electric_grill.rsi/high.png differ diff --git a/Resources/Textures/Structures/Machines/electric_grill.rsi/icon.png b/Resources/Textures/Structures/Machines/electric_grill.rsi/icon.png new file mode 100644 index 0000000000..d085b5b4c8 Binary files /dev/null and b/Resources/Textures/Structures/Machines/electric_grill.rsi/icon.png differ diff --git a/Resources/Textures/Structures/Machines/electric_grill.rsi/low.png b/Resources/Textures/Structures/Machines/electric_grill.rsi/low.png new file mode 100644 index 0000000000..db27683a63 Binary files /dev/null and b/Resources/Textures/Structures/Machines/electric_grill.rsi/low.png differ diff --git a/Resources/Textures/Structures/Machines/electric_grill.rsi/medium.png b/Resources/Textures/Structures/Machines/electric_grill.rsi/medium.png new file mode 100644 index 0000000000..ed5d431e8d Binary files /dev/null and b/Resources/Textures/Structures/Machines/electric_grill.rsi/medium.png differ diff --git a/Resources/Textures/Structures/Machines/electric_grill.rsi/meta.json b/Resources/Textures/Structures/Machines/electric_grill.rsi/meta.json new file mode 100644 index 0000000000..acb06666db --- /dev/null +++ b/Resources/Textures/Structures/Machines/electric_grill.rsi/meta.json @@ -0,0 +1,23 @@ +{ + "version": 1, + "license": "CC0-1.0", + "copyright": "Created by deltanedas (github) for SS14.", + "size": { + "x": 32, + "y": 32 + }, + "states": [ + { + "name": "icon" + }, + { + "name": "low" + }, + { + "name": "medium" + }, + { + "name": "high" + } + ] +}