How to convert CIV6MAP file into Lua script?

pippolo

Chieftain
Joined
Nov 13, 2016
Messages
9
Hi :)
Can anybody help me?
I was thinking about creating a map in world builder and then use it as a lua script to play in multiplayer.
Any ideas?
Thanks a lot
 
Thank you
I really would like to try.... I dont understand well this point (perhaps because I dont know so very well firetuner)....


Now to get the MapToConvert data, use this code in civ5 (in firetuner for example)
PHP:
for iPlotLoop = 0, Map.GetNumPlots()-1, 1 do
local plot = Map.GetPlotByIndex(iPlotLoop)
local NEOfRiver = 0
local WOfRiver = 0
local NWOfRiver = 0
if plot:IsNEOfRiver() then NEOfRiver = 1 end -- GetRiverSWFlowDirection()
if plot:IsWOfRiver() then WOfRiver = 1 end -- GetRiverEFlowDirection()
if plot:IsNWOfRiver() then NWOfRiver = 1 end -- GetRiverSEFlowDirection()
print("MapToConvert["..plot:GetX().."]["..plot:GetY().."]={"..plot:GetTerrainType()..","..plot:GetPlotType()..","..plot:GetFeatureType()..","..plot:GetContinentArtType()..",{{"..NEOfRiver..","..plot:GetRiverSWFlowDirection().. "},{"..WOfRiver..","..plot:GetRiverEFlowDirection().."},{"..NWOfRiver..","..plot:GetRiverSEFlowDirection().."}},{"..plot:GetResourceType(-1)..","..plot:GetNumResource().."}}")
end
and then copy/paste in YourMap.Lua all the "MapToConvert" lines from the lua.log (removing the "[760818.859] InGame: " part, using a good file editor like Notepad++ because of the size of the text (use shift+alt to select the part to cut)


in any case, if I understand well, with this method is necessary to use a civ5map
something to use the civ6editor to create a map and directly convert ?
Thank you
I really like your works....for civ5 too :)
 
I have managed to pull out some civ6map data using code in YNAMP.

