From 5a744169612df7928116873c69d55de0c4e0c97c Mon Sep 17 00:00:00 2001
From: Blank_Alt <12406-Blank_Alt@users.noreply.gitgud.io>
Date: Sat, 20 Mar 2021 16:57:42 +1300
Subject: [PATCH] secExp-fix

---
 src/Mods/SecExp/js/secExpBC.js | 530 ++++++++++++++++-----------------
 src/gui/options/options.js     |   9 +-
 2 files changed, 265 insertions(+), 274 deletions(-)

diff --git a/src/Mods/SecExp/js/secExpBC.js b/src/Mods/SecExp/js/secExpBC.js
index 7518b44fdb3..7274b6d7b55 100644
--- a/src/Mods/SecExp/js/secExpBC.js
+++ b/src/Mods/SecExp/js/secExpBC.js
@@ -9,308 +9,302 @@ App.SecExp.generalBC = function() {
 		V.secExpEnabled = 0;
 	}
 
-	V.SecExp.settings = V.SecExp.settings || {};
-	delete V.SecExp.settings.show;
 	delete V.SecExp.army;
 
 	if (V.secExpEnabled === 0) {
 		return;
-	} else {
-		V.SecExp.edicts = V.SecExp.edicts || {};
-		V.SecExp.edicts.alternativeRents = V.SecExp.edicts.alternativeRents || V.alternativeRents || 0;
-		V.SecExp.edicts.enslavementRights = V.SecExp.edicts.enslavementRights || V.enslavementRights || 0;
-		V.SecExp.edicts.sellData = V.SecExp.edicts.sellData || V.sellData || 0;
-		V.SecExp.edicts.propCampaignBoost = V.SecExp.edicts.propCampaignBoost || V.propCampaignBoost || 0;
-		V.SecExp.edicts.tradeLegalAid = V.SecExp.edicts.tradeLegalAid || V.tradeLegalAid || 0;
-		V.SecExp.edicts.taxTrade = V.SecExp.edicts.taxTrade || V.taxTrade || 0;
-		V.SecExp.edicts.slaveWatch = V.SecExp.edicts.slaveWatch || V.slaveWatch || 0;
-		V.SecExp.edicts.subsidyChurch = V.SecExp.edicts.subsidyChurch || V.subsidyChurch || 0;
-		V.SecExp.edicts.SFSupportLevel = V.SecExp.edicts.SFSupportLevel || V.SFSupportLevel || 0;
-		V.SecExp.edicts.limitImmigration = V.SecExp.edicts.limitImmigration || V.limitImmigration || 0;
-		V.SecExp.edicts.openBorders = V.SecExp.edicts.openBorders || V.openBorders || 0;
-		V.SecExp.edicts.weaponsLaw = V.weaponsLaw || between(V.SecExp.edicts.weaponsLaw, 0, 3, 'inclusive') ? V.SecExp.edicts.weaponsLaw : 3;
-
-		V.SecExp.edicts.defense = V.SecExp.edicts.defense || {};
-		V.SecExp.edicts.defense.soldierWages = V.SecExp.edicts.defense.soldierWages || V.soldierWages || 1;
-		V.SecExp.edicts.defense.slavesOfficers = V.SecExp.edicts.defense.slavesOfficers || V.slavesOfficers || 0;
-		V.SecExp.edicts.defense.discountMercenaries = V.SecExp.edicts.defense.discountMercenaries || V.discountMercenaries || 0;
-
-		V.SecExp.edicts.defense.militia = V.SecExp.edicts.defense.militia || 0;
-		if (V.militiaFounded) {
-			V.SecExp.edicts.defense.militia = 1;
-		}
-		if (V.recruitVolunteers) {
-			V.SecExp.edicts.defense.militia = 2;
-		}
-		if (V.conscription) {
-			V.SecExp.edicts.defense.militia = 3;
-		}
-		if (V.militaryService) {
-			V.SecExp.edicts.defense.militia = 4;
-		}
-		if (V.militarizedSociety) {
-			V.SecExp.edicts.defense.militia = 5;
-		}
-
-		V.SecExp.edicts.defense.militaryExemption = V.SecExp.edicts.defense.militaryExemption || V.militaryExemption || 0;
-		V.SecExp.edicts.defense.noSubhumansInArmy = V.SecExp.edicts.defense.noSubhumansInArmy || V.noSubhumansInArmy || 0;
-		V.SecExp.edicts.defense.pregExemption = V.SecExp.edicts.defense.pregExemption || V.pregExemption || 0;
-		V.SecExp.edicts.defense.liveTargets = V.SecExp.edicts.defense.liveTargets || V.liveTargets || 0;
-		V.SecExp.edicts.defense.pregExemption = V.SecExp.edicts.defense.pregExemption || V.pregExemption || 0;
-
-		// Units
-		V.SecExp.edicts.defense.martialSchool = V.SecExp.edicts.defense.martialSchool || V.martialSchool || 0;
-		V.SecExp.edicts.defense.eliteOfficers = V.SecExp.edicts.defense.eliteOfficers || V.eliteOfficers || 0;
-		V.SecExp.edicts.defense.lowerRequirements = V.SecExp.edicts.defense.lowerRequirements || V.lowerRequirements|| V.lowerRquirements || 0;
-		V.SecExp.edicts.defense.legionTradition = V.SecExp.edicts.defense.legionTradition || V.legionTradition || 0;
-		V.SecExp.edicts.defense.eagleWarriors = V.SecExp.edicts.defense.eagleWarriors || V.eagleWarriors || 0;
-		V.SecExp.edicts.defense.ronin = V.SecExp.edicts.defense.ronin || V.ronin || 0;
-		V.SecExp.edicts.defense.sunTzu = V.SecExp.edicts.defense.sunTzu || V.sunTzu || 0;
-		V.SecExp.edicts.defense.mamluks = V.SecExp.edicts.defense.mamluks || V.mamluks || 0;
-		V.SecExp.edicts.defense.pharaonTradition = V.SecExp.edicts.defense.pharaonTradition || V.pharaonTradition || 0;
-
-		// Priv
-		V.SecExp.edicts.defense.privilege = V.SecExp.edicts.defense.privilege || {};
-		V.SecExp.edicts.defense.privilege.militiaSoldier = V.SecExp.edicts.defense.privilege.militiaSoldier || V.militiaSoldier || 0;
-		V.SecExp.edicts.defense.privilege.slaveSoldier = V.SecExp.edicts.defense.privilege.slaveSoldier || V.slaveSoldier || 0;
-		V.SecExp.edicts.defense.privilege.mercSoldier = V.SecExp.edicts.defense.privilege.mercSoldier || V.mercSoldier || 0;
-
-		V.SecExp.units = V.SecExp.units || {};
-		V.SecExp.units.bots = V.SecExp.units.bots || {};
-		V.SecExp.units.bots.active = Math.max(0, V.SecExp.units.bots.active) || V.arcologyUpgrade.drones > 0 ? 1 : 0;
-		V.SecExp.units.bots.ID = -1;
-		V.SecExp.units.bots.isDeployed = V.SecExp.units.bots.isDeployed || 0;
-		V.SecExp.units.bots.troops = Math.max(V.SecExp.units.bots.troops || 0, V.arcologyUpgrade.drones > 0 ? 30 : 0);
-		V.SecExp.units.bots.maxTroops = Math.max(V.SecExp.units.bots.maxTroops || 0, V.arcologyUpgrade.drones > 0 ? 30 : 0);
-		V.SecExp.units.bots.equip = V.SecExp.units.bots.equip || 0;
-		if (V.secBots) {
-			V.SecExp.units.bots = V.secBots;
-		}
+	}
+	V.SecExp.settings = V.SecExp.settings || {};
+	V.SecExp.edicts = V.SecExp.edicts || {};
+	V.SecExp.edicts.defense = V.SecExp.edicts.defense || {};
+	V.SecExp.units = V.SecExp.units || {};
+	V.SecExp.units.bots = V.SecExp.units.bots || {};
+	V.SecExp.smilingMan = V.SecExp.smilingMan || {};
+	V.SecExp.core = V.SecExp.core || {};
+	V.SecExp.battles = V.SecExp.battles || {};
+	V.SecExp.rebellions = V.SecExp.rebellions || {};
+	V.SecExp.settings.battle = V.SecExp.settings.battle || {};
+	V.SecExp.settings.battle.major = V.SecExp.settings.battle.major || {};
+	V.SecExp.settings.rebellion = V.SecExp.settings.rebellion || {};
+	V.SecExp.buildings = V.SecExp.buildings || {};
+	V.SecExp.proclamation = V.SecExp.proclamation || {};
+
+	V.SecExp.edicts.alternativeRents = V.SecExp.edicts.alternativeRents || V.alternativeRents || 0;
+	V.SecExp.edicts.enslavementRights = V.SecExp.edicts.enslavementRights || V.enslavementRights || 0;
+	V.SecExp.edicts.sellData = V.SecExp.edicts.sellData || V.sellData || 0;
+	V.SecExp.edicts.propCampaignBoost = V.SecExp.edicts.propCampaignBoost || V.propCampaignBoost || 0;
+	V.SecExp.edicts.tradeLegalAid = V.SecExp.edicts.tradeLegalAid || V.tradeLegalAid || 0;
+	V.SecExp.edicts.taxTrade = V.SecExp.edicts.taxTrade || V.taxTrade || 0;
+	V.SecExp.edicts.slaveWatch = V.SecExp.edicts.slaveWatch || V.slaveWatch || 0;
+	V.SecExp.edicts.subsidyChurch = V.SecExp.edicts.subsidyChurch || V.subsidyChurch || 0;
+	V.SecExp.edicts.SFSupportLevel = V.SecExp.edicts.SFSupportLevel || V.SFSupportLevel || 0;
+	V.SecExp.edicts.limitImmigration = V.SecExp.edicts.limitImmigration || V.limitImmigration || 0;
+	V.SecExp.edicts.openBorders = V.SecExp.edicts.openBorders || V.openBorders || 0;
+	V.SecExp.edicts.weaponsLaw = V.weaponsLaw || between(V.SecExp.edicts.weaponsLaw, 0, 3, 'inclusive') ? V.SecExp.edicts.weaponsLaw : 3;
+
+	V.SecExp.edicts.defense.soldierWages = V.SecExp.edicts.defense.soldierWages || V.soldierWages || 1;
+	V.SecExp.edicts.defense.slavesOfficers = V.SecExp.edicts.defense.slavesOfficers || V.slavesOfficers || 0;
+	V.SecExp.edicts.defense.discountMercenaries = V.SecExp.edicts.defense.discountMercenaries || V.discountMercenaries || 0;
+
+	V.SecExp.edicts.defense.militia = V.SecExp.edicts.defense.militia || 0;
+	if (V.militiaFounded) {
+		V.SecExp.edicts.defense.militia = 1;
+	}
+	if (V.recruitVolunteers) {
+		V.SecExp.edicts.defense.militia = 2;
+	}
+	if (V.conscription) {
+		V.SecExp.edicts.defense.militia = 3;
+	}
+	if (V.militaryService) {
+		V.SecExp.edicts.defense.militia = 4;
+	}
+	if (V.militarizedSociety) {
+		V.SecExp.edicts.defense.militia = 5;
+	}
 
