C++/Lua Request Thread

The code as written assumes also that only one slot per game will ever be CIVILIZATION_X.

The problem with this is that the game accepts multiple uses of the same civilization within the same game, and while it is not a CFC sort of a thing to do, people who live mostly on other sites have a meme of using all civs in a game as CIVILIZATION_X.
 
Well I wanted the code for two separate civilizations:

1. When Flight is researched Civ 1's units can cross over mountains (so the dummybuilding will give their units a promotion allowing them to do so).

2. For Civ 2, when they research Atomic Theory they also receive a promotion, and yields from other dummybuildings are changed and then new dummybuildings appear in each of their cities which cause other effects (either increased damage from Nuclear Weapons, or a chance for Nuclear Meltdowns to occur in the city). For Civ 2, all of the things added to their cities are de-buffs.
 
Well I wanted the code for two separate civilizations:

1. When Flight is researched Civ 1's units can cross over mountains (so the dummybuilding will give their units a promotion allowing them to do so).

2. For Civ 2, when they research Atomic Theory they also receive a promotion, and yields from other dummybuildings are changed and then new dummybuildings appear in each of their cities which cause other effects (either increased damage from Nuclear Weapons, or a chance for Nuclear Meltdowns to occur in the city). For Civ 2, all of the things added to their cities are de-buffs.
  • For #1 give not a building but a dummy policy that gives the free promotion via table <Policy_FreePromotions>. This way city capturing, city founding, etc., need not be tracked. The promotion is only given to appropriate units based on their UnitCombat Type so you have to define which types of units ought to get the promotion via table <UnitPromotions_UnitCombats>, like as is done for the Exploration Policy Opener:
    Code:
    <Policy_FreePromotions>
    	...snipped lines......
    	<Row>
    		<PolicyType>POLICY_EXPLORATION</PolicyType>
    		<PromotionType>PROMOTION_NAVAL_TRADITION</PromotionType>
    	</Row>
    	...snipped lines......
    </Policy_FreePromotions>
    and then the unit-combat types for PROMOTION_NAVAL_TRADITION are established as so:​
    Code:
    <UnitPromotions_UnitCombats>
    	...snipped lines......
    	<Row>
    		<PromotionType>PROMOTION_NAVAL_TRADITION</PromotionType>
    		<UnitCombatType>UNITCOMBAT_NAVALRANGED</UnitCombatType>
    	</Row>
    	<Row>
    		<PromotionType>PROMOTION_NAVAL_TRADITION</PromotionType>
    		<UnitCombatType>UNITCOMBAT_NAVALMELEE</UnitCombatType>
    	</Row>
    	<Row>
    		<PromotionType>PROMOTION_NAVAL_TRADITION</PromotionType>
    		<UnitCombatType>UNITCOMBAT_CARRIER</UnitCombatType>
    	</Row>
    	<Row>
    		<PromotionType>PROMOTION_NAVAL_TRADITION</PromotionType>
    		<UnitCombatType>UNITCOMBAT_SUBMARINE</UnitCombatType>
    	</Row>
    	...snipped lines......
    </UnitPromotions_UnitCombats>
  • For number 2, dummy buildings are able to take advantage of column <EnhancedYieldTech>TECH_ATOMIC_THEORY</EnhancedYieldTech> within table <Buildings> which will then implement anything within table <Building_TechEnhancedYieldChanges> specified for the dummy building, as like this:
    Code:
    	<!-- specify extra yields to your wonder or building BUILDING_NEW_BUILDING when the "enhancement tech" is discovered,
    			or eliminate the table altogether -->
    	<!-- any of the yields PRODUCTION, GOLD, FOOD, CULTURE, FAITH, SCIENCE can be used -->
    	<!-- the enhanced yields will be reflected in the city yields box, but not directly shown as part of the wonder or building -->
    <Building_TechEnhancedYieldChanges>
    	<Row>
    		<BuildingType>BUILDING_NEW_BUILDING</BuildingType>
    		<YieldType>YIELD_CULTURE</YieldType>
    		<Yield>6</Yield>
    	</Row>
    </Building_TechEnhancedYieldChanges>
    Doesn't matter if the <Yield> is specified as a negative. So you should use as much of this built-in mechanic as possible.
 
