Skip to content

Commit ce66d26

Browse files
committed
MM: MM1: Fix Cast Spell, Spellbook display in combat
1 parent 31a2814 commit ce66d26

File tree

6 files changed

+83
-21
lines changed

6 files changed

+83
-21
lines changed

engines/mm/mm1/data/character.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,5 +737,16 @@ Common::String Character::getConditionString(ConditionEnum cond) {
737737
}
738738
}
739739

740+
int Character::spellNumber() const {
741+
return g_events->isInCombat() ? _combatSpell : _nonCombatSpell;
742+
}
743+
744+
void Character::setSpellNumber(int spellNum) {
745+
if (g_events->isInCombat())
746+
_combatSpell = spellNum;
747+
else
748+
_nonCombatSpell = spellNum;
749+
}
750+
740751
} // namespace MM1
741752
} // namespace MM

engines/mm/mm1/data/character.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,16 @@ struct Character : public PrimaryAttributes {
470470
int _nonCombatSpell = -1;
471471
int _combatSpell = -1;
472472

473+
/**
474+
* Get the selected combat/noncombat spell number
475+
*/
476+
int spellNumber() const;
477+
478+
/**
479+
* Sets the selected spell
480+
*/
481+
void setSpellNumber(int spellNum);
482+
473483
Character();
474484

475485
/**

engines/mm/mm1/views_enh/spells/cast_spell.cpp

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,26 @@ CastSpell::CastSpell() : PartyView("CastSpell") {
4040
}
4141

4242
bool CastSpell::msgFocus(const FocusMessage &msg) {
43-
(void)PartyView::msgFocus(msg);
43+
if (!isInCombat())
44+
(void)PartyView::msgFocus(msg);
45+
4446
updateSelectedSpell();
4547
return true;
4648
}
4749

50+
bool CastSpell::msgUnfocus(const UnfocusMessage &msg) {
51+
if (!isInCombat())
52+
(void)PartyView::msgUnfocus(msg);
53+
54+
return true;
55+
}
56+
4857
void CastSpell::draw() {
49-
PartyView::draw();
58+
if (!isInCombat()) {
59+
PartyView::draw();
60+
} else {
61+
ScrollView::draw();
62+
}
5063
_fontReduced = false;
5164

5265
const Character &c = *g_globals->_currCharacter;
@@ -56,11 +69,12 @@ void CastSpell::draw() {
5669

5770
setTextColor(37);
5871

72+
int spellNum = c.spellNumber();
5973
Common::String spellName = STRING["enhdialogs.cast_spell.none"];
60-
if (c._nonCombatSpell >= 0 && c._nonCombatSpell < 47) {
61-
spellName = STRING[Common::String::format("spells.cleric.%d", c._nonCombatSpell)];
62-
} else if (c._nonCombatSpell >= 47) {
63-
spellName = STRING[Common::String::format("spells.wizard.%d", c._nonCombatSpell - 47)];
74+
if (spellNum >= 0 && spellNum < 47) {
75+
spellName = STRING[Common::String::format("spells.cleric.%d", spellNum)];
76+
} else if (spellNum >= 47) {
77+
spellName = STRING[Common::String::format("spells.wizard.%d", spellNum - 47)];
6478
}
6579
writeString(0, 60, spellName, ALIGN_MIDDLE);
6680

@@ -82,8 +96,7 @@ void CastSpell::draw() {
8296
bool CastSpell::msgKeypress(const KeypressMessage &msg) {
8397
if (msg.keycode == Common::KEYCODE_c) {
8498
// Cast a spell
85-
const Character &c = *g_globals->_currCharacter;
86-
if (c._nonCombatSpell != -1) {
99+
if (_spellIndex != -1) {
87100
if (!canCast()) {
88101
close();
89102
spellError();
@@ -101,8 +114,10 @@ bool CastSpell::msgKeypress(const KeypressMessage &msg) {
101114
// Select a new spell
102115
addView("Spellbook");
103116
return true;
104-
} else {
117+
} else if (!isInCombat()) {
105118
return PartyView::msgKeypress(msg);
119+
} else {
120+
return false;
106121
}
107122
}
108123

@@ -111,8 +126,10 @@ bool CastSpell::msgAction(const ActionMessage &msg) {
111126
close();
112127
return true;
113128

114-
} else {
129+
} else if (!isInCombat()) {
115130
return PartyView::msgAction(msg);
131+
} else {
132+
return false;
116133
}
117134
}
118135

@@ -132,13 +149,15 @@ bool CastSpell::msgGame(const GameMessage &msg) {
132149
void CastSpell::updateSelectedSpell() {
133150
const Character &c = *g_globals->_currCharacter;
134151

135-
if (c._nonCombatSpell == -1) {
152+
int spellNum = c.spellNumber();
153+
if (spellNum == -1) {
136154
_requiredSp = _requiredGems = 0;
155+
_spellIndex = -1;
137156

138157
} else {
139158
int lvl, num;
140-
getSpellLevelNum(c._nonCombatSpell, lvl, num);
141-
assert(getSpellIndex(&c, lvl, num) == c._nonCombatSpell);
159+
getSpellLevelNum(spellNum, lvl, num);
160+
assert(getSpellIndex(&c, lvl, num) == spellNum);
142161

143162
setSpell(&c, lvl, num);
144163
}
@@ -150,6 +169,9 @@ void CastSpell::charSwitched(Character *priorChar) {
150169
}
151170

152171
void CastSpell::castSpell(Character *target) {
172+
if (_spellIndex == -1)
173+
return;
174+
153175
if (!isMagicAllowed()) {
154176
g_events->send(InfoMessage(STRING["spells.magic_doesnt_work"]));
155177

engines/mm/mm1/views_enh/spells/cast_spell.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ class CastSpell : public PartyView, public MM1::Game::SpellCasting {
5454
void spellError();
5555

5656
protected:
57+
/**
58+
* Return true if the selected character can be switched
59+
*/
60+
bool canSwitchChar() override {
61+
return !isInCombat();
62+
}
63+
5764
/**
5865
* Called when the selected character has been switched
5966
*/
@@ -65,6 +72,7 @@ class CastSpell : public PartyView, public MM1::Game::SpellCasting {
6572

6673
void draw() override;
6774
bool msgFocus(const FocusMessage &msg) override;
75+
bool msgUnfocus(const UnfocusMessage &msg) override;
6876
bool msgKeypress(const KeypressMessage &msg) override;
6977
bool msgAction(const ActionMessage &msg) override;
7078
bool msgGame(const GameMessage &msg) override;

engines/mm/mm1/views_enh/spells/spellbook.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,31 @@ void Spellbook::addButtons() {
5757
}
5858

5959
bool Spellbook::msgFocus(const FocusMessage &msg) {
60-
PartyView::msgFocus(msg);
60+
if (!isInCombat())
61+
PartyView::msgFocus(msg);
6162

6263
// In this view we don't want 1 to 6 mapping to char selection
6364
MetaEngine::setKeybindingMode(KeybindingMode::KBMODE_MENUS);
6465
updateChar();
6566
return true;
6667
}
6768

69+
bool Spellbook::msgUnfocus(const UnfocusMessage &msg) {
70+
if (!isInCombat())
71+
PartyView::msgUnfocus(msg);
72+
return true;
73+
}
74+
6875
bool Spellbook::canSwitchChar() {
6976
return !g_events->isInCombat();
7077
}
7178

7279
void Spellbook::draw() {
73-
PartyView::draw();
80+
if (isInCombat()) {
81+
ScrollView::draw();
82+
} else {
83+
PartyView::draw();
84+
}
7485

7586
Graphics::ManagedSurface s = getSurface();
7687
const Character &c = *g_globals->_currCharacter;
@@ -162,7 +173,7 @@ bool Spellbook::msgKeypress(const KeypressMessage &msg) {
162173
// Alternate alias for Select button
163174
msgAction(ActionMessage(KEYBIND_SELECT));
164175

165-
} else {
176+
} else if (!isInCombat()) {
166177
return PartyView::msgKeypress(msg);
167178
}
168179

@@ -191,8 +202,10 @@ bool Spellbook::msgGame(const GameMessage &msg) {
191202
if (msg._name == "UPDATE") {
192203
updateChar();
193204
return true;
194-
} else {
205+
} else if (!isInCombat()) {
195206
return PartyView::msgGame(msg);
207+
} else {
208+
return true;
196209
}
197210
}
198211

@@ -228,10 +241,7 @@ void Spellbook::spellSelected() {
228241
int spellIndex = (_isWizard ? CATEGORY_SPELLS_COUNT : 0) + _selectedIndex;
229242

230243
// Set the selected spell for the character
231-
if (g_events->isInCombat())
232-
c._combatSpell = spellIndex;
233-
else
234-
c._nonCombatSpell = spellIndex;
244+
c.setSpellNumber(spellIndex);
235245
}
236246

237247
} // namespace Spells

engines/mm/mm1/views_enh/spells/spellbook.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class Spellbook : public PartyView, public MM1::Game::SpellCasting {
6666

6767
void draw() override;
6868
bool msgFocus(const FocusMessage &msg) override;
69+
bool msgUnfocus(const UnfocusMessage &msg) override;
6970
bool msgKeypress(const KeypressMessage &msg) override;
7071
bool msgAction(const ActionMessage &msg) override;
7172
bool msgGame(const GameMessage &msg) override;

0 commit comments

Comments
 (0)