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 "dreamweb/sound.h"
24 #include "dreamweb/dreamweb.h"
25
26 namespace DreamWeb {
27
talk()28 void DreamWebEngine::talk() {
29 _talkPos = 0;
30 _inMapArea = 0;
31 _character = _command;
32 createPanel();
33 showPanel();
34 showMan();
35 showExit();
36 underTextLine();
37 convIcons();
38 startTalk();
39 _commandType = 255;
40 readMouse();
41 showPointer();
42 workToScreen();
43
44 RectWithCallback talkList[] = {
45 { 273,320,157,198,&DreamWebEngine::getBack1 },
46 { 240,290,2,44,&DreamWebEngine::moreTalk },
47 { 0,320,0,200,&DreamWebEngine::blank },
48 { 0xFFFF,0,0,0,0 }
49 };
50
51 do {
52 delPointer();
53 readMouse();
54 animPointer();
55 showPointer();
56 waitForVSync();
57 dumpPointer();
58 dumpTextLine();
59 _getBack = 0;
60 checkCoords(talkList);
61 if (_quitRequested)
62 break;
63 } while (!_getBack);
64
65 if (_talkPos >= 4)
66 _personData->b7 |= 128;
67
68 redrawMainScrn();
69 workToScreenM();
70 if (_speechLoaded) {
71 _sound->cancelCh1();
72 _sound->volumeChange(0, -1);
73 }
74 }
75
convIcons()76 void DreamWebEngine::convIcons() {
77 uint8 index = _character & 127;
78 uint16 frame = getPersFrame(index);
79 const GraphicsFile *base = findSource(frame);
80 showFrame(*base, 234, 2, frame, 0);
81 }
82
getPersFrame(uint8 index)83 uint16 DreamWebEngine::getPersFrame(uint8 index) {
84 return READ_LE_UINT16(&_personFramesLE[index]);
85 }
86
startTalk()87 void DreamWebEngine::startTalk() {
88 _talkMode = 0;
89
90 const uint8 *str = getPersonText(_character & 0x7F, 0);
91 uint16 y;
92
93 _charShift = 91+91;
94 y = 64;
95 printDirect(&str, 66, &y, 241, true);
96
97 _charShift = 0;
98 y = 80;
99 printDirect(&str, 66, &y, 241, true);
100
101 if (hasSpeech()) {
102 _speechLoaded = _sound->loadSpeech('R', _realLocation, 'C', 64*(_character & 0x7F));
103 if (_speechLoaded) {
104 _sound->volumeChange(6, 1);
105 _sound->playChannel1(62);
106 }
107 }
108 }
109
getPersonText(uint8 index,uint8 talkPos)110 const uint8 *DreamWebEngine::getPersonText(uint8 index, uint8 talkPos) {
111 return (const uint8 *)_personText.getString(index*64 + talkPos);
112 }
113
moreTalk()114 void DreamWebEngine::moreTalk() {
115 if (_talkMode != 0) {
116 redes();
117 return;
118 }
119
120 commandOnlyCond(49, 215);
121
122 if (_mouseButton == _oldButton)
123 return; // nomore
124
125 if (!(_mouseButton & 1))
126 return;
127
128 _talkMode = 2;
129 _talkPos = 4;
130
131 if (_character >= 100)
132 _talkPos = 48; // second part
133 doSomeTalk();
134 }
135
doSomeTalk()136 void DreamWebEngine::doSomeTalk() {
137 // FIXME: This is for the CD version only
138
139 while (true) {
140 const uint8 *str = getPersonText(_character & 0x7F, _talkPos);
141
142 if (*str == 0) {
143 // endheartalk
144 _pointerMode = 0;
145 return;
146 }
147
148 createPanel();
149 showPanel();
150 showMan();
151 showExit();
152 convIcons();
153
154 printDirect(str, 164, 64, 144, false);
155
156 _speechLoaded = _sound->loadSpeech('R', _realLocation, 'C', (64 * (_character & 0x7F)) + _talkPos);
157 if (_speechLoaded)
158 _sound->playChannel1(62);
159
160 _pointerMode = 3;
161 workToScreenM();
162 if (hangOnPQ())
163 return;
164
165 _talkPos++;
166
167 str = getPersonText(_character & 0x7F, _talkPos);
168 if (*str == 0) {
169 // endheartalk
170 _pointerMode = 0;
171 return;
172 }
173
174 if (*str != ':' && *str != 32) {
175 createPanel();
176 showPanel();
177 showMan();
178 showExit();
179 convIcons();
180 printDirect(str, 48, 128, 144, false);
181
182 _speechLoaded = _sound->loadSpeech('R', _realLocation, 'C', (64 * (_character & 0x7F)) + _talkPos);
183 if (_speechLoaded)
184 _sound->playChannel1(62);
185
186 _pointerMode = 3;
187 workToScreenM();
188 if (hangOnPQ())
189 return;
190 }
191
192 _talkPos++;
193 }
194 }
195
hangOnPQ()196 bool DreamWebEngine::hangOnPQ() {
197 _getBack = 0;
198
199 RectWithCallback quitList[] = {
200 { 273,320,157,198,&DreamWebEngine::getBack1 },
201 { 0,320,0,200,&DreamWebEngine::blank },
202 { 0xFFFF,0,0,0,0 }
203 };
204
205 uint16 speechFlag = 0;
206
207 do {
208 delPointer();
209 readMouse();
210 animPointer();
211 showPointer();
212 waitForVSync();
213 dumpPointer();
214 dumpTextLine();
215 checkCoords(quitList);
216
217 if (_getBack == 1 || _quitRequested) {
218 // Quit conversation
219 delPointer();
220 _pointerMode = 0;
221 _sound->cancelCh1();
222 return true;
223 }
224
225 if (_speechLoaded && !_sound->isChannel1Playing()) {
226 speechFlag++;
227 if (speechFlag == 40)
228 break;
229 }
230 } while (!_mouseButton || _oldButton);
231
232 delPointer();
233 _pointerMode = 0;
234 return false;
235 }
236
redes()237 void DreamWebEngine::redes() {
238 if (_sound->isChannel1Playing() || _talkMode != 2) {
239 blank();
240 return;
241 }
242
243 commandOnlyCond(50, 217);
244
245 if (!(_mouseButton & 1))
246 return;
247
248 delPointer();
249 createPanel();
250 showPanel();
251 showMan();
252 showExit();
253 convIcons();
254 startTalk();
255 readMouse();
256 showPointer();
257 workToScreen();
258 delPointer();
259 }
260
261 } // End of namespace DreamWeb
262