Trying to understand the Map file format to export/import civ maps

Gedemon

Modder
Super Moderator
Joined
Oct 4, 2004
Messages
11,581
Location
France
After a bit of searching, I think it will be harder/slower for me to write something in Lua to export civ5/6 map data in HK format than
  • make a screen shot of a full screen map
  • convert it to a 2-3 colors PNG
  • import it for continent shapes in the map editor
  • redraw everything else.
Because here is what I've found so far:

The .hmap files in the "\Documents\Humankind\Maps" folder are zip files, so you can easily access the 2 archived files containing the map information (Descriptor.hmd) and data (Save.hms)

In the later, the terrain information (Elevation, Zone, POI, Visibility, Road, Rivers...) are encoded in base 64 PNG like for example (taken from Elhoim's Huge Earth) :
Code:
        <NaturalWonderTexture.Width>150</NaturalWonderTexture.Width>
        <NaturalWonderTexture.Height>88</NaturalWonderTexture.Height>
        <NaturalWonderTexture.Format>4</NaturalWonderTexture.Format>
        <NaturalWonderTexture.Bytes Length="874">iVBORw0KGgoAAAANSUhEUgAAAJYAAABYCAYAAAAX4w4mAAADMUlEQVR4Ae2dDUsDMQxAd5ubn/P//05FBMWPDEWZQh01SZPmiYJ6uzR5efTazZ3L22oln3xAQJfAWjcc0SDwQQCxMMGEAGKZYCUoYuGACQHEMsFKUMTCARMCiGWClaCIhQMmBBDLBCtBEQsHTAgglglWgiIWDpgQQCwTrARFLBwwIYBYJlgJilg4YEIAsUyw+gfdLf5jtkY8ax3kWHwCu43kKF9PT7FyXfjT5FgNmSUbLoWzdDJYHYgVrCGzpINYs3QyWB3qYt1KxNtgO5RgzEukoy7WSvaZdxO+U/F6V8IHtSLZFZ6I8vrwxIzMxA/PJ55Q/GGIVVwAq/L1L4VWmRI3FQHEStWuPMkiVp5epcoUsVK1K0+yiJWnV6kyRaxU7cqTLGLl6VWqTBErVbuOk72QVwMujn8V5ifECtOKjkRe5Zxtx3kOp/DMuwPkikMwY1XsukPN7mJt3Ed0oMgQvwi4t/lF1gUb/gTlVyNm+wVrrNk6GqQe9xkrSN0l0ziTK4XX+/2YsUoqZl80M5Y945IjIJZR2xd5d/JSeJOCWEZivb1IYNkBL0GfGTcq+yssa6wvFHyjSSDcjHUll5CrwpcQzeaOjBVOrMNbrPgPiiOV0BmbS6EOR6L8IBBvxvqRID/qE7h06LrDEPpgiPg/Ao+yW700Xsci1v96lPds4/trsMbKq0bozJmxQrcnb3LDxdpzL6289jQyHyrWXhaQ98bX+kbtHDIkMFSse7mF9L7oa2mGPT0p9NZ4V8ji/aQ2zPWg7edN5J4NbyKHWHM5E6aaoZfCMBRIRJ0AYqkjrRNw3djRI1YdD1QrXR8W/40dPWKp4i4U7I/7RrB4L+SCZ6nMWJ60C42FWIWa7VkqYnnSLjQWYhVqtmepiOVJu9BYiFWo2Z6lIpYn7UJjIVahZnuWilietAuNhViFmu1ZKmJ50g481rm8qHyumB+vFSrCJNQ3AWasbxZ8p0hgqFg3Mv3eKBZDqDgEhop1uONd1P8FE6dFOTNhjZWzb+GzHjtjhcdDgr0EEKuXHOc1CSBWEw8HewkgVi85zmsSQKwmHg72EkCsXnKc1ySAWE08HOwl8A5gxzh3rIsj7wAAAABJRU5ErkJggg==</NaturalWonderTexture.Bytes>

Using an online converter, the result is a 150x88x32 PNG file looking like that for the code above:
Spoiler :
upload_2021-8-22_11-32-44.png


Exporting the "ElevationTexture" layer like that result in a fully transparent PNG, but you can get the colors with an image tool.

From the source code, for the ElevationTexture it seems to use the blue, red, green channels for:

Spoiler Mountains, blue :
Code:
        public static void MountainFlagToColor(uint mountainFlag, ref Color32 color)
        {
            uint flags = color.b;
            FlagsReference.SetFlagsValue(ref flags, mountainFlag, FlagsReference.FlagMapBChannelMountainOffset, FlagsReference.FlagMapBChannelMountainMask);
            color.b = (byte)flags;
        }

Spoiler Altitude, red :

Code:
        public static void AltitudeToColor(int altitude, ref Color32 color)
        {
            color.r = (byte)Math.Min(255, altitude);
        }

Spoiler GroundMaterial (Lake, ... ?), green :

Code:
        public static void GroundMaterialIndexToColor(uint groundMaterialIndex, ref Color color)
        {
            uint flagMapGChannelTerrainTypeMask = FlagsReference.FlagMapGChannelTerrainTypeMask;
            uint num = greenChannelEncodingMax;
            uint flags = (uint)Mathf.Round(color.g * (float)num);
            int flagMapGChannelTerrainTypeOffset = FlagsReference.FlagMapGChannelTerrainTypeOffset;
            uint flagMapGChannelTerrainTypeMask2 = FlagsReference.FlagMapGChannelTerrainTypeMask;
            FlagsReference.SetFlagsValue(ref flags, groundMaterialIndex, flagMapGChannelTerrainTypeOffset, flagMapGChannelTerrainTypeMask2);
            color.g = (float)flags / (float)num;
        }
Spoiler Biome, green (again ?) :

Code:
        public static void BiomeToColor(uint biomeIndex, ref Color32 color)
        {
            uint flags = color.g;
            FlagsReference.SetFlagsValue(ref flags, biomeIndex, FlagsReference.FlagMapGChannelBiomeOffset, FlagsReference.FlagMapGChannelBiomeMask);
            color.g = (byte)flags;
        }


So I suppose it's possible, but as I said I think it will be faster for me to "just" redraw features, rivers, lake and elevation, and I'm leaving this here in case it could save some time to someone else looking to do the same...
 
Top Bottom