Dynamically adding any amount of tourism

UltimatePotato

Chieftain
Joined
Jul 6, 2014
Messages
24
Location
United Kingdom
Turns out it is possible to do after all :wavey:

[make_dummies.lua]
Spoiler :
Code:
local sCitizen = GameInfo.Specialists.SPECIALIST_CITIZEN.ID;
local bDummy = GameInfoTypes.BUILDING_DUMMY_UNEMPLOYED;
local bDummy1 = GameInfoTypes.BUILDING_DUMMY_TOURISM_1;
local bDummy2 = GameInfoTypes.BUILDING_DUMMY_TOURISM_2;
local bDummy4 = GameInfoTypes.BUILDING_DUMMY_TOURISM_4;
local bDummy8 = GameInfoTypes.BUILDING_DUMMY_TOURISM_8;
local bDummy16 = GameInfoTypes.BUILDING_DUMMY_TOURISM_16;
local bDummy32 = GameInfoTypes.BUILDING_DUMMY_TOURISM_32;
local bDummy64 = GameInfoTypes.BUILDING_DUMMY_TOURISM_64;
local bDummy128 = GameInfoTypes.BUILDING_DUMMY_TOURISM_128;



function toBits(num)
    -- returns a table of bits, least significant first.
	t={} -- will contain the bits
    while num>0 do
        local rest=math.fmod(num,2)
        t[#t+1]=rest
        num=(num-rest)/2
    end
    return t
end



--Define DummyFromUnemployed function
function DummyFromUnemployed(iPlayer, pPlayer)
	local pPlayer = Players[iPlayer];
	if (pPlayer:IsAlive()) then
		if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_YOURCIV) then --or whatever your trigger is
			for pCity in pPlayer:Cities() do
				--local cCitizen = pCity:GetSpecialistCount(sCitizen);
				local num = pCity:GetSpecialistCount(sCitizen);
				toBits(num)
				pCity:SetNumRealBuilding(bDummy, num);
				pCity:SetNumRealBuilding(bDummy1, t[1]);
				pCity:SetNumRealBuilding(bDummy2, t[2]);
				pCity:SetNumRealBuilding(bDummy4, t[3]);
				pCity:SetNumRealBuilding(bDummy8, t[4]);
				pCity:SetNumRealBuilding(bDummy16, t[5]);
				pCity:SetNumRealBuilding(bDummy32, t[6]);
				pCity:SetNumRealBuilding(bDummy64, t[7]);
				pCity:SetNumRealBuilding(bDummy128, t[8]);				
			end
		end
	end
end


function DummyFromUnemployedTurnStart(iPlayer, pPlayer)
	--print ("Turn Trigger")
	local pPlayer = Players[iPlayer]
	local bIsTurnStart = true
	DummyFromUnemployed(iPlayer, pPlayer)
end

function DummyFromUnemployedDirty()
	local iPlayer = Game.GetActivePlayer()
	local pPlayer = Players[iPlayer]
	if pPlayer:IsTurnActive() then
		--print ("Swap Trigger")
		local bIsTurnStart = false
		DummyFromUnemployed(iPlayer, pPlayer)
	end
end

