Closed radekmie closed 7 years ago
Today I had some time I could put off to look at this, starting by hex diffing the files you provided.
The first differences are in the player section, but I quickly discovered they are not causing the problem as the failing map was still failing when copying the slightly different player section from the non-failing map.
The next differences are all in the terrain section. When diffing the terrain section I found that it contains a lot of invalid road and river types (which the map editor fixes when re-saving). Specifically it looked amongst other things like the type bytes were incorrectly set to what should be in the mirroring byte or something like that.
To me it seems you are supplying invalid input to h3m_generate_tiles. Note that this function only takes as argument the type of terrain/road/river and not the direction of any of these. Direction is resolved internally. This means that if you are passing values greater than 0-3 for roads and rivers, you will get tiles with invalid roads and rivers (there is no error checking internally).
Here is a snippet which fixes your testmap (/ creates a new one if you uncomment the init line): https://gist.github.com/potmdehex/8f24d7c4d1ed6b416a920d767be4780c
I had a look at your homm3lua project after seeing it mentioned in the map description so I based my snippet off this: https://github.com/radekmie/homm3lua/blob/master/homm3luatest/init.lua#L45
In conclusion I do not think this is a bug with h3mlib (it's not a bug it's a feature). Arguably error checking could be added, but I do not think that is relatively important and is not really done much in other places anyway. But h3mlib could be improved in this area with some H3M_ROAD_COBBLESTONE etc defines and some better APIs for setting roads and rivers (notably retrieval functions for these like h3m_terrain_get_all()
are currently missing) and also support for setting custom direction/sprite (but note that for normal cases you will never have to specify direction manually since it is resolved internally the same way as the map editor would - so only if you want to make a bunch of non-standard patterns such as the same vertical sprite spammed in a horizontal row).
Anyways, it looks like you are making a really cool project. Do not hesitate to contact me for help/questions and I will get back as soon as I have time to put off. For roads and rivers specifically, I want to mention that I made a function in my Python API that takes two sets of coordinates and creates a road/river from one to the other: https://github.com/potmdehex/homm3tools/blob/master/h3m/phlm/phlm.py#L203
Well, it looks like you found it. Indeed, I thought that I should pass computed masks to h3m_generate_tiles
because of dispatch_river
/dispatch_road
. I've tried it and it works - you can see it here.
I see you are not interested in any error checking in there but how about some documentation? At least for h3m_generate_tiles
- about it arguments and assumptions. There's no point in allowing custom sprites (at this point I can't imagine other case than this you've mentioned) but it's worth mentioning that this function does it automatically.
Yeah, we have a crazy idea to write a full featured homm3 maps generator. My package, homm3lua
is only a simple wrapper for your code (mostly h3mlib) - the full project can be found here.
Anyway, I'd go with a PR for both documentation and defines for river and road types. If you want, of course.
Yeah, this and most of my repo could indeed use with a lot better documentation. I simply did not get around to it. I agree it's worth mentioning clearly how it works.
h3mlib is poorly documented, rough, in parts messy and unfinished but as you may have noticed it does lend it self to creating an RMG pretty well. This is not a coincidence - the original reason I started creating it was that I wanted to make an RMG. When HD Edition was announced I decided to take the project in another direction for the time being so that I could release a mod with a lot of content on the same day as it was being launched on Steam (of course wanted to make my own RMG for this but there was no way I could have finished one in the one month before HD Edition was released, especially since I was not even done reversing the .h3m format and making h3mlib so I wouldn't even be able to start on the actual RMG algorithms).
Here is about as far as I got on the RMG (using http://nothings.org/gamedev/herringbone ): https://raw.githubusercontent.com/potmdehex/homm3tools/master/screenshots/hbwang/snow144.png
Btw I like what you are doing here: https://github.com/radekmie/homm3lua/blob/master/homm3lua/homm3lua_h3m.c
I suggest to keep doing like this, avoiding to include _internal/h3mlibctx.h in a lot of places as the internal representations of structures might change in future versions of h3mlib (but the idea is that the exposed API should not). Things like the ones you have already made there can also easily be added to h3mlib itself eventually (but for your own productivity it is not a bad idea to first keep using them like you are now).
If you make PRs I will happily merge them after verification. Otherwise I will take care of it myself eventually, but might take long.
Then we are set. I'll submit PRs with some fixes as soon as I'll find something, some enhancements, like you've already mentioned and (rarely) with some documentation. Thank you again.
Here are two maps which are crashing the game - this one fail at the first week and this one fail randomly later.
Few notes: