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
|
/* 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.
*
* $URL$
* $Id$
*
*/
#include "common/endian.h"
#include "common/scummsys.h"
#include "common/util.h"
#include "cine/cine.h"
#include "cine/object.h"
#include "cine/part.h"
#include "cine/various.h"
namespace Cine {
objectStruct objectTable[NUM_MAX_OBJECT];
ScriptVars globalVars(NUM_MAX_VAR);
overlayHeadElement overlayHead;
void unloadAllMasks(void) {
overlayHeadElement *current = overlayHead.next;
while (current) {
overlayHeadElement *next = current->next;
delete current;
current = next;
}
resetMessageHead();
}
void resetMessageHead(void) {
overlayHead.next = NULL;
overlayHead.previous = NULL;
}
void loadObject(char *pObjectName) {
uint16 numEntry;
uint16 entrySize;
uint16 i;
byte *ptr, *dataPtr;
checkDataDisk(-1);
ptr = dataPtr = readBundleFile(findFileInBundle(pObjectName));
setMouseCursor(MOUSE_CURSOR_DISK);
numEntry = READ_BE_UINT16(ptr); ptr += 2;
entrySize = READ_BE_UINT16(ptr); ptr += 2;
assert(numEntry <= NUM_MAX_OBJECT);
for (i = 0; i < numEntry; i++) {
if (objectTable[i].costume != -2) { // flag is keep ?
Common::MemoryReadStream readS(ptr, entrySize);
objectTable[i].x = readS.readSint16BE();
objectTable[i].y = readS.readSint16BE();
objectTable[i].mask = readS.readUint16BE();
objectTable[i].frame = readS.readSint16BE();
objectTable[i].costume = readS.readSint16BE();
readS.read(objectTable[i].name, 20);
objectTable[i].part = readS.readUint16BE();
}
ptr += entrySize;
}
if (!strcmp(pObjectName, "INTRO.OBJ")) {
for (i = 0; i < 10; i++) {
objectTable[i].costume = 0;
}
}
free(dataPtr);
}
int8 removeOverlayElement(uint16 objIdx, uint16 param) {
overlayHeadElement *currentHeadPtr = &overlayHead;
overlayHeadElement *tempHead = currentHeadPtr;
overlayHeadElement *tempPtr2;
currentHeadPtr = tempHead->next;
while (currentHeadPtr && (currentHeadPtr->objIdx != objIdx || currentHeadPtr->type != param)) {
tempHead = currentHeadPtr;
currentHeadPtr = tempHead->next;
}
if (!currentHeadPtr || currentHeadPtr->objIdx != objIdx || currentHeadPtr->type != param) {
return -1;
}
tempHead->next = tempPtr2 = currentHeadPtr->next;
if (!tempPtr2) {
tempPtr2 = &overlayHead;
}
tempPtr2->previous = currentHeadPtr->previous;
delete currentHeadPtr;
return 0;
}
int16 freeOverlay(uint16 objIdx, uint16 param) {
overlayHeadElement *currentHeadPtr = overlayHead.next;
overlayHeadElement *previousPtr = &overlayHead;
overlayHeadElement *tempPtr2;
while (currentHeadPtr && ((currentHeadPtr->objIdx != objIdx) || (currentHeadPtr->type != param))) {
previousPtr = currentHeadPtr;
currentHeadPtr = previousPtr->next;
}
if (!currentHeadPtr || !((currentHeadPtr->objIdx == objIdx) && (currentHeadPtr->type == param))) {
return -1;
}
previousPtr->next = tempPtr2 = currentHeadPtr->next;
if (!tempPtr2) {
tempPtr2 = &overlayHead;
}
tempPtr2->previous = currentHeadPtr->previous;
delete currentHeadPtr;
return 0;
}
void loadOverlayElement(uint16 objIdx, uint16 param) {
overlayHeadElement *currentHeadPtr = &overlayHead;
overlayHeadElement *pNewElement;
uint16 si = objectTable[objIdx].mask;
overlayHeadElement *tempHead = currentHeadPtr;
currentHeadPtr = tempHead->next;
while (currentHeadPtr && (objectTable[currentHeadPtr->objIdx].mask < si)) {
tempHead = currentHeadPtr;
currentHeadPtr = tempHead->next;
}
pNewElement = new overlayHeadElement;
assert(pNewElement);
pNewElement->next = tempHead->next;
tempHead->next = pNewElement;
pNewElement->objIdx = objIdx;
pNewElement->type = param;
if (!currentHeadPtr) {
currentHeadPtr = &overlayHead;
}
pNewElement->previous = currentHeadPtr->previous;
currentHeadPtr->previous = pNewElement;
}
void setupObject(byte objIdx, uint16 param1, uint16 param2, uint16 param3, uint16 param4) {
objectTable[objIdx].x = param1;
objectTable[objIdx].y = param2;
objectTable[objIdx].mask = param3;
objectTable[objIdx].frame = param4;
if (!removeOverlayElement(objIdx, 0)) {
loadOverlayElement(objIdx, 0);
}
}
void subObjectParam(byte objIdx, byte paramIdx, int16 newValue) {
addObjectParam(objIdx, paramIdx, -newValue);
}
void addObjectParam(byte objIdx, byte paramIdx, int16 newValue) {
int16 currentValue = getObjectParam(objIdx, paramIdx);
modifyObjectParam(objIdx, paramIdx, currentValue + newValue);
}
void modifyObjectParam(byte objIdx, byte paramIdx, int16 newValue) {
paramIdx--;
assert(paramIdx <= 5);
switch (paramIdx) {
case 0:
objectTable[objIdx].x = newValue;
break;
case 1:
objectTable[objIdx].y = newValue;
break;
case 2:
objectTable[objIdx].mask = newValue;
if (!removeOverlayElement(objIdx, 0)) {
loadOverlayElement(objIdx, 0);
}
break;
case 3:
objectTable[objIdx].frame = newValue;
break;
case 4:
// is it really in Future Wars? it breaks the newspaper machine
// on the airport in Operation Stealth
if (newValue == -1 && g_cine->getGameType() != Cine::GType_OS) {
objectTable[objIdx].costume = globalVars[0];
} else {
objectTable[objIdx].costume = newValue;
}
break;
case 5:
objectTable[objIdx].part = newValue;
break;
}
}
uint16 compareObjectParam(byte objIdx, byte type, int16 value) {
uint16 compareResult = 0;
int16 objectParam = getObjectParam(objIdx, type);
if (objectParam > value) {
compareResult |= kCmpGT;
} else if (objectParam < value) {
compareResult |= kCmpLT;
} else {
compareResult |= kCmpEQ;
}
return compareResult;
}
int16 getObjectParam(uint16 objIdx, uint16 paramIdx) {
assert(objIdx <= NUM_MAX_OBJECT);
paramIdx--;
assert(paramIdx <= 5);
switch (paramIdx) {
case 0:
return objectTable[objIdx].x;
case 1:
return objectTable[objIdx].y;
case 2:
return objectTable[objIdx].mask;
case 3:
return objectTable[objIdx].frame;
case 4:
return objectTable[objIdx].costume;
case 5:
return objectTable[objIdx].part;
}
return 0;
}
} // End of namespace Cine
|