[Guide/Formula] Critical hit rate, cont. attack chance, wars

If you are stuck in the Dunan Unification Wars; or wish for more details on the gameplay systems, this is the place.
psychedelist
Posts: 20
Joined: Sat Oct 27, 2018 1:45 pm

Re: [Guide/Formula] Critical hit rate, cont. attack chance, wars

Postby psychedelist » Mon Aug 19, 2019 10:22 am

Very useful info, Omnigamer and Z3R01337, thanks for that. I kept noticing that the characters "on the right side and back row" are much more likely to be targeted, as well as that a character can be targeted only once per turn (unless the attack misses or there are no other available targets). Except for Neclord's bat attack maybe, that one has a really weird pattern.

About attack probabilities, each enemy data entry can have up to 4 attack data sub-entries, i already felt that some of the first bytes in each entry might affect the probabilities, and you just prompted me to verify that the second attack-related byte is indeed the probability that affects the actual chance, the posted Luca values match the data. But still those values are like "recommendations" for the enemy-specific AI routines that may or may not use them. For example TargetLady starts using explosion anyway as long as some of the other enemies are defeated. Rowd, Nightmare and Culgan can use healing spells but pretty sure they (or other enemies) need to be considerably damaged for them to even consider using it.
First off, critical only applies to physical attacks.
Would you happen to know if having more than one crit character in a single unit helps the probability?

About the escape probability, i just loaded up the original game version (was using Pyriel's patch before). If you hack your current party characters to have 1 luck, get into a battle and press Run on the 1st turn, here are some breakpoint addresses of interest (1st turn of a battle only):
8002DAE0 This Lhu loads a character's Luck for the first time, then loops through other characters to find the max value, then turns it into a value in 5-30 range, which stands for the chance to fail escaping (if everyone's Luck is 1, the value will be 30)
8002DBA8 This Slt compares the calculated chance against a normalized rng value, then Xori reverses the result and the function will return v0 value as "IsRunSuccess". If you modify v0 at this point, you can see it indeed affects the outcome of Run. Now you can also give 200 or more Luck to at least one character, re-enter a battle (Luck isn't recalculated upon pressing Run), and the calculated chance to fail will be 5 instead of 30. I'm pretty new to the game and its modding community so i'm not sure why it's became the general consensus that this part of code isn't actually used, especially since Pyriel did find this part of code and has a disassembly of it. I'm pretty sure it does work, it's just hard to notice the difference on practice, especially in normal gameplay (Hero's Luck growth is very strong). Hope someone else can confirm it after debugging it. Omnigamer, you say this code isn't executed, but were you trying it on the first turn of a battle? It's still there for 2nd+ turns, just the address would be different, but that might have helped the impression that it isn't executed. Also, if you have have Stallion (or anyone with a hacked True Holly Rune) in the party, it won't execute indeed as that rune always turns Run into instant success.

I recently updated my reference document with some evade and counter conditions and formulas, if anyone has any comments, additions or corrections, it'll be very appreciated.

Omnigamer
Posts: 323
Joined: Wed Feb 13, 2013 11:48 am

Re: [Guide/Formula] Critical hit rate, cont. attack chance, wars

Postby Omnigamer » Mon Aug 19, 2019 5:31 pm

Neclord's bat attack has a targeting preference/requirement. It will always/only target members that are Female, and prioritize members that are Youth. I don't believe it follows the same rules for normal Single Target attacks in that it can target the same character twice in one round. The Youth part is conjecture, but it checks out based on available data, ie he will always target Eilie in a party of both Eilie and Rina.

For Criticals, every unit with a Critical skill gets an independent chance for it to trigger. So if you have 3 members of a unit with Critical skill, all of them have the potential to trigger for 4 total damage. But each one is checked independently, so you can drastically increase your chances of a crit with more than one member having Critical.

What I was referring to with code not being executed was actually escape code that tries to check party level relative to enemy party level. It had branches for different multiples of the of the the enemy's party level, but I believe each branch pointed to the same code, effectively doing nothing different. It's been a couple years since I looked at it though.

The escape testing I've done is via a special script that can brute force test conditions while manually altering the RNG. A lot of that testing was also done a long time ago, but I believe at least some of it was performed during the first walk through North Sparrow Pass, when all levels would have been very low. Even in that scenario, you would successfully run away 90% of the time after several thousand trials. I will test again to be sure, and your addresses do provide good reference points.

