From cdd65eb65d5969b5c82abfc9f5adfb7b9565a4e7 Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Fri, 23 Oct 2020 14:18:32 -0700
Subject: [PATCH] Move tradeReport to JS and reconnect it.

---
 src/Mods/SecExp/js/tradeReport.js | 165 ++++++++++++++++++++++++++++++
 src/Mods/SecExp/tradeReport.tw    | 158 ----------------------------
 src/endWeek/economics/arcmgmt.js  |  17 +--
 3 files changed, 175 insertions(+), 165 deletions(-)
 create mode 100644 src/Mods/SecExp/js/tradeReport.js
 delete mode 100644 src/Mods/SecExp/tradeReport.tw

diff --git a/src/Mods/SecExp/js/tradeReport.js b/src/Mods/SecExp/js/tradeReport.js
new file mode 100644
index 00000000000..ef4a95debe3
--- /dev/null
+++ b/src/Mods/SecExp/js/tradeReport.js
@@ -0,0 +1,165 @@
+App.SecExp.tradeReport = function() {
+	let r = [];
+	let tradeChange = 0;
+
+	if (V.week < 30) {
+		r.push(`The world economy is in good enough shape to sustain economic growth. Trade flows liberally in all the globe.`);
+		tradeChange += 1;
+	} else if (V.week < 60) {
+		r.push(`The world economy is deteriorating, but still in good enough shape to sustain economic growth.`);
+		tradeChange += 0.5;
+	} else if (V.week < 90) {
+		r.push(`The world economy is deteriorating, but still in decent enough shape to sustain economic growth.`);
+	} else if (V.week < 120) {
+		r.push(`The world economy is deteriorating and the slowing down of global growth is starting to have some effect on trade flow.`);
+		tradeChange -= 1;
+	} else {
+		r.push(`The world economy is heavily deteriorated. The slowing down of global growth has a great negative effect on trade flow.`);
+		tradeChange -= 2;
+	}
+
+	const countBattles = V.SecExp.battles.victories + V.SecExp.battles.losses;
+	const countRebellions = V.SecExp.rebellions.victories + V.SecExp.rebellions.losses;
+	if (V.SecExp.battles.lastEncounterWeeks < 2 && countBattles > 0) {
+		r.push(`The recent attack has a negative effect on the trade of the arcology.`);
+		tradeChange -= 1;
+	} else if (V.SecExp.battles.lastEncounterWeeks < 4 && countBattles > 0) {
+		r.push(`While some time has passed, the last attack still has a negative effect on the commercial activity of the arcology.`);
+		tradeChange -= 0.5;
+	}
+	if (V.SecExp.rebellions.lastEncounterWeeks < 2 && countRebellions > 0) {
+		r.push(`The recent rebellion has a negative effect on the trade of the arcology.`);
+		tradeChange -= 1;
+	} else if (V.SecExp.rebellions.lastEncounterWeeks < 4 && countRebellions > 0) {
+		r.push(`While some time has passed, the last rebellion still has a negative effect on the commercial activity of the arcology.`);
+		tradeChange -= 0.5;
+	}
+
+	if (V.terrain === "urban") {
+		r.push(`Since your arcology is located in the heart of an urban area, its commerce is naturally vibrant.`);
+		tradeChange++;
+	}
+	if (V.terrain === "ravine") {
+		r.push(`Since your arcology is located in the heart of a ravine, its commerce is hindered by a lack of accessibility.`);
+		tradeChange -= 0.5;
+	}
+
+	if (V.PC.career === "wealth" || V.PC.career === "capitalist" || V.PC.career === "celebrity" || V.PC.career === "BlackHat") {
+		tradeChange += 1;
+	} else if (V.PC.career === "escort" || V.PC.career === "servant" || V.PC.career === "gang") {
+		tradeChange -= 0.5;
+	}
+
+	if (V.rep > 18000) {
+		r.push(`Your extremely high reputation attracts trade from all over the world.`);
+	} else if (V.rep > 12000) {
+		r.push(`Your high reputation attracts trade from all over the world.`);
+	}
+
+	const {himA} = getPronouns(assistant.pronouns().main).appendSuffix('A');
+	if (V.assistant.power === 1) {
+		r.push(`Thanks to the computing power available to ${himA}, ${V.assistant.name} is able to guide the commercial development of the arcology to greater levels.`);
+		tradeChange++;
+	} else if (V.assistant.power >= 2) {
+		r.push(`Thanks to the incredible computing power available to ${himA}, ${V.assistant.name} is able to guide the commercial development of the arcology to greater levels.`);
+		tradeChange += 2;
+	}
+
+	if (V.SecExp.edicts.tradeLegalAid === 1) {
+		r.push(`Your support in legal matters for new businesses helps improve the economic dynamicity of your arcology, boosting commercial activities.`);
+		tradeChange += 1;
+	}
+
+	if (V.SecExp.edicts.taxTrade === 1) {
+		r.push(`The fees imposed on transitioning goods do little to earn you the favor of the companies making use of your arcology.`);
+		tradeChange -= 1;
+	}
+
+	if (V.SecExp.buildings.weapManu) {
+		r.push(`The weapons manufacturing facility of the arcology attracts a significant amount of trade.`);
+		tradeChange += 0.5 * (V.SecExp.buildings.weapManu.productivity + V.SecExp.buildings.weapManu.lab);
+	}
+	if (V.SecExp.buildings.transportHub) {
+		if (V.SecExp.buildings.transportHub.airport === 1) {
+			r.push(`The airport, while small, helps facilitate the commercial development of the arcology.`);
+			tradeChange += 1;
+		} else if (V.SecExp.buildings.transportHub.airport === 2) {
+			r.push(`The airport, while fairly small, helps facilitate the commercial development of the arcology.`);
+			tradeChange += 1.5;
+		} else if (V.SecExp.buildings.transportHub.airport === 3) {
+			r.push(`The airport helps facilitate the commercial development of the arcology.`);
+			tradeChange += 2;
+		} else if (V.SecExp.buildings.transportHub.airport === 4) {
+			r.push(`The airport is a great boon to the commercial development of the arcology.`);
+			tradeChange += 2.5;
+		} else {
+			r.push(`The airport is an incredible boon to the commercial development of the arcology.`);
+			tradeChange += 3;
+		}
+
+		if (V.terrain !== "oceanic" && V.terrain !== "marine") {
+			if (V.SecExp.buildings.transportHub.surfaceTransport === 1) {
+				r.push(`The railway network's age and limited extension limit commercial activity.`);
+			} else if (V.SecExp.buildings.transportHub.surfaceTransport === 2) {
+				r.push(`The railway network is a great help to the commercial development of the arcology, but its limited extension hampers its potential.`);
+				tradeChange += 1;
+			} else if (V.SecExp.buildings.transportHub.surfaceTransport === 3) {
+				r.push(`The railway network is a great help to the commercial development of the arcology.`);
+				tradeChange += 1.5;
+			} else {
+				r.push(`The railway network is a huge help to the commercial development of the arcology. Few in the world can boast such a modern and efficient transport system.`);
+				tradeChange += 2;
+			}
+		} else {
+			if (V.SecExp.buildings.transportHub.surfaceTransport === 1) {
+				r.push(`The docks' age and limited size limit commercial activity.`);
+			} else if (V.SecExp.buildings.transportHub.surfaceTransport === 2) {
+				r.push(`The docks are a great help to the commercial development of the arcology, but their limited size hampers its potential.`);
+				tradeChange += 1;
+			} else if (V.SecExp.buildings.transportHub.surfaceTransport === 3) {
+				r.push(`The docks are a great help to the commercial development of the arcology.`);
+				tradeChange += 1.5;
+			} else {
+				r.push(`The docks are a huge help to the commercial development of the arcology. Few in the world can boast such a modern and efficient transport system.`);
+				tradeChange += 2;
+			}
+		}
+	}
+
+	const SFsize = App.SF.upgrades.total();
+	if (V.SF.Toggle && V.SF.Active >= 1 && SFsize > 10) {
+		r.push(`Having a powerful special force increases trade security.`);
+		tradeChange += SFsize / 10;
+	}
+
+	if (tradeChange > 0) {
+		r.push(`This week <span class="green">trade improved.</span>`);
+	} else if (tradeChange === 0) {
+		r.push(`This week <span class="yellow">trade did not change.</span>`);
+	} else {
+		r.push(`This week <span class="red">trade diminished.</span>`);
+	}
+
+	V.SecExp.core.trade = Math.clamp(V.SecExp.core.trade + tradeChange, 0, 100);
+
+	let AWeekGrowth = 0;
+	if (V.SecExp.core.trade <= 20) {
+		r.push(`The almost non-existent trade crossing the arcology <span class="yellow">does little to promote growth.</span>`);
+	} else if (V.SecExp.core.trade <= 40) {
+		r.push(`The low level of trade crossing the arcology promotes a <span class="green">slow yet steady growth</span> of its economy.`);
+		AWeekGrowth += 1.5;
+	} else if (V.SecExp.core.trade <= 60) {
+		r.push(`With trade at positive levels, the <span class="green">prosperity of the arcology grows more powerful.</span>`);
+		AWeekGrowth += 2.5;
+	} else if (V.SecExp.core.trade <= 80) {
+		r.push(`With trade at high levels, the <span class="green">prosperity of the arcology grows quickly and violently.</span>`);
+		AWeekGrowth += 3.5;
+	} else {
+		r.push(`With trade at extremely high levels, the <span class="green">prosperity of the arcology grows with unprecedented speed.</span>`);
+		AWeekGrowth += 4.5;
+	}
+
+	const para = document.createElement("p");
+	$(para).append(r.join(' '));
+	return {output: para, growth: AWeekGrowth};
+};
diff --git a/src/Mods/SecExp/tradeReport.tw b/src/Mods/SecExp/tradeReport.tw
deleted file mode 100644
index 266aa0a62f7..00000000000
--- a/src/Mods/SecExp/tradeReport.tw
+++ /dev/null
@@ -1,158 +0,0 @@
-:: tradeReport [nobr]
-
-<<if $week < 30>>
-	The world economy is in good enough shape to sustain economic growth. Trade flows liberally in all the globe.
-	<<set _tradeChange += 1>>
-<<elseif $week < 60>>
-	The world economy is deteriorating, but still in good enough shape to sustain economic growth.
-	<<set _tradeChange += 0.5>>
-<<elseif $week < 90>>
-	The world economy is deteriorating, but still in decent enough shape to sustain economic growth.
-<<elseif $week < 120>>
-	The world economy is deteriorating and the slowing down of global growth is starting to have some effect on trade flow.
-	<<set _tradeChange -= 1>>
-<<else>>
-	The world economy is heavily deteriorated. The slowing down of global growth has a great negative effect on trade flow.
-	<<set _tradeChange -= 2>>
-<</if>>
-
-<<set _tradeChange = 0>>
-<<set _countBattles = $SecExp.battles.victories + $SecExp.battles.losses>>
-<<set _countRebellions = $SecExp.rebellions.victories + $SecExp.rebellions.losses>>
-<<if $SecExp.battles.lastEncounterWeeks < 2 && _countBattles > 0>>
-	The recent attack has a negative effect on the trade of the arcology.
-	<<set _tradeChange -= 1>>
-<<elseif $SecExp.battles.lastEncounterWeeks < 4 && _countBattles > 0>>
-	While some time has passed, the last attack still has a negative effect on the commercial activity of the arcology.
-	<<set _tradeChange -= 0.5>>
-<</if>>
-<<if $SecExp.rebellions.lastEncounterWeeks < 2 && _countRebellions > 0>>
-	The recent rebellion has a negative effect on the trade of the arcology.
-	<<set _tradeChange -= 1>>
-<<elseif $SecExp.rebellions.lastEncounterWeeks < 4 && _countRebellions > 0>>
-	While some time has passed, the last rebellion still has a negative effect on the commercial activity of the arcology.
-	<<set _tradeChange -= 0.5>>
-<</if>>
-
-<<if $terrain == "urban">>
-	Since your arcology is located in the heart of an urban area, its commerce is naturally vibrant.
-	<<set _tradeChange++>>
-<</if>>
-<<if $terrain == "ravine">>
-	Since your arcology is located in the heart of a ravine, its commerce is hindered by a lack of accessibility.
-	<<set _tradeChange -= 0.5>>
-<</if>>
-
-<<if $PC.career == "wealth" || $PC.career == "capitalist" || $PC.career == "celebrity" || $PC.career == "BlackHat">>
-	<<set _tradeChange += 1>>
-<<elseif $PC.career == "escort" || $PC.career == "servant" || $PC.career == "gang">>
-	<<set _tradeChange -= 0.5>>
-<</if>>
-
-<<if $rep > 18000>>
-	Your extremely high reputation attracts trade from all over the world.
-<<elseif $rep > 12000>>
-	Your high reputation attracts trade from all over the world.
-<</if>>
-
-<<setAssistantPronouns>>
-<<if $assistant.power == 1>>
-	Thanks to the computing power available to _himA, $assistant.name is able to guide the commercial development of the arcology to greater levels.
-	<<set _tradeChange++>>
-<<elseif $assistant.power >= 2>>
-	Thanks to the incredible computing power available to _himA, $assistant.name is able to guide the commercial development of the arcology to greater levels.
-	<<set _tradeChange += 2>>
-<</if>>
-
-<<if $SecExp.edicts.tradeLegalAid == 1>>
-	Your support in legal matters for new businesses helps improve the economic dynamicity of your arcology, boosting commercial activities.
-	<<set _tradeChange += 1>>
-<</if>>
-
-<<if $SecExp.edicts.taxTrade == 1>>
-	The fees imposed on transitioning goods do little to earn you the favor of the companies making use of your arcology.
-	<<set _tradeChange -= 1>>
-<</if>>
-
-<<if $SecExp.buildings.weapManu>>
-	The weapons manufacturing facility of the arcology attracts a significant amount of trade.
-	<<set _tradeChange += 0.5 * ($SecExp.buildings.weapManu.productivity + $SecExp.buildings.weapManu.lab)>>
-<</if>>
-<<if $SecExp.buildings.transportHub>>
-	<<if $SecExp.buildings.transportHub.airport == 1>>
-		The airport, while small, helps facilitate the commercial development of the arcology.
-		<<set _tradeChange += 1>>
-	<<elseif $SecExp.buildings.transportHub.airport == 2>>
-		The airport, while fairly small, helps facilitate the commercial development of the arcology.
-		<<set _tradeChange += 1.5>>
-	<<elseif $SecExp.buildings.transportHub.airport == 3>>
-		The airport helps facilitate the commercial development of the arcology.
-		<<set _tradeChange += 2>>
-	<<elseif $SecExp.buildings.transportHub.airport == 4>>
-		The airport is a great boon to the commercial development of the arcology.
-		<<set _tradeChange += 2.5>>
-	<<else>>
-		The airport is an incredible boon to the commercial development of the arcology.
-		<<set _tradeChange += 3>>
-	<</if>>
-
-	<<if $terrain != "oceanic" && $terrain != "marine">>
-		<<if $SecExp.buildings.transportHub.surfaceTransport == 1>>
-			The railway network's age and limited extension limit commercial activity.
-		<<elseif $SecExp.buildings.transportHub.surfaceTransport == 2>>
-			The railway network is a great help to the commercial development of the arcology, but its limited extension hampers its potential.
-			<<set _tradeChange += 1>>
-		<<elseif $SecExp.buildings.transportHub.surfaceTransport == 3>>
-			The railway network is a great help to the commercial development of the arcology.
-			<<set _tradeChange += 1.5>>
-		<<else>>
-			The railway network is a huge help to the commercial development of the arcology. Few in the world can boast such a modern and efficient transport system.
-			<<set _tradeChange += 2>>
-		<</if>>
-	<<else>>
-		<<if $SecExp.buildings.transportHub.surfaceTransport == 1>>
-			The docks' age and limited size limit commercial activity.
-		<<elseif $SecExp.buildings.transportHub.surfaceTransport == 2>>
-			The docks are a great help to the commercial development of the arcology, but their limited size hampers its potential.
-			<<set _tradeChange += 1>>
-		<<elseif $SecExp.buildings.transportHub.surfaceTransport == 3>>
-			The docks are a great help to the commercial development of the arcology.
-			<<set _tradeChange += 1.5>>
-		<<else>>
-			The docks are a huge help to the commercial development of the arcology. Few in the world can boast such a modern and efficient transport system.
-			<<set _tradeChange += 2>>
-		<</if>>
-	<</if>>
-<</if>>
-
-<<set _size = App.SF.upgrades.total()>>
-<<if $SF.Toggle && $SF.Active >= 1 && _size > 10>>
-	Having a powerful special force increases trade security.
-	<<set _tradeChange += _size/10>>
-<</if>>
-
-<<if _tradeChange > 0>>
-	This week @@.green;trade improved.@@
-<<elseif _tradeChange == 0>>
-	This week @@.yellow;trade did not change.@@
-<<else>>
-	This week @@.red;trade diminished.@@
-<</if>>
-
-<<if $SecExp.core.trade <= 20>>
-	The almost non-existent trade crossing the arcology @@.yellow;does little to promote growth.@@
-<<elseif $SecExp.core.trade <= 40>>
-	The low level of trade crossing the arcology promotes a @@.green;slow yet steady growth@@ of its economy.
-	<<set _AWeekGrowth += 1.5>>
-<<elseif $SecExp.core.trade <= 60>>
-	With trade at positive levels, the @@.green;prosperity of the arcology grows more powerful.@@
-	<<set _AWeekGrowth += 2.5>>
-<<elseif $SecExp.core.trade <= 80>>
-	With trade at high levels, the @@.green;prosperity of the arcology grows quickly and violently.@@
-	<<set _AWeekGrowth += 3.5>>
-<<else>>
-	With trade at extremely high levels, the @@.green;prosperity of the arcology grows with unprecedented speed.@@
-	<<set _AWeekGrowth += 4.5>>
-<</if>>
-
-<<set $SecExp.core.trade = Math.clamp($SecExp.core.trade + _tradeChange,0,100)>>
diff --git a/src/endWeek/economics/arcmgmt.js b/src/endWeek/economics/arcmgmt.js
index 8d48c579fd0..0713a4fa670 100644
--- a/src/endWeek/economics/arcmgmt.js
+++ b/src/endWeek/economics/arcmgmt.js
@@ -631,23 +631,26 @@ globalThis.arcmgmt = function() {
 		} else {
 			r.push(`Though ${V.arcologies[0].name} can support more citizens and more activity, <span class="red">it lost prosperity this week.</span>`);
 		}
-		if (isNaN(_AWeekGrowth)) {
-			r.push(App.UI.DOM.makeElement("div", `Error: AWeekGrowth is NaN`, "red"));
-		} else {
-			V.arcologies[0].prosperity += _AWeekGrowth;
-		}
 
 		App.Events.addNode(el, r);
 		r = [];
+
 		if (V.secExpEnabled > 0) {
-			App.UI.DOM.appendNewElement("p", el, App.UI.DOM.renderPassage("tradeReport"));
+			const {output, growth} = App.SecExp.tradeReport();
+			_AWeekGrowth += growth;
+			el.append(output);
+		}
+
+		if (isNaN(_AWeekGrowth)) {
+			r.push(App.UI.DOM.makeElement("div", `Error: AWeekGrowth is NaN`, "red"));
+		} else {
+			V.arcologies[0].prosperity += _AWeekGrowth;
 		}
 
 		if (_schools > 0) {
 			el.append(schools());
 		}
 
-
 		if (V.assistant.market && V.assistant.market.limit > 0) {
 			let _popCap = menialPopCap();
 			let _menialSlaveValue = menialSlaveCost();
-- 
GitLab