Any help with the tech diffusion situation?
trying something, will post the result after the test.
Anything yet?
-- Tech Diffusion
-- Author: Afforess, modified by Erendir, adapted to G+K/HSD/AH by Gedemon
-- DateCreated: 10/8/2010 8:52:20 PM
--------------------------------------------------------------
iTechsBehindReq = 4;
iTechsBehindFullBenefit = 12;
iHasMetBonus = 0.25; -- Bonus for having met the civ
iIsAtwarMalus = -0.75; -- Malus for being at war
iDenouncedMalus = -0.50; -- Malus for being denounced (but denouncing does not give malus)
iEmbassyBonus = 0.50; -- Bonus for having an Embassy
iOpenBorderBonus = 0.75; -- Bonus for open border
iFriendBonus = 0.50; -- Bonus for being friend
iDefPactBonus = 0.25; -- Bonus for having a defensive pact
iResearchBonus = 1.50; -- Bonus for having a research agreement
function TechDiffusion()
print("-------------------------------------")
print("Tech Diffusion...")
for iPlayerLoop = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
local pPlayer = Players[ iPlayerLoop ];
if pPlayer ~= nil and pPlayer:IsAlive() and pPlayer:GetNumCities() > 0 then
local pTeam = Teams[pPlayer:GetTeam()];
local pTeamTechs = pTeam:GetTeamTechs();
local iTechsBehindLead = numberOfTechsBehindLeadTeam(pTeam);
print()
print(string.format("Techs Behind Lead Team: %d", iTechsBehindLead));
if (iTechsBehindReq < iTechsBehindLead) then
local sum, num = 0, 0
for eTech in GameInfo.Technologies() do
if not pTeam:IsHasTech(eTech.ID) then
local knownExp = 0;
for iOtherTeam = 0, GameDefines.MAX_CIV_TEAMS-1, 1 do
pOtherTeam = Teams[iOtherTeam];
if(pOtherTeam ~= nil) and iOtherTeam ~= pTeam:GetID() and not Players[pOtherTeam:GetLeaderID()]:IsMinorCiv() then
if pOtherTeam:IsHasTech(eTech.ID) and pTeam:IsHasMet(iOtherTeam) then
local teamExp = iHasMetBonus;
if (pTeam:GetCurrentEra() < pOtherTeam:GetCurrentEra()) then
teamExp = teamExp + (pOtherTeam:GetCurrentEra() - pTeam:GetCurrentEra() / 2);
end
if pTeam:IsAtWar(iOtherTeam) then
teamExp = teamExp + iIsAtwarMalus;
end
if (pPlayer:IsDenouncedPlayer(pOtherTeam:GetLeaderID())) then
teamExp = teamExp + iDenouncedMalus;
end
if pTeam:HasEmbassyAtTeam(iOtherTeam) then
teamExp = teamExp + iEmbassyBonus;
end
if pTeam:IsAllowsOpenBordersToTeam(iOtherTeam) then
teamExp = teamExp + iOpenBorderBonus;
end
if (pPlayer:IsFriends(pOtherTeam:GetLeaderID())) then
teamExp = teamExp + iFriendBonus;
end
if (pTeam:IsDefensivePact(iOtherTeam)) then
teamExp = teamExp + iDefPactBonus;
end
if (pTeam:IsHasResearchAgreement(iOtherTeam)) then
teamExp = teamExp + iResearchBonus;
end
knownExp = knownExp + teamExp;
print(string.format("%g teamExp From %s", teamExp, Players[pOtherTeam:GetLeaderID()]:GetCivilizationShortDescription()));
--print(Players[pTeam:GetLeaderID()]:GetCivilizationShortDescription(),'<',Players[pOtherTeam:GetLeaderID()]:GetCivilizationShortDescription(),'teamExp='..teamExp,'EraDiff: '..pTeam:GetCurrentEra()..'-'..pOtherTeam:GetCurrentEra(),'IsAtWar:'..tostring(pTeam:IsAtWar(pOtherTeam:GetID())), 'IsAllowsOpenBorderToTeam:'..tostring(pTeam:IsAllowsOpenBordersToTeam(pOtherTeam:GetID())), 'IsDefensivePact:'..tostring(pTeam:IsDefensivePact(pOtherTeam:GetID())), 'pPlayer:', 'IsFriends:'..tostring(pPlayer:IsFriends(pOtherTeam:GetLeaderID())), 'IsDoF:'..tostring(pPlayer:IsDoF(pOtherTeam:GetLeaderID())) )
end
end
end
--print(string.format("Tech Numerator for %s: %d", eTech.Type, knownExp));
local iModifier = 100;
local techDiffMod = 50;
if (knownExp > 0.0) then
--print(string.format("Tech Numerator: %g", knownExp));
iModifier = iModifier + (techDiffMod - math.floor((techDiffMod * math.pow(0.85, knownExp) + 0.5)));
end
-- Tech flows downhill to those who are far behind
local iTechScorePercent = getBestKnownTechScorePercent(pTeam);
local iWelfareThreshold = 75;
local iWelfareModifier = 50;
if( iTechScorePercent < iWelfareThreshold ) then
if( knownExp > 0.0 ) then
iModifier = iModifier + (iWelfareModifier * Game:GetCurrentEra() * (iWelfareThreshold - iTechScorePercent))/200;
end
end
--Teams don't recieve full effect unless very far behind
if (iModifier > 100) then
--print(string.format("Tech Modifier for %s: %d", eTech.Type, iModifier));
iModifier = iModifier * math.pow(iTechsBehindLead / iTechsBehindFullBenefit, 0.45);
end
--print(string.format("Tech Modifier for %s: %d", eTech.Type, iModifier));
if (iModifier > 100) then
local iTechCost = pTeamTechs:GetResearchCost(eTech.ID);
local iFreeBeakers = ((iTechCost * iModifier) / 100) - iTechCost;
iFreeBeakers = math.pow(iFreeBeakers,0.40);
iFreeBeakers = math.floor(iFreeBeakers * 100);
print(string.format("Free Beakers for %s for %s: %d", Players[pTeam:GetLeaderID()]:GetCivilizationShortDescription(), eTech.Type, (iFreeBeakers / 100)));
sum = sum + iFreeBeakers; num = num + 1;
pTeamTechs:ChangeResearchProgressTimes100(eTech.ID, iFreeBeakers);
end
end
end
print(string.format("Free Beakers for %s: %d in %d tech(s)", Players[pTeam:GetLeaderID()]:GetCivilizationShortDescription(), sum/100, num ));
if iPlayerLoop == Game.GetActivePlayer() then
Events.GameplayAlertMessage(string.format("You get %d [ICON_RESEARCH] in %d tech(s) from other Civilizations", sum/100, num ))
end
end
end
end
print("-------------------------------------")
end
function getBestKnownTechScorePercent(pTeam)
local iOurTechScore = 0;
local iBestKnownTechScore = 0;
for iPlayerLoop = 0, GameDefines.MAX_MAJOR_CIVS-1, 1 do
local pPlayer = Players[ iPlayerLoop ];
if pPlayer ~= nil and pPlayer:IsAlive() and pPlayer:GetNumCities() > 0 and pPlayer.GetTechScore then
if Teams[pPlayer:GetTeam()]:GetID() == pTeam:GetID() then
iOurTechScore = math.max( iOurTechScore, pPlayer:GetTechScore() );
elseif (pTeam:IsHasMet(pPlayer:GetTeam())) then
iBestKnownTechScore = math.max( iBestKnownTechScore, pPlayer:GetTechScore() );
end
end
end
iBestKnownTechScore = math.max( iBestKnownTechScore, iOurTechScore );
return ((100*iOurTechScore)/math.max(iBestKnownTechScore, 1));
end
function numberOfTechsBehindLeadTeam(pTeam)
local pBestTeam = Teams[0];
local iBestTeamTechCount = 0;
for iTeamLoop = 0, GameDefines.MAX_CIV_TEAMS-1, 1 do
local pOtherTeam = Teams[iTeamLoop];
local pOtherTeamTechs = pOtherTeam:GetTeamTechs();
if(pOtherTeam ~= nil) and pOtherTeam:GetID() ~= pTeam:GetID() then
local iTechCount = 0;
for eTech in GameInfo.Technologies() do
if pOtherTeam:IsHasTech(eTech.ID) then
iTechCount = iTechCount + 1;
end
end
if (iTechCount > iBestTeamTechCount) then
pBestTeam = pOtherTeam;
iBestTeamTechCount = iTechCount;
end
end
end
local iTechCount = 0;
for eTech in GameInfo.Technologies() do
if pTeam:IsHasTech(eTech.ID) then
iTechCount = iTechCount + 1;
end
end
return iBestTeamTechCount - iTechCount;
end
Events.ActivePlayerTurnEnd.Add(TechDiffusion);
i wouldn't mind contributing what i can."Real Name Earth" is a mod I've followed since the start, I do want real city name, but the task is huge, I will request help here for the city list & position.
Yes, some of the spawn dates are really strange. I have already posted my ideas higher. You can post yours and then we can discuss them.