Author Topic: FF7 World/Field Map Scripts and Encounters  (Read 3222 times)

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
FF7 World/Field Map Scripts and Encounters
« on: 2019-01-20 07:36:12 »
This was meant to be a PM to DLPB, but it seems he has PMs disabled.

I noticed a couple forums he was involved in (ha, I know that narrows it down, right?) involving world map data, so I'm guessing he the's the right person to ask.

So, I'm working on a project that will take a walkthrough and split it into small sections (as it's kinda already done, by different parts of the story) but will basically attach all the field map IDs associated with that part of the walkthru and then display all the enemies that can be encountered during that specific portion.  All that is great, but things get a bit trickier when involving the world map.  Basically for field maps, I have a "map of maps", linking all the maps to the ones that can be accessed from (by walking off the screen to another).  I want to extend this to how field maps will transfer you to the world map (and vice-versa) and also how areas of the world map lead to other areas (ie. walking from Midgar Area Dirt to Midgar Area Grass) and continue my map of maps so it includes world map areas.  Another complication is the restrictive nature of some areas, like areas only the buggy can penetrate, but I want to consider those scenarios as my walkthru project will consider GameMoment to determine things like if you have the Buggy or Highwind (can jump from Grass to Grass areas) or Gold Chocobo is possible (after you have Tifa as your main party member, then can jump from any world encounter area to any other, although to cut down on the verbose-ness of the possible enemies you can encounter, it will only show the new ones you couldn't encounter prior).  Hopefully you're catching my drift.

A foreword tho: I know that there's a world_us.lgp file for PC, but I do not have this file.  I'm working with original PSX files, so if you know where to look there, that would help.

In a nutshell, I'm missing 2 things:
1) Where world map encounter rates/battle IDs are stored on PSX (I'm surprised none of this is on the Wiki, not even the world_us.lgp structure)
2) Where the scripting is located for world map areas, similar to how field maps have scripts to jump to another map when crossing a walkmesh threshold, I assume the world map has similar scripts to change the encounter rates at the point of crossing a threshold.

Hopefully someone can help point me in the right direction. As long as I know I should be working with a specific file, I should be good to get started, I am quite good as analyzing binary data structures.  Problem is, I'm spending so much time deciphering files just to realize it's not the right file.
« Last Edit: 2019-01-26 22:49:50 by codemann8 »

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #1 on: 2019-01-20 10:24:43 »
I'm not actually well up on the world map module and definitely not on PSX.

I can answer your second question - but only for PC.  On PC, the scripting is in world_us in the .ev files.  There are 3.  One for snowfield, one for overworld, one for underworld (submarine).

The calls to create the windows are there - but the text is in a file called "mes"

As to where the PSX files are - I haven't a clue.  Your best bet is Green_Goblin, who ported my translation project to the PSX.

The world map module is by far the least understood... and you're right that it's strange.


codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #2 on: 2019-01-20 16:34:41 »
I did read that wm0 is the overworld, wm1 is underworld, wm2 is the snowfield, however, in the FIELD folder, there are 64 WMx.DAT files (where x is replaced by a number 0-63) and all 64 files have identical contents, seems wasteful to me but also serves to stump me as to what's actually in there. But it's also not the same structure as the other field maps, so it still remains a mystery to me. There's also a WORLD folder which probably is where I'm supposed to be looking.

I do know that the lgp files made for the PC are simply repackaged archives that contain what would show up as multiple files under PSX. Perhaps if I knew more about all the things that CAN be found and what's still a mystery within world_us.lgp, perhaps that could help.

I will also definitely reach out to green_goblin as well.

DynamixDJ

  • Crazy poster
  • *
  • Posts: 239
  • Karma: 22
  • 1111 1111 0111
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #3 on: 2019-01-20 17:49:12 »
If you do manage to discover where the WM formation data is stored in the PSX file, then try also to find the Yuffie Encounters. They've always alluded me, and I've had to resort to TFerguson's FAQS for that info.

Anyway, field map IDs 1 ~ 64 are all shortcut-jumps to various places on the World Map. Using a placeholder ID for the World Maps as a Field Map means that the devs could easily assign a Field Map ID as the jump, without having to input the x,y,&z coordinates for the WM each time.