Well, the problem with both of those methods is the first one absolutely needs to trigger when the Tech is researched. As far as I know, Policies don't trigger off of discovering technologies (unless there's a code for giving a free Policy upon researching a tech, which would work fine in this instance).

As for the other instance, I was unaware that multiple changes to TechEnhancedYieldChanges could be applied, but I'd still need an additional effect to trigger upon discovery of Atomic Theory, which I'm certain TechEnhancedYieldChanges would not be able to handle.
 
Well, the problem with both of those methods is the first one absolutely needs to trigger when the Tech is researched. As far as I know, Policies don't trigger off of discovering technologies (unless there's a code for giving a free Policy upon researching a tech, which would work fine in this instance).

As for the other instance, I was unaware that multiple changes to TechEnhancedYieldChanges could be applied, but I'd still need an additional effect to trigger upon discovery of Atomic Theory, which I'm certain TechEnhancedYieldChanges would not be able to handle.

Giving a dummy policy is equivalent to giving a dummy building in terms of the lua code required to detect the discovery of the tech and to hand out the policy or the building. Thereinafter, however, nothing further needs to be coded in lua to track city founding, city capturing, etc., when a policy is given. The policy gives the promotion so it does not matter what happens with individual cities.

No, you can't apply changes for multiple techs via EnhancedYieldTech method for the same building, but you can actually handle quite a bit via xml. <FreeBuildingThisCity> is a powerful tool and also works for dummy buildings both for the recieved extra building and the building that is doing the giving. A building does not have to have any yields stated in table <Building_YieldChanges> in order for the <Building_TechEnhancedYieldChanges> table to have its effects. But as I said this will only handle part of #2 but you should use the existing game systems to handle as much of your code-needs as is possible.
So you should use as much of this built-in mechanic as possible
 
I must've mis-typed, I didn't think that TechEnhancedYieldChanges would work for multiple Techs, I just didn't know you could apply multiple yield changes from the same Tech (Petra didn't do it with Archaeology, and that was all I had to base that on, so that's what I assumed).

Well since it now appears I can alter building outputs with Policies and whatnot, I may have to add a phase 1.5 to my agenda to go through my mods and replace all unnecessary Dummybuildings with Policies I guess.
 
I must've mis-typed, I didn't think that TechEnhancedYieldChanges would work for multiple Techs, I just didn't know you could apply multiple yield changes from the same Tech (Petra didn't do it with Archaeology, and that was all I had to base that on, so that's what I assumed).

Well since it now appears I can alter building outputs with Policies and whatnot, I may have to add a phase 1.5 to my agenda to go through my mods and replace all unnecessary Dummybuildings with Policies I guess.

You should use policies sparingly, though. Three or four at most for one civ because one civ with lots of free policies breaks some game mechanics to one degree or another.
 
I finally just settled on using the code posted by qqqbbb because it seemed the easiest to work with. Also, I tested the code with 2 separate Washingtons and ran into no problems. I discovered Flight and the other Washington didn't magically receive it (unless of course you're considering that he could receive it by capturing the city, in which case: the Dummybuildings are always set to NeverCapture = true).

I actually try to steer towards using Dummybuildings for everything, particularly ones that work off of the Capital. So long as the player has one of those (which they will as long as they have at least 1 city), there shouldn't be any problems with the Civilizations I've programmed.

-EDIT-

Oh yes, and I could use one last lua code:
I need a code that triggers a Golden Age when a specific Civilization liberates a Captured City.
 
My point is that the code will only function for the 1st washingon found within the same game, and not the second, third, fourth, etc.

The reasoning for using policies when it makes more sense to do so is that dummy buildings added only in a capital mean that when the capital is captured, the effects of the UA are trashed by this occuring unless you then add an event that monitors city-capturing, looks for whether the captured city was the capital of Civ-X, and then takes action accordingly.
 
Well then, is there an .lua code that would provide a specific Policy upon researching a specific Tech for a specific Civilization?
 
I need a code that triggers a Golden Age when a specific Civilization liberates a Captured City.
Well then, is there an .lua code that would provide a specific Policy upon researching a specific Tech for a specific Civilization?

Code:
local iYourTech = GameInfoTypes.TECH
local iYourPolicy = GameInfoTypes.POLICY
local iYourPlayer
local pYourPlayer

local function OnCityCaptureComplete(iPlayer, bIsCapital, iPlotX, iPlotY, iNewPlayer, iOldPop, bConquest, iGreatWorkCount)
	if iNewPlayer == iYourPlayer then
		local pPlot = Map.GetPlot(iPlotX, iPlotY)
		local pCity = pPlot:GetPlotCity()
		if pCity:GetOriginalOwner() ~= iPlayer then
			pYourPlayer:ChangeGoldenAgeProgressMeter(11)
		end
	end
end

function OnTeamTechResearched(iTeam,iTech)
	if iTeam == iYourTeam and iTech == iYourTech then
		pYourPlayer:SetNumFreePolicies(1)
		pYourPlayer:SetNumFreePolicies(0)
		pYourPlayer:SetHasPolicy(iYourPolicy, true)	
	end
end

for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
	local pPlayer = Players[iPlayer]
	if pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_YOURCIV then
		GameEvents.CityCaptureComplete.Add(OnCityCaptureComplete)
		GameEvents.TeamTechResearched.Add(OnTeamTechResearched)
		pYourPlayer = pPlayer
		iYourPlayer = iPlayer
		iYourTeam = pPlayer:GetTeam()
		break
    end
end
 
hi guys,

