I've written the code. I made only a short try in BG2, it seemed to work properly. This code will make your TP2 fatter, that's sure, but I think it's not hard to customize or extend it. I've attached it to this post.
Single-line comments such as // this in the code usually indicate lines where you can set attributes. The code is divided into several sections. I'll paste here the most important lines that you should change when you want to modify the code.
I've tried to add all those features we've discussed in the above posts, so the area names, coordinates, initial map icon etc. are already specified in the code.
These variables (from section 4) are very important, they're used in several calculations:
CODE
/* ALL area links, including the ones FROM the new area as well as all links you want to add from other areas */
SET "my-northlink" = 0 // How many north links you'll add from your NEW area
SET "my-westlink" = 2 // How many west links you'll add from your NEW area
SET "my-southlink" = 2 // How many south links you'll add from your NEW area
SET "my-eastlink" = 2 // How many east links you'll add from your NEW area
SET "ext-northlink" = 2 // How many total north links you'll add from other EXISTING areas
SET "ext-westlink" = 1 // How many total west links you'll add from other EXISTING areas
SET "ext-southlink" = 2 // How many total south links you'll add from other EXISTING areas
SET "ext-eastlink" = 2 // How many total east links you'll add from other EXISTING areas
I'm sure this part (from section 5) is obvious, so no explanation is needed:
CODE
WRITE_ASCII "%area-section-end%" ~AZ1000~ // Your area's filename
WRITE_ASCII "%area-section-end%" + 0x8 ~AZ1000~
WRITE_ASCII "%area-section-end%" + 0x10 ~AZ1000~
WRITE_LONG "%area-section-end%" + 0x34 10 // Icon index
WRITE_LONG "%area-section-end%" + 0x38 1292 // X coordinate on the worldmap
WRITE_LONG "%area-section-end%" + 0x3C 402 // Y coordinate on the worldmap
SAY "%area-section-end%" + 0x40 ~Kula~ // Worldmap caption of your area
If you want it to detect an existing game area, and add a link from it to your new area, you have to change the code at three points, basically. The first are the already mentioned variables in section 5, the second is pasted directly below, and the third (section 9) will be quoted in a later part of this post. The following code is from section 7:
CODE
PATCH_IF(
/* Specify the list of EXISTING areas you want links FROM */
// You can use the commented template below to include a new area. Substitute ARXXXX with the area filename.
/* ("%area-resref%" STRING_EQUAL "ARXXXX") OR */
("%area-resref%" STRING_EQUAL "AR0020") OR /* City Gates */
("%area-resref%" STRING_EQUAL "AR2000") /* Trademeet */)
BEGIN
...
END
Though you probably won't have to modify it directly, it's important to mention the following code block. This is a typical statement inside the body of PATCH_IF (also in section 7):
CODE
READ_LONG ("%northlink-offset%" + 4) "north-count"
WRITE_LONG ("%northlink-offset%" + 4) ("%north-count%" + 1)
"north-position" = "%link-offset%" + 216 * ("%north-current%" + "%north-count%")
INNER_PATCH_SAVE str "%str%" BEGIN
FOR (j=8 * "%north-current%" + 2; j<=8*("%link-count%" - "%new-link-count%") + 6; j+=2) BEGIN
READ_SHORT j "temp"
WRITE_SHORT j ("%temp%" + 1)
END
END
"actual-north" = "%actual-north%" + 1
So the above code creates (or rather just starts to create) one north link FROM an existing game area to your new area. It is applied on each detected area from those you've listed. If you don't want an area to have a north link to yours, exclude it. The following code snipeet, also from section 7, ensures that no west link will be added from City Gates to your area:
CODE
// You can specify conditions if you want. Here we won't add west link from City Gates to the new area.
PATCH_IF !("%area-resref%" STRING_EQUAL "AR0020") BEGIN
READ_LONG ("%northlink-offset%" + 12) "west-count"
WRITE_LONG ("%northlink-offset%" + 12) ("%west-count%" + 1)
"west-position" = "%link-offset%" + 216 * ("%west-current%" + "%west-count%")
INNER_PATCH_SAVE str "%str%" BEGIN
FOR (j=8 * "%west-current%" + 8; j<=8*("%link-count%" - "%new-link-count%") + 6; j+=2) BEGIN
READ_SHORT j "temp"
WRITE_SHORT j ("%temp%" + 1)
END
END
"actual-west" = "%actual-west%" + 1
END ELSE "west-position" = 0
The below lines are from section 9. Important: all area resrefs on your first list of existing game areas must also be added here:
CODE
// This is where you specify the structure of inserted links that come from EXISTING areas to your new area
/* In this example, we only have City Gates and Trademeet */
PATCH_IF (("%area-resref%" STRING_EQUAL "AR0020") OR
("%area-resref%" STRING_EQUAL "AR2000"))
BEGIN
// Travel time factor. You don't need PATCH_IF if you use the same time multiplier for all areas.
PATCH_IF ("%area-resref%" STRING_EQUAL "AR2000") BEGIN
SET "travel" = 1 // Journey (or a trip?) takes 4 hours to Trademeet from your new area
END ELSE BEGIN
SET "travel" = 5 // Otherwise 20 hours
END
// North link
PATCH_IF ("north-position") BEGIN
INNER_PATCH "%str%" BEGIN READ_SHORT (8 * "%north-current%") "shift" END
SET "new-position" = "%north-position%" + (216 * shift)
INSERT_BYTES "%new-position%" 216
WRITE_LONG "%new-position%" ("%area-count%" - 1)
WRITE_ASCII ("%new-position%" + 4) ~ExitSE~ // Entrance in new area. Non-existing entrance causes the game to crash.
WRITE_LONG ("%new-position%"+ 0x24) travel // Travel time factor
WRITE_LONG ("%new-position%"+ 0x28) 4
/* WRITE_ASCII ("%new-position%"+ 0x2C) ~ARXXXX~ */ // Filename of random encounter area
/* WRITE_LONG ("%new-position%"+ 0x54) 50 */ // Probability of random encounter
"actual-north" = "%actual-north%" + 1
END
// East link
...
// South link
...
// West link
Very important: as the only direct connection between the ARE file and the worldmap is the entrance, make sure to specify an existing entrance name here. (I've added ExitSE, the entrance of the test area I quickly made.)
The only section that has a bigger chance to be modified by you in the future and I didn't mention it yet is section 12, which adds links FROM YOUR area to other existing game areas.
If you browse the code, you might notice three short sections, with "Check code consistency" as a title comment. It is recommended that you never remove these (unlike most of the comments and commented code), because they make the installation fail if anything is wrong. The installation won't fail in its current state, but if you modify it in the future, it is possible that you accidently make some mistakes in the code. In the latter case, without these lines, it is possible that WeiDU would happily inform the user about a successful install while the worldmap would become totally messed up, causing a crash in the game.
The player has to start a new game, or the worldmap change will not take effect. (The worldmap is stored in the savegame.)
The code is quite long, as I've already written. This is because it must be capable of adding links from theoretically any number of areas, not just from one. (And you needed Trademeet and City Gates.) Though since I've optimized it for your needs, you probably won't have to change anything except the bam icon stuff. Tell me how it works for you.