Load map from script

There are possibility to change map at any time in Forest Village from mod script by changeMap function:

fv.core.game:changeMap(info, transferData)


 * info is instance of GameStartInfo class;
 * transferData is optional lua table that will be migrated from map to map.

GameStartInfo class
GameStartInfo class describes target map and stores the same information as New Game menu. It support both generated and custom maps.

You can create empty entry of GameStartInfo and then fill all it values: local info = fv.core.GameStartInfo:new -- filling fields goes here

or you can get info that was used to create current map and then change only needed fields: local info = fv.core.game.gameInfo:getStartGameInfo -- filling fields goes here

Common fields
Common fields are required to fill both for generated and custom maps.

info.gameType = GAMETYPE_DEFAULT info.cityName = "New York" info.difficult = DIFFICULT_NORMAL info.climatType = CLIMAT_SOFT info.disastersModeActive = true info.scenarioName = ""

gameType must be one of the following values:
 * GAMETYPE_DEFAULT
 * GAMETYPE_TUTORIAL

cityName is name of your village (string)

difficult must be one of the following values:
 * DIFFICULT_EASY
 * DIFFICULT_NORMAL
 * DIFFICULT_HARD

climatType must be one of the following values:
 * CLIMAT_SOFT
 * CLIMAT_COLD

disastersModeActive is flag (true or false) that indicate is disasters enabled

scenarioName is id of scenario mod. In most cases you can leave it empty.

Generated map fields
There are also some fields that specific only for random generated maps:

info.generationCode = 13 info.landSize = 512 info.mountainsType = MOUNTAINS_MEDIUM

generationCode is seed number for generation

landSize must be one of the following values:
 * 512
 * 1024
 * 2048

difficult must be one of the following values:
 * MOUNTAINS_SMALL
 * MOUNTAINS_MEDIUM
 * MOUNTAINS_LARGE

Custom map fields
In case of custom maps you need specify customMapPath and optionally customMapInfo fields.

In most cases you need specify it through full pathes to corresponding files in map folder:

info.customMapPath = 'maps/974465187/map.data' info.customMapInfo = fv.core.MapInfo:new( 'maps/974465187/mapinfo.lua' )

But there are still possibility to not set mapinfo at all (all settings will be detected automatically) or set it manually instead like in snippet below:

info.customMapInfo = fv.core.MapInfo:new info.customMapInfo.format = HEIGHTMAP_FORMAT_FLOAT info.customMapInfo.scale = 1 info.customMapInfo.offset = 0 info.customMapInfo.landingInfo.isValid = true info.customMapInfo.landingInfo.position = Vec2( 100, 100 ) info.customMapInfo.landingInfo.radius = 20

Meaning of fields obviously equals to fields from mapinfo.lua.

<font color=AAAA99>format must be one of the following values:
 * HEIGHTMAP_FORMAT_FLOAT
 * HEIGHTMAP_FORMAT_INT32
 * HEIGHTMAP_FORMAT_UINT32
 * HEIGHTMAP_FORMAT_UNKNOWN

<font color=AAAA99>scale — multiplier factor for each value of heightmap

<font color=AAAA99>offset — offset that will be added for each value of heightmap

<font color=AAAA99>landingInfo.isValid — use landingInfo position and radius if set and find these values automatically otherwise

<font color=AAAA99>landingInfo.position — landing area center position

<font color=AAAA99>landingInfo.radius — landing area radius

Transfer data
The second parameter of <font color=AAAA99>changeMap function is lua table that will be pass to LevelDirector at map initialization. It is useful when you want to pass some information from one map to another. Note, that you can place in this table only strings, numbers, bool values and other subtables but not objects or functions (the same rules as in the SaveManager).

For instance, you can place to <font color=AAAA99>transferData information about resources in barn and override LevelDirector:perform function to be able to restore this values after map changing. Complete example:

fv.core.GameMenu.model:regButton( 'map', 'GameLook1/iconMainMenu' , '@btnMenu@' , - 1 , function (button)   local info = fv.core.game.gameInfo:getStartGameInfo       info.customMapPath = 'maps/974465187/map.data'     info.customMapInfo = fv.core.MapInfo:new( 'maps/974465187/mapinfo.lua' )    local transferData = {}    for building in iter(fv.core.gameMap:getBuildings) do         if building.name == 'Barn' then             transferData.barnRes = building:getResources            break         end     end     fv.core.game:changeMap(info, transferData) end ) function fv.core.LevelDirector: perform(transferData) self :initStartPlace if transferData.barnRes then for building in iter(fv.core.gameMap:getBuildings) do            if building.name == 'Barn' then building:clearStorage for k, v in pairs (transferData.barnRes) do                    building:setResourceCount(k, v)                end break end end end end