Help with Dummy Buildings and Database Woes

Civitar

Adventurer
Joined
Mar 23, 2014
Messages
1,507
Location
Switzerland
So, Colonialist Legacies' Australia update is supposed to come out tomorrow or later today and... it's not working.
The trouble is the UA, which should be the following:
Settlers found puppeted cities that generate +1 Tourism. +1 Tourism per outgoing sea trade route. Cities that generate +2 Tourism or more expand at double speed.
But, the new puppet cities are not getting their tourism. Here is the code for the entire UA, if anyone can spot the trouble I'd be very grateful.
Code:
--------------------
--Colonialist Legacies' Australia
--Boundless Plains To Share
--Civitar, Neirai, bane_
--------------------

print("Loaded CL_AustraliaBoundlessPlainsToShare.lua.");

local iAussieCiv = GameInfoTypes.CIVILIZATION_CL_AUSTRALIA;
local iAussiePuppetTourismBuilding = GameInfoTypes.BUILDING_CL_AUSTRALIA_PUPPET_TOURISM; --hidden building, gives +1 Tourism
local iAussieTradeTourismBuilding = GameInfoTypes.BUILDING_CL_AUSTRALIA_TRADE_TOURISM; --ditto


--Founded cities are puppets and generate +1 Tourism
function CL_AussieFoundPuppetCities(iPlayer, iCityX, iCityY)
	print("A city has been founded at " .. iCityX .. ", " .. iCityY .. ".");
	local pPlayer = Players[iPlayer];
	if pPlayer:IsAlive() and pPlayer:GetCivilizationType() == iAussieCiv then
		print("The city was founded by Australia!");
		local pPlot = Map.GetPlot(iCityX, iCityY);
		local pCity = pPlot:GetPlotCity();
		if not pCity:IsCapital() then
			print("The city is not Australia's capital! So...");
			pCity:SetPuppet(true);
			print("It is a puppet.");
			pCity:SetNumRealBuilding(iAussiePuppetTourismBuilding, 1);
			print("And it generates +1 Tourism.");
		end
	end
end

function CL_AussiePuppetCheck(iPlayer)
	print("Checking Australian cities for puppet status...");
	local pPlayer = Players[iPlayer];
	if pPlayer:IsAlive() and pPlayer:GetCivilizationType() == iAussieCiv then
		for pCity in pPlayer:Cities() do
			print("Found an Australian city! Is it a puppet?");
			if not pCity:IsPuppet() then
				print("It's not a puppet. So it shouldn't have a Tourism bonus from being a puppet.");
				pCity:SetNumRealBuilding(iAussiePuppetTourismBuilding, 0);
				print("It has no Tourism bonus from being a puppet.");
			end
		end
	end
end

--+1 Tourism per sea-based Trade Route
function CL_GetNumOutgoingSeaTradeRoutes(pPlayer, pCity)
	print("Checking the number of outgoing sea trade routes in this city...");
	local TradeRoutes = pPlayer:GetTradeRoutes();
	local iNumOutgoingSeaTradeRoutes = 0;
	for k, v in pairs(TradeRoutes) do
		if v.FromCity == pPlayer:GetCityByID(pCity) then
			if v.Domain == GameInfoTypes.DOMAIN_SEA then
				iNumOutgoingSeaTradeRoutes = iNumOutgoingSeaTradeRoutes + 1;
			end
		end
	end
	return iNumOutgoingSeaTradeRoutes;
end

function CL_AussieTourismFromSeaTrade(iPlayer)
	print("Checking Australian cities for potential trade benefits to Tourism...");
	local pPlayer = Players[iPlayer];
	if pPlayer:IsAlive() and pPlayer:GetCivilizationType() == iAussieCiv then
		for pCity in pPlayer:Cities() do
			local iNumOutgoingSeaTradeRoutes = CL_GetNumOutgoingSeaTradeRoutes(pPlayer, pCity);
			print("This city has " .. iNumOutgoingSeaTradeRoutes .. " outgoing sea trade routes.");
			if iNumOutgoingSeaTradeRoutes > 0 then
				pCity:SetNumRealBuilding(iAussieTradeTourismBuilding, iNumOutgoingSeaTradeRoutes);
				print("This city now gets +" .. iNumOutgoingSeaTradeRoutes .. " Tourism from outgoing sea trade routes.");
			end
		end
	end
