yield changes with era

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
3,019
Location
Operation Padlock ground zero
Well, my Inuit mod is nearly done, but there are still a few glitches.
One of which is that the alternate UB - the igloo (replaces granary) - is supposed to give +1 culture per era... that is, +1 if you're in the ancient era, +2 in classical, +3 in medieval, and so on. Well, it isn't. (Who could've seen that coming? :rolleyes:)

So I have coding, it has InGameUIAddin and everything, but no success:
Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(
function(playerID)
	local pPlayer = Players[playerID]
	if (pPlayer:IsAlive()) then
		for pCity in pPlayer:Cities() do
			local pBuilding = GameInfoTypes.BUILDING_IGLOO
			local pBuildClass = GameInfoTypes.BUILDINGCLASS_GRANARY
			local culture = GameInfoTypes.YIELD_CULTURE
			if (pCity:IsHasBuilding(pBuilding)) then
				if (pPlayer:GetCurrentEra() == GameInfoTypes.ERA_ANCIENT) then
					pCity:SetBuildingYieldChange(pBuildClass, culture, 1)
				elseif (pPlayer:GetCurrentEra() == GameInfoTypes.ERA_CLASSICAL) then
					pCity:SetBuildingYieldChange(pBuildClass, culture, 2)
				elseif (pPlayer:GetCurrentEra() == GameInfoTypes.ERA_MEDIEVAL) then
					pCity:SetBuildingYieldChange(pBuildClass, culture, 3)
				elseif (pPlayer:GetCurrentEra() == GameInfoTypes.ERA_RENAISSANCE) then
					pCity:SetBuildingYieldChange(pBuildClass, culture, 4)
				elseif (pPlayer:GetCurrentEra() == GameInfoTypes.ERA_INDUSTRIAL) then
					pCity:SetBuildingYieldChange(pBuildClass, culture, 5)
				elseif (pPlayer:GetCurrentEra() == GameInfoTypes.ERA_MODERN) then
					pCity:SetBuildingYieldChange(pBuildClass, culture, 6)
				elseif (pPlayer:GetCurrentEra() == GameInfoTypes.ERA_ATOMIC) then
					pCity:SetBuildingYieldChange(pBuildClass, culture, 7)
				elseif (pPlayer:GetCurrentEra() == GameInfoTypes.ERA_INFORMATION) then
					pCity:SetBuildingYieldChange(pBuildClass, culture, 8)
				else break end
			end
		end
	end
end)
I'm not entirely sure whether or not I was supposed to use "else break end", but I needed some way to end the code there.

So, questions:

1) Is such a feature even possible? Yields that change with the era?
2) Why wouldn't the code be working?
3) It isn't a syntax error - in fact, the lua.log mentions nothing. But why isn't it showing up?

If I still need to attach my mod, I can.

TIA :goodjob:
 
I would recommend an alternative approach.

I have some lua code that will detect when a player enters a new era and when a unit is created. You'll need both for this algorithm to work.

1) Create a noLimit building that has +1 Culture.
2) Create a new unitClass "unitClass_igloo_finished" that can't be built normally.
3) The igloo should do nothing but spawn a free "unit_igloo_finished".
4) When you detect a unit of "igloo_finished" class, delete it and get the city at the plot where the unit was created (this information is provided via the "unit created event" code)
5) (continuing from 4) Give the city X copies of the noLimit building based on the current era.
6) When you detect the player entering a new era, loop over all their cities and test if they have the igloo. Give them the correct number of the noLimit building for the new era.
7) When a player of this civ captures a city, test if the city has an igloo, if so, add the correct number of the noLimit building.
 
I would recommend an alternative approach.

I have some lua code that will detect when a player enters a new era and when a unit is created. You'll need both for this algorithm to work.

1) Create a noLimit building that has +1 Culture.
2) Create a new unitClass "unitClass_igloo_finished" that can't be built normally.
3) The igloo should do nothing but spawn a free "unit_igloo_finished".
4) When you detect a unit of "igloo_finished" class, delete it and get the city at the plot where the unit was created (this information is provided via the "unit created event" code)
5) (continuing from 4) Give the city X copies of the noLimit building based on the current era.
6) When you detect the player entering a new era, loop over all their cities and test if they have the igloo. Give them the correct number of the noLimit building for the new era.
7) When a player of this civ captures a city, test if the city has an igloo, if so, add the correct number of the noLimit building.
:confused: But how do you create a buildingclass - if I'm understanding what you're saying correctly - that can have multiple instances in a single city?
 
You can create a new buildingClass by adding a new row in the buildingClass table.

Normally a player can only have at most 1 "Wall" building in a city. However, if you make a building with "noLimit = true" the city could have 3 copies of the building. No normal building has "noLimit = true".
----------
There is some XML for the landmark improvement that allows its yield to change depending on the era. If you give the civilization a unique improvement instead of a unique building you may be able to use the landmark XML for your own unique improvement. It could let you get a similar effect with only XML instead of this tricky method.
 
:confused: But how do you create a buildingclass - if I'm understanding what you're saying correctly - that can have multiple instances in a single city?

When you define the BuildingClass, there's a tag in the XML for <NoLimit>, so you just go <NoLimit>true</NoLimit>.

I'll admit, I'm pretty novice at modding and coding Lua myself, but to implement your Igloo code I'd probably do something like this:

Create the Igloo as a UB replacement to the Granary that gives a base +1 culture, and create a dummy building that just gives +1 Culture and has <NoLimit>true</NoLimit> in its BuildingClass. Then, at the start of the player's turn, go through each of their cities and find if they've got the corresponding building there. If it is, then use player:GetCurrentEra to find what era they're in -- since this value is an integer, going from 0 for the Ancient era to 6 for the Future era, you can then spawn that many dummy buildings using City:SetNumRealBuilding.

It's probably a brute-force approach that lacks the finesse of more sophisticated code, and your culture output will lag slightly since it's only updated at the start of the turn, but since that's when culture is added to policies, it shouldn't be too noticable.

If you need an example of how to set up the Lua code and the dummy building, take a look at my Moriya Shrine mod. The Taisha is basically set up in this fashion -- it has a base faith yield, but then the Lua code goes through the sequence I described above each turn, checking to see how many religious followers are in each city and spawning a certain number of dummy buildings there to give the illusion of a varying yield. All you'd really need to do is change my faith yields to culture, and change the number of buildings generated to correspond to the value of GetCurrentEra. It's not the most elegant solution, but it works for me. :P
 
Back
Top Bottom