01 - WM0 - Midgar Southern Entrance
02 - WM1 - Kalm Entrance
03 - WM2 - Chocobo Ranch Entrance
04 - WM3 - Mythril Mine Entrance Swamp Side
05 - WM4 - Mythril Mine Entrance Junon Side
06 - WM5 - Fort Condor Entrance
07 - WM6 - Junon Entrance
08 - WM7 - Temple of The Ancients Entrance
09 - WM8 - Sleeping Man's Cave Entrance
10 - WM9 - Blacksmith's House Entrance
11 - WM10 - Mideel Entrance
12 - WM11 - Mideel Materia Cave Entrance
13 - WM12 - Costa Del Sol Entrance
14 - WM13 - Mt. Corel Entrance
15 - WM14 - North Corel Entrance
16 - WM15 - Corel Prison Entrance
17 - WM16 - Gongaga Entrance
18 - WM17 - Cosmo Canyon Entrance
19 - WM18 - Nibelheim Southern Entrance
20 - WM19 - Rocket Town Entrance
21 - WM20 - Lucrecia's Waterfall Entrance
22 - WM21 - North Corel Materia Cave Entrance
23 - WM22 - Wutai Entrance
24 - WM23 - Wutai Materia Cave Entrance
25 - WM24 - Bone Village Entrance
26 - WM25 - Corral Valley Entrance Snow Side
27 - WM26 - Icicle Inn Entrance Southern Side
28 - WM27 - Chocobo Sage's House Entrance
29 - WM28 - Round Island Materia Cave Entrance
30 - WM29 - Underwater (Last Coordinates)
31 - WM30 - Underwater Gelnika Entrance
32 - WM31 - Last World Map Coordinates
33 - WM32 - Last World Map Coordinates
34 - WM33 - Last World Map Coordinates
35 - WM34 - Last World Map Coordinates
36 - WM35 - Junon Ship Leaving Junon (Main Event)
37 - WM36 - Junon Ship Arriving at Costa Del Sol
38 - WM37 - Junon Ship Leaving Junon
39 - WM38 - Junon Ship Leaving Costa Del Sol
40 - WM39 - Wutai Shores
41 - WM40 - Highwind Outside Junon (After Escape)
42 - WM41 - Underwater By Junon's Reactor (After Mission)
43 - WM42 - Nibelheim Northern Entrance
44 - WM43 - Mt. Nibel Entrance Nibelheim Side
45 - WM44 - Last World Map Coordinates
46 - WM45 - Mt. Nibel Entrance Rocket Town Side
47 - WM46 - Icicle Inn Entrance Northern Side
48 - WM47 - Great Glacier Entrance
49 - WM48 - Rocket Town North of Entrance
50 - WM49 - Last World Map Coordinates
51 - WM50 - Diamond Weapon Surfaces (Event)
52 - WM51 - Last World Map Coordinates
53 - WM52 - Last World Map Coordinates
54 - WM53 - Highwind Outside Junon
55 - WM54 - Ancient Forest Entrance
56 - WM55 - Underwater (Last Coordinates)
57 - WM56 - Corral Valley Entrance Ravine Side
58 - WM57 - Forgotten Capitol Entrance
59 - WM58 - Highwind Over North Crater
60 - WM59 - Icicle Area Snowstorm Northern Entrance
61 - WM60 - Icicle Area Snowstorm Eastern Entrance
62 - WM61 - Icicle Area Snowstorm Southern Entrance
63 - WM62 - Icicle Area Snowstorm Western Entrance
64 - WM63 - Icicle Area Snowstorm Cavern Entrance

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #4 on: 2019-01-20 18:43:15 »
I believe all Yuffie encounters are hardcoded into scripts, versus defined in all the other fixed encounter data, but I have yet to find it, this is among the things I'm definitely looking for.

Very interesting about the WM fields, that makes perfect sense, and thank you, that info will help me reverse engineer this.  I do still wonder why they needed to have all 64 DAT files in the directory, when they are all the same, probably just a lazy approach.  But now it makes me all that more curious as to what's actually in those DATs.

You wouldn't happen to know where those corresponding x,y,z values are stored, do you? My first guess is within those DATS and then the scripts also in the DAT to transport you to the xyz location.

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #5 on: 2019-01-20 19:05:38 »
Yuffie's will likely be hard coded in PC. And it will be in the executable.

That's where I assume it will be anyway.  A lot of the world map stuff is.

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #6 on: 2019-01-20 19:19:55 »
But PSX doesn't have an executable, just a bunch of assembly/scripts scattered everywhere, right?
« Last Edit: 2019-01-20 20:10:42 by codemann8 »

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #7 on: 2019-01-20 20:35:53 »
It does have an executable - the sces scus file etc from what i recall... but who knows where the data was in psx. 

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #8 on: 2019-01-22 21:50:08 »
For future reference, if anyone else is searching for this, regarding the IDs of field maps:

