边缘世界 RimWorld

边缘世界 RimWorld

Move the Patient
kenny 10 月 6 日 上午 5:35
Bugreport:
Hey! I just spent some time bug hunting an issue where pawns get stuck trying to move a patient to beds for operations. The following report was written with Deepseek, so it might not be 100% comprehensive and accurate, but I verified the basic assumptions and the logic seems sound to me. I hope it helps improve this nice mod!

The basic testing setup:
One operating table set as surgery bed, for colonists. No surgery bed for prisoners, but a normal bed was available for the prisoner.
Setting an operation on the prisoner fails the job creation and the surgeon or nurse trying to move them gets stuck in a job assignment error loop.



Deepseek generated report:

Bug Report: Move the Patient Mod - Infinite Loop with Prisoners/Slaves/Guests
Problem Summary

The Move the Patient mod causes an infinite job loop when trying to assign restricted pawn types (prisoners, slaves, guests) to incompatible surgery beds. This results in:

- Log spam: "Pawn started 10 jobs in one tick" errors

- Game performance issues: Infinite job creation loops

- Failed surgeries: Prisoners/slaves cannot receive needed medical care

- Stuck pawns attempting to move patients to surgery beds

Root Cause Analysis
Primary Issue

The mod's BedUtility.FindBestSurgeryBed() method finds surgery beds but does not check bed compatibility with the pawn's status:
// Current problematic code in BedUtility.FindBestSurgeryBed(): List<Building_Bed> list = BedUtility.GetSurgeryBeds(pawn.Map).Where(bed => { if (bed == null || bed.Destroyed || !bed.Spawned || !bed.Medical || !bed.AnyUnoccupiedSleepingSlot) return false; return worker == null || worker.CanReach(bed, PathEndMode.ClosestTouch, Danger.Deadly); // MISSING: Check for prisoner/slave/guest compatibility! }).ToList();

Secondary Issue

The mod's bed validation in JobDriver_TransferPatientToBed.IsValidBedForPawnStatic() is correct but comes too late - the invalid job is already created and fails, causing retries.
Affected Pawn Types

Prisoners: Require bed.ForPrisoners == true

Slaves: Require bed.ForSlaves == true

Guests: Require !bed.ForPrisoners && !bed.ForSlaves (can use colonist beds)

The Infinite Loop Sequence

Mod finds surgery bed → Returns closest medical bed regardless of prisoner status

Job creation → TakeToBedToOperate job created with invalid bed assignment

Job validation fails → IsValidBedForPawnStatic rejects the assignment

Job retry → Work giver immediately recreates the same invalid job

Repeat forever → Creates 10+ jobs per tick until error threshold

Potential Solution: Enhanced Bed Filtering

Modify the original bed filtering in FindBestSurgeryBed:

// In BedUtility.FindBestSurgeryBed(), replace the bed filtering: List<Building_Bed> list = BedUtility.GetSurgeryBeds(pawn.Map).Where(bed => { if (bed == null || bed.Destroyed || !bed.Spawned || !bed.Medical || !bed.AnyUnoccupiedSleepingSlot) return false; // ADD THIS COMPATIBILITY CHECK: if (pawn.IsPrisonerOfColony && !bed.ForPrisoners) return false; if (pawn.IsSlaveOfColony && !bed.ForSlaves) return false; if (pawn.GuestStatus == GuestStatus.Guest && (bed.ForPrisoners || bed.ForSlaves)) return false; return worker == null || worker.CanReach(bed, PathEndMode.ClosestTouch, Danger.Deadly); }).ToList();

Assumptions & Testing Notes
Verified Assumptions

Prisoners: Cannot use colonist beds (vanilla behavior)

Slaves: Cannot use non-slave beds (vanilla behavior)

Guests: Can use colonist hospital beds (vanilla behavior)

Move the Patient: Intends to move all pawn types to surgery beds when needed

Expected Behavior After Fix

Prisoners: Assigned only to prisoner surgery beds

Slaves: Assigned only to slave surgery beds

Guests: Assigned only to colonist surgery beds (not prisoner/slave)

No compatible beds: Job fails gracefully with "No suitable bed" message

No infinite loops: Invalid bed assignments prevented at source

Testing Recommendations

Test with prisoner needing surgery when:

Only colonist surgery beds available

Prisoner surgery beds available

No surgery beds available

Repeat tests with slaves and guests

Verify no job spam in developer log
< >
正在显示第 1 - 1 条,共 1 条留言
Hey, thank you so much for this very detailed bug report. I managed to fix the bug with a simple status check with my bool method IsBedCompatibleWithPawn(). There are a few situations that I most likely overlooked and this was one of them.

I recreated the scenario you described, and the job spam no longer appears :GDNormal:
< >
正在显示第 1 - 1 条,共 1 条留言
每页显示数: 1530 50