diff --git a/CMakeLists.txt b/CMakeLists.txt index f61962b..abed874 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,8 +3,8 @@ cmake_minimum_required(VERSION 3.12) # Build mode debug/release? set(CMAKE_BUILD_TYPE Debug) -# Set C++ standard to C++11 -set(CMAKE_CXX_STANDARD 11) +# Set C++ standard to C++17 +set(CMAKE_CXX_STANDARD 17) project("Metin2 Server") diff --git a/common/stl.h b/common/stl.h index 32ee18f..75f4cc1 100644 --- a/common/stl.h +++ b/common/stl.h @@ -96,24 +96,6 @@ namespace std a.clear(); } - template T MIN(T a, T b) - { - return a < b ? a : b; - } - - template T MAX(T a, T b) - { - return a > b ? a : b; - } - - template T MINMAX(T min, T value, T max) - { - T tv; - - tv = (min > value ? min : value); - return (max < tv) ? max : tv; - } - template class void_mem_fun_t : public unary_function<_Ty *, void> { diff --git a/db/src/Cache.cpp b/db/src/Cache.cpp index 236ad02..8b1aa87 100644 --- a/db/src/Cache.cpp +++ b/db/src/Cache.cpp @@ -22,7 +22,7 @@ const int auctionMinFlushSec = 1800; CItemCache::CItemCache() { - m_expireTime = MIN(1800, g_iItemCacheFlushSeconds); + m_expireTime = std::min(1800, g_iItemCacheFlushSeconds); } CItemCache::~CItemCache() @@ -158,7 +158,7 @@ void CItemCache::OnFlush() // CPlayerTableCache::CPlayerTableCache() { - m_expireTime = MIN(1800, g_iPlayerCacheFlushSeconds); + m_expireTime = std::min(1800, g_iPlayerCacheFlushSeconds); } CPlayerTableCache::~CPlayerTableCache() @@ -184,7 +184,7 @@ const int CItemPriceListTableCache::s_nMinFlushSec = 1800; CItemPriceListTableCache::CItemPriceListTableCache() { - m_expireTime = MIN(s_nMinFlushSec, g_iItemPriceListTableCacheFlushSeconds); + m_expireTime = std::min(s_nMinFlushSec, g_iItemPriceListTableCacheFlushSeconds); } void CItemPriceListTableCache::UpdateList(const TItemPriceListTable* pUpdateList) diff --git a/db/src/ClientManager.cpp b/db/src/ClientManager.cpp index b25850e..1ff6267 100644 --- a/db/src/ClientManager.cpp +++ b/db/src/ClientManager.cpp @@ -702,7 +702,7 @@ void CClientManager::RESULT_SAFEBOX_LOAD(CPeer * pkPeer, SQLMsg * msg) if (pSet && !m_vec_itemTable.empty()) { - CGrid grid(5, MAX(1, pi->pSafebox->bSize) * 9); + CGrid grid(5, std::max(1, pi->pSafebox->bSize) * 9); bool bEscape = false; for (DWORD i = 0; i < s_items.size(); ++i) @@ -1624,7 +1624,7 @@ void CClientManager::UpdatePlayerCache() void CClientManager::SetCacheFlushCountLimit(int iLimit) { - m_iCacheFlushCountLimit = MAX(10, iLimit); + m_iCacheFlushCountLimit = std::max(10, iLimit); sys_log(0, "CACHE_FLUSH_LIMIT_PER_SECOND: %d", m_iCacheFlushCountLimit); } @@ -3065,8 +3065,8 @@ int CClientManager::Process() //30ºÐ¸¶´Ù º¯°æ if (((thecore_pulse() % (60 * 30 * 10)) == 0)) { - g_iPlayerCacheFlushSeconds = MAX(60, rand() % 180); - g_iItemCacheFlushSeconds = MAX(60, rand() % 180); + g_iPlayerCacheFlushSeconds = std::max(60, rand() % 180); + g_iItemCacheFlushSeconds = std::max(60, rand() % 180); sys_log(0, "[SAVE_TIME]Change saving time item %d player %d", g_iPlayerCacheFlushSeconds, g_iItemCacheFlushSeconds); } */ @@ -3130,7 +3130,7 @@ int CClientManager::Process() DWORD dwCount = CClientManager::instance().GetUserCount(); g_dwUsageAvg += dwCount; - g_dwUsageMax = MAX(g_dwUsageMax, dwCount); + g_dwUsageMax = std::max(g_dwUsageMax, dwCount); memset(&thecore_profiler[0], 0, sizeof(thecore_profiler)); diff --git a/db/src/ClientManagerBoot.cpp b/db/src/ClientManagerBoot.cpp index eebff25..4a44ef9 100644 --- a/db/src/ClientManagerBoot.cpp +++ b/db/src/ClientManagerBoot.cpp @@ -1178,7 +1178,7 @@ void parse_pair_number_string(const char * c_pszString, std::vector(sizeof(szNum), (p-t)+1)); comma = strchr(szNum, ','); @@ -1236,7 +1236,7 @@ bool CClientManager::InitializeObjectProto() m_vec_kObjectProto.clear(); } - m_vec_kObjectProto.reserve(MAX(0, pRes->uiNumRows)); + m_vec_kObjectProto.reserve(std::max(0, pRes->uiNumRows)); MYSQL_ROW data; @@ -1277,7 +1277,7 @@ bool CClientManager::InitializeObjectProto() str_to_number(t.dwDependOnGroupVnum, data[col++]); t.lNPCX = 0; - t.lNPCY = MAX(t.lRegion[1], t.lRegion[3])+300; + t.lNPCY = std::max(t.lRegion[1], t.lRegion[3])+300; // END_OF_ADD_BUILDING_NPC sys_log(0, "OBJ_PROTO: vnum %lu price %lu mat %lu %lu", diff --git a/db/src/ClientManagerPlayer.cpp b/db/src/ClientManagerPlayer.cpp index 10e1c72..edc1919 100644 --- a/db/src/ClientManagerPlayer.cpp +++ b/db/src/ClientManagerPlayer.cpp @@ -531,11 +531,11 @@ bool CreatePlayerTableFromRes(MYSQL_RES * res, TPlayerTable * pkTab) int max_point = pkTab->level - 9; int skill_point = - MIN(20, pkTab->skills[121].bLevel) + // SKILL_LEADERSHIP Åë¼Ö·Â - MIN(20, pkTab->skills[124].bLevel) + // SKILL_MINING 䱤 - MIN(10, pkTab->skills[131].bLevel) + // SKILL_HORSE_SUMMON ¸»¼Òȯ - MIN(20, pkTab->skills[141].bLevel) + // SKILL_ADD_HP HPº¸°­ - MIN(20, pkTab->skills[142].bLevel); // SKILL_RESIST_PENETRATE °üÅëÀúÇ× + std::min(20, pkTab->skills[121].bLevel) + // SKILL_LEADERSHIP Åë¼Ö·Â + std::min(20, pkTab->skills[124].bLevel) + // SKILL_MINING 䱤 + std::min(10, pkTab->skills[131].bLevel) + // SKILL_HORSE_SUMMON ¸»¼Òȯ + std::min(20, pkTab->skills[141].bLevel) + // SKILL_ADD_HP HPº¸°­ + std::min(20, pkTab->skills[142].bLevel); // SKILL_RESIST_PENETRATE °üÅëÀúÇ× pkTab->sub_skill_point = max_point - skill_point; } diff --git a/db/src/GuildManager.cpp b/db/src/GuildManager.cpp index b3526a3..f0d7402 100644 --- a/db/src/GuildManager.cpp +++ b/db/src/GuildManager.cpp @@ -211,7 +211,7 @@ int CGuildManager::GetRanking(DWORD dwGID) if (it == map_kLadderPointRankingByGID.end()) return GUILD_RANK_MAX_NUM; - return MINMAX(0, it->second, GUILD_RANK_MAX_NUM); + return std::clamp(it->second, 0, GUILD_RANK_MAX_NUM); } void CGuildManager::ResultRanking(MYSQL_RES * pRes) @@ -1013,7 +1013,7 @@ bool CGuildManager::ReserveWar(TPacketGuildWar * p) // ÆÄ¿ö °è»ê TGuild & k1 = TouchGuild(GID1); - lvp = c_aiScoreByLevel[MIN(GUILD_MAX_LEVEL, k1.level)]; + lvp = c_aiScoreByLevel[std::min(GUILD_MAX_LEVEL, k1.level)]; rkp = c_aiScoreByRanking[GetRanking(GID1)]; alv = GetAverageGuildMemberLevel(GID1); mc = GetGuildMemberCount(GID1); @@ -1029,7 +1029,7 @@ bool CGuildManager::ReserveWar(TPacketGuildWar * p) // ÆÄ¿ö °è»ê TGuild & k2 = TouchGuild(GID2); - lvp = c_aiScoreByLevel[MIN(GUILD_MAX_LEVEL, k2.level)]; + lvp = c_aiScoreByLevel[std::min(GUILD_MAX_LEVEL, k2.level)]; rkp = c_aiScoreByRanking[GetRanking(GID2)]; alv = GetAverageGuildMemberLevel(GID2); mc = GetGuildMemberCount(GID2); diff --git a/db/src/Main.cpp b/db/src/Main.cpp index efda49d..df92cc9 100644 --- a/db/src/Main.cpp +++ b/db/src/Main.cpp @@ -169,7 +169,7 @@ int Start() if (CConfig::instance().GetValue("LOG_KEEP_DAYS", &tmpValue)) { - tmpValue = MINMAX(3, tmpValue, 30); + tmpValue = std::clamp(tmpValue, 3, 30); log_set_expiration_days(tmpValue); fprintf(stderr, "Setting log keeping days to %d\n", tmpValue); } diff --git a/db/src/grid.cpp b/db/src/grid.cpp index fe3c392..1487055 100644 --- a/db/src/grid.cpp +++ b/db/src/grid.cpp @@ -12,7 +12,7 @@ CGrid::CGrid(int w, int h) : m_iWidth(w), m_iHeight(h) CGrid::CGrid(CGrid * pkGrid, int w, int h) : m_iWidth(w), m_iHeight(h) { m_pGrid = new char[m_iWidth * m_iHeight]; - int iSize = std::MIN(w * h, pkGrid->m_iWidth * pkGrid->m_iHeight); + int iSize = std::min(w * h, pkGrid->m_iWidth * pkGrid->m_iHeight); memcpy(m_pGrid, pkGrid->m_pGrid, sizeof(char) * iSize); } diff --git a/game/src/DragonSoul.cpp b/game/src/DragonSoul.cpp index a7f0801..ad5edd1 100644 --- a/game/src/DragonSoul.cpp +++ b/game/src/DragonSoul.cpp @@ -184,7 +184,7 @@ bool DSManager::RefreshItemAttributes(LPITEM pDS) } fWeight /= 100.f; - int n = MIN(basic_apply_num, vec_basic_applys.size()); + int n = std::min(basic_apply_num, vec_basic_applys.size()); for (int i = 0; i < n; i++) { const SApply& basic_apply = vec_basic_applys[i]; @@ -253,7 +253,7 @@ bool DSManager::PutAttributes(LPITEM pDS) } fWeight /= 100.f; - int n = MIN(basic_apply_num, vec_basic_applys.size()); + int n = std::min(basic_apply_num, vec_basic_applys.size()); for (int i = 0; i < n; i++) { const SApply& basic_apply = vec_basic_applys[i]; @@ -263,7 +263,7 @@ bool DSManager::PutAttributes(LPITEM pDS) pDS->SetForceAttribute(i, bType, sValue); } - BYTE additional_attr_num = MIN(Random::get(add_min, add_max), 3); + BYTE additional_attr_num = std::min(Random::get(add_min, add_max), 3); std::vector random_set; if (additional_attr_num > 0) @@ -355,7 +355,7 @@ bool DSManager::ExtractDragonHeart(LPCHARACTER ch, LPITEM pItem, LPITEM pExtract } float fCharge = vec_chargings[idx] * (100 + iBonus) / 100.f; - fCharge = std::MINMAX (0.f, fCharge, 100.f); + fCharge = std::clamp(fCharge, 0.f, 100.f); if (fCharge < FLT_EPSILON) { diff --git a/game/src/ani.cpp b/game/src/ani.cpp index e231298..625ed16 100644 --- a/game/src/ani.cpp +++ b/game/src/ani.cpp @@ -206,11 +206,11 @@ bool ANI::load_one_race(int race, const char *dir_name) { // ¸» ¾ÈÅÀÀ» ¶§ m_speed[race][0][weapon][combo] = load_one_weapon(dir_name, weapon, combo, false); - m_speed[race][0][weapon][0] = MIN(m_speed[race][0][weapon][0], m_speed[race][0][weapon][combo]); // ÃÖ¼Ò°ª + m_speed[race][0][weapon][0] = std::min(m_speed[race][0][weapon][0], m_speed[race][0][weapon][combo]); // ÃÖ¼Ò°ª // ¸» ÅÀÀ» ¶§ m_speed[race][1][weapon][combo] = load_one_weapon(dir_name, weapon, combo, true); - m_speed[race][1][weapon][0] = MIN(m_speed[race][1][weapon][0], m_speed[race][1][weapon][combo]); // ÃÖ¼Ò°ª + m_speed[race][1][weapon][0] = std::min(m_speed[race][1][weapon][0], m_speed[race][1][weapon][combo]); // ÃÖ¼Ò°ª dev_log(LOG_DEB0, "combo%02d speed=%d horse=%d", combo, m_speed[race][0][weapon][combo], m_speed[race][1][weapon][combo]); diff --git a/game/src/battle.cpp b/game/src/battle.cpp index eb007a7..1e9e9d6 100644 --- a/game/src/battle.cpp +++ b/game/src/battle.cpp @@ -135,7 +135,7 @@ int battle_melee_attack(LPCHARACTER ch, LPCHARACTER victim) { // PCÀÏ °æ¿ì »ó´ë°¡ melee ¸÷ÀÏ °æ¿ì ¸÷ÀÇ °ø°Ý °Å¸®°¡ ÃÖ´ë °ø°Ý °Å¸® if (false == victim->IsPC() && BATTLE_TYPE_MELEE == victim->GetMobBattleType()) - max = MAX(300, (int) (victim->GetMobAttackRange() * 1.15f)); + max = std::max(300, (int) (victim->GetMobAttackRange() * 1.15f)); } if (distance > max) @@ -211,8 +211,8 @@ float CalcAttackRating(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnor if (LC_IsYMIR()) // õ¸¶ { - iARSrc = MIN(90, pkAttacker->GetPolymorphPoint(POINT_DX)); - iERSrc = MIN(90, pkVictim->GetPolymorphPoint(POINT_DX)); + iARSrc = std::min(90, pkAttacker->GetPolymorphPoint(POINT_DX)); + iERSrc = std::min(90, pkVictim->GetPolymorphPoint(POINT_DX)); } else { @@ -222,8 +222,8 @@ float CalcAttackRating(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnor int victim_dx = pkVictim->GetPolymorphPoint(POINT_DX); int victim_lv = pkAttacker->GetLevel(); - iARSrc = MIN(90, (attacker_dx * 4 + attacker_lv * 2) / 6); - iERSrc = MIN(90, (victim_dx * 4 + victim_lv * 2) / 6); + iARSrc = std::min(90, (attacker_dx * 4 + attacker_lv * 2) / 6); + iERSrc = std::min(90, (victim_dx * 4 + victim_lv * 2) / 6); } float fAR = ((float) iARSrc + 210.0f) / 300.0f; // fAR = 0.7 ~ 1.0 @@ -479,7 +479,7 @@ int CalcMeleeDamage(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, bool bIgnoreDe if (pkAttacker->IsNPC()) iAtk = (int) (iAtk * pkAttacker->GetMobDamageMultiply()); - iDam = MAX(0, iAtk - iDef); + iDam = std::max(0, iAtk - iDef); if (test_server) { @@ -592,7 +592,7 @@ int CalcArrowDamage(LPCHARACTER pkAttacker, LPCHARACTER pkVictim, LPITEM pkBow, if (pkAttacker->IsNPC()) iAtk = (int) (iAtk * pkAttacker->GetMobDamageMultiply()); - iDam = MAX(0, iAtk - iDef); + iDam = std::max(0, iAtk - iDef); int iPureDam = iDam; diff --git a/game/src/buffer_manager.cpp b/game/src/buffer_manager.cpp index 801720f..43d8a00 100644 --- a/game/src/buffer_manager.cpp +++ b/game/src/buffer_manager.cpp @@ -6,7 +6,7 @@ TEMP_BUFFER::TEMP_BUFFER(int Size, bool bForceDelete) forceDelete = bForceDelete; if (forceDelete) - Size = MAX(Size, 1024 * 128); + Size = std::max(Size, 1024 * 128); buf = buffer_new(Size); } diff --git a/game/src/castle.cpp b/game/src/castle.cpp index ef59c36..2d78211 100644 --- a/game/src/castle.cpp +++ b/game/src/castle.cpp @@ -786,7 +786,7 @@ bool castle_spawn_tower(int empire, int tower_count) GET_TOWER(empire, i) = NULL; } - int spawn_count = MINMAX(MIN_CASTLE_TOWER, tower_count, MAX_CASTLE_TOWER); // 5 ~ 10¸¶¸® + int spawn_count = std::clamp(tower_count, MIN_CASTLE_TOWER, MAX_CASTLE_TOWER); // 5 ~ 10¸¶¸® for (int j = 0; j < spawn_count; ++j) { diff --git a/game/src/char.cpp b/game/src/char.cpp index 14eaeac..428ef34 100644 --- a/game/src/char.cpp +++ b/game/src/char.cpp @@ -2411,7 +2411,7 @@ EVENTFUNC(recovery_event) // ¸ó½ºÅÍ È¸º¹ // if (ch->IsAffectFlag(AFF_POISON)) - return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle)); + return PASSES_PER_SEC(std::max(1, ch->GetMobTable().bRegenCycle)); if (2493 == ch->GetMobTable().dwVnum) { @@ -2432,12 +2432,12 @@ EVENTFUNC(recovery_event) } } - ch->PointChange(POINT_HP, MAX(1, (ch->GetMaxHP() * regenPct) / 100)); + ch->PointChange(POINT_HP, std::max(1, (ch->GetMaxHP() * regenPct) / 100)); } else if (!ch->IsDoor()) { - ch->MonsterLog("HP_REGEN +%d", MAX(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100)); - ch->PointChange(POINT_HP, MAX(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100)); + ch->MonsterLog("HP_REGEN +%d", std::max(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100)); + ch->PointChange(POINT_HP, std::max(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100)); } if (ch->GetHP() >= ch->GetMaxHP()) @@ -2456,12 +2456,12 @@ EVENTFUNC(recovery_event) size_t val = BlueDragon_GetIndexFactor("DragonStone", i, "val"); size_t cnt = SECTREE_MANAGER::instance().GetMonsterCountInMap( ch->GetMapIndex(), dwDragonStoneID ); - return PASSES_PER_SEC(MAX(1, (ch->GetMobTable().bRegenCycle - (val*cnt)))); + return PASSES_PER_SEC(std::max(1, (ch->GetMobTable().bRegenCycle - (val*cnt)))); } } } - return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle)); + return PASSES_PER_SEC(std::max(1, ch->GetMobTable().bRegenCycle)); } else { @@ -2492,7 +2492,7 @@ EVENTFUNC(recovery_event) int iAmount = 0; { - iPercent = aiRecoveryPercents[MIN(9, iSec)]; + iPercent = aiRecoveryPercents[std::min(9, iSec)]; iAmount = 15 + (ch->GetMaxHP() * iPercent) / 100; } @@ -2520,7 +2520,7 @@ void CHARACTER::StartRecoveryEvent() info->ch = this; - int iSec = IsPC() ? 3 : (MAX(1, GetMobTable().bRegenCycle)); + int iSec = IsPC() ? 3 : (std::max(1, GetMobTable().bRegenCycle)); m_pkRecoveryEvent = event_create(recovery_event, info, PASSES_PER_SEC(iSec)); } @@ -3210,7 +3210,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast int prev_hp = GetHP(); - amount = MIN(GetMaxHP() - GetHP(), amount); + amount = std::min(GetMaxHP() - GetHP(), amount); SetHP(GetHP() + amount); val = GetHP(); @@ -3226,7 +3226,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast if (IsDead() || IsStun()) return; - amount = MIN(GetMaxSP() - GetSP(), amount); + amount = std::min(GetMaxSP() - GetSP(), amount); SetSP(GetSP() + amount); val = GetSP(); } @@ -3238,7 +3238,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast return; int prev_val = GetStamina(); - amount = MIN(GetMaxStamina() - GetStamina(), amount); + amount = std::min(GetMaxStamina() - GetStamina(), amount); SetStamina(GetStamina() + amount); val = GetStamina(); @@ -3265,7 +3265,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast //SetMaxHP(GetMaxHP() + amount); // ÃÖ´ë »ý¸í·Â = (±âº» ÃÖ´ë »ý¸í·Â + Ãß°¡) * ÃÖ´ë»ý¸í·Â% int hp = GetRealPoint(POINT_MAX_HP); - int add_hp = MIN(3500, hp * GetPoint(POINT_MAX_HP_PCT) / 100); + int add_hp = std::min(3500, hp * GetPoint(POINT_MAX_HP_PCT) / 100); add_hp += GetPoint(POINT_MAX_HP); add_hp += GetPoint(POINT_PARTY_TANKER_BONUS); @@ -3282,7 +3282,7 @@ void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast //SetMaxSP(GetMaxSP() + amount); // ÃÖ´ë Á¤½Å·Â = (±âº» ÃÖ´ë Á¤½Å·Â + Ãß°¡) * ÃÖ´ëÁ¤½Å·Â% int sp = GetRealPoint(POINT_MAX_SP); - int add_sp = MIN(800, sp * GetPoint(POINT_MAX_SP_PCT) / 100); + int add_sp = std::min(800, sp * GetPoint(POINT_MAX_SP_PCT) / 100); add_sp += GetPoint(POINT_MAX_SP); add_sp += GetPoint(POINT_PARTY_SKILL_MASTER_BONUS); @@ -5105,7 +5105,7 @@ void CHARACTER::SetTarget(LPCHARACTER pkChrTarget) int iHorseMaxHealth = owner->GetHorseMaxHealth(); if (iHorseMaxHealth) - p.bHPPercent = MINMAX(0, iHorseHealth * 100 / iHorseMaxHealth, 100); + p.bHPPercent = std::clamp(iHorseHealth * 100 / iHorseMaxHealth, 0, 100); else p.bHPPercent = 100; } @@ -5113,7 +5113,7 @@ void CHARACTER::SetTarget(LPCHARACTER pkChrTarget) p.bHPPercent = 100; } else - p.bHPPercent = MINMAX(0, (m_pkChrTarget->GetHP() * 100) / m_pkChrTarget->GetMaxHP(), 100); + p.bHPPercent = std::clamp((m_pkChrTarget->GetHP() * 100) / m_pkChrTarget->GetMaxHP(), 0, 100); } } else @@ -5138,7 +5138,7 @@ void CHARACTER::BroadcastTargetPacket() if (IsPC()) p.bHPPercent = 0; else - p.bHPPercent = MINMAX(0, (GetHP() * 100) / GetMaxHP(), 100); + p.bHPPercent = std::clamp((GetHP() * 100) / GetMaxHP(), 0, 100); CHARACTER_SET::iterator it = m_set_pkChrTargetedBy.begin(); @@ -5727,7 +5727,7 @@ bool CHARACTER::BuildUpdatePartyPacket(TPacketGCPartyUpdate & out) out.header = HEADER_GC_PARTY_UPDATE; out.pid = GetPlayerID(); - out.percent_hp = MINMAX(0, GetHP() * 100 / GetMaxHP(), 100); + out.percent_hp = std::clamp(GetHP() * 100 / GetMaxHP(), 0, 100); out.role = GetParty()->GetRole(GetPlayerID()); sys_log(1, "PARTY %s role is %d", GetName(), out.role); @@ -5881,8 +5881,8 @@ void CHARACTER::ResetPoint(int iLv) SetRandomHP((iLv - 1) * Random::get(JobInitialPoints[GetJob()].hp_per_lv_begin, JobInitialPoints[GetJob()].hp_per_lv_end)); SetRandomSP((iLv - 1) * Random::get(JobInitialPoints[GetJob()].sp_per_lv_begin, JobInitialPoints[GetJob()].sp_per_lv_end)); - //PointChange(POINT_STAT, ((MINMAX(1, iLv, 99) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT)); - PointChange(POINT_STAT, ((MINMAX(1, iLv, 90) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT)); + //PointChange(POINT_STAT, ((std::clamp(iLv, 1, 99) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT)); + PointChange(POINT_STAT, ((std::clamp(iLv, 1, 90) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT)); ComputePoints(); @@ -6126,7 +6126,7 @@ int CHARACTER::GetPolymorphPower() const if (value) return value; } - return aiPolymorphPowerByLevel[MINMAX(0, GetSkillLevel(SKILL_POLYMORPH), 40)]; + return aiPolymorphPowerByLevel[std::clamp(GetSkillLevel(SKILL_POLYMORPH), 0, 40)]; } void CHARACTER::SetPolymorph(DWORD dwRaceNum, bool bMaintainStat) @@ -7204,5 +7204,5 @@ DWORD CHARACTER::GetNextExp() const int CHARACTER::GetSkillPowerByLevel(int level, bool bMob) const { - return CTableBySkill::instance().GetSkillPowerByLevelFromType(GetJob(), GetSkillGroup(), MINMAX(0, level, SKILL_MAX_LEVEL), bMob); + return CTableBySkill::instance().GetSkillPowerByLevelFromType(GetJob(), GetSkillGroup(), std::clamp(level, 0, SKILL_MAX_LEVEL), bMob); } \ No newline at end of file diff --git a/game/src/char_affect.cpp b/game/src/char_affect.cpp index db8d099..0d0a6e0 100644 --- a/game/src/char_affect.cpp +++ b/game/src/char_affect.cpp @@ -103,11 +103,11 @@ bool CHARACTER::UpdateAffect() if (LC_IsYMIR()) { - iVal = MIN(GetPoint(POINT_HP_RECOVERY), GetMaxHP() * 9 / 100); + iVal = std::min(GetPoint(POINT_HP_RECOVERY), GetMaxHP() * 9 / 100); } else { - iVal = MIN(GetPoint(POINT_HP_RECOVERY), GetMaxHP() * 7 / 100); + iVal = std::min(GetPoint(POINT_HP_RECOVERY), GetMaxHP() * 7 / 100); } PointChange(POINT_HP, iVal); @@ -124,9 +124,9 @@ bool CHARACTER::UpdateAffect() int iVal; if (!g_iUseLocale) - iVal = MIN(GetPoint(POINT_SP_RECOVERY), GetMaxSP() * 7 / 100); + iVal = std::min(GetPoint(POINT_SP_RECOVERY), GetMaxSP() * 7 / 100); else - iVal = MIN(GetPoint(POINT_SP_RECOVERY), GetMaxSP() * 7 / 100); + iVal = std::min(GetPoint(POINT_SP_RECOVERY), GetMaxSP() * 7 / 100); PointChange(POINT_SP, iVal); PointChange(POINT_SP_RECOVERY, -iVal); diff --git a/game/src/char_battle.cpp b/game/src/char_battle.cpp index eae04bc..ac6a70d 100644 --- a/game/src/char_battle.cpp +++ b/game/src/char_battle.cpp @@ -328,22 +328,22 @@ void CHARACTER::DeathPenalty(BYTE bTown) } // END_OF_NO_DEATH_PENALTY_BUG_FIX - int iLoss = ((GetNextExp() * aiExpLossPercents[MINMAX(1, GetLevel(), PLAYER_EXP_TABLE_MAX)]) / 100); + int iLoss = ((GetNextExp() * aiExpLossPercents[std::clamp(GetLevel(), 1, PLAYER_EXP_TABLE_MAX)]) / 100); if (true == LC_IsYMIR()) { if (PLAYER_EXP_TABLE_MAX < GetLevel()) { - iLoss = MIN(500000, iLoss); + iLoss = std::min(500000, iLoss); } else { - iLoss = MIN(200000, iLoss); + iLoss = std::min(200000, iLoss); } } else if (true == LC_IsEurope()) { - iLoss = MIN(800000, iLoss); + iLoss = std::min(800000, iLoss); } if (bTown) @@ -361,7 +361,7 @@ void CHARACTER::DeathPenalty(BYTE bTown) if (IsEquipUniqueItem(UNIQUE_ITEM_TEARDROP_OF_GODNESS)) iLoss /= 2; - sys_log(0, "DEATH_PENALTY(%s) EXP_LOSS: %d percent %d%%", GetName(), iLoss, aiExpLossPercents[MIN(gPlayerMaxLevel, GetLevel())]); + sys_log(0, "DEATH_PENALTY(%s) EXP_LOSS: %d percent %d%%", GetName(), iLoss, aiExpLossPercents[std::min(gPlayerMaxLevel, GetLevel())]); PointChange(POINT_EXP, -iLoss, true); } @@ -1054,7 +1054,7 @@ void CHARACTER::ItemDropPenalty(LPCHARACTER pkKiller) { random_shuffle(vec_bSlots.begin(), vec_bSlots.end()); - int iQty = MIN(vec_bSlots.size(), r.iInventoryQty); + int iQty = std::min(vec_bSlots.size(), r.iInventoryQty); if (iQty) iQty = Random::get(1, iQty); @@ -1090,7 +1090,7 @@ void CHARACTER::ItemDropPenalty(LPCHARACTER pkKiller) if (isDropAllEquipments) iQty = vec_bSlots.size(); else - iQty = MIN(vec_bSlots.size(), Random::get(1, r.iEquipmentQty)); + iQty = std::min(vec_bSlots.size(), Random::get(1, r.iEquipmentQty)); if (iQty) iQty = Random::get(1, iQty); @@ -1306,7 +1306,7 @@ void CHARACTER::Dead(LPCHARACTER pkKiller, bool bImmediateDead) if (GetEmpire() != pkKiller->GetEmpire()) { - int iEP = MIN(GetPoint(POINT_EMPIRE_POINT), pkKiller->GetPoint(POINT_EMPIRE_POINT)); + int iEP = std::min(GetPoint(POINT_EMPIRE_POINT), pkKiller->GetPoint(POINT_EMPIRE_POINT)); PointChange(POINT_EMPIRE_POINT, -(iEP / 10)); pkKiller->PointChange(POINT_EMPIRE_POINT, iEP / 5); @@ -1916,7 +1916,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu if (Random::get(1, 10) <= pct) { - int iHP = MIN(dam, MAX(0, iCurHP)) * pAttacker->GetPoint(POINT_STEAL_HP) / 100; + int iHP = std::min(dam, std::max(0, iCurHP)) * pAttacker->GetPoint(POINT_STEAL_HP) / 100; if (iHP > 0 && GetHP() >= iHP) { @@ -1941,7 +1941,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu else iCur = iCurHP; - int iSP = MIN(dam, MAX(0, iCur)) * pAttacker->GetPoint(POINT_STEAL_SP) / 100; + int iSP = std::min(dam, std::max(0, iCur)) * pAttacker->GetPoint(POINT_STEAL_SP) / 100; if (iSP > 0 && iCur >= iSP) { @@ -1968,7 +1968,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu // Ä¥ ¶§¸¶´Ù HPȸº¹ if (pAttacker->GetPoint(POINT_HIT_HP_RECOVERY) && Random::get(0, 4) > 0) // 80% È®·ü { - int i = MIN(dam, iCurHP) * pAttacker->GetPoint(POINT_HIT_HP_RECOVERY) / 100; + int i = std::min(dam, iCurHP) * pAttacker->GetPoint(POINT_HIT_HP_RECOVERY) / 100; if (i) { @@ -1980,7 +1980,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu // Ä¥ ¶§¸¶´Ù SPȸº¹ if (pAttacker->GetPoint(POINT_HIT_SP_RECOVERY) && Random::get(0, 4) > 0) // 80% È®·ü { - int i = MIN(dam, iCurHP) * pAttacker->GetPoint(POINT_HIT_SP_RECOVERY) / 100; + int i = std::min(dam, iCurHP) * pAttacker->GetPoint(POINT_HIT_SP_RECOVERY) / 100; if (i) { @@ -2009,7 +2009,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu if (pAttacker->GetPoint(POINT_NORMAL_HIT_DAMAGE_BONUS)) dam = dam * (100 + pAttacker->GetPoint(POINT_NORMAL_HIT_DAMAGE_BONUS)) / 100; - dam = dam * (100 - MIN(99, GetPoint(POINT_NORMAL_HIT_DEFEND_BONUS))) / 100; + dam = dam * (100 - std::min(99, GetPoint(POINT_NORMAL_HIT_DEFEND_BONUS))) / 100; break; case DAMAGE_TYPE_MELEE: @@ -2022,7 +2022,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu if (pAttacker->GetPoint(POINT_SKILL_DAMAGE_BONUS)) dam = dam * (100 + pAttacker->GetPoint(POINT_SKILL_DAMAGE_BONUS)) / 100; - dam = dam * (100 - MIN(99, GetPoint(POINT_SKILL_DEFEND_BONUS))) / 100; + dam = dam * (100 - std::min(99, GetPoint(POINT_SKILL_DEFEND_BONUS))) / 100; break; default: @@ -2049,7 +2049,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu { // Á¤½Å·ÂÀÌ ¸ðÀÚ¶ó¼­ ÇÇ°¡ ´õ ±ï¿©¾ßÇÒ?? PointChange(POINT_SP, -GetSP()); - dam -= iSP * 100 / MAX(GetPoint(POINT_MANASHIELD), 1); + dam -= iSP * 100 / std::max(GetPoint(POINT_MANASHIELD), 1); } } @@ -2058,7 +2058,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu // if (GetPoint(POINT_MALL_DEFBONUS) > 0) { - int dec_dam = MIN(200, dam * GetPoint(POINT_MALL_DEFBONUS) / 100); + int dec_dam = std::min(200, dam * GetPoint(POINT_MALL_DEFBONUS) / 100); dam -= dec_dam; } @@ -2069,7 +2069,7 @@ bool CHARACTER::Damage(LPCHARACTER pAttacker, int dam, EDamageType type) // retu // if (pAttacker->GetPoint(POINT_MALL_ATTBONUS) > 0) { - int add_dam = MIN(300, dam * pAttacker->GetLimitPoint(POINT_MALL_ATTBONUS) / 100); + int add_dam = std::min(300, dam * pAttacker->GetLimitPoint(POINT_MALL_ATTBONUS) / 100); dam += add_dam; } @@ -2484,7 +2484,7 @@ static void GiveExp(LPCHARACTER from, LPCHARACTER to, int iExp) iExp = iExp * CHARACTER_MANAGER::instance().GetMobExpRate(to) / 100; // °æÇèÄ¡ Çѹø ȹµæ·® Á¦ÇÑ - iExp = MIN(to->GetNextExp() / 10, iExp); + iExp = std::min(to->GetNextExp() / 10, iExp); if (test_server) { @@ -2821,7 +2821,7 @@ int CHARACTER::GetArrowAndBow(LPITEM * ppkBow, LPITEM * ppkArrow, int iArrowCoun return 0; } - iArrowCount = MIN(iArrowCount, pkArrow->GetCount()); + iArrowCount = std::min(iArrowCount, pkArrow->GetCount()); *ppkBow = pkBow; *ppkArrow = pkArrow; @@ -2833,7 +2833,7 @@ void CHARACTER::UseArrow(LPITEM pkArrow, DWORD dwArrowCount) { int iCount = pkArrow->GetCount(); DWORD dwVnum = pkArrow->GetVnum(); - iCount = iCount - MIN(iCount, dwArrowCount); + iCount = iCount - std::min(iCount, dwArrowCount); pkArrow->SetCount(iCount); if (iCount == 0) @@ -3303,7 +3303,7 @@ void CHARACTER::UpdateAlignment(int iAmount) int i = m_iAlignment / 10; - m_iRealAlignment = MINMAX(-200000, m_iRealAlignment + iAmount, 200000); + m_iRealAlignment = std::clamp(m_iRealAlignment + iAmount, -200000, 200000); if (bShow) { diff --git a/game/src/char_item.cpp b/game/src/char_item.cpp index 12129da..9ca9b3b 100644 --- a/game/src/char_item.cpp +++ b/game/src/char_item.cpp @@ -1129,16 +1129,16 @@ bool CHARACTER::DoRefineWithScroll(LPITEM item) if (pkItemScroll->GetValue(0) == YONGSIN_SCROLL) { if (LC_IsYMIR() == true || LC_IsKorea() == true) - success_prob = hyuniron_prob_euckr[MINMAX(0, item->GetRefineLevel(), 8)]; + success_prob = hyuniron_prob_euckr[std::clamp(item->GetRefineLevel(), 0, 8)]; else - success_prob = hyuniron_prob[MINMAX(0, item->GetRefineLevel(), 8)]; + success_prob = hyuniron_prob[std::clamp(item->GetRefineLevel(), 0, 8)]; } else if (pkItemScroll->GetValue(0) == YAGONG_SCROLL) { if (LC_IsYMIR() == true || LC_IsKorea() == true) - success_prob = yagong_prob_euckr[MINMAX(0, item->GetRefineLevel(), 8)]; + success_prob = yagong_prob_euckr[std::clamp(item->GetRefineLevel(), 0, 8)]; else - success_prob = yagong_prob[MINMAX(0, item->GetRefineLevel(), 8)]; + success_prob = yagong_prob[std::clamp(item->GetRefineLevel(), 0, 8)]; } else { @@ -3144,7 +3144,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) } DWORD dwSkillVnum = item->GetValue(0); - int iPct = MINMAX(0, item->GetValue(1), 100); + int iPct = std::clamp(item->GetValue(1), 0, 100); if (GetSkillLevel(dwSkillVnum)>=20 || dwSkillVnum-SKILL_LANGUAGE1+1 == GetEmpire()) { ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ÀÌ¹Ì ¿Ïº®ÇÏ°Ô ¾Ë¾ÆµéÀ» ¼ö ÀÖ´Â ¾ð¾îÀÌ´Ù.")); @@ -3172,7 +3172,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) } DWORD dwSkillVnum = item->GetValue(0); - int iPct = MINMAX(0, item->GetValue(1), 100); + int iPct = std::clamp(item->GetValue(1), 0, 100); if (GetSkillLevel(dwSkillVnum) >= 10) { @@ -3204,7 +3204,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) int iSkillLevelLowLimit = item->GetValue(0); int iSkillLevelHighLimit = item->GetValue(1); - int iPct = MINMAX(0, item->GetValue(2), 100); + int iPct = std::clamp(item->GetValue(2), 0, 100); int iLevelLimit = item->GetValue(3); DWORD dwSkillVnum = 0; @@ -3276,7 +3276,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) } DWORD dwSkillVnum = SKILL_CREATE; - int iPct = MINMAX(0, item->GetValue(1), 100); + int iPct = std::clamp(item->GetValue(1), 0, 100); if (GetSkillLevel(dwSkillVnum)>=40) { @@ -3318,7 +3318,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) } DWORD dwSkillVnum = SKILL_MINING; - int iPct = MINMAX(0, item->GetValue(1), 100); + int iPct = std::clamp(item->GetValue(1), 0, 100); if (GetSkillLevel(dwSkillVnum)>=40) { @@ -3348,7 +3348,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) } DWORD dwSkillVnum = SKILL_HORSE; - int iPct = MINMAX(0, item->GetValue(1), 100); + int iPct = std::clamp(item->GetValue(1), 0, 100); if (GetLevel() < 50) { @@ -3406,7 +3406,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) if (GetAlignment() >= 0) return false; - int delta = MIN(-GetAlignment(), item->GetValue(0)); + int delta = std::min(-GetAlignment(), item->GetValue(0)); sys_log(0, "%s ALIGNMENT ITEM %d", GetName(), delta); @@ -4232,7 +4232,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) return false; } - PointChange(POINT_SP_RECOVERY, item->GetValue(1) * MIN(200, (100 + GetPoint(POINT_POTION_BONUS))) / 100); + PointChange(POINT_SP_RECOVERY, item->GetValue(1) * std::min(200, (100 + GetPoint(POINT_POTION_BONUS))) / 100); StartAffectEvent(); EffectPacket(SE_SPUP_BLUE); } @@ -4244,7 +4244,7 @@ bool CHARACTER::UseItemEx(LPITEM item, TItemPos DestCell) return false; } - PointChange(POINT_HP_RECOVERY, item->GetValue(0) * MIN(200, (100 + GetPoint(POINT_POTION_BONUS))) / 100); + PointChange(POINT_HP_RECOVERY, item->GetValue(0) * std::min(200, (100 + GetPoint(POINT_POTION_BONUS))) / 100); StartAffectEvent(); EffectPacket(SE_HPUP_RED); } @@ -5597,7 +5597,7 @@ bool CHARACTER::MoveItem(TItemPos Cell, TItemPos DestCell, BYTE count) sys_log(0, "%s: ITEM_STACK %s (window: %d, cell : %d) -> (window:%d, cell %d) count %d", GetName(), item->GetName(), Cell.window_type, Cell.cell, DestCell.window_type, DestCell.cell, count); - count = MIN(200 - item2->GetCount(), count); + count = std::min(200 - item2->GetCount(), count); item->SetCount(item->GetCount() - count); item2->SetCount(item2->GetCount() + count); @@ -5815,7 +5815,7 @@ bool CHARACTER::PickupItem(DWORD dwVID) if (j != ITEM_SOCKET_MAX_NUM) continue; - BYTE bCount2 = MIN(200 - item2->GetCount(), bCount); + BYTE bCount2 = std::min(200 - item2->GetCount(), bCount); bCount -= bCount2; item2->SetCount(item2->GetCount() + bCount2); @@ -6541,7 +6541,7 @@ LPITEM CHARACTER::AutoGiveItem(DWORD dwItemVnum, BYTE bCount, int iRarePct, bool bCount = p->alValues[1]; } - BYTE bCount2 = MIN(200 - item->GetCount(), bCount); + BYTE bCount2 = std::min(200 - item->GetCount(), bCount); bCount -= bCount2; item->SetCount(item->GetCount() + bCount2); @@ -7037,7 +7037,7 @@ bool CHARACTER::GiveItemFromSpecialItemGroup(DWORD dwGroupNum, std::vectorm_table.bLevel >= GetLevel() + iPolymorphLevelLimit) { ChatPacket(CHAT_TYPE_INFO, LC_TEXT("³ªº¸´Ù ³Ê¹« ³ôÀº ·¹º§ÀÇ ¸ó½ºÅͷδ º¯½Å ÇÒ ¼ö ¾ø½À´Ï´Ù.")); diff --git a/game/src/char_resist.cpp b/game/src/char_resist.cpp index 4723a11..0b052b9 100644 --- a/game/src/char_resist.cpp +++ b/game/src/char_resist.cpp @@ -26,7 +26,7 @@ int GetPoisonDamageRate(LPCHARACTER ch) else iRate = poison_damage_rate[ch->GetMobRank()]; - iRate = MAX(0, iRate - ch->GetPoint(POINT_POISON_REDUCE)); + iRate = std::max(0, iRate - ch->GetPoint(POINT_POISON_REDUCE)); return iRate; } diff --git a/game/src/char_skill.cpp b/game/src/char_skill.cpp index 2658239..4769b3d 100644 --- a/game/src/char_skill.cpp +++ b/game/src/char_skill.cpp @@ -125,7 +125,7 @@ bool TSkillUseInfo::UseSkill(bool isGrandMaster, DWORD vid, DWORD dwCooltime, in int CHARACTER::GetChainLightningMaxCount() const { - return aiChainLightningCountBySkillLevel[MIN(SKILL_MAX_LEVEL, GetSkillLevel(SKILL_CHAIN))]; + return aiChainLightningCountBySkillLevel[std::min(SKILL_MAX_LEVEL, GetSkillLevel(SKILL_CHAIN))]; } void CHARACTER::SetAffectedEunhyung() @@ -178,7 +178,7 @@ void CHARACTER::SetSkillLevel(DWORD dwVnum, BYTE bLev) return; } - m_pSkillLevels[dwVnum].bLevel = MIN(40, bLev); + m_pSkillLevels[dwVnum].bLevel = std::min(40, bLev); if (bLev >= 40) m_pSkillLevels[dwVnum].bMasterType = SKILL_PERFECT_MASTER; @@ -320,7 +320,7 @@ bool CHARACTER::LearnGrandMasterSkill(DWORD dwSkillVnum) // ¿©±â¼­ È®·üÀ» °è»êÇÕ´Ï´Ù. BYTE bLastLevel = GetSkillLevel(dwSkillVnum); - int idx = MIN(9, GetSkillLevel(dwSkillVnum) - 30); + int idx = std::min(9, GetSkillLevel(dwSkillVnum) - 30); sys_log(0, "LearnGrandMasterSkill %s table idx %d value %d", GetName(), idx, aiGrandMasterSkillBookCountForLevelUp[idx]); @@ -500,7 +500,7 @@ bool CHARACTER::LearnSkillByBook(DWORD dwSkillVnum, BYTE bProb) } else { - int idx = MIN(9, GetSkillLevel(dwSkillVnum) - 20); + int idx = std::min(9, GetSkillLevel(dwSkillVnum) - 20); sys_log(0, "LearnSkillByBook %s table idx %d value %d", GetName(), idx, aiSkillBookCountForLevelUp[idx]); @@ -818,7 +818,7 @@ void CHARACTER::SkillLevelUp(DWORD dwVnum, BYTE bMethod) } else { - if (Random::get(1, 21 - MIN(20, GetSkillLevel(pkSk->dwVnum))) == 1) + if (Random::get(1, 21 - std::min(20, GetSkillLevel(pkSk->dwVnum))) == 1) SetSkillLevel(pkSk->dwVnum, 20); } } @@ -827,7 +827,7 @@ void CHARACTER::SkillLevelUp(DWORD dwVnum, BYTE bMethod) case SKILL_MASTER: if (GetSkillLevel(pkSk->dwVnum) >= 30) { - if (Random::get(1, 31 - MIN(30, GetSkillLevel(pkSk->dwVnum))) == 1) + if (Random::get(1, 31 - std::min(30, GetSkillLevel(pkSk->dwVnum))) == 1) SetSkillLevel(pkSk->dwVnum, 30); } break; @@ -2648,7 +2648,7 @@ int CHARACTER::GetUsedSkillMasterType(DWORD dwVnum) if (rInfo.isGrandMaster) return GetSkillMasterType(dwVnum); - return MIN(GetSkillMasterType(dwVnum), SKILL_MASTER); + return std::min(GetSkillMasterType(dwVnum), SKILL_MASTER); } int CHARACTER::GetSkillMasterType(DWORD dwVnum) const @@ -2708,7 +2708,7 @@ int CHARACTER::GetSkillLevel(DWORD dwVnum) const return 0; } - return MIN(SKILL_MAX_LEVEL, m_pSkillLevels ? m_pSkillLevels[dwVnum].bLevel : 0); + return std::min(SKILL_MAX_LEVEL, m_pSkillLevels ? m_pSkillLevels[dwVnum].bLevel : 0); } EVENTFUNC(skill_muyoung_event) diff --git a/game/src/char_state.cpp b/game/src/char_state.cpp index c81f672..426cc07 100644 --- a/game/src/char_state.cpp +++ b/game/src/char_state.cpp @@ -390,7 +390,7 @@ void CHARACTER::__StateIdle_Stone() m_dwStateDuration = PASSES_PER_SEC(1); int iPercent = (GetHP() * 100) / GetMaxHP(); - DWORD dwVnum = Random::get(MIN(GetMobTable().sAttackSpeed, GetMobTable().sMovingSpeed ), MAX(GetMobTable().sAttackSpeed, GetMobTable().sMovingSpeed)); + DWORD dwVnum = Random::get(std::min(GetMobTable().sAttackSpeed, GetMobTable().sMovingSpeed ), std::max(GetMobTable().sAttackSpeed, GetMobTable().sMovingSpeed)); if (iPercent <= 10 && GetMaxSP() < 10) { @@ -1069,7 +1069,7 @@ void CHARACTER::StateBattle() if ((dwCurTime - m_dwLastAttackTime) < dwDuration) // 2ÃÊ ¸¶´Ù °ø°ÝÇØ¾ß ÇÑ´Ù. { - m_dwStateDuration = MAX(1, (passes_per_sec * (dwDuration - (dwCurTime - m_dwLastAttackTime)) / 1000)); + m_dwStateDuration = std::max(1, (passes_per_sec * (dwDuration - (dwCurTime - m_dwLastAttackTime)) / 1000)); return; } diff --git a/game/src/cmd_general.cpp b/game/src/cmd_general.cpp index e6f98e0..eec9296 100644 --- a/game/src/cmd_general.cpp +++ b/game/src/cmd_general.cpp @@ -2133,8 +2133,8 @@ ACMD(do_inventory) } else { - str_to_number(index, arg1); index = MIN(index, INVENTORY_MAX_NUM); - str_to_number(count, arg2); count = MIN(count, INVENTORY_MAX_NUM); + str_to_number(index, arg1); index = std::min(index, INVENTORY_MAX_NUM); + str_to_number(count, arg2); count = std::min(count, INVENTORY_MAX_NUM); } for (int i = 0; i < count; ++i) @@ -2374,8 +2374,8 @@ ACMD(do_dice) end = atoi(arg1); } - end = MAX(start, end); - start = MIN(start, end); + end = std::max(start, end); + start = std::min(start, end); int n = Random::get(start, end); diff --git a/game/src/cmd_gm.cpp b/game/src/cmd_gm.cpp index 3c14e13..7431a6b 100644 --- a/game/src/cmd_gm.cpp +++ b/game/src/cmd_gm.cpp @@ -258,7 +258,7 @@ bool FindInString(const char * c_pszFind, const char * c_pszIn) do { - strncpy(sz, c, MIN(sizeof(sz), (p - c) + 1)); + strncpy(sz, c, std::min(sizeof(sz), (p - c) + 1)); if (!strncasecmp(c_pszFind, sz, strlen(c_pszFind))) return true; @@ -391,7 +391,7 @@ ACMD(do_goto) if (*arg2 && isdigit(*arg2)) { str_to_number(empire, arg2); - empire = MINMAX(1, empire, 3); + empire = std::clamp(empire, 1, 3); } else empire = ch->GetEmpire(); @@ -513,7 +513,7 @@ ACMD(do_item) if (*arg2) { str_to_number(iCount, arg2); - iCount = MINMAX(1, iCount, ITEM_MAX_COUNT); + iCount = std::clamp(iCount, 1, ITEM_MAX_COUNT); } DWORD dwVnum; @@ -655,7 +655,7 @@ ACMD(do_mob_coward) else iCount = 1; - iCount = MIN(20, iCount); + iCount = std::min(20, iCount); while (iCount--) { @@ -737,7 +737,7 @@ ACMD(do_mob_aggresive) else iCount = 1; - iCount = MIN(20, iCount); + iCount = std::min(20, iCount); while (iCount--) { @@ -798,9 +798,9 @@ ACMD(do_mob) iCount = 1; if (test_server) - iCount = MIN(40, iCount); + iCount = std::min(40, iCount); else - iCount = MIN(20, iCount); + iCount = std::min(20, iCount); while (iCount--) { @@ -1547,7 +1547,7 @@ ACMD(do_advance) int level = 0; str_to_number(level, arg2); - tch->ResetPoint(MINMAX(0, level, PLAYER_MAX_LEVEL_CONST)); + tch->ResetPoint(std::clamp(level, 0, PLAYER_MAX_LEVEL_CONST)); } ACMD(do_respawn) @@ -1730,7 +1730,7 @@ ACMD(do_event_flag) !strcmp(arg1, "mob_gold_buyer") || !strcmp(arg1, "mob_gold_pct_buyer") ) - value = MINMAX(0, value, 1000); + value = std::clamp(value, 0, 1000); //quest::CQuestManager::instance().SetEventFlag(arg1, atoi(arg2)); quest::CQuestManager::instance().RequestSetEventFlag(arg1, value); @@ -2158,7 +2158,7 @@ ACMD(do_level) int level = 0; str_to_number(level, arg2); - ch->ResetPoint(MINMAX(1, level, PLAYER_MAX_LEVEL_CONST)); + ch->ResetPoint(std::clamp(level, 1, PLAYER_MAX_LEVEL_CONST)); ch->ClearSkill(); ch->ClearSubSkill(); @@ -2513,7 +2513,7 @@ ACMD(do_priv_empire) str_to_number(empire, arg1); str_to_number(type, arg2); str_to_number(value, arg3); - value = MINMAX(0, value, 1000); + value = std::clamp(value, 0, 1000); str_to_number(duration, arg4); if (empire < 0 || 3 < empire) @@ -3159,7 +3159,7 @@ ACMD(do_horse_level) } str_to_number(level, arg2); - level = MINMAX(0, level, HORSE_MAX_LEVEL); + level = std::clamp(level, 0, HORSE_MAX_LEVEL); ch->ChatPacket(CHAT_TYPE_INFO, "horse level set (%s: %d)", victim->GetName(), level); @@ -3172,7 +3172,7 @@ ACMD(do_horse_level) char arg1[256]; one_argument(argument, arg1, sizeof(arg1)); - int level = MINMAX(0, atoi(arg1), HORSE_MAX_LEVEL); + int level = std::clamp(atoi(arg1), 0, HORSE_MAX_LEVEL); ch->ChatPacket(CHAT_TYPE_INFO, "horse level set to %d.", level); ch->SetHorseLevel(level); diff --git a/game/src/config.cpp b/game/src/config.cpp index ba195c9..1e33675 100644 --- a/game/src/config.cpp +++ b/game/src/config.cpp @@ -695,7 +695,7 @@ void config_init(const string& st_localeServiceName) TOKEN("mark_min_level") { str_to_number(guild_mark_min_level, value_string); - guild_mark_min_level = MINMAX(0, guild_mark_min_level, GUILD_MAX_LEVEL); + guild_mark_min_level = std::clamp(guild_mark_min_level, 0, GUILD_MAX_LEVEL); continue; } @@ -709,7 +709,7 @@ void config_init(const string& st_localeServiceName) { int i = 0; str_to_number(i, value_string); - log_set_expiration_days(MINMAX(1, i, 90)); + log_set_expiration_days(std::clamp(i, 1, 90)); continue; } @@ -988,13 +988,13 @@ void config_init(const string& st_localeServiceName) TOKEN("spam_block_score") { str_to_number(g_uiSpamBlockScore, value_string); - g_uiSpamBlockScore = MAX(1, g_uiSpamBlockScore); + g_uiSpamBlockScore = std::max(1, g_uiSpamBlockScore); } TOKEN("spam_block_reload_cycle") { str_to_number(g_uiSpamReloadCycle, value_string); - g_uiSpamReloadCycle = MAX(60, g_uiSpamReloadCycle); // ÃÖ¼Ò 1ºÐ + g_uiSpamReloadCycle = std::max(60, g_uiSpamReloadCycle); // ÃÖ¼Ò 1ºÐ } TOKEN("check_multihack") @@ -1025,7 +1025,7 @@ void config_init(const string& st_localeServiceName) { str_to_number(gPlayerMaxLevel, value_string); - gPlayerMaxLevel = MINMAX(1, gPlayerMaxLevel, PLAYER_MAX_LEVEL_CONST); + gPlayerMaxLevel = std::clamp(gPlayerMaxLevel, 1, PLAYER_MAX_LEVEL_CONST); fprintf(stderr, "PLAYER_MAX_LEVEL: %d\n", gPlayerMaxLevel); } diff --git a/game/src/constants.h b/game/src/constants.h index 827e87a..0cb11d2 100644 --- a/game/src/constants.h +++ b/game/src/constants.h @@ -107,8 +107,8 @@ extern const DWORD guild_exp_table[GUILD_MAX_LEVEL + 1]; extern const DWORD guild_exp_table2[GUILD_MAX_LEVEL + 1]; #define MAX_EXP_DELTA_OF_LEV 31 -#define PERCENT_LVDELTA(me, victim) aiPercentByDeltaLev[MINMAX(0, (victim + 15) - me, MAX_EXP_DELTA_OF_LEV - 1)] -#define PERCENT_LVDELTA_BOSS(me, victim) aiPercentByDeltaLevForBoss[MINMAX(0, (victim + 15) - me, MAX_EXP_DELTA_OF_LEV - 1)] +#define PERCENT_LVDELTA(me, victim) aiPercentByDeltaLev[std::clamp((victim + 15) - me, 0, MAX_EXP_DELTA_OF_LEV - 1)] +#define PERCENT_LVDELTA_BOSS(me, victim) aiPercentByDeltaLevForBoss[std::clamp((victim + 15) - me, 0, MAX_EXP_DELTA_OF_LEV - 1)] #define CALCULATE_VALUE_LVDELTA(me, victim, val) ((val * PERCENT_LVDELTA(me, victim)) / 100) extern const int aiPercentByDeltaLev_euckr[MAX_EXP_DELTA_OF_LEV]; extern const int aiPercentByDeltaLevForBoss_euckr[MAX_EXP_DELTA_OF_LEV]; diff --git a/game/src/db.cpp b/game/src/db.cpp index 1fa383d..38787f0 100644 --- a/game/src/db.cpp +++ b/game/src/db.cpp @@ -209,7 +209,7 @@ void DBManager::PushBilling(CLoginData * pkLD) pkLD->SetLogonTime(); int lRemainSecs = pkLD->GetRemainSecs() - t.dwUseSec; - pkLD->SetRemainSecs(MAX(0, lRemainSecs)); + pkLD->SetRemainSecs(std::max(0, lRemainSecs)); t.dwLoginKey = pkLD->GetKey(); t.bBillType = pkLD->GetBillType(); @@ -614,7 +614,7 @@ void SendBillingExpire(const char * c_pszLogin, BYTE bBillType, int iSecs, CLogi strncpy(ptod.szLogin, c_pszLogin, sizeof(ptod.szLogin)); ptod.bBillType = bBillType; - ptod.dwRemainSeconds = MAX(0, iSecs); + ptod.dwRemainSeconds = std::max(0, iSecs); db_clientdesc->DBPacket(HEADER_GD_BILLING_EXPIRE, 0, &ptod, sizeof(TPacketBillingExpire)); sys_log(0, "BILLING: EXPIRE %s type %d sec %d ptr %p", c_pszLogin, bBillType, iSecs, pkLD); } @@ -927,7 +927,7 @@ void DBManager::AnalyzeReturnQuery(SQLMsg * pMsg) } } - SendBillingExpire(pinfo->szLogin, pinfo->bBillType, MAX(0, iRemainSecs), pkLD); + SendBillingExpire(pinfo->szLogin, pinfo->bBillType, std::max(0, iRemainSecs), pkLD); M2_DELETE(pinfo); } break; diff --git a/game/src/fishing.cpp b/game/src/fishing.cpp index c58c112..90385eb 100644 --- a/game/src/fishing.cpp +++ b/game/src/fishing.cpp @@ -248,7 +248,7 @@ void Initialize() do { - strncpy(szCol2, start, MIN(sizeof(szCol2), (tab - start) + 1)); + strncpy(szCol2, start, std::min(sizeof(szCol2), (tab - start) + 1)); szCol2[tab-start] = '\0'; trim_and_lower(szCol2, szCol, sizeof(szCol)); @@ -378,7 +378,7 @@ int DetermineFish(LPCHARACTER ch) int adjust = 0; if (quest::CQuestManager::instance().GetEventFlag("fish_miss_pct") != 0) { - int fish_pct_value = MINMAX(0, quest::CQuestManager::instance().GetEventFlag("fish_miss_pct"), 200); + int fish_pct_value = std::clamp(quest::CQuestManager::instance().GetEventFlag("fish_miss_pct"), 0, 200); adjust = (100-fish_pct_value) * fish_info[0].prob[prob_idx] / 100; } @@ -565,7 +565,7 @@ int Compute(DWORD fish_id, DWORD ms, DWORD* item, int level) if (ms > 6000) return -1; - int time_step = MINMAX(0,((ms + 99) / 200), MAX_FISHING_TIME_COUNT - 1); + int time_step = std::clamp(((ms + 99) / 200), 0, MAX_FISHING_TIME_COUNT - 1); if (Random::get(1, 100) <= aFishingTime[fish_info[fish_id].time_type][time_step]) { diff --git a/game/src/guild.cpp b/game/src/guild.cpp index 2485499..a08625a 100644 --- a/game/src/guild.cpp +++ b/game/src/guild.cpp @@ -446,7 +446,7 @@ void CGuild::SendListPacket(LPCHARACTER ch) buf.write(&(it->second), sizeof(DWORD)*3+1); - strncpy(c, it->second.name.c_str(), MIN(sizeof(c), it->second.name.length() + 1)); + strncpy(c, it->second.name.c_str(), std::min(sizeof(c), it->second.name.length() + 1)); buf.write(c, CHARACTER_NAME_MAX_LEN+1 ); @@ -604,7 +604,7 @@ void CGuild::LoadGuildData(SQLMsg* pmsg) else memset(m_data.abySkill, 0, sizeof(BYTE) * GUILD_SKILL_COUNT); - m_data.power = MAX(0, strtoul(row[6], (char **) NULL, 10)); + m_data.power = std::max(0, strtoul(row[6], (char **) NULL, 10)); str_to_number(m_data.ladder_point, row[7]); @@ -1411,7 +1411,7 @@ void CGuild::ComputeGuildPoints() { m_data.max_power = GUILD_BASE_POWER + (m_data.level-1) * GUILD_POWER_PER_LEVEL; - m_data.power = MINMAX(0, m_data.power, m_data.max_power); + m_data.power = std::clamp(m_data.power, 0, m_data.max_power); } int CGuild::GetSkillLevel(DWORD vnum) @@ -1489,7 +1489,7 @@ void CGuild::GuildPointChange(BYTE type, int amount, bool save) case POINT_SP: m_data.power += amount; - m_data.power = MINMAX(0, m_data.power, m_data.max_power); + m_data.power = std::clamp(m_data.power, 0, m_data.max_power); if (save) { @@ -1800,7 +1800,7 @@ void CGuild::AdvanceLevel(int iLevel) if (m_data.level == iLevel) return; - m_data.level = MIN(GUILD_MAX_LEVEL, iLevel); + m_data.level = std::min(GUILD_MAX_LEVEL, iLevel); } void CGuild::RequestDepositMoney(LPCHARACTER ch, int iGold) diff --git a/game/src/horse_rider.cpp b/game/src/horse_rider.cpp index 8bbf099..a2d0a71 100644 --- a/game/src/horse_rider.cpp +++ b/game/src/horse_rider.cpp @@ -166,7 +166,7 @@ void CHorseRider::UpdateHorseStamina(int iStamina, bool bSend) { int level = GetHorseLevel(); - m_Horse.sStamina = MINMAX(0, m_Horse.sStamina + iStamina, c_aHorseStat[level].iMaxStamina); + m_Horse.sStamina = std::clamp(m_Horse.sStamina + iStamina, 0, c_aHorseStat[level].iMaxStamina); if (GetHorseStamina() == 0 && IsHorseRiding()) { @@ -347,7 +347,7 @@ void CHorseRider::UpdateHorseHealth(int iHealth, bool bSend) { int level = GetHorseLevel(); - m_Horse.sHealth = MINMAX(0, m_Horse.sHealth + iHealth, c_aHorseStat[level].iMaxHealth); + m_Horse.sHealth = std::clamp(m_Horse.sHealth + iHealth, 0, c_aHorseStat[level].iMaxHealth); if (level && m_Horse.sHealth == 0) HorseDie(); @@ -366,7 +366,7 @@ void CHorseRider::HorseDie() void CHorseRider::SetHorseLevel(int iLevel) { - m_Horse.bLevel = iLevel = MINMAX(0, iLevel, HORSE_MAX_LEVEL); + m_Horse.bLevel = iLevel = std::clamp(iLevel, 0, HORSE_MAX_LEVEL); m_Horse.sStamina = c_aHorseStat[iLevel].iMaxStamina; m_Horse.sHealth = c_aHorseStat[iLevel].iMaxHealth; diff --git a/game/src/input.cpp b/game/src/input.cpp index b7c524c..72f02dc 100644 --- a/game/src/input.cpp +++ b/game/src/input.cpp @@ -526,7 +526,7 @@ dev_log(LOG_DEB0, "DC : '%s'", msg.c_str()); is >> strPrivEmpire >> empire >> type >> value >> duration; // ÃÖ´ëÄ¡ 10¹è - value = MINMAX(0, value, 1000); + value = std::clamp(value, 0, 1000); stResult = "PRIV_EMPIRE FAIL"; if (!is.fail()) diff --git a/game/src/input_db.cpp b/game/src/input_db.cpp index 9decf79..1222328 100644 --- a/game/src/input_db.cpp +++ b/game/src/input_db.cpp @@ -1875,7 +1875,7 @@ void CInputDB::BillingExpire(const char * c_pData) if (p->dwRemainSeconds <= 60) { - int i = MAX(5, p->dwRemainSeconds); + int i = std::max(5, p->dwRemainSeconds); sys_log(0, "BILLING_EXPIRE: %s %u", p->szLogin, p->dwRemainSeconds); d->DelayedDisconnect(i); } diff --git a/game/src/input_main.cpp b/game/src/input_main.cpp index 42505b0..5c7afde 100644 --- a/game/src/input_main.cpp +++ b/game/src/input_main.cpp @@ -395,7 +395,7 @@ int CInputMain::Whisper(LPCHARACTER ch, const char * data, size_t uiBytes) BYTE bType = WHISPER_TYPE_NORMAL; char buf[CHAT_MAX_LEN + 1]; - strncpy(buf, data + sizeof(TPacketCGWhisper), MIN(iExtraLen + 1, sizeof(buf))); + strncpy(buf, data + sizeof(TPacketCGWhisper), std::min(iExtraLen + 1, sizeof(buf))); const size_t buflen = strlen(buf); if (true == SpamBlockCheck(ch, buf, buflen)) @@ -654,7 +654,7 @@ int CInputMain::Chat(LPCHARACTER ch, const char * data, size_t uiBytes) } char buf[CHAT_MAX_LEN - (CHARACTER_NAME_MAX_LEN + 3) + 1]; - strncpy(buf, data + sizeof(TPacketCGChat), MIN(iExtraLen + 1, sizeof(buf))); + strncpy(buf, data + sizeof(TPacketCGChat), std::min(iExtraLen + 1, sizeof(buf))); const size_t buflen = strlen(buf); if (buflen > 1 && *buf == '/') @@ -1359,7 +1359,7 @@ bool CheckComboHack(LPCHARACTER ch, BYTE bArg, DWORD dwTime, bool CheckSpeedHack } else if (bArg > 14 && bArg < 22) { - int idx = MIN(2, ch->GetComboIndex()); + int idx = std::min(2, ch->GetComboIndex()); if (ch->GetComboSequence() > 5) // ÇöÀç 6ÄÞº¸ ÀÌ»óÀº ¾ø´Ù. { @@ -2561,7 +2561,7 @@ int CInputMain::Guild(LPCHARACTER ch, const char * data, size_t uiBytes) // by mhh : ±æµåÀÚ±ÝÀº ´çºÐ°£ ³ÖÀ» ¼ö ¾ø´Ù. return SubPacketLen; - const int gold = MIN(*reinterpret_cast(c_pData), __deposit_limit()); + const int gold = std::min(*reinterpret_cast(c_pData), __deposit_limit()); if (gold < 0) { @@ -2584,7 +2584,7 @@ int CInputMain::Guild(LPCHARACTER ch, const char * data, size_t uiBytes) // by mhh : ±æµåÀÚ±ÝÀº ´çºÐ°£ »¬ ¼ö ¾ø´Ù. return SubPacketLen; - const int gold = MIN(*reinterpret_cast(c_pData), 500000); + const int gold = std::min(*reinterpret_cast(c_pData), 500000); if (gold < 0) { diff --git a/game/src/input_p2p.cpp b/game/src/input_p2p.cpp index 63d3b08..140c29e 100644 --- a/game/src/input_p2p.cpp +++ b/game/src/input_p2p.cpp @@ -73,7 +73,7 @@ int CInputP2P::Relay(LPDESC d, const char * c_pData, size_t uiBytes) } char buf[1024]; - memcpy(buf, c_pbData, MIN(p->lSize, sizeof(buf))); + memcpy(buf, c_pbData, std::min(p->lSize, sizeof(buf))); TPacketGCWhisper* p2 = (TPacketGCWhisper*) buf; // bType »óÀ§ 4ºñÆ®: Empire ¹øÈ£ @@ -117,7 +117,7 @@ int CInputP2P::Notice(LPDESC d, const char * c_pData, size_t uiBytes) } char szBuf[256+1]; - strncpy(szBuf, c_pData + sizeof(TPacketGGNotice), MIN(p->lSize + 1, sizeof(szBuf))); + strncpy(szBuf, c_pData + sizeof(TPacketGGNotice), std::min(p->lSize + 1, sizeof(szBuf))); SendNotice(szBuf); return (p->lSize); } @@ -137,7 +137,7 @@ int CInputP2P::MonarchNotice(LPDESC d, const char * c_pData, size_t uiBytes) } char szBuf[256+1]; - strncpy(szBuf, c_pData + sizeof(TPacketGGMonarchNotice), MIN(p->lSize + 1, sizeof(szBuf))); + strncpy(szBuf, c_pData + sizeof(TPacketGGMonarchNotice), std::min(p->lSize + 1, sizeof(szBuf))); SendMonarchNotice(p->bEmpire, szBuf); return (p->lSize); } diff --git a/game/src/item.cpp b/game/src/item.cpp index f5a5e4c..9b3dc50 100644 --- a/game/src/item.cpp +++ b/game/src/item.cpp @@ -224,10 +224,10 @@ void CItem::UpdatePacket() DWORD CItem::GetCount() { - if (GetType() == ITEM_ELK) return MIN(m_dwCount, INT_MAX); + if (GetType() == ITEM_ELK) return std::min(m_dwCount, INT_MAX); else { - return MIN(m_dwCount, 200); + return std::min(m_dwCount, 200); } } @@ -235,11 +235,11 @@ bool CItem::SetCount(DWORD count) { if (GetType() == ITEM_ELK) { - m_dwCount = MIN(count, INT_MAX); + m_dwCount = std::min(count, INT_MAX); } else { - m_dwCount = MIN(count, ITEM_MAX_COUNT); + m_dwCount = std::min(count, ITEM_MAX_COUNT); } if (count == 0 && m_pOwner) @@ -630,7 +630,7 @@ void CItem::ModifyPoints(bool bAdd) } else { - accessoryGrade = MIN(GetAccessorySocketGrade(), ITEM_ACCESSORY_SOCKET_MAX_NUM); + accessoryGrade = std::min(GetAccessorySocketGrade(), ITEM_ACCESSORY_SOCKET_MAX_NUM); } for (int i = 0; i < ITEM_APPLY_MAX_NUM; ++i) @@ -647,7 +647,7 @@ void CItem::ModifyPoints(bool bAdd) else { if (0 != accessoryGrade) - value += MAX(accessoryGrade, value * aiAccessorySocketEffectivePct[accessoryGrade] / 100); + value += std::max(accessoryGrade, value * aiAccessorySocketEffectivePct[accessoryGrade] / 100); m_pOwner->ApplyPoint(m_pProto->aApplies[i].bType, bAdd ? value : -value); } @@ -1340,7 +1340,7 @@ EVENTFUNC(timer_based_on_wear_expire_event) return 0; } pkItem->SetSocket(ITEM_SOCKET_REMAIN_SEC, remain_time); - return PASSES_PER_SEC (MIN (60, remain_time)); + return PASSES_PER_SEC (std::min(60, remain_time)); } void CItem::SetUniqueExpireEvent(LPEVENT pkEvent) @@ -1433,7 +1433,7 @@ void CItem::StartUniqueExpireEvent() if (iSec == 0) iSec = 60; else - iSec = MIN(iSec, 60); + iSec = std::min(iSec, 60); SetSocket(ITEM_SOCKET_UNIQUE_SAVE_TIME, 0); @@ -1525,7 +1525,7 @@ bool CItem::IsAccessoryForSocket() void CItem::SetAccessorySocketGrade(int iGrade) { - SetSocket(0, MINMAX(0, iGrade, GetAccessorySocketMaxGrade())); + SetSocket(0, std::clamp(iGrade, 0, GetAccessorySocketMaxGrade())); int iDownTime = aiAccessorySocketDegradeTime[GetAccessorySocketGrade()]; @@ -1537,7 +1537,7 @@ void CItem::SetAccessorySocketGrade(int iGrade) void CItem::SetAccessorySocketMaxGrade(int iMaxGrade) { - SetSocket(1, MINMAX(0, iMaxGrade, ITEM_ACCESSORY_SOCKET_MAX_NUM)); + SetSocket(1, std::clamp(iMaxGrade, 0, ITEM_ACCESSORY_SOCKET_MAX_NUM)); } void CItem::SetAccessorySocketDownGradeTime(DWORD time) @@ -1603,7 +1603,7 @@ void CItem::StartAccessorySocketExpireEvent() if (iSec <= 1) iSec = 5; else - iSec = MIN(iSec, 60); + iSec = std::min(iSec, 60); item_vid_event_info* info = AllocEventInfo(); info->item_vid = GetVID(); @@ -1881,17 +1881,17 @@ void CItem::CopySocketTo(LPITEM pItem) int CItem::GetAccessorySocketGrade() { - return MINMAX(0, GetSocket(0), GetAccessorySocketMaxGrade()); + return std::clamp(GetSocket(0), 0, GetAccessorySocketMaxGrade()); } int CItem::GetAccessorySocketMaxGrade() { - return MINMAX(0, GetSocket(1), ITEM_ACCESSORY_SOCKET_MAX_NUM); + return std::clamp(GetSocket(1), 0, ITEM_ACCESSORY_SOCKET_MAX_NUM); } int CItem::GetAccessorySocketDownGradeTime() { - return MINMAX(0, GetSocket(2), aiAccessorySocketDegradeTime[GetAccessorySocketGrade()]); + return std::clamp(GetSocket(2), 0, aiAccessorySocketDegradeTime[GetAccessorySocketGrade()]); } void CItem::AttrLog() diff --git a/game/src/item_addon.cpp b/game/src/item_addon.cpp index e5e936b..43443c2 100644 --- a/game/src/item_addon.cpp +++ b/game/src/item_addon.cpp @@ -22,7 +22,7 @@ void CItemAddonManager::ApplyAddonTo(int iAddonType, LPITEM pItem) // TODO ÀÏ´Ü ÇϵåÄÚµùÀ¸·Î ÆòŸ ½ºÅ³ ¼öÄ¡ º¯°æ¸¸ °æ¿ì¸¸ Àû¿ë¹Þ°ÔÇÑ´Ù. - int iSkillBonus = MINMAX(-30, (int) (Random::get>(0, 5) + 0.5f), 30); + int iSkillBonus = std::clamp((int) (Random::get>(0, 5) + 0.5f), -30, 30); int iNormalHitBonus = 0; if (abs(iSkillBonus) <= 20) iNormalHitBonus = -2 * iSkillBonus + abs(Random::get(-8, 8) + Random::get(-8, 8)) + Random::get(1, 4); diff --git a/game/src/item_attribute.cpp b/game/src/item_attribute.cpp index 234b2db..4e1ab95 100644 --- a/game/src/item_attribute.cpp +++ b/game/src/item_attribute.cpp @@ -104,7 +104,7 @@ void CItem::AddAttr(BYTE bApply, BYTE bLevel) else { const TItemAttrTable & r = g_map_itemAttr[bApply]; - int lVal = r.lValues[MIN(4, bLevel - 1)]; + int lVal = r.lValues[std::min(4, bLevel - 1)]; if (lVal) SetAttribute(i, bApply, lVal); diff --git a/game/src/item_manager.cpp b/game/src/item_manager.cpp index fb1171b..f6b6ca0 100644 --- a/game/src/item_manager.cpp +++ b/game/src/item_manager.cpp @@ -263,7 +263,7 @@ LPITEM ITEM_MANAGER::CreateItem(DWORD vnum, DWORD count, DWORD id, bool bTryMagi ; else if (item->IsStackable()) // ÇÕÄ¥ ¼ö ÀÖ´Â ¾ÆÀÌÅÛÀÇ °æ¿ì { - count = MINMAX(1, count, ITEM_MAX_COUNT); + count = std::clamp(count, 1, ITEM_MAX_COUNT); if (bTryMagic && count <= 1 && IS_SET(item->GetFlag(), ITEM_FLAG_MAKECOUNT)) count = item->GetValue(1); diff --git a/game/src/item_manager_read_tables.cpp b/game/src/item_manager_read_tables.cpp index eb69275..44efb2c 100644 --- a/game/src/item_manager_read_tables.cpp +++ b/game/src/item_manager_read_tables.cpp @@ -60,7 +60,7 @@ bool ITEM_MANAGER::ReadCommonDropItemFile(const char * c_pszFileName) if (!p2) break; - strncpy(szTemp, p, MIN(sizeof(szTemp), (p2 - p) + 1)); + strncpy(szTemp, p, std::min(sizeof(szTemp), (p2 - p) + 1)); p = p2 + 1; switch (j) @@ -610,7 +610,7 @@ bool ITEM_MANAGER::ReadMonsterDropItemGroup(const char * c_pszFileName) int iRarePct = 0; str_to_number(iRarePct, pTok->at(3).c_str()); - iRarePct = MINMAX(0, iRarePct, 100); + iRarePct = std::clamp(iRarePct, 0, 100); sys_log(0," %s count %d rare %d", name.c_str(), iCount, iRarePct); pkGroup->AddItem(dwVnum, iCount, iPartPct, iRarePct); diff --git a/game/src/main.cpp b/game/src/main.cpp index 3531fdf..f94ba72 100644 --- a/game/src/main.cpp +++ b/game/src/main.cpp @@ -268,7 +268,7 @@ void heartbeat(LPHEART ht, int pulse) if (save_idx < g_vec_save.size()) { - count = MIN(100, g_vec_save.size() - save_idx); + count = std::min(100, g_vec_save.size() - save_idx); for (int i = 0; i < count; ++i, ++save_idx) db_clientdesc->DBPacket(HEADER_GD_PLAYER_SAVE, 0, &g_vec_save[save_idx], sizeof(TPlayerTable)); diff --git a/game/src/marriage.cpp b/game/src/marriage.cpp index 48e6b9e..583f45e 100644 --- a/game/src/marriage.cpp +++ b/game/src/marriage.cpp @@ -64,7 +64,7 @@ namespace marriage int TMarriage::GetMarriageGrade() { - int point = MINMAX(50, GetMarriagePoint(), 100); + int point = std::clamp(GetMarriagePoint(), 50, 100); if (point < 65) return 0; else if (point < 80) @@ -80,7 +80,7 @@ namespace marriage { int value = quest::CQuestManager::instance().GetEventFlag("lovepoint"); if (value) - return MINMAX(0, value, 100); + return std::clamp(value, 0, 100); } int point_per_day = MARRIAGE_POINT_PER_DAY; @@ -112,7 +112,7 @@ namespace marriage // ³¯Â¥¿¡ ÀÇÇÑ ¿µÇâ 60% ÇÏ·ç´ç 6% // ÀüÅõ¿¡ ÀÇÇÑ ¿µÇâ 60% // ÅäÅ» 100% - return MIN(50 + MIN(days * point_per_day, max_limit) + MIN(love_point / 1000000, max_limit), 100); + return std::min(50 + std::min(days * point_per_day, max_limit) + std::min(love_point / 1000000, max_limit), 100); } bool TMarriage::IsNear() @@ -433,7 +433,7 @@ namespace marriage bSave = true; love_point += point; - love_point = MIN( love_point, 2000000000 ); + love_point = std::min( love_point, 2000000000 ); if (test_server) { diff --git a/game/src/mining.cpp b/game/src/mining.cpp index 26d15d1..c702dfe 100644 --- a/game/src/mining.cpp +++ b/game/src/mining.cpp @@ -157,7 +157,7 @@ namespace mining if (!pick || pick->GetType() != ITEM_PICK) return 0; - return defaultPct + SkillLevelAddPct[MINMAX(0, iSkillLevel, 40)] + PickGradeAddPct[MINMAX(0, pick->GetRefineLevel(), 9)]; + return defaultPct + SkillLevelAddPct[std::clamp(iSkillLevel, 0, 40)] + PickGradeAddPct[std::clamp(pick->GetRefineLevel(), 0, 9)]; } EVENTINFO(mining_event_info) diff --git a/game/src/party.cpp b/game/src/party.cpp index a509f60..cb5a98e 100644 --- a/game/src/party.cpp +++ b/game/src/party.cpp @@ -1220,8 +1220,8 @@ void CParty::ComputeRolePoint(LPCHARACTER ch, BYTE bRole, bool bAdd) } //SKILL_POWER_BY_LEVEL - float k = (float) ch->GetSkillPowerByLevel( MIN(SKILL_MAX_LEVEL, m_iLeadership ) )/ 100.0f; - //float k = (float) aiSkillPowerByLevel[MIN(SKILL_MAX_LEVEL, m_iLeadership)] / 100.0f; + float k = (float) ch->GetSkillPowerByLevel(std::min(SKILL_MAX_LEVEL, m_iLeadership)) / 100.0f; + //float k = (float) aiSkillPowerByLevel[std::min(SKILL_MAX_LEVEL, m_iLeadership)] / 100.0f; // //sys_log(0,"ComputeRolePoint %fi %d, %d ", k, SKILL_MAX_LEVEL, m_iLeadership ); //END_SKILL_POWER_BY_LEVEL @@ -1646,7 +1646,7 @@ BYTE CParty::GetMemberMaxLevel() if (!bMax) bMax = it->second.bLevel; else if (it->second.bLevel) - bMax = MAX(bMax, it->second.bLevel); + bMax = std::max(bMax, it->second.bLevel); ++it; } return bMax; @@ -1668,7 +1668,7 @@ BYTE CParty::GetMemberMinLevel() if (!bMin) bMin = it->second.bLevel; else if (it->second.bLevel) - bMin = MIN(bMin, it->second.bLevel); + bMin = std::min(bMin, it->second.bLevel); ++it; } return bMin; @@ -1684,7 +1684,7 @@ int CParty::ComputePartyBonusExpPercent() int iBonusPartyExpFromItem = 0; // UPGRADE_PARTY_BONUS - int iMemberCount=MIN(8, GetNearMemberCount()); + int iMemberCount = std::min(8, GetNearMemberCount()); if (leader && (leader->IsEquipUniqueItem(UNIQUE_ITEM_PARTY_BONUS_EXP) || leader->IsEquipUniqueItem(UNIQUE_ITEM_PARTY_BONUS_EXP_MALL) || leader->IsEquipUniqueItem(UNIQUE_ITEM_PARTY_BONUS_EXP_GIFT) || leader->IsEquipUniqueGroup(10010))) diff --git a/game/src/priv_manager.cpp b/game/src/priv_manager.cpp index 65577e2..18a97e4 100644 --- a/game/src/priv_manager.cpp +++ b/game/src/priv_manager.cpp @@ -32,8 +32,8 @@ void CPrivManager::RequestGiveGuildPriv(DWORD guild_id, BYTE type, int value, ti return; } - value = MINMAX(0, value, 50); - duration_sec = MINMAX(0, duration_sec, 60*60*24*7); + value = std::clamp(value, 0, 50); + duration_sec = std::clamp(duration_sec, 0, 60*60*24*7); TPacketGiveGuildPriv p; p.type = type; @@ -52,8 +52,8 @@ void CPrivManager::RequestGiveEmpirePriv(BYTE empire, BYTE type, int value, time return; } - value = MINMAX(0, value, 200); - duration_sec = MINMAX(0, duration_sec, 60*60*24*7); + value = std::clamp(value, 0, 200); + duration_sec = std::clamp(duration_sec, 0, 60*60*24*7); TPacketGiveEmpirePriv p; p.type = type; @@ -72,7 +72,7 @@ void CPrivManager::RequestGiveCharacterPriv(DWORD pid, BYTE type, int value) return; } - value = MINMAX(0, value, 100); + value = std::clamp(value, 0, 100); TPacketGiveCharacterPriv p; p.type = type; @@ -92,8 +92,8 @@ void CPrivManager::GiveGuildPriv(DWORD guild_id, BYTE type, int value, BYTE bLog sys_log(0,"Set Guild Priv: guild_id(%u) type(%d) value(%d) duration_sec(%d)", guild_id, type, value, end_time_sec - get_global_time()); - value = MINMAX(0, value, 50); - end_time_sec = MINMAX(0, end_time_sec, get_global_time()+60*60*24*7); + value = std::clamp(value, 0, 50); + end_time_sec = std::clamp(end_time_sec, 0, get_global_time()+60*60*24*7); m_aPrivGuild[type][guild_id].value = value; m_aPrivGuild[type][guild_id].end_time_sec = end_time_sec; @@ -132,7 +132,7 @@ void CPrivManager::GiveCharacterPriv(DWORD pid, BYTE type, int value, BYTE bLog) sys_log(0,"Set Character Priv %u %d %d", pid, type, value); - value = MINMAX(0, value, 100); + value = std::clamp(value, 0, 100); m_aPrivChar[type][pid] = value; @@ -150,8 +150,8 @@ void CPrivManager::GiveEmpirePriv(BYTE empire, BYTE type, int value, BYTE bLog, sys_log(0, "Set Empire Priv: empire(%d) type(%d) value(%d) duration_sec(%d)", empire, type, value, end_time_sec-get_global_time()); - value = MINMAX(0, value, 200); - end_time_sec = MINMAX(0, end_time_sec, get_global_time()+60*60*24*7); + value = std::clamp(value, 0, 200); + end_time_sec = std::clamp(end_time_sec, 0, get_global_time()+60*60*24*7); SPrivEmpireData& rkPrivEmpireData=m_aakPrivEmpireData[type][empire]; rkPrivEmpireData.m_value = value; @@ -235,11 +235,11 @@ int CPrivManager::GetPriv(LPCHARACTER ch, BYTE type) int val; // °³ÀÎ, Á¦±¹, ±æµå, Àüü Áß Å« °ªÀ» ÃëÇÑ´Ù. - val = MAX(val_ch, GetPrivByEmpire(0, type)); - val = MAX(val, GetPrivByEmpire(ch->GetEmpire(), type)); + val = std::max(val_ch, GetPrivByEmpire(0, type)); + val = std::max(val, GetPrivByEmpire(ch->GetEmpire(), type)); if (ch->GetGuild()) - val = MAX(val, GetPrivByGuild(ch->GetGuild()->GetID(), type)); + val = std::max(val, GetPrivByGuild(ch->GetGuild()->GetID(), type)); return val; } diff --git a/game/src/pvp.cpp b/game/src/pvp.cpp index fd36701..251e21b 100644 --- a/game/src/pvp.cpp +++ b/game/src/pvp.cpp @@ -213,7 +213,7 @@ void CPVPManager::Insert(LPCHARACTER pkChr, LPCHARACTER pkVictim) { TPacketGCWhisper pack; - int len = MIN(CHAT_MAX_LEN, strlen(msg) + 1); + int len = std::min(CHAT_MAX_LEN, strlen(msg) + 1); pack.bHeader = HEADER_GC_WHISPER; pack.wSize = sizeof(TPacketGCWhisper) + len; diff --git a/game/src/questlua_global.cpp b/game/src/questlua_global.cpp index 3e4b462..596570e 100644 --- a/game/src/questlua_global.cpp +++ b/game/src/questlua_global.cpp @@ -1133,7 +1133,7 @@ namespace quest } const DWORD dwVnum = static_cast(lua_tonumber(L, 1)); - const size_t count = MINMAX(1, static_cast(lua_tonumber(L, 2)), 10); + const size_t count = std::clamp(static_cast(lua_tonumber(L, 2)), 1, 10); const bool isAggresive = static_cast(lua_toboolean(L, 3)); size_t SpawnCount = 0; diff --git a/game/src/questlua_horse.cpp b/game/src/questlua_horse.cpp index 599207c..da46282 100644 --- a/game/src/questlua_horse.cpp +++ b/game/src/questlua_horse.cpp @@ -102,7 +102,7 @@ namespace quest if (!lua_isnumber(L, 1)) return 0; - int newlevel = MINMAX(0, (int)lua_tonumber(L, 1), HORSE_MAX_LEVEL); + int newlevel = std::clamp((int)lua_tonumber(L, 1), 0, HORSE_MAX_LEVEL); ch->SetHorseLevel(newlevel); ch->ComputePoints(); ch->SkillLevelPacket(); @@ -145,7 +145,7 @@ namespace quest { LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr(); - int pct = MINMAX(0, ch->GetHorseHealth() * 100 / ch->GetHorseMaxHealth(), 100); + int pct = std::clamp(ch->GetHorseHealth() * 100 / ch->GetHorseMaxHealth(), 0, 100); sys_log(1, "horse.get_health_pct %d", pct); if (ch->GetHorseLevel()) @@ -171,7 +171,7 @@ namespace quest int horse_get_stamina_pct(lua_State* L) { LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr(); - int pct = MINMAX(0, ch->GetHorseStamina() * 100 / ch->GetHorseMaxStamina(), 100); + int pct = std::clamp(ch->GetHorseStamina() * 100 / ch->GetHorseMaxStamina(), 0, 100); sys_log(1, "horse.get_stamina_pct %d", pct); if (ch->GetHorseLevel()) diff --git a/game/src/questlua_npc.cpp b/game/src/questlua_npc.cpp index 455fb8c..270cf39 100644 --- a/game/src/questlua_npc.cpp +++ b/game/src/questlua_npc.cpp @@ -77,7 +77,7 @@ namespace quest lua_pushnumber(L, 0); return 1; } - lua_pushnumber(L, MAX(0, npc->GetPoint(POINT_ATT_GRADE_BONUS))); + lua_pushnumber(L, std::max(0, npc->GetPoint(POINT_ATT_GRADE_BONUS))); return 1; } @@ -88,7 +88,7 @@ namespace quest { return 0; } - npc->SetPoint(POINT_ATT_GRADE_BONUS, MAX(0, npc->GetPoint(POINT_ATT_GRADE_BONUS)-1)); + npc->SetPoint(POINT_ATT_GRADE_BONUS, std::max(0, npc->GetPoint(POINT_ATT_GRADE_BONUS)-1)); return 0; } @@ -100,7 +100,7 @@ namespace quest lua_pushnumber(L, 0); return 1; } - lua_pushnumber(L, MAX(0, npc->GetPoint(POINT_DEF_GRADE_BONUS))); + lua_pushnumber(L, std::max(0, npc->GetPoint(POINT_DEF_GRADE_BONUS))); return 1; } @@ -111,7 +111,7 @@ namespace quest { return 0; } - npc->SetPoint(POINT_DEF_GRADE_BONUS, MAX(0, npc->GetPoint(POINT_DEF_GRADE_BONUS)-1)); + npc->SetPoint(POINT_DEF_GRADE_BONUS, std::max(0, npc->GetPoint(POINT_DEF_GRADE_BONUS)-1)); return 0; } diff --git a/game/src/questlua_pc.cpp b/game/src/questlua_pc.cpp index 5ebe577..55a8c87 100644 --- a/game/src/questlua_pc.cpp +++ b/game/src/questlua_pc.cpp @@ -865,8 +865,8 @@ namespace quest //Æ÷ÀÎÆ® : ½ºÅ³, ¼­ºê½ºÅ³, ½ºÅÈ ch->PointChange(POINT_SKILL, newLevel - ch->GetLevel()); - ch->PointChange(POINT_SUB_SKILL, newLevel < 10 ? 0 : newLevel - MAX(ch->GetLevel(), 9)); - ch->PointChange(POINT_STAT, ((MINMAX(1, newLevel, 90) - ch->GetLevel()) * 3) + ch->GetPoint(POINT_LEVEL_STEP)); + ch->PointChange(POINT_SUB_SKILL, newLevel < 10 ? 0 : newLevel - std::max(ch->GetLevel(), 9)); + ch->PointChange(POINT_STAT, ((std::clamp(newLevel, 1, 90) - ch->GetLevel()) * 3) + ch->GetPoint(POINT_LEVEL_STEP)); //·¹º§ ch->PointChange(POINT_LEVEL, newLevel - ch->GetLevel()); //HP, SP @@ -1149,7 +1149,7 @@ namespace quest sys_log(0, "QUEST [REWARD] %s give exp %s lev %d percent %g%%", ch->GetName(), lua_tostring(L, 1), lev, proc); - DWORD exp = (DWORD)((exp_table[MINMAX(0, lev, PLAYER_EXP_TABLE_MAX)] * proc) / 100); + DWORD exp = (DWORD)((exp_table[std::clamp(lev, 0, PLAYER_EXP_TABLE_MAX)] * proc) / 100); PC * pPC = CQuestManager::instance().GetCurrentPC(); LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), exp, 0); diff --git a/game/src/questnpc.cpp b/game/src/questnpc.cpp index ad2d096..c8600ef 100644 --- a/game/src/questnpc.cpp +++ b/game/src/questnpc.cpp @@ -159,7 +159,7 @@ namespace quest istreambuf_iterator ib(inf), ie; - m_mapOwnArgQuest[event_index][quest_index][state_index].resize(MAX(index + 1, m_mapOwnArgQuest[event_index][quest_index][state_index].size())); + m_mapOwnArgQuest[event_index][quest_index][state_index].resize(std::max(index + 1, m_mapOwnArgQuest[event_index][quest_index][state_index].size())); if (type_name == "when") { diff --git a/game/src/safebox.cpp b/game/src/safebox.cpp index 75b3981..244cc75 100644 --- a/game/src/safebox.cpp +++ b/game/src/safebox.cpp @@ -198,7 +198,7 @@ bool CSafebox::MoveItem(BYTE bCell, BYTE bDestCell, BYTE count) if (count == 0) count = item->GetCount(); - count = MIN(200 - item2->GetCount(), count); + count = std::min(200 - item2->GetCount(), count); if (item->GetCount() >= count) Remove(bCell); diff --git a/game/src/sectree_manager.cpp b/game/src/sectree_manager.cpp index 9b5402b..b204978 100644 --- a/game/src/sectree_manager.cpp +++ b/game/src/sectree_manager.cpp @@ -1295,9 +1295,6 @@ bool SECTREE_MANAGER::ForAttrRegionRightAngle( int lMapIndex, int lCX, int lCY, return mode == ATTR_REGION_MODE_CHECK ? false : true; } -#define min( l, r ) ((l) < (r) ? (l) : (r)) -#define max( l, r ) ((l) < (r) ? (r) : (l)) - bool SECTREE_MANAGER::ForAttrRegionFreeAngle( int lMapIndex, int lCX, int lCY, int lCW, int lCH, int lRotate, DWORD dwAttr, EAttrRegionMode mode ) { float fx1 = (-lCW/2) * sinf(float(lRotate)/180.0f*3.14f) + (-lCH/2) * cosf(float(lRotate)/180.0f*3.14f); @@ -1330,15 +1327,15 @@ bool SECTREE_MANAGER::ForAttrRegionFreeAngle( int lMapIndex, int lCX, int lCY, i float fb3 = fy4 - fTilt1*fx4; float fb4 = fy4 - fTilt2*fx4; - float fxMin = min(fx1, min(fx2, min(fx3, fx4))); - float fxMax = max(fx1, max(fx2, max(fx3, fx4))); + float fxMin = std::min(fx1, std::min(fx2, std::min(fx3, fx4))); + float fxMax = std::max(fx1, std::max(fx2, std::max(fx3, fx4))); for (int i = int(fxMin); i < int(fxMax); ++i) { - float fyValue1 = fTilt1*i + min(fb1, fb3); - float fyValue2 = fTilt2*i + min(fb2, fb4); + float fyValue1 = fTilt1*i + std::min(fb1, fb3); + float fyValue2 = fTilt2*i + std::min(fb2, fb4); - float fyValue3 = fTilt1*i + max(fb1, fb3); - float fyValue4 = fTilt2*i + max(fb2, fb4); + float fyValue3 = fTilt1*i + std::max(fb1, fb3); + float fyValue4 = fTilt2*i + std::max(fb2, fb4); float fMinValue; float fMaxValue; @@ -1351,7 +1348,7 @@ bool SECTREE_MANAGER::ForAttrRegionFreeAngle( int lMapIndex, int lCX, int lCY, i else fMinValue = fyValue4; - for (int j = int(min(fMinValue, fMaxValue)); j < int(max(fMinValue, fMaxValue)); ++j) { + for (int j = int(std::min(fMinValue, fMaxValue)); j < int(std::max(fMinValue, fMaxValue)); ++j) { if ( ForAttrRegionCell( lMapIndex, lCX + (lCW / 2) + i, lCY + (lCH / 2) + j, dwAttr, mode ) ) return true; } diff --git a/game/src/target.cpp b/game/src/target.cpp index 1062242..25b1824 100644 --- a/game/src/target.cpp +++ b/game/src/target.cpp @@ -75,7 +75,7 @@ EVENTFUNC(target_event) int iDist = 5000; if (info->iMapIndex != pkChr->GetMapIndex()) - return MINMAX(passes_per_sec / 2, iDist / (1500 / passes_per_sec), passes_per_sec * 5); + return std::clamp(iDist / (1500 / passes_per_sec), passes_per_sec / 2, passes_per_sec * 5); switch (info->iType) { @@ -128,7 +128,7 @@ EVENTFUNC(target_event) if (!bRet) return passes_per_sec; else - return MINMAX(passes_per_sec / 2, iDist / (1500 / passes_per_sec), passes_per_sec * 5); + return std::clamp(iDist / (1500 / passes_per_sec), passes_per_sec / 2, passes_per_sec * 5); } void CTargetManager::CreateTarget(DWORD dwPID, diff --git a/libgame/src/grid.cc b/libgame/src/grid.cc index 1aacccf..e2b7391 100644 --- a/libgame/src/grid.cc +++ b/libgame/src/grid.cc @@ -12,7 +12,7 @@ CGrid::CGrid(int w, int h) : m_iWidth(w), m_iHeight(h) CGrid::CGrid(CGrid * pkGrid, int w, int h) : m_iWidth(w), m_iHeight(h) { m_pGrid = new char[m_iWidth * m_iHeight]; - int iSize = std::MIN(w * h, pkGrid->m_iWidth * pkGrid->m_iHeight); + int iSize = std::min(w * h, pkGrid->m_iWidth * pkGrid->m_iHeight); memcpy(m_pGrid, pkGrid->m_pGrid, sizeof(char) * iSize); } diff --git a/libthecore/include/utils.h b/libthecore/include/utils.h index a73bdf0..b1ec6ec 100644 --- a/libthecore/include/utils.h +++ b/libthecore/include/utils.h @@ -5,20 +5,12 @@ #include "effolkronium/random.hpp" using Random = effolkronium::random_static; -#define SAFE_FREE(p) { if (p) { free( (void *) p); (p) = NULL; } } -#define SAFE_DELETE(p) { if (p) { delete (p); (p) = NULL; } } -#define SAFE_DELETE_ARRAY(p) { if (p) { delete[] (p); (p) = NULL; } } -#define SAFE_RELEASE(p) { if (p) { (p)->Release(); (p) = NULL; } } +#include #define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c)) #define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c)) #define str_cmp strcasecmp -#define STRNCPY(dst, src, len) do {strncpy(dst, src, len); dst[len] = '\0'; } while(0) - - extern char * str_dup(const char * source); // ¸Þ¸ð¸® ÇÒ´ç Çؼ­ source º¹»ç ÇÑ°Å ¸®ÅÏ - extern void printdata(const unsigned char * data, int bytes); // data¸¦ hex¶û ascii·Î Ãâ·Â (ÆÐŶ ºÐ¼® µî¿¡ ¾²ÀÓ) - extern int filesize(FILE * fp); // ÆÄÀÏ Å©±â ¸®ÅÏ #define core_dump() core_dump_unix(__FILE__, __LINE__) extern void core_dump_unix(const char *who, WORD line); // Äھ °­Á¦·Î ´ýÇÁ @@ -29,12 +21,6 @@ using Random = effolkronium::random_static; extern void trim_and_lower(const char * src, char * dest, size_t dest_size); - // ¹®ÀÚ¿­À» ¼Ò¹®ÀÚ·Î - extern void lower_string(const char * src, char * dest, size_t dest_len); - - // arg1ÀÌ arg2·Î ½ÃÀÛÇϴ°¡? (´ë¼Ò¹®ÀÚ ±¸º°ÇÏÁö ¾ÊÀ½) - extern int is_abbrev(char *arg1, char *arg2); - // a¿Í bÀÇ ½Ã°£ÀÌ ¾ó¸¶³ª Â÷À̳ª´ÂÁö ¸®ÅÏ extern struct timeval * timediff(const struct timeval *a, const struct timeval *b); @@ -44,10 +30,6 @@ using Random = effolkronium::random_static; // ÇöÀç ½Ã°£ curr_tmÀ¸·Î ºÎÅÍ days°¡ Áö³­ ³¯À» ¸®ÅÏ extern struct tm * tm_calc(const struct tm *curr_tm, int days); - extern int MAX(int a, int b); // µÑÁß¿¡ Å« °ªÀ» ¸®ÅÏ - extern int MIN(int a, int b); // µÑÁß¿¡ ÀÛÀº °ªÀ» ¸®ÅÏ - extern int MINMAX(int min, int value, int max); // ÃÖ¼Ò ÃÖ´ë °ªÀ» ÇÔ²² ºñ±³Çؼ­ ¸®ÅÏ - extern void thecore_sleep(struct timeval * timeout); // timeout¸¸Å­ ÇÁ·Î¼¼½º ½¬±â extern float get_float_time(); diff --git a/libthecore/src/buffer.cpp b/libthecore/src/buffer.cpp index 122ef2e..7f71ce3 100644 --- a/libthecore/src/buffer.cpp +++ b/libthecore/src/buffer.cpp @@ -162,7 +162,7 @@ void buffer_reset(LPBUFFER buffer) void buffer_write(LPBUFFER& buffer, const void *src, int length) { if (buffer->write_point_pos + length >= buffer->mem_size) - buffer_realloc(buffer, buffer->mem_size + length + MIN(10240, length)); + buffer_realloc(buffer, buffer->mem_size + length + std::min(10240, length)); memcpy(buffer->write_point, src, length); buffer_write_proceed(buffer, length); diff --git a/libthecore/src/utils.cpp b/libthecore/src/utils.cpp index c299dd8..083f344 100644 --- a/libthecore/src/utils.cpp +++ b/libthecore/src/utils.cpp @@ -10,56 +10,6 @@ static struct timeval null_time = { 0, 0 }; -#define ishprint(x) ((((x) & 0xE0) > 0x90) || isprint(x)) - -void printdata(const unsigned char *data, int bytes) -{ - int i, j, k; - const unsigned char *p; - - fprintf(stderr, "------------------------------------------------------------------\n"); - j = bytes; - while (1) - { - k = j >= 16 ? 16 : j; - - p = data; - for (i = 0; i < 16; i++) - { - if (i >= k) - fprintf(stderr, " "); - else - fprintf(stderr, "%02x ", *p); - p++; - } - - fprintf(stderr, "| "); - - p = data; - for (i = 0; i < k; i++) - { - if (i >= k) - fprintf(stderr, " "); - else - { - fprintf(stderr, "%c", ishprint(*p) && ishprint(*(p+1)) ? *p : '.'); - } - p++; - } - - fprintf(stderr, "\n"); - - j -= 16; - data += 16; - - if (j <= 0) - break; - } - - fprintf(stderr, "------------------------------------------------------------------\n"); -} - - struct timeval * timediff(const struct timeval *a, const struct timeval *b) { static struct timeval rslt; @@ -166,73 +116,6 @@ void trim_and_lower(const char * src, char * dest, size_t dest_size) } } -void lower_string(const char *src, char *dest, size_t dest_size) -{ - const char* tmp = src; - size_t len = 0; - - if (!dest || dest_size == 0) - return; - - if (!src) - { - *dest = '\0'; - return; - } - - // \0 È®º¸ - --dest_size; - - while (*tmp && len < dest_size) - { - *(dest++) = LOWER(*tmp); // LOWER´Â ¸ÅÅ©·Î¶ó ++ ¾²¸é ¾ÈµÊ - ++tmp; - ++len; - } - - *dest = '\0'; -} - -char *str_dup(const char *source) -{ - char *new_line; - - CREATE(new_line, char, strlen(source) + 1); - return (strcpy(new_line, source)); -} - -/* arg1 ÀÌ arg2 ÀÇ ¾Õ´Ü°ú °°À» ¶§ 1 À» ¸®ÅÏÇÑ´Ù. */ -int is_abbrev(char *arg1, char *arg2) -{ - if (!*arg1) - return 0; - - for (; *arg1 && *arg2; arg1++, arg2++) - if (LOWER(*arg1) != LOWER(*arg2)) - return 0; - - if (!*arg1) - return 1; - else - return 0; -} - - -int filesize(FILE *fp) -{ - int pos; - int size; - - pos = ftell(fp); - - fseek(fp, 0, SEEK_END); - size = ftell(fp); - fseek(fp, pos, SEEK_SET); - - return (size); -} - - /* "Name : ºñ¿±" °ú °°ÀÌ "Ç׸ñ : °ª" À¸·Î ÀÌ·ç¾îÁø ¹®ÀÚ¿­¿¡¼­ Ç׸ñÀ» token À¸·Î, °ªÀ» value ·Î º¹»çÇÏ¿© ¸®ÅÏÇÑ´Ù. */ void parse_token(char *src, char *token, char *value) @@ -327,24 +210,6 @@ struct tm * tm_calc(const struct tm * curr_tm, int days) return (&new_tm); } -int MIN(int a, int b) -{ - return a < b ? a : b; -} - -int MAX(int a, int b) -{ - return a > b ? a : b; -} - -int MINMAX(int min, int value, int max) -{ - register int tv; - - tv = (min > value ? min : value); - return (max < tv) ? max : tv; -} - #ifndef __WIN32__ void thecore_sleep(struct timeval* timeout) {