diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-08-24 22:48:35 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-08-24 22:48:35 +0300 |
commit | b474de4a54c9b1d4d863971e40b807588d554436 (patch) | |
tree | 761e71f86ea232d1688ee2838bd2294c59dea947 | |
parent | a316d537dce50f4b4e1e10f5c26a7851baddbd8b (diff) | |
download | manaverse-b474de4a54c9b1d4d863971e40b807588d554436.tar.gz manaverse-b474de4a54c9b1d4d863971e40b807588d554436.tar.bz2 manaverse-b474de4a54c9b1d4d863971e40b807588d554436.tar.xz manaverse-b474de4a54c9b1d4d863971e40b807588d554436.zip |
replace defines to consts.
42 files changed, 149 insertions, 138 deletions
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index f3762fa69..7a635f852 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -225,7 +225,7 @@ impHandler(shortcut) if (itemShortcutWindow) { int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < SHORTCUT_TABS) + if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS)) { itemShortcut[num]->useItem(event.action - Input::KEY_SHORTCUT_1); diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 4debab9e8..5e53febcd 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -42,7 +42,7 @@ #include "debug.h" -#define EFFECTS_FILE "effects.xml" +static const char *const EFFECTS_FILE = "effects.xml"; ImageSet *ActorSprite::targetCursorImages[2][NUM_TC]; SimpleAnimation *ActorSprite::targetCursor[2][NUM_TC]; @@ -188,8 +188,7 @@ static EffectDescription *getEffectDescription(int effectId) if (!root || !xmlNameEqual(root, "being-effects")) { - logger->log1("Error loading being effects file: " - EFFECTS_FILE); + logger->log1("Error loading being effects file"); return nullptr; } @@ -238,7 +237,7 @@ void ActorSprite::setStatusEffect(int index, bool active) void ActorSprite::setStatusEffectBlock(int offset, uint16_t newEffects) { - for (int i = 0; i < STATUS_EFFECTS; i++) + for (unsigned i = 0; i < STATUS_EFFECTS; i++) { int index = StatusEffect::blockEffectIndexToEffectIndex(offset + i); diff --git a/src/being.cpp b/src/being.cpp index 8ec6f7927..6316c26c3 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -67,7 +67,7 @@ #include "debug.h" -#define CACHE_SIZE 50 +const unsigned int CACHE_SIZE = 50; class BeingCacheEntry { @@ -451,8 +451,8 @@ void Being::setSpeech(const std::string &text, int time) if (!time && mSpeech.size() < 200) time = static_cast<int>(SPEECH_TIME - 300 + (3 * mSpeech.size())); - if (time < SPEECH_MIN_TIME) - time = SPEECH_MIN_TIME; + if (time < static_cast<int>(SPEECH_MIN_TIME)) + time = static_cast<int>(SPEECH_MIN_TIME); // Check for links size_t start = mSpeech.find('['); @@ -486,7 +486,10 @@ void Being::setSpeech(const std::string &text, int time) } if (!mSpeech.empty()) - mSpeechTime = time <= SPEECH_MAX_TIME ? time : SPEECH_MAX_TIME; + { + mSpeechTime = time <= static_cast<int>(SPEECH_MAX_TIME) + ? time : static_cast<int>(SPEECH_MAX_TIME); + } const int speech = mSpeechType; if (speech == TEXT_OVERHEAD && userPalette) diff --git a/src/being.h b/src/being.h index ded3f9962..66e6618e2 100644 --- a/src/being.h +++ b/src/being.h @@ -34,12 +34,12 @@ #include <map> #include <set> -#define FIRST_IGNORE_EMOTE 14 -#define STATUS_EFFECTS 32 +static const unsigned int FIRST_IGNORE_EMOTE = 14; +static const unsigned int STATUS_EFFECTS = 32; -#define SPEECH_TIME 500 -#define SPEECH_MIN_TIME 200 -#define SPEECH_MAX_TIME 800 +static const unsigned int SPEECH_TIME = 500; +static const unsigned int SPEECH_MIN_TIME = 200; +static const unsigned int SPEECH_MAX_TIME = 800; static const int DEFAULT_BEING_WIDTH = 32; static const int DEFAULT_BEING_HEIGHT = 32; diff --git a/src/client.cpp b/src/client.cpp index 8a8fcd06c..3deb72488 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -549,7 +549,7 @@ void Client::gameInit() // Theme::prepareThemePath(); // Initialize the item and emote shortcuts. - for (int f = 0; f < SHORTCUT_TABS; f ++) + for (unsigned f = 0; f < SHORTCUT_TABS; f ++) itemShortcut[f] = new ItemShortcut(f); emoteShortcut = new EmoteShortcut; @@ -705,7 +705,7 @@ void Client::gameClear() PlayerInfo::deinit(); // Before config.write() since it writes the shortcuts to the config - for (int f = 0; f < SHORTCUT_TABS; f ++) + for (unsigned f = 0; f < SHORTCUT_TABS; f ++) { delete itemShortcut[f]; itemShortcut[f] = nullptr; @@ -1753,7 +1753,7 @@ void Client::initServerConfig(std::string serverName) player_relations.init(); // Initialize the item and emote shortcuts. - for (int f = 0; f < SHORTCUT_TABS; f ++) + for (unsigned f = 0; f < SHORTCUT_TABS; f ++) { delete itemShortcut[f]; itemShortcut[f] = new ItemShortcut(f); diff --git a/src/compoundsprite.cpp b/src/compoundsprite.cpp index 53caedc47..1ac054bbb 100644 --- a/src/compoundsprite.cpp +++ b/src/compoundsprite.cpp @@ -41,8 +41,8 @@ #include "debug.h" -#define BUFFER_WIDTH 100 -#define BUFFER_HEIGHT 100 +static const int BUFFER_WIDTH = 100; +static const int BUFFER_HEIGHT = 100; static const unsigned cache_max_size = 10; static const unsigned cache_clean_part = 3; @@ -175,13 +175,13 @@ int CompoundSprite::getWidth() const for (SpriteConstIterator it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { - if (base = *it) - break; + if ((base = *it)) + { + if (base) + return base->getWidth(); + } } - if (base) - return base->getWidth(); - return 0; } @@ -192,13 +192,13 @@ int CompoundSprite::getHeight() const for (SpriteConstIterator it = mSprites.begin(), it_end = mSprites.end(); it != it_end; ++ it) { - if (base = *it) - break; + if ((base = *it)) + { + if (base) + return base->getHeight(); + } } - if (base) - return base->getHeight(); - return 0; } diff --git a/src/dropshortcut.h b/src/dropshortcut.h index b9a8db7c7..0e56a9728 100644 --- a/src/dropshortcut.h +++ b/src/dropshortcut.h @@ -23,7 +23,7 @@ #ifndef DROPSHORTCUT_H #define DROPSHORTCUT_H -#define DROP_SHORTCUT_ITEMS 16 +static const int DROP_SHORTCUT_ITEMS = 16; class Item; diff --git a/src/emoteshortcut.h b/src/emoteshortcut.h index c47569738..f43585a0e 100644 --- a/src/emoteshortcut.h +++ b/src/emoteshortcut.h @@ -22,7 +22,7 @@ #ifndef EMOTESHORTCUT_H #define EMOTESHORTCUT_H -#define SHORTCUT_EMOTES 48 +static const int SHORTCUT_EMOTES = 48; /** * The class which keeps track of the emote shortcuts. diff --git a/src/equipment.h b/src/equipment.h index ed38d32ca..48d538081 100644 --- a/src/equipment.h +++ b/src/equipment.h @@ -23,7 +23,7 @@ #ifndef EQUIPMENT_H #define EQUIPMENT_H -#define EQUIPMENT_SIZE 13 +static const int EQUIPMENT_SIZE = 13; #include "localconsts.h" diff --git a/src/game.cpp b/src/game.cpp index 8a8cdce5a..f00123af3 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -215,7 +215,7 @@ static void createGuiWindows() itemShortcutWindow = new ShortcutWindow( "ItemShortcut", "items.xml", 83, 460); - for (int f = 0; f < SHORTCUT_TABS; f ++) + for (unsigned f = 0; f < SHORTCUT_TABS; f ++) { itemShortcutWindow->addTab(toString(f + 1), new ItemShortcutContainer(f)); @@ -238,7 +238,7 @@ static void createGuiWindows() spellShortcutWindow = new ShortcutWindow("SpellShortcut", "spells.xml", 265, 328); - for (int f = 0; f < SPELL_SHORTCUT_TABS; f ++) + for (unsigned f = 0; f < SPELL_SHORTCUT_TABS; f ++) { spellShortcutWindow->addTab(toString(f + 1), new SpellShortcutContainer(f)); diff --git a/src/game.h b/src/game.h index 17e67b243..6fc42be42 100644 --- a/src/game.h +++ b/src/game.h @@ -29,7 +29,7 @@ #include <SDL/SDL.h> -#define MAX_LASTKEYS 10 +static const int MAX_LASTKEYS = 10; extern volatile int cur_time; //extern std::string map_path; // TODO: Get rid of this global diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index b0318a9aa..c69e7b8a2 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -150,8 +150,7 @@ public: } }; -#define ACTION_COLOR_PICKER "color picker" - +static const char *ACTION_COLOR_PICKER = "color picker"; ChatWindow::ChatWindow(): Window(_("Chat"), false, nullptr, "chat.xml"), diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index ddc9574f2..0638d4e7a 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -56,7 +56,7 @@ namespace gcn class DropDown; } -#define DEFAULT_CHAT_WINDOW_SCROLL 7 // 1 means `1/8th of the window size'. +const int DEFAULT_CHAT_WINDOW_SCROLL = 7; enum Own { diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 7ce62aa4e..93257c6c3 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -133,7 +133,7 @@ void OutfitWindow::load(bool oldConfig) memset(mItems, -1, sizeof(mItems)); memset(mItemColors, 1, sizeof(mItemColors)); - for (int o = 0; o < OUTFITS_COUNT; o++) + for (unsigned o = 0; o < OUTFITS_COUNT; o++) { std::string outfit = cfg->getValue("Outfit" + toString(o), "-1"); std::string buf; @@ -169,8 +169,8 @@ void OutfitWindow::load(bool oldConfig) true); } mAwayOutfit = cfg->getValue("OutfitAwayIndex", OUTFITS_COUNT - 1); - if (mAwayOutfit >= OUTFITS_COUNT) - mAwayOutfit = OUTFITS_COUNT - 1; + if (mAwayOutfit >= static_cast<int>(OUTFITS_COUNT)) + mAwayOutfit = static_cast<int>(OUTFITS_COUNT) - 1; if (mAwayOutfitCheck) mAwayOutfitCheck->setSelected(mAwayOutfit == mCurrentOutfit); @@ -180,10 +180,10 @@ void OutfitWindow::save() { std::string outfitStr; std::string outfitColorsStr; - for (int o = 0; o < OUTFITS_COUNT; o++) + for (unsigned o = 0; o < OUTFITS_COUNT; o++) { bool good = false; - for (int i = 0; i < OUTFIT_ITEM_COUNT; i++) + for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++) { int res = mItems[o][i] ? mItems[o][i] : -1; if (res != -1) @@ -235,7 +235,7 @@ void OutfitWindow::action(const gcn::ActionEvent &event) } else if (eventId == "unequip") { - if (mCurrentOutfit < OUTFITS_COUNT) + if (mCurrentOutfit < static_cast<int>(OUTFITS_COUNT)) mItemsUnequip[mCurrentOutfit] = mUnequipCheck->isSelected(); } else if (eventId == "equip") @@ -257,10 +257,10 @@ void OutfitWindow::wearOutfit(int outfit, bool unwearEmpty, bool select) bool isEmpty = true; Item *item; - if (outfit < 0 || outfit > OUTFITS_COUNT) + if (outfit < 0 || outfit > static_cast<int>(OUTFITS_COUNT)) return; - for (int i = 0; i < OUTFIT_ITEM_COUNT; i++) + for (unsigned i = 0; i < OUTFIT_ITEM_COUNT; i++) { item = PlayerInfo::getInventory()->findItem( mItems[outfit][i], mItemColors[outfit][i]); @@ -274,7 +274,7 @@ void OutfitWindow::wearOutfit(int outfit, bool unwearEmpty, bool select) } } - if ((!isEmpty || unwearEmpty) && outfit < OUTFITS_COUNT + if ((!isEmpty || unwearEmpty) && outfit < static_cast<int>(OUTFITS_COUNT) && mItemsUnequip[outfit]) { unequipNotInOutfit(outfit); @@ -293,13 +293,13 @@ void OutfitWindow::copyOutfit(int outfit) void OutfitWindow::copyOutfit(int src, int dst) { - if (src < 0 || src > OUTFITS_COUNT - || dst < 0 || dst > OUTFITS_COUNT) + if (src < 0 || src > static_cast<int>(OUTFITS_COUNT) + || dst < 0 || dst > static_cast<int>(OUTFITS_COUNT)) { return; } - for (int i = 0; i < OUTFIT_ITEM_COUNT; i++) + for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++) mItems[dst][i] = mItems[src][i]; } @@ -308,7 +308,7 @@ void OutfitWindow::draw(gcn::Graphics *graphics) Window::draw(graphics); Graphics *g = static_cast<Graphics*>(graphics); - for (int i = 0; i < OUTFIT_ITEM_COUNT; i++) + for (unsigned int i = 0; i < OUTFIT_ITEM_COUNT; i++) { const int itemX = 10 + ((i % mGridWidth) * mBoxWidth); const int itemY = 25 + ((i / mGridWidth) * mBoxHeight); @@ -476,7 +476,7 @@ int OutfitWindow::getIndexFromGrid(int pointX, int pointY) const return -1; const int index = (((pointY - 25) / mBoxHeight) * mGridWidth) + (pointX - 10) / mBoxWidth; - if (index >= OUTFIT_ITEM_COUNT || index < 0) + if (index >= static_cast<int>(OUTFIT_ITEM_COUNT) || index < 0) return -1; return index; } @@ -519,7 +519,7 @@ std::string OutfitWindow::keyName(int number) void OutfitWindow::next() { - if (mCurrentOutfit < (OUTFITS_COUNT - 1)) + if (mCurrentOutfit < (static_cast<int>(OUTFITS_COUNT) - 1)) mCurrentOutfit++; else mCurrentOutfit = 0; @@ -547,7 +547,7 @@ void OutfitWindow::showCurrentOutfit() void OutfitWindow::wearNextOutfit(bool all) { next(); - if (!all && mCurrentOutfit < OUTFITS_COUNT) + if (!all && mCurrentOutfit < static_cast<int>(OUTFITS_COUNT)) { bool fromStart = false; while (!mItemsUnequip[mCurrentOutfit]) @@ -568,7 +568,7 @@ void OutfitWindow::wearNextOutfit(bool all) void OutfitWindow::wearPreviousOutfit(bool all) { previous(); - if (!all && mCurrentOutfit < OUTFITS_COUNT) + if (!all && mCurrentOutfit < static_cast<int>(OUTFITS_COUNT)) { bool fromStart = false; while (!mItemsUnequip[mCurrentOutfit]) @@ -606,7 +606,7 @@ void OutfitWindow::copyFromEquiped(int dst) { mItems[dst][outfitCell] = item->getId(); mItemColors[dst][outfitCell++] = item->getColor(); - if (outfitCell >= OUTFIT_ITEM_COUNT) + if (outfitCell >= static_cast<int>(OUTFIT_ITEM_COUNT)) break; } } diff --git a/src/gui/outfitwindow.h b/src/gui/outfitwindow.h index 21b78addf..9aae112e3 100644 --- a/src/gui/outfitwindow.h +++ b/src/gui/outfitwindow.h @@ -34,8 +34,8 @@ #define A_PURE #endif -#define OUTFITS_COUNT 100 -#define OUTFIT_ITEM_COUNT 16 +const unsigned int OUTFITS_COUNT = 100; +const unsigned int OUTFIT_ITEM_COUNT = 16; class Button; class CheckBox; diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 45119fcec..dc24e0e35 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -334,7 +334,7 @@ int SDLFont::getHeight() const void SDLFont::doClean() { - for (int f = 0; f < CACHES_NUMBER; f ++) + for (unsigned int f = 0; f < CACHES_NUMBER; f ++) { std::list<SDLTextChunk> *cache = &mCache[f]; const size_t size = cache->size(); diff --git a/src/gui/sdlfont.h b/src/gui/sdlfont.h index c2cf1025f..a7bea343f 100644 --- a/src/gui/sdlfont.h +++ b/src/gui/sdlfont.h @@ -35,7 +35,7 @@ #include <list> #include <string> -#define CACHES_NUMBER 256 +const unsigned int CACHES_NUMBER = 256; class SDLTextChunk; diff --git a/src/gui/setup_relations.cpp b/src/gui/setup_relations.cpp index c0558f56f..635adebe2 100644 --- a/src/gui/setup_relations.cpp +++ b/src/gui/setup_relations.cpp @@ -40,16 +40,16 @@ #include "utils/dtor.h" #include "utils/gettext.h" -#define COLUMNS_NR 2 // name plus listbox -#define NAME_COLUMN 0 -#define RELATION_CHOICE_COLUMN 1 +static const int COLUMNS_NR = 2; // name plus listbox +static const int NAME_COLUMN = 0; +static const unsigned int RELATION_CHOICE_COLUMN = 1; -#define ROW_HEIGHT 12 +static const unsigned int ROW_HEIGHT = 12; // The following column widths really shouldn't be hardcoded // but should scale with the size of the widget... except // that, right now, the widget doesn't exactly scale either. -#define NAME_COLUMN_WIDTH 230 -#define RELATION_CHOICE_COLUMN_WIDTH 80 +static const unsigned int NAME_COLUMN_WIDTH = 230; +static const unsigned int RELATION_CHOICE_COLUMN_WIDTH = 80; #define WIDGET_AT(row, column) (((row) * COLUMNS_NR) + column) @@ -227,9 +227,9 @@ public: } }; -#define ACTION_DELETE "delete" -#define ACTION_TABLE "table" -#define ACTION_STRATEGY "strategy" +static const std::string ACTION_DELETE = "delete"; +static const std::string ACTION_TABLE = "table"; +static const std::string ACTION_STRATEGY = "strategy"; Setup_Relations::Setup_Relations(): mPlayerTableTitleModel(new StaticTableModel(1, COLUMNS_NR)), diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 723cdc5e1..6195b92fc 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -273,7 +273,8 @@ void SkillDialog::action(const gcn::ActionEvent &event) mUseButton->setEnabled(info->range > 0); int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < SHORTCUT_TABS && itemShortcut[num]) + if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS) + && itemShortcut[num]) { itemShortcut[num]->setItemSelected( info->id + SKILL_MIN_ID); diff --git a/src/gui/skilldialog.h b/src/gui/skilldialog.h index b0f837ccf..d5c332740 100644 --- a/src/gui/skilldialog.h +++ b/src/gui/skilldialog.h @@ -31,7 +31,7 @@ #include <map> #include <vector> -#define SKILL_MIN_ID 200000 +const int SKILL_MIN_ID = 200000; class Button; class Label; diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index b9c6b2530..d96ef7c85 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -50,8 +50,8 @@ #include "debug.h" -#define SPECIALS_WIDTH 200 -#define SPECIALS_HEIGHT 32 +static const unsigned int SPECIALS_WIDTH = 200; +static const unsigned int SPECIALS_HEIGHT = 32; class SpecialEntry : public Container { diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 102fc9546..0c1bab71a 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -48,7 +48,7 @@ #include "debug.h" -#define MAX_WORD_SIZE 50 +static const unsigned int MAX_WORD_SIZE = 50; ChatTab::ChatTab(const std::string &name) : Tab(), diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index bff17cfa2..ba359118f 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -364,7 +364,7 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) mSelectionStatus = SEL_SELECTING; int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < SHORTCUT_TABS) + if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS)) { if (itemShortcut[num]) itemShortcut[num]->setItemSelected(item); diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index a057eceb4..5236daec4 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -233,7 +233,8 @@ void SpellShortcutContainer::mouseReleased(gcn::MouseEvent &event) if (spell && !spell->isEmpty()) { int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < SHORTCUT_TABS && itemShortcut[num]) + if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS) + && itemShortcut[num]) { itemShortcut[num]->setItemSelected( spell->getId() + SPELL_MIN_ID); @@ -244,8 +245,11 @@ void SpellShortcutContainer::mouseReleased(gcn::MouseEvent &event) else { int num = itemShortcutWindow->getTabIndex(); - if (num >= 0 && num < SHORTCUT_TABS && itemShortcut[num]) + if (num >= 0 && num < static_cast<int>(SHORTCUT_TABS) + && itemShortcut[num]) + { itemShortcut[num]->setItemSelected(-1); + } spellShortcut->setItemSelected(-1); } } diff --git a/src/guild.cpp b/src/guild.cpp index 1e577b2b5..11817c48d 100644 --- a/src/guild.cpp +++ b/src/guild.cpp @@ -95,7 +95,7 @@ GuildMember *Guild::addMember(int accountId, int charId, const std::string &name) { GuildMember *m; - if (m = getMember(accountId, charId)) + if ((m = getMember(accountId, charId))) return m; m = new GuildMember(this, accountId, charId, name); @@ -108,7 +108,7 @@ GuildMember *Guild::addMember(int accountId, int charId, GuildMember *Guild::addMember(const std::string &name) { GuildMember *m; - if (m = getMember(name)) + if ((m = getMember(name))) return m; m = new GuildMember(this, name); diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp index cc6492817..c22e9192f 100644 --- a/src/inputmanager.cpp +++ b/src/inputmanager.cpp @@ -72,9 +72,9 @@ InputManager::InputManager() : void InputManager::init() { - for (int i = 0; i < Input::KEY_TOTAL; i++) + for (unsigned int i = 0; i < Input::KEY_TOTAL; i++) { - for (int f = 0; f < KeyFunctionSize; f ++) + for (unsigned int f = 0; f < KeyFunctionSize; f ++) { mKey[i].values[f].type = INPUT_UNKNOWN; mKey[i].values[f].value = -1; @@ -108,7 +108,7 @@ void InputManager::retrieve() StringVect keys; splitToStringVector(keys, keyStr, ','); - int i2 = 0; + unsigned int i2 = 0; for (StringVectCIter it = keys.begin(), it_end = keys.end(); it != it_end && i2 < KeyFunctionSize; ++ it) { diff --git a/src/inputmanager.h b/src/inputmanager.h index 016670e5b..ce1724077 100644 --- a/src/inputmanager.h +++ b/src/inputmanager.h @@ -29,7 +29,7 @@ #include <SDL/SDL.h> -#define KeyFunctionSize 3 +const unsigned int KeyFunctionSize = 3; // hack to avoid conflicts with windows headers. #ifdef INPUT_KEYBOARD diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index 10fa20a50..3eb2bea42 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -71,7 +71,7 @@ void ItemShortcut::load(bool oldConfig) name = "shortcut"; color = "shortcutColor"; } - for (int i = 0; i < SHORTCUT_ITEMS; i++) + for (unsigned int i = 0; i < SHORTCUT_ITEMS; i++) { int itemId = cfg->getValue(name + toString(i), -1); unsigned char itemColor = static_cast<unsigned char>( @@ -99,7 +99,7 @@ void ItemShortcut::save() logger->log("save %s", name.c_str()); - for (int i = 0; i < SHORTCUT_ITEMS; i++) + for (unsigned int i = 0; i < SHORTCUT_ITEMS; i++) { const int itemId = mItems[i] ? mItems[i] : -1; const int itemColor = mItemColors[i] ? mItemColors[i] : 1; diff --git a/src/itemshortcut.h b/src/itemshortcut.h index 6367ba6e8..8711b9c03 100644 --- a/src/itemshortcut.h +++ b/src/itemshortcut.h @@ -23,9 +23,8 @@ #ifndef ITEMSHORTCUT_H #define ITEMSHORTCUT_H -#define SHORTCUT_ITEMS 20 - -#define SHORTCUT_TABS 3 +const unsigned int SHORTCUT_ITEMS = 20; +const unsigned int SHORTCUT_TABS = 3; class Item; diff --git a/src/main.h b/src/main.h index d3b588b63..ee52da018 100644 --- a/src/main.h +++ b/src/main.h @@ -53,7 +53,7 @@ #elif defined WIN32 #include "winver.h" #else -#define PACKAGE_VERSION SMALL_VERSION +#define PACKAGE_VERSION SMALL_VERSION; #endif #if defined __APPLE__ diff --git a/src/net/ea/specialhandler.cpp b/src/net/ea/specialhandler.cpp index 7db3f1b31..226531a11 100644 --- a/src/net/ea/specialhandler.cpp +++ b/src/net/ea/specialhandler.cpp @@ -37,33 +37,33 @@ #include "debug.h" /** job dependend identifiers (?) */ -#define SKILL_BASIC 0x0001 -#define SKILL_WARP 0x001b -#define SKILL_STEAL 0x0032 -#define SKILL_ENVENOM 0x0034 +static const unsigned int SKILL_BASIC = 0x0001; +static const unsigned int SKILL_WARP = 0x001b; +static const unsigned int SKILL_STEAL = 0x0032; +static const unsigned int SKILL_ENVENOM = 0x0034; /** basic skills identifiers */ -#define BSKILL_TRADE 0x0000 -#define BSKILL_EMOTE 0x0001 -#define BSKILL_SIT 0x0002 -#define BSKILL_CREATECHAT 0x0003 -#define BSKILL_JOINPARTY 0x0004 -#define BSKILL_SHOUT 0x0005 +static const unsigned int BSKILL_TRADE = 0x0000; +static const unsigned int BSKILL_EMOTE = 0x0001; +static const unsigned int BSKILL_SIT = 0x0002; +static const unsigned int BSKILL_CREATECHAT = 0x0003; +static const unsigned int BSKILL_JOINPARTY = 0x0004; +static const unsigned int BSKILL_SHOUT = 0x0005; /** reasons why action failed */ -#define RFAIL_SKILLDEP 0x00 -#define RFAIL_INSUFSP 0x01 -#define RFAIL_INSUFHP 0x02 -#define RFAIL_NOMEMO 0x03 -#define RFAIL_SKILLDELAY 0x04 -#define RFAIL_ZENY 0x05 -#define RFAIL_WEAPON 0x06 -#define RFAIL_REDGEM 0x07 -#define RFAIL_BLUEGEM 0x08 -#define RFAIL_OVERWEIGHT 0x09 +static const unsigned int RFAIL_SKILLDEP = 0x00; +static const unsigned int RFAIL_INSUFSP = 0x01; +static const unsigned int RFAIL_INSUFHP = 0x02; +static const unsigned int RFAIL_NOMEMO = 0x03; +static const unsigned int RFAIL_SKILLDELAY = 0x04; +static const unsigned int RFAIL_ZENY = 0x05; +static const unsigned int RFAIL_WEAPON = 0x06; +static const unsigned int RFAIL_REDGEM = 0x07; +static const unsigned int RFAIL_BLUEGEM = 0x08; +static const unsigned int RFAIL_OVERWEIGHT = 0x09; /** should always be zero if failed */ -#define SKILL_FAILED 0x00 +static const unsigned int SKILL_FAILED = 0x00; namespace Ea { @@ -129,14 +129,21 @@ void SpecialHandler::processSkillFailed(Net::MessageIn &msg) msg.readInt16(); // btype char success = msg.readInt8(); char reason = msg.readInt8(); - if (success != SKILL_FAILED && bskill == BSKILL_EMOTE) + if (success != static_cast<int>(SKILL_FAILED) + && bskill == static_cast<int>(BSKILL_EMOTE)) + { logger->log("Action: %d/%d", bskill, success); + } std::string txt; - if (success == SKILL_FAILED && skillId == SKILL_BASIC) + if (success == static_cast<int>(SKILL_FAILED) + && skillId == static_cast<int>(SKILL_BASIC)) { - if (player_node && bskill == BSKILL_EMOTE && reason == RFAIL_SKILLDEP) + if (player_node && bskill == static_cast<int>(BSKILL_EMOTE) + && reason == static_cast<int>(RFAIL_SKILLDEP)) + { player_node->stopAdvert(); + } switch (bskill) { diff --git a/src/particle.cpp b/src/particle.cpp index 408446caf..950411f7b 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -45,7 +45,7 @@ #include "debug.h" -#define SIN45 0.707106781f +static const float SIN45 = 0.707106781f; class Graphics; class Image; diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp index 4a6e39e18..9b84a3392 100644 --- a/src/particleemitter.cpp +++ b/src/particleemitter.cpp @@ -35,8 +35,8 @@ #include "debug.h" -#define SIN45 0.707106781f -#define DEG_RAD_FACTOR 0.017453293f +static const float SIN45 = 0.707106781f; +static const float DEG_RAD_FACTOR = 0.017453293f; ParticleEmitter::ParticleEmitter(XmlNodePtr emitterNode, Particle *target, Map *map, int rotation, diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp index e06f87955..e7f4aeb2f 100644 --- a/src/playerrelations.cpp +++ b/src/playerrelations.cpp @@ -34,14 +34,14 @@ #include "debug.h" -#define PLAYER_IGNORE_STRATEGY_NOP "nop" -#define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" -#define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 +static const char *PLAYER_IGNORE_STRATEGY_NOP = "nop"; +static const char *PLAYER_IGNORE_STRATEGY_EMOTE0 = "emote0"; +static const char *DEFAULT_IGNORE_STRATEGY = PLAYER_IGNORE_STRATEGY_EMOTE0; -#define NAME "name" // constant for xml serialisation -#define RELATION "relation" // constant for xml serialisation +static const char *NAME = "name"; // constant for xml serialisation +static const char *RELATION = "relation"; // constant for xml serialisation -#define IGNORE_EMOTE_TIME 100 +static const unsigned int IGNORE_EMOTE_TIME = 100; typedef std::map<std::string, PlayerRelation *> PlayerRelations; typedef PlayerRelations::const_iterator PlayerRelationsCIter; diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp index b82007ccf..af0cd765c 100644 --- a/src/resources/monsterdb.cpp +++ b/src/resources/monsterdb.cpp @@ -35,7 +35,7 @@ #include "debug.h" -#define OLD_TMWATHENA_OFFSET 1002 +static const unsigned int OLD_TMWATHENA_OFFSET = 1002; namespace { diff --git a/src/rotationalparticle.cpp b/src/rotationalparticle.cpp index 7c79932a3..8c024c4fa 100644 --- a/src/rotationalparticle.cpp +++ b/src/rotationalparticle.cpp @@ -27,7 +27,7 @@ #include "debug.h" -#define PI 3.14159265 +static const double PI = 3.14159265; RotationalParticle::RotationalParticle(Map *map, Animation *animation): ImageParticle(map, nullptr), diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp index ca84f28f7..fa567d256 100644 --- a/src/spellmanager.cpp +++ b/src/spellmanager.cpp @@ -90,7 +90,7 @@ void SpellManager::fillSpells() addSpell(new TextCommand(11, "hi", "hi", "", NOTARGET, "")); addSpell(new TextCommand(12, "hea", "heal", "", NOTARGET, "")); addSpell(new TextCommand(13, "@sp", "@spawn maggot 10", "", NOTARGET, "")); - for (int f = 12; f < SPELL_SHORTCUT_ITEMS * SPELL_SHORTCUT_TABS; f++) + for (unsigned f = 12; f < SPELL_SHORTCUT_ITEMS * SPELL_SHORTCUT_TABS; f++) addSpell(new TextCommand(f)); } @@ -254,7 +254,7 @@ void SpellManager::load(bool oldConfig) unsigned int mana; unsigned int commandType; - for (int i = 0; i < SPELL_SHORTCUT_ITEMS * SPELL_SHORTCUT_TABS; i++) + for (unsigned i = 0; i < SPELL_SHORTCUT_ITEMS * SPELL_SHORTCUT_TABS; i++) { std::string flags = cfg->getValue("commandShortcutFlags" + toString(i), ""); @@ -291,7 +291,7 @@ void SpellManager::load(bool oldConfig) void SpellManager::save() { - for (int i = 0; i < SPELL_SHORTCUT_ITEMS * SPELL_SHORTCUT_TABS; i++) + for (unsigned i = 0; i < SPELL_SHORTCUT_ITEMS * SPELL_SHORTCUT_TABS; i++) { TextCommand *spell = mSpellsVector[i]; if (spell) diff --git a/src/spellmanager.h b/src/spellmanager.h index 90f4d23c7..c3abd829a 100644 --- a/src/spellmanager.h +++ b/src/spellmanager.h @@ -29,9 +29,9 @@ #include "being.h" -#define SPELL_MIN_ID 100000 -#define SPELL_SHORTCUT_ITEMS 49 -#define SPELL_SHORTCUT_TABS 5 +const int SPELL_MIN_ID = 100000; +const unsigned int SPELL_SHORTCUT_ITEMS = 49; +const unsigned int SPELL_SHORTCUT_TABS = 5; class SpellManager { diff --git a/src/spellshortcut.cpp b/src/spellshortcut.cpp index 7d488299b..9e31d1295 100644 --- a/src/spellshortcut.cpp +++ b/src/spellshortcut.cpp @@ -48,14 +48,14 @@ SpellShortcut::~SpellShortcut() void SpellShortcut::load() { - for (int f = 0; f < SPELL_SHORTCUT_ITEMS * SPELL_SHORTCUT_TABS; f ++) + for (unsigned f = 0; f < SPELL_SHORTCUT_ITEMS * SPELL_SHORTCUT_TABS; f ++) mItems[f] = -1; if (!spellManager) return; std::vector<TextCommand*> spells = spellManager->getAll(); - int k = 0; + unsigned k = 0; for (std::vector<TextCommand*>::const_iterator i = spells.begin(), i_end = spells.end(); i != i_end diff --git a/src/statuseffect.cpp b/src/statuseffect.cpp index 810c65aca..0855d2c9b 100644 --- a/src/statuseffect.cpp +++ b/src/statuseffect.cpp @@ -33,7 +33,7 @@ #include "debug.h" -#define STATUS_EFFECTS_FILE "status-effects.xml" +static const char *STATUS_EFFECTS_FILE = "status-effects.xml"; static void unloadMap(std::map<int, StatusEffect *> &map); @@ -132,8 +132,7 @@ void StatusEffect::load() if (!rootNode || !xmlNameEqual(rootNode, "status-effects")) { - logger->log1("Error loading status effects file: " - STATUS_EFFECTS_FILE); + logger->log1("Error loading status effects file"); return; } diff --git a/src/textcommand.h b/src/textcommand.h index 959320b48..8a46d73ba 100644 --- a/src/textcommand.h +++ b/src/textcommand.h @@ -25,7 +25,7 @@ #include <string> -#define MAGIC_START_ID 340 +const unsigned int MAGIC_START_ID = 340; class Image; diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp index a56f6ec9a..efc3e285e 100644 --- a/src/utils/sha256.cpp +++ b/src/utils/sha256.cpp @@ -85,7 +85,7 @@ typedef unsigned int uint32_t; #include "debug.h" -#define SHA256_BLOCK_SIZE (512 / 8) +static const unsigned int SHA256_BLOCK_SIZE = (512 / 8); /** An sha 256 context, used by original m_opersha256 */ class SHA256Context @@ -97,7 +97,7 @@ class SHA256Context uint32_t h[8]; }; -#define SHA256_DIGEST_SIZE (256 / 8) +static const unsigned int SHA256_DIGEST_SIZE = (256 / 8); #define SHFR(x, n) (x >> n) #define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n))) |