From 6dd62fd1082bad225e02312094332630b0debd07 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 21 Aug 2011 23:20:57 +0300 Subject: Show dead hp bar if monster have current damage more than counted maximum value. --- src/being.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index d3181c32a..cc88d8f6e 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -2039,14 +2039,28 @@ void Being::drawHpBar(Graphics *graphics, int maxHP, int hp, int damage, int dx = static_cast(static_cast(width) / p); + if (!damage || (!hp && maxHP == damage)) + { + graphics->setColor(userPalette->getColorWithAlpha(color1)); + + graphics->fillRectangle(gcn::Rectangle( + x, y, dx, height)); + return; + } + else if (width - dx <= 0) + { + graphics->setColor(userPalette->getColorWithAlpha(color2)); + + graphics->fillRectangle(gcn::Rectangle( + x, y, width, height)); + return; + } + graphics->setColor(userPalette->getColorWithAlpha(color1)); graphics->fillRectangle(gcn::Rectangle( x, y, dx, height)); - if (width - dx <= 0) - return; - graphics->setColor(userPalette->getColorWithAlpha(color2)); graphics->fillRectangle(gcn::Rectangle( -- cgit v1.2.3-70-g09d2 From 12bf548533867a2eb3a1c354b778ef7f9157322a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 26 Aug 2011 16:57:05 +0300 Subject: Basic support for guild bot integration. Not working context menu actions, chat commands, auto complete. --- manaplus.cbp | 4 + src/CMakeLists.txt | 4 + src/Makefile.am | 4 + src/being.cpp | 6 +- src/client.cpp | 16 +++ src/client.h | 2 + src/game.cpp | 24 ++-- src/gui/chatwindow.cpp | 6 +- src/gui/popupmenu.cpp | 77 ++++++++--- src/gui/setup_other.cpp | 6 + src/gui/socialwindow.cpp | 111 +++++++++++++++- src/gui/widgets/guildtab.cpp | 127 ++++++++++++++++++ src/gui/widgets/guildtab.h | 52 ++++++++ src/guild.cpp | 6 +- src/guild.h | 9 +- src/guildmanager.cpp | 309 +++++++++++++++++++++++++++++++++++++++++++ src/guildmanager.h | 81 ++++++++++++ src/net/ea/chathandler.cpp | 7 + src/net/ea/guildhandler.cpp | 1 + src/utils/stringutils.cpp | 54 ++++++++ src/utils/stringutils.h | 8 ++ 21 files changed, 878 insertions(+), 36 deletions(-) create mode 100644 src/gui/widgets/guildtab.cpp create mode 100644 src/gui/widgets/guildtab.h create mode 100644 src/guildmanager.cpp create mode 100644 src/guildmanager.h (limited to 'src/being.cpp') diff --git a/manaplus.cbp b/manaplus.cbp index 8ed18dbed..d05cccd3b 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -310,6 +310,8 @@ + + @@ -394,6 +396,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 413a72f65..7f59135b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,6 +137,8 @@ SET(SRCS gui/widgets/emoteshortcutcontainer.h gui/widgets/flowcontainer.cpp gui/widgets/flowcontainer.h + gui/widgets/guildtab.cpp + gui/widgets/guildtab.h gui/widgets/horizontcontainer.cpp gui/widgets/horizontcontainer.h gui/widgets/icon.cpp @@ -508,6 +510,8 @@ SET(SRCS guichanfwd.h guild.cpp guild.h + guildmanager.cpp + guildmanager.h imageparticle.cpp imageparticle.h imagesprite.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 57bb4e620..7d0c1634b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -140,6 +140,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/emoteshortcutcontainer.h \ gui/widgets/flowcontainer.cpp \ gui/widgets/flowcontainer.h \ + gui/widgets/guildtab.cpp \ + gui/widgets/guildtab.h \ gui/widgets/horizontcontainer.cpp \ gui/widgets/horizontcontainer.h \ gui/widgets/icon.cpp \ @@ -515,6 +517,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ guichanfwd.h \ guild.cpp \ guild.h \ + guildmanager.cpp \ + guildmanager.h \ imageparticle.cpp \ imageparticle.h \ imagesprite.cpp \ diff --git a/src/being.cpp b/src/being.cpp index cc88d8f6e..1924a8944 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -871,8 +871,12 @@ void Being::updateGuild() return; } if (guild->getMember(getName())) + { setGuild(guild); - updateColors(); + if (!guild->getName().empty()) + mGuildName = guild->getName(); + updateColors(); + } } void Being::setGuild(Guild *guild) diff --git a/src/client.cpp b/src/client.cpp index 0e871ed91..385af99ad 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -30,6 +30,7 @@ #include "event.h" #include "game.h" #include "guild.h" +#include "guildmanager.h" #include "graphicsvertexes.h" #include "itemshortcut.h" #include "keyboardconfig.h" @@ -793,6 +794,10 @@ int Client::exec() if (mumbleManager) mumbleManager->setServer(mCurrentServer.hostname); + if (!guildManager) + guildManager = new GuildManager(); + guildManager->init(); + if (!mConfigAutoSaved) { mConfigAutoSaved = true; @@ -2180,3 +2185,14 @@ void Client::closeDialogs() NpcDialog::closeAll(); SellDialog::closeAll(); } + +bool Client::isTmw() +{ + if (getServerName() == "server.themanaworld.org" + || Client::getServerName() == "themanaworld.org" + || Client::getServerName() == "81.161.192.4") + { + return true; + } + return false; +} diff --git a/src/client.h b/src/client.h index 986e06cfb..3edf12674 100644 --- a/src/client.h +++ b/src/client.h @@ -260,6 +260,8 @@ public: static void setFramerate(int fpsLimit); + static bool isTmw(); + void optionChanged(const std::string &name); void action(const gcn::ActionEvent &event); diff --git a/src/game.cpp b/src/game.cpp index 82f919976..c933378e6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -31,14 +31,13 @@ #include "client.h" #include "commandhandler.h" #include "configuration.h" +#include "dropshortcut.h" #include "effectmanager.h" -#include "event.h" -#include "spellmanager.h" #include "emoteshortcut.h" +#include "event.h" +#include "guildmanager.h" #include "graphics.h" #include "itemshortcut.h" -#include "dropshortcut.h" -#include "spellshortcut.h" #include "joystick.h" #include "keyboardconfig.h" #include "localplayer.h" @@ -47,6 +46,8 @@ #include "particle.h" #include "playerrelations.h" #include "sound.h" +#include "spellmanager.h" +#include "spellshortcut.h" #include "gui/botcheckerwindow.h" #include "gui/buyselldialog.h" @@ -156,6 +157,7 @@ Particle *particleEngine = NULL; EffectManager *effectManager = NULL; SpellManager *spellManager = NULL; Viewport *viewport = NULL; /**< Viewport on the map. */ +GuildManager *guildManager = NULL; ChatTab *localChatTab = NULL; ChatTab *debugChatTab = NULL; @@ -175,6 +177,8 @@ static void initEngines() commandHandler = new CommandHandler; channelManager = new ChannelManager; effectManager = new EffectManager; + if (!guildManager) + guildManager = new GuildManager; particleEngine = new Particle(NULL); particleEngine->setupEngine(); @@ -393,6 +397,9 @@ Game::Game(): setupWindow->setInGame(true); clearKeysArray(); + if (guildManager && guildManager->getEnableGuildBot()) + guildManager->requestGuildInfo(); + Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_CONSTRUCTED)); } @@ -411,16 +418,17 @@ Game::~Game() del_0(actorSpriteManager) if (Client::getState() != STATE_CHANGE_MAP) del_0(player_node) + del_0(guildManager) del_0(channelManager) del_0(commandHandler) - del_0(effectManager); + del_0(effectManager) del_0(joystick) del_0(particleEngine) del_0(viewport) del_0(mCurrentMap) - del_0(spellManager); - del_0(spellShortcut); - del_0(mumbleManager); + del_0(spellManager) + del_0(spellShortcut) + del_0(mumbleManager) Being::clearCache(); diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 8896ca028..9c75320a6 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -1459,12 +1459,8 @@ void ChatWindow::saveState() std::string ChatWindow::doReplace(const std::string &msg) { - if (Client::getServerName() == "server.themanaworld.org" - || Client::getServerName() == "themanaworld.org" - || Client::getServerName() == "81.161.192.4") - { + if (Client::isTmw()) return msg; - } std::string str = msg; replaceSpecialChars(str); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 61769bc7e..a3041fcf7 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -27,6 +27,7 @@ #include "being.h" #include "dropshortcut.h" #include "guild.h" +#include "guildmanager.h" #include "flooritem.h" #include "graphics.h" #include "item.h" @@ -224,14 +225,22 @@ void PopupMenu::showPopup(int x, int y, Being *being) { mBrowserBox->addRow(strprintf( "@@guild-kick|%s@@", _("Kick from guild"))); - mBrowserBox->addRow(strprintf("@@guild-pos|%s >@@", - _("Change pos in guild"))); + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf( + "@@guild-pos|%s >@@", + _("Change pos in guild"))); + } } } else { - mBrowserBox->addRow(strprintf( - "@@guild|%s@@", _("Invite to guild"))); + if (guild2->getServerGuild() + || (guildManager && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild|%s@@", _("Invite to guild"))); + } } } @@ -435,15 +444,26 @@ void PopupMenu::showPlayerPopup(int x, int y, std::string nick) { if (guild2->getMember(mNick)) { - mBrowserBox->addRow(strprintf( - "@@guild-kick|%s@@", _("Kick from guild"))); - mBrowserBox->addRow(strprintf( - "@@guild-pos|%s >@@", _("Change pos in guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild-kick|%s@@", _("Kick from guild"))); + } + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf( + "@@guild-pos|%s >@@", _("Change pos in guild"))); + } } else { - mBrowserBox->addRow(strprintf( - "@@guild|%s@@", _("Invite to guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild|%s@@", _("Invite to guild"))); + } } } @@ -725,16 +745,27 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) { if (guild1->getId() == guild2->getId()) { - mBrowserBox->addRow(strprintf( - "@@guild-kick|%s@@", _("Kick from guild"))); - mBrowserBox->addRow(strprintf( - "@@guild-pos|%s >@@", _("Change pos in guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild-kick|%s@@", _("Kick from guild"))); + } + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf("@@guild-pos|%s >@@", + _("Change pos in guild"))); + } } } else { - mBrowserBox->addRow(strprintf( - "@@guild|%s@@", _("Invite to guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild|%s@@", _("Invite to guild"))); + } } } } @@ -897,7 +928,12 @@ void PopupMenu::handleLink(const std::string &link, { const Guild *guild = player_node->getGuild(); if (guild) - Net::getGuildHandler()->invite(guild->getId(), mNick); + { + if (guild->getServerGuild()) + Net::getGuildHandler()->invite(guild->getId(), mNick); + else if (guildManager) + guildManager->invite(mNick); + } } } else if (link == "nuke" && being) @@ -1263,7 +1299,12 @@ void PopupMenu::handleLink(const std::string &link, { const Guild *guild = player_node->getGuild(); if (guild) - Net::getGuildHandler()->kick(guild->getMember(mNick)); + { + if (guild->getServerGuild()) + Net::getGuildHandler()->kick(guild->getMember(mNick)); + else if (guildManager) + guildManager->kick(mNick); + } } } else if (link == "enable highlight" && mTab) diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index b405f5045..05ec9d672 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -145,6 +145,12 @@ Setup_Other::Setup_Other() this, "logNpcInGuiEvent"); + new SetupItemLabel(_("Bots support"), "", this); + + new SetupItemCheckBox(_("Enable guild bot support and disable native " + "guild support"), "", "enableGuildBot", this, + "enableGuildBotEvent", false); + new SetupItemLabel(_("Other"), "", this); new SetupItemCheckBox(_("Enable server side attack"), "", diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index e3aa69b30..aa26fa051 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -206,6 +206,109 @@ private: Guild *mGuild; }; +class GuildTab2 : public SocialTab, public gcn::ActionListener +{ +public: + GuildTab2(Guild *guild): + mGuild(guild) + { + setCaption(_("Guild")); + + setTabColor(&Theme::getThemeColor(Theme::GUILD_SOCIAL_TAB)); + + mList = new AvatarListBox(guild); + mScroll = new ScrollArea(mList); + + mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + } + + ~GuildTab2() + { + delete mList; + mList = 0; + delete mScroll; + mScroll = 0; + } + + void action(const gcn::ActionEvent &event) + { +/* + if (event.getId() == "do invite") + { + std::string name = mInviteDialog->getText(); + Net::getGuildHandler()->invite(mGuild->getId(), name); + + if (localChatTab) + { + localChatTab->chatLog(strprintf( + _("Invited user %s to guild %s."), + name.c_str(), mGuild->getName().c_str()), BY_SERVER); + } + mInviteDialog = 0; + } + else if (event.getId() == "~do invite") + { + mInviteDialog = 0; + } + else if (event.getId() == "yes") + { + Net::getGuildHandler()->leave(mGuild->getId()); + if (localChatTab) + { + localChatTab->chatLog(strprintf(_("Guild %s quit requested."), + mGuild->getName().c_str()), BY_SERVER); + } + mConfirmDialog = 0; + } + else if (event.getId() == "~yes") + { + mConfirmDialog = 0; + } +*/ + } + + void updateList() + { + } + + void updateAvatar(std::string name A_UNUSED) + { + } + + void resetDamage(std::string name A_UNUSED) + { + } + +protected: + void invite() + { +/* + mInviteDialog = new TextDialog(_("Member Invite to Guild"), + strprintf(_("Who would you like to invite to guild %s?"), + mGuild->getName().c_str()), + socialWindow); + mInviteDialog->setActionEventId("do invite"); + mInviteDialog->addActionListener(this); +*/ + } + + void leave() + { +/* + mConfirmDialog = new ConfirmDialog(_("Leave Guild?"), + strprintf(_("Are you sure you want to leave guild %s?"), + mGuild->getName().c_str()), + socialWindow); + + mConfirmDialog->addActionListener(this); +*/ + } + +private: + Guild *mGuild; +}; + class PartyTab : public SocialTab, public gcn::ActionListener { public: @@ -1106,9 +1209,13 @@ bool SocialWindow::addTab(Guild *guild) if (mGuilds.find(guild) != mGuilds.end()) return false; - GuildTab *tab = new GuildTab(guild); - mGuilds[guild] = tab; + SocialTab *tab = 0; + if (guild->getServerGuild()) + tab = new GuildTab(guild); + else + tab = new GuildTab2(guild); + mGuilds[guild] = tab; mTabs->addTab(tab, tab->mScroll); updateButtons(); diff --git a/src/gui/widgets/guildtab.cpp b/src/gui/widgets/guildtab.cpp new file mode 100644 index 000000000..d9f61cb43 --- /dev/null +++ b/src/gui/widgets/guildtab.cpp @@ -0,0 +1,127 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gui/widgets/guildtab.h" + +#include "chatlogger.h" +#include "commandhandler.h" +#include "guild.h" +#include "guildmanager.h" +#include "localplayer.h" + +#include "gui/theme.h" + +#include "resources/iteminfo.h" +#include "resources/itemdb.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include "debug.h" + +GuildTab::GuildTab() : + ChatTab(_("Guild")) +{ + setTabColor(&Theme::getThemeColor(Theme::GUILD_CHAT_TAB)); +} + +GuildTab::~GuildTab() +{ +} + +bool GuildTab::handleCommand(const std::string &type, const std::string &args) +{ + if (type == "help") + { + if (args == "invite") + { + chatLog(_("Command: /invite ")); + chatLog(_("This command invites to the guild you're in.")); + chatLog(_("If the has spaces in it, enclose it in " + "double quotes (\").")); + } + else if (args == "leave") + { + chatLog(_("Command: /leave")); + chatLog(_("This command causes the player to leave the guild.")); + } + else + return false; + } + else if (type == "invite" && guildManager) + { + guildManager->invite(args); + } + else if (type == "leave" && guildManager) + { + guildManager->leave(); + } + else if (type == "kick" && guildManager) + { + guildManager->kick(args); + } + else if (type == "notice" && guildManager) + { + guildManager->notice(args); + } + else + { + return false; + } + + return false; +} + +void GuildTab::handleInput(const std::string &msg) +{ + if (!guildManager) + return; + + if (chatWindow) + guildManager->chat(chatWindow->doReplace(msg)); + else + guildManager->chat(msg); +} + +void GuildTab::showHelp() +{ + chatLog(_("/help > Display this help.")); + chatLog(_("/invite > Invite a player to your guild")); + chatLog(_("/leave > Leave the guild you are in")); + chatLog(_("/kick > Kick some one from the guild you are in")); +} + +void GuildTab::getAutoCompleteList(std::vector &names) const +{ + if (!guildManager) + return; + + guildManager->getNames(names); + names.push_back("/notice "); +} + +void GuildTab::saveToLogFile(std::string &msg) +{ + if (chatLogger) + chatLogger->log("#Guild", msg); +} diff --git a/src/gui/widgets/guildtab.h b/src/gui/widgets/guildtab.h new file mode 100644 index 000000000..a7f0aa766 --- /dev/null +++ b/src/gui/widgets/guildtab.h @@ -0,0 +1,52 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUI_GUILDTAB_H +#define GUI_GUILDTAB_H + +#include "gui/widgets/chattab.h" + +/** + * A tab for a guild chat channel. + */ +class GuildTab : public ChatTab +{ + public: + GuildTab(); + + ~GuildTab(); + + bool handleCommand(const std::string &type, const std::string &args); + + void showHelp(); + + void saveToLogFile(std::string &msg); + + int getType() const { return ChatTab::TAB_GUILD; } + + protected: + void handleInput(const std::string &msg); + + void getAutoCompleteList(std::vector &names) const; +}; + +#endif diff --git a/src/guild.cpp b/src/guild.cpp index b84602858..e36b68863 100644 --- a/src/guild.cpp +++ b/src/guild.cpp @@ -36,6 +36,9 @@ class SortGuildFunctor if (m1->getPos() != m2->getPos()) return m1->getPos() < m2->getPos(); +// if (m1->getOnline() != m2->getOnline()) +// return m1->getOnline() > m2->getOnline(); + return m1->getName() < m2->getName(); } } guildSorter; @@ -66,7 +69,8 @@ Guild::GuildMap Guild::guilds; Guild::Guild(short id): mId(id), mCanInviteUsers(false), - mEmblemId(0) + mEmblemId(0), + mServerGuild(true) { guilds[id] = this; } diff --git a/src/guild.h b/src/guild.h index 7986eb5d3..62135e9ad 100644 --- a/src/guild.h +++ b/src/guild.h @@ -178,11 +178,17 @@ public: void setEmblemId(int id) { mEmblemId = id; } - int getEmblemId() + int getEmblemId() const { return mEmblemId; } static void clearGuilds(); + void setServerGuild(bool b) + { mServerGuild = b; } + + bool getServerGuild() const + { return mServerGuild; } + private: typedef std::map GuildMap; static GuildMap guilds; @@ -199,6 +205,7 @@ private: bool mCanInviteUsers; int mEmblemId; PositionsMap mPositions; + bool mServerGuild; }; #endif // GUILD_H diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp new file mode 100644 index 000000000..ec9de2506 --- /dev/null +++ b/src/guildmanager.cpp @@ -0,0 +1,309 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "guildmanager.h" + +#include "actorspritemanager.h" +#include "client.h" +#include "configuration.h" +#include "guild.h" +#include "localplayer.h" + +#include "gui/socialwindow.h" + +#include "gui/widgets/guildtab.h" + +#include "net/chathandler.h" +#include "net/net.h" + +#include "utils/stringutils.h" + +#include "debug.h" + + +GuildManager::GuildManager() : + mEnableGuildBot(false), + mGotInfo(false), + mGotName(false), + mHavePower(false), + mTab(0), + mRequest(false) +{ +} + +GuildManager::~GuildManager() +{ + mTab = 0; +} + +void GuildManager::init() +{ + int val = serverConfig.getValue("enableGuildBot", -1); + if (val == -1) + { + if (Client::isTmw()) + val = 1; + else + val = 0; + serverConfig.setValue("enableGuildBot", val); + } + mEnableGuildBot = val; +} + +void GuildManager::send(std::string msg) +{ + Net::getChatHandler()->privateMessage("guild", msg); +} + +void GuildManager::chat(std::string msg) +{ + if (!player_node || !mTab) + return; + + Net::getChatHandler()->privateMessage("guild", msg); + mTab->chatLog(player_node->getName(), msg); +} + +void GuildManager::getNames(std::vector &names) +{ +} + +void GuildManager::requestGuildInfo() +{ + if (mRequest) + return; + + if (!mGotName) + { + send("!info"); + mRequest = true; + } + else if (!mGotInfo) + { + send("!getonlineinfo"); + mRequest = true; + } +} + +void GuildManager::updateList() +{ + Guild *guild = Guild::getGuild(1); + if (guild) + { + logger->log("filling player"); + guild->setServerGuild(false); + std::vector::iterator it = mTempList.begin(); + std::vector::iterator it_end = mTempList.end(); + int i = 0; + while (it != it_end) + { + std::string name = *it; + if (name.size() > 1) + { + int status = atoi(name.substr(name.size() - 1).c_str()); + name = name.substr(0, name.size() - 1); + GuildMember *m = guild->addMember(i, 0, name); + if (m) + { + m->setOnline(status & 1); + m->setGender(GENDER_UNSPECIFIED); + } + } + ++ it; + i ++; + } + guild->sort(); + if (actorSpriteManager) + actorSpriteManager->updatePlayerGuild(); + } + mTempList.clear(); + mGotInfo = true; + if (!mTab) + { + mTab = new GuildTab(); + mTab->loadFromLogFile("#Guild"); + if (player_node) + player_node->addGuild(guild); + } +} + +bool GuildManager::processGuildMessage(std::string msg) +{ + bool res = process(msg); + + if (!mRequest) + requestGuildInfo(); + + return res; +} + +bool GuildManager::process(std::string msg) +{ + if (msg.size() > 4 && msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + + Guild *guild = Guild::getGuild(1); + if (!guild) + return false; + + guild->setServerGuild(false); + + if (findCutLast(msg, " is now Offline.")) + { + if (msg.size() < 4) + return false; + if (msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + + GuildMember *m = guild->getMember(msg); + if (m) + m->setOnline(false); + mRequest = false; + return true; + } + else if (findCutLast(msg, " is now Online.")) + { + if (msg.size() < 4) + return false; + if (msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + GuildMember *m = guild->getMember(msg); + if (m) + m->setOnline(true); + mRequest = false; + return true; + } + else if (findCutFirst(msg, "Welcome to the ")) + { + logger->log("welcome message: %s", msg.c_str()); + int pos = msg.find("! ("); + if (pos == (int)std::string::npos) + return false; + msg = msg.substr(0, pos); + guild->setName(msg); + if (player_node) + player_node->setGuildName(msg); + mGotName = true; + mRequest = false; + return true; + } + else if (findCutFirst(msg, "Player name: ")) + { + int pos = msg.find("Access Level: "); + if (pos == (int)std::string::npos) + return false; + + msg = msg.substr(pos); + if (!findCutFirst(msg, "Access Level: ")) + return false; + + pos = msg.find(", Guild:"); + if (pos == (int)std::string::npos) + return false; + + int level = atoi(msg.substr(0, pos).c_str()); + if (level >= 10) + mHavePower = true; + else + mHavePower = false; + + msg = msg.substr(pos + strlen(", Guild:")); + pos = msg.find(", No. Of Online Players: "); + if (pos == (int)std::string::npos) + return false; + + msg = msg.substr(0, pos); +// logger->log("guild name: %s", msg.c_str()); + + guild->setName(msg); + if (player_node) + player_node->setGuildName(msg); + mGotName = true; + mRequest = false; + return true; + } + else if (findCutFirst(msg, "OL#")) + { + logger->log("OL"); + mTempList.clear(); + splitToStringVector(mTempList, msg, '#'); + if (msg.size() < 1 || msg[msg.size() - 1] != '#') + updateList(); + mRequest = false; + return true; + } + else if (findCutFirst(msg, "oL#")) + { + logger->log("oL"); + splitToStringVector(mTempList, msg, '#'); + if (msg.size() < 1 || msg[msg.size() - 1] != '#') + updateList(); + mRequest = false; + return true; + } + else if (msg == "You are currently not in a guild. For more information " + "or to discuss the possibility of adding you own guild " + "please contact Jero.") + { + mRequest = true; + return true; + } + else + { + if (mTab) + { + std::string::size_type pos = msg.find(": ", 0); + if (pos != std::string::npos) + { + std::string sender_name = ((pos == std::string::npos) + ? "" : msg.substr(0, pos)); + + msg.erase(0, pos + 2); + if (msg.size() > 3 && msg[0] == '#' && msg[1] == '#') + msg.erase(0, 3); + + trim(msg); + mTab->chatLog(sender_name, msg); + } + else + { + mTab->chatLog(msg); + } + return true; + } + } + return false; +} + +void GuildManager::kick(std::string msg) +{ +} + +void GuildManager::invite(std::string msg) +{ +} + +void GuildManager::leave() +{ +} + +void GuildManager::notice(std::string msg) +{ +} diff --git a/src/guildmanager.h b/src/guildmanager.h new file mode 100644 index 000000000..f02368ab6 --- /dev/null +++ b/src/guildmanager.h @@ -0,0 +1,81 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUILDMANAGER_H +#define GUILDMANAGER_H + +#include "utils/dtor.h" + +#include +#include +#include + +class GuildTab; + +class GuildManager +{ + public: + GuildManager(); + + ~GuildManager(); + + void init(); + + void chat(std::string msg); + + void send(std::string msg); + + bool processGuildMessage(std::string msg); + + void getNames(std::vector &names); + + void requestGuildInfo(); + + void updateList(); + + bool getEnableGuildBot() + { return mEnableGuildBot; } + + void kick(std::string msg); + + void invite(std::string msg); + + void leave(); + + void notice(std::string msg); + + bool havePower() + { return mHavePower; } + + private: + bool process(std::string msg); + + bool mEnableGuildBot; + bool mGotInfo; + bool mGotName; + bool mHavePower; + std::vector mTempList; + GuildTab *mTab; + bool mRequest; +}; + +extern GuildManager *guildManager; + +#endif // GUILDMANAGER_H diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index c188a2204..e430dfc0f 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -25,6 +25,7 @@ #include "actorspritemanager.h" #include "being.h" #include "configuration.h" +#include "guildmanager.h" #include "localplayer.h" #include "playerrelations.h" #include "logger.h" @@ -161,6 +162,12 @@ void ChatHandler::processWhisper(Net::MessageIn &msg) if (nick != "Server") { + if (guildManager && guildManager->getEnableGuildBot() + && nick == "guild" && guildManager->processGuildMessage(chatMsg)) + { + return; + } + if (player_relations.hasPermission( nick, PlayerRelation::WHISPER)) { diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp index 0210a76ff..2accb1f1d 100644 --- a/src/net/ea/guildhandler.cpp +++ b/src/net/ea/guildhandler.cpp @@ -125,6 +125,7 @@ void GuildHandler::processGuildPositionInfo(Net::MessageIn &msg) if (!guildTab && chatWindow) { guildTab = new GuildTab(); + guildTab->loadFromLogFile("#Guild"); if (player_node) player_node->addGuild(taGuild); memberList(guildId); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 0243c4315..317d88f2d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -524,3 +524,57 @@ void deleteCharLeft(std::string &str, unsigned *pos) break; } } + +bool findLast(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(s1 - s2); + if (tmp == str2) + return true; + return false; +} + +bool findFirst(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(0, s2); + if (tmp == str2) + return true; + return false; +} + +bool findCutLast(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(s1 - s2); + if (tmp == str2) + { + str1 = str1.substr(0, s1 - s2); + return true; + } + return false; +} + +bool findCutFirst(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(0, s2); + if (tmp == str2) + { + str1 = str1.substr(s2); + return true; + } + return false; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 4fe6369e9..25e038a89 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -193,4 +193,12 @@ std::string stringToHexPath(const std::string &str); void deleteCharLeft(std::string &str, unsigned *pos); +bool findLast(std::string &str1, std::string str2); + +bool findFirst(std::string &str1, std::string str2); + +bool findCutLast(std::string &str1, std::string str2); + +bool findCutFirst(std::string &str1, std::string str2); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-70-g09d2 From cf8445d68f109a20ec22cee84c7dc06411390900 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 27 Aug 2011 06:07:27 +0300 Subject: Fix guild name update on players. --- src/being.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index 1924a8944..eeb366b5d 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -875,8 +875,8 @@ void Being::updateGuild() setGuild(guild); if (!guild->getName().empty()) mGuildName = guild->getName(); - updateColors(); } + updateColors(); } void Being::setGuild(Guild *guild) -- cgit v1.2.3-70-g09d2 From 064a2aea075b9d519912e7fdb98c5e06eb4ab9f0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 27 Aug 2011 22:28:05 +0300 Subject: Add guild name to beings cache. --- src/being.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index eeb366b5d..36aa00689 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -97,6 +97,7 @@ class BeingCacheEntry mId(id), mName(""), mPartyName(""), + mGuildName(""), mLevel(0), mPvpRank(0), mTime(0), @@ -129,9 +130,15 @@ class BeingCacheEntry void setPartyName(const std::string &name) { mPartyName = name; } + void setGuildName(const std::string &name) + { mGuildName = name; } + const std::string &getPartyName() const { return mPartyName; } + const std::string &getGuildName() const + { return mGuildName; } + void setLevel(int n) { mLevel = n; } @@ -172,6 +179,7 @@ class BeingCacheEntry int mId; /**< Unique sprite id */ std::string mName; /**< Name of character */ std::string mPartyName; + std::string mGuildName; int mLevel; unsigned int mPvpRank; int mTime; @@ -1773,6 +1781,7 @@ bool Being::updateFromCache() if (!entry->getName().empty()) setName(entry->getName()); setPartyName(entry->getPartyName()); + setGuildName(entry->getGuildName()); setLevel(entry->getLevel()); setPvpRank(entry->getPvpRank()); setIp(entry->getIp()); @@ -1824,6 +1833,7 @@ void Being::addToCache() entry->setName(getName()); entry->setLevel(getLevel()); entry->setPartyName(getPartyName()); + entry->setGuildName(getGuildName()); entry->setTime(cur_time); entry->setPvpRank(getPvpRank()); entry->setIp(getIp()); -- cgit v1.2.3-70-g09d2 From 106180f42f536f4b898a72f36af1b2be28d1a8ed Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 28 Aug 2011 00:18:58 +0300 Subject: Fix guild name reset on players from time. --- src/being.cpp | 1 - src/net/ea/beinghandler.cpp | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index 36aa00689..2d9194c6e 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -760,7 +760,6 @@ void Being::setGuildName(const std::string &name) mGuildName = name; } - void Being::setGuildPos(const std::string &pos A_UNUSED) { // logger->log("Got guild position \"%s\" for being %s(%i)", pos.c_str(), mName.c_str(), mId); diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 06e86f8a4..2714f94ce 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -29,6 +29,7 @@ #include "client.h" #include "effectmanager.h" #include "guild.h" +#include "guildmanager.h" #include "keyboardconfig.h" #include "localplayer.h" #include "logger.h" @@ -661,7 +662,8 @@ void BeingHandler::processPlayerGuilPartyInfo(Net::MessageIn &msg) if ((dstBeing = actorSpriteManager->findBeing(msg.readInt32()))) { dstBeing->setPartyName(msg.readString(24)); - dstBeing->setGuildName(msg.readString(24)); + if (!guildManager || !guildManager->getEnableGuildBot()) + dstBeing->setGuildName(msg.readString(24)); dstBeing->setGuildPos(msg.readString(24)); dstBeing->addToCache(); msg.readString(24); // Discard this -- cgit v1.2.3-70-g09d2 From b8cdabbd20690d57930dce9dda949fca21a6233a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 1 Sep 2011 20:04:35 +0300 Subject: Eliminate asserts from most files. --- src/actorsprite.cpp | 4 ---- src/animatedsprite.cpp | 4 ---- src/being.cpp | 1 - src/client.cpp | 2 -- src/graphics.cpp | 2 -- src/gui/charselectdialog.cpp | 5 ++--- src/gui/popupmenu.cpp | 2 -- src/gui/quitdialog.cpp | 15 +++++---------- src/gui/widgets/layout.cpp | 7 +++++-- src/gui/widgets/window.cpp | 3 ++- src/joystick.cpp | 5 ++--- src/localplayer.cpp | 2 -- src/net/manaserv/messagehandler.cpp | 2 -- src/net/tmwa/generalhandler.cpp | 1 - src/particlecontainer.cpp | 2 -- src/resources/imageloader.cpp | 4 ---- src/resources/itemdb.cpp | 14 +++++++------- src/resources/mapreader.cpp | 6 +++--- src/resources/resource.cpp | 2 -- 19 files changed, 26 insertions(+), 57 deletions(-) (limited to 'src/being.cpp') diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 848e84e0f..2b133eca5 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -477,9 +477,6 @@ void ActorSprite::loadTargetCursor(const std::string &filename, if (size < TC_SMALL || size >= NUM_TC) return; -// assert(size > -1); -// assert(size < 3); - ResourceManager *resman = ResourceManager::getInstance(); ImageSet *currentImageSet = resman->getImageSet(filename, width, height); @@ -493,7 +490,6 @@ void ActorSprite::loadTargetCursor(const std::string &filename, for (unsigned int i = 0; i < currentImageSet->size(); ++i) { -// anim->addFrame(currentImageSet->get(i), 0, anim->addFrame(currentImageSet->get(i), 75, (16 - (currentImageSet->getWidth() / 2)), (16 - (currentImageSet->getHeight() / 2)), diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 7414c94bc..27be02e36 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -32,8 +32,6 @@ #include "utils/xml.h" -#include - #include "debug.h" AnimatedSprite::AnimatedSprite(SpriteDef *sprite): @@ -46,8 +44,6 @@ AnimatedSprite::AnimatedSprite(SpriteDef *sprite): mAnimation(0), mFrame(0) { -// assert(mSprite); - mAlpha = 1.0f; // Take possession of the sprite diff --git a/src/being.cpp b/src/being.cpp index 2d9194c6e..6d35f1df0 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -79,7 +79,6 @@ #include "utils/stringutils.h" #include "utils/xml.h" -#include #include #include "debug.h" diff --git a/src/client.cpp b/src/client.cpp index 843f7c961..ab176c00b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -114,7 +114,6 @@ #endif #include -#include #include #include @@ -260,7 +259,6 @@ Client::Client(const Options &options): mMouseFocused(true), mGuiAlpha(1.0f) { - assert(!mInstance); mInstance = this; logger = new Logger; diff --git a/src/graphics.cpp b/src/graphics.cpp index c5dc38b72..abd7341e2 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -20,8 +20,6 @@ * along with this program. If not, see . */ -#include - #include "graphics.h" #include "graphicsvertexes.h" diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 28c7a083c..1942ebaeb 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -60,7 +60,6 @@ #include #include -#include #include "debug.h" @@ -342,8 +341,8 @@ void CharSelectDialog::setCharacters(const Net::Characters &characters) void CharSelectDialog::lock() { - assert(!mLocked); - setLocked(true); + if (!mLocked) + setLocked(true); } void CharSelectDialog::unlock() diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 6db4a408f..0eac0a4f9 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -78,8 +78,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include - #include "debug.h" std::string tradePartnerName(""); diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index f66872b5d..04f43fb88 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -41,23 +41,17 @@ #include "utils/gettext.h" -#include - #include "debug.h" QuitDialog::QuitDialog(QuitDialog** pointerToMe): Window(_("Quit"), true, NULL), mMyPointer(pointerToMe) { -// int width = 200; -// int height = 120; - mForceQuit = new RadioButton(_("Quit"), "quitdialog"); mLogoutQuit = new RadioButton(_("Quit"), "quitdialog"); mSwitchAccountServer = new RadioButton(_("Switch server"), "quitdialog"); mSwitchCharacter = new RadioButton(_("Switch character"), "quitdialog"); mOkButton = new Button(_("OK"), "ok", this); mCancelButton = new Button(_("Cancel"), "cancel", this); -// setContentSize(width, height); addKeyListener(this); @@ -149,10 +143,11 @@ void QuitDialog::action(const gcn::ActionEvent &event) } else if (mSwitchCharacter->isSelected()) { - assert(Client::getState() == STATE_GAME); - - Net::getCharHandler()->switchCharacter(); - Client::closeDialogs(); + if (Client::getState() == STATE_GAME) + { + Net::getCharHandler()->switchCharacter(); + Client::closeDialogs(); + } } } scheduleDelete(); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 382d169dc..a14b416ce 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -68,7 +68,9 @@ LayoutArray &LayoutCell::getArray() void LayoutCell::reflow(int nx, int ny, int nw, int nh) { - assert(mType != NONE); + if (mType == NONE) + return; + nx += mHPadding; ny += mVPadding; nw -= 2 * mHPadding; @@ -81,7 +83,8 @@ void LayoutCell::reflow(int nx, int ny, int nw, int nh) void LayoutCell::computeSizes() { - assert(mType == ARRAY); + if (mType != ARRAY) + return; std::vector< std::vector< LayoutCell * > >::iterator i = mArray->mCells.begin(); diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 7508d4e4b..0a3779307 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -663,7 +663,8 @@ void Window::setModal(bool modal) void Window::loadWindowState() { const std::string &name = mWindowName; - assert(!name.empty()); + if (name.empty()) + return; setPosition(config.getValueInt(name + "WinX", mDefaultX), config.getValueInt(name + "WinY", mDefaultY)); diff --git a/src/joystick.cpp b/src/joystick.cpp index 8f808a2d1..f45729351 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -24,8 +24,6 @@ #include "joystick.h" #include "logger.h" -#include - #include "debug.h" int Joystick::joystickCount = 0; @@ -48,7 +46,8 @@ Joystick::Joystick(int no): mCalibrating(false), mEnabled(false) { - assert(no < joystickCount); + if (no >= joystickCount) + no = joystickCount; mJoystick = SDL_JoystickOpen(no); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5192390bc..e9386a5ee 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -78,8 +78,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include - #include "mumblemanager.h" #include "debug.h" diff --git a/src/net/manaserv/messagehandler.cpp b/src/net/manaserv/messagehandler.cpp index 7524c95e8..2e9603f19 100644 --- a/src/net/manaserv/messagehandler.cpp +++ b/src/net/manaserv/messagehandler.cpp @@ -24,8 +24,6 @@ #include "net/manaserv/network.h" -#include - namespace ManaServ { diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 746cb6620..5ebeb5da9 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -67,7 +67,6 @@ #include "utils/gettext.h" -#include #include #include "debug.h" diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp index d00c68a63..70b1e2c84 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -20,8 +20,6 @@ * along with this program. If not, see . */ -#include - #include "particle.h" #include "particlecontainer.h" diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index c63d33c00..72a839573 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -29,8 +29,6 @@ #include -#include - #include "debug.h" #ifdef free @@ -79,12 +77,10 @@ int ProxyImage::getHeight() const return mImage->mBounds.h; else return 0; -// return mSDLImage ? mSDLImage->h : mImage->getHeight(); } gcn::Color ProxyImage::getPixel(int x, int y) { - assert(mSDLImage); return gcn::SDLgetPixel(mSDLImage, x, y); } diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 394aa74be..733c12958 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -36,8 +36,6 @@ #include -#include - #include "debug.h" namespace @@ -435,7 +433,8 @@ void ItemDB::unload() bool ItemDB::exists(int id) { - assert(mLoaded); + if (!mLoaded) + return false; ItemInfos::const_iterator i = mItemInfos.find(id); @@ -444,7 +443,8 @@ bool ItemDB::exists(int id) const ItemInfo &ItemDB::get(int id) { - assert(mLoaded); + if (!mLoaded) + load(); ItemInfos::const_iterator i = mItemInfos.find(id); @@ -459,7 +459,8 @@ const ItemInfo &ItemDB::get(int id) const ItemInfo &ItemDB::get(const std::string &name) { - assert(mLoaded); + if (!mLoaded) + load(); NamedItemInfos::const_iterator i = mNamedItemInfos.find(normalize(name)); @@ -597,7 +598,7 @@ void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) else { logger->log("ItemDB: Ignoring unknown sound event '%s'", - event.c_str()); + event.c_str()); } } @@ -656,7 +657,6 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) } case -2: { - logger->log("parse -2"); for_each_xml_child_node(itemNode, replaceNode) { if (xmlStrEqual(itemNode->name, BAD_CAST "item")) diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 70c45054f..685d415ff 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -37,7 +37,6 @@ #include "utils/stringutils.h" #include "utils/xml.h" -#include #include #include @@ -110,7 +109,8 @@ int inflateMemory(unsigned char *in, unsigned int inLength, } ret = inflate(&strm, Z_NO_FLUSH); - assert(ret != Z_STREAM_ERROR); + if (ret == Z_STREAM_ERROR) + return ret; switch (ret) { @@ -140,7 +140,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, } } while (ret != Z_STREAM_END); - assert(strm.avail_in == 0); +// assert(strm.avail_in == 0); outLength = bufferSize - strm.avail_out; (void) inflateEnd(&strm); diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index b180712c1..552af06ec 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -27,8 +27,6 @@ #include "resources/resourcemanager.h" -#include - #include "debug.h" Resource::~Resource() -- cgit v1.2.3-70-g09d2 From cfcdacfd6ed49916890a93d7565bd2a2d1f1e8f5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 2 Sep 2011 04:29:31 +0300 Subject: Possible fix for random incorrect camera position. --- src/being.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/being.cpp') diff --git a/src/being.cpp b/src/being.cpp index 6d35f1df0..b4c97f15d 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -1453,6 +1453,11 @@ int Being::getOffset(char pos, char neg) const if (mDirection & pos) offset = -offset; + if (offset > 32) + offset = 32; + if (offset < -32) + offset = -32; + return offset; } -- cgit v1.2.3-70-g09d2