Tech tree modding tutorial, please.

Fariic

Chieftain
Joined
Apr 13, 2010
Messages
93
Could someone please make a tutorial on how to mod technologies?


please
 
Here is an informal one. Perhaps I will consider making a larger one, but I'm working on a mod right now.

Adding a technology:

In order to add a technology, open up modboddy, create a new mod, etc. In the XML file you create, add code like this:

Code:
<GameData>
	<Technologies>
	</Technologies>
</GameData>

This will tell the file that it is referencing the Technologies XML.

Adding a technology is simple. For this example, I'll add Fishing.

Code:
<GameData>
	<Technologies>
                  <Row>
			<Type>TECH_FISHING</Type>
			<Cost>35</Cost>
			<Description>TXT_KEY_TECH_FISHING_TITLE</Description> <!-- the name of your technology -->
			<Civilopedia>TXT_KEY_TECH_FISHING_DESC</Civilopedia> <!-- the Civilopedia entry -->
			<Help>TXT_KEY_TECH_FISHING_HELP</Help> <!-- Mouse-over help text -->
			<Era>ERA_ANCIENT</Era> <!-- self-explanatory -->
			<Trade>true</Trade> <!-- guessing this is an available technology for Research Agreements -->
			<GoodyTech>true</GoodyTech> <!-- Ancient Ruins gives this to you? -->
			<GridX>0</GridX> <!-- position left-to-right on tech tree. The absolute left value is 0 -->
			<GridY>1</GridY> <!-- position top-to-bottom on tech tree. The absolute top value is 0 -->
			<Quote>TXT_KEY_TECH_FISHING_QUOTE</Quote> <!-- Quote displayed when tech is researched -->
			<PortraitIndex>9</PortraitIndex> <!-- exactly what icon from the atlas is being displayed (see below)
			<IconAtlas>RESOURCE_ATLAS</IconAtlas> <!-- what is being referenced for the icon displayed -->
			<AudioIntro></AudioIntro> <!-- not needed for custom techs -->
			<AudioIntroHeader></AudioIntroHeader>  <!-- not needed for custom techs -->
		</Row>
	</Technologies>
</GameData>

Excellent! We have added Fishing into the game! Those TXT_KEY references are just keys to help translate the game. If you want, you can instead fill those TXT_KEY's with the actual text you want displayed, but then it can't be translated. If you want to keep those in, we'll reference those later.

Now that the tech is displayed in the game, it appears in the tech tree. But it has no prereqs (meaning you'll be able to research it from the start), and no flavors (I'm pretty sure this means the AI will do its best to ignore it).

For the sake of moving this along, let's have fishing grant the fishing boats ability, as well as the ability to train Work Boats. We'll have Sailing require Fishing. Let's tackle the easier stuff first, the prereqs and the AI flavors. As I said above, the prereqs make the lines appear on the tech tree, as well as make that technology required, and the flavors help with the AI. In the same XML file as above, let's add the following:

Code:
<GameData>
	<Technologies>
                  <Row>
			<Type>TECH_FISHING</Type>
			<Cost>35</Cost>
			<Description>TXT_KEY_TECH_FISHING_TITLE</Description> <!-- the name of your technology -->
			<Civilopedia>TXT_KEY_TECH_FISHING_DESC</Civilopedia> <!-- the Civilopedia entry -->
			<Help>TXT_KEY_TECH_FISHING_HELP</Help> <!-- Mouse-over help text -->
			<Era>ERA_ANCIENT</Era> <!-- self-explanatory -->
			<Trade>true</Trade> <!-- guessing this is an available technology for Research Agreements -->
			<GoodyTech>true</GoodyTech> <!-- Ancient Ruins gives this to you? -->
			<GridX>0</GridX> <!-- position left-to-right on tech tree. The absolute left value is 0 -->
			<GridY>1</GridY> <!-- position top-to-bottom on tech tree. The absolute top value is 0 -->
			<Quote>TXT_KEY_TECH_FISHING_QUOTE</Quote> <!-- Quote displayed when tech is researched -->
			<PortraitIndex>9</PortraitIndex> <!-- exactly what icon from the atlas is being displayed (see below)
			<IconAtlas>RESOURCE_ATLAS</IconAtlas> <!-- what is being referenced for the icon displayed -->
			<AudioIntro></AudioIntro> <!-- not needed for custom techs -->
			<AudioIntroHeader></AudioIntroHeader>  <!-- not needed for custom techs -->
		</Row>
	</Technologies>
        <Technology_Flavors>
		<Row>
			<TechType>TECH_FISHING</TechType>
			<FlavorType>FLAVOR_NAVAL_TILE_IMPROVEMENT</FlavorType>
			<Flavor>3</Flavor>
		</Row>
	</Technology_Flavors>
	<Technology_PrereqTechs>
                <Row>
			<TechType>TECH_SAILING</TechType>
			<PrereqTech>TECH_FISHING</PrereqTech>
		</Row>
	</Technology_PrereqTechs>
