Civ5Map to LUA-script Tools

nORb Dragon

Chieftain
Joined
Apr 11, 2013
Messages
27
Location
Murmansk, Russia
Description

Little program for convert civ5map files to lua-scripts with "true start locations".
Sorry for typo, english is not my native language.

Decoded part of civ5map files:
  • plots + terrain types;
  • features (ice, jungles, marsh etc.);
  • improvements;
  • resources (type+count);
  • rivers;
  • natural wonders;
  • art style type (regions);
  • random player start locations;
  • random citystate start locations.

Not decoded part of civ5map files:
  • players;
  • cities;
  • units;
  • territory ownership;
  • scenario parameters.

Files

  • civ5map2lua.exe - executable file
  • template.lua - template for new lua-scripts
    (some bugs can be fixed by changes in this file)
  • map\ - folder for civ5map-files and xml-files (for TSL)
    (with example "Play The World Extended BNW MARATHON")
  • lua\ - folder for results (lua-scripts)
  • readme_en.txt - junk
  • readme_ru.txt - junk

How to use

I recommend (before start) to copy the map-file (civ5map) to a folder "map". If you need lua-script with true start locations, сreate a xml-file with the same name as yours civ5map-file. For template you can use my example for one good map: Play The World Extended BNW MARATHON.xml

Coordinates for "start locations" you can find by Sid Meier's Civilization V SDK (World Builder).

After all just run "civ5map2lua.exe", select your civ5map file and press "START". If all goes well, you will see a window with congratulations. Check the folder "lua".

You can rename your lua-script. And change information about this script in body. Just open file in notepad, find "function GetMapScriptInfo()" and change value for "Name" and "Description" variables.


How to install and play

  1. Close game client.
  2. Copy your lua-script to <GameFolder>\Assets\Maps\
  3. Run game client, create game (single or multiplayer).
  4. Press "Advanced Setup" for open advanced game create options.
  5. Select Map Type "xxxxx" (where xxxxx - "Name" of your lua-script map).
  6. World size setting not affect to true game size (map size is locked by script).
  7. Set max count City-States for your game (how much you want, but script drop some City-States if need).
  8. Start game and play!

You think about multiplayer? Just give your lua-script to your friends for install.
But if map is very huge, you (and your friends) need good hardware (RAM, usually) for start and stable play. Sorry, but it is Civilization 5 trouble, not my.


Changelog

= 1.0.2 : 2013.07.31
[ * ] Minor changes in template:
  • function nORbConvWorld:GetCivStartPlot() optimized;
  • function nORbConvWorld:GetMinorCivStartPlot() optimized;
  • in function nORbConvWorld:MoveStartPos() added shoshone/aztec/polynesia units for start;
  • in function nORbConvWorld:MoveStartPos() added worker in "starting package".

= 1.0.1 : 2013.07.24
[ + ] Added optional checkbox "convert with improvements".
[ + ] Added decode for random city-states start locations.

= 1.0 : 2013.07.23
Release? After long time...
 

Attachments

  • civ5map2lua_1_0_2.zip
    1.1 MB · Views: 1,819
Is this the way to use starting locations on earth maps on Multiplayer???
Does it still work with this version?
I heard that there is no way to use starting location on multiplayers, does that mean that this is obsolete, or it is just not well known?
 
Im now able to play every map i want with true start locations, so me and my friends can play together in a team :)

but i'm not able to set citystates... i place them in the map... i look where "x and y" is ...place the correct values in the .xml --> DELETE all not placed citiystates from the xml. but when i start the map (after converting it to lua) me and my friends start at the correct position... the AI too... but on the whole map there are no citiystates :( what do i have to do to place them ? (what did i do wrong) ?
 
Well... I don't know, maybe something changed in past 2 years. So I can't be 100% sure. I describe for you how "citystates creation" worked about two years ago.

In the process of "creating a map" engine select "set of citystates" (by random) that will be used in the game. Game engine locks this "set of citystates" and give this list to lua-script with other options (like civilizations for players, world size and others).

Lua-scripting haven't rights for change "player/citystate type/name". So i decided to just "remove", which is not present in XML-file. Since "set of citystates" is determined by "random", your citystates from your "little list of citystates" do not fall in this list (by random) from engine, imho.

There are some subtleties of the work of my old template, perfectly described in this quote:
is there some reason i set max city states to 41 but only 26 appear?

edit:

After reloading a bunch of times to just test it and make sure it wasnt something i was doing, i am going to describe the collusion of functionality. If its unclear, please ask and i will go into more detail.

The map script tells city states to spawn in certain spots, but if that area is 'too crowded', then they just dont spawn. Since the city state already has a name and identity, instead of spawning a new one in an 'open' area, it just deletes.

