Jump to content

C++ Some Code Corrections


0x0

Recommended Posts

Hello, Corrections of some syntax error made by Ymir;

 

cmd_general.cpp Find:

ACMD(do_shutdown)
{
    if (NULL == ch)
    {
        sys_err("Accept shutdown command from %s.", ch->GetName());
    }
    TPacketGGShutdown p;
    p.bHeader = HEADER_GG_SHUTDOWN;
    P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGShutdown));

    Shutdown(10);
}

Replace:

ACMD(do_shutdown)
{
    if (!ch)
        return;

    sys_err("Accept shutdown command from %s.", ch->GetName());
    TPacketGGShutdown p;
    p.bHeader = HEADER_GG_SHUTDOWN;
    P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGShutdown));

    Shutdown(10);
}

 

Dungeon.cpp Find:

float CDungeon::GetUniqueHpPerc(const std::string& key)
{
    TUniqueMobMap::iterator it = m_map_UniqueMob.find(key);
    if (it == m_map_UniqueMob.end())
    {
        sys_err("Unknown Key : %s", key.c_str());
        return false;
    }
    return (100.f*it->second->GetHP())/it->second->GetMaxHP();
}

Replace:

float CDungeon::GetUniqueHpPerc(const std::string& key)
{
    TUniqueMobMap::iterator it = m_map_UniqueMob.find(key);
    if (it == m_map_UniqueMob.end())
    {
        sys_err("Unknown Key : %s", key.c_str());
        return 0.0f;
    }
    return (100.f*it->second->GetHP())/it->second->GetMaxHP();
}

ClientManager.cpp Find:

if (!dwSkillVnum > 120)

Replace:

if (dwSkillVnum > 120)

 

Special Thanks @Moț;

4 hours ago, Moț said:

 

Edited by Metin2 Dev
Core X - External 2 Internal
  • Metin2 Dev 9
  • Confused 1
  • Good 2
  • Love 1
  • Love 12

Best Regards,

0x0

Link to comment
Share on other sites

vor 7 Stunden schrieb 0x0:

if (!dwSkillVnum > 120)

Replace:


if (dwSkillVnum > 120)

 

					else if ((dwItemVnum == 50300 || dwItemVnum == 70037) && pItemAward->dwSocket0 == 0)
					{
						DWORD dwSkillIdx;
						DWORD dwSkillVnum;

						do
						{
							dwSkillIdx = number(0, m_vec_skillTable.size()-1);
							dwSkillVnum = m_vec_skillTable[dwSkillIdx].dwVnum;
						} while(dwSkillVnum != 0 || dwSkillVnum < 120);

						pItemAward->dwSocket0 = dwSkillVnum;
					}

 

  • Love 1
Link to comment
Share on other sites

  • Premium
14 hours ago, DrTurk said:

					else if ((dwItemVnum == 50300 || dwItemVnum == 70037) && pItemAward->dwSocket0 == 0)
					{
						DWORD dwSkillIdx;
						DWORD dwSkillVnum;

						do
						{
							dwSkillIdx = number(0, m_vec_skillTable.size()-1);
							dwSkillVnum = m_vec_skillTable[dwSkillIdx].dwVnum;
						} while(dwSkillVnum != 0 || dwSkillVnum < 120);

						pItemAward->dwSocket0 = dwSkillVnum;
					}

 

Good idea but there's a little mistake;

 

while(dwSkillVnum != 0 || dwSkillVnum < 120);

Replace:

while(dwSkillVnum > 120);

Here 0 control is unnecessary table 0 vnum does not have skill

  • Love 1

Best Regards,

0x0

Link to comment
Share on other sites

  • Honorable Member
5 hours ago, Moț said:

shopEx.cpp find:


for (itertype(m_vec_shopTabs) it = m_vec_shopTabs.begin(); it != m_vec_shopTabs.end(); it++)

replace:


for (itertype(m_vec_shopTabs) it = m_vec_shopTabs.begin(); it != m_vec_shopTabs.end(); ++it)

 

really?

  • Love 6

 

Link to comment
Share on other sites

  • Bronze

Would be nice if you could also provide informations about the fixes, and why is better like this way.

 

Example the virtual void with void [...] override; is the same virtual void is for overidding, could be also virtual void [...] override;

 

++i increments the value, then returns it.

i++ returns the value, and then increments it.

 

Also when the function is float a simple 0 do the work if the value is zero.

return 0.0f;
return 0;

 

NULL = 0 (can return integers)

nullptr (is keyword that represents a null pointer value, not integers)

 

Thanks.

  • Love 2
Link to comment
Share on other sites

13 minutes ago, HITRON said:

Would be nice if you could also provide informations about the fixes, and why is better like this way.

 

Example the virtual void with void [...] override; is the same virtual void is for overidding, could be also virtual void [...] override;

 

++i increments the value, then returns it.

i++ returns the value, and then increments it. 

 

Thanks.

 

I would like to correct you.

 

++it is more efficient because it++ need to return a copy of the object then increment itself.

 

  • Love 2

All wolves are gray in the dark.

Link to comment
Share on other sites

  • Honorable Member
12 minutes ago, UdvAtt108 said:

 

I would like to correct you.

 

++it is more efficient because it++ need to return a copy of the object then increment itself.

 

I know what they mean.We are talking about wrong codes, not efficient

  • Love 3

 

Link to comment
Share on other sites

The ++it and it++ operations you are talking about do not matter when used as a single line because they are not used with another process.

Example:

it++;

and

++it;

 

If the variable returned in for loop is set it does not matter.

Example:

for (itertype(m_vec_shopTabs) it = m_vec_shopTabs.begin(); it != m_vec_shopTabs.end(); it++)

and

for (itertype(m_vec_shopTabs) it = m_vec_shopTabs.begin(); it != m_vec_shopTabs.end(); ++it)

 

The process here is the same:

for (itertype(m_vec_shopTabs) it = m_vec_shopTabs.begin(); it != m_vec_shopTabs.end())

{

    ++it;

}

and

for (itertype(m_vec_shopTabs) it = m_vec_shopTabs.begin(); it != m_vec_shopTabs.end())

{

    it++;

}

 

You're right if it's used in an array operation.

Example:

row[i++]

and

row[++i]

Best Regards,

0x0

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
  • 5 months later...
  • Honorable Member
On 1/8/2020 at 5:16 PM, UdvAtt108 said:

 

I would like to correct you.

 

++it is more efficient because it++ need to return a copy of the object then increment itself.

 

 

And you really think the compiler won't optimize it anyway?

  • Lmao 1

WRnRW3H.gif

Link to comment
Share on other sites

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.