Machiavelli24
Mod creator
- Joined
- May 9, 2012
- Messages
- 818
The most recent update of Race (the Reformation update) did add some code that executes when capitals are captured. I'll take a close look at it to see if there are mistakes in it that could be the cause of the crashing.
EDIT:
I think I have a solution but I haven't been able to test it yet. Replace the "...\Documents\my games\Sid Meier's Civilization 5\MODS\Race for Religion (BNW) (v 4)\Shared\Belief_FounderFreeBuildingClassCapital\Belief_FounderFreeBuildingClassCapital.lua" file with the below:
EDIT:
I think I have a solution but I haven't been able to test it yet. Replace the "...\Documents\my games\Sid Meier's Civilization 5\MODS\Race for Religion (BNW) (v 4)\Shared\Belief_FounderFreeBuildingClassCapital\Belief_FounderFreeBuildingClassCapital.lua" file with the below:
Spoiler :
Code:
-- Belief_FounderFreeBuildingClassCapital
-- Author: Machiavelli
-- DateCreated: 3/6/2014 10:49:51 AM
--------------------------------------------------------------
-- NOTE: Depends on ReligionFoundedEvent.
--------------------------------------------------------------
function GiveBeliefBuildingCapital(founderID, iX, iY, eOldReligion, eNewReligion)
local founder = Players[founderID];
for row in GameInfo.Belief_FounderFreeBuildingClassCapital() do
if(ReligionHasBelief(eNewReligion, GameInfoTypes[row.BeliefType])) then
local building = GetBuildingTypeFromClass(row.BuildingClassType, founder:GetCivilizationType());
founder:GetCapitalCity():SetNumRealBuilding(GameInfoTypes[building], 1);
end
end
end
--LuaEvents.ReligionFoundedEvent.Add(GiveBeliefBuildingCapital);
function GiveBeliefBuildingCapitalMove(oldPlayerID, bCapital, iX, iY, newPlayerID, conquest, conquest2)
local oldPlayer = Players[oldPlayerID];
local newPlayer = Players[newPlayerID];
local city = Map.GetPlot(iX, iY):GetPlotCity();
local oldPlayerReligion = oldPlayer:GetReligionCreatedByPlayer();
local newPlayerReligion = newPlayer:GetReligionCreatedByPlayer();
-- If the old player just lost their capital, they may need to have their buildings replaced
if(bCapital and oldPlayer:IsAlive() and oldPlayerReligion > 0) then
for row in GameInfo.Belief_FounderFreeBuildingClassCapital() do
if(ReligionHasBelief(oldPlayerReligion, GameInfoTypes[row.BeliefType])) then
local building = GetBuildingTypeFromClass(row.BuildingClassType, oldPlayer:GetCivilizationType());
oldPlayer:GetCapitalCity():SetNumRealBuilding(GameInfoTypes[building], 1);
end
end
end
---------------------------------
-- If the new player just recovered their capital, they will need to have their buildings moved
if(newPlayer:GetCapitalCity():GetID() == city:GetID() and newPlayerReligion > 0) then
for row in GameInfo.Belief_FounderFreeBuildingClassCapital() do
if(ReligionHasBelief(newPlayerReligion, GameInfoTypes[row.BeliefType])) then
local building = GetBuildingTypeFromClass(row.BuildingClassType, newPlayer:GetCivilizationType());
-- Remove capital only buildings from the new player's cities
for cityToRemove in newPlayer:Cities() do
cityToRemove:SetNumRealBuilding(GameInfoTypes[building], 0);
end
-- Add back the capital-only buildings
city:SetNumRealBuilding(GameInfoTypes[building], 1);
end
end
end
end
--GameEvents.CityCaptureComplete.Add(GiveBeliefBuildingCapitalMove);
--------------------
-- Private helper functions
--------------------
function ReligionHasBelief(eReligion, eBelief)
local hasBelief = false;
for i,v in ipairs(Game.GetBeliefsInReligion(eReligion)) do
local belief = GameInfo.Beliefs[v];
if (belief ~= nil and belief.ID == eBelief) then
hasBelief = true;
return hasBelief;
end
end
return hasBelief;
end
function GetBuildingTypeFromClass(buildingClass, civilizationTypeID)
-- Assume it is the default building
local buildingType = GameInfo.BuildingClasses[buildingClass].DefaultBuilding;
-- See if this civilization has a unique building for this building class
for row in GameInfo.Civilization_BuildingClassOverrides() do
if (GameInfoTypes[row.CivilizationType] == civilizationTypeID and row.BuildingClassType == buildingClass) then
-- This civilization has a unique building
buildingType = row.BuildingType;
return buildingType;
end
end
return buildingType;
end
--------------
-- Initialization check. Ensures this code isn't loaded twice
--------------
local retVal = {};
LuaEvents.Belief_FounderFreeBuildingClassCapital_IsInitialized(retVal);
-- If retVal isn't changed, no other mod has initialized this code.
if (retVal.isInitialized == nil) then
LuaEvents.Belief_FounderFreeBuildingClassCapital_IsInitialized.Add(function (retVal) retVal.isInitialized = true; end);
-- Initialize the code
LuaEvents.ReligionFoundedEvent.Add(GiveBeliefBuildingCapital);
GameEvents.CityCaptureComplete.Add(GiveBeliefBuildingCapitalMove);
end