diff options
-rw-r--r-- | src/actionmanager.cpp | 25 | ||||
-rw-r--r-- | src/actorsprite.cpp | 17 | ||||
-rw-r--r-- | src/actorsprite.h | 2 | ||||
-rw-r--r-- | src/actorspritemanager.cpp | 89 | ||||
-rw-r--r-- | src/actorspritemanager.h | 32 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 2 | ||||
-rw-r--r-- | src/utils/stringutils.h | 2 |
7 files changed, 74 insertions, 95 deletions
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp index 01b48d1bf..f98449459 100644 --- a/src/actionmanager.cpp +++ b/src/actionmanager.cpp @@ -211,7 +211,7 @@ impHandler0(ok) return true; } // Close the config window, cancelling changes if opened - else if (setupWindow->isVisible()) + else if (setupWindow && setupWindow->isVisible()) { setupWindow->action(gcn::ActionEvent(nullptr, "cancel")); return true; @@ -389,7 +389,7 @@ impHandler0(itenplz) { if (actorSpriteManager) { - if (Net::getPlayerHandler()->canUseMagic() + if (Net::getPlayerHandler() && Net::getPlayerHandler()->canUseMagic() && PlayerInfo::getAttribute(PlayerInfo::MP) >= 3) { actorSpriteManager->itenplz(); @@ -874,7 +874,8 @@ impHandler0(directUp) // if (Client::limitPackets(PACKET_DIRECTION)) { player_node->setDirection(Being::UP); - Net::getPlayerHandler()->setDirection(Being::UP); + if (Net::getPlayerHandler()) + Net::getPlayerHandler()->setDirection(Being::UP); } } return true; @@ -891,7 +892,8 @@ impHandler0(directDown) // if (Client::limitPackets(PACKET_DIRECTION)) { player_node->setDirection(Being::DOWN); - Net::getPlayerHandler()->setDirection(Being::DOWN); + if (Net::getPlayerHandler()) + Net::getPlayerHandler()->setDirection(Being::DOWN); } } return true; @@ -908,7 +910,8 @@ impHandler0(directLeft) // if (Client::limitPackets(PACKET_DIRECTION)) { player_node->setDirection(Being::LEFT); - Net::getPlayerHandler()->setDirection(Being::LEFT); + if (Net::getPlayerHandler()) + Net::getPlayerHandler()->setDirection(Being::LEFT); } } return true; @@ -925,7 +928,8 @@ impHandler0(directRight) // if (Client::limitPackets(PACKET_DIRECTION)) { player_node->setDirection(Being::RIGHT); - Net::getPlayerHandler()->setDirection(Being::RIGHT); + if (Net::getPlayerHandler()) + Net::getPlayerHandler()->setDirection(Being::RIGHT); } } return true; @@ -938,7 +942,7 @@ impHandler0(talk) if (player_node) { Being *target = player_node->getTarget(); - if (!target) + if (!target && actorSpriteManager) { target = actorSpriteManager->findNearestLivingBeing( player_node, 1, ActorSprite::NPC); @@ -1095,7 +1099,12 @@ impHandler0(showKeyboard) impHandler0(showWindows) { - viewport->showWindowsPopup(); + if (viewport) + { + viewport->showWindowsPopup(); + return true; + } + return false; } } diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index b0ed43b75..be7fcb165 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -221,7 +221,11 @@ static EffectDescription *getEffectDescription(const int effectId) effects_initialized = true; } // done initializing - EffectDescription *const ed = effects[effectId]; + std::map<int, EffectDescription *>::iterator it = effects.find(effectId); + if (it == effects.end()) + return default_effect; + + EffectDescription *const ed = (*it).second; return ed ? ed : default_effect; } @@ -274,12 +278,7 @@ void ActorSprite::internalTriggerEffect(const int effectId, const bool sfx, } if (gfx && !ed->mGFXEffect.empty()) - { - Particle *selfFX; - - selfFX = particleEngine->addEffect(ed->mGFXEffect, 0, 0); - controlParticle(selfFX); - } + controlParticle(particleEngine->addEffect(ed->mGFXEffect, 0, 0)); if (sfx && !ed->mSFXEffect.empty()) sound.playSfx(ed->mSFXEffect); @@ -325,7 +324,7 @@ void ActorSprite::handleStatusEffect(StatusEffect *const effect, void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, const bool forceDisplay, const int imageType, - std::string color) + const std::string &color) { clear(); @@ -333,7 +332,7 @@ void ActorSprite::setupSpriteDisplay(const SpriteDisplay &display, { if (!*it) continue; - std::string file = paths.getStringValue("sprites") + const std::string file = paths.getStringValue("sprites") + combineDye2((*it)->sprite, color); const int variant = (*it)->variant; diff --git a/src/actorsprite.h b/src/actorsprite.h index b01e2d1a3..28d8e8f92 100644 --- a/src/actorsprite.h +++ b/src/actorsprite.h @@ -223,7 +223,7 @@ protected: void setupSpriteDisplay(const SpriteDisplay &display, const bool forceDisplay = true, const int imageType = 0, - std::string color = ""); + const std::string &color = ""); int mId; uint16_t mStunMode; /**< Stun mode; zero if not stunned */ diff --git a/src/actorspritemanager.cpp b/src/actorspritemanager.cpp index 7cae07a5b..dc6676dfd 100644 --- a/src/actorspritemanager.cpp +++ b/src/actorspritemanager.cpp @@ -611,7 +611,7 @@ bool ActorSpriteManager::pickUpAll(const int x1, const int y1, return finded; } -bool ActorSpriteManager::pickUpNearest(const int x, const int y, int maxdist) +bool ActorSpriteManager::pickUpNearest(const int x, const int y, int maxdist) const { if (!player_node) return false; @@ -718,7 +718,9 @@ Being *ActorSpriteManager::findNearestByName(const std::string &name, (type == Being::UNKNOWN || type == being->getType())) { if (being->getType() == Being::PLAYER) + { return being; + } else { const int d = (being->getTileX() - x) * (being->getTileX() - x) @@ -1024,8 +1026,6 @@ Being *ActorSpriteManager::findNearestLivingBeing(const Being *const if (being->getInfo() && !being->getInfo()->isTargetSelection()) continue; -// Being *being = (*i); - const bool valid = validateBeing(aroundBeing, being, type, excluded, 50); int d = being->getDistance(); @@ -1104,6 +1104,8 @@ bool ActorSpriteManager::validateBeing(const Being *const aroundBeing, const Being* const excluded, const int maxCost) const { + if (!player_node) + return false; return being && ((being->getType() == type || type == Being::UNKNOWN) && (being->isAlive() || (mTargetDeadPlayers && type == Being::PLAYER)) @@ -1228,46 +1230,17 @@ bool ActorSpriteManager::hasActorSprite(const ActorSprite *const actor) const void ActorSpriteManager::addBlock(const uint32_t id) { - bool alreadyBlocked(false); - for (int i = 0; i < static_cast<int>(blockedBeings.size()); ++i) - { - if (id == blockedBeings.at(i)) - { - alreadyBlocked = true; - break; - } - } - if (alreadyBlocked == false) - blockedBeings.push_back(id); + mBlockedBeings.insert(id); } void ActorSpriteManager::deleteBlock(const uint32_t id) { - std::vector<uint32_t>::iterator iter = blockedBeings.begin(); - const std::vector<uint32_t>::iterator iter_end = blockedBeings.end(); - while (iter != iter_end) - { - if (*iter == id) - { - blockedBeings.erase(iter); - break; - } - ++ iter; - } + mBlockedBeings.erase(id); } bool ActorSpriteManager::isBlocked(const uint32_t id) const { - bool blocked(false); - for (int i = 0; i < static_cast<int>(blockedBeings.size()); ++i) - { - if (id == blockedBeings.at(i)) - { - blocked = true; - break; - } - } - return blocked; + return mBlockedBeings.find(id) != mBlockedBeings.end(); } void ActorSpriteManager::printAllToChat() const @@ -1275,8 +1248,8 @@ void ActorSpriteManager::printAllToChat() const printBeingsToChat(getAll(), _("Visible on map")); } -void ActorSpriteManager::printBeingsToChat(ActorSprites beings, - std::string header) const +void ActorSpriteManager::printBeingsToChat(const ActorSprites &beings, + const std::string &header) const { if (!debugChatTab) return; @@ -1293,16 +1266,15 @@ void ActorSpriteManager::printBeingsToChat(ActorSprites beings, const Being *const being = static_cast<Being*>(*it); - debugChatTab->chatLog(being->getName() - + " (" + toString(being->getTileX()) + "," - + toString(being->getTileY()) + ") " - + toString(being->getSubType()), BY_SERVER); + debugChatTab->chatLog(strprintf("%s (%d,%d) %d", + being->getName().c_str(), being->getTileX(), being->getTileY(), + being->getSubType()), BY_SERVER); } debugChatTab->chatLog("---------------------------------------"); } -void ActorSpriteManager::printBeingsToChat(std::vector<Being*> beings, - std::string header) const +void ActorSpriteManager::printBeingsToChat(const std::vector<Being*> &beings, + const std::string &header) const { if (!debugChatTab) return; @@ -1317,10 +1289,9 @@ void ActorSpriteManager::printBeingsToChat(std::vector<Being*> beings, const Being *const being = *i; - debugChatTab->chatLog(being->getName() - + " (" + toString(being->getTileX()) + "," - + toString(being->getTileY()) + ") " - + toString(being->getSubType()), BY_SERVER); + debugChatTab->chatLog(strprintf("%s (%d,%d) %d", + being->getName().c_str(), being->getTileX(), being->getTileY(), + being->getSubType()), BY_SERVER); } debugChatTab->chatLog("---------------------------------------"); } @@ -1534,18 +1505,18 @@ void ActorSpriteManager::removePickupItem(const std::string &name) }\ } -void ActorSpriteManager::addAttackMob(std::string name) +void ActorSpriteManager::addAttackMob(const std::string &name) { addMobToList(name, AttackMob); rebuildPriorityAttackMobs(); } -void ActorSpriteManager::addPriorityAttackMob(std::string name) +void ActorSpriteManager::addPriorityAttackMob(const std::string &name) { addMobToList(name, PriorityAttackMob); } -void ActorSpriteManager::addIgnoreAttackMob(std::string name) +void ActorSpriteManager::addIgnoreAttackMob(const std::string &name) { mIgnoreAttackMobs.push_back(name); mIgnoreAttackMobsSet.insert(name); @@ -1553,13 +1524,13 @@ void ActorSpriteManager::addIgnoreAttackMob(std::string name) rebuildPriorityAttackMobs(); } -void ActorSpriteManager::addPickupItem(std::string name) +void ActorSpriteManager::addPickupItem(const std::string &name) { addMobToList(name, PickupItem); rebuildPickupItems(); } -void ActorSpriteManager::addIgnorePickupItem(std::string name) +void ActorSpriteManager::addIgnorePickupItem(const std::string &name) { mIgnorePickupItems.push_back(name); mIgnorePickupItemsSet.insert(name); @@ -1581,8 +1552,8 @@ void ActorSpriteManager::rebuildPickupItems() rebuildMobsList(PickupItem); } -int ActorSpriteManager::getIndexByName(std::string name, - std::map<std::string, int> &map) const +int ActorSpriteManager::getIndexByName(const std::string &name, + const std::map<std::string, int> &map) const { const std::map<std::string, int>::const_iterator i = map.find(name); @@ -1592,17 +1563,17 @@ int ActorSpriteManager::getIndexByName(std::string name, return (*i).second; } -int ActorSpriteManager::getPriorityAttackMobIndex(std::string name) +int ActorSpriteManager::getPriorityAttackMobIndex(const std::string &name) const { return getIndexByName(name, mPriorityAttackMobsMap); } -int ActorSpriteManager::getAttackMobIndex(std::string name) +int ActorSpriteManager::getAttackMobIndex(const std::string &name) const { return getIndexByName(name, mAttackMobsMap); } -int ActorSpriteManager::getPickupItemIndex(std::string name) +int ActorSpriteManager::getPickupItemIndex(const std::string &name) const { return getIndexByName(name, mPickupItemsMap); } @@ -1652,7 +1623,7 @@ void ActorSpriteManager::loadAttackList() rebuildPickupItems(); } -void ActorSpriteManager::storeAttackList() +void ActorSpriteManager::storeAttackList() const { serverConfig.setValue("attackPriorityMobs", packList(mPriorityAttackMobs)); serverConfig.setValue("attackMobs", packList(mAttackMobs)); @@ -1672,7 +1643,7 @@ bool ActorSpriteManager::checkForPickup(const FloorItem *const item) const return true; } } - else if (mPickupItemsSet.find(item->getName()) != mPickupItemsSet.end()) + else if (item && mPickupItemsSet.find(item->getName()) != mPickupItemsSet.end()) { return true; } diff --git a/src/actorspritemanager.h b/src/actorspritemanager.h index 506bda97d..0386a93f2 100644 --- a/src/actorspritemanager.h +++ b/src/actorspritemanager.h @@ -202,8 +202,6 @@ class ActorSpriteManager final: public ConfigListener */ void clear(); - std::vector<uint32_t> blockedBeings; - void addBlock(const uint32_t id); void deleteBlock(const uint32_t id); @@ -212,10 +210,11 @@ class ActorSpriteManager final: public ConfigListener void printAllToChat() const; - void printBeingsToChat(ActorSprites beings, std::string header) const; + void printBeingsToChat(const ActorSprites &beings, + const std::string &header) const; - void printBeingsToChat(std::vector<Being*> beings, - std::string header) const; + void printBeingsToChat(const std::vector<Being*> &beings, + const std::string &header) const; void getPlayerNames(StringVect &names, const bool npcNames) const; @@ -233,7 +232,7 @@ class ActorSpriteManager final: public ConfigListener bool pickUpAll(const int x1, const int y1, const int x2, const int y2, const bool serverBuggy = false); - bool pickUpNearest(const int x, const int y, int maxdist); + bool pickUpNearest(const int x, const int y, int maxdist) const; void optionChanged(const std::string &name) override; @@ -241,15 +240,15 @@ class ActorSpriteManager final: public ConfigListener void removePickupItem(const std::string &name); - void addPriorityAttackMob(std::string name); + void addPriorityAttackMob(const std::string &name); - void addAttackMob(std::string name); + void addAttackMob(const std::string &name); - void addIgnoreAttackMob(std::string name); + void addIgnoreAttackMob(const std::string &name); - void addPickupItem(std::string name); + void addPickupItem(const std::string &name); - void addIgnorePickupItem(std::string name); + void addIgnorePickupItem(const std::string &name); void setPriorityAttackMobs(std::list<std::string> mobs) { mPriorityAttackMobs = mobs; } @@ -288,13 +287,13 @@ class ActorSpriteManager final: public ConfigListener const A_WARN_UNUSED { return mPriorityAttackMobsMap; } - int getAttackMobIndex(std::string name) A_WARN_UNUSED; + int getAttackMobIndex(const std::string &name) const A_WARN_UNUSED; - int getPriorityAttackMobIndex(std::string name) A_WARN_UNUSED; + int getPriorityAttackMobIndex(const std::string &name) const A_WARN_UNUSED; - int getPickupItemIndex(std::string name) A_WARN_UNUSED; + int getPickupItemIndex(const std::string &name) const A_WARN_UNUSED; - int getIndexByName(std::string name, std::map<std::string, + int getIndexByName(const std::string &name, const std::map<std::string, int> &map) const A_WARN_UNUSED; bool checkForPickup(const FloorItem *const item) const A_WARN_UNUSED; @@ -314,10 +313,11 @@ class ActorSpriteManager final: public ConfigListener excluded = nullptr) const A_WARN_UNUSED; void loadAttackList(); - void storeAttackList(); + void storeAttackList() const; ActorSprites mActors; ActorSprites mDeleteActors; + std::set<uint32_t> mBlockedBeings; Map *mMap; std::string mSpellHeal1; std::string mSpellHeal2; diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 7786002e5..74e5d9f58 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -525,7 +525,7 @@ std::string combineDye2(std::string file, std::string dye) } } -std::string packList(std::list<std::string> &list) +std::string packList(const std::list<std::string> &list) { std::list<std::string>::const_iterator i = list.begin(); std::string str(""); diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 45c1f4b0a..612486cb2 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -199,7 +199,7 @@ std::string combineDye(std::string file, std::string dye) A_WARN_UNUSED; std::string combineDye2(std::string file, std::string dye) A_WARN_UNUSED; -std::string packList(std::list<std::string> &list) A_WARN_UNUSED; +std::string packList(const std::list<std::string> &list) A_WARN_UNUSED; std::list<std::string> unpackList(const std::string &str) A_WARN_UNUSED; |