File: game_view.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (211 lines) | stat: -rw-r--r-- 5,475 bytes parent folder | download | duplicates (2)
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
/* 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 3 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, see <http://www.gnu.org/licenses/>.
 *
 */

#include "mm/mm1/views/game_view.h"
#include "mm/mm1/maps/maps.h"
#include "mm/mm1/globals.h"

namespace MM {
namespace MM1 {
namespace Views {

static byte ARR1[] = { 8, 6, 4, 2 };
static byte ARR2[] = { 6, 4, 2, 1 };
static byte ARR3[] = { 4, 5, 3, 2 };
static byte ARR4[] = { 4, 9, 6, 2 };
static byte ARR5[] = { 4, 5, 3, 2 };
static byte ARR6[] = { 22, 12, 6, 2 };
static byte ARR7[] = { 0, 8, 18, 24 };
static byte ARR8[] = { 0, 0, 12, 24 };
static byte ARR9[] = { 52, 42, 36, 32 };
static byte ARR10[] = { 52, 42, 36, 32 };
static byte ARR11[] = { 8, 18, 24, 28 };
static byte ARR12[] = { 8, 10, 6, 4 };
static byte ARR13[] = { 44, 24, 12, 4 };
static byte ARR14[] = { 0, 0, 0, 0 };
static byte ARR15[] = { 36, 4, 0, 0 };
static byte ARR16[] = { 36, 14, 6, 0 };
static uint16 ARR17[] = { 0, 1, 2, 3 };
static uint16 ARR18[] = { 4, 5, 6, 7 };
static uint16 ARR19[] = { 8, 9, 10, 11 };

GameView::GameView(UIElement *owner) : Game::ViewBase(owner) {
	Common::fill(&_drawFlags[0], &_drawFlags[10], 0);
}

void GameView::draw() {
	clearSurface();

	if (!_isDark)
		drawScene();

	if (!_dialogMessage.empty()) {
		drawDialogMessage();
		_dialogMessage.clear();
	} else if (_isDark) {
		writeString(9, 7, STRING["view.darkness"]);
	}

	if (!_descriptionLine.empty())
		drawDescriptionLine();
}

void GameView::drawScene() {
	Maps::Maps &maps = g_globals->_maps;
	Maps::Map &map = *maps._currentMap;
	byte mapOffset = maps._mapOffset;

	Common::fill(&_drawFlags[0], &_drawFlags[10], 0);

	// Loop through four regions in front of the party
	for (int dist = 0; dist < 4; ++dist,
			mapOffset += maps._forwardOffset) {
		byte walls = map._walls[mapOffset];
		byte wallsLeft = map._walls[mapOffset + maps._leftOffset];
		byte wallsRight = map._walls[mapOffset + maps._rightOffset];

		// Draw left-hand side
		_mask = walls & maps._leftMask;
		if (_mask) {
			_tileIndex = ARR17[dist];
			_srcWidth = ARR3[dist];
			_srcPitch = ARR12[dist];
			_destLeft = ARR7[dist];
			_destTop = ARR1[dist];
			_srcLeft = ARR14[dist];
			_drawFlags[dist + 1]++;
			drawTile();

		} else {
			_mask = wallsLeft & maps._forwardMask;
			if (_mask) {
				_tileIndex = ARR19[dist];
				_drawFlags[dist + 1]++;

				if (_drawFlags[dist]) {
					_srcWidth = ARR5[dist];
					_srcPitch = ARR13[dist];
					_destLeft = ARR7[dist];
					_destTop = ARR2[dist];
					_srcLeft = ARR16[dist];
				} else {
					_srcWidth = ARR4[dist];
					_srcPitch = ARR13[dist];
					_destLeft = ARR8[dist];
					_destTop = ARR2[dist];
					_srcLeft = ARR15[dist];
				}

				drawTile();
			}
		}

		// Draw right-hand side
		_mask = walls & maps._rightMask;
		if (_mask) {
			_tileIndex = ARR18[dist];
			_srcWidth = ARR3[dist];
			_srcPitch = ARR12[dist];
			_destLeft = ARR9[dist];
			_destTop = ARR1[dist];
			_srcLeft = ARR14[dist];
			_drawFlags[dist + 6]++;
			drawTile();

		} else {
			_mask = wallsRight & maps._forwardMask;
			if (_mask) {
				_tileIndex = ARR19[dist];
				_drawFlags[6 + dist]++;

				if (_drawFlags[5 + dist]) {
					_srcWidth = ARR5[dist];
					_srcPitch = ARR13[dist];
					_destLeft = ARR10[dist];
					_destTop = ARR2[dist];
					_srcLeft = ARR14[dist];
				} else {
					_srcWidth = ARR4[dist];
					_srcPitch = ARR13[dist];
					_destLeft = ARR10[dist];
					_destTop = ARR2[dist];
					_srcLeft = ARR14[dist];
				}

				drawTile();
			}
		}

		// Handle drawing any wall directly in front
		_mask = walls & maps._forwardMask;
		if (_mask) {
			_tileIndex = ARR19[dist];
			_srcWidth = ARR6[dist];
			_srcPitch = ARR13[dist];
			_destLeft = ARR11[dist];
			_destTop = ARR2[dist];
			_srcLeft = ARR14[dist];
			drawTile();
			break;
		}
	}
}

void GameView::drawTile() {
	Maps::Maps &maps = g_globals->_maps;

	// Determine graphics section to use
	int section = 0;
	if ((_mask & 0x55) != _mask) {
		++section;
		if ((_mask & 0xaa) != _mask)
			++section;
	}

	Graphics::ManagedSurface surf = getSurface();
	const Common::Array<Graphics::ManagedSurface> &tiles =
		maps._tiles[section];
	const Graphics::ManagedSurface &tile = tiles[_tileIndex];

	Common::Rect r(_srcLeft * 4, 0, _srcLeft * 4 + _srcWidth * 8, tile.h);
	Common::Point pos(_destLeft * 4, (8 - _destTop) * 8);
	pos.x -= _bounds.left;
	pos.y -= _bounds.top;
	if (_bounds.top != 0)
		pos.y += 12;

	surf.blitFrom(tile, r, pos);
}

void GameView::drawDialogMessage() {
	writeString(9, 6, "            ");
	writeString(9, 7, _dialogMessage);
	writeString(9, 8, "            ");
}

void GameView::drawDescriptionLine() {
	writeString(10, 15, _descriptionLine);
	_descriptionLine.clear();
}

} // namespace Views
} // namespace MM1
} // namespace MM