It is in the form of...
Code:
-- Map Data (from Civ6 WB)
    -- MapToConvert[x][y] = {civ6TerrainType, civ6FeatureTypes, civ6ContinentType, {{IsNEOfRiver, flow}, {IsWOfRiver, flow}, {IsNWOfRiver, flow}}, {Civ6ResourceType, num}, {IsNEOfCliff, IsWOfCliff, IsNWOfCliff} }

    MapToConvert[0][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[1][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[2][0]={3,-1,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[3][0]={3,-1,42,{{0,-1},{0,-1},{0,-1}},{9,1},{0,0,0}}
    MapToConvert[4][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[5][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[6][0]={4,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[7][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[8][0]={3,-1,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[9][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[10][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}

I didn't print out all of it here of course.

Now I am having a hard time doing anything useful with it. What I want to do is print out the map as specified, and then randomize resources and place natural wonders. (although they may be in the feature type data for all I know.

I have tried replacing YNAMP MapToConvert values with my MapToConvert and porting that over to my mod, but after the leader screen appears, I am kicked out of the program in short order. I then went through YNAMP into the AssigntStartPlots and pulled out some code to import civ6map data. I tried to add tha into a map file, but am still getting kicked. Finally, I have tried adding AssignStartPlots as an override, but also failed.

What I really need it a simplified template which I can simply plug in my MapToConvert data and put in the coordinates to add 3 natural wonders and code to randomize, respawn, the resources. I feel this is likely fairly easily done, but I can't seem to figure it out between wondering what component the map script should be a part of and how the script should be set up.

PS I guess I would also need to spread goodie huts.
 
have you edited the g_iW and g_iH values to fit your map Width and Height ?
 
This is my latest iteration... it has been considerably changed over time, and this may not be the best try. I cludged together something using the "PlayEuropeAgain" map in YNAMP and pasting over various parts with items found in AssignStartingPlots (notably "function ImportCiv6Map") and adjusted the code to suit. I have used iterations where I simply pasted over the PlayEuropeAgain MapToConvert section and not changed anything else, (Changing Map grid) but that never worked either. i have also included and not included an override for AssignStartingPlots but that also failed (although Civ 6 froze rather than crashing to desk top in that case). Finally, I have used different modinfo setups to see if that was where the problem lay, without success.

Code:
------------------------------------------------------------------------------
--    FILE:     PlayEuropeAgain.Lua
--  Hormigas
--  Imported to Civ VI by Gedemon (2016)
------------------------------------------------------------------------------

include "MapEnums"
include "MapUtilities"
include "MountainsCliffs"
include "RiversLakes"
include "FeatureGenerator"
include "TerrainGenerator"
include "NaturalWonderGenerator"
include "ResourceGenerator"
include "AssignStartingPlots"

local mapName = MapConfiguration.GetValue("MapName")
print("Loading "..tostring(mapName).." script")

local g_iW = 135
local g_iH = 81
local g_iFlags = {}
local g_continentsFrac = nil

------------------------------------------------------------------------------
-- The application side will call GetMapScriptInfo directly to request
-- information about the map script.
-------------------------------------------------------------------------------
function GetMapInitData(worldSize)
    return {
        Width = g_iW,
        Height = g_iH,
        WrapX = false,
        WrapY = false,
    };     
end

-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
function GenerateMap()
    print("Calling Map Generator");
    -- Everything has been moved to the modded AssignStartingPlots in the "override" folder, search for "YnAMP" string in that file
    GenerateImportedMap(GetMap(), ImportCiv6Map(), GetNaturalWonders(), g_iW, g_iH)
        
end

function GetNaturalWonders()
    --[[local NaturalWonders = {}   
        
    NaturalWonders[GameInfo.Features["FEATURE_CLIFFS_DOVER"].Index]     = { X = 30, Y = 59}    -- 2 plots, hills on coast, 1st plot is WEST
    NaturalWonders[GameInfo.Features["FEATURE_DEAD_SEA"].Index]         = { X = 83, Y = 10}    -- 2 plots, flat desert surrounded by desert, 1st plot is SOUTHWEST

    if GameInfo.Features["FEATURE_EYJAFJALLAJOKULL"] then -- Vikings DLC is loaded
    NaturalWonders[GameInfo.Features["FEATURE_EYJAFJALLAJOKULL"].Index]    = { X = 12, Y = 88}    -- 2 plots EAST-WEST, flat tundra/plains without features, 1st plot is WEST (YOSEMITE rule)
    NaturalWonders[GameInfo.Features["FEATURE_LYSEFJORDEN"].Index]         = { X = 43, Y = 72}    -- 3 plots, , flat grass near coast, 1st plot is EAST
    NaturalWonders[GameInfo.Features["FEATURE_GIANTS_CAUSEWAY"].Index]     = { X = 23, Y = 71}    -- 2 plots, one on coastal land and one in water, 1st plot is land, SOUTHEAST
    end
    
    return NaturalWonders]]
end


function ImportCiv6Map(MapToConvert, g_iW, g_iH, bDoTerrains, bImportRivers, bImportFeatures, bImportResources, bImportContinents)
    print("Importing Civ6 Map ( Terrain = "..tostring(bDoTerrains)..", Rivers = "..tostring(bImportRivers)..", Features = "..tostring(bImportFeatures)..", Resources = "..tostring(bImportResources)..", Continents = "..tostring(bImportContinents)..")")
    local count = 0
        
    bOutput = false
    for i = 0, (g_iW * g_iH) - 1, 1 do
        plot = Map.GetPlotByIndex(i)
        if bOutput then
            print("----------")
            print("Convert plot at "..plot:GetX()..","..plot:GetY())
        end
        -- Map Data
        -- MapToConvert[x][y] = {civ6TerrainType, civ6FeatureType, civ6ContinentType, {{IsNEOfRiver, flow}, {IsWOfRiver, flow}, {IsNWOfRiver, flow}}, {Civ6ResourceType, num} }
        local civ6TerrainType = MapToConvert[plot:GetX()][plot:GetY()][1]
        local civ6FeatureType = MapToConvert[plot:GetX()][plot:GetY()][2]
        local civ6ContinentType = MapToConvert[plot:GetX()][plot:GetY()][3]
        local Rivers = MapToConvert[plot:GetX()][plot:GetY()][4] -- = {{IsNEOfRiver, flow}, {IsWOfRiver, flow}, {IsNWOfRiver, flow}}
        local resource = MapToConvert[plot:GetX()][plot:GetY()][5] -- = {Civ6ResourceType, num}
        local Cliffs =  MapToConvert[plot:GetX()][plot:GetY()][6] -- {IsNEOfCliff,IsWOfCliff,IsNWOfCliff}
        
        -- Set terrain type
        if bDoTerrains then
            if bOutput then print(" - Set Terrain Type = "..tostring(GameInfo.Terrains[civ6TerrainType].TerrainType)) end
            count = count + 1
            TerrainBuilder.SetTerrainType(plot, civ6TerrainType)
        end
        
        -- Set Rivers
        if bImportRivers then
            if Rivers[1][1] == 1 then -- IsNEOfRiver
                TerrainBuilder.SetNEOfRiver(plot, true, Rivers[1][2])
                if bOutput then print(" - Set is NE of River, flow = "..tostring(Rivers[1][2])) end
            end
            if Rivers[2][1] == 1 then -- IsWOfRiver
                TerrainBuilder.SetWOfRiver(plot, true, Rivers[2][2])
                if bOutput then print(" - Set is W of River, flow = "..tostring(Rivers[2][2])) end
            end
            if Rivers[3][1] == 1 then -- IsNWOfRiver
                TerrainBuilder.SetNWOfRiver(plot, true, Rivers[3][2])
                if bOutput then print(" - Set is NW of River, flow = "..tostring(Rivers[3][2])) end
            end
        end
        
        -- Set Features
        if bImportFeatures then
            if civ6FeatureType ~= g_FEATURE_NONE and civ6FeatureType < GameInfo.Features["FEATURE_BARRIER_REEF"].Index then -- Do not import Natural Wonder here !
                if bOutput then print(" - Set Feature Type = "..tostring(GameInfo.Features[civ6FeatureType].FeatureType)) end
                TerrainBuilder.SetFeatureType(plot, civ6FeatureType)
            end
        end
        
        -- Set Continent
        if bImportContinents then
            if civ6ContinentType ~= -1 then       
                if bOutput then print(" - Set Continent Type = "..tostring(GameInfo.Continents[civ6ContinentType].ContinentType)) end
                TerrainBuilder.SetContinentType(plot, civ6ContinentType)
            end
        end
        
        -- Set Resources
        if bImportResources and not plot:IsNaturalWonder() then
            if resource[1] ~= -1 then       
                if bOutput then print(" - Set Resource Type = "..tostring(GameInfo.Resources[resource[1]].ResourceType)) end
                --ResourceBuilder.SetResourceType(plot, ResourceCiv5toCiv6[resource[1]], resource[2]) -- maybe an option to import number of resources on one plot even if civ6 use 1 ?
                ResourceBuilder.SetResourceType(plot, resource[1], 1)
            end
        end
        
        -- Set Cliffs
        if Cliffs then
            if Cliffs[1] == 1 then -- IsNEOfCliff
                TerrainBuilder.SetNEOfCliff(plot, true)
                if bOutput then print(" - Set is NE of Cliff") end
            end
            if Cliffs[2] == 1 then -- IsWOfCliff
                TerrainBuilder.SetWOfCliff(plot, true)
                if bOutput then print(" - Set is W of Cliff") end
            end
            if Cliffs[3] == 1 then -- IsNWOfCliff
                TerrainBuilder.SetNWOfCliff(plot, true)
                if bOutput then print(" - Set is NW of Cliff") end
            end   
        end
        
    end   
    
    print("Placed terrain on "..tostring(count) .. " tiles")
end

function GetMap()

    local MapToConvert = {}
    for i = 0, g_iW - 1, 1 do
        MapToConvert[i] = {}
    end
    
    -- Map Data (from Civ6 WB)
    -- MapToConvert[x][y] = {civ6TerrainType, civ6FeatureTypes, civ6ContinentType, {{IsNEOfRiver, flow}, {IsWOfRiver, flow}, {IsNWOfRiver, flow}}, {Civ6ResourceType, num}, {IsNEOfCliff, IsWOfCliff, IsNWOfCliff} }

    MapToConvert[0][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[1][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[2][0]={3,-1,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[3][0]={3,-1,42,{{0,-1},{0,-1},{0,-1}},{9,1},{0,0,0}}
    MapToConvert[4][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[5][0]={3,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[6][0]={4,3,42,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    
    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    
    MapToConvert[131][80]={16,-1,-1,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[132][80]={16,-1,-1,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[133][80]={16,-1,-1,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}
    MapToConvert[134][80]={16,-1,-1,{{0,-1},{0,-1},{0,-1}},{-1,1},{0,0,0}}

    
    
    return MapToConvert
end

Thank-you.
 
for what you want, try to replace the
Code:
GenerateImportedMap(GetMap(), ImportCiv6Map(), GetNaturalWonders(), g_iW, g_iH)
line in your code by those lines
Code:
ImportCiv6Map(GetMap(), g_iW, g_iH, true,  true,  true, false, true)

TerrainBuilder.AnalyzeChokepoints()

resourcesConfig = MapConfiguration.GetValue("resources");
local args = {
    resources = resourcesConfig,
};
ResourceGenerator.Create(args);

local startConfig = MapConfiguration.GetValue("start");-- Get the start config
-- START_MIN_Y and START_MAX_Y is the percent of the map ignored for major civs' starting positions.
local args = {
    MIN_MAJOR_CIV_FERTILITY = 150,
    MIN_MINOR_CIV_FERTILITY = 50,
    MIN_BARBARIAN_FERTILITY = 1,
    START_MIN_Y = 15,
    START_MAX_Y = 15,
    START_CONFIG = startConfig,
}
local start_plot_database = AssignStartingPlots.Create(args)
local GoodyGen = AddGoodies(g_iW, g_iH)
 
No dice... I don't want you to put anymore energy into this. Thank-you for the effort and assistance, but the work will likely be all for naught when a better version of worldbuilder is released (similar to civ 5 builder's capabilities).

I may try to make the map backward compatible with YNAMP instead because hacking parts of the code into my own mod as that doesn't seem to be working. Once I get a map file that works within YNAMP, I will start deleting stuff to trim the mod to just my map requirements.

You'll of course be credited :).
 
Phew! I've just recovered from the Post-NubianPatch-GameCrash-Disorder...

I'm painstakingly drawing a Mediterranean map in civ6 worldbuilder for a scenario/mod and while it (still) loads and plays using TZ method, I'd really like to convert it to lua script. I am a complete noob to lua programing and I need help with this.
I found Gedemon's code
Spoiler Gedemon's code :
for iPlotLoop = 0, Map.GetNumPlots()-1, 1 do
local plot = Map.GetPlotByIndex(iPlotLoop)
local NEOfRiver = 0
local WOfRiver = 0
local NWOfRiver = 0
if plot:IsNEOfRiver() then NEOfRiver = 1 end -- GetRiverSWFlowDirection()
if plot:IsWOfRiver() then WOfRiver = 1 end -- GetRiverEFlowDirection()
if plot:IsNWOfRiver() then NWOfRiver = 1 end -- GetRiverSEFlowDirection()
print("MapToConvert["..plot:GetX().."]["..plot:GetY().."]={"..plot:GetTerrainType()..","..plot:GetPlotType()..","..plot:GetFeatureType()..","..plot:GetContinentArtType()..",{{"..NEOfRiver..","..plot:GetRiverSWFlowDirection().. "},{"..WOfRiver..","..plot:GetRiverEFlowDirection().."},{"..NWOfRiver..","..plot:GetRiverSEFlowDirection().."}},{"..plot:GetResourceType(-1)..","..plot:GetNumResource().."}}")
end
but it didn't work for me. I tried pasting itin Firetuner, but it just returned a syntax error "function expected instead of nil". I must have been doing it wrong way...

Can someone please help me out with this? (Gedemon? :please:) I need detailed instructions on how to extract the plot info from a map. Thanks in advance!
 
for civ6 I use this code to export the map data to a table format (from a script context, like GameCore_Tuner)
Code:
    local iPlotCount = Map.GetPlotCount();
    for iPlotLoop = 0, iPlotCount-1, 1 do
        local bData = false
        local plot = Map.GetPlotByIndex(iPlotLoop)
        local NEOfCliff = 0
        local WOfCliff = 0
        local NWOfCliff = 0
        if plot:IsNEOfCliff() then NEOfCliff = 1 end
        if plot:IsWOfCliff() then WOfCliff = 1 end
        if plot:IsNWOfCliff() then NWOfCliff = 1 end
        local NEOfRiver = 0
        local WOfRiver = 0
        local NWOfRiver = 0
        if plot:IsNEOfRiver() then NEOfRiver = 1 end -- GetRiverSWFlowDirection()
        if plot:IsWOfRiver() then WOfRiver = 1 end -- GetRiverEFlowDirection()
        if plot:IsNWOfRiver() then NWOfRiver = 1 end -- GetRiverSEFlowDirection()
        print("MapToConvert["..plot:GetX().."]["..plot:GetY().."]={"..plot:GetTerrainType()..","..plot:GetFeatureType()..","..plot:GetContinentType()..",{{"..NEOfRiver..","..plot:GetRiverSWFlowDirection().. "},{"..WOfRiver..","..plot:GetRiverEFlowDirection().."},{"..NWOfRiver..","..plot:GetRiverSEFlowDirection().."}},{"..plot:GetResourceType(-1)..","..tostring(1).."},{"..NEOfCliff..","..WOfCliff..","..NWOfCliff.."}}")
    end

then look after "-- Imported Maps Creation" in YnAMP's AssignStartingPlots.lua file for all the function used to create the map from the table, it's possible to extract just the needed part from there to a single mapscript file but I won't have the time to do that.

The simpler way (not so simple) for you may be to edit one of the example additional map for YnAMP (found in addons) swapping the map table with the one generated with the code above in the lua file (removing the first columns so each line of the table start with "MapToConvert"), changing the folder names, map names and mod's ID and let YnAMP handle the rest...

I still plan to make a tutorial, but free time is always a constraint...
 
Wow, that's... that's magic! Eternally grateful, Gedemon!

I'll surely use one of your YnAMP maps as a template, it's easier to implement the code and I can learn some basics that way, too.

Thank you for your great work and inspiration you give us!
 
Back
Top Bottom