News:

SimuTranslator
Make Simutrans speak your language.

Import road/river data from file

Started by statto, August 24, 2021, 09:47:29 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

statto

Hello,

I've looked into this before but finally wrapped my mind around the code enough to think this could be implemented relatively easily, but I also don't completely understand what's going on.

I'd like to import a height map, but I'd also like to import a road/river map to match the height map. For instance, europe.ppm and europe_data.ppm. Europe.ppm gets loaded first, the game then checks for the _data extension.

Roads would have a certain RGB (say 255,0,0) and rivers would have a certain RGB (say 0,0,255), you could probably do trees as well (0,255,0). If the pixel matches, then create a road/river/tree object at (x,y). If it does not match, you can ignore it.

I don't really understand all the enums in dataobj/height_map_builder.cc height_map_loader_t::rgb_to_height but a rgb_to_object shouldn't be that hard to implement? I'm not very confident with malloc or how hfield gets passed to the world objects or else I'd give it a go.

I'm trying to create maps loosely based on the real world and having this ability would be both a huge time-saver and make the map more accurate as well. It also doesn't need to be perfect.

Thanks

prissi

This was suggested many time before. The best solution so far was using a script building the roads at certain coordinates, with the script built from an image.

Yona-TYT

#2
@Isidoro achieved something with the rivers sometime, doing it with the streets should also be possible, you have to obtain the coordinates, check the terrain and modify it if necessary, then build the roads / highways.
-> https://forum.simutrans.com/index.php/topic,18419.msg174894.html#msg174894-> https://forum.simutrans.com/index.php/topic,17998.msg171451.html#msg171451


But unfortunately there is a drawback, you need to read a file that contains the imported coordinates, but I think this is not yet implemented.

Look here: https://forum.simutrans.com/index.php/topic,20759.0.htmlAnd

here: https://forum.simutrans.com/index.php/topic,20106.0.html

statto

Thank you for the responses. I was thinking of something simpler by parsing a second image with the same height/width as the height map, something along the lines of:




sint8 height_map_loader_t::rgb_to_object(const int r, const int g, const int b)
{
const sint32 h0 = (2*r + 3*g + b); // 0..0x5FA


switch (h0) {
case 510: {
// r255 g0 b0
//return road object
}
case 765: {
// r0 g255 b0
//return tree object
}
case 255: {
//r0 g0 b255
//return river object
}
default: {
//return false
}
}
}



But I'm not sure how to return the objects properly in Simutrans yet.

prissi

SInce there can be many road or tree objects, a pixel may be to little to convey the information. Moreover, drawing another layer may be tedious; probably as much as just drawing the roads in SImutrans ...

statto

Quote from: prissi on August 27, 2021, 02:34:02 PM
SInce there can be many road or tree objects, a pixel may be to little to convey the information. Moreover, drawing another layer may be tedious; probably as much as just drawing the roads in SImutrans ...

I've actually played around with something like this before, and it works well even if it's limited - advanced versions could split out water from roads/rail, and you can easily generate the pixels from GIS software, and having tried to draw pixel by pixel in Simutrans using a graphics editor would be less tedious... still may have a look at implementing if I can figure out how the objects work