Users browsing this thread: 1 Guest(s)
Radom Battle and Boss Themes

#1
Posts: 3,804
Threads: 270
Thanks Received: 765
Thanks Given: 392
Joined: Oct 2011
Reputation: 63
Status
Tissue-aware
author: madsiur
version: 1.1
released on: 2016/04/28
Apply to a FF3us 1.0 ROM
Download


Files
randomsongsC2.asm: For implementation in bank $C2
randomsongsEE.asm: For implementation in bank $EE or any other bank

Apply with xkas 0.06
Command example: xkas randomsongsEE.asm romname.smc

Description

Randomize the battle theme and default boss song. By default the max number of song for the battle theme is 8 and 4 for the boss theme.

By default, battleTable and bossTable have their entries nullified with only the default song as entry. Replace the !noSong in a table  to add a song choice. You can also reduce or expand the tables. If your table has 50% or more of null values (!nosong) it is more efficient to reduce it in half (e.g. remove 4 lines for a 8 song table) than  nullifying most of the entries. You'll also need to change the !numSongBattle and/or !numSongBoss value(s).

What the code does is if he picks a null value it will choose a new random number and repick from the table. If tables are modified properly, the repick probability will always be less than 50%, e.g. 44% maximum for a 16 songs table. The probability of a total of 3 picks before getting a song is 19% maximum and for 4 picks or more is 8,5%. So basically there can be relooping and cycles wasted  but I don't consider it significant taking in account it was the easiest  solution code-wise.

To recap, if you want 12 possible songs for the battle theme, add 8 lines to the table and nullifie 4 entries (!noSong). Then you need to  change the !numSongBattle variable to $0F.


Extra notes: This is a hack that uses the default RNG table at $C0FD00,X, meaning for now it is a much random as the default RNG system can be. Also, having table that are 2^X entries is not the optimal system since cycles are wasted for repicking in case of null entries. I'm opened to suggestion to improve both aspect, especially having as an example a table of 10 entries for 10 songs, not a table of 16 entries with 6 null values in it.

Assembly file:
Code:
hirom   ; Don't change this.
header  ; Comment out if your ROM has no header.

; Configuration
!battleSongId = $24        ; Change only if you changed its value in the $C2BF3B table.
!bossSongId = $14        ; Change only if you changed its value in the $C2BF3B table.
!noSong = $FE            ; "null" song ID value.
!numSongBattle = $07    ; X - 1 battle songs, where X = 2^Y and Y <= 7.
!numSongBoss = $03        ; X - 1 boss songs, where X = 2^Y and Y <= 7.
                        ; In other words, these last two variable must equal
                        ; $01, $03, $07, $0F, $1F, $3F or $7F for respectively
                        ; 2, 4, 8, 16, 32, 64 or 128 songs.

; Code                    
org $C2BDB7
JSL randomness
BRA continue

; Code from above BRA up to here is skipped, since it is no longer needed
org $C2BDCD
continue:

; This can go anywhere where there is enough free space
org $EEAF01
randomness:
LDA $C2BF3B,X        ; Load song ID
CMP #$FF      
BEQ return            ; Branch if we keep the current music playing
CMP #!battleSongId    ; Check if battle song
BEQ getBattle
CMP #!bossSongId        ; Check if boss song
BEQ getBoss
BRA loadSong        ; otherwise just load the song
getBattle:
JSR getRandom        ; Get random number
AND #!numSongBattle    ; Reduce it to a number from 0 to 7
TAX
LDA battleTable,X    ; Load the table song
CMP #!noSong            ; Check if "null" value
BEQ getBattle        ; Get another random number if "null"
BRA loadSong        ; Otherwise load song
getBoss:
JSR getRandom        ; Get random number
AND #!numSongBoss    ; Reduce it to a number from 0 to 3
TAX
LDA bossTable,X        ; Load the table song
CMP #!noSong            ; Check if "null" value
BEQ getBoss            ; Get another random number if "null"
loadSong:            
STA $1301            ; Save song ID
LDA $11E4  
AND #$08                
BNE return    
JSL $C50004            ; Play song
return:
RTL

getRandom:
LDA $1F6D            ; Get RNG index
INC $1F6D            ; Increment RNG index
TAX                
LDA $C0FD00,X        ; Get random number
RTS

; It is more efficient to reduce a table to its half than
; nullifying 50% or more of its entries.
battleTable:
db $24
db !noSong
db !noSong
db !noSong
db !noSong
db !noSong
db !noSong
db !noSong

bossTable:
db $14
db !noSong
db !noSong
db !noSong
  Find
Quote  
[-] The following 1 user says Thank You to madsiur for this post:
  • Gi Nattak (03-08-2016)

#2
Posts: 2,316
Threads: 91
Thanks Received: 326
Thanks Given: 297
Joined: Aug 2009
Reputation: 44
Status
Nattak\'d
Nice! A feature from your hack released far before the actual hack!
Definitely a good patch to have access to, as a fan of many battle musics.
Kind of you to share. Smile
Quote  

#3
Posts: 826
Threads: 11
Thanks Received: 60
Thanks Given: 29
Joined: Nov 2011
Reputation: 16
Status
Double
I like this as a patch idea.


Confused Moogles FTW
Quote  

#4
Posts: 3,804
Threads: 270
Thanks Received: 765
Thanks Given: 392
Joined: Oct 2011
Reputation: 63
Status
Tissue-aware
(03-08-2016, 06:32 PM)Gi Nattak Wrote: Nice! A feature from your hack released far before the actual hack!

(03-08-2016, 10:40 PM)Lockirby2 Wrote: I like this as a patch idea.

Thanks you both. I also had a revelation like Moses before my nap, I was thinking of also releasing the 4 drops per monster feature that was planned for FF6: Enhanced. Since there is 384 * 4 drops to edit, it would require to code a small utility rather than a .asm file but I got the base code for that. You could also assign % for each type of drop, from 25% to all to 70%, 20%, 8% and 2% as an example for the most common to rarest type.

It's not that much work in fact and not a project that would be on several weeks so I'm definitely considering it. Victory

Edit: With the random patch, I also though that as an example if you want 5 songs, you can create a 16 songs table with 3 entries per song and leave one as !noSong. This is more efficient than a table of 8 with 3 null entries. You could also do a table of 128 songs with 127 identical song ID and 1 entry with a special song, kinda of a special battle song with 0.8% chance of occurrence. This is an extreme example but with a little bit more asm work, you could give a special item or even select from another table an item to give at end of combat.
  Find
Quote  



Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite