CorsixTH/CorsixTH — pull request #305 by benckx (2014-09-04 14:35:39+00:00)
Title: Fix #838

Issue: When picking up one of the surgeons in the middle of an operation, another surgeon comes in the room, changes his clothes but does not resume the operation. Instead, he just wanders around, waiting for patients to come. So the operation never finishes and the queue of the room just grows infinitely.

https://code.google.com/p/corsix-th/issues/detail?id=838

For some reason, only the surgeon whose we see from behind can be picked up.

Thanks to this fix, one surgeon comes back to replace the picked up one (as he used to), but now washes his hands and restarts the operation. I also added a few changes for the sake of readability (e.g. a setter function to turn on/off the x-ray viewer), which helped me grasping the logic of the room behaviour.

The action queue thing still confuses me a bit and it's possible that I don't manage them perfectly as I should, so feedback is welcomed on this topic.

In some cases, while testing, I even found the following stack trace but I don't really know how to reproduce it or how it happened exactly (it triggered the error box but it was able to recover):

An error has occured! (sic)
Almost anything can be the cause, but the detailed information below can help the developers find the source of the error.
Running: The timer handler.
A stack trace is included below, and the handler has been disconnected.
./Lua/humanoid_actions/multi_use_object.lua:313: attempt to index a nil value
stack traceback:

./Lua/humanoid_actions/multi_use_object.lua: in function <./Lua/humanoid_actions/multi_use_object.lua:279>
./Lua/entities/humanoid.lua:558: in function 'Humanoid_startAction'
./Lua/entities/humanoid.lua:650: in function 'finishAction'
./Lua/humanoid_actions/walk.lua:144: in function 'timer_function'
./Lua/entity.lua:166: in function 'tick'
./Lua/world.lua:1085: in function 'onTick'
./Lua/app.lua:839: in function 'dispatch'
./Lua/app.lua:740: in function <./Lua/app.lua:735>

It would probably makes sense to add a kind of penalty (decrease patient's happiness or even make her/him die sometimes) if the surgeon has been picked up during operation, but I suppose that'd rather be for another patch.