-		App.SecExp.unit.gen('slaves', {count: V.createdSlavesUnits, killed: V.slavesTotalCasualties, squads: V.slaveUnits});
+	V.SecExp.edicts.defense.militaryExemption = V.SecExp.edicts.defense.militaryExemption || V.militaryExemption || 0;
+	V.SecExp.edicts.defense.noSubhumansInArmy = V.SecExp.edicts.defense.noSubhumansInArmy || V.noSubhumansInArmy || 0;
+	V.SecExp.edicts.defense.pregExemption = V.SecExp.edicts.defense.pregExemption || V.pregExemption || 0;
+	V.SecExp.edicts.defense.liveTargets = V.SecExp.edicts.defense.liveTargets || V.liveTargets || 0;
+	V.SecExp.edicts.defense.pregExemption = V.SecExp.edicts.defense.pregExemption || V.pregExemption || 0;
+
+	// Units
+	V.SecExp.edicts.defense.martialSchool = V.SecExp.edicts.defense.martialSchool || V.martialSchool || 0;
+	V.SecExp.edicts.defense.eliteOfficers = V.SecExp.edicts.defense.eliteOfficers || V.eliteOfficers || 0;
+	V.SecExp.edicts.defense.lowerRequirements = V.SecExp.edicts.defense.lowerRequirements || V.lowerRequirements|| V.lowerRquirements || 0;
+	V.SecExp.edicts.defense.legionTradition = V.SecExp.edicts.defense.legionTradition || V.legionTradition || 0;
+	V.SecExp.edicts.defense.eagleWarriors = V.SecExp.edicts.defense.eagleWarriors || V.eagleWarriors || 0;
+	V.SecExp.edicts.defense.ronin = V.SecExp.edicts.defense.ronin || V.ronin || 0;
+	V.SecExp.edicts.defense.sunTzu = V.SecExp.edicts.defense.sunTzu || V.sunTzu || 0;
+	V.SecExp.edicts.defense.mamluks = V.SecExp.edicts.defense.mamluks || V.mamluks || 0;
+	V.SecExp.edicts.defense.pharaonTradition = V.SecExp.edicts.defense.pharaonTradition || V.pharaonTradition || 0;
+
+	// Priv
+	V.SecExp.edicts.defense.privilege = V.SecExp.edicts.defense.privilege || {};
+	V.SecExp.edicts.defense.privilege.militiaSoldier = V.SecExp.edicts.defense.privilege.militiaSoldier || V.militiaSoldier || 0;
+	V.SecExp.edicts.defense.privilege.slaveSoldier = V.SecExp.edicts.defense.privilege.slaveSoldier || V.slaveSoldier || 0;
+	V.SecExp.edicts.defense.privilege.mercSoldier = V.SecExp.edicts.defense.privilege.mercSoldier || V.mercSoldier || 0;
+
+	V.SecExp.units.bots.active = Math.max(0, V.SecExp.units.bots.active) || V.arcologyUpgrade.drones > 0 ? 1 : 0;
+	V.SecExp.units.bots.ID = -1;
+	V.SecExp.units.bots.isDeployed = V.SecExp.units.bots.isDeployed || 0;
+	V.SecExp.units.bots.troops = Math.max(V.SecExp.units.bots.troops || 0, V.arcologyUpgrade.drones > 0 ? 30 : 0);
+	V.SecExp.units.bots.maxTroops = Math.max(V.SecExp.units.bots.maxTroops || 0, V.arcologyUpgrade.drones > 0 ? 30 : 0);
+	V.SecExp.units.bots.equip = V.SecExp.units.bots.equip || 0;
+	if (V.secBots) {
+		V.SecExp.units.bots = V.secBots;
+	}
 
