Debian Codegraph @

CorsixTH/Lua/objects/helicopter.lua

raw
1 --[[ Copyright (c) 2009 Edvin "Lego3" Linge
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 corsixth.require("announcer")
22 local AnnouncementPriority = _G["AnnouncementPriority"]
23
24 local object = {}
25 object.id = "helicopter"
26 object.thob = 63
27 object.name = "helicopter" -- Not seen anywhere
28 object.class = "Helicopter"
29 object.ticks = true
30 object.idle_animations = {
31 north = 2456,
32 }
33 object.orientations = {
34 north = {
35 -- Helicopter is outside the hospital, so does not need a footprint
36 footprint = {}
37 },
38 }
39
40 --! An `Object` which drops off emergency patients.
41 class "Helicopter" (Object)
42
43 ---@type Helicopter
44 local Helicopter = _G["Helicopter"]
45
46 function Helicopter:Helicopter(hospital, object_type, direction, etc)
47 local x, y = hospital:getHeliportPosition()
48 -- Helicopter needs to land below tile to be positioned correctly
49 y = y + 1
50 self:Object(hospital, object_type, x, y, direction, etc)
51 self.th:makeInvisible()
52 self:setPosition(0, -600)
53 self.phase = -120
54 self.hospital = hospital
55 -- TODO: Shadow: 3918
56 hospital.emergency_patients = {}
57 end
58
59 function Helicopter:tick()
60 local phase = self.phase
61 local ui = TheApp.ui
62 if phase == 0 then
63 self.th:makeVisible()
64 self:setSpeed(0, 10)
65 ui:playAnnouncement(ui.hospital.emergency.disease.emergency_sound, AnnouncementPriority.Critical)
66 elseif phase == 60 then
67 self:setSpeed(0, 0)
68 self.spawned_patients = 0
69 ui.adviser:say(_A.information.emergency)
70 elseif phase == 85 then
71 if self.spawned_patients < self.hospital.emergency.victims then
72 self:spawnPatient()
73 phase = 60
74 end
75 elseif phase == 87 then
76 self:setSpeed(0, -10)
77 elseif phase == 147 then
78 self.world:destroyEntity(self)
79 end
80 self.phase = phase + 1
81 Object.tick(self)
82 end
83
84 --! When the helicopter has landed this method is called each time a patient should spawn from it.
85 function Helicopter:spawnPatient()
86 local hospital = self.hospital
87 self.spawned_patients = self.spawned_patients + 1
88 local patient = self.world:newEntity("Patient", 2, 1)
89 patient:setDisease(hospital.emergency.disease)
90 patient.diagnosis_progress = 1
91 patient.is_emergency = self.spawned_patients
92 patient:setDiagnosed()
93 patient:setMood("emergency", "activate")
94 hospital.emergency_patients[self.spawned_patients] = patient
95 local x, y = hospital:getHeliportSpawnPosition()
96 patient:setNextAction(SpawnAction("spawn", {x = x, y = y}):setOffset({y = 1}))
97 patient:setHospital(hospital)
98 -- TODO: If new combined diseases are added this will not work correctly anymore.
99 patient.cure_rooms_visited = #patient.disease.treatment_rooms - 1
100 local no_of_rooms = #patient.disease.treatment_rooms
101 -- a spawning emergency patient might rather leave than pay
102 if not patient:agreesToPay(patient.disease.id) then
103 patient:goHome("over_priced", patient.disease.id)
104 else
105 patient:queueAction(SeekRoomAction(patient.disease.treatment_rooms[no_of_rooms]))
106 end
107 end
108
109 return object