summaryrefslogtreecommitdiff
path: root/src/localplayer.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-09-18 17:49:18 +0300
committerAndrei Karas <akaras@inbox.ru>2011-09-18 17:49:18 +0300
commit70b520b1e876f9698bb95baa2d274ea289a0c6bd (patch)
tree152c7519b0d9b8fb424af2373ec48db823a85575 /src/localplayer.cpp
parent62ec17f6e489ec50f17219444468aeb8969dc961 (diff)
parent3b999f51c740d0541c53d223518e5e4bb482d996 (diff)
downloadplus-70b520b1e876f9698bb95baa2d274ea289a0c6bd.tar.gz
plus-70b520b1e876f9698bb95baa2d274ea289a0c6bd.tar.bz2
plus-70b520b1e876f9698bb95baa2d274ea289a0c6bd.tar.xz
plus-70b520b1e876f9698bb95baa2d274ea289a0c6bd.zip
Merge branch 'master' into strippedstripped1.1.9.18
Conflicts: src/guichan/cliprectangle.cpp src/guichan/focushandler.cpp src/guichan/gui.cpp src/guichan/include/guichan/cliprectangle.hpp src/guichan/include/guichan/inputevent.hpp src/guichan/include/guichan/keyevent.hpp src/guichan/include/guichan/mouseevent.hpp src/guichan/include/guichan/widgets/button.hpp src/guichan/include/guichan/widgets/checkbox.hpp src/guichan/include/guichan/widgets/dropdown.hpp src/guichan/include/guichan/widgets/radiobutton.hpp src/guichan/include/guichan/widgets/slider.hpp src/guichan/include/guichan/widgets/tab.hpp src/guichan/include/guichan/widgets/tabbedarea.hpp src/guichan/include/guichan/widgets/textfield.hpp src/guichan/include/guichan/widgets/window.hpp src/guichan/inputevent.cpp src/guichan/keyevent.cpp src/guichan/mouseevent.cpp src/guichan/widget.cpp src/guichan/widgets/button.cpp src/guichan/widgets/checkbox.cpp src/guichan/widgets/dropdown.cpp src/guichan/widgets/radiobutton.cpp src/guichan/widgets/slider.cpp src/guichan/widgets/tab.cpp src/guichan/widgets/tabbedarea.cpp src/guichan/widgets/textfield.cpp src/guichan/widgets/window.cpp
Diffstat (limited to 'src/localplayer.cpp')
-rw-r--r--src/localplayer.cpp143
1 files changed, 65 insertions, 78 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index e9386a5ee..e17cf09c4 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),
@@ -123,7 +125,8 @@ LocalPlayer::LocalPlayer(int id, int subtype):
mLastHitFrom(""),
mWaitFor(""),
mAdvertTime(0),
- mBlockAdvert(false)
+ mBlockAdvert(false),
+ mNextStep(false)
{
logger->log1("LocalPlayer::LocalPlayer");
@@ -137,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;
@@ -222,8 +228,9 @@ void LocalPlayer::logic()
if (mActivityTime == 0 || mLastAction != -1)
mActivityTime = cur_time;
- if (mAction != MOVE && !mNavigatePath.empty())
+ if ((mAction != MOVE || mNextStep) && !mNavigatePath.empty())
{
+ mNextStep = false;
int dist = 5;
if (!mSyncPlayerMove)
dist = 20;
@@ -389,8 +396,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)
@@ -844,7 +849,17 @@ void LocalPlayer::nextTile(unsigned char dir A_UNUSED = 0)
mPath.clear();
}
- Being::nextTile();
+ if (mPath.empty())
+ {
+ if (mNavigatePath.empty() || mAction != MOVE)
+ setAction(STAND);
+ else
+ mNextStep = true;
+ }
+ else
+ {
+ Being::nextTile();
+ }
}
#ifdef MANASERV_SUPPORT
else
@@ -890,11 +905,11 @@ void LocalPlayer::inviteToGuild(Being *being)
// TODO: Allow user to choose which guild to invite being to
// For now, just invite to the first guild you have permissions to invite with
- std::map<int, Guild*>::iterator itr = mGuilds.begin();
- std::map<int, Guild*>::iterator itr_end = mGuilds.end();
+ std::map<int, Guild*>::const_iterator itr = mGuilds.begin();
+ std::map<int, Guild*>::const_iterator itr_end = mGuilds.end();
for (; itr != itr_end; ++itr)
{
- if (checkInviteRights(itr->second->getName()))
+ if (itr->second && checkInviteRights(itr->second->getName()))
{
Net::getGuildHandler()->invite(itr->second->getId(), being);
return;
@@ -1028,13 +1043,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);
@@ -1104,8 +1119,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);
}
@@ -1415,7 +1430,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"))
@@ -1533,9 +1548,6 @@ void LocalPlayer::setGotoTarget(Being *target)
}
}
-extern MiniStatusWindow *miniStatusWindow;
-extern SkillDialog *skillDialog;
-
void LocalPlayer::handleStatusEffect(StatusEffect *effect, int effectId)
{
Being::handleStatusEffect(effect, effectId);
@@ -1621,7 +1633,8 @@ void LocalPlayer::optionChanged(const std::string &value)
mTradebot = config.getBoolValue("tradebot");
}
-void LocalPlayer::event(Mana::Channels channel, const Mana::Event &event)
+void LocalPlayer::processEvent(Mana::Channels channel,
+ const Mana::Event &event)
{
if (channel == Mana::CHANNEL_ATTRIBUTES)
{
@@ -1749,9 +1762,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;
@@ -1799,9 +1815,9 @@ void LocalPlayer::moveToHome()
{
moveTo(mCrossX, mCrossY);
}
- else
+ else if (mMap)
{
- std::map<std::string, Vector>::iterator iter =
+ std::map<std::string, Vector>::const_iterator iter =
mHomes.find(mMap->getProperty("_realfilename"));
if (iter != mHomes.end())
@@ -1916,20 +1932,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)
@@ -1937,21 +1957,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);
- }
}
}
@@ -1959,29 +1975,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)
@@ -2238,7 +2247,7 @@ void LocalPlayer::crazyMove7()
void LocalPlayer::crazyMove8()
{
- if (mAction == MOVE)
+ if (mAction == MOVE || !mMap)
return;
int idx = 0;
int dist = 1;
@@ -2366,7 +2375,7 @@ void LocalPlayer::crazyMoveA()
if (mAction == MOVE)
return;
- if (mMoveProgram.length() == 0)
+ if (mMoveProgram.empty())
return;
if (mCrazyMoveState >= mMoveProgram.length())
@@ -2432,8 +2441,6 @@ void LocalPlayer::crazyMoveA()
// direction command
else if (mMoveProgram[mCrazyMoveState] == 'd')
{
- Uint8 dir = 0;
-
mCrazyMoveState ++;
if (mCrazyMoveState < mMoveProgram.length())
@@ -2479,6 +2486,7 @@ void LocalPlayer::crazyMoveA()
case 'L':
if (Client::limitPackets(PACKET_DIRECTION))
{
+ Uint8 dir = 0;
switch (getDirection())
{
case UP : dir = Being::LEFT; break;
@@ -2494,6 +2502,7 @@ void LocalPlayer::crazyMoveA()
case 'R':
if (Client::limitPackets(PACKET_DIRECTION))
{
+ Uint8 dir = 0;
switch (getDirection())
{
case UP : dir = Being::RIGHT; break;
@@ -2509,6 +2518,7 @@ void LocalPlayer::crazyMoveA()
case 'b':
if (Client::limitPackets(PACKET_DIRECTION))
{
+ Uint8 dir = 0;
switch (getDirection())
{
case UP : dir = Being::DOWN; break;
@@ -2595,11 +2605,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)
@@ -2844,8 +2851,6 @@ void LocalPlayer::specialMove(unsigned char direction)
}
else
{
-// if (direction != 0 && getInvertDirection() == 4)
-// crazyMove();
setWalkingDir(direction);
}
@@ -2966,7 +2971,6 @@ void LocalPlayer::setMap(Map *map)
Being::setMap(map);
updateNavigateList();
-// updateCoords();
}
void LocalPlayer::setHome()
@@ -2984,7 +2988,7 @@ void LocalPlayer::setHome()
if (mAction == SIT)
{
- std::map<std::string, Vector>::iterator iter = mHomes.find(key);
+ std::map<std::string, Vector>::const_iterator iter = mHomes.find(key);
if (iter != mHomes.end())
{
@@ -2998,8 +3002,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));
@@ -3017,8 +3019,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());
@@ -3034,8 +3034,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)
@@ -3046,8 +3044,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)
@@ -3062,7 +3058,6 @@ void LocalPlayer::setHome()
type = MapItem::EMPTY;
}
mMap->updatePortalTile("", type, getTileX(), getTileY());
-// mapItem = specialLayer->getTile(getTileX(), getTileY());
if (type != MapItem::EMPTY)
{
@@ -3090,7 +3085,7 @@ void LocalPlayer::saveHomes()
std::string homeStr;
std::stringstream ss(homeStr);
- for (std::map<std::string, Vector>::iterator iter = mHomes.begin();
+ for (std::map<std::string, Vector>::const_iterator iter = mHomes.begin();
iter != mHomes.end(); ++iter )
{
Vector pos = (*iter).second;
@@ -3336,8 +3331,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)
@@ -3561,17 +3555,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));
@@ -3621,7 +3607,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);
@@ -3661,9 +3648,9 @@ void LocalPlayer::followMoveTo(Being *being, int x1, int y1, int x2, int y2)
{
if (actorSpriteManager)
{
- Being *being = actorSpriteManager->findBeingByName(
- mPlayerFollowed, Being::PLAYER);
- setTarget(being);
+ Being *b = actorSpriteManager->findBeingByName(
+ mPlayerFollowed, Being::PLAYER);
+ setTarget(b);
}
}
moveToTarget();
@@ -3790,7 +3777,7 @@ void LocalPlayer::updateNavigateList()
{
if (mMap)
{
- std::map<std::string, Vector>::iterator iter =
+ std::map<std::string, Vector>::const_iterator iter =
mHomes.find(mMap->getProperty("_realfilename"));
if (iter != mHomes.end())