I don't know, maybe someone knows how to change type (rename) for citystate by lua-script? It would solve a lot of problems. And not give me links to wiki, please. =) I'm so tired.

Sorry for typo, english is not my native language. =)

P.S.: I can check your map/xml-files and result script, if you want.
 
You can easily change the name of the city on the map with Lua, and then using a technique like the compatible version of my City States Leaders II mod--which doesn't replace the base game's popup Lua, it just revises the display whenever the popup occurs.

Here's the Lua from the above mentioned mod. Obviously a lot of it won't be applicable as you're only interested in changing the "title" portion. If you need help making sense of it, feel free to ask.

Spoiler :
Code:
Lua MinorCivLeaders

-- Author: Nutty, based on Gedemon's Ynaemp Leaders for City States

-- DateCreated: 3/27/2011 8:52:38 PM

-------------------------------------------------------------------



local g_iMinorCivID = -1

local g_iMinorCivTeamID = -1

local g_control = nil

local m_PopupInfo = nil



----------------------

-- On City State PopUp

----------------------

function OnEventReceived( popupInfo )



if (popupInfo.Type == ButtonPopupTypes.BUTTONPOPUP_CITY_STATE_DIPLO) then

g_control = "/InGame/CityStateDiploPopup/"

elseif (popupInfo.Type == ButtonPopupTypes.BUTTONPOPUP_CITY_STATE_GREETING) then

g_control = "/InGame/CityStateGreetingPopup/"

elseif (popupInfo.Type == ButtonPopupTypes.BUTTONPOPUP_CITY_STATE_MESSAGE) then

g_control = "/InGame/CityStateDiploPopup/"

else

return

end



m_PopupInfo = popupInfo



    local iPlayer = popupInfo.Data1

    local pPlayer = Players[iPlayer]

local iTeam = pPlayer:GetTeam()

local pTeam = Teams[iTeam]

    

    g_iMinorCivID = iPlayer

    g_iMinorCivTeamID = iTeam



local bForcePeace = false



SetCityStateLeader()

end

Events.SerialEventGameMessagePopup.Add( OnEventReceived )



function OnGameDataDirty()

if (not (ContextPtr:LookUpControl("/InGame/CityStateDiploPopup"):IsHidden())) then

g_control = "/InGame/CityStateDiploPopup/"

elseif (not (ContextPtr:LookUpControl("/InGame/CityStateGreetingPopup"):IsHidden())) then

g_control = "/InGame/CityStateGreetingPopup/"

else

return

end



SetCityStateLeader()

end

Events.SerialEventGameDataDirty.Add( OnGameDataDirty )



------------------------

-- Set City State Leader 

------------------------

function SetCityStateLeader()



--if (ContextPtr:LookUpControl("/InGame/CityStateDiploPopup"):IsHidden()) then

--if (ContextPtr:LookUpControl("/InGame/CityStateGreetingPopup"):IsHidden()) then

--return

--end

--end



local pPlayer = Players[g_iMinorCivID];

local sMinorCivType = pPlayer:GetMinorCivType();



local leaderIcon = nil;

local modernCountry = nil;

--local shortModernCountry = nil;

local leaderPlace = nil;

local leaderName = nil;

--local leaderTitle = nil;

--local leaderSuffix = nil;

--local artistName = nil;

--local title = nil;

local description = nil;

local status = nil;

local trait = nil;

local personality = nil;



if (sMinorCivType ~= nil) then

local realMinorCivType = GameInfo.MinorCivilizations[sMinorCivType].Type;



if realMinorCivType ~= nil then

local condition = "Type = '".. realMinorCivType .."'";

for row in GameInfo.MinorCivLeaders(condition) do

leaderIcon = row.LeaderIcon;

modernCountry = row.ModernCountry;

--shortModernCountry = row.ShortModernCountry;

leaderPlace = row.LeaderPlace;

leaderName = row.LeaderName;

--leaderTitle = row.LeaderTitle;

--leaderSuffix = row.LeaderSuffix;

--artistName = row.LeaderArtistName;

end

end

end



description = ContextPtr:LookUpControl(g_control .."DescriptionLabel"):GetText();



if (description:sub(1, 18) ~= "[COLOR_POPUP_TEXT]") then

--title = leaderName .." of ".. ContextPtr:LookUpControl(g_control .."TitleLabel"):GetText();

if (leaderName ~= nil) then

local artPack = GameInfo.MinorCivLeaders["ARTPACK"].LeaderIcon;



if artPack == "MODERN_FLAGS" then

--[for Modern Flags Art Pack (e.g., "Romania"):]

description = "[COLOR_POPUP_TEXT]".. modernCountry .."[ENDCOLOR][NEWLINE]".. description;

