Crusade Against Dummy Buildings (C.A.D.B) - A Lua Workaround Question/Request

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
2,984
Location
Operation Padlock ground zero
The title makes it sound like some kind of ongoing project :lol::crazyeye:
It's not, really

Basically, since I aim to make my mods compatible with G&K, I try to use as few dummy buildings as possible, since they can't be turned invisible anywhere near as easily as in BNW. Therefore, I'm trying to figure out some lua trickery to reduce (but not eliminate) the need for dummy buildings:

Primarily right now I'm working with a script where dummy buildings handled within it can be replaced by Boolean variables. (full explanation here) How exactly is that broken down?
nil - near as I can figure out, this means the dummy building doesn't exist at all?
true - this probably means it exists within a city meeting specified conditions?
false - and this means it doesn't?
Anyone have any insight on that?

If anyone also has the time and patience with me to help me turn several dummy buildings into as many Booleans as possible, drop me a line via PM.

Another workaround I'm thinking of:
How is this:
Spoiler :
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	pPlayer = Players[iPlayer]
		if (foo) then
			for pCity in pPlayer:Cities() do
				pCity:ChangeProduction(2)
			end
		end
	end
end)
Really any different from this?
Spoiler :
Code:
-----[ Lua Part ]-----

GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	pPlayer = Players[iPlayer]
		if (foo) then
			for pCity in pPlayer:Cities() do
				pCity:SetNumRealBuilding(GameInfoTypes.BUILDING_XTRA_YIELD, 1)
			end
		end
	end
end)

-----[ XML Part ]-----

<GameData>
	<Buildings>
		<!-- We'll just assume that
		     BUILDING_XTRA_YIELD already
		     exists and we can skip defining it
		-->
	</Buildings>
	<Building_YieldChanges>
		<Row>
			<BuildingType>BUILDING_XTRA_YIELD</BuildingType>
			<YieldType>YIELD_PRODUCTION</YieldType>
			<Yield>2</Yield>
		</Row>
	</Building_YieldChanges>
</GameData>
So straight lua should work for adding base yields? What else from the building table are we aware of that can be modified sort of similarly? <Building_YieldChangesPerPop>, maybe? Stuff like that?

Input is welcome; less dummy builds is more!
TIA,
AW
 
"+X% Production in the city" won't increase your 2 Production if you add it with the method City:ChangeProduction() as far as I know.
Another thing is that most of the time the use of dummy building is due to the intent of using existing columns in the <Buildings> table and subtables, so you keep the code clean while the effect is the same (K.I.S.S. principle).
 
Correct me if I'm wrong, but yields added via lua may not be affected by things that modify that yield by a %. In your example, the production would not be modified by a stable, for instance, in the case of producing a mounted unit.

Or perhaps I am wrong about how % modifications work.

It would also depend upon the intent of the proposed yield addition... is it to modify base yield or to be added to modified yields, for example.

Another thing, if changes are done in Lua instead of a dummy building, the UI/information panels might need to be modified as well to show the changes. I presume the dummy buildings are accounted for in the regular interface generation process and the totals shown appropriately in the various information panels.
 
I'm presuming that some of these dummy buildings exist because you would like a trait to have some effect or other. What I've found out is how to tap into the policies format, creating a dummy policy that's attached to the trait. This is how I've done it:

Step one - create a .lua script to give the policy automatically. Please note that it doesn't matter about which policy branch you use here, as the policy won't be attached to a branch. I've adapted a script that JFD created, so it's something like this:

Code:
----------------------------------------------------------------------------------------------------------------------------
--InitZenobia
----------------------------------------------------------------------------------------------------------------------------
function InitZenobia(player)
	print("The Palmyran civilization cometh")
	for playerID, player in pairs(Players) do
		local player = Players[playerID];
		if player:GetCivilizationType() == GameInfoTypes["CIVILIZATION_PALMYRA"] then
			if not player:HasPolicy(GameInfoTypes["POLICY_QUEENZENOBIA"]) then
				player:SetPolicyBranchUnlocked(GameInfoTypes["POLICY_BRANCH_HONOR"], false)
				player:SetNumFreePolicies(1)
				player:SetNumFreePolicies(0)
				player:SetHasPolicy(GameInfoTypes["POLICY_QUEENZENOBIA"], true)	
			end
		end
	end 
end
Events.SequenceGameInitComplete.Add(InitZenobia)


Then, I've created a dummy policy without a branch - so it doesn't show in the civilopedia:

