How to quickly spread a religion for testing purposes?

PawelS

Ancient Druid
Joined
Dec 11, 2003
Messages
2,811
Location
Poland
I need to test some religious aspects of my mod, and therefore I need a religion to be present in several cities.

Is there a way to do it quickly? Spawning a prophet or missionary using FireTuner doesn't work, as the spawned unit won't have a religion.
 
In-game Editor.
 
Spawning a prophet or missionary using FireTuner doesn't work, as the spawned unit won't have a religion.
I assume you're using Player.InitUnit()? Spawning a missionary with InitUnit into a city that already has a majority religion works perfectly fine for me.

I use this command to instantly found a religion:
Code:
Players[0]:SetFaith(Game.GetMinimumFaithNextPantheon()) Game.FoundPantheon(0, GameInfoTypes["BELIEF_FAITH_HEALERS"]) Game.FoundReligion(0, GameInfoTypes["RELIGION_CHRISTIANITY"], nil, GameInfoTypes["BELIEF_TITHE"], GameInfoTypes["BELIEF_CATHEDRALS"], -1, -1, Players[0]:GetCapitalCity())
 
I'm not using the console, just the "unit plopper" feature of the FireTuner. And I want to spread a religion to a city that doesn't have a majority religion, preferably without the need to move the unit there manually (founding a religion is easy, I just need to spawn a prophet.)

I'm somewhat reserved when it comes to using IGE, as I'm afraid it might interfere with my mod. This time I moved the Prophets manually to the cities where I needed them, but I guess I'll try IGE the next time I need to spread a religion.
 
I'm not using the console, just the "unit plopper" feature of the FireTuner. And I want to spread a religion to a city that doesn't have a majority religion, preferably without the need to move the unit there manually (founding a religion is easy, I just need to spawn a prophet.)

I'm somewhat reserved when it comes to using IGE, as I'm afraid it might interfere with my mod. This time I moved the Prophets manually to the cities where I needed them, but I guess I'll try IGE the next time I need to spread a religion.
I haven't found using IGE to test things causes any different behavior than the game will naturally have. With the exception that plopping a building or a unit directly from IGE does not cause the CityConstructed and CityTrained events to fire (I don't think LiveTuner does either), and I don't think as I remember that you get the correct experience, promotions, etc., that you otherwise would by producing or buying a unit in the normal way.

I don't plop missionaries, inquisitors, or Great Prophets using IGE directly, though. I use IGE to give me the requisite faithpoints and then use the game's regular in-game systems to actually buy or create the units. For the 1st and 2nd Great Prophet this can be a bit of a PITA because of the RNG on when exactly the game will pop the Great Prophet. I also found that even if you have 200 FaithPoints, if you aren't making any FPT the game never seems to pop that 1st Great Prophet. So in these cases I always plop a shrine into the capital city of the civ I am using for the test.

Once you use the game's normal system to buy the Missionary or Great Poprhet, you can advance turn and then IGE-teleport the unit wherever desired in order to test what you are really trying to test.
 
IGE also has a SetFollwers function. I extracted it from the mod and changed a couple iterators to remove null pointer errors, but all in all I have absolutely no idea how it works. I also haven't put extensive any testing into how it works if not surrounded by the IGE context, so I actually, um, don't know if it works at all.

That said, it may be worth a shot:
Spoiler :
Code:
-- From: IGE (modified)
function ConvertState(state, sourceID, targetID, toConvert)
	-- Enough people from that other religion?
	local converted = toConvert
	if state[sourceID] < toConvert then
		converted = state[sourceID]
	end

	state[sourceID] = state[sourceID] - converted;
	state[targetID] = state[targetID] + converted;
	return toConvert - converted;
end

-- From: IGE (modified)
function SetFollowers(pCity, religionID, num)
	local current = pCity:GetNumFollowers(religionID);
	if (num == current) then return end

	-- Get followers state
	local count = 0;
	local state = {}
	for row in GameInfo.Religions() do
		state[row.ID] = pCity:GetNumFollowers(row.ID);
		count = count + state[row.ID];
	end
	state[-1] = pCity:GetPopulation() - count;

	if num < current then
		-- Convert to atheists
		ConvertState(state, religionID, -1, current - num);
	else
		local toConvert = num - current;

		-- Convert from atheists
		toConvert = ConvertState(state, -1, religionID, toConvert)

		-- Convert from pantheon
		toConvert = ConvertState(state, 0, religionID, toConvert)

		-- Convert from group with max followers, one at a time
		while toConvert > 0 do
			local maxFollowers = 0;
			local sourceID = -1;
			for row in GameInfo.Religions() do
				if row.ID ~= religionID and row.ID > 0 then
					if state[row.ID] > maxFollowers then
						sourceID = row.ID;
						maxFollowers = state[row.ID];
					end
				end
			end
			if sourceID == -1 then break end

			if ConvertState(state, sourceID, religionID, 1) == 0 then
				toConvert = toConvert - 1;
			end
		end
	end	

	SetReligionState(pCity, state);
end

-- From: IGE (modified)
function SetReligionState(pCity, state)

	-- What is the majority?
	local maxFollowers = -1;
	local majority = -1;
	for i in pairs(state) do
		state[i] = math.floor(state[i] + 0.5)
		if state[i] > maxFollowers then
			majority = i;
			maxFollowers = state[i]
		end
	end

	-- EDIT: Those crashes may actually have only been caused by tests with a religion not founded yet. Doesn't matter, leave the code like that
	-- ConvertPercentFollowers is full of nasty bugs (can only convert from majority to minority) hence this twisted method
	pCity:AdoptReligionFully(majority);
	print("Done fully adopting")

	for i, v in pairs(state) do
		if i ~= majority and i >= 0 then
			-- Convert 1% at a time because followers are internally stored as real numbers.
			while (pCity:GetNumFollowers(i) + 0.5) < v do
				pCity:ConvertPercentFollowers(i, majority, 1)
			end
		end
	end
	print("Done increasing minorities.")

	-- We do atheists in the end because of a rounding error in civ5 (sum of followers can be population + 1)
	-- Since they're never displayed, we actually use the majority as a loop condition.
	if majority >= 0 then
		while (pCity:GetNumFollowers(majority) - 0.5) > state[majority] do
			pCity:ConvertPercentFollowers(-1, majority, 1)
		end
	end
	print("Done lowering majority.")
end

And I encourage you, Pawel, to use the console. But you'd have to extend the command to this:
Code:
Players[0]:SetFaith(Game.GetMinimumFaithNextPantheon()) Game.FoundPantheon(0, GameInfoTypes["BELIEF_FAITH_HEALERS"]) Game.FoundReligion(0, GameInfoTypes["RELIGION_CHRISTIANITY"], nil, GameInfoTypes["BELIEF_TITHE"], GameInfoTypes["BELIEF_CATHEDRALS"], -1, -1, Players[0]:GetCapitalCity()) Players[0]:InitUnit(GameInfoTypes.UNIT_MISSIONARY, Players[0]:GetCapitalCity():GetX(), Players[0]:GetCapitalCity:GetY())
 
Top Bottom