How to add happiness to Technology?

chauism

Warlord
Joined
Mar 15, 2006
Messages
225
Location
Earth
I want to modify the future tech that so everytime when it is researched, it will add +2happiness to the empire. Since it is not in the xml, there is something has to be done in lua, does anyone know what to do there?
 
I've already done that in my own mod (the Crazy Spatz mod, in the main customization forum) using Lua. Except I only made it +1 happiness per tech, and it triggers on any repeatable tech. I'll paste the logic here tonight when I get home, since I don't remember offhand the exact syntax I used. (Or you can download my mod; the code for this will be in SpatzStartTurn.lua, I think.)

The only headache is UI-related; it deducts the Happiness from the difficulty level bonus in the top panel. But I'm working on adding a new line for "Other".
 
I've already done that in my own mod (the Crazy Spatz mod, in the main customization forum) using Lua. Except I only made it +1 happiness per tech, and it triggers on any repeatable tech. I'll paste the logic here tonight when I get home, since I don't remember offhand the exact syntax I used. (Or you can download my mod; the code for this will be in SpatzStartTurn.lua, I think.)

The only headache is UI-related; it deducts the Happiness from the difficulty level bonus in the top panel. But I'm working on adding a new line for "Other".

Thanks for the help, but somehow I can not find the spatzstartturn.lua in your mod. Anyways, it will be great if you can post the code, so I can understand how it is done.
 
Thanks for the help, but somehow I can not find the spatzstartturn.lua in your mod. Anyways, it will be great if you can post the code, so I can understand how it is done.

To be clear, there are two mods in that thread: the Crazy Spatz Balance Mod, and the Spatz' Mod of Alpha Centauri. If it's in the Balance mod then there should only be one Lua file there to begin with (in the Lua directory) and it'll have some other name. If it's in the AC mod, then it'll be in Lua/SpatzStartTurn.lua. I just can't remember which one it's in at the moment, as I've been migrating content from one to the other. Inconvenient, I know.

It'll be a few hours until I get home, but I'll put it here then if you can't find it. It's really not too complex of a system, I just don't remember the Lua functions offhand; the only thing to keep in mind is that the Lua "ChangeHappinessFromBuildings" function just doesn't work, so you have to use the Get/Set pairing. And certain events (building a new +happy building this turn, for instance) will reset the Happiness until the end of the turn and undo your change, but it'll correct itself on the next turn.

There's actually a similar bit of logic in SpatzWonders.lua in the AC mod, because I added a wonder (the Dream Twister) that subtracts happiness from all OTHER civs each turn. But I'm guessing you're more interested in how it ties to the tech than how it subtracts the happiness.
 
Okay, here's the code. It'll find whichever tech has the Repeat tag. (If there's more than one, then right now it only keys on the one with the highest ID number.) They key is the TeamTech:GetTechCount() function, which tells how many times your civ had researched a given tech.

Code:
	endTech = 0;
	for tech in GameInfo.Technologies() do
		if( tech.Repeat ) then
			endTech = tech.ID;
		end
	end
	for index,pPlayer in pairs (Players) do
		if( pPlayer ~= nil and pPlayer:IsAlive() and not (pPlayer:IsBarbarian()) ) then
			pTnum = pPlayer:GetTeam();
			pTeam = Teams[pTnum];
			teamtech = pTeam:GetTeamTechs();
			repCount = teamtech:GetTechCount(endTech);
--			print( "  Repeated tech count: ",pPlayer:GetName(),repCount)
			if ( repCount > 0 ) then
				local pHappy = pPlayer:GetHappiness();
				pPlayer:SetHappiness(pHappy + repCount);
			end
		end
	end
 
Top Bottom