Per Myster6, the field IDs are in order as they are arranged physically on the game disc, although IDs 1-64 are reserved for 64 dummy field maps (wm0, etc) that are used as entry points to the world map (for example, when you leave a city, a "world field map" is used as a placeholder to transport your character to a certain coordinates on the world map, usually on the south side of a city), then ID 65 and on are the rest of the fields.

I can only assume that the PC version defines this somehow thru the flevel.lgp file, albeit with many of the unused fields missing. And I believe ID 0 is the black background dummy field.

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #9 on: 2019-01-22 21:56:31 »
@DynamixDJ Do you know which TFerg guide mentions Yuffie Encounters? I looked thru all his guides, I don't seem to see any part mentioning Yuffie/Mystery Ninja. Looking at his findings may narrow my search in the end.

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #10 on: 2019-01-22 22:17:16 »
The flevel names are listed in maplist file inside the lgp.  The entry coords to fields from world map are in a table in the exe. The exits are defined in the fields and exit to 1-64 (also probably in a table in exe to define where those tags lead).   

Some of the field name handling stuff is hard coded.
« Last Edit: 2019-01-22 22:19:03 by DLPB »

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #11 on: 2019-01-23 04:29:45 »
I could always find the names of fields, it was always the IDs I had a hard time finding. Which is how fields are referenced inside the scripts.

But also, as far as specific coordinates, if I happen to find them, it'd be cool, but that's really just a "nice to have" at this point.

My current goal is to build a full "map of maps" (think graph theory, or Google maps) and be able to divide it into subsections and display the enemies for a general area (specific point in the game) along with attaching sections of a walkthrough to each subsection.
« Last Edit: 2019-01-23 04:38:32 by codemann8 »

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #12 on: 2019-01-26 03:34:03 »
For those who like this sort of thing, I created a graph of the maps of maps thing I was talking about.  I thought it was interesting to share.  Sorry for the overlapping, I didn't have a whole lot of control over the placement of the nodes, but also, there's just a sheer number of entry/exit points everywhere, particularly Gold Saucer (in yellow) and Great Glacier (in blue).  The Northern Crater (in green) I thought was interesting cuz you can actually see the left/right path.  Also, the black dot is the train station when you first start the game.

Link to larger version

« Last Edit: 2019-01-26 17:53:26 by codemann8 »

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #13 on: 2019-01-26 16:39:23 »
Oooooo  I like it very mucho!

One correction, though.  Lastmap does not go back to any other map.
« Last Edit: 2019-01-26 16:41:03 by DLPB »

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #14 on: 2019-01-26 17:18:34 »
There may be false positives in the results, as there may be unused scripts. But lastmap must either have a map jump defined in a script that's never invoked or a walkmesh trigger gateway that's impossible to reach.

Anyone have an idea how I can determine if a script will never be run? That would help narrow down on a more truthful graph.

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #15 on: 2019-01-26 18:01:12 »
Hmm the only way there would be to check the code to see if a call is made.  If no call, then script unused.

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #16 on: 2019-01-26 18:13:36 »
Are field scripts only called from within, or can things invoke from the outside? Is it that every script group calls its init (script 0) and its main (script 1)? Or a subset of the script groups, if so which ones? I'd imagine that ordering matters too, as a map jump could occur before it executes the rest of the scripts. To further complicate things, I also assume things run in parallel too, as multiple models need to animate at the same time.

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #17 on: 2019-01-26 18:20:28 »
I am soon to actually do a video on this.  I saw how the game does it at assembly level.  See here:
http://forums.qhimm.com/index.php?topic=15956.msg250079#msg250079

JBedford128

  • Crazy poster
  • *
  • Posts: 103
  • Karma: 5
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #18 on: 2019-01-26 22:23:22 »
One correction, though.  Lastmap does not go back to any other map.
There's a scene at las4_0 after the Safer fight and before the final Sephiroth fight.
« Last Edit: 2019-01-26 22:25:50 by JBedford128 »

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World Map Scripts and Encounters
« Reply #19 on: 2019-01-26 22:41:31 »
Great post! I think a video would be great! When you say soon, how soon? Lol, reason I ask, is I'm looking to move forward on some things and wondering if it's worth waiting for that so I better understand it before writing logic around it.

