summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-11-16 20:02:04 +0300
committerAndrei Karas <akaras@inbox.ru>2015-11-16 20:02:04 +0300
commit18bd0722a9cebc3ba80bfb74a5b5ba0dd9e53c75 (patch)
tree179d12121a4e588efa53c67a207e2ab5392d99eb /src
parent44cdf80268135a21ddb09710fc029e808fb3f519 (diff)
downloadmv-18bd0722a9cebc3ba80bfb74a5b5ba0dd9e53c75.tar.gz
mv-18bd0722a9cebc3ba80bfb74a5b5ba0dd9e53c75.tar.bz2
mv-18bd0722a9cebc3ba80bfb74a5b5ba0dd9e53c75.tar.xz
mv-18bd0722a9cebc3ba80bfb74a5b5ba0dd9e53c75.zip
Rename SpellTarget into CommandTarget enum and convert it to strong typed.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/enums/commandtarget.h34
-rw-r--r--src/gui/windows/textcommandeditor.cpp4
-rw-r--r--src/resources/db/commandsdb.cpp10
-rw-r--r--src/spellmanager.cpp17
-rw-r--r--src/textcommand.cpp6
-rw-r--r--src/textcommand.h19
8 files changed, 62 insertions, 30 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 12ccfb432..7e4e11e3d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -913,6 +913,7 @@ SET(SRCS
graphicsvertexes.h
guild.cpp
guild.h
+ enums/commandtarget.h
enums/dragdropsource.h
enums/equipslot.h
enums/guildpositionflags.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 7fd366647..ffa69a2d6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -689,6 +689,7 @@ manaplus_SOURCES += main.cpp \
itemshortcut.h \
itemsoundmanager.cpp \
itemsoundmanager.h \
+ enums/commandtarget.h \
enums/dragdropsource.h \
enums/equipslot.h \
enums/guildpositionflags.h \
diff --git a/src/enums/commandtarget.h b/src/enums/commandtarget.h
new file mode 100644
index 000000000..3fe5febed
--- /dev/null
+++ b/src/enums/commandtarget.h
@@ -0,0 +1,34 @@
+/*
+ * 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_COMMANDTARGET_H
+#define ENUMS_COMMANDTARGET_H
+
+#include "enums/simpletypes/enumdefines.h"
+
+enumStart(CommandTarget)
+{
+ NoTarget = 0,
+ AllowTarget = 1,
+ NeedTarget = 2
+}
+enumEnd(CommandTarget);
+
+#endif // ENUMS_COMMANDTARGET_H
diff --git a/src/gui/windows/textcommandeditor.cpp b/src/gui/windows/textcommandeditor.cpp
index 4269508aa..b72b82501 100644
--- a/src/gui/windows/textcommandeditor.cpp
+++ b/src/gui/windows/textcommandeditor.cpp
@@ -261,7 +261,7 @@ void TextCommandEditor::save()
mCommand->setComment(mCommentTextField->getText());
mCommand->setMana(mManaField->getValue());
mCommand->setTargetType(
- static_cast<SpellTarget>(mTypeDropDown->getSelected()));
+ static_cast<CommandTargetT>(mTypeDropDown->getSelected()));
mCommand->setIcon(mIconDropDown->getSelectedString());
mCommand->setBaseLvl(mMagicLvlField->getValue());
mCommand->setSchool(static_cast<MagicSchool>(
@@ -278,7 +278,7 @@ void TextCommandEditor::deleteCommand()
mCommand->setCommand("");
mCommand->setComment("");
mCommand->setMana(0);
- mCommand->setTargetType(NOTARGET);
+ mCommand->setTargetType(CommandTarget::NoTarget);
mCommand->setIcon("");
mCommand->setBaseLvl(0);
mCommand->setSchool(SKILL_MAGIC);
diff --git a/src/resources/db/commandsdb.cpp b/src/resources/db/commandsdb.cpp
index 091ae718c..2203cbaa8 100644
--- a/src/resources/db/commandsdb.cpp
+++ b/src/resources/db/commandsdb.cpp
@@ -46,14 +46,14 @@ void CommandsDB::load()
mLoaded = true;
}
-static SpellTarget parseTarget(const std::string &text)
+static CommandTargetT parseTarget(const std::string &text)
{
if (text == "allow target")
- return ALLOWTARGET;
+ return CommandTarget::AllowTarget;
else if (text == "need target")
- return NEEDTARGET;
+ return CommandTarget::NeedTarget;
else
- return NOTARGET;
+ return CommandTarget::NoTarget;
}
void CommandsDB::loadXmlFile(const std::string &fileName)
@@ -99,7 +99,7 @@ void CommandsDB::loadXmlFile(const std::string &fileName)
commandNode, "command", "");
const std::string comment = XML::getProperty(
commandNode, "comment", "");
- const SpellTarget targetType = parseTarget(XML::getProperty(
+ const CommandTargetT targetType = parseTarget(XML::getProperty(
commandNode, "target", ""));
const std::string icon = XML::getProperty(
commandNode, "icon", "");
diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp
index bc14f7537..84d05bc12 100644
--- a/src/spellmanager.cpp
+++ b/src/spellmanager.cpp
@@ -143,18 +143,18 @@ void SpellManager::invoke(const int spellId) const
&& PlayerInfo::getAttribute(Attributes::MP) >= spell->getMana()))
{
const Being *const target = localPlayer->getTarget();
- if (spell->getTargetType() == NOTARGET)
+ if (spell->getTargetType() == CommandTarget::NoTarget)
{
invokeSpell(spell);
}
if ((target && (target->getType() != ActorType::Monster
|| spell->getCommandType() == TEXT_COMMAND_TEXT))
- && (spell->getTargetType() == ALLOWTARGET
- || spell->getTargetType() == NEEDTARGET))
+ && (spell->getTargetType() == CommandTarget::AllowTarget
+ || spell->getTargetType() == CommandTarget::NeedTarget))
{
invokeSpell(spell, target);
}
- else if (spell->getTargetType() == ALLOWTARGET)
+ else if (spell->getTargetType() == CommandTarget::AllowTarget)
{
invokeSpell(spell);
}
@@ -287,13 +287,13 @@ void SpellManager::load(const bool oldConfig)
if (static_cast<TextCommandType>(commandType) == TEXT_COMMAND_MAGIC)
{
addSpell(new TextCommand(i, symbol, cmd, comment,
- static_cast<SpellTarget>(targetType), icon, basicLvl,
+ static_cast<CommandTargetT>(targetType), icon, basicLvl,
static_cast<MagicSchool>(school), schoolLvl, mana));
}
else
{
addSpell(new TextCommand(i, symbol, cmd, comment,
- static_cast<SpellTarget>(targetType), icon));
+ static_cast<CommandTargetT>(targetType), icon));
}
}
}
@@ -368,8 +368,9 @@ std::string SpellManager::autoComplete(const std::string &partName) const
}
++i;
}
- if (!newName.empty() && newCommand
- && newCommand->getTargetType() == NEEDTARGET)
+ if (!newName.empty() &&
+ newCommand &&
+ newCommand->getTargetType() == CommandTarget::NeedTarget)
{
return newName.append(" ");
}
diff --git a/src/textcommand.cpp b/src/textcommand.cpp
index 7f2a66748..5dbaa578d 100644
--- a/src/textcommand.cpp
+++ b/src/textcommand.cpp
@@ -37,7 +37,7 @@
TextCommand::TextCommand(const unsigned int id, const std::string &symbol,
const std::string &command,
const std::string &comment,
- const SpellTarget type, const std::string &icon,
+ const CommandTargetT type, const std::string &icon,
const unsigned int basicLvl, const MagicSchool school,
const unsigned int schoolLvl, const int mana) :
mCommand(command),
@@ -60,7 +60,7 @@ 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 SpellTarget type, const std::string &icon) :
+ const CommandTargetT type, const std::string &icon) :
mCommand(command),
mComment(comment),
mSymbol(symbol),
@@ -81,7 +81,7 @@ TextCommand::TextCommand(const unsigned int id) :
mCommand(""),
mComment(""),
mSymbol(""),
- mTargetType(NOTARGET),
+ mTargetType(CommandTarget::NoTarget),
mIcon(""),
mId(id),
mMana(0),
diff --git a/src/textcommand.h b/src/textcommand.h
index 79a6b6f7e..76749b51f 100644
--- a/src/textcommand.h
+++ b/src/textcommand.h
@@ -23,6 +23,8 @@
#ifndef TEXTCOMMAND_H
#define TEXTCOMMAND_H
+#include "enums/commandtarget.h"
+
#include <string>
#include "localconsts.h"
@@ -31,13 +33,6 @@ const unsigned int MAGIC_START_ID = 340;
class Image;
-enum SpellTarget
-{
- NOTARGET = 0,
- ALLOWTARGET = 1,
- NEEDTARGET = 2
-};
-
enum MagicSchool
{
SKILL_MAGIC = 340,
@@ -65,7 +60,7 @@ class TextCommand final
*/
TextCommand(const unsigned int id, const std::string &symbol,
const std::string &command,
- const std::string &comment, const SpellTarget type,
+ 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);
@@ -75,7 +70,7 @@ class TextCommand final
*/
TextCommand(const unsigned int id, const std::string &symbol,
const std::string &command, const std::string &comment,
- const SpellTarget type, const std::string &icon);
+ const CommandTargetT type, const std::string &icon);
/**
* Constructor.
@@ -104,7 +99,7 @@ class TextCommand final
unsigned int getId() const A_WARN_UNUSED
{ return mId; }
- SpellTarget getTargetType() const A_WARN_UNUSED
+ CommandTargetT getTargetType() const A_WARN_UNUSED
{ return mTargetType; }
std::string getIcon() const A_WARN_UNUSED
@@ -137,7 +132,7 @@ class TextCommand final
void setId(const unsigned int id)
{ mId = id; }
- void setTargetType(const SpellTarget targetType)
+ void setTargetType(const CommandTargetT targetType)
{ mTargetType = targetType; }
void setIcon(const std::string &icon)
@@ -171,7 +166,7 @@ class TextCommand final
std::string mCommand;
std::string mComment;
std::string mSymbol;
- SpellTarget mTargetType;
+ CommandTargetT mTargetType;
std::string mIcon;
unsigned int mId;
int mMana;