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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
|
/* 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 "common/scummsys.h"
#include "mads/scene_data.h"
#include "mads/mads.h"
#include "mads/compression.h"
#include "mads/graphics.h"
#include "mads/resources.h"
#include "mads/nebular/nebular_scenes.h"
namespace MADS {
ScreenObject::ScreenObject() {
_category = CAT_NONE;
_descId = 0;
_layer = 0;
}
/*------------------------------------------------------------------------*/
ScreenObjects::ScreenObjects(MADSEngine *vm): _vm(vm) {
_v8333C = false;
_v832EC = 0;
_yp = 0;
_v7FECA = 0;
_v7FED6 = 0;
_v8332A = 0;
_selectedObject = 0;
_category = CAT_NONE;
_objectIndex = 0;
_released = false;
}
void ScreenObjects::add(const Common::Rect &bounds, ScrCategory category, int descId) {
assert(size() < 100);
ScreenObject so;
so._bounds = bounds;
so._category = category;
so._descId = descId;
so._layer = 0x1413;
push_back(so);
}
void ScreenObjects::check(bool scanFlag) {
Scene &scene = _vm->_game->_scene;
if (!_vm->_events->_mouseButtons || _v832EC)
_v7FECA = false;
if ((_vm->_events->_vD6 || _v8332A || _yp || _v8333C) && scanFlag) {
_selectedObject = scanBackwards(_vm->_events->currentPos(), LAYER_GUI);
if (_selectedObject > 0) {
_category = (ScrCategory)((*this)[_selectedObject - 1]._category & 7);
_objectIndex = (*this)[_selectedObject - 1]._descId;
}
// Handling for easy mouse
ScrCategory category = scene._interface._category;
if (_vm->_easyMouse && !_vm->_events->_vD4 && category != _category
&& scene._interface._category != CAT_NONE) {
_released = true;
if (category >= CAT_ACTION && category <= CAT_6) {
scene._interface.elementHighlighted();
}
}
_released = _vm->_events->_mouseReleased;
if (_vm->_events->_vD2 || (_vm->_easyMouse && !_vm->_events->_vD4))
scene._interface._category = _category;
if (!_vm->_events->_mouseButtons || _vm->_easyMouse) {
if (category >= CAT_ACTION && category <= CAT_6) {
scene._interface.elementHighlighted();
}
}
if (_vm->_events->_mouseButtons || (_vm->_easyMouse && scene._action._v83338 > 1
&& scene._interface._category == CAT_INV_LIST) ||
(_vm->_easyMouse && scene._interface._category == CAT_HOTSPOT)) {
scene._action.checkActionAtMousePos();
}
if (_vm->_events->_mouseReleased) {
scene.leftClick();
scene._interface._category = CAT_NONE;
}
if (_vm->_events->_mouseButtons || _vm->_easyMouse || _yp)
proc1();
if (_vm->_events->_mouseButtons || _vm->_easyMouse)
scene._action.set();
_v8333C = 0;
}
scene._action.refresh();
// Loop through image inter list
warning("TODO: iimageInterList loop");
}
int ScreenObjects::scanBackwards(const Common::Point &pt, int layer) {
for (int i = (int)size() - 1; i >= 0; --i) {
if ((*this)[i]._bounds.contains(pt) && ((*this)[i]._layer == layer))
return i + 1;
}
// Entry not found
return 0;
}
void ScreenObjects::proc1() {
warning("TODO: ScreenObjects::proc1");
}
/*------------------------------------------------------------------------*/
SpriteSlot::SpriteSlot() {
_spriteType = ST_NONE;
_seqIndex = 0;
_spritesIndex = 0;
_frameNumber = 0;
_depth = 0;
_scale = 0;
}
SpriteSlot::SpriteSlot(SpriteType type, int seqIndex) {
_spriteType = type;
_seqIndex = seqIndex;
_spritesIndex = 0;
_frameNumber = 0;
_depth = 0;
_scale = 0;
}
/*------------------------------------------------------------------------*/
void SpriteSlots::clear(bool flag) {
_vm->_game->_scene._textDisplay.clear();
if (flag)
_vm->_game->_scene._sprites.clear();
Common::Array<SpriteSlot>::clear();
push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1));
}
/**
* Releases any sprites used by the player
*/
void SpriteSlots::releasePlayerSprites() {
Player &player = _vm->_game->_player;
if (player._spritesLoaded && player._numSprites > 0) {
int spriteEnd = player._spritesStart + player._numSprites - 1;
do {
deleteEntry(spriteEnd);
} while (--spriteEnd >= player._spritesStart);
}
}
void SpriteSlots::deleteEntry(int index) {
remove_at(index);
}
void SpriteSlots::fullRefresh(bool clearAll) {
if (clearAll)
Common::Array<SpriteSlot>::clear();
push_back(SpriteSlot(ST_FULL_SCREEN_REFRESH, -1));
}
/*------------------------------------------------------------------------*/
int SpriteSets::add(SpriteAsset *asset, int idx) {
if (!idx)
idx = size();
if (idx >= (int)(size() + 1))
resize(idx + 1);
delete (*this)[idx];
(*this)[idx] = asset;
return idx;
}
/*------------------------------------------------------------------------*/
void DirtyArea::setArea(int width, int height, int maxWidth, int maxHeight) {
if (_bounds.left % 2) {
--_bounds.left;
++width;
}
if (_bounds.left < 0)
_bounds.left = 0;
else if (_bounds.left > maxWidth)
_bounds.left = maxWidth;
int right = _bounds.left + width;
if (right < 0)
right = 0;
if (right > maxWidth)
right = maxWidth;
_bounds.right = right;
_bounds2.left = _bounds.width() / 2;
_bounds2.right = _bounds.left + (_bounds.width() + 1) / 2 - 1;
if (_bounds.top < 0)
_bounds.top = 0;
else if (_bounds.top > maxHeight)
_bounds.top = maxHeight;
int bottom = _bounds.top + height;
if (bottom < 0)
bottom = 0;
if (bottom > maxHeight)
bottom = maxHeight;
_bounds.bottom = bottom;
_bounds2.top = _bounds.height() / 2;
_bounds2.bottom = _bounds.top + (_bounds.height() + 1) / 2 - 1;
_active = true;
}
/*------------------------------------------------------------------------*/
DirtyAreas::DirtyAreas(MADSEngine *vm) : _vm(vm) {
for (int i = 0; i < DIRTY_AREAS_SIZE; ++i) {
DirtyArea rec;
rec._active = false;
_entries.push_back(rec);
}
}
void DirtyAreas::setSpriteSlot(int dirtyIdx, const SpriteSlot &spriteSlot) {
int width, height;
DirtyArea &dirtyArea = _entries[dirtyIdx];
Scene &scene = _vm->_game->_scene;
if (spriteSlot._spriteType == ST_FULL_SCREEN_REFRESH) {
// Special entry to refresh the entire screen
dirtyArea._bounds.left = 0;
dirtyArea._bounds.top = 0;
width = MADS_SCREEN_WIDTH;
height = MADS_SCENE_HEIGHT;
} else {
// Standard sprite slots
dirtyArea._bounds.left = spriteSlot._position.x - scene._posAdjust.x;
dirtyArea._bounds.top = spriteSlot._position.y - scene._posAdjust.y;
SpriteAsset &spriteSet = scene._spriteSlots.getSprite(spriteSlot._spritesIndex);
MSprite *frame = spriteSet.getFrame(((spriteSlot._frameNumber & 0x7fff) - 1) & 0x7f);
if (spriteSlot._scale == -1) {
width = frame->getWidth();
height = frame->getHeight();
} else {
width = frame->getWidth() * spriteSlot._scale / 100;
height = frame->getHeight() * spriteSlot._scale / 100;
dirtyArea._bounds.left -= width / 2;
dirtyArea._bounds.top += -(height - 1);
}
}
dirtyArea.setArea(width, height, MADS_SCREEN_WIDTH, MADS_SCENE_HEIGHT);
}
void DirtyAreas::setTextDisplay(int dirtyIdx, const TextDisplay &textDisplay) {
DirtyArea &dirtyArea = _entries[dirtyIdx];
dirtyArea._bounds.left = textDisplay._bounds.left;
dirtyArea._bounds.top = textDisplay._bounds.top;
dirtyArea.setArea(textDisplay._bounds.width(), textDisplay._bounds.height(),
MADS_SCREEN_WIDTH, MADS_SCENE_HEIGHT);
}
void DirtyAreas::merge(int startIndex, int count) {
error("TODO: DirtyAreas::merge");
if (startIndex >= count)
return;
for (int outerCtr = startIndex - 1, idx = 0; idx < count; ++outerCtr, ++idx) {
if (!_entries[outerCtr]._active)
continue;
for (int innerCtr = outerCtr + 1; innerCtr < count; ++innerCtr) {
if (!_entries[innerCtr]._active || !intersects(outerCtr, innerCtr))
continue;
if (_entries[outerCtr]._textActive && _entries[innerCtr]._textActive)
mergeAreas(outerCtr, innerCtr);
}
}
}
/**
* Returns true if two dirty areas intersect
*/
bool DirtyAreas::intersects(int idx1, int idx2) {
return _entries[idx1]._bounds2.intersects(_entries[idx2]._bounds2);
}
void DirtyAreas::mergeAreas(int idx1, int idx2) {
DirtyArea &da1 = _entries[idx1];
DirtyArea &da2 = _entries[idx2];
da1._bounds.extend(da2._bounds);
da1._bounds2.left = da1._bounds.width() / 2;
da1._bounds2.right = da1._bounds.left + (da1._bounds.width() + 1) / 2 - 1;
da1._bounds2.top = da1._bounds.height() / 2;
da1._bounds2.bottom = da1._bounds.top + (da1._bounds.height() + 1) / 2 - 1;
da2._active = false;
da1._textActive = true;
}
void DirtyAreas::copy(MSurface *dest, MSurface *src, const Common::Point &posAdjust) {
for (uint i = 0; i < _entries.size(); ++i) {
const Common::Rect &srcBounds = _entries[i]._bounds;
Common::Rect bounds(srcBounds.left + posAdjust.x, srcBounds.top + posAdjust.y,
srcBounds.right + posAdjust.x, srcBounds.bottom + posAdjust.y);
if (_entries[i]._active && _entries[i]._bounds.isValidRect())
src->copyTo(dest, bounds, Common::Point(_entries[i]._bounds.left, _entries[i]._bounds.top));
}
}
void DirtyAreas::clear() {
for (uint i = 0; i < _entries.size(); ++i)
_entries[i]._active = false;
}
/*------------------------------------------------------------------------*/
DynamicHotspot::DynamicHotspot() {
_seqIndex = 0;
_facing = 0;
_descId = 0;
_field14 = 0;
_articleNumber = 0;
_cursor = CURSOR_NONE;
}
/*------------------------------------------------------------------------*/
DynamicHotspots::DynamicHotspots(MADSEngine *vm): _vm(vm) {
for (int i = 0; i < DYNAMIC_HOTSPOTS_SIZE; ++i) {
DynamicHotspot rec;
rec._active = false;
_entries.push_back(rec);
}
_changed = true;
_count = 0;
}
int DynamicHotspots::add(int descId, int field14, int seqIndex, const Common::Rect &bounds) {
// Find a free slot
uint idx = 0;
while ((idx < _entries.size()) && _entries[idx]._active)
++idx;
if (idx == _entries.size())
error("DynamicHotspots overflow");
_entries[idx]._active = true;
_entries[idx]._descId = descId;
_entries[idx]._seqIndex = seqIndex;
_entries[idx]._bounds = bounds;
_entries[idx]._feetPos.x = -3;
_entries[idx]._feetPos.y = 0;
_entries[idx]._facing = 5;
_entries[idx]._field14 = field14;
_entries[idx]._articleNumber = 6;
_entries[idx]._cursor = CURSOR_NONE;
++_count;
_changed = true;
if (seqIndex >= 0)
_vm->_game->_scene._sequences[seqIndex]._dynamicHotspotIndex = idx;
return idx;
}
int DynamicHotspots::setPosition(int index, int xp, int yp, int facing) {
if (index >= 0) {
_entries[index]._feetPos.x = xp;
_entries[index]._feetPos.y = yp;
_entries[index]._facing = facing;
}
return index;
}
int DynamicHotspots::setCursor(int index, CursorType cursor) {
if (index >= 0)
_entries[index]._cursor = cursor;
return index;
}
void DynamicHotspots::remove(int index) {
Scene &scene = _vm->_game->_scene;
if (_entries[index]._active) {
if (_entries[index]._seqIndex >= 0)
scene._sequences[_entries[index]._seqIndex]._dynamicHotspotIndex = -1;
_entries[index]._active = false;
--_count;
_changed = true;
}
}
void DynamicHotspots::clear() {
for (uint i = 0; i < _entries.size(); ++i)
_entries[i]._active = false;
_changed = false;
_count = 0;
}
void DynamicHotspots::reset() {
for (uint i = 0; i < _entries.size(); ++i)
remove(i);
_count = 0;
_changed = false;
}
void DynamicHotspots::refresh() {
error("DynamicHotspots::refresh");
}
/*------------------------------------------------------------------------*/
KernelMessage::KernelMessage() {
_flags = 0;
_sequenceIndex = 0;
_asciiChar = '\0';
_asciiChar2 = '\0';
_color1 = 0;
_color2 = 0;
_msgOffset = 0;
_numTicks = 0;
_frameTimer2 = 0;
_frameTimer = 0;
_timeout = 0;
_abortTimers = 0;
_abortMode = ABORTMODE_0;
_actionDetails._verbId = 0;
_actionDetails._objectNameId = 0;
_actionDetails._indirectObjectId = 0;
}
/*------------------------------------------------------------------------*/
Hotspot::Hotspot() {
_facing = 0;
_articleNumber = 0;
_cursor = CURSOR_NONE;
_vocabId = 0;
_verbId = 0;
}
Hotspot::Hotspot(Common::SeekableReadStream &f) {
_bounds.left = f.readSint16LE();
_bounds.top = f.readSint16LE();
_bounds.right = f.readSint16LE();
_bounds.bottom = f.readSint16LE();
_feetPos.x = f.readSint16LE();
_feetPos.y = f.readSint16LE();
_facing = f.readByte();
_articleNumber = f.readByte();
f.skip(1);
_cursor = (CursorType)f.readByte();
_vocabId = f.readUint16LE();
_verbId = f.readUint16LE();
}
/*------------------------------------------------------------------------*/
void ARTHeader::load(Common::SeekableReadStream *f) {
// Read in dimensions of image
_width = f->readUint16LE();
_height = f->readUint16LE();
// Read in palette information
int palCount = f->readUint16LE();
for (int i = 0; i < palCount; ++i) {
RGB6 rgb;
rgb.load(f);
_palette.push_back(rgb);
}
f->skip(6 * (256 - palCount));
// Read unknown???
palCount = f->readUint16LE();
for (int i = 0; i < palCount; ++i) {
RGB4 rgb;
rgb.r = f->readByte();
rgb.g = f->readByte();
rgb.b = f->readByte();
rgb.u = f->readByte();
_palAnimData.push_back(rgb);
}
}
/*------------------------------------------------------------------------*/
void SceneNode::load(Common::SeekableReadStream *f) {
_walkPos.x = f->readSint16LE();
_walkPos.y = f->readSint16LE();
for (int i = 0; i < MAX_ROUTE_NODES; ++i)
_indexes[i] = f->readUint16LE();
}
/*------------------------------------------------------------------------*/
InterfaceSurface::InterfaceSurface(MADSEngine *vm): _vm(vm) {
_category = CAT_NONE;
_screenObjectsCount = 0;
}
void InterfaceSurface::elementHighlighted() {
warning("TODO: InterfaceSurface::elementHighlighted");
}
void InterfaceSurface::writeText() {
warning("TODO: InterfaceSurface::writeText");
}
/*------------------------------------------------------------------------*/
void SceneInfo::SpriteInfo::load(Common::SeekableReadStream *f) {
f->skip(3);
_spriteSetIndex = f->readByte();
f->skip(2);
_position.x = f->readSint16LE();
_position.y = f->readSint16LE();
_depth = f->readByte();
_scale = f->readByte();
}
/*------------------------------------------------------------------------*/
void InterfaceSurface::load(const Common::String &resName) {
File f(resName);
MadsPack madsPack(&f);
// Load in the palette
Common::SeekableReadStream *palStream = madsPack.getItemStream(0);
RGB4 *gamePalP = &_vm->_palette->_gamePalette[0];
byte *palP = &_vm->_palette->_mainPalette[0];
for (int i = 0; i < 16; ++i, gamePalP++, palP += 3) {
palP[0] = palStream->readByte();
palP[1] = palStream->readByte();
palP[2] = palStream->readByte();
gamePalP->r |= 1;
palStream->skip(3);
}
delete palStream;
// set the size for the interface
setSize(MADS_SCREEN_WIDTH, MADS_INTERFACE_HEIGHT);
Common::SeekableReadStream *pixelsStream = madsPack.getItemStream(1);
pixelsStream->read(getData(), MADS_SCREEN_WIDTH * MADS_INTERFACE_HEIGHT);
delete pixelsStream;
}
/*------------------------------------------------------------------------*/
SceneInfo *SceneInfo::init(MADSEngine *vm) {
if (vm->getGameID() == GType_RexNebular) {
return new SceneInfoNebular(vm);
}
else {
return new SceneInfo(vm);
}
}
void SceneInfo::load(int sceneId, int v1, const Common::String &resName,
int flags, MSurface &depthSurface, MSurface &bgSurface) {
bool sceneFlag = sceneId >= 0;
// Figure out the resource to use
Common::String resourceName;
if (sceneFlag) {
resourceName = Resources::formatName(RESPREFIX_RM, sceneId, ".DAT");
} else {
resourceName = "*" + Resources::formatResource(resName, resName);
}
// Open the scene info resource for access
File infoFile(resourceName);
MadsPack infoPack(&infoFile);
// Read in basic data
Common::SeekableReadStream *infoStream = infoPack.getItemStream(0);
_sceneId = infoStream->readUint16LE();
_artFileNum = infoStream->readUint16LE();
_depthStyle = infoStream->readUint16LE();
_width = infoStream->readUint16LE();
_height = infoStream->readUint16LE();
infoStream->skip(24);
int nodeCount = infoStream->readUint16LE();
_yBandsEnd = infoStream->readUint16LE();
_yBandsStart = infoStream->readUint16LE();
_maxScale = infoStream->readUint16LE();
_minScale = infoStream->readUint16LE();
for (int i = 0; i < DEPTH_BANDS_SIZE; ++i)
_depthList[i] = infoStream->readUint16LE();
_field4A = infoStream->readUint16LE();
// Load the set of objects that are associated with the scene
for (int i = 0; i < 20; ++i) {
SceneNode node;
node.load(infoStream);
if (i < nodeCount)
_nodes.push_back(node);
}
int spriteSetsCount = infoStream->readUint16LE();
int spriteInfoCount = infoStream->readUint16LE();
// Load in sprite sets
Common::StringArray setNames;
for (int i = 0; i < 10; ++i) {
char name[64];
infoStream->read(name, 64);
if (i < spriteSetsCount)
setNames.push_back(Common::String(name));
}
// Load in sprite draw information
Common::Array<SpriteInfo> spriteInfo;
for (int i = 0; i < 50; ++i) {
SpriteInfo info;
info.load(infoStream);
if (i < spriteInfoCount)
spriteInfo.push_back(info);
}
delete infoStream;
infoFile.close();
int width = _width;
int height = _height;
if (!bgSurface.getPixels()) {
bgSurface.setSize(width, height);
}
if (_depthStyle == 2)
width >>= 2;
if (!depthSurface.getPixels()) {
depthSurface.setSize(width, height);
}
// Load the depth surface with the scene codes
loadCodes(depthSurface);
// Get the ART resource
if (sceneFlag) {
resourceName = Resources::formatName(RESPREFIX_RM, _artFileNum, ".ART");
} else {
resourceName = "*" + Resources::formatResource(resName, resName);
}
// Load in the ART header and palette
File artFile(resourceName);
MadsPack artResource(&artFile);
Common::SeekableReadStream *stream = artResource.getItemStream(0);
ARTHeader artHeader;
artHeader.load(stream);
delete stream;
// Copy out the palette data
for (uint i = 0; i < artHeader._palAnimData.size(); ++i)
_palAnimData.push_back(artHeader._palAnimData[i]);
if (!(flags & 1)) {
if (!_vm->_palette->_paletteUsage.empty()) {
_vm->_palette->_paletteUsage.getKeyEntries(artHeader._palette);
_vm->_palette->_paletteUsage.prioritize(artHeader._palette);
}
_field4C = _vm->_palette->_paletteUsage.process(artHeader._palette, 0xF800);
if (_field4C > 0) {
_vm->_palette->_paletteUsage.transform(artHeader._palette);
for (uint i = 0; i < _palAnimData.size(); ++i) {
byte g = _palAnimData[i].g;
_palAnimData[g].b = artHeader._palAnimData[g].u;
}
}
}
// Read in the background surface data
assert(_width == bgSurface.w && _height == bgSurface.h);
stream = artResource.getItemStream(1);
stream->read(bgSurface.getPixels(), bgSurface.w * bgSurface.h);
// Close the ART file
delete stream;
artFile.close();
Common::Array<SpriteAsset *> spriteSets;
Common::Array<int> indexList;
if (flags & 1) {
for (uint i = 0; i < setNames.size(); ++i) {
Common::String setResName;
if (sceneFlag || resName.hasPrefix("*"))
setResName += "*";
setResName += setNames[i];
SpriteAsset *sprites = new SpriteAsset(_vm, setResName, flags);
spriteSets.push_back(sprites);
indexList.push_back(-1); // TODO:: sprites->_field6
}
}
warning("TODO: sub_201E4(indexList, namesCount, &pal data2");
for (uint i = 0; i < spriteInfo.size(); ++i) {
SpriteInfo &si = spriteInfo[i];
SpriteAsset *asset = spriteSets[si._spriteSetIndex];
assert(asset && _depthStyle != 2);
asset->drawScaled(asset->getCount(), depthSurface, bgSurface,
si._scale, si._depth, si._position);
}
// Free the sprite sets
for (int i = (int)spriteSets.size() - 1; i >= 0; --i) {
warning("TODO: sub_201C8 SPRITE_SET.field_6");
delete spriteSets[i];
}
}
void SceneInfo::loadCodes(MSurface &depthSurface) {
File f(Resources::formatName(RESPREFIX_RM, _sceneId, ".DAT"));
MadsPack codesPack(&f);
Common::SeekableReadStream *stream = codesPack.getItemStream(0);
uint16 width = _width;
uint16 height = _height;
byte *walkMap = new byte[stream->size()];
depthSurface.setSize(width, height);
stream->read(walkMap, f.size());
delete stream;
f.close();
byte *ptr = (byte *)depthSurface.getPixels();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int ofs = x + (y * width);
if ((walkMap[ofs / 8] << (ofs % 8)) & 0x80)
*ptr++ = 1; // walkable
else
*ptr++ = 0;
}
}
delete[] walkMap;
}
/*------------------------------------------------------------------------*/
void SceneInfoNebular::loadCodes(MSurface &depthSurface) {
File f(Resources::formatName(RESPREFIX_RM, _sceneId, ".DAT"));
MadsPack codesPack(&f);
Common::SeekableReadStream *stream = codesPack.getItemStream(0);
byte *destP = depthSurface.getData();
byte *endP = depthSurface.getBasePtr(0, depthSurface.h);
byte runLength = stream->readByte();
while (destP < endP && runLength > 0) {
byte runValue = stream->readByte();
// Write out the run length
Common::fill(destP, destP + runLength, runValue);
destP += runLength;
// Get the next run length
runLength = stream->readByte();
}
if (destP < endP)
Common::fill(destP, endP, 0);
delete stream;
f.close();
}
} // End of namespace MADS
|