1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "titanic/game/transport/service_elevator.h"
24 #include "titanic/core/room_item.h"
25 #include "titanic/npcs/doorbot.h"
26 #include "titanic/translation.h"
27
28 namespace Titanic {
29
30 BEGIN_MESSAGE_MAP(CServiceElevator, CTransport)
31 ON_MESSAGE(BodyInBilgeRoomMsg)
32 ON_MESSAGE(EnterViewMsg)
33 ON_MESSAGE(ServiceElevatorMsg)
34 ON_MESSAGE(TimerMsg)
35 ON_MESSAGE(ServiceElevatorFloorRequestMsg)
36 ON_MESSAGE(LeaveRoomMsg)
37 ON_MESSAGE(OpeningCreditsMsg)
38 END_MESSAGE_MAP()
39
40 bool CServiceElevator::_v1;
41 int CServiceElevator::_v2;
42 int CServiceElevator::_v3;
43
CServiceElevator()44 CServiceElevator::CServiceElevator() : CTransport(),
45 _fieldF8(0), _soundHandle1(0), _timerId(0), _soundHandle2(0) {
46 }
47
save(SimpleFile * file,int indent)48 void CServiceElevator::save(SimpleFile *file, int indent) {
49 file->writeNumberLine(1, indent);
50 file->writeNumberLine(_v1, indent);
51 file->writeNumberLine(_v2, indent);
52 file->writeNumberLine(_v3, indent);
53 file->writeNumberLine(_fieldF8, indent);
54 file->writeNumberLine(_soundHandle1, indent);
55 file->writeNumberLine(_timerId, indent);
56 file->writeNumberLine(_soundHandle2, indent);
57
58 CTransport::save(file, indent);
59 }
60
load(SimpleFile * file)61 void CServiceElevator::load(SimpleFile *file) {
62 file->readNumber();
63 _v1 = file->readNumber();
64 _v2 = file->readNumber();
65 _v3 = file->readNumber();
66 _fieldF8 = file->readNumber();
67 _soundHandle1 = file->readNumber();
68 _timerId = file->readNumber();
69 _soundHandle2 = file->readNumber();
70
71 CTransport::load(file);
72 }
73
BodyInBilgeRoomMsg(CBodyInBilgeRoomMsg * msg)74 bool CServiceElevator::BodyInBilgeRoomMsg(CBodyInBilgeRoomMsg *msg) {
75 _v2 = true;
76 _string1 = "BilgeRoomWith.Node 2.N";
77 return true;
78 }
79
EnterViewMsg(CEnterViewMsg * msg)80 bool CServiceElevator::EnterViewMsg(CEnterViewMsg *msg) {
81 petShow();
82 return true;
83 }
84
ServiceElevatorMsg(CServiceElevatorMsg * msg)85 bool CServiceElevator::ServiceElevatorMsg(CServiceElevatorMsg *msg) {
86 switch (msg->_value) {
87 case 1:
88 case 2:
89 case 3: {
90 switch (msg->_value) {
91 case 1:
92 _v3 = 0;
93 break;
94 case 2:
95 _v3 = 1;
96 break;
97 case 3:
98 _v3 = 2;
99 break;
100 default:
101 break;
102 }
103
104 CServiceElevatorFloorRequestMsg requestMsg;
105 requestMsg.execute(this);
106 break;
107 }
108
109 case 4:
110 if (!_string1.empty()) {
111 if (_string1 == "DeepSpace") {
112 disableMouse();
113 _soundHandle1 = playSound(TRANSLATE("z#413.wav", "z#157.wav"), 50);
114 _timerId = addTimer(1, 1000, 500);
115 } else {
116 changeView(_string1);
117 }
118 }
119 break;
120
121 case 5:
122 // Reaching destination floor
123 _fieldF8 = false;
124 _fieldDC = _v3;
125 loadSound(TRANSLATE("z#423.wav", "z#168.wav"));
126 stopSound(_soundHandle2);
127 _soundHandle2 = playSound(TRANSLATE("z#423.wav", "z#168.wav"), 80);
128
129 switch (_fieldDC) {
130 case 0:
131 _string1 = "DeepSpace";
132 _string2 = TRANSLATE("a#2.wav", "a#54.wav");
133 queueSound(TRANSLATE("z#416.wav", "z#160.wav"), _soundHandle2, 50);
134 break;
135
136 case 1:
137 _string1 = _v2 ? "BilgeRoomWith.Node 2.N" : "BilgeRoom.Node 1.N";
138 queueSound(TRANSLATE("z#421.wav", "z#165.wav"), _soundHandle2, 50);
139 break;
140
141 case 2:
142 _string1 = _v1 ? "MoonEmbLobby.Node 1.NE" : "EmbLobby.Node 1.NE";
143 queueSound(TRANSLATE("z#411.wav", "z#155.wav"), _soundHandle2, 50);
144 break;
145
146 default:
147 break;
148 }
149
150 enableMouse();
151 if (findRoom()->findByName("Doorbot"))
152 addTimer(3, 3000, 0);
153 break;
154
155 default:
156 break;
157 }
158
159 return true;
160 }
161
TimerMsg(CTimerMsg * msg)162 bool CServiceElevator::TimerMsg(CTimerMsg *msg) {
163 CDoorbot *doorbot = dynamic_cast<CDoorbot *>(findRoom()->findByName("Doorbot"));
164
165 switch (msg->_actionVal) {
166 case 0:
167 case 1:
168 if (!isSoundActive(_soundHandle1)) {
169 stopAnimTimer(_timerId);
170 if (msg->_actionVal == 0) {
171 // Elevator in motion after pressing button
172 _fieldF8 = true;
173 CServiceElevatorFloorChangeMsg changeMsg(_fieldDC, _v3);
174 changeMsg.execute(getRoom(), nullptr, MSGFLAG_SCAN);
175 _soundHandle2 = playSound(TRANSLATE("z#424.wav", "z#169.wav"));
176
177 if (doorbot) {
178 CActMsg actMsg("DoorbotPlayerPressedTopButton");
179 actMsg.execute(doorbot);
180 }
181 } else {
182 // Finished playing message for bottom/middle floor disabled
183 enableMouse();
184 if (doorbot) {
185 CActMsg actMsg;
186 if (_v3 == 0)
187 actMsg._action = "DoorbotPlayerPressedBottomButton";
188 else if (_v3 == 1)
189 actMsg._action = "DoorbotPlayerPressedMiddleButton";
190
191 actMsg.execute(doorbot);
192 }
193 }
194 }
195 break;
196
197 case 3: {
198 CActMsg actMsg("DoorbotReachedEmbLobby");
199 actMsg.execute(doorbot);
200 break;
201 }
202
203 default:
204 break;
205 }
206
207 return true;
208 }
209
ServiceElevatorFloorRequestMsg(CServiceElevatorFloorRequestMsg * msg)210 bool CServiceElevator::ServiceElevatorFloorRequestMsg(CServiceElevatorFloorRequestMsg *msg) {
211 disableMouse();
212 CDoorbot *doorbot = dynamic_cast<CDoorbot *>(findRoom()->findByName("Doorbot"));
213
214 if (doorbot && _v3 == 0) {
215 _soundHandle1 = playSound(TRANSLATE("z#415.wav", "z#159.wav"), 50);
216 _timerId = addTimer(1, 1000, 500);
217 } else if (doorbot && _v3 == 1) {
218 _soundHandle1 = playSound(TRANSLATE("z#417.wav", "z#161.wav"), 50);
219 _timerId = addTimer(1, 1000, 500);
220 } else if (_fieldDC == _v3) {
221 switch (_v3) {
222 case 0:
223 _soundHandle1 = playSound(TRANSLATE("z#415.wav", "z#159.wav"), 50);
224 break;
225 case 1:
226 _soundHandle1 = playSound(TRANSLATE("z#420.wav", "z#164.wav"), 50);
227 break;
228 case 2:
229 _soundHandle1 = playSound(TRANSLATE("z#410.wav", "z#154.wav"), 50);
230 break;
231 default:
232 break;
233 }
234
235 _timerId = addTimer(1, 1000, 500);
236 } else {
237 switch (_v3) {
238 case 0:
239 _soundHandle1 = playSound(TRANSLATE("z#414.wav", "z#158.wav"), 50);
240 break;
241 case 1:
242 _soundHandle1 = playSound(_fieldDC ? TRANSLATE("z#419.wav", "z#163.wav")
243 : TRANSLATE("z#418.wav", "z#162.wav"), 50);
244 break;
245 case 2:
246 _soundHandle1 = playSound(TRANSLATE("z#409.wav", "z#153.wav"), 50);
247 break;
248 default:
249 break;
250 }
251
252 _timerId = addTimer(0, 1000, 500);
253 }
254
255 return true;
256 }
257
LeaveRoomMsg(CLeaveRoomMsg * msg)258 bool CServiceElevator::LeaveRoomMsg(CLeaveRoomMsg *msg) {
259 CDoorbot *doorbot = dynamic_cast<CDoorbot *>(findRoom()->findByName("Doorbot"));
260
261 if (doorbot) {
262 CPutBotBackInHisBoxMsg boxMsg(0);
263 boxMsg.execute("Doorbot");
264 doorbot->performAction(false);
265 enableMouse();
266 }
267
268 return true;
269 }
270
OpeningCreditsMsg(COpeningCreditsMsg * msg)271 bool CServiceElevator::OpeningCreditsMsg(COpeningCreditsMsg *msg) {
272 _v1 = false;
273 _string1 = "EmbLobby.Node 1.NE";
274 return true;
275 }
276
277 } // End of namespace Titanic
278