File: map09.cpp

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (243 lines) | stat: -rw-r--r-- 5,943 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
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
/* 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/maps/map09.h"
#include "mm/mm1/maps/maps.h"
#include "mm/mm1/events.h"
#include "mm/mm1/globals.h"
#include "mm/mm1/sound.h"

namespace MM {
namespace MM1 {
namespace Maps {

static const byte MAP_DEST_X[4] = { 8, 15, 15, 7 };
static const byte MAP_DEST_Y[4] = { 5, 1, 0, 0 };
static const uint16 MAP_DEST_ID[4] = { 0x604, 0x51b, 0x601, 0xa00 };

void Map09::special() {
	// Scan for special actions on the map cell
	for (uint i = 0; i < 28; ++i) {
		if (g_maps->_mapOffset == _data[51 + i]) {
			// Found a specially handled cell, but it
			// only triggers in designated direction(s)
			if (g_maps->_forwardMask & _data[79 + i]) {	
				(this->*SPECIAL_FN[i])();
			} else {
				checkPartyDead();
			}
			return;
		}
	}

	// All other cells on the map are encounters
	g_maps->clearSpecial();
	g_globals->_encounters.execute();
}

void Map09::special00() {
	visitedExit();
	send(SoundMessage(
		STRING["maps.stairs_up"],
		[]() {
			g_maps->changeMap(0x802, 1);
		}
	));
}

void Map09::special01() {
	visitedExit();
	send(SoundMessage(
		STRING["maps.map09.passage_outside"],
		[]() {
			g_maps->_mapPos = Common::Point(0, 0);
			g_maps->changeMap(0xf05, 3);
		}
	));
}

void Map09::special02() {
	portal(0);
}

void Map09::special03() {
	portal(1);
}

void Map09::special04() {
	portal(2);
}

void Map09::special05() {
	portal(3);
}

void Map09::special06() {
	for (uint i = 0; i < g_globals->_party.size(); ++i) {
		Character &c = g_globals->_party[i];
		if (!(c._flags[11] & CHARFLAG11_GOT_ACCURACY)) {
			c._flags[11] |= CHARFLAG11_GOT_ACCURACY;
			c._might._base = MIN((int)c._accuracy._base + 4, 255);
		}
	}

	g_events->send(SoundMessage(0, 1, STRING["maps.map09.accuracy"]));
}

void Map09::special07() {
	for (uint i = 0; i < g_globals->_party.size(); ++i) {
		Character &c = g_globals->_party[i];
		if (!(c._flags[11] & CHARFLAG11_GOT_SPEED)) {
			c._flags[11] |= CHARFLAG11_GOT_SPEED;
			c._might._base = MIN((int)c._speed._base + 4, 255);
		}
	}

	g_events->send(SoundMessage(0, 1, STRING["maps.map09.agility"]));
}

void Map09::special08() {
	for (uint i = 0; i < g_globals->_party.size(); ++i) {
		Character &c = g_globals->_party[i];
		c._flags[5] |= CHARFLAG5_8;
	}

	send(SoundMessage(
		0, 1, STRING["maps.map09.shrine1"],
		[]() {
			const Character &leader = g_globals->_party[0];

			if (leader._alignment == leader._alignmentInitial) {
				SoundMessage msg(
					STRING["maps.map09.shrine2"],
					[]() {
						g_globals->_treasure._items[2] = g_events->getRandomNumber(26) + 120;
						g_globals->_treasure.setGold(120);
						g_events->addAction(KEYBIND_SEARCH);
					}
				);
				msg._delaySeconds = 2;
				g_events->send(msg);

			} else {
				SoundMessage msg(
					STRING["maps.map09.shrine3"],
					[]() {
						// TODO: Check this is right. Original set y twice
						g_maps->_mapPos = Common::Point(5, 13);
						g_maps->changeMap(0x201, 3);
					}
				);
				msg._delaySeconds = 2;
				g_events->send(msg);
			}
		}
	));
}

void Map09::special09() {
	send(SoundMessage(0, 1, STRING["maps.map09.stalactites"]));
	reduceHP();
}

void Map09::special14() {
	g_maps->clearSpecial();

	if (g_globals->_activeSpells._s.levitate) {
		send(SoundMessage(
			0, 1, STRING["maps.map09.pit"],
			0, 2, STRING["maps.map09.levitation"]
		));
	} else {
		for (uint i = 0; i < g_globals->_party.size(); ++i) {
			Character &c = g_globals->_party[i];
			if (!g_globals->_activeSpells._s.poison &&
				!(c._condition & BAD_CONDITION))
				c._condition = POISONED;
			c._hpCurrent /= 2;
		}

		SoundMessage msg(
			STRING["maps.map09.pit"],
			[]() {
				g_globals->_encounters.execute();
			}
		);
		msg._delaySeconds = 2;
		send(msg);
	}
}

void Map09::special18() {
	if (g_globals->_activeSpells._s.psychic_protection) {
		send(SoundMessage(
			0, 1, STRING["maps.map09.psychic_blast"],
			0, 2, STRING["maps.map09.protection"]
		));
	} else {
		g_globals->_currCharacter = &g_globals->_party[
			getRandomNumber(g_globals->_party.size()) - 1
		];

		if (!(g_globals->_currCharacter->_condition & BAD_CONDITION)) {
			// Chosen character is okay, so blast them
			g_globals->_currCharacter->_condition = BAD_CONDITION | DEAD;
		} else {
			// Chosen character is disabled, so instead
			// remove the SP from all members of the party
			for (uint i = 0; i < g_globals->_party.size(); ++i) {
				g_globals->_party[i]._sp._current = 0;
			}
		}

		g_globals->_encounters.execute();
	}
}

void Map09::special25() {
	send(SoundMessage(0, 1, STRING["maps.map09.scrawl"]));
}

void Map09::special26() {
	send(SoundMessage(0, 1, STRING["maps.map09.corak_was_here"]));
}

void Map09::special27() {
	send(SoundMessage(0, 1, STRING["maps.map09.message"]));
}

void Map09::portal(int index) {
	visitedExit();
	_portalIndex = index;

	send(SoundMessage(
		STRING["maps.map09.portal"],
		[]() {
			int idx = static_cast<Map09 *>(g_maps->_currentMap)->_portalIndex;
			g_maps->_mapPos = Common::Point(MAP_DEST_X[idx], MAP_DEST_Y[idx]);
			g_maps->changeMap(MAP_DEST_ID[idx], 1);
		}
	));
}

} // namespace Maps
} // namespace MM1
} // namespace MM