News:

Don't forget to visit the main site! There's lots of helpful docs, patches, and more!

Main Menu

[SM] 'Rate for Collecting Items' Percentage

Started by Quietus, April 12, 2010, 01:38:08 PM

Previous topic - Next topic

Quietus

I know this has been covered before, at least to some degree.  I even went as far as recording it in my SMILE document for future reference:

[spoiler]Quote from: Acheron86 on 15 July 2009, 01:08:59
any documentation on the workings of item % count?
Quote from: Kejardon
E70D,X: Offsets to measure
E717,X: Divisors for those offsets (E70D,X / E717,X = +% for total)
X ranges from 0 to 8, 5 total

E721,X: Bits to test 09A4 for
X ranges from 0 to 14, B total

E737,X: Bits to test 09A8 for
X ranges from 0 to 8, 5 total


At $8B:E70D are five 2-byte pointers:
Code:

In this order:
$09C4   (Health capacity)
$09D4   (Reserve capacity)
$09C8   (Missiles capacity)
$09CC   (SuperMissiles capacity)
$09D0   (Power Bombs capacity)

They're used as the numerators

At $8B:E717 are five 16-bit values:
Code:

In this order:
$0064   (Energy per tank)
$0064   (Reserve per tank)
$0005   (Missiles per tank)
$0005   (Super missiles per tank)
$0005   (Power bombs per tank)

They're used as the denominators

That fraction works out how many tanks of each item you have. The game then adds them all together and stores it to $12

At $8B:E721 are 11 16-bit values
Code:

In this order:
$0001   (Varia suit)
$0020   (Gravity suit)
$0004   (Morph ball)
$1000   (Bombs)
$0002   (Spring ball)
$0008   (Screw attack)
$0100   (Hi jump)
$0200   (Space jump)
$2000   (Speed booster)
$4000   (Grappling beam)
$8000   (X-ray)

$09A4 (your collected items) is tested against all of these values, for each item you have, the game increments $12
Same with $09A8 (your collected beams) using the $8B:E737 table
[/spoiler]

But, if I'm honest - love him as we do - Kejardon's explanation still sails one or two atmospheric layers above my head.  (Even though my brain is screaming "He's spelling it out, fool!")

Could somebody possibly explain this in dimwit terms, so that us mere mortals can alter the percentage as well!  And for additional brownie / scout / whatever points, would it be additional work to implement the decimal place ala Redesign?  This isn't as important, but would be nice for one of my other projects.  I'm perfectly confident with editing hex values, but the what / where is what throws me.

Many thanks in advance, and might I be so bold as to suggest that a worthwhile (read: in depth) response might be worthy of adding to the Q/A section?

P.JBoy

Well, there's a load of RAM addresses and value around $8B:E62F:
At $8B:E70D, there are 5 RAM pointers: $09C4 $09D4 $09C8 $09CC $09D0
At $8B:E717, there are 5 16-bit values: $0064 $0064 $0005 $0005 $0005

It takes the value from each RAM address, and divides it by its respective 16-bit value, which gives you for example:
$09C4 is your max health, dividing it by 100 gives the number of energy tanks you have.
Those 5 values are then totalled up.

At $8B:E721, are values to 'test' against your collected items: $0001 $0020 $0004 $1000 $0002 $0008 $0100 $0200 $2000 $4000 $8000
At $8B:E737, are values to 'test' against your collected beams: $0001 $0002 $0004 $0008 $1000
To test these values, is to see if they are part of the value they're being tested to, that is, if you ANDed the value you're testing for to the variable, it would be non-zero.  E.g., if you had the items Screw Attack and Varia Suit, which would make your collected items $0009, then testing it for $0001 and $0008 would be true, whereas testing it for $0004 or $0002 would be false.
It totals the number of true tests, and adds it to the previous total.  That then gives you your percentage
...

Scyzer

I should probably mention that the way it works now, without a complete rewrite, the game can only calculate by check how MANY missiles/supers/pbs you have collected, not how many tanks you have collected. This makes calculating the percentage screwy if you have tanks of multiple values.
I'm gonna change the way it calculates later so it counts the number of tanks collected, but it would not be "any-hack-friendly" as it's need to know exactly how many items are in the game.

It would take a bit of ASM to put in a decimal point.

Quietus

Quote from: Sadiztyk Fish on April 16, 2010, 08:27:34 PMI'm gonna change the way it calculates later so it counts the number of tanks collected, but it would not be "any-hack-friendly" as it's need to know exactly how many items are in the game.

This'd be cool.  Like everything, there's no rush on my part, but once you get done with it, let me know, and I could - probably - give you the totals for my hack, and then commence begging for your help. :heheh:

JAM

Quote from: P.JBoy on April 12, 2010, 02:11:43 PM
At $8B:E721, are values to 'test' against your collected items: $0001 $0020 $0004 $1000 $0002 $0008 $0100 $0200 $2000 $4000 $8000
So, if I want to use extra item (that using value $0010), then array at $E721 should be expanded and item counter for $E721 (placed somewhere) should be incremented if I want to get correct percentage. Am I right?

