Hi everyone, i'm finally home from work and wanted to share what i found out so far
in the process of adding a new resource.
Step 1: Setting up Modbuddy
Open Modbuddy and start a new Project. Name it what you like. Now lets set up the Project. Add the following Folder Structure: Art, Lua, XML (see attached Image 1).
Step 2: The Resources XML
Now lets add the XML Information for the new Copper Resource. Add a File to XML/Terrain and name it "Copper.xml".
For a reference you can open "Assets/GamePlay/XML/CIV5Resources.xml" from your Civ5 Installation folder.
Here's the full content of the file, but i will explain each section as good as i can below:
2.1) The <Resources> Block
Thats pretty much copied from one of the standard resources ingame. Some Parameters here explained:
<Type>RESOURCE_COPPER</Type>
Thats our reference for the new resource, and we will use this several times
<TechReveal>TECH_MINING</TechReveal>
Self-explanatory, this is the Technology you need to see the Resource on the Map
<TechCityTrade>TECH_MINING</TechCityTrade>
This is the Technology from which on you will see the Resource in the TopPanel.
<ResourceClassType>RESOURCECLASS_RUSH</ResourceClassType>
Strategic Resources have either RESOURCECLASS_RUSH or RESOURCECLASS_MODERN here, i haven't figured out the real difference. I would guess the AI will try to settle immediately near a RESOURCECLASS_RUSH if possible.
<IconString>[ICON_RES_COPPER]</IconString>
The String you can use in CivPedia entries to reference this Resource and show a tiny icon next to the text (see part 6).
<IconAtlas>CUSTOM_RESOURCE_ATLAS</IconAtlas>
The IconAtlas the game should use (a bunch of icons) when trying to display this resource. Since we won't use the basic IconAtlas, we reference a new one.
<PortraitIndex>0</PortraitIndex>
The index of the Icon in the IconAtlas of this Resource.
And last but not least <ResourceUsage>1</ResourceUsage>
None of the standard Resources have this set, but a Strategic Resource needs "1" here. Haven't tried adding luxury resources, but i think they need 4. Everything else is just a Bonus Resource (as Sheep).
2.2) The <Resource_YieldChanges> Block
Here we specify, what additonal Yields a plot gets, when this resource is added. We add 1 Production for Copper.
2.3) The <Resource_Flavors> Block
Here we specify the Flavor of the Resource. Not sure if this is used ingame, but lets just add the same flavor that Iron has.
2.4) The <Resource_TerrainBooleans> Block
This specifies on which Terrains the Resource can appear. Currently the game totally ignores those values, but please add them anyway, cause a modular approach (which will surely come soon), will need those values.
2.5) The <Resource_QuantityTypes> Block
Same as 2.4 -> Ignored by the game so far. This should specify in which quantities the Resource Can Appear on the Map (depending on your settings "Abundant", "Balanced" or "Sparse" in the Advanced Game Options when starting a game). Only Strategic Resources need this block.
This ends our <Resources> Block. I added the following blocks into the "Copper.xml" for easier reference. I also like when all parts of one added element can be put in one file.
2.6) The <Language_en_US> Block
Here we define the Text Keys for the ingame reference. You might want to add translations for other languages here, e.g. Language_de_DE or even more, so more people can use the mod.
2.7) The <Improvement_ResourceTypes> Block
This is an excerpt from /Assets/Gameplay/XML/Terrain/Improvements.xml and specifies which Improvement can be built on our Resource. For Copper we choose a mine.
2.8) The <IconFontMapping> Block
This specifies, which Icon in the FontMapping should be used, whenever we enter [ICON_RES_COPPER] into Text Keys, so the game knows which Icon it should use. Lets set this to 10, which is the Iron Icon (see Step 6 for more info)
Thats for the XML Part, but dont forget:
2.9) Add the newly added XML to the Mod Properties
In Modbuddy Rightclick on "CopperMod" in the Solution Explorer and select "Properties". We now have to tell the game to use the new XML file when the Mod gets loaded.
In the properties, go to the Tab "Actions" and add the following:
OnModActivated | UpdateDatabase | XML/Terrain/Copper.xml
(you probably know this from Kaeels guide, look it up there to see how it works)
Step 3: The Icon Files
Now lets generate the Icon File. The readme.txt in "Sid Meiers Civilization 5 SDK/Art/" says we need four dds files for a Resource. 256, 80, 64 and 45.
How to create a dds with Adobe Photoshop
When you have your 4 dds-files, drag&drop them into ModBuddy in our /Art/IconAtlas Folder. I named them ResourceAtlas256.dds, ResourceAtlas80.dds, ResourceAtlas64.dds and ResourceAtlas45.dds
I know the Icon doesnt really look that good, i'm no real artist.. It was more of a proof-of-concept than real Art.
Step 4: The IconAtlas File
Now add a new XML File to our XML Folder and call it CopperIconAtlas.xml
Here's the contents:
Its quite self-explanatory too. We tell the game which dds Files it should use for the different Icon sizes. An IconAtlas (usually) exists of 8 Rows of 8 Icons each, making a total of 64 Icons possible per Atlas.
4.1) Add the newly added XML to the Mod Properties
As in 2.9 add a new Action to your Mods properties:
OnModActivated | UpdateDatabase | XML/CopperIconAtlas.xml
Step 5: The Lua Files
5.1): AssignStartingPlots.lua
So far we would have the Resource Ingame, and the Resource plus correct Icons shown in the CivPedia, but the Resource will not be distributed on the map... so ... we have to change AssignStartingPlots.lua.
In this file the resources get scattered on the map. Sadly this is hardcoded in Lua, does not reference to anything we set in our XML file and cannot be modded via XML.
For now, just download the attached "AssignStartingPlots.lua" file and add it to our "Lua" folder. If you want to know what i changed in there, compare the new File to the original one.
(I hope SamBC wil come up with a modular solution, or someone else for that matter, because if things stay as they are, Resource-Mods will NOT be compatible with each other).
Now our Resource gets scattered on the Map. But whats that? The description does say "Copper" but it has the Icon of Iron on the worldmap....lets fix that.
5.2): ResourceIconManager.lua
Again this file is not modular, but i found out how to make it so. Hardcoded they all use the same texture, which means we can't load our Custom IconAtlas and thats bad.
Below is the code explained, but you can download the ResourceIconManager.lua in the attachement.
Step 6): The TopPanel
Since we have added a Strategic Resource, it will automatically show in the top panel after <TechReveal> was researched by the player. Sadly, i have found no way yet, to display the correct Icon in that panel. Civ5 is not really modular, and i found no way to override the IconFontMapping. You can read more about the problem here.
I hope this guide isnt too confusing and helps you to add new resources. There's still several things to figure out, but still i'm quite happy with the result.
The added resource also instantly shows up in the "AgS - Resource Info Panel (v 1)" mod without any changes
If you have any questions feel free to post them
Kyoss
PS: I did not have time yet to run the attached mod. There might be some changes needed, i just copied most of the stuff out of the mod i'm currently developing.
in the process of adding a new resource.
Step 1: Setting up Modbuddy
Open Modbuddy and start a new Project. Name it what you like. Now lets set up the Project. Add the following Folder Structure: Art, Lua, XML (see attached Image 1).
Step 2: The Resources XML
Now lets add the XML Information for the new Copper Resource. Add a File to XML/Terrain and name it "Copper.xml".
For a reference you can open "Assets/GamePlay/XML/CIV5Resources.xml" from your Civ5 Installation folder.
Here's the full content of the file, but i will explain each section as good as i can below:
Spoiler :
Code:
<?xml version="1.0" encoding="utf-8"?>
<GameData>
<Resources>
<Row>
<Type>RESOURCE_COPPER</Type>
<TechReveal>TECH_MINING</TechReveal>
<TechCityTrade>TECH_MINING</TechCityTrade>
<AIStopTradingEra>ERA_INDUSTRIAL</AIStopTradingEra>
<Description>TXT_KEY_RESOURCE_COPPER</Description>
<Civilopedia>TXT_KEY_CIV5_RESOURCE_COPPER_TEXT</Civilopedia>
<Help>TXT_KEY_RESOURCE_COPPER_HELP</Help>
<ResourceClassType>RESOURCECLASS_RUSH</ResourceClassType>
<ArtDefineTag>ART_DEF_RESOURCE_IRON</ArtDefineTag>
<ArtDefineTagHeavy>ART_DEF_RESOURCE_IRON_HEAVY</ArtDefineTagHeavy>
<AltArtDefineTag>ART_DEF_RESOURCE_IRON_MARSH</AltArtDefineTag>
<AltArtDefineTagHeavy>ART_DEF_RESOURCE_IRON_HEAVY_MARSH</AltArtDefineTagHeavy>
<AITradeModifier>10</AITradeModifier>
<ResourceUsage>1</ResourceUsage>
<PlacementOrder>1</PlacementOrder>
<AIObjective>1</AIObjective>
<ConstAppearance>100</ConstAppearance>
<MinAreaSize>3</MinAreaSize>
<MaxLatitude>90</MaxLatitude>
<RandApp1>10</RandApp1>
<RandApp2>10</RandApp2>
<Player>100</Player>
<Hills>true</Hills>
<Flatlands>true</Flatlands>
<NoRiverSide>true</NoRiverSide>
<IconString>[ICON_RES_COPPER]</IconString>
<PortraitIndex>0</PortraitIndex>
<IconAtlas>CUSTOM_RESOURCE_ATLAS</IconAtlas>
</Row>
</Resources>
<Resource_YieldChanges>
<Row>
<ResourceType>RESOURCE_COPPER</ResourceType>
<YieldType>YIELD_PRODUCTION</YieldType>
<Yield>1</Yield>
</Row>
</Resource_YieldChanges>
<Resource_Flavors>
<Row>
<ResourceType>RESOURCE_COPPER</ResourceType>
<FlavorType>FLAVOR_OFFENSE</FlavorType>
<Flavor>10</Flavor>
</Row>
</Resource_Flavors>
<Resource_TerrainBooleans>
<Row>
<ResourceType>RESOURCE_COPPER</ResourceType>
<TerrainType>TERRAIN_GRASS</TerrainType>
</Row>
<Row>
<ResourceType>RESOURCE_COPPER</ResourceType>
<TerrainType>TERRAIN_PLAINS</TerrainType>
</Row>
<Row>
<ResourceType>RESOURCE_COPPER</ResourceType>
<TerrainType>TERRAIN_DESERT</TerrainType>
</Row>
<Row>
<ResourceType>RESOURCE_COPPER</ResourceType>
<TerrainType>TERRAIN_TUNDRA</TerrainType>
</Row>
<Row>
<ResourceType>RESOURCE_COPPER</ResourceType>
<TerrainType>TERRAIN_SNOW</TerrainType>
</Row>
</Resource_TerrainBooleans>
<Resource_QuantityTypes>
<Row>
<ResourceType>RESOURCE_COPPER</ResourceType>
<Quantity>3</Quantity>
</Row>
<Row>
<ResourceType>RESOURCE_COPPER</ResourceType>
<Quantity>2</Quantity>
</Row>
</Resource_QuantityTypes>
<Language_en_US>
<Row Tag="TXT_KEY_RESOURCE_COPPER">
<Text>Copper</Text>
<Gender>neuter:an</Gender>
</Row>
<Row Tag="TXT_KEY_RESOURCE_COPPER_HELP">
<Text>Used for Units.</Text>
</Row>
<Row Tag="TXT_KEY_CIV5_RESOURCE_COPPER">
<Text>Copper</Text>
</Row>
<Row Tag="TXT_KEY_CIV5_RESOURCE_COPPER_TEXT">
<Text>
Copper, as native copper, is one of the few metals to occur naturally as an un-compounded mineral. Copper was known to some of the oldest civilizations on record, and has a history of use that is at least 10,000 years old.
</Text>
</Row>
<Row Tag="TXT_KEY_CIV5_RESOURCE_COPPER_TITLE1">
<Text>Technology Required to See</Text>
</Row>
<Row Tag="TXT_KEY_CIV5_RESOURCE_COPPER_TITLE2">
<Text>Location</Text>
</Row>
<Row Tag="TXT_KEY_CIV5_RESOURCE_COPPER_TITLE3">
<Text>Improvement</Text>
</Row>
<Row Tag="TXT_KEY_CIV5_RESOURCE_COPPER_TITLE4">
<Text>Yield Bonus</Text>
</Row>
<Row Tag="TXT_KEY_CIV5_RESOURCE_COPPER_TITLE5">
<Text>Allows</Text>
</Row>
</Language_en_US>
<Improvement_ResourceTypes>
<Row>
<ImprovementType>IMPROVEMENT_MINE</ImprovementType>
<ResourceType>RESOURCE_COPPER</ResourceType>
</Row>
</Improvement_ResourceTypes>
<IconFontMapping>
<Row>
<IconName>ICON_RES_COPPER</IconName>
<IconMapping>10</IconMapping>
</Row>
</IconFontMapping>
</GameData>
2.1) The <Resources> Block
Thats pretty much copied from one of the standard resources ingame. Some Parameters here explained:
<Type>RESOURCE_COPPER</Type>
Thats our reference for the new resource, and we will use this several times
<TechReveal>TECH_MINING</TechReveal>
Self-explanatory, this is the Technology you need to see the Resource on the Map
<TechCityTrade>TECH_MINING</TechCityTrade>
This is the Technology from which on you will see the Resource in the TopPanel.
<ResourceClassType>RESOURCECLASS_RUSH</ResourceClassType>
Strategic Resources have either RESOURCECLASS_RUSH or RESOURCECLASS_MODERN here, i haven't figured out the real difference. I would guess the AI will try to settle immediately near a RESOURCECLASS_RUSH if possible.
<IconString>[ICON_RES_COPPER]</IconString>
The String you can use in CivPedia entries to reference this Resource and show a tiny icon next to the text (see part 6).
<IconAtlas>CUSTOM_RESOURCE_ATLAS</IconAtlas>
The IconAtlas the game should use (a bunch of icons) when trying to display this resource. Since we won't use the basic IconAtlas, we reference a new one.
<PortraitIndex>0</PortraitIndex>
The index of the Icon in the IconAtlas of this Resource.
And last but not least <ResourceUsage>1</ResourceUsage>
None of the standard Resources have this set, but a Strategic Resource needs "1" here. Haven't tried adding luxury resources, but i think they need 4. Everything else is just a Bonus Resource (as Sheep).
2.2) The <Resource_YieldChanges> Block
Here we specify, what additonal Yields a plot gets, when this resource is added. We add 1 Production for Copper.
2.3) The <Resource_Flavors> Block
Here we specify the Flavor of the Resource. Not sure if this is used ingame, but lets just add the same flavor that Iron has.
2.4) The <Resource_TerrainBooleans> Block
This specifies on which Terrains the Resource can appear. Currently the game totally ignores those values, but please add them anyway, cause a modular approach (which will surely come soon), will need those values.
2.5) The <Resource_QuantityTypes> Block
Same as 2.4 -> Ignored by the game so far. This should specify in which quantities the Resource Can Appear on the Map (depending on your settings "Abundant", "Balanced" or "Sparse" in the Advanced Game Options when starting a game). Only Strategic Resources need this block.
This ends our <Resources> Block. I added the following blocks into the "Copper.xml" for easier reference. I also like when all parts of one added element can be put in one file.
2.6) The <Language_en_US> Block
Here we define the Text Keys for the ingame reference. You might want to add translations for other languages here, e.g. Language_de_DE or even more, so more people can use the mod.
2.7) The <Improvement_ResourceTypes> Block
This is an excerpt from /Assets/Gameplay/XML/Terrain/Improvements.xml and specifies which Improvement can be built on our Resource. For Copper we choose a mine.
2.8) The <IconFontMapping> Block
This specifies, which Icon in the FontMapping should be used, whenever we enter [ICON_RES_COPPER] into Text Keys, so the game knows which Icon it should use. Lets set this to 10, which is the Iron Icon (see Step 6 for more info)
Thats for the XML Part, but dont forget:
2.9) Add the newly added XML to the Mod Properties
In Modbuddy Rightclick on "CopperMod" in the Solution Explorer and select "Properties". We now have to tell the game to use the new XML file when the Mod gets loaded.
In the properties, go to the Tab "Actions" and add the following:
OnModActivated | UpdateDatabase | XML/Terrain/Copper.xml
(you probably know this from Kaeels guide, look it up there to see how it works)
Step 3: The Icon Files
Now lets generate the Icon File. The readme.txt in "Sid Meiers Civilization 5 SDK/Art/" says we need four dds files for a Resource. 256, 80, 64 and 45.
How to create a dds with Adobe Photoshop
Spoiler :
If you have Adobe Photoshop go to http://developer.nvidia.com/object/photoshop_dds_plugins.html and download the plugin. Install it, and run Photoshop (but not in 64bit mode, the dds plugin doesnt work in 64bit).
Now create a new image in 256x256 and draw your new Icon, press CTRL+a (to select it). Open the IconAtlas256.psd with Photoshop and copy (CTRL+v) it onto the stage. Drag it in the top left slot.
It doesnt matter if you drag it ON the black circle-raster. Try to align it to the middle of the cut-out circle in the top left.
Merge the Topmost Layer (your image) with the next one (Rightclick on your Layer and Select -> Merge Down). Now use "File->Save As" and save it as .dds file.
A Nvidia Window will pop up: Select DXT3 in the topmost Dropdown, "2D Texture" below and "No Mipmaps" on the right side. Save it.
Repeat those steps for all 4 IconAtlases until you have 4 dds file.
Now create a new image in 256x256 and draw your new Icon, press CTRL+a (to select it). Open the IconAtlas256.psd with Photoshop and copy (CTRL+v) it onto the stage. Drag it in the top left slot.
It doesnt matter if you drag it ON the black circle-raster. Try to align it to the middle of the cut-out circle in the top left.
Merge the Topmost Layer (your image) with the next one (Rightclick on your Layer and Select -> Merge Down). Now use "File->Save As" and save it as .dds file.
A Nvidia Window will pop up: Select DXT3 in the topmost Dropdown, "2D Texture" below and "No Mipmaps" on the right side. Save it.
Repeat those steps for all 4 IconAtlases until you have 4 dds file.
When you have your 4 dds-files, drag&drop them into ModBuddy in our /Art/IconAtlas Folder. I named them ResourceAtlas256.dds, ResourceAtlas80.dds, ResourceAtlas64.dds and ResourceAtlas45.dds
I know the Icon doesnt really look that good, i'm no real artist.. It was more of a proof-of-concept than real Art.
Step 4: The IconAtlas File
Now add a new XML File to our XML Folder and call it CopperIconAtlas.xml
Here's the contents:
Spoiler :
Code:
<?xml version="1.0" encoding="utf-8"?>
<GameData>
<IconTextureAtlases>
<Row>
<Atlas>CUSTOM_RESOURCE_ATLAS</Atlas>
<IconSize>256</IconSize>
<Filename>ResourceAtlas256.dds</Filename>
<IconsPerRow>8</IconsPerRow>
<IconsPerColumn>8</IconsPerColumn>
</Row>
<Row>
<Atlas>CUSTOM_RESOURCE_ATLAS</Atlas>
<IconSize>80</IconSize>
<Filename>ResourceAtlas80.dds</Filename>
<IconsPerRow>8</IconsPerRow>
<IconsPerColumn>8</IconsPerColumn>
</Row>
<Row>
<Atlas>CUSTOM_RESOURCE_ATLAS</Atlas>
<IconSize>64</IconSize>
<Filename>ResourceAtlas64.dds</Filename>
<IconsPerRow>8</IconsPerRow>
<IconsPerColumn>8</IconsPerColumn>
</Row>
<Row>
<Atlas>CUSTOM_RESOURCE_ATLAS</Atlas>
<IconSize>45</IconSize>
<Filename>ResourceAtlas45.dds</Filename>
<IconsPerRow>8</IconsPerRow>
<IconsPerColumn>8</IconsPerColumn>
</Row>
</IconTextureAtlases>
</GameData>
4.1) Add the newly added XML to the Mod Properties
As in 2.9 add a new Action to your Mods properties:
OnModActivated | UpdateDatabase | XML/CopperIconAtlas.xml
Step 5: The Lua Files
5.1): AssignStartingPlots.lua
So far we would have the Resource Ingame, and the Resource plus correct Icons shown in the CivPedia, but the Resource will not be distributed on the map... so ... we have to change AssignStartingPlots.lua.
In this file the resources get scattered on the map. Sadly this is hardcoded in Lua, does not reference to anything we set in our XML file and cannot be modded via XML.
For now, just download the attached "AssignStartingPlots.lua" file and add it to our "Lua" folder. If you want to know what i changed in there, compare the new File to the original one.
(I hope SamBC wil come up with a modular solution, or someone else for that matter, because if things stay as they are, Resource-Mods will NOT be compatible with each other).
Now our Resource gets scattered on the Map. But whats that? The description does say "Copper" but it has the Icon of Iron on the worldmap....lets fix that.
5.2): ResourceIconManager.lua
Again this file is not modular, but i found out how to make it so. Hardcoded they all use the same texture, which means we can't load our Custom IconAtlas and thats bad.
Below is the code explained, but you can download the ResourceIconManager.lua in the attachement.
Spoiler :
Code:
-- Added by Kyoss
if GameInfo.Resources[ResourceType].IconAtlas ~= "RESOURCE_ATLAS" then
[COLOR="DarkGreen"]-- means if the Resource is NOT using the default IconAtlas, then[/COLOR]
--get right Texture Atlas
local customAtlas = false;
for iTA in GameInfo.IconTextureAtlases() do
[COLOR="DarkGreen"] --do this for each IconAtlas:[/COLOR]
local iconAtlasRef, iconAtlasIconSize = iTA.Atlas, iTA.IconSize;
if iconAtlasRef == GameInfo.Resources[ResourceType].IconAtlas and iconAtlasIconSize == 64 then
[COLOR="DarkGreen"] -- if this Atlas is the Atlas we specified for the current Resource and has a width of 64 (WorldMap icons are 64x64px). then[/COLOR]
customAtlas = iTA.Filename;
[COLOR="DarkGreen"]-- YAY, we found the Atlas for our custom resource[/COLOR]
instance.ResourceIcon:SetTexture(customAtlas);
[COLOR="DarkGreen"] -- set the background Image of the IconResource to the IconAtlas we found[/COLOR]
break;
end
end
end
-- End: Added by Kyoss
Step 6): The TopPanel
Since we have added a Strategic Resource, it will automatically show in the top panel after <TechReveal> was researched by the player. Sadly, i have found no way yet, to display the correct Icon in that panel. Civ5 is not really modular, and i found no way to override the IconFontMapping. You can read more about the problem here.
I hope this guide isnt too confusing and helps you to add new resources. There's still several things to figure out, but still i'm quite happy with the result.
The added resource also instantly shows up in the "AgS - Resource Info Panel (v 1)" mod without any changes

If you have any questions feel free to post them
Kyoss
PS: I did not have time yet to run the attached mod. There might be some changes needed, i just copied most of the stuff out of the mod i'm currently developing.