</GameData>

For the AI flavors, I put Naval Tile Improvement as the flavor because it seemed to fit the most for the technology. If Fishing grants the ability to make Fishing Boats, then it should be common sense that the AI thinks that's what it's going to do as well.

For PrereqTechs, TechType defines the technology you want to be researched, and PrereqTech defines the technology that needs to be researched in order to research the next tech. Fishing is at the left of the tree (with Agriculture) so I do not need to specify a Prereq for it (it can be researched at the start of the game). For other technologies, you will need to have to assign a PrereqTech for that, as well another tech to require the one you just made (refer to Kael's Modding Guide for updates).

So far, we have added the technology, gave it a prereq, and gave it a flavor. It's fully functional. The remaining bits are making it allow units, fishing boats, and making those TXT_KEYs mean something.

Create a new XML, or use the technology one, but creating a new XML is recommended by myself, and most likely many other people. Type the following:

Code:
<GameData>
	<Builds>
		<Update>
			<Set PrereqTech="TECH_FISHING"/>
			<Where Type="BUILD_FISHING_BOATS"/>
		</Update>
	</Builds>
	<Resources>
		<Update>
			<Set TechCityTrade="TECH_FISHING"/>
			<Where Type="RESOURCE_PEARLS"/>
		</Update>
		<Update>
			<Set TechCityTrade="TECH_FISHING"/>
			<Where Type="RESOURCE_FISH"/>
		</Update>
	</Resources>
</GameData>

Notice I used Update commands here. This is referenced in the Modding Guide. I basically did not have to add a single line of code to the XML, just updated the previous codes to reflect my new technology. They will not require Sailing anymore (although Sailing's tooltip will still say they do, this is just an aesthetic change).

And another code for the units:

Code:
<GameData>
		<Units>
                        <Update>
				<Set PrereqTech="TECH_FISHING"/>
				<Where Type="UNIT_WORKBOAT"/>
			</Update>
                </Units>
</GameData>

Viola! Now Fishing grants a Work Boat, allows you to build Fishing Boats, and allows you to work Pearls and Fish. We're done (gameplay-wise!). Now let's change the aesthetics (i.e. make those TXT_KEY stuff display text)!

Code:
	<Language_en_US>
		<Row Tag="TXT_KEY_TECH_FISHING_TITLE">
			<Text>Fishing</Text>
		</Row>
		<Row Tag="TXT_KEY_TECH_FISHING_DESC">
			<Text>Man has long relied on the sea to provide sustenance. The most primitive peoples gathered mollusks and crabs from the sand; eventually they learned to make spears to capture the rich foodstuffs out of reach of hand. The fishing technology allows sophisticated advancements in fishing: building small coastal fishing vessels, weaving and deploying large fishing nets, constructing crab traps, and so forth. [NEWLINE][NEWLINE]Fishing is a major industry in the world today, and hundreds of thousands of pounds of fish are taken from the sea every day. However, this has put a serious strain on the ocean's ecology, and continued unfettered fishing may soon overwhelm and destroy this precious resource.</Text>
		</Row>
		<Row Tag="TXT_KEY_TECH_FISHING_HELP">
			<Text>Allows you to build [COLOR_POSITIVE_TEXT]Work Boats[ENDCOLOR], allowing you to harvest [ICON_RES_FISH] [COLOR_POSITIVE_TEXT]Fish[ENDCOLOR] and [ICON_RES_PEARLS] [COLOR_POSITIVE_TEXT]Pearls[ENDCOLOR] from the coast.</Text>
		</Row>
		<Row Tag="TXT_KEY_TECH_FISHING_QUOTE">
			<Text>"Give a man a fish, and you feed him for a day. Teach a man to fish, and you feed him for a lifetime." - Kurdish Proverb</Text>
		</Row>
	</Language_en_US>

And...we're done! Try this out and you should be able to add a technology.

Updating and deleting technologies to come on request...this is much harder. :)

Enjoy!
 
No problem! :)
 
Code:
<GameData>
        <Technology_PrereqTechs>
                <Delete TechType="TECH_HORSEBACK_RIDING"/>
	</Technology_PrereqTechs>
</GameData>

That code will delete the prereqs from Horseback Riding (The Wheel)
 
For me personally, I intended to rewire every single tech and add plenty of new techs in, so this is what mine looks like:

<Technology_PrereqTechs>
<Delete />

<Row>
<TechType>TECH_MYSTICISM</TechType>
<PrereqTech>TECH_AGRICULTURE</PrereqTech>
</Row>
etc
etc
etc
 
Okay, I'll reserve the following for a tech tree deletion tutorial later today.

