aboutsummaryrefslogtreecommitdiff
path: root/engines/draci/game.cpp
blob: 1b6a25679d4a09cf365d94535d0a3381f57e3e16 (plain)
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
/* 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/stream.h"

#include "draci/draci.h"
#include "draci/game.h"
#include "draci/barchive.h"

namespace Draci {

Game::Game() {
	unsigned int i;
	Common::String path("INIT.DFW");
	
	BArchive initArchive(path);
	BAFile *file;
	
	// Read in persons
	
	file = initArchive[5];
	Common::MemoryReadStream personData(file->_data, file->_length);
	
	unsigned int numPersons = file->_length / personSize;
	_persons = new Person[numPersons];
	
	for (i = 0; i < numPersons; ++i) {
		_persons[i]._x = personData.readByte();
		_persons[i]._y = personData.readByte();
		_persons[i]._fontColour = personData.readUint16LE();
	}
	
	// Read in dialog offsets
	
	file = initArchive[4];
	Common::MemoryReadStream dialogData(file->_data, file->_length);
	
	unsigned int numDialogs = file->_length / sizeof(uint16);
	_dialogOffsets = new uint16[numDialogs];	
	
	unsigned int curOffset;
	for (i = 0, curOffset = 0; i < numDialogs; ++i) {
		_dialogOffsets[i] = curOffset;
		curOffset += dialogData.readUint16LE();
	}
	
	// Read in game info
	
	file = initArchive[3];
	Common::MemoryReadStream gameData(file->_data, file->_length);
	_info = new GameInfo();
	
	_info->_currentRoom = gameData.readByte();
	_info->_mapRoom = gameData.readByte();
	_info->_numObjects = gameData.readUint16LE();
	_info->_numIcons = gameData.readUint16LE();
	_info->_numVariables = gameData.readByte();
	_info->_numPersons = gameData.readByte();
	_info->_numDialogs = gameData.readByte();
	_info->_maxIconWidth = gameData.readUint16LE();
	_info->_maxIconHeight = gameData.readUint16LE();
	_info->_musicLength = gameData.readUint32LE();

// FIXME: Something is wrong here. The total file length is only 23 bytes
// but the whole struct should be 35 bytes.
	_info->_crc[0] = gameData.readUint32LE();
	_info->_crc[1] = gameData.readUint32LE();
	_info->_crc[2] = gameData.readUint32LE();
	_info->_crc[3] = gameData.readUint32LE();
	_info->_numDialogBlocks = gameData.readUint16LE();

	// Read in variables
	
	file = initArchive[2];
	unsigned int numVariables = file->_length / sizeof (int16);
	
	_variables = new int16[numVariables];
	memcpy(_variables, file->_data, file->_length);
	
	// Read in item status
	
	file = initArchive[1];
	_itemStatus = new byte[file->_length];
	memcpy(_itemStatus, file->_data, file->_length);
	
	// Read in object status
	
	file = initArchive[0];
	unsigned int numObjects = file->_length;
	
	_objectStatus = new byte[numObjects];
	memcpy(_objectStatus, file->_data, file->_length);
	
	assert(numDialogs == _info->_numDialogs);
	assert(numPersons == _info->_numPersons);
	assert(numVariables == _info->_numVariables);
	assert(numObjects == _info->_numObjects);	

// TODO: Why is this failing?
//	assert(curOffset == _info->_numDialogBlocks);

}

Game::~Game() {
	delete[] _persons;
	delete[] _variables;
	delete[] _dialogOffsets;
	delete[] _itemStatus;
	delete[] _objectStatus;
	delete _info;
}	

}