summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-26 00:27:05 +0100
committerBjørn Lindeijer <bjorn@lindeijer.nl>2009-03-26 00:32:19 +0100
commitdfcc6397848d4597b386b688f689352de6c19ae2 (patch)
treea6e8c9afd6a49ea96e4498080a96d3e06ecaebd7 /src
parentcd20fb3432498b8871401bdd65a143197e2a6538 (diff)
downloadmana-dfcc6397848d4597b386b688f689352de6c19ae2.tar.gz
mana-dfcc6397848d4597b386b688f689352de6c19ae2.tar.bz2
mana-dfcc6397848d4597b386b688f689352de6c19ae2.tar.xz
mana-dfcc6397848d4597b386b688f689352de6c19ae2.zip
Remove redundancy, fix variable names and other code cleanups
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp24
-rw-r--r--src/being.h5
-rw-r--r--src/gui/changeemaildialog.h3
-rw-r--r--src/gui/icon.h6
-rw-r--r--src/gui/inventorywindow.cpp24
-rw-r--r--src/gui/itempopup.cpp4
-rw-r--r--src/gui/serverdialog.h4
-rw-r--r--src/gui/skilldialog.cpp57
-rw-r--r--src/gui/skilldialog.h62
-rw-r--r--src/gui/speechbubble.cpp5
-rw-r--r--src/gui/textdialog.cpp40
-rw-r--r--src/gui/textdialog.h8
-rw-r--r--src/gui/trade.cpp23
-rw-r--r--src/gui/widgets/resizegrip.cpp2
-rw-r--r--src/gui/widgets/resizegrip.h2
-rw-r--r--src/guild.h4
-rw-r--r--src/localplayer.cpp9
-rw-r--r--src/localplayer.h2
-rw-r--r--src/main.cpp83
-rw-r--r--src/monster.cpp8
-rw-r--r--src/monster.h2
-rw-r--r--src/units.cpp32
22 files changed, 190 insertions, 219 deletions
diff --git a/src/being.cpp b/src/being.cpp
index c0623255..921ed75e 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -90,7 +90,6 @@ Being::Being(int id, int job, Map *map):
mSpriteDirection(DIRECTION_DOWN),
#endif
mMap(NULL),
- mName(""),
mIsGM(false),
mParticleEffects(config.getValue("particleeffects", 1)),
mEquippedWeapon(NULL),
@@ -120,7 +119,6 @@ Being::Being(int id, int job, Map *map):
mSpeechBubble = new SpeechBubble;
- mSpeech = "";
mNameColor = &guiPalette->getColor(Palette::CHAT);
mText = 0;
}
@@ -916,32 +914,18 @@ int Being::getOffset(char pos, char neg) const
int Being::getWidth() const
{
- if (mSprites[BASE_SPRITE])
- {
- const int width = mSprites[BASE_SPRITE]->getWidth() > DEFAULT_WIDTH ?
- mSprites[BASE_SPRITE]->getWidth() :
- DEFAULT_WIDTH;
- return width;
- }
+ if (AnimatedSprite *base = mSprites[BASE_SPRITE])
+ return std::max(base->getWidth(), DEFAULT_WIDTH);
else
- {
return DEFAULT_WIDTH;
- }
}
int Being::getHeight() const
{
- if (mSprites[BASE_SPRITE])
- {
- const int height = mSprites[BASE_SPRITE]->getHeight() > DEFAULT_HEIGHT ?
- mSprites[BASE_SPRITE]->getHeight() :
- DEFAULT_HEIGHT;
- return height;
- }
+ if (AnimatedSprite *base = mSprites[BASE_SPRITE])
+ return std::max(base->getHeight(), DEFAULT_HEIGHT);
else
- {
return DEFAULT_HEIGHT;
- }
}
void Being::setTargetAnimation(SimpleAnimation* animation)
diff --git a/src/being.h b/src/being.h
index e9805d9b..8c92ab78 100644
--- a/src/being.h
+++ b/src/being.h
@@ -633,11 +633,6 @@ class Being : public Sprite
/** Reset particle status effects on next redraw? */
bool mMustResetParticles;
-#ifdef TMWSERV_SUPPORT
- static const int DEFAULT_WIDTH = 32;
- static const int DEFAULT_HEIGHT = 32;
-#endif
-
// Speech Bubble components
SpeechBubble *mSpeechBubble;
diff --git a/src/gui/changeemaildialog.h b/src/gui/changeemaildialog.h
index 8ec3705d..c39c6b50 100644
--- a/src/gui/changeemaildialog.h
+++ b/src/gui/changeemaildialog.h
@@ -37,7 +37,8 @@ class WrongDataNoticeListener;
*
* \ingroup Interface
*/
-class ChangeEmailDialog : public Window, public gcn::ActionListener {
+class ChangeEmailDialog : public Window, public gcn::ActionListener
+{
public:
/**
* Constructor.
diff --git a/src/gui/icon.h b/src/gui/icon.h
index 9baf1a99..7435a6e7 100644
--- a/src/gui/icon.h
+++ b/src/gui/icon.h
@@ -27,13 +27,13 @@
class Image;
-
/**
* An icon.
*
* \ingroup GUI
*/
-class Icon : public gcn::Widget {
+class Icon : public gcn::Widget
+{
public:
/**
* Constructor.
@@ -48,7 +48,7 @@ class Icon : public gcn::Widget {
/**
* Gets the current Image.
*/
- Image* getImage() { return mImage; }
+ Image *getImage() const { return mImage; }
/**
* Sets the image to display.
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 0b554469..5a5d8db6 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -136,34 +136,28 @@ void InventoryWindow::logic()
// redesign of InventoryWindow and ItemContainer probably.
updateButtons();
+ const int usedSlots = player_node->getInventory()->getNumberOfSlotsUsed();
+ const std::string usedSlotsStr = toString(usedSlots);
+
if (mMaxWeight != player_node->getMaxWeight() ||
mTotalWeight != player_node->getTotalWeight() ||
- mUsedSlots != toString(player_node->getInventory()->getNumberOfSlotsUsed()))
+ mUsedSlots != usedSlotsStr)
{
mTotalWeight = player_node->getTotalWeight();
mMaxWeight = player_node->getMaxWeight();
- mUsedSlots = toString(player_node->getInventory()->getNumberOfSlotsUsed());
+ mUsedSlots = usedSlotsStr;
// Weight Bar coloration
- if (int(player_node->getTotalWeight()) < int(player_node->getMaxWeight() / 3))
- {
+ if (mTotalWeight < (int) (mMaxWeight / 3))
mWeightBar->setColor(0, 0, 255); // Blue
- }
- else if (int(player_node->getTotalWeight()) <
- int((player_node->getMaxWeight() / 3) * 2))
- {
+ else if (mTotalWeight < (int) ((mMaxWeight * 2) / 3))
mWeightBar->setColor(255, 255, 0); // Yellow
- }
else
- {
mWeightBar->setColor(255, 0, 0); // Red
- }
// Adjust progress bars
- mSlotsBar->setProgress((float)
- player_node->getInventory()->getNumberOfSlotsUsed() / mMaxSlots);
- mWeightBar->setProgress((float) player_node->getTotalWeight() /
- player_node->getMaxWeight());
+ mSlotsBar->setProgress((float) usedSlots / mMaxSlots);
+ mWeightBar->setProgress((float) mTotalWeight / mMaxWeight);
mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots));
mWeightBar->setText(strprintf("%s/%s",
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 8023f0c2..379e6029 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -42,10 +42,8 @@
ItemPopup::ItemPopup():
Popup()
{
- mItemType = "";
-
// Item Name
- mItemName = new gcn::Label("");
+ mItemName = new gcn::Label;
mItemName->setFont(boldFont);
mItemName->setPosition(2, 2);
diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h
index 16965571..dd4f369f 100644
--- a/src/gui/serverdialog.h
+++ b/src/gui/serverdialog.h
@@ -43,8 +43,8 @@ class LoginData;
*/
struct Server {
Server():
- serverName(""),
- port(0) {};
+ port(0)
+ {}
std::string serverName;
short port;
diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp
index 22d1db60..9506e7f8 100644
--- a/src/gui/skilldialog.cpp
+++ b/src/gui/skilldialog.cpp
@@ -40,6 +40,61 @@
#include "../utils/gettext.h"
#include "../utils/stringutils.h"
+class Skill_Tab : public GCContainer, public gcn::ActionListener
+{
+ public:
+ /**
+ * The type of this skill tab
+ */
+ const std::string type;
+
+ /**
+ * Constructor
+ */
+ Skill_Tab(const std::string &type);
+
+ /**
+ * Update this tab
+ */
+ void update();
+
+ /**
+ * Called when receiving actions from widget.
+ */
+ void action(const gcn::ActionEvent &event) {}
+
+ private:
+ /**
+ * Update the information of a skill at
+ * the given index
+ */
+ void updateSkill(int index);
+
+ /**
+ * Gets the number of skills in this particular
+ * type of tab.
+ */
+ int getSkillNum();
+
+ /**
+ * Get the first enumeration of this skill tab's
+ * skill type.
+ */
+ int getSkillBegin();
+
+ /**
+ * Get the icon associated with the given index
+ */
+ Icon* getIcon(int index);
+
+ std::vector<Icon *> mSkillIcons;
+ std::vector<gcn::Label *> mSkillNameLabels;
+ std::vector<gcn::Label *> mSkillLevelLabels;
+ std::vector<gcn::Label *> mSkillExpLabels;
+ std::vector<ProgressBar *> mSkillProgress;
+};
+
+
SkillDialog::SkillDialog():
Window(_("Skills"))
{
@@ -50,7 +105,7 @@ SkillDialog::SkillDialog():
TabbedArea *panel = new TabbedArea();
panel->setDimension(gcn::Rectangle(5, 5, 270, 420));
- Skill_Tab* tab;
+ Skill_Tab *tab;
// Add each type of skill tab to the panel
tab = new Skill_Tab("Weapon");
diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h
index 3d010daa..64fd800a 100644
--- a/src/gui/skilldialog.h
+++ b/src/gui/skilldialog.h
@@ -35,61 +35,7 @@
class ProgressBar;
class Icon;
-
-class Skill_Tab : public GCContainer, public gcn::ActionListener
-{
- public:
- /**
- * The type of this skill tab
- */
- const std::string type;
-
- /**
- * Constructor
- */
- Skill_Tab(const std::string &type);
-
- /**
- * Update this tab
- */
- void update();
-
- /**
- * Called when receiving actions from widget.
- */
- void action(const gcn::ActionEvent &event) {}
-
- private:
- /**
- * Update the information of a skill at
- * the given index
- */
- void updateSkill(int index);
-
- /**
- * Gets the number of skills in this particular
- * type of tab.
- */
- int getSkillNum();
-
- /**
- * Get the first enumeration of this skill tab's
- * skill type.
- */
- int getSkillBegin();
-
- /**
- * Get the icon associated with the given index
- */
- Icon* getIcon(int index);
-
- std::vector<Icon *> mSkillIcons;
- std::vector<gcn::Label *> mSkillNameLabels;
- std::vector<gcn::Label *> mSkillLevelLabels;
- std::vector<gcn::Label *> mSkillExpLabels;
- std::vector<ProgressBar *> mSkillProgress;
-};
-
+class Skill_Tab;
/**
* The skill dialog.
@@ -125,15 +71,9 @@ class SkillDialog : public Window, public gcn::ActionListener
void draw(gcn::Graphics *g);
private:
-
-
std::list<Skill_Tab*> mTabs;
-
};
-
-
-
extern SkillDialog *skillDialog;
#endif
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index 73ada2e1..b191ba77 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -34,14 +34,13 @@
#include "../utils/gettext.h"
SpeechBubble::SpeechBubble():
- Popup("Speech", NULL, "graphics/gui/speechbubble.xml"),
- mText("")
+ Popup("Speech", NULL, "graphics/gui/speechbubble.xml")
{
setContentSize(140, 46);
setMinWidth(29);
setMinHeight(29);
- mCaption = new gcn::Label("");
+ mCaption = new gcn::Label;
mCaption->setFont(boldFont);
mCaption->setPosition(5, 3);
diff --git a/src/gui/textdialog.cpp b/src/gui/textdialog.cpp
index 68a6f502..6163fa36 100644
--- a/src/gui/textdialog.cpp
+++ b/src/gui/textdialog.cpp
@@ -20,41 +20,41 @@
*/
#include "textdialog.h"
+#include "button.h"
+
+#include "../utils/gettext.h"
#include <guichan/widgets/label.hpp>
#include <guichan/widgets/textfield.hpp>
-#include "button.h"
-
TextDialog::TextDialog(const std::string &title, const std::string &msg,
- Window *parent):
+ Window *parent):
Window(title, true, parent),
- textField(new TextField(""))
+ mTextField(new TextField)
{
gcn::Label *textLabel = new gcn::Label(msg);
- okButton = new Button("OK", "OK", this);
- gcn::Button *cancelButton = new Button("Cancel", "CANCEL", this);
+ mOkButton = new Button(_("OK"), "OK", this);
+ gcn::Button *cancelButton = new Button(_("Cancel"), "CANCEL", this);
int w = textLabel->getWidth() + 20;
- int inWidth = okButton->getWidth() + cancelButton->getWidth() + 5;
- int h = textLabel->getHeight() + 25 + okButton->getHeight() + textField->getHeight();
+ int inWidth = mOkButton->getWidth() + cancelButton->getWidth() + 5;
+ int h = textLabel->getHeight() + 25 + mOkButton->getHeight() + mTextField->getHeight();
- if (w < inWidth + 10) {
+ if (w < inWidth + 10)
w = inWidth + 10;
- }
setContentSize(w, h);
textLabel->setPosition(10, 10);
- textField->setWidth(85);
- textField->setPosition(10,20 + textLabel->getHeight());
- okButton->setPosition((w - inWidth) / 2,
+ mTextField->setWidth(85);
+ mTextField->setPosition(10,20 + textLabel->getHeight());
+ mOkButton->setPosition((w - inWidth) / 2,
h - 5 - cancelButton->getHeight());
- cancelButton->setPosition(okButton->getX() + okButton->getWidth() + 5,
+ cancelButton->setPosition(mOkButton->getX() + mOkButton->getWidth() + 5,
h - 5 - cancelButton->getHeight());
add(textLabel);
- add(textField);
- add(okButton);
+ add(mTextField);
+ add(mOkButton);
add(cancelButton);
if (getParent()) {
@@ -62,7 +62,7 @@ TextDialog::TextDialog(const std::string &title, const std::string &msg,
getParent()->moveToTop(this);
}
setVisible(true);
- textField->requestFocus();
+ mTextField->requestFocus();
}
void TextDialog::action(const gcn::ActionEvent &event)
@@ -74,7 +74,7 @@ void TextDialog::action(const gcn::ActionEvent &event)
(*i)->action(event);
}
- if(event.getId() == "CANCEL" || event.getId() == "OK")
+ if (event.getId() == "CANCEL" || event.getId() == "OK")
{
scheduleDelete();
}
@@ -82,10 +82,10 @@ void TextDialog::action(const gcn::ActionEvent &event)
const std::string &TextDialog::getText() const
{
- return textField->getText();
+ return mTextField->getText();
}
void TextDialog::setOKButtonActionId(const std::string &name)
{
- okButton->setActionEventId(name);
+ mOkButton->setActionEventId(name);
}
diff --git a/src/gui/textdialog.h b/src/gui/textdialog.h
index 5583e189..3e544fb4 100644
--- a/src/gui/textdialog.h
+++ b/src/gui/textdialog.h
@@ -27,13 +27,13 @@
#include "window.h"
-
/**
* An option dialog.
*
* \ingroup GUI
*/
-class TextDialog : public Window, public gcn::ActionListener {
+class TextDialog : public Window, public gcn::ActionListener
+{
public:
/**
* Constructor.
@@ -59,8 +59,8 @@ public:
void setOKButtonActionId(const std::string &name);
private:
- TextField *textField;
- gcn::Button *okButton;
+ TextField *mTextField;
+ gcn::Button *mOkButton;
};
#endif
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 5be71a6f..2ba076a3 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -79,11 +79,12 @@ TradeWindow::TradeWindow(Network *network):
getFont()->getWidth(_("Trade")) ?
_("OK") : _("Trade");
- Button *mAddButton = new Button(_("Add"), "add", this);
+ Button *addButton = new Button(_("Add"), "add", this);
#ifdef EATHENA_SUPPORT
mOkButton = new Button(longestName, "ok", this);
+#else
+ Button *cancelButton = new Button(_("Cancel"), "cancel", this);
#endif
- Button *mCancelButton = new Button(_("Cancel"), "cancel", this);
mTradeButton = new Button(_("Propose trade"), "trade", this);
mTradeButton->setWidth(8 + std::max(
mTradeButton->getFont()->getWidth(_("Propose trade")),
@@ -96,7 +97,7 @@ TradeWindow::TradeWindow(Network *network):
#endif
mMyItemContainer->addSelectionListener(this);
- ScrollArea *mMyScroll = new ScrollArea(mMyItemContainer);
+ ScrollArea *myScroll = new ScrollArea(mMyItemContainer);
#ifdef TMWSERV_SUPPORT
mPartnerItemContainer = new ItemContainer(mPartnerInventory.get(), 4, 3, 0);
@@ -105,30 +106,30 @@ TradeWindow::TradeWindow(Network *network):
#endif
mPartnerItemContainer->addSelectionListener(this);
- ScrollArea *mPartnerScroll = new ScrollArea(mPartnerItemContainer);
+ ScrollArea *partnerScroll = new ScrollArea(mPartnerItemContainer);
mMoneyLabel = new Label(strprintf(_("You get %s."), ""));
gcn::Label *mMoneyLabel2 = new Label(_("You give:"));
mMoneyField = new TextField;
mMoneyField->setWidth(40);
- Button *mMoneyChange = new Button(_("Change"), "money", this);
+ Button *moneyChange = new Button(_("Change"), "money", this);
place(1, 0, mMoneyLabel);
- place(0, 1, mMyScroll).setPadding(3);
- place(1, 1, mPartnerScroll).setPadding(3);
+ place(0, 1, myScroll).setPadding(3);
+ place(1, 1, partnerScroll).setPadding(3);
ContainerPlacer place;
place = getPlacer(0, 0);
place(0, 0, mMoneyLabel2);
place(1, 0, mMoneyField);
- place(2, 0, mMoneyChange).setHAlign(LayoutCell::LEFT);
+ place(2, 0, moneyChange).setHAlign(LayoutCell::LEFT);
place = getPlacer(0, 2);
- place(0, 0, mAddButton);
+ place(0, 0, addButton);
#ifdef EATHENA_SUPPORT
place(1, 0, mOkButton);
#else
place(2, 0, mTradeButton);
- place(3, 0, mCancelButton);
+ place(3, 0, cancelButton);
#endif
Layout &layout = getLayout();
layout.extend(0, 2, 2, 1);
@@ -276,7 +277,7 @@ void TradeWindow::valueChanged(const gcn::SelectionEvent &event)
if (event.getSource() == mMyItemContainer &&
(item = mMyItemContainer->getSelectedItem()))
mPartnerItemContainer->selectNone();
- else if ((item = mPartnerItemContainer->getSelectedItem()))
+ else if (item = mPartnerItemContainer->getSelectedItem())
mMyItemContainer->selectNone();
}
diff --git a/src/gui/widgets/resizegrip.cpp b/src/gui/widgets/resizegrip.cpp
index fa264e37..172d4d7e 100644
--- a/src/gui/widgets/resizegrip.cpp
+++ b/src/gui/widgets/resizegrip.cpp
@@ -33,7 +33,7 @@ Image *ResizeGrip::gripImage = 0;
int ResizeGrip::mInstances = 0;
float ResizeGrip::mAlpha = config.getValue("guialpha", 0.8);
-ResizeGrip::ResizeGrip(std::string image)
+ResizeGrip::ResizeGrip(const std::string &image)
{
if (mInstances == 0)
{
diff --git a/src/gui/widgets/resizegrip.h b/src/gui/widgets/resizegrip.h
index 620c133f..40a40a0f 100644
--- a/src/gui/widgets/resizegrip.h
+++ b/src/gui/widgets/resizegrip.h
@@ -39,7 +39,7 @@ class ResizeGrip : public gcn::Widget
/**
* Constructor.
*/
- ResizeGrip(std::string image = "graphics/gui/resize.png");
+ ResizeGrip(const std::string &image = "graphics/gui/resize.png");
/**
* Destructor.
diff --git a/src/guild.h b/src/guild.h
index 2d096710..4b1e244a 100644
--- a/src/guild.h
+++ b/src/guild.h
@@ -22,9 +22,11 @@
#ifndef TMW_GUILD_H
#define TMW_GUILD_H
-#include <string>
#include <guichan/listmodel.hpp>
+#include <string>
+#include <vector>
+
class Guild : public gcn::ListModel
{
public:
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index 2233942d..08c778d2 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -645,12 +645,12 @@ void LocalPlayer::setTarget(Being *target)
mTarget->untarget();
if (mTarget && mTarget->getType() == Being::MONSTER)
- static_cast<Monster *>(mTarget)->showName(false);
+ static_cast<Monster *>(mTarget)->setShowName(false);
mTarget = target;
if (target && target->getType() == Being::MONSTER)
- static_cast<Monster *>(target)->showName(true);
+ static_cast<Monster *>(target)->setShowName(true);
}
#ifdef TMWSERV_SUPPORT
@@ -943,9 +943,6 @@ void LocalPlayer::attack(Being *target, bool keep)
setDirection(LEFT);
}
- // Implement charging attacks here
- mLastAttackTime = 0;
-
mWalkTime = tick_time;
mTargetTime = tick_time;
@@ -1079,7 +1076,7 @@ void LocalPlayer::setXp(int xp)
#endif
-void LocalPlayer::pickedUp(std::string item)
+void LocalPlayer::pickedUp(const std::string &item)
{
if (mMap)
{
diff --git a/src/localplayer.h b/src/localplayer.h
index 703dbbfa..99cb00d6 100644
--- a/src/localplayer.h
+++ b/src/localplayer.h
@@ -368,7 +368,7 @@ class LocalPlayer : public Player
/**
* Shows item pickup effect if the player is on a map.
*/
- void pickedUp(std::string item);
+ void pickedUp(const std::string &item);
#ifdef EATHENA_SUPPORT
/**
diff --git a/src/main.cpp b/src/main.cpp
index 50eb6444..2f99b352 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -207,7 +207,7 @@ struct Options
skipUpdate(false),
chooseDefault(false),
serverPort(0)
- {};
+ {}
bool printHelp;
bool printVersion;
@@ -228,7 +228,7 @@ struct Options
* Parse the update host and determine the updates directory
* Then verify that the directory exists (creating if needed).
*/
-void setUpdatesDir()
+static void setUpdatesDir()
{
std::stringstream updates;
@@ -307,7 +307,7 @@ void setUpdatesDir()
* Initializes the home directory. On UNIX and FreeBSD, ~/.tmw is used. On
* Windows and other systems we use the current working directory.
*/
-void initHomeDir()
+static void initHomeDir()
{
homeDir = std::string(PHYSFS_getUserDir()) +
"/." +
@@ -338,7 +338,7 @@ void initHomeDir()
/**
* Initialize configuration.
*/
-void initConfiguration(const Options &options)
+static void initConfiguration(const Options &options)
{
// Fill configuration with defaults
logger->log("Initializing configuration...");
@@ -397,7 +397,7 @@ void initConfiguration(const Options &options)
/**
* Do all initialization stuff.
*/
-void initEngine(const Options &options)
+static void initEngine(const Options &options)
{
// Initialize SDL
logger->log("Initializing SDL...");
@@ -533,7 +533,7 @@ void initEngine(const Options &options)
}
/** Clear the engine */
-void exit_engine()
+static void exitEngine()
{
// Before config.write() since it writes the shortcuts to the config
delete itemShortcut;
@@ -563,7 +563,7 @@ void exit_engine()
SDL_FreeSurface(icon);
}
-void printHelp()
+static void printHelp()
{
std::cout
<< _("tmw") << std::endl << std::endl
@@ -584,7 +584,7 @@ void printHelp()
<< _(" -v --version : Display the version") << std::endl;
}
-void printVersion()
+static void printVersion()
{
#ifdef PACKAGE_VERSION
std::cout << _("The Mana World version ") << PACKAGE_VERSION << std::endl;
@@ -594,7 +594,7 @@ void printVersion()
#endif
}
-void parseOptions(int argc, char *argv[], Options &options)
+static void parseOptions(int argc, char *argv[], Options &options)
{
const char *optstring = "hvud:U:P:Dc:s:o:C:H:S:";
@@ -671,7 +671,7 @@ void parseOptions(int argc, char *argv[], Options &options)
* Reads the file "{Updates Directory}/resources2.txt" and attempts to load
* each update mentioned in it.
*/
-void loadUpdates()
+static void loadUpdates()
{
if (updatesDir.empty()) return;
const std::string updatesFile = "/" + updatesDir + "/resources2.txt";
@@ -718,11 +718,13 @@ struct LoginListener : public gcn::ActionListener
} loginListener;
#endif
+} // namespace
+
// TODO Find some nice place for these functions
#ifdef TMWSERV_SUPPORT
-void accountLogin(LoginData *loginData)
+static void accountLogin(LoginData *loginData)
#else
-void accountLogin(Network *network, LoginData *loginData)
+static void accountLogin(Network *network, LoginData *loginData)
#endif
{
#ifdef EATHENA_SUPPORT
@@ -794,7 +796,7 @@ static void positionDialog(Window *dialog, int screenWidth, int screenHeight)
(screenHeight - dialog->getHeight()) / 2);
}
-void charLogin(Network *network, LoginData *loginData)
+static void charLogin(Network *network, LoginData *loginData)
{
logger->log("Trying to connect to char server...");
network->connect(loginData->hostname, loginData->port);
@@ -817,7 +819,7 @@ void charLogin(Network *network, LoginData *loginData)
network->skip(4);
}
-void mapLogin(Network *network, LoginData *loginData)
+static void mapLogin(Network *network, LoginData *loginData)
{
logger->log("Memorizing selected character %s",
player_node->getName().c_str());
@@ -845,7 +847,7 @@ void mapLogin(Network *network, LoginData *loginData)
#else
-void accountRegister(LoginData *loginData)
+static void accountRegister(LoginData *loginData)
{
logger->log("Username is %s", loginData->username.c_str());
@@ -861,7 +863,7 @@ void accountRegister(LoginData *loginData)
loginData->email);
}
-void accountUnRegister(LoginData *loginData)
+static void accountUnRegister(LoginData *loginData)
{
Net::registerHandler(&logoutHandler);
@@ -870,7 +872,7 @@ void accountUnRegister(LoginData *loginData)
}
-void accountChangePassword(LoginData *loginData)
+static void accountChangePassword(LoginData *loginData)
{
Net::registerHandler(&loginHandler);
@@ -879,14 +881,14 @@ void accountChangePassword(LoginData *loginData)
loginData->newPassword);
}
-void accountChangeEmail(LoginData *loginData)
+static void accountChangeEmail(LoginData *loginData)
{
Net::registerHandler(&loginHandler);
Net::AccountServer::Account::changeEmail(loginData->newEmail);
}
-void switchCharacter(std::string *passToken)
+static void switchCharacter(std::string *passToken)
{
Net::registerHandler(&logoutHandler);
@@ -897,7 +899,7 @@ void switchCharacter(std::string *passToken)
Net::ChatServer::logout();
}
-void switchAccountServer()
+static void switchAccountServer()
{
Net::registerHandler(&logoutHandler);
@@ -933,7 +935,7 @@ void switchAccountServer()
}
}
-void logoutThenExit()
+static void logoutThenExit()
{
Net::registerHandler(&logoutHandler);
@@ -969,7 +971,7 @@ void logoutThenExit()
}
}
-void reconnectAccount(const std::string &passToken)
+static void reconnectAccount(const std::string &passToken)
{
Net::registerHandler(&loginHandler);
@@ -981,14 +983,30 @@ void reconnectAccount(const std::string &passToken)
#endif
-void xmlNullLogger(void *ctx, const char *msg, ...)
+static void initInternationalization()
+{
+#if ENABLE_NLS
+#ifdef WIN32
+ putenv(("LANG=" + std::string(_nl_locale_name_default())).c_str());
+ // mingw doesn't like LOCALEDIR to be defined for some reason
+ bindtextdomain("tmw", "translations/");
+#else
+ bindtextdomain("tmw", LOCALEDIR);
+#endif
+ setlocale(LC_MESSAGES, "");
+ bind_textdomain_codeset("tmw", "UTF-8");
+ textdomain("tmw");
+#endif
+}
+
+static void xmlNullLogger(void *ctx, const char *msg, ...)
{
// Does nothing, that's the whole point of it
}
// Initialize libxml2 and check for potential ABI mismatches between
// compiled version and the shared library actually used.
-void initXML()
+static void initXML()
{
xmlInitParser();
LIBXML_TEST_VERSION;
@@ -997,8 +1015,6 @@ void initXML()
xmlSetGenericErrorFunc(NULL, xmlNullLogger);
}
-} // namespace
-
extern "C" char const *_nl_locale_name_default(void);
/** Main */
@@ -1018,18 +1034,7 @@ int main(int argc, char *argv[])
return 0;
}
-#if ENABLE_NLS
-#ifdef WIN32
- putenv(("LANG=" + std::string(_nl_locale_name_default())).c_str());
- // mingw doesn't like LOCALEDIR to be defined for some reason
- bindtextdomain("tmw", "translations/");
-#else
- bindtextdomain("tmw", LOCALEDIR);
-#endif
- setlocale(LC_MESSAGES, "");
- bind_textdomain_codeset("tmw", "UTF-8");
- textdomain("tmw");
-#endif
+ initInternationalization();
// Initialize PhysicsFS
PHYSFS_init(argv[0]);
@@ -1804,7 +1809,7 @@ int main(int argc, char *argv[])
#endif
logger->log("Quitting");
- exit_engine();
+ exitEngine();
PHYSFS_deinit();
delete logger;
diff --git a/src/monster.cpp b/src/monster.cpp
index c8abcc05..eaea6225 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -211,12 +211,10 @@ const MonsterInfo &Monster::getInfo() const
#endif
}
-void Monster::showName(bool show)
+void Monster::setShowName(bool show)
{
- if (mText)
- {
- delete mText;
- }
+ delete mText;
+
if (show)
{
mText = new Text(getInfo().getName(), mPx + NAME_X_OFFSET,
diff --git a/src/monster.h b/src/monster.h
index 34a2f237..cd2a8f0c 100644
--- a/src/monster.h
+++ b/src/monster.h
@@ -76,7 +76,7 @@ class Monster : public Being
/**
* Determine whether the mob should show it's name
*/
- void showName(bool show);
+ void setShowName(bool show);
/**
* Gets the way the monster is blocked by other objects
diff --git a/src/units.cpp b/src/units.cpp
index 7e8d8e6a..acdbd564 100644
--- a/src/units.cpp
+++ b/src/units.cpp
@@ -21,16 +21,16 @@
#include "units.h"
-#include <cmath>
-#include <climits>
-#include <vector>
-
#include "log.h"
#include "utils/strprintf.h"
#include "utils/stringutils.h"
#include "utils/xml.h"
+#include <cmath>
+#include <climits>
+#include <vector>
+
struct UnitLevel {
std::string symbol;
int count;
@@ -53,11 +53,6 @@ struct UnitDescription units[UNIT_END];
void Units::loadUnits()
{
- int level;
- std::string type;
- XML::Document doc("units.xml");
- xmlNodePtr root = doc.rootNode();
-
{ // Setup default weight
struct UnitDescription ud;
@@ -97,6 +92,9 @@ void Units::loadUnits()
units[UNIT_CURRENCY] = ud;
}
+ XML::Document doc("units.xml");
+ xmlNodePtr root = doc.rootNode();
+
if (!root || !xmlStrEqual(root->name, BAD_CAST "units"))
{
logger->log("Error loading unit definition file: units.xml");
@@ -108,8 +106,8 @@ void Units::loadUnits()
if (xmlStrEqual(node->name, BAD_CAST "unit"))
{
struct UnitDescription ud;
- level = 1;
- type = XML::getProperty(node, "type", "");
+ int level = 1;
+ const std::string type = XML::getProperty(node, "type", "");
ud.conversion = XML::getProperty(node, "conversion", 1.0);
ud.mix = XML::getProperty(node, "mix", "no") == "yes";
@@ -151,9 +149,12 @@ void Units::loadUnits()
ud.levels.push_back(ll);
- if (type == "weight") units[UNIT_WEIGHT] = ud;
- else if (type =="currency") units[UNIT_CURRENCY] = ud;
- else logger->log("Error unknown unit type: %s", type.c_str());
+ if (type == "weight")
+ units[UNIT_WEIGHT] = ud;
+ else if (type == "currency")
+ units[UNIT_CURRENCY] = ud;
+ else
+ logger->log("Error unknown unit type: %s", type.c_str());
}
}
}
@@ -162,13 +163,14 @@ std::string formatUnit(int value, int type)
{
struct UnitDescription ud = units[type];
struct UnitLevel ul;
- double amount = ud.conversion * value;
// Shortcut for 0; do the same for values less than 0 (for now)
if (value <= 0) {
ul = ud.levels[0];
return strprintf("0%s", ul.symbol.c_str());
} else {
+ double amount = ud.conversion * value;
+
// If only the first level is needed, act like mix if false
if (ud.mix && ud.levels.size() > 0 && ud.levels[1].count < amount)
{