Help with custom civ decision (for E&D support)

Gurra09

Emperor
Joined
Jan 1, 2008
Messages
1,298
Location
Sweden
Hi!

I'm working to include support for Sukritact's Events and Decisions in my Sikh Empire civ but I'm running into some problems with how to implement my design.

The decision I have in mind is:

Restrictions/Requirements:
- Player is Sikh
- Must have researched Architecture
- Must have built Gurdwara (unique Temple replacement) in at least one city founded by the player
Costs:
- 600 gold
- 2 magistrates
Rewards:
- Harmandir Sahib (world wonder) is built in a city founded by the player which has a Gurdwara

I have been able to make a decision that detects whether you:
- play as Sikh
- have 600 gold
- have 2 magistrates
- have researched Architecture

And if that's true you can enact it upon which the game will:
- take 600 gold away from you
- take 2 magistrates away from you

Code:
-- SikhEmpire_Decisions
-- Author: Almgren
-- DateCreated: 6/7/2015 4:37:10 PM
--------------------------------------------------------------
  
local Decisions_GurraSikhHarmandir = {}
	Decisions_GurraSikhHarmandir.Name = "TXT_KEY_DECISIONS_GURRASIKHHARMANDIR"
	Decisions_GurraSikhHarmandir.Desc = "TXT_KEY_DECISIONS_GURRASIKHHARMANDIR_DESC"
	HookDecisionCivilizationIcon(Decisions_GurraSikhHarmandir, "CIVILIZATION_GURRA_SIKH")
	Decisions_GurraSikhHarmandir.CanFunc = (
	function(pPlayer)
		if (pPlayer:GetCivilizationType() ~= GameInfoTypes.CIVILIZATION_GURRA_SIKH) then 
		return false, false
		end

		if load(pPlayer, "Decisions_GurraSikhHarmandir") == true then
		Decisions_GurraSikhHarmandir.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_GURRASIKHHARMANDIR_ENACTED_DESC")
		return false, false, true
		end

		local iCost = math.ceil(600 * iMod)
		Decisions_GurraSikhHarmandir.Desc = Locale.ConvertTextKey("TXT_KEY_DECISIONS_GURRASIKHHARMANDIR_DESC", iCost)

		if (pPlayer:GetGold() < iCost) then return true, false end
		if (pPlayer:GetNumResourceAvailable(iMagistrate, false) < 2) then return true, false end
		if not(Teams[pPlayer:GetTeam()]:IsHasTech(GameInfoTypes.TECH_ARCHITECTURE)) then return true, false end

		return true, true
	end
	)
	
	Decisions_GurraSikhHarmandir.DoFunc = (
	function(pPlayer)
		local iCost = math.ceil(600) * iMod
		pPlayer:ChangeGold(-iCost)
		pPlayer:ChangeNumResourceTotal(iMagistrate, -2)
		save(pPlayer, "Decisions_GurraSikhHarmandir", true)
	end
	)
	
Decisions_AddCivilisationSpecific(GameInfoTypes.CIVILIZATION_GURRA_SIKH, "Decisions_GurraSikhHarmandir", Decisions_GurraSikhHarmandir)

But the decision is still missing the main point which I just can't work out how to add. I want the game to go through all of the player's cities to see if they have a BUILDING_GURDWARA in a city they founded themselves (mostly to avoid puppets). Then I want it to pick one of those cities, and when the decision is enacted build the BUILDING_GURRA_HARMANDIR world wonder in the chosen city.

Basically, I want to add 'one city founded by the player, with Gurdwara' to the CanFunc function and add 'Build Harmandir Sahib wonder in one of the cities with a Gurdwara' to the DoFunc function.

How would I accomplish that? Is it even possible? I tried to find something similar among the civ specific decisions provided in E&D itself but the only ones I found built the building in the capital city.

(I do not want the player to be able to choose which city with a Gurdwara to build it in, I want it to be random and for there to only be one decision in the list. I already tried a method where I got one decision for each possible city using tTempDecisions.)

-------------------------------------------------------------------------------------------------
And if what I'm looking to achieve is possible, would it be possible to refine the way the function chooses city like this?
1 Go through all cities. Then:
2 If a city has a Gurdwara and all three of Writer's Guild, Artist's Guild and Musicians Guild: pick that city. Else:
3 If a city has a Gurdwara and two of the three Guilds: pick that city. Else:
4 Pick a city that has a Gurdwara and one of the three Guilds. Else:
5 Pick any city that has a Gurdwara.

So, if there are Guilds the wonder will preferrably be placed in those cities but Guilds are no requirement to enact the decision.
 
Sorting whether the player has BUILDING_GURDWARA in a city they founded themselves

Normally I would be doing this sort of thing in a sub-function that just returns true/false, but I am not sure how well that would work for being inserted into Suktritact's systems. I am still trying to wrap my head around the whole Events & Decisions thing myself.

Code:
local bBuildingRequirementsMet = false
if (pPlayer:GetBuildingClassCount(GameInfoTypes.BUILDINGCLASS_GURRA_HARMANDIR_WONDER) == 0) and (pPlayer:GetBuildingClassCount(GameInfoTypes.BUILDINGCLASS_GURDWARA_BUILDING) > 0) then
	for pCity in pPlayer:Cities() do
		if pCity:IsHasBuilding(GameInfoTypes.BUILDING_GURDWARA) then
			if Players[pCity:GetOriginalOwner()] == pPlayer then
				bBuildingRequirementsMet = true
				break
			end
		end
	end