Z3R01337
Posts: 15
Joined: Sat Feb 06, 2016 6:06 am

Re: [Guide/Formula] Critical hit rate, cont. attack chance, wars

Postby Z3R01337 » Mon Aug 19, 2019 6:12 pm

I'm gonna have a look into the escape stuff as well. Those addresses should provide a great starting point, thanks for those! Anecdotally speaking, I feel like it isn't just a flat 90% as the escape rate seems way worse in the early game.

If you have any info on the enemy structures in terms of probabilities, that would be great! I've been gathering my data via brute force scripts & it would save a lot of time if I could just check probabilities by examining the structure. I've personally been looking at the in-battle enemy structures to gather data. I've been trying to keep an eye out for probabilities there but haven't had any luck. For reference, each structure is 0x7c in length and the first one is generally at 0x145ba4 or 0x195ba4. It starts with your characters and then moves onto enemies. Some interesting addresses I found there as well that are worth sharing:

Code: Select all

Offsets from start of structure:
0x42: Number of attacks enemy had taken
0x43: Number of attacks enemy can/must take.
0x54: Current enemy attack index. This matches up psychedelist's attack data sheet.

0x42 is only used until the game calculates the turn, afterwards it's reset to 0. Usually lasts a frame or 2. 0x54 will be the last attack used at the end of the turn. If tracking writes you can see it change as the game is calculating the enemy attack.

As for special cases like healing, I haven't looked into those considerably. I did run tests for Culgan though, here are his probabilities. I did seperate tests where in one I didn't damage either Seed or Culgan and in the other I used one Blazing Camp. Also worth noting that in most of these tests I artificially limited the test target to one attack per turn & the other enemies in the group to 0 attacks per turn. This was done by editing the byte at 0x43.

No Damage: Attack 70%, Lightning 30%.
Damage: Attack 50% Kindness Rain 30% Lightning 20%.

I don't know how these match up to the probabilities in the enemy data but it might give us some insight on that as well.

psychedelist
Posts: 20
Joined: Sat Oct 27, 2018 1:45 pm

Re: [Guide/Formula] Critical hit rate, cont. attack chance, wars

Postby psychedelist » Mon Aug 19, 2019 8:21 pm

That's what i meant with the Neclord's attack being weird, he didn't care for anyone else until Nanami was down in my game too. It also seemed like he likes to use that attack almost exclusively for the first few turns, then switch to magic-only for several turns. Could been just the rng though. Thanks for the crit answer as well, sounds like a good idea to have a double critical unit.

I only know character and enemy levels matter for the Let Go condition, wasn't aware it mattered (or was meant to matter) for Run anyhow. I loaded Sparrow Pass Save from here, the calculated failure chance is 30 as expected. But i wouldn't be surprised if the rng function is just that much biased even over the long periods. I had to enter a battle like 10 times before getting an rng value under 30 now. Could it be that the function is less likely to return small values? It seems to load some seed value, multiply it by some magic number, get the lower 32-bit result, add another magic number, save the result so that it becomes the seed value for the next rng call, finally right-shift by 16 bits and ensure that the final value isn't higher than 7fff. I don't know where the original seed value comes from and how those "magical numbers" were chosen, does anyone have a mathematical or intuitive explanation of why such a calculation would be at least remotely fair for all possible values in the intended 0-7fff range?
If you have any info on the enemy structures in terms of probabilities, that would be great!
Sure, actually i made and have been using an app to edit monster and character stats, thought i'd mention it later when the time comes, but if anyone thinks it really could be of use, then give me a hint. It's far from perfect and not entirely user friendly though, but it gets the job done for my project. For now, here's how my current enemy source data mapping goes,

Code: Select all

