Placing Rivers in lua mapscript

Aldollin

Chieftain
Joined
Mar 7, 2017
Messages
87
does anyone have a clever way to place a large amount of rivers in a lua mapscript (in predefined places)?

i am working on a mapscript for my map and i want to have rivers in certain set places
(the map will be a middle earth map with semi-random features/terrains and resources)

i am using sql tables to group plots to regions and to give each region a terraintype, rate of forests, rate of hills etc (similar to how HandyVac made his "randomised mediterranean" mapscript)
what i am wondering is if there is a more effective way of writing the info about my rivers in the database

currenty my best idea is having one line for every river segment, with the x,y coordinates of the plot the river is at, the direction relative to the plot and the flowdirection of the river

before i start doing that i thought ill ask to see if anyone has a better idea
 
That's how I store them in the lua tables for ynamp's script, but I also use a script to generate the table from an existing map then copy it from the lua log if that's your question.
 
so you make a map that has the rivers on it( from hand using the worldbuilder i assume) and then use a script to generate a table for the mapscript to use?
sounds smart, can you share the script?
 
export
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

import
Code:
function ImportCiv6Map(MapToConvert, g_iW, g_iH, bDoTerrains, bImportRivers, bImportFeatures, bImportResources, bImportContinents, bIgnoreCliffs)
    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 ~= -1 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 and not bIgnoreCliffs 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
 
Top Bottom