GameEvents.PlayerDoTurn.Add(DummyFromUnemployedTurnStart)
Events.SerialEventCityInfoDirty.Add(DummyFromUnemployedDirty)
[dummies.xml]
Spoiler :
Code:
<GameData>
	<Buildings>
		<Row>
			<Type>BUILDING_DUMMY_TOURISM_1</Type>
			<BuildingClass>BUILDINGCLASS_DUMMY_TOURISM_1</BuildingClass>
			<TechEnhancedTourism>1</TechEnhancedTourism>
			<!--These four make it invisible -1, -1, -1 and NULL respectively-->
			<GreatWorkCount>-1</GreatWorkCount>
			<FaithCost>-1</FaithCost>
			<Cost>-1</Cost>
			<PrereqTech>NULL</PrereqTech>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_1</Description>
			<Civilopedia>BUILDINGCLASS_DUMMY_TOURISM_TEXT1</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_DUMMY_TOURISM_STRATEGY_1</Strategy>
			<Help>TXT_KEY_BUILDING_DUMMY_TOURISM_HELP_1</Help>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<HurryCostModifier>0</HurryCostModifier>
			<IconAtlas>CITIZEN_ATLAS</IconAtlas>
			<PortraitIndex>5</PortraitIndex>
		</Row>
		<Row>
			<Type>BUILDING_DUMMY_TOURISM_2</Type>
			<BuildingClass>BUILDINGCLASS_DUMMY_TOURISM_2</BuildingClass>
			<TechEnhancedTourism>2</TechEnhancedTourism>
			<!--These four make it invisible -1, -1, -1 and NULL respectively-->
			<GreatWorkCount>-1</GreatWorkCount>
			<FaithCost>-1</FaithCost>
			<Cost>-1</Cost>
			<PrereqTech>NULL</PrereqTech>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_2</Description>
			<Civilopedia>BUILDINGCLASS_DUMMY_TOURISM_TEXT2</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_DUMMY_TOURISM_STRATEGY_2</Strategy>
			<Help>TXT_KEY_BUILDING_DUMMY_TOURISM_HELP_2</Help>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<HurryCostModifier>0</HurryCostModifier>
			<IconAtlas>CITIZEN_ATLAS</IconAtlas>
			<PortraitIndex>5</PortraitIndex>
		</Row>
		<Row>
			<Type>BUILDING_DUMMY_TOURISM_4</Type>
			<BuildingClass>BUILDINGCLASS_DUMMY_TOURISM_4</BuildingClass>
			<TechEnhancedTourism>4</TechEnhancedTourism>
			<!--These four make it invisible -1, -1, -1 and NULL respectively-->
			<GreatWorkCount>-1</GreatWorkCount>
			<FaithCost>-1</FaithCost>
			<Cost>-1</Cost>
			<PrereqTech>NULL</PrereqTech>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_4</Description>
			<Civilopedia>BUILDINGCLASS_DUMMY_TOURISM_TEXT4</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_DUMMY_TOURISM_STRATEGY_4</Strategy>
			<Help>TXT_KEY_BUILDING_DUMMY_TOURISM_HELP_4</Help>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<HurryCostModifier>0</HurryCostModifier>
			<IconAtlas>CITIZEN_ATLAS</IconAtlas>
			<PortraitIndex>5</PortraitIndex>
		</Row>
		<Row>
			<Type>BUILDING_DUMMY_TOURISM_8</Type>
			<BuildingClass>BUILDINGCLASS_DUMMY_TOURISM_8</BuildingClass>
			<TechEnhancedTourism>8</TechEnhancedTourism>
			<!--These four make it invisible -1, -1, -1 and NULL respectively-->
			<GreatWorkCount>-1</GreatWorkCount>
			<FaithCost>-1</FaithCost>
			<Cost>-1</Cost>
			<PrereqTech>NULL</PrereqTech>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_8</Description>
			<Civilopedia>BUILDINGCLASS_DUMMY_TOURISM_TEXT8</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_DUMMY_TOURISM_STRATEGY_8</Strategy>
			<Help>TXT_KEY_BUILDING_DUMMY_TOURISM_HELP_8</Help>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<HurryCostModifier>0</HurryCostModifier>
			<IconAtlas>CITIZEN_ATLAS</IconAtlas>
			<PortraitIndex>5</PortraitIndex>
		</Row>
		<Row>
			<Type>BUILDING_DUMMY_TOURISM_16</Type>
			<BuildingClass>BUILDINGCLASS_DUMMY_TOURISM_16</BuildingClass>
			<TechEnhancedTourism>16</TechEnhancedTourism>
			<!--These four make it invisible -1, -1, -1 and NULL respectively-->
			<GreatWorkCount>-1</GreatWorkCount>
			<FaithCost>-1</FaithCost>
			<Cost>-1</Cost>
			<PrereqTech>NULL</PrereqTech>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_16</Description>
			<Civilopedia>BUILDINGCLASS_DUMMY_TOURISM_TEXT16</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_DUMMY_TOURISM_STRATEGY_16</Strategy>
			<Help>TXT_KEY_BUILDING_DUMMY_TOURISM_HELP_16</Help>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<HurryCostModifier>0</HurryCostModifier>
			<IconAtlas>CITIZEN_ATLAS</IconAtlas>
			<PortraitIndex>5</PortraitIndex>
		</Row>
		<Row>
			<Type>BUILDING_DUMMY_TOURISM_32</Type>
			<BuildingClass>BUILDINGCLASS_DUMMY_TOURISM_32</BuildingClass>
			<TechEnhancedTourism>32</TechEnhancedTourism>
			<!--These four make it invisible -1, -1, -1 and NULL respectively-->
			<GreatWorkCount>-1</GreatWorkCount>
			<FaithCost>-1</FaithCost>
			<Cost>-1</Cost>
			<PrereqTech>NULL</PrereqTech>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_32</Description>
			<Civilopedia>BUILDINGCLASS_DUMMY_TOURISM_TEXT32</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_DUMMY_TOURISM_STRATEGY_32</Strategy>
			<Help>TXT_KEY_BUILDING_DUMMY_TOURISM_HELP_32</Help>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<HurryCostModifier>0</HurryCostModifier>
			<IconAtlas>CITIZEN_ATLAS</IconAtlas>
			<PortraitIndex>5</PortraitIndex>
		</Row>
		<Row>
			<Type>BUILDING_DUMMY_TOURISM_64</Type>
			<BuildingClass>BUILDINGCLASS_DUMMY_TOURISM_64</BuildingClass>
			<TechEnhancedTourism>64</TechEnhancedTourism>
			<!--These four make it invisible -1, -1, -1 and NULL respectively-->
			<GreatWorkCount>-1</GreatWorkCount>
			<FaithCost>-1</FaithCost>
			<Cost>-1</Cost>
			<PrereqTech>NULL</PrereqTech>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_64</Description>
			<Civilopedia>BUILDINGCLASS_DUMMY_TOURISM_TEXT64</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_DUMMY_TOURISM_STRATEGY_64</Strategy>
			<Help>TXT_KEY_BUILDING_DUMMY_TOURISM_HELP_64</Help>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<HurryCostModifier>0</HurryCostModifier>
			<IconAtlas>CITIZEN_ATLAS</IconAtlas>
			<PortraitIndex>5</PortraitIndex>
		</Row>
		<Row>
			<Type>BUILDING_DUMMY_TOURISM_128</Type>
			<BuildingClass>BUILDINGCLASS_DUMMY_TOURISM_128</BuildingClass>
			<TechEnhancedTourism>128</TechEnhancedTourism>
			<!--These four make it invisible -1, -1, -1 and NULL respectively-->
			<GreatWorkCount>-1</GreatWorkCount>
			<FaithCost>-1</FaithCost>
			<Cost>-1</Cost>
			<PrereqTech>NULL</PrereqTech>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_128</Description>
			<Civilopedia>BUILDINGCLASS_DUMMY_TOURISM_TEXT128</Civilopedia>
			<Strategy>TXT_KEY_BUILDING_DUMMY_TOURISM_STRATEGY_128</Strategy>
			<Help>TXT_KEY_BUILDING_DUMMY_TOURISM_HELP_128</Help>
			<MinAreaSize>-1</MinAreaSize>
			<NeverCapture>true</NeverCapture>
			<HurryCostModifier>0</HurryCostModifier>
			<IconAtlas>CITIZEN_ATLAS</IconAtlas>
			<PortraitIndex>5</PortraitIndex>
		</Row>

	</Buildings>
