OrionFive / Hospitality

Orion's "Hospitality" and more
https://www.patreon.com/orionmods
GNU General Public License v3.0
91 stars 54 forks source link

Hospitality: Compatibility with MedPod #805

Closed sumghai closed 2 months ago

sumghai commented 2 months ago

What problem does your suggestion solve A number of players have reported that as of Hospitality v1.5.0.5 and MedPod v1.5.26, Hospitality guests with medical conditions do not automatically seek out treatment on MedPods, which are spacer/ultratech medical beds designed to rapidly heal nearly all hediffs at the cost of very high power consumption.

Describe the solution you propose I'd like to suggest a minor collaboration between myself (@sumghai) and @OrionFive, to make minor code changes to both our mods, so that Hospitality guests will automatically use MedPods within the designated guest area. (sumghai/MedPod#64)

Context:

  • The MedPod mod uses a custom MedPod.JobGiver_PatientGoToMedPod to automatically and periodically check if a pawn has any acute or chronic/incurable hediffs, and orders said pawn to find and use a MedPod.
  • This custom JobDriver is not related to the vanilla JobGiver_PatientGoToBed or the RestingForMedicalReasons think node tag, as vanilla behaviour would only trigger if the pawn has an acute/tendable medical emergency.
  • MedPod contains its own custom medical rest and AI utilities, which are based on vanilla methods but with extra MedPod-specific logic.
  • The v1.5.26 public stable release of MedPod currently does not allow non-colonists / guests to use MedPods at all.

Scope:

  • For simplicity, Hospitality guests should be able to use any MedPods free of charge (rather than using a vending machine payment system like how Hospitality handles Replimat Terminals).
  • A possible stretch goal may be that guests who have used a MedPod would have a more positive opinion of their stay (not 100% sure how Hospitality does this).

Progress so far:

  • I (@sumghai) have a WIP dev branch (https://github.com/sumghai/MedPod/tree/guestmode_dev) that adds a new "Allow guests" gizmo button to MedPods for humanlikes, along with internal logic and a public allowGuests boolean flag that should theoretically allow non-colonists to use MedPods with the gizmo set to true/enabled.
  • Hospitality guests currently still ignore this boolean value and underlying logic, and so still do not use MedPods.

TODO - Questions for @OrionFive

  • [ ] In the Hospitality mod's Relax DutyDef thinktree, where would be the ideal patch insertion location for MedPod.JobGiver_PatientGoToMedPod? This should be a high priority job, so that guests with "incurable" conditions like bad backs or Luciferium addiction should immediately seek out an available MedPod.
  • [ ] What changes are needed for Hospitality's RestUtility_Patch.cs (and/or MedPod's own code) for guests to recognize MedPods as a valid (or even prioritized) medical bed?

Links and references to the MedPod code can be provided on request to aid in discussions.

Describe alternatives you've considered The sole alternative is to have guest only be able to use regular hospital beds only in emergencies, and be unable to treat incurable conditions. This is essentially current behaviour, but fails to address to requests of players who use both mods.

OrionFive commented 2 months ago

I haven't meddled with medical stuff in Hospitality for a long time. My guess is that you should insert the ThinkNode in

            <li Class="ThinkNode_Tagger">
              <tagToGive>RestingForMedicalReasons</tagToGive>
              <subNodes>
                <li Class="JobGiver_PatientGoToBed" />
              </subNodes>
            </li>

Concerning RestUtility_Patch, I think you should patch IsValidBedFor (which you probably already have) and use Hospitality.GuestUtility.IsGuest(Pawn) to determine if the pawn in question is a guest. I'm not sure even that is needed, since you essentially want all pawns to use pods, regardless of if they're guests.

sumghai commented 2 months ago

My guess is that you should insert the ThinkNode in

          <li Class="ThinkNode_Tagger">
            <tagToGive>RestingForMedicalReasons</tagToGive>
            <subNodes>

I probably mentioned this before, but inserting the ThinkNode under the RestingForMedicalReasons means guests only use MedPods for acute medical emergencies, and not if they only have permanent scars or incurable chronic conditions.

Instead, I targeted Humanlike_PreMain under Hospitality.ThinkNode_OnlyAllowed, which seems to work better at getting guests to automatically prioritize using MedPods if they have anything that the MedPods are designed to treat. Apparently, Hospitality.GuestUtility.IsGuest(Pawn) wasn't needed as you guessed.

However, I've now run into a new problem - guests who finish treatment on MedPods now lose their assigned Hospitality guest bed when they wake up, are forced to "re-join" the guest group, and subsequently complain that they don't have any money left to re-rent a guest bed. Essentially, they lose their Visitor duty.

My MedPod code currently applies a custom coma hediff to keep patients on MedPods, as in the past there have been issues where patients prematurely jump off MedPods without completing treatment. It seems that applying this hediff makes either the base game or Hospitality think the pawn has been Downed() or made unconscious.

I tried caching the guest pawn's duty before treatment and restoring it after finishing treatment, but it seems that the very act of making guests on MedPods unconscious removes their Hospitality guest status.

Alternatively, when I disable the MedPod coma hediff, the guest pawn retains their guest status and duty but runs off halfway during treatment. I've tried various Harmony patches, job giver parameters to tell the pawn to stay until treatment is finished, but nothing seems to stick.

Do you think there's something you could tweak on your end to tell guests to retain their guest status/duty even when downed/unconscious?

Here's a link to my MedPod dev build with source code, if you want to try it out on your end - https://github.com/sumghai/MedPod/archive/refs/heads/guestmode_dev.zip

Test conditions:

sumghai commented 2 months ago

It looks like I'll have to rewrite MedPod to not use its coma hediff, and instead rely on a different mechanism for keeping patients within MedPods so that lords and duties from mods like Hospitality aren't affected. As such, the ball's in my court.

I think this is a good place to wrap things up here. Thanks again, @OrionFive.

OrionFive commented 2 months ago

Sorry for the late response. The mechanism is that when guests are downed, they need to be medically handled, so they stop being guests, so medical stuff works as intended. However, when any pawn is rescued, they get flagged as rescued and subsequently become guests once recovered.

Keeping pawns from getting up and running off can probably be handled by hooking into the top of the Relax ThinkTree somewhere before other activities.

Maybe that helps.