Skip to content

Commit

Permalink
Merge branch 'main' into fix-exp-formula
Browse files Browse the repository at this point in the history
  • Loading branch information
omarcopires authored May 16, 2024
2 parents f09580a + b83c9b4 commit ad92e23
Show file tree
Hide file tree
Showing 85 changed files with 552 additions and 578 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build-ubuntu-dummy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
os: [ubuntu-22.04]
buildtype: [linux-release, linux-debug]
include:
- os: ubuntu-20.04
triplet: x64-linux
- os: ubuntu-22.04
triplet: x64-linux

Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/build-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
os: [ubuntu-22.04]
buildtype: [linux-release, linux-debug]
include:
- os: ubuntu-20.04
triplet: x64-linux
- os: ubuntu-22.04
triplet: x64-linux

Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ endif()


# === IPO ===
option(OPTIONS_ENABLE_IPO "Check and Enable interprocedural optimization (IPO/LTO)" ON)
if(OPTIONS_ENABLE_IPO)
log_option_enabled("IPO/LTO")
if(MSVC)
log_option_enabled("IPO/LTO")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
else()
if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Release")
log_option_enabled("IPO/LTO")
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
Expand Down
4 changes: 3 additions & 1 deletion cmake/modules/BaseConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ if (MSVC)
endforeach(type)

add_compile_options(/MP /FS /Zf /EHsc)
endif (MSVC)
else()
add_compile_options(-Wno-unused-parameter -Wno-sign-compare -Wno-switch -Wno-implicit-fallthrough -Wno-extra)
endif()

## Link compilation files to build/bin folder, else link to the main dir
function(set_output_directory target_name)
Expand Down
6 changes: 2 additions & 4 deletions data-otservbr-global/lib/quests/the_primal_ordeal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ function RegisterPrimalPackBeast(template)
primalMonster.loot = {}
primalMonster.name = "Primal Pack Beast"
primalMonster.description = "a primal pack beast"

primalMonster.health = primalMonster.health
primalMonster.maxHealth = primalMonster.maxHealth
primalMonster.maxHealth = primalMonster.maxHealth * 0.7
primalMonster.health = primalMonster.maxHealth
primalMonster.raceId = nil
primalMonster.Bestiary = nil
primalMonster.corpse = 0

