summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-06-02 00:32:53 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2011-06-02 16:41:47 +0200
commit4e27937924766948d7ff9200f04a37fe4d59018c (patch)
treec1f5c255192c85a82c77c2f8f916984e2b863c44
parentc2eab288ecc7d7c5e26d02ccecf285cbc0c218ed (diff)
downloadmana-client-4e27937924766948d7ff9200f04a37fe4d59018c.tar.gz
mana-client-4e27937924766948d7ff9200f04a37fe4d59018c.tar.bz2
mana-client-4e27937924766948d7ff9200f04a37fe4d59018c.tar.xz
mana-client-4e27937924766948d7ff9200f04a37fe4d59018c.zip
Arbitrary code cleanups
Just some stuff that piles up while "looking" at the code, which eventually gets annoying to ignore while staging real changes. * Replaced a few NULL occurrences with 0 * Rely on default parameter for std::vector::resize. * Replaced a few "" with std::string() * Prefer .empty() to == "" * Removed a few comparisons with NULL * Don't check pointers before deleting them * Removed a bunch of redundant semicolons * Made some global variables static (local to their compilation unit) * Prefer prefix ++/-- operators to postfix versions when possible * Corrected location of a comment
-rw-r--r--src/being.cpp8
-rw-r--r--src/being.h3
-rw-r--r--src/client.cpp6
-rw-r--r--src/compoundsprite.cpp9
-rw-r--r--src/gui/equipmentwindow.cpp32
-rw-r--r--src/gui/ministatus.cpp6
-rw-r--r--src/gui/okdialog.h2
-rw-r--r--src/gui/widgets/listbox.cpp4
-rw-r--r--src/gui/widgets/tablemodel.cpp4
-rw-r--r--src/inventory.cpp7
-rw-r--r--src/inventory.h2
-rw-r--r--src/net/manaserv/manaserv_protocol.h2
-rw-r--r--src/net/messagein.h2
-rw-r--r--src/net/tmwa/beinghandler.cpp2
-rw-r--r--src/net/tmwa/generalhandler.h2
-rw-r--r--src/net/tmwa/inventoryhandler.cpp7
-rw-r--r--src/net/tmwa/inventoryhandler.h21
-rw-r--r--src/particlecontainer.cpp2
-rw-r--r--src/playerinfo.cpp24
-rw-r--r--src/resources/itemdb.cpp2
-rw-r--r--src/resources/itemdb.h18
-rw-r--r--src/resources/iteminfo.h12
-rw-r--r--src/resources/resource.cpp4
-rw-r--r--src/tileset.h2
24 files changed, 88 insertions, 95 deletions
diff --git a/src/being.cpp b/src/being.cpp
index a307ddc1..9c50ca1d 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -1061,10 +1061,10 @@ void Being::setSprite(unsigned int slot, int id, const std::string &color,
ensureSize(slot + 1);
if (slot >= mSpriteIDs.size())
- mSpriteIDs.resize(slot + 1, 0);
+ mSpriteIDs.resize(slot + 1);
if (slot >= mSpriteColors.size())
- mSpriteColors.resize(slot + 1, "");
+ mSpriteColors.resize(slot + 1);
// id = 0 means unequip
if (id == 0)
@@ -1072,12 +1072,12 @@ void Being::setSprite(unsigned int slot, int id, const std::string &color,
removeSprite(slot);
if (isWeapon)
- mEquippedWeapon = NULL;
+ mEquippedWeapon = 0;
}
else
{
std::string filename = itemDb->get(id).getSprite(mGender);
- AnimatedSprite *equipmentSprite = NULL;
+ AnimatedSprite *equipmentSprite = 0;
if (!filename.empty())
{
diff --git a/src/being.h b/src/being.h
index 9ac014e0..76e2edae 100644
--- a/src/being.h
+++ b/src/being.h
@@ -261,7 +261,8 @@ class Being : public ActorSprite, public EventListener
* Sets visible equipments for this being.
*/
void setSprite(unsigned int slot, int id,
- const std::string &color = "", bool isWeapon = false);
+ const std::string &color = std::string(),
+ bool isWeapon = false);
void setSpriteID(unsigned int slot, int id);
diff --git a/src/client.cpp b/src/client.cpp
index f2d3222f..5736cec4 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -214,7 +214,7 @@ Client::Client(const Options &options):
initConfiguration();
chatLogger = new ChatLogger;
- if (options.chatLogDir == "")
+ if (options.chatLogDir.empty())
chatLogger->setLogDir(mLocalDataDir + std::string("/logs/"));
else
chatLogger->setLogDir(options.chatLogDir);
@@ -1020,8 +1020,8 @@ int Client::exec()
}
void Client::showOkDialog(const std::string &title,
- const std::string &message,
- State state)
+ const std::string &message,
+ State state)
{
OkDialog *okDialog = new OkDialog(title, message);
okDialog->addActionListener(this);
diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp
index e96137c4..d77005c7 100644
--- a/src/compoundsprite.cpp
+++ b/src/compoundsprite.cpp
@@ -184,7 +184,7 @@ void CompoundSprite::addSprite(Sprite* sprite)
mNeedsRedraw = true;
}
-void CompoundSprite::setSprite(int layer, Sprite* sprite)
+void CompoundSprite::setSprite(int layer, Sprite *sprite)
{
// Skip if it won't change anything
if (at(layer) == sprite)
@@ -199,7 +199,7 @@ void CompoundSprite::setSprite(int layer, Sprite* sprite)
void CompoundSprite::removeSprite(int layer)
{
// Skip if it won't change anything
- if (at(layer) == NULL)
+ if (!at(layer))
return;
delete at(layer);
@@ -223,7 +223,7 @@ void CompoundSprite::ensureSize(size_t layerCount)
if (size() >= layerCount)
return;
- resize(layerCount, NULL);
+ resize(layerCount);
}
/**
@@ -234,8 +234,7 @@ size_t CompoundSprite::getCurrentFrame(size_t layer)
if (layer >= size())
return 0;
- Sprite *s = getSprite(layer);
- if (s)
+ if (Sprite *s = getSprite(layer))
return s->getCurrentFrame();
return 0;
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 339cf717..c17b5e04 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -50,21 +50,6 @@
static const int BOX_WIDTH = 36;
static const int BOX_HEIGHT = 36;
-// Positions of the boxes, 2nd dimension is X and Y respectively.
-static const int boxPosition[][2] = {
- { 90, 40 }, // EQUIP_TORSO_SLOT
- { 8, 78 }, // EQUIP_GLOVES_SLOT
- { 70, 0 }, // EQUIP_HEAD_SLOT
- { 50, 208 }, // EQUIP_LEGS_SLOT
- { 90, 208 }, // EQUIP_FEET_SLOT
- { 8, 168 }, // EQUIP_RING1_SLOT
- { 129, 168 }, // EQUIP_RING2_SLOT
- { 50, 40 }, // EQUIP_NECK_SLOT
- { 8, 123 }, // EQUIP_FIGHT1_SLOT
- { 129, 123 }, // EQUIP_FIGHT2_SLOT
- { 129, 78 } // EQUIP_PROJECTILE_SLOT
-};
-
EquipmentWindow::EquipmentWindow(Equipment *equipment):
Window(_("Equipment")),
mEquipBox(0),
@@ -210,6 +195,21 @@ namespace TmwAthena {
TaEquipmentWindow::TaEquipmentWindow(Equipment *equipment):
EquipmentWindow(equipment)
{
+ // Positions of the boxes, 2nd dimension is X and Y respectively.
+ const int boxPosition[][2] = {
+ { 90, 40 }, // EQUIP_TORSO_SLOT
+ { 8, 78 }, // EQUIP_GLOVES_SLOT
+ { 70, 0 }, // EQUIP_HEAD_SLOT
+ { 50, 208 }, // EQUIP_LEGS_SLOT
+ { 90, 208 }, // EQUIP_FEET_SLOT
+ { 8, 168 }, // EQUIP_RING1_SLOT
+ { 129, 168 }, // EQUIP_RING2_SLOT
+ { 50, 40 }, // EQUIP_NECK_SLOT
+ { 8, 123 }, // EQUIP_FIGHT1_SLOT
+ { 129, 123 }, // EQUIP_FIGHT2_SLOT
+ { 129, 78 } // EQUIP_PROJECTILE_SLOT
+ };
+
// Load equipment boxes.
mEquipBox = new EquipBox[TmwAthena::EQUIP_VECTOR_END];
@@ -271,4 +271,4 @@ void TaEquipmentWindow::draw(gcn::Graphics *graphics)
}
}
-};
+} // namespace TmwAthena
diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp
index 0fdf59b1..f3a8b807 100644
--- a/src/gui/ministatus.cpp
+++ b/src/gui/ministatus.cpp
@@ -92,11 +92,9 @@ MiniStatusWindow::MiniStatusWindow():
void MiniStatusWindow::setIcon(int index, AnimatedSprite *sprite)
{
if (index >= (int) mIcons.size())
- mIcons.resize(index + 1, NULL);
-
- if (mIcons[index])
- delete mIcons[index];
+ mIcons.resize(index + 1);
+ delete mIcons[index];
mIcons[index] = sprite;
}
diff --git a/src/gui/okdialog.h b/src/gui/okdialog.h
index 68841566..c5c29536 100644
--- a/src/gui/okdialog.h
+++ b/src/gui/okdialog.h
@@ -48,4 +48,4 @@ class OkDialog : public Window, public gcn::ActionListener
TextBox *mTextBox;
};
-#endif
+#endif // OK_DIALOG_H
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp
index 570983ca..239f4784 100644
--- a/src/gui/widgets/listbox.cpp
+++ b/src/gui/widgets/listbox.cpp
@@ -118,8 +118,6 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent)
}
}
-// Don't do anything on scrollwheel. ScrollArea will deal with that.
-
void ListBox::mousePressed(gcn::MouseEvent &mouseEvent)
{
if (mouseEvent.getButton() != gcn::MouseEvent::LEFT)
@@ -134,10 +132,12 @@ void ListBox::mousePressed(gcn::MouseEvent &mouseEvent)
void ListBox::mouseWheelMovedUp(gcn::MouseEvent &mouseEvent)
{
+ // Don't do anything on scrollwheel. ScrollArea will deal with that.
}
void ListBox::mouseWheelMovedDown(gcn::MouseEvent &mouseEvent)
{
+ // Don't do anything on scrollwheel. ScrollArea will deal with that.
}
void ListBox::mouseDragged(gcn::MouseEvent &event)
diff --git a/src/gui/widgets/tablemodel.cpp b/src/gui/widgets/tablemodel.cpp
index b4bbb409..477b35c0 100644
--- a/src/gui/widgets/tablemodel.cpp
+++ b/src/gui/widgets/tablemodel.cpp
@@ -56,7 +56,7 @@ StaticTableModel::StaticTableModel(int row, int column) :
mColumns(column),
mHeight(1)
{
- mTableModel.resize(row * column, NULL);
+ mTableModel.resize(row * column);
mWidths.resize(column, 1);
}
@@ -69,7 +69,7 @@ void StaticTableModel::resize()
{
mRows = getRows();
mColumns = getColumns();
- mTableModel.resize(mRows * mColumns, NULL);
+ mTableModel.resize(mRows * mColumns);
}
void StaticTableModel::set(int row, int column, gcn::Widget *widget)
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 25c1ebf7..683251ed 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -119,11 +119,10 @@ void Inventory::removeItemAt(int index)
{
delete mItems[index];
mItems[index] = 0;
- mUsed--;
- if (mUsed < 0) // Already at 0, no need to distribute event
- mUsed = 0;
- else
+ if (mUsed > 0) {
+ mUsed--;
distributeSlotsChangedEvent();
+ }
}
bool Inventory::contains(Item *item) const
diff --git a/src/inventory.h b/src/inventory.h
index d76d6afd..f7dc1ea2 100644
--- a/src/inventory.h
+++ b/src/inventory.h
@@ -146,4 +146,4 @@ class Inventory
int mUsed; /**< THe number of slots in use */
};
-#endif
+#endif // INVENTORY_H
diff --git a/src/net/manaserv/manaserv_protocol.h b/src/net/manaserv/manaserv_protocol.h
index ca9a0f02..180e9810 100644
--- a/src/net/manaserv/manaserv_protocol.h
+++ b/src/net/manaserv/manaserv_protocol.h
@@ -438,6 +438,6 @@ enum SpriteLayer
SPRITE_VECTOREND
};
-}; // Namespace ManaServ
+} // namespace ManaServ
#endif // MANASERV_PROTOCOL_H
diff --git a/src/net/messagein.h b/src/net/messagein.h
index 29f5e930..726c3bab 100644
--- a/src/net/messagein.h
+++ b/src/net/messagein.h
@@ -103,6 +103,6 @@ class MessageIn
unsigned int mPos;
};
-}
+} // namespace Net
#endif // NET_MESSAGEIN_H
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp
index b7cf7bd9..7adb6ed7 100644
--- a/src/net/tmwa/beinghandler.cpp
+++ b/src/net/tmwa/beinghandler.cpp
@@ -78,7 +78,7 @@ BeingHandler::BeingHandler(bool enableSync):
handledMessages = _messages;
}
-Being *createBeing(int id, short job)
+static Being *createBeing(int id, short job)
{
ActorSprite::Type type = ActorSprite::UNKNOWN;
if (job <= 25 || (job >= 4001 && job <= 4049))
diff --git a/src/net/tmwa/generalhandler.h b/src/net/tmwa/generalhandler.h
index a4725b89..3698c6d3 100644
--- a/src/net/tmwa/generalhandler.h
+++ b/src/net/tmwa/generalhandler.h
@@ -73,4 +73,4 @@ class GeneralHandler : public MessageHandler, public Net::GeneralHandler,
} // namespace TmwAthena
-#endif // NET_TA_GENERALHANDLER_H
+#endif // NET_TMWA_GENERALHANDLER_H
diff --git a/src/net/tmwa/inventoryhandler.cpp b/src/net/tmwa/inventoryhandler.cpp
index edb5e53f..48f40e11 100644
--- a/src/net/tmwa/inventoryhandler.cpp
+++ b/src/net/tmwa/inventoryhandler.cpp
@@ -49,7 +49,7 @@ extern Net::InventoryHandler *inventoryHandler;
namespace TmwAthena {
-const EquipmentSlot EQUIP_POINTS[EQUIP_VECTOR_END] = {
+static const EquipmentSlot EQUIP_POINTS[EQUIP_VECTOR_END] = {
EQUIP_LEGS_SLOT,
EQUIP_FIGHT1_SLOT,
EQUIP_ARMS_SLOT,
@@ -60,9 +60,10 @@ const EquipmentSlot EQUIP_POINTS[EQUIP_VECTOR_END] = {
EQUIP_NECKLACE_SLOT,
EQUIP_HEAD_SLOT,
EQUIP_TORSO_SLOT,
- EQUIP_PROJECTILE_SLOT};
+ EQUIP_PROJECTILE_SLOT
+};
-int getSlot(int eAthenaSlot)
+static int getSlot(int eAthenaSlot)
{
if (eAthenaSlot == 0)
{
diff --git a/src/net/tmwa/inventoryhandler.h b/src/net/tmwa/inventoryhandler.h
index 315be16c..218723e6 100644
--- a/src/net/tmwa/inventoryhandler.h
+++ b/src/net/tmwa/inventoryhandler.h
@@ -49,10 +49,6 @@ class EquipBackend : public Equipment::Backend
Item *getEquipment(int index) const
{
int invyIndex = mEquipment[index];
- if (invyIndex == -1)
- {
- return NULL;
- }
return PlayerInfo::getInventory()->getItem(invyIndex);
}
@@ -62,11 +58,8 @@ class EquipBackend : public Equipment::Backend
{
if (mEquipment[i] != -1)
{
- Item* item = PlayerInfo::getInventory()->getItem(i);
- if (item)
- {
+ if (Item *item = PlayerInfo::getInventory()->getItem(i))
item->setEquipped(false);
- }
}
mEquipment[i] = -1;
@@ -75,20 +68,16 @@ class EquipBackend : public Equipment::Backend
void setEquipment(int index, int inventoryIndex)
{
+ Inventory *inventory = PlayerInfo::getInventory();
+
// Unequip existing item
- Item* item = PlayerInfo::getInventory()->getItem(mEquipment[index]);
- if (item)
- {
+ if (Item *item = inventory->getItem(mEquipment[index]))
item->setEquipped(false);
- }
mEquipment[index] = inventoryIndex;
- item = PlayerInfo::getInventory()->getItem(inventoryIndex);
- if (item)
- {
+ if (Item *item = inventory->getItem(inventoryIndex))
item->setEquipped(true);
- }
inventoryWindow->updateButtons();
}
diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp
index 6900539d..d38f2b2a 100644
--- a/src/particlecontainer.cpp
+++ b/src/particlecontainer.cpp
@@ -128,7 +128,7 @@ void ParticleVector::setLocally(int index, Particle *particle)
delLocally(index);
if (mIndexedElements.size() <= (unsigned) index)
- mIndexedElements.resize(index + 1, NULL);
+ mIndexedElements.resize(index + 1);
if (particle)
particle->disableAutoDelete();
diff --git a/src/playerinfo.cpp b/src/playerinfo.cpp
index feb39413..6fd4a71a 100644
--- a/src/playerinfo.cpp
+++ b/src/playerinfo.cpp
@@ -33,25 +33,23 @@ namespace PlayerInfo {
class PlayerLogic;
-PlayerLogic *mListener = 0;
+static PlayerLogic *mListener = 0;
-PlayerInfoBackend mData;
+static PlayerInfoBackend mData;
-Inventory *mInventory = 0;
-Equipment *mEquipment = 0;
+static Inventory *mInventory = 0;
+static Equipment *mEquipment = 0;
-bool mStorageCount = 0;
+static bool mStorageCount = 0;
-bool mNPCCount = 0;
-bool mNPCPostCount = 0;
+static bool mNPCCount = 0;
+static bool mNPCPostCount = 0;
-BuySellState mBuySellState = BUYSELL_NONE;
-bool mTrading = false;
+static BuySellState mBuySellState = BUYSELL_NONE;
+static bool mTrading = false;
-std::map<int, Special> mSpecials;
-char mSpecialRechargeUpdateNeeded = 0;
-
-int mLevelProgress = 0;
+static std::map<int, Special> mSpecials;
+static char mSpecialRechargeUpdateNeeded = 0;
// --- Triggers ---------------------------------------------------------------
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 1457b6dd..e913bb0a 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -551,4 +551,4 @@ void ManaServItemDB::checkItemInfo(ItemInfo* itemInfo)
// Add specific Manaserv checks here
}
-}; // namespace ManaServ
+} // namespace ManaServ
diff --git a/src/resources/itemdb.h b/src/resources/itemdb.h
index e80f2cd0..aa6e62c0 100644
--- a/src/resources/itemdb.h
+++ b/src/resources/itemdb.h
@@ -33,9 +33,13 @@
class ItemInfo;
class SpriteDisplay;
-// Used to make the compiler uderstand the iteminfo friendship.
-namespace TmwAthena { class TaItemDB; };
-namespace ManaServ { class ManaServItemDB; };
+namespace TmwAthena {
+class TaItemDB;
+}
+
+namespace ManaServ {
+class ManaServItemDB;
+}
/**
* Nano-description functions
@@ -48,10 +52,10 @@ class ItemStat
public:
ItemStat(const std::string &tag,
- const std::string &format):
+ const std::string &format):
mTag(tag), mFormat(format) {}
- bool operator ==(std::string &name) const
+ bool operator ==(const std::string &name) const
{ return mTag == name; }
private:
@@ -176,7 +180,7 @@ class TaItemDB: public ItemDB
void checkItemInfo(ItemInfo* itemInfo);
};
-}; // namespace TmwAthena
+} // namespace TmwAthena
namespace ManaServ {
@@ -203,7 +207,7 @@ class ManaServItemDB: public ItemDB
void checkItemInfo(ItemInfo* itemInfo);
};
-}; // namespace ManaServ
+} // namespace ManaServ
extern ItemDB *itemDb;
diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h
index 4ab66597..24872060 100644
--- a/src/resources/iteminfo.h
+++ b/src/resources/iteminfo.h
@@ -60,9 +60,13 @@ enum ItemType
ITEM_SPRITE_HAIR // 15
};
-// Used to make the compiler uderstand the iteminfo friendship.
-namespace TmwAthena { class TaItemDB; };
-namespace ManaServ { class ManaServItemDB; };
+namespace TmwAthena {
+class TaItemDB;
+}
+
+namespace ManaServ {
+class ManaServItemDB;
+}
/**
* Defines a class for storing generic item infos.
@@ -256,4 +260,4 @@ class ManaServItemInfo: public ItemInfo
} // namespace ManaServ
-#endif
+#endif // ITEMINFO_H
diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp
index 349e2948..f60009ab 100644
--- a/src/resources/resource.cpp
+++ b/src/resources/resource.cpp
@@ -33,7 +33,7 @@ Resource::~Resource()
void Resource::incRef()
{
- mRefCount++;
+ ++mRefCount;
}
void Resource::decRef()
@@ -44,7 +44,7 @@ void Resource::decRef()
assert(false);
}
- mRefCount--;
+ --mRefCount;
if (mRefCount == 0)
{
diff --git a/src/tileset.h b/src/tileset.h
index 387222b3..cab784e2 100644
--- a/src/tileset.h
+++ b/src/tileset.h
@@ -48,4 +48,4 @@ class Tileset : public ImageSet
int mFirstGid;
};
-#endif
+#endif // TILESET_H