Problems with SetNumRealBuildings

bouncymischa

Synthetic Genie
Joined
Nov 28, 2012
Messages
1,537
Location
In a bottle
Okay, for a civ I'm working on I've put together this Lua code:

Code:
-- Earn Happiness from spies.

local bHAPPY = GameInfoTypes.BUILDING_TH_TANUKI_PRANKS

GameEvents.PlayerDoTurn.Add(
function(iPlayer)
   local pPlayer = Players[iPlayer];
   if (pPlayer:IsAlive()) then
     if (pPlayer:GetCivilizationType() == GameInfoTypes.CIVILIZATION_TH_TANUKI) then
		 local pCity = pPlayer:GetCapitalCity();
		 local iNumSpies = pPlayer:GetNumSpies();
		 local iNumUnassignedSpies = pPlayer:GetNumUnassignedSpies();
		 local iActiveSpies = iNumSpies - iNumUnassignedSpies;

		 print("Num Spies: " .. iNumSpies)
		 print("Num Spies Unassigned: " .. iNumUnassignedSpies)
		 print("Num Spies Active: " .. iActiveSpies)

	     if (pCity:GetNumBuilding(bHAPPY) > 0) then
           pCity:SetNumRealBuilding(bHAPPY, 0);
		 end
		 if (iActiveSpies > 0) then
		   print("Spawning buildings: " .. iActiveSpies)
		   pCity:SetNumRealBuilding(bHAPPY, iActiveSpies);
		 end
	 end
   end
end)

However, when I start a game with 3 spies, the first one spawns the building fine... but then the others don't. According to my text strings, it should be spawning the proper number of buildings, but they don't seem to be spawning correctly. Each building generates 2 happiness, but while I get 2 happiness from the first, I only get 1 from the second, and 0 from the third.

I set the buildingclass <NoLimit>true</NoLimit>, so I don't think it's that.

Is there something in the DLL that affects the spawning of buildings?

EDIT: Apparently, this may be related to the Happiness effect. I tried having each building generate 1 Gold, and got the appropriate numbers for the number of buildings. So apparently Civ doesn't like getting happiness from multiple copies of the same building?
 
Is the happiness global or local? If you were testing in a low pop city it could have been the happiness was working fine, it was just being reduced since it couldn't exceed the population of the city.
 
Is the happiness global or local? If you were testing in a low pop city it could have been the happiness was working fine, it was just being reduced since it couldn't exceed the population of the city.

... Huh, I hadn't thought of that. Given that the Happiness is coming from a building, I suspect it's local, like the Colosseum and its kind... which would be why my happiness kept capping out at the total population of the city (3), no matter how high I made it.

Looking at Notre Dame, it uses <UnmoddedHappiness>10</UnmoddedHappiness>, so I'll give that a shot.
 
Aaaaaand that works. Now I feel stupid. X3

Thanks for the help, Machiavelli. I do find it amusing that it was Machiavelli who taught me about happiness. :p
 
Top Bottom