diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/being/being.cpp | 40 | ||||
-rw-r--r-- | src/being/being.h | 6 | ||||
-rw-r--r-- | src/being/crazymoves.cpp | 48 | ||||
-rw-r--r-- | src/being/localplayer.cpp | 9 | ||||
-rw-r--r-- | src/being/playerinfo.cpp | 48 |
5 files changed, 104 insertions, 47 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp index 27cebc99c..4ba600294 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -177,8 +177,9 @@ Being::Being(const BeingId id, mIsGM(false), mType(type), mSpeechBubble(nullptr), - mWalkSpeed(playerHandler->getDefaultWalkSpeed()), - mSpeed(playerHandler->getDefaultWalkSpeed().x), + mWalkSpeed(playerHandler ? playerHandler->getDefaultWalkSpeed() + : Vector(1, 1, 1)), + mSpeed(playerHandler ? playerHandler->getDefaultWalkSpeed().x : 0), mIp(), mSpriteRemap(new int[20]), mSpriteHide(new int[20]), @@ -423,9 +424,16 @@ void Being::setSubtype(const BeingTypeId subtype, mYDiff = mInfo->getSortOffsetY(); const int speed = mInfo->getWalkSpeed(); if (!speed) - setWalkSpeed(playerHandler->getDefaultWalkSpeed()); + { + if (playerHandler) + setWalkSpeed(playerHandler->getDefaultWalkSpeed()); + else + setWalkSpeed(Vector(1, 1, 0)); + } else + { setWalkSpeed(Vector(speed, speed, 0)); + } } } else if (mType == ActorType::Player) @@ -577,7 +585,7 @@ void Being::setSpeech(const std::string &text, const std::string &channel, } const int speech = mSpeechType; - if (speech == BeingSpeech::TEXT_OVERHEAD && userPalette) + if (speech == BeingSpeech::TEXT_OVERHEAD) { delete mText; mText = new Text(mSpeech, @@ -592,8 +600,11 @@ void Being::setSpeech(const std::string &text, const std::string &channel, const bool isShowName = (speech == BeingSpeech::NAME_IN_BUBBLE); if (!mSpeechBubble) createSpeechBubble(); - mSpeechBubble->setCaption(isShowName ? mName : ""); - mSpeechBubble->setText(mSpeech, isShowName); + if (mSpeechBubble) + { + mSpeechBubble->setCaption(isShowName ? mName : ""); + mSpeechBubble->setText(mSpeech, isShowName); + } } } @@ -894,7 +905,9 @@ void Being::handleAttack(Being *const victim, const int damage, reset(); mActionTime = tick_time; - if (!serverFeatures->haveAttackDirections() && this != localPlayer) + if (serverFeatures && + !serverFeatures->haveAttackDirections() && + this != localPlayer) { const uint8_t dir = calcDirection(victim->getTileX(), victim->getTileY()); @@ -2287,7 +2300,7 @@ void Being::updateSprite(const unsigned int slot, const int id, std::string color, const unsigned char colorId, const bool isWeapon, const bool isTempSprite) { - if (slot >= charServerHandler->maxSprite()) + if (!charServerHandler || slot >= charServerHandler->maxSprite()) return; if (slot >= static_cast<unsigned int>(mSpriteIDs.size())) @@ -2302,7 +2315,7 @@ void Being::setSprite(const unsigned int slot, const int id, std::string color, const unsigned char colorId, const bool isWeapon, const bool isTempSprite) { - if (slot >= charServerHandler->maxSprite()) + if (!charServerHandler || slot >= charServerHandler->maxSprite()) return; if (slot >= static_cast<unsigned int>(size())) @@ -2509,7 +2522,7 @@ bool Being::updateFromCache() if (mAdvanced) { const int flags = entry->getFlags(); - if (!serverFeatures->haveVending()) + if (serverFeatures && !serverFeatures->haveVending()) mShop = ((flags & BeingFlag::SHOP) != 0); mAway = ((flags & BeingFlag::AWAY) != 0); mInactive = ((flags & BeingFlag::INACTIVE) != 0); @@ -2518,7 +2531,7 @@ bool Being::updateFromCache() } else { - if (!serverFeatures->haveVending()) + if (serverFeatures && !serverFeatures->haveVending()) mShop = false; mAway = false; mInactive = false; @@ -2564,7 +2577,7 @@ void Being::addToCache() const if (isAdvanced()) { int flags = 0; - if (!serverFeatures->haveVending() && mShop) + if (serverFeatures && !serverFeatures->haveVending() && mShop) flags += BeingFlag::SHOP; if (mAway) flags += BeingFlag::AWAY; @@ -2650,7 +2663,8 @@ void Being::talkTo() const if (!PacketLimiter::limitPackets(PacketType::PACKET_NPC_TALK)) return; - npcHandler->talk(mId); + if (npcHandler) + npcHandler->talk(mId); } void Being::draw(Graphics *const graphics, diff --git a/src/being/being.h b/src/being/being.h index ff00d5bef..8926e5548 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -1069,9 +1069,9 @@ class Being notfinal : public ActorSprite, Vector mWalkSpeed; float mSpeed; std::string mIp; - int *mSpriteRemap; - int *mSpriteHide; - int *mSpriteDraw; + int *mSpriteRemap A_NONNULLPOINTER; + int *mSpriteHide A_NONNULLPOINTER; + int *mSpriteDraw A_NONNULLPOINTER; std::string mComment; #ifdef EATHENA_SUPPORT std::string mBuyBoard; diff --git a/src/being/crazymoves.cpp b/src/being/crazymoves.cpp index 0405a0fcc..9636e6711 100644 --- a/src/being/crazymoves.cpp +++ b/src/being/crazymoves.cpp @@ -94,8 +94,12 @@ void CrazyMoves::crazyMove() void CrazyMoves::crazyMove1() { - if (localPlayer->getCurrentAction() == BeingAction::MOVE) + if (!localPlayer || + !playerHandler || + localPlayer->getCurrentAction() == BeingAction::MOVE) + { return; + } // if (!PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) // return; @@ -129,8 +133,12 @@ void CrazyMoves::crazyMove1() void CrazyMoves::crazyMove2() { - if (localPlayer->getCurrentAction() == BeingAction::MOVE) + if (!localPlayer || + !playerHandler || + localPlayer->getCurrentAction() == BeingAction::MOVE) + { return; + } // if (!PacketLimiter::limitPackets(PacketType::PACKET_DIRECTION)) // return; @@ -176,8 +184,12 @@ void CrazyMoves::crazyMove2() void CrazyMoves::crazyMove3() { - if (localPlayer->getCurrentAction() == BeingAction::MOVE) + if (!localPlayer || + !playerHandler || + localPlayer->getCurrentAction() == BeingAction::MOVE) + { return; + } switch (settings.crazyMoveState) { @@ -210,8 +222,11 @@ void CrazyMoves::crazyMove3() void CrazyMoves::crazyMove4() { - if (localPlayer->getCurrentAction() == BeingAction::MOVE) + if (!localPlayer || + localPlayer->getCurrentAction() == BeingAction::MOVE) + { return; + } switch (settings.crazyMoveState) { @@ -230,8 +245,11 @@ void CrazyMoves::crazyMove4() void CrazyMoves::crazyMove5() { - if (localPlayer->getCurrentAction() == BeingAction::MOVE) + if (!localPlayer || + localPlayer->getCurrentAction() == BeingAction::MOVE) + { return; + } switch (settings.crazyMoveState) { @@ -250,8 +268,11 @@ void CrazyMoves::crazyMove5() void CrazyMoves::crazyMove6() { - if (localPlayer->getCurrentAction() == BeingAction::MOVE) + if (!localPlayer || + localPlayer->getCurrentAction() == BeingAction::MOVE) + { return; + } switch (settings.crazyMoveState) { @@ -294,8 +315,11 @@ void CrazyMoves::crazyMove6() void CrazyMoves::crazyMove7() { - if (localPlayer->getCurrentAction() == BeingAction::MOVE) + if (!localPlayer || + localPlayer->getCurrentAction() == BeingAction::MOVE) + { return; + } switch (settings.crazyMoveState) { @@ -322,7 +346,7 @@ void CrazyMoves::crazyMove7() void CrazyMoves::crazyMove8() { - if (localPlayer->getCurrentAction() == BeingAction::MOVE) + if (!localPlayer || localPlayer->getCurrentAction() == BeingAction::MOVE) return; const Map *const map = localPlayer->getMap(); if (!map) @@ -431,7 +455,7 @@ void CrazyMoves::crazyMove9() int dx = 0; int dy = 0; - if (localPlayer->getCurrentAction() == BeingAction::MOVE) + if (!localPlayer || localPlayer->getCurrentAction() == BeingAction::MOVE) return; switch (settings.crazyMoveState) @@ -452,7 +476,8 @@ void CrazyMoves::crazyMove9() settings.crazyMoveState = 2; if (!localPlayer->allowAction()) return; - playerHandler->changeAction(BeingAction::SIT); + if (playerHandler) + playerHandler->changeAction(BeingAction::SIT); break; case 2: settings.crazyMoveState = 3; @@ -467,6 +492,9 @@ void CrazyMoves::crazyMove9() void CrazyMoves::crazyMoveAm() { + if (!localPlayer) + return; + settings.crazyMoveState ++; if (settings.crazyMoveState < mMoveProgram.length()) { diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index af3f3df03..b7d965a43 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -333,10 +333,11 @@ void LocalPlayer::slowLogic() weightNoticeTime = 0; } - if (!serverFeatures->havePlayerStatusUpdate() - && mEnableAdvert - && !mBlockAdvert - && mAdvertTime < cur_time) + if (serverFeatures && + !serverFeatures->havePlayerStatusUpdate() && + mEnableAdvert && + !mBlockAdvert && + mAdvertTime < cur_time) { uint8_t smile = BeingFlag::SPECIAL; if (mTradebot && shopWindow && !shopWindow->isShopEmpty()) diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp index 8c7b55639..b3c3f5bb4 100644 --- a/src/being/playerinfo.cpp +++ b/src/being/playerinfo.cpp @@ -209,7 +209,9 @@ Inventory *getInventory() Inventory *getStorageInventory() { - return inventoryHandler->getStorage(); + if (inventoryHandler) + return inventoryHandler->getStorage(); + return nullptr; } #ifdef EATHENA_SUPPORT @@ -250,21 +252,24 @@ void equipItem(const Item *const item, const Sfx sfx) { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::EQUIP); - inventoryHandler->equipItem(item); + if (inventoryHandler) + inventoryHandler->equipItem(item); } void unequipItem(const Item *const item, const Sfx sfx) { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::UNEQUIP); - inventoryHandler->unequipItem(item); + if (inventoryHandler) + inventoryHandler->unequipItem(item); } void useItem(const Item *const item, const Sfx sfx) { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::USE); - inventoryHandler->useItem(item); + if (inventoryHandler) + inventoryHandler->useItem(item); } void useEquipItem(const Item *const item, const Sfx sfx) @@ -276,7 +281,8 @@ void useEquipItem(const Item *const item, const Sfx sfx) { if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) { - inventoryHandler->useCard(item); + if (inventoryHandler) + inventoryHandler->useCard(item); if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::USECARD); } @@ -289,20 +295,23 @@ void useEquipItem(const Item *const item, const Sfx sfx) { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::UNEQUIP); - inventoryHandler->unequipItem(item); + if (inventoryHandler) + inventoryHandler->unequipItem(item); } else { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::EQUIP); - inventoryHandler->equipItem(item); + if (inventoryHandler) + inventoryHandler->equipItem(item); } } else { if (mProtectedItems.find(item->getId()) == mProtectedItems.end()) { - inventoryHandler->useItem(item); + if (inventoryHandler) + inventoryHandler->useItem(item); if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::USE); } @@ -320,13 +329,15 @@ void useEquipItem2(const Item *const item, const Sfx sfx) { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::UNEQUIP); - inventoryHandler->unequipItem(item); + if (inventoryHandler) + inventoryHandler->unequipItem(item); } else { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::EQUIP); - inventoryHandler->equipItem(item); + if (inventoryHandler) + inventoryHandler->equipItem(item); } } else @@ -335,7 +346,8 @@ void useEquipItem2(const Item *const item, const Sfx sfx) { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::USE); - inventoryHandler->useItem(item); + if (inventoryHandler) + inventoryHandler->useItem(item); } } } @@ -347,7 +359,8 @@ void dropItem(const Item *const item, const int amount, const Sfx sfx) { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::DROP); - inventoryHandler->dropItem(item, amount); + if (inventoryHandler) + inventoryHandler->dropItem(item, amount); } } @@ -355,7 +368,8 @@ void pickUpItem(const FloorItem *const item, const Sfx sfx) { if (sfx == Sfx_true) ItemSoundManager::playSfx(item, ItemSoundEvent::PICKUP); - playerHandler->pickUp(item); + if (playerHandler) + playerHandler->pickUp(item); } // --- Misc ------------------------------------------------------------------- @@ -582,18 +596,18 @@ BeingId getMercenaryId() void updateMoveAI() { - if (mMercenary) + if (mMercenary && mercenaryHandler) mercenaryHandler->moveToMaster(); - if (mHomunculus) + if (mHomunculus && homunculusHandler) homunculusHandler->moveToMaster(); } void updateAttackAi(const BeingId targetId, const Keep keep) { - if (mMercenary) + if (mMercenary && mercenaryHandler) mercenaryHandler->attack(targetId, keep); - if (mHomunculus) + if (mHomunculus && homunculusHandler) homunculusHandler->attack(targetId, keep); } |