So, if I understand this correctly. When a field is loaded, all groups will one by one execute their Script 0 in order sequentially. After all have been run, with each of the IPs (instruction pointer) are set on start of each Script 1 (since Script 0 and 1 are actually the same script just with a RETURN to indicate a pause in execution while the IP increments, clever way to handle that), the Script 1s start executing each group's Line 1 in sequential order, then Line 2, and so on. But every 8 instructions will advance the next frame.  But each group will have it's own context (stack and IP).  Anything missing or wrong?  I'm guessing so since there was mention of if a Script 1 hasn't begun executing on a certain group and there is a call to that same group's Script >1, it will execute the script and then follow it up with Script 1, but how can that be if there is only one IP, or is it technically the caller's IP?  If so, how does it handle ASync calls?  And also, it seems like that would be an extremely rare case since all Script 1s seem to execute relatively at the same time, the execute call would have to come very early, like the first line.

Also, I'm not sure how models are tied in with groups, and if there's any special rules or things that only apply to models when running scripts.

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World/Field Map Scripts and Encounters
« Reply #20 on: 2019-01-27 00:12:24 »
There's a scene at las4_0 after the Safer fight and before the final Sephiroth fight.

That's a point.  Though I guess I never saw it that way due to the battle that comes before it.  But yeah field would be calling that jump.

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World/Field Map Scripts and Encounters
« Reply #21 on: 2019-01-27 00:13:12 »
As for your query... it's much easier to just show you.   ;D

The field script doesn't have a stack or threads.  It's a very efficient and well designed script-based solution for the field module.
« Last Edit: 2019-01-27 00:22:15 by DLPB »

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World/Field Map Scripts and Encounters
« Reply #22 on: 2019-01-27 00:40:26 »
Oh, so you're working on a video that soon then? Sweet!

Interesting tho, so without a stack how does it keep track of calls? Or does it just have the callee (is that a word) track it's execution while the caller continues it's own execution?  If so, how does it know that Script 1 hasn't executed yet if the IP changes on the callee?  Or maybe I'm interchanging the terms stack pointer and frame pointer inappropriately, and it uses a frame pointer? But it sounds like not. Sorry, it's been awhile since I briefly studied low level language in college, although I am a coder by trade.
« Last Edit: 2019-01-27 00:55:25 by codemann8 »

DLPB

  • No life
  • *
  • Posts: 9638
  • Karma: 320
  • For I realized that God's a young man, too.
    • View Profile
Re: FF7 World/Field Map Scripts and Encounters
« Reply #23 on: 2019-01-27 00:55:47 »
It just advances through script from byte to byte.  Each instruction is defined and it can jump back and forward a number of bytes (jump instructions). It keeps track of script execution via a table from what I can see.  The field module isn't stack based or assembly based (though obviously the hard code is).  It's script based.

The world map module is stack based.

codemann8

  • Cool newbie
  • *
  • Posts: 52
  • Karma: 3
    • View Profile
Re: FF7 World/Field Map Scripts and Encounters
« Reply #24 on: 2019-01-27 23:08:06 »
I'm looking forward to understanding more after your video.  However, as I'm trying to quick get a working method of ignoring unused scripts, I need a little bit more to get started.  In MR, the different groups/entities have a "Type" and the scripts seem to have differ, based on the first opcode in Script 0.  The pseudocode logic is this:
Code: [Select]
switch(opcode) {
case Opcode::PC:
type = Model;
_character = charID;
return;
case Opcode::CHAR:
type = Model;
_character = 0xFF;
break;
case Opcode::LINE:
if(_character==-1) type = Location;
return;
case Opcode::BGPDH:
case Opcode::BGSCR:
case Opcode::BGON:
case Opcode::BGOFF:
case Opcode::BGROL:
case Opcode::BGROL2:
case Opcode::BGCLR:
if(_character==-1) type = Animation;
return;
case Opcode::MPNAM:
if(_character==-1) type = Main;
return;
default:
break;
}

And based on what type each group/entity is, the different scripts are given labels:
Code: [Select]
if (type == Model) {
Script 2 = "S1 - Talk";
Script 3 = "S2 - Contact";
}

if (type = Location) {
Script 2 = "S1 - [OK]";
Script 3 = "S2 - Move";
Script 4 = "S3 - Move";
Script 5 = "S4 - Go";
Script 6 = "S5 - Go 1x";
Script 7 = "S6 - Go away";
}

So, getting to the point: I know the all Script 0s and 1s execute (assuming they don't get shortcutted based on Jumps) on their own and those two scripts can execute other scripts in other entities.  However, I'm assuming that the Location type scripts (the ones that create lines in their first opcode) also execute scripts on their own (probably when your character crosses a threshold).  My question is, which ones execute specifically? Are there any other scripts that are also executed by other external forces?

I'm basically trying to weed out unused scripts, but first I need to know ALL the ways these scripts can be invoked.  If you know this, it would help out a lot.
« Last Edit: 2019-01-27 23:10:45 by codemann8 »