elseif artPack == "NONE" then

--[for LEADERS version:] (e.g., "Vlad III of Wallachia says:"):]

description = "[COLOR_POPUP_TEXT]".. leaderName .." of ".. leaderPlace .." says:[ENDCOLOR][NEWLINE]".. description;



--[Alternative long LEADERS version: (e.g., "Prince Vlad III the Impaler of Wallachia says:"):]

--description = " of ".. leaderPlace .."[ENDCOLOR] says:[NEWLINE]".. description;

--if (leaderSuffix ~= nil)

--description = leaderName .." ".. leaderSuffix .. description;

--else

--  description = leaderName .. description;

--end

--if (leaderTitle ~= nil)

--description = leaderTitle .." ".. description;

--end

--description = "[COLOR_POPUP_TEXT]".. description;

else

description = "[COLOR_POPUP_TEXT]".. leaderName .."[ENDCOLOR][NEWLINE]".. description;

end



else

description = "[COLOR_POPUP_TEXT][ENDCOLOR]".. description;

end



trait = ContextPtr:LookUpControl(g_control .."TraitInfo"):GetText();

if (trait == "[COLOR_POSITIVE_TEXT]".. Locale.ConvertTextKey("TXT_KEY_CITY_STATE_CULTURED_ADJECTIVE") .."[ENDCOLOR]") then

trait = trait:gsub("POSITIVE_TEXT]", "MAGENTA][ICON_CULTURE] ");

elseif (trait == "[COLOR_POSITIVE_TEXT]".. Locale.ConvertTextKey("TXT_KEY_CITY_STATE_MILITARISTIC_ADJECTIVE") .."[ENDCOLOR]") then

trait = trait:gsub("POSITIVE_TEXT]", "RED][ICON_WAR] ");

elseif (trait == "[COLOR_POSITIVE_TEXT]".. Locale.ConvertTextKey("TXT_KEY_CITY_STATE_MARITIME_ADJECTIVE") .."[ENDCOLOR]") then

trait = trait:gsub("POSITIVE_TEXT]", "CYAN][ICON_FOOD] ");

elseif (trait == "[COLOR_POSITIVE_TEXT]".. Locale.ConvertTextKey("TXT_KEY_CITY_STATE_MERCANTILE_ADJECTIVE") .."[ENDCOLOR]") then

trait = trait:gsub("POSITIVE_TEXT]", "YELLOW][ICON_GOLD] ");

elseif (trait == "[COLOR_POSITIVE_TEXT]".. Locale.ConvertTextKey("TXT_KEY_CITY_STATE_RELIGIOUS_ADJECTIVE") .."[ENDCOLOR]") then

trait = trait:gsub("POSITIVE_TEXT]", "WHITE][ICON_PEACE] ");

end



personality = ContextPtr:LookUpControl(g_control .."PersonalityInfo"):GetText();

if (personality == "[COLOR_POSITIVE_TEXT]".. Locale.ConvertTextKey("TXT_KEY_CITY_STATE_PERSONALITY_FRIENDLY") .."[ENDCOLOR]") then

personality = personality:gsub("COLOR_POSITIVE_TEXT]", "COLOR_POSITIVE_TEXT][ICON_HAPPINESS_1] ");

elseif (personality == "[COLOR_POSITIVE_TEXT]" ..Locale.ConvertTextKey("TXT_KEY_CITY_STATE_PERSONALITY_NEUTRAL") .."[ENDCOLOR]") then

personality = personality:gsub("COLOR_POSITIVE_TEXT]", "COLOR_FADING_POSITIVE_TEXT][ICON_HAPPINESS_2] ");

elseif (personality == "[COLOR_POSITIVE_TEXT]" ..Locale.ConvertTextKey("TXT_KEY_CITY_STATE_PERSONALITY_IRRATIONAL") .."[ENDCOLOR]") then

personality = personality:gsub("COLOR_POSITIVE_TEXT]", "COLOR_FADING_NEGATIVE_TEXT][ICON_HAPPINESS_3] ");

elseif (personality == "[COLOR_POSITIVE_TEXT]" ..Locale.ConvertTextKey("TXT_KEY_CITY_STATE_PERSONALITY_HOSTILE") .."[ENDCOLOR]") then

personality = personality:gsub("COLOR_POSITIVE_TEXT]", "COLOR_NEGATIVE_TEXT][ICON_HAPPINESS_4] ");

end



if (g_control == "/InGame/CityStateDiploPopup/") then

--status = ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/StatusInfo"):GetText();

--if (status == "[COLOR_POSITIVE_TEXT]".. Locale.ConvertTextKey("TXT_KEY_CITY_STATE_PERSONALITY_NEUTRAL") .. "[ENDCOLOR]") then

