As far as the randomized chests go, they use a LOCA event code on that tile with a 0x14 (flag for “do this if Chest command used”?) at the end instead of the normal CHES code used for chests, which means that it’ll do whatever the pointer it got fed (i.e. 0C D7 9E 08) instead of just opening a chest and giving an item.
Hm. Okay, another question. How hard would it be to write an ASM code that picks randomly from a list of say… 15 possible items?
For example, I set up an array that is in blocks of 15, and every 15 blocks is another chest/event’s worth of items. So I could say 0x01 = Chest 1 [Iron Sword, Iron Lance, 500 gold, Etc], 0x02 is Chest 2, 0x03 is random reward 1, etc. The cutoff would be when 15 0x00 entries were detected. From here I could make events refer to this array and just use 0x01 to load chest 1’s contents, chest 2, event 1, etc.
The data at 0x089ED70C isn’t actually ASM code; it’s the start of a list of possible treasure items and their probability out of a hundred; it’s just a list of item ID + % chance for every possible item, terminated by two 00 bytes.
Probably every randomized chest has a pointer to its own list in this region. This would also explain why some Valni/Lagdou chapters don’t disassemble - the LOCA events probably contain commands that aren’t in EA’s definitions (like “_FE8CODE” but worse).
Randomized enemy inventories likely use a similar system (though done automatically if the unit has the flag set in unit data); I’m 100% certain it’s based off of the enemy’s class ID; the Cyclops in Lagdou 8 and the Elder Bael at Melkaen use their own individual classes.
First download this fix to EA’s fe8 definitions; the command you want to use is CHESRANDOM, which is formatted like so:
CHESRANDOM EventID pointer [x,y]
Where “pointer” points to your item/probability list. The item list is composed of the item ID of a possible item, then it’s chance out of 100 of being taken, repeated for every item you want the chest to have, then ended by 0000. The chances for each item in the list should add up to 100 or unexpected things could happen.
Well, if less than 100 means you might not get an item, that could be kinda amusing. I suppose a smarter thing to do would be to put in a “1 Gold” piece drop, so the player gets the shittiest thing ever and realizes they were juked.