The whole enemy entry is no less than 159 bytes (haven't identified the data past 159th byte)
// General stats
[16 bytes] enemy's name (in custom encoding), the one used during the battle
[2 bytes] Counter Str (listed as plain Str in the bestiary)
[2] Mag
[2] Prot
[2] Mdef
[2] Tech
[2] Speed
[2] Luck
[2] HP
[1] Enemy level
[3] unknown, probably always 0 and unused
// 1st Attack entry (24 bytes)
[1] always 1 or 2, not tested yet but suspecting it might be for Silent Lake check
[1] attack probability (in percent, 0-100)
[2] unknown, usually 0 but not always, never seen higher than 9
[2] Attack's Str
[2] Attack's Hit (like Tech but for calculating the chance that the character will dodge this attack)
[1] Inflicted Status ID
[1] Status Probability
[1] Attack type data. Lower 4 bits are for attack's Element (1 is Fire, 2 is Water, then Wind, Earth, Lightning, Resurrection, Darkness, Bright Shield).
If higher 4 bits are "1" then the attack is Physical (Character's Def and enemy's AttackStr (Counter Str is [i]not[/i] added) are used), if it's "2" then the attack is Magical (Character's Mdef and enemy's Mag+AttackStr are used). I don't know how and if other higher bits are used here. An example: 10001 = 11 (hex) = Physical Fire; 100010 = 22 = Magical Water
[1] unused
[2] Target data. A lot of stuff goes here, each bit may mean something, i haven't mapped them all, but they're mainly for defining the target type (single target in any row, or only front row, or all party, column, etc), there's also a bit for whether the attack can be countered or not.
[10] Either empty or some RAM addresses, maybe for AI routines used by the attack
// 3 more Attack entries like the above
...
// Resistances and loot
[1] Unknown resistance but often used by bosses (it's just now that i noticed this byte, will test it later, hopefully it's for Unbalanced)
[1] Fire resistance (0 normal, 1 weak, 2 strong, 3 invulnerable)
[1] Water
[1] Wind
[1] Earth
[1] Lightning
[1] Resurrection
[1] Darkness
[1] Bright Shield
[1] Silence
[1] Physical (listed as Knockdown in the bestiary, not used by anyone except Neclord)
[1] Sleep
[1] Poison
[1] Instant Death
[2] unknown
[2] Potch (divided by 10 for bosses)
[2] Item1 (Id and Modifier)
[2] Item2
[2] Item3
[1] Item1 drop chance
[1] Item2 drop chance
[1] Item3 drop chance
To find these entries, i just search the rom or RAM for the enemy names, the custom encoding can be found in this file by Pyriel posted in some other thread, i have a text encode/decode feature in my editor as well.
This matches up psychedelist's attack data sheet.
If you mean attack properties data, sorry i wasn't making sure they're exactly in the same order as in the raw data. There could be some other inaccuracies, like Flyers have two attacks, one for back row and other for front row, yet i considered it to be equivalent to a single "any single target" attack for simplicity. Not sure if it was the right approach. By the way i'm watching your s2 speedruns these days, great stuff.

Omnigamer
Posts: 323
Joined: Wed Feb 13, 2013 11:48 am

Re: [Guide/Formula] Critical hit rate, cont. attack chance, wars

Postby Omnigamer » Mon Aug 19, 2019 10:33 pm

I've managed to dig into the escape rate a bit better now. I was using a flawed check for battle state before - while I haven't found a "correct" address to check for battle state, I've instead been able to check the dialog text characters after starting to run away as my conditional. It only works for a small subset of battles, but I set up a good manipulable instance for party luck before the battle starts. It also must use some mirrors somewhere to store the max character LCK, since modifying both the slot-aligned LCK values and source character LCK values don't affect it mid-battle. The character's LCK needs to be manipulated prior to the battle start.

The relationship seems to be this:

Escape failure rate = max(30%-max((LCK-100)/4,0),5%)

That is, for every 4 LCK your luckiest character has over 100, you gain an extra 1% escape chance. If you have 100 or less, then you see no benefit at all. After 200, you are at the max of 95%. Note that each 4 threshold is important - 100 through 103 would still give the same 30% rate. 104 through 107 would give 29%, and so on.

Sorry I dismissed your formula initially based on my own flawed tests! I appreciate the corrections and further information in tracking it all down.

makotech222
Posts: 5
Joined: Sat Mar 05, 2016 1:30 pm

Re: [Guide/Formula] Critical hit rate, cont. attack chance, wars

Postby makotech222 » Fri Oct 04, 2019 10:34 pm

Does anyone have the .iso memory addresses that contain every character's war stats (Atk, Def, Skills)? I would like to edit those if they were available.


Return to “Suikoden II”

Who is online

Users browsing this forum: No registered users and 4 guests