First you need to learn a bit about the modinfo file to setup the mod, something like that (with your own GUID)
Then in Config.xml
and in YourMap.lua
Note that some line are commented out, like
You may reactivate them by removing the "--" at the beginning, it's
very important for resources:
because if your imported map doesn't have any, the game won't find starting positions for the civilizations.
There are also 3 mandatory things to change in this file:
The Width and Height here: (and maybe WrapX for an regional map)
and here
to match your map size.
and of course all the
lines at the end of the file (but do not overwrite the 2 final lines !)
Now to get the MapToConvert data, use this code in civ5 (in firetuner for example)
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)
HTML:
<?xml version="1.0" encoding="utf-8"?>
<Mod id="any_GUID" version="23">
<Properties>
<Name>Your Mod Name</Name>
<Stability>Alpha</Stability>
<Teaser>ttt</Teaser>
<Description>ddd</Description>
<Authors>xxx</Authors>
</Properties>
<Dependencies />
<References />
<Blocks />
<Settings>
<Custom>
<Items>
<File>Config.xml</File>
</Items>
</Custom>
</Settings>
<Components>
<ImportFiles>
<Items>
<File>YourMap.lua</File>
</Items>
</ImportFiles>
</Components>
<Files>
<File>YourMap.lua</File>
<File>Config.xml</File>
</Files>
</Mod>
Then in Config.xml
HTML:
<GameInfo>
<Maps>
<Row File="YourMap.lua" Name="Your Map" Description="The map description" SortIndex="1"/>
</Maps>
</GameInfo>
and in YourMap.lua
PHP:
------------------------------------------------------------------------------
-- FILE: YourMap.Lua
--
------------------------------------------------------------------------------
include "MapEnums"
include "MapUtilities"
include "MountainsCliffs"
include "RiversLakes"
include "FeatureGenerator"
include "TerrainGenerator"
include "NaturalWonderGenerator"
include "ResourceGenerator"
include "AssignStartingPlots"
print("LoadingYour map")
local g_iW, g_iH;
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 = 180,
Height = 94,
WrapX = true,
WrapY = false,
};
end
-------------------------------------------------------------------------------
function GenerateMap()
print("Generating Your Map");
local pPlot;
-- Set globals
g_iW, g_iH = 180, 94;
g_iFlags = TerrainBuilder.GetFractalFlags();
ImportMap()
-- Temp
AreaBuilder.Recalculate();
local biggest_area = Areas.FindBiggestArea(false);
print("After Adding Hills: ", biggest_area:GetPlotCount());
-- River generation is affected by plot types, originating from highlands and preferring to traverse lowlands.
--AddRivers();
--AddFeatures();
local args = {
numberToPlace = GameInfo.Maps[Map.GetMapSize()].NumNaturalWonders,
};
--local nwGen = NaturalWonderGenerator.Create(args);
AreaBuilder.Recalculate();
TerrainBuilder.AnalyzeChokepoints();
TerrainBuilder.StampContinents();
resourcesConfig = MapConfiguration.GetValue("resources");
local args = {
resources = resourcesConfig,
};
--ResourceGenerator.Create(args);
print("Creating start plot database.");
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);
end
function AddFeatures()
print("Adding Features");
-- Get Rainfall setting input by user.
local rainfall = MapConfiguration.GetValue("rainfall");
if rainfall == 4 then
rainfall = 1 + TerrainBuilder.GetRandomNumber(3, "Random Rainfall - Lua");
end
local args = {rainfall = rainfall}
local featuregen = FeatureGenerator.Create(args);
featuregen:AddFeatures();
end
--[[
ENUM from Civ5
ResourceType
[0] = RESOURCE_IRON
[1] = RESOURCE_HORSE
[2] = RESOURCE_COAL
[3] = RESOURCE_OIL
[4] = RESOURCE_ALUMINUM
[5] = RESOURCE_URANIUM
[6] = RESOURCE_WHEAT
[7] = RESOURCE_COW
[8] = RESOURCE_SHEEP
[9] = RESOURCE_DEER
[10] = RESOURCE_BANANA
[11] = RESOURCE_FISH
[12] = RESOURCE_STONE
[13] = RESOURCE_WHALE
[14] = RESOURCE_PEARLS
[15] = RESOURCE_GOLD
[16] = RESOURCE_SILVER
[17] = RESOURCE_GEMS
[18] = RESOURCE_MARBLE
[19] = RESOURCE_IVORY
[20] = RESOURCE_FUR
[21] = RESOURCE_DYE
[22] = RESOURCE_SPICES
[23] = RESOURCE_SILK
[24] = RESOURCE_SUGAR
[25] = RESOURCE_COTTON
[26] = RESOURCE_WINE
[27] = RESOURCE_INCENSE
[28] = RESOURCE_JEWELRY
[29] = RESOURCE_PORCELAIN
[30] = RESOURCE_COPPER
[31] = RESOURCE_SALT
[32] = RESOURCE_CRAB
[33] = RESOURCE_TRUFFLES
[34] = RESOURCE_CITRUS
[40] = RESOURCE_BISON
[41] = RESOURCE_COCOA
civ6
[0] = RESOURCE_BANANAS
[1] = RESOURCE_CATTLE
[2] = RESOURCE_COPPER
[3] = RESOURCE_CRABS
[4] = RESOURCE_DEER
[5] = RESOURCE_FISH
[6] = RESOURCE_RICE
[7] = RESOURCE_SHEEP
[8] = RESOURCE_STONE
[9] = RESOURCE_WHEAT
[10] = RESOURCE_CITRUS
[11] = RESOURCE_COCOA
[12] = RESOURCE_COFFEE
[13] = RESOURCE_COTTON
[14] = RESOURCE_DIAMONDS
[15] = RESOURCE_DYES
[16] = RESOURCE_FURS
[17] = RESOURCE_GYPSUM
[18] = RESOURCE_INCENSE
[19] = RESOURCE_IVORY
[20] = RESOURCE_JADE
[21] = RESOURCE_MARBLE
[22] = RESOURCE_MERCURY
[23] = RESOURCE_PEARLS
[24] = RESOURCE_SALT
[25] = RESOURCE_SILK
[26] = RESOURCE_SILVER
[27] = RESOURCE_SPICES
[28] = RESOURCE_SUGAR
[29] = RESOURCE_TEA
[30] = RESOURCE_TOBACCO
[31] = RESOURCE_TRUFFLES
[32] = RESOURCE_WHALES
[33] = RESOURCE_WINE
[40] = RESOURCE_ALUMINUM
[41] = RESOURCE_COAL
[42] = RESOURCE_HORSES
[43] = RESOURCE_IRON
[44] = RESOURCE_NITER
[45] = RESOURCE_OIL
[46] = RESOURCE_URANIUM
FeaturesType
[0] = FEATURE_ICE ----> 1
[1] = FEATURE_JUNGLE ----> 2
[2] = FEATURE_MARSH ----> 5
[3] = FEATURE_OASIS ----> 4
[4] = FEATURE_FLOOD_PLAINS ----> 0
[5] = FEATURE_FOREST ----> 3
[6] = FEATURE_FALLOUT
[7] = FEATURE_CRATER
[8] = FEATURE_FUJI
[9] = FEATURE_MESA
[10] = FEATURE_REEF ----> 6
[11] = FEATURE_VOLCANO
[12] = FEATURE_GIBRALTAR
[13] = FEATURE_GEYSER
[14] = FEATURE_FOUNTAIN_YOUTH
[15] = FEATURE_POTOSI
[16] = FEATURE_EL_DORADO
[17] = FEATURE_ATOLL
[18] = FEATURE_SRI_PADA
[19] = FEATURE_MT_SINAI
[20] = FEATURE_MT_KAILASH
[21] = FEATURE_ULURU
[22] = FEATURE_LAKE_VICTORIA
[23] = FEATURE_KILIMANJARO ----> 12
[24] = FEATURE_SOLOMONS_MINES
PlotType
[0] = PLOT_MOUNTAIN
[1] = PLOT_HILLS
[2] = PLOT_LAND
[3] = PLOT_OCEAN
TerrainTypes
[0] = TERRAIN_GRASS,
[1] = TERRAIN_PLAINS,
[2] = TERRAIN_DESERT,
[3] = TERRAIN_TUNDRA,
[4] = TERRAIN_SNOW,
[5] = TERRAIN_COAST,
[6] = TERRAIN_OCEAN,
FeatureTypes
[0] = FEATURE_ICE,
[1] = FEATURE_JUNGLE,
[2] = FEATURE_MARSH,
[3] = FEATURE_OASIS,
[4] = FEATURE_FLOOD_PLAINS,
[5] = FEATURE_FOREST,
[6] = FEATURE_FALLOUT,
[7] = FEATURE_ATOLL,
Continental Art Set
[0] = Ocean
[1] = America
[2] = Asia
[3] = Africa
[4] = Europe
Rivers (same for civ6)
[0] = FLOWDIRECTION_NORTH
[1] = FLOWDIRECTION_NORTHEAST
[2] = FLOWDIRECTION_SOUTHEAST
[3] = FLOWDIRECTION_SOUTH
[4] = FLOWDIRECTION_SOUTHWEST
[5] = FLOWDIRECTION_NORTHWEST
Directions (same for civ6)
[0] = DIRECTION_NORTHEAST
[1] = DIRECTION_EAST
[2] = DIRECTION_SOUTHEAST
[3] = DIRECTION_SOUTHWEST
[4] = DIRECTION_WEST
[5] = DIRECTION_NORTHWEST
-- Code to export the civ5 map
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
--]]
function ImportMap()
local MapToConvert = GetMap()
local count = 0
-- Civ5 ENUM
PLOT_MOUNTAIN = 0
PLOT_HILLS = 1
-- Civ5 to Civ6
local FeaturesCiv5toCiv6 = {}
for i = 0, 24 do FeaturesCiv5toCiv6[i] = g_FEATURE_NONE end
FeaturesCiv5toCiv6[0] = g_FEATURE_ICE
FeaturesCiv5toCiv6[1] = g_FEATURE_JUNGLE
FeaturesCiv5toCiv6[2] = g_FEATURE_MARSH
FeaturesCiv5toCiv6[3] = g_FEATURE_OASIS
FeaturesCiv5toCiv6[4] = g_FEATURE_FLOODPLAINS
FeaturesCiv5toCiv6[5] = g_FEATURE_FOREST
-- Natural wonders may require a special coding
FeaturesCiv5toCiv6[10] = g_FEATURE_BARRIER_REEF
--FeaturesCiv5toCiv6[23] = g_FEATURE_KILIMANJARO
local ResourceCiv5toCiv6 = {}
for i = 0, 41 do ResourceCiv5toCiv6[i] = -1 end
ResourceCiv5toCiv6[4]= 40 -- ALUMINUM
ResourceCiv5toCiv6[10]= 0 -- BANANAS
ResourceCiv5toCiv6[40]= 16 -- BISON to FURS
ResourceCiv5toCiv6[7]= 1 -- CATTLE
ResourceCiv5toCiv6[34]= 10 -- CITRUS
ResourceCiv5toCiv6[2]= 41 -- COAL
ResourceCiv5toCiv6[41]= 11 -- COCOA
ResourceCiv5toCiv6[30]= 2 -- COPPER
ResourceCiv5toCiv6[25]= 13 -- COTTON
ResourceCiv5toCiv6[32]= 3 -- CRABS
ResourceCiv5toCiv6[9]= 4 -- DEER
ResourceCiv5toCiv6[17]= 14 -- DIAMONDS
ResourceCiv5toCiv6[21]= 15 -- DYES
ResourceCiv5toCiv6[11]= 5 -- FISH
ResourceCiv5toCiv6[20]= 16 -- FURS
ResourceCiv5toCiv6[15]= 44 -- GOLD to NITER
ResourceCiv5toCiv6[1]= 42 -- HORSES
ResourceCiv5toCiv6[27]= 18 -- INCENSE
ResourceCiv5toCiv6[0]= 43 -- IRON
ResourceCiv5toCiv6[19]= 19 -- IVORY
ResourceCiv5toCiv6[28]= 20 -- JADE
ResourceCiv5toCiv6[18]= 21 -- MARBLE
ResourceCiv5toCiv6[3]= 45 -- OIL
ResourceCiv5toCiv6[14]= 23 -- PEARLS
ResourceCiv5toCiv6[31]= 24 -- SALT
ResourceCiv5toCiv6[8]= 7 -- SHEEP
ResourceCiv5toCiv6[23]= 25 -- SILK
ResourceCiv5toCiv6[16]= 26 -- SILVER
ResourceCiv5toCiv6[22]= 27 -- SPICES
ResourceCiv5toCiv6[12]= 8 -- STONE
ResourceCiv5toCiv6[24]= 28 -- SUGAR
ResourceCiv5toCiv6[33]= 31 -- TRUFFLES
ResourceCiv5toCiv6[5]= 46 -- URANIUM
ResourceCiv5toCiv6[13]= 32 -- WHALES
ResourceCiv5toCiv6[6]= 9 -- WHEAT
ResourceCiv5toCiv6[26]= 33 -- WINE
for i = 0, (g_iW * g_iH) - 1, 1 do
plot = Map.GetPlotByIndex(i)
print("----------")
print("Convert plot at "..plot:GetX()..","..plot:GetY())
-- Map Data
-- MapToConvert[x][y] = {civ5TerrainType, civ5PlotTypes, civ5FeatureTypes, civ5ContinentType, {{IsNEOfRiver, flow}, {IsWOfRiver, flow}, {IsNWOfRiver, flow}}, {Civ5ResourceType, num} }
local civ5TerrainType = MapToConvert[plot:GetX()][plot:GetY()][1]
local civ5PlotTypes = MapToConvert[plot:GetX()][plot:GetY()][2]
local civ5FeatureTypes = MapToConvert[plot:GetX()][plot:GetY()][3]
local civ5ContinentType = MapToConvert[plot:GetX()][plot:GetY()][4]
local rivers = MapToConvert[plot:GetX()][plot:GetY()][5] -- = {{IsNEOfRiver, flow}, {IsWOfRiver, flow}, {IsNWOfRiver, flow}}
local resource = MapToConvert[plot:GetX()][plot:GetY()][6] -- = {Civ5ResourceType, num}
-- Set terrain type
local civ6TerrainType = g_TERRAIN_TYPE_OCEAN
if civ5TerrainType == 5 then civ6TerrainType = g_TERRAIN_TYPE_COAST
elseif civ5TerrainType ~= 6 then
-- the code below won't work if the order is changed in the terrains table
-- entrie for civ5 are: 0 = GRASS, 1= PLAINS, ...
-- entries for civ6 are: 0 = GRASS, 1= GRASS_HILL, 2 = GRASS_MOUNTAIN, 3= PLAINS, 4 = PLAINS_HILL, ...
civ6TerrainType = civ5TerrainType * 3 -- civ5TerrainType * 3 0-0 1-3 2-6 3-9 4-12
if civ5PlotTypes == PLOT_HILLS then
civ6TerrainType = civ6TerrainType + g_TERRAIN_BASE_TO_HILLS_DELTA
elseif civ5PlotTypes == PLOT_MOUNTAIN then
civ6TerrainType = civ6TerrainType + g_TERRAIN_BASE_TO_MOUNTAIN_DELTA
end
end
print(" - Set Terrain Type = "..tostring(GameInfo.Terrains[civ6TerrainType].TerrainType))
count = count + 1
TerrainBuilder.SetTerrainType(plot, civ6TerrainType)
-- Set rivers
if rivers[1][1] == 1 then -- IsNEOfRiver
TerrainBuilder.SetNEOfRiver(plot, true, rivers[1][2])
print(" - Set is NE of river, flow = "..tostring(rivers[1][2]))
end
if rivers[2][1] == 1 then -- IsWOfRiver
TerrainBuilder.SetWOfRiver(plot, true, rivers[2][2])
print(" - Set is W of river, flow = "..tostring(rivers[2][2]))
end
if rivers[3][1] == 1 then -- IsNWOfRiver
TerrainBuilder.SetNWOfRiver(plot, true, rivers[3][2])
print(" - Set is NW of river, flow = "..tostring(rivers[3][2]))
end
-- Set Features
if civ5FeatureTypes ~= -1 and FeaturesCiv5toCiv6[civ5FeatureTypes] ~= g_FEATURE_NONE then
print(" - Set Feature Type = "..tostring(GameInfo.Features[FeaturesCiv5toCiv6[civ5FeatureTypes]].FeatureType))
TerrainBuilder.SetFeatureType(plot, FeaturesCiv5toCiv6[civ5FeatureTypes])
end
-- Set Resources
if resource[1] ~= -1 and ResourceCiv5toCiv6[resource[1]] ~= -1 then
print(" - Set Resource Type = "..tostring(GameInfo.Resources[ResourceCiv5toCiv6[resource[1]]].ResourceType))
ResourceBuilder.SetResourceType(plot, ResourceCiv5toCiv6[resource[1]], resource[2])
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
-- MapToConvert[x][y] = {civ5TerrainType, civ5PlotTypes, civ5FeatureTypes, civ5ContinentType, {{IsNEOfRiver, flow}, {IsWOfRiver, flow}, {IsNWOfRiver, flow}}, {Civ5ResourceType, num} }
MapToConvert[0][0]={5,3,0,4,{{0,-1},{0,-1},{0,-1}},{-1,0}}
MapToConvert[1][0]={5,3,0,4,{{0,-1},{0,-1},{0,-1}},{-1,0}}
MapToConvert[2][0]={5,3,0,4,{{0,-1},{0,-1},{0,-1}},{-1,0}}
MapToConvert[3][0]={4,1,-1,3,{{0,-1},{0,-1},{0,-1}},{-1,0}}
MapToConvert[4][0]={5,3,0,0,{{0,-1},{0,-1},{0,-1}},{-1,0}}
-- of course there will be a lot more lines here...
MapToConvert[176][93]={5,3,0,4,{{0,-1},{0,-1},{0,-1}},{-1,0}}
MapToConvert[177][93]={5,3,0,4,{{0,-1},{0,-1},{0,-1}},{-1,0}}
MapToConvert[178][93]={5,3,0,4,{{0,-1},{0,-1},{0,-1}},{-1,0}}
MapToConvert[179][93]={4,0,-1,1,{{0,-1},{0,-1},{0,-1}},{-1,0}}
return MapToConvert
end
Note that some line are commented out, like
PHP:
--AddRivers();
--AddFeatures();
You may reactivate them by removing the "--" at the beginning, it's
very important for resources:
PHP:
ResourceGenerator.Create(args)
because if your imported map doesn't have any, the game won't find starting positions for the civilizations.
There are also 3 mandatory things to change in this file:
The Width and Height here: (and maybe WrapX for an regional map)
PHP:
function GetMapInitData(worldSize)
return {
Width = 180,
Height = 94,
WrapX = true,
WrapY = false,
};
end
and here
PHP:
-- Set globals
g_iW, g_iH = 180, 94;
g_iFlags = TerrainBuilder.GetFractalFlags();
to match your map size.
and of course all the
PHP:
MapToConvert[179][93]={4,0,-1,1,{{0,-1},{0,-1},{0,-1}},{-1,0}}
lines at the end of the file (but do not overwrite the 2 final lines !)
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
Last edited: