Some assistance with Civilization Traits in Lua

  1. Go to this website : http://www.lua.org/cgi-bin/demo
  2. enter this code
    Code:
    local bThisThing = true
    print(tostring(bThisThing == 1))
  3. press the 'run' and see the result
    Spoiler :
    unless you put '1' in for the value of 'bThisThing' you get false.
    boolean values do not evaluate for equality against integer values as anything except false
 
Well, since I pretty much just changed one thing from what was essentially a copy/paste, I have no idea what any of that means.
Spoiler :
I feel like I'm slogging; haven't been learning this .lua stuff very good at all. I hate .lua, I miss coding for C++. :cry:

Anyways, that aside, I think what you're telling me is that maybe IsDenouncedPlayer is a boolean term? Which makes sense. But since I have no real IsDenouncedPlayer code to reference (aside from something overly complicated), I can't make this stuff click in my head.
 
I'm currently programming in a Civ that requires its units to receive a promotion while said civilization has no cities in its empire. I was able to get most of everything working except a few things:

1. When the Civilization has a city I set their unique Palace replacement to remove said unique promotion (PROMOTION_INDOMITABLE_WILL), but that didn't work, so then I set the Palace to give them the PROMOTION_SUBSIDED_WILL which negates the ability of the first promotion (which works). The Problem is that when the city is lost, they should then lose the second promotion, since there is no longer a need for said promotion when they have no cities.

2. The unique Palace gives a unique building in the Capital that gives the player +2 Happiness. If the Capital is captured, the unique building is set to 100 ConquestProb so that they will receive the "normal" version, which should reduce the effectiveness of their defensive buildings by 25%, but it does not seem to want to keep said building when the Capital is captured.

For problem 1, if I cannot do what I desire with a building, is it possible to give a Civilization's units a promotion when they have no cities?

And for problem 2, which probably doesn't require lua, how would I fix the unique building so that it stays in the city upon capture by the enemy?

I've attached the code below for reference.
 

Attachments

  • Harkodos' Jack's Kingdom (BNW).zip
    13.9 KB · Views: 73
I'm currently working on a Civilization trait where the Civ will receive a Combat Bonus against captured cities. To achieve this, I modified the code found in OTiger's Mario Land civilization so that I could achieve this.

However, I'm not quite sure if I've been able to program what I wanted with it. I made a few changes, listed below, but I just want to have someone go over it to make sure that it works correctly.

