aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/npcs/deskbot.cpp
blob: 825e12922f4d930694ea3db3d0b91e250a515eeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

#include "titanic/npcs/deskbot.h"
#include "titanic/pet_control/pet_control.h"
#include "titanic/game_manager.h"
#include "titanic/translation.h"

namespace Titanic {

static const char *const TALKING_NAMES[] = {
	"NeutralTalking", "HandFidget1", "HandFidget2", "LookingAround",
	"FriendlyTalking", "MoreRudeness", "HandUp", "TapFingers",
	"WaveOn", "WaveArmsAround", "HandsOverEdge",
	nullptr
};

static const char *const IDLE_NAMES[] = {
	"WaveOn", "HandFidget1", "HandFidget2", "TapFingers", "HandsOverEdge",
	nullptr
};

BEGIN_MESSAGE_MAP(CDeskbot, CTrueTalkNPC)
	ON_MESSAGE(TurnOn)
	ON_MESSAGE(EnterViewMsg)
	ON_MESSAGE(ActMsg)
	ON_MESSAGE(MovieEndMsg)
	ON_MESSAGE(LeaveViewMsg)
	ON_MESSAGE(TrueTalkTriggerActionMsg)
	ON_MESSAGE(NPCPlayTalkingAnimationMsg)
	ON_MESSAGE(NPCPlayIdleAnimationMsg)
	ON_MESSAGE(TrueTalkNotifySpeechStartedMsg)
	ON_MESSAGE(TrueTalkNotifySpeechEndedMsg)
	ON_MESSAGE(TurnOff)
END_MESSAGE_MAP()

int CDeskbot::_v1;
int CDeskbot::_v2;

CDeskbot::CDeskbot() : CTrueTalkNPC(), _deskbotActive(false),
		_classNum(NO_CLASS) {
}

void CDeskbot::save(SimpleFile *file, int indent) {
	file->writeNumberLine(1, indent);
	file->writeNumberLine(_v1, indent);
	file->writeNumberLine(_v2, indent);
	file->writeNumberLine(_deskbotActive, indent);
	file->writeNumberLine(_classNum, indent);

	CTrueTalkNPC::save(file, indent);
}

void CDeskbot::load(SimpleFile *file) {
	file->readNumber();
	_v1 = file->readNumber();
	_v2 = file->readNumber();
	_deskbotActive = file->readNumber();
	_classNum = (PassengerClass)file->readNumber();

	CTrueTalkNPC::load(file);
}

bool CDeskbot::TurnOn(CTurnOn *msg) {
	if (!_deskbotActive) {
		setVisible(true);
		playClip("BellRinging");
		playClip("Opening", MOVIE_NOTIFY_OBJECT);

		playSound(TRANSLATE("b#69.wav", "b#47.wav"));
		petSetArea(PET_CONVERSATION);

		_npcFlags |= NPCFLAG_MOVE_START;
		_deskbotActive = true;
	}

	return true;
}

bool CDeskbot::EnterViewMsg(CEnterViewMsg *msg) {
	setVisible(false);
	_deskbotActive = false;
	_fieldC4 = 0;
	loadFrame(625);

	// WORKAROUND: If loading directly from the launcher when Marcinta
	// is active, reset the active NPC back to none at the same time
	CPetControl *pet = getPetControl();
	pet->resetActiveNPC();

	return true;
}

bool CDeskbot::ActMsg(CActMsg *msg) {
	if (msg->_action == "2ndClassUpgrade" && getPassengerClass() > 2) {
		startTalking(this, 140, findView());
	}

	return true;
}

bool CDeskbot::MovieEndMsg(CMovieEndMsg *msg) {
	bool flag = false;
	if (_npcFlags & NPCFLAG_MOVING) {
		if (_classNum) {
			petSetArea(PET_ROOMS);
			decTransitions();
			unlockMouse();
			playSound(TRANSLATE("z#47.wav", "z#578.wav"));
			_classNum = NO_CLASS;
		}

		_npcFlags &= ~NPCFLAG_MOVING;
	}

	if (_npcFlags & NPCFLAG_MOVE_LOOP) {
		_deskbotActive = false;
		_npcFlags &= ~(NPCFLAG_MOVE_LOOP | NPCFLAG_MOVE_START);

		if (_npcFlags & NPCFLAG_MOVE_FINISH) {
			CTurnOn turnOn;
			turnOn.execute("EmbBellbotTrigger");
			unlockMouse();
			getGameManager()->lockInputHandler();
			changeView("EmbLobby.Node 4.N", "");
		} else if (_npcFlags & NPCFLAG_MOVE_LEFT) {
			CTurnOn turnOn;
			turnOn.execute("EmbDoorBotTrigger");
			unlockMouse();
			changeView("EmbLobby.Node 4.N", "");
		}

		_npcFlags &= ~(NPCFLAG_MOVE_FINISH | NPCFLAG_MOVE_LEFT);
		flag = true;
	}

	if (_npcFlags & NPCFLAG_MOVE_START) {
		_npcFlags &= ~(NPCFLAG_MOVE_LOOP | NPCFLAG_MOVE_START);
		setTalking(this, true, findView());

		_npcFlags |= NPCFLAG_START_IDLING;
		flag = true;
	}

	if (!flag)
		CTrueTalkNPC::MovieEndMsg(msg);

	return true;
}

bool CDeskbot::LeaveViewMsg(CLeaveViewMsg *msg) {
	if (_deskbotActive) {
		CTurnOff turnOff;
		turnOff.execute(this);
	}

	return true;
}

bool CDeskbot::TrueTalkTriggerActionMsg(CTrueTalkTriggerActionMsg *msg) {
	switch (msg->_action) {
	case 19:
		incTransitions();
		lockMouse();
		petSetArea(PET_CONVERSATION);
		playClip("ReprogramPETInHand", MOVIE_NOTIFY_OBJECT);
		_npcFlags |= NPCFLAG_MOVING;
		_classNum = (PassengerClass)msg->_param1;

		switch (_classNum) {
		case FIRST_CLASS:
			petDisplayMessage(UPGRADED_TO_FIRST_CLASS);
			setPassengerClass(_classNum);
			petReassignRoom(_classNum);
			break;
		case SECOND_CLASS:
			petDisplayMessage(UPGRADED_TO_SECOND_CLASS);
			setPassengerClass(_classNum);
			petReassignRoom(_classNum);
			break;
		case THIRD_CLASS:
			setPassengerClass(THIRD_CLASS);
			petReassignRoom(_classNum);
			break;
		default:
			break;
		}
		break;

	case 20:
		if (getPassengerClass() == 1) {
			CPetControl *petControl = getPetControl();
			if (petControl)
				petControl->changeLocationClass(UNCHECKED);
		}
		break;

	case 21:
		if (getPassengerClass() == FIRST_CLASS) {
			CPetControl *petControl = getPetControl();
			if (petControl)
				petControl->changeLocationClass(THIRD_CLASS);
		}
		break;

	case 22:
		if (getPassengerClass() == FIRST_CLASS) {
			CPetControl *petControl = getPetControl();
			if (petControl)
				petControl->changeLocationClass(SECOND_CLASS);
		}
		break;

	case 23:
		if (getPassengerClass() == FIRST_CLASS) {
			CPetControl *petControl = getPetControl();
			if (petControl)
				petControl->changeLocationClass(FIRST_CLASS);
		}
		break;

	case 26:
		_npcFlags |= NPCFLAG_MOVE_FINISH;
		CTurnOff turnOff;
		turnOff.execute(this);
		lockMouse();
		break;
	}

	return true;
}

bool CDeskbot::NPCPlayTalkingAnimationMsg(CNPCPlayTalkingAnimationMsg *msg) {
	if (msg->_value2 != 2)
		msg->_names = TALKING_NAMES;

	return true;
}

bool CDeskbot::NPCPlayIdleAnimationMsg(CNPCPlayIdleAnimationMsg *msg) {
	msg->_names = IDLE_NAMES;
	return true;
}

bool CDeskbot::TrueTalkNotifySpeechStartedMsg(CTrueTalkNotifySpeechStartedMsg *msg) {
	if (_npcFlags & NPCFLAG_MOVE_LOOP)
		return true;

	CTrueTalkNPC::TrueTalkNotifySpeechStartedMsg(msg);

	if (g_language == Common::DE_DEU) {
		switch (msg->_dialogueId) {
		case 41701:
		case 41703:
		case 41804:
		case 41805:
		case 41806:
			lockMouse();
			break;
		default:
			break;
		}
	} else {
		switch (msg->_dialogueId) {
		case 41684:
		case 41686:
		case 41787:
		case 41788:
		case 41789:
			lockMouse();
			break;
		default:
			break;
		}
	}

	return true;
}

bool CDeskbot::TrueTalkNotifySpeechEndedMsg(CTrueTalkNotifySpeechEndedMsg *msg) {
	if (_npcFlags & NPCFLAG_MOVE_LOOP)
		return true;

	CTurnOff turnOff;
	CTrueTalkNPC::TrueTalkNotifySpeechEndedMsg(msg);

	if (g_language == Common::DE_DEU) {
		switch (msg->_dialogueId) {
		case 41701:
		case 41804:
		case 41805:
		case 41806:
			_npcFlags |= NPCFLAG_MOVE_FINISH;
			turnOff.execute(this);
			break;

		case 41703:
			_npcFlags |= NPCFLAG_MOVE_LEFT;
			turnOff.execute(this);
			break;

		default:
			break;
		}
	} else {
		switch (msg->_dialogueId) {
		case 41684:
		case 41787:
		case 41788:
		case 41789:
			_npcFlags |= NPCFLAG_MOVE_FINISH;
			turnOff.execute(this);
			break;

		case 41686:
			_npcFlags |= NPCFLAG_MOVE_LEFT;
			turnOff.execute(this);
			break;

		default:
			break;
		}
	}

	return true;
}

bool CDeskbot::TurnOff(CTurnOff *msg) {
	if (_deskbotActive) {
		stopMovie();
		performAction(1, findView());

		_npcFlags = (_npcFlags & ~(NPCFLAG_SPEAKING | NPCFLAG_IDLING | NPCFLAG_START_IDLING)) | NPCFLAG_MOVE_LOOP;
		playClip("Closing", MOVIE_WAIT_FOR_FINISH | MOVIE_NOTIFY_OBJECT);
	}

	return true;
}

} // End of namespace Titanic