Code:
-- CORE REGIONS --
-- SELEUCID --
core_regions_seleucid = {
["emp_syria_antioch"]=true,
["emp_syria_tarsus"]=true,
["emp_syria_thapsacus"]=true,
["emp_mesopotamia_ctesiphon"]=true,
["emp_mesopotamia_charax"]=true,
["emp_mesopotamia_hatra"]=true,
["emp_mesopotamia_edessa"]=true,
["emp_palmyra_dura"]=true,
["emp_palmyra_palmyra"]=true,
};
-- PTOLEMY --
core_regions_ptolemy = {
["emp_aegyptos_alexandria"]=true,
["emp_aegyptos_diospolis"]=true,
["emp_aegyptos_memphis"]=true,
["emp_aegyptos_myos_hormos"]=true,
["emp_judea_jerusalem"]=true,
["emp_judea_tyros"]=true,
["emp_galatia_et_cappadocia_side"]=true,
["emp_libya_ammonium"]=true,
["emp_libya_paraitonion"]=true,
};
-- CARTHAGE --
core_regions_carthage = {
["emp_africa_carthago"]=true,
["emp_africa_leptis_magna"]=true,
["emp_africa_hadrumentum"]=true,
["emp_africa_macomades"]=true,
["emp_sicily_agrigentum"]=true,
["emp_sicily_panormus"]=true,
["emp_corsica_et_sardinia_aleria"]=true,
["emp_corsica_et_sardinia_caralis"]=true,
["emp_hispania_ibossim"]=true,
["emp_hispania_nova_carthago"]=true,
["emp_mauretania_siga"]=true,
["emp_mauretania_tingis"]=true,
["emp_baetica_gades"]=true,
["emp_numidia_iol"]=true,
["emp_hispania_saguntum"]=true,
};
-- MACEDON --
core_regions_antigonidai = {
["emp_macedonia_thessalonica"]=true,
["emp_macedonia_pharsalus"]=true,
};
-- ATHENS --
core_regions_athens = {
["emp_achaia_athenae"]=true,
};
-- EPIRUS --
core_regions_epirus = {
["emp_macedonia_apollonia"]=true,
["emp_macedonia_pharsalus"]=true,
["emp_italia_brundisium"]=true,
};
-- BAKTRIA --
core_regions_baktria = {
["emp_bactria_baktria"]=true,
["emp_bactria_eucratides"]=true,
["emp_transoxania_maracanda"]=true,
["emp_transoxania_bukhara"]=true,
};
-- My above "home regions" per factions are arbitrary, based on mostly what the game sets up at start of the DeI grand campaign startpos.esf, but also depending on my preferences
-- Some starting territory of a large faction might not be protected, for the sake of randomness and to allow some liberties for the AI to conquer or liberate an emergent faction
-- PENDING BATTLE, AUTORESOLVER BONUSES --
local function CORE_REGION_AR_BONUS(context)
local attacker = context:pending_battle():attacker():faction() -- To check if human
local defender = context:pending_battle():defender():faction()
local attacker_name = context:pending_battle():attacker():faction():name() -- To check the factions involved by names
local defender_name = context:pending_battle():defender():faction():name()
local attacker_region = context:pending_battle():attacker():region():name() -- To check the current region of the battle, i havent tried it but i wish i could reduce this to an easier/simple "context:pending_battle():region():name()"
local defender_region = context:pending_battle():defender():region():name()
-- I exclude the player from the conditions, the original script checked if player was nearby or if faction was allied
-- But since my scripts protects factions regardless of their previous or current "importance" it doesn't matter because they will be protected in their homeland or crushed in (most) of their neighbors territory
if attacker:is_human() == false and defender:is_human() == false then
-- I then start a first "faction bloc", of whatever list i fancy, i can simply add factions to the bloc or make several blocs, i chose to do this by culture except for the first (my "major factions")
------ SELEUKIDAI ------
if core_regions_seleucid[attacker_region]
or core_regions_seleucid[defender_region]
then
if attacker_name == "rom_seleucid" then -- attacker is local
LuaLog("ASSAULT OF "..context:pending_battle():attacker():faction():name().." VS "..context:pending_battle():defender():faction():name().." IN "..context:pending_battle():attacker():region():name())
LuaLog("LOCAL ATTACK BONUS FOR "..context:pending_battle():attacker():faction():name()) -- LOCAL ATTACK BONUS
scripting.game_interface:modify_next_autoresolve_battle(100, 0.01, 0.01, 100, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
elseif defender_name == "rom_seleucid" then -- defender is local
LuaLog("DEFENSE OF "..context:pending_battle():defender():faction():name().." VS "..context:pending_battle():attacker():faction():name().." IN "..context:pending_battle():defender():region():name())
LuaLog("LOCAL DEFENSE BONUS FOR "..context:pending_battle():defender():faction():name()) -- LOCAL DEFENSE BONUS
scripting.game_interface:modify_next_autoresolve_battle(0.01, 100, 100, 0.01, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
else -- attacker / defender is foreigner
LuaLog("FOREIGN FACTION "..context:pending_battle():attacker():faction():name()" GETS NO BONUS") -- FOREIGNER PENALTY
end
------ PTOLEMY ------
elseif core_regions_ptolemy[attacker_region]
or core_regions_ptolemy[defender_region]
then
if attacker_name == "rom_ptolemaics" then -- attacker is local
LuaLog("ASSAULT OF "..context:pending_battle():attacker():faction():name().." VS "..context:pending_battle():defender():faction():name().." IN "..context:pending_battle():attacker():region():name())
LuaLog("LOCAL ATTACK BONUS FOR "..context:pending_battle():attacker():faction():name()) -- LOCAL ATTACK BONUS
scripting.game_interface:modify_next_autoresolve_battle(100, 0.01, 0.01, 100, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
elseif defender_name == "rom_ptolemaics" then -- defender is local
LuaLog("DEFENSE OF "..context:pending_battle():defender():faction():name().." VS "..context:pending_battle():attacker():faction():name().." IN "..context:pending_battle():defender():region():name())
LuaLog("LOCAL DEFENSE BONUS FOR "..context:pending_battle():defender():faction():name()) -- LOCAL DEFENSE BONUS
scripting.game_interface:modify_next_autoresolve_battle(0.01, 100, 100, 0.01, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
else -- attacker / defender is foreigner
LuaLog("FOREIGN FACTION "..context:pending_battle():attacker():faction():name()" GETS NO BONUS") -- FOREIGNER PENALTY
end
------ CARTHAGE ------
elseif core_regions_carthage[attacker_region]
or core_regions_carthage[defender_region]
then
if attacker_name == "rom_carthage" then -- attacker is local
LuaLog("ASSAULT OF "..context:pending_battle():attacker():faction():name().." VS "..context:pending_battle():defender():faction():name().." IN "..context:pending_battle():attacker():region():name())
LuaLog("LOCAL ATTACK BONUS FOR "..context:pending_battle():attacker():faction():name()) -- LOCAL ATTACK BONUS
scripting.game_interface:modify_next_autoresolve_battle(100, 0.01, 0.01, 100, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
elseif defender_name == "rom_carthage" then -- defender is local
LuaLog("DEFENSE OF "..context:pending_battle():defender():faction():name().." VS "..context:pending_battle():attacker():faction():name().." IN "..context:pending_battle():defender():region():name())
LuaLog("LOCAL DEFENSE BONUS FOR "..context:pending_battle():defender():faction():name()) -- LOCAL DEFENSE BONUS
scripting.game_interface:modify_next_autoresolve_battle(0.01, 100, 100, 0.01, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
else -- attacker / defender is foreigner
LuaLog("FOREIGN FACTION "..context:pending_battle():attacker():faction():name()" GETS NO BONUS") -- FOREIGNER PENALTY
end
------ ANTIGONIDAI ------
elseif core_regions_antigonidai[attacker_region]
or core_regions_antigonidai[defender_region]
then
if attacker_name == "rom_macedon" then -- attacker is local
LuaLog("ASSAULT OF "..context:pending_battle():attacker():faction():name().." VS "..context:pending_battle():defender():faction():name().." IN "..context:pending_battle():attacker():region():name())
LuaLog("LOCAL ATTACK BONUS FOR "..context:pending_battle():attacker():faction():name()) -- LOCAL ATTACK BONUS
scripting.game_interface:modify_next_autoresolve_battle(100, 0.01, 0.01, 100, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
elseif defender_name == "rom_macedon" then -- defender is local
LuaLog("DEFENSE OF "..context:pending_battle():defender():faction():name().." VS "..context:pending_battle():attacker():faction():name().." IN "..context:pending_battle():defender():region():name())
LuaLog("LOCAL DEFENSE BONUS FOR "..context:pending_battle():defender():faction():name()) -- LOCAL DEFENSE BONUS
scripting.game_interface:modify_next_autoresolve_battle(0.01, 100, 100, 0.01, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
else -- attacker / defender is foreigner
LuaLog("FOREIGN FACTION "..context:pending_battle():attacker():faction():name()" GETS NO BONUS") -- FOREIGNER PENALTY
end
------ EPIRUS ------
elseif core_regions_epirus[attacker_region]
or core_regions_epirus[defender_region]
then
if attacker_name == "rom_epirus" then -- attacker is local
LuaLog("ASSAULT OF "..context:pending_battle():attacker():faction():name().." VS "..context:pending_battle():defender():faction():name().." IN "..context:pending_battle():attacker():region():name())
LuaLog("LOCAL ATTACK BONUS FOR "..context:pending_battle():attacker():faction():name()) -- LOCAL ATTACK BONUS
scripting.game_interface:modify_next_autoresolve_battle(100, 0.01, 0.01, 100, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
elseif defender_name == "rom_epirus" then -- defender is local
LuaLog("DEFENSE OF "..context:pending_battle():defender():faction():name().." VS "..context:pending_battle():attacker():faction():name().." IN "..context:pending_battle():defender():region():name())
LuaLog("LOCAL DEFENSE BONUS FOR "..context:pending_battle():defender():faction():name()) -- LOCAL DEFENSE BONUS
scripting.game_interface:modify_next_autoresolve_battle(0.01, 100, 100, 0.01, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
else -- attacker / defender is foreigner
LuaLog("FOREIGN FACTION "..context:pending_battle():attacker():faction():name()" GETS NO BONUS") -- FOREIGNER PENALTY
end
------ ATHENAI ------
elseif core_regions_athens[attacker_region]
or core_regions_athens[defender_region]
then
if attacker_name == "rom_athens" then -- attacker is local
LuaLog("ASSAULT OF "..context:pending_battle():attacker():faction():name().." VS "..context:pending_battle():defender():faction():name().." IN "..context:pending_battle():attacker():region():name())
LuaLog("LOCAL ATTACK BONUS FOR "..context:pending_battle():attacker():faction():name()) -- LOCAL ATTACK BONUS
scripting.game_interface:modify_next_autoresolve_battle(100, 0.01, 0.01, 100, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
elseif defender_name == "rom_athens" then -- defender is local
LuaLog("DEFENSE OF "..context:pending_battle():defender():faction():name().." VS "..context:pending_battle():attacker():faction():name().." IN "..context:pending_battle():defender():region():name())
LuaLog("LOCAL DEFENSE BONUS FOR "..context:pending_battle():defender():faction():name()) -- LOCAL DEFENSE BONUS
scripting.game_interface:modify_next_autoresolve_battle(0.01, 100, 100, 0.01, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
else -- attacker / defender is foreigner
LuaLog("FOREIGN FACTION "..context:pending_battle():attacker():faction():name()" GETS NO BONUS") -- FOREIGNER PENALTY
end
------ BAKTRIA ------
elseif core_regions_baktria[attacker_region]
or core_regions_baktria[defender_region]
then
if attacker_name == "rom_baktria" then -- attacker is local
LuaLog("ASSAULT OF "..context:pending_battle():attacker():faction():name().." VS "..context:pending_battle():defender():faction():name().." IN "..context:pending_battle():attacker():region():name())
LuaLog("LOCAL ATTACK BONUS FOR "..context:pending_battle():attacker():faction():name()) -- LOCAL ATTACK BONUS
scripting.game_interface:modify_next_autoresolve_battle(100, 0.01, 0.01, 100, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
elseif defender_name == "rom_baktria" then -- defender is local
LuaLog("DEFENSE OF "..context:pending_battle():defender():faction():name().." VS "..context:pending_battle():attacker():faction():name().." IN "..context:pending_battle():defender():region():name())
LuaLog("LOCAL DEFENSE BONUS FOR "..context:pending_battle():defender():faction():name()) -- LOCAL DEFENSE BONUS
scripting.game_interface:modify_next_autoresolve_battle(0.01, 100, 100, 0.01, false) -- ATT, DEF, ATT LOSSES, DEF LOSSES
else -- attacker / defender is foreigner
LuaLog("FOREIGN FACTION "..context:pending_battle():attacker():faction():name()" GETS NO BONUS") -- FOREIGNER PENALTY
end
else
LuaLog("BATTLE REGION IS NOT MAJOR EMPIRE") -- NO BONUS
end -- IF REGION
------ FACTION BLOCS END => Create as many blocs as you wish but there is probably better ways to set this up
------ In my case i choose to make factions blocs as "if then - elseif then else end" by my own standards => my "major factions" are arbitrary, depending on my own preferences
------ This is because i thought i was restricted to a certain number of loops / if - elseif => mostly the reason was because i misspelled region/factions provoking code failures
------ So it seems that if syntax is correct, you can go a lot farther than the mere 6 - 8 factions blocs i made or the larger 12 - 15 for celts / gauls for example
else -- IF HUMAN
LuaLog("BATTLE BETWEEN "..context:pending_battle():attacker():faction():name().." AND "..context:pending_battle():defender():faction():name().." IN "..context:pending_battle():attacker():region():name())
end -- IF HUMAN
end -- END ONPENDINGBATTLE FUNCTION
-- Event callbacks => of course, to make sure the script runs for every battles --
scripting.AddEventCallBack("PendingBattle", CORE_REGION_AR_BONUS);
This code should work properly, if yes, then for AI autobattle (ON LAND only, because i don't know yet how to manage the naval battles, if at all possible ...) the bonus/penalty will apply on selected regions for specified factions. Base line is => region owner gets bonus to attack / defense, it doesn't matter where as long as the region is on their ownership list.