</GameData>
[dummyclass.xml]
Spoiler :
Code:
<GameData>
	<BuildingClasses>
		<Row>
			<Type>BUILDINGCLASS_DUMMY_TOURISM_1</Type>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_1</Description>
			<NoLimit>true</NoLimit> --I know the nolimit isn't necessary but I keep it in anyway
		</Row>
		<Row>
			<Type>BUILDINGCLASS_DUMMY_TOURISM_2</Type>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_2</Description>
			<NoLimit>true</NoLimit>
		</Row>
		<Row>
			<Type>BUILDINGCLASS_DUMMY_TOURISM_4</Type>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_4</Description>
			<NoLimit>true</NoLimit>
		</Row>
		<Row>
			<Type>BUILDINGCLASS_DUMMY_TOURISM_8</Type>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_8</Description>
			<NoLimit>true</NoLimit>
		</Row>
		<Row>
			<Type>BUILDINGCLASS_DUMMY_TOURISM_16</Type>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_16</Description>
			<NoLimit>true</NoLimit>
		</Row>
		<Row>
			<Type>BUILDINGCLASS_DUMMY_TOURISM_32</Type>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_32</Description>
			<NoLimit>true</NoLimit>
		</Row>
		<Row>
			<Type>BUILDINGCLASS_DUMMY_TOURISM_64</Type>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_64</Description>
			<NoLimit>true</NoLimit>
		</Row>
		<Row>
			<Type>BUILDINGCLASS_DUMMY_TOURISM_128</Type>
			<Description>TXT_KEY_BUILDING_DUMMY_TOURISM_128</Description>
			<NoLimit>true</NoLimit>
		</Row>

	</BuildingClasses>
</GameData>

This is a little script I managed to put together that gives +1:tourism: per unemployed citizen. The principle is, if you have 1 unemployed citizen, it spawns one building with +1 tourism. If you have 7 unemployed citizens, it spawns one building with +1 tourism, one building with +2 and one with +4. If you have 20 unemployed citizens it spawns one building with +4, and one with +16, and so on. It currently goes up to a maximum of +255:tourism: per city. Completely unnecessary, I know, but 9 unique buildings form a nice square that looks better in the civilopedia. It can easily be modified to do whatever you want.

Unfortunately the following must be done for any building to add tourism:

