Can you link tech and policy tree branches?

gazius

Warlord
Joined
Nov 24, 2007
Messages
117
Would it be possible to link a tech to a specific cultural policy branch? So all the various policies are available to be selected, but to move down the tree requires not only cultural points but certain techs?
 
That's already in there. Policies have a "TechPrereq" field, where the policy won't unlock until you reach certain technologies. So if you want to change each policy to require a certain tech, then it's not hard to do.

Unfortunately, while it works correctly, there's no indicator in the UI about why the policy is locked; it'll just say that you don't have the prerequisites. In my own mod I added a better indicator for this, since I use this feature for all of my new policies, so that it'll now say what tech you need to unlock the policy.

Now, the reverse isn't true, you can't have a tech require a policy. (Or pretty much anything else, actually; Technologies are the "base" table that everything else really builds off of.)
 
I think you misunderstood what I meant.

Unlocked Policy Tree
|
Item A Item B
| |
Item C Item D
- Item E -

I want Item E locked by a tech.
 
How is that different that what Spatz explained? Set the TechPrereq for Policy E to whatever you want and that policy will be unavailable unless you have that tech as well as policies C and D.
 
I thought he was referring to the overall branches, since that's the only time I've seen the tech prereq used.

:blush:
 
I thought he was referring to the overall branches, since that's the only time I've seen the tech prereq used.

:blush:

No, you HAVEN'T seen the tech prereq used. You've seen the Era prereq used, which is a completely different entry in the table.

You can set a Policy to explicitly require a single tech. It works just fine, because I've been using it in my mod for months now. It's just that it's not used in the core game and the UI doesn't display it well (until you mod it, like I did). But you CAN do it.
 
I thought he was referring to the overall branches, since that's the only time I've seen the tech prereq used.

:blush:

It would be nice to have a tech-prereq apply to an overall branch the same way an era-prereq does. This way you could have a specific tech like "Monarchy" for example, unlock an entire Monarchy policy branch and not just the policy itself.
 
This way you could have a specific tech like "Monarchy" for example, unlock an entire Monarchy policy branch and not just the policy itself.

I'm pretty sure you can. What the UI shows as a branch is internally treated as the first policy in a tree; it's POLICY_TRADITION, POLICY_LIBERTY, and so on. So it's still listed in the same table as the rest, which means it still has the same TechPrereq field. Sure, the UI probably can't display that prereq even with my fix, but it SHOULD work.
 
I'm pretty sure you can. What the UI shows as a branch is internally treated as the first policy in a tree; it's POLICY_TRADITION, POLICY_LIBERTY, and so on. So it's still listed in the same table as the rest, which means it still has the same TechPrereq field. Sure, the UI probably can't display that prereq even with my fix, but it SHOULD work.

I've tried that because I thought the exact same thing - all that happens is that you don't get the policy when you activate the branch. It's kind of unfortunate because I totally agree that it should work.
 
It's kind of unfortunate because I totally agree that it should work.

Ah, the Civ5 Mantra. (Not to be confused with "It's all a game, I should really just relax".)

When I get home I'll post my change to SocialPolicyPopup that displays tech prerequisites. (There's also a small XML component for the text keys, of course.) I HIGHLY recommend adding it to a mod if you're going to start tweaking policy tech prerequisites. I also edited TechButtonInclude to display the unlocked policy's icon in the tech tree at the tech in question, again with an XML bit, but I've changed so many other things in that file that it might be harder to splice into your own mods.

Thing is, after using it for a while now, I can say that tech prerequisites for policies are a bit... awkward. Remember that you can't (by default) save up policies, and culture generation is not very "tunable"; like research, it's basically set by your cities and what they have in them, so outside of choosing whether or not to work a Landmark or certain natural wonders, or Artist specialists, there's not much you can adjust if you need just a little more/less culture for a few turns. (Research is the same way, but I find myself running Scientist specialists way more often than Artists.) So if you make the tech prereqs too restrictive, then the player could be left without good choices, while delaying by even a turn or two would make a huge difference. The AI, for obvious reasons, would not be as good at this as a human.

