Machiavelli24
Mod creator
- Joined
- May 9, 2012
- Messages
- 818
It won't download until you subscribe to the mod and start up civ 5 and go to the mods menu. It may also be in ...Documents\my games\Sid Meier's Civilization 5\MODS\mods.
Ahhh. I see.It won't download until you subscribe to the mod and start up civ 5 and go to the mods menu. It may also be in ...Documents\my games\Sid Meier's Civilization 5\MODS\mods.
LuaEvents.ReligionFoundedEvent.Add(
function (founderID, iX, iY, eOldReligion, eNewReligion)
player = Players[founderID]
if (player:GetCivilizationType() == GameInfoTypes.CIVILIZATION_GEORGIA) then
if (Game.GetNumReligionsFounded() == 1) then
if (foundedReligionFirst == nil) then
global foundedReligionFirst = true
end
else
global foundedReligionFirst = false
end
end
end)
if(X and Y) then
...do stuff...
end
if(X) then
if(Y) then
...do stuff...
end
end
Dang. I didn't see that it hooks into LuaEvents.CityAdoptsReligionEvent.While the ReligionFoundedEvent doesn't use any additional dummy buildings of its own, it will not work correctly unless you are also using LuaEvents.CityAdoptsReligionEvent (the one which has all the dummy buildings for every religion).
I typically do that (Inuit UA dummy building as an example) except when the conditions for adding the dummy buildings don't match, which is almost all the time anyway.As for providing the benefit, if you want to make things much easier on yourself (and want to get around having to use any dummy buildings) use a bonus that can be implemented with a single building. Something like +4 Happiness, +1 Happiness from every Temple, +5 Faith, +25% Great People, etc.
The code in question:From what I can tell simply from looking at the code for your event, it seems to be defining eOldReligion and eNewReligion and the initialization check at the end, as well as removing buildings for some reason I'm still trying to grasp (lines 41 - 47).
-- If a city has no religious majority, eNewReligion will be -1
if(eNewReligion < 1) then
-- Case 1) no majority religion
-- Remove any buildings marking what the old religion the city is (TODO: this check should be happening every turn to avoid having incorrect state for a few turns)
for row in GameInfo.Religions() do
local temp = "BUILDING_" .. row.Type;
if (city:IsHasBuilding(GameInfoTypes[temp])) then
city:SetNumRealBuilding(GameInfoTypes[temp], 0); -- Remove the building
end
end
-- Do not continue because the city has no majority religion
return;
else
-- Only way to get here is if: eNewReligion >= 1 and city does not have newReligionBuilding
-- Case 2.B) majority religion and city has changed religion
local eOldReligion = 0;
-- Find any buildings marking what the old religion the city is
for row in GameInfo.Religions() do
local religionMarkingBuilding = "BUILDING_" .. row.Type;
-- Skip the current local majority religion (eNewReligion) but remove all other religion marking buildings
if (row.ID ~= eNewReligion and city:IsHasBuilding(GameInfoTypes[religionMarkingBuilding])) then
city:SetNumRealBuilding(GameInfoTypes[religionMarkingBuilding], 0);
-- Possible error check. Just because there is a building marking for the old religion doesn't mean the city has been that religion recently.
-- For example, if the city was hit by an Inquisitor the building marking old religion wouldn't be removed.
-- For now, better to have old religion sometimes be the most recent religion than risk adding bugs with extra checks.
--if(city:GetNumFollowers(row.ID) > 0 or city:GetPopulation() == 1) then
-- Found the old religion of the city
eOldReligion = row.ID;
--end
end
end
-- Is this the first time the city has adopted the majorityReligion
local hasBeenReligionBuilding = "BUILDING_HAS_BEEN_" .. GameInfo.Religions[eNewReligion].Type;
-- Only way to get here is if: eNewReligion >= 1 and city does not have newReligionBuilding
-- Case 2.B) majority religion and city has changed religion
local eOldReligion = 0;
-- Find any buildings marking what the old religion the city is
for row in GameInfo.Religions() do
local religionMarkingBuilding = GameInfoTypes.BUILDING_GEORGIA_DUMMY_IS_RELIGION
-- Skip the current local majority religion (eNewReligion) but remove all other religion marking buildings
if (row.ID ~= eNewReligion and city:IsHasBuilding(GameInfoTypes[religionMarkingBuilding])) then
city:SetNumRealBuilding(GameInfoTypes[religionMarkingBuilding], 0);
-- Possible error check. Just because there is a building marking for the old religion doesn't mean the city has been that religion recently.
-- For example, if the city was hit by an Inquisitor the building marking old religion wouldn't be removed.
-- For now, better to have old religion sometimes be the most recent religion than risk adding bugs with extra checks.
--if(city:GetNumFollowers(row.ID) > 0 or city:GetPopulation() == 1) then
-- Found the old religion of the city
eOldReligion = row.ID;
--end
end
end
-- Is this the first time the city has adopted the majorityReligion
local hasBeenReligionBuilding = GameInfoTypes.BUILDING_GEORGIA_DUMMY_HAS_BEEN_RELIGION
if (row.ID ~= eNewReligion and city:IsHasBuilding(GameInfoTypes[religionMarkingBuilding])) then
function GeorgiaFoundingBonus(founderID, iX, iY, eOldReligion, eNewReligion)
player = Players[founderID];
city = Game.GetHolyCityForReligion(eNewReligion, -1);
if(player:GetCivilizationType() == GameInfoTypes.CIVILIZATION_GEORGIA and Game.GetNumReligionsFounded() == 1 and not city:IsHasBuilding(GameInfoTypes["BUILDING_GEORGIA_FOUNDING_BONUS"])) then
city:SetNumRealBuilding(GameInfoTypes["BUILDING_GEORGIA_FOUNDING_BONUS"], 1);
end
end
LuaEvents.ReligionFoundedEvent.Add(GeorgiaFoundingBonus);
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
local iPlayer = Players[iPlayer]
if (iPlayer:HasCreatedReligion()) then
iReligion = iPlayer:GetReligionCreatedByPlayer()
if Game.GetHolyCityForReligion(iReligion):IsHasBuilding(GameInfoTypes.BUILDING_GEORGIA_DUMMY_RELIGION_FIRST) then
iPlayer:ChangeFaith(math.floor(Game.GetNumFollowers(iReligion)/4))
end
else
return;
end
end)
New UA (just switching around the effects): If you found a religion first, all your cities which have that religion as their majority religion convert all religious followers in that city to their majority religion/adopt it fully. After founding a religion all of your cities following that religion gain a defence bonus. +2 (or 25%)AgressiveWimp said:I've finally decided on a UA (I promise I won't change it unless it sounds unbalanced to other people or [is] impossible) that will take a form like this:
Yes they could. I decided to implement them as buildings because it let me (and others) have things that boost buildings (like beliefs or social policies) buff specific religious marking buildings. For example, I could do things like the belief "Religious Diversity: +1 Science per religion this city has followed" by having the belief provide +1 Science from every "HAS_BEEN" religion marking building.If the CityAdoptsReligion event uses dummy buildings just to mark a city's past and current religions and other than that they have no real effect, couldn't they easily be swapped out for global variables?
Yes! I actually got one right!Yes they could. I decided to implement them as buildings because it let me (and others) have things that boost buildings (like beliefs or social policies) buff specific religious marking buildings. For example, I could do things like the belief "Religious Diversity: +1 Science per religion this city has followed" by having the belief provide +1 Science from every "HAS_BEEN" religion marking building.
It was not a costless design choice, so I can understand the appeal of using persistent data instead.
function CallCityAdoptsReligionEvent(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();
local eNewReligion = city:GetReligiousMajority();
local newReligionBuilding = nil;
-- If a city has no religious majority, eNewReligion will be -1
if(eNewReligion < 1) then
-- Case 1) no majority religion
-- Remove any buildings marking what the old religion the city is (TODO: this check should be happening every turn to avoid having incorrect state for a few turns)
for row in GameInfo.Religions() do
[B][COLOR="Blue"]local temp = "BUILDING_" .. row.Type;
if (city:IsHasBuilding(GameInfoTypes[temp])) then
city:SetNumRealBuilding(GameInfoTypes[temp], 0); -- Remove the building[/COLOR][/B] end
end
-- Do not continue because the city has no majority religion
return;
else
-- Case 2.A) majority religion but city hasn't changed religion
[COLOR="blue"][B]newReligionBuilding = "BUILDING_" .. GameInfo.Religions[/B][/COLOR][eNewReligion].Type;
[B][COLOR="blue"]if(city:IsHasBuilding(GameInfoTypes[newReligionBuilding])) then[/COLOR][/B]
-- The city has not changed religion, don't continue
return;
end
end
-- Only way to get here is if: eNewReligion >= 1 and city does not have newReligionBuilding
-- Case 2.B) majority religion and city has changed religion
local eOldReligion = 0;
-- Find any buildings marking what the old religion the city is
for row in GameInfo.Religions() do
[B][COLOR="blue"]local religionMarkingBuilding = "BUILDING_" .. row.Type;[/COLOR][/B]
-- Skip the current local majority religion (eNewReligion) but remove all other religion marking buildings
[B][COLOR="blue"]if (row.ID ~= eNewReligion and city:IsHasBuilding(GameInfoTypes[religionMarkingBuilding])) then
city:SetNumRealBuilding(GameInfoTypes[religionMarkingBuilding], 0);[/COLOR][/B]
-- Possible error check. Just because there is a building marking for the old religion doesn't mean the city has been that religion recently.
-- For example, if the city was hit by an Inquisitor the building marking old religion wouldn't be removed.
-- For now, better to have old religion sometimes be the most recent religion than risk adding bugs with extra checks.
--if(city:GetNumFollowers(row.ID) > 0 or city:GetPopulation() == 1) then
-- Found the old religion of the city
eOldReligion = row.ID;
--end
end
end
-- Is this the first time the city has adopted the majorityReligion
[B][COLOR="blue"]local hasBeenReligionBuilding = "BUILDING_HAS_BEEN_" .. [/COLOR][/B]GameInfo.Religions[eNewReligion].Type;
local bFirstConversion = false;
[B][COLOR="blue"]if(not city:IsHasBuilding(GameInfoTypes[hasBeenReligionBuilding])) then[/COLOR][/B] bFirstConversion = true;
end
-- Update religion building state
[B][COLOR="blue"]city:SetNumRealBuilding(GameInfoTypes[newReligionBuilding], 1);
city:SetNumRealBuilding(GameInfoTypes[hasBeenReligionBuilding], 1);[/COLOR][/B]
-- Call the lua event
--print("Calling CityAdoptsReligionEvent(iOwner: " .. tostring(iOwner) .. " iX: " .. tostring(iX) .. " iY: " .. tostring(iY) .. " eOldReligion: " .. tostring(eOldReligion) .. " eNewReligion: " .. tostring(eNewReligion) .. " bFirstConversion: " .. tostring(bFirstConversion) .. ")");
LuaEvents.CityAdoptsReligionEvent(iOwner, iX, iY, eOldReligion, eNewReligion, bFirstConversion);
end
--------------
-- Initialization check. Ensures this code isn't loaded twice
--------------
local retVal = {};
LuaEvents.CityAdoptsReligionEvent_IsInitialized(retVal);
-- If retVal isn't changed, no other mod has initialized this code.
if (retVal.isInitialized == nil) then
LuaEvents.CityAdoptsReligionEvent_IsInitialized.Add(function (retVal) retVal.isInitialized = true; end);
-- Initialize the code
GameEvents.CityConvertsReligion.Add(CallCityAdoptsReligionEvent);
end
newReligion = GameInfo.Religions[eNewReligion].Type;
newReligionBuilding = "BUILDING_" .. GameInfo.Religions[eNewReligion].Type;
function CallCityAdoptsReligionEvent(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();
local eNewReligion = city:GetReligiousMajority();
local newReligionBuilding = nil;
-- If a city has no religious majority, eNewReligion will be -1
if(eNewReligion < 1) then
-- Case 1) no majority religion
-- Remove any buildings marking what the old religion the city is (TODO: this check should be happening every turn to avoid having incorrect state for a few turns)
for row in GameInfo.Religions() do
local temp = nil;
if (temp) then
temp = false; -- Remove the building
end
end
-- Do not continue because the city has no majority religion
return;
else
-- Case 2.A) majority religion but city hasn't changed religion
newReligion = true;
if(newReligion) then
-- The city has not changed religion, don't continue
return;
end
end
-- Only way to get here is if: eNewReligion >= 1 and city does not have newReligionBuilding
-- Case 2.B) majority religion and city has changed religion
local eOldReligion = 0;
-- Find any buildings marking what the old religion the city is
for row in GameInfo.Religions() do
local is_religion = nil;
-- Skip the current local majority religion (eNewReligion) but remove all other religion marking buildings
if (row.ID ~= eNewReligion and is_newReligion) then
is_newReligion = false;
-- Possible error check. Just because there is a building marking for the old religion doesn't mean the city has been that religion recently.
-- For example, if the city was hit by an Inquisitor the building marking old religion wouldn't be removed.
-- For now, better to have old religion sometimes be the most recent religion than risk adding bugs with extra checks.
--if(city:GetNumFollowers(row.ID) > 0 or city:GetPopulation() == 1) then
-- Found the old religion of the city
eOldReligion = row.ID;
--end
end
end
-- Is this the first time the city has adopted the majorityReligion
local hasBeen_newReligion = true;
local bFirstConversion = false;
if(not hasBeen_newReligion) then
bFirstConversion = true;
end
-- Update religion building state
is_newReligion = true;
hasBeen_newReligion = true;
-- Call the lua event
--print("Calling CityAdoptsReligionEvent(iOwner: " .. tostring(iOwner) .. " iX: " .. tostring(iX) .. " iY: " .. tostring(iY) .. " eOldReligion: " .. tostring(eOldReligion) .. " eNewReligion: " .. tostring(eNewReligion) .. " bFirstConversion: " .. tostring(bFirstConversion) .. ")");
LuaEvents.CityAdoptsReligionEvent(iOwner, iX, iY, eOldReligion, eNewReligion, bFirstConversion);
end
--------------
-- Initialization check. Ensures this code isn't loaded twice
--------------
local retVal = {};
LuaEvents.CityAdoptsReligionEvent_IsInitialized(retVal);
-- If retVal isn't changed, no other mod has initialized this code.
if (retVal.isInitialized == nil) then
LuaEvents.CityAdoptsReligionEvent_IsInitialized.Add(function (retVal) retVal.isInitialized = true; end);
-- Initialize the code
GameEvents.CityConvertsReligion.Add(CallCityAdoptsReligionEvent);
end