Skip to content

Commit

Permalink
Cryosleep Fallbacks (new-frontiers-14#2482)
Browse files Browse the repository at this point in the history
  • Loading branch information
whatston3 authored Dec 3, 2024
1 parent 180f2ca commit 78373ba
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Content.Client/CryoSleep/CryosleepWakeupWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void OnWakeupResponse(WakeupRequestMessage.Response response)
DenyButton.Disabled = false;
if (response.Status == ReturnToBodyStatus.Occupied)
Label.SetMessage(Loc.GetString("cryo-wakeup-result-occupied"));
else if (response.Status == ReturnToBodyStatus.CryopodMissing)
else if (response.Status == ReturnToBodyStatus.NoCryopodAvailable)
Label.SetMessage(Loc.GetString("cryo-wakeup-result-no-cryopod"));
else if (response.Status == ReturnToBodyStatus.BodyMissing)
Label.SetMessage(Loc.GetString("cryo-wakeup-result-no-body"));
Expand Down
6 changes: 6 additions & 0 deletions Content.Server/_NF/CryoSleep/CryoSleepFallbackComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Server.CryoSleep;

// In the case a user's body cannot be revived in a cryopod, this component denotes an entity as being
// a fallback to revive them at.
[RegisterComponent]
public sealed partial class CryoSleepFallbackComponent : Component;
30 changes: 24 additions & 6 deletions Content.Server/_NF/CryoSleep/CryoSleepSystem.Returning.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,30 @@ public ReturnToBodyStatus TryReturnToBody(MindComponent mind, bool force = false
return ReturnToBodyStatus.NotAGhost;

var cryopod = storedBody!.Value.Cryopod;
if (!Exists(cryopod) || Deleted(cryopod) || !TryComp<CryoSleepComponent>(cryopod, out var cryoComp))
return ReturnToBodyStatus.CryopodMissing;

var body = storedBody.Value.Body;
if (IsOccupied(cryoComp) || !_container.Insert(body, cryoComp.BodyContainer))
return ReturnToBodyStatus.Occupied;
if (!Exists(cryopod) || Deleted(cryopod) || !TryComp<CryoSleepComponent>(cryopod, out var cryoComp))
{
var fallbackQuery = EntityQueryEnumerator<CryoSleepFallbackComponent, CryoSleepComponent>();
bool foundFallback = false;
while (fallbackQuery.MoveNext(out cryopod, out _, out cryoComp))
{
if (!IsOccupied(cryoComp) && _container.Insert(body, cryoComp.BodyContainer))
{
foundFallback = true;
break;
}
}

// No valid cryopod, all fallbacks occupied or missing.
if (!foundFallback)
return ReturnToBodyStatus.NoCryopodAvailable;
}
else
{
// NOTE: if the pod is occupied but still exists, do not let the user teleport.
if (IsOccupied(cryoComp!) || !_container.Insert(body, cryoComp!.BodyContainer))
return ReturnToBodyStatus.Occupied;
}

_storedBodies.Remove(id.Value);
_mind.ControlMob(id.Value, body);
Expand All @@ -74,7 +92,7 @@ public ReturnToBodyStatus TryReturnToBody(MindComponent mind, bool force = false

_popup.PopupEntity(Loc.GetString("cryopod-wake-up", ("entity", body)), body);

RaiseLocalEvent(body, new CryosleepWakeUpEvent(storedBody.Value.Cryopod, id), true);
RaiseLocalEvent(body, new CryosleepWakeUpEvent(cryopod, id), true);

_adminLogger.Add(LogType.LateJoin, LogImpact.Medium, $"{id.Value} has returned from cryosleep!");
return ReturnToBodyStatus.Success;
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/_NF/CryoSleep/SharedCryoSleepSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public enum ReturnToBodyStatus : byte
Success,
Occupied,
BodyMissing,
CryopodMissing,
NoCryopodAvailable,
NotAGhost,
Disabled
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cryo-wakeup-window-accept-button = Accept
cryo-wakeup-window-deny-button = Cancel
cryo-wakeup-window-rules = You are going to try to return from your cryosleep! You do not know anything that happened since the moment you went to sleep. Accept this and continue?
cryo-wakeup-result-occupied = The cryopod is occupied! Try waiting a bit.
cryo-wakeup-result-no-cryopod = The cryopod went missing! Uh oh.
cryo-wakeup-result-no-cryopod = No cryopods were available to return your body to.
cryo-wakeup-result-no-body = You do not have a cryosleeping body!
cryo-wakeup-result-disabled = Returning from cryosleep is disabled on this server.
Expand Down
2 changes: 1 addition & 1 deletion Resources/Maps/_NF/Outpost/frontier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27613,7 +27613,7 @@ entities:
rot: -1.5707963267948966 rad
pos: 33.5,17.5
parent: 2173
- proto: MachineCryoSleepPod
- proto: MachineCryoSleepPodFallback
entities:
- uid: 1394
components:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@
containers:
body_container: !type:ContainerSlot

# WIP for a medical bounty reclaimer machine
# If cryopods get deleted, this one is considered as a safe fallback.
- type: entity
id: MachineCryoSleepPodFallback
parent: MachineCryoSleepPod
suffix: Fallback
components:
- type: CryoSleepFallback

- type: entity
parent: [BaseStructureDisableToolUse, BaseStructureIndestructible, BaseMachinePowered]
id: MachineMedicalBountyRedemption
Expand Down

0 comments on commit 78373ba

Please sign in to comment.