The_Space_Cows
Chieftain
- Joined
- Mar 18, 2023
- Messages
- 16
I am trying to create an Enhancer Belief which allows Great Generals to spread religion like Prophets do. To accomplish this, in XML I have outlined a new unit called a 'Prophet General.' Using Lua code, I check if a player has chosen the right belief, and then find any great generals they have and convert them into Prophet Generals using Unit.Convert().
Unfortunately, the newly spawned Prophet Generals always have a ReligionType of -1, and cannot spread any religion since the Great Generals they upgraded from are not religious. If I allow the Prophet Generals the ability to FOUND a religion, they can indeed found a religion if the player hasn't already. Interesingly, If a General is converted into a Prophet General before the player founded a religion, when a religion is founded by a Great Prophet the Prophet Generals gain the ReligionType of the newly founded religion. This would indicate that when you found a religion, all existing units gain the ReligionType of your religion (or just those capable of spreading religion?).
Given that there is no Unit.SetReligion() method, is there any way around this issue? Does anyone know of either a way to change a unit's ReligionType, or have a different approach to adding the spread religion functionality to Great Generals?
XML Code for Prophet Generals
Lua function for converting Generals to Prophet Generals
Unfortunately, the newly spawned Prophet Generals always have a ReligionType of -1, and cannot spread any religion since the Great Generals they upgraded from are not religious. If I allow the Prophet Generals the ability to FOUND a religion, they can indeed found a religion if the player hasn't already. Interesingly, If a General is converted into a Prophet General before the player founded a religion, when a religion is founded by a Great Prophet the Prophet Generals gain the ReligionType of the newly founded religion. This would indicate that when you found a religion, all existing units gain the ReligionType of your religion (or just those capable of spreading religion?).
Given that there is no Unit.SetReligion() method, is there any way around this issue? Does anyone know of either a way to change a unit's ReligionType, or have a different approach to adding the spread religion functionality to Great Generals?
XML Code for Prophet Generals
XML:
<Units>
<Row>
<Class>UNITCLASS_GREAT_GENERAL</Class>
<Type>UNIT_PROPHET_GENERAL</Type>
<Cost>-1</Cost>
<Moves>2</Moves>
<CivilianAttackPriority>CIVILIAN_ATTACK_PRIORITY_HIGH</CivilianAttackPriority>
<Special>SPECIALUNIT_PEOPLE</Special>
<Domain>DOMAIN_LAND</Domain>
<DefaultUnitAI>UNITAI_GENERAL</DefaultUnitAI>
<Description>TXT_KEY_UNIT_GREAT_GENERAL</Description>
<Civilopedia>TXT_KEY_CIV5_GREATGENERALS_TEXT</Civilopedia>
<Strategy>TXT_KEY_UNIT_GREAT_GENERAL_STRATEGY</Strategy>
<AdvancedStartCost>-1</AdvancedStartCost>
<WorkRate>1</WorkRate>
<CombatLimit>0</CombatLimit>
<DontShowYields>true</DontShowYields>
<UnitArtInfo>ART_DEF_UNIT_GENERAL</UnitArtInfo>
<UnitArtInfoEraVariation>true</UnitArtInfoEraVariation>
<UnitFlagIconOffset>90</UnitFlagIconOffset>
<IconAtlas>UNIT_ATLAS_2</IconAtlas>
<PortraitIndex>48</PortraitIndex>
<MoveRate>GREAT_PERSON</MoveRate>
<FoundReligion>true</FoundReligion>
<SpreadReligion>true</SpreadReligion>
<ReligionSpreads>4</ReligionSpreads>
<ReligiousStrength>1000</ReligiousStrength>
</Row>
</Units>
Lua function for converting Generals to Prophet Generals
Code:
function UpgradeGeneralsToProphetGenerals(player)
for unit in player:Units() do
if (unit:GetUnitType() == GameInfoTypes.UNIT_GREAT_GENERAL) then
local prophetGeneral = player:InitUnit(GameInfoTypes.UNIT_PROPHET_GENERAL, unit:GetX(), unit:GetY())
prophetGeneral:Convert(unit)
if (unit) then
unit:Kill()
end
end
end
end