Code:
<GameData>
	<Policies>
			<Type>POLICY_QUEENZENOBIA</Type>
			<Description>TXT_KEY_POLICY_QUEENZENOBIA</Description>
			<Civilopedia>TXT_KEY_POLICY_QUEENZENOBIA_TEXT</Civilopedia>
			<Help>TXT_KEY_POLICY_QUEENZENOBIA_HELP</Help>
			<GridX>1000</GridX>
			<GridY>1000</GridY>
			<ExtraHappinessPerLuxury>2</ExtraHappinessPerLuxury>
			<PortraitIndex>47</PortraitIndex>
			<IconAtlas>POLICY_ATLAS</IconAtlas>
			<IconAtlasAchieved>POLICY_A_ATLAS</IconAtlasAchieved>
		</Row>
	</Policies>
	<Language_en_US>
		<Row Tag="TXT_KEY_POLICY_QUEENZENOBIA">
			<Text>Palmyra Hadriana</Text>
		</Row>
		<Row Tag="TXT_KEY_POLICY_QUEENZENOBIA_HELP">
			<Text>+2 [ICON_HAPPINESS_1] happiness from all luxuries.</Text>
		</Row>
		<Row Tag="TXT_KEY_POLICY_QUEENZENOBIA_TEXT">
			<Text>The Palmyra Hadriana policy forms part of the Palmyran UA</Text>
		</Row>
	</Language_en_US>
</GameData>

Whilst I've opted for the +2 happiness from all luxuries here, which is an exact match for a policy, as long as I match the right format for policies, I could have made it unique.

That's it! All you need to do now is create the trait in the normal manner, i.e.
Code:
		<Row>
			<Type>TRAIT_PALMYRA_HADRIANA</Type>
			<Description>TXT_KEY_TRAIT_PALMYRA_HADRIANA</Description>
			<ShortDescription>TXT_KEY_TRAIT_PALMYRA_HADRIANA_SHORT</ShortDescription>
		</Row>

Hopefully, this should prevent a couple of dummy buildings. In the scenario you mentioned in the first post, your policy in this instance could include this:
Code:
<Policy_CityYieldChanges>
		<Row>
			<PolicyType>POLICY_YOURPOLICYNAME</PolicyType>
			<YieldType>YIELD_PRODUCTION</YieldType>
			<Yield>2</Yield>
		</Row>
<Policy_CityYieldChanges>
 
By my calculations, using policies could eliminate 3 of my current dummy buildings. :) It would be even more if there was such a table as <Policy_CityYieldModifiers> for G&K, but there isn't as far as I know... :(

To that point, is it possible to make the effects of a policy only take effect in certain cities? For example, take the Zapotecs - their extra 20% science is only given to the first three cities (let's just assume Policy_CityYieldModifiers exists for the sake of the argument), and the Harappans' modifiers are only given to river cities. Is there some kind of lua trickery to accomplish that, or are policy effects delegated to the whole civ no matter what?

Anyways, thanks for the tip for using policies. I'd like to try and manage Taiwan's UA (After researching Electronics, all cities with at least 10 citizens receive +2 production and +1 gold per citizen) without a dummy building, which would probably be something like this:
Code:
GameEvents.PlayerDoTurn.Add(
function(iPlayer)
	pPlayer = Players[iPlayer]
	if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_TAIWAN) and (Teams[pPlayer:GetTeam()]:IsHasTech(GameInfoTypes.TECH_ELECTRONICS()) then
		for pCity in pPlayer:Cities() do
			pCityPop = pCity:GetPopulation()
			pCity:ChangeProduction(pCityPop*2)
			pCity:ChangeGold(pCityPop)
		end
	else
		return;
	end
end)
Unfortunately, I don't think this can be controlled using policies since while there is TechPrereq column for policies, there doesn't seem to be a PopulationPrereq (another thing where having policies only work in certain cities would help). And then there's always the questionability of whether or not yield modifiers actually work here, but I guess only a DLL modder can really settle that...
 
To that point, is it possible to make the effects of a policy only take effect in certain cities?
I'm not that good! I'm sorry but I don't know. With respect to the question about population, there isn't anything AFAIK about gold or production, but there are a couple of handy ones for the record:
<HappinessPerXPopulation>
<NewCityExtraPopulation>

There are some that have tables, but are unused in the main game. Again, this is for the record and doesn't directly answer your question:
<OccupiedPopulationUnhappinessMod>
<FreeUnitsPopulationPercent>
<FreeMilitaryUnitsPopulationPercent>
 
Top Bottom