expand comment on expand_rate

This commit is contained in:
Martin Michelsen
2023-12-10 09:16:59 -08:00
parent afd63ca1dd
commit b53bde9046
+9 -6
View File
@@ -31,12 +31,15 @@ string RareItemSet::ExpandedDrop::str(Version version, shared_ptr<const ItemName
} }
uint32_t RareItemSet::expand_rate(uint8_t pc) { uint32_t RareItemSet::expand_rate(uint8_t pc) {
// pc = bits SSSSS VVV // To compute the actual drop rare drop rate from pc, first decode pc into
// S = shift + 4 (so actual shift is 0-27) // shift and value:
// V = value - 7 (so actual value is 7-14) // pc = bits SSSSSVVV
// take the bits 00000000 00000000 00000000 00000010 // shift = S - 4 (so shift is 0-27)
// shift left by shift (0-27) // value = V + 7 (so value is 7-14)
// multiply by value // Then, take the value 0x00000002, shift it left by shift (0-27), and
// multiply the result by value (7-14) to get the actual drop rate. The result
// is a probability out of 0xFFFFFFFF (so 0x40000000 means the item will drop
// 25% of the time, for example).
int8_t shift = ((pc >> 3) & 0x1F) - 4; int8_t shift = ((pc >> 3) & 0x1F) - 4;
if (shift < 0) { if (shift < 0) {
shift = 0; shift = 0;