I'm adding some events to Sukritact's events mod, to fit with Anno Domini. One event involves gaining a free missionary as one of the possible outcomes, and it struck me that I'd better check if the civ had a major religion first. Is this code correct?
Just in case you need to see it in context with the rest of the code:
Code:
local iReligion = GetPlayerMajorityReligion(pPlayer)
if iReligion == nil then return false, false end
end
Just in case you need to see it in context with the rest of the code:
Code:
--------------------------------------------------------------------------------------------------------------------------
-- Religious man
--------------------------------------------------------------------------------------------------------------------------
local Event_ReligiousMan = {}
Event_ReligiousMan.Name = "TXT_KEY_EVENT_RELIGIOUSMAN"
Event_ReligiousMan.Desc = "TXT_KEY_EVENT_RELIGIOUSMAN_DESC"
Event_ReligiousMan.Weight = 5
Event_ReligiousMan.CanFunc = (
local iReligion = GetPlayerMajorityReligion(pPlayer)
if iReligion == nil then return false, false end
end
)
Event_ReligiousMan.Outcomes = {}
--=========================================================
-- Outcome 1
--=========================================================
Event_ReligiousMan.Outcomes[1] = {}
Event_ReligiousMan.Outcomes[1].Name = "TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_1"
Event_ReligiousMan.Outcomes[1].Desc = "TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_RESULT_1"
Event_ReligiousMan.Outcomes[1].CanFunc = (
function(pPlayer)
local iReward = math.ceil(20 * iMod * (pPlayer:GetCurrentEra() + 1))
Event_ReligiousMan.Outcomes[1].Desc = Locale.ConvertTextKey("TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_RESULT_1", iReward)
return true
end
)
Event_ReligiousMan.Outcomes[1].DoFunc = (
function(pPlayer)
local iReward = math.ceil(20 * iMod * (pPlayer:GetCurrentEra() + 1))
pPlayer:ChangeFaith(iReward)
JFD_SendNotification(pPlayer:GetID(), "NOTIFICATION_GENERIC", Locale.ConvertTextKey("TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_1_NOTIFICATION"), Locale.ConvertTextKey (Event_ReligiousMan.Name))
end
)
--=========================================================
-- Outcome 2
--=========================================================
Event_ReligiousMan.Outcomes[2] = {}
Event_ReligiousMan.Outcomes[2].Name = "TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_2"
Event_ReligiousMan.Outcomes[2].Desc = "TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_RESULT_2"
Event_ReligiousMan.Outcomes[2].CanFunc = (
function(pPlayer)
local iGoldCost = math.ceil(98 * iMod)
if pPlayer:GetGold() < iGoldCost then return false end
Event_ReligiousMan.Outcomes[2].Desc = Locale.ConvertTextKey("TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_RESULT_2", iGoldCost)
return true
end
)
[2].DoFunc = (
function(pPlayer)
local iGoldCost = math.ceil(98 * iMod)
pPlayer:ChangeGold(-iGoldCost)
pPlayer:AddFreeUnit(GameInfoTypes[JFD_GetUniqueUnit(pPlayer, "UNITCLASS_MISSIONARY")], GameInfoTypes["UNIT_MISSIONARY"])
JFD_SendNotification(pPlayer:GetID(), "NOTIFICATION_GENERIC", Locale.ConvertTextKey("TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_2_NOTIFICATION"), Locale.ConvertTextKey("TXT_KEY_EVENT_RELIGIOUSMAN"))
end)
--=========================================================
-- Outcome 3
--=========================================================
Event_ReligiousMan.Outcomes[3] = {}
Event_ReligiousMan.Outcomes[3].Name = "TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_3"
Event_ReligiousMan.Outcomes[3].Desc = "TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_RESULT_3"
Event_ReligiousMan.Outcomes[3].CanFunc = (
function(pPlayer)
local iGoldenAgeCost = math.ceil(33 * iMod)
local iGoldReward = math.ceil(52 * iMod)
if pPlayer:GetGoldenAgeProgressMeter() < iGoldenAgeCost then return false end
Event_ReligiousMan.Outcomes[3].Desc = Locale.ConvertTextKey("TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_RESULT_3", iGoldenAgeCost, iGoldReward)
return true
end
)
Event_ReligiousMan.Outcomes[3].DoFunc = (
function(pPlayer)
local iGoldenAgeCost = math.ceil(33 * iMod)
local iGoldReward = math.ceil(52 * iMod)
pPlayer:ChangeGoldenAgeProgressMeter(-iGoldenAgeCost)
pPlayer:ChangeGold(iGoldReward)
JFD_SendNotification(pPlayer:GetID(), "NOTIFICATION_GENERIC", Locale.ConvertTextKey("TXT_KEY_EVENT_RELIGIOUSMAN_OUTCOME_3_NOTIFICATION"), Locale.ConvertTextKey("TXT_KEY_EVENT_RELIGIOUSMAN"))
end)
tEvents.Event_ReligiousMan = Event_ReligiousMan