Skip to content

Commit

Permalink
Mirror: allow biomass reclaimer to reclaim plants (#150)
Browse files Browse the repository at this point in the history
## Mirror of PR #23731: [allow biomass reclaimer to reclaim
plants](space-wizards/space-station-14#23731)
from <img src="https://avatars.githubusercontent.com/u/10567778?v=4"
alt="space-wizards" width="22"/>
[space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14)

###### `ec4e0990e16f70e6e4a2c1461680240f78cccaf3`

PR opened by <img
src="https://avatars.githubusercontent.com/u/57039557?v=4"
width="16"/><a href="https://github.com/Ilya246"> Ilya246</a> at
2024-01-08 09:45:55 UTC
PR merged by <img
src="https://avatars.githubusercontent.com/u/19864447?v=4"
width="16"/><a href="https://github.com/web-flow"> web-flow</a> at
2024-03-11 21:59:21 UTC

---

PR changed 2 files with 45 additions and 11 deletions.

The PR had the following labels:
- Status: Needs Review


---

<details open="true"><summary><h1>Original Body</h1></summary>

> <!-- Please read these guidelines before opening your PR:
https://docs.spacestation14.io/en/getting-started/pr-guideline -->
> <!-- The text between the arrows are comments - they will not be
visible on your PR. -->
> 
> ## About the PR
> title: allows biomass reclaimer to reclaim plants at 0.5 biomass per
plant
> also makes insertion doafter time scale with mass of inserted entity
> also fixes click insertion (as opposed to drag insertion) not working
> 
> ## Why / Balance
> provides a fallback way to obtain biomass if cargo is not doing their
job
> since cloning is not real, makes it actually feasible to obtain
biomass for the biofabricator
> if cloning were real, seems like it would still be balanced with the
amounts it gives
> 
> ## Technical details
> also cleans up BiomassReclaimerComponent's `DataField` tags
> 
> ## Media
> <!-- 
> PRs which make ingame changes (adding clothing, items, new features,
etc) are required to have media attached that showcase the changes.
> Small fixes/refactors are exempt.
> Any media may be used in SS14 progress reports, with clear credit
given.
> 
> If you're unsure whether your PR will require media, ask a maintainer.
> 
> Check the box below to confirm that you have in fact seen this (put an
X in the brackets, like [X]):
> -->
> tested, works
> trust
> 
> - [ ] I have added screenshots/videos to this PR showcasing its
changes ingame, **or** this PR does not require an ingame showcase
> 
> **Changelog**
> <!--
> Make players aware of new features and changes that could affect how
they play the game by adding a Changelog entry. Please read the
Changelog guidelines located at:
https://docs.spacestation14.io/en/getting-started/pr-guideline#changelog
> -->
> 
> 🆑
> - tweak: The biomass reclaimer may now reclaim plants, and inserting
smaller entities into it is now faster.


</details>

Co-authored-by: Ilya246 <[email protected]>
  • Loading branch information
SimpleStation14 and Ilya246 authored May 6, 2024
1 parent 8fd2d6b commit 2f7c608
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed partial class BiomassReclaimerComponent : Component
/// <summary>
/// The interval for <see cref="RandomMessTimer"/>.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("randomMessInterval")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public TimeSpan RandomMessInterval = TimeSpan.FromSeconds(5);

/// <summary>
Expand All @@ -28,9 +28,10 @@ public sealed partial class BiomassReclaimerComponent : Component
/// <summary>
/// Amount of biomass that the mob being processed will yield.
/// This is calculated from the YieldPerUnitMass.
/// Also stores non-integer leftovers.
/// </summary>
[ViewVariables]
public int CurrentExpectedYield = default;
public float CurrentExpectedYield = 0f;

/// <summary>
/// The reagent that will be spilled while processing a mob.
Expand All @@ -49,6 +50,18 @@ public sealed partial class BiomassReclaimerComponent : Component
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float YieldPerUnitMass = 0.4f;

/// <summary>
/// How many seconds to take to insert an entity per unit of its mass.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float BaseInsertionDelay = 0.1f;

/// <summary>
/// How much to multiply biomass yield from botany produce.
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
public float ProduceYieldMultiplier = 0.25f;

/// <summary>
/// The time it takes to process a mob, per mass.
/// </summary>
Expand All @@ -58,7 +71,7 @@ public sealed partial class BiomassReclaimerComponent : Component
/// <summary>
/// Will this refuse to gib a living mob?
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("safetyEnabled")]
[ViewVariables(VVAccess.ReadWrite), DataField]
public bool SafetyEnabled = true;
}
}
37 changes: 29 additions & 8 deletions Content.Server/Medical/BiomassReclaimer/BiomassReclaimerSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Numerics;
using Content.Server.Body.Components;
using Content.Server.Botany.Components;
using Content.Server.Fluids.EntitySystems;
using Content.Server.Materials;
using Content.Server.Power.Components;
Expand All @@ -17,6 +18,7 @@
using Content.Shared.Jittering;
using Content.Shared.Medical;
using Content.Shared.Mind;
using Content.Shared.Materials;
using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems;
using Content.Shared.Nutrition.Components;
Expand All @@ -26,6 +28,7 @@
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Physics.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;

