| 1 |
--[[ Copyright (c) 2009 Manuel König |
| 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 = "research" |
| 23 |
room.vip_must_visit = true |
| 24 |
room.level_config_id = 28 |
| 25 |
room.class = "ResearchRoom" |
| 26 |
room.name = _S.rooms_short.research_room |
| 27 |
room.long_name = _S.rooms_long.research_room |
| 28 |
room.tooltip = _S.tooltip.rooms.research_room |
| 29 |
room.objects_additional = { |
| 30 |
"extinguisher", |
| 31 |
"radiator", |
| 32 |
"plant", |
| 33 |
"bin", |
| 34 |
"computer", |
| 35 |
"desk", |
| 36 |
"cabinet", |
| 37 |
"analyser" } |
| 38 |
room.objects_needed = { desk = 1, cabinet = 1, autopsy = 1 } |
| 39 |
room.build_preview_animation = 5102 |
| 40 |
room.categories = { |
| 41 |
facilities = 2, |
| 42 |
} |
| 43 |
room.minimum_size = 5 |
| 44 |
room.wall_type = "green" |
| 45 |
room.floor_tile = 21 |
| 46 |
room.required_staff = { |
| 47 |
Researcher = 1, |
| 48 |
} |
| 49 |
room.call_sound = "reqd023.wav" |
| 50 |
|
| 51 |
class "ResearchRoom" (Room) |
| 52 |
|
| 53 |
---@type ResearchRoom |
| 54 |
local ResearchRoom = _G["ResearchRoom"] |
| 55 |
|
| 56 |
function ResearchRoom:ResearchRoom(...) |
| 57 |
self:Room(...) |
| 58 |
self.staff_member_set = {} |
| 59 |
end |
| 60 |
|
| 61 |
local staff_usage_objects = { |
| 62 |
desk = true, |
| 63 |
cabinet = true, |
| 64 |
computer = true, |
| 65 |
analyser = true, |
| 66 |
-- Not autopsy: it should be free for when a patient arrives |
| 67 |
} |
| 68 |
|
| 69 |
function ResearchRoom:doStaffUseCycle(staff, previous_object) |
| 70 |
local obj, ox, oy = self.world:findFreeObjectNearToUse(staff, |
| 71 |
staff_usage_objects, "near", previous_object) |
| 72 |
|
| 73 |
if obj then |
| 74 |
obj.reserved_for = staff |
| 75 |
staff:walkTo(ox, oy) |
| 76 |
if obj.object_type.id == "desk" then |
| 77 |
local desk_use_time = math.random(7, 14) |
| 78 |
local loop_callback_desk = --[[persistable:research_desk_loop_callback]] function(action) |
| 79 |
desk_use_time = desk_use_time - 1 |
| 80 |
if action.todo_interrupt or desk_use_time == 0 then |
| 81 |
action.prolonged_usage = false |
| 82 |
end |
| 83 |
end |
| 84 |
|
| 85 |
local after_use_desk = --[[persistable:research_desk_after_use]] function() |
| 86 |
-- TODO: Should interactions give points? |
| 87 |
self.hospital.research:addResearchPoints(100) |
| 88 |
end |
| 89 |
|
| 90 |
staff:queueAction(UseObjectAction(obj):setLoopCallback(loop_callback_desk) |
| 91 |
:setAfterUse(after_use_desk)) |
| 92 |
else |
| 93 |
local after_use_obj = --[[persistable:research_obj_after_use]] function() |
| 94 |
if obj.object_type.id == "computer" then |
| 95 |
self.hospital.research:addResearchPoints(500) |
| 96 |
elseif obj.object_type.id == "analyser" then |
| 97 |
self.hospital.research:addResearchPoints(800) |
| 98 |
-- TODO: Balance value, find it in level config? |
| 99 |
end |
| 100 |
end |
| 101 |
|
| 102 |
staff:queueAction(UseObjectAction(obj):setAfterUse(after_use_obj)) |
| 103 |
end |
| 104 |
end |
| 105 |
|
| 106 |
local num_meanders = math.random(2, 4) |
| 107 |
local loop_callback_meander = --[[persistable:research_meander_loop_callback]] function() |
| 108 |
num_meanders = num_meanders - 1 |
| 109 |
if num_meanders == 0 then |
| 110 |
self:doStaffUseCycle(staff) |
| 111 |
end |
| 112 |
end |
| 113 |
|
| 114 |
staff:queueAction(MeanderAction():setLoopCallback(loop_callback_meander)) |
| 115 |
end |
| 116 |
|
| 117 |
function ResearchRoom:roomFinished() |
| 118 |
local fx, fy = self:getEntranceXY(true) |
| 119 |
local objects = self.world:findAllObjectsNear(fx, fy) |
| 120 |
local number = 0 |
| 121 |
for object, _ in pairs(objects) do |
| 122 |
-- The number of desks in the room determines how many researchers |
| 123 |
-- can work there at once. |
| 124 |
if object.object_type.id == "desk" then |
| 125 |
number = number + 1 |
| 126 |
end |
| 127 |
end |
| 128 |
self.maximum_staff = { |
| 129 |
Researcher = number, |
| 130 |
} |
| 131 |
-- Is this the first research department built? |
| 132 |
if not self.hospital.research_dep_built and not TheApp.using_demo_files then |
| 133 |
self.hospital.research_dep_built = true |
| 134 |
self.hospital:giveAdvice({_A.information.initial_general_advice |
| 135 |
.research_now_available}) |
| 136 |
end |
| 137 |
-- Also check if it would be good to hire a researcher. |
| 138 |
if self.hospital:countStaffOfCategory("Researcher", 1) == 0 then |
| 139 |
self.hospital:giveAdvice({_A.room_requirements.research_room_need_researcher}) |
| 140 |
end |
| 141 |
return Room.roomFinished(self) |
| 142 |
end |
| 143 |
|
| 144 |
function ResearchRoom:getMaximumStaffCriteria() |
| 145 |
return self.maximum_staff |
| 146 |
end |
| 147 |
|
| 148 |
function ResearchRoom:commandEnteringStaff(staff) |
| 149 |
self.staff_member_set[staff] = true |
| 150 |
self:doStaffUseCycle(staff) |
| 151 |
return Room.commandEnteringStaff(self, staff, true) |
| 152 |
end |
| 153 |
|
| 154 |
function ResearchRoom:commandEnteringPatient(patient) |
| 155 |
local staff = self:getStaffMember() |
| 156 |
local autopsy, stf_x, stf_y = self.world:findObjectNear(patient, "autopsy") |
| 157 |
local pat_x, pat_y = autopsy:getSecondaryUsageTile() |
| 158 |
patient:walkTo(pat_x, pat_y) |
| 159 |
patient:queueAction(IdleAction():setDirection("east")) |
| 160 |
staff:walkTo(stf_x, stf_y) |
| 161 |
|
| 162 |
local after_use_autopsy = --[[persistable:autopsy_after_use]] function() |
| 163 |
self:commandEnteringStaff(staff) |
| 164 |
-- Patient dies :( |
| 165 |
self:onHumanoidLeave(patient) |
| 166 |
-- Some research is done. :) Might trigger a loss of reputation though. |
| 167 |
local hosp = self.hospital |
| 168 |
local patient_room = patient.disease.treatment_rooms[#patient.disease.treatment_rooms] |
| 169 |
hosp.research:addResearchPointsForAutopsy(patient_room) |
| 170 |
-- average morale of all staff affects chances |
| 171 |
local avg_happiness = hosp:getAverageStaffAttribute("happiness", nil) |
| 172 |
local autopsy_discovered |
| 173 |
-- low morale - more likely to discover |
| 174 |
if avg_happiness < 0.25 then |
| 175 |
autopsy_discovered = math.random(1,3) ~= 1 |
| 176 |
else |
| 177 |
autopsy_discovered = math.random(1,3) == 1 |
| 178 |
end |
| 179 |
if autopsy_discovered then |
| 180 |
hosp:changeReputation("autopsy_discovered") |
| 181 |
hosp:giveAdvice({_A.research.autopsy_discovered_rep_loss}) |
| 182 |
end |
| 183 |
if patient.hospital then |
| 184 |
hosp:removePatient(patient) |
| 185 |
end |
| 186 |
patient.world:destroyEntity(patient) |
| 187 |
end |
| 188 |
|
| 189 |
staff:queueAction(MultiUseObjectAction(autopsy, patient):setAfterUse(after_use_autopsy)) |
| 190 |
return Room.commandEnteringPatient(self, patient) |
| 191 |
end |
| 192 |
|
| 193 |
function ResearchRoom:setStaffMember(staff) |
| 194 |
self.staff_member_set[staff] = true |
| 195 |
end |
| 196 |
|
| 197 |
function ResearchRoom:setStaffMembersAttribute(attribute, value) |
| 198 |
for staff_member, _ in pairs(self.staff_member_set) do |
| 199 |
staff_member[attribute] = value |
| 200 |
end |
| 201 |
end |
| 202 |
|
| 203 |
function ResearchRoom:onHumanoidLeave(humanoid) |
| 204 |
self.staff_member_set[humanoid] = nil |
| 205 |
Room.onHumanoidLeave(self, humanoid) |
| 206 |
end |
| 207 |
|
| 208 |
function ResearchRoom:afterLoad(old, new) |
| 209 |
if old < 56 then |
| 210 |
self.hospital.research_dep_built = true |
| 211 |
end |
| 212 |
Room.afterLoad(self, old, new) |
| 213 |
end |
| 214 |
return room |