Remove requirement of object probs adding to 1000
When discussing the recent commit that removed makedefs -o from the build process, nhmall pointed out that a sanity check ensuring all objects within one class add up to 1000 probability had been removed as well. This requirement was a perennial thorn in the side for anyone doing anything that touches object probabilities, because allocating probability to something meant deciding what to take it away from, without a good way to evenly distribute that across all the other members of the object class. I had gotten around this in xNetHack by removing the sanity check and making mkobj() total up the probability within an object class and then using that instead of 1000. This commit takes a similar approach, but instead of inefficiently recalculating the sum every time mkobj() is called, it instead computes it at the start of the game or when restoring the save file and stores it in a global variable. This fixes a slight bias problem with rings - they are all supposed to be of equal probability, but there are 28 of them and 1000 is not evenly divisible by that, so the old formula made the later rings slightly more likely. Now instead of a 35/1000 or 36/1000 chance, they are all uniformly 1/28. (Internally they have a oc_prob of 1 now, not 0). Gems are also weird, because their oc_prob values change every level. This ought to have still worked without a change, because the arcane formula for assigning the probabilities would still end up with them adding to 1000. But I added in code to reset the total gem probability anyway; this may help make the formula less arcane in the future. There is still a sanity check against object classes having a nonzero number of objects but zero total probability, in which case an impossible will be thrown and every member of the class will be given equal probability. I also downgraded the "probtype error" panic in mkobj() to an impossible because it has a reasonable failure case - return the first item in that class.
This commit is contained in:
committed by
Pasi Kallinen
parent
ecee4e8610
commit
0e05c94400
@@ -651,7 +651,7 @@ BOOTS("levitation boots", "snow boots",
|
||||
OBJECT(OBJ(name, stone), \
|
||||
BITS(0, 0, spec, 0, mgc, spec, 0, 0, 0, \
|
||||
HARDGEM(mohs), 0, P_NONE, metal), \
|
||||
power, RING_CLASS, 0, 0, 3, cost, 0, 0, 0, 0, 15, color,sn)
|
||||
power, RING_CLASS, 1, 0, 3, cost, 0, 0, 0, 0, 15, color,sn)
|
||||
RING("adornment", "wooden",
|
||||
ADORNED, 100, 1, 1, 2, WOOD, HI_WOOD, RIN_ADORNMENT),
|
||||
RING("gain strength", "granite",
|
||||
|
||||
Reference in New Issue
Block a user