namespace Content.Server.Medical.BiomassReclaimer
Expand All @@ -47,6 +50,9 @@ public sealed class BiomassReclaimerSystem : EntitySystem
[Dependency] private readonly MaterialStorageSystem _material = default!;
[Dependency] private readonly SharedMindSystem _minds = default!;

[ValidatePrototypeId<MaterialPrototype>]
public const string BiomassPrototype = "Biomass";

public override void Update(float frameTime)
{
base.Update(frameTime);
Expand Down Expand Up @@ -79,7 +85,9 @@ public override void Update(float frameTime)
continue;
}

_material.SpawnMultipleFromMaterial(reclaimer.CurrentExpectedYield, "Biomass", Transform(uid).Coordinates);
var actualYield = (int) (reclaimer.CurrentExpectedYield); // can only have integer biomass
reclaimer.CurrentExpectedYield = reclaimer.CurrentExpectedYield - actualYield; // store non-integer leftovers
_material.SpawnMultipleFromMaterial(actualYield, BiomassPrototype, Transform(uid).Coordinates);

reclaimer.BloodReagent = null;
reclaimer.SpawnedEntities.Clear();
Expand Down Expand Up @@ -148,10 +156,14 @@ private void OnAfterInteractUsing(Entity<BiomassReclaimerComponent> reclaimer, r
if (!args.CanReach || args.Target == null)
return;

if (!HasComp<MobStateComponent>(args.Used) || !CanGib(reclaimer, args.Used))
if (!CanGib(reclaimer, args.Used))
return;

if (!TryComp<PhysicsComponent>(args.Used, out var physics))
return;

_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, 7f, new ReclaimerDoAfterEvent(), reclaimer, target: args.Target, used: args.Used)
var delay = reclaimer.Comp.BaseInsertionDelay * physics.FixturesMass;
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, args.User, delay, new ReclaimerDoAfterEvent(), reclaimer, target: args.Target, used: args.Used)
{
BreakOnTargetMove = true,
BreakOnUserMove = true,
Expand All @@ -174,11 +186,14 @@ private void OnClimbedOn(Entity<BiomassReclaimerComponent> reclaimer, ref Climbe

private void OnDoAfter(Entity<BiomassReclaimerComponent> reclaimer, ref ReclaimerDoAfterEvent args)
{
if (args.Handled || args.Cancelled || args.Args.Target == null || HasComp<BiomassReclaimerComponent>(args.Args.Target.Value))
if (args.Handled || args.Cancelled)
return;

if (args.Args.Used == null || args.Args.Target == null || !HasComp<BiomassReclaimerComponent>(args.Args.Target.Value))
return;

_adminLogger.Add(LogType.Action, LogImpact.Extreme, $"{ToPrettyString(args.Args.User):player} used a biomass reclaimer to gib {ToPrettyString(args.Args.Target.Value):target} in {ToPrettyString(reclaimer):reclaimer}");
StartProcessing(args.Args.Target.Value, reclaimer);
StartProcessing(args.Args.Used.Value, reclaimer);

args.Handled = true;
}
Expand All @@ -200,8 +215,13 @@ private void StartProcessing(EntityUid toProcess, Entity<BiomassReclaimerCompone
component.SpawnedEntities = butcherableComponent.SpawnedEntities;
}

component.CurrentExpectedYield = (int) Math.Max(0, physics.FixturesMass * component.YieldPerUnitMass);
var expectedYield = physics.FixturesMass * component.YieldPerUnitMass;
if (HasComp<ProduceComponent>(toProcess))
expectedYield *= component.ProduceYieldMultiplier;
component.CurrentExpectedYield += expectedYield;

component.ProcessingTimer = physics.FixturesMass * component.ProcessingTimePerUnitMass;

QueueDel(toProcess);
}

Expand All @@ -210,7 +230,8 @@ private bool CanGib(Entity<BiomassReclaimerComponent> reclaimer, EntityUid dragg
if (HasComp<ActiveBiomassReclaimerComponent>(reclaimer))
return false;

if (!HasComp<MobStateComponent>(dragged))
bool isPlant = HasComp<ProduceComponent>(dragged);
if (!isPlant && !HasComp<MobStateComponent>(dragged))
return false;

if (!Transform(reclaimer).Anchored)
Expand All @@ -219,7 +240,7 @@ private bool CanGib(Entity<BiomassReclaimerComponent> reclaimer, EntityUid dragg
if (TryComp<ApcPowerReceiverComponent>(reclaimer, out var power) && !power.Powered)
return false;

if (reclaimer.Comp.SafetyEnabled && !_mobState.IsDead(dragged))
if (!isPlant && reclaimer.Comp.SafetyEnabled && !_mobState.IsDead(dragged))
return false;

// Reject souled bodies in easy mode.
Expand Down

0 comments on commit 2f7c608

Please sign in to comment.