From 734cb987c184e79ccbea00a31dc51feb6a1cacd1 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Alves Cruz Date: Sun, 19 Jan 2025 17:12:21 -0300 Subject: [PATCH] fix: monster spawntime load and save --- source/iomap_otbm.cpp | 11 ++--------- source/monster.h | 6 +++--- source/monster_brush.cpp | 2 +- source/spawn_monster_brush.cpp | 4 ++-- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/source/iomap_otbm.cpp b/source/iomap_otbm.cpp index 57ecc5eb..825811bb 100644 --- a/source/iomap_otbm.cpp +++ b/source/iomap_otbm.cpp @@ -1035,7 +1035,7 @@ bool IOMapOTBM::loadSpawnsMonster(Map &map, pugi::xml_document &doc) { break; } - int32_t spawntime = monsterNode.attribute("spawntime").as_int(); + uint16_t spawntime = monsterNode.attribute("spawntime").as_uint(0); if (spawntime == 0) { spawntime = g_settings.getInteger(Config::DEFAULT_SPAWN_MONSTER_TIME); } @@ -1773,14 +1773,7 @@ bool IOMapOTBM::saveSpawns(Map &map, pugi::xml_document &doc) { monsterNode.append_attribute("x") = x; monsterNode.append_attribute("y") = y; monsterNode.append_attribute("z") = spawnPosition.z; - auto monsterSpawnTime = monster->getSpawnMonsterTime(); - uint16_t maxUint16 = std::numeric_limits::max(); - uint16_t minUint16 = std::numeric_limits::min(); - if (std::cmp_greater(monsterSpawnTime, maxUint16) || std::cmp_greater(monsterSpawnTime, minUint16)) { - monsterSpawnTime = 60; - } - - monsterNode.append_attribute("spawntime") = monsterSpawnTime; + monsterNode.append_attribute("spawntime") = monster->getSpawnMonsterTime(); if (monster->getDirection() != NORTH) { monsterNode.append_attribute("direction") = monster->getDirection(); } diff --git a/source/monster.h b/source/monster.h index 4325d2a6..d6db8eff 100644 --- a/source/monster.h +++ b/source/monster.h @@ -65,10 +65,10 @@ class Monster { weight = newWeight; } - int getSpawnMonsterTime() const noexcept { + uint16_t getSpawnMonsterTime() const noexcept { return spawntime; } - void setSpawnMonsterTime(int time) noexcept { + void setSpawnMonsterTime(uint16_t time) noexcept { spawntime = time; } @@ -87,7 +87,7 @@ class Monster { std::string type_name; Direction direction; uint8_t weight; - int spawntime; + uint16_t spawntime; bool saved; bool selected; }; diff --git a/source/monster_brush.cpp b/source/monster_brush.cpp index 66b7650d..00a0688c 100644 --- a/source/monster_brush.cpp +++ b/source/monster_brush.cpp @@ -82,7 +82,7 @@ void MonsterBrush::drawMonster(BaseMap* map, Tile* tile, void* parameter) { }); if (it == tile->monsters.end()) { const auto monster = newd Monster(monster_type); - monster->setSpawnMonsterTime(*(int*)parameter); + monster->setSpawnMonsterTime(*(uint16_t*)parameter); tile->monsters.emplace_back(monster); } } diff --git a/source/spawn_monster_brush.cpp b/source/spawn_monster_brush.cpp index 8be4499b..7dd87c8f 100644 --- a/source/spawn_monster_brush.cpp +++ b/source/spawn_monster_brush.cpp @@ -67,7 +67,7 @@ void SpawnMonsterBrush::draw(BaseMap* map, Tile* tile, void* parameter) { auto size = std::max(1, *(int*)parameter); auto side = size * 2 + 1; - int time = g_settings.getInteger(Config::DEFAULT_SPAWN_MONSTER_TIME); + uint16_t spawnTime = g_settings.getInteger(Config::DEFAULT_SPAWN_MONSTER_TIME); int density = g_settings.getInteger(Config::SPAWN_MONSTER_DENSITY); if (tile && tile->spawnMonster == nullptr) { tile->spawnMonster = newd SpawnMonster(size); @@ -99,7 +99,7 @@ void SpawnMonsterBrush::draw(BaseMap* map, Tile* tile, void* parameter) { if (tileSpawn) { auto monsterBrush = monsters[rand() % monsters.size()]; - monsterBrush->drawMonster(map, tileSpawn, &time); + monsterBrush->drawMonster(map, tileSpawn, &spawnTime); } } }