Also, it's very all-or-nothing. My own mod adds one additional policy to each of the ten trees, and only that one policy has a tech prerequisite, all of which fall in my future eras. So there's a lot of backtracking, as you grab, say, all but the final Tradition or Liberty policy in the early eras and then come back several millenia later for the final policy. (The final Tradition policy is actually the LAST of the ten to unlock.)
If you were to do this organically, with EVERY policy having a distinct prerequisite, then this'd work a bit better. But it'd also be more prone to balance issues, so it's a hard thing to balance.
 
Okay, as promised, here are a few useful functions.

In SocialPolicyPopup.lua (UI/InGame/Popups/), about halfway down (I've included the first few lines so that you can see where to add it):

Spoiler :
Code:
			-- Policy is locked
			else
				--thisPolicyIcon.Lock:SetTexture( lockTexture ); 
				thisPolicyIcon.MouseOverContainer:SetHide( true );
				--thisPolicyIcon.Lock:SetHide( true ); 
				thisPolicyIcon.PolicyIcon:SetDisabled( true );
				--thisPolicyIcon.Lock:SetHide( false ); 
				--thisPolicyIcon.PolicyIcon:SetVoid1( -1 );
				thisPolicyIcon.PolicyImage:SetColor( fadeColorRV );
				IconHookup( policyInfo.PortraitIndex, 64, policyInfo.IconAtlas, thisPolicyIcon.PolicyImage );
				-- Tooltip

-- START OF NEW CODE
				local TechPrereq = policyInfo.TechPrereq;
				if( TechPrereq == nil ) then
					strTooltip = strTooltip .. "[NEWLINE][NEWLINE]" .. Locale.ConvertTextKey("TXT_KEY_POLICY_CANNOT_UNLOCK");
				else
					local TechID = 0;
					local TechDesc = "";
					for tech in GameInfo.Technologies() do
						if( tech.Type == TechPrereq ) then
							TechID = tech.ID;
							TechDesc = tech.Description;
						end
					end
					local tNum = player:GetTeam();
					if( Teams[tNum]:IsHasTech(TechID) ) then
						strTooltip = strTooltip .. "[NEWLINE][NEWLINE]" .. Locale.ConvertTextKey("TXT_KEY_POLICY_CANNOT_UNLOCK");
					else
						local strPText = Locale.ConvertTextKey( TechDesc );
						strTooltip = strTooltip .. "[NEWLINE][NEWLINE]" .. Locale.ConvertTextKey("TXT_KEY_POLICY_CANNOT_UNLOCK_TECHPREREQ", strPText);
					end
				end
			end

This'll require one little XML addition:
Code:
  <Language_en_US>
		<Row Tag="TXT_KEY_POLICY_CANNOT_UNLOCK_TECHPREREQ">
			<Text>[COLOR_WARNING_TEXT]Requires the[ENDCOLOR] [COLOR_POSITIVE_TEXT]{1_TechType:textkey}[ENDCOLOR] [COLOR_WARNING_TEXT]Technology.[ENDCOLOR]</Text>
		</Row>
  </Language_en_US>

With the above changes, the game will now say which techs are needed, for policies that you don't meet the tech requirement for. Once you DO have the tech, it'll automatically switch to the more generic "must select the other policies first" message.

Also, another useful tidbit that adds the policy's icon to the tech tree:
in UI/InGame/TechTree, TechButtonInclude.lua, insert this about halfway down (AFTER the processCondition declaration):
Spoiler :
Code:
	for row in GameInfo.Policies(processCondition) do
		local buttonName = "B"..tostring(buttonNum);
		local thisButton = thisTechButtonInstance[buttonName];
		if thisButton then

			IconHookup( row.PortraitIndex, textureSize, row.IconAtlasAchieved, thisButton );
--			IconHookup( 0, textureSize, "GENERIC_FUNC_ATLAS", thisButton );

			thisButton:SetHide( false );
			local strPText = Locale.ConvertTextKey( row.Description );
			thisButton:SetToolTipString( Locale.ConvertTextKey("TXT_KEY_POLICY_TECHPREREQ", strPText ) );
			buttonNum = buttonNum + 1;
		end
	end

which in turn requires another small text key addition:
Code:
  <Language_en_US>
		<Row Tag="TXT_KEY_POLICY_TECHPREREQ">
			<Text>{1_PolicyType:textkey} policy unlocks.</Text>
		</Row>
  </Language_en_US>
 
Ah, the Civ5 Mantra. (Not to be confused with "It's all a game, I should really just relax".)

When I get home I'll post my change to SocialPolicyPopup that displays tech prerequisites. (There's also a small XML component for the text keys, of course.) I HIGHLY recommend adding it to a mod if you're going to start tweaking policy tech prerequisites. I also edited TechButtonInclude to display the unlocked policy's icon in the tech tree at the tech in question, again with an XML bit, but I've changed so many other things in that file that it might be harder to splice into your own mods.

