[BNW] Unique Units for every Religion

Wololo_Priest

Chieftain
Joined
Jul 14, 2012
Messages
20
Hello civfanatic-modding-community! I hope you can help me. ;)

I created a new religion called “Ishtar” (based on Robert E. Howards books “Conan”) and my idea is, that every new religion has own unique priest unit (= archer) and a mythology unit. I’m not the best modder, but I can do the basic modding things i.e. creating new civs and minor civs, religions, icons with Photoshop etc.

My question: Is there an easy way, to have unique units for every religion, for example using a normal warrior unit as template? XML? SQL? Is there a step-by-step tutorial, that I missed? Can someone help me, please?

Thank you for your help!

Code for Ishtar-Religion:

<Religions>
<Row>
<Type>RELIGION_ISHTAR</Type>
<Description>TXT_KEY_RELIGION_ISHTAR</Description>
<Civilopedia>TXT_KEY_RELIGION_ISHTAR_PEDIA</Civilopedia>
<IconAtlas>RELIGION_ATLAS_WHITE</IconAtlas> (placeholder)
<PortraitIndex>6</PortraitIndex>
<IconString>[ICON_RELIGION_SHINTO]</IconString> (placeholder)​
</Row>​
</Religions>​
 
It won't be possible with just XML/SQL. It would require lua to implement, and in practical terms you will be adding completely new classes of units to the game that the lua code disallows a player to train or purchase unless a city is following ReligionX, or the player founded ReligionX, or the player's majority religion is ReligionX (all depending on how the lua code is structured).

I've actually done this very sort of thing in a mod that I never actually published mostly because I decided I did not want to inadvertently offend someone by making Islam allow a player to get "UnitX" as an examnple, only to find those actual real life people who are of Islamic faith found my choice of unit offensive.
 
First of all: thank you for your quick answer, LeeS! :D

May I ask you: Is there a chance, that I can use your code/work for my mod?

I’m creating new fantasy religion based on Howards World “Hyboria”, so I think there will be no offended people around the world. Hope so... :D
 
Code:
local iCatholicUnit = GameInfoTypes.UNIT_CATHOLIC_UNIT
local iChristianity = GameInfoTypes.RELIGION_CHRISTIANITY	--this is actually Catholicism in-game

------------------------------------------------------------------
--toolkit functions that can be used by multiple other functions
------------------------------------------------------------------
function UnitCityFounderReligionCheck(iPlayerReligion, iCityMajority, iRequiredReligion)
	if iPlayerReligion < 1 then return false end	--player has not founded a major religion, return false
	if iPlayerReligion ~= iRequiredReligion then return false end	--player founded an incorrect major religion for this unit, return false
	if iCityMajority < 1 then return false end	--pCity does not have a religious majority of a major religion, return false
	if iPlayerReligion ~= iCityMajority then return false end	--pCity's majority is not the same as the religion the player founded, return false
	return true
end
function UnitCityFollowerReligionCheck(iCityMajority, iRequiredReligion)
	if iCityMajority < 1 then return false end	--pCity does not have a religious majority of a major religion, return false
	if iCityMajority ~= iRequiredReligion then return false end	--pCity's majority is not the same as the required religion, return false
	return true
end
-------------------------------------------------------------------------
--GameEvent hooks to allow or disallow the training or purchase of units
-------------------------------------------------------------------------

--this function allows a PLAYER to train the unit in any city if they founded the religion
function PlayerCanTrainCatholicUnit(iPlayer, iUnitType) 
	if (iUnitType == iCatholicUnit) then
		local pPlayer = Players[iPlayer]
		return (pPlayer:GetReligionCreatedByPlayer() == iChristianity)
	end
	return true
end
GameEvents.PlayerCanTrain.Add(PlayerCanTrainCatholicUnit)

--this function only allows a CITY to create the unit if the CITY OWNER founded the religion AND the city's majority is the correct religion
function FounderCityCanTrainCatholicUnits(PlayerID, CityID, iUnitType)
	if (iUnitType == iCatholicUnit) then
		local pPlayer = Players[PlayerID]
		local pCity = pPlayer:GetCityByID(CityID)
		return UnitCityFounderReligionCheck(pPlayer:GetReligionCreatedByPlayer(), pCity:GetReligiousMajority(), iChristianity)
	end
	return true
end
GameEvents.CityCanTrain.Add(FounderCityCanTrainCatholicUnits)

--this function allows ANY CITY to create the unit if the city's majority is the correct religion
function FollowerCityCanTrainCatholicUnits(PlayerID, CityID, iUnitType)
	if (iUnitType == iCatholicUnit) then
		local pPlayer = Players[PlayerID]
		local pCity = pPlayer:GetCityByID(CityID)
		return UnitCityFollowerReligionCheck(pCity:GetReligiousMajority(), iChristianity)
	end
	return true
end
GameEvents.CityCanTrain.Add(FollowerCityCanTrainCatholicUnits)
  1. You will need to choose which of the three Game Event hook-types I have examples for that you would want to use and eliminate the other two.
  2. So you should only really use one of PlayerCanTrainCatholicUnit, FounderCityCanTrainCatholicUnits, or FollowerCityCanTrainCatholicUnits and you should delete or comment-out the other two.
  3. This is coded based on one special unit per religion and is an example for the base game's "Catholicism" (ie, RELIGION_CHRISTIANITY).
  4. You would need to copy/paste which of PlayerCanTrainCatholicUnit, FounderCityCanTrainCatholicUnits, or FollowerCityCanTrainCatholicUnits you want to use, and then edit as needed for the other religions, and rename the names of the function(s) and UNIT_CATHOLIC_UNIT and RELIGION_CHRISTIANITY as needed for your units and the religion name as you've used it within the XML/SQL code.
  5. And you would need to think of a new variable-name for "iCatholicUnit" and "iChristianity" and edit-replace these everywhere for the various religions you are going to use.

The other thing to remember with the two "City" functions, is that if the city's religious majority changes to another religion mid-stream of the city "constructing" the unit, the game will remove the unit from the city build qeue and the production spent on it will go *poof*.
 
Last edited:
Top Bottom