Free missionaries after founding a religion?

Ok, so the proposed code would not work, at least not the part that deals with happiness.

IIRC it was one of the first reasons that the TC modders jumped through the hoops of adding/removing invisible buildings ;)
 
So if the part about giving +5 happiness doesn't work, how can we get it to work? I think it's a reasonable assumption that we don't just make a building in the capital with +5 happiness when the civ has a religious majority of their own religion, then remove the building if they don't...

Actually, how well would that work, if we used the same City.SetNumberRealBuilding() method as before, with the free missionaries dummy building? Then all we (I) need to do is make a dummy building that gives 5 happiness, plug it into the code... could that work better?
 
This might work :
Code:
local function AdoptReligionFullyIfMajorityFriendlyReligionAndHappyIfAlsoOwnsHolyCity()
	for playerID = 0, GameDefines.MAX_MAJOR_CIVS - 1 do
		local player = Players[ playerID ];
		if player:IsAlive()
			and player:HasCreatedReligion()
			and player:GetCivilizationType() == GameInfoTypes.CIVILIZATION_THIS_CIV
		then
			local religionID = player:GetReligionCreatedByPlayer();
			for city in player:GetCities() do
				if city:GetReligiousMajority() == religionID then
					city:AdoptReligionFully( religionID );
				end
			end
			local holyCity = Game.GetHolyCityForReligion( religionID, playerID );
			if holyCity and holyCity:GetOwner() == playerID then
				holyCity:SetNumRealBuilding( GameInfoTypes.BUILDING_FIVE_FREE_HAPPINESS, player:HasReligionInMostCities( religionID ) and 1 or 0 );
			end
		end
	end
end
Events.ActivePlayerTurnStart.Add( AdoptReligionFullyIfMajorityFriendlyReligionAndHappyIfAlsoOwnsHolyCity );
 
Okay, something about the code is making the game crash. I play as my new civ and the music on the loading screen stops, and upon opening task manager I get a message saying the game crashed. It wasn't even able to make a log entry about the problem with the mod. :(

At least with the old code the game started, but I'm not quite sure what's wrong. I replaced the old lua for this one (remembering to change CIVILIZATION_THIS_CIV) and used this for the building xml:
Code:
<GameData>
	<BuildingClasses>
		<Row>
			<Type>BUILDING_FIVE_FREE_HAPPINESS</Type>
			<DefaultBuilding>BUILDING_FIVE_FREE_HAPPINESS</DefaultBuilding>
			<Description>TXT_KEY_BUILDING_FIVE_FREE_HAPPINESS</Description>
		</Row>
	</BuildingClasses>-<Buildings>
		<Row>
			<Type>BUILDING_FIVE_FREE_HAPPINESS</Type>
			<BuildingClass>BUILDINGCLASS_FIVE_FREE_HAPPINESS</BuildingClass>
			<Cost>-1</Cost>
			<Help>TXT_KEY_BUILDING_FIVE_FREE_HAPPINESS_HELP</Help>
			<Description>TXT_KEY_BUILDING_FIVE_FREE_HAPPINESS</Description>
			<Civilopedia>TXT_KEY_BUILDING_FIVE_FREE_HAPPINESS_PEDIA</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_FIVE_FREE_HAPPINESS_STRATEGY</Strategy>
			<ArtDefineTag>TEMPLE</ArtDefineTag>
			<HolyCity>true</HolyCity>
			<Happiness>5</Happiness>
			<MinAreaSize>-1</MinAreaSize>
			<IconAtlas>CIV_COLOR_ATLAS_BUILDING_FIVE_FREE_HAPPINESS</IconAtlas>
			<PortraitIndex>0</PortraitIndex>
		</Row>
	</Buildings>
</GameData>
The current mod version is essentially the same as the attachment I posted a while back, except as I said before, it uses different building xml and lua. So it must be one of those, because the previous mod version at least started up.
 
Back
Top Bottom