Loading

Paste #pxgoy4hiz

  1. diff --git a/CorsixTH/Lua/room.lua b/CorsixTH/Lua/room.lua
  2. index e338916..0aadacf 100644
  3. --- a/CorsixTH/Lua/room.lua
  4. +++ b/CorsixTH/Lua/room.lua
  5. @@ -678,13 +678,13 @@ function Room:roomFinished()
  6.    self:tryAdvanceQueue()
  7.  end
  8.  
  9. ---! Try to move a patient from another room to us.
  10. ---!param room (Room) Other room to 'steal' from.
  11. +--! Try to move a patient from the old room to the new room.
  12. +--!param old_room (Room) Room that currently has the patient in the queue.
  13. +--!param new_room (Room) Room that wants the patient in the queue.
  14.  --!param patient (Humanoid) Patient to move.
  15. ---!return (boolean) Whether we are done with this room (no more patients will come from it).
  16. -function Room:tryMovePatient(room, patient)
  17. -  local world = self.world
  18. -  local other_queue = room.door.queue
  19. +--!return (boolean) Whether we are done with the old room (no more patients will come from it).
  20. +local function tryMovePatient(old_room, new_room, patient)
  21. +  local world = new_room.world
  22.  
  23.    local px, py = patient.tile_x, patient.tile_y
  24.    -- Don't reroute the patient if he just decided to go to the toilet
  25. @@ -692,26 +692,27 @@ function Room:tryMovePatient(room, patient)
  26.      return false
  27.    end
  28.  
  29. -  local our_x, our_y = self:getEntranceXY(true)
  30. -  local other_x, other_y = room:getEntranceXY(true)
  31. -  local distance_to_us = world:getPathDistance(px, py, our_x, our_y)
  32. -  if not distance_to_us then return true end -- Patient cannot reach us, quit trying
  33. +  local new_x, new_y = new_room:getEntranceXY(true)
  34. +  local old_x, old_y = old_room:getEntranceXY(true)
  35. +  local new_distance = world:getPathDistance(px, py, new_x, new_y)
  36. +  if not new_distance then return true end -- Patient cannot reach us, quit trying
  37.  
  38. -  local our_score = self:getUsageScore() + distance_to_us
  39. -  local other_score
  40. -  local distance_to_current_room = world:getPathDistance(px, py, other_x, other_y)
  41. -  if distance_to_current_room then
  42. -    other_score = room:getUsageScore() + distance_to_current_room
  43. +  local new_score = new_room:getUsageScore() + new_distance
  44. +  local old_score
  45. +  local old_distance = world:getPathDistance(px, py, old_x, old_y)
  46. +  if old_distance then
  47. +    old_score = old_room:getUsageScore() + old_distance
  48.    else
  49. -    other_score = our_score + 1 -- Make condition below fail.
  50. +    old_score = new_score + 1 -- Make condition below fail.
  51.    end
  52. -  if our_score >= other_score then return true end
  53. +  if new_score >= old_score then return true end
  54.  
  55.    -- Update the queues
  56. -  other_queue:removeValue(patient)
  57. -  patient.next_room_to_visit = self
  58. -  self.door.queue:expect(patient)
  59. -  self.door:updateDynamicInfo()
  60. +  local old_queue = old_room.door.queue
  61. +  old_queue:removeValue(patient)
  62. +  patient.next_room_to_visit = new_room
  63. +  new_room.door.queue:expect(patient)
  64. +  new_room.door:updateDynamicInfo()
  65.  
  66.    -- Rewrite the action queue
  67.    for i, action in ipairs(patient.action_queue) do
  68. @@ -724,8 +725,8 @@ function Room:tryMovePatient(room, patient)
  69.      -- again, is_in_queue is set to false so the callback won't run
  70.      if action.name == 'queue' then
  71.        action.is_in_queue = false
  72. -    elseif action.name == "walk" and action.x == other_x and action.y == other_y then
  73. -      local action = self:createEnterAction(patient)
  74. +    elseif action.name == "walk" and action.x == old_x and action.y == old_y then
  75. +      local action = new_room:createEnterAction(patient)
  76.        patient:queueAction(action, i)
  77.        break
  78.      end
  79. @@ -746,15 +747,15 @@ function Room:tryToFindNearbyPatients()
  80.      return
  81.    end
  82.  
  83. -  for _, room in pairs(self.world.rooms) do
  84. -    if room.hospital == self.hospital and room ~= self and
  85. -        room.room_info == self.room_info and room.door.queue and
  86. -        room.door.queue:reportedSize() >= 2 then
  87. -      local other_queue = room.door.queue
  88. -      local pat_number = other_queue:reportedSize()
  89. +  for _, old_room in pairs(self.world.rooms) do
  90. +    if old_room.hospital == self.hospital and old_room ~= self and
  91. +        old_room.room_info == self.room_info and old_room.door.queue and
  92. +        old_room.door.queue:reportedSize() >= 2 then
  93. +      local old_queue = old_room.door.queue
  94. +      local pat_number = old_queue:reportedSize()
  95.        while pat_number > 1 do
  96. -        local patient = other_queue:reportedHumanoid(pat_number)
  97. -        if self:tryMovePatient(room, patient) then break end
  98. +        local patient = old_queue:reportedHumanoid(pat_number)
  99. +        if tryMovePatient(old_room, self, patient) then break end
  100.          -- tryMovePatient may have just removed patient 'pat_number', but it does
  101.          -- not change the queue in front of it. 'pat_number - 1' thus still exists.
  102.          pat_number = pat_number - 1

Comments