A couple of assorted lua questions

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
2,984
Location
Operation Padlock ground zero
1) What UI file codes for being able to see your enemy's city if you have spy/diplomat stationed in it? I assume it's EspionageOverview.lua but I didn't find anything like that in it. (Or I just skimmed over it, since nothing in that file makes sense to me) The reason I ask is because I'd like to make a civ that, in essence, can't be spied on, by adding a line something along the lines of "and not (iTarget:GetCivilizationType() == GameInfoTypes.CIVILIZATION_WHATEVERTHECIVENDSUPBEING) then".*

2) Is there a lua function for getting the total number of followers of a religion? Like how tithe, world church and peace loving beliefs do? None were listed on the UI reference.

3) Does anyone have an idea about how to make a city more resistant to being converted to a different religion? The best I can think of is detecting if a city follows a certain religion, and if it does, adds a dummy building that increases its religious pressure.

3.5) I may also have a question about how to check if a civ is the first to found a religion, but I have an idea on how to do that....

TIA,
AW
 
Anyone? :(

For #3, I tried drafting up a test code:
Code:
function(iPlayer, pReligion)
	local pPlayer = Players[iPlayer]
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_GEORGIA) then
		if (pPlayer:HasCreatedReligion()) then
			local pReligion = pPlayer:GetReligionCreatedByPlayer()
			for pCity in pPlayer:Cities() do
				if (pCity:GetReligiousMajority() == pReligion) then
					pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_GEORGIA_DUMMY_PRESSURE, 1)
				else
					pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_GEORGIA_DUMMY_PRESSURE, 0)
				end
			end
		end
	end
end
Does anyone have any idea what event hook I should be using?
And I do see a problem with the whole thing, since wouldn't it increase religious pressure for all religions in the city? And optimally I would like it to not take effect only when it's the majority religion... but I couldn't find any functions at all that deal with religious pressure.
 
The reason I ask is because I'd like to make a civ that, in essence, can't be spied on...
While it isn't an ideal fit for what you're going for, you could use traits to give them a free building in every city that had -100% spy steal rate. Spies could still be put in their cities but it would only be for line of sight, never tech.

3) Does anyone have an idea about how to make a city more resistant to being converted to a different religion? The best I can think of is detecting if a city follows a certain religion, and if it does, adds a dummy building that increases its religious pressure.
Adding a building that increases pressure would makes the city's neighbors have higher pressure but cities don't self pressure. There is a lua function to convert a percent of a city's majority followers to another religion. You could call that when some specific thing happens.

3.5) I may also have a question about how to check if a civ is the first to found a religion, but I have an idea on how to do that.
I have some lua code that can detect when a religion is founded (it fires off a lua event when a religion is founded and has info on the holy city). It is in my Race for Religion mod.

Just hook into that event and test to see how many other religions are founded. If there is only one religion than you know that civ was the first to get a religion.
 
1) Would only work for the player, not the AI (as obviously the AI doesn't use the UI). You'll either need to use the "anti-espionage building in every city" approach or mod the DLL

2) Game.GetNumFollowers(iReligionType) and pCity:GetNumFollowers(iReligionType) - but only call the latter if pCity:IsReligionInCity(iReligionType) returns true

Can't remember if you use my DLL or not, but if so

3) can be done as I've added the ConversionModifier to the buildings table (works similar to EspionageModifier) - see "Global - Counter Religion"

3.5) Three game events added
Code:
GameEvents.PantheonFounded.Add(function(iPlayer, iCapitalCity, iReligion, iBelief1) end)
GameEvents.ReligionFounded.Add(function(iPlayer, iHolyCity, iReligion, iBelief1, iBelief2, iBelief3, iBelief4, iBelief5) end)
GameEvents.ReligionEnhanced.Add(function(iPlayer, iReligion, iBelief1, iBelief2) end)
 