P.JBoy

If you wanted to add an item that's checked for the percentage, you would need to add it to the array, as well as increasing a value in the ASM code from 0x14 to 0x16 (this value is the X value, i.e. the value in the X-index register).  The ASM routine will increment the item counter for you, just because it's in the array.  Also, the array that follows it, ($E737, the beams), will need to be moved, and the its pointer changed
...

Prime Hunter

I don't really follow what was said in the first post, but how easy it is to change the coding for missiles/supers/power bombs as far as calculating the final percentage goes? I've changed the final totals for all three, and for supers and power bombs the number per tank, but I have no idea what I'd need to change in the code itself for things to register properly. Is this something I can easily modify with just hex changes, or would it take ASM?

Quietus

In short, I was asking what to change to make the final percentage correct after changing the total number of pickups / items.

For exmaple, in the normal game you have exactly 100 items, which makes a percentage easy, as each item is 1%.  If you were to increase it to something easy, like twice as many, this would probably be an easy change too, as everything would just become 0.5% instead.  But if you've changed it to some (seemingly) random number, to suit your own hack, it's harder to work out.

Speaking of which:
Quote from: Sadiztyk Fish on April 16, 2010, 08:27:34 PMI'm gonna change the way it calculates later so it counts the number of tanks collected, but it would not be "any-hack-friendly" as it's need to know exactly how many items are in the game.

It would take a bit of ASM to put in a decimal point.
Did you have any luck with this?

Were you even looking at the second part, or just stating? :O_o:

Prime Hunter

No, my total item count is still 100, but the number of individual tanks for missiles, supers, and power bombs are different than normal. (And you get less supers and pbs per tank than normal too.) But I was testing part of my escape route what what I intend to be the lowest item % you can have to finish the game, and the number that came up in the end ended up being off by two from what I expected. My guess was because I had less than 5 supers and power bombs and the game simply didn't register that the totals I had would count as 1 expansion for each of them. Is that just because I went through SMILE's test mode and therefore didn't grab all of my items normally, or is the coding itself to blame?

personitis

No no, don't use SMILE's test room feature as that just sets you up with equipment you want to use without actually physically collecting the expansions.

To clarify:

Item: Total possible/Given per expansion
E-Tank: 1400/14 = 14%
R-Tank: 400/4 = 4%
Missiles: 230/5 = 46%
Supers: 50/5 = 10%
Powers: 50/5 = 10%
Items: 14/1 = 14% (all non-expansion power ups)

The value you're changing to alter is "given per expansion." So for example, this is my list from an older plan of Rebuild:

E-Tanks: 1400/14 = 14%
R-Tanks: 400/4 = 4%
Missiles: 300/8 = 37.5%
Supers: 100/5 = 20%
Powers: 30/3 = 10%
Items: 14/1 = 14%

You'll notice the total is actually 99.5% but Super Metroid rounds up so it makes 100%. ^-^

Again, just for clarification.

Prime Hunter

Yeah, so all it would take would be to modify the totals and # per expansion, since all of my expansions give the same number per tank across the board. That part is good to know.

I just have no idea where I'd look to make those changes in hex format, if that's possible. I'm assuming the data in the first post would point me right to them if I knew ASM, but I just tried to install xkas (which is what you'd need to work in ASM right?) and my computer wouldn't start it up at all unless I'm just being stupid about it.

personitis

The info in the first post does point you to the data. It's however, wrote in the form of SNES LoROM address where if you open it in the hex editor you're more looking for the PC address. You don't need any ASM at all. Just open your ROM in a hex editor and got to these offsets:

5E717 (E-Tanks)
5E719 (R-Tanks)
5E71B (Missiles)
5E71D (Supers)
5E71F (Powers)

You'll notice each is respectively 64, 64, 5, 5, and 5. If it's not obvious, those numbers are how much each expansion gives you in hex. Got a grasp on it yet?

Also yes, xkas is what's used to compile ASM.

Prime Hunter

That's exactly what I was looking for! Thanks for the assistance. (I haven't quite gotten the hang of comparing hex values with those that are from ASM, which is what my main problem was here.)

JAM

Quote from: person701 on June 25, 2010, 11:07:03 PM
Item: Total possible/Given per expansion
E-Tank: 1400/14 = 14%
Actually, 1499/100 = 14.99 => 14% (rounded down)
and if you change value at 5E717 to 32 (50) as well as Energy Tank value, but not change starting HP, you'll get:
799/50 = 15.98 => 15% with 14 collected Energy Tanks.

Just a small problem that can annoy...

P.JBoy

Well, not quite, when doing the divide, the quotient and the remainder is returned, and the routine takes the quotient
...

personitis

Quote from: JAM on June 30, 2010, 06:26:02 PM
Actually, 1499/100 = 14.99 => 14% (rounded down)
I though this takes the max amount you get from the expansions which would make 1400/100 = 14%... Then again, I don't know the ROM inside out like most.