local P = {}
AI_ENG = P
-- #######################################
-- Static Production Variables overide
function P._LandRatio_Units_(minister)
local laLandRatioUnits = {
'garrison_brigade', -- Garrison
'infantry_brigade', -- Infantry
'motorized_brigade', -- Motorized
'mechanized_brigade', -- Mechanized
'armor_brigade|heavy_armor_brigade|super_heavy_armor_brigade', -- Armor
'militia_brigade', -- Militia
'cavalry_brigade'}; -- Cavalry
return laLandRatioUnits
end
-- #######################################
-- #######################################
-- Start of Trade Weights
function P.TradeWeights(voResourceData)
local laResouces = {
METAL = {
Buffer = 2,
BufferSaleCap = 5000},
ENERGY = {
Buffer = 2,
BufferSaleCap = 5000},
RARE_MATERIALS = {
Buffer = 2,
BufferSaleCap = 5000},
CRUDE_OIL = {
Buffer = 2,
BufferSaleCap = 10000},
FUEL = {
Buffer = 2,
BufferSaleCap = 10000}}
return laResouces
end
-- Tech weights
-- 1.0 = 100% the total needs to equal 1.0
function P.TechWeights(voTechnologyData)
local laTechWeights = {
0.15, -- landBasedWeight
0.10, -- landDoctrinesWeight
0.15, -- airBasedWeight
0.15, -- airDoctrinesWeight
0.14, -- navalBasedWeight
0.15, -- navalDoctrinesWeight
0.10, -- industrialWeight
0.03, -- secretWeaponsWeight
0.03}; -- otherWeight
return laTechWeights
end
-- Techs that are used in the main file to be ignored
-- techname|level (level must be 1-9 a 0 means ignore all levels
-- use as the first tech name the word "all" and it will cause the AI to ignore all the techs
function P.LandTechs(voTechnologyData)
local ignoreTech = {
{"cavalry_smallarms", 0},
{"cavalry_support", 0},
{"cavalry_guns", 0},
{"cavalry_at", 0}};
local preferTech = {};
return ignoreTech, preferTech
end
function P.LandDoctrinesTechs(voTechnologyData)
local ignoreTech = {};
local preferTech = {};
return ignoreTech, preferTech
end
function P.AirTechs(voTechnologyData)
local ignoreTech = {};
local preferTech = {};
return ignoreTech, preferTech
end
function P.AirDoctrineTechs(voTechnologyData)
local ignoreTech = {};
local preferTech = {};
return ignoreTech, preferTech
end
function P.NavalTechs(voTechnologyData)
local ignoreTech = {
{"battlecruiser_technology", 0},
{"battlecruiser_antiaircraft", 0},
{"battlecruiser_engine", 0},
{"battlecruiser_armour", 0}};
local preferTech = {};
return ignoreTech, preferTech
end
function P.NavalDoctrineTechs(voTechnologyData)
local ignoreTech = {};
local preferTech = {};
return ignoreTech, preferTech
end
function P.IndustrialTechs(voTechnologyData)
local ignoreTech = {};
local preferTech = {};
return ignoreTech, preferTech
end
function P.SecretWeaponTechs(voTechnologyData)
local ignoreTech = {};
local preferTech = {};
return ignoreTech, preferTech
end
function P.OtherTechs(voTechnologyData)
local ignoreTech = {};
local preferTech = {
"supply_transportation",
"supply_organisation",
"civil_defence"};
return ignoreTech, preferTech
end
-- END OF TECH RESEARCH OVERIDES
-- #######################################
-- #######################################
-- Production Overides the main LUA with country specific ones
-- Production Weights
-- 1.0 = 100% the total needs to equal 1.0
function P.ProductionWeights(voProductionData)
-- Default Ratio when no conditions are met
local laArray = {
0.40, -- Land
0.20, -- Air
0.40, -- Sea
0.00}; -- Other
-- Check to see if manpower is to low
-- More than 900 brigades so build stuff that does not use manpower
if (voProductionData.ManpowerTotal < 300 or voProductionData.LandCountTotal > 500) then
laArray = {
0.00, -- Land
0.45, -- Air
0.45, -- Sea
0.10}; -- Other
elseif voProductionData.IsAtWar then
local gerTag = CCountryDataBase.GetTag('GER')
local lbControlBerlin = (CCurrentGameState.GetProvince(1861):GetController() == gerTag)
local lbGerEngWar = voProductionData.ministerCountry:GetRelation(gerTag):HasWar()
local lbGerEngAlly = voProductionData.ministerCountry:GetRelation(gerTag):HasAlliance()
local japTag = CCountryDataBase.GetTag('JAP')
local lbControlTokyo = (CCurrentGameState.GetProvince(5315):GetController() == japTag)
local lbJapEngWar = voProductionData.ministerCountry:GetRelation(japTag):HasWar()
if lbGerEngAlly then
laArray = {
0.30, -- Land
0.30, -- Air
0.40, -- Sea
0.00}; -- Other
elseif lbJapEngWar and lbControlTokyo then
laArray = {
0.30, -- Land
0.20, -- Air
0.50, -- Sea
0.00}; -- Other
elseif lbGerEngWar and lbControlBerlin then
laArray = {
0.40, -- Land
0.20, -- Air
0.40, -- Sea
0.00}; -- Other
end
end
return laArray
end
-- Land ratio distribution
function P.LandRatio(voProductionData)
local laArray = {
garrison_brigade = 4,
infantry_brigade = 20,
motorized_brigade = 2,
mechanized_brigade = 1,
armor_brigade = 2};
return laArray
end
-- Special Forces ratio distribution
function P.SpecialForcesRatio(voProductionData)
local laRatio = {
12, -- Land
1}; -- Special Force Unit
local laUnits = {
marine_brigade = 1,
bergsjaeger_brigade = 1,
paratrooper_brigade = 1};
return laRatio, laUnits
end
-- Elite Units
function P.EliteUnits(voProductionData)
local laUnits = {"gurkha_brigade"};
return laUnits
end
-- Which units should get 1 more Support unit with Superior Firepower tech
function P.FirePower(voProductionData)
local laArray = {
"infantry_brigade",
"motorized_brigade",
"mechanized_brigade",
"armor_brigade",
"heavy_armor_brigade"};
return laArray
end
-- Air ratio distribution
function P.AirRatio(voProductionData)
local laArray = {
interceptor = 4,
multi_role = 4,
rocket_interceptor = 1,
cas = 2,
tactical_bomber = 2,
naval_bomber = 1,
strategic_bomber = 2};
return laArray
end
-- Naval ratio distribution
function P.NavalRatio(voProductionData)
local laArray = {
destroyer = 4,
submarine = 1,
light_cruiser = 3,
heavy_cruiser = 3,
battleship = 1.5,
super_heavy_battleship = 0.5,
escort_carrier = 1,
carrier = 1};
local gerTag = CCountryDataBase.GetTag('GER')
local lbControlBerlin = (CCurrentGameState.GetProvince(1861):GetController() == gerTag)
local lbGerEngWar = voProductionData.ministerCountry:GetRelation(gerTag):HasWar()
local lbGerEngAlly = voProductionData.ministerCountry:GetRelation(gerTag):HasAlliance()
local japTag = CCountryDataBase.GetTag('JAP')
local lbControlTokyo = (CCurrentGameState.GetProvince(5315):GetController() == japTag)
local lbJapEngWar = voProductionData.ministerCountry:GetRelation(japTag):HasWar()
if lbGerEngWar and lbControlBerlin then
laArray = {
destroyer = 4,
submarine = 1,
light_cruiser = 3,
heavy_cruiser = 3,
battleship = 1.5,
super_heavy_battleship = 0.5,
escort_carrier = 1,
carrier = 0.5};
elseif lbJapEngWar then
laArray = {
destroyer = 2,
submarine = 1,
light_cruiser = 3,
heavy_cruiser = 3,
battleship = 1.5,
super_heavy_battleship = 1,
escort_carrier = 1.5,
carrier = 1};
elseif lbGerEngAlly then
laArray = {
destroyer = 2,
submarine = 1,
light_cruiser = 3,
heavy_cruiser = 3,
battleship = 1,
super_heavy_battleship = 1,
escort_carrier = 1,
carrier = 1};
end
return laArray
end
-- Transport to Land unit distribution
function P.TransportLandRatio(voProductionData)
local laArray = {
16, -- Land
1, -- transport
0.5}; -- invasion craft
return laArray
end
-- Convoy Ratio control
--- NOTE: If goverment is in Exile these parms are ignored
function P.ConvoyRatio(voProductionData)
local laArray = {
20, -- Percentage extra (adds to 100 percent so if you put 10 it will make it 110% of needed amount)
80, -- If Percentage extra is less than this it will force it up to the amount entered
150, -- If Percentage extra is greater than this it will force it down to this
5}; -- Escort to Convoy Ratio (Number indicates how many convoys needed to build 1 escort)
return laArray
end
-- Create Armored
function P.Build_Armor(ic, voProductionData, armor_brigade, vbGoOver)
return Support.Build_Standard_Armor(ic, voProductionData, armor_brigade, vbGoOver)
end
-- Create Motorised
function P.Build_Motorized(ic, voProductionData, motorized_brigade, vbGoOver)
return Support.Build_Standard_Motorized(ic, voProductionData, motorized_brigade, vbGoOver)
end
-- Never build and underground
function P.Build_Underground(ic, voProductionData)
return ic, false
end
function P.Build_AntiAir(vIC, voProductionData)
if voProductionData.ManpowerTotal > 800 then
return vIC, false
end
return vIC, true
end
function P.Build_Infrastructure(vIC, voProductionData)
if voProductionData.ManpowerTotal > 800 then
return vIC, false
end
return vIC, true
end
function P.Build_Fort(vIC, voProductionData)
if voProductionData.ManpowerTotal > 800 then
return vIC, false
end
return vIC, true
end
function P.Build_CoastalFort(vIC, voProductionData)
if voProductionData.ManpowerTotal > 800 then
return vIC, false
end
return vIC, true
end
function P.Build_AirBase(vIC, voProductionData)
if voProductionData.ManpowerTotal > 800 then
return vIC, false
end
return vIC, true
end
function P.Build_NavalBase(vIC, voProductionData)
if voProductionData.ManpowerTotal > 800 then
return vIC, false
end
return vIC, true
end
function P.Build_Radar(vIC, voProductionData)
if voProductionData.ManpowerTotal > 800 then
return vIC, false
end
return vIC, true
end
function P.Build_Industry(ic, voProductionData)
return ic, false
end
-- END OF PRODUTION OVERIDES
-- #######################################
-- #######################################
-- Intelligence Hooks
-- End of Intelligence Hooks
-- #######################################
function P.DiploScore_Embargo(voDiploScoreObj)
-- If Japan then do some special checks
if tostring(voDiploScoreObj.EmbargoTag) == "JAP" then
-- If we are part of the allies and JAP in axis
if (voDiploScoreObj.ministerCountry:GetFaction() == CCurrentGameState.GetFaction("allies")) and
(voDiploScoreObj.Faction == CCurrentGameState.GetFaction("axis"))
then
local usaTag = CCountryDataBase.GetTag("USA")
local loRelation = usaTag:GetCountry():GetRelation(voDiploScoreObj.EmbargoTag)
-- USA is currently embargoing Japan
-- and is at war so we make sure they dow US first
if loRelation:HasEmbargo() and loRelation:HasWar() then
voDiploScoreObj.Score = 100
-- Do not embargo japan unless the USA does so first
else
voDiploScoreObj.Score = 0
end
-- Never embargo Japan then
else
voDiploScoreObj.Score = 0
end
end
return voDiploScoreObj.Score
end
function P.DiploScore_OfferTrade(voDiploScoreObj)
local laTrade = {
CAN = {Score = 100},
USA = {Score = 100},
HOL = {Score = 100},
CHI = {Score = 100},
GER = {Score = 20},
ITA = {Score = 20},
JAP = {Score = 20}}
if laTrade[voDiploScoreObj.TagName] then
return voDiploScoreObj.Score + laTrade[voDiploScoreObj.TagName].Score
end
return voDiploScoreObj.Score
end
function P.DiploScore_InfluenceNation(voDiploScoreObj)
-- Only do this if we are in the allies
if voDiploScoreObj.FactionName == "allies" then
local loInfluences = {
CHI = {Score = 50},
CAN = {Score = 50},
USA = {Score = 50},
HOL = {Score = 20},
YUG = {Score = 20},
NOR = {Score = 20},
SPR = {Score = 20},
POR = {Score = 20},
GRE = {Score = 20},
TUR = {Score = 20},
SAU = {Score = 20},
PER = {Score = 20}}
-- Are they on our list
if loInfluences[voDiploScoreObj.TargetName] then
return (voDiploScoreObj.Score + loInfluences[voDiploScoreObj.TargetName].Score)
end
end
return voDiploScoreObj.Score
end
--##########################
-- Foreign Minister Hooks
function P.ForeignMinister_Influence(voForeignMinisterData)
local laIgnoreWatch -- Ignore this country but monitor them if they are about to join someone else
local laWatch -- Monitor them and also fi their score is high enough they can be influenced normally
local laIgnore -- Ignore them completely
if voForeignMinisterData.FactionName == "allies" then
laWatch = {
"CAN",
"USA",
"CHI"}
laIgnoreWatch = {
"TUR", -- Turkey
"SPA", -- Spain
"PER", -- Persia
"SAU", -- Saudi Arabia
"ARG", -- South America
"BOL",
"BRA",
"CHL",
"COL",
"ECU",
"GUY",
"PAR",
"PRU",
"URU",
"VEN",
"CUB", -- Central America
"COS",
"DOM",
"GUA",
"HAI",
"HON",
"MEX",
"NIC",
"PAN",
"HOL", -- Holland
"SWE", -- Sweden
"SPR", -- Republic Spain
"POR", -- Portugal
"SAL"}
laIgnore = {
"HUN", -- Hungary
"ROM", -- Romania
"BUL", -- Bulgaria
"FIN", -- Finland
"CYN", -- Yunnan
"SIA", -- Siam
"SIK", -- Sikiang
"CGX", -- Guangxi Clique
"CSX", -- Shanxi
"TIB", -- Tibet
"CHC", -- Communist China
"LAT", -- Lativia
"LIT", -- Lithuania
"EST", -- Estonia
"LUX", -- Luxemburg
"VIC", -- Vichy
"DEN", -- Denmark
"ETH", -- Ethiopia
"AUS", -- Austria
"CZE", -- Czechoslovakia
"SCH", -- Switzerland
"VIC", -- Vichy
"JAP", -- Japan
"ITA"} -- Italy
end
return laWatch, laIgnoreWatch, laIgnore
end
function P.ForeignMinister_ProposeWar(voForeignMinisterData)
if not(voForeignMinisterData.Strategy:IsPreparingWar()) then
if voForeignMinisterData.FactionName == "allies" then
local loMinisterCapital = voForeignMinisterData.ministerCountry:GetCapitalLocation():GetContinent()
-- Generic DOW for countries not part of the same faction
if not(voForeignMinisterData.IsAtWar) then
for loDiploStatus in voForeignMinisterData.ministerCountry:GetDiplomacy() do
local loTargetTag = loDiploStatus:GetTarget()
if loTargetTag:IsValid() then
local loTargetCountry = loTargetTag:GetCountry()
local loTargetContinent = loTargetCountry:GetCapitalLocation():GetContinent()
-- Limit DOWs to the same continent as the UKs capital
if loMinisterCapital == loTargetContinent then
if loDiploStatus:GetThreat():Get() > voForeignMinisterData.ministerCountry:GetMaxNeutralityForWarWith(loTargetTag):Get() then
if Support.GoodToWarCheck(loTargetTag, loTargetCountry, voForeignMinisterData, true, true) then
voForeignMinisterData.Strategy:PrepareWar(loTargetTag, 100 )
end
end
end
end
end
end
-- Special Checks Start after this point
local loWarTag = nil
local loAxisTag = CCurrentGameState.GetFaction("axis"):GetFactionLeader()
-- Normal DOW checks
if not(voForeignMinisterData.IsAtWar) and voForeignMinisterData.Year < 1941 then
local loCominternTag = CCurrentGameState.GetFaction("comintern"):GetFactionLeader()
local loCominternCountry = loCominternTag:GetCountry()
local loAxisCountry = loAxisTag:GetCountry()
local lbAxisVsComintermWar = loAxisCountry:GetRelation(loCominternTag):HasWar()
if lbAxisVsComintermWar then
-- Both Axis and Comintern are at war but we are at peace then check to see if we help Russia or Germany
if loCominternCountry:CalcDesperation():Get() > 0.4 then
loWarTag = loAxisTag
elseif loAxisCountry:CalcDesperation():Get() > 0.4 then
loWarTag = loCominternTag
end
else
-- If Axis are at war
if loAxisCountry:IsAtWar() then
loWarTag = loAxisTag
-- If Comintern are at war
elseif loCominternCountry:IsAtWar() then
loWarTag = loCominternTag
end
end
-- Seperate Watch for Italy
if loWarTag == nil then
local loITATag = CCountryDataBase.GetTag("ITA")
local loItalyCountry = loITATag:GetCountry()
if loItalyCountry:IsAtWar() then
for loDiploStatus in loItalyCountry:GetDiplomacy() do
local loTargetTag = loDiploStatus:GetTarget()
local lsTargetTag = tostring(loTargetTag)
if loTargetTag:IsValid() and loDiploStatus:HasWar() and lsTargetTag ~= "ETH" then
loWarTag = loITATag
break
end
end
end
end
-- If we are atwar with the leader of the Axis then look for Vichy
elseif voForeignMinisterData.ministerCountry:GetRelation(loAxisTag):HasWar() then
-- Vichy Check and allied with USA
local loUSATag = CCountryDataBase.GetTag("USA")
local loUSACountry = loUSATag:GetCountry()
-- Only consider this if we are in the same faction
if loUSACountry:GetFaction() == voForeignMinisterData.Faction then
local loVICTag = CCountryDataBase.GetTag("VIC")
local loVichyCountry = loVICTag:GetCountry()
if Support.GoodToWarCheck(loVICTag, loVichyCountry, voForeignMinisterData, true, false) then
loWarTag = loVICTag
end
end
end
-- Do we have a DOW?
if loWarTag ~= nil then
voForeignMinisterData.Strategy:PrepareWar(loWarTag, 100)
end
end
end
end
-- Produce slightly better trained troops
function P.CallLaw_training_laws(minister, voCurrentLaw)
local _ADVANCED_TRAINING_ = 29
return CLawDataBase.GetLaw(_ADVANCED_TRAINING_)
end
function P.DiploScore_Debt(voDiploScoreObj)
if (tostring(voDiploScoreObj.ToTag) == "USA") then
return 100
end
return voDiploScoreObj.Score
end
return AI_ENG