TurningWheel / Barony

Barony Open Source Release
http://www.baronygame.com/
Other
501 stars 130 forks source link

[Bug] Light Level Calculated incorrectly for low Stealth and negative perception #793

Open philipandresen opened 1 year ago

philipandresen commented 1 year ago

https://github.com/TurningWheel/Barony/blob/33b568c8dff4baf3f178bd9afe6c790082c9ba05/src/entity.cpp#L895-L899

Evaluate this expression with minimum light (48) touch range (32) and stealth skill of zero. No observer or observer perception is zero

if ( sneaking ){ 48 /= 2; } // == 24
24 -= (24 - 32) * (1.0 * (0 / 100.0)); // 24 - (-8 * 0) = 24
// Visibility is 24

Evaluate with minimum light (48) touch range (32) and stealth skill of 100. No observer or observer perception is zero

if ( sneaking ){ 48 /= 2; } // == 24
24 -= (24 - 32) * (1.0 * (100 / 100.0)); // 24 - (-8 * 1) = 24 + 8 = 32
// Visibility is 32

This also makes enemies with negative perception scores give odd values - with higher stealth giving you worse ability to hide.

That's the bug report!

I submitted a fix here along with a refactor. I have a feeling this bug exists because this code is particularly confusing, so a refactor seemed appropriate. https://github.com/TurningWheel/Barony/pull/805