diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-08-25 15:43:51 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-08-25 15:43:51 +0300 |
commit | 4a21e45a63137009a654a212ea7512ecc2846648 (patch) | |
tree | 13e0b726bacb3f73d9bf215a4c195ea75d4f6a55 | |
parent | 5f97d3fd31bb5a17037610342ea09c21da9c47d3 (diff) | |
download | manaplus-4a21e45a63137009a654a212ea7512ecc2846648.tar.gz manaplus-4a21e45a63137009a654a212ea7512ecc2846648.tar.bz2 manaplus-4a21e45a63137009a654a212ea7512ecc2846648.tar.xz manaplus-4a21e45a63137009a654a212ea7512ecc2846648.zip |
Add consts to being class.
-rw-r--r-- | src/avatar.h | 28 | ||||
-rw-r--r-- | src/being.cpp | 216 | ||||
-rw-r--r-- | src/being.h | 153 | ||||
-rw-r--r-- | src/localplayer.cpp | 4 | ||||
-rw-r--r-- | src/localplayer.h | 4 |
5 files changed, 214 insertions, 191 deletions
diff --git a/src/avatar.h b/src/avatar.h index 5ff0a8f75..d329f81a9 100644 --- a/src/avatar.h +++ b/src/avatar.h @@ -75,37 +75,37 @@ public: /** * Set the avatar's online status. */ - void setOnline(bool online) + void setOnline(const bool online) { mOnline = online; } int getHp() const { return mHp; } - void setHp(int hp) + void setHp(const int hp) { mHp = hp; } int getMaxHp() const { return mMaxHp; } - void setMaxHp(int maxHp) + void setMaxHp(const int maxHp) { mMaxHp = maxHp; } int getDamageHp() const { return mDamageHp; } - void setDamageHp(int damageHp) + void setDamageHp(const int damageHp) { mDamageHp = damageHp; } bool getDisplayBold() const { return mDisplayBold; } - void setDisplayBold(bool displayBold) + void setDisplayBold(const bool displayBold) { mDisplayBold = displayBold; } int getLevel() const { return mLevel; } - void setLevel(int level) + void setLevel(const int level) { mLevel = level; } std::string getMap() const @@ -117,49 +117,49 @@ public: int getX() const { return mX; } - void setX(int x) + void setX(const int x) { mX = x; } int getY() const { return mY; } - void setY(int y) + void setY(const int y) { mY = y; } int getType() const { return mType; } - void setType(int n) + void setType(const int n) { mType = n; } int getExp() const { return mExp; } - void setExp(int n) + void setExp(const int n) { mExp = n; } int getID() const { return mId; } - void setID(int id) + void setID(const int id) { mId = id; } int getCharId() const { return mCharId; } - void setCharId(int id) + void setCharId(const int id) { mCharId = id; } int getGender() const { return mGender; } - void setGender(int g) + void setGender(const int g) { mGender = g; } int getRace() const { return mRace; } - void setRace(int r) + void setRace(const int r) { mRace = r; } const std::string &getIp() const diff --git a/src/being.cpp b/src/being.cpp index 6316c26c3..d24ba1374 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -72,7 +72,7 @@ const unsigned int CACHE_SIZE = 50; class BeingCacheEntry { public: - BeingCacheEntry(int id): + BeingCacheEntry(const int id): mId(id), mName(""), mPartyName(""), @@ -118,13 +118,13 @@ class BeingCacheEntry const std::string &getGuildName() const { return mGuildName; } - void setLevel(int n) + void setLevel(const int n) { mLevel = n; } int getLevel() const { return mLevel; } - void setTime(int n) + void setTime(const int n) { mTime = n; } int getTime() const @@ -133,7 +133,7 @@ class BeingCacheEntry unsigned getPvpRank() const { return mPvpRank; } - void setPvpRank(int r) + void setPvpRank(const int r) { mPvpRank = r; } std::string getIp() const @@ -145,13 +145,13 @@ class BeingCacheEntry bool isAdvanced() const { return mIsAdvanced; } - void setAdvanced(bool a) + void setAdvanced(const bool a) { mIsAdvanced = a; } int getFlags() const { return mFlags; } - void setFlags(int flags) + void setFlags(const int flags) { mFlags = flags; } protected: @@ -190,7 +190,8 @@ std::list<BeingCacheEntry*> beingInfoCache; // TODO: mWalkTime used by eAthena only -Being::Being(int id, Type type, uint16_t subtype, Map *map): +Being::Being(const int id, const Type type, const uint16_t subtype, + Map *const map) : ActorSprite(id), mInfo(BeingInfo::unknown), mActionTime(0), @@ -288,7 +289,7 @@ Being::~Being() mText = nullptr; } -void Being::setSubtype(uint16_t subtype) +void Being::setSubtype(const uint16_t subtype) { if (!mInfo) return; @@ -354,7 +355,7 @@ void Being::setPosition(const Vector &pos) } } -void Being::setDestination(int dstX, int dstY) +void Being::setDestination(const int dstX, const int dstY) { // We can't calculate anything without a map anyway. if (!mMap) @@ -440,7 +441,7 @@ void Being::setSpeech(const std::string &text, int time) // Trim whitespace trim(mSpeech); - unsigned int lineLim = mConfLineLim; + const unsigned int lineLim = mConfLineLim; if (lineLim > 0 && mSpeech.length() > lineLim) mSpeech = mSpeech.substr(0, lineLim); @@ -504,7 +505,8 @@ void Being::setSpeech(const std::string &text, int time) } } -void Being::takeDamage(Being *attacker, int amount, AttackType type, int id) +void Being::takeDamage(Being *const attacker, const int amount, + const AttackType type, const int id) { if (!userPalette || !attacker) return; @@ -638,7 +640,8 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type, int id) int hitEffectId = 0; if (type != SKILL) { - const ItemInfo *attackerWeapon = attacker->getEquippedWeapon(); + const ItemInfo *const attackerWeapon + = attacker->getEquippedWeapon(); if (attacker->mType == PLAYER && attackerWeapon) { if (type != CRITICAL) @@ -664,8 +667,8 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type, int id) } } -void Being::handleAttack(Being *victim, int damage, - AttackType type A_UNUSED) +void Being::handleAttack(Being *const victim, const int damage, + const AttackType type A_UNUSED) { if (!victim || !mInfo) return; @@ -688,7 +691,8 @@ void Being::handleAttack(Being *victim, int damage, if (this != player_node) { - uint8_t dir = calcDirection(victim->getTileX(), victim->getTileY()); + const uint8_t dir = calcDirection(victim->getTileX(), + victim->getTileY()); if (dir) setDirection(dir); } @@ -699,7 +703,8 @@ void Being::handleAttack(Being *victim, int damage, SOUND_EVENT_HIT : SOUND_EVENT_MISS), mX, mY); } -void Being::handleSkill(Being *victim, int damage, int skillId) +void Being::handleSkill(Being *const victim, const int damage, + const int skillId) { if (!victim || !mInfo || !skillDialog) return; @@ -707,7 +712,7 @@ void Being::handleSkill(Being *victim, int damage, int skillId) if (this != player_node) setAction(Being::ATTACK, 1); - SkillInfo *skill = skillDialog->getSkill(skillId); + const SkillInfo *const skill = skillDialog->getSkill(skillId); if (skill) fireMissile(victim, skill->particle); @@ -721,7 +726,8 @@ void Being::handleSkill(Being *victim, int damage, int skillId) if (this != player_node) { - uint8_t dir = calcDirection(victim->getTileX(), victim->getTileY()); + const uint8_t dir = calcDirection(victim->getTileX(), + victim->getTileY()); if (dir) setDirection(dir); } @@ -758,7 +764,7 @@ void Being::setName(const std::string &name) } } -void Being::setShowName(bool doShowName) +void Being::setShowName(const bool doShowName) { if (mShowName == doShowName) return; @@ -785,7 +791,7 @@ void Being::setGuildPos(const std::string &pos A_UNUSED) { } -void Being::addGuild(Guild *guild) +void Being::addGuild(Guild *const guild) { if (!guild) return; @@ -796,7 +802,7 @@ void Being::addGuild(Guild *guild) socialWindow->addTab(guild); } -void Being::removeGuild(int id) +void Being::removeGuild(const int id) { if (this == player_node && socialWindow) socialWindow->removeTab(mGuilds[id]); @@ -811,7 +817,7 @@ Guild *Being::getGuild(const std::string &guildName) const for (std::map<int, Guild*>::const_iterator itr = mGuilds.begin(), itr_end = mGuilds.end(); itr != itr_end; ++itr) { - Guild *guild = itr->second; + Guild *const guild = itr->second; if (guild && guild->getName() == guildName) return guild; } @@ -819,9 +825,9 @@ Guild *Being::getGuild(const std::string &guildName) const return nullptr; } -Guild *Being::getGuild(int id) const +Guild *Being::getGuild(const int id) const { - std::map<int, Guild*>::const_iterator itr = mGuilds.find(id); + const std::map<int, Guild*>::const_iterator itr = mGuilds.find(id); if (itr != mGuilds.end()) return itr->second; @@ -830,7 +836,7 @@ Guild *Being::getGuild(int id) const Guild *Being::getGuild() const { - std::map<int, Guild*>::const_iterator itr = mGuilds.begin(); + const std::map<int, Guild*>::const_iterator itr = mGuilds.begin(); if (itr != mGuilds.end()) return itr->second; @@ -842,7 +848,7 @@ void Being::clearGuilds() for (std::map<int, Guild*>::const_iterator itr = mGuilds.begin(), itr_end = mGuilds.end(); itr != itr_end; ++itr) { - Guild *guild = itr->second; + Guild *const guild = itr->second; if (guild) { @@ -856,12 +862,12 @@ void Being::clearGuilds() mGuilds.clear(); } -void Being::setParty(Party *party) +void Being::setParty(Party *const party) { if (party == mParty) return; - Party *old = mParty; + Party *const old = mParty; mParty = party; if (old) @@ -887,7 +893,7 @@ void Being::updateGuild() if (!player_node) return; - Guild *guild = player_node->getGuild(); + Guild *const guild = player_node->getGuild(); if (!guild) { clearGuilds(); @@ -903,9 +909,9 @@ void Being::updateGuild() updateColors(); } -void Being::setGuild(Guild *guild) +void Being::setGuild(Guild *const guild) { - Guild *old = getGuild(); + Guild *const old = getGuild(); if (guild == old) return; @@ -927,17 +933,18 @@ void Being::setGuild(Guild *guild) } } -void Being::fireMissile(Being *victim, const std::string &particle) +void Being::fireMissile(Being *const victim, const std::string &particle) const { if (!victim || particle.empty() || !particleEngine) return; - Particle *target = particleEngine->createChild(); + Particle *const target = particleEngine->createChild(); if (!target) return; - Particle *missile = target->addEffect(particle, getPixelX(), getPixelY()); + Particle *const missile = target->addEffect( + particle, getPixelX(), getPixelY()); if (missile) { @@ -966,7 +973,7 @@ std::string Being::getSitAction() const } } -void Being::setAction(Action action, int attackType A_UNUSED) +void Being::setAction(const Action action, const int attackType A_UNUSED) { std::string currentAction = SpriteAction::INVALID; @@ -1077,7 +1084,7 @@ void Being::setAction(Action action, int attackType A_UNUSED) mActionTime = tick_time; } -void Being::setDirection(uint8_t direction) +void Being::setDirection(const uint8_t direction) { if (mDirection == direction) return; @@ -1138,7 +1145,7 @@ uint8_t Being::calcDirection() const return dir; } -uint8_t Being::calcDirection(int dstX, int dstY) const +uint8_t Being::calcDirection(const int dstX, const int dstY) const { uint8_t dir = 0; if (dstX > mX) @@ -1160,10 +1167,10 @@ void Being::nextTile() return; } - Position pos = mPath.front(); + const Position pos = mPath.front(); mPath.pop_front(); - uint8_t dir = calcDirection(pos.x, pos.y); + const uint8_t dir = calcDirection(pos.x, pos.y); if (dir) setDirection(dir); @@ -1347,9 +1354,9 @@ void Being::logic() case RIGHT: rotation = 270; break; default: break; } - Particle *p = particleEngine->addEffect(particleEffect, - 0, 0, rotation); - controlParticle(p); + Particle *const p = particleEngine->addEffect( + particleEffect, 0, 0, rotation); + controlParticle(p); } if (this == player_node && curFrame >= frameCount) @@ -1387,7 +1394,8 @@ void Being::logic() } } -void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) +void Being::drawEmotion(Graphics *const graphics, const int offsetX, + const int offsetY) { if (!mEmotion) return; @@ -1405,7 +1413,7 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) } } -void Being::drawSpeech(int offsetX, int offsetY) +void Being::drawSpeech(const int offsetX, const int offsetY) { if (!mSpeechBubble || mSpeech.empty()) return; @@ -1456,7 +1464,7 @@ void Being::drawSpeech(int offsetX, int offsetY) } /** TODO: eAthena only */ -int Being::getOffset(char pos, char neg) const +int Being::getOffset(const char pos, const char neg) const { // Check whether we're walking in the requested direction if (mAction != MOVE || !(mDirection & (pos | neg))) @@ -1515,7 +1523,7 @@ void Being::optionChanged(const std::string &value) setShowName(config.getBoolValue("visiblenames")); } -void Being::flashName(int time) +void Being::flashName(const int time) { if (mDispName) mDispName->flash(time); @@ -1684,8 +1692,9 @@ void Being::updateColors() } } -void Being::setSprite(unsigned int slot, int id, std::string color, - unsigned char colorId, bool isWeapon, bool isTempSprite) +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 >= Net::getCharHandler()->maxSprite()) return; @@ -1748,12 +1757,12 @@ void Being::setSprite(unsigned int slot, int id, std::string color, } } -void Being::setSpriteID(unsigned int slot, int id) +void Being::setSpriteID(const unsigned int slot, const int id) { setSprite(slot, id, mSpriteColors[slot]); } -void Being::setSpriteColor(unsigned int slot, const std::string &color) +void Being::setSpriteColor(const unsigned int slot, const std::string &color) { setSprite(slot, mSpriteIDs[slot], color); } @@ -1805,7 +1814,7 @@ void Being::reReadConfig() bool Being::updateFromCache() { - BeingCacheEntry *entry = Being::getCacheEntry(getId()); + const BeingCacheEntry *const entry = Being::getCacheEntry(getId()); if (entry && entry->getTime() + 120 >= cur_time) { @@ -1820,7 +1829,7 @@ bool Being::updateFromCache() mAdvanced = entry->isAdvanced(); if (entry->isAdvanced()) { - int flags = entry->getFlags(); + const int flags = entry->getFlags(); mShop = ((flags & FLAG_SHOP) != 0); mAway = ((flags & FLAG_AWAY) != 0); mInactive = ((flags & FLAG_INACTIVE) != 0); @@ -1841,7 +1850,7 @@ bool Being::updateFromCache() return false; } -void Being::addToCache() +void Being::addToCache() const { if (player_node == this) return; @@ -1886,7 +1895,7 @@ void Being::addToCache() } } -BeingCacheEntry* Being::getCacheEntry(int id) +BeingCacheEntry* Being::getCacheEntry(const int id) { for (std::list<BeingCacheEntry*>::iterator i = beingInfoCache.begin(); i != beingInfoCache.end(); ++ i) @@ -1909,7 +1918,7 @@ BeingCacheEntry* Being::getCacheEntry(int id) } -void Being::setGender(Gender gender) +void Being::setGender(const Gender gender) { if (gender != mGender) { @@ -1926,7 +1935,7 @@ void Being::setGender(Gender gender) } } -void Being::setGM(bool gm) +void Being::setGM(const bool gm) { mIsGM = gm; @@ -1959,7 +1968,7 @@ void Being::drawSprites(Graphics* graphics, int posX, int posY) const if (rSprite == 1) continue; - Sprite *sprite = getSprite(mSpriteRemap[f]); + Sprite *const sprite = getSprite(mSpriteRemap[f]); if (sprite) { sprite->setAlpha(mAlpha); @@ -1977,7 +1986,7 @@ void Being::drawSpritesSDL(Graphics* graphics, int posX, int posY) const if (rSprite == 1) continue; - Sprite *sprite = getSprite(mSpriteRemap[f]); + const Sprite *const sprite = getSprite(mSpriteRemap[f]); if (sprite) sprite->draw(graphics, posX, posY); } @@ -1999,7 +2008,7 @@ bool Being::drawSpriteAt(Graphics *graphics, int x, int y) const if (mDrawHotKeys && !mName.empty()) { - gcn::Font *font = gui->getFont(); + gcn::Font *const font = gui->getFont(); if (font) { graphics->setColor(userPalette->getColor(UserPalette::BEING)); @@ -2047,9 +2056,10 @@ bool Being::drawSpriteAt(Graphics *graphics, int x, int y) const return res; } -void Being::drawHpBar(Graphics *graphics, int maxHP, int hp, int damage, - int color1, int color2, int x, int y, - int width, int height) const +void Being::drawHpBar(Graphics *const graphics, const int maxHP, const int hp, + const int damage, const int color1, const int color2, + const int x, const int y, const int width, + const int height) const { if (maxHP <= 0) return; @@ -2076,7 +2086,7 @@ void Being::drawHpBar(Graphics *graphics, int maxHP, int hp, int damage, if (p <= 0 || p > width) return; - int dx = static_cast<int>(static_cast<float>(width) / p); + const int dx = static_cast<const int>(static_cast<float>(width) / p); if (serverVersion < 1) { // old servers @@ -2123,7 +2133,7 @@ void Being::drawHpBar(Graphics *graphics, int maxHP, int hp, int damage, x + dx, y, width - dx, height)); } -void Being::setHP(int hp) +void Being::setHP(const int hp) { mHP = hp; if (mMaxHP < mHP) @@ -2132,7 +2142,7 @@ void Being::setHP(int hp) updatePercentHP(); } -void Being::setMaxHP(int hp) +void Being::setMaxHP(const int hp) { mMaxHP = hp; if (mMaxHP < mHP) @@ -2154,7 +2164,7 @@ void Being::recalcSpritesOrder() return; // logger->log("recalcSpritesOrder"); - unsigned sz = static_cast<unsigned>(size()); + const unsigned sz = static_cast<unsigned>(size()); if (sz < 1) return; @@ -2180,7 +2190,7 @@ void Being::recalcSpritesOrder() if (mSpriteIDs.size() <= slot) continue; - int id = mSpriteIDs[slot]; + const int id = mSpriteIDs[slot]; if (!id) continue; @@ -2188,15 +2198,15 @@ void Being::recalcSpritesOrder() if (info.isRemoveSprites()) { - SpriteToItemMap *spriteToItems = info.getSpriteToItemReplaceMap( - mSpriteDirection); + SpriteToItemMap *const spriteToItems + = info.getSpriteToItemReplaceMap(mSpriteDirection); if (spriteToItems) { for (SpriteToItemMapCIter itr = spriteToItems->begin(), itr_end = spriteToItems->end(); itr != itr_end; ++ itr) { - int remSprite = itr->first; + const int remSprite = itr->first; const std::map<int, int> &itemReplacer = itr->second; if (remSprite >= 0) { // slot known @@ -2254,7 +2264,7 @@ void Being::recalcSpritesOrder() if (info.mDrawBefore[dir] > 0) { - int id2 = mSpriteIDs[info.mDrawBefore[dir]]; + const int id2 = mSpriteIDs[info.mDrawBefore[dir]]; if (itemSlotRemap.find(id2) != itemSlotRemap.end()) { // logger->log("found duplicate (before)"); @@ -2276,7 +2286,7 @@ void Being::recalcSpritesOrder() } else if (info.mDrawAfter[dir] > 0) { - int id2 = mSpriteIDs[info.mDrawAfter[dir]]; + const int id2 = mSpriteIDs[info.mDrawAfter[dir]]; if (itemSlotRemap.find(id2) != itemSlotRemap.end()) { // logger->log("found duplicate (after)"); @@ -2310,8 +2320,8 @@ void Being::recalcSpritesOrder() for (unsigned slot0 = 0; slot0 < sz; slot0 ++) { - int slot = searchSlotValue(slotRemap, slot0); - int val = slotRemap.at(slot); + const int slot = searchSlotValue(slotRemap, slot0); + const int val = slotRemap.at(slot); int id = 0; if (static_cast<int>(mSpriteIDs.size()) > val) @@ -2321,7 +2331,7 @@ void Being::recalcSpritesOrder() int idx1 = -1; // logger->log("item %d, id=%d", slot, id); int reorder = 0; - std::map<int, int>::const_iterator + const std::map<int, int>::const_iterator orderIt = itemSlotRemap.find(id); if (orderIt != itemSlotRemap.end()) reorder = orderIt->second; @@ -2378,7 +2388,7 @@ void Being::recalcSpritesOrder() mSpriteRemap[slot] = slotRemap[slot]; if (oldHide[slot] != 0 && oldHide[slot] != 1 && mSpriteHide[slot] == 0) { - int id = mSpriteIDs[slot]; + const int id = mSpriteIDs[slot]; if (!id) continue; @@ -2388,7 +2398,7 @@ void Being::recalcSpritesOrder() } } -int Being::searchSlotValue(std::vector<int> &slotRemap, int val) +int Being::searchSlotValue(std::vector<int> &slotRemap, const int val) const { for (unsigned slot = 0; slot < size(); slot ++) { @@ -2399,11 +2409,12 @@ int Being::searchSlotValue(std::vector<int> &slotRemap, int val) } void Being::searchSlotValueItr(std::vector<int>::iterator &it, int &idx, - std::vector<int> &slotRemap, int val) + std::vector<int> &slotRemap, + const int val) const { // logger->log("searching %d", val); it = slotRemap.begin(); - std::vector<int>::iterator it_end = slotRemap.end(); + const std::vector<int>::iterator it_end = slotRemap.end(); idx = 0; while (it != it_end) { @@ -2421,7 +2432,7 @@ void Being::searchSlotValueItr(std::vector<int>::iterator &it, int &idx, return; } -void Being::updateHit(int amount) +void Being::updateHit(const int amount) { if (amount > 0) { @@ -2434,13 +2445,13 @@ void Being::updateHit(int amount) Equipment *Being::getEquipment() { - Equipment *eq = new Equipment(); - Equipment::Backend *bk = new BeingEquipBackend(this); + Equipment *const eq = new Equipment(); + Equipment::Backend *const bk = new BeingEquipBackend(this); eq->setBackend(bk); return eq; } -void Being::undressItemById(int id) +void Being::undressItemById(const int id) { size_t sz = mSpriteIDs.size(); @@ -2469,7 +2480,7 @@ void Being::updateComment() mComment = loadComment(mName, mType); } -std::string Being::loadComment(const std::string &name, int type) +std::string Being::loadComment(const std::string &name, const int type) { std::string str; switch (type) @@ -2488,7 +2499,7 @@ std::string Being::loadComment(const std::string &name, int type) logger->log("load from: %s", str.c_str()); StringVect lines; - ResourceManager *resman = ResourceManager::getInstance(); + ResourceManager *const resman = ResourceManager::getInstance(); if (resman->existsLocal(str)) { lines = resman->loadTextFileLocal(str); @@ -2499,7 +2510,7 @@ std::string Being::loadComment(const std::string &name, int type) } void Being::saveComment(const std::string &name, - const std::string &comment, int type) + const std::string &comment, const int type) { std::string dir; switch (type) @@ -2514,16 +2525,16 @@ void Being::saveComment(const std::string &name, return; } dir += stringToHexPath(name); - ResourceManager *resman = ResourceManager::getInstance(); + ResourceManager *const resman = ResourceManager::getInstance(); resman->saveTextFile(dir, "comment.txt", name + "\n" + comment); } -void Being::setState(uint8_t state) +void Being::setState(const uint8_t state) { - bool shop = ((state & FLAG_SHOP) != 0); - bool away = ((state & FLAG_AWAY) != 0); - bool inactive = ((state & FLAG_INACTIVE) != 0); - bool needUpdate = (shop != mShop || away != mAway + const bool shop = ((state & FLAG_SHOP) != 0); + const bool away = ((state & FLAG_AWAY) != 0); + const bool inactive = ((state & FLAG_INACTIVE) != 0); + const bool needUpdate = (shop != mShop || away != mAway || inactive != mInactive); mShop = shop; @@ -2537,7 +2548,7 @@ void Being::setState(uint8_t state) } } -void Being::setEmote(uint8_t emotion, int emote_time) +void Being::setEmote(const uint8_t emotion, const int emote_time) { if ((emotion & FLAG_SPECIAL) == FLAG_SPECIAL) { @@ -2557,7 +2568,7 @@ void Being::updatePercentHP() return; if (mHP) { - unsigned num = mHP * 100 / mMaxHP; + const unsigned num = mHP * 100 / mMaxHP; if (num != mNumber) { mNumber = num; @@ -2567,7 +2578,7 @@ void Being::updatePercentHP() } } -uint8_t Being::genderToInt(Gender sex) +uint8_t Being::genderToInt(const Gender sex) { switch (sex) { @@ -2582,7 +2593,7 @@ uint8_t Being::genderToInt(Gender sex) } } -Gender Being::intToGender(uint8_t sex) +Gender Being::intToGender(const uint8_t sex) { switch (sex) { @@ -2596,7 +2607,7 @@ Gender Being::intToGender(uint8_t sex) } } -int Being::getSpriteID(int slot) +int Being::getSpriteID(const int slot) const { if (slot < 0 || static_cast<unsigned>(slot) >= mSpriteIDs.size()) return -1; @@ -2604,7 +2615,7 @@ int Being::getSpriteID(int slot) return mSpriteIDs[slot]; } -BeingEquipBackend::BeingEquipBackend(Being *being): +BeingEquipBackend::BeingEquipBackend(Being *const being): mBeing(being) { memset(mEquipment, 0, sizeof(mEquipment)); @@ -2614,8 +2625,9 @@ BeingEquipBackend::BeingEquipBackend(Being *being): for (unsigned f = 0; f < sz; f ++) { - int idx = Net::getInventoryHandler()->convertFromServerSlot(f); - int id = being->mSpriteIDs[f]; + const int idx = Net::getInventoryHandler()-> + convertFromServerSlot(f); + const int id = being->mSpriteIDs[f]; if (id > 0 && idx >= 0 && idx < EQUIPMENT_SIZE) { mEquipment[idx] = new Item(id, 1, 0, @@ -2639,12 +2651,12 @@ void BeingEquipBackend::clear() } } -void BeingEquipBackend::setEquipment(int index, Item *item) +void BeingEquipBackend::setEquipment(const int index, Item *const item) { mEquipment[index] = item; } -Item *BeingEquipBackend::getEquipment(int index) const +Item *BeingEquipBackend::getEquipment(const int index) const { if (index < 0 || index >= EQUIPMENT_SIZE) return nullptr; diff --git a/src/being.h b/src/being.h index 66e6618e2..453a30a18 100644 --- a/src/being.h +++ b/src/being.h @@ -74,15 +74,15 @@ enum Gender class BeingEquipBackend : public Equipment::Backend { public: - BeingEquipBackend(Being *being); + BeingEquipBackend(Being *const being); virtual ~BeingEquipBackend(); - Item *getEquipment(int index) const; + Item *getEquipment(const int index) const; void clear(); - void setEquipment(int index, Item *item); + void setEquipment(const int index, Item *const item); private: Item *mEquipment[EQUIPMENT_SIZE]; @@ -165,7 +165,8 @@ class Being : public ActorSprite, public ConfigListener * @param subtype partly determines the type of the being * @param map the map the being is on */ - Being(int id, Type type, uint16_t subtype, Map *map); + Being(const int id, const Type type, const uint16_t subtype, + Map *const map); virtual ~Being(); @@ -187,7 +188,7 @@ class Being : public ActorSprite, public ConfigListener * Set the current action time. * @see Ea::BeingHandler that set it to tick time. */ - void setActionTime(int actionTime) + void setActionTime(const int actionTime) { mActionTime = actionTime; } /** @@ -213,7 +214,7 @@ class Being : public ActorSprite, public ConfigListener /** * Creates a path for the being from current position to ex and ey */ - void setDestination(int ex, int ey); + void setDestination(const int dstX, const int dstY); /** * Returns the destination for this being. @@ -236,7 +237,7 @@ class Being : public ActorSprite, public ConfigListener /** * Sets the tile x and y coord */ - void setTileCoords(int x, int y) + void setTileCoords(const int x, const int y) { mX = x; mY = y; } /** @@ -256,8 +257,8 @@ class Being : public ActorSprite, public ConfigListener * @param type the attack type * @param id skill id */ - void takeDamage(Being *attacker, int damage, - AttackType type, int id = 0); + void takeDamage(Being *const attacker, const int damage, + const AttackType type, const int id = 0); /** * Handles an attack of another being by this being. @@ -266,9 +267,11 @@ class Being : public ActorSprite, public ConfigListener * @param damage the amount of damage dealt (0 means miss) * @param type the attack type */ - virtual void handleAttack(Being *victim, int damage, AttackType type); + virtual void handleAttack(Being *const victim, const int damage, + const AttackType type); - virtual void handleSkill(Being *victim, int damage, int skillId); + virtual void handleSkill(Being *const victim, const int damage, + const int skillId); const ItemInfo *getEquippedWeapon() const { return mEquippedWeapon; } @@ -289,7 +292,7 @@ class Being : public ActorSprite, public ConfigListener bool getShowName() const { return mShowName; } - void setShowName(bool doShowName); + void setShowName(const bool doShowName); /** * Sets the name of the party the being is in. Shown in BeingPopup. @@ -314,12 +317,12 @@ class Being : public ActorSprite, public ConfigListener /** * Adds a guild to the being. */ - void addGuild(Guild *guild); + void addGuild(Guild *const guild); /** * Removers a guild from the being. */ - void removeGuild(int id); + void removeGuild(const int id); /** * Returns a pointer to the specified guild that the being is in. @@ -329,7 +332,7 @@ class Being : public ActorSprite, public ConfigListener /** * Returns a pointer to the specified guild that the being is in. */ - Guild *getGuild(int id) const; + Guild *getGuild(const int id) const; /** * Returns a pointer to the specified guild that the being is in. @@ -356,29 +359,31 @@ class Being : public ActorSprite, public ConfigListener bool isInParty() const { return mParty; } - void setParty(Party *party); + void setParty(Party *const party); - void setGuild(Guild *guild); + void setGuild(Guild *const guild); void updateGuild(); Party *getParty() const { return mParty; } - int getSpritesCount() + int getSpritesCount() const { return static_cast<int>(size()); } /** * Sets visible equipments for this being. */ - void setSprite(unsigned int slot, int id, + void setSprite(const unsigned int slot, const int id, std::string color = "", - unsigned char colorId = 1, bool isWeapon = false, - bool isTempSprite = false); + const unsigned char colorId = 1, + const bool isWeapon = false, + const bool isTempSprite = false); - void setSpriteID(unsigned int slot, int id); + void setSpriteID(const unsigned int slot, const int id); - void setSpriteColor(unsigned int slot, const std::string &color = ""); + void setSpriteColor(const unsigned int slot, + const std::string &color = ""); /** * Get the number of hairstyles implemented @@ -400,12 +405,13 @@ class Being : public ActorSprite, public ConfigListener /** * Draws the speech text above the being. */ - void drawSpeech(int offsetX, int offsetY); + void drawSpeech(const int offsetX, const int offsetY); /** * Draws the emotion picture above the being. */ - void drawEmotion(Graphics *graphics, int offsetX, int offsetY); + void drawEmotion(Graphics *const graphics, const int offsetX, + const int offsetY); uint16_t getSubType() const { return mSubType; } @@ -413,7 +419,7 @@ class Being : public ActorSprite, public ConfigListener /** * Set Being's subtype (mostly for view for monsters and NPCs) */ - void setSubtype(uint16_t subtype); + void setSubtype(const uint16_t subtype); const BeingInfo *getInfo() const { return mInfo; } @@ -459,7 +465,7 @@ class Being : public ActorSprite, public ConfigListener * in pixels per second for eAthena, * in tiles per second for Manaserv. */ - void setWalkSpeed(Vector speed) + void setWalkSpeed(const Vector speed) { mWalkSpeed = speed; } /** @@ -474,7 +480,7 @@ class Being : public ActorSprite, public ConfigListener * Sets the attack speed. * @todo In what unit? */ - void setAttackSpeed(int speed) + void setAttackSpeed(const int speed) { mAttackSpeed = speed; } /** @@ -487,7 +493,7 @@ class Being : public ActorSprite, public ConfigListener /** * Sets the current action. */ - virtual void setAction(Action action, int attackType = 0); + virtual void setAction(const Action action, const int attackType = 0); /** * Get the being's action currently performed. @@ -510,9 +516,9 @@ class Being : public ActorSprite, public ConfigListener /** * Sets the current direction. */ - virtual void setDirection(uint8_t direction); + virtual void setDirection(const uint8_t direction); - virtual void setDirectionDelayed(uint8_t direction) + virtual void setDirectionDelayed(const uint8_t direction) { mDirectionDelayed = direction; } uint8_t getDirectionDelayed() const @@ -531,7 +537,8 @@ class Being : public ActorSprite, public ConfigListener * * @see setPosition(const Vector &pos) */ - inline void setPosition(float x, float y, float z = 0.0f) + inline void setPosition(const float x, const float y, + const float z = 0.0f) { setPosition(Vector(x, y, z)); } /** @@ -555,7 +562,8 @@ class Being : public ActorSprite, public ConfigListener /** * Shoots a missile particle from this being, to target being */ - void fireMissile(Being *target, const std::string &particle); + void fireMissile(Being *const target, + const std::string &particle) const; /** * Returns the path this being is following. An empty path is returned @@ -567,16 +575,16 @@ class Being : public ActorSprite, public ConfigListener int getDistance() const { return mDistance; } - void setDistance(int n) + void setDistance(const int n) { mDistance = n; } /** * Set the Emoticon type and time displayed above * the being. */ - void setEmote(uint8_t emotion, int emote_time); + void setEmote(const uint8_t emotion, const int emote_time); - void setState(uint8_t state); + void setState(const uint8_t state); /** * Get the current Emoticon type displayed above @@ -590,31 +598,32 @@ class Being : public ActorSprite, public ConfigListener virtual void drawSpritesSDL(Graphics* graphics, int posX, int posY) const; - void drawHpBar(Graphics *graphics, int x, int y, - int maxHP, int hp, int damage, int color1, int color2, - int width, int height) const; + void drawHpBar(Graphics *const graphics, const int x, const int y, + const int maxHP, const int hp, const int damage, + const int color1, const int color2, const int width, + const int height) const; static void load(); virtual void optionChanged(const std::string &value); - void flashName(int time); + void flashName(const int time); int getDamageTaken() const { return mDamageTaken; } - void setDamageTaken(int damage) + void setDamageTaken(const int damage) { mDamageTaken = damage; } void updateName(); - void setLevel(int n) + void setLevel(const int n) { mLevel = n; } virtual int getLevel() const { return mLevel; } - void setIsReachable(int n) + void setIsReachable(const int n) { mIsReachable = n; } int isReachable() const @@ -622,16 +631,16 @@ class Being : public ActorSprite, public ConfigListener static void reReadConfig(); - static BeingCacheEntry* getCacheEntry(int id); + static BeingCacheEntry* getCacheEntry(const int id); - void addToCache(); + void addToCache() const; bool updateFromCache(); /** * Sets the gender of this being. */ - virtual void setGender(Gender gender); + virtual void setGender(const Gender gender); Gender getGender() const { return mGender; } @@ -650,9 +659,9 @@ class Being : public ActorSprite, public ConfigListener /** * Triggers whether or not to show the name as a GM name. */ - void setGM(bool gm); + void setGM(const bool gm); - bool canTalk() + bool canTalk() const { return mType == NPC; } void talkTo(); @@ -695,7 +704,7 @@ class Being : public ActorSprite, public ConfigListener virtual void updateColors(); - void setEnemy(bool n) + void setEnemy(const bool n) { mEnemy = n; } const std::string &getIp() const @@ -707,21 +716,21 @@ class Being : public ActorSprite, public ConfigListener unsigned int getPvpRank() const { return mPvpRank; } - void setPvpRank(unsigned int rank) + void setPvpRank(const unsigned int rank) { mPvpRank = rank; } - void setHP(int n); + void setHP(const int n); - void setMaxHP(int hp); + void setMaxHP(const int hp); int getHP() const { return mHP; } - uint8_t calcDirection(int dstX, int dstY) const; + uint8_t calcDirection(const int dstX, const int dstY) const; uint8_t calcDirection() const; - void setAttackDelay(int n) + void setAttackDelay(const int n) { mAttackDelay = n; } int getAttackDelay() const @@ -730,31 +739,31 @@ class Being : public ActorSprite, public ConfigListener int getMinHit() const { return mMinHit; } - void setMinHit(int n) + void setMinHit(const int n) { mMinHit = n; } int getMaxHit() const { return mMaxHit; } - void setMaxHit(int n) + void setMaxHit(const int n) { mMaxHit = n; } int getCriticalHit() const { return mCriticalHit; } - void setCriticalHit(int n) + void setCriticalHit(const int n) { mCriticalHit = n; } - void updateHit(int amount); + void updateHit(const int amount); Equipment *getEquipment(); - void undressItemById(int id); + void undressItemById(const int id); int getGoodStatus() const { return mGoodStatus; } - void setGoodStatus(int n) + void setGoodStatus(const int n) { mGoodStatus = n; } std::string getGenderSign() const; @@ -771,27 +780,28 @@ class Being : public ActorSprite, public ConfigListener static void clearCache(); - static std::string loadComment(const std::string &name, int type); + static std::string loadComment(const std::string &name, + const int type); static void saveComment(const std::string &name, - const std::string &comment, int type); + const std::string &comment, const int type); bool isAdvanced() const { return mAdvanced; } - void setAdvanced(bool n) + void setAdvanced(const bool n) { mAdvanced = n; addToCache(); } bool isShopEnabled() const { return mShop; } - void enableShop(bool b) + void enableShop(const bool b) { mShop = b; } /** * Sets the attack range. */ - void setAttackRange(int range) + void setAttackRange(const int range) { mAttackRange = range; } void attack(Being *target = nullptr, bool keep = false, @@ -805,12 +815,12 @@ class Being : public ActorSprite, public ConfigListener void setRaceName(std::string name) { mRaceName = name; } - std::string getRaceName() + std::string getRaceName() const { return mRaceName; } - int getSpriteID(int slot); + int getSpriteID(const int slot) const; - static uint8_t genderToInt(Gender sex); + static uint8_t genderToInt(const Gender sex); static Gender intToGender(uint8_t sex); @@ -892,12 +902,13 @@ class Being : public ActorSprite, public ConfigListener * If walking in direction 'neg' the value is negated. * TODO: Used by eAthena only? */ - int getOffset(char pos, char neg) const; + int getOffset(const char pos, const char neg) const; - int searchSlotValue(std::vector<int> &slotRemap, int val); + int searchSlotValue(std::vector<int> &slotRemap, const int val) const; void searchSlotValueItr(std::vector<int>::iterator &it, int &idx, - std::vector<int> &slotRemap, int val); + std::vector<int> &slotRemap, + const int val) const; const Type mType; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index dec72bcf7..a7e352c48 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -364,7 +364,7 @@ void LocalPlayer::slowLogic() } } -void LocalPlayer::setAction(Action action, int attackType) +void LocalPlayer::setAction(const Action action, const int attackType) { if (action == DEAD) { @@ -1021,7 +1021,7 @@ void LocalPlayer::setTarget(Being *target) target->setShowName(true); } -void LocalPlayer::setDestination(int x, int y) +void LocalPlayer::setDestination(const int x, const int y) { mActivityTime = cur_time; diff --git a/src/localplayer.h b/src/localplayer.h index a12aacc91..b9e012d45 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -84,7 +84,7 @@ class LocalPlayer : public Being, public ActorSpriteListener, void slowLogic(); - virtual void setAction(Action action, int attackType = 0); + virtual void setAction(const Action action, const int attackType = 0); /** * Compute the next pathnode location when walking using keyboard. @@ -160,7 +160,7 @@ class LocalPlayer : public Being, public ActorSpriteListener, /** * Sets a new destination for this being to walk to. */ - virtual void setDestination(int x, int y); + virtual void setDestination(const int x, const int y); /** * Sets a new direction to keep walking in. |