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)