primal:register(primalMonster)
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ local thePrimalMenaceConfig = {
CountGrowthPerHazard = 1.05,
CountMax = 6,

HpRateOnSpawn = 0.7,
MonsterPool = {
"Emerald Tortoise (Primal)",
"Gore Horn (Primal)",
Expand Down Expand Up @@ -291,8 +290,6 @@ local function spawnMonster(monsterId, spawnPosition)
MonsterId = primalMonster:getId(),
Created = os.time(),
}
local monsterMaxHealth = primalMonster:getMaxHealth()
primalMonster:setHealth(monsterMaxHealth * thePrimalMenaceConfig.MonsterConfig.HpRateOnSpawn)

local primalBeasts = monster:getStorageValue(thePrimalMenaceConfig.Storage.PrimalBeasts)
table.insert(primalBeasts, primalBeastEntry)
Expand Down
67 changes: 44 additions & 23 deletions data/scripts/lib/register_achievements.lua

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void CanaryServer::loadModules() {
// If "USE_ANY_DATAPACK_FOLDER" is set to true then you can choose any datapack folder for your server
const auto useAnyDatapack = g_configManager().getBoolean(USE_ANY_DATAPACK_FOLDER, __FUNCTION__);
auto datapackName = g_configManager().getString(DATA_DIRECTORY, __FUNCTION__);
if (!useAnyDatapack && (datapackName != "data-canary" && datapackName != "data-otservbr-global" || datapackName != "data-otservbr-global" && datapackName != "data-canary")) {
if (!useAnyDatapack && datapackName != "data-canary" && datapackName != "data-otservbr-global") {
throw FailedToInitializeCanary(fmt::format(
"The datapack folder name '{}' is wrong, please select valid "
"datapack name 'data-canary' or 'data-otservbr-global "
Expand Down
2 changes: 1 addition & 1 deletion src/canary_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class CanaryServer {
FAILED
};

RSA &rsa;
Logger &logger;
RSA &rsa;
ServiceManager &serviceManager;

std::atomic<LoaderStatus> loaderStatus = LoaderStatus::LOADING;
Expand Down
1 change: 0 additions & 1 deletion src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "config/configmanager.hpp"
#include "lib/di/container.hpp"
#include "declarations.hpp"
#include "game/game.hpp"
#include "server/network/webhook/webhook.hpp"

Expand Down
9 changes: 4 additions & 5 deletions src/creatures/appearance/mounts/mounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool Mounts::loadFromXml() {
continue;
}

mounts.emplace_back(std::make_shared<Mount>(
mounts.emplace(std::make_shared<Mount>(
static_cast<uint8_t>(pugi::cast<uint16_t>(mountNode.attribute("id").value())),
lookType,
mountNode.attribute("name").as_string(),
Expand All @@ -44,12 +44,11 @@ bool Mounts::loadFromXml() {
mountNode.attribute("type").as_string()
));
}
mounts.shrink_to_fit();
return true;
}

std::shared_ptr<Mount> Mounts::getMountByID(uint8_t id) {
auto it = std::find_if(mounts.begin(), mounts.end(), [id](const std::shared_ptr<Mount> mount) {
auto it = std::find_if(mounts.begin(), mounts.end(), [id](const std::shared_ptr<Mount> &mount) {
return mount->id == id; // Note the use of -> operator to access the members of the Mount object
});

Expand All @@ -58,15 +57,15 @@ std::shared_ptr<Mount> Mounts::getMountByID(uint8_t id) {

std::shared_ptr<Mount> Mounts::getMountByName(const std::string &name) {
auto mountName = name.c_str();
auto it = std::find_if(mounts.begin(), mounts.end(), [mountName](const std::shared_ptr<Mount> mount) {
auto it = std::find_if(mounts.begin(), mounts.end(), [mountName](const std::shared_ptr<Mount> &mount) {
return strcasecmp(mountName, mount->name.c_str()) == 0;
});

return it != mounts.end() ? *it : nullptr;
}

std::shared_ptr<Mount> Mounts::getMountByClientID(uint16_t clientId) {
auto it = std::find_if(mounts.begin(), mounts.end(), [clientId](const std::shared_ptr<Mount> mount) {
auto it = std::find_if(mounts.begin(), mounts.end(), [clientId](const std::shared_ptr<Mount> &mount) {
return mount->clientId == clientId; // Note the use of -> operator to access the members of the Mount object
});

Expand Down
8 changes: 4 additions & 4 deletions src/creatures/appearance/mounts/mounts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

struct Mount {
Mount(uint8_t initId, uint16_t initClientId, std::string initName, int32_t initSpeed, bool initPremium, std::string initType) :
name(initName), speed(initSpeed), clientId(initClientId), id(initId), premium(initPremium),
type(initType) { }
name(std::move(initName)), speed(initSpeed), clientId(initClientId), id(initId), premium(initPremium),
type(std::move(initType)) { }

std::string name;
int32_t speed;
Expand All @@ -30,10 +30,10 @@ class Mounts {
std::shared_ptr<Mount> getMountByName(const std::string &name);
std::shared_ptr<Mount> getMountByClientID(uint16_t clientId);

[[nodiscard]] const std::vector<std::shared_ptr<Mount>> &getMounts() const {
[[nodiscard]] const phmap::parallel_flat_hash_set<std::shared_ptr<Mount>> &getMounts() const {
return mounts;
}

private:
std::vector<std::shared_ptr<Mount>> mounts;
phmap::parallel_flat_hash_set<std::shared_ptr<Mount>> mounts;
};
31 changes: 15 additions & 16 deletions src/creatures/appearance/outfit/outfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#include "utils/tools.hpp"
#include "game/game.hpp"

bool Outfits::reload() {
for (auto &outfitsVector : outfits) {
outfitsVector.clear();
}
return loadFromXml();
}

bool Outfits::loadFromXml() {
pugi::xml_document doc;
auto folder = g_configManager().getString(CORE_DIRECTORY, __FUNCTION__) + "/XML/outfits.xml";
Expand Down Expand Up @@ -68,10 +75,12 @@ bool Outfits::loadFromXml() {
}

std::shared_ptr<Outfit> Outfits::getOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const {
for (const auto &outfit : outfits[sex]) {
if (outfit->lookType == lookType) {
return outfit;
}
auto it = std::ranges::find_if(outfits[sex], [&lookType](const auto &outfit) {
return outfit->lookType == lookType;
});

if (it != outfits[sex].end()) {
return *it;
}
return nullptr;
}
Expand All @@ -83,17 +92,7 @@ std::shared_ptr<Outfit> Outfits::getOutfitByLookType(PlayerSex_t sex, uint16_t l
* @return <b>const</b> pointer to the outfit or <b>nullptr</b> if it could not be found.
*/

std::shared_ptr<Outfit> Outfits::getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType) {
std::shared_ptr<Outfit> Outfits::getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const {
PlayerSex_t searchSex = (sex == PLAYERSEX_MALE) ? PLAYERSEX_FEMALE : PLAYERSEX_MALE;

for (uint16_t i = 0; i < outfits[sex].size(); i++) {
if (outfits[sex].at(i)->lookType == lookType) {
if (outfits[searchSex].size() > i) {
return outfits[searchSex].at(i);
} else { // looktype found but the oposite sex array doesn't have this index.
return nullptr;
}
}
}
return nullptr;
return getOutfitByLookType(searchSex, lookType);
}
13 changes: 11 additions & 2 deletions src/creatures/appearance/outfit/outfit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
#include "declarations.hpp"
#include "lib/di/container.hpp"

struct OutfitEntry {
constexpr OutfitEntry(uint16_t initLookType, uint8_t initAddons) :
lookType(initLookType), addons(initAddons) { }

uint16_t lookType;
uint8_t addons;
};

struct Outfit {
Outfit(std::string initName, uint16_t initLookType, bool initPremium, bool initUnlocked, std::string initFrom) :
name(initName), lookType(initLookType), premium(initPremium), unlocked(initUnlocked), from(initFrom) { }
name(std::move(initName)), lookType(initLookType), premium(initPremium), unlocked(initUnlocked), from(std::move(initFrom)) { }

std::string name;
uint16_t lookType;
Expand All @@ -38,9 +46,10 @@ class Outfits {
return inject<Outfits>();
}

std::shared_ptr<Outfit> getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType);
std::shared_ptr<Outfit> getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const;

bool loadFromXml();
bool reload();

[[nodiscard]] std::shared_ptr<Outfit> getOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const;
[[nodiscard]] const std::vector<std::shared_ptr<Outfit>> &getOutfits(PlayerSex_t sex) const {
Expand Down
24 changes: 12 additions & 12 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ bool Combat::isProtected(std::shared_ptr<Player> attacker, std::shared_ptr<Playe
return true;
}

if (!attacker->getVocation()->canCombat() || !target->getVocation()->canCombat() && (attacker->getVocationId() == VOCATION_NONE || target->getVocationId() == VOCATION_NONE)) {
if ((!attacker->getVocation()->canCombat() || !target->getVocation()->canCombat()) && (attacker->getVocationId() == VOCATION_NONE || target->getVocationId() == VOCATION_NONE)) {
return true;
}

Expand Down Expand Up @@ -707,7 +707,7 @@ bool Combat::checkFearConditionAffected(std::shared_ptr<Player> player) {
auto affectedCount = (party->getMemberCount() + 5) / 5;
g_logger().debug("[{}] Player is member of a party, {} members can be feared", __FUNCTION__, affectedCount);

for (const auto member : party->getMembers()) {
for (const auto &member : party->getMembers()) {
if (member->hasCondition(CONDITION_FEARED)) {
affectedCount -= 1;
}
Expand Down Expand Up @@ -759,7 +759,7 @@ void Combat::CombatConditionFunc(std::shared_ptr<Creature> caster, std::shared_p
}
}

if (caster == target || target && !target->isImmune(condition->getType())) {
if (caster == target || (target && !target->isImmune(condition->getType()))) {
auto conditionCopy = condition->clone();
if (caster) {
conditionCopy->setParam(CONDITION_PARAM_OWNER, caster->getID());
Expand Down Expand Up @@ -1030,10 +1030,10 @@ bool Combat::doCombatChain(std::shared_ptr<Creature> caster, std::shared_ptr<Cre
uint8_t chainDistance;
bool backtracking = false;
params.chainCallback->getChainValues(caster, maxTargets, chainDistance, backtracking);
auto targets = pickChainTargets(caster, params, chainDistance, maxTargets, backtracking, aggressive, target);
auto targets = pickChainTargets(caster, params, chainDistance, maxTargets, aggressive, backtracking, std::move(target));

g_logger().debug("[{}] Chain targets: {}", __FUNCTION__, targets.size());
if (targets.empty() || targets.size() == 1 && targets.begin()->second.empty()) {
if (targets.empty() || (targets.size() == 1 && targets.begin()->second.empty())) {
return false;
}

Expand Down Expand Up @@ -1122,7 +1122,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
uint32_t maxY = 0;

// calculate the max viewable range
for (std::shared_ptr<Tile> tile : tileList) {
for (const std::shared_ptr<Tile> &tile : tileList) {
const Position &tilePos = tile->getPosition();

uint32_t diff = Position::getDistanceX(tilePos, pos);
Expand All @@ -1140,7 +1140,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
const int32_t rangeY = maxY + MAP_MAX_VIEW_PORT_Y;

int affected = 0;
for (std::shared_ptr<Tile> tile : tileList) {
for (const std::shared_ptr<Tile> &tile : tileList) {
if (canDoCombat(caster, tile, params.aggressive) != RETURNVALUE_NOERROR) {
continue;
}
Expand Down Expand Up @@ -1195,7 +1195,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
uint8_t beamAffectedCurrent = 0;

tmpDamage.affected = affected;
for (std::shared_ptr<Tile> tile : tileList) {
for (const std::shared_ptr<Tile> &tile : tileList) {
if (canDoCombat(caster, tile, params.aggressive) != RETURNVALUE_NOERROR) {
continue;
}
Expand Down Expand Up @@ -1241,7 +1241,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
}

void Combat::doCombatHealth(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, CombatDamage &damage, const CombatParams &params) {
doCombatHealth(caster, target, caster ? caster->getPosition() : Position(), damage, params);
doCombatHealth(caster, std::move(target), caster ? caster->getPosition() : Position(), damage, params);
}

void Combat::doCombatHealth(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const Position &origin, CombatDamage &damage, const CombatParams &params) {
Expand Down Expand Up @@ -1382,7 +1382,7 @@ void Combat::doCombatDispel(std::shared_ptr<Creature> caster, std::shared_ptr<Cr
}
}

void Combat::doCombatDefault(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const CombatParams &params) {
[[maybe_unused]] void Combat::doCombatDefault(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const CombatParams &params) {
doCombatDefault(caster, target, caster ? caster->getPosition() : Position(), params);
}

Expand Down Expand Up @@ -2076,7 +2076,7 @@ void AreaCombat::setupExtArea(const std::list<uint32_t> &list, uint32_t rows) {

void MagicField::onStepInField(const std::shared_ptr<Creature> &creature) {
// remove magic walls/wild growth
if (!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE || id == ITEM_WILDGROWTH_SAFE) {
if ((!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE) || id == ITEM_WILDGROWTH_SAFE) {
if (!creature->isInGhostMode()) {
g_game().internalRemoveItem(static_self_cast<Item>(), 1);
}
Expand All @@ -2091,7 +2091,7 @@ void MagicField::onStepInField(const std::shared_ptr<Creature> &creature) {
if (ownerId) {
bool harmfulField = true;
auto itemTile = getTile();
if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE)) {
if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || (itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE))) {
auto ownerPlayer = g_game().getPlayerByGUID(ownerId);
if (ownerPlayer) {
harmfulField = false;
Expand Down
Loading

0 comments on commit ad92e23

Please sign in to comment.