Policy/Science Editing

formerdc81

Chieftain
Joined
Nov 19, 2018
Messages
53
I am trying to make a simple balance mod, but I'm not really sure what is hard-coded and what isn't.

I tried editing SCIENCE_PER_POPULATION in GlobalDefines.xml from 1 to 0.5, but apparently, it only accepts integer values and my choices are 1 or 0.
I tried editing Palace to grant 50% science per population, but there is no way to make the effect global. It only works for the capital.
I tried creating a new, hidden psuedo-library, but I don't know how to get it to automatically be built inside every new city.
At this point, I'm frustrated enough that I'd rather find the place where SCIENCE_PER_POPULATION is parsed in C++ and change it from int to float.

Similarly, I tried to edit Tradition opener's 3 culture to the capital city in Policies.xml but I can't seem to find any mention of it. Is it hard-coded? It makes no sense though, because CapitalPolicyYieldChanges already exists as a table, why did the makers of Civ not include it in there?

For those of you write LUA scripts to solve this problem, how do you even know what are the names of the variables used by the game? When I read many of your scripts, it's clear you are calling on internal game variables. How do you guys know the names of such variables?
 
Last edited:
At this point, I'm frustrated enough that I'd rather find the place where SCIENCE_PER_POPULATION is parsed in C++ and change it from int to float.

... and then find all the other places where Firaxis use that value in calculations and change those as well. If you find XML modding frustrating and Lua coding a "black art of knowing", they are degrees easier than delving into the DLL C++ source code!

There are a number of tutorials and links to this stuff in the Tutorials sub-forum and on the Wiki pages (may be out-of-date, but will get you started).

Also, one of the best sources of knowledge is to find similar mods and look to see how they do the bits you're interested in.
 
Well, that's probably why my editing hasn't been so successful. Downloading the SDK now. I'll repost when I have real progress.
 
Tradition's "opener" policy is POLICY_TRADITION
Code:
	<Policy_BuildingClassCultureChanges>
		<Row>
			<PolicyType>POLICY_TRADITION</PolicyType>
			<BuildingClassType>BUILDINGCLASS_PALACE</BuildingClassType>
			<CultureChange>3</CultureChange>
		</Row>
	</Policy_BuildingClassCultureChanges>
The reason this is not done in the <Policy_CapitalYieldChanges> table probably has to do with the Culture effect of Tradition on the capital city is "inherited" from Vanilla, when the entire system for Culture was different and not nearly as modding-friendly. The game still has all manner of Something_SomethingCultureChanges tables that are really no longer needed but still actually work for Culture. Firaxis did not go to the extra labor of eliminating the data from the "old" tables and moving it to the "new" tables when they re-drafted how Culture works in the XML/SQL as part of the Gods & Kings expansion.

One way to add a hidden building in every city would be to add the new hidden building's BuildingClass as a <FreeBuilding> to the Palace:
Code:
<GameData>
    <Buildings>
        <Update>
           <Where Type="BUILDING_PALACE" />
           <Set FreeBuilding="BUILDINGCLASS_PSEUDO_LIBRARY" />
        </Update>
    </Buildings>
</GameData>
In the example update, BUILDINGCLASS_PSEUDO_LIBRARY would be the Class of Building that will be added to every city.

How do you guys know the names of such variables?
Back in the day when I learned lua I extensively relied on the wiki, and then later on William's reference https://forums.civfanatics.com/threads/bnw-lua-api-reference.558353/
 
Last edited:
I tried creating a new, hidden psuedo-library, but I don't know how to get it to automatically be built inside every new city.
One way to add a hidden building in every city would be to add the new hidden building's BuildingClass as a <FreeBuilding> to the Palace

I suspect that setting <FreeStartEra>ERA_ANCIENT</FreeStartEra> (on the dummy) would do the trick too.
This way you don't need to deal with palace-UBs either.

...and then later on William's reference...
Those references have saved me so much time since I found them! :lol:
 
Thank you everyone for your help! As for the Science code, I figured it out in the C++, though my solution isn't optimal yet.

There's a line that says:
Code:
ChangeBaseYieldRateFromMisc(YIELD_SCIENCE, (iNewValue - iOldPopulation) * GC.getSCIENCE_PER_POPULATION());
where this function call only happens only when the population is changed (by natural growth/starvation, a nuclear bomb, or Order's settlement of a new city with 3 population). However, the second argument must be an integer. Since I was too sleepy last night to debug properly, I just replaced it with this:
Code:
ChangeBaseYieldRateFromMisc(YIELD_SCIENCE, iNewValue * GC.getSCIENCE_PER_POPULATION() / 100 - iOldPopulation * GC.getSCIENCE_PER_POPULATION() / 100);
A value of SCIENCE_PER_POPULATION of 50 means 50% science per population, rounded down. I should fix the round down for public release, but the extra bit of nerf suits me just fine.
 
Last edited:
Back
Top Bottom