Author Topic: Treasure Code stored somewhere else?  (Read 2314 times)

Agent 12

  • Zurvan Surfer (+2500)
  • *
  • Posts: 2572
    • View Profile
Treasure Code stored somewhere else?
« on: March 31, 2006, 02:39:15 pm »
I was always under the impression that all chests code is stored in the events for the location however while editing Forest ruins I took out all of the code and the treasure chest still worked.  I tested it on that basement room of magus' castle (with the save point battles) and had the same issue.  Anyone know where these events are stored?  I'd like to see how they implement chests.

This may be why my treasure chests aren't working 100%.  I've always had the problem where after opening a chest you could open the menu and close it and the chest would "close" again, though you could not get the item again.  Once you left the location it was closed for good.

--jp

JLukas

  • Fan Project Leader
  • Squaretable Knight (+400)
  • *
  • Posts: 426
    • View Profile
Treasure Code stored somewhere else?
« Reply #1 on: March 31, 2006, 06:53:34 pm »
Original thread:

http://www.chronocompendium.com/Forums/viewtopic.php?t=1900&highlight=

Treasure chest memory map:

http://www.chronocompendium.com/Term/Text_List_of_Treasure_Chests

Only about a dozen regular treasure chests are event controlled.  Mostly at Cyrus' Grave.  Another good example if you want to study the code is the kids guarding the treasure in the east hall of Magus Castle.  Sealed chests are always event controlled.

Here's the notes I compiled while looking at the data format.  This data is built upon Geiger and Chickenlump's original notes.

-----

Offsets:

35F000 to 35F401 Pointers to treasure chest data (513 addresses)
35F402 to 35F7E5 Treasure chest data (4 bytes per chest, 249 chests total)
3FF7E6 to 35FE03 JUNK - Overwritten Geno Dome location map
35FE04 to 35FFFF UNUSED SPACE (508 bytes)

Data format:

Byte 1: X coord
Byte 2: Y coord
Byte 3: Item value, or Gold x2
Byte 4: Bitfield (notes in part 3)

Data format notes:

If byte 1 and 2 (X & Y coords) are both $00, the game reads the next 2 bytes
as a room index to load the treasure chest data from instead.

Ex: 00 00 2E 01

Load treasure chest data from location 12E
There are 5 examples of this in the memory map document (mainly the Tyrano
Lair/Giant's Claw, that share similar rooms)

Memory address notes:

7F0020 to 7F004F appears to be unused treasure chest space.  Using this space would allow the possibility of having 632 treasure chests in
total.  For comparison the existing game only has 249, that is quite a bit of
expansion room.

If the max 632 chests were created, when applied to the offsets, the treasure
chest data would begin at $35F402 and end at $35FED1.  $35FED2 to $35FFFF
would be available free space.

Treasure chest opening notes:

The treasure chest won't update itelf with the opened graphic unless it is on
the correct layer.


The routines work the same way I assume the location exit data does - it reads
the following pointer to determine the length.

Example:

The game loads the Location 000 treasure chest pointer 02F4, then compares it
to the next one in the list, 06F4.  It now knows that the data is 4 bytes long
(1 treasure chest)

If the next pointer is exactly the same, it obviously has no data.

-----

Data format bitfield:

If bit 80 in byte 4 is set, byte 3 is the gold amount x2.

If other bits in byte 4 are set along with 80, it multiplies (and adds if
needed), and then adds the contents of byte 3 (which itself is x2).

Examples:

Treasure chest data format

10 10 00 80 = 0 Gold

10 10 00 81 = 512 Gold
10 10 00 82 = 1024 Gold
10 10 00 84 = 2048 Gold
10 10 00 88 = 4096 Gold

10 10 00 90 = 8192 Gold
10 10 00 A0 = 16384 Gold
10 10 00 C0 = 32768 Gold

10 10 00 92 = 9216G

Finally, here's an example that has a value in byte 3:

10 10 02 81 = 516 Gold

-----

Other Byte 4 bits (when 80 is not set)

01
02
04
08
10
20

Are all for items

40 is what was previously described as the "Event bit"  The chest opens along
with the sound, but no textbox is displayed nor are you given the item.  There
are no known examples of this being used with the existing treasure chests in
the game.

Agent 12

  • Zurvan Surfer (+2500)
  • *
  • Posts: 2572
    • View Profile
Treasure Code stored somewhere else?
« Reply #2 on: March 31, 2006, 07:35:59 pm »
Hm...well I fixed my problem.

The Activate command for object00 is seems to be ran after you go to your menu.  It may be worth renaming this command.

So if you want your chests to stay closed copy and paste your closing code into the activate of object 00.

It's probably worth mentioning to everyone to ALWAYS have object 00 be a startup object i.e. load strings, set memory.  I just got done fixing the worst bug i've ever seen (after about 19 seconds the graphics got garbled and zsnes literally froze so that I couldn't even quit chrono trigger w/o ctrl alt delete) and it was because someone had made lucca PC object 00.  

Finally it seems that if you are copying to multiple places and having issues changing the parameter of copy tiles can solve that problem.  

Zeality I think we have enough info on chests to put together a TF tutorial.  I can probably make one if you want.

--jp