-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCodea59a.cpp
More file actions
430 lines (402 loc) · 11.5 KB
/
Codea59a.cpp
File metadata and controls
430 lines (402 loc) · 11.5 KB
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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
#include "stdafx.h"
#include "UI.h"
#include <stdio.h>
//#include "Objects.h"
#include "Dispatch.h"
#include "CSB.h"
#include "Data.h"
bool IsPlayFileOpen();
//*********************************************************
// I separated this from SummarizeRoomInfo to make it
// a little easier to see what is going on.
//*********************************************************
void SummarizeStoneRoom(SUMMARIZEROOMDATA *rslt,
const i32 facing,
bool FalseStoneWall)
{
dReg D0;
i32 i;
i32 rightCFmask;
i32 rearCFmask;
i32 leftCFmask;
i32 cellFlags;
i32 relativePosition;
i32 DBType;
RN LOCAL_12;
ROOMTYPE rtD0;
DBCOMMON *dbA2;
DB3 *pActuator;
i32 actuatorType;
cellFlags = GetCellFlags(rslt->x, rslt->y);
LOCAL_12 = FindFirstObject(rslt->x, rslt->y);
rtD0 = (ROOMTYPE)(cellFlags >> 5);
rslt->roomType = roomSTONE; // even for false wall
rightCFmask = cellFlags & 8;
rearCFmask = cellFlags & 8;
leftCFmask = cellFlags & 8;
bool realDecoration[3];
realDecoration[0]=realDecoration[1]=realDecoration[2]=false;
if (!FalseStoneWall)
{
switch (facing)
{
case 0:
rightCFmask = cellFlags & 4;
rearCFmask = cellFlags & 2;
leftCFmask = cellFlags & 1;
break;
case 1:
rightCFmask = cellFlags & 2;
rearCFmask = cellFlags & 1;
leftCFmask = cellFlags & 8;
break;
case 2:
rightCFmask = cellFlags & 1;
rearCFmask = cellFlags & 8;
leftCFmask = cellFlags & 4;
break;
case 3:
rightCFmask = cellFlags & 8;
rearCFmask = cellFlags & 4;
leftCFmask = cellFlags & 2;
break;
default:
NotImplemented(0xa6a0);
};
};
//d.ChampionPortraitOrdinal = 0;
rslt->championPortraitOrdinal = 0;
TAG00a4a2(rslt,
(UI16)rightCFmask, // Which bit to look
(UI16)rearCFmask, // at in cellflags
(UI16)leftCFmask, // for the three directions
facing,
rslt->x,
rslt->y,
FalseStoneWall?1:0);
while ( (LOCAL_12 != RNeof)
&& ((DBType=LOCAL_12.dbType()) <= dbACTUATOR) )
{ // Must be a dbTEXT or a dbACTUATOR.
// You should not have doors or teleporters in stone!
if ( (DBType == dbDOOR) || (DBType == dbTELEPORTER) )
{
// But the TeamDungeon of Zyx et al did have a door in a wall!!!
LOCAL_12 = GetDBRecordLink(LOCAL_12);
continue;
};
relativePosition = (LOCAL_12.pos()-facing)&3;
if (relativePosition != 0) // Same side as facing?
{
dbA2 = GetCommonAddress(LOCAL_12);
if (DBType == dbTEXT)
{
D0W = dbA2->CastToDB2()->show();
//D0W &= 1;
if (D0W != 0)
{
D0W = sw(d.NumWallDecoration + 1);
ASSERT((relativePosition>=1) && (relativePosition<=3),"relpos");
//rslt->decorations[relativePosition-1] = D0W;
//d.rn10540[relativePosition-1] = LOCAL_12;
rslt->text[relativePosition-1] = LOCAL_12;
};
}
else
{ //Must be an ACTUATOR
if (dbA2->CastToDB3()->actuatorType() == 47)
{ //No graphics in DSA!
// Wrong!!! A DSA of type 255 has a 16-bit graphic ID (from CSBgraphics.dat)
DB3 *pDSA;
i32 levelIndex, absIndex;
pDSA = dbA2->CastToDB3();
levelIndex = pDSA->DSAselector();
absIndex = DSALevelIndex[d.LoadedLevel][levelIndex];
if (absIndex == 255)
{
i32 graphicID;
graphicID = 0x10000 | pDSA->ParameterA();
rslt->decorations[relativePosition-1] = graphicID;
};
LOCAL_12 = GetDBRecordLink(LOCAL_12);
continue;
};
ASSERT((relativePosition>=1) && (relativePosition<=3),"relpos");
pActuator = dbA2->CastToDB3();
actuatorType = pActuator->actuatorType();
if ( (actuatorType != 127)
|| ((pActuator->State() & PORTRAIT_HideGraphic)==0))
{
rslt->decorations[relativePosition-1] =
pActuator->wallGraphicOrdinal();
realDecoration[relativePosition-1] = true;
if (rslt->decorations[relativePosition-1] > d.NumWallDecoration)
{
if ((d.newFlags & IllegalWallDecorationWarning) == 0)
{
d.newFlags |= IllegalWallDecorationWarning;
if (IsPlayFileOpen())
{
UI_MessageBox("Illegal Wall Graphic\nI will not warn you again!",
"Warning",MB_OK);
};
};
rslt->decorations[relativePosition-1] = 0;
};
};
D0W = dbA2->CastToDB3()->actuatorType();
if (D0W == 127)
{
if (relativePosition == 2)
{
DB3 *pPortrait;
pPortrait = dbA2->CastToDB3();
if ((pPortrait->State() & PORTRAIT_HidePortrait) == 0)
{
//d.ChampionPortraitOrdinal
rslt->championPortraitOrdinal
= ((dbA2->CastToDB3()->value() & 511)+1);
};
};
};
};
};
LOCAL_12 = GetDBRecordLink(LOCAL_12);
};
for (i=0; i<3; i++)
{
if ( (rslt->text[i] != RNeof)
&& !realDecoration[i])
{
rslt->decorations[i] = 0;
};
};
if (FalseStoneWall)
{
if (d.partyX != rslt->x)
{
if (d.partyY != rslt->y)
{
rslt->rn2 = RN(RNeof);
return;
};
};
};
rslt->rn2 = LOCAL_12;
return;
}
ui8 graphicRoomTypes[20] =
{
gRoomSTONE, // STONE -> STONE
gRoomOPEN, // OPEN -> OPEN
gRoomPIT, // PIT -> PIT
255, // STAIRS -> illegal
255, // DOOR -> ILLEGAL
gRoomTELEPORTER, // TELEPORTER -> TELEPORTER
255, // FALSEWALL -> illegal
255, // 7 -> illegal
255, // 8 -> illegal
255, // 9 -> illegal
255, // 10 -> illegal
255, // 11 -> illegal
255, // 12 -> illegal
255, // 13 -> illegal
255, // 14 -> illegal
255, // 15 -> illegal
gRoomDOOREDGE, // DOOREDGE -> DOOREDGE
gRoomDOORFACING, // DOORFACING -> DOORFACING
gRoomSTAIREDGE, // STAIREDGE -> STAIREDGE
gRoomSTAIRFACING // STAIRFACING -> STAIRFACING
};
//*********************************************************
//
//*********************************************************
//TAG00a59a
void SummarizeRoomInfo(SUMMARIZEROOMDATA *rslt,i32 facing)
{
// rslt[0] = Cell's DUDAD word
dReg D0, D1;
CELLFLAG cfD4;
ROOMTYPE rtD0;
DB3 *DB3A2;
RN LOCAL_12;
RN firstObject;
i32 dbType;
//i16 LOCAL_10;
//i16 LOCAL_8;
//i32 relativePosition;
//ui16 leftCFmask=0xbade;
//ui16 rearCFmask=0xbade;
//ui16 rightCFmask=0xbade;
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
//ClearMemory((pnt)rslt, sizeof (*rslt));
rslt->text[0] = RNeof;
rslt->text[1] = RNeof;
rslt->text[2] = RNeof;
rslt->decorations[0] = 0;
rslt->decorations[1] = 0;
rslt->decorations[2] = 0;
rslt->rn2 = RNeof;
cfD4 = GetCellFlags(rslt->x, rslt->y);
rtD0 = (ROOMTYPE)(cfD4 >> 5);
rslt->roomType = rtD0;
LOCAL_12 = firstObject = FindFirstObject(rslt->x, rslt->y);
switch (rtD0)
{
case roomSTONE:
SummarizeStoneRoom(rslt,
facing,
false); // Real Stone!
rslt->graphicRoomType = (GRAPHICROOMTYPE)graphicRoomTypes[rslt->roomType];
return;
case roomPIT:
D0W = (I16)(cfD4 & 8);
if (D0W != 0)
{
D0W = (I16)(cfD4 & 4);
rslt->decorations[0] = D0W;
cfD4 &= 1;
}
else
{
rslt->roomType = roomOPEN;
cfD4 = 1;
};
goto tag00a860;
case roomFALSEWALL:
if ((cfD4 & 4) == 0)
{
//rslt->roomType = roomSTONE;
//D0W = D4W & 8;
//rightCFmask = D0W;
//rearCFmask = D0W;
//leftCFmask = D0W;
//LOCAL_10 = 1;
SummarizeStoneRoom(rslt,
facing,
true); // Fake stone!
rslt->graphicRoomType = (GRAPHICROOMTYPE)graphicRoomTypes[rslt->roomType];
return;
};
rslt->roomType = roomOPEN;
D0W = (I16)(cfD4 & 8);
if (D0W != 0) cfD4 = 8;
else cfD4 = 0;
// NOTE fall-through
case roomOPEN:
rslt->decorations[2] = RandomWallDecoration(
(I16)(cfD4 & 8),
d.pCurLevelDesc->NumRandomFloorDecorations(),
rslt->x,
rslt->y,
30);
tag00a85c:
cfD4 = 1;
tag00a860:
while (LOCAL_12 != RNeof)
{
dbType = LOCAL_12.dbType();
if (dbType == dbACTUATOR)
{
DB3A2 = GetRecordAddressDB3(LOCAL_12);
if (DB3A2->actuatorType() == 47)
{ //No graphics in DSA!
// Wrong!!! A DSA of type 255 has a 16-bit graphic ID (from CSBgraphics.dat)
DB3 *pDSA;
i32 levelIndex, absIndex;
pDSA = DB3A2;
levelIndex = pDSA->DSAselector();
absIndex = DSALevelIndex[d.LoadedLevel][levelIndex];
if (absIndex == 255)
{
i32 graphicID;
graphicID = 0x4000 | pDSA->ParameterB();
rslt->decorations[2] = graphicID;
};
}
else
{
i32 decoration;
decoration = DB3A2->wallGraphicOrdinal();
if ( (decoration > 0) && (decoration <= d.pCurLevelDesc->NumFloorDecorations()) )
{
rslt->decorations[2] = decoration;
};
};
};
LOCAL_12 = GetDBRecordLink(LOCAL_12);
};
LOCAL_12 = firstObject;
goto tag00a984;
case roomTELEPORTER:
rslt->decorations[0] = sw((cfD4 & 0x0c) == 0x0c ? 1 : 0);
goto tag00a85c;
case roomSTAIRS:
D0W = (I16)((cfD4 & 8) >> 3); // Set if N/S travel
D1W = (I16)(facing & 1);
if (D1W == D0W)
{
rtD0 = roomSTAIREDGE;
}
else
{
rtD0 = roomSTAIRFACING;
};
rslt->roomType = rtD0;
D0W = (I16)(cfD4 & 4);
rslt->decorations[0] = D0W;
cfD4 = 0;
break;
case roomDOOR:
D0W = (I16)((cfD4 & 8) >> 3); // N/S door
D1W = (I16)(facing & 1);
if (D0W == D1W)
{
rslt->roomType = roomDOOREDGE; //facing at right angle to door direction
}
else
{
rslt->roomType = roomDOORFACING; //facing in door direction
D0W = (I16)(cfD4 & 7);
rslt->decorations[0] = D0W;
rslt->decorations[1] = FindFirstDoor(rslt->x, rslt->y).idx();
};
goto tag00a85c;
default:
cfD4 = 1;
}; // switch
while ( (LOCAL_12 != RNeof)
&&(LOCAL_12.dbType() <= dbACTUATOR) )
{
LOCAL_12 = GetDBRecordLink(LOCAL_12);
};
tag00a984:
if (cfD4 != 0) //Can footprints be shown here?
{
cfD4 = ub(SearchFootprints(rslt->x, rslt->y));
if (cfD4 != 0)
{
cfD4--;
D0W = (UI8)(cfD4);
D1W = (UI8)(d.IndexOfFirstMagicFootprint);
if (D0W >= D1W)
{
D0W = (UI8)(cfD4);
D1W = (UI8)(d.IndexOfLastMagicFootprint);
if (D0W < D1W)
{
rslt->decorations[2] |= 0x8000; // footprints?
};
};
}
if (d.Time > 0)
{
if (GetExtendedCellFlag(
d.LoadedLevel, rslt->x, rslt->y, ECF_FOOTPRINTS))
{
rslt->decorations[2] |= 0x8000; // footprints?
};
};
};
rslt->rn2 = LOCAL_12;
rslt->graphicRoomType = (GRAPHICROOMTYPE)graphicRoomTypes[rslt->roomType];
}