NB: this is a
theoretical request: I don't need it for modding or playing, I'm just reporting this potentially interesting factoid.
The algorithm used for applying the effect percentage (0x12 and 0x13 in effect structure in itm/spl files) is completely out of whack, and runs counter to what most modding guides state. I can identify three problems:
1) percentages are both inclusive (effect is applied if prob2 <= rand <= prob1, whereas modding guides suggest that this is prob2 <= rand < prob1).
2) the random number aren't calculated once (when it starts applying the effect block), but every time the engine feels like it wants to recalculate (it never recalculates chances if old_prob1 == new_prob1 && old_prob2 == new_prob2, or if new_prob2 <= old_rand <= new_prob1)
3) probably related to the algorithm in 2, effects are applied more often than what the percentages state.
Test cases:
COPY_EXISTING ~amul04.itm~ ~override~
FOR (i = 0; i < 101; ++i) BEGIN
FOR (j = 0; j < 3; ++j) BEGIN
LPF ADD_ITEM_EQEFFECT
INT_VAR
opcode = 139 // display string
target = 1
timing = 2
parameter1 = RESOLVE_STR_REF ( ~Result %i%, run %j%~ )
probability1 = i + 1
probability2 = i
END
END
END
COPY_EXISTING ~amul05.itm~ ~override~
FOR (j = 0; j < 3; ++j) BEGIN
FOR (i = 0; i < 101; ++i) BEGIN
LPF ADD_ITEM_EQEFFECT
INT_VAR
opcode = 139
target = 1
timing = 2
parameter1 = RESOLVE_STR_REF ( ~Result %i%, run %j%~ )
probability1 = i + 1
probability2 = i
END
END
END
Tests are run by cheating in and equipping amul04 or amul05. In a ideal world, both cases should both print exactly three strings: "Result X, run 1" to "Result X, run 3".
With amul04 (which groups effects with the same probability), run 1 through 3 are always printed together (because it doesn't reroll if two effects with same probabilities are adjacent), but it prints lines for both X and X + 1 (because the check is inclusive at both ends, and doesn't reroll if the current random number results in the effect being applied); moreover, sometimes more than the six messages are printed (prob X and X+1, run 1, 2 and 3), because of favorable reroll results (I haven't observed a single instance of nothing being printed for a batch).
With amul05, the X/X+1 pairing is still observed, but having result X at run 1 doesn't guarantee that result X turns up at run 2 (because the random number has been rerolled in the meantime). Also in this case, at least one (X, X+1) pair is always printed for all three runs (at least during my experimentation).