I would need a simple script with a building which generates daily General points (let's say Monument generates 10 points daily). Can someone please help me with?

Thats because I need AI players to have more leaders. On the settings I use all AI are allied vs me, so they don't kill enough to get those generals. If you have a better idea on how to do this dynamically (get more points with each game turn) I take it.


Thanks in advance for your time.
 
Well, since I need this problem to be solved and I'm not getting answers elsewhere, I figured I'd post my problem here:

So, I was given the following code through the generous efforts of LeeS in which a Dummybuilding is placed in a custom Civ's Capital whenever they finish a Policy Tree. This works all well and good, even with multiple copies of the same Civilization. The problem however arises when their Capital is captured as all of their Dummybuildings are lost and are not replaced until another Policy Tree is finished (assuming they still have a city that can be treated as a Capital at this point).

What I need is for the code below to refresh the amount of Dummybuildings at some sort of interval so that they are replaced in the Civ's new Capital city once their previous Capital is taken, provided they have any Policy Trees completed, thus allowing the Civ to have the Dummybuildings in the first place.

Code:
local iBuildingForCompletedPolicyBranches = GameInfoTypes.BUILDING_AMERICA_POLICY_DUMMYBUILDING
local tPolicyAndBranchCorrespondances = {}
for Policy in DB.Query("SELECT ID, Type, PolicyBranchType FROM Policies WHERE Level = '0'") do
	local iPolicyId, sPolicyType, sPolicyBranchName, iPolicyBranchID = Policy.ID, Policy.Type, Policy.PolicyBranchType, -1
	if (sPolicyBranchName ~= nil) then
		for PolicyBranch in GameInfo.PolicyBranchTypes("Type='" .. sPolicyBranchName .. "'") do
			iPolicyBranchID = PolicyBranch.ID
		end
	end
	if iPolicyBranchID ~= -1 then
		if (GameInfo.PolicyBranchTypes[iPolicyBranchID].FreePolicy ~= sPolicyType) and (GameInfo.PolicyBranchTypes[iPolicyBranchID].FreeFinishingPolicy ~= sPolicyType) then
			local bPolicyIsAPreReq = false
			for row in GameInfo.Policy_PrereqPolicies("PrereqPolicy = '" .. sPolicyType .. "'") do
				bPolicyIsAPreReq = true
				break
			end
			if not bPolicyIsAPreReq then
				tPolicyAndBranchCorrespondances[iPolicyId] = iPolicyBranchID
			end
		end
	end
end

function PolicyBranchFinished(PlayerID, policyID)
	if tPolicyAndBranchCorrespondances[policyID] then
		local pPlayer = Players[PlayerID]
		if pPlayer:IsPolicyBranchFinished(tPolicyAndBranchCorrespondances[policyID]) then
			local pCapitalCity = pPlayer:GetCapitalCity()
			if pCapitalCity ~= nil then
				print("We Should have added " .. pPlayer:GetNumPolicyBranchesFinished() .. " Dummy Buildings in the city of " .. pCapitalCity:GetName())
				pCapitalCity:SetNumRealBuilding(iBuildingForCompletedPolicyBranches, pPlayer:GetNumPolicyBranchesFinished())
			end
		end
	end
end
GameEvents.PlayerAdoptPolicy.Add(PolicyBranchFinished);
 
......dummy buildings added only in a capital mean that when the capital is captured, the effects of the UA are trashed by this occuring unless you then add an event that monitors city-capturing, looks for whether the captured city was the capital of Civ-X, and then takes action accordingly.
Would need to see the xml for the dummy building to refresh my memory as to whether it is just a marker or actually has game-effects.
 
  1. In Johnny_Buildings.xml:
    • Change this:
      Code:
      <BuildingClasses>
      	<Row>
      		<Type>BUILDINGCLASS_AMERICA_POLICY_DUMMYBUILDING</Type>
      		<DefaultBuilding>BUILDING_POLICY_DUMMYBUILDING</DefaultBuilding>
      		<Description>TXT_KEY_BUILDING_AMERICA_POLICY_DUMMYBUILDING_DESC</Description>
      		<NoLimit>true</NoLimit>
      	</Row>
      </BuildingClasses>
      to this​
      Code:
      <BuildingClasses>
      	<Row>
      		<Type>BUILDINGCLASS_AMERICA_POLICY_DUMMYBUILDING</Type>
      		<DefaultBuilding>BUILDING_AMERICA_POLICY_DUMMYBUILDING</DefaultBuilding>
      		<Description>TXT_KEY_BUILDING_AMERICA_POLICY_DUMMYBUILDING_DESC</Description>
      	</Row>
      </BuildingClasses>
      You want the dummy building you are actually going to use to be the default building within its class. Setting it as a unique version within the class for a particular civilization does not work properly anyway, and does not keep the wrong civilization from being given the building. Such issues must be handled within lua-scripts.<NoLimit> actually makes no difference so isn't really needed.​
    • Eliminate this:
      Code:
      <Row>
      	<Type>BUILDING_POLICY_DUMMYBUILDING</Type>
      	<BuildingClass>BUILDINGCLASS_AMERICA_POLICY_DUMMYBUILDING</BuildingClass>
      	<Description>TXT_KEY_BUILDING_POLICY_DUMMYBUILDING_DESC</Description>
      	<PrereqTech>NULL</PrereqTech>
      	<Cost>-1</Cost>
      	<GreatWorkCount>-1</GreatWorkCount>
      	<FaithCost>-1</FaithCost>
      	<MinAreaSize>-1</MinAreaSize>
      	<HurryCostModifier>-1</HurryCostModifier>
      	<NeverCapture>true</NeverCapture>
      	<NukeImmune>true</NukeImmune>
      	<PortraitIndex>16</PortraitIndex>
      	<IconAtlas>BW_ATLAS_1</IconAtlas>
      </Row>
      It is not needed, and does not actually accomplish anything.​
    • Eliminate this:
      Code:
      <Row Tag="TXT_KEY_BUILDING_POLICY_DUMMYBUILDING_DESC">
      	<Text>Unused Generic Policy Dummybuilding</Text>
      </Row>
      It also will not be needed​
  2. In Johnny_Civilization.xml:
    • Eliminate this:
      Code:
      <Row>
      	<CivilizationType>CIVILIZATION_AMERICA</CivilizationType>
      	<BuildingClassType>BUILDINGCLASS_AMERICA_POLICY_DUMMYBUILDING</BuildingClassType>
      	<BuildingType>BUILDING_AMERICA_POLICY_DUMMYBUILDING</BuildingType>
      </Row>
      It is not needed, and does not actually accomplish anything.​
  3. Change the contents of file Johnny_UA.lua to the following:
    Spoiler :
    Code:
    -- JOHNNY BRAVO UA
    -- Author: LeeS
    -- Edited by: Harkodos
    --------------------------------------------------------------
    local iBuildingForCompletedPolicyBranches = GameInfoTypes.BUILDING_AMERICA_POLICY_DUMMYBUILDING
    local iRequiredCivilization = GameInfoTypes.CIVILIZATION_AMERICA
    local tPolicyAndBranchCorrespondances = {}
    
    --=======================================================================================================================
    -- Utility Functions
    --=======================================================================================================================
    -- JFD_IsCivilisationActive
    --------------------------------------------------------------
    function JFD_IsCivilisationActive(civilisationID)
    	for iSlot = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
    		local slotStatus = PreGame.GetSlotStatus(iSlot)
    		if (slotStatus == SlotStatus["SS_TAKEN"] or slotStatus == SlotStatus["SS_COMPUTER"]) then
    			if PreGame.GetCivilization(iSlot) == civilisationID then
    				return true
    			end
    		end
    	end
    	return false
    end
    function SearchThroughCitiesAndCorrectDummyBuildingPlacements(iPlayer, iBuilding, iNumBuildingsRequired, sMethod)
    	local pPlayer = Players[iPlayer]
    	if sMethod == nil then
    		print("!!!!!!!!!!!!!!!!  sMethod was nil when SearchThroughCitiesAndCorrectDummyBuildingPlacements was called: cannot do anything with that  !!!!!!!!!!!!!")
    		return
    	end
    	if pPlayer:GetNumCities() < 1 then
    		print("SearchThroughCitiesAndCorrectDummyBuildingPlacements was called but the player has no cities at the moment")
    		return
    	end
    	local pCapitalCity = pPlayer:GetCapitalCity()
    	local pOriginalCapital = "NONE"
    	if sMethod == "CapitalCity" then
    		if pCapitalCity ~= nil then
    			for pCity in pPlayer:Cities() do
    				if pCity:IsOriginalMajorCapital() and pCity:IsCapital() and (pCity:GetOriginalOwner() == iPlayer) then
    					pOriginalCapital = pCity
    					break
    				end
    			end
    			if pOriginalCapital ~= "NONE" then
    				pOriginalCapital:SetNumRealBuilding(iBuilding, iNumBuildingsRequired)
    				if pCapitalCity ~= pOriginalCapital then
    					pCapitalCity:SetNumRealBuilding(iBuilding, 0)
    				end
    			end
    			if pPlayer:CountNumBuildings(iBuilding) ~= iNumBuildingsRequired then
    				--something is still not correct, we need to fix it
    				for pCity in pPlayer:Cities() do
    					if (pOriginalCapital ~= "NONE") then
    						if (pCity == pOriginalCapital) then
    							pCity:SetNumRealBuilding(iBuilding, iNumBuildingsRequired)
    						else
    							pCity:SetNumRealBuilding(iBuilding, 0)
    						end
    					else
    						if pCity == pCapitalCity then
    							pCity:SetNumRealBuilding(iBuilding, iNumBuildingsRequired)
    						else
    							pCity:SetNumRealBuilding(iBuilding, 0)
    						end
    					end
    				end
    			end
    		else
    			print("SearchThroughCitiesAndCorrectDummyBuildingPlacements: we should not have been able to get here: sMethod == 'CapitalCity' and 'pCapitalCity == nil'")
    			return
    		end
    	elseif sMethod == "All" then
    		for pCity in pPlayer:Cities() do
    			pCity:SetNumRealBuilding(iBuilding, iNumBuildingsRequired)
    		end
    	end
    end
    --=======================================================================================================================
    -- End of Utility Functions
    --=======================================================================================================================
    local bIsCivActive = JFD_IsCivilisationActive(iRequiredCivilization)
    
    if bIsCivActive then
    	for Policy in DB.Query("SELECT ID, Type, PolicyBranchType FROM Policies WHERE Level = '0'") do
    		local iPolicyId, sPolicyType, sPolicyBranchName, iPolicyBranchID = Policy.ID, Policy.Type, Policy.PolicyBranchType, -1
    		if (sPolicyBranchName ~= nil) then
    			for PolicyBranch in GameInfo.PolicyBranchTypes("Type='" .. sPolicyBranchName .. "'") do
    				iPolicyBranchID = PolicyBranch.ID
    			end
    		end
    		if iPolicyBranchID ~= -1 then
    			if (GameInfo.PolicyBranchTypes[iPolicyBranchID].FreePolicy ~= sPolicyType) and (GameInfo.PolicyBranchTypes[iPolicyBranchID].FreeFinishingPolicy ~= sPolicyType) then
    				local bPolicyIsAPreReq = false
    				for row in GameInfo.Policy_PrereqPolicies("PrereqPolicy = '" .. sPolicyType .. "'") do
    					bPolicyIsAPreReq = true
    					break
    				end
    				if not bPolicyIsAPreReq then
    					tPolicyAndBranchCorrespondances[iPolicyId] = iPolicyBranchID
    				end
    			end
    		end
    	end
    end
    function PolicyBranchFinished(PlayerID, policyID)
    	if tPolicyAndBranchCorrespondances[policyID] then
    		local pPlayer = Players[PlayerID]
    		if pPlayer:GetCivilizationType() ~= iRequiredCivilization then
    			return
    		end
    		if pPlayer:IsPolicyBranchFinished(tPolicyAndBranchCorrespondances[policyID]) then
    			local pCapitalCity = pPlayer:GetCapitalCity()
    			if pCapitalCity ~= nil then
    				print("We Should have added " .. pPlayer:GetNumPolicyBranchesFinished() .. " Dummy Buildings in the city of " .. pCapitalCity:GetName())
    				pCapitalCity:SetNumRealBuilding(iBuildingForCompletedPolicyBranches, pPlayer:GetNumPolicyBranchesFinished())
    			end
    		end
    	end
    end
    function PlayerCapitalCaptured(iOldOwner, bIsCapital, iX, iY, iNewOwner, iPop, bConquest)
    	local pOldOwner = Players[iOldOwner]
    	if pOldOwner:GetCivilizationType() ~= iRequiredCivilization then
    		return
    	end
    	if pOldOwner:CountNumBuildings(iBuildingForCompletedPolicyBranches) ~= pOldOwner:GetNumPolicyBranchesFinished() then
    		SearchThroughCitiesAndCorrectDummyBuildingPlacements(iOldOwner, iBuildingForCompletedPolicyBranches, pOldOwner:GetNumPolicyBranchesFinished(), "CapitalCity")
    	end
    	-- ensuring that the new owner has none of the dummy buildings, even by some code-accident, from capturing the city
    	local pCity = Map.GetPlot(iX, iY):GetPlotCity();
    	pCity:SetNumRealBuilding(iBuildingForCompletedPolicyBranches, 0)
    end
    function PlayerDoTurn(iPlayer)
    	local pPlayer = Players[iPlayer]
    	if pPlayer:GetCivilizationType() ~= iRequiredCivilization then
    		return
    	end
    	local pCapitalCity = pPlayer:GetCapitalCity()
    	if pCapitalCity ~= nil then
    		if pCapitalCity:GetNumRealBuilding(iBuildingForCompletedPolicyBranches) ~= pPlayer:GetNumPolicyBranchesFinished() then
    			SearchThroughCitiesAndCorrectDummyBuildingPlacements(iPlayer, iBuildingForCompletedPolicyBranches, pPlayer:GetNumPolicyBranchesFinished(), "CapitalCity")
    		end
    	end
    end
    function CityFounded(iPlayer, iCityX, iCityY)
    	local pPlayer = Players[iPlayer]
    	if pPlayer:GetCivilizationType() ~= iRequiredCivilization then
    		return
    	end
    	if pPlayer:CountNumBuildings(iBuildingForCompletedPolicyBranches) ~= pPlayer:GetNumPolicyBranchesFinished() then
    		SearchThroughCitiesAndCorrectDummyBuildingPlacements(iPlayer, iBuildingForCompletedPolicyBranches, pPlayer:GetNumPolicyBranchesFinished(), "CapitalCity")
    	end
    end
    if bIsCivActive then
    	GameEvents.PlayerAdoptPolicy.Add(PolicyBranchFinished);  -- theoretically we don't need this anymore but it does make the effect instant on policy branch completion
    								 -- instead of waiting for the next player turn processing
    	GameEvents.PlayerDoTurn.Add(PlayerDoTurn)
    	GameEvents.PlayerCityFounded.Add(CityFounded)
    	GameEvents.CityCaptureComplete.Add(PlayerCapitalCaptured)
    end
    print("JOHNNY BRAVO UA script loaded all the way to the end and did not barf")
 
LeeS originally wrote this Lua script to allow several Roman modcivs access to the Baths of Trajan...

Spoiler :


Code:
-- BathsOfTrajanScript
-- Author: LeeS
-- DateCreated: 5/27/2016
--------------------------------------------------------------

local iBathsOfTrajan = GameInfoTypes.BUILDING_TRAJAN
local tCivsOfRome = {}
for row in GameInfo.Civilizations("Type='CIVILIZATION_ROME'") do
	tCivsOfRome[row.ID] = "true"
end
for row in GameInfo.Civilizations("Type='CIVILIZATION_SCIPIO_ROME'") do
	tCivsOfRome[row.ID] = "true"
end
for row in GameInfo.Civilizations("Type='CIVILIZATION_GPUZ_ROME_JULIUS'") do
	tCivsOfRome[row.ID] = "true"
end
for row in GameInfo.Civilizations("Type='CIVILIZATION_GPUZ_GAIUS_ROME'") do
	tCivsOfRome[row.ID] = "true"
end
for row in GameInfo.Civilizations("Type='CIVILIZATION_JFD_ROME_CONSTANTINE'") do
	tCivsOfRome[row.ID] = "true"
end
for row in GameInfo.Civilizations("Type='CIVILIZATION_TCM_AURELIAN_ROME'") do
	tCivsOfRome[row.ID] = "true"
end

function PlayerCanBuildTrajan(PlayerID, BuildingType)
	if BuildingType == iBathsOfTrajan then
		local pPlayer = Players[PlayerID]
		if tCivsOfRome[pPlayer:GetCivilizationType()] then
			return true
		else
			return false
		end
	end
	return true
end
GameEvents.PlayerCanConstruct.Add(PlayerCanBuildTrajan)

print("BathsOfTrajanScript loaded to end")



Could a not-so-burnt-out regular please show me how to generalize that script into a two-list rule: "only the civilizations on List A can build items on List B"? My current modding project includes a lot of "shared unique" buildings which only Scandinavian civs should get; duplicating the same script for each one seems like overkill, so I'd strongly appreciate any help you can offer. :thanx:
 
Back
Top Bottom