fix(config): let rateLoot accept decimal values - #877
Open
msholl wants to merge 1 commit into
Open
Conversation
rateLoot was loaded with loadIntConfig, which static_casts to int32_t and silently drops the fractional part: "rateLoot = 2.5" became 2, with nothing in config.lua suggesting the field is integer-only. Switching to loadFloatConfig requires fixing every reader, because getNumber() on a value stored as float takes the wrong type branch, returns 0 and logs a warning (configmanager.cpp). Besides the single C++ use in monster.cpp, those are the four Lua readers and protocolstatus.cpp -- the last one is easy to miss and made the status protocol announce loot="0" while looting itself worked. Verified in a live server: loot="2.5" is now reported correctly by the status protocol and fractional rates apply to drops.
Collaborator
|
Please remove the unnecessary comment in configmanager.cpp, and thank you for the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rateLootis loaded withloadIntConfig, which doesstatic_cast<int32_t>and silently drops the fractional part —rateLoot = 2.5becomes2, with no warning and nothing inconfig.luasuggesting the field is integer-only.Switching it to
loadFloatConfigforces every reader to be updated, becausegetNumber()on a value stored as a float takes the wrong type branch: it returns0and logs a warning (configmanager.cpp:529-533). The readers are:src/creatures/monsters/monster.cpp> 0gate that decides whether loot is generated at allsrc/server/network/protocol/protocolstatus.cpploot="0"while looting itself worked finedata/libs/functions/functions.luagetLootRandom(), the actual multiplierdata/libs/functions/monster.lua,monstertype.lua<= 0gate on the Lua sidedata/scripts/talkactions/player/server_info.lua!serverinfoshows the playerprotocolstatus.cppusesfmt::format("{:g}", ...)so the value comes out as2.5rather than2.500000.Testing
Running on a live server (Crystal 15.25). With
rateLoot = 2.5the status protocol reportsloot="2.5"and fractional rates apply to drops; withrateLoot = 3behaviour is unchanged from before. The warning in the log was what exposed the missedprotocolstatus.cppreader in the first place.Note for LuaJIT (5.1 semantics, as used here): a non-integer float passed where an integer is expected truncates. On Lua 5.3+
lua_tointegerwould return 0 instead — another reason the readers must match the stored type.