Custom Unit is Given to Every Civ When Starting in a Later Era

Mr. Spiffy

Chieftain
Joined
Mar 5, 2016
Messages
20
Location
Tennessee
One of my custom units has its own unit classes. It is supposed to be only available to my custom civ, and it is in that only my custom civ can train it. However, when starting the game in the Classical Era or above, everyone gets this custom unit as part of the starting unit package.

To be more specific, there are 8 custom units (each with their respective unit classes), trainable only in their respective eras. I haven't been able to find out much about how advanced starts work, so I experimented a bit. Tinkering with the strength and advanced start cost of my custom units did nothing. This is odd, because my custom units for certain eras match up with the era that the player starts in.

I would like to make it to where this custom unit is excluded from advanced starts completely. Even the custom civ starting with extra of these units is broken. How can I fix this issue?
 
Did you add your custom units to Civilization_UnitClassOverrides?

I have not. Since there are 8 of them, I would have to replace 8 base game units. That would be way too many.

Are there unused unit classes that I could replace, so that it looks like I didn't get rid of any units with the override?
 
There are no unused unit classes.
You can add a policy requirement to your units and give that policy to your custom civ using lua script.
 
There are no unused unit classes.
You can add a policy requirement to your units and give that policy to your custom civ using lua script.

Excellent idea. I've never done stuff with policies, but I'm sure it won't be too difficult. I'll try that out.
 
When giving player a dummy policy use this code:
Code:
pPlayer:SetNumFreePolicies(1)
pPlayer:SetNumFreePolicies(0)
pPlayer:SetHasPolicy(iPolicyID, true)
Otherwise next policy cost will get bugged and will not increase when player gets vanilla policies.
 
When giving player a dummy policy use this code:
Code:
pPlayer:SetNumFreePolicies(1)
pPlayer:SetNumFreePolicies(0)
pPlayer:SetHasPolicy(iPolicyID, true)
Otherwise next policy cost will get bugged and will not increase when player gets vanilla policies.

I used the Game Event PlayerCityFounded and set the social policy to true every time a city gets founded. This seems to work without the two lines about SetNumFreePolicies. With those two lines, every time I founded a city, the cost of obtaining a new policy actually went down. When using PlayerDoTurn, those two lines seem to be necessary though.
 
I used the Game Event PlayerCityFounded and set the social policy to true every time a city gets founded. This seems to work without the two lines about SetNumFreePolicies. With those two lines, every time I founded a city, the cost of obtaining a new policy actually went down. When using PlayerDoTurn, those two lines seem to be necessary though.
Whatever method you use to give a policy (ie, PlayerDoTurn or PlayerCityFounded) you need to do as:
Code:
if not pPlayer:HasPolicy(iPolicyID) then
	pPlayer:SetNumFreePolicies(1)
	pPlayer:SetNumFreePolicies(0)
	pPlayer:SetHasPolicy(iPolicyID, true)
end
Otherwise you get re-firing of the 'free' policy as well as re-firing of the pPlayer:SetHasPolicy(iPolicyID, true) line. This later won't change the social policy cost of the next policy, but the giving of a free policy which is then not used up certainly will.

The method specified is tried and true. If you are doing this:
Code:
pPlayer:SetHasPolicy(iPolicyID, true)
without also doing this
Code:
pPlayer:SetNumFreePolicies(1)
pPlayer:SetNumFreePolicies(0)
You are in fact derailing the standard social policy cost calculations.
 
I see what you guys were saying. It's now working as it should with those two lines in place. All problems should be clear. Thanks for the extra effort in telling me this. I was just about to publish it with that flaw still in there.
 
Back
Top Bottom