-		App.SecExp.unit.gen('militia', {
-			count: V.createdMilitiaUnits, killed: V.militiaTotalCasualties, squads: V.militiaUnits, free: V.militiaFreeManpower
-		});
-		if (jsDef(V.SecExp.defaultNames) && (V.SecExp.defaultNames.milita || V.SecExp.defaultNames.militia)) {
-			V.SecExp.units.militia.defaultName = V.SecExp.defaultNames.milita || V.SecExp.defaultNames.militia;
-			delete V.SecExp.defaultNames.milita; delete V.SecExp.defaultNames.militia;
-		}
+	App.SecExp.unit.gen('slaves', {count: V.createdSlavesUnits, killed: V.slavesTotalCasualties, squads: V.slaveUnits});
 
-		App.SecExp.unit.gen('mercs', {
-			count: V.createdMercUnits, killed: V.mercTotalCasualties, squads: V.mercUnits, free: V.mercFreeManpower
-		});
-		if (V.SecExp.units.mercs.free === 0) {
-			if (V.mercenaries === 1) {
-				V.SecExp.units.mercs.free = 15;
-			} else if (V.mercenaries > 1) {
-				V.SecExp.units.mercs.free = 30;
-			}
-		}
+	App.SecExp.unit.gen('militia', {
+		count: V.createdMilitiaUnits, killed: V.militiaTotalCasualties, squads: V.militiaUnits, free: V.militiaFreeManpower
+	});
+	if (jsDef(V.SecExp.defaultNames) && (V.SecExp.defaultNames.milita || V.SecExp.defaultNames.militia)) {
+		V.SecExp.units.militia.defaultName = V.SecExp.defaultNames.milita || V.SecExp.defaultNames.militia;
+		delete V.SecExp.defaultNames.milita; delete V.SecExp.defaultNames.militia;
+	}
 
