summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/actorspritemanager.cpp10
-rw-r--r--src/animatedsprite.cpp5
-rw-r--r--src/being.cpp22
-rw-r--r--src/client.cpp6
-rw-r--r--src/commandhandler.cpp5
-rw-r--r--src/configuration.cpp11
-rw-r--r--src/dropshortcut.cpp2
-rw-r--r--src/game.cpp2
-rw-r--r--src/gui/charselectdialog.cpp13
-rw-r--r--src/gui/chat.cpp2
-rw-r--r--src/gui/gui.cpp5
-rw-r--r--src/gui/minimap.cpp2
-rw-r--r--src/gui/npcdialog.cpp2
-rw-r--r--src/gui/serverdialog.cpp4
-rw-r--r--src/gui/setup_video.cpp4
-rw-r--r--src/gui/specialswindow.cpp7
-rw-r--r--src/gui/truetypefont.cpp5
-rw-r--r--src/gui/widgets/browserbox.cpp5
-rw-r--r--src/gui/widgets/chattab.cpp3
-rw-r--r--src/gui/widgets/emoteshortcutcontainer.cpp4
-rw-r--r--src/gui/widgets/shopitems.cpp5
-rw-r--r--src/gui/widgets/shortcutcontainer.cpp2
-rw-r--r--src/gui/widgets/tabbedarea.cpp2
-rw-r--r--src/gui/widgets/window.cpp5
-rw-r--r--src/imageparticle.cpp14
-rw-r--r--src/inventory.cpp2
-rw-r--r--src/itemshortcut.cpp2
-rw-r--r--src/keyboardconfig.cpp6
-rw-r--r--src/localplayer.cpp51
-rw-r--r--src/log.cpp28
-rw-r--r--src/main.cpp2
-rw-r--r--src/map.cpp13
-rw-r--r--src/mumblemanager.cpp4
-rw-r--r--src/net/download.cpp3
-rw-r--r--src/net/messagein.cpp19
-rw-r--r--src/net/messageout.cpp2
-rw-r--r--src/net/tmwa/beinghandler.cpp13
-rw-r--r--src/net/tmwa/messagein.cpp2
-rw-r--r--src/net/tmwa/messageout.cpp10
-rw-r--r--src/net/tmwa/network.cpp8
-rw-r--r--src/net/tmwa/playerhandler.cpp5
-rw-r--r--src/opengl1graphics.cpp34
-rw-r--r--src/openglgraphics.cpp14
-rw-r--r--src/particle.cpp12
-rw-r--r--src/particlecontainer.cpp4
-rw-r--r--src/particleemitter.cpp19
-rw-r--r--src/particleemitterprop.h24
-rw-r--r--src/playerrelations.cpp4
-rw-r--r--src/resources/emotedb.cpp18
-rw-r--r--src/resources/image.cpp44
-rw-r--r--src/resources/imageset.cpp3
-rw-r--r--src/resources/imagewriter.cpp10
-rw-r--r--src/resources/itemdb.cpp18
-rw-r--r--src/resources/mapreader.cpp23
-rw-r--r--src/resources/monsterdb.cpp11
-rw-r--r--src/resources/npcdb.cpp8
-rw-r--r--src/resources/resourcemanager.cpp7
-rw-r--r--src/resources/wallpaper.cpp2
-rw-r--r--src/simpleanimation.cpp7
-rw-r--r--src/spellmanager.cpp13
-rw-r--r--src/textparticle.cpp5
-rw-r--r--src/textparticle.h2
-rw-r--r--src/units.cpp2
-rw-r--r--src/utils/base64.cpp6
-rw-r--r--src/utils/copynpaste.cpp2
-rw-r--r--src/utils/sha256.cpp8
-rw-r--r--src/utils/stringutils.cpp15
-rw-r--r--src/utils/xml.cpp11
68 files changed, 359 insertions, 284 deletions
diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp
index b50c92ff5..302b656d7 100644
--- a/src/actorspritemanager.cpp
+++ b/src/actorspritemanager.cpp
@@ -101,9 +101,11 @@ class SortBeingFunctor
if (Net::getNetworkType() == ServerInfo::MANASERV)
{
const Vector &pos1 = being1->getPosition();
- d1 = abs(((int) pos1.x) - x) + abs(((int) pos1.y) - y);
+ d1 = abs((static_cast<int>(pos1.x)) - x)
+ + abs((static_cast<int>(pos1.y)) - y);
const Vector &pos2 = being2->getPosition();
- d2 = abs(((int) pos2.x) - x) + abs(((int) pos2.y) - y);
+ d2 = abs((static_cast<int>(pos2.x)) - x)
+ + abs((static_cast<int>(pos2.y)) - y);
}
else
{
@@ -862,7 +864,7 @@ bool ActorSpriteManager::hasActorSprite(ActorSprite *actor) const
void ActorSpriteManager::addBlock(Uint32 id)
{
bool alreadyBlocked(false);
- for (int i = 0; i < (int)blockedBeings.size(); ++i)
+ for (int i = 0; i < static_cast<int>(blockedBeings.size()); ++i)
{
if (id == blockedBeings.at(i))
{
@@ -890,7 +892,7 @@ void ActorSpriteManager::deleteBlock(Uint32 id)
bool ActorSpriteManager::isBlocked(Uint32 id)
{
bool blocked(false);
- for (int i = 0; i < (int)blockedBeings.size(); ++i)
+ for (int i = 0; i < static_cast<int>(blockedBeings.size()); ++i)
{
if (id == blockedBeings.at(i))
{
diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp
index 806be56df..5e33b65d2 100644
--- a/src/animatedsprite.cpp
+++ b/src/animatedsprite.cpp
@@ -142,9 +142,10 @@ bool AnimatedSprite::updateCurrentAnimation(unsigned int time)
mFrameTime += time;
- while (mFrameTime > (unsigned)mFrame->delay && mFrame->delay > 0)
+ while (mFrameTime > static_cast<unsigned>(mFrame->delay)
+ && mFrame->delay > 0)
{
- mFrameTime -= (unsigned)mFrame->delay;
+ mFrameTime -= static_cast<unsigned>(mFrame->delay);
mFrameIndex++;
if (mFrameIndex == mAnimation->getLength())
diff --git a/src/being.cpp b/src/being.cpp
index 1d3b78293..8604f0053 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -340,8 +340,8 @@ void Being::setPosition(const Vector &pos)
if (mText)
{
- mText->adviseXY((int)pos.x,
- (int)pos.y - getHeight() - mText->getHeight() - 6);
+ mText->adviseXY(static_cast<int>(pos.x), static_cast<int>(pos.y)
+ - getHeight() - mText->getHeight() - 6);
}
}
@@ -379,8 +379,8 @@ void Being::setDestination(int dstX, int dstY)
{
// If there is no path but the destination is on the same walkable tile,
// we accept it.
- if ((int)mPos.x / 32 == dest.x / 32
- && (int)mPos.y / 32 == dest.y / 32)
+ if (static_cast<int>(mPos.x) / 32 == dest.x / 32
+ && static_cast<int>(mPos.y) / 32 == dest.y / 32)
{
mDest.x = static_cast<float>(dest.x);
mDest.y = static_cast<float>(dest.y);
@@ -1044,7 +1044,7 @@ void Being::nextTile()
mX = pos.x;
mY = pos.y;
setAction(MOVE);
- mActionTime += (int)(mWalkSpeed.x / 10);
+ mActionTime += static_cast<int>(mWalkSpeed.x / 10);
}
int Being::getCollisionRadius() const
@@ -1162,9 +1162,9 @@ void Being::logic()
case MOVE:
{
- if (getWalkSpeed().x
- && (int) ((get_elapsed_time(mActionTime) * frameCount)
- / getWalkSpeed().x) >= frameCount)
+ if (getWalkSpeed().x && static_cast<int> ((get_elapsed_time(
+ mActionTime) * frameCount) / getWalkSpeed().x)
+ >= frameCount)
{
nextTile();
}
@@ -1249,7 +1249,7 @@ void Being::logic()
if (!isAlive() && getWalkSpeed().x
&& Net::getGameHandler()->removeDeadBeings()
- && (int) ((get_elapsed_time(mActionTime)
+ && static_cast<int> ((get_elapsed_time(mActionTime)
/ getWalkSpeed().x) >= static_cast<float>(frameCount)))
{
if (getType() != PLAYER && actorSpriteManager)
@@ -1335,10 +1335,10 @@ int Being::getOffset(char pos, char neg) const
if (mMap)
{
offset = (pos == LEFT && neg == RIGHT) ?
- (int)((static_cast<float>(get_elapsed_time(mActionTime))
+ static_cast<int>((static_cast<float>(get_elapsed_time(mActionTime))
* static_cast<float>(mMap->getTileWidth()))
/ static_cast<float>(mWalkSpeed.x)) :
- (int)((static_cast<float>(get_elapsed_time(mActionTime))
+ static_cast<int>((static_cast<float>(get_elapsed_time(mActionTime))
* static_cast<float>(mMap->getTileHeight()))
/ static_cast<float>(mWalkSpeed.y));
}
diff --git a/src/client.cpp b/src/client.cpp
index 8b7eea4e9..76a53fdfd 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -496,8 +496,8 @@ Client::Client(const Options &options):
if (mCurrentServer.port == 0)
{
- mCurrentServer.port = (short) branding.getValue("defaultPort",
- DEFAULT_PORT);
+ mCurrentServer.port = static_cast<short>(branding.getValue(
+ "defaultPort", DEFAULT_PORT));
mCurrentServer.type = ServerInfo::parseType(
branding.getValue("defaultServerType", "tmwathena"));
}
@@ -516,7 +516,7 @@ Client::Client(const Options &options):
mLogicCounterId = SDL_AddTimer(MILLISECONDS_IN_A_TICK, nextTick, NULL);
mSecondsCounterId = SDL_AddTimer(1000, nextSecond, NULL);
- const int fpsLimit = (int) config.getIntValue("fpslimit");
+ const int fpsLimit = config.getIntValue("fpslimit");
mLimitFps = fpsLimit > 0;
// Initialize frame limiting
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 51d1bdf78..8fc1b8ca3 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -1178,7 +1178,10 @@ void CommandHandler::handleCacheInfo(const std::string &args _UNUSED_,
for (int f = 0; f < 256; f ++)
{
if (!cache[f].empty())
- str += strprintf("%d: %u, ", f, (unsigned int)cache[f].size());
+ {
+ str += strprintf("%d: %u, ", f,
+ static_cast<unsigned int>(cache[f].size()));
+ }
}
debugChatTab->chatLog(str);
#ifdef DEBUG_FONT_COUNTERS
diff --git a/src/configuration.cpp b/src/configuration.cpp
index b5f76c4fb..900a22563 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -179,7 +179,8 @@ int Configuration::getIntValue(const std::string &key) const
if (itdef != mDefaultsData->end() && itdef->second
&& itdef->second->getType() == Mana::VariableData::DATA_INT)
{
- defaultValue = ((Mana::IntData*)itdef->second)->getData();
+ defaultValue = (static_cast<Mana::IntData*>(
+ itdef->second))->getData();
}
else
{
@@ -209,7 +210,8 @@ std::string Configuration::getStringValue(const std::string &key) const
if (itdef != mDefaultsData->end() && itdef->second
&& itdef->second->getType() == Mana::VariableData::DATA_STRING)
{
- defaultValue = ((Mana::StringData*)itdef->second)->getData();
+ defaultValue = (static_cast<Mana::StringData*>(
+ itdef->second))->getData();
}
else
{
@@ -241,7 +243,7 @@ float Configuration::getFloatValue(const std::string &key) const
&& itdef->second->getType() == Mana::VariableData::DATA_FLOAT)
{
defaultValue = static_cast<float>(
- ((Mana::FloatData*)itdef->second)->getData());
+ (static_cast<Mana::FloatData*>(itdef->second))->getData());
}
else
{
@@ -271,7 +273,8 @@ bool Configuration::getBoolValue(const std::string &key) const
if (itdef != mDefaultsData->end() && itdef->second
&& itdef->second->getType() == Mana::VariableData::DATA_BOOL)
{
- defaultValue = ((Mana::BoolData*)itdef->second)->getData();
+ defaultValue = (static_cast<Mana::BoolData*>(
+ itdef->second))->getData();
}
else
{
diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp
index 55046c0f6..6976f3f1f 100644
--- a/src/dropshortcut.cpp
+++ b/src/dropshortcut.cpp
@@ -63,7 +63,7 @@ void DropShortcut::load(bool oldConfig)
for (int i = 0; i < DROP_SHORTCUT_ITEMS; i++)
{
- int itemId = (int) cfg->getValue("drop" + toString(i), -1);
+ int itemId = static_cast<int>(cfg->getValue("drop" + toString(i), -1));
if (itemId != -1)
mItems[i] = itemId;
diff --git a/src/game.cpp b/src/game.cpp
index 21758f66b..c087046d0 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -541,7 +541,7 @@ void Game::handleInput()
if (setupWindow && setupWindow->isVisible() &&
keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE)
{
- keyboard.setNewKey((int) event.key.keysym.sym);
+ keyboard.setNewKey(static_cast<int>(event.key.keysym.sym));
keyboard.callbackNewKey();
keyboard.setNewKeyIndex(keyboard.KEY_NO_VALUE);
return;
diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp
index e437c029a..bff000ef3 100644
--- a/src/gui/charselectdialog.cpp
+++ b/src/gui/charselectdialog.cpp
@@ -160,10 +160,11 @@ CharSelectDialog::CharSelectDialog(LoginData *loginData):
place = getPlacer(0, 1);
- for (int i = 0; i < (int)mLoginData->characterSlots; i++)
+ for (int i = 0; i < static_cast<int>(mLoginData->characterSlots); i++)
{
mCharacterEntries.push_back(new CharacterDisplay(this));
- place(i % SLOTS_PER_ROW, (int)i / SLOTS_PER_ROW, mCharacterEntries[i]);
+ place(i % SLOTS_PER_ROW, static_cast<int>(i) / SLOTS_PER_ROW,
+ mCharacterEntries[i]);
}
reflowLayout();
@@ -187,7 +188,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event)
// Check if a button of a character was pressed
const gcn::Widget *sourceParent = event.getSource()->getParent();
int selected = -1;
- for (int i = 0; i < (int)mCharacterEntries.size(); ++i)
+ for (int i = 0; i < static_cast<int>(mCharacterEntries.size()); ++i)
{
if (mCharacterEntries[i] == sourceParent)
{
@@ -297,7 +298,7 @@ void CharSelectDialog::setCharacters(const Net::Characters &characters)
if (Net::getNetworkType() == ServerInfo::MANASERV && characterSlot > 0)
--characterSlot;
- if (characterSlot >= (int)mCharacterEntries.size())
+ if (characterSlot >= static_cast<int>(mCharacterEntries.size()))
{
logger->log("Warning: slot out of range: %d", character->slot);
continue;
@@ -331,7 +332,7 @@ void CharSelectDialog::setLocked(bool locked)
if (mChangeEmailButton)
mChangeEmailButton->setEnabled(!locked);
- for (int i = 0; i < (int)mCharacterEntries.size(); ++i)
+ for (int i = 0; i < static_cast<int>(mCharacterEntries.size()); ++i)
{
if (mCharacterEntries[i])
mCharacterEntries[i]->setActive(!mLocked);
@@ -344,7 +345,7 @@ bool CharSelectDialog::selectByName(const std::string &name,
if (mLocked)
return false;
- for (int i = 0; i < (int)mCharacterEntries.size(); ++i)
+ for (int i = 0; i < static_cast<int>(mCharacterEntries.size()); ++i)
{
Net::Character *character = mCharacterEntries[i]->getCharacter();
if (mCharacterEntries[i] && character)
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 399202b70..6815796ff 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -367,7 +367,7 @@ void ChatWindow::nextTab()
void ChatWindow::defaultTab()
{
if (mChatTabs)
- mChatTabs->setSelectedTab((unsigned)0);
+ mChatTabs->setSelectedTab(static_cast<unsigned>(0));
}
void ChatWindow::action(const gcn::ActionEvent &event)
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 3813c050f..baccb7796 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -344,8 +344,7 @@ void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
if (!gcn::Widget::widgetExists(widget))
break;
- parent = (gcn::Widget*)widget->getParent();
-
+ parent = static_cast<gcn::Widget*>(widget->getParent());
if (widget->isEnabled() || force)
{
@@ -403,7 +402,7 @@ void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
gcn::Widget* swap = widget;
widget = parent;
- parent = (gcn::Widget*)swap->getParent();
+ parent = static_cast<gcn::Widget*>(swap->getParent());
// If a non modal focused widget has been reach
// and we have modal focus cancel the distribution.
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 197c92ee3..de9d2a150 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -111,7 +111,7 @@ void Minimap::setMap(Map *map)
// I'm not sure if the locks are necessary since it's a SWSURFACE
SDL_LockSurface(surface);
- int* data = (int*)surface->pixels;
+ int* data = static_cast<int*>(surface->pixels);
if (!data)
{
if (!isSticky())
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index e61bb120f..af89a6881 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -77,7 +77,7 @@ NpcDialog::NpcDialog(int npcId)
// Setup output text box
mTextBox = new BrowserBox(BrowserBox::AUTO_WRAP);
mTextBox->setOpaque(false);
- mTextBox->setMaxRow((int) config.getIntValue("ChatLogLength"));
+ mTextBox->setMaxRow(static_cast<int>(config.getIntValue("ChatLogLength")));
mTextBox->setLinkHandler(mItemLinkHandler);
mScrollArea = new ScrollArea(mTextBox);
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index c89c7846b..b9f0bc6f5 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -620,8 +620,8 @@ void ServerDialog::loadServers(bool addNew)
}
else if (xmlStrEqual(subNode->name, BAD_CAST "description"))
{
- server.description =
- (const char*)subNode->xmlChildrenNode->content;
+ server.description = reinterpret_cast<const char*>(
+ subNode->xmlChildrenNode->content);
}
}
diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp
index 97b973afe..543d7aa8d 100644
--- a/src/gui/setup_video.cpp
+++ b/src/gui/setup_video.cpp
@@ -110,7 +110,7 @@ ModeListModel::ModeListModel()
{
logger->log1("No modes available");
}
- else if (modes == (SDL_Rect **)-1)
+ else if (modes == reinterpret_cast<SDL_Rect **>(-1))
{
logger->log1("All resolutions available");
}
@@ -767,7 +767,7 @@ void Setup_Video::action(const gcn::ActionEvent &event)
mSpeechSlider->getValue());
mSpeechLabel->setCaption(speechModeToString(val));
mSpeechSlider->setValue(val);
- config.setValue("speech", (int)val);
+ config.setValue("speech", static_cast<int>(val));
}
else if (id == "lognpc")
{
diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp
index b2c57775f..51d31f2c9 100644
--- a/src/gui/specialswindow.cpp
+++ b/src/gui/specialswindow.cpp
@@ -237,8 +237,8 @@ SpecialEntry::SpecialEntry(SpecialInfo *info) :
float progress = 0;
if (info->rechargeNeeded)
{
- progress = (float)info->rechargeCurrent
- / (float)info->rechargeNeeded;
+ progress = static_cast<float>(info->rechargeCurrent)
+ / static_cast<float>(info->rechargeNeeded);
}
mRechargeBar = new ProgressBar(progress, 100, 10, Theme::PROG_MP);
mRechargeBar->setSmoothProgress(false);
@@ -252,7 +252,8 @@ void SpecialEntry::update(int current, int needed)
{
if (mRechargeBar && needed)
{
- float progress = (float)current / (float)needed;
+ float progress = static_cast<float>(current)
+ / static_cast<float>(needed);
mRechargeBar->setProgress(progress);
}
}
diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp
index a25f4748a..62003d94c 100644
--- a/src/gui/truetypefont.cpp
+++ b/src/gui/truetypefont.cpp
@@ -173,8 +173,11 @@ void TrueTypeFont::loadFont(const std::string &filename, int size, int style)
void TrueTypeFont::clear()
{
- for (unsigned short f = 0; f < (unsigned short)CACHES_NUMBER; f ++)
+ for (unsigned short f = 0; f < static_cast<unsigned short>(
+ CACHES_NUMBER); f ++)
+ {
mCache[static_cast<unsigned short>(f)].clear();
+ }
}
void TrueTypeFont::drawString(gcn::Graphics *graphics,
diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp
index eaeed4d06..8546cbd7e 100644
--- a/src/gui/widgets/browserbox.cpp
+++ b/src/gui/widgets/browserbox.cpp
@@ -290,7 +290,8 @@ void BrowserBox::draw(gcn::Graphics *graphics)
graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
}
- if (mSelectedLink >= 0 && mSelectedLink < (signed)mLinks.size())
+ if (mSelectedLink >= 0 && mSelectedLink
+ < static_cast<signed>(mLinks.size()))
{
if ((mHighMode & BACKGROUND))
{
@@ -434,7 +435,7 @@ int BrowserBox::calcHeight()
}
}
- if (c == '<' && link < (signed)mLinks.size())
+ if (c == '<' && link < static_cast<signed>(mLinks.size()))
{
const int size =
font->getWidth(mLinks[link].caption) + 1;
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 736594859..9675eb621 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -56,7 +56,8 @@ ChatTab::ChatTab(const std::string &name) :
mTextOutput = new BrowserBox(BrowserBox::AUTO_WRAP);
mTextOutput->setOpaque(false);
- mTextOutput->setMaxRow((int) config.getIntValue("ChatLogLength"));
+ mTextOutput->setMaxRow(static_cast<int>(
+ config.getIntValue("ChatLogLength")));
if (chatWindow)
mTextOutput->setLinkHandler(chatWindow->mItemLinkHandler);
mTextOutput->setAlwaysUpdate(false);
diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp
index 4abe279da..f6762a5cb 100644
--- a/src/gui/widgets/emoteshortcutcontainer.cpp
+++ b/src/gui/widgets/emoteshortcutcontainer.cpp
@@ -131,7 +131,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
mEmoteImg[i]->sprite->draw(g, emoteX + 2, emoteY + 10);
}
- if (mEmoteMoved && mEmoteMoved < (unsigned)mEmoteImg.size() + 1
+ if (mEmoteMoved && mEmoteMoved < static_cast<unsigned>(mEmoteImg.size()) + 1
&& mEmoteMoved > 0)
{
// Draw the emote image being dragged by the cursor.
@@ -245,7 +245,7 @@ void EmoteShortcutContainer::mouseMoved(gcn::MouseEvent &event)
mEmotePopup->setVisible(false);
- if ((unsigned)index < mEmoteImg.size() && mEmoteImg[index])
+ if (static_cast<unsigned>(index) < mEmoteImg.size() && mEmoteImg[index])
{
mEmotePopup->show(viewport->getMouseX(), viewport->getMouseY(),
mEmoteImg[index]->name);
diff --git a/src/gui/widgets/shopitems.cpp b/src/gui/widgets/shopitems.cpp
index 15f4292a5..6cd0ef39d 100644
--- a/src/gui/widgets/shopitems.cpp
+++ b/src/gui/widgets/shopitems.cpp
@@ -43,8 +43,11 @@ int ShopItems::getNumberOfElements()
std::string ShopItems::getElementAt(int i)
{
- if (i < 0 || (unsigned)i >= mShopItems.size() || !mShopItems.at(i))
+ if (i < 0 || static_cast<unsigned>(i) >= mShopItems.size()
+ || !mShopItems.at(i))
+ {
return "";
+ }
return mShopItems.at(i)->getDisplayName();
}
diff --git a/src/gui/widgets/shortcutcontainer.cpp b/src/gui/widgets/shortcutcontainer.cpp
index dd5dcf95a..a804f2658 100644
--- a/src/gui/widgets/shortcutcontainer.cpp
+++ b/src/gui/widgets/shortcutcontainer.cpp
@@ -65,7 +65,7 @@ int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const
int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
if (!tRect.isPointInRect(pointX, pointY) ||
- index >= (int)mMaxItems || index < 0)
+ index >= static_cast<int>(mMaxItems) || index < 0)
{
index = -1;
}
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index ca3eb5095..67882deca 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -155,7 +155,7 @@ void TabbedArea::removeTab(Tab *tab)
}
}
- if (tabIndexToBeSelected >= (signed)mTabs.size())
+ if (tabIndexToBeSelected >= static_cast<signed>(mTabs.size()))
tabIndexToBeSelected = mTabs.size() - 1;
if (tabIndexToBeSelected < -1)
tabIndexToBeSelected = -1;
diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp
index 9b05a1389..1037296b6 100644
--- a/src/gui/widgets/window.cpp
+++ b/src/gui/widgets/window.cpp
@@ -748,7 +748,8 @@ int Window::getResizeHandles(gcn::MouseEvent &event)
const int y = event.getY();
if (mGrip && (y > static_cast<int>(mTitleBarHeight)
- || (y < (int)getPadding() && mTitleBarHeight > getPadding())))
+ || (y < static_cast<int>(getPadding()) && mTitleBarHeight
+ > getPadding())))
{
const int x = event.getX();
@@ -776,7 +777,7 @@ bool Window::isResizeAllowed(gcn::MouseEvent &event)
const int y = event.getY();
if (mGrip && (y > static_cast<int>(mTitleBarHeight)
- || y < (int)getPadding()))
+ || y < static_cast<int>(getPadding())))
{
const int x = event.getX();
diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp
index ec1a62fd0..2d4f21337 100644
--- a/src/imageparticle.cpp
+++ b/src/imageparticle.cpp
@@ -66,8 +66,8 @@ bool ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const
if (!isAlive() || !mImage)
return false;
- int screenX = (int) mPos.x + offsetX - mImage->getWidth() / 2;
- int screenY = (int) mPos.y - (int)mPos.z
+ int screenX = static_cast<int>(mPos.x) + offsetX - mImage->getWidth() / 2;
+ int screenY = static_cast<int>(mPos.y) - static_cast<int>(mPos.z)
+ offsetY - mImage->getHeight() / 2;
// Check if on screen
@@ -82,10 +82,16 @@ bool ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const
float alphafactor = mAlpha;
if (mFadeOut && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
- alphafactor *= (float) mLifetimeLeft / (float) mFadeOut;
+ {
+ alphafactor *= static_cast<float>(mLifetimeLeft)
+ / static_cast<float>(mFadeOut);
+ }
if (mFadeIn && mLifetimePast < mFadeIn)
- alphafactor *= (float) mLifetimePast / (float) mFadeIn;
+ {
+ alphafactor *= static_cast<float>(mLifetimePast)
+ / static_cast<float>(mFadeIn);
+ }
mImage->setAlpha(alphafactor);
return graphics->drawImage(mImage, screenX, screenY);
diff --git a/src/inventory.cpp b/src/inventory.cpp
index 705ae9329..555117638 100644
--- a/src/inventory.cpp
+++ b/src/inventory.cpp
@@ -49,7 +49,7 @@ Inventory::Inventory(int type, int size):
mUsed(0)
{
mItems = new Item*[mSize];
- std::fill_n(mItems, mSize, (Item*) 0);
+ std::fill_n(mItems, mSize, static_cast<Item*>(0));
}
Inventory::~Inventory()
diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp
index b15e618d7..7f8f8ddc0 100644
--- a/src/itemshortcut.cpp
+++ b/src/itemshortcut.cpp
@@ -62,7 +62,7 @@ void ItemShortcut::load(bool oldConfig)
name = "shortcut";
for (int i = 0; i < SHORTCUT_ITEMS; i++)
{
- int itemId = (int) cfg->getValue(name + toString(i), -1);
+ int itemId = static_cast<int>(cfg->getValue(name + toString(i), -1));
mItems[i] = itemId;
}
diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp
index 3636bea5f..2ed3d8a61 100644
--- a/src/keyboardconfig.cpp
+++ b/src/keyboardconfig.cpp
@@ -356,8 +356,8 @@ void KeyboardConfig::retrieve()
{
for (int i = 0; i < KEY_TOTAL; i++)
{
- mKey[i].value = (int) config.getValue(
- mKey[i].configField, mKey[i].defaultValue);
+ mKey[i].value = static_cast<int>(config.getValue(
+ mKey[i].configField, mKey[i].defaultValue));
}
}
@@ -451,7 +451,7 @@ void KeyboardConfig::refreshActiveKeys()
std::string KeyboardConfig::getKeyValueString(int index) const
{
std::string key = SDL_GetKeyName(
- (SDLKey) getKeyValue(index));
+ static_cast<SDLKey>(getKeyValue(index)));
return getKeyShortString(key);
}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index e69703e06..d544b8ed7 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -2534,9 +2534,9 @@ bool LocalPlayer::isReachable(int x, int y, int maxCost)
const Vector &playerPos = getPosition();
Path debugPath = mMap->findPath(
- (int) (playerPos.x - 16) / 32,
- (int) (playerPos.y - 32) / 32,
- x, y, 0x00, maxCost);
+ static_cast<int>(playerPos.x - 16) / 32,
+ static_cast<int>(playerPos.y - 32) / 32,
+ x, y, 0x00, maxCost);
return !debugPath.empty();
}
@@ -2562,9 +2562,9 @@ bool LocalPlayer::isReachable(Being *being, int maxCost)
const Vector &playerPos = getPosition();
Path debugPath = mMap->findPath(
- (int) (playerPos.x - 16) / 32,
- (int) (playerPos.y - 32) / 32,
- being->getTileX(), being->getTileY(), 0x00, maxCost);
+ static_cast<int>(playerPos.x - 16) / 32,
+ static_cast<int>(playerPos.y - 32) / 32,
+ being->getTileX(), being->getTileY(), 0x00, maxCost);
being->setDistance(static_cast<int>(debugPath.size()));
if (!debugPath.empty())
@@ -3134,9 +3134,10 @@ void LocalPlayer::navigateTo(int x, int y)
mNavigateY = y;
mNavigateId = 0;
- mNavigatePath = mMap->findPath((int) (playerPos.x - 16) / 32,
- (int) (playerPos.y - 32) / 32,
- x, y, 0x00, 0);
+ mNavigatePath = mMap->findPath(
+ static_cast<int>(playerPos.x - 16) / 32,
+ static_cast<int>(playerPos.y - 32) / 32,
+ x, y, 0x00, 0);
if (mDrawPath)
tmpLayer->addRoad(mNavigatePath);
@@ -3160,10 +3161,11 @@ void LocalPlayer::navigateTo(Being *being)
mNavigateX = being->getTileX();
mNavigateY = being->getTileY();
- mNavigatePath = mMap->findPath((int) (playerPos.x - 16) / 32,
- (int) (playerPos.y - 32) / 32,
- being->getTileX(), being->getTileY(),
- 0x00, 0);
+ mNavigatePath = mMap->findPath(
+ static_cast<int>(playerPos.x - 16) / 32,
+ static_cast<int>(playerPos.y - 32) / 32,
+ being->getTileX(), being->getTileY(),
+ 0x00, 0);
if (mDrawPath)
tmpLayer->addRoad(mNavigatePath);
@@ -3215,8 +3217,8 @@ void LocalPlayer::updateCoords()
if (!tmpLayer)
return;
- int x = (int) (playerPos.x - 16) / 32;
- int y = (int) (playerPos.y - 32) / 32;
+ int x = static_cast<int>(playerPos.x - 16) / 32;
+ int y = static_cast<int>(playerPos.y - 32) / 32;
if (mNavigateId)
{
if (!actorSpriteManager)
@@ -3291,10 +3293,11 @@ int LocalPlayer::getPathLength(Being* being)
const Vector &playerPos = getPosition();
- Path debugPath = mMap->findPath((int) (playerPos.x - 16) / 32,
- (int) (playerPos.y - 32) / 32,
- being->getTileX(), being->getTileY(),
- 0x00, 0);
+ Path debugPath = mMap->findPath(
+ static_cast<int>(playerPos.x - 16) / 32,
+ static_cast<int>(playerPos.y - 32) / 32,
+ being->getTileX(), being->getTileY(),
+ 0x00, 0);
return static_cast<int>(debugPath.size());
}
@@ -3629,10 +3632,12 @@ void LocalPlayer::fixAttackTarget()
return;
const Vector &playerPos = getPosition();
- Path debugPath = mMap->findPath((int) (playerPos.x - 16) / 32,
- (int) (playerPos.y - 32) / 32,
- mTarget->getTileX(), mTarget->getTileY(),
- 0x00, 0);
+ Path debugPath = mMap->findPath(
+ static_cast<int>(playerPos.x - 16) / 32,
+ static_cast<int>(playerPos.y - 32) / 32,
+ mTarget->getTileX(), mTarget->getTileY(),
+ 0x00, 0);
+
if (!debugPath.empty())
{
Path::const_iterator i = debugPath.begin();
diff --git a/src/log.cpp b/src/log.cpp
index d66cdab2f..982f2eed7 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -86,16 +86,16 @@ void Logger::dlog(std::string str)
std::stringstream timeStr;
timeStr << "["
<< ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "")
- << (int)(((tv.tv_sec / 60) / 60) % 24)
+ << static_cast<int>(((tv.tv_sec / 60) / 60) % 24)
<< ":"
<< (((tv.tv_sec / 60) % 60 < 10) ? "0" : "")
- << (int)((tv.tv_sec / 60) % 60)
+ << static_cast<int>((tv.tv_sec / 60) % 60)
<< ":"
<< ((tv.tv_sec % 60 < 10) ? "0" : "")
- << (int)(tv.tv_sec % 60)
+ << static_cast<int>(tv.tv_sec % 60)
<< "."
<< (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "")
- << (int)((tv.tv_usec / 10000) % 100)
+ << static_cast<int>((tv.tv_usec / 10000) % 100)
<< "] ";
if (mLogFile.is_open())
@@ -118,16 +118,16 @@ void Logger::log1(const char *buf)
std::stringstream timeStr;
timeStr << "["
<< ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "")
- << (int)(((tv.tv_sec / 60) / 60) % 24)
+ << static_cast<int>(((tv.tv_sec / 60) / 60) % 24)
<< ":"
<< (((tv.tv_sec / 60) % 60 < 10) ? "0" : "")
- << (int)((tv.tv_sec / 60) % 60)
+ << static_cast<int>((tv.tv_sec / 60) % 60)
<< ":"
<< ((tv.tv_sec % 60 < 10) ? "0" : "")
- << (int)(tv.tv_sec % 60)
+ << static_cast<int>(tv.tv_sec % 60)
<< "."
<< (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "")
- << (int)((tv.tv_usec / 10000) % 100)
+ << static_cast<int>((tv.tv_usec / 10000) % 100)
<< "] ";
if (mLogFile.is_open())
@@ -142,10 +142,10 @@ void Logger::log1(const char *buf)
void Logger::log(const char *log_text, ...)
{
- unsigned int size = 1024;
+ unsigned size = 1024;
char* buf = 0;
if (strlen(log_text) * 3 > size)
- size = (unsigned)strlen(log_text) * 3;
+ size = static_cast<unsigned>(strlen(log_text) * 3);
buf = new char[size];
va_list ap;
@@ -163,16 +163,16 @@ void Logger::log(const char *log_text, ...)
std::stringstream timeStr;
timeStr << "["
<< ((((tv.tv_sec / 60) / 60) % 24 < 10) ? "0" : "")
- << (int)(((tv.tv_sec / 60) / 60) % 24)
+ << static_cast<int>(((tv.tv_sec / 60) / 60) % 24)
<< ":"
<< (((tv.tv_sec / 60) % 60 < 10) ? "0" : "")
- << (int)((tv.tv_sec / 60) % 60)
+ << static_cast<int>((tv.tv_sec / 60) % 60)
<< ":"
<< ((tv.tv_sec % 60 < 10) ? "0" : "")
- << (int)(tv.tv_sec % 60)
+ << static_cast<int>(tv.tv_sec % 60)
<< "."
<< (((tv.tv_usec / 10000) % 100) < 10 ? "0" : "")
- << (int)((tv.tv_usec / 10000) % 100)
+ << static_cast<int>((tv.tv_usec / 10000) % 100)
<< "] ";
if (mLogFile.is_open())
diff --git a/src/main.cpp b/src/main.cpp
index 71e29b9b2..6efa736e7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -143,7 +143,7 @@ static void parseOptions(int argc, char *argv[], Client::Options &options)
options.serverName = optarg;
break;
case 'p':
- options.serverPort = (short) atoi(optarg);
+ options.serverPort = static_cast<short>(atoi(optarg));
break;
case 'u':
options.skipUpdate = true;
diff --git a/src/map.cpp b/src/map.cpp
index c5cd1e3b5..9557d7b79 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -119,7 +119,7 @@ MapLayer::MapLayer(int x, int y, int width, int height, bool isFringeLayer):
const int size = mWidth * mHeight;
mTiles = new Image*[size];
- std::fill_n(mTiles, size, (Image*) 0);
+ std::fill_n(mTiles, size, static_cast<Image*>(0));
config.addListener("highlightAttackRange", this);
}
@@ -951,9 +951,9 @@ Path Map::findPixelPath(int startPixelX, int startPixelY, int endPixelX,
float endOffsetY = static_cast<float>(endPixelY % 32);
// Find the distance, and divide it by the number of steps
- int changeX = (int)((endOffsetX - startOffsetX)
+ int changeX = static_cast<int>((endOffsetX - startOffsetX)
/ static_cast<float>(myPath.size()));
- int changeY = (int)((endOffsetY - startOffsetY)
+ int changeY = static_cast<int>((endOffsetY - startOffsetY)
/ static_cast<float>(myPath.size()));
// Convert the map path to pixels over tiles
@@ -1323,8 +1323,9 @@ void Map::saveExtraLayer()
if (item && item->mType != MapItem::EMPTY
&& item->mType != MapItem::HOME)
{
- mapFile << x << " " << y << " " << (int)item->mType
- << " " << item->mComment << std::endl;
+ mapFile << x << " " << y << " "
+ << static_cast<int>(item->mType) << " "
+ << item->mComment << std::endl;
}
}
}
@@ -1434,7 +1435,7 @@ SpecialLayer::SpecialLayer(int width, int height, bool drawSprites):
{
const int size = mWidth * mHeight;
mTiles = new MapItem*[size];
- std::fill_n(mTiles, size, (MapItem*) 0);
+ std::fill_n(mTiles, size, static_cast<MapItem*>(0));
mDrawSprites = drawSprites;
}
diff --git a/src/mumblemanager.cpp b/src/mumblemanager.cpp
index 6586f9546..b21fac2ee 100644
--- a/src/mumblemanager.cpp
+++ b/src/mumblemanager.cpp
@@ -111,10 +111,10 @@ void MumbleManager::init()
return;
}
- mLinkedMem = (LinkedMem *)(mmap(NULL, sizeof(struct LinkedMem),
+ mLinkedMem = static_cast<LinkedMem *>(mmap(NULL, sizeof(struct LinkedMem),
PROT_READ | PROT_WRITE, MAP_SHARED, shmfd, 0));
- if (mLinkedMem == (void *)(-1))
+ if (mLinkedMem == reinterpret_cast<void *>(-1))
{
mLinkedMem = NULL;
logger->log1("MumbleManager::init cant map MumbleLink");
diff --git a/src/net/download.cpp b/src/net/download.cpp
index 40d7c872a..aa2793ddb 100644
--- a/src/net/download.cpp
+++ b/src/net/download.cpp
@@ -92,7 +92,8 @@ unsigned long Download::fadler32(FILE *file)
char *buffer = static_cast<char*>(malloc(fileSize));
const size_t read = fread(buffer, 1, fileSize, file);
unsigned long adler = adler32(0L, Z_NULL, 0);
- adler = adler32(static_cast<uInt>(adler), (Bytef*)buffer, read);
+ adler = adler32(static_cast<uInt>(adler),
+ reinterpret_cast<Bytef*>(buffer), read);
free(buffer);
return adler;
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index e39a443f1..9ffc052f6 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -30,8 +30,8 @@
#include "utils/stringutils.h"
#define MAKEWORD(low, high) \
- ((unsigned short)(((unsigned char)(low)) | \
- ((unsigned short)((unsigned char)(high))) << 8))
+ (static_cast<unsigned short>((static_cast<unsigned char>(low)) | \
+ (static_cast<unsigned short>(static_cast<unsigned char>(high))) << 8))
namespace Net
{
@@ -121,14 +121,16 @@ void MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction)
break;
}
default:
- logger->log("incorrect direction: %d", (int)direction);
+ logger->log("incorrect direction: %d",
+ static_cast<int>(direction));
// OOPSIE! Impossible or unknown
direction = 0;
}
}
mPos += 3;
PacketCounters::incInBytes(3);
- DEBUGLOG("readCoordinates: " + toString((int)x) + "," + toString((int)y));
+ DEBUGLOG("readCoordinates: " + toString(static_cast<int>(x))
+ + "," + toString(static_cast<int>(y)));
}
void MessageIn::readCoordinatePair(Uint16 &srcX, Uint16 &srcY,
@@ -151,9 +153,10 @@ void MessageIn::readCoordinatePair(Uint16 &srcX, Uint16 &srcY,
srcY = static_cast<unsigned short>(temp >> 4);
}
mPos += 5;
- DEBUGLOG("readCoordinatePair: " + toString((int)srcX) + ","
- + toString((int)srcY) + " " + toString((int)dstX) + ","
- + toString((int)dstY));
+ DEBUGLOG("readCoordinatePair: " + toString(static_cast<int>(srcX)) + ","
+ + toString(static_cast<int>(srcY)) + " "
+ + toString(static_cast<int>(dstX)) + ","
+ + toString(static_cast<int>(dstY)));
PacketCounters::incInBytes(5);
}
@@ -161,7 +164,7 @@ void MessageIn::skip(unsigned int length)
{
mPos += length;
PacketCounters::incInBytes(length);
- DEBUGLOG("skip: " + toString((int)length));
+ DEBUGLOG("skip: " + toString(static_cast<int>(length)));
}
std::string MessageIn::readString(int length)
diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp
index 82123a2df..db7f4842e 100644
--- a/src/net/messageout.cpp
+++ b/src/net/messageout.cpp
@@ -45,7 +45,7 @@ MessageOut::MessageOut(short id _UNUSED_):
void MessageOut::writeInt8(Sint8 value)
{
- DEBUGLOG("writeInt8: " + toString((int)value));
+ DEBUGLOG("writeInt8: " + toString(static_cast<int>(value)));
expand(1);
mData[mPos] = value;
mPos += 1;
diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp
index 74a620ce3..f066db0bd 100644
--- a/src/net/tmwa/beinghandler.cpp
+++ b/src/net/tmwa/beinghandler.cpp
@@ -179,7 +179,8 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
speed = msg.readInt16();
stunMode = msg.readInt16(); // opt1
statusEffects = msg.readInt16(); // opt2
- statusEffects |= ((Uint32)msg.readInt16()) << 16; // option
+ statusEffects |= (static_cast<Uint32>(
+ msg.readInt16())) << 16; // option
job = msg.readInt16(); // class
dstBeing = actorSpriteManager->findBeing(id);
@@ -500,12 +501,12 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
if (dstBeing)
{
dstBeing->takeDamage(srcBeing, param1,
- (Being::AttackType)type);
+ static_cast<Being::AttackType>(type));
}
if (srcBeing)
{
srcBeing->handleAttack(dstBeing, param1,
- (Being::AttackType)type);
+ static_cast<Being::AttackType>(type));
if (srcBeing->getType() == Being::PLAYER)
srcBeing->setAttackTime();
}
@@ -560,7 +561,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
if (!effectManager)
return;
- id = (Uint32)msg.readInt32();
+ id = static_cast<Uint32>(msg.readInt32());
Being* being = actorSpriteManager->findBeing(id);
if (!being)
break;
@@ -843,7 +844,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
speed = msg.readInt16();
stunMode = msg.readInt16(); // opt1; Aethyra use this as cape
statusEffects = msg.readInt16(); // opt2; Aethyra use this as misc1
- statusEffects |= ((Uint32) msg.readInt16())
+ statusEffects |= (static_cast<Uint32>(msg.readInt16()))
<< 16; // status.options; Aethyra uses this as misc2
job = msg.readInt16();
@@ -1100,7 +1101,7 @@ void BeingHandler::handleMessage(Net::MessageIn &msg)
stunMode = msg.readInt16();
statusEffects = msg.readInt16();
- statusEffects |= ((Uint32) msg.readInt16()) << 16;
+ statusEffects |= (static_cast<Uint32>(msg.readInt16())) << 16;
msg.readInt8(); // Unused?
dstBeing->setStunMode(stunMode);
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp
index 3e079ed75..ca32b1df4 100644
--- a/src/net/tmwa/messagein.cpp
+++ b/src/net/tmwa/messagein.cpp
@@ -60,7 +60,7 @@ Sint16 MessageIn::readInt16()
}
mPos += 2;
PacketCounters::incInBytes(2);
- DEBUGLOG("readInt16: " + toString((int)value));
+ DEBUGLOG("readInt16: " + toString(static_cast<int>(value)));
return value;
}
diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp
index c12105581..17314937d 100644
--- a/src/net/tmwa/messageout.cpp
+++ b/src/net/tmwa/messageout.cpp
@@ -55,7 +55,7 @@ void MessageOut::expand(size_t bytes)
void MessageOut::writeInt16(Sint16 value)
{
- DEBUGLOG("writeInt16: " + toString((int)value));
+ DEBUGLOG("writeInt16: " + toString(static_cast<int>(value)));
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
Sint16 swap = SDL_Swap16(value);
@@ -81,8 +81,8 @@ void MessageOut::writeInt32(Sint32 value)
PacketCounters::incOutBytes(4);
}
-#define LOBYTE(w) ((unsigned char)(w))
-#define HIBYTE(w) ((unsigned char)(((unsigned short)(w)) >> 8))
+#define LOBYTE(w) (static_cast<unsigned char>(w))
+#define HIBYTE(w) (static_cast<unsigned char>((static_cast<unsigned short>(w)) >> 8))
void MessageOut::writeCoordinates(unsigned short x, unsigned short y,
unsigned char direction)
@@ -99,7 +99,7 @@ void MessageOut::writeCoordinates(unsigned short x, unsigned short y,
data[1] = 1;
data[2] = 2;
data[0] = HIBYTE(temp);
- data[1] = (unsigned char) temp;
+ data[1] = static_cast<unsigned char>(temp);
temp = y;
temp <<= 4;
data[1] |= HIBYTE(temp);
@@ -134,7 +134,7 @@ void MessageOut::writeCoordinates(unsigned short x, unsigned short y,
break;
default:
// OOPSIE! Impossible or unknown
- direction = (unsigned char) -1;
+ direction = static_cast<unsigned char>(-1);
}
data[2] |= direction;
PacketCounters::incOutBytes(3);
diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp
index ad8be300c..5beb05c20 100644
--- a/src/net/tmwa/network.cpp
+++ b/src/net/tmwa/network.cpp
@@ -257,7 +257,7 @@ void Network::flush()
SDL_mutexP(mMutex);
ret = SDLNet_TCP_Send(mSocket, mOutBuffer, mOutSize);
- if (ret < (int)mOutSize)
+ if (ret < static_cast<int>(mOutSize))
{
setError("Error in SDLNet_TCP_Send(): " +
std::string(SDLNet_GetError()));
@@ -396,7 +396,7 @@ void Network::receive()
{
// TODO Try to get this to block all the time while still being able
// to escape the loop
- int numReady = SDLNet_CheckSockets(set, ((Uint32)500));
+ int numReady = SDLNet_CheckSockets(set, (static_cast<Uint32>(500)));
int ret;
switch (numReady)
{
@@ -476,9 +476,9 @@ void Network::setError(const std::string &error)
Uint16 Network::readWord(int pos)
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- return SDL_Swap16((*(Uint16*)(mInBuffer + (pos))));
+ return SDL_Swap16((*static_cast<Uint16*>(mInBuffer + (pos))));
#else
- return (*(Uint16*)(mInBuffer + (pos)));
+ return (*reinterpret_cast<Uint16*>(mInBuffer + (pos)));
#endif
}
diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp
index 8ba323268..55908093f 100644
--- a/src/net/tmwa/playerhandler.cpp
+++ b/src/net/tmwa/playerhandler.cpp
@@ -241,8 +241,9 @@ void PlayerHandler::handleMessage(Net::MessageIn &msg)
// player_node->updateNavigateList();
}
- logger->log("Adjust scrolling by %d:%d", (int) scrollOffsetX,
- (int) scrollOffsetY);
+ logger->log("Adjust scrolling by %d:%d",
+ static_cast<int>(scrollOffsetX),
+ static_cast<int>(scrollOffsetY));
if (viewport)
viewport->scrollBy(scrollOffsetX, scrollOffsetY);
diff --git a/src/opengl1graphics.cpp b/src/opengl1graphics.cpp
index e319aa43c..03742ccb3 100644
--- a/src/opengl1graphics.cpp
+++ b/src/opengl1graphics.cpp
@@ -93,7 +93,8 @@ bool OpenGL1Graphics::setVideoMode(int w, int h, int bpp,
logger->log("Using OpenGL %s double buffering.",
(gotDoubleBuffer ? "with" : "without"));
- char const *glExtensions = (char const *)glGetString(GL_EXTENSIONS);
+ char const *glExtensions = reinterpret_cast<char const *>(
+ glGetString(GL_EXTENSIONS));
GLint texSize;
bool rectTex = strstr(glExtensions, "GL_ARB_texture_rectangle");
if (rectTex)
@@ -120,10 +121,12 @@ static inline void drawQuad(Image *image,
if (image->getTextureType() == GL_TEXTURE_2D)
{
// Find OpenGL normalized texture coordinates.
- float texX1 = srcX / (float) image->getTextureWidth();
- float texY1 = srcY / (float) image->getTextureHeight();
- float texX2 = (srcX + width) / (float) image->getTextureWidth();
- float texY2 = (srcY + height) / (float) image->getTextureHeight();
+ float texX1 = srcX / static_cast<float>(image->getTextureWidth());
+ float texY1 = srcY / static_cast<float>(image->getTextureHeight());
+ float texX2 = (srcX + width) / static_cast<float>(
+ image->getTextureWidth());
+ float texY2 = (srcY + height) / static_cast<float>(
+ image->getTextureHeight());
glTexCoord2f(texX1, texY1);
glVertex2i(dstX, dstY);
@@ -154,10 +157,12 @@ static inline void drawRescaledQuad(Image *image, int srcX, int srcY,
if (image->getTextureType() == GL_TEXTURE_2D)
{
// Find OpenGL normalized texture coordinates.
- float texX1 = srcX / (float) image->getTextureWidth();
- float texY1 = srcY / (float) image->getTextureHeight();
- float texX2 = (srcX + width) / (float) image->getTextureWidth();
- float texY2 = (srcY + height) / (float) image->getTextureHeight();
+ float texX1 = srcX / static_cast<float>(image->getTextureWidth());
+ float texY1 = srcY / static_cast<float>(image->getTextureHeight());
+ float texX2 = (srcX + width) / static_cast<float>(
+ image->getTextureWidth());
+ float texY2 = (srcY + height) / static_cast<float>(
+ image->getTextureHeight());
glTexCoord2f(texX1, texY1);
glVertex2i(dstX, dstY);
@@ -396,7 +401,8 @@ void OpenGL1Graphics::_beginDraw()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0.0, (double)mTarget->w, (double)mTarget->h, 0.0, -1.0, 1.0);
+ glOrtho(0.0, static_cast<double>(mTarget->w),
+ static_cast<double>(mTarget->h), 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -431,12 +437,14 @@ SDL_Surface* OpenGL1Graphics::getScreenshot()
// Flip the screenshot, as OpenGL has 0,0 in bottom left
unsigned int lineSize = 3 * w;
- GLubyte* buf = (GLubyte*)malloc(lineSize);
+ GLubyte* buf = static_cast<GLubyte*>(malloc(lineSize));
for (int i = 0; i < (h / 2); i++)
{
- GLubyte *top = (GLubyte*)screenshot->pixels + lineSize * i;
- GLubyte *bot = (GLubyte*)screenshot->pixels + lineSize * (h - 1 - i);
+ GLubyte *top = static_cast<GLubyte*>(
+ screenshot->pixels) + lineSize * i;
+ GLubyte *bot = static_cast<GLubyte*>(
+ screenshot->pixels) + lineSize * (h - 1 - i);
memcpy(buf, top, lineSize);
memcpy(top, bot, lineSize);
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 6b71da13e..302c895d0 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -105,7 +105,8 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
logger->log("Using OpenGL %s double buffering.",
(gotDoubleBuffer ? "with" : "without"));
- char const *glExtensions = (char const *)glGetString(GL_EXTENSIONS);
+ char const *glExtensions = reinterpret_cast<char const *>(
+ glGetString(GL_EXTENSIONS));
GLint texSize;
bool rectTex = strstr(glExtensions, "GL_ARB_texture_rectangle");
if (rectTex)
@@ -631,7 +632,8 @@ void OpenGLGraphics::_beginDraw()
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(0.0, (double)mTarget->w, (double)mTarget->h, 0.0, -1.0, 1.0);
+ glOrtho(0.0, static_cast<double>(mTarget->w),
+ static_cast<double>(mTarget->h), 0.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -681,12 +683,14 @@ SDL_Surface* OpenGLGraphics::getScreenshot()
// Flip the screenshot, as OpenGL has 0,0 in bottom left
unsigned int lineSize = 3 * w;
- GLubyte* buf = (GLubyte*)malloc(lineSize);
+ GLubyte* buf = static_cast<GLubyte*>(malloc(lineSize));
for (int i = 0; i < (h / 2); i++)
{
- GLubyte *top = (GLubyte*)screenshot->pixels + lineSize * i;
- GLubyte *bot = (GLubyte*)screenshot->pixels + lineSize * (h - 1 - i);
+ GLubyte *top = static_cast<GLubyte*>(
+ screenshot->pixels) + lineSize * i;
+ GLubyte *bot = static_cast<GLubyte*>(
+ screenshot->pixels) + lineSize * (h - 1 - i);
memcpy(buf, top, lineSize);
memcpy(top, bot, lineSize);
diff --git a/src/particle.cpp b/src/particle.cpp
index 24f6e128f..9ecd8e65d 100644
--- a/src/particle.cpp
+++ b/src/particle.cpp
@@ -315,8 +315,8 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
// Image
else if ((node = XML::findFirstChildByName(effectChildNode, "image")))
{
- Image *img = resman->getImage((const char*)
- node->xmlChildrenNode->content);
+ Image *img = resman->getImage(reinterpret_cast<const char*>(
+ node->xmlChildrenNode->content));
newParticle = new ImageParticle(mMap, img);
}
@@ -333,8 +333,8 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
effectChildNode, "position-y", 0);
float offsetZ = XML::getFloatProperty(
effectChildNode, "position-z", 0);
- Vector position (mPos.x + (float)pixelX + offsetX,
- mPos.y + (float)pixelY + offsetY,
+ Vector position (mPos.x + static_cast<float>(pixelX) + offsetX,
+ mPos.y + static_cast<float>(pixelY) + offsetY,
mPos.z + offsetZ);
newParticle->moveTo(position);
@@ -357,8 +357,8 @@ Particle *Particle::addEffect(const std::string &particleEffectFile,
}
else if (xmlStrEqual(emitterNode->name, BAD_CAST "deatheffect"))
{
- std::string deathEffect = (const char*)emitterNode
- ->xmlChildrenNode->content;
+ std::string deathEffect = reinterpret_cast<const char*>(
+ emitterNode->xmlChildrenNode->content);
char deathEffectConditions = 0x00;
if (XML::getBoolProperty(emitterNode, "on-floor", true))
diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp
index bfeb2a694..72aed5df2 100644
--- a/src/particlecontainer.cpp
+++ b/src/particlecontainer.cpp
@@ -138,7 +138,7 @@ void ParticleVector::setLocally(int index, Particle *particle)
delLocally(index);
- if (mIndexedElements.size() <= (unsigned) index)
+ if (mIndexedElements.size() <= static_cast<unsigned>(index))
mIndexedElements.resize(index + 1, NULL);
if (particle)
@@ -151,7 +151,7 @@ void ParticleVector::delLocally(int index)
if (index < 0)
return;
- if (mIndexedElements.size() <= (unsigned) index)
+ if (mIndexedElements.size() <= static_cast<unsigned>(index))
return;
Particle *p = mIndexedElements[index];
diff --git a/src/particleemitter.cpp b/src/particleemitter.cpp
index ad4fd2989..f1bb81d59 100644
--- a/src/particleemitter.cpp
+++ b/src/particleemitter.cpp
@@ -353,7 +353,8 @@ ParticleEmitter::ParticleEmitter(xmlNodePtr emitterNode, Particle *target,
}
else if (xmlStrEqual(propertyNode->name, BAD_CAST "deatheffect"))
{
- mDeathEffect = (const char*)propertyNode->xmlChildrenNode->content;
+ mDeathEffect = reinterpret_cast<const char*>(
+ propertyNode->xmlChildrenNode->content);
mDeathEffectConditions = 0x00;
if (XML::getBoolProperty(propertyNode, "on-floor", true))
mDeathEffectConditions += Particle::DEAD_FLOOR;
@@ -425,13 +426,16 @@ ParticleEmitter::readParticleEmitterProp(xmlNodePtr propertyNode, T def)
{
ParticleEmitterProp<T> retval;
- def = (T) XML::getFloatProperty(propertyNode, "value", (double) def);
- retval.set((T) XML::getFloatProperty(propertyNode, "min", (double) def),
- (T) XML::getFloatProperty(propertyNode, "max", (double) def));
+ def = static_cast<T>(XML::getFloatProperty(propertyNode, "value",
+ static_cast<double>(def)));
+ retval.set(static_cast<T>(XML::getFloatProperty(propertyNode, "min",
+ static_cast<double>(def))), static_cast<T>(XML::getFloatProperty(
+ propertyNode, "max", static_cast<double>(def))));
std::string change = XML::getProperty(propertyNode, "change-func", "none");
- T amplitude = (T) XML::getFloatProperty(propertyNode,
- "change-amplitude", 0.0);
+ T amplitude = static_cast<T>(XML::getFloatProperty(propertyNode,
+ "change-amplitude", 0.0));
+
int period = XML::getProperty(propertyNode, "change-period", 0);
int phase = XML::getProperty(propertyNode, "change-phase", 0);
if (change == "saw" || change == "sawtooth")
@@ -564,7 +568,8 @@ void ParticleEmitter::adjustSize(int w, int h)
mParticlePosY.set(0, static_cast<float>(h));
int newArea = w * h;
// adjust the output so that the particle density stays the same
- float outputFactor = (float)newArea / (float)oldArea;
+ float outputFactor = static_cast<float>(newArea)
+ / static_cast<float>(oldArea);
mOutput.minVal *= static_cast<float>(outputFactor);
mOutput.maxVal *= static_cast<float>(outputFactor);
}
diff --git a/src/particleemitterprop.h b/src/particleemitterprop.h
index 5327005bc..5b0b22e4f 100644
--- a/src/particleemitterprop.h
+++ b/src/particleemitterprop.h
@@ -66,29 +66,33 @@ template <typename T> struct ParticleEmitterProp
T value(int tick)
{
tick += changePhase;
- T val = (T) (minVal + (maxVal - minVal)
- * (rand() / ((double) RAND_MAX + 1)));
+ T val = static_cast<T>(minVal + (maxVal - minVal)
+ * (rand() / (static_cast<double>(RAND_MAX) + 1)));
switch (changeFunc)
{
case FUNC_SINE:
- val += (T) std::sin(M_PI * 2 * ((double)(tick % changePeriod)
- / (double)changePeriod)) * changeAmplitude;
+ val += static_cast<T>(std::sin(M_PI * 2 * (static_cast<double>(
+ tick % changePeriod) / static_cast<double>(
+ changePeriod)))) * changeAmplitude;
break;
case FUNC_SAW:
- val += (T) (changeAmplitude * ((double)(tick % changePeriod)
- / (double)changePeriod)) * 2 - changeAmplitude;
+ val += static_cast<T>(changeAmplitude * (static_cast<double>(
+ tick % changePeriod) / static_cast<double>(
+ changePeriod))) * 2 - changeAmplitude;
break;
case FUNC_TRIANGLE:
if ((tick % changePeriod) * 2 < changePeriod)
{
- val += changeAmplitude - (T)((tick % changePeriod)
- / (double)changePeriod) * changeAmplitude * 4;
+ val += changeAmplitude - static_cast<T>((
+ tick % changePeriod) / static_cast<double>(
+ changePeriod)) * changeAmplitude * 4;
}
else
{
- val += changeAmplitude * -3 + (T)((tick % changePeriod)
- / (double)changePeriod) * changeAmplitude * 4;
+ val += changeAmplitude * -3 + static_cast<T>((
+ tick % changePeriod) / static_cast<double>(
+ changePeriod)) * changeAmplitude * 4;
// I have no idea why this works but it does
}
break;
diff --git a/src/playerrelations.cpp b/src/playerrelations.cpp
index 0dd13e924..9259ae034 100644
--- a/src/playerrelations.cpp
+++ b/src/playerrelations.cpp
@@ -155,8 +155,8 @@ void PlayerRelationsManager::load(bool oldConfig)
clear();
mPersistIgnores = cfg->getValue(PERSIST_IGNORE_LIST, 1);
- mDefaultPermissions = (int) cfg->getValue(DEFAULT_PERMISSIONS,
- mDefaultPermissions);
+ mDefaultPermissions = static_cast<int>(cfg->getValue(DEFAULT_PERMISSIONS,
+ mDefaultPermissions));
std::string ignore_strategy_name = cfg->getValue(PLAYER_IGNORE_STRATEGY,
DEFAULT_IGNORE_STRATEGY);
diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp
index 6084f6092..d0cb84b90 100644
--- a/src/resources/emotedb.cpp
+++ b/src/resources/emotedb.cpp
@@ -83,17 +83,17 @@ void EmoteDB::load()
{
EmoteSprite *currentSprite = new EmoteSprite;
std::string file = paths.getStringValue("sprites")
- + (std::string) (const char*)
- spriteNode->xmlChildrenNode->content;
+ + (std::string) reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
currentSprite->sprite = AnimatedSprite::load(file,
- XML::getProperty(spriteNode, "variant", 0));
+ XML::getProperty(spriteNode, "variant", 0));
currentSprite->name = XML::getProperty(spriteNode, "name", "");
currentInfo->sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
- std::string particlefx = (const char*)(
- spriteNode->xmlChildrenNode->content);
+ std::string particlefx = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
currentInfo->particles.push_back(particlefx);
}
}
@@ -138,8 +138,8 @@ void EmoteDB::load()
{
EmoteSprite *currentSprite = new EmoteSprite;
std::string file = paths.getStringValue("sprites")
- + (std::string) (const char*)
- spriteNode->xmlChildrenNode->content;
+ + (std::string) reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
currentSprite->sprite = AnimatedSprite::load(file,
XML::getProperty(spriteNode, "variant", 0));
currentSprite->name = XML::getProperty(spriteNode, "name", "");
@@ -147,8 +147,8 @@ void EmoteDB::load()
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
- std::string particlefx = (const char*)(
- spriteNode->xmlChildrenNode->content);
+ std::string particlefx = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
currentInfo->particles.push_back(particlefx);
}
}
diff --git a/src/resources/image.cpp b/src/resources/image.cpp
index 86c5956ea..0cb8779ff 100644
--- a/src/resources/image.cpp
+++ b/src/resources/image.cpp
@@ -341,7 +341,8 @@ void Image::setAlpha(float alpha)
mSDLSurface->format,
&r, &g, &b, &a);
- a = (Uint8) (static_cast<float>(sourceAlpha) * mAlpha);
+ a = static_cast<Uint8>(static_cast<float>(
+ sourceAlpha) * mAlpha);
// Here is the pixel we want to set
(static_cast<Uint32 *>(mSDLSurface->pixels))[i] =
@@ -392,27 +393,29 @@ Image* Image::SDLmerge(Image *image, int x, int y)
surface_offset = offset_y * surface->w + offset_x;
// Retrieving a pixel to merge
- surface_pix = ((Uint32*) surface->pixels)[surface_offset];
- cur_pix = ((Uint32*) mSDLSurface->pixels)[current_offset];
+ surface_pix = (static_cast<Uint32*>(
+ surface->pixels))[surface_offset];
+ cur_pix = (static_cast<Uint32*>(
+ mSDLSurface->pixels))[current_offset];
// Retreiving each channel of the pixel using pixel format
- r = (Uint8)(((surface_pix & surface_fmt->Rmask) >>
+ r = static_cast<Uint8>(((surface_pix & surface_fmt->Rmask) >>
surface_fmt->Rshift) << surface_fmt->Rloss);
- g = (Uint8)(((surface_pix & surface_fmt->Gmask) >>
+ g = static_cast<Uint8>(((surface_pix & surface_fmt->Gmask) >>
surface_fmt->Gshift) << surface_fmt->Gloss);
- b = (Uint8)(((surface_pix & surface_fmt->Bmask) >>
+ b = static_cast<Uint8>(((surface_pix & surface_fmt->Bmask) >>
surface_fmt->Bshift) << surface_fmt->Bloss);
- a = (Uint8)(((surface_pix & surface_fmt->Amask) >>
+ a = static_cast<Uint8>(((surface_pix & surface_fmt->Amask) >>
surface_fmt->Ashift) << surface_fmt->Aloss);
// Retreiving previous alpha value
- p_a = (Uint8)(((cur_pix & current_fmt->Amask) >>
+ p_a = static_cast<Uint8>(((cur_pix & current_fmt->Amask) >>
current_fmt->Ashift) << current_fmt->Aloss);
// new pixel with no alpha or nothing on previous pixel
if (a == SDL_ALPHA_OPAQUE || (p_a == 0 && a > 0))
{
- ((Uint32 *)(surface->pixels))[current_offset] =
+ (static_cast<Uint32 *>(surface->pixels))[current_offset] =
SDL_MapRGBA(current_fmt, r, g, b, a);
}
else if (a > 0)
@@ -420,17 +423,20 @@ Image* Image::SDLmerge(Image *image, int x, int y)
f_a = static_cast<double>(a) / 255.0;
f_ca = 1.0 - f_a;
f_pa = static_cast<double>(p_a) / 255.0;
- p_r = (Uint8)(((cur_pix & current_fmt->Rmask) >>
+ p_r = static_cast<Uint8>(((cur_pix & current_fmt->Rmask) >>
current_fmt->Rshift) << current_fmt->Rloss);
- p_g = (Uint8)(((cur_pix & current_fmt->Gmask) >>
+ p_g = static_cast<Uint8>(((cur_pix & current_fmt->Gmask) >>
current_fmt->Gshift) << current_fmt->Gloss);
- p_b = (Uint8)(((cur_pix & current_fmt->Bmask) >>
+ p_b = static_cast<Uint8>(((cur_pix & current_fmt->Bmask) >>
current_fmt->Bshift) << current_fmt->Bloss);
- r = (Uint8)((double) p_r * f_ca * f_pa + (double)r * f_a);
- g = (Uint8)((double) p_g * f_ca * f_pa + (double)g * f_a);
- b = (Uint8)((double) p_b * f_ca * f_pa + (double)b * f_a);
+ r = static_cast<Uint8>(static_cast<double>(p_r) * f_ca
+ * f_pa + static_cast<double>(r) * f_a);
+ g = static_cast<Uint8>(static_cast<double>(p_g) * f_ca
+ * f_pa + static_cast<double>(g) * f_a);
+ b = static_cast<Uint8>(static_cast<double>(p_b) * f_ca
+ * f_pa + static_cast<double>(b) * f_a);
a = (a > p_a ? a : p_a);
- ((Uint32 *)(surface->pixels))[current_offset] =
+ (static_cast<Uint32 *>(surface->pixels))[current_offset] =
SDL_MapRGBA(current_fmt, r, g, b, a);
}
}
@@ -459,8 +465,8 @@ Image* Image::SDLgetScaledImage(int width, int height)
if (mSDLSurface)
{
scaledSurface = zoomSurface(mSDLSurface,
- (double) width / getWidth(),
- (double) height / getHeight(),
+ static_cast<double>(width) / getWidth(),
+ static_cast<double>(height) / getHeight(),
1);
// The load function takes care of the SDL<->OpenGL implementation
@@ -546,7 +552,7 @@ Image *Image::_SDLload(SDL_Surface *tmpImage)
for (int i = 0; i < tmpImage->w * tmpImage->h; ++i)
{
Uint8 r, g, b, a;
- SDL_GetRGBA(((Uint32*) tmpImage->pixels)[i],
+ SDL_GetRGBA((static_cast<Uint32*>(tmpImage->pixels))[i],
tmpImage->format, &r, &g, &b, &a);
if (a != 255)
diff --git a/src/resources/imageset.cpp b/src/resources/imageset.cpp
index d1fceea69..fa0cef349 100644
--- a/src/resources/imageset.cpp
+++ b/src/resources/imageset.cpp
@@ -55,7 +55,8 @@ Image* ImageSet::get(size_type i) const
{
if (i >= mImages.size())
{
- logger->log("Warning: No sprite %d in this image set", (int) i);
+ logger->log("Warning: No sprite %d in this image set",
+ static_cast<int>(i));
return NULL;
}
else
diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp
index bc5fb7905..d5d3de898 100644
--- a/src/resources/imagewriter.cpp
+++ b/src/resources/imagewriter.cpp
@@ -53,14 +53,14 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename)
info_ptr = png_create_info_struct(png_ptr);
if (!info_ptr)
{
- png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ png_destroy_write_struct(&png_ptr, static_cast<png_infopp>(NULL));
logger->log1("Could not create png_info");
return false;
}
if (setjmp(png_jmpbuf(png_ptr)))
{
- png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ png_destroy_write_struct(&png_ptr, static_cast<png_infopp>(NULL));
logger->log("problem writing to %s", filename.c_str());
return false;
}
@@ -95,8 +95,8 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename)
for (int i = 0; i < surface->h; i++)
{
- row_pointers[i] = (png_bytep)(Uint8 *)surface->pixels
- + i * surface->pitch;
+ row_pointers[i] = static_cast<png_bytep>(static_cast<Uint8 *>(
+ surface->pixels)) + i * surface->pitch;
}
png_write_image(png_ptr, row_pointers);
@@ -106,7 +106,7 @@ bool ImageWriter::writePNG(SDL_Surface *surface, const std::string &filename)
delete [] row_pointers;
- png_destroy_write_struct(&png_ptr, (png_infopp)NULL);
+ png_destroy_write_struct(&png_ptr, static_cast<png_infopp>(NULL));
if (SDL_MUSTLOCK(surface))
SDL_UnlockSurface(surface);
diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp
index 4ba254cf3..c7515fc6b 100644
--- a/src/resources/itemdb.cpp
+++ b/src/resources/itemdb.cpp
@@ -510,22 +510,20 @@ int parseSpriteName(std::string &name)
void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node)
{
std::string gender = XML::getProperty(node, "gender", "unisex");
- std::string filename = (const char*) node->xmlChildrenNode->content;
+ std::string filename = reinterpret_cast<const char*>(
+ node->xmlChildrenNode->content);
if (gender == "male" || gender == "unisex")
- {
itemInfo->setSprite(filename, GENDER_MALE);
- }
if (gender == "female" || gender == "unisex")
- {
itemInfo->setSprite(filename, GENDER_FEMALE);
- }
}
void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node)
{
std::string event = XML::getProperty(node, "event", "");
- std::string filename = (const char*) node->xmlChildrenNode->content;
+ std::string filename = reinterpret_cast<const char*>(
+ node->xmlChildrenNode->content);
if (event == "hit")
{
@@ -549,16 +547,16 @@ void loadFloorSprite(SpriteDisplay *display, xmlNodePtr floorNode)
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
SpriteReference *currentSprite = new SpriteReference;
- currentSprite->sprite
- = (const char*)spriteNode->xmlChildrenNode->content;
+ currentSprite->sprite = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
currentSprite->variant
= XML::getProperty(spriteNode, "variant", 0);
display->sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
- std::string particlefx
- = (const char*)spriteNode->xmlChildrenNode->content;
+ std::string particlefx = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
display->particles.push_back(particlefx);
}
}
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 7bcb08a0f..d66e2dbe3 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -84,7 +84,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength,
int ret;
z_stream strm;
- out = (unsigned char*) malloc(bufferSize);
+ out = static_cast<unsigned char*>(malloc(bufferSize));
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
@@ -124,7 +124,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength,
if (ret != Z_STREAM_END)
{
- out = (unsigned char*) realloc(out, bufferSize * 2);
+ out = static_cast<unsigned char*>(realloc(out, bufferSize * 2));
if (out == NULL)
{
@@ -200,8 +200,8 @@ Map *MapReader::readMap(const std::string &filename,
if (realFilename.find(".gz", realFilename.length() - 3) != std::string::npos)
{
// Inflate the gzipped map data
- inflatedSize =
- inflateMemory((unsigned char*) buffer, fileSize, inflated);
+ inflatedSize = inflateMemory(static_cast<unsigned char*>(buffer),
+ fileSize, inflated);
free(buffer);
if (inflated == NULL)
@@ -213,11 +213,11 @@ Map *MapReader::readMap(const std::string &filename,
}
else
{
- inflated = (unsigned char*) buffer;
+ inflated = static_cast<unsigned char*>(buffer);
inflatedSize = fileSize;
}
- XML::Document doc((char*) inflated, inflatedSize);
+ XML::Document doc(reinterpret_cast<char*>(inflated), inflatedSize);
free(inflated);
xmlNodePtr node = doc.rootNode();
@@ -456,9 +456,10 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
continue;
int len = static_cast<int>(strlen(
- (const char*)dataChild->content) + 1);
+ reinterpret_cast<const char*>(dataChild->content)) + 1);
unsigned char *charData = new unsigned char[len + 1];
- const char *charStart = (const char*) xmlNodeGetContent(dataChild);
+ const char *charStart = reinterpret_cast<const char*>(
+ xmlNodeGetContent(dataChild));
if (!charStart)
{
delete charData;
@@ -481,7 +482,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
int binLen;
unsigned char *binData = php3_base64_decode(charData,
- static_cast<int>(strlen((char*)charData)), &binLen);
+ static_cast<int>(strlen(reinterpret_cast<char*>(
+ charData))), &binLen);
delete[] charData;
@@ -537,7 +539,8 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
if (!dataChild)
continue;
- const char *data = (const char*) xmlNodeGetContent(dataChild);
+ const char *data = reinterpret_cast<const char*>(
+ xmlNodeGetContent(dataChild));
if (!data)
return;
diff --git a/src/resources/monsterdb.cpp b/src/resources/monsterdb.cpp
index 854450bfd..8990d679a 100644
--- a/src/resources/monsterdb.cpp
+++ b/src/resources/monsterdb.cpp
@@ -104,8 +104,8 @@ void MonsterDB::load()
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
SpriteReference *currentSprite = new SpriteReference;
- currentSprite->sprite
- = (const char*)spriteNode->xmlChildrenNode->content;
+ currentSprite->sprite = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
currentSprite->variant = XML::getProperty(
spriteNode, "variant", 0);
@@ -115,7 +115,8 @@ void MonsterDB::load()
{
std::string event = XML::getProperty(spriteNode, "event", "");
const char *filename;
- filename = (const char*) spriteNode->xmlChildrenNode->content;
+ filename = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
if (event == "hit")
{
@@ -156,8 +157,8 @@ void MonsterDB::load()
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
- display.particles.push_back(
- (const char*) spriteNode->xmlChildrenNode->content);
+ display.particles.push_back(reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content));
}
}
currentInfo->setDisplay(display);
diff --git a/src/resources/npcdb.cpp b/src/resources/npcdb.cpp
index 5a1ad9985..5c8c0e8c8 100644
--- a/src/resources/npcdb.cpp
+++ b/src/resources/npcdb.cpp
@@ -85,16 +85,16 @@ void NPCDB::load()
if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite"))
{
SpriteReference *currentSprite = new SpriteReference;
- currentSprite->sprite =
- (const char*)spriteNode->xmlChildrenNode->content;
+ currentSprite->sprite = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
currentSprite->variant =
XML::getProperty(spriteNode, "variant", 0);
display.sprites.push_back(currentSprite);
}
else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx"))
{
- std::string particlefx =
- (const char*)spriteNode->xmlChildrenNode->content;
+ std::string particlefx = reinterpret_cast<const char*>(
+ spriteNode->xmlChildrenNode->content);
display.particles.push_back(particlefx);
}
}
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 3ba99d248..0c1dafe4b 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -199,7 +199,7 @@ void ResourceManager::cleanOrphans()
bool ResourceManager::setWriteDir(const std::string &path)
{
- return (bool) PHYSFS_setWriteDir(path.c_str());
+ return static_cast<bool>(PHYSFS_setWriteDir(path.c_str()));
}
bool ResourceManager::addToSearchPath(const std::string &path, bool append)
@@ -278,7 +278,7 @@ void ResourceManager::searchAndRemoveArchives(const std::string &path,
bool ResourceManager::mkdir(const std::string &path)
{
- return (bool) PHYSFS_mkdir(path.c_str());
+ return static_cast<bool>(PHYSFS_mkdir(path.c_str()));
}
bool ResourceManager::exists(const std::string &path)
@@ -611,7 +611,8 @@ std::vector<std::string> ResourceManager::loadTextFile(
const std::string &fileName)
{
int contentsLength;
- char *fileContents = (char*)loadFile(fileName, contentsLength);
+ char *fileContents = static_cast<char*>(
+ loadFile(fileName, contentsLength));
std::vector<std::string> lines;
if (!fileContents)
diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp
index e7f3b7dc9..936e72ca0 100644
--- a/src/resources/wallpaper.cpp
+++ b/src/resources/wallpaper.cpp
@@ -158,7 +158,7 @@ std::string Wallpaper::getWallpaper(int width, int height)
{
// Return randomly a wallpaper between vector[0] and
// vector[vector.size() - 1]
- srand((unsigned) time(0));
+ srand(static_cast<unsigned>(time(0)));
return wallPaperVector[int(static_cast<double>(
wallPaperVector.size()) * rand() / (RAND_MAX + 1.0))];
}
diff --git a/src/simpleanimation.cpp b/src/simpleanimation.cpp
index 5d8f1dc33..9931f491c 100644
--- a/src/simpleanimation.cpp
+++ b/src/simpleanimation.cpp
@@ -83,7 +83,7 @@ void SimpleAnimation::setFrame(int frame)
if (frame < 0)
frame = 0;
- if ((unsigned)frame >= mAnimation->getLength())
+ if (static_cast<unsigned>(frame) >= mAnimation->getLength())
frame = mAnimation->getLength() - 1;
mAnimationPhase = frame;
mCurrentFrame = mAnimation->getFrame(mAnimationPhase);
@@ -104,8 +104,11 @@ void SimpleAnimation::update(int timePassed)
mAnimationTime -= mCurrentFrame->delay;
mAnimationPhase++;
- if ((unsigned)mAnimationPhase >= mAnimation->getLength())
+ if (static_cast<unsigned>(mAnimationPhase)
+ >= mAnimation->getLength())
+ {
mAnimationPhase = 0;
+ }
mCurrentFrame = mAnimation->getFrame(mAnimationPhase);
}
diff --git a/src/spellmanager.cpp b/src/spellmanager.cpp
index fb0a338d5..ef630fc67 100644
--- a/src/spellmanager.cpp
+++ b/src/spellmanager.cpp
@@ -52,7 +52,7 @@ SpellManager::~SpellManager()
TextCommand* SpellManager::getSpell(int spellId)
{
- if (spellId < 0 || (unsigned int)spellId >= mSpells.size())
+ if (spellId < 0 || static_cast<unsigned int>(spellId) >= mSpells.size())
return NULL;
return mSpells[spellId];
@@ -273,15 +273,16 @@ void SpellManager::load(bool oldConfig)
std::string icon = cfg->getValue("commandShortcutIcon"
+ toString(i), "");
- if ((TextCommandType)commandType == TEXT_COMMAND_MAGIC)
+ if (static_cast<TextCommandType>(commandType) == TEXT_COMMAND_MAGIC)
{
- addSpell(new TextCommand(i, symbol, cmd, (SpellTarget)targetType,
- icon, basicLvl, (MagicSchool)school, schoolLvl, mana));
+ addSpell(new TextCommand(i, symbol, cmd,
+ static_cast<SpellTarget>(targetType), icon, basicLvl,
+ static_cast<MagicSchool>(school), schoolLvl, mana));
}
else
{
- addSpell(new TextCommand(i, symbol, cmd, (SpellTarget)targetType,
- icon));
+ addSpell(new TextCommand(i, symbol, cmd,
+ static_cast<SpellTarget>(targetType), icon));
}
}
}
diff --git a/src/textparticle.cpp b/src/textparticle.cpp
index 7e05d81c7..3b28e5e05 100644
--- a/src/textparticle.cpp
+++ b/src/textparticle.cpp
@@ -42,8 +42,9 @@ bool TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const
if (!isAlive())
return false;
- int screenX = (int) mPos.x + offsetX;
- int screenY = (int) mPos.y - (int) mPos.z + offsetY;
+ int screenX = static_cast<int>(mPos.x) + offsetX;
+ int screenY = static_cast<int>(mPos.y) - static_cast<int>(mPos.z)
+ + offsetY;
float alpha = mAlpha * 255.0f;
diff --git a/src/textparticle.h b/src/textparticle.h
index 2ba2132bc..db9dc1766 100644
--- a/src/textparticle.h
+++ b/src/textparticle.h
@@ -43,7 +43,7 @@ class TextParticle : public Particle
// hack to improve text visibility
virtual int getPixelY() const
- { return (int) (mPos.y + mPos.z); }
+ { return static_cast<int>(mPos.y + mPos.z); }
private:
std::string mText; /**< Text of the particle. */
diff --git a/src/units.cpp b/src/units.cpp
index b9a995820..d1861b78b 100644
--- a/src/units.cpp
+++ b/src/units.cpp
@@ -186,7 +186,7 @@ std::string formatUnit(int value, int type)
std::string output;
struct UnitLevel pl = ud.levels[0];
ul = ud.levels[1];
- int levelAmount = (int) amount;
+ int levelAmount = static_cast<int>(amount);
int nextAmount = 0;
if (ul.count)
diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp
index 1221a7c7f..c7f34a5d9 100644
--- a/src/utils/base64.cpp
+++ b/src/utils/base64.cpp
@@ -47,8 +47,8 @@ unsigned char *php3_base64_encode(const unsigned char *string,
{
const unsigned char *current = string;
int i = 0;
- unsigned char *result = (unsigned char *)malloc(
- ((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char));
+ unsigned char *result = static_cast<unsigned char *>(malloc(
+ ((length + 3 - length % 3) * 4 / 3 + 1) * sizeof(char)));
while (length > 2)
{ /* keep going until we have less than 24 bits */
@@ -97,7 +97,7 @@ unsigned char *php3_base64_decode(const unsigned char *string,
int ch, i = 0, j = 0, k;
char *chp;
- unsigned char *result = (unsigned char *)malloc(length + 1);
+ unsigned char *result = static_cast<unsigned char *>(malloc(length + 1));
if (result == NULL)
return NULL;
diff --git a/src/utils/copynpaste.cpp b/src/utils/copynpaste.cpp
index 73ab1b35c..06c959017 100644
--- a/src/utils/copynpaste.cpp
+++ b/src/utils/copynpaste.cpp
@@ -301,7 +301,7 @@ static char* getSelection2(Display *dpy, Window us, Atom selection,
//printf(">>> Got %s: len=%lu left=%lu (event %i)\n", data,
// len, left, 50-max_events);
- return (char*)data;
+ return reinterpret_cast<char*>(data);
}
}
return NULL;
diff --git a/src/utils/sha256.cpp b/src/utils/sha256.cpp
index 0da2a18fe..80126479a 100644
--- a/src/utils/sha256.cpp
+++ b/src/utils/sha256.cpp
@@ -110,10 +110,10 @@ class SHA256Context
#define UNPACK32(x, str) \
{ \
- *((str) + 3) = (uint8_t) ((x) ); \
- *((str) + 2) = (uint8_t) ((x) >> 8); \
- *((str) + 1) = (uint8_t) ((x) >> 16); \
- *((str) + 0) = (uint8_t) ((x) >> 24); \
+ *((str) + 3) = static_cast<uint8_t> ((x) ); \
+ *((str) + 2) = static_cast<uint8_t> ((x) >> 8); \
+ *((str) + 1) = static_cast<uint8_t> ((x) >> 16); \
+ *((str) + 0) = static_cast<uint8_t> ((x) >> 24); \
}
#define PACK32(str, x) \
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 63924eb78..b5c2abd3e 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -74,10 +74,10 @@ const char *ipToString(int address)
static char asciiIP[18];
sprintf(asciiIP, "%i.%i.%i.%i",
- (unsigned char)(address),
- (unsigned char)(address >> 8),
- (unsigned char)(address >> 16),
- (unsigned char)(address >> 24));
+ static_cast<unsigned char>(address),
+ static_cast<unsigned char>(address >> 8),
+ static_cast<unsigned char>(address >> 16),
+ static_cast<unsigned char>(address >> 24));
return asciiIP;
}
@@ -209,7 +209,7 @@ const std::string encodeStr(unsigned int value, unsigned int size)
while (value);
while (buf.length() < size)
- buf += (char)start;
+ buf += static_cast<char>(start);
return buf;
}
@@ -325,7 +325,7 @@ bool getBoolFromString(const std::string &text)
else if (txt == "false" || txt == "no" || txt == "off" || txt == "0")
return false;
else
- return (bool) atoi(txt.c_str());
+ return static_cast<bool>(atoi(txt.c_str()));
}
void replaceSpecialChars(std::string &text)
@@ -347,7 +347,8 @@ void replaceSpecialChars(std::string &text)
if (idx + 1 < f && text[f] == ';')
{
std::string str = " ";
- str[0] = (char)atoi(text.substr(idx, f - idx).c_str());
+ str[0] = static_cast<char>(atoi(text.substr(
+ idx, f - idx).c_str()));
text = text.substr(0, pos1) + str + text.substr(f + 1);
pos1 += 1;
}
diff --git a/src/utils/xml.cpp b/src/utils/xml.cpp
index adba59fce..0ffd2acfc 100644
--- a/src/utils/xml.cpp
+++ b/src/utils/xml.cpp
@@ -40,7 +40,8 @@ namespace XML
if (useResman)
{
ResourceManager *resman = ResourceManager::getInstance();
- data = (char*) resman->loadFile(filename.c_str(), size);
+ data = static_cast<char*>(resman->loadFile(
+ filename.c_str(), size));
}
else
{
@@ -54,7 +55,7 @@ namespace XML
size = static_cast<int>(file.tellg());
file.seekg(0, std::ios::beg);
- data = (char*) malloc(size);
+ data = static_cast<char*>(malloc(size));
file.read(data, size);
file.close();
@@ -105,7 +106,7 @@ namespace XML
xmlChar *prop = xmlGetProp(node, BAD_CAST name);
if (prop)
{
- ret = atoi((char*)prop);
+ ret = atoi(reinterpret_cast<char*>(prop));
xmlFree(prop);
}
@@ -119,7 +120,7 @@ namespace XML
xmlChar *prop = xmlGetProp(node, BAD_CAST name);
if (prop)
{
- ret = atof((char*)prop);
+ ret = atof(reinterpret_cast<char*>(prop));
xmlFree(prop);
}
@@ -132,7 +133,7 @@ namespace XML
xmlChar *prop = xmlGetProp(node, BAD_CAST name);
if (prop)
{
- std::string val = (char*)prop;
+ std::string val = reinterpret_cast<char*>(prop);
xmlFree(prop);
return val;
}