Pass/Fail Roll
Jump to navigation
Jump to search
# ROUTINE: PASS/FAIL ROLL DUPLICATED PAGE Check_if_Random_is_greater/equal_to_Chance # # Makes a (pseudo)random roll between 0 to max-1, inclusive, and checks against threshold. # Often used for percentage rolls with max = 100 and threshold = (percentage chance). # # Parameters: # r4 = (max) Maximum (non-inclusive) value for roll # r5 = (threshold) Threshold value to check against # Returns: # r2 = 1, if resulting roll >= threshold # 0, otherwise (resulting roll < threshold) 8005e0cc: 27bdffe0 addiu r29,r29,-0x0010 8005e0d0: afb00010 sw r16,0x0010(r29) 8005e0d4: 00808021 addu r16,r4,r0 # max 8005e0d8: afb10014 sw r17,0x0014(r29) 8005e0dc: afbf0018 sw r31,0x0018(r29) 8005e0e0: 0c0088c3 jal 0x0002230c # randResult = rand(); 8005e0e4: 00a08821 addu r17,r5,r0 # threshold 8005e0e8: 00500018 mult r2,r16 # randResult * max 8005e0ec: 00001012 mflo r2 8005e0f0: 04410002 bgez r2,0x 0005e0fc # if (randResult < 0) { 8005e0f4: 00000000 nop # (Affects the way negative numbers round on division) 8005e0f8: 24427fff addiu r2,r2,0x7fff # randResult = randResult + 0x7fff # } 8005e0fc: 000213c3 sra r2,r2,0x0f # roll = randResult / 0x8000 8005e100: 0051102a slt r2,r2,r17 8005e104: 38420001 xori r2,r2,0x0001 # return (roll < threshold) ? 0 : 1; 8005e108: 8fbf0018 lw r31,0x0018(r29) 8005e10c: 8fb10014 lw r17,0x0014(r29) 8005e110: 8fb00010 lw r16,0x0010(r29) 8005e114: 27bd0020 addiu r29,r29,0x0020 8005e118: 03e00008 jr r31 8005e11c: 00000000 nop
Return Locations
0005cfe0: Calculate Learned Abilities Battle.bin 00176c80: 00180270: 001807e8: Generate Crystal or Treasure 001843c0: 00184900: Attack Evaded Calculations 001869cc: 0018758c: 001876b0: Conditional_Status_Proc_Roll_(19%)_Inner_Routine 00187990: Katana Break Chance 001880f0: Apply status (to action) 0018c6f4: 0018d3a4: Chance to React 0018e850: