Code Request - Reducing Specific Technology Costs

TPangolin

Just the worst person
Joined
May 23, 2013
Messages
4,029
Location
Sydney, Australia
Hey guys, I'm looking to implement some code in an upcoming Sponsor that would have part of the trait give the player the following ability:

"Technologies that increase points towards Affinities are researched x% Faster"

Is anybody here willing to help out?
 
One thing you can do is award the players x% progress automatically to all of those technologies when they start the game. It's fairly easy to do and also you could future-proof it by iterating through all the entries of the <Technology_Affinities> table rather than hard coding it.

You can look at assets\Gameplay\Lua\PlotBonuses\TechProgressPlotBonus.lua to see an example of this. It governs the behavior for when an expedition uncovers progress for a tech you're not currently researching:
Code:
teamTechs:ChangeResearchProgressPercent(techID, ProgressPercent, player:GetID());

Alternatively, you can use a trait-building that gives the player +x% science bonus and control the building's existence with a function that check's the player's current research. You can call the function through Events.SerialEventGameDataDirty(). As an example, the tech panel in the upper-right hand side is updated with the function:

Code:
Events.SerialEventGameDataDirty.Add(OnTechPanelUpdated);

This method might be more representative of what you're trying to achieve (note disadvantage of this would be you don't get an accurate turn count for technologies while browsing the web, depending on what you're currently researching), but a little more computation intensive. It honestly would only be a drop in the well, in my opinion. Might need to put some logic in to make sure you don't get caught in a loop of listeners however. It's always dangerous to modify the game data on a GameDataDirty event.

Hope this helps. Honestly shouldn't be too difficult to code up.

edit: I had some time, so I figured I'd give it a shot.
Code:
--This function gets called approximately when the player immediately starts the game.
--It takes advantage of the capital being founded on the initial turn to allow setting up 
--the civ when a city exists. Certain things like spawning explorers and other units will
--occur after this method.
function LGF_InitialTurn(player, x, y)
	local pPlayer = Players[player]
	if pPlayer == nil then
		return
	end

	--civilisationID is the modded sponsor's ID declared elsewhere in the code
	if pPlayer:GetCivilizationType() == civilisationID then 
		local pCapital = pPlayer:GetCapitalCity()
		if pCapital == nil then
			return
		end

		if pCapital:GetX() == x and pCapital:GetY() == y then
			--Call functions you want called on the initial turn only
			LGF_AwardAffinityTechProgress(player)
		end
	end
end


--This function iterates through the table entries of Technology_Affinities
--and awards each technology in it a set percentage bonus of progress
function LGF_AwardAffinityTechProgress(player)
	local pPlayer = Players[player]
	local pTeam = Teams[pPlayer:GetTeam()]
	local teamTechs = pTeam:GetTeamTechs()
	local percent = 25 --Use your percentage value here
	for affinityTech in GameInfo.Technology_Affinities() do
		local techType = affinityTech.TechType
		local tech = GameInfo.Technologies[techType]
		teamTechs:ChangeResearchProgressPercent(tech.ID, percent, player);
	end
end

GameEvents.PlayerCityFounded.Add(LGF_InitialTurn)
 
Back
Top Bottom