I've been following the tutorial Baronius gave about area editing for a BG1 map. My-links are fine but I'm having problems with the external links. In some cases I only want to include one external link and leave the rest blank. Unfortunately whenever I set my external links to 0, I get code consistency errors. Setting the all external links to one as shown below works fine but is not ideal for areas on the edge of the map where no travelling occurs. Can anyone help me with this problem?
/** 1. Read file header **/
/* READ_ASCII 0x0 "wmap-marker" (8) */
READ_LONG 0x8 "wmap-count"
READ_LONG 0xC "wmap-offset"
INNER_ACTION BEGIN
/* ACTION_IF !("%wmap-marker%" STRING_EQUAL_CASE_CASE "WMAPV1.0") THEN BEGIN FAIL ~Cannot add area to worldmap: your wmap file is invalid~ END */
ACTION_IF ("%wmap-count%" != 1) THEN BEGIN FAIL ~Cannot add area to worldmap: you've a non-standard SoA wmap file~ END
ACTION_IF ("%wmap-offset%" != 16) THEN BEGIN FAIL ~Cannot add area to worldmap: you've a non-standard SoA wmap file~ END
END
/** 2. Read worldmap entry data **/
READ_LONG 0x30 "area-count"
READ_LONG 0x34 "area-offset"
READ_LONG 0x38 "link-offset"
READ_LONG 0x3C "link-count"
/** 3. Check file consistency **/
INNER_ACTION BEGIN
ACTION_IF ("%link-offset%" != "%area-offset%" + (240 * "%area-count%")) THEN BEGIN FAIL ~Cannot add area to worldmap: fatal inconsistency in wmap file~ END
END
/** 4. Update worldmap entry with necessary values **/
SET "area-count" = "%area-count%" + 1
SET "link-offset" = "%link-offset%" + 240
/* 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 // This is how many north links you will add from your NEW area
SET "my-westlink" = 1 // This is how many west links you will add from your NEW area
SET "my-southlink" = 0 // This is how many south links you will add from your NEW area
SET "my-eastlink" = 0 // This is how many east links you will add from your NEW area
SET "ext-northlink" = 1 // This is how many total north links you will add from other EXISTING areas
SET "ext-westlink" = 1 // This is how many total west links you will add from other EXISTING areas
SET "ext-southlink" = 1 // This is how many total south links you will add from other EXISTING areas
SET "ext-eastlink" = 1 // This is how many total east links you will add from other EXISTING areas
SET "my-link-count" = "%my-northlink%" + "%my-westlink%" + "%my-southlink%" + "%my-eastlink%"
SET "ext-link-count" = "%ext-northlink%" + "%ext-westlink%" + "%ext-southlink%" + "%ext-eastlink%"
SET "new-link-count" = "%my-link-count%" + "%ext-link-count%"
SET "link-count" = "%link-count%" + "%new-link-count%"
WRITE_LONG 0x30 "%area-count%"
WRITE_LONG 0x38 "%link-offset%"
WRITE_LONG 0x3C "%link-count%"
/** 5. Add a new area to the end of the areas section **/
SET "area-section-end" = "%area-offset%" + 240 * ("%area-count%" - 1)
INSERT_BYTES area-section-end 240
WRITE_ASCII "%area-section-end%" ~ARC011~ // Forgotten Forest
WRITE_ASCII "%area-section-end%" + 0x8 ~ARC011~
WRITE_ASCII "%area-section-end%" + 0x10 ~ARC011~
WRITE_LONG "%area-section-end%" + 0x34 %FIRSTICONID% // Icon index
WRITE_LONG "%area-section-end%" + 0x38 522 // X coordinate on the worldmap
WRITE_LONG "%area-section-end%" + 0x3C 345 // Y coordinate on the worldmap
SAY "%area-section-end%" + 0x40 ~~ // Worldmap caption of your area
WRITE_LONG "%area-section-end%" + 0x44 (BNOT 0x0)
/** 6. Update position and number of links FROM this area to other areas **/
WRITE_LONG "%area-section-end%" + 0x50 ("%link-count%" - "%my-link-count%")
WRITE_LONG "%area-section-end%" + 0x54 "%my-northlink%"
WRITE_LONG "%area-section-end%" + 0x58 ("%link-count%" - "%my-westlink%")
WRITE_LONG "%area-section-end%" + 0x5C "%my-westlink%"
WRITE_LONG "%area-section-end%" + 0x60 ("%link-count%" - "%my-westlink%" - "%my-southlink%")
WRITE_LONG "%area-section-end%" + 0x64 "%my-southlink%"
WRITE_LONG "%area-section-end%" + 0x68 ("%link-count%" - "%my-link-count%" + "%my-northlink%")
WRITE_LONG "%area-section-end%" + 0x6C "%my-eastlink%"
/** 7. Gather information and update link count in EXISTING areas**/
SPRINT str ""
SPRINT off ""
SET "size" = 0
SET "actual-north" = 0
SET "actual-west" = 0
SET "actual-south" = 0
SET "actual-east" = 0
SET "north-position" = 0
SET "west-position" = 0
SET "south-position" = 0
SET "east-position" = 0
INNER_PATCH_SAVE str "%str%" BEGIN INSERT_BYTES 0 (8 * ("%link-count%" - "%new-link-count%" + 1)) END
FOR (i=0; i<"%area-count%"-1; i+=1) BEGIN
SET "northlink-offset" = ("%area-offset%" + 240*i + 80)
READ_ASCII ("%area-offset%" + 240*i) "area-resref" (6)
READ_LONG "%northlink-offset%" "north-current"
READ_LONG ("%northlink-offset%" + 8) "west-current"
READ_LONG ("%northlink-offset%" + 16) "south-current"
READ_LONG ("%northlink-offset%" + 24) "east-current"
/* 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.
PATCH_IF("%area-resref%" STRING_EQUAL_CASE "%Z2400%")
BEGIN
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
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
READ_LONG ("%northlink-offset%" + 20) "south-count"
WRITE_LONG ("%northlink-offset%" + 20) ("%south-count%" + 1)
"south-position" = "%link-offset%" + 216 * ("%south-current%" + "%south-count%")
INNER_PATCH_SAVE str "%str%" BEGIN
FOR (j=8 * "%south-current%" + 6; j<=8*("%link-count%" - "%new-link-count%") + 6; j+=2) BEGIN
READ_SHORT j "temp"
WRITE_SHORT j ("%temp%" + 1)
END
END
"actual-south" = "%actual-south%" + 1
READ_LONG ("%northlink-offset%" + 28) "east-count"
WRITE_LONG ("%northlink-offset%" + 28) ("%east-count%" + 1)
"east-position" = "%link-offset%" + 216 * ("%east-current%" + "%east-count%")
INNER_PATCH_SAVE str "%str%" BEGIN
FOR (j=8 * "%east-current%" + 4; j<=8*("%link-count%" - "%new-link-count%") + 6; j+=2) BEGIN
READ_SHORT j "temp"
WRITE_SHORT j ("%temp%" + 1)
END
END
"actual-east" = "%actual-east%" + 1
INNER_PATCH_SAVE off "%off%" BEGIN
INSERT_BYTES size 30
WRITE_EVALUATED_ASCII size "%area-resref%" #6
WRITE_LONG (size+6) "%north-position%"
WRITE_LONG (size+10) "%east-position%"
WRITE_LONG (size+14) "%south-position%"
WRITE_LONG (size+18) "%west-position%"
WRITE_SHORT (size+22) "%north-current%"
WRITE_SHORT (size+24) "%east-current%"
WRITE_SHORT (size+26) "%south-current%"
WRITE_SHORT (size+28) "%west-current%"
END
"size" = "%size%" + 30
END
END
/** 8. Check code consistency **/
INNER_ACTION BEGIN
ACTION_IF ("%actual-north%" != "%ext-northlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (first ext-north-link check failed)~ END
ACTION_IF ("%actual-west%" != "%ext-westlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (first ext-west-link check failed)~ END
ACTION_IF ("%actual-south%" != "%ext-southlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (first ext-south-link check failed)~ END
ACTION_IF ("%actual-east%" != "%ext-eastlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (first ext-east-link check failed)~ END
END
/** 9. Insert the area links that come from other EXISTING areas **/
SET "actual-north" = 0
SET "actual-west" = 0
SET "actual-south" = 0
SET "actual-east" = 0
FOR (i=0; i<size; i+=30) BEGIN
INNER_PATCH "%off%" BEGIN
READ_ASCII i "area-resref" (6)
READ_LONG (i+6) "north-position"
READ_LONG (i+10) "east-position"
READ_LONG (i+14) "south-position"
READ_LONG (i+18) "west-position"
READ_SHORT (i+22) "north-current"
READ_SHORT (i+24) "east-current"
READ_SHORT (i+26) "south-current"
READ_SHORT (i+28) "west-current"
END
// This is where you specify the structure of inserted links that come from EXISTING areas to your new area
PATCH_IF ("%area-resref%" STRING_EQUAL_CASE "%Z2400%") 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_CASE "%Z2400%") BEGIN
SET "travel" = 1 // Journey (or a trip?) takes 4 hours to Forgotton Forest
END ELSE BEGIN
SET "travel" = 5 // Otherwise 20 hours
END
//SET "travel" = 1 // Four hours to blah blah blah. Travel time divided by 4
//Only East link is actually used
// 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) ~Exit2400~ // 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
PATCH_IF ("east-position") BEGIN
INNER_PATCH "%str%" BEGIN READ_SHORT (8 * "%east-current%" + 2) "shift" END
SET "new-position" = "%east-position%" + (216 * shift)
INSERT_BYTES "%new-position%" 216
WRITE_LONG "%new-position%" ("%area-count%" - 1)
WRITE_ASCII ("%new-position%" + 4) ~Exit2400~ // 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-east" = "%actual-east%" + 1
END
// South link
PATCH_IF ("south-position") BEGIN
INNER_PATCH "%str%" BEGIN READ_SHORT (8 * "%south-current%" + 4) "shift" END
SET "new-position" = "%south-position%" + (216 * shift)
INSERT_BYTES "%new-position%" 216
WRITE_LONG "%new-position%" ("%area-count%" - 1)
WRITE_ASCII ("%new-position%" + 4) ~Exit2400~ // 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-south" = "%actual-south%" + 1
END
// West link
PATCH_IF ("west-position") BEGIN
INNER_PATCH "%str%" BEGIN READ_SHORT (8 * "%west-current%" + 6) "shift" END
SET "new-position" = "%west-position%" + (216 * shift)
INSERT_BYTES "%new-position%" 216
WRITE_LONG "%new-position%" ("%area-count%" - 1)
WRITE_ASCII ("%new-position%" + 4) ~Exit2400~ // 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-west" = "%actual-west%" + 1
END
END
END
/** 10. Check code consistency **/
INNER_ACTION BEGIN
ACTION_IF ("%actual-north%" != "%ext-northlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (second ext-north-link check failed)~ END
ACTION_IF ("%actual-west%" != "%ext-westlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (second ext-west-link check failed)~ END
ACTION_IF ("%actual-south%" != "%ext-southlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (second ext-south-link check failed)~ END
ACTION_IF ("%actual-east%" != "%ext-eastlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (second ext-east-link check failed)~ END
END
/** 11. Fix link references in original area entries **/
FOR (i=0; i<"%area-count%"-1; i+=1) BEGIN
SET "northlink-offset" = ("%area-offset%" + 240*i + 80)
READ_LONG "%northlink-offset%" "north-current"
READ_LONG ("%northlink-offset%" + 8) "west-current"
READ_LONG ("%northlink-offset%" + 16) "south-current"
READ_LONG ("%northlink-offset%" + 24) "east-current"
INNER_PATCH "%str%" BEGIN READ_SHORT (8 * "%north-current%") "shift" END
WRITE_LONG "%northlink-offset%" ("%north-current%" + shift)
INNER_PATCH "%str%" BEGIN READ_SHORT (8 * "%west-current%" + 6) "shift" END
WRITE_LONG ("%northlink-offset%" + 8) ("%west-current%" + shift)
INNER_PATCH "%str%" BEGIN READ_SHORT (8 * "%south-current%" + 4) "shift" END
WRITE_LONG ("%northlink-offset%" + 16) ("%south-current%" + shift)
INNER_PATCH "%str%" BEGIN READ_SHORT (8 * "%east-current%" + 2) "shift" END
WRITE_LONG ("%northlink-offset%" + 24) ("%east-current%" + shift)
END
/** 12. Add links that go FROM the new area to other existing areas **/
SET "actual-north" = 0
SET "actual-west" = 0
SET "actual-south" = 0
SET "actual-east" = 0
//ONLY WEST NEEDED
/*
/* Add north links */
SET "current-link" = "%link-offset%" + 216 * ("%link-count%" - "%my-link-count%")
INSERT_BYTES "%current-link%" 216
WRITE_LONG "%current-link%" 19 /* Watch Tower */
WRITE_ASCII ("%current-link%" + 4) ~ExitNE~ // Name of an EXISTING entrance of the area
WRITE_LONG ("%current-link%"+ 0x24) 1
WRITE_LONG ("%current-link%"+ 0x28) 4
/* WRITE_ASCII ("%current-link%"+ 0x2C) ~ARXXXX~ */ // Filename of random encounter area
/* WRITE_LONG ("%current-link%"+ 0x54) 50 */ // Probability of random encounter
SET "actual-north" = "%actual-north%" + 1
/* Add east links */
/* First east link FROM our new area */
SET "current-link" = "%link-offset%" + 216 * ("%link-count%" - "%my-link-count%" + "%my-northlink%")
INSERT_BYTES "%current-link%" 216
WRITE_LONG "%current-link%" 11 /* */
WRITE_ASCII ("%current-link%" + 4) ~ExitNE~ // Name of an EXISTING entrance of the area
WRITE_LONG ("%current-link%"+ 0x24) 5
WRITE_LONG ("%current-link%"+ 0x28) 4
/* WRITE_ASCII ("%current-link%"+ 0x2C) ~ARXXXX~ */ // Filename of random encounter area
/* WRITE_LONG ("%current-link%"+ 0x54) 50 */ // Probability of random encounter
SET "actual-east" = "%actual-east%" + 1
/* Second east link FROM our new area */
SET "current-link" = "%link-offset%" + 216 * ("%link-count%" - "%my-link-count%" + "%my-northlink%" + 1)
INSERT_BYTES "%current-link%" 216
WRITE_LONG "%current-link%" 14 /* */
WRITE_ASCII ("%current-link%" + 4) ~ExitNE~ // Name of an EXISTING entrance of the area
WRITE_LONG ("%current-link%"+ 0x24) 1
WRITE_LONG ("%current-link%"+ 0x28) 4
/* WRITE_ASCII ("%current-link%"+ 0x2C) ~ARXXXX~ */ // Filename of random encounter area
/* WRITE_LONG ("%current-link%"+ 0x54) 50 */ // Probability of random encounter
SET "actual-east" = "%actual-east%" + 1
/* Add south links */
/* First south link FROM our new area */
SET "current-link" = "%link-offset%" + 216 * ("%link-count%" - "%my-westlink%" - "%my-southlink%")
INSERT_BYTES "%current-link%" 216
WRITE_LONG "%current-link%" 11 /* */
WRITE_ASCII ("%current-link%" + 4) ~ExitNE~ // Name of an EXISTING entrance of the area
WRITE_LONG ("%current-link%"+ 0x24) 5
WRITE_LONG ("%current-link%"+ 0x28) 4
/* WRITE_ASCII ("%current-link%"+ 0x2C) ~ARXXXX~ */ // Filename of random encounter area
/* WRITE_LONG ("%current-link%"+ 0x54) 50 */ // Probability of random encounter
SET "actual-south" = "%actual-south%" + 1
/* Second south link FROM our new area */
SET "current-link" = "%link-offset%" + 216 * ("%link-count%" - "%my-westlink%" - "%my-southlink%" + 1)
INSERT_BYTES "%current-link%" 216
WRITE_LONG "%current-link%" 14 /* */
WRITE_ASCII ("%current-link%" + 4) ~ExitNE~ // Name of an EXISTING entrance of the area
WRITE_LONG ("%current-link%"+ 0x24) 1
WRITE_LONG ("%current-link%"+ 0x28) 4
/* WRITE_ASCII ("%current-link%"+ 0x2C) ~ARXXXX~ */ // Filename of random encounter area
/* WRITE_LONG ("%current-link%"+ 0x54) 50 */ // Probability of random encounter
SET "actual-south" = "%actual-south%" + 1
*/
/* Add west links */
/* First west link FROM our new area */
SET "current-link" = "%link-offset%" + 216 * ("%link-count%" - "%my-westlink%")
INSERT_BYTES "%current-link%" 216
WRITE_LONG "%current-link%" 19 /* Z2400 */
WRITE_ASCII ("%current-link%" + 4) ~ExitC011~ // Name of an EXISTING entrance of the area
WRITE_LONG ("%current-link%"+ 0x24) 1
WRITE_LONG ("%current-link%"+ 0x28) 4
/* WRITE_ASCII ("%current-link%"+ 0x2C) ~ARXXXX~ */ // Filename of random encounter area
/* WRITE_LONG ("%current-link%"+ 0x54) 50 */ // Probability of random encounter
SET "actual-west" = "%actual-west%" + 1
/*
/* Second west link FROM our new area */
SET "current-link" = "%link-offset%" + 216 * ("%link-count%" - "%my-westlink%" + 1)
INSERT_BYTES "%current-link%" 216
WRITE_LONG "%current-link%" 14 /* Trademeet */
WRITE_ASCII ("%current-link%" + 4) ~ExitNE~ // Name of an EXISTING entrance of the area
WRITE_LONG ("%current-link%"+ 0x24) 1
WRITE_LONG ("%current-link%"+ 0x28) 4
/* WRITE_ASCII ("%current-link%"+ 0x2C) ~ARXXXX~ */ // Filename of random encounter area
/* WRITE_LONG ("%current-link%"+ 0x54) 50 */ // Probability of random encounter
SET "actual-west" = "%actual-west%" + 1
*/
/** 13. Check code consistency **/
INNER_ACTION BEGIN
ACTION_IF ("%actual-north%" != "%my-northlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (my-north-link check failed)~ END
ACTION_IF ("%actual-west%" != "%my-westlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (my-west-link check failed)~ END
ACTION_IF ("%actual-south%" != "%my-southlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (my-south-link check failed)~ END
ACTION_IF ("%actual-east%" != "%my-eastlink%") THEN BEGIN FAIL ~Semantic error in TP2 code (my-east-link check failed)~ END
END