Bugged lua?

Craig_Sutter

Deity
Joined
Aug 13, 2002
Messages
2,773
Location
Calgary, Canada
I have been using the following code to install religions in my scenario... here is one example of the founding of Christianity in Paris...

Code:
-- Find Paris player and found Christianity in their city, returning the city

function EstablishChristian()
if Game.GetElapsedGameTurns() == 0 then

function CreateChristianHolyCity(pCity, religion, pantheonBelief, founderBelief, followerBelief, followerBelief2, enhancerBelief)
  local iPlayer = pCity:GetOwner()
  local iReligion = GameInfoTypes[religion]

  -- Optional extra beliefs
  local iBelief4 = followerBelief2 and GameInfoTypes[followerBelief2] or -1
  local iBelief5 = enhancerBelief and GameInfoTypes[enhancerBelief] or -1

  Game.FoundPantheon(iPlayer, GameInfoTypes[pantheonBelief])
  Game.FoundReligion(iPlayer, iReligion, nil, GameInfoTypes[founderBelief], GameInfoTypes[followerBelief], iBelief4, iBelief5, pCity)
end

function FoundChristianity()
  for iPlayer=0, GameDefines.MAX_CIV_PLAYERS - 1 do
    local pPlayer = Players[iPlayer]
    if (pPlayer:IsEverAlive()) then

	for pCity in pPlayer:Cities() do

				-- City exists and has the proper name?
    			if pCity ~= nil and pCity:GetName() == "Paris" then

		             CreateChristianHolyCity(pCity, "RELIGION_CHRISTIANITY", "BELIEF_FORMAL_LITURGY",
					"BELIEF_CHURCH_PROPERTY", "BELIEF_CATHEDRALS",  "BELIEF_MOSQUES", "BELIEF_RELIGIOUS_TEXTS");
					print ("okay, Paris is the Catholic holy city")
				return pCity
				end
			end
		end
	end
end

local pChristianPlot = FoundChristianity():Plot()

end
end

Events.SequenceGameInitComplete.Add(EstablishChristian)

The code has been working, but there are a couple of problems that I need advice on how to address:

1) My scenario has established via xml that there should be only 4 religions. I use the code above (with changes per each religion) to create holy cities for my scenario for each of the 4 religions. To my mind, that means no more pantheons may be founded in the game since max religions have been reached. In game, the religion panel says available religions=0, but pantheons are still being founded.

2) Even worse, the civilizations with the holy city under their name and having founded the religion are still able to add beliefs to their religion. My Celts, for example, founded the religion "Druidism" with 5 beliefs yet were able to add 2 more beliefs!!

I think that the game is not registering these religions as being founded when they are installed by lua. It is therefore ignoring the restrictions on purchases of beliefs.

This is not a new problem... my previous solution was simply to delete all beliefs but the ones needed for the religions. However, since BNW that seems to lead to a CTD, and I can no longer use that method.

Any suggestions as to how I can tell the game that it no longer needs to spend on pantheons and religions?

Has anyone else run into this problem?
 
Thank-you... I first created the function using 'Into the Renaissance' as a template. I think that because most of the religions start in city state cities that the founding expression incorporated all the beliefs for the religion. Didn't go far enough in examining the Protestant part so never new about the enhance function. It'll be easy to change my function to incorporate the new info you've provided.

Thank-you very much.
 
I have altered the code and it is enhancing the religion as specified...

However, I am still able to create a pantheon even with the maximum religions enchanced as allowed for the by map size (changed to "4" for "Huge" in XML).

The religion screen shows no more religions can be built.

Good thing is that my 4 enhanced religions no longer can get 2 more beliefs via enhancement so that is one of the two bugs corrected.

I can live with the extra pantheons being created as they will be stuck at pantheons and eventually overwhelmed by the enhanced religions.

Here is the modified code... if anyone has an idea about how to address the pantheon issue, I'm all ears.

Code:
-- Find Paris player and found Christianity in their city, returning the city

function EstablishChristian()
if Game.GetElapsedGameTurns() == 0 then

function CreateChristianHolyCity(pCity, religion, pantheonBelief, founderBelief, followerBelief, followerBelief2, enhancerBelief)
  local iPlayer = pCity:GetOwner()
  local iReligion = GameInfoTypes[religion]

  -- Optional extra beliefs
  local iBelief4 = followerBelief2 and GameInfoTypes[followerBelief2] or -1
  local iBelief5 = enhancerBelief and GameInfoTypes[enhancerBelief] or -1

  Game.FoundPantheon(iPlayer, GameInfoTypes[pantheonBelief])
  Game.FoundReligion(iPlayer, iReligion, nil, GameInfoTypes[founderBelief], GameInfoTypes[followerBelief], -1, -1, pCity)
  Game.EnhanceReligion(iPlayer, iReligion, GameInfoTypes[followerBelief2], GameInfoTypes[enhancerBelief]);
end

function FoundChristianity()
  for iPlayer=0, GameDefines.MAX_CIV_PLAYERS - 1 do
    local pPlayer = Players[iPlayer]
    if (pPlayer:IsEverAlive()) then

	for pCity in pPlayer:Cities() do

				-- City exists and has the proper name?
    			if pCity ~= nil and pCity:GetName() == "Paris" then

		             CreateChristianHolyCity(pCity, "RELIGION_CHRISTIANITY", "BELIEF_GOD_KING",
					"BELIEF_PAPAL_PRIMACY", "BELIEF_CATHEDRALS",  "BELIEF_MOSQUES", "BELIEF_RELIGIOUS_TEXTS");
					print ("okay, Paris is the Catholic holy city")
				return pCity
				end
			end
		end
	end
end

local pChristianPlot = FoundChristianity():Plot()

end
end

Events.SequenceGameInitComplete.Add(EstablishChristian)

As I said, still the pantheon creation issue, but it's not a biggie.
 
Solved... looked over "Into the Renaissance". Noticed all world sizes had max religion set at "3" even though 4 religions were in the scenario.

I'm guessing the number of enhanced religions is only counted when a major civ is involved. Since one of my "founders" is a minor civilization, I'm guessing it does is not counted by the lua method that tracks such things.

I changed number of religions to "3" and now no pantheon belief is available.
 
Back
Top Bottom