Changing Beakers

VFS: False
Requires an InGameUIAddin entry
thank you so much, now it works and i can properly debug the thing (strange that there are no ingame tools for that).

i was a bit perplexed by the InGameUiAddin because you have to type the name of the lua file manually; whereas, if you can simply select an xml via the drop down suggestions.
 
it works! (tested ingame)

Code:
function AffinityResearchDelay(iPlayer)
        local pPlayer = Players[iPlayer]
		local ipur = pPlayer:GetAffinityLevel(GameInfo.Affinity_Types["AFFINITY_TYPE_PURITY"].ID)
		local ihar = pPlayer:GetAffinityLevel(GameInfo.Affinity_Types["AFFINITY_TYPE_HARMONY"].ID)
		local isup = pPlayer:GetAffinityLevel(GameInfo.Affinity_Types["AFFINITY_TYPE_SUPREMACY"].ID)
		local techType = pPlayer:GetCurrentResearch()
		local sTechType = GameInfo.Technologies[techType].Type
		local pCity = pPlayer:GetCapitalCity()

		local sAffinityType = nil
		for row in GameInfo.Technology_Affinities{TechType = sTechType} do
			sAffinityType = row.AffinityType
		end

		if (sAffinityType) then
			local iOpposingAffinity = 0
			if (sAffinityType == "AFFINITY_TYPE_PURITY") then
				iOpposingAffinity = ihar + isup
			elseif (sAffinityType == "AFFINITY_TYPE_HARMONY") then
				iOpposingAffinity = ipur + isup
			elseif (sAffinityType == "AFFINITY_TYPE_SUPREMACY") then
				iOpposingAffinity = ipur + ihar
			end
			if (iOpposingAffinity > 0) then
				local iResearchPerTurn = pPlayer:GetScience()
				local Malus = 1 + 0.15*iOpposingAffinity
				local iResearchDelay = math.ceil((1/Malus - 1)*iResearchPerTurn)

				if pPlayer:IsHuman() then
					local sHead = "Affinities slow research!"
					local sText = "Science lowered by: " .. math.abs(iResearchDelay)
					pPlayer:AddNotification(NotificationTypes.NOTIFICATION_GENERIC, sText, sHead, pCity:GetX(), pCity:GetY())
				end
				local team = Teams[pPlayer:GetTeam()]
				local teamTechs = team:GetTeamTechs()
				teamTechs:ChangeResearchProgress(techType, iResearchDelay, pPlayer)
			end
		end	
end
GameEvents.PlayerDoTurn.Add(AffinityResearchDelay)

it is a bit annoying that the message comes every turn (but only when you are researching a tech that grants an affinity and you already have opposing affinity points). personally i would rather have a little tooltip somewhere, maybe an icon in the upper black row (where science, energy, strat. res. and so on are) that shows on tooltip the value by which the research progress is lowered.

in my test games i noticed that the game does not treat science as an integer, sometimes it would be off by 1 science due to rounding from some bonuses, e.g. from virtues. the value i give in the function should be integer like because i use math.ceil however (which the message varifies)
 
I was a bit perplexed by the InGameUiAddin because you have to type the name of the lua file manually; whereas, if you can simply select an xml via the drop down suggestions.

From post #3 of that thread ...

"Note: If adding an InGameUIAddin where there is only a .lua file (and no associated .xml file), do step 6 before step 3"
 
it is a bit annoying that the message comes every turn (but only when you are researching a tech that grants an affinity and you already have opposing affinity points)

Code:
[B]local lastPlayerTechs = {}[/B]

function AffinityResearchDelay(iPlayer)
  ...
  if (sAffinityType) then
    ...
    if (iOpposingAffinity > 0) then
      ...
      if (pPlayer:IsHuman() [B]and lastPlayerTechs[iPlayer] ~= techType)[/B] then
        [B]lastPlayerTechs[iPlayer] = techType[/B]

        local sHead = "Affinities slow research!"
        ...
      end
      ...
    end
  end  
end
 
again thank you for your help. i got another question though:

is there a more intuitive approach to this problem? currently i just delay the research progress, but this is neither shown in the science per turn, nor the beaker cost of the technology, hence the notification.

for example might it be a better approach to use something like:

Code:
city:ChangeBaseYieldRateFromMisc(YieldTypes.YIELD_SCIENCE, iResearchDelay)
and make sure it affects just one city. or does the game have a problem with giving negative science to the cities base yield? how about dummy policies or dummy buildings (similar to the building quests) would those work? the big upside would be that the research delay from affinities would then be reflected in the science per turn tooltip.

edit: i saw a civ5 mod and apparently negative science on buildings work (although i don't know if it has a custom dll), however it is affected by percentage changes, e.g. -10 science reduces to -12 science from a 20% science increase(!) modifier (in this case golden age). so i guess policies might work? there are industry virtues that increase yields, e.g. http://civilizationbeyondearth.gamepedia.com/Central_Planning gives +5 energy in the capital, but i guess this is modified by percentage bonuses too.
 
Back
Top Bottom