And just to be clear I want this:
"Military Units receive a combat bonus against captured cities" (This includes cities captured from Major Civilizations, not just City States like in OTiger's original code).

Code:
local iRequiredCiv = GameInfoTypes.CIVILIZATION_AMERICA
local iPromoExtraStrength = GameInfoTypes.PROMOTION_INDOMITABLE_WILL

function GetPlayersAtWarWith(iOurTeamID)
	local tPlayersAtWarWith = {}
	for iTeam = 0, GameDefines.MAX_CIV_TEAMS - 1 do
		if iTeam ~= iOurTeamID then
			local pTheirTeam = Teams[iTeam]
			if not pTheirTeam:IsBarbarian() and not pTheirTeam:IsMinorCiv() and pTheirTeam:IsAlive() then
				if Teams[iOurTeamID]:IsAtWar(iTeam) then
					for PlayerID = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
						local pPlayer = Players[PlayerID]
						if (pPlayer ~= nil) then
							if (pPlayer:GetTeam() == iTeam) and pPlayer:IsAlive() then
								tPlayersAtWarWith[PlayerID] = PlayerID
							end
						end
					end
				end
			end
		end
	end
	return tPlayersAtWarWith
end
function GetConqueredCities(tPlayersAtWarWith)
	local ConqueredCities = "NONE"
	for k,v in pairs(tPlayersAtWarWith) do
		for pCity in Players[v]:Cities() do
			if Players[pCity:GetOriginalOwner()]:IsMinorCiv() or not Players[pCity:GetOriginalOwner()]:IsMinorCiv() then
				if ConqueredCities == "NONE" then
					ConqueredCities = {}
				end
				table.insert(ConqueredCities, pCity)
			end
		end
	end
	return ConqueredCities
end
function ExtraStrengthCityLiberate(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iRequiredCiv then
		local iOurTeamID = pPlayer:GetTeam()
		local bIsAtWar = (Teams[iOurTeamID]:GetAtWarCount(true) > 0)
		for pUnit in pPlayer:Units() do
			if pUnit:IsCombatUnit() then
				local bUnitShouldHavePromotion = false
				if bIsAtWar then
					local tPlayersAtWarWith = GetPlayersAtWarWith(iOurTeamID)
					local tCitiesToBeLiberated = GetConqueredCities(tPlayersAtWarWith)
					if tCitiesToBeLiberated ~= "NONE" then
						local pUnitPlot = pUnit:GetPlot()
						local iTileOwnerID = pUnitPlot:GetOwner()
						if tPlayersAtWarWith[iTileOwnerID] then
							for pCity in Players[iTileOwnerID]:Cities() do
								local bCityIsInConqueredList = false
								for k,v in pairs(tCitiesToBeLiberated) do
									if pCity == v then
										bCityIsInConqueredList = true
										break
									end
								end
								if bCityIsInConqueredList and (Map.PlotDistance(pUnitPlot:GetX(), pUnitPlot:GetY(), pCity:GetX(), pCity:GetY()) <= 3) then
									bUnitShouldHavePromotion = true
								end
							end
						end
					end
				end
				pUnit:SetHasPromotion(iPromoExtraStrength, bUnitShouldHavePromotion)
			end
		end
	end
end
GameEvents.PlayerDoTurn.Add(ExtraStrengthCityLiberate)
 
Perhaps I should rephrase what I want from the previous post:

I want to know if the code, as-is, will work in the intended way with the way I have programmed it and not cause some unforeseen hiccups down the line like: "This code will work in circumstances X and Y, but not Z."

Does that make sense?

So, will the code, as-is, allow the Civilization's Military Units to receive a Combat Bonus against captured cities without other unforeseen hiccups?
 
The code above does not make much sense. To give units combat bonus vs certain cities you have to use combat events from VMC.
 
VMC?

Well, it's pretty much just a code I've edited slightly from a mod by OTiger, that LeeS made.

Really, this line is the most I changed from it in function GetConqueredCities:
Code:
if Players[pCity:GetOriginalOwner()]:IsMinorCiv() [COLOR="Blue"]or not Players[pCity:GetOriginalOwner()]:IsMinorCiv()[/COLOR] then
From what I've observed, it does work, but the unit has to begin its turn right next to said City in order to gain said combat bonus.
 
Hmmm. I'm trying to make sure my mods don't require any modded .dlls, because they might conflict with one another, or add extra workload for the CPU. I want as little inter-dependencies as possible.
 
Alright, with the completion of Phase 1 for my Custom Civilizations, I've decided to go through each of my civs one last time before starting Phase 2 with what I call: Phase 1.5. Essentially, I want to know under what circumstances with would be okay to keep a Civilization's custom Dummybuildings due to the circumstance that LeeS brought to my attention where having Civilizations on Teams or having more than one of the same Civilization in the game can cause irregularities with Dummybuildings.

So, I'm going to list every Civilization I've made that uses Dummybuildings and lump each one into what type of circumstance the Dummybuilding was used for, and I just want to know if leaving the Dummybuilding and the associated XML or Lua code is fine, or if I will have to replace it with something else.

Circumstance #1: for The Monarch's Butterfly Empire and The Mystics:
Spoiler :
This circumstance is purely for Reference purposes as it has already been solved. Under this circumstance, I needed to make the Civilization receive a Dummybuilding that would give the Civilization a unique promotion or effect current buildings upon discovering a certain Technology. Upon LeeS' instruction, this would not work with Dummybuildings, so I fixed it using a Dummy Social Policy given by this code from qqqbbb:
Code:
local iAmerica = GameInfoTypes.CIVILIZATION_AMERICA
local iMysticsTech = GameInfoTypes.TECH_ATOMIC_THEORY
local iMysticsPolicy = GameInfoTypes.POLICY_MAGUS_UA
local iMysticsPlayer
local pMysticsPlayer

function OnTeamTechResearched(iTeam,iTech)
	if iTeam == iMysticsTeam and iTech == iMysticsTech then
		pMysticsPlayer:SetNumFreePolicies(1)
		pMysticsPlayer:SetNumFreePolicies(0)
		pMysticsPlayer:SetHasPolicy(iMysticsPolicy, true)	
	end
end

for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
	local pPlayer = Players[iPlayer]
	if pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == iAmerica then
		GameEvents.TeamTechResearched.Add(OnTeamTechResearched)
		pMysticsPlayer = pPlayer
		iMysticsPlayer = iPlayer
		iMysticsTeam = pPlayer:GetTeam()
		break
    end
end
Circumstance #2: for Clan Bravo:
Spoiler :
I needed a Dummybuilding provided in the Capital for every Social Policy Tree completed. LeeS provided a code for this and I just want to make sure that it will not cause problems with multiple copies of the same Civilization. Code provided here:
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);
Circumstance #3: for Duckburg, Nowhere, Spargus, and The Legion of Beavers:
Spoiler :
I'm pretty sure this one is alright, but I just want confirmation to be sure. For these civilizations, they receive a unique building upon settling cities near specific types of Terrain or Features. This one is purely XML.
Code:
        <Traits>
		<Row>
			... (cut to save space)
			<FreeBuilding>BUILDING_AMERICA_LAKE_DUMMYBUILDING</FreeBuilding>
			... (cut to save space)
		</Row>
	</Traits>
In this circumstance, Duckburg receives a free Dummybuilding when settling near a source of Fresh Water (though it will only affect Lakes).
Circumstance #4: for Haven City, Peach Creek, Petoria, Spargus, Sudanya, The Air Nomads, The Barnyard Burglars, The City of Townsville, The Digital World, The Imaginary Friends, The Land of Discord, The Legion of Beavers, The Mistlands, The Mystics, The Riptocs, The Shinra Electric Power Company, The Simpsons, The Twin Baronies, The Ultimecian Empire, The Valley of Peace, The World of Darkness, The Zanarkand Abes, and Venture Industries:
Spoiler :
I'm pretty sure that this one is fine, since it only uses XML, and uses a unique Palace replacement, but I just want to be sure. Anyways, using said unique Palace replacement, the Civilization receives a unique Dummybuilding in all cities that will do various things. for reference, here's the code for the Palace replacement for The Ultimecian Empire:
Code:
        <Buildings>
		<Row>
			<Type>BUILDING_AMERICA_ULTIMECIAS_CASTLE</Type>
			...
			<FreeBuilding>BUILDINGCLASS_AMERICA_DUMMYBUILDING</FreeBuilding>
			...
		</Row>
        </Buildings
And the subsequent Dummybuilding:
Code:
        <Buildings>
                <Row>
			<Type>BUILDING_AMERICA_DUMMYBUILDING</Type>
			<BuildingClass>BUILDINGCLASS_AMERICA_DUMMYBUILDING</BuildingClass>
			<Description>TXT_KEY_BUILDING_AMERICA_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>30</PortraitIndex>
			<IconAtlas>BW_ATLAS_1</IconAtlas>
		</Row>
        </Buildings>
Circumstance #5: for Hueco Mundo:
Spoiler :
I'm pretty sure this one is fine, but I want to be sure. Anyways, in this circumstance, using Lua, the Civilization in question receives +1 Food in the Capital for every 4 Citizens in the cities of other Major Civilizations. LeeS and Klisz were nice enough to provide Lua code for this:
Code:
local iYourCiv = GameInfoTypes.CIVILIZATION_AMERICA
local iDummy = GameInfoTypes.BUILDING_AMERICA_FOOD_DUMMYBUILDING

function GetWorldPopulation(iPlayer, bSkipDesignatediPlayer, bCountMinors, bTruncateEachCivPop, bTruncateTotalReturned)
	local iTotalCount = 0
	local iCivsNumber = (bCountMinors and (GameDefines.MAX_PLAYERS - 2) or (GameDefines.MAX_MAJOR_CIVS - 1))
	for iOtherPlayer = 0, iCivsNumber do
		local pOtherPlayer = Players[iOtherPlayer]
		if pOtherPlayer:IsEverAlive() and pOtherPlayer:IsAlive() then
			local bCountThisPlayer = true
			if iOtherPlayer == iPlayer and bSkipDesignatediPlayer then
				bCountThisPlayer = false
			end
			if bCountThisPlayer then
				if bTruncateEachCivPop then
					iTotalCount = iTotalCount + math.floor(pOtherPlayer:GetTotalPopulation())
				else
					iTotalCount = iTotalCount + pOtherPlayer:GetTotalPopulation()
				end
			end
		end
	end
	if bTruncateTotalReturned then
		return math.floor(iTotalCount)
	else
		return iTotalCount
	end
end

function FillTheEmptiness(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iYourCiv then
		local pCapital = pPlayer:GetCapitalCity()
		if pCapital then
			pCapital:SetNumRealBuilding(iDummy, math.floor(GetWorldPopulation(iPlayer, true, false, false, true) / 4))
		end
	end
end

GameEvents.PlayerDoTurn.Add(FillTheEmptiness)
Circumstance #6: for South Park, The Land of Discord, The Monarch's Butterfly Empire, and Jack's Kingdom:
Spoiler :
I borrowed the code for this one from PHXRHC/OTiger's New Texas Mod, so I'm failry certain that it should be fine. Anyways in this circumstance the Civilization will receive a Dummybuilding in the Capital while at War with a Major Civilization (which may itself provide an additional Dummybuilding in the rest of their cities, depending upon what use it has). Here's the version used in The Land of Discord:
Code:
local iCiv = GameInfoTypes.CIVILIZATION_AMERICA
local gMFaith = GameInfoTypes.BUILDING_AMERICA_HIDDEN_WAR_FAITH_EFFECTS

function 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 MilitaryFaith(iPlayer)
	local pPlayer = Players[iPlayer]
	-- If the player is in war:
	if (pPlayer:GetCivilizationType() == iCiv) and pPlayer:IsAlive() and pPlayer:IsFoundedFirstCity() then
		pPlayer:GetCapitalCity():SetNumRealBuilding(gMFaith, ((Teams[pPlayer:GetTeam()]:GetAtWarCount(true) > 0) and 1 or 0))
	end
end
if IsCivilisationActive(iCiv) then
	GameEvents.PlayerDoTurn.Add(MilitaryFaith)
end
Circumstance #7: for Springfield, Mewni, and Mystery Twins Incorporated:
Spoiler :
This one I borrowed from DoktorAppleJuice's Soul Society Mod and triggers whenever the Civilization is currently in a Golden Age. I'm pretty sure this one works as well, but I want to be sure. Here's the code as used in my Springfield Civilization:
Code:
print("Springfield Lua loaded")

local iSpringfieldCiv = GameInfoTypes.CIVILIZATION_AMERICA
local iPalace = GameInfoTypes.BUILDING_PALACE
local iGoldenAgeBuilding = GameInfoTypes.BUILDING_AMERICA_GOLDEN_AGE_DUMMYBUILDING

function BurnsTurnFunction(iPlayer)
	local pPlayer = Players[iPlayer];
	--print("Calling Mr. Burns' Turn Function")
	if pPlayer:GetCivilizationType() == iSpringfieldCiv then
		for pCity in pPlayer:Cities() do
			if (pPlayer:IsGoldenAge() and (pCity:GetNumBuilding(iPalace) > 0)) then
				local strCityName = pCity:GetName();	
				--print("Spawning Golden Age Dummybuilding in " .. strCityName)
				pCity:SetNumRealBuilding(iGoldenAgeBuilding, 1)
			else
				pCity:SetNumRealBuilding(iGoldenAgeBuilding, 0)
			end	
		end
	end
end
GameEvents.PlayerDoTurn.Add(BurnsTurnFunction)
Circumstance #8: for The Aku Empire and The Pollutors:
Spoiler :
Pretty sure this one should work, but I just wnat confirmation is all. This one provides a Dummybuilding in another Civilization's Capital when they Declare Friendship with this particular Civilization (in this case: either The Aku Empire or The Pollutors. Also, the effects of the Dummybuilding are detrimental to the other Civilization.) Here's the code as used in The Pollutors:
Code:
local iAmerica = GameInfoTypes.CIVILIZATION_AMERICA
local 	iWashington
local 	pWashington
local iDummyBuilding = GameInfoTypes.BUILDING_AMERICA_FRIENDSHIP_DUMMYBUILDING

local function OnPlayerDoTurn(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:IsAlive() and pPlayer:GetDoFCounter(iWashington) == 1 then
		local pTheirCapital = pPlayer:GetCapitalCity()
		pTheirCapital :SetNumRealBuilding(iDummyBuilding , 1)
	end
end

for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iAmerica then
		iWashington = iPlayer
		pWashington = pPlayer
		GameEvents.PlayerDoTurn.Add ( OnPlayerDoTurn )
		break
	end
end
Circumstance #9: for The Chroniclers, The Hamato Clan, The Simpsons, and The Valley of Peace:
Spoiler :
Klisz was nice enough to provide a modified code from his Radiant Garden civilization, so I'm fairly certain this one should work, but again, just want confirmation. Anyways, this code provides a number of Dummybuildings in a City based upon how many Great Works it currently possesses. Code by Klisz for The Chroniclers here:
Code:
local iCivilization = GameInfoTypes.CIVILIZATION_AMERICA
local iDummyBuilding = GameInfoTypes.BUILDING_AMERICA_DUMMYBUILDING

local iMaxCivs = GameDefines.MAX_MAJOR_CIVS
local iMaxPlayers = GameDefines.MAX_CIV_PLAYERS
local bPopup;
local tGreatWorkBuildings = {};
for pBuilding in GameInfo.Buildings() do
	if pBuilding.GreatWorkCount > 0 then
		local pBuildingClass = GameInfo.BuildingClasses("Type = '" ..pBuilding.BuildingClass.. "'")()
		tGreatWorkBuildings[pBuildingClass.ID] = pBuildingClass.Type
	end
end

function UpdateDummyBuildings(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() ~= iCivilization then return end
	if pPlayer:IsEverAlive() and not pPlayer:IsMinorCiv() then
		for pCity in pPlayer:Cities() do
			local iBuildingsToAdd = 0
			for iBuildingClass, pBuildingClass in pairs(tGreatWorkBuildings) do
				local iCurrentWorks = pCity:GetNumGreatWorksInBuilding(iBuildingClass)
				print("In the " .. pBuildingClass .. " in " .. pCity:GetName() .. " there are " .. iCurrentWorks .. " Great Works")
				if iCurrentWorks > 0 then
					for i = 0, iCurrentWorks - 1, 1 do
						local iWorkType = pCity:GetBuildingGreatWork(iBuildingClass, i)
						print("Found a Great Work!")
						iBuildingsToAdd = iBuildingsToAdd + 1;
					end
				end
			end
			print("Adding " .. iBuildingsToAdd .. " buildings to " .. pCity:GetName())
			pCity:SetNumRealBuilding(iDummyBuilding, iBuildingsToAdd);
		end
	end
end

function UpdateDummyBuildingsUI()
	if bPopup then
		UpdateDummyBuildings(Game:GetActivePlayer())
	end
end

GameEvents.PlayerDoTurn.Add(UpdateDummyBuildings)
Events.SerialEventCityInfoDirty.Add(UpdateDummyBuildingsUI)

function SetCurrentPopup(popupInfo)
	local popupType = popupInfo.Type
	if popupType == ButtonPopupTypes.BUTTONPOPUP_CULTURE_OVERVIEW then
		bPopup = true
	end
end
Events.SerialEventGameMessagePopup.Add(SetCurrentPopup)

function ClearCurrentPopup()
	bPopup = nil;
end
Events.SerialEventGameMessagePopupProcessed.Add(ClearCurrentPopup)
Circumstance #10: for Slugterra, The City of Nerekhall, and The Zanarkand Abes:
Spoiler :
I borrowed this one from PHXHRC/OTiger's Bikini Bottom Mod, so I'm fairly sure this will work, but I just want confirmation. This code provides a Dummybuilding in the Capital for every City State Ally the Civilization possesses. Here's the code used from The City of Nerekhall:
Code:
gRylanDummy = GameInfoTypes.BUILDING_AMERICA_DUMMYBUILDING
local iNeededPlayer = GameInfoTypes.CIVILIZATION_AMERICA
function RylanCSUA(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iNeededPlayer then
		local iCityDefenseBonus = 0
		local pCapitalCity = pPlayer:GetCapitalCity()
		for iLoopPlayer, pLoopPlayer in pairs(Players) do
			if pLoopPlayer:IsMinorCiv() then
				if pLoopPlayer:GetMinorCivFriendshipLevelWithMajor(iPlayer) >= 2 then
					iCityDefenseBonus = iCityDefenseBonus + 1
				end
			end
		end
		pCapitalCity:SetNumRealBuilding(gRylanDummy , iCityDefenseBonus)
		print("Setting " .. iCityDefenseBonus .. " Rylan Olliven Dummy Buildings into the capital city of " .. pCapitalCity:GetName())
	end
end
GameEvents.PlayerDoTurn.Add(RylanCSUA)
Circumstance #11: for The Equalists and The Simpsons:
Spoiler :
If memory serves this may be the one I'm most worried about, so I really want to get this one fixed and done with. Anyways, this code provides a Dummybuilding in the Capital each time the Civilization enters into a new Era. For The Simpsons, this decreases the yields of other Dummybuildings that they're already given by their unique Palace (explained earlier in circumstance #4), and for The Equalists this will trigger them adopting an Ideology upon entering into the Industrial Era. Here's the code as used in The Equalists:
Code:
local iBuildingEarlyIdeology = GameInfoTypes.BUILDING_AMERICA_IDEOLOGY_DUMMYBUILDING
local iRequiredCivilization = GameInfoTypes.CIVILIZATION_AMERICA

--------------------------------------------------------------
-- check for a change in era during PlayerDoTurn
--------------------------------------------------------------
function PlayerEraChanged(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() ~= iRequiredCivilization then return end
	if not pPlayer:IsAlive() then return end
	local iNewPlayerEra = pPlayer:GetCurrentEra()
	--print("The value for player era was " .. iNewPlayerEra)
	local iNumBuildingEarlyIdeology = 0
	local pCapitalCity = pPlayer:GetCapitalCity()
	if pCapitalCity ~= nil then
		if pCapitalCity:IsHasBuilding(iBuildingEarlyIdeology) then
			iNumBuildingEarlyIdeology = pCapitalCity:GetNumRealBuilding(iBuildingEarlyIdeology)
			--print("The number of iBuildingEarlyIdeology buildings was " .. iNumBuildingEarlyIdeology)
		end
		if iNewPlayerEra > iNumBuildingEarlyIdeology then
			--print("The era value was found to be greater than the number of Early Ideology buildings")
			pCapitalCity:SetNumRealBuilding(iBuildingEarlyIdeology, iNewPlayerEra)
			--print("The number of iBuildingEarlyIdeology buildings was changed from " .. iNumBuildingEarlyIdeology .. " to " .. iNewPlayerEra)
		end
	end
end
GameEvents.PlayerDoTurn.Add(PlayerEraChanged);
Circumstance #12: for Jack's Kingdom, and The Imaginary Friends:
Spoiler :
I borrowed this code from DoktorAppleJuice's Soul Society Mod, so I'm pretty sure it should work. Anyways, this code will place a Dummybuilding in any city that has a particular building inside of it to "fake" increasing that building's yields. Here's the code used in The Imaginary Friends:
Code:
print("Imaginary Friends Lua loaded")

local iImaginaryFriendsCiv = GameInfoTypes.CIVILIZATION_AMERICA
local iMonastery = GameInfoTypes.BUILDING_MONASTERY
local iDummyBuilding = GameInfoTypes.BUILDING_AMERICA_MONASTERY_DUMMYBUILDING

function FosterTurnFunction(iPlayer)
	local pPlayer = Players[iPlayer];
	--print("Calling Madame Foster's Turn Function")
	if pPlayer:GetCivilizationType() == iImaginaryFriendsCiv then
		for pCity in pPlayer:Cities() do
			if (pCity:GetNumBuilding(iMonastery) > 0) then
				local strCityName = pCity:GetName();	
				--print("Spawning Monastery Dummybuilding in " .. strCityName)
				pCity:SetNumRealBuilding(iDummyBuilding, 1)
			else
				pCity:SetNumRealBuilding(iDummyBuilding, 0)
			end	
		end
	end
end
GameEvents.PlayerDoTurn.Add(FosterTurnFunction)
Circumstance #13: for The World of Darkness:
Spoiler :
I borrowed this code from the Vietnam ft. The Trung Sisters Mod, so I'm fairly certain it should work, but I just want to be sure. Anyways, this code provides a Dummybuilding in the Capital for every Policy in the Exploration Tree that the Civilization has adopted. Here's the code used:
Code:
function GetWorldOfDarknessExploration(player)
        local numExplorationPolicies = 0
        for row in GameInfo.Policies() do
            if row.PolicyBranchType == "POLICY_BRANCH_EXPLORATION" then
                local policyType = row.Type
                if player:HasPolicy(GameInfoTypes[policyType]) then
                    numExplorationPolicies = numExplorationPolicies + 1
                end
            end
        end
       
    return numExplorationPolicies
end
                               
function WorldOfDarknessExploration(playerID)
    local player = Players[playerID]
    if player:IsAlive() and player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_AMERICA"] then
        local numExplorationPolicies = GetWorldOfDarknessExploration(player)
        for city in player:Cities() do
            if city:GetNumBuilding(GameInfoTypes["BUILDING_AMERICA_RELIGION_DUMMYBUILDING"]) < numExplorationPolicies then
                city:SetNumRealBuilding(GameInfoTypes["BUILDING_AMERICA_RELIGION_DUMMYBUILDING"], numExplorationPolicies)
            end
        end
    end
end
GameEvents.PlayerDoTurn.Add(WorldOfDarknessExploration)
And that's it. So, just to reiterate: I want to know if any of these uses of Dummybuildings will come into complications when playing on Teams or with more than one of the same Civilization in-game. Most of these I'm pretty sure are fine, but I just want to double check to make sure.
 
Alright, so I went through each of the Mods individually to scope out what was wrong with any of the buildings/UAs, and I found a few problems that I'd like help with:

For Clan Bravo:
Spoiler :
It seems that when conquering Clan Bravo's Capital, they will lose all of their unique buildings, but will regain them once they've completed a new Policy Tree. This is pretty much true for all copies of the civ when playing with multiple copies. Basically, I need the code below to recheck for when they have a new Capital and give them the allotted copies of the appropriate Dummybuilding for how many Policy Trees they've finished; not just when they finish a new Policy Tree, but also when they have a new Capital in place (or regain their old one).
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);

For Slugterra:
Spoiler :
This one should be pretty simple to fix. Slugterra is supposed to receive 100 Golden Age points every time they Liberate a city. This works fine for the first copy of the Civilization, but not the rest. Therefore, I need this code to be tweaked to work with multiple copies of the same Civ:
Code:
local iAmerica = GameInfoTypes.CIVILIZATION_AMERICA
local iSlugterraPlayer
local pSlugterraPlayer

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

for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
	local pPlayer = Players[iPlayer]
	if pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == iAmerica then
		GameEvents.CityCaptureComplete.Add(OnCityCaptureComplete)
		pSlugterraPlayer = pPlayer
		iSlugterraPlayer = iPlayer
		break
    end
end

For The Aku Empire and The Pollutors:
Spoiler :
These two Civilizations have the same problem. When Declaring Friendship with another civilization, they are supposed to provide a Dummybuilding in the Capital city of their friend, but this only seems to work with the first copy of said civ. Ideally, I need the code below to be tweaked to work for multiple copies of the same civ.
Code:
local iAmerica = GameInfoTypes.CIVILIZATION_AMERICA
local 	iWashington
local 	pWashington
local iDummyBuilding = GameInfoTypes.BUILDING_AMERICA_FRIENDSHIP_DUMMYBUILDING

local function OnPlayerDoTurn(iPlayer)
	local pPlayer = Players[iPlayer]
	if pPlayer:IsAlive() and pPlayer:GetDoFCounter(iWashington) == 1 then
		local pTheirCapital = pPlayer:GetCapitalCity()
		pTheirCapital :SetNumRealBuilding(iDummyBuilding , 1)
	end
end

for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
	local pPlayer = Players[iPlayer]
	if pPlayer:GetCivilizationType() == iAmerica then
		iWashington = iPlayer
		pWashington = pPlayer
		GameEvents.PlayerDoTurn.Add ( OnPlayerDoTurn )
		break
	end
end

For The Equalists:
Spoiler :
This one should be pretty simple. Almost all of The Equalists' UA works except for the below excerpt I borrowed from The Koopa Troop which I need to work for multiple copies of the same Civilization. Basically, this code reduces the time a City spends in Resistance when captured by The Equalists by half. Perhaps I removed something necessary when transferring it to my Mod, I don't know, but I would love help fixing it in either case.
Code:
-- ============================================================================
-- Enables debug statements
-- ============================================================================
local bDebug = false

function dprint(...)
  if (bDebug) then
    print(string.format(...))
  end
end

-- ============================================================================
-- AmonConquerCheck
-- ============================================================================
--We have a couple of things to check when a city is conquered...
function AmonConquerCheck(iPlayer, isCapital, cityX, cityY, iNewPlayer)

	-- Get the city that was specified by the coordinates
	local pCity = Map.GetPlot(cityX, cityY):GetPlotCity()
	
	-- Check if this is an Equalist city
	local pPlayer = Players[iPlayer];
	local pNewPlayer = Players[iNewPlayer];
	if (pNewPlayer:GetCivilizationType() == GameInfo.Civilizations.CIVILIZATION_AMERICA.ID) then
		dprint("Amon has conquered " .. pCity:GetName() .. "!")
		AmonHalveResist(pCity)
	end
end

-- ============================================================================
-- AmonHalveResist
-- ============================================================================
-- Halves the resistance time of a conquered city if Amon conquered it
function AmonHalveResist(pCity)
		dprint("Halving resistance time for " .. pCity:GetName() .. " (original was " .. pCity:GetResistanceTurns() .. " turns)...");
		-- Only fixed this just before release! I suppose I should have known since the function is "ChangeResistanceTurns()" rather than "SetResistanceTurns()"...
		pCity:ChangeResistanceTurns(-pCity:GetResistanceTurns()/2);
		dprint("Resistance time for " .. pCity:GetName() .. " is now " .. pCity:GetResistanceTurns() .. " turns.");
end

For The Monarch's Butterfly Empire and The Mystics:
Spoiler :
The Lua code I was using for these doesn't want to work for multiple copies of the same Civilization, so I tried converting it to XML with the Traits Table, but I'm having a problem:

The <PrereqTech> in <Traits> and the <Trait_FreePromotionUnitCombats> don't seem to want to work with each other. Can I get confirmation as to why that is? If XML is out of the question, then could someone fix the following Lua code to work for multiple copies of the same Civ as well?
Code:
local iAmerica = GameInfoTypes.CIVILIZATION_AMERICA
local iButterflyEmpireTech = GameInfoTypes.TECH_FLIGHT
local iButterflyEmpirePolicy = GameInfoTypes.POLICY_THE_MONARCH_UA
local iButterflyEmpirePlayer
local pButterflyEmpirePlayer

function OnTeamTechResearched(iTeam,iTech)
	if iTeam == iButterflyEmpireTeam and iTech == iButterflyEmpireTech then
		pButterflyEmpirePlayer:SetNumFreePolicies(1)
		pButterflyEmpirePlayer:SetNumFreePolicies(0)
		pButterflyEmpirePlayer:SetHasPolicy(iButterflyEmpirePolicy, true)	
	end
end

for iPlayer = 0, GameDefines.MAX_MAJOR_CIVS - 1, 1 do
	local pPlayer = Players[iPlayer]
	if pPlayer:IsEverAlive() and pPlayer:GetCivilizationType() == iAmerica then
		GameEvents.TeamTechResearched.Add(OnTeamTechResearched)
		pButterflyEmpirePlayer = pPlayer
		iButterflyEmpirePlayer = iPlayer
		iButterflyEmpireTeam = pPlayer:GetTeam()
		break
    end
end
 
Top Bottom