end

--Cities with +2 Tourism expand 100% faster
function CL_AussieCityExpandWithTourism(iPlayer)
	print("Checking Australian cities for potential expansion benefits from tourism...");
	local pPlayer = Players[iPlayer];
	if pPlayer:IsAlive() and pPlayer:GetCivilizationType() == iAussieCiv then
		for pCity in pPlayer:Cities() do
			if pCity:GetBaseTourism() >= 2 then
				print("This city generates 2 or more Tourism per turn! It gets expansion bonuses.");
				local iCultureStored = pCity:GetJONSCultureStored();
				local iCityCultureOutput = pCity:GetJONSCulturePerTurn();
				pCity:SetJONSCultureStored(iCultureStored + iCityCultureOutput);
				print("City expansion rate doubled.");
			end
		end
	end
end

GameEvents.PlayerCityFounded.Add(CL_AussieFoundPuppetCities);
GameEvents.PlayerDoTurn.Add(CL_AussiePuppetCheck);
GameEvents.PlayerDoTurn.Add(CL_AussieTourismFromSeaTrade);
GameEvents.PlayerDoTurn.Add(CL_AussieCityExpandWithTourism);
The dummy buildings are defined like this:
Code:
/*-**************-*\
Colonialist Legacies' Australia
Buildings
Civitar
\*-**************-*/

INSERT INTO BuildingClasses (Type,											DefaultBuilding,						NoLimit) VALUES
							('BUILDINGCLASS_CL_AUSTRALIA_PUPPET_TOURISM',	'BUILDING_CL_AUSTRALIA_PUPPET_TOURISM',	1),
							('BUILDINGCLASS_CL_AUSTRALIA_TRADE_TOURISM',	'BUILDING_CL_AUSTRALIA_TRADE_TOURISM',	1),
							('BUILDINGCLASS_CL_AUSTRALIA_PM_TOURISM',		'BUILDING_CL_AUSTRALIA_PM_TOURISM',		1);
INSERT INTO Buildings (Type,									BuildingClass,									Cost,	GreatWorkCount,	TechEnhancedTourism,	EnhancedYieldTech,	NeverCapture,	ShowInPedia) VALUES
					  ('BUILDING_CL_AUSTRALIA_PUPPET_TOURISM',	'BUILDINGCLASS_CL_AUSTRALIA_PUPPET_TOURISM',	-1,		-1,				1,						'TECH_AGRICULTURE',	1,				0),
					  ('BUILDING_CL_AUSTRALIA_TRADE_TOURISM',	'BUILDINGCLASS_CL_AUSTRALIA_TRADE_TOURISM',		-1,		-1,				1,						'TECH_AGRICULTURE',	1,				0),
					  ('BUILDING_CL_AUSTRALIA_PM_TOURISM',	'BUILDINGCLASS_CL_AUSTRALIA_PM_TOURISM',		-1,		-1,				1,						'TECH_AGRICULTURE',	1,				0);
And if it matters to anyone, there is a file that defines three new columns also in the mod (though it often crashes the mod, for some reason):
Code:
/*-**************-*\
Colonialist Legacies' Australia
New Database Columns
Civitar
\*-**************-*/

ALTER TABLE UnitPromotions ADD COLUMN 'ShowInPedia' INTEGER DEFAULT 1;
ALTER TABLE UnitPromotions ADD COLUMN 'ShowInUnitPanel' INTEGER DEFAULT 1;
ALTER TABLE Buildings ADD COLUMN 'ShowInPedia' INTEGER DEFAULT 1;