Update: Alright, first I want to say I downloaded the tech tree helper tool, going to see how well it saves me time. Then I'm going to write up this quick tech deletion tutorial. It won't be as detailed as the first one I wrote, but it shouldn't be hard to understand (I hope).

In this tutorial I'll cover:
1) Disabling technologies so they cannot be researched.
2) Removing those technologies (eras only) so that they are not visible on the tree any longer.

Disabling technologies
This is the easy bit (and so is the next one). Simply put, there is a disable command for all technologies. Setting this value to "1" will disable the technology (make it appear red and have the locked symbol next to it), and "0" will enable it (please stop reading if you don't know what this means :p)

Disabling a single tech:
Code:
<Update>
  <Where Type="TECH_NANOTECHNOLOGY"/>
  <Set Disable="1"/>
</Update>

Disabling a single era:
Code:
<Update>
  <Where Era="ERA_MODERN"/>
  <Set Disable="1"/>
</Update>

Remove Disabled technologies from the tech tree

The following LUA bit was taught to me by FiresForever. He deserves a lot of the credit for this! :)

This is the tougher bit. Basically, if you don't want to remove any eras, add a new era to the tech tree (I haven't experimented with this method, so ask someone else how to do it! :) ) and assign all the techs you want removed from the tech tree to that new era.

Example:
Code:
<Update>
  <Where Type="TECH_NANOTECHNOLOGY"/>
  <Set Era="ERA_NEWERA"/>
</Update>

Where NEWERA is a placeholder for whatever your new era is.

Another way of doing this (useful if you want the tech tree to visually stop at, say, the Industrial Era) is to assign all the techs in the era you want disappeared to the same "GridY" value. For the purposes of the example, I will remove all the technologies from the Modern Era and make them disappear (won't touch the Future Era). This requires use of the LUA. Copy the TechTree.lua file from Assets -> UI -> InGame -> TechTree. Find this line in that LUA:

Code:
thisTechButtonInstance.TechButton:SetOffsetVal( tech.GridX*blockSpacingX + 64, (tech.GridY-5)*blockSpacingY + extraYOffset);

and replace it with:

Code:
if tech.Era == "ERA_MODERN" then
thisTechButtonInstance.TechButton:SetOffsetVal( tech.GridX*blockSpacingX + 64, (tech.GridY-25)*blockSpacingY + extraYOffset); --Changed tech.GridY
else
thisTechButtonInstance.TechButton:SetOffsetVal( tech.GridX*blockSpacingX + 64, (tech.GridY-5)*blockSpacingY + extraYOffset);
end

What this basically will do is to move every technology in the Modern Era and move it out of the tech tree. The branches will still be there, and the techs technically still exist, but they are disabled (can't be researched) and are moved out of view.

Removing the tech tree branches:
Code:
<Technology_PrereqTechs>
<Delete TechType="TECH_GLOBALIZATION"/>
		<Delete TechType="TECH_ROBOTICS"/>
		<Delete TechType="TECH_SATELLITES"/>
		<Delete TechType="TECH_STEALTH"/>
		<Delete TechType="TECH_ADVANCED_BALLISTICS"/>
		<Delete TechType="TECH_ECOLOGY"/>
		<Delete TechType="TECH_COMPUTERS"/>
		<Delete TechType="TECH_ROCKETRY"/>
		<Delete TechType="TECH_LASERS"/>
		<Delete TechType="TECH_NUCLEAR_FISSION"/>
		<Delete TechType="TECH_PLASTIC"/>
		<Delete TechType="TECH_PENICILIN"/>
		<Delete TechType="TECH_ELECTRONICS"/>
		<Delete TechType="TECH_MASS_MEDIA"/>
		<Delete TechType="TECH_RADAR"/>
		<Delete TechType="TECH_ATOMIC_THEORY"/>
</Technology_PrereqTechs>

And now, the Modern Era should be completely tech-free and branch-fee. Basically, the whole era is invisible.*

*note, you'll have to assign the Future Era techs' prereqs to earlier technologies, as their original prereqs are disabled.

Hope this helps! If you need to ask any questions, be free to!
 
its still not completley finished but it gets most of the process done and will save you alot of time.
 
Updated with deleting technologies. I don't know if your fantastic tech tree mod (which I finally got around to downloading) works with deleting technologies.
 
Since the tech tree experts seem to be congregating within this thread, I figured I'd ask here.

In my mod, I changed the spaceship so that it doesn't end the game. Instead, I want it to, among other things, grant a specific, untradeable, unresearchable tech to each civ that launches its own spaceship. (Centauri Ecology, which is then the prerequisite for many future-era techs.)
I'm assuming that the granting of a specific tech can be handled through .lua editing (since it doesn't look like it can through XML editing), but the question is, how do I make it so that the tech is still visible in the tech tree (preferably without a big red X from a Disable) but not have it be researchable?
 
From what I know specifically, you can't. If you want it to not be researchable, you have to disable it. If you don't disable it, but don't add a prereq, then it becomes available right from the start (i.e. Agriculture).

Disable doesn't look too terrible, imo, as it just gives it the same graphic as techs that can't be granted by a Great Scientist.
 
Since the tech tree experts seem to be congregating within this thread, I figured I'd ask here.

In my mod, I changed the spaceship so that it doesn't end the game. Instead, I want it to, among other things, grant a specific, untradeable, unresearchable tech to each civ that launches its own spaceship. (Centauri Ecology, which is then the prerequisite for many future-era techs.)
I'm assuming that the granting of a specific tech can be handled through .lua editing (since it doesn't look like it can through XML editing), but the question is, how do I make it so that the tech is still visible in the tech tree (preferably without a big red X from a Disable) but not have it be researchable?