-		for (const unit of App.SecExp.unit.list().slice(1)) {
-			for (const squad of V.SecExp.units[unit].squads) {
-				App.SecExp.unit.fixBroken(unit, squad);
-			}
+	App.SecExp.unit.gen('mercs', {
+		count: V.createdMercUnits, killed: V.mercTotalCasualties, squads: V.mercUnits, free: V.mercFreeManpower
+	});
+	if (V.SecExp.units.mercs.free === 0) {
+		if (V.mercenaries === 1) {
+			V.SecExp.units.mercs.free = 15;
+		} else if (V.mercenaries > 1) {
+			V.SecExp.units.mercs.free = 30;
 		}
+	}
 
-		if (V.SecExp.defaultNames) {
-			V.SecExp.units.slaves.defaultName = V.SecExp.defaultNames.slaves;
-			V.SecExp.units.mercs.defaultName = V.SecExp.defaultNames.mercs;
-			delete V.SecExp.defaultNames;
+	for (const unit of App.SecExp.unit.list().slice(1)) {
+		for (const squad of V.SecExp.units[unit].squads) {
+			App.SecExp.unit.fixBroken(unit, squad);
 		}
+	}
 
-		V.SecExp.smilingMan = V.SecExp.smilingMan || {};
-		V.SecExp.smilingMan.progress = V.SecExp.smilingMan.progress || V.smilingManProgress || 0;
-		if (jsDef(V.smilingManFate)) {
-			if (V.smilingManFate === 0) { // Offer $him a new life
-				V.SecExp.smilingMan.progress = 10;
-			} else if (V.smilingManFate === 1) { // Make $him pay
-				V.SecExp.smilingMan.progress = 20;
-			} else if (V.smilingManFate === 2) { // Enslave $him
-				V.SecExp.smilingMan.progress = 30;
-			}
-		}
+	if (V.SecExp.defaultNames) {
+		V.SecExp.units.slaves.defaultName = V.SecExp.defaultNames.slaves;
+		V.SecExp.units.mercs.defaultName = V.SecExp.defaultNames.mercs;
+		delete V.SecExp.defaultNames;
+	}
 
-		if (V.SecExp.smilingMan.progress === 4) {
+	V.SecExp.smilingMan.progress = V.SecExp.smilingMan.progress || V.smilingManProgress || 0;
+	if (jsDef(V.smilingManFate)) {
+		if (V.smilingManFate === 0) { // Offer $him a new life
 			V.SecExp.smilingMan.progress = 10;
-		} else if (V.SecExp.smilingMan.progress < 4) {
-			if (V.SecExp.smilingMan.progress === 0 && V.investedFunds) {
-				V.SecExp.smilingMan.investedFunds = V.investedFunds;
-			}
-			if (V.relationshipLM) {
-				V.SecExp.smilingMan.relationship = V.relationshipLM;
-			}
-			if (V.globalCrisisWeeks) {
-				V.SecExp.smilingMan.globalCrisisWeeks = V.globalCrisisWeeks;
-			}
+		} else if (V.smilingManFate === 1) { // Make $him pay
+			V.SecExp.smilingMan.progress = 20;
+		} else if (V.smilingManFate === 2) { // Enslave $him
+			V.SecExp.smilingMan.progress = 30;
 		}
+	}
 
-		V.SecExp.core = V.SecExp.core || {};
-		delete V.SecExp.core.crimeCap;
-
-		V.SecExp.core.trade = V.SecExp.core.trade || V.trade || 0;
-		App.SecExp.initTrade();
-
-		V.SecExp.core.authority = V.SecExp.core.authority || V.authority || 0;
-		V.SecExp.core.security = V.SecExp.core.security || V.security || 100;
-		if (jsDef(V.SecExp.security)) {
-			V.SecExp.core.security = V.SecExp.security.cap;
-			delete V.SecExp.security;
+	if (V.SecExp.smilingMan.progress === 4) {
+		V.SecExp.smilingMan.progress = 10;
+	} else if (V.SecExp.smilingMan.progress < 4) {
+		if (V.SecExp.smilingMan.progress === 0 && V.investedFunds) {
+			V.SecExp.smilingMan.investedFunds = V.investedFunds;
 		}
-		V.SecExp.core.totalKills = +V.SecExp.core.totalKills || V.totalKills || 0;
-
-		if (V.week === 1 || !jsDef(V.SecExp.core.crimeLow)) {
-			V.SecExp.core.crimeLow = 30;
+		if (V.relationshipLM) {
+			V.SecExp.smilingMan.relationship = V.relationshipLM;
 		}
-		V.SecExp.core.crimeLow = Math.clamp(V.SecExp.core.crimeLow, 0, 100);
-		if (V.crime) {
-			V.SecExp.core.crimeLow = V.crime;
+		if (V.globalCrisisWeeks) {
+			V.SecExp.smilingMan.globalCrisisWeeks = V.globalCrisisWeeks;
 		}
+	}
 
-		V.SecExp.battles = V.SecExp.battles || {};
-		V.SecExp.battles.slaveVictories = V.SecExp.battles.slaveVictories || V.slaveVictories || [];
-		V.SecExp.battles.major = V.SecExp.battles.major || 0;
-		if (jsDef(V.majorBattlesCount)) {
-			if (V.majorBattlesCount === 0 && V.hasFoughtMajorBattleOnce === 1) {
-				V.SecExp.battles.major = 1;
-			} else {
-				V.SecExp.battles.major = V.majorBattlesCount;
-			}
-		}
-		V.SecExp.battles.victories = V.SecExp.battles.victories || V.PCvictories || 0;
-		V.SecExp.battles.victoryStreak = V.SecExp.battles.victoryStreak || V.PCvictoryStreak || 0;
-		V.SecExp.battles.losses = V.SecExp.battles.losses || V.PClosses || 0;
-		V.SecExp.battles.lossStreak = V.SecExp.battles.lossStreak || V.PClossStreak || 0;
-		V.SecExp.battles.lastEncounterWeeks = V.SecExp.battles.lastEncounterWeeks || V.lastAttackWeeks || 0;
-		V.SecExp.battles.lastSelection = V.SecExp.battles.lastSelection || V.lastSelection || [];
-		V.SecExp.battles.saved = V.SecExp.battles.saved || {};
-		V.SecExp.battles.saved.commander = V.SecExp.battles.saved.commander || V.SavedLeader || "";
-		V.SecExp.battles.saved.sfSupport = V.SecExp.battles.saved.sfSupport || V.SavedSFI || 0;
-
-		V.SecExp.rebellions = V.SecExp.rebellions || {};
-		V.SecExp.rebellions.tension = V.SecExp.rebellions.tension || V.tension || 0;
-		V.SecExp.rebellions.slaveProgress = V.SecExp.rebellions.slaveProgress || V.slaveProgress || 0;
-		V.SecExp.rebellions.citizenProgress = V.SecExp.rebellions.citizenProgress || V.citizenProgress || 0;
-		V.SecExp.rebellions.victories = V.SecExp.rebellions.victories || V.PCrebWon || 0;
-		V.SecExp.rebellions.losses = V.SecExp.rebellions.losses || V.PCrebLoss || 0;
-		V.SecExp.rebellions.lastEncounterWeeks = V.SecExp.rebellions.lastEncounterWeeks || V.lastRebellionWeeks || 0;
-		if (V.SFGear) {
-			V.SecExp.rebellions.sfArmor = V.SFGear;
-		}
+	delete V.SecExp.core.crimeCap;
+	V.SecExp.core.trade = V.SecExp.core.trade || V.trade || 0;
+	App.SecExp.initTrade();
 
-		V.SecExp.settings.difficulty = V.SecExp.settings.difficulty || 1;
-		if (jsDef(V.difficulty)) {
-			V.SecExp.settings.difficulty = V.difficulty;
-		}
+	V.SecExp.core.authority = V.SecExp.core.authority || V.authority || 0;
+	V.SecExp.core.security = V.SecExp.core.security || V.security || 100;
+	if (jsDef(V.SecExp.security)) {
+		V.SecExp.core.security = V.SecExp.security.cap;
+		delete V.SecExp.security;
+	}
+	V.SecExp.core.totalKills = +V.SecExp.core.totalKills || V.totalKills || 0;
 
-		V.SecExp.settings.battle = V.SecExp.settings.battle || {};
-		if (!jsDef(V.SecExp.settings.battle.enabled)) {
-			V.SecExp.settings.battle.enabled = 1;
-		}
-		if (jsDef(V.battlesEnabled)) {
-			V.SecExp.settings.battle.enabled = V.battlesEnabled;
-		}
-		delete V.SecExp.battle;
+	if (V.week === 1 || !jsDef(V.SecExp.core.crimeLow)) {
+		V.SecExp.core.crimeLow = 30;
+	}
+	V.SecExp.core.crimeLow = Math.clamp(V.SecExp.core.crimeLow, 0, 100) || V.crime || 0;
 
-		V.SecExp.settings.battle.major = V.SecExp.settings.battle.major || {};
-		V.SecExp.settings.battle.frequency = V.SecExp.settings.battle.frequency || 1;
-		if (jsDef(V.battleFrequency)) {
-			V.SecExp.settings.battle.frequency = V.battleFrequency;
-		}
-		V.SecExp.settings.battle.force = V.SecExp.settings.battle.force || 0;
-		if (jsDef(V.forceBattle)) {
-			V.SecExp.settings.battle.force = V.forceBattle;
+	V.SecExp.battles.slaveVictories = V.SecExp.battles.slaveVictories || V.slaveVictories || [];
+	V.SecExp.battles.major = V.SecExp.battles.major || 0;
+	if (jsDef(V.majorBattlesCount)) {
+		if (V.majorBattlesCount === 0 && V.hasFoughtMajorBattleOnce === 1) {
+			V.SecExp.battles.major = 1;
+		} else {
+			V.SecExp.battles.major = V.majorBattlesCount;
 		}
+	}
+	V.SecExp.battles.victories = V.SecExp.battles.victories || V.PCvictories || 0;
+	V.SecExp.battles.victoryStreak = V.SecExp.battles.victoryStreak || V.PCvictoryStreak || 0;
+	V.SecExp.battles.losses = V.SecExp.battles.losses || V.PClosses || 0;
+	V.SecExp.battles.lossStreak = V.SecExp.battles.lossStreak || V.PClossStreak || 0;
+	V.SecExp.battles.lastEncounterWeeks = V.SecExp.battles.lastEncounterWeeks || V.lastAttackWeeks || 0;
+	V.SecExp.battles.lastSelection = V.SecExp.battles.lastSelection || V.lastSelection || [];
+	V.SecExp.battles.saved = V.SecExp.battles.saved || {};
+	V.SecExp.battles.saved.commander = V.SecExp.battles.saved.commander || V.SavedLeader || "";
+	V.SecExp.battles.saved.sfSupport = V.SecExp.battles.saved.sfSupport || V.SavedSFI || 0;
+
+	V.SecExp.rebellions.tension = V.SecExp.rebellions.tension || V.tension || 0;
+	V.SecExp.rebellions.slaveProgress = V.SecExp.rebellions.slaveProgress || V.slaveProgress || 0;
+	V.SecExp.rebellions.citizenProgress = V.SecExp.rebellions.citizenProgress || V.citizenProgress || 0;
+	V.SecExp.rebellions.victories = V.SecExp.rebellions.victories || V.PCrebWon || 0;
+	V.SecExp.rebellions.losses = V.SecExp.rebellions.losses || V.PCrebLoss || 0;
+	V.SecExp.rebellions.lastEncounterWeeks = V.SecExp.rebellions.lastEncounterWeeks || V.lastRebellionWeeks || 0;
+	if (V.SFGear) {
+		V.SecExp.rebellions.sfArmor = V.SFGear;
+	}
 
-		if (V.readiness && V.readiness === 10 || V.sectionInFirebase) {
-			V.SecExp.sectionInFirebase = 1;
-		}
+	V.SecExp.settings.difficulty = V.SecExp.settings.difficulty || 1;
+	if (jsDef(V.difficulty)) {
+		V.SecExp.settings.difficulty = V.difficulty;
+	}
 
-		V.SecExp.settings.unitDescriptions = V.SecExp.settings.unitDescriptions || 0;
+	if (!jsDef(V.SecExp.settings.battle.enabled)) {
+		V.SecExp.settings.battle.enabled = 1;
+	}
+	if (jsDef(V.battlesEnabled)) {
+		V.SecExp.settings.battle.enabled = V.battlesEnabled;
+	}
+	delete V.SecExp.battle;
 
-		if (!jsDef(V.SecExp.settings.battle.allowSlavePrestige)) {
-			V.SecExp.settings.battle.allowSlavePrestige = 1;
-		}
-		if (jsDef(V.allowPrestigeFromBattles)) {
-			V.SecExp.settings.battle.allowSlavePrestige = V.allowPrestigeFromBattles;
-		}
+	V.SecExp.settings.battle.frequency = V.SecExp.settings.battle.frequency || 1;
+	if (jsDef(V.battleFrequency)) {
+		V.SecExp.settings.battle.frequency = V.battleFrequency;
+	}
+	V.SecExp.settings.battle.force = V.SecExp.settings.battle.force || 0;
+	if (jsDef(V.forceBattle)) {
+		V.SecExp.settings.battle.force = V.forceBattle;
+	}
 
-		V.SecExp.settings.battle.major.enabled = V.SecExp.settings.battle.major.enabled || 0;
-		if (jsDef(V.majorBattlesEnabled)) {
-			V.SecExp.settings.battle.major.enabled = V.majorBattlesEnabled;
-		}
+	if (V.readiness && V.readiness === 10 || V.sectionInFirebase) {
+		V.SecExp.sectionInFirebase = 1;
+	}
 
-		if (!jsDef(V.SecExp.settings.battle.major.gameOver)) {
-			V.SecExp.settings.battle.major.gameOver = 1;
-		}
-		if (jsDef(V.majorBattleGameOver)) {
-			V.SecExp.settings.battle.major.gameOver = V.majorBattleGameOver;
-		}
-		V.SecExp.settings.battle.major.force = V.SecExp.settings.battle.major.force || 0;
-		if (jsDef(V.forceMajorBattle)) {
-			V.SecExp.settings.battle.major.force = V.forceMajorBattle;
-		}
-		V.SecExp.settings.battle.major.mult = V.SecExp.settings.battle.major.mult || 1;
+	V.SecExp.settings.unitDescriptions = V.SecExp.settings.unitDescriptions || 0;
 
-		V.SecExp.settings.rebellion = V.SecExp.settings.rebellion || {};
-		if (!jsDef(V.SecExp.settings.rebellion.enabled)) {
-			V.SecExp.settings.rebellion.enabled = 1;
-		}
-		if (jsDef(V.rebellionsEnabled)) {
-			V.SecExp.settings.rebellion.enabled = V.rebellionsEnabled;
-		}
+	if (!jsDef(V.SecExp.settings.battle.allowSlavePrestige)) {
+		V.SecExp.settings.battle.allowSlavePrestige = 1;
+	}
+	if (jsDef(V.allowPrestigeFromBattles)) {
+		V.SecExp.settings.battle.allowSlavePrestige = V.allowPrestigeFromBattles;
+	}
 
-		V.SecExp.settings.rebellion.force = V.SecExp.settings.rebellion.force || 0;
-		if (jsDef(V.forceRebellion)) {
-			V.SecExp.settings.rebellion.force = V.forceRebellion;
-		}
-		if (!jsDef(V.SecExp.settings.rebellion.gameOver)) {
-			V.SecExp.settings.rebellion.gameOver = 1;
-		}
-		if (jsDef(V.rebellionGameOver)) {
-			V.SecExp.settings.rebellion.gameOver = V.rebellionGameOver;
-		}
+	V.SecExp.settings.battle.major.enabled = V.SecExp.settings.battle.major.enabled || 0;
+	if (jsDef(V.majorBattlesEnabled)) {
+		V.SecExp.settings.battle.major.enabled = V.majorBattlesEnabled;
+	}
 
-		V.SecExp.settings.rebellion.speed = V.SecExp.settings.rebellion.speed || 1;
-		if (jsDef(V.rebellionSpeed)) {
-			V.SecExp.settings.rebellion.speed = V.rebellionSpeed;
-		}
+	if (!jsDef(V.SecExp.settings.battle.major.gameOver)) {
+		V.SecExp.settings.battle.major.gameOver = 1;
+	}
+	if (jsDef(V.majorBattleGameOver)) {
+		V.SecExp.settings.battle.major.gameOver = V.majorBattleGameOver;
+	}
+	V.SecExp.settings.battle.major.force = V.SecExp.settings.battle.major.force || 0;
+	if (jsDef(V.forceMajorBattle)) {
+		V.SecExp.settings.battle.major.force = V.forceMajorBattle;
+	}
+	V.SecExp.settings.battle.major.mult = V.SecExp.settings.battle.major.mult || 1;
 
-		V.SecExp.settings.showStats = V.SecExp.settings.showStats || 0;
-		if (jsDef(V.showBattleStatistics)) {
-			V.SecExp.settings.showStats = V.showBattleStatistics;
-		}
+	if (!jsDef(V.SecExp.settings.rebellion.enabled)) {
+		V.SecExp.settings.rebellion.enabled = 1;
+	}
+	if (jsDef(V.rebellionsEnabled)) {
+		V.SecExp.settings.rebellion.enabled = V.rebellionsEnabled;
+	}
 
-		V.SecExp.buildings = V.SecExp.buildings || {};
-		App.SecExp.propHub.BC();
-		App.SecExp.barracks.BC();
-		App.SecExp.secHub.BC();
-		App.SecExp.transportHub.BC();
-		App.SecExp.riotCenter.BC();
-		App.SecExp.weapManu.BC();
-
-		V.SecExp.proclamation = V.SecExp.proclamation || {};
-		V.SecExp.proclamation.cooldown = V.SecExp.proclamation.cooldown || V.proclamationsCooldown || 0;
-		V.SecExp.proclamation.currency = V.SecExp.proclamation.currency || V.proclamationCurrency || "";
-		V.SecExp.proclamation.type = V.SecExp.proclamation.type || "crime";
-		if (jsDef(V.proclamationType) && V.proclamationType !== "none") {
-			V.SecExp.proclamation.type = V.proclamationType;
-		}
-		/*
-		V.SecExp.rebellions.repairTime = V.SecExp.rebellions.repairTime || {};
-		V.SecExp.rebellions.repairTime.waterway = V.SecExp.rebellions.repairTime.waterway || 0;
-		V.SecExp.rebellions.repairTime.assistant = V.SecExp.rebellions.repairTime.assistant || 0;
-		V.SecExp.rebellions.repairTime.reactor = V.SecExp.rebellions.repairTime.reactor || 0;
-		V.SecExp.rebellions.repairTime.arc = V.SecExp.rebellions.repairTime.arc || 0;
-		if (jsDef(V.garrison)) {
-			V.SecExp.rebellions.repairTime.waterway = V.garrison.waterwayTime;
-			V.SecExp.rebellions.repairTime.assistant = V.garrison.assistantTime;
-			V.SecExp.rebellions.repairTime.reactor = V.garrison.reactorTime;
-			V.SecExp.rebellions.repairTime.arc = V.arcRepairTime;
-		}
-		*/
+	V.SecExp.settings.rebellion.force = V.SecExp.settings.rebellion.force || 0;
+	if (jsDef(V.forceRebellion)) {
+		V.SecExp.settings.rebellion.force = V.forceRebellion;
+	}
+	if (!jsDef(V.SecExp.settings.rebellion.gameOver)) {
+		V.SecExp.settings.rebellion.gameOver = 1;
+	}
+	if (jsDef(V.rebellionGameOver)) {
+		V.SecExp.settings.rebellion.gameOver = V.rebellionGameOver;
 	}
 
-	delete V.SecExp.security;
+	V.SecExp.settings.rebellion.speed = V.SecExp.settings.rebellion.speed || 1;
+	if (jsDef(V.rebellionSpeed)) {
+		V.SecExp.settings.rebellion.speed = V.rebellionSpeed;
+	}
+
+	V.SecExp.settings.showStats = V.SecExp.settings.showStats || 0;
+	if (jsDef(V.showBattleStatistics)) {
+		V.SecExp.settings.showStats = V.showBattleStatistics;
+	}
+
+	App.SecExp.propHub.BC();
+	App.SecExp.barracks.BC();
+	App.SecExp.secHub.BC();
+	App.SecExp.transportHub.BC();
+	App.SecExp.riotCenter.BC();
+	App.SecExp.weapManu.BC();
+
+	V.SecExp.proclamation.cooldown = V.SecExp.proclamation.cooldown || V.proclamationsCooldown || 0;
+	V.SecExp.proclamation.currency = V.SecExp.proclamation.currency || V.proclamationCurrency || "";
+	V.SecExp.proclamation.type = V.SecExp.proclamation.type || "crime";
+	if (jsDef(V.proclamationType) && V.proclamationType !== "none") {
+		V.SecExp.proclamation.type = V.proclamationType;
+	}
+	/*
+	V.SecExp.rebellions.repairTime = V.SecExp.rebellions.repairTime || {};
+	V.SecExp.rebellions.repairTime.waterway = V.SecExp.rebellions.repairTime.waterway || 0;
+	V.SecExp.rebellions.repairTime.assistant = V.SecExp.rebellions.repairTime.assistant || 0;
+	V.SecExp.rebellions.repairTime.reactor = V.SecExp.rebellions.repairTime.reactor || 0;
+	V.SecExp.rebellions.repairTime.arc = V.SecExp.rebellions.repairTime.arc || 0;
+	if (jsDef(V.garrison)) {
+		V.SecExp.rebellions.repairTime.waterway = V.garrison.waterwayTime;
+		V.SecExp.rebellions.repairTime.assistant = V.garrison.assistantTime;
+		V.SecExp.rebellions.repairTime.reactor = V.garrison.reactorTime;
+		V.SecExp.rebellions.repairTime.arc = V.arcRepairTime;
+	}
+	*/
+	delete V.SecExp.settings.show;
 };
diff --git a/src/gui/options/options.js b/src/gui/options/options.js
index 2b7d4233282..0afef7bc208 100644
--- a/src/gui/options/options.js
+++ b/src/gui/options/options.js
@@ -437,7 +437,8 @@ App.UI.optionsPassage = function() {
 			.addComment("<div>This mod is triggered after week 72. It is non-canon where it conflicts with canonical updates to the base game.</div>");
 
 		options.addOption("The Security Expansion mod is", "secExpEnabled")
-			.addValue("Enabled", 1).on().addValue("Disabled", 0).off()
+			.addValue("Enabled", 1).on().addCallback(() => App.SecExp.generalBC())
+			.addValue("Disabled", 0).off()
 			.addComment("<div>The mod can be activated in any moment, but it may result in unbalanced gameplay if activated very late in the game.</div>");
 
 		options.addOption("Catmod is currently", "seeCats")
@@ -447,13 +448,9 @@ App.UI.optionsPassage = function() {
 		el.append(options.render());
 
 		if (V.secExpEnabled > 0) {
-			if (Object.values(V.SecExp).length === 0) {
-				App.SecExp.generalBC();
-				Engine.play("Options");
-			}
 			App.UI.DOM.appendNewElement("h2", el, `Security Expansion mod options`);
 			if (V.terrain === "oceanic") {
-				App.UI.DOM.appendNewElement("div", el, `Oceanic arcologies are not by default subject to external attacks. You can however allow them to happen anyway. If you choose to do so please keep in mind that descriptions and mechanics are not intended for naval combat but land combat.`);
+				App.UI.DOM.appendNewElement("div", el, `Oceanic arcologies are not by default subject to external attacks. You can however allow them to happen anyway. If you choose to do so please keep in mind that descriptions and mechanics are intended for land combat.`);
 			}
 			options = new App.UI.OptionsGroup();
 
-- 
GitLab