I noticed when playtesting a while back that the founded puppet cities got a Floating Gardens, but I haven't noticed that since...
If anyone can resolve these issues as well as the frequent crashes caused by the New Database Columns code, Henry Parkes thanks you.:)
 
I've found in more-recent experimentation that it is not necessary to add EnhancedYieldTech in order to get the tourism to work. If EnhancedYieldTech is left as the default value (NULL), the building will begin to generate tourism as soon as it is created.

But in my opinion you need to:

  1. Ditch the ShowInPedia attempt for the buildings.
  2. Add a <Description> reference in BuildingClasses and Buildings, with the proper definition of the tag in Language_en_US.
  3. Add a portrait index and icon atlas (I generally use the Palace info)
  4. Set PrereqTech to NULL.
I generally also set the following, though I have not confirmed that these are necessary:
Code:
<ArtDefineTag>NONE</ArtDefineTag>
<MinAreaSize>-1</MinAreaSize>
<FaithCost>-1</FaithCost>
For the FaithCost I've never taken the time to confirm whether or not Irkalla was correct in thinking it was necessary.

This won't work:
Code:
pCity:SetNumRealBuilding(iAussieTradeTourismBuilding, iNumOutgoingSeaTradeRoutes);
The game will not allow you to 'stack' multiple copies of the same building within a city to get additional tourism. It will only apply the tourism for the 1st copy of the building within a city, and will ignore the presence of additional copies so far as tourism is concerned. Adding NoLimit in the buildingclass has no effect on this game-behavior.

I also don't see where BUILDING_CL_AUSTRALIA_PM_TOURISM is being used anywhere in your code.

I haven't spoken to anything in the Unit Promotions because I don't feel confident of my 'ground'.

[edit]
Floating Gardens is the building with ID# 0. Getting Floating Gardens as a reuslt of an lua function running is an indication that the desired building has failed to load properly into the SQL/XML, so attempts to do SetNumRealBuilding(x, i) are reverting to the default ID # within Buildings, which happens to be Floating Gardens. I've seen this happen also with traits or what-have-you that are giving <FreeBuilding>.
 
@LeeS: Thanks for the response, but... I managed to get Neirai and Bane on Steam and we sorted everything out between ourselves. Neirai also showed me how to get around the tourism stacking problem.
Out of curiosity - do dummy buildings that you could end up having more than one of have to have a NoLimit entry in their BuildingClass definition?
 
@LeeS: Thanks for the response, but... I managed to get Neirai and Bane on Steam and we sorted everything out between ourselves. Neirai also showed me how to get around the tourism stacking problem.
Out of curiosity - do dummy buildings that you could end up having more than one of have to have a NoLimit entry in their BuildingClass definition?
I haven't tried that, but I'm assuming the game won't like it in one way or another.
 
Out of curiosity - do dummy buildings that you could end up having more than one of have to have a NoLimit entry in their BuildingClass definition?

I don't think the game crashes or anything, but I have a strong suspicion that the game won't count any extra copies of a building without NoLimit. In the past I've made the mistake of using dummy buildings without NoLimit, and then wondered why my yields weren't stacking properly. So if you make a dummy building that gives +1 Production, say, if it doesn't have NoLimit even if you put 10 copies in a city, you'll only get +1 Production (instead of +10).
 
My most recent tests support what JFD just said.
Specifically, I was testing all 4 available trade route gold yield columns, and forgot to set the BuildingClass to NoLimit. The affects of certain columns still stacked, although other columns refused to do so, but that's just Firaxis being Firaxis (inconsistent.)

I believe NoLimit should really only affect whether or not the game would allow you to build multiple copies manually, but Lua ignores all those restrictions to begin with. Still, it feels better for me personally to set NoLimit on those buildings which I need to have multiple of.
 
Back
Top Bottom