I'm having a similar problem.

Giving a Civ a tech for free Can be done through XML and is the easy part - you can literally just copy and paste the bit about the free agriculture tech on the main civ page so there's another free tech and it's yours. Example:

<Civilization_FreeTechs>
<Row>
<CivilizationType>CIVILIZATION_RFS_SUNEMPIRE</CivilizationType>
<TechType>TECH_AGRICULTURE</TechType>
</Row>
<Row>
<CivilizationType>CIVILIZATION_RFS_SUNEMPIRE</CivilizationType>
<TechType>TECH_RFS_SIGHT</TechType>
</Row>
</Civilization_FreeTechs>

I didn't give it any flavour so I'm HOPING that will stop the AI from trying to use it, but unsure. My problem is stopping other players playing other Civs from using it. I tried making my tech a part of 'New Era', then using the lua code in this thread to hide that era, but it doesn't seem to have hidden it. I wondered if it wasn't hidden because it had been researched and so I tested by playing another Civ that didn't get it for free but the new era is still sitting there at the end making my tech tree all ugly. I've never changed lua before so I could have done something wrong but it seemed pretty simple. I literally just changed the document in my program files to have your line except with my era instead of the modern era and saved it. If this is where I messed up someone please say.

I'm not sure if the XML method relied on the tech being in a non-existent era but when I did just the XML without also creating my own era or doing lua or anything my whole tree went blank.

If anyone can help me make this tech hidden that would be super helpful please.
 
I found out what I was doing with the lua so don't need help with that anymore. Also realised the whole tech tree disappearing is unrelated to the lua because it's doing it without. No idea what else I changed in order for this to happen because I could see the era before but yeah don't need help anymore is my point.
 
Hi again, sorry I keep bumping a dead post but I've got my tech sorted and thought I'd share it in case anyone else comes across this post googling similar things as me.
Two things I want to add:
1. If you're new to lua like me make sure that it's the latest version you're updating if you have expansions. Search your assets folder for all files with that name and import the most recent expansion version into your mod.
2. The lua code you gave hid my technology from my era but I still had an empty era panel making my tech tree ugly. I played about a bit and eventually found how to hide the whole era from the tree.
Where it has:
Code:
        -- adjust the sizes of the era panels
        local blockWidth;
        if (eraColumns[era.ID] ~= nil) then
            blockWidth = (eraColumns[era.ID].maxGridX - eraColumns[era.ID].minGridX + 1);
        else
            blockWidth = 1;
        end
            
        blockWidth = (blockWidth * blockSpacingX);
        if era.ID == 0 then
            blockWidth = blockWidth + 32;
        end
        local blockSize = thisEraBlockInstance.EraBlock:GetSize();
        blockSize.x = blockWidth;
        thisEraBlockInstance.EraBlock:SetSize( blockSize );
        blockSize = thisEraBlockInstance.FrameBottom:GetSize();
        blockSize.x = blockWidth;
        thisEraBlockInstance.FrameBottom:SetSize( blockSize );
I added
Code:
        elseif era.ID == 8 then
            blockWidth = 0;
so that it looks like this:
Code:
blockWidth = (blockWidth * blockSpacingX);
        if era.ID == 0 then
            blockWidth = blockWidth + 32;
        elseif era.ID == 8 then
            blockWidth = 0;
        end
        local blockSize = thisEraBlockInstance.EraBlock:GetSize();
        blockSize.x = blockWidth;
        thisEraBlockInstance.EraBlock:SetSize( blockSize );
        blockSize = thisEraBlockInstance.FrameBottom:GetSize();
        blockSize.x = blockWidth;
        thisEraBlockInstance.FrameBottom:SetSize( blockSize );

Just replace your era.ID with whichever Era you want to hide and voila!
No idea if you have to use the other code as well as this, I'm running both just because I already added the other code and can't be bothered to remove it and test.
 
Top Bottom