Is there any way to create a map without touching the world builder?

Zobtzler

Chieftain
Joined
Oct 21, 2017
Messages
95
Location
Sweden
I.e. is there a way to create a custom map using only code (yes, that would mean some 5760 lines of code for every tile on a 96x60 map, but don't worry about that, I already have a method of generating these).
 
yes, just write a mapscript to generate a fixed map, that's how it's done for YnAMP.
 
Well, I've been digging through your YnAMP files a little (as you know per our previous conversation about this) but am a bit overwhelmed with the file structure.

I'm having issues properly understanding what to need and how these scripts and xml/sql files are implemented (mostly the lua files as you seem to divide much of the code into different files, the xml is easier to understand).
 
Well, for a simple map, the structure should be relatively simple:

a reference to the script (let's call it YourMapScript.lua for the example) in the InGameActions ImportFiles section of the Modinfo
Code:
    <InGameActions>
        <ImportFiles id="YourMap_IMPORT">
            <File>YourMapScript.lua</File>
        </ImportFiles>
    <InGameActions>


a XML config file (for example Config.xml)
Code:
<GameInfo>
 
    <Maps>
        <Row File="YourMapScript.lua" Name="LOC_YOURMAP_NAME" Description="LOC_YOURMAP_DESC" SortIndex="50"/>
        <Row Domain="Maps:Expansion1Maps" File="YourMapScript.lua" Name="LOC_YOURMAP_NAME" Description="LOC_YOURMAP_DESC" SortIndex="50"/>
    </Maps>
</GameInfo>

referenced in the FrontEndActions UpdateDatabase section of the Modinfo
Code:
    <FrontEndActions>
        <UpdateDatabase id="YourMap_SETTING">
            <File>Config.xml</File>
        </UpdateDatabase>
    </FrontEndActions>

remember to reference both files in the Files section of the modinfo (if you write it manually)

and finally your map script:
Code:
------------------------------------------------------------------------------
-- Include all file required for the map generation
------------------------------------------------------------------------------
include "MapEnums"
include "MapUtilities"
include "MountainsCliffs"
include "RiversLakes"
include "FeatureGenerator"
include "TerrainGenerator"
include "NaturalWonderGenerator"
include "ResourceGenerator"
include "AssignStartingPlots"


------------------------------------------------------------------------------
-- Set globals
------------------------------------------------------------------------------
local g_iW = 100 -- your map width
local g_iH = 50 -- your map height
local g_iFlags = {}
local g_continentsFrac = nil

------------------------------------------------------------------------------
-- The application side will call GetMapInitDatadirectly to request
-- information about the map script.
-- This allow to use custom size, that will be returned by Map.GetGridSize()
-------------------------------------------------------------------------------
function GetMapInitData(worldSize)
    return {
        Width = g_iW,
        Height = g_iH,
        WrapX = false,
        WrapY = false,
    };
end

-------------------------------------------------------------------------------
-- then the code for the map generation itself, the application side will call GenerateMap()
-- your 5760 lines will be in there
-- see the Firaxis maps for example of code, this part is actually included
-- in YnAMP AssignStartingPlot.lua override, so that I don't have to duplicate it with every map
-------------------------------------------------------------------------------
function GenerateMap()
    -- Set everything to OCEAN
    for i = 0, (g_iW * g_iH) - 1, 1 do
        local pPlot = Map.GetPlotByIndex(i);
        TerrainBuilder.SetTerrainType(pPlot, g_TERRAIN_TYPE_OCEAN);
    end
    AreaBuilder.Recalculate();
    TerrainBuilder.AnalyzeChokepoints();
    TerrainBuilder.StampContinents();
end


It's when you want to use the custom options of YnAMP that the configuration is a bit more complex.
 
Last edited:
After some debugging and fixing errors I get stuck on this issue

Code:
Map Script: In NaturalWonderGenerator.Create()
Map Script:     Placing 4 Natural Wonders
Runtime Error: B:\Steam\steamapps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Utility\NaturalWonderGenerator.lua:347: attempt to index a nil value
stack traceback:
    B:\Steam\steamapps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Utility\NaturalWonderGenerator.lua:347: in function 'CustomGetMultiTileFeaturePlotList'
    (tail call): ?
    B:\Steam\steamapps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Utility\NaturalWonderGenerator.lua:99: in function 'NaturalWonderGenerator:__FindValidLocs'
    B:\Steam\steamapps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Utility\NaturalWonderGenerator.lua:44: in function 'NaturalWonderGenerator.Create'
    B:\Steam\steamapps\workshop\content\289070\871861883\Override\AssignStartingPlots.lua:2799: in function 'GenerateImportedMap'
    C:\Users\Zobtzler\Documents\My Games\Sid Meier's Civilization VI\Mods\Zobtzlers_Americas_Map\LUA\ZobtzlersAmericasMap.lua:47: in function 'GenerateMap'
    [C]: in function '(anonymous)'
Lua callstack:
Runtime Error: Call to GenerateMap() had errors
stack traceback:
    [C]: in function '(anonymous)'
LoadScreen: OnLoadGameViewStateDone
Mods: Failed to create mods browser search context!

The line 47 in my file being this

Code:
GenerateImportedMap(GetMap(), GetCiv6DataToConvert(), GetNaturalWonders(), g_iW, g_iH);

This error shows up regardless if I place 4 natural wonders on the map or not.

Do you happen to know what this error means and what might be wrong?
 
looks like you're trying to place a NW on an edge of a non-warped map.

Start at the top when looking for an error, in that case NaturalWonderGenerator.lua:347, I suppose that one of the plot is nil

Code:
                if (pWaterCheck1:IsWater() == false or pWaterCheck2:IsWater() == false or pWaterCheck3:IsWater() == false) then
 
what are the placement options for your NW in you map config file ? (or do you have set such an option ? if not, how do you select the number of NW to place ?)
 
Well the config file is kinda... empty so to speak.
Code:
<GameInfo>
    <Maps>
        <Row File="ZobtzlersAmericasMap.lua" Name="LOC_ZobtzlersAmericasMap_NAME" Description="LOC_ZobtzlersAmericasMap_DESC" SortIndex="50"/>
        <Row Domain="Maps:Expansion1Maps" File="ZobtzlersAmericasMap.lua" Name="LOC_ZobtzlersAmericasMapP_NAME" Description="LOC_ZobtzlersAmericasMap_DESC" SortIndex="50"/>
    </Maps>
</GameInfo>

The only thing that I can think of (or rather, what I think I understand you mean) is this code snippet from the cordiform earth config file

Code:
<Row Key1="Map" Key2="CordiformEarth.lua" ParameterId="NaturalWondersPlacement" Name="LOC_MAP_NATURAL_WONDERS_PLACEMENT_NAME" Description="LOC_MAP_NATURAL_WONDERS_PLACEMENT_DESCRIPTION" Domain="NaturalWondersPlacement" DefaultValue="PLACEMENT_IMPORT" ConfigurationGroup="Map" ConfigurationId="NaturalWondersPlacement" GroupId="MapOptions" Hash="0" SortIndex="244"/>
 
let me ask differently: how do you (not) "put down any natural wonders" ?

edit: or how do you place them ATM ?
 
Code:
function GetNaturalWonders()
    local NaturalWonders = {}
   
    NaturalWonders[GameInfo.Features["FEATURE_KILIMANJARO"].Index]         = { X = 1, Y = 1}   
    NaturalWonders[GameInfo.Features["FEATURE_PANTANAL"].Index]         = { X = 11, Y = 1}    
    NaturalWonders[GameInfo.Features["FEATURE_TSINGY"].Index]             = { X = 21, Y = 1}   
    NaturalWonders[GameInfo.Features["FEATURE_TORRES_DEL_PAINE"].Index]  = { X = 31, Y = 1}    

    return NaturalWonders
end

This is the code in the natural wonders section of the lua file... all four are either commented out or not (that's how I assumed you did... right?), but they still produce the same error...
If it seems I'm still not understanding what you mean, you are welcome to look through the files yourself as I've linked them here, as that might be a lot easier
(Disclaimer, the map itself is currently just a placeholder filled with a bunch of stuff pretty much. All tiles have a comment with what they include)
 
try with this in your config file to set the type of NW wonders placement used by YnAMP:

Code:
    <Parameters>
        <Row Key1="Map" Key2="ZobtzlersAmericasMap.lua" ParameterId="NaturalWondersPlacement" Name="LOC_MAP_NATURAL_WONDERS_PLACEMENT_NAME" Description="LOC_MAP_NATURAL_WONDERS_PLACEMENT_DESCRIPTION" Domain="NaturalWondersPlacement" DefaultValue="PLACEMENT_IMPORT" ConfigurationGroup="Map" ConfigurationId="NaturalWondersPlacement" GroupId="MapOptions" Hash="0" SortIndex="244"/>
    </Parameters>

this should show the NW option in the advanced setup, "Import" means using the content of the NaturalWonders table set in the Lua file (or/and in the NaturalWonderPosition table set in the gameplay DB), there is also a "map generator" option (which is the default when the above parameter is not set) and you should also get an "empty" option.
 
Last edited:
Well, that kinda fixes the issue.

It works in "empty" and "import", but crashes at "map generator"

Code:
Map Script: In NaturalWonderGenerator.Create()
Map Script:     Placing 4 Natural Wonders
Runtime Error: B:\Steam\steamapps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Utility\NaturalWonderGenerator.lua:347: attempt to index a nil value
stack traceback:
    B:\Steam\steamapps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Utility\NaturalWonderGenerator.lua:347: in function 'CustomGetMultiTileFeaturePlotList'
    (tail call): ?
    B:\Steam\steamapps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Utility\NaturalWonderGenerator.lua:99: in function 'NaturalWonderGenerator:__FindValidLocs'
    B:\Steam\steamapps\common\Sid Meier's Civilization VI\Base\Assets\Maps\Utility\NaturalWonderGenerator.lua:44: in function 'NaturalWonderGenerator.Create'
    B:\Steam\steamapps\workshop\content\289070\871861883\Override\AssignStartingPlots.lua:2799: in function 'GenerateImportedMap'
    C:\Users\Zobtzler\Documents\My Games\Sid Meier's Civilization VI\Mods\Zobtzlers_Americas_Map\LUA\ZobtzlersAmericasMap.lua:52: in function 'GenerateMap'
    [C]: in function '(anonymous)'
Lua callstack:
Runtime Error: Call to GenerateMap() had errors
stack traceback:
    [C]: in function '(anonymous)'
LoadScreen: OnLoadGameViewStateDone
 
To remove the "map generator" option from the NW placements, just add this in the config file:

Code:
    <!-- Only use those values for a domain -->
    <MapSupportedValues>
        <Row Map="ZobtzlersAmericasMap.lua" Domain="NaturalWondersPlacement" Value="PLACEMENT_IMPORT" />
        <Row Map="ZobtzlersAmericasMap.lua" Domain="NaturalWondersPlacement" Value="PLACEMENT_EMPTY" />
    </MapSupportedValues>
 
Thanks! The map is coming around just fine right now.

COyzekp.png


Also gotten TSL to work.

Quick question about the city naming process...

Code:
<Replace MapName="GiantEarth" X="7" Y="52" CityLocaleName="LOC_CITY_NAME_GIBRALTAR" Area="0" />

This piece of code comes from one of your citymap.xml files. Now, what does "Area" mean, and what does it do when it's either:
1) not included?
2) value = 0?
3) value = 1?
4) value = 2?
5) value is 3 and up...
etc
 
It's the max distance from the x, y coordinates at which the code allows the name to be used when there is no closer name available.

0 means x, y only.
Default when not set is 1
 
Back
Top Bottom