Code:
SeleucidDebugging = false;
EasternRebellionTriggered = false;
SeleucidTurnProtection = 15;
all_diplomatic_treaty_types = {
"current_treaty_vassal_of_player",
"current_treaty_client_of_player",
"current_treaty_at_war",
"current_treaty_defensive_alliance",
"current_treaty_military_alliance",
"current_treaty_trade_agreement",
"current_treaty_non_aggression_pact",
"current_treaty_giving_soft_military_access_turns",
"current_treaty_trade_embargoed",
"current_treaty_embargoing_trade"
};
local function SeleucidGetTreaties(context)
if not EasternRebellionTriggered and context:faction():name() == "rom_seleucid" then
local human = context:faction():is_human()
if scripting.game_interface:model():turn_number() == 2 and human then
scripting.game_interface:show_message_event("custom_event_520", 0, 0);
end;
if SeleucidTurnProtection < scripting.game_interface:model():turn_number() then
DebugSeleucid("SeleucidGetTreaties");
SeleucidTreatyDetailsGetTreaties(context:faction():treaty_details(), context:faction():faction_attitudes(), human);
end;
end;
end;
function SeleucidTreatyDetailsGetTreaties(treaty_details, faction_attitudes, human)
local count = 0;
local VassalFactionKeys = {};
for faction, details in pairs(treaty_details) do
DebugSeleucid("details.culture: "..details.culture);
if details.culture == "rom_Eastern" then
DebugSeleucid("faction ??: "..tostring(faction));
for k, treaty in ipairs(details) do
DebugSeleucid("treaty_details: "..treaty);
if treaty == "current_treaty_vassal_of_player"
or treaty == "current_treaty_client_of_player" then
table.insert(VassalFactionKeys, tostring(faction));
count = count + 1;
DebugSeleucid("Faction Added: "..faction);
end;
end;
end;
end;
if count > 2 then SeleucidRebellionFactions(VassalFactionKeys, faction_attitudes, count, human) end;
end;
function SeleucidRandomSeed()
local region = "emp_syria_antioch";
TotalPop = 0;
for i = 1, 4 do
TotalPop = rom_region_to_pop_table[region][i] + TotalPop;
end;
DebugSeleucid("TotalPop as random seed: "..tostring(TotalPop))
return TotalPop;
end;
function SeleucidRandomNumber()
DebugSeleucid("SeleucidRandomNumber")
local random_var = SeleucidRandomSeed();
math.randomseed(random_var);
random_var = math.random(1,100);
DebugSeleucid("random_var: "..tostring(random_var));
random_var = math.random(1,100);
DebugSeleucid("random_var: "..tostring(random_var));
return random_var;
end;
function SeleucidRebellionFactions(VassalFactionKeys, faction_attitudes, count, human)
local RebelFactions = {};
local MaxRebels = 0;
local strength = 0;
if count > 2 then
DebugSeleucid("SeleucidRandomNumber: Start Rebel Faction List");
for _,i in pairs(VassalFactionKeys) do
local VassalFaction = i;
DebugSeleucid("faction_attitudes[VassalFaction]: "..faction_attitudes[VassalFaction])
if not human and MaxRebels < 5
or (human and MaxRebels < 5 and faction_attitudes[VassalFaction] <= 0) then
local newstrength = SeleucidRebelStrength(VassalFaction)
if newstrength > 1 then
table.insert(RebelFactions, VassalFaction)
strength = strength + newstrength
MaxRebels = MaxRebels + 1;
DebugSeleucid("Rebel Faction added: "..VassalFaction)
end;
end;
end;
end;
DebugSeleucid("MaxRebels: "..tostring(MaxRebels));
DebugSeleucid("strength: "..tostring(strength));
if MaxRebels >= 2 then SeleucidRebellionChance(MaxRebels, strength, RebelFactions) end;
end;
function SeleucidRebellionChance(MaxRebels, Rebelstrength, RebelFactions)
local SeleucidStrength = SeleucidRebelStrength("rom_seleucid")
DebugSeleucid("SeleucidStrength: "..tostring(SeleucidStrength));
local strength = Rebelstrength - SeleucidStrength
if strength < 0
then strength = -1
end;
local randomNumber = SeleucidRandomNumber();
local chance = (MaxRebels*3) + (strength*5);
DebugSeleucid("chance: "..tostring(chance));
if randomNumber < chance
then SeleucidTriggerRebellionForFactions(RebelFactions);
end;
end;
function SeleucidRebelStrength(CheckFaction)
local minUpkeepThreshold = 1000;
if CheckFaction == "rom_seleucid"
then minUpkeepThreshold = 2500
end;
local strength = 0;
local faction = scripting.game_interface:model():world():faction_by_key(CheckFaction)
local forceCount = faction:military_force_list():num_items();
for i = 0, forceCount - 1 do
local force = faction:military_force_list():item_at(i);
if force:upkeep() > minUpkeepThreshold then
strength = strength + 1;
end;
end;
DebugSeleucid("CheckFaction: ".. CheckFaction.. " strength: "..strength);
return strength;
end;
function SeleucidTriggerRebellionForFactions(RebelFactions)
DebugSeleucid("SeleucidTriggerRebellionForFactions")
for _,i in pairs(RebelFactions) do
local RebelFaction = i;
scripting.game_interface:force_declare_war(RebelFaction, "rom_seleucid");
scripting.game_interface:cai_strategic_stance_manager_promote_specified_stance_towards_target_faction(RebelFaction, "rom_seleucid", "CAI_STRATEGIC_STANCE_BITTER_ENEMIES")
scripting.game_interface:cai_strategic_stance_manager_promote_specified_stance_towards_target_faction("rom_seleucid", RebelFaction, "CAI_STRATEGIC_STANCE_BITTER_ENEMIES")
scripting.game_interface:cai_strategic_stance_manager_block_all_stances_but_that_specified_towards_target_faction(RebelFaction, "rom_seleucid", "CAI_STRATEGIC_STANCE_BITTER_ENEMIES")
scripting.game_interface:force_change_cai_faction_personality(RebelFaction, "minor_eastern_alternative");
end;
for _,i in pairs(RebelFactions) do
local RebelFaction = i;
for _,k in pairs(RebelFactions) do
local RebelFaction2 = k;
if RebelFaction ~= RebelFaction2 then
scripting.game_interface:force_make_peace(RebelFaction, RebelFaction2);
end;
end;
end;
scripting.game_interface:show_message_event("custom_event_510", 0, 0); -- add new message about Eastern Rebels
EasternRebellionTriggered = true;
end;
function DebugSeleucid(text, isTitle, isNew)
if not SeleucidDebugging then
return
end;
local logfile;
text = tostring(text);
if isNew then
logfile = io.open("DebugSeleucid.log.txt","w");
local text = tostring("- Sleucid Debug Log -\n");
logfile:write(text.."\n\n");
else
logfile = io.open("DebugSeleucid.log.txt","a");
if not logfile then logfile = io.open("DebugSeleucid.log.txt","w") end
end
if isTitle then
local title_text = "*************************************************************************\n";
text = "\n"..title_text..text.."\n"..title_text;
end
logfile:write(text.."\n");
logfile:close();
end;