This guide explains how to add new towns, farms, or resources to the campaign map (I refer to these as a new building in the explanation). This method cannot be used to add new regions, settlements, or ports.
This guide explains how to add new buildings using the current version of taw's esf2xml converter. So you'll need to convert the Pathfinding.esf, Region.esf, and Startpos.esf to XML format in order to use this guide. It also involves using DB tables so I recommend learning how to create a mod pack.
http://www.twcenter.net/forums/showthread.php?t=239575
Pathfinding.esf
If a campaign has multiple theatres it will have multiple grid_data and pathfinding_area files. Below is a list of the various files and the theatre they correspond to.
Grid data part 1
At present it's not possible to add traits to grid_cells so the only way to add a new building is to replace the traits in an existing grid_cell with the traits for your new building.
1) Find a grid_cell close to where you want your new building to be that only contains a path_type="2 (transition area)" and a path_type="0 (passable area)". It is possible to add a new building using a grid_cell that has 2 passable areas and a road but it's much more complicated.
In this example I'll be editing the following grid_cell.
Code:
<rec type="grid_cells">
<bin6>a8 72 72 6e ; ab ab ab ab</bin6>
<ary type="boundaries">
<boundaries passable_part="255 (of 255)" unknown2="331794 (51012)" path_type="0 (passable area)" path_id="23 (cherokee_territory)" vertex_index="69866"/><!-- 3; 16362 (-615.377696037292,244.0); 16345 (-615.426207542419,243.967456817627); 16361 (-615.490156173706,244.0); 1; 0; 2 -->
<boundaries passable_part="0 (of 255)" unknown2="0 (00000)" path_type="2 (transition area)" path_id="-1 (transition)" vertex_index="69874"/><!-- 16362 (-615.377696037292,244.0); 16361 (-615.490156173706,244.0); 16345 (-615.426207542419,243.967456817627) -->
</ary>
</rec>
2) Figure out the coordinates of the center of this grid_cell. As each grid_cell is 2 pixels by 2 pixels this will be an odd number. In the example the grid_cell is 614-616 by 242-244, so the center is 615,243.
Enter these coordinates into the attached a spreadsheet and it will calculate the coordinates for all the files you need to edit.
Pathfinding areas
1) In the pathfinding_areas the <vertices> tags contains a long list of all the coordinates used in this theatre. Each coordinate is assigned a number; so the first coordinate is 0, the second is 1 and so forth.
Add the new coordinates for your building to the end of the <vertices> group. They're the Pathfinding axis coordinates in the spreadsheet.
In the example the new coordinates are listed below. They are entries 41686 to 41693.
Code:
-615.35358,243.98994
-614.64642,243.98994
-614.01007,243.35355
-614.01007,242.64645
-614.64642,242.01005
-615.35358,242.01005
-615.98993,242.64645
-615.98993,243.35355
2) Add the following code to the end of <u4_ary>. You'll need to replace the parts in bold with the entries that corresponds to your new coordinates.
Code:
12 <!-- vertices count -->
3
1
41686 <!-- -615.353580474853,243.989950180054 -->
41687 <!-- -614.646419525146,243.989950180054 -->
41688 <!-- -614.010069847107,243.353549957275 -->
41689 <!-- -614.010069847107,242.646459579468 -->
41690 <!-- -614.646419525146,242.010060310364 -->
41691 <!-- -615.353580474853,242.010060310364 -->
41692 <!-- -615.989930152893,242.646459579468 -->
41693 <!-- -615.989930152893,243.353549957275 -->
0
2
8 <!-- vertices count -->
<!-- closed line -->
41693 <!-- -615.989930152893,243.353549957275 -->
41692 <!-- -615.989930152893,242.646459579468 -->
41691 <!-- -615.353580474853,242.010060310364 -->
41690 <!-- -614.646419525146,242.010060310364 -->
41689 <!-- -614.010069847107,242.646459579468 -->
41688 <!-- -614.010069847107,243.353549957275 -->
41687 <!-- -614.646419525146,243.989950180054 -->
41686 <!-- -615.353580474853,243.989950180054 -->
The parts marked with a <!-- vertices count --> tell ETW where I trait ends and another begins. In the grid_data each grid_cell with a trait has a vertex_index which tells ETW which part of the pathfinding to use in this grid_cell. To determine what the vertex index of your new building you need to count the number of <u4_ary> entries in the theatre (blank lines and <!-- closed line --> should be ignored).
In this example the first trait's vertex_index is 173318 (area around the building) and the second is 173331 (building).
Grid data part 2, passable version
1) Replace both of the existing vertex_index entries with your new vertice_index. Ensure that the path_id="0 (passable area)" entry has the vertice_index for the area around the building.
2) Replace the <boundaries passable_part="0 (of 255)" unknown2="0 (00000)" path_type="2 (transition area)" part with <boundaries passable_part="32 (of 255)" unknown2="8448 (02100)" path_type="7 (slot)".
3) Replace the -1 (transition) part with the region the new building is in. In this example it's 23 (cherokee_territory)
Thus your code should look like this.
Code:
<rec type="grid_cells">
<bin6>a8 72 72 6e ; ab ab ab ab</bin6>
<ary type="boundaries">
<boundaries passable_part="255 (of 255)" unknown2="331794 (51012)" path_type="0 (passable area)" path_id="23 (cherokee_territory)" vertex_index="173318"/>
<boundaries passable_part="32 (of 255)" unknown2="8448 (02100)" path_type="7 (slot)" path_id="23 (cherokee_territory)" vertex_index="173331"/>
</ary>
</rec>
Grid data part 2, impassable version
If you find that after adding your new building ETW keeps crashing whenever a unit moves near it I recommend using an impassable building instead. This building is less likely to crash but can't be entered.
1) Replace both of the existing vertex_index entries with your new vertice_index. Ensure that the path_id="-1 (transition)" entry has the vertice_index for the area around the building.
2) Replace the path_type="0 (passable area)" part with path_type="7 (slot)".
Thus your code should look like this.
Code:
<rec type="grid_cells">
<bin6>a8 72 72 6e ; ab ab ab ab</bin6>
<ary type="boundaries">
<boundaries passable_part="255 (of 255)" unknown2="331794 (51012)" path_type=7 (slot)" path_id="23 (cherokee_territory)" vertex_index="173331"/>
<boundaries passable_part="0 (of 255)" unknown2="0 (00000)" path_type="2 (transition area)" path_id="-1 (transition)" vertex_index="173318"/>
</ary>
</rec>
Regions.esf
1) Go to the regions-1 folder.
2) Open the region that you want to add a new building to. In this example it's the cherokee_territory.xml.
3) In the slot_descriptions ary add your new building. For example if you want to add a new corn farm to the Cherokee region you'd add the following code.
Code:
<xml_include path="slot/corn-cherokee_territory-natives_only.xml"/>
4) Go to the slot folder, clone an existing xml that's the same type as your new building, and rename this xml with the name of your new building. In this example I clone the corn-cherokee_territory-north.xml and rename it corn-cherokee_territory-natives_only.xml.
5) Open your new xml.
6) Rename the <s> part with the name of your new building. In this example I change corn:cherokee_territory:north to corn:cherokee_territory:natives_only.
7) Replace all the coordinates in the v2 and v2_ary with the coordinates of your new building. They're the V2 axis coordinates in the spreadsheet.
8) Replace all the v2_ary coordinates with the coordinates of your new building. They're the Pathfinding axis coordinates in the spreadsheet. These coordinates have to be entered in the same order they've been entered in the pathfinding_areas of the pathfinding.esf.
Startpos.esf
World
These files tell ETW what level the new building is. It is nearly identical to the Regions.esf entry.
1) Go to the regions folder.
2) Open the region that you want to add a new building to. In this example it's the cherokee_territory.xml.
3) In the REGION_SLOT_ARRAY ary add your new building. For example if you want to add a new building to the Cherokee region you'd add the following code.
Code:
<xml_include path="region_slot/corn-cherokee_territory-natives_only.xml"/>
4) Go to the region_slot folder, clone an existing xml that's the same type as your new building, and rename this xml with the name of your new building. In this example I clone the corn-cherokee_territory-north.xml and rename it corn-cherokee_territory-natives_only.xml.
5) Open your new xml.
6) Increase the <!-- slot number --> by 50. Each slot needs a unique slot number.
7) Replace the <!-- Building slot Number --> with the slot number.
8) Rename the <s> part with the name of your new building. In this example I change corn:cherokee_territory:north to corn:cherokee_territory:natives_only.
9) Replace the coordinates in the v2x with the coordinates of your new building. They're the Pathfinding axis coordinates in the spreadsheet.
CAI_world
These files tell the AI where the new building is.
1) Go to the cai_building_slots folder and clone a building slot that is the same type as your new building, preferably in the same region.
2) Change the <!-- Building ID --> number to a new number. This ID represents this building_slot and has to be unique. I recommend adding 9 to the building_slot ID in the xml file you cloned, for example changing "3294" to "93294".
3) Change the <!-- Building Number --> number to the <!-- Building slot Number --> you added to your new region_slot. This number links the World and CAI_World entries.
4) Change the <!-- Settlement ID --> number to a new number. This ID is used to tell ETW which Region_slot ID or Settlement ID corresponds to this building_slot. It has to be unique. I recommend adding 9 to the Settlement or Region_slot ID in the xml file you cloned, for example changing "3295" to "93295".
5) Delete all the BDI information. DO NOT delete the <u4_ary> or </u4_ary> parts, only the numbers between these tags.
Below is a list of building slots' XML number and what they correspond to.
1) Go to the cai_region_slots folder and clone a region slot that is in the same region as your new building.
2) Change the cai_situated coordinates to the coordinates of your new building. They're the V2 axis coordinates in the spreadsheet.
3) Change the <!-- Region Slot ID --> number to the Settlement ID you used in the building slot file. Any other number will cause ETW to crash.
4) Change the <!-- Building ID --> number to the Building ID you used in the building slot file. Any other number will cause ETW to crash.
5) Delete all the BDI information. DO NOT delete the <u4_ary> or </u4_ary> parts, only the numbers between these tags.
Below is a list of region slots' XML number and what they correspond to.
1) Go to the cai_regions folder and open the region you're adding a new building to.
2) Add your new region_slot ID to the <u4_ary> marked <!-- Region Slot IDs of region_slots in this region -->.
3) Delete all the BDI information. DO NOT delete the <u4_ary> or </u4_ary> parts, only the numbers between these tags.
Below is a list of regions' XML number and what they correspond to.
1) Go to the cai_interface folder and open the cai_world.xml.
2) Add your new building_slot and region_slot to the list of building_slots and region_slots.
DB tables
1A) To add a new town make a mod pack that contains the campaign_map_towns_and_ports_tables from the main.pack.
1B) Clone an existing town that's the same type as your town.
1C) Rename the cloned town with the name of your new town.
2A) To add a new farm or resource make a mod pack that contains the campaign_map_slots_tables from the main.pack.
2B) Clone an existing farm or resource that's the same type as your farm or resource.
2C) Rename the cloned farm or resource with the name of your new farm or resource.
Localiation.loc
1) Make a mod pack that contains the localiation.loc from the local_en.pack (this pack may have a different name in the non-English version of ETW).
2) Clone a building that's the same type as your new building. For farms and resourced the entry will begin campaign_map_slots_onscreen and for towns it will begin campaign_map_towns_and_ports_onscreen_name_town.
3) Rename the cloned building with the name of your new building.
Testing
1) Use Taw's esf converter to turn your modified XML files into the Pathfinding.esf, Region.esf, and Startpos.esf.
2) Add the new Region.esf and Startpos.esf to your ETW folder, enable the mod pack with the new DB tables, and start ETW. If you've done eveything correctly you should be able to start a new campaign. However your new building won't have a name and it will have the pathfinding bug.
3) Enable the mod pack that contains the Localiation.loc. The name of the new building should now appear.
4) Add the new Pathfinding.esf to your ETW folder and start ETW. If you've done everything correctly you should be able to make units walk to your new building and they should be able to exit it.
Please let me know if you have any problems.