Separtate Social Policies for Each Civ???

Formulapower

Warlord
Joined
Nov 5, 2007
Messages
148
I am working on a mod where I want only certain civs to have access to a specific social policy tree. Just like the Scenario "Fall of Rome" in the G&K Expansion. I have looked through the lua code for the Rome scenario but nothing makes any sense to me...I have only a little experience with lua so any help from some of you more seasoned modders would be great!

Thanks
 
Fall of Rome disables policy branch acquisition by default.

Code:
function CanAdoptPolicyBranch (iPlayerID, iPolicyBranch)
	return false;
end
GameEvents.PlayerCanAdoptPolicyBranch.Add(CanAdoptPolicyBranch);

It then assigns default social policies:

Code:
function SetInitialSocialPolicies ()

	for iPlayerLoop = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
		local pPlayer = Players[iPlayerLoop];
		if (pPlayer:IsAlive()) then
			if (IsRoman(iPlayerLoop)) then		
				pPlayer:SetPolicyBranchUnlocked(GameInfo.PolicyBranchTypes["POLICY_BRANCH_ROMAN"].ID, true);
				pPlayer:SetHasPolicy(GameInfo.Policies["POLICY_ROMAN_ATROPHY"].ID, true);
			elseif (IsSassanid(iPlayerLoop)) then
				pPlayer:SetPolicyBranchUnlocked(GameInfo.PolicyBranchTypes["POLICY_BRANCH_SASSANID"].ID, true);	
				pPlayer:SetHasPolicy(GameInfo.Policies["POLICY_SASSANID_HERITAGE"].ID, true);
			else 
				pPlayer:SetPolicyBranchUnlocked(GameInfo.PolicyBranchTypes["POLICY_BRANCH_BARBARIAN"].ID, true);
				pPlayer:SetHasPolicy(GameInfo.Policies["POLICY_BARBARIAN_HERITAGE"].ID, true);		
			end
		end
	end
end

It's a really hard-coded method of doing things, and for your purposes you don't want to do it this way.

My next question is: Are you good at coding? Are you willing to learn programming?
 
I'm very willing to learn. I have done some lua stuff but it's all pretty simple...such as making civs go to war on a specific turn or declaring war when one civ conquers a specific city...etc
 
Here would be the steps I would take in order to get this working.

  1. Add a new table called "PolicyBranch_CivilizationDisables" with columns "CivilizationType" and "PolicyBranch"
  2. CivilizationType would accept just that, for example CIVILIZATION_EGYPT
  3. PolicyBranchDisable would accept a policy branch, for example POLICY_BRANCH_LIBERTY
  4. In LUA, in CanAdoptPolicyBranch: Check to see if this policybranch and the player's civilization type match in the table PolicyBranch_CivilizationDisables.
  5. If they match, then return false (can't adopt)
  6. If they don't match, return true (can adopt)

Now, in your table, you'll create a new row with CivilizationType=CIVILIZATION_EGYPT and PolicyBranchDisable = POLICY_BRANCH_LIBERTY. You can do this with XML or SQL. Your choice.

...if I have time I can provide the code to do this, if you'd like. But try it out on your own, and see what you can come up with.
 
hold on...did some research should be something like this

<GameData>
<Table Name="MyColors">
<Column name="ID" type="integer" primarykey="true" autoincrement="true"/>
<Column name="Type" type="text" notnull="true" unique="true"/>
</Table>
</GameData>
 
more like this?


<Table Name="PolicyBranch_CivilizationDisables">
<Column name="CivilizationType" type="text" reference="Civilizations(Type)"/>
<Column name="PolicyBranch" type="text" reference="PolicyBranchTypes(Type)"/>
</Table>
 
ok I think I got the table..but I am lost on the lua code here is what i got


<GameData>
<Table Name="PolicyBranch_CivilizationDisables">
<Column name="CivilizationType" type="text" reference="Civilizations(Type)"/>
<Column name="PolicyBranch" type="text" reference="PolicyBranchTypes(Type)"/>
</Table>
<!-- Table data -->
<PolicyBranch_CivilizationDisables>
<CivilizationType>CIVILIZATION_GERMANY</CivilizationType>
<PolicyBranch>POLICY_BRANCH_TRADITION</PolicyBranch>
</PolicyBranch_CivilizationDisables>
</GameData>
 
Hm. I would use SQL for creating the new table, just because I think it looks a little cleaner.

Pardon me, I'm not an SQL expert here, but something like this'll probably work. I'm using the syntax from w3schools.com because SQL is fairly new to me, so the syntax may be off, but the general idea is this:

Code:
-- Create a new table with two columns
CREATE TABLE PolicyBranch_CivilizationDisables
(
	CivilizationType	text,
	PolicyBranch		text,
);

-- Insert new rows into this table...
-- America won't be able to get "Tradition"
INSERT INTO PolicyBranch_CivilizationDisables (CivilizationType, PolicyBranch)
VALUES ("CIVILIZATION_AMERICA", "POLICY_BRANCH_TRADITION");

-- Aztecs won't be able to get "Liberty"
INSERT INTO PolicyBranch_CivilizationDisables (CivilizationType, PolicyBranch)
VALUES ("CIVILIZATION_AZTEC", "POLICY_BRANCH_LIBERTY");

-- Germany won't be able to get "Tradition"
INSERT INTO PolicyBranch_CivilizationDisables (CivilizationType, PolicyBranch)
VALUES ("CIVILIZATION_GERMANY", "POLICY_BRANCH_TRADITION");

I was gonna write the LUA code right now, but I'm exhausted right now...I have no energy and will to do that right now. ;) Besides I know somebody else in this forum is 3x the LUA scripter than I am, so maybe they'll jump in to help.

But you definitely would start like this:

Code:
GameEvents.PlayerCanAdoptPolicyBranch.Add(function (iPlayerID, iPolicyBranch)

      -- code goes here...

end);
 
Back
Top Bottom