[Lua] What does City.SetBuildingYieldChange() do?

Irkalla

ENTP POWWWEEEEEER
Joined
Sep 25, 2012
Messages
1,009
Location
Way down around Vicksburg
So.....anyone use this one yet? I was thinking of using this in a wonder of mine that would add gold per turn based on the copies of Gold luxury you have. Does the building have to already have a yield to it for this to work?
 
So I got it to work. However what is lame is while it is "updating the yield" of the building you dont actually see this change when you highlight over the building when you are looking at all the buildings that are in your city. Also you have to set the building's normal gold yield to 0 in the XML for it to truly work (at least for what I want it to do, which is give no gold unless you have a copy of Gold luxury).

For example: The wonder is set to normally give a yield of 0 gold in its XML, I then give myself 2 copies of Gold and I have City.SetBuildingYieldChange() changing the wonder to give +10 gold per Gold luxury. So sure enough I get my 20 gold a turn, however the building doesn't actually show that its giving that as a yield. You can see the gold change at the top in your "empire panel" and under the info of where you are getting your gold from in the city "+25 gold from buildings" (not that it shows this part but its 5 from the palace and 20 from the wonder), however the yield of 0 gold seems to prevent the building from displaying that its giving any gold. I then try to set the wonder to give a yield of 20 gold in its XML. I was thinking that this would be ok since the wonder gives you 2 copies anyways and that if I were to trade away those copies, I should have the wonder giving 0 gold. However this didnt work either, no matter what the wonder will always give at least 20 gold plus the bonus gold per turn for having the Gold copies. And again, the city overlay didnt update the actual yield of the building, just kept it at 20 gold no matter what.

Bottom line: The code works but the building wont display the actual change that is occurring. Anyone else figure out how to get a building's yields to show dynamic changes?

Here is the code to show you how I have it working.

Code:
FortKnoxClass = GameInfoTypes.BUILDINGCLASS_FORT_KNOX
FortKnoxBuilding = GameInfoTypes.BUILDING_FORT_KNOX
BuildingGold = YieldTypes.YIELD_GOLD
MajorPlayers = GameDefines.MAX_MAJOR_CIVS

function FortKnoxGoldBonus(playerId)
	--if you are not a CS or Barb
	if playerId < MajorPlayers then
		local pPlayer = Players[playerId];
		-- If you have the wonder do the following
		if pPlayer:GetBuildingClassCount(FortKnoxClass) > 0 then
			local iGoldLuxury = pPlayer:GetNumResourceTotal(15, true);
			local iGoldBonus = (iGoldLuxury * 10);

			for pCity in pPlayer:Cities() do

				if pCity:IsHasBuilding(FortKnoxBuilding) then
					pCity:SetBuildingYieldChange(FortKnoxClass, BuildingGold, iGoldBonus);
					break
				end
			end
		end
	end
end 
GameEvents.PlayerDoTurn.Add(FortKnoxGoldBonus);
 
What you are experiencing is actually an exact copy of the method Firaxis uses to impliment yield changes coming from <Building_TechEnhancedYieldChanges>. They are never applied directly to the building, they are added as a direct city-enhancement within the city yields box in the upper-left corner of the city view.
 
Back
Top Bottom