[HELP] AIResearchPercentPerEra

Allinuse

Chieftain
Joined
Jan 7, 2018
Messages
37
I've been looking for a way to give the AI some research bonuses per era as for some reason setting production to standard while research is at marathon screws with AI teching after Medieval era.

I found a mod, Communitas AI and Tools that unfortunately was bugged for me and wouldn't work properly. There was however some code in there that seemed very interesting. It's AIResearchPercentPerEra. Just sticking it into vanilla handicapinfos won't work so I used agent ransack to search for AIResearchPercentPerEra and found it in the a few files. I am planning on using these files to make a new mod that just contains the AIResearchPercent + PerEra.

I'm thinking delete every file that doesn't have this in it.

Could someone have a look at these and see what I'm missing?

Handicapinfos
Spoiler :

<?xml version="1.0" encoding="utf-8"?>
<GameData>
<PostDefines>
<Update>
<Where Name="AI_HANDICAP" />
<Set Key="HANDICAP_AI_DEFAULT" />
</Update>
<Update>
<Where Name="MINOR_CIV_HANDICAP" />
<Set Key="HANDICAP_AI_DEFAULT" />
</Update>
</PostDefines>
<HandicapInfo_AIFreeTechs>
<Delete />
</HandicapInfo_AIFreeTechs>

<HandicapInfos>
<Update>
<Where Type="HANDICAP_SETTLER" />
<Set Description = "TXT_KEY_HANDICAP_SETTLER"
Help = "TXT_KEY_HANDICAP_SETTLER_HELP"
AIResearchPercent = "0"
AIResearchPercentPerEra = "0"
/>
</Update>

<Update>
<Where Type="HANDICAP_CHIEFTAIN" />
<Set Description = "TXT_KEY_HANDICAP_CHIEFTAIN"
Help = "TXT_KEY_HANDICAP_CHIEFTAIN_HELP"
AIResearchPercent = "0"
AIResearchPercentPerEra = "0"
/>
</Update>

<Update>
<Where Type="HANDICAP_WARLORD" />
<Set Description = "TXT_KEY_HANDICAP_WARLORD"
Help = "TXT_KEY_HANDICAP_WARLORD_HELP"
AIResearchPercent = "0"
AIResearchPercentPerEra = "5"
/>
</Update>

<Update>
<Where Type="HANDICAP_PRINCE" />
<Set Description = "TXT_KEY_HANDICAP_PRINCE"
Help = "TXT_KEY_HANDICAP_PRINCE_HELP"
AIResearchPercent = "2"
AIResearchPercentPerEra = "10"
/>
</Update>

<Update>
<Where Type="HANDICAP_KING" />
<Set Description = "TXT_KEY_HANDICAP_KING"
Help = "TXT_KEY_HANDICAP_KING_HELP"
AIResearchPercent = "4"
AIResearchPercentPerEra = "12"
/>
</Update>

<Update>
<Where Type="HANDICAP_EMPEROR" />
<Set Description = "TXT_KEY_HANDICAP_EMPEROR"
Help = "TXT_KEY_HANDICAP_EMPEROR_HELP"
AIResearchPercent = "5"
AIResearchPercentPerEra = "15"
/>
</Update>

<Update>
<Where Type="HANDICAP_IMMORTAL" />
<Set Description = "TXT_KEY_HANDICAP_IMMORTAL"
Help = "TXT_KEY_HANDICAP_IMMORTAL_HELP"
AIResearchPercent = "5"
AIResearchPercentPerEra = "20"
/>
</Update>

<Update>
<Where Type="HANDICAP_DEITY" />
<Set Description = "TXT_KEY_HANDICAP_DEITY"
Help = "TXT_KEY_HANDICAP_DEITY_HELP"
AIResearchPercent = "10"
AIResearchPercentPerEra = "25"
/>
</Update>

<Update>
<Where Type="HANDICAP_AI_DEFAULT" />
<Set Description = "TXT_KEY_HANDICAP_AI_DEFAULT"
Help = "TXT_KEY_HANDICAP_AI_DEFAULT_HELP"
AIResearchPercent = "0"
AIResearchPercentPerEra = "0"
ResearchPercent = "100"
/>
</Update>
</HandicapInfos>
</GameData>


Separate from above code? I notice there is no "Update" in this code.
Spoiler :

<?xml version="1.0" encoding="utf-8"?>
<GameData>
<Table name="HandicapInfos">
<Column name="AIResearchPercent" type="variant" default="0"/>
<Column name="AIResearchPercentPerEra" type="variant" default="0"/>
</Table>
</GameData>


On to the parts that I don't understand at all..
I just copied the function from the original mod.
events lua
Spoiler :

function AIPerTurnBonuses(player)
local capitalCity = player:GetCapitalCity()
if capitalCity == nil or player:IsMinorCiv() or player:IsHuman() then
return
end
log:Debug("%-25s %15s", "AIPerTurnBonuses", player:GetName())
local activePlayer = Players[Game.GetActivePlayer()]
local handicapInfo = Game.GetHandicapInfo()
local yieldStored = player:GetYieldStored(YieldTypes.YIELD_SCIENCE)
local yieldRate = player:GetYieldRate(YieldTypes.YIELD_SCIENCE)
local yieldMod = handicapInfo.AIResearchPercent/100
local yieldModPerEra = handicapInfo.AIResearchPercentPerEra/100 * Game.GetAverageHumanEra()
player:ChangeYieldStored(YieldTypes.YIELD_SCIENCE, Game.Round(yieldRate * (yieldMod + yieldModPerEra)))
--
log:Debug("Sci bonus for %-25s: %5s + %4s * (%4s + %-4s) = %5s (+%s)",
player:GetName(),
yieldStored,
yieldRate,
Game.Round(yieldMod, 2),
Game.Round(yieldModPerEra, 2),
player:GetYieldStored(YieldTypes.YIELD_SCIENCE),
Game.Round(yieldRate * (yieldMod + yieldModPerEra))
)
--]]
end


Same here, altertables.sql, not sure if the first part is necessary or if I only need the alter table part.
Spoiler :

--
-- Create Tables
--
CREATE TABLE IF NOT EXISTS
Trait_CityCaptureInstantYield (
TraitType text REFERENCES Traits(Type),
YieldType text REFERENCES Yields(Type),
Yield integer default 0,
YieldPerPop integer default 0,
YieldPerEra integer default 0,
YieldPerEraExponent integer default 0
);

--ALTER TABLE changes to CepHandicapInfos in CAT_Info.xml
ALTER TABLE HandicapInfos ADD AIResearchPercent variant default 0;
ALTER TABLE HandicapInfos ADD AIResearchPercentPerEra variant default 0;
UPDATE HandicapInfos SET AIResearchPercent = 0;
UPDATE HandicapInfos SET AIResearchPercentPerEra = 0;


This one might not be needed but I'm not sure, it has all references to percentperera commented out "--"
fixtables.lua
Spoiler :

function Game.GetWorldInfo()
return GameInfo.CepWorlds[Map.GetWorldSize()]
end
function Game.GetSpeedInfo()
return GameInfo.CepGameSpeeds[Game.GetGameSpeedType()]
end
function Game.GetHandicapInfo()
return GameInfo.CepHandicapInfos[Game.GetAverageHumanHandicap()]
end


Also has the following comment by the mod creator inside the file:
"VFS lua files set their GameInfo table before the program reads database tables used on the "modding game setup" screen.
We must therefore hardcode these data values in a Lua table.

Can copy the modded tables into another set of tables that hasn't been cached before the database has been modded."
 
Top Bottom