Thalassicus
Bytes and Nibblers
Thalassicus, i've not included some stuff like modifiers for garrisoned units, occupied and puppeted cities, as i think there have to be more complex mechanics to introduce these. e.g. garrisoned unit lowering emigration has not much scence if player runs freedom policy (or liberty).
That makes perfect sense. Looking through the game's lua code, it seems player:HasPolicy(index) would be helpful. It doesn't take policies by name so it'd be passed through a new utility function. Hmm...
Basically, a table can be added for policy modifiers. If the lua code detects the player has any of the excluded policies, or doesn't have a required policy, it ignores the weight. What if the Military Cast policy is required to let garrisons reduce emigration? It's the policy that reduces unhappiness when units are garrisoned. Something like this...
PHP:
XML
<Emigration_Weight_Policy_Requirements>
<Row>
<WeightType>GetGarrisonedUnit</WeightType>
<PolicyType>POLICY_FREEDOM</PolicyType>
<ExcludesWeight>true</ExcludesWeight>
</Row>
</Emigration_Weight_Policy_Requirements>
or
<Emigration_Weight_Policy_Requirements>
<Row>
<WeightType>GetGarrisonedUnit</WeightType>
<PolicyType>POLICY_MILITARY_CASTE</PolicyType>
</Row>
</Emigration_Weight_Policy_Requirements>
PHP:
cityWeight[cityID] = 1;
-- retrieve function and weight from jump table stored with XML
for weight in GameInfo.Emigration_Weights() do
if weight.IsCityStatus and city[weight.Type](city) then
local bUseWeight = true;
for j in GameInfo.Emigration_Weight_Policy_Requirements() do
if weight.Type == j.WeightType then
if (j.ExcludesWeight and hasPolicyName(pPlayer, j.PolicyType)) then
bUseWeight = false;
elseif (not j.ExcludesWeight and not hasPolicyName(pPlayer, j.PolicyType)) then
bUseWeight = false;
end
end
end
if bUseWeight then
cityWeight[cityID] = cityWeight[cityID] * weight.Value;
end
end
end
-- factor in culture
cityWeight[cityID] = cityWeight[cityID] / (GameInfo.Emigration_Weights["Culture"].Value * math.log(city:GetJONSCultureThreshold() + 2));
totalWeight = totalWeight + cityWeight[cityID];
PHP:
function hasPolicyName(player, policyName)
for policy in GameInfo.Policies() do
if policy.Type == policyName then
return player:HasPolicy(policy.ID);
end
end
return false;
end
I've been thinking about culture modifiers for a while, it seems a logarithmic curve might work well. With the weight/log(threshold+2) done above, cities with no culture would be about 3 times as likely to lose emigrants as cities with a 500 culture-threshold. (Threshold is the culture required for the next border expansion. There doesn't appear to be a function to read a city's total culture, so this is an approximation.) With the original weight/threshold formula I tried these cities were 25 times as likely, which was probably too much.