summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIra Rice <irarice@gmail.com>2009-02-17 13:36:53 -0700
committerIra Rice <irarice@gmail.com>2009-02-17 13:36:53 -0700
commited96706d8080049dc20d1487f6165ed9bd77306b (patch)
tree935ff3a65a4a2a307ade465a646a5a4cdd31e632
parent1a7a8714ce420e65cf34f65454682d202e9ba284 (diff)
downloadmana-ed96706d8080049dc20d1487f6165ed9bd77306b.tar.gz
mana-ed96706d8080049dc20d1487f6165ed9bd77306b.tar.bz2
mana-ed96706d8080049dc20d1487f6165ed9bd77306b.tar.xz
mana-ed96706d8080049dc20d1487f6165ed9bd77306b.zip
Fixed an error reported by m0t1k4 which caused a segmentation fault on
closing when displaying your own name is turned on. Signed-off-by: Ira Rice <irarice@gmail.com>
-rw-r--r--src/localplayer.cpp1
-rw-r--r--src/player.cpp45
2 files changed, 21 insertions, 25 deletions
diff --git a/src/localplayer.cpp b/src/localplayer.cpp
index a719e265..0470fefc 100644
--- a/src/localplayer.cpp
+++ b/src/localplayer.cpp
@@ -91,7 +91,6 @@ LocalPlayer::~LocalPlayer()
{
delete mInventory;
delete mStorage;
- delete mName;
for (int i = Being::TC_SMALL; i < Being::NUM_TC; i++)
{
diff --git a/src/player.cpp b/src/player.cpp
index 5256831b..4d5ef171 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -36,7 +36,7 @@ static const int NAME_Y_OFFSET = 30;
Player::Player(int id, int job, Map *map):
Being(id, job, map)
{
- mName = 0;
+ mName = NULL;
}
Player::~Player()
@@ -46,19 +46,21 @@ Player::~Player()
void Player::setName(const std::string &name)
{
- if (mName == 0)
+ if (mName == NULL)
{
if (mIsGM)
{
mNameColor = 0x009000;
- mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET,
- gcn::Graphics::CENTER, gcn::Color(0, 255, 0));
+ mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy +
+ NAME_Y_OFFSET, gcn::Graphics::CENTER,
+ gcn::Color(0, 255, 0));
}
else
{
mNameColor = 0x202020;
mName = new FlashText(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET,
- gcn::Graphics::CENTER, gcn::Color(255, 255, 255));
+ gcn::Graphics::CENTER,
+ gcn::Color(255, 255, 255));
}
Being::setName(name);
}
@@ -66,7 +68,8 @@ void Player::setName(const std::string &name)
void Player::logic()
{
- switch (mAction) {
+ switch (mAction)
+ {
case STAND:
break;
@@ -81,22 +84,25 @@ void Player::logic()
case WALK:
mFrame = (get_elapsed_time(mWalkTime) * 6) / mWalkSpeed;
- if (mFrame >= 6) {
+
+ if (mFrame >= 6)
nextStep();
- }
+
break;
case ATTACK:
int frames = 4;
- if ( mEquippedWeapon
- && mEquippedWeapon->getAttackType() == ACTION_ATTACK_BOW)
+ if (mEquippedWeapon &&
+ mEquippedWeapon->getAttackType() == ACTION_ATTACK_BOW)
{
frames = 5;
}
+
mFrame = (get_elapsed_time(mWalkTime) * frames) / mAttackSpeed;
- if (mFrame >= frames) {
+
+ if (mFrame >= frames)
nextStep();
- }
+
break;
}
@@ -111,9 +117,7 @@ Being::Type Player::getType() const
void Player::flash(int time)
{
if (mName)
- {
mName->flash(time);
- }
}
void Player::setGender(Gender gender)
@@ -132,9 +136,7 @@ void Player::setGender(Gender gender)
for (int i = 1; i < VECTOREND_SPRITE; i++)
{
if (mSpriteIDs.at(i) != 0)
- {
setSprite(i, mSpriteIDs.at(i), mSpriteColors.at(i));
- }
}
}
}
@@ -161,9 +163,7 @@ void Player::setSprite(int slot, int id, std::string color)
mSprites[slot] = NULL;
if (slot == WEAPON_SPRITE)
- {
mEquippedWeapon = NULL;
- }
}
else
{
@@ -174,8 +174,9 @@ void Player::setSprite(int slot, int id, std::string color)
{
if (!color.empty())
filename += "|" + color;
- equipmentSprite = AnimatedSprite::load(
- "graphics/sprites/" + filename);
+
+ equipmentSprite = AnimatedSprite::load("graphics/sprites/" +
+ filename);
}
if (equipmentSprite)
@@ -185,9 +186,7 @@ void Player::setSprite(int slot, int id, std::string color)
mSprites[slot] = equipmentSprite;
if (slot == WEAPON_SPRITE)
- {
mEquippedWeapon = &ItemDB::get(id);
- }
setAction(mAction);
}
@@ -198,8 +197,6 @@ void Player::setSprite(int slot, int id, std::string color)
void Player::updateCoords()
{
if (mName)
- {
mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET);
- }
}