Calculate Random Equipment

From Final Fantasy Hacktics Wiki
Revision as of 19:52, 23 March 2012 by Glain (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Calculate Random Equipment
0005cc98: 27bdff68 addiu r29,r29,0xff68
0005cc9c: 00806821 addu r13,r4,r0		r13 = Unit's Data Pointer
0005cca0: 30a500ff andi r5,r5,0x00ff		r5 = Item Type
0005cca4: 34020020 ori r2,r0,0x0020
0005cca8: afbf0094 sw r31,0x0094(r29)
0005ccac: 10a20014 beq r5,r2,0x 0005cd00		Branch if Item Type = Headgear
0005ccb0: afb00090 sw r16,0x0090(r29)
0005ccb4: 28a20021 slti r2,r5,0x0021
0005ccb8: 10400007 beq r2,r0,0x 0005ccd8		Branch if Item Type >= 0x21
0005ccbc: 34020008 ori r2,r0,0x0008
0005ccc0: 10a20014 beq r5,r2,0x 0005cd14		Branch if Item Type = Accessories
0005ccc4: 34020010 ori r2,r0,0x0010
0005ccc8: 10a20010 beq r5,r2,0x 0005cd0c		Branch if Item Type = Armor
0005cccc: 340200ac ori r2,r0,0x00ac		Item Counter = 0xac
0005ccd0: 08017348 j 0x 0005cd20
0005ccd4: 00001021 addu r2,r0,r0		Item Counter = 0
0005ccd8: 34020040 ori r2,r0,0x0040
0005ccdc: 10a20006 beq r5,r2,0x 0005ccf8		Branch if Item Type = Shields
0005cce0: 34020080 ori r2,r0,0x0080		Item Counter = 0x80 (also used for check)
0005cce4: 14a2000e bne r5,r2,0x 0005cd20		Branch if Item Type = Weapons
0005cce8: 00001021 addu r2,r0,r0		Item Counter = 0
0005ccec: 34020001 ori r2,r0,0x0001		Item Counter = 1
0005ccf0: 08017349 j 0x 0005cd24
0005ccf4: 340a0080 ori r10,r0,0x0080		Limit = 0x80 (Item Type = Weapons)
0005ccf8: 08017349 j 0x 0005cd24
0005ccfc: 340a0090 ori r10,r0,0x0090		Limit = 0x90 (Item Type = Shields)
0005cd00: 34020090 ori r2,r0,0x0090		Item Counter = 0x90
0005cd04: 08017349 j 0x 0005cd24
0005cd08: 340a00ac ori r10,r0,0x00ac		Limit = 0xac (Item Type = Armor)
0005cd0c: 08017349 j 0x 0005cd24
0005cd10: 340a00d0 ori r10,r0,0x00d0		Limit = 0xd0 (Item Type = Headgear)
0005cd14: 340200d0 ori r2,r0,0x00d0		Item Counter = 0xd0
0005cd18: 08017349 j 0x 0005cd24
0005cd1c: 340a00f0 ori r10,r0,0x00f0		Limit = 0xf0 (Item Type = Accessories)
0005cd20: 340a0100 ori r10,r0,0x0100		Limit = 0x100 (Item Type != Any above)
0005cd24: 00004821 addu r9,r0,r0		Temp Counter = 0
0005cd28: 00404021 addu r8,r2,r0		r8 = Item Counter
0005cd2c: 91ae0022 lbu r14,0x0022(r13)		Load Unit's Level
0005cd30: 010a102a slt r2,r8,r10
0005cd34: 1040003c beq r2,r0,0x 0005ce28		Branch if Item Counter = 0
0005cd38: 00006021 addu r12,r0,r0		High Level = 0
0005cd3c: 30e700ff andi r7,r7,0x00ff		r7 = Chosen Type
0005cd40: 00081040 sll r2,r8,0x01		Item Counter * 2
0005cd44: 00481021 addu r2,r2,r8		IC * 3
0005cd48: 00025880 sll r11,r2,0x02		Pointer Mod = IC * 12
0005cd4c: 3c028006 lui r2,0x8006
0005cd50: 24422eb8 addiu r2,r2,0x2eb8
0005cd54: 01622821 addu r5,r11,r2
0005cd58: 90a30003 lbu r3,0x0003(r5)		Load Item's Type Flags
0005cd5c: 00000000 nop
0005cd60: 30620002 andi r2,r3,0x0002
0005cd64: 1440002c bne r2,r0,0x 0005ce18		Branch if Item is Rare
0005cd68: 340200ff ori r2,r0,0x00ff		r2 = FF
0005cd6c: 90a3 0005 lbu r3,0x 0005(r5)		Load Item's Type
0005cd70: 10e20003 beq r7,r2,0x 0005cd80		Branch if Chosen Type = Any
0005cd74: 00000000 nop
0005cd78: 14670027 bne r3,r7,0x 0005ce18		Branch if Chosen Type != Item Type
0005cd7c: 00000000 nop
0005cd80: 306300ff andi r3,r3,0x00ff
0005cd84: 000310c2 srl r2,r3,0x03		Type / 8
0005cd88: 01a21021 addu r2,r13,r2
0005cd8c: 9044004a lbu r4,0x004a(r2)		Load Unit's Equippable Item Flags
0005cd90: 30630007 andi r3,r3,0x0007
0005cd94: 34020080 ori r2,r0,0x0080		r2 = 0x80
0005cd98: 00621007 srav r2,r2,r3		0x80 / 2^(Type AND 7) (flag to check)
0005cd9c: 00822024 and r4,r4,r2
0005cda0: 1080001d beq r4,r0,0x 0005ce18		Branch if Type isn't usable
0005cda4: 30c200ff andi r2,r6,0x00ff		r2 = Required Flags
0005cda8: 1040000b beq r2,r0,0x 0005cdd8		Branch if there are no Required Flags
0005cdac: 00000000 nop
0005cdb0: 90a20004 lbu r2,0x0004(r5)		Load Item's Second Table ID
0005cdb4: 00000000 nop
0005cdb8: 000210c0 sll r2,r2,0x03		ID * 8
0005cdbc: 3c018006 lui r1,0x8006
0005cdc0: 00220821 addu r1,r1,r2
0005cdc4: 90223ab9 lbu r2,0x3ab9(r1)		Load Item's Attack Flags
0005cdc8: 00000000 nop
0005cdcc: 00c21024 and r2,r6,r2
0005cdd0: 10400011 beq r2,r0,0x 0005ce18		Branch if Required Flags aren't present
0005cdd4: 00000000 nop
0005cdd8: 90a30002 lbu r3,0x0002(r5)		Load Item's Required Level
0005cddc: 00000000 nop
0005cde0: 306400ff andi r4,r3,0x00ff
0005cde4: 01c4102b sltu r2,r14,r4
0005cde8: 1440000b bne r2,r0,0x 0005ce18		Branch if Unit's Level is too low
0005cdec: 0184102b sltu r2,r12,r4
0005cdf0: 10400003 beq r2,r0,0x 0005ce00		Branch if High Level >= Required Level
0005cdf4: 00000000 nop				(a new high level overrides the old possible equipment list)
0005cdf8: 00606021 addu r12,r3,r0		High Level = Required Level
0005cdfc: 00004821 addu r9,r0,r0		Temp Counter = 0
0005ce00: 01201821 addu r3,r9,r0		r3 = Current Temp Counter
0005ce04: 25290001 addiu r9,r9,0x0001		Temp Counter ++
0005ce08: 306300ff andi r3,r3,0x00ff
0005ce0c: 27a20010 addiu r2,r29,0x0010		r2 = Stack Pointer + 0x10
0005ce10: 00431021 addu r2,r2,r3
0005ce14: a0480000 sb r8,0x0000(r2)		Store Item Counter
0005ce18: 25080001 addiu r8,r8,0x0001		Item Counter ++
0005ce1c: 010a102a slt r2,r8,r10
0005ce20: 1440ffca bne r2,r0,0x 0005cd4c		Branch if Item Counter < Limit
0005ce24: 256b000c addiu r11,r11,0x000c		Pointer Mod += 0xc
0005ce28: 313000ff andi r16,r9,0x00ff		r16 = Stack Counter
0005ce2c: 1200000c beq r16,r0,0x 0005ce60	Branch if nothing was stored
0005ce30: 340200fe ori r2,r0,0x00fe		Item ID = FE
0005ce34: 0c0088c3 jal 0x0002230c		Random Number Generator
0005ce38: 00000000 nop
0005ce3c: 00500018 mult r2,r16			Random * Stack Counter
0005ce40: 00001012 mflo r2			r2 = "
0005ce44: 04410003 bgez r2,0x 0005ce54		Branch if Random is Positive
0005ce48: 00021bc2 srl r3,r2,0x0f		rand(0..Stack Counter - 1)
0005ce4c: 24427fff addiu r2,r2,0x7fff
0005ce50: 00021bc2 srl r3,r2,0x0f
0005ce54: 306200ff andi r2,r3,0x00ff
0005ce58: 03a21021 addu r2,r29,r2
0005ce5c: 90420010 lbu r2,0x0010(r2)		Load Chosen Item ID
0005ce60: 8fbf0094 lw r31,0x0094(r29)
0005ce64: 8fb00090 lw r16,0x0090(r29)
0005ce68: 27bd0098 addiu r29,r29,0x0098
0005ce6c: 03e00008 jr r31
0005ce70: 00000000 nop


Return Locations

0005be5c:  Calculate/Store ENTD Unit Equipment
0005be84:  Calculate/Store ENTD Unit Equipment
0005beb8:  Calculate/Store ENTD Unit Equipment
0005bee4:  Calculate/Store ENTD Unit Equipment
0005bf10:  Calculate/Store ENTD Unit Equipment
0005bf3c:  Calculate/Store ENTD Unit Equipment
0005bf68:  Calculate/Store ENTD Unit Equipment
0005bf94:  Calculate/Store ENTD Unit Equipment
0005bfb8:  Calculate/Store ENTD Unit Equipment
0005c09c:  Calculate/Store ENTD Unit Equipment
0005c0d0:  Calculate/Store ENTD Unit Equipment
0005c14c:  Calculate/Store ENTD Unit Equipment
0005c16c:  Calculate/Store ENTD Unit Equipment
0005c1b0:  Calculate/Store ENTD Unit Equipment
0005c1d0:  Calculate/Store ENTD Unit Equipment
0005c20c:  Calculate/Store ENTD Unit Equipment