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
|
/* 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 "dreamweb/dreamweb.h"
namespace DreamGen {
void DreamBase::showRyanPage() {
showFrame(engine->icons1(), kInventx + 167, kInventy - 12, 12, 0);
showFrame(engine->icons1(), kInventx + 167 + 18 * data.byte(kRyanpage), kInventy - 12, 13 + data.byte(kRyanpage), 0);
}
void DreamBase::findAllRyan(uint8 *inv) {
memset(inv, 0xff, 60);
for (size_t i = 0; i < kNumexobjects; ++i) {
DynObject *extra = getExAd(i);
if (extra->mapad[0] != 4)
continue;
if (extra->mapad[1] != 0xff)
continue;
uint8 slot = extra->mapad[2];
assert(slot < 30);
inv[2 * slot + 0] = i;
inv[2 * slot + 1] = 4;
}
}
void DreamBase::fillRyan() {
uint8 *inv = getSegment(data.word(kBuffers)).ptr(kRyaninvlist, 60);
findAllRyan(inv);
inv += data.byte(kRyanpage) * 2 * 10;
for (size_t i = 0; i < 2; ++i) {
for (size_t j = 0; j < 5; ++j) {
uint8 objIndex = *inv++;
uint8 objType = *inv++;
obToInv(objIndex, objType, kInventx + j * kItempicsize, kInventy + i * kItempicsize);
}
}
showRyanPage();
}
void DreamGenContext::isItWorn() {
flags._z = isItWorn((const DynObject *)es.ptr(bx, sizeof(DynObject)));
}
bool DreamBase::isItWorn(const DynObject *object) {
return (object->id[0] == 'W'-'A') && (object->id[1] == 'E'-'A');
}
void DreamGenContext::wornError() {
data.byte(kCommandtype) = 255;
delPointer();
printMessage(76, 21, 57, 240, false);
workToScreenM();
hangOnP(50);
showPanel();
showMan();
examIcon();
data.byte(kCommandtype) = 255;
workToScreenM();
}
void DreamGenContext::makeWorn() {
makeWorn((DynObject *)es.ptr(bx, sizeof(DynObject)));
}
void DreamGenContext::makeWorn(DynObject *object) {
object->id[0] = 'W'-'A';
object->id[1] = 'E'-'A';
}
void DreamGenContext::obToInv() {
obToInv(al, ah, di, bx);
}
void DreamBase::obToInv(uint8 index, uint8 flag, uint16 x, uint16 y) {
showFrame(engine->icons1(), x - 2, y - 1, 10, 0);
if (index == 0xff)
return;
Frame *extras = (Frame *)getSegment(data.word(kExtras)).ptr(0, 0);
Frame *frees = (Frame *)getSegment(data.word(kFreeframes)).ptr(0, 0);
Frame *frames = (flag == 4) ? extras : frees;
showFrame(frames, x + 18, y + 19, 3 * index + 1, 128);
const DynObject *object = (const DynObject *)getAnyAdDir(index, flag);
bool worn = isItWorn(object);
if (worn)
showFrame(engine->icons1(), x - 3, y - 2, 7, 0);
}
void DreamBase::obPicture() {
if (data.byte(kObjecttype) == 1)
return;
Frame *frames;
if (data.byte(kObjecttype) == 4)
frames = (Frame *)getSegment(data.word(kExtras)).ptr(0, 0);
else
frames = (Frame *)getSegment(data.word(kFreeframes)).ptr(0, 0);
uint8 frame = 3 * data.byte(kCommand) + 1;
showFrame(frames, 160, 68, frame, 0x80);
}
void DreamBase::obIcons() {
uint8 value1, value2;
getAnyAd(&value1, &value2);
if (value1 != 0xff) {
// can open it
showFrame(engine->icons2(), 210, 1, 4, 0);
}
showFrame(engine->icons2(), 260, 1, 1, 0);
}
void DreamGenContext::examineOb(bool examineAgain) {
data.byte(kPointermode) = 0;
data.word(kTimecount) = 0;
while (true) {
if (examineAgain) {
data.byte(kInmaparea) = 0;
data.byte(kExamagain) = 0;
data.byte(kOpenedob) = 255;
data.byte(kOpenedtype) = 255;
data.byte(kInvopen) = 0;
al = data.byte(kCommandtype);
data.byte(kObjecttype) = al;
data.byte(kItemframe) = 0;
data.byte(kPointerframe) = 0;
createPanel();
showPanel();
showMan();
showExit();
obIcons();
obPicture();
describeOb();
underTextLine();
data.byte(kCommandtype) = 255;
readMouse();
showPointer();
workToScreenCPP();
delPointer();
examineAgain = false;
}
readMouse();
showPointer();
vSync();
dumpPointer();
dumpTextLine();
delPointer();
data.byte(kGetback) = 0;
switch (data.byte(kInvopen)) {
case 0: {
RectWithCallback examList[] = {
{ 273,320,157,198,&DreamGenContext::getBackFromOb },
{ 260,300,0,44,&DreamGenContext::useObject },
{ 210,254,0,44,&DreamGenContext::selectOpenOb },
{ 144,176,64,96,&DreamGenContext::setPickup },
{ 0,50,50,200,&DreamBase::examineInventory },
{ 0,320,0,200,&DreamBase::blank },
{ 0xFFFF,0,0,0,0 }
};
checkCoords(examList);
break;
}
case 1: {
// Note: This table contains the non-constant _openChangeSize!
RectWithCallback invList1[] = {
{ 273,320,157,198,&DreamGenContext::getBackFromOb },
{ 255,294,0,24,&DreamGenContext::dropObject },
{ kInventx+167,kInventx+167+(18*3),kInventy-18,kInventy-2,&DreamGenContext::incRyanPage },
{ kInventx,_openChangeSize,kInventy+100,kInventy+100+kItempicsize,&DreamGenContext::useOpened },
{ kInventx,kInventx+(5*kItempicsize),kInventy,kInventy+(2*kItempicsize),&DreamGenContext::inToInv },
{ 0,320,0,200,&DreamBase::blank },
{ 0xFFFF,0,0,0,0 }
};
checkCoords(invList1);
break;
}
default: {
RectWithCallback withList1[] = {
{ 273,320,157,198,&DreamGenContext::getBackFromOb },
{ kInventx+167,kInventx+167+(18*3),kInventy-18,kInventy-2,&DreamGenContext::incRyanPage },
{ kInventx,kInventx+(5*kItempicsize), kInventy,kInventy+(2*kItempicsize),&DreamGenContext::selectOb },
{ 0,320,0,200,&DreamBase::blank },
{ 0xFFFF,0,0,0,0 }
};
checkCoords(withList1);
break;
}
}
if (data.byte(kQuitrequested) != 0)
break;
if (data.byte(kExamagain) != 0)
examineAgain = true;
else if (data.byte(kGetback) != 0)
break;
}
data.byte(kPickup) = 0;
if (data.word(kWatchingtime) != 0 || data.byte(kNewlocation) == 255) {
// isWatching
makeMainScreen();
}
data.byte(kInvopen) = 0;
data.byte(kOpenedob) = 255;
}
void DreamGenContext::inventory() {
if (data.byte(kMandead) == 1 || data.word(kWatchingtime) != 0) {
blank();
return;
}
if (data.byte(kCommandtype) != 239) {
data.byte(kCommandtype) = 239;
al = 32;
commandOnly();
}
if (data.word(kMousebutton) == data.word(kOldbutton))
return;
if (!(data.word(kMousebutton) & 1)) // only on left mouse button
return;
data.word(kTimecount) = 0;
data.byte(kPointermode) = 0;
data.byte(kInmaparea) = 0;
animPointer();
createPanel();
showPanel();
examIcon();
showMan();
showExit();
underTextLine();
data.byte(kPickup) = 0;
data.byte(kInvopen) = 2;
openInv();
readMouse();
showPointer();
workToScreenCPP();
delPointer();
data.byte(kOpenedob) = 255;
examineOb(false);
}
void DreamGenContext::transferText() {
getSegment(data.word(kExtras)).word(kExtextdat + data.byte(kExpos) * 2) = data.word(kExtextpos);
uint16 freeTextOffset = data.byte(kItemtotran) * 2;
uint16 srcOffset = getSegment(data.word(kFreedesc)).word(kFreetextdat + freeTextOffset);
const char *src = (const char *)getSegment(data.word(kFreedesc)).ptr(kFreetext + srcOffset, 0);
char *dst = (char *)getSegment(data.word(kExtras)).ptr(kExtext + data.word(kExtextpos), 0);
size_t len = strlen(src);
memcpy(dst, src, len + 1);
data.word(kExtextpos) += len + 1;
}
void DreamBase::getBackFromOb() {
if (data.byte(kPickup) != 1)
getBack1();
else
blank();
}
void DreamGenContext::getOpenedSize() {
ax = getOpenedSizeCPP();
}
byte DreamGenContext::getOpenedSizeCPP() {
byte obj = data.byte(kOpenedob);
switch (data.byte(kOpenedtype)) {
case 4:
return getExAd(obj)->b7;
case 2:
return getFreeAd(obj)->b7;
default:
return getSetAd(obj)->b3;
}
}
void DreamGenContext::openOb() {
uint8 commandLine[64] = "OBJECT NAME ONE ";
copyName(data.byte(kOpenedtype), data.byte(kOpenedob), commandLine);
printMessage(kInventx, kInventy+86, 62, 240, false);
al = printDirect(commandLine, data.word(kLastxpos) + 5, kInventy+86, 220, false);
fillOpen();
_openChangeSize = getOpenedSizeCPP() * kItempicsize + kInventx;
}
} // End of namespace DreamGen
|