summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-11-16 20:23:30 +0300
committerAndrei Karas <akaras@inbox.ru>2015-11-16 20:23:30 +0300
commit11000f010f19a2de85ba26660b451c7c41ab3a97 (patch)
tree65eee18b5fcb17f35cb90fcc930242e02b0a79f1
parent18bd0722a9cebc3ba80bfb74a5b5ba0dd9e53c75 (diff)
downloadplus-11000f010f19a2de85ba26660b451c7c41ab3a97.tar.gz
plus-11000f010f19a2de85ba26660b451c7c41ab3a97.tar.bz2
plus-11000f010f19a2de85ba26660b451c7c41ab3a97.tar.xz
plus-11000f010f19a2de85ba26660b451c7c41ab3a97.zip
Move MagicSchool enum into separate file and convert to strong typed.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/enums/magicschool.h37
-rw-r--r--src/gui/windows/textcommandeditor.cpp4
-rw-r--r--src/resources/db/commandsdb.cpp21
-rw-r--r--src/spellmanager.cpp4
-rw-r--r--src/textcommand.cpp16
-rw-r--r--src/textcommand.h31
8 files changed, 82 insertions, 33 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7e4e11e3d..b5a1ee9f9 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -918,6 +918,7 @@ SET(SRCS
enums/equipslot.h
enums/guildpositionflags.h
enums/inventorytype.h
+ enums/magicschool.h
particle/imageparticle.cpp
particle/imageparticle.h
imagesprite.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index ffa69a2d6..bbdcdd6b6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -694,6 +694,7 @@ manaplus_SOURCES += main.cpp \
enums/equipslot.h \
enums/guildpositionflags.h \
enums/inventorytype.h \
+ enums/magicschool.h \
spellshortcut.cpp \
spellshortcut.h \
statuseffect.cpp \
diff --git a/src/enums/magicschool.h b/src/enums/magicschool.h
new file mode 100644
index 000000000..1a12b9539
--- /dev/null
+++ b/src/enums/magicschool.h
@@ -0,0 +1,37 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2011-2015 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * 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
+ * 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/>.
+ */
+
+#ifndef ENUMS_MAGICSCHOOL_H
+#define ENUMS_MAGICSCHOOL_H
+
+#include "enums/simpletypes/enumdefines.h"
+
+enumStart(MagicSchool)
+{
+ SkillMagic = 340,
+ SkillMagicLife = 341,
+ SkillMagicWar = 342,
+ SkillMagicTransmute = 343,
+ SkillMagicNature = 344,
+ SkillMagicAstral = 345
+}
+enumEnd(MagicSchool);
+
+#endif // ENUMS_MAGICSCHOOL_H
diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp
index b72b82501..32cc0959f 100644
--- a/src/gui/windows/textcommandeditor.cpp
+++ b/src/gui/windows/textcommandeditor.cpp
@@ -264,7 +264,7 @@ void TextCommandEditor::save()
static_cast<CommandTargetT>(mTypeDropDown->getSelected()));
mCommand->setIcon(mIconDropDown->getSelectedString());
mCommand->setBaseLvl(mMagicLvlField->getValue());
- mCommand->setSchool(static_cast<MagicSchool>(
+ mCommand->setSchool(static_cast<MagicSchoolT>(
mSchoolDropDown->getSelected() + MAGIC_START_ID));
mCommand->setSchoolLvl(mSchoolLvlField->getValue());
if (spellManager)
@@ -281,7 +281,7 @@ void TextCommandEditor::deleteCommand()
mCommand->setTargetType(CommandTarget::NoTarget);
mCommand->setIcon("");
mCommand->setBaseLvl(0);
- mCommand->setSchool(SKILL_MAGIC);
+ mCommand->setSchool(MagicSchool::SkillMagic);
mCommand->setSchoolLvl(0);
if (spellManager)
spellManager->save();
diff --git a/src/resources/db/commandsdb.cpp b/src/resources/db/commandsdb.cpp
index 2203cbaa8..69c918f86 100644
--- a/src/resources/db/commandsdb.cpp
+++ b/src/resources/db/commandsdb.cpp
@@ -117,14 +117,25 @@ void CommandsDB::loadXmlFile(const std::string &fileName)
TextCommand *cmd = nullptr;
if (skill1)
{
- cmd = new TextCommand(id, name, command, comment,
- targetType, icon, level1, static_cast<MagicSchool>(skill2),
- level2, mana);
+ cmd = new TextCommand(id,
+ name,
+ command,
+ comment,
+ targetType,
+ icon,
+ level1,
+ static_cast<MagicSchoolT>(skill2),
+ level2,
+ mana);
}
else
{
- cmd = new TextCommand(id, name, command, comment,
- targetType, icon);
+ cmd = new TextCommand(id,
+ name,
+ command,
+ comment,
+ targetType,
+ icon);
}
mCommands[id] = cmd;
}
diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp
index 84d05bc12..9409c6c1c 100644
--- a/src/spellmanager.cpp
+++ b/src/spellmanager.cpp
@@ -136,7 +136,7 @@ void SpellManager::invoke(const int spellId) const
if (spell->getCommandType() == TEXT_COMMAND_TEXT
|| (playerHandler->canUseMagic()
- && PlayerInfo::getSkillLevel(SKILL_MAGIC)
+ && PlayerInfo::getSkillLevel(static_cast<int>(MagicSchool::SkillMagic))
>= static_cast<signed>(spell->getBaseLvl())
&& PlayerInfo::getSkillLevel(static_cast<int>(
spell->getSchool())) >= static_cast<signed>(spell->getSchoolLvl())
@@ -288,7 +288,7 @@ void SpellManager::load(const bool oldConfig)
{
addSpell(new TextCommand(i, symbol, cmd, comment,
static_cast<CommandTargetT>(targetType), icon, basicLvl,
- static_cast<MagicSchool>(school), schoolLvl, mana));
+ static_cast<MagicSchoolT>(school), schoolLvl, mana));
}
else
{
diff --git a/src/textcommand.cpp b/src/textcommand.cpp
index 5dbaa578d..baca21090 100644
--- a/src/textcommand.cpp
+++ b/src/textcommand.cpp
@@ -34,12 +34,16 @@
#include "debug.h"
-TextCommand::TextCommand(const unsigned int id, const std::string &symbol,
+TextCommand::TextCommand(const unsigned int id,
+ const std::string &symbol,
const std::string &command,
const std::string &comment,
- const CommandTargetT type, const std::string &icon,
- const unsigned int basicLvl, const MagicSchool school,
- const unsigned int schoolLvl, const int mana) :
+ const CommandTargetT type,
+ const std::string &icon,
+ const unsigned int basicLvl,
+ const MagicSchoolT school,
+ const unsigned int schoolLvl,
+ const int mana) :
mCommand(command),
mComment(comment),
mSymbol(symbol),
@@ -68,7 +72,7 @@ TextCommand::TextCommand(const unsigned int id, const std::string &symbol,
mIcon(icon),
mId(id),
mMana(0),
- mSchool(SKILL_MAGIC),
+ mSchool(MagicSchool::SkillMagic),
mBaseLvl(0),
mSchoolLvl(0),
mCommandType(TEXT_COMMAND_TEXT),
@@ -85,7 +89,7 @@ TextCommand::TextCommand(const unsigned int id) :
mIcon(""),
mId(id),
mMana(0),
- mSchool(SKILL_MAGIC),
+ mSchool(MagicSchool::SkillMagic),
mBaseLvl(0),
mSchoolLvl(0),
mCommandType(TEXT_COMMAND_TEXT),
diff --git a/src/textcommand.h b/src/textcommand.h
index 76749b51f..d09a1b9be 100644
--- a/src/textcommand.h
+++ b/src/textcommand.h
@@ -24,6 +24,7 @@
#define TEXTCOMMAND_H
#include "enums/commandtarget.h"
+#include "enums/magicschool.h"
#include <string>
@@ -33,16 +34,6 @@ const unsigned int MAGIC_START_ID = 340;
class Image;
-enum MagicSchool
-{
- SKILL_MAGIC = 340,
- SKILL_MAGIC_LIFE = 341,
- SKILL_MAGIC_WAR = 342,
- SKILL_MAGIC_TRANSMUTE = 343,
- SKILL_MAGIC_NATURE = 344,
- SKILL_MAGIC_ASTRAL = 345
-};
-
enum TextCommandType
{
TEXT_COMMAND_MAGIC = 0,
@@ -58,12 +49,16 @@ class TextCommand final
/**
* Constructor.
*/
- TextCommand(const unsigned int id, const std::string &symbol,
+ TextCommand(const unsigned int id,
+ const std::string &symbol,
const std::string &command,
- const std::string &comment, const CommandTargetT type,
- const std::string &icon, const unsigned int basicLvl,
- const MagicSchool school = SKILL_MAGIC,
- const unsigned int schoolLvl = 0, const int mana = 0);
+ const std::string &comment,
+ const CommandTargetT type,
+ const std::string &icon,
+ const unsigned int basicLvl,
+ const MagicSchoolT school = MagicSchool::SkillMagic,
+ const unsigned int schoolLvl = 0,
+ const int mana = 0);
/**
* Constructor.
@@ -108,7 +103,7 @@ class TextCommand final
int getMana() const A_WARN_UNUSED
{ return mMana; }
- MagicSchool getSchool() const A_WARN_UNUSED
+ MagicSchoolT getSchool() const A_WARN_UNUSED
{ return mSchool; }
unsigned getBaseLvl() const A_WARN_UNUSED
@@ -141,7 +136,7 @@ class TextCommand final
void setMana(const unsigned int mana)
{ mMana = mana; }
- void setSchool(const MagicSchool school)
+ void setSchool(const MagicSchoolT school)
{ mSchool = school; }
void setBaseLvl(const unsigned int baseLvl)
@@ -170,7 +165,7 @@ class TextCommand final
std::string mIcon;
unsigned int mId;
int mMana;
- MagicSchool mSchool;
+ MagicSchoolT mSchool;
unsigned mBaseLvl;
unsigned mSchoolLvl;
TextCommandType mCommandType;