[replace unique]
Spoiler :
Code:
	<Civilization_BuildingClassOverrides>
		<Row><!--Override a building with itself. It will make the dummies visible, but it's the only way to make tourism work-->
			<CivilizationType>CIVILIZATION_YOURCIV</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_DUMMY_TOURISM_1</BuildingClassType>
			<BuildingType>BUILDING_DUMMY_TOURISM_1</BuildingType>
		</Row>
		<Row>
			<CivilizationType>CIVILIZATION_YOURCIV</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_DUMMY_TOURISM_2</BuildingClassType>
			<BuildingType>BUILDING_DUMMY_TOURISM_2</BuildingType>
		</Row>
		<Row>
			<CivilizationType>CIVILIZATION_YOURCIV</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_DUMMY_TOURISM_4</BuildingClassType>
			<BuildingType>BUILDING_DUMMY_TOURISM_4</BuildingType>
		</Row>
		<Row>
			<CivilizationType>CIVILIZATION_YOURCIV</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_DUMMY_TOURISM_8</BuildingClassType>
			<BuildingType>BUILDING_DUMMY_TOURISM_8</BuildingType>
		</Row>
		<Row>
			<CivilizationType>CIVILIZATION_YOURCIV</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_DUMMY_TOURISM_16</BuildingClassType>
			<BuildingType>BUILDING_DUMMY_TOURISM_16</BuildingType>
		</Row>
		<Row>
			<CivilizationType>CIVILIZATION_YOURCIV</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_DUMMY_TOURISM_32</BuildingClassType>
			<BuildingType>BUILDING_DUMMY_TOURISM_32</BuildingType>
		</Row>
		<Row>
			<CivilizationType>CIVILIZATION_YOURCIV</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_DUMMY_TOURISM_64</BuildingClassType>
			<BuildingType>BUILDING_DUMMY_TOURISM_64</BuildingType>
		</Row>
		<Row>
			<CivilizationType>CIVILIZATION_YOURCIV</CivilizationType>
			<BuildingClassType>BUILDINGCLASS_DUMMY_TOURISM_128</BuildingClassType>
			<BuildingType>BUILDING_DUMMY_TOURISM_128</BuildingType>
		</Row>
	</Civilization_BuildingClassOverrides>


This operation must be done, or the buildings will not produce tourism. The tourism dummy will be invisible, except in your civilization's unique building civilopedia table. The non-tourism dummy will always be invisible though (BUILDING_DUMMY_UNEMPLOYED adds +1:c5food:, so unemployed citizens effectively consume half as much food).

So there you have it. I hope you find this helpful :)
 
Very intelligent! :goodjob:

As a workaround for the multiple buildings in the Leader Screen you could just keep them as default for their own unique class and add a 'PlayerCanConstruct' event negating any attempt to build it.
This way it would still be a dummy building capable of giving Tourism. :D
 
The real requirement for adding tourism via a building is not that the building is a unique, but rather that the building is the one from within the class to which the civilization is normally entitled. Making the dummy the default within the class cures this issue for all civilizations. Setting the <Cost> to -1 makes it unbuildable and unbuyable in the normal manner. You can also give yourself a little bit of extra insurance that the building will not be purchaseable simply by adding <HurryCostModifier>-1</HurryCostModifier> within the definition of the building, but I've never actually found this to be necessary whenever I've specified <Cost>-1</Cost>

[edit]
By 'normally entitled' I mean the building is the default within the class to which the civ in question is entitled or it is a unique within the class to which the civ is entitled by a <Civilization_BuildingClassOverrides>.

So you can add a Mughal Fort to a Roman city via lua or IGE or some other method, but doing so does not result in any Tourism from the Mughal Fort for Rome. But if you make a mod that allows Rome to build Mughal Forts instead of the normal Castle, the Tourism will work.

You could also make a mod that adds the same Tourism effects to the default Castle, and every civilization except India would get that Tourism from Castles. In this case, adding a regular Castle to an Indian city by lua or IGE would not have the Tourism effect.

You can also have both the default building within a class and a unique within the same class give tourism, but the tourism will only work for the default building for civs that are entitled to the default building, and the tourism for the unique building will only work for the civilzation that is entitled to the unique building.

BTW, UltimatePotatoe, so it doesn't seem like all I'm doing is picking nits, nice work-around for the issue where multiple copies of the same building within a city don't "stack" so far as dynamically adding tourism goes.
 
So wait, why are you overriding at all? Oh yeah, you're lacking the Default Building tag on the building classes, that will make the overriding unnecessary. Anyway I like the concept!, instead of adding 256 buildings you only add 8, its very clever.

EDIT:

Also, to enhance modularity so other people can use this, you could use <Replace> tags instead of <Row>, so there won't be Database duplicates if this is found in other mods.
 
Oh, and I forgot to mention that when using the override method on a hidden building you should check the civilopedia for the civilization before concluding that everything is working OK. I ran into a case where a hidden building (hidden by <GreatWorkCount>-1</GreatWorkCount>) resulted in a hash of that Civilization's civilopedia entry. So you should probably check for that, even though it is quite possible that I was doing something else wrong at the time.
 
Top Bottom