end
Since I don't know what the correct BUILDINGCLASS name is for the wonder or the building, I used names that should be obvious as which is which. bBuildingRequirementsMet should only be altered to true in the following conditions:
  1. The wonder has not already been added.
    • if it is already added somewhere in the empire, nothing should run past the second line, and bBuildingRequirementsMet should remain as false. This should ensure that the 'can' function will not result in an 'enable' of the 'do' function more than once.
  2. there is at least one BUILDING_GURDWARA somewhere in the empire
    • if there is not already a BUILDING_GURDWARA somewhere in the empire, nothing should run past the second line, and bBuildingRequirementsMet should remain as false.
  3. At least one city that has a BUILDING_GURDWARA was founded by the player
Selecting a city the player has with a BUILDING_GURDWARA in a city they founded themselves

The bit with randomly selecting a city which has a BUILDING_GURDWARA and which was also founded by the player would not be too terribly hard, but I am not sure I would be able to have time to look at it until perhaps tomorrow sometime for including the bit related to the Guilds. The thing with the Guilds being present is not insurmountable, just a bit more involved in figuring the code+logic to adhere to the conditions you have expressed as desired.

In order to generate a list of the possible cities to stick the wonder (assuming none of the Guilds have been constructed) I would just add a similar iteration through the player's cities in the 'do' function, except that every time a valid candidate is discovered, I would stick it into a temporary table that I had defined before I ever started looking through the list of cities, something like:
Code:
local ValidCitiesForWonder = {}
for pCity in pPlayer:Cities() do
	if pCity:IsHasBuilding(GameInfoTypes.BUILDING_GURDWARA) then
		if Players[pCity:GetOriginalOwner()] == pPlayer then
			table.insert(ValidCitiesForWonder, pCity)
		end
	end
end
And then pick the random city from that list:
Code:
local ValidCitiesForWonder = {}
for pCity in pPlayer:Cities() do
	if pCity:IsHasBuilding(GameInfoTypes.BUILDING_GURDWARA) then
		if Players[pCity:GetOriginalOwner()] == pPlayer then
			table.insert(ValidCitiesForWonder, pCity)
		end
	end
end
local pSelectedCity = ValidCitiesForWonder[math.random(#ValidCitiesForWonder)]
Which will stick a randomly-selected city from the list of valid cities into pSelectedCity. Then the wonder is simply added to that selected city:
Code:
local ValidCitiesForWonder = {}
for pCity in pPlayer:Cities() do
	if pCity:IsHasBuilding(GameInfoTypes.BUILDING_GURDWARA) then
		if Players[pCity:GetOriginalOwner()] == pPlayer then
			table.insert(ValidCitiesForWonder, pCity)
		end
	end
end
local pSelectedCity = ValidCitiesForWonder[math.random(#ValidCitiesForWonder)]
pSelectedCity:SetNumRealBuilding(GameInfoTypes.BUILDING_GURRA_HARMANDIR, 1)
But as mentioned the deal with the Guilds makes the logic a bit more to sort through and think-out, so the above doesn't have anything for it.
 
Thanks for your help! It works just like I had planned in my original design now, which makes me a very happy person.

Now onto the guilds, it's not that much of a deal really. The only reason for it was because the world wonder you receive has this stat:
+1 Faith from Artist, Musician, and Writer Specialists.

I'm not completely sure if that's global or local. If it's global, then I don't really need any existing Guilds to be considered when placing the wonder. But if it's local then it would be pretty annoying if you had all your Artist, Musician, and Writer specialists in one city (that has a Gurdwara) but got the wonder placed in another.

In other words: I should probably look into whether the <Building_SpecialistYieldChanges> XML table works locally or globally before trying to make the Lua consider existing guilds.
 
Thanks for your help! It works just like I had planned in my original design now, which makes me a very happy person.

Now onto the guilds, it's not that much of a deal really. The only reason for it was because the world wonder you receive has this stat:
+1 Faith from Artist, Musician, and Writer Specialists.

I'm not completely sure if that's global or local. If it's global, then I don't really need any existing Guilds to be considered when placing the wonder. But if it's local then it would be pretty annoying if you had all your Artist, Musician, and Writer specialists in one city (that has a Gurdwara) but got the wonder placed in another.

In other words: I should probably look into whether the <Building_SpecialistYieldChanges> XML table works locally or globally before trying to make the Lua consider existing guilds.
<Building_SpecialistYieldChanges> is global, but quirky in the way Firaxis implimented it. See 2nd segment of this post. Long story short, faith doesn't work, so you'd have to write lua to get around this PITA limitation, or (a) require the user to also enable whoward's VMC dll mod, and (b) force your mod to be dependant on whoward's VMC dll mod, and (c) conform your change to specialist yields to whatever whoward did in his dll (I think all he did was complete the hook-ups for the missing two yields so with his VMC mod active all you do is state the Faith-change like you would under that table for any of the four 'primary' yields).
 
Top Bottom