--status = status:gsub("[COLOR_POSITIVE_TEXT]", "[COLOR_FADING_POSITIVE_TEXT]");

--elseif status == "" then

--status = "";

--ContextPtr:LookUpControl("/InGame/CityStateDiploPopup/StatusInfo"):LocalizeAndSetText(status);

--end

--ContextPtr:LookUpControl(g_control .."StatusIcon"):UnloadTexture();

ContextPtr:LookUpControl(g_control .."StatusIcon"):SetTexture("blank_texture.dds");

end



if (leaderIcon ~= nil) then

local prefix = nil;

local gk_mode = Game.GetReligionName ~= nil;

local bnw_mode = Game.GetActiveLeague ~= nil;

if bnw_mode then

prefix = "bnw_";

elseif gk_mode then

prefix = "g+k_";

else

prefix = "van_";

end



ContextPtr:LookUpControl(g_control .."TitleIcon"):UnloadTexture();

ContextPtr:LookUpControl(g_control .."TitleIcon"):SetTextureAndResize(prefix .. leaderIcon);

else

ContextPtr:LookUpControl(g_control .."TitleIcon"):UnloadTexture();

ContextPtr:LookUpControl(g_control .."TitleIcon"):SetTextureAndResize(GameInfo.MinorCivTraits[GameInfo.MinorCivilizations[sMinorCivType].MinorCivTrait].TraitTitleIcon);

end



--ContextPtr:LookUpControl(g_control .."BackgroundImage"):UnloadTexture();

--ContextPtr:LookUpControl(g_control .."BackgroundImage"):SetTexture("CityStateBackgroundCulture.dds");



--ContextPtr:LookUpControl(g_control .."TitleLabel"):LocalizeAndSetText(title);

ContextPtr:LookUpControl(g_control .."DescriptionLabel"):LocalizeAndSetText(description);

ContextPtr:LookUpControl(g_control .."TraitInfo"):LocalizeAndSetText(trait);

ContextPtr:LookUpControl(g_control .."PersonalityInfo"):LocalizeAndSetText(personality);

end

end
[/QUOTE]
 
Could you modify the script to allow underscores (_) in the civ/minor civ names? Or - is the source for your utility available?


Thanks and great work!

EDIT: It wasn't the underscores - they parse fine - I had an invisible char. Thanks again for the utility!
 
Where do you put the xml files? Like in which directory?

I put it in with the map I converted and it doesn't work. Nothing spawns.

I set random start locations on the map just to be sure and everything spawns randomly, specified start locations are ignored.

Anyone able to help?
 
For "TSL" before start conversion you must prepare and put xml file in same folder with "civ5map" file.

In directory "<converter folder>\maps" must be 2 files:
- xxx.civ5map;
- xxx.xml (same filename as ".civ5map").

Result for play (after conversion) you can find in directory "<converter folder>\lua", 1 file:
- xxx.lua

Copy this lua-script to "<GameFolder>\Assets\Maps\" and play.

About specified random start locations. I can't remember how this works. xD Maybe somewhere bug in my old lua-template. Or just little misunderstanding in game settings.

If you give me your files (civ5map and xml), i can check.
 
I used your utility once before as a test and it worked. So I understand the basics of getting it to work.

I heavily edited an example xml file to suit the needs of my new map. I named it the same as my map, put both in the same folder and used your utility. Now the map I create doesn't show up when I put it in the maps folder.

Do you mind checking out the files and seeing what the issue is?

Here is a zip with the Map, Lua and XML files
https://www.dropbox.com/s/9rj7cwbal1duany/Map%20Files.zip?dl=0
 
I used your utility once before as a test and it worked. So I understand the basics of getting it to work.

I heavily edited an example xml file to suit the needs of my new map. I named it the same as my map, put both in the same folder and used your utility. Now the map I create doesn't show up when I put it in the maps folder.

Do you mind checking out the files and seeing what the issue is?

Here is a zip with the Map, Lua and XML files
https://www.dropbox.com/s/9rj7cwbal1duany/Map%20Files.zip?dl=0

Ok I managed to sort out the XML issue, but I'm having another. It seems that no resources are spawning. I have random resources enabled, but when I start a world no resources spawn at all. Does this tool support random resource spawning?
 
No, not support. But if you good in lua-scripting and have some skill, you can add custom function for random resource spawning in "template.lua" by yourself. =)
 
Haha, If I was that good at Lua I could probably code TSL for my own maps.

Here is an actual image of me attempting to code:
Spoiler :
 
Heh. Well, if I find some free time at this weekend... I can look what I can to do. But I don't promise anything. It is MY personal free time!
 
Top Bottom