From 141ddce9676d66c12258c9789e7def86ece21384 Mon Sep 17 00:00:00 2001
From: lowercasedonkey <lowercasedonkey@gmail.com>
Date: Wed, 10 Mar 2021 21:39:30 -0500
Subject: [PATCH] rival victory conversion

---
 src/005-passages/eventsPassages.js  |   8 ++
 src/events/story/pRivalryVictory.js | 172 ++++++++++++++++++++++++++++
 src/events/story/pRivalryVictory.tw | 150 ------------------------
 3 files changed, 180 insertions(+), 150 deletions(-)
 create mode 100644 src/events/story/pRivalryVictory.js
 delete mode 100644 src/events/story/pRivalryVictory.tw

diff --git a/src/005-passages/eventsPassages.js b/src/005-passages/eventsPassages.js
index c3b3a5fca91..ceae37127d8 100644
--- a/src/005-passages/eventsPassages.js
+++ b/src/005-passages/eventsPassages.js
@@ -110,3 +110,11 @@ new App.DomPassage("P rivalry actions",
 		return App.Events.pRivalryActions();
 	}
 );
+
+new App.DomPassage("P rivalry victory",
+	() => {
+		V.nextButton = "Continue";
+		V.nextLink = "Random Nonindividual Event";
+		return App.Events.pRivalryVictory();
+	}
+);
diff --git a/src/events/story/pRivalryVictory.js b/src/events/story/pRivalryVictory.js
new file mode 100644
index 00000000000..8c994045356
--- /dev/null
+++ b/src/events/story/pRivalryVictory.js
@@ -0,0 +1,172 @@
+App.Events.pRivalryVictory = function() {
+	return execute();
+
+	function execute() {
+		const node = new DocumentFragment();
+		const {
+			HisR, HeR,
+			hisR, heR
+		} = getPronouns({pronoun: (V.rivalGender === 2) ? 1 : 0}).appendSuffix("R");
+		V.nextButton = " "; // hide button until user makes a selection
+		V.rivalOwner = 0;
+		V.rivalryPower = 0;
+		V.rivalRace = 0;
+
+		App.Events.addParagraph(node, [`For the first time, you receive a direct call from your rival. You pictured the moment as feeling grander than this, sitting at your desk as usual looking into ${hisR} downcast face. You're the victor in a new form of warfare in which bankruptcy has replaced surrender. If the world survives in its present state, you may one day be remembered as an innovator in the evolution of (nearly) bloodless war. Today, your reputation has <span class="green">greatly improved.</span> But today all you have that's tangible is a view of a still-dignified arcology owner, self-possessed despite the situation.`]);
+
+		App.UI.DOM.appendNewElement("p", node, `"For what it's worth," ${heR} says without preamble, "I had nothing against you. The Daughters wouldn't accept a straight buy-off. Their leadership needed a target to attack, or the rank and file would have killed them themselves and gone ahead attacking me. I had to give them an alternative, or it would have been me." ${HeR} looks nervous for the first time. "So, what do we do now? I've still got enough resources to make the end of this story a messy one for you. Let me go, and I won't. I'll walk away, and I'll sign everything I've got left over to you.${(V.hostageAnnounced === 1 && V.hostage) ? ` Including ${V.hostage.slaveName}, of course.` : ``}`);
+
+		const result = App.UI.DOM.appendNewElement("div", node);
+
+		App.UI.DOM.appendNewElement("div", result, App.UI.DOM.link(
+			`Accept`,
+			() => {
+				const el = new DocumentFragment();
+				const r = [];
+				V.nextButton = "Continue";
+				App.Utils.updateUserButton();  // unlock Continue button
+				r.push(`You accept, magnanimous in victory. "I don't think I would have done that," your rival replies. "Thank you. When they write the book, I'll make sure you look good."`);
+				if (V.rivalSet !== 0) {
+					r.push(`${HisR} remaining liquid assets will go to satisfy ${hisR} great debts, but ${hisR} <span class="yellowgreen">arcology holdings are yours.</span>`);
+					for (const arc of V.arcologies) {
+						if (arc.rival === 1) {
+							arc.embargo = 0;
+							arc.embargoTarget = -1;
+							arc.influenceTarget = -1;
+							arc.rival = 0;
+							arc.government = "direct democracy";
+							arc.PCminority += arc.ownership;
+							arc.PCminority = Math.clamp(arc.PCminority, 0, 49);
+							break;
+						}
+					}
+					if (V.hostageAnnounced === 1) {
+						V.hostageRescued = 1;
+					}
+				} else {
+					r.push(`_HisR arcology will go to satisfy _hisR great debts, but you will still profit <span class="yellowgreen">immensely</span> from your victory`);
+					if (V.hostageAnnounced === 1 && V.hostage) {
+						r.push(`, and acquire ${V.hostage.slaveName} as a slave`);
+					}
+					r.push(`.`);
+					cashX(random(100000, 250000), "war");
+				}
+				App.Events.addNode(el, r, "div");
+				jQuery(result).empty().append(el);
+			}
+		));
+
+		App.UI.DOM.appendNewElement("div", result, App.UI.DOM.link(
+			`Refuse`,
+			() => {
+				const el = new DocumentFragment();
+				const r = [];
+				V.nextButton = "Continue";
+				App.Utils.updateUserButton(); // unlock Continue button
+				r.push(`You coldly decline. "That was a mistake," your rival replies, entering a computer command.`);
+				if (V.rivalSet !== 0) {
+					r.push(`"All my remaining liquid assets have just been <span class="red">carefully dispersed to deny you control of my arcology.</span> You'll get nothing from me." It's true. The financial self-destruction ensures that the fiscal wreckage goes to the arcology's citizens, not you.`);
+					for (const arc of V.arcologies) {
+						if (arc.rival === 1) {
+							arc.embargo = 0;
+							arc.embargoTarget = -1;
+							arc.influenceTarget = -1;
+							arc.rival = 0;
+							arc.government = "direct democracy";
+							break;
+						}
+					}
+					if (V.hostageAnnounced === 1) {
+						r.push(hostageBounty());
+					}
+				} else {
+					r.push(`"All my remaining liquid assets have just been <span class="red">expended in an attack on the value of your holdings,</span> and my arcology has been heavily sabotaged. You'll get nothing from me." It's not entirely true, but the damage to your holdings does outweigh your gains by a significant margin. Your rival vanishes back into the old world.`);
+					cashX(random(-10000, -25000), "war");
+				}
+				App.Events.addNode(el, r, "div");
+				jQuery(result).empty().append(el);
+			}
+		));
+		if (V.rivalryDuration >= 30 && V.hostageAnnounced === 0 && V.rivalSet !== 0) {
+			App.UI.DOM.appendNewElement("div", result, App.UI.DOM.link(
+				`Refuse, and place a bounty of ${cashFormat(50000)} on your rival's death`,
+				() => {
+					const el = new DocumentFragment();
+					const r = [];
+					V.nextButton = "Continue"; // unlock Continue button
+					App.Utils.updateUserButton();
+					App.UI.DOM.appendNewElement("p", el, `You coldly decline. "That was a mistake," your rival replies, entering a computer command. "All my remaining liquid assets have just been <span class="red">expended in an attack on the value of your holdings,</span> and my arcology has been heavily sabotaged. You'll get nothing from me." It's not entirely true, but the damage to your holdings does outweigh your gains by a significant margin. Your rival vanishes back into the old world — but only for a few days.`);
+					App.UI.DOM.appendNewElement("p", el, `Your bounty is quickly claimed, and you are treated to the delicious moment of finding your rival's head delivered to your doorstep. It might not have done much good, but damn did it feel good.`);
+					cashX(-50000, "war");
+					for (const arc of V.arcologies) {
+						if (arc.rival === 1) {
+							arc.embargo = 0;
+							arc.embargoTarget = -1;
+							arc.influenceTarget = -1;
+							arc.rival = 0;
+							arc.government = "direct democracy";
+							break;
+						}
+					}
+					App.Events.addNode(el, r, "div");
+					jQuery(result).empty().append(el);
+				}
+			));
+		}
+		App.UI.DOM.appendNewElement("div", result, App.UI.DOM.link(
+			`Refuse, and place a bounty of ${cashFormat(50000)} on your rival's enslavement`,
+			() => {
+				const el = new DocumentFragment();
+				const r = [];
+				V.nextButton = "Continue";
+				App.Utils.updateUserButton(); // unlock Continue button
+				r.push(`You coldly decline. "That was a mistake," your rival replies, entering a computer command.`);
+				if (V.rivalSet !== 0) {
+					r.push(`"All my remaining liquid assets have just been <span class="red">carefully dispersed to deny you control of my arcology.</span> You'll get nothing from me." It's true.The financial self - destruction ensures that the fiscal wreckage goes to the arcology's citizens, not you.`);
+					for (const arc of V.arcologies) {
+						if (arc.rival === 1) {
+							arc.embargo = 0;
+							arc.embargoTarget = -1;
+							arc.influenceTarget = -1;
+							arc.rival = 0;
+							arc.government = "direct democracy";
+							if (arc.FSSupremacist > 20) {
+								V.rivalRace = arc.FSSupremacistRace;
+							} else if (arc.FSSubjugationist > 20) {
+								V.rivalRace = Array.from(setup.filterRaces.keys()).filter(race => race !== arc.FSSubjugationistRace).random();
+							}
+							break;
+						}
+					}
+				} else {
+					r.push(`"All my remaining liquid assets have just been <span class="red">expended in an attack on the value of your holdings,</span> and my arcology has been heavily sabotaged. You'll get nothing from me." It's not entirely true, but the damage to your holdings does outweigh your gains by a significant margin.`);
+					cashX(random(-10000, -25000), "war");
+				}
+				if (V.hostageAnnounced === 1) {
+					r.push(hostageBounty());
+				}
+				cashX(-50000, "war");
+				r.push(pRivalryCapture());
+				App.Events.addNode(el, r, "div");
+				jQuery(result).empty().append(el);
+			}
+		));
+		return node;
+	}
+
+	function hostageBounty() {
+		const result2 = App.UI.DOM.makeElement("p");
+		App.UI.DOM.appendNewElement("div", result2, App.UI.DOM.link(
+			`Place a bounty of ${cashFormat(10000)}  on your rival's psychological warfare tool`,
+			() => {
+				if (V.hostage) {
+					const {He} = getPronouns(V.hostage);
+					jQuery(result2).empty().append(`You make sure to post a bounty sufficient to ensure that ${V.hostage.slaveName}, your rival's psychological warfare tool, does not escape or go unrescued, depending on one's point of view. ${He} is quickly picked out of the chaos of your rival's escape and delivered to you.`);
+					V.hostageRescued = 1;
+					cashX(-10000, "war");
+				}
+			}
+		));
+		return result2;
+	}
+};
diff --git a/src/events/story/pRivalryVictory.tw b/src/events/story/pRivalryVictory.tw
deleted file mode 100644
index dfa4c946a9b..00000000000
--- a/src/events/story/pRivalryVictory.tw
+++ /dev/null
@@ -1,150 +0,0 @@
-:: P rivalry victory [nobr]
-
-<<set $nextButton = " ", $nextLink = "Random Nonindividual Event", $rivalOwner = 0, $rivalryPower = 0>> /* hide button until user makes a selection */
-<<set $rivalRace = 0>>
-<<if $rivalGender == 2>>
-	<<set _heR = "he">>
-	<<set _hisR = "his">>
-	<<set _HeR = capFirstChar(_heR)>>
-	<<set _HisR = capFirstChar(_hisR)>>
-<<else>>
-	<<set _heR = "she">>
-	<<set _hisR = "her">>
-	<<set _HeR = capFirstChar(_heR)>>
-	<<set _HisR = capFirstChar(_hisR)>>
-<</if>>
-
-
-For the first time, you receive a direct call from your rival. You pictured the moment as feeling grander than this, sitting at your desk as usual looking into _hisR downcast face. You're the victor in a new form of warfare in which bankruptcy has replaced surrender. If the world survives in its present state, you may one day be remembered as an innovator in the evolution of (nearly) bloodless war. Today, your reputation has @@.green;greatly improved.@@ But today all you have that's tangible is a view of a still-dignified arcology owner, self-possessed despite the situation.
-
-<br><br>
-
-"For what it's worth," _heR says without preamble, "I had nothing against you. The Daughters wouldn't accept a straight buy-off. Their leadership needed a target to attack, or the rank and file would have killed them themselves and gone ahead attacking me. I had to give them an alternative, or it would have been me." _HeR looks nervous for the first time. "So, what do we do now? I've still got enough resources to make the end of this story a messy one for you. Let me go, and I won't. I'll walk away, and I'll sign everything I've got left over to you.<<if $hostageAnnounced == 1>> Including $hostage.slaveName, of course.<</if>>"
-
-<br><br>
-
-<span id="result">
-<<link "Accept">>
-	<<set $nextButton = "Continue">><<run App.Utils.updateUserButton()>> /* unlock Continue button */
-	<<replace "#result">>
-	You accept, magnanimous in victory. "I don't think I would have done that," your rival replies. "Thank you. When they write the book, I'll make sure you look good."
-	<<if $rivalSet != 0>>
-		_HisR remaining liquid assets will go to satisfy _hisR great debts, but _hisR @@.yellowgreen;arcology holdings are yours.@@
-		<<for _prv = 0; _prv < $arcologies.length; _prv++>>
-			<<if $arcologies[_prv].rival == 1>>
-				<<set $arcologies[_prv].embargo = 0>>
-				<<set $arcologies[_prv].embargoTarget = -1>>
-				<<set $arcologies[_prv].influenceTarget = -1>>
-				<<set $arcologies[_prv].rival = 0>>
-				<<set $arcologies[_prv].government = "direct democracy">>
-				<<set $arcologies[_prv].PCminority += $arcologies[_prv].ownership>>
-				<<set $arcologies[_prv].PCminority = Math.clamp($arcologies[_prv].PCminority, 0, 49)>>
-				<<break>>
-			<</if>>
-		<</for>>
-		<<if $hostageAnnounced == 1>><<set $hostageRescued = 1>><</if>>
-	<<else>>
-		_HisR arcology will go to satisfy _hisR great debts, but you will still profit @@.yellowgreen;immensely@@ from your victory<<if $hostageAnnounced == 1>>, and acquire $hostage.slaveName as a slave<</if>>.
-		<<run cashX(random(100000,250000), "war")>>
-	<</if>>
-	<</replace>>
-<</link>>
-<br><<link "Refuse">>
-	<<set $nextButton = "Continue">><<run App.Utils.updateUserButton()>> /* unlock Continue button */
-	<<replace "#result">>
-	You coldly decline. "That was a mistake," your rival replies, entering a computer command.
-	<<if $rivalSet != 0>>
-		"All my remaining liquid assets have just been @@.red;carefully dispersed to deny you control of my arcology.@@ You'll get nothing from me." It's true. The financial self-destruction ensures that the fiscal wreckage goes to the arcology's citizens, not you.
-		<<for _prv = 0; _prv < $arcologies.length; _prv++>>
-			<<if $arcologies[_prv].rival == 1>>
-				<<set $arcologies[_prv].embargo = 0>>
-				<<set $arcologies[_prv].embargoTarget = -1>>
-				<<set $arcologies[_prv].influenceTarget = -1>>
-				<<set $arcologies[_prv].rival = 0>>
-				<<set $arcologies[_prv].government = "direct democracy">>
-				<<break>>
-			<</if>>
-		<</for>>
-		<<if $hostageAnnounced == 1>>
-			<br><br>
-			<span id="result2">
-			<br><<link "Place a bounty of <<print cashFormat(10000)>> on your rival's psychological warfare tool">>
-				<<replace "#result2">>
-				<<run cashX(-10000, "war")>>
-				<<setLocalPronouns $hostage>>
-				You make sure to post a bounty sufficient to ensure that $hostage.slaveName, your rival's psychological warfare tool, does not escape or go unrescued, depending on one's point of view. $He is quickly picked out of the chaos of your rival's escape and delivered to you.
-				<<set $hostageRescued = 1>>
-				<</replace>>
-			<</link>>
-			</span>
-		<</if>>
-	<<else>>
-		"All my remaining liquid assets have just been @@.red;expended in an attack on the value of your holdings,@@ and my arcology has been heavily sabotaged. You'll get nothing from me." It's not entirely true, but the damage to your holdings does outweigh your gains by a significant margin. Your rival vanishes back into the old world.
-		<<run cashX(random(-10000,-25000), "war")>>
-	<</if>>
-	<</replace>>
-<</link>>
-<<if $rivalryDuration >= 30 && $hostageAnnounced == 0 && $rivalSet != 0>>
-	<br><<link "Refuse, and place a bounty of <<print cashFormat(50000)>> on your rival's death">>
-		<<set $nextButton = "Continue">><<run App.Utils.updateUserButton()>> /* unlock Continue button */
-		<<replace "#result">>
-		You coldly decline. "That was a mistake," your rival replies, entering a computer command. "All my remaining liquid assets have just been @@.red;expended in an attack on the value of your holdings,@@ and my arcology has been heavily sabotaged. You'll get nothing from me." It's not entirely true, but the damage to your holdings does outweigh your gains by a significant margin. Your rival vanishes back into the old world — but only for a few days.
-		<br><br>
-		Your bounty is quickly claimed, and you are treated to the delicious moment of finding your rival's head delivered to your doorstep. It might not have done much good, but damn did it feel good.
-		<<run cashX(-50000, "war")>>
-		<<for _prv = 0; _prv < $arcologies.length; _prv++>>
-			<<if $arcologies[_prv].rival == 1>>
-				<<set $arcologies[_prv].embargo = 0>>
-				<<set $arcologies[_prv].embargoTarget = -1>>
-				<<set $arcologies[_prv].influenceTarget = -1>>
-				<<set $arcologies[_prv].rival = 0>>
-				<<set $arcologies[_prv].government = "direct democracy">>
-				<<break>>
-			<</if>>
-		<</for>>
-		<</replace>>
-	<</link>>
-<</if>>
-<br><<link "Refuse, and place a bounty of <<print cashFormat(50000)>> on your rival's enslavement">>
-	<<set $nextButton = "Continue">><<run App.Utils.updateUserButton()>> /* unlock Continue button */
-	<<replace "#result">>
-	You coldly decline. "That was a mistake," your rival replies, entering a computer command.
-	<<if $rivalSet != 0>>
-		"All my remaining liquid assets have just been @@.red;carefully dispersed to deny you control of my arcology.@@ You'll get nothing from me." It's true. The financial self-destruction ensures that the fiscal wreckage goes to the arcology's citizens, not you.
-		<<for _prv = 0; _prv < $arcologies.length; _prv++>>
-			<<if $arcologies[_prv].rival == 1>>
-				<<set $arcologies[_prv].embargo = 0>>
-				<<set $arcologies[_prv].embargoTarget = -1>>
-				<<set $arcologies[_prv].influenceTarget = -1>>
-				<<set $arcologies[_prv].rival = 0>>
-				<<set $arcologies[_prv].government = "direct democracy">>
-				<<if $arcologies[_prv].FSSupremacist > 20>>
-					<<set $rivalRace = $arcologies[_prv].FSSupremacistRace>>
-				<<elseif $arcologies[_prv].FSSubjugationist > 20>>
-					<<set $rivalRace = Array.from(setup.filterRaces.keys()).filter(race => race !== $arcologies[_prv].FSSubjugationistRace)>>
-				<</if>>
-				<<break>>
-			<</if>>
-		<</for>>
-		<<if $hostageAnnounced == 1>>
-			<br><br>
-			<span id="result2">
-			<br><<link "Place a bounty of <<print cashFormat(10000)>> on your rival's psychological warfare tool">>
-				<<replace "#result2">>
-				<<run cashX(-10000, "war")>>
-				<<setLocalPronouns $hostage>>
-				You make sure to post a bounty sufficient to ensure that $hostage.slaveName, your rival's psychological warfare tool, does not escape or go unrescued, depending on one's point of view. $He is quickly picked out of the chaos of your rival's escape and delivered to you.
-				<<set $hostageRescued = 1>>
-				<</replace>>
-			<</link>>
-			</span>
-		<</if>>
-	<<else>>
-		"All my remaining liquid assets have just been @@.red;expended in an attack on the value of your holdings,@@ and my arcology has been heavily sabotaged. You'll get nothing from me." It's not entirely true, but the damage to your holdings does outweigh your gains by a significant margin.
-		<<run cashX(random(-10000,-25000), "war")>>
-	<</if>>
-	<<run cashX(-50000, "war")>>
-	<<includeDOM pRivalryCapture()>>
-	<</replace>>
-<</link>>
-</span>
-- 
GitLab