summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client.cpp8
-rw-r--r--src/configuration.cpp2
-rw-r--r--src/configuration.h3
-rw-r--r--src/dropshortcut.cpp12
-rw-r--r--src/emoteshortcut.cpp11
-rw-r--r--src/event.cpp6
-rw-r--r--src/flooritem.cpp14
-rw-r--r--src/flooritem.h1
-rw-r--r--src/game.cpp326
-rw-r--r--src/graphics.cpp13
-rw-r--r--src/guild.cpp19
-rw-r--r--src/guildmanager.cpp5
-rw-r--r--src/item.cpp7
-rw-r--r--src/keyboardconfig.cpp2
-rw-r--r--src/localplayer.cpp102
-rw-r--r--src/logger.cpp2
16 files changed, 300 insertions, 233 deletions
diff --git a/src/client.cpp b/src/client.cpp
index bdba75aa8..47d0e9a21 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -1044,10 +1044,10 @@ int Client::exec()
if (!BeingInfo::unknown)
BeingInfo::unknown = new BeingInfo;
- Mana::Event evt(EVENT_STATECHANGE);
- evt.setInt("newState", STATE_LOAD_DATA);
- evt.setInt("oldState", mOldState);
- Mana::Event::trigger(CHANNEL_CLIENT, evt);
+ Mana::Event evt2(EVENT_STATECHANGE);
+ evt2.setInt("newState", STATE_LOAD_DATA);
+ evt2.setInt("oldState", mOldState);
+ Mana::Event::trigger(CHANNEL_CLIENT, evt2);
// Load XML databases
ColorDB::load();
diff --git a/src/configuration.cpp b/src/configuration.cpp
index 94c0dce37..a0167b9b0 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -585,4 +585,4 @@ void Configuration::removeListener(
const std::string &key, ConfigListener *listener)
{
mListenerMap[key].remove(listener);
-} \ No newline at end of file
+}
diff --git a/src/configuration.h b/src/configuration.h
index 2e694002d..1f03b7387 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -179,6 +179,9 @@ class ConfigurationObject
ConfigurationList *list = &(mContainerOptions[name]);
CONT container = empty;
+ if (!manager)
+ return container;
+
for (ConfigurationList::const_iterator it = list->begin();
it != list->end(); it++)
{
diff --git a/src/dropshortcut.cpp b/src/dropshortcut.cpp
index 48eed92bc..79f895490 100644
--- a/src/dropshortcut.cpp
+++ b/src/dropshortcut.cpp
@@ -150,6 +150,10 @@ void DropShortcut::dropItems(int cnt)
bool DropShortcut::dropItem(int cnt)
{
+ const Inventory *inv = PlayerInfo::getInventory();
+ if (!inv)
+ return false;
+
int itemId = 0;
unsigned char itemColor = 1;
while (mLastDropIndex < DROP_SHORTCUT_ITEMS && itemId < 1)
@@ -160,7 +164,7 @@ bool DropShortcut::dropItem(int cnt)
}
if (itemId > 0)
{
- Item *item = PlayerInfo::getInventory()->findItem(itemId, itemColor);
+ Item *item = inv->findItem(itemId, itemColor);
if (item && item->getQuantity() > 0)
{
Net::getInventoryHandler()->dropItem(item, cnt);
@@ -180,8 +184,7 @@ bool DropShortcut::dropItem(int cnt)
}
if (itemId > 0)
{
- Item *item = PlayerInfo::getInventory()->findItem(
- itemId, itemColor);
+ Item *item = inv->findItem(itemId, itemColor);
if (item && item->getQuantity() > 0)
{
Net::getInventoryHandler()->dropItem(item, cnt);
@@ -210,6 +213,9 @@ void DropShortcut::setItemSelected(Item *item)
void DropShortcut::setItem(int index)
{
+ if (index < 0 || index >= DROP_SHORTCUT_ITEMS)
+ return;
+
mItems[index] = mItemSelected;
mItemColors[index] = mItemColorSelected;
save();
diff --git a/src/emoteshortcut.cpp b/src/emoteshortcut.cpp
index 00d7264a4..352c373b5 100644
--- a/src/emoteshortcut.cpp
+++ b/src/emoteshortcut.cpp
@@ -34,7 +34,6 @@ EmoteShortcut *emoteShortcut;
EmoteShortcut::EmoteShortcut():
mEmoteSelected(0)
{
-// load();
for (int i = 0; i < SHORTCUT_EMOTES; i++)
mEmotes[i] = 0;
}
@@ -57,16 +56,6 @@ void EmoteShortcut::load()
j ++;
}
}
-
-/*
- for (int i = 0; i < SHORTCUT_EMOTES; i++)
- {
- unsigned char emoteId = static_cast<unsigned char>(
- serverConfig.getValue("emoteshortcut" + toString(i), i + 1));
- mEmotes[i] = emoteId;
-// mEmotes[i] = i + 1;
- }
-*/
}
void EmoteShortcut::save()
diff --git a/src/event.cpp b/src/event.cpp
index 5a1d673b2..6913e8660 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -56,7 +56,7 @@ int Event::getInt(const std::string &key) const throw (BadEvent)
if (it == mData.end())
throw BAD_KEY;
- if (it->second->getType() != VariableData::DATA_INT)
+ if (!it->second || it->second->getType() != VariableData::DATA_INT)
throw BAD_VALUE;
return static_cast<IntData *>(it->second)->getData();
@@ -78,7 +78,7 @@ const std::string &Event::getString(const std::string &key)
if (it == mData.end())
throw BAD_KEY;
- if (it->second->getType() != VariableData::DATA_STRING)
+ if (!! it->second || it->second->getType() != VariableData::DATA_STRING)
throw BAD_VALUE;
return static_cast<StringData *>(it->second)->getData();
@@ -99,7 +99,7 @@ double Event::getFloat(const std::string &key) const throw (BadEvent)
if (it == mData.end())
throw BAD_KEY;
- if (it->second->getType() != VariableData::DATA_FLOAT)
+ if (!it->second || it->second->getType() != VariableData::DATA_FLOAT)
throw BAD_VALUE;
return static_cast<FloatData *>(it->second)->getData();
diff --git a/src/flooritem.cpp b/src/flooritem.cpp
index 63112511e..9b11bdc9c 100644
--- a/src/flooritem.cpp
+++ b/src/flooritem.cpp
@@ -50,14 +50,13 @@ FloorItem::FloorItem(int id,
mX(x),
mY(y),
mMap(map),
-// mAlpha(1.0f),
+ mDropTime(cur_time),
mAmount(amount),
mPickupCount(0),
mColor(color),
- mShowMsg(true)
+ mShowMsg(true),
+ mHighlight(config.getBoolValue("floorItemsHighlight"))
{
- mDropTime = cur_time;
-
setMap(map);
if (map)
{
@@ -99,9 +98,8 @@ bool FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const
const int x = mX * mMap->getTileWidth() + offsetX;
const int y = mY * mMap->getTileHeight() + offsetY;
gcn::Font *font = 0;
- const bool highl = config.getBoolValue("floorItemsHighlight");
- if (highl)
+ if (mHighlight)
{
int curTime = cur_time;
font = gui->getFont();
@@ -118,7 +116,7 @@ bool FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const
{
graphics->setColor(gcn::Color(200, 80, 20,
80 + 10 * (curTime - mDropTime - 18)));
- graphics->fillRectangle(gcn::Rectangle(
+ graphics->fillRectangle(gcn::Rectangle(
x, y, dx, dy));
}
else if (curTime > mDropTime && curTime < mDropTime + 20)
@@ -133,7 +131,7 @@ bool FloorItem::draw(Graphics *graphics, int offsetX, int offsetY) const
const bool res = ActorSprite::draw(graphics, offsetX, offsetY);
- if (highl)
+ if (mHighlight)
{
if (font && mAmount > 1)
{
diff --git a/src/flooritem.h b/src/flooritem.h
index dd1db1b35..fb929268a 100644
--- a/src/flooritem.h
+++ b/src/flooritem.h
@@ -100,6 +100,7 @@ class FloorItem : public ActorSprite
unsigned mPickupCount;
unsigned char mColor;
bool mShowMsg;
+ bool mHighlight;
};
#endif
diff --git a/src/game.cpp b/src/game.cpp
index 6eda01640..4762055fa 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -383,12 +383,14 @@ Game::Game():
windowMenu = new WindowMenu;
// mWindowMenu = windowMenu;
- windowContainer->add(windowMenu);
+ if (windowContainer)
+ windowContainer->add(windowMenu);
initEngines();
// Initialize beings
- actorSpriteManager->setPlayer(player_node);
+ if (actorSpriteManager)
+ actorSpriteManager->setPlayer(player_node);
/*
* To prevent the server from sending data before the client
@@ -551,14 +553,12 @@ void Game::logic()
// Handle network stuff
if (!Net::getGameHandler()->isConnected())
{
-
if (Client::getState() == STATE_CHANGE_MAP)
return; // Not a problem here
if (Client::getState() != STATE_ERROR)
errorMessage = _("The connection to the server was lost.");
-
if (!disconnectedDialog)
{
if (viewport)
@@ -830,7 +830,7 @@ void Game::handleInput()
}
}
- if (!chatWindow->isInputFocused()
+ if ((!chatWindow || !chatWindow->isInputFocused())
&& !gui->getFocusHandler()->getModalFocused()
&& !player_node->getAwayMode())
{
@@ -847,7 +847,8 @@ void Game::handleInput()
else if (dialog)
dialog->action(gcn::ActionEvent(NULL, "ok"));
}
- if (keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT))
+ if (chatWindow && keyboard.isKeyActive(
+ keyboard.KEY_TOGGLE_CHAT))
{
if (!InventoryWindow::isAnyInputFocused())
{
@@ -864,10 +865,10 @@ void Game::handleInput()
}
}
- if ((!chatWindow->isInputFocused() &&
+ if (chatWindow && ((!chatWindow->isInputFocused() &&
!NpcDialog::isAnyInputFocused() &&
!InventoryWindow::isAnyInputFocused())
- || (event.key.keysym.mod & KMOD_ALT))
+ || (event.key.keysym.mod & KMOD_ALT)))
{
if (keyboard.isKeyActive(keyboard.KEY_PREV_CHAT_TAB))
{
@@ -900,14 +901,14 @@ void Game::handleInput()
switch (tKey)
{
case KeyboardConfig::KEY_SCROLL_CHAT_UP:
- if (chatWindow->isVisible())
+ if (chatWindow && chatWindow->isVisible())
{
chatWindow->scroll(-DEFAULT_CHAT_WINDOW_SCROLL);
used = true;
}
break;
case KeyboardConfig::KEY_SCROLL_CHAT_DOWN:
- if (chatWindow->isVisible())
+ if (chatWindow && chatWindow->isVisible())
{
chatWindow->scroll(DEFAULT_CHAT_WINDOW_SCROLL);
used = true;
@@ -916,21 +917,23 @@ void Game::handleInput()
break;
case KeyboardConfig::KEY_WINDOW_HELP:
// In-game Help
- if (helpWindow->isVisible())
- helpWindow->setVisible(false);
- else
+ if (helpWindow)
{
- helpWindow->loadHelp("index");
- helpWindow->requestMoveToTop();
+ if (helpWindow->isVisible())
+ {
+ helpWindow->setVisible(false);
+ }
+ else
+ {
+ helpWindow->loadHelp("index");
+ helpWindow->requestMoveToTop();
+ }
}
used = true;
break;
-
-
-
// Quitting confirmation dialog
case KeyboardConfig::KEY_QUIT:
- if (!chatWindow->isInputFocused())
+ if (!chatWindow || !chatWindow->isInputFocused())
{
if (viewport && viewport->isPopupMenuVisible())
{
@@ -948,31 +951,38 @@ void Game::handleInput()
break;
}
- if (keyboard.isEnabled() && !chatWindow->isInputFocused()
+ if (keyboard.isEnabled() && (!chatWindow
+ || !chatWindow->isInputFocused())
&& !gui->getFocusHandler()->getModalFocused()
&& mValidSpeed
- && !setupWindow->isVisible()
- && !player_node->getAwayMode()
+ && (!setupWindow || !setupWindow->isVisible())
+ && (!player_node || !player_node->getAwayMode())
&& !NpcDialog::isAnyInputFocused()
&& !InventoryWindow::isAnyInputFocused())
{
switch (tKey)
{
case KeyboardConfig::KEY_QUICK_DROP:
- dropShortcut->dropFirst();
+ if (dropShortcut)
+ dropShortcut->dropFirst();
break;
case KeyboardConfig::KEY_QUICK_DROPN:
- dropShortcut->dropItems();
+ if (dropShortcut)
+ dropShortcut->dropItems();
break;
case KeyboardConfig::KEY_SWITCH_QUICK_DROP:
- if (!player_node->getDisableGameModifiers())
- player_node->changeQuickDropCounter();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->changeQuickDropCounter();
+ }
break;
case KeyboardConfig::KEY_MAGIC_INMA1:
- actorSpriteManager->healTarget();
+ if (actorSpriteManager)
+ actorSpriteManager->healTarget();
setValidSpeed();
break;
@@ -986,85 +996,125 @@ void Game::handleInput()
break;
case KeyboardConfig::KEY_CRAZY_MOVES:
- player_node->crazyMove();
+ if (player_node)
+ player_node->crazyMove();
break;
case KeyboardConfig::KEY_CHANGE_CRAZY_MOVES_TYPE:
- if (!player_node->getDisableGameModifiers())
- player_node->changeCrazyMoveType();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->changeCrazyMoveType();
+ }
break;
case KeyboardConfig::KEY_CHANGE_PICKUP_TYPE:
- if (!player_node->getDisableGameModifiers())
- player_node->changePickUpType();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->changePickUpType();
+ }
break;
case KeyboardConfig::KEY_MOVE_TO_TARGET:
- if (!keyboard.isKeyActive(keyboard.KEY_TARGET_ATTACK)
- && !keyboard.isKeyActive(keyboard.KEY_ATTACK))
+ if (player_node)
{
- player_node->moveToTarget();
+ if (!keyboard.isKeyActive(
+ keyboard.KEY_TARGET_ATTACK)
+ && !keyboard.isKeyActive(keyboard.KEY_ATTACK))
+ {
+ player_node->moveToTarget();
+ }
}
break;
case KeyboardConfig::KEY_MOVE_TO_HOME:
- if (!keyboard.isKeyActive(keyboard.KEY_TARGET_ATTACK)
- && !keyboard.isKeyActive(keyboard.KEY_ATTACK))
+ if (player_node)
{
- player_node->moveToHome();
+ if (!keyboard.isKeyActive(
+ keyboard.KEY_TARGET_ATTACK)
+ && !keyboard.isKeyActive(keyboard.KEY_ATTACK))
+ {
+ player_node->moveToHome();
+ }
+ setValidSpeed();
}
- setValidSpeed();
break;
case KeyboardConfig::KEY_SET_HOME:
- player_node->setHome();
+ if (player_node)
+ player_node->setHome();
break;
case KeyboardConfig::KEY_INVERT_DIRECTION:
- if (!player_node->getDisableGameModifiers())
- player_node->invertDirection();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->invertDirection();
+ }
break;
case KeyboardConfig::KEY_CHANGE_ATTACK_WEAPON_TYPE:
- if (!player_node->getDisableGameModifiers())
- player_node->changeAttackWeaponType();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->changeAttackWeaponType();
+ }
break;
case KeyboardConfig::KEY_CHANGE_ATTACK_TYPE:
- if (!player_node->getDisableGameModifiers())
- player_node->changeAttackType();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->changeAttackType();
+ }
break;
case KeyboardConfig::KEY_CHANGE_FOLLOW_MODE:
- if (!player_node->getDisableGameModifiers())
- player_node->changeFollowMode();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->changeFollowMode();
+ }
break;
case KeyboardConfig::KEY_CHANGE_IMITATION_MODE:
- if (!player_node->getDisableGameModifiers())
- player_node->changeImitationMode();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->changeImitationMode();
+ }
break;
case KeyboardConfig::KEY_MAGIC_ATTACK:
- player_node->magicAttack();
+ if (player_node)
+ player_node->magicAttack();
break;
case KeyboardConfig::KEY_SWITCH_MAGIC_ATTACK:
- if (!player_node->getDisableGameModifiers())
- player_node->switchMagicAttack();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->switchMagicAttack();
+ }
break;
case KeyboardConfig::KEY_CHANGE_MOVE_TO_TARGET:
- if (!player_node->getDisableGameModifiers())
- player_node->changeMoveToTargetType();
+ if (player_node)
+ {
+ if (!player_node->getDisableGameModifiers())
+ player_node->changeMoveToTargetType();
+ }
break;
case KeyboardConfig::KEY_COPY_EQUIPED_OUTFIT:
- outfitWindow->copyFromEquiped();
+ if (outfitWindow)
+ outfitWindow->copyFromEquiped();
break;
case KeyboardConfig::KEY_DISABLE_GAME_MODIFIERS:
- player_node->switchGameModifiers();
+ if (player_node)
+ player_node->switchGameModifiers();
break;
case KeyboardConfig::KEY_CHANGE_AUDIO:
@@ -1072,14 +1122,20 @@ void Game::handleInput()
break;
case KeyboardConfig::KEY_AWAY:
- player_node->changeAwayMode();
- setValidSpeed();
+ if (player_node)
+ {
+ player_node->changeAwayMode();
+ setValidSpeed();
+ }
break;
case KeyboardConfig::KEY_CAMERA:
- if (!player_node->getDisableGameModifiers())
- viewport->toggleCameraMode();
- setValidSpeed();
+ if (player_node && viewport)
+ {
+ if (!player_node->getDisableGameModifiers())
+ viewport->toggleCameraMode();
+ setValidSpeed();
+ }
break;
default:
@@ -1088,15 +1144,15 @@ void Game::handleInput()
}
if (keyboard.isEnabled()
- && !chatWindow->isInputFocused()
+ && (!chatWindow || !chatWindow->isInputFocused())
&& !NpcDialog::isAnyInputFocused()
- && !player_node->getAwayMode()
+ && (!player_node || !player_node->getAwayMode())
&& !keyboard.isKeyActive(keyboard.KEY_TARGET)
&& !InventoryWindow::isAnyInputFocused())
{
// const int tKey = keyboard.getKeyIndex(event.key.keysym.sym);
- if (setupWindow->isVisible())
+ if (setupWindow && setupWindow->isVisible())
{
if (tKey == KeyboardConfig::KEY_WINDOW_SETUP)
{
@@ -1107,7 +1163,8 @@ void Game::handleInput()
else
{
// Do not activate shortcuts if tradewindow is visible
- if (itemShortcutWindow && !tradeWindow->isVisible()
+ if (itemShortcutWindow && tradeWindow
+ && !tradeWindow->isVisible()
&& !setupWindow->isVisible())
{
int num = itemShortcutWindow->getTabIndex();
@@ -1131,34 +1188,51 @@ void Game::handleInput()
switch (tKey)
{
case KeyboardConfig::KEY_PICKUP:
- player_node->pickUpItems();
+ if (player_node)
+ player_node->pickUpItems();
used = true;
break;
case KeyboardConfig::KEY_SIT:
// Player sit action
- if (keyboard.isKeyActive(keyboard.KEY_EMOTE))
- player_node->updateSit();
- else
- player_node->toggleSit();
+ if (player_node)
+ {
+ if (keyboard.isKeyActive(keyboard.KEY_EMOTE))
+ player_node->updateSit();
+ else
+ player_node->toggleSit();
+ }
used = true;
break;
case KeyboardConfig::KEY_HIDE_WINDOWS:
// Hide certain windows
- if (!chatWindow->isInputFocused())
+ if (!chatWindow || !chatWindow->isInputFocused())
{
- statusWindow->setVisible(false);
- inventoryWindow->setVisible(false);
- shopWindow->setVisible(false);
- skillDialog->setVisible(false);
- setupWindow->setVisible(false);
- equipmentWindow->setVisible(false);
- helpWindow->setVisible(false);
- debugWindow->setVisible(false);
- outfitWindow->setVisible(false);
- dropShortcutWindow->setVisible(false);
- spellShortcutWindow->setVisible(false);
- botCheckerWindow->setVisible(false);
- socialWindow->setVisible(false);
+ if (statusWindow)
+ statusWindow->setVisible(false);
+ if (inventoryWindow)
+ inventoryWindow->setVisible(false);
+ if (shopWindow)
+ shopWindow->setVisible(false);
+ if (skillDialog)
+ skillDialog->setVisible(false);
+ if (setupWindow)
+ setupWindow->setVisible(false);
+ if (equipmentWindow)
+ equipmentWindow->setVisible(false);
+ if (helpWindow)
+ helpWindow->setVisible(false);
+ if (debugWindow)
+ debugWindow->setVisible(false);
+ if (outfitWindow)
+ outfitWindow->setVisible(false);
+ if (dropShortcutWindow)
+ dropShortcutWindow->setVisible(false);
+ if (spellShortcutWindow)
+ spellShortcutWindow->setVisible(false);
+ if (botCheckerWindow)
+ botCheckerWindow->setVisible(false);
+ if (socialWindow)
+ socialWindow->setVisible(false);
}
break;
case KeyboardConfig::KEY_WINDOW_STATUS:
@@ -1222,7 +1296,8 @@ void Game::handleInput()
break;
case KeyboardConfig::KEY_PATHFIND:
// Find path to mouse (debug purpose)
- if (!player_node->getDisableGameModifiers())
+ if (!player_node || !player_node->
+ getDisableGameModifiers())
{
if (viewport)
viewport->toggleDebugPath();
@@ -1239,16 +1314,22 @@ void Game::handleInput()
unsigned int deflt = player_relations.getDefault();
if (deflt & PlayerRelation::TRADE)
{
- localChatTab->chatLog(
- _("Ignoring incoming trade requests"),
- BY_SERVER);
+ if (localChatTab)
+ {
+ localChatTab->chatLog(
+ _("Ignoring incoming trade requests"),
+ BY_SERVER);
+ }
deflt &= ~PlayerRelation::TRADE;
}
else
{
- localChatTab->chatLog(
- _("Accepting incoming trade requests"),
- BY_SERVER);
+ if (localChatTab)
+ {
+ localChatTab->chatLog(
+ _("Accepting incoming trade requests"),
+ BY_SERVER);
+ }
deflt |= PlayerRelation::TRADE;
}
@@ -1284,10 +1365,11 @@ void Game::handleInput()
if (event.active.gain)
{ // window restore
Client::setIsMinimized(false);
- if (player_node && !player_node->getAwayMode())
+ if (!player_node && !player_node->getAwayMode())
{
fpsLimit = config.getIntValue("fpslimit");
- player_node->setHalfAway(false);
+ if (player_node)
+ player_node->setHalfAway(false);
}
}
else
@@ -1309,12 +1391,20 @@ void Game::handleInput()
if (event.active.state & SDL_APPMOUSEFOCUS)
Client::setMouseFocused(event.active.gain);
- if (player_node->getAwayMode())
+ if (player_node)
{
- if (Client::getInputFocused() || Client::getMouseFocused())
- fpsLimit = config.getIntValue("fpslimit");
- else
- fpsLimit = config.getIntValue("altfpslimit");
+ if (player_node->getAwayMode())
+ {
+ if (Client::getInputFocused() || Client::getMouseFocused())
+ fpsLimit = config.getIntValue("fpslimit");
+ else
+ fpsLimit = config.getIntValue("altfpslimit");
+ Client::setFramerate(fpsLimit);
+ }
+ }
+ else
+ {
+ fpsLimit = config.getIntValue("fpslimit");
Client::setFramerate(fpsLimit);
}
}
@@ -1329,7 +1419,8 @@ void Game::handleInput()
{
try
{
- guiInput->pushInput(event);
+ if (guiInput)
+ guiInput->pushInput(event);
}
catch (const gcn::Exception &e)
{
@@ -1341,12 +1432,12 @@ void Game::handleInput()
} // End while
// If the user is configuring the keys then don't respond.
- if (!keyboard.isEnabled() || player_node->getAwayMode())
+ if (!player_node || !keyboard.isEnabled() || player_node->getAwayMode())
return;
if (keyboard.isKeyActive(keyboard.KEY_WEAR_OUTFIT)
|| keyboard.isKeyActive(keyboard.KEY_COPY_OUTFIT)
- || setupWindow->isVisible())
+ || (setupWindow && setupWindow->isVisible()))
{
return;
}
@@ -1355,7 +1446,7 @@ void Game::handleInput()
if (player_node->isAlive() && (!Being::isTalking()
|| keyboard.getKeyIndex(event.key.keysym.sym)
== KeyboardConfig::KEY_TALK)
- && !chatWindow->isInputFocused() && !quitDialog)
+ && chatWindow && !chatWindow->isInputFocused() && !quitDialog)
{
// Get the state of the keyboard keys
keyboard.refreshActiveKeys();
@@ -1602,19 +1693,24 @@ void Game::changeMap(const std::string &mapPath)
resetAdjustLevel();
// Clean up floor items, beings and particles
- actorSpriteManager->clear();
+ if (actorSpriteManager)
+ actorSpriteManager->clear();
// Close the popup menu on map change so that invalid options can't be
// executed.
- viewport->closePopupMenu();
- viewport->cleanHoverItems();
+ if (viewport)
+ {
+ viewport->closePopupMenu();
+ viewport->cleanHoverItems();
+ }
// Unset the map of the player so that its particles are cleared before
// being deleted in the next step
if (player_node)
player_node->setMap(0);
- particleEngine->clear();
+ if (particleEngine)
+ particleEngine->clear();
mMapName = mapPath;
@@ -1647,10 +1743,14 @@ void Game::changeMap(const std::string &mapPath)
socialWindow->setMap(newMap);
// Notify the minimap and actorSpriteManager about the map change
- minimap->setMap(newMap);
- actorSpriteManager->setMap(newMap);
- particleEngine->setMap(newMap);
- viewport->setMap(newMap);
+ if (minimap)
+ minimap->setMap(newMap);
+ if (actorSpriteManager)
+ actorSpriteManager->setMap(newMap);
+ if (particleEngine)
+ particleEngine->setMap(newMap);
+ if (viewport)
+ viewport->setMap(newMap);
// Initialize map-based particle effects
if (newMap)
@@ -1683,7 +1783,7 @@ void Game::changeMap(const std::string &mapPath)
void Game::updateHistory(SDL_Event &event)
{
- if (!player_node->getAttackType())
+ if (!player_node || !player_node->getAttackType())
return;
bool old = false;
@@ -1738,7 +1838,7 @@ void Game::checkKeys()
const int timeRange = 120;
const int cntInTime = 130;
- if (!player_node->getAttackType())
+ if (!player_node || !player_node->getAttackType())
return;
for (int f = 0; f < MAX_LASTKEYS; f ++)
diff --git a/src/graphics.cpp b/src/graphics.cpp
index 37fd72c08..efa1058a6 100644
--- a/src/graphics.cpp
+++ b/src/graphics.cpp
@@ -97,13 +97,14 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel)
logger->log1("Using video driver: unknown");
mDoubleBuffer = ((mTarget->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF);
- logger->log("Double buffer mode: %s",
- mDoubleBuffer ? "yes" : "no");
+ logger->log("Double buffer mode: %s", mDoubleBuffer ? "yes" : "no");
if (mTarget->format)
logger->log("Bits per pixel: %d", mTarget->format->BytesPerPixel);
const SDL_VideoInfo *vi = SDL_GetVideoInfo();
+ if (!vi)
+ return false;
logger->log("Possible to create hardware surfaces: %s",
((vi->hw_available) ? "yes" : "no"));
@@ -259,7 +260,8 @@ void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h)
const int iw = image->mBounds.w;
const int ih = image->mBounds.h;
- if (iw == 0 || ih == 0) return;
+ if (iw == 0 || ih == 0)
+ return;
for (int py = 0; py < h; py += ih) // Y position on pattern plane
{
@@ -346,8 +348,6 @@ void Graphics::drawImageRect(int x, int y, int w, int h,
Image *bottom, Image *left,
Image *center)
{
-// pushClipArea(gcn::Rectangle(x, y, w, h));
-
const bool drawMain = center && topLeft && topRight
&& bottomLeft && bottomRight;
@@ -390,8 +390,6 @@ void Graphics::drawImageRect(int x, int y, int w, int h,
x + w - bottomRight->getWidth(),
y + h - bottomRight->getHeight());
}
-
-// popClipArea();
}
void Graphics::drawImageRect(int x, int y, int w, int h,
@@ -601,6 +599,7 @@ void Graphics::calcTile(ImageVertexes *vert, int x, int y)
void Graphics::drawTile(ImageVertexes *vert)
{
+ // vert and img must be != 0
Image *img = vert->image;
DoubleRects *rects = &vert->sdl;
DoubleRects::const_iterator it = rects->begin();
diff --git a/src/guild.cpp b/src/guild.cpp
index a2d9149eb..5d129e11e 100644
--- a/src/guild.cpp
+++ b/src/guild.cpp
@@ -124,7 +124,7 @@ GuildMember *Guild::getMember(int id) const
itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr)->mId == id)
+ if ((*itr) && (*itr)->mId == id)
return (*itr);
++itr;
}
@@ -138,7 +138,7 @@ GuildMember *Guild::getMember(int accountId, int charId) const
itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr)->mId == accountId && (*itr)->mCharId == charId)
+ if ((*itr) && (*itr)->mId == accountId && (*itr)->mCharId == charId)
return (*itr);
++itr;
}
@@ -152,7 +152,7 @@ GuildMember *Guild::getMember(const std::string &name) const
itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr)->getName() == name)
+ if ((*itr) && (*itr)->getName() == name)
return (*itr);
++itr;
}
@@ -189,7 +189,7 @@ void Guild::removeMember(int id)
itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr)->mId == id)
+ if ((*itr) && (*itr)->mId == id)
{
GuildMember *member = *itr;
mMembers.erase(itr);
@@ -212,7 +212,7 @@ void Guild::removeMember(const std::string &name)
itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr)->getName() == name)
+ if ((*itr) && (*itr)->getName() == name)
{
GuildMember *member = *itr;
mMembers.erase(itr);
@@ -262,7 +262,7 @@ bool Guild::isMember(GuildMember *member) const
itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr)->mId == member->mId &&
+ if ((*itr) && (*itr)->mId == member->mId &&
(*itr)->getName() == member->getName())
{
return true;
@@ -279,7 +279,7 @@ bool Guild::isMember(int id) const
itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr)->mId == id)
+ if ((*itr) && (*itr)->mId == id)
return true;
++itr;
}
@@ -293,7 +293,7 @@ bool Guild::isMember(const std::string &name) const
itr_end = mMembers.end();
while (itr != itr_end)
{
- if ((*itr)->getName() == name)
+ if ((*itr) && (*itr)->getName() == name)
return true;
++itr;
}
@@ -309,7 +309,8 @@ void Guild::getNames(std::vector<std::string> &names) const
while (it != it_end)
{
- names.push_back((*it)->getName());
+ if (*it)
+ names.push_back((*it)->getName());
++it;
}
}
diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp
index c5d8f8bb6..4620de742 100644
--- a/src/guildmanager.cpp
+++ b/src/guildmanager.cpp
@@ -96,7 +96,7 @@ void GuildManager::reload()
if (socialWindow)
{
Guild *guild = Guild::getGuild(1);
- if (guild)
+ if (guild && socialWindow)
socialWindow->removeTab(guild);
}
delete mTab;
@@ -120,7 +120,8 @@ void GuildManager::chat(std::string msg)
void GuildManager::getNames(std::vector<std::string> &names)
{
Guild *guild = createGuild();
- guild->getNames(names);
+ if (guild)
+ guild->getNames(names);
}
void GuildManager::requestGuildInfo()
diff --git a/src/item.cpp b/src/item.cpp
index d76eaf401..45a10f837 100644
--- a/src/item.cpp
+++ b/src/item.cpp
@@ -72,14 +72,9 @@ void Item::setId(int id, unsigned char color)
ResourceManager *resman = ResourceManager::getInstance();
const ItemInfo &info = getInfo();
mTags = info.getTags();
-// logger->log("tag0=" + toString(mTags[1]));
-
-// for (int f = 0; f < mTags->size(); f ++)
-// logger->log("tag: %d", (*mTags)[f]);
SpriteDisplay display = info.getDisplay();
- std::string imagePath = paths.getStringValue("itemIcons")
- + display.image;
+ std::string imagePath = paths.getStringValue("itemIcons") + display.image;
std::string dye = combineDye2(imagePath, info.getDyeColorsString(color));
mImage = resman->getImage(dye);
mDrawImage = resman->getImage(dye);
diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp
index bf58c518a..ea9f9b90b 100644
--- a/src/keyboardconfig.cpp
+++ b/src/keyboardconfig.cpp
@@ -477,4 +477,4 @@ std::string KeyboardConfig::getKeyShortString(const std::string &key) const
else if (key == "unknown key")
return "u key";
return key;
-} \ No newline at end of file
+}
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index ff93cdbf1..8105f3291 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -93,6 +93,8 @@ LocalPlayer *player_node = NULL;
extern std::list<BeingCacheEntry*> beingInfoCache;
extern OkDialog *weightNotice;
extern int weightNoticeTime;
+extern MiniStatusWindow *miniStatusWindow;
+extern SkillDialog *skillDialog;
LocalPlayer::LocalPlayer(int id, int subtype):
Being(id, PLAYER, subtype, 0),
@@ -138,7 +140,10 @@ LocalPlayer::LocalPlayer(int id, int subtype):
mUpdateName = true;
mTextColor = &Theme::getThemeColor(Theme::PLAYER);
- mNameColor = &userPalette->getColor(UserPalette::SELF);
+ if (userPalette)
+ mNameColor = &userPalette->getColor(UserPalette::SELF);
+ else
+ mNameColor = 0;
mLastTargetX = 0;
mLastTargetY = 0;
@@ -345,8 +350,11 @@ void LocalPlayer::logic()
if (mEnableAdvert && !mBlockAdvert && mAdvertTime < cur_time)
{
Uint8 smile = FLAG_SPECIAL;
- if (mTradebot && shopWindow && !shopWindow->isShopEmpty())
+ if (mTradebot && shopWindow && shopWindow
+ && !shopWindow->isShopEmpty())
+ {
smile += FLAG_SHOP;
+ }
if (mAwayMode)
smile += FLAG_AWAY;
@@ -391,8 +399,6 @@ void LocalPlayer::setGMLevel(int level)
Position LocalPlayer::getNextWalkPosition(unsigned char dir)
{
- // check for mMap?
-
// Compute where the next tile will be set.
int dx = 0, dy = 0;
if (dir & Being::UP)
@@ -1040,13 +1046,13 @@ void LocalPlayer::setDestination(int x, int y)
else if (mInvertDirection == 1)
{
Uint8 newDir = 0;
- if (mDirection&UP)
+ if (mDirection & UP)
newDir |= DOWN;
- if (mDirection&LEFT)
+ if (mDirection & LEFT)
newDir |= RIGHT;
- if (mDirection&DOWN)
+ if (mDirection & DOWN)
newDir |= UP;
- if (mDirection&RIGHT)
+ if (mDirection & RIGHT)
newDir |= LEFT;
Net::getPlayerHandler()->setDestination(x, y, newDir);
@@ -1116,8 +1122,8 @@ void LocalPlayer::setWalkingDir(unsigned char dir)
startWalking(dir);
}
#ifdef MANASERV_SUPPORT
- else if (mAction == MOVE
- && (Net::getNetworkType() == ServerInfo::MANASERV))
+ else if (mAction == MOVE && (Net::getNetworkType()
+ == ServerInfo::MANASERV))
{
nextTile(dir);
}
@@ -1427,7 +1433,7 @@ void LocalPlayer::pickedUp(const ItemInfo &itemInfo, int amount,
msg = N_("Unknown problem picking up item.");
break;
}
- if (config.getBoolValue("showpickupchat"))
+ if (localChatTab && config.getBoolValue("showpickupchat"))
localChatTab->chatLog(_(msg), BY_SERVER);
if (mMap && config.getBoolValue("showpickupparticle"))
@@ -1545,9 +1551,6 @@ void LocalPlayer::setGotoTarget(Being *target)
}
}
-extern MiniStatusWindow *miniStatusWindow;
-extern SkillDialog *skillDialog;
-
void LocalPlayer::handleStatusEffect(StatusEffect *effect, int effectId)
{
Being::handleStatusEffect(effect, effectId);
@@ -1762,9 +1765,12 @@ void LocalPlayer::moveToTarget(unsigned int dist)
if (mTarget)
{
- debugPath = mMap->findPath(static_cast<int>(playerPos.x - 16) / 32,
+ if (mMap)
+ {
+ debugPath = mMap->findPath(static_cast<int>(playerPos.x - 16) / 32,
static_cast<int>(playerPos.y - 32) / 32,
mTarget->getTileX(), mTarget->getTileY(), getWalkMask(), 0);
+ }
if (debugPath.size() < dist)
return;
@@ -1812,7 +1818,7 @@ void LocalPlayer::moveToHome()
{
moveTo(mCrossX, mCrossY);
}
- else
+ else if (mMap)
{
std::map<std::string, Vector>::const_iterator iter =
mHomes.find(mMap->getProperty("_realfilename"));
@@ -1929,20 +1935,24 @@ void LocalPlayer::changeEquipmentBeforeAttack(Being* target)
if (dx * dx + dy * dy < 8)
allowSword = true;
+ const Inventory *inv = PlayerInfo::getInventory();
+ if (!inv)
+ return;
+
//if attack distance for sword
if (allowSword)
{
//finding sword
- item = PlayerInfo::getInventory()->findItem(571, 0);
+ item = inv->findItem(571, 0);
if (!item)
- item = PlayerInfo::getInventory()->findItem(570, 0);
+ item = inv->findItem(570, 0);
if (!item)
- item = PlayerInfo::getInventory()->findItem(579, 0);
+ item = inv->findItem(579, 0);
if (!item)
- item = PlayerInfo::getInventory()->findItem(536, 0);
+ item = inv->findItem(536, 0);
//no swords
if (!item)
@@ -1950,21 +1960,17 @@ void LocalPlayer::changeEquipmentBeforeAttack(Being* target)
//if sword not equiped
if (!item->isEquipped())
- {
Net::getInventoryHandler()->equipItem(item);
- }
//if need equip shield too
if (mAttackWeaponType == 3)
{
//finding shield
- item = PlayerInfo::getInventory()->findItem(601, 0);
+ item = inv->findItem(601, 0);
if (!item)
- item = PlayerInfo::getInventory()->findItem(602, 0);
+ item = inv->findItem(602, 0);
if (item && !item->isEquipped())
- {
Net::getInventoryHandler()->equipItem(item);
- }
}
}
@@ -1972,29 +1978,22 @@ void LocalPlayer::changeEquipmentBeforeAttack(Being* target)
else
{
//finding bow
- item = PlayerInfo::getInventory()->findItem(545, 0);
+ item = inv->findItem(545, 0);
if (!item)
- item = PlayerInfo::getInventory()->findItem(530, 0);
+ item = inv->findItem(530, 0);
//no bow
if (!item)
return;
if (!item->isEquipped())
- {
Net::getInventoryHandler()->equipItem(item);
- }
}
-
}
-
void LocalPlayer::crazyMove()
{
-// if (!allowAction())
-// return;
-
bool oldDisableCrazyMove = mDisableCrazyMove;
mDisableCrazyMove = true;
switch(mCrazyMoveType)
@@ -2251,7 +2250,7 @@ void LocalPlayer::crazyMove7()
void LocalPlayer::crazyMove8()
{
- if (mAction == MOVE)
+ if (mAction == MOVE || !mMap)
return;
int idx = 0;
int dist = 1;
@@ -2379,7 +2378,7 @@ void LocalPlayer::crazyMoveA()
if (mAction == MOVE)
return;
- if (mMoveProgram.length() == 0)
+ if (mMoveProgram.empty())
return;
if (mCrazyMoveState >= mMoveProgram.length())
@@ -2609,11 +2608,8 @@ void LocalPlayer::crazyMoveA()
mCrazyMoveState ++;
}
-// mCrazyMoveState ++;
if (mCrazyMoveState >= mMoveProgram.length())
mCrazyMoveState = 0;
-
-// debugMsg("mCrazyMoveState: " + toString(mCrazyMoveState));
}
bool LocalPlayer::isReachable(int x, int y, int maxCost)
@@ -2858,8 +2854,6 @@ void LocalPlayer::specialMove(unsigned char direction)
}
else
{
-// if (direction != 0 && getInvertDirection() == 4)
-// crazyMove();
setWalkingDir(direction);
}
@@ -2980,7 +2974,6 @@ void LocalPlayer::setMap(Map *map)
Being::setMap(map);
updateNavigateList();
-// updateCoords();
}
void LocalPlayer::setHome()
@@ -3012,8 +3005,6 @@ void LocalPlayer::setHome()
mMap->updatePortalTile("", MapItem::EMPTY,
static_cast<int>(pos.x), static_cast<int>(pos.y));
-// if (specialLayer)
-// specialLayer->setTile(pos.x, pos.y, MapItem::EMPTY);
mHomes.erase(key);
socialWindow->removePortal(static_cast<int>(pos.x),
static_cast<int>(pos.y));
@@ -3031,8 +3022,6 @@ void LocalPlayer::setHome()
mHomes[key] = pos;
mMap->updatePortalTile("home", MapItem::HOME,
getTileX(), getTileY());
-// if (specialLayer)
-// specialLayer->setTile(getTileX(), getTileY(), MapItem::HOME);
socialWindow->addPortal(getTileX(), getTileY());
}
MapItem *mapItem = specialLayer->getTile(getTileX(), getTileY());
@@ -3048,8 +3037,6 @@ void LocalPlayer::setHome()
{
MapItem *mapItem = specialLayer->getTile(getTileX(), getTileY());
int type = 0;
-// if (!mapItem)
-// return;
std::map<std::string, Vector>::iterator iter = mHomes.find(key);
if (iter != mHomes.end() && getTileX() == pos.x && getTileY() == pos.y)
@@ -3060,8 +3047,6 @@ void LocalPlayer::setHome()
if (!mapItem || mapItem->getType() == MapItem::EMPTY)
{
-// if (mAction == SIT)
-// type = MapItem::HOME;
if (mDirection & UP)
type = MapItem::ARROW_UP;
else if (mDirection & LEFT)
@@ -3076,7 +3061,6 @@ void LocalPlayer::setHome()
type = MapItem::EMPTY;
}
mMap->updatePortalTile("", type, getTileX(), getTileY());
-// mapItem = specialLayer->getTile(getTileX(), getTileY());
if (type != MapItem::EMPTY)
{
@@ -3350,8 +3334,7 @@ void LocalPlayer::updateCoords()
if (mShowNavigePath)
{
- if (getTileX() != mOldTileX || getTileY() != mOldTileY)
-// if (playerPos.x != mOldX || playerPos.y != mOldY)
+ if (mMap && (getTileX() != mOldTileX || getTileY() != mOldTileY))
{
SpecialLayer *tmpLayer = mMap->getTempLayer();
if (!tmpLayer)
@@ -3575,17 +3558,9 @@ void LocalPlayer::imitateOutfit(Being *player, int sprite)
if (mImitationMode == 1 && !player_imitated.empty()
&& player->getName() == player_imitated)
{
-// logger->log("have equip %d", sprite);
-// std::string filename = ItemDB::get(
-// player->getId()).getSprite(mGender);
-// logger->log("LocalPlayer::imitateOutfit sprite: " + toString(sprite));
-// logger->log("LocalPlayer::imitateOutfit sprite: " + toString(player->getNumberOfLayers()));
-// logger->log("LocalPlayer::imitateOutfit spritecount: " + toString(player->getSpritesCount()));
if (sprite < 0 || sprite >= player->getNumberOfLayers())
-// if (sprite < 0 || sprite >= 20)
return;
-// logger->log("after check");
AnimatedSprite *equipmentSprite = dynamic_cast<AnimatedSprite *>(player
->getSprite(sprite));
@@ -3635,7 +3610,8 @@ void LocalPlayer::imitateOutfit(Being *player, int sprite)
void LocalPlayer::followMoveTo(Being *being, int x, int y)
{
- if (!mPlayerFollowed.empty() && being->getName() == mPlayerFollowed)
+ if (being && !mPlayerFollowed.empty()
+ && being->getName() == mPlayerFollowed)
{
mPickUpTarget = 0;
setDestination(x, y);
diff --git a/src/logger.cpp b/src/logger.cpp
index 6790d622a..2ec5c331e 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -51,9 +51,7 @@ Logger::Logger():
Logger::~Logger()
{
if (mLogFile.is_open())
- {
mLogFile.close();
- }
}
void Logger::setLogFile(const std::string &logFilename)