Thing is, after using it for a while now, I can say that tech prerequisites for policies are a bit... awkward. Remember that you can't (by default) save up policies, and culture generation is not very "tunable"; like research, it's basically set by your cities and what they have in them, so outside of choosing whether or not to work a Landmark or certain natural wonders, or Artist specialists, there's not much you can adjust if you need just a little more/less culture for a few turns. (Research is the same way, but I find myself running Scientist specialists way more often than Artists.) So if you make the tech prereqs too restrictive, then the player could be left without good choices, while delaying by even a turn or two would make a huge difference. The AI, for obvious reasons, would not be as good at this as a human.

Also, it's very all-or-nothing. My own mod adds one additional policy to each of the ten trees, and only that one policy has a tech prerequisite, all of which fall in my future eras. So there's a lot of backtracking, as you grab, say, all but the final Tradition or Liberty policy in the early eras and then come back several millenia later for the final policy. (The final Tradition policy is actually the LAST of the ten to unlock.)
If you were to do this organically, with EVERY policy having a distinct prerequisite, then this'd work a bit better. But it'd also be more prone to balance issues, so it's a hard thing to balance.

I look forward to seeing the code and appreciate your taking time to answer questions. I was hoping I could ask a few more here:

Is it possible to create a system by which I can make policies in one tree far more expensive than they would normally be through a leader trait?

Is it possible to add and remove leader traits as the game progresses? I'm thinking of removing leaders and instead adding the 'government' as the controller which will change based on events going on in the nation. Assuming that's all possible.
 
Yet another question; Can you assign policies based off an event like completing the construction of a building?
 
Yet another question; Can you assign policies based off an event like completing the construction of a building?

No, because there's no event for completing the construction of a building.

I'm serious. The Serial Events were made for UI reasons, to tell the engine when to draw something (unit, improvement, whatever), and since you don't do that for non-wonder buildings, there's no one for buildings, and there aren't a lot of non-UI ingame events. The closest you can come is use the SaveData/LoadData functions to see if the building was there on the previous turn and if it wasn't before but is now, then do something. That's how the "Building Resources" mod works, for instance.

Now, if you wanted a specific policy to ONLY be available through a building/wonder, then that's a bit different. At the start of each turn, look for that building, and if you have it but don't have the policy in question, then award the policy. I've done the same with a custom technology I've added that's only available when you launch the spaceship (which doesn't end the game in my mod, obviously). The problem with doing this for a policy is finding a way to "disable" the policy. Sure, you can set its TechPrereq to Future Tech so that it stays locked all game long (or better yet, create a Disabled tech that you'll never award, and put it there), but which policy branch do you put it in? (This'd invariably screw up the Cultural win.)
 
Back
Top Bottom