Hello! I need programming help with Heroes2 autoborder.
I'd want to ask if someone knows the rules for creating map borders in Heroes2 editor? I'll introduce briefly the problem:
Heroes 2 has several borders that connects different terrains, like in this screenshot:
The rules for connecting terrain are quite complicated but I have managed to implement it 100% correctly (though its not the most optimal way...). I've used a pattern matcher approach that scans all changed tiles and is looking for certain patterns to place borders. The implementation looks like this:
https://github.com/nullptr128/openheroes2/blob/master/src/Editor/Utils/AutoBorder/AutoBorder.ts
Example patterns for water can be found here:
https://github.com/nullptr128/openheroes2/blob/master/src/Editor/Utils/AutoBorder/WaterBorders.ts
And this works perfectly. There are no case where border will be placed wrong, as you can see:
However, in Heroes 2 there are some combinations, where its IMPOSSIBLE to generate border using these tiles, simplest example would be a 1x1 grass tile on ocean. Original Heroes2 editor can strip those situations, fixing tiles behind the scenes to make sure it can be borderized correctly. Original H2 editor does this perfectly 100% of time, and I am struggling for few days now to create such alghoritm.
Perhaps some of you guys played with that problem? How should this be addressed? I've tried to make pattern-based fixing but it looks like there are endless combinations of "wrong" borders. I've also tried to figure out some rules, while some of them are quite good (like a rule "any specific tile must be part of 2x2 tile block of same terrain" that fixes like 90% of bad tiles), but I believe that I am approaching problem in totally wrong way.
Here are some examples of invalid combinations that are impossible to borderize using h2 tileset:
If you want to play around with this, you can run the project:
1. Node.JS 6+ is required
2. git clone https://github.com/nullptr128/openheroes2
3. Move to cloned dir in console
4. npm install
5. npm run editor-dev
However this is not required as this is not really Heroes 2 specific problem, many tile-based games have there problems.