While it isn't an ideal fit for what you're going for, you could use traits to give them a free building in every city that had -100% spy steal rate. Spies could still be put in their cities but it would only be for line of sight, never tech.
Actually, what I meant is, you know how when you station a spy in an enemy's city, you can see the area surrounding the city? I'd like that to not be the case for a certain civ - or rather, the reverse - when other people spy on the civ, they don't see the area surrounding their civs. However, as whoward pointed out, this apparently isn't possible without modding the DLL. :sad:
Adding a building that increases pressure would makes the city's neighbors have higher pressure but cities don't self pressure. There is a lua function to convert a percent of a city's majority followers to another religion. You could call that when some specific thing happens.
Right. I always forget that about religious pressure. :cringe:
By the way, what is that lua function?
I have some lua code that can detect when a religion is founded (it fires off a lua event when a religion is founded and has info on the holy city). It is in my Race for Religion mod.
I think I've tried using that in another mod UA attempt (for the Kingdom of Georgia). Is it the same function that uses dummy buildings to check if the holy city converts to a religion for the first time?
1) Would only work for the player, not the AI (as obviously the AI doesn't use the UI). You'll either need to use the "anti-espionage building in every city" approach or mod the DLL
So the AI can't see enemy cities via spying?
Do the AI spy on each other at all, just out of curiosity?
2) Game.GetNumFollowers(iReligionType) and pCity:GetNumFollowers(iReligionType) - but only call the latter if pCity:IsReligionInCity(iReligionType) returns true
Thanks! I needed Game.GetNumFollowers.
Can't remember if you use my DLL or not, but if so
I don't, for two reasons:
1 - Only DLL mod can be active at a time and I'd like to have my mods incompatible with as few other mods as possible. Especially since I know a lot of people already use your DLL mods.
2 - Any modding involving C++, the visual game engine, 3D modeling, UI, and most lua is waaay beyond me.
3.5) Three game events added
Code:
GameEvents.PantheonFounded.Add(function(iPlayer, iCapitalCity, iReligion, iBelief1) end)
GameEvents.ReligionFounded.Add(function(iPlayer, iHolyCity, iReligion, iBelief1, iBelief2, iBelief3, iBelief4, iBelief5) end)
GameEvents.ReligionEnhanced.Add(function(iPlayer, iReligion, iBelief1, iBelief2) end)
:goodjob: Nice. I'll try out GameEvents.ReligionFounded and see if it works.
 
By the way, what is that lua function?
City:ConvertPercentFollowers(ReligionType arg0, ReligionType arg1, int arg2)

The arg0 should be the religion who the followers become. arg1 should be the religion in the city that will be changed. arg3 is the percent of the second religion's followers that will be changed. For example, if its 50 than half of the followers of the second religion will become the first religion.

I think I've tried using that in another mod UA attempt (for the Kingdom of Georgia). Is it the same function that uses dummy buildings to check if the holy city converts to a religion for the first time?
That is the one. It can be overkill but it doesn't depend on a modded DLL.
 
So if I understand your code correctly:

In essence there are two buildings, one added to a city if it currently has a certain majority religion and subtracted if it doesn't - the "is" building - and one that's added to a city permanently one turn after the "is" building to determine whether or not it has ever had that religion - the "has been" building.
To determine if a city converts to a religion for the first time, the requirement is simply for the city to have the "is" building but not the "has been" building.
It then determines if a player founds a religion if the holy city converts to its own religion for the first time.

Is that about right?

That should be easy enough to duplicate. Ideally - no offense intended - but I'd rather not use your code because it adds, what 22 dummy buildings? And theoretically it could be done with 2. In this case, there only need to be buildings for one religion - the one Georgia founds.
 
That is mostly correct, but it is a bit simpler than that. The "has been" building is added at the same time and never removed.

