File: dungeon_surface.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 (195 lines) | stat: -rw-r--r-- 6,456 bytes parent folder | download | duplicates (3)
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
/* 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 "ultima/shared/gfx/dungeon_surface.h"
#include "ultima/shared/maps/map.h"
#include "ultima/shared/early/game.h"

namespace Ultima {
namespace Shared {

const byte ARRAY_X[] = { 0, 72, 108, 126, 135, 144 };
const byte ARRAY_Y[] = { 0, 36, 54, 63, 68, 72 };

DungeonSurface::DungeonSurface(const Graphics::ManagedSurface &src, const Rect &bounds, Game *game, DrawWidgetFn widgetFn) :
		Gfx::VisualSurface(src, bounds), _widgetFn(widgetFn) {
	_edgeColor = game->_edgeColor;
	_highlightColor = game->_highlightColor;
	_widgetColor = 0;
}

void DungeonSurface::drawWall(uint distance) {
	int offsetX = !distance ? 8 : 0, offsetY = !distance ? 8 : 0;

	if (distance <= 5) {
		hLine(ARRAY_X[distance] + 16 + offsetX, ARRAY_Y[distance] + 8 + offsetY,
			303 - ARRAY_X[distance] - offsetX, _edgeColor);
		hLine(ARRAY_X[distance] + 16 + offsetX, 151 - ARRAY_Y[distance] - offsetY,
			303 - ARRAY_X[distance] - offsetX, _edgeColor);
	}
}

void DungeonSurface::drawDoorway(uint distance) {
	int offsetY = !distance ? 8 : 0;
	byte color = !distance ? 0 : _edgeColor;

	if (distance < 5) {
		drawWall(distance);
		drawLine(ARRAY_X[distance + 1] + 16, 151 - ARRAY_Y[distance] - offsetY,
			ARRAY_X[distance + 1] + 16, ARRAY_Y[distance + 1] + 8, _edgeColor);
		drawLineTo(303 - ARRAY_X[distance + 1], ARRAY_Y[distance + 1] + 8, _edgeColor);
		drawLineTo(303 - ARRAY_X[distance + 1], 151 - ARRAY_Y[distance] - offsetY, _edgeColor);
		drawLineTo(ARRAY_X[distance + 1] + 16, 151 - ARRAY_Y[distance] - offsetY, color);
	}
}

void DungeonSurface::drawLeftEdge(uint distance) {
	if (distance <= 5) {
		vLine(ARRAY_X[distance] + 16, ARRAY_Y[distance] + 8, 151 - ARRAY_Y[distance], _edgeColor);
	}
}

void DungeonSurface::drawRightEdge(uint distance) {
	if (distance <= 5) {
		vLine(303 - ARRAY_X[distance], ARRAY_Y[distance] + 8, 151 - ARRAY_Y[distance], _edgeColor);
	}
}

void DungeonSurface::drawWidget(uint widgetId, uint distance, byte color) {
	_widgetFn(*this, widgetId, distance, color);
}

void DungeonSurface::drawLadderDownFaceOn(uint distance) {
	if (distance <= 5) {
		drawWidget(27, distance, _edgeColor);
		drawWidget(28, distance, _edgeColor);
	}
}

void DungeonSurface::drawLadderDownSideOn(uint distance) {
	if (distance <= 5) {
		drawWidget(27, distance, _edgeColor);
		drawWidget(29, distance, _edgeColor);
	}
}

void DungeonSurface::drawLadderUpFaceOn(uint distance) {
	if (distance <= 5) {
		drawWidget(26, distance, _edgeColor);
		drawWidget(28, distance, _edgeColor);
	}
}

void DungeonSurface::drawLadderUpSideOn(uint distance) {
	if (distance <= 5) {
		drawWidget(26, distance, _edgeColor);
		drawWidget(29, distance, _edgeColor);
	}
}

void DungeonSurface::drawLeftDoor(uint distance) {
	if (distance <= 5) {
		drawLeftWall(distance);

		Point p1(ARRAY_X[distance], ARRAY_Y[distance]),
			p2(ARRAY_X[distance - 1], ARRAY_Y[distance - 1]);
		Point diff = p1 - p2;
		diff.x /= 9;
		diff.y /= 5;

		drawLine(p2.x + diff.x * 2 + 16, 151 - diff.y - p2.y - 1, p2.x + diff.x * 2 + 16,
			p1.y + 8 - diff.y, _edgeColor);
		drawLineTo(p2.x + diff.x * 6 + 16, p1.y + diff.y + 8, _edgeColor);
		drawLineTo(p2.x + diff.x * 6 + 16, 151 - p1.y + diff.y * 2 - (distance == 1 ? 2 : 0), _edgeColor);
	}
}

void DungeonSurface::drawLeftWall(uint distance) {
	if (distance <= 5) {
		Point p1(ARRAY_X[distance], ARRAY_Y[distance]),
			p2(ARRAY_X[distance - 1], ARRAY_Y[distance - 1]);
		drawLine(p2.x + 16, p2.y + 8, p1.x + 16, p1.y + 8, _edgeColor);
		drawLine(p2.x + 16, 151 - p2.y, p1.x + 16, 151 - p1.y, _edgeColor);
	}
}

void DungeonSurface::drawLeftBlank(uint distance) {
	if (distance <= 5) {
		Point p1(ARRAY_X[distance], ARRAY_Y[distance]),
			p2(ARRAY_X[distance - 1], ARRAY_Y[distance - 1]);
		drawLine(p2.x + 16, p1.y + 8, p1.x + 16, p1.y + 8, _edgeColor);
		drawLine(p2.x + 16, 151 - p1.y, p1.x + 16, 151 - p1.y, _edgeColor);
	}
}

void DungeonSurface::drawRightDoor(uint distance) {
	if (distance <= 5) {
		drawRightWall(distance);

		Point p1(ARRAY_X[distance], ARRAY_Y[distance]),
			p2(ARRAY_X[distance - 1], ARRAY_Y[distance - 1]);
		Point diff = p1 - p2;
		diff.x /= 9;
		diff.y /= 5;

		drawLine(303 - (p2.x + diff.x * 2), 151 - diff.y - p2.y - 1, 303 - (p2.x + diff.x * 2),
			p1.y + 8 - diff.y, _edgeColor);
		drawLineTo(303 - (diff.x * 6 + p2.x), p1.y + 8 + diff.y, _edgeColor);
		drawLineTo(303 - (diff.x * 6 + p2.x), 151 - p1.y + diff.y * 2 - (distance == 1 ? 2 : 0), _edgeColor);
	}
}

void DungeonSurface::drawRightWall(uint distance) {
	if (distance <= 5) {
		Point p1(ARRAY_X[distance], ARRAY_Y[distance]),
			p2(ARRAY_X[distance - 1], ARRAY_Y[distance - 1]);

		drawLine(303 - p2.x, p2.y + 8, 303 - p1.x, p1.y + 8, _edgeColor);
		drawLine(303 - p2.x, 151 - p2.y, 303 - p1.x, 151 - p1.y, _edgeColor);
	}
}

void DungeonSurface::drawRightBlank(uint distance) {
	if (distance <= 5) {
		Point p1(ARRAY_X[distance], ARRAY_Y[distance]),
			p2(ARRAY_X[distance - 1], ARRAY_Y[distance - 1]);
		drawLine(303 - p2.x, p1.y + 8, 303 - p1.x, p1.y + 8, _edgeColor);
		drawLine(303 - p2.x, 151 - p1.y, 303 - p1.x, 151 - p1.y, _edgeColor);
	}
}

void DungeonSurface::drawBeams(uint distance) {
	if (distance <= 5) {
		// Figure out the Y difference between each beam
		const int Y_START = ARRAY_Y[distance] + 8;
		const int Y_END = 151 - ARRAY_Y[distance];
		const int HEIGHT = (Y_END - Y_START) / 4;

		for (int beamNum = 0; beamNum < 4; ++beamNum) {
			const int YP = Y_START + HEIGHT * beamNum + (distance / 2);

			drawLine(ARRAY_X[distance] + 16, YP, 303 - ARRAY_X[distance], YP, _highlightColor);
		}
	}
}

} // End of namespace Shared
} // End of namespace Ultima