| 1 |
--[[ Copyright (c) 2009 Peter "Corsix" Cawley |
| 2 |
|
| 3 |
Permission is hereby granted, free of charge, to any person obtaining a copy of |
| 4 |
this software and associated documentation files (the "Software"), to deal in |
| 5 |
the Software without restriction, including without limitation the rights to |
| 6 |
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies |
| 7 |
of the Software, and to permit persons to whom the Software is furnished to do |
| 8 |
so, subject to the following conditions: |
| 9 |
|
| 10 |
The above copyright notice and this permission notice shall be included in all |
| 11 |
copies or substantial portions of the Software. |
| 12 |
|
| 13 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 14 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 16 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 17 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 18 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 19 |
SOFTWARE. --]] |
| 20 |
|
| 21 |
local room = {} |
| 22 |
room.id = "toilets" |
| 23 |
room.vip_must_visit = false |
| 24 |
room.level_config_id = 29 |
| 25 |
room.class = "ToiletRoom" |
| 26 |
room.name = _S.rooms_short.toilets |
| 27 |
room.long_name = _S.rooms_long.toilets |
| 28 |
room.tooltip = _S.tooltip.rooms.toilets |
| 29 |
room.objects_additional = { "extinguisher", "radiator", "plant", "bin", "loo", "sink" } |
| 30 |
room.objects_needed = { loo = 1, sink = 1 } |
| 31 |
room.build_preview_animation = 5098 |
| 32 |
room.categories = { |
| 33 |
facilities = 3, |
| 34 |
} |
| 35 |
room.minimum_size = 4 |
| 36 |
room.wall_type = "green" |
| 37 |
room.floor_tile = 21 |
| 38 |
|
| 39 |
class "ToiletRoom" (Room) |
| 40 |
|
| 41 |
---@type ToiletRoom |
| 42 |
local ToiletRoom = _G["ToiletRoom"] |
| 43 |
|
| 44 |
function ToiletRoom:ToiletRoom(...) |
| 45 |
self:Room(...) |
| 46 |
self.door.queue:setBenchThreshold(3) |
| 47 |
end |
| 48 |
|
| 49 |
function ToiletRoom:roomFinished() |
| 50 |
local fx, fy = self:getEntranceXY(true) |
| 51 |
local objects = self.world:findAllObjectsNear(fx, fy) |
| 52 |
local number = 0 |
| 53 |
for object, _ in pairs(objects) do |
| 54 |
if object.object_type.id == "loo" then |
| 55 |
number = number + 1 |
| 56 |
end |
| 57 |
end |
| 58 |
self.maximum_patients = number |
| 59 |
Room.roomFinished(self) |
| 60 |
end |
| 61 |
|
| 62 |
function ToiletRoom:dealtWithPatient(patient) |
| 63 |
-- Continue going to the room before going to the toilets. |
| 64 |
patient:setNextAction(self:createLeaveAction()) |
| 65 |
if patient.next_room_to_visit then |
| 66 |
patient:queueAction(SeekRoomAction(patient.next_room_to_visit.room_info.id)) |
| 67 |
else |
| 68 |
patient:queueAction(SeekReceptionAction()) |
| 69 |
end |
| 70 |
end |
| 71 |
|
| 72 |
function ToiletRoom:onHumanoidEnter(humanoid) |
| 73 |
if class.is(humanoid, Patient) then |
| 74 |
local loo, lx, ly = self.world:findFreeObjectNearToUse(humanoid, "loo") |
| 75 |
if loo and lx and ly then |
| 76 |
humanoid:walkTo(lx, ly) |
| 77 |
loo.reserved_for = humanoid |
| 78 |
local use_time = math.random(0, 2) |
| 79 |
-- One class only have a 1 tick long usage animation |
| 80 |
if humanoid:isType("Transparent Female Patient") then |
| 81 |
use_time = math.random(15, 40) |
| 82 |
end |
| 83 |
|
| 84 |
local loop_callback_toilets = --[[persistable:toilets_loop_callback]] function() |
| 85 |
use_time = use_time - 1 |
| 86 |
if use_time <= 0 then |
| 87 |
humanoid:setMood("poo", "deactivate") |
| 88 |
humanoid:changeAttribute("toilet_need", -(0.85 + math.random() * 0.15)) |
| 89 |
humanoid.going_to_toilet = "no" |
| 90 |
|
| 91 |
-- There are only animations for standard patients to use the sinks. |
| 92 |
if humanoid:isType("Standard Female Patient") or |
| 93 |
humanoid:isType("Standard Male Patient") then |
| 94 |
local --[[persistable:toilets_find_sink]] function after_use() |
| 95 |
local sink, sx, sy = self.world:findFreeObjectNearToUse(humanoid, "sink") |
| 96 |
if sink then |
| 97 |
humanoid:walkTo(sx, sy) |
| 98 |
|
| 99 |
local after_use_sink = --[[persistable:toilets_after_use_sink]] function() |
| 100 |
self:dealtWithPatient(humanoid) |
| 101 |
end |
| 102 |
|
| 103 |
humanoid:queueAction(UseObjectAction(sink):setProlongedUsage(false) |
| 104 |
:setAfterUse(after_use_sink)) |
| 105 |
sink.reserved_for = humanoid |
| 106 |
-- Make sure that the mood waiting is no longer active. |
| 107 |
humanoid:setMood("patient_wait", "deactivate") |
| 108 |
else |
| 109 |
-- if there is a queue to wash hands there is a chance we might not bother |
| 110 |
-- but the patient won't be happy about this. |
| 111 |
if math.random(1, 4) > 2 then |
| 112 |
-- Wait for a while before trying again. |
| 113 |
humanoid:setNextAction(IdleAction():setCount(5):setAfterUse(after_use) |
| 114 |
:setDirection(loo.direction == "north" and "south" or "east")) |
| 115 |
|
| 116 |
else |
| 117 |
self:dealtWithPatient(humanoid) |
| 118 |
humanoid:changeAttribute("happiness", -0.08) |
| 119 |
humanoid:setMood("patient_wait", "deactivate") |
| 120 |
end |
| 121 |
-- For now, activate the wait icon to show the player that the patient hasn't |
| 122 |
-- got stuck. TODO: Make a custom mood? Let many people use the sinks? |
| 123 |
humanoid:setMood("patient_wait", "activate") |
| 124 |
end |
| 125 |
end |
| 126 |
after_use() |
| 127 |
else |
| 128 |
self:dealtWithPatient(humanoid) |
| 129 |
end |
| 130 |
end |
| 131 |
end |
| 132 |
|
| 133 |
humanoid:queueAction(UseObjectAction(loo):setLoopCallback(loop_callback_toilets)) |
| 134 |
else |
| 135 |
--[[ If no loo is found, perhaps the patient followed another one in and they were heading for the same one. |
| 136 |
Now there is no free loo, so wait for a bit and then leave the room to wait outside. No need for a warning |
| 137 |
as this is what happens in busy toilets]] |
| 138 |
humanoid:setNextAction(MeanderAction():setCount(1)) |
| 139 |
humanoid:queueAction(self:createLeaveAction()) |
| 140 |
humanoid:queueAction(self:createEnterAction(humanoid)) |
| 141 |
end |
| 142 |
end |
| 143 |
return Room.onHumanoidEnter(self, humanoid) |
| 144 |
end |
| 145 |
|
| 146 |
-- Override the standard way to count the number of patients to take into account |
| 147 |
-- that some of them may not be using the loo, allowing others to enter the room earlier than normal; |
| 148 |
-- but not if there is only one loo in the room, then it becomes a private toilet with only one person at a time. |
| 149 |
function ToiletRoom:getPatientCount() |
| 150 |
local number_users = 0 |
| 151 |
local not_using_loo = 0 |
| 152 |
for humanoid in pairs(self.humanoids) do |
| 153 |
if class.is(humanoid, Patient) then |
| 154 |
number_users = number_users + 1 |
| 155 |
|
| 156 |
if humanoid:getCurrentAction().name == "use_object" and |
| 157 |
humanoid:getCurrentAction().object.object_type.id ~= "loo" then |
| 158 |
not_using_loo = not_using_loo + 1 |
| 159 |
end |
| 160 |
end |
| 161 |
end |
| 162 |
|
| 163 |
if self.maximum_patients == 1 then |
| 164 |
return number_users |
| 165 |
else |
| 166 |
return number_users - not_using_loo |
| 167 |
end |
| 168 |
end |
| 169 |
|
| 170 |
function ToiletRoom:afterLoad(old, new) |
| 171 |
if old < 110 then |
| 172 |
room.free_loos = nil |
| 173 |
end |
| 174 |
Room.afterLoad(self, old, new) |
| 175 |
end |
| 176 |
|
| 177 |
return room |