I understand not wanting to use a general solution that is overkill for the very small subset of the functionality you care about. You'll want to do something like:
Code:
function MyUniqueAbility(iOwner, eReligion, iX, iY)
	local plot = Map.GetPlot(iX, iY);
	-- Error check, if this isn't a city don't continue
	if(not plot:IsCity()) then
		return;
	end

	local city = plot:GetPlotCity();

[COLOR="Brown"]	if(city is the civ AND haven't already given the bonus) then
		Give the bonus
		Mark that the bonus has been given
	end[/COLOR]
end
GameEvents.CityConvertsReligion.Add(MyUniqueAbility);
The brown marks the pesudo code you would have to fill out.
 
They're added simultaneously? Now you lost me. :crazyeye:
If the "is" and "has been" buildings are added simultaneously, wouldn't that mean that upon founding the religion they would both be present in the holy city? And if that's the case, how can you detect when the city has one but not the other? Or is that not really how to detect the first conversion?
 
The "is" buildings are intended to sync up with the majority religion of a city. A city should only ever have one "is" building.

The "hasBeen" buildings are never removed and a city can have 1 of them for each religion it 'has ever been'.

When a city adopts a Christianity the "is" building is updated (remove any old "is" buildings, place a "is" Christianity building) and a "has been" Christianity building is added if it doesn't already exists. If the "has been Christianity" building is not already in the city than the algorithm knows it is the first time the city has adopted Christianity.
 
Alright then - this is my attempt, probably riddled with errors and loopholes, but I think it should work up to a point:
Spoiler :
Code:
GameEvents.CityConvertsReligion.Add(
function(iPlayer, iReligion, iX, iY)

	-- First set up boolean variable firstConversion to be used later	

	local plot = Map.GetPlot(iX, iY);
	if not (plot:IsCity()) then
		return;
	end
	
	local city = plot:GetPlotCity();
	local isReligion = GameInfoTypes.BUILDING_GEORGIA_DUMMY_IS_RELIGION
	local hasBeenReligion = GameInfoTypes.BUILDING_GEORGIA_DUMMY_HAS_BEEN_RELIGION
	
	
	if (city:GetOwner() == iPlayer)
	and (iPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_GEORGIA) then
		if (iPlayer:HasCreatedReligion()) then
			local iReligion = iPlayer:GetReligionCreatedByPlayer()
			
			if (city:GetReligiousMajority() == iReligion) then
				if not (city:IsHasBuilding(isReligion)) then
					city:SetNumRealBuilding(isReligion, 1)
				else
					if not (city:IsHasBuilding(hasBeenReligion)) then
						firstConversion = true;
						city:SetNumRealBuilding(hasBeenReligion, 1)
					else
						firstConversion = false;
					end
				end
			else
				city:SetNumRealBuilding(isReligion, 0)
			end
		end
	end
	print("Georgian City Converts Religon Event: (iPlayer: " ..tostring(iPlayer).. " iX: " ..tostring(iX).. " iY: " ..tostring(iY).. "iReligion: " ..tostring(iReligion).. "firstConversion: " ..tostring(firstConversion).. ")");
	LuaEvents.GeorgianCityConvertsReligionFirstTime(iPlayer, iX, iY, iReligion, firstConversion);		
end)

-- Now call the event

LuaEvents.GeorgianCityConvertsReligionFirstTime.Add(
function(iPlayer, iX, iY, iReligion, firstConversion)
	local pPlayer = Players[iPlayer]
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_GEORGIA) then
		if (pPlayer:IsAlive()) then
			local city = Map.GetPlot(iX, iY):GetPlotCity()
				if (firstConversion) and (city:IsHolyCityForReligion(iReligion)) then
					
					-- More coding that I'll figure out later
				
				end
			end
		end
	end
end)
I'm not sure what I'll do with it later but right now I'm just trying to get it to detect a holy city's first conversion to its own religion. It's mostly based off your code but I had to adapt it to one civilization and two buildings, which I may have (probably) done wrong.
 
Top Bottom