From e39e785975e44a6aecf0cd0d8cff7ec3fdb80822 Mon Sep 17 00:00:00 2001
From: Svornost <11434-svornost@users.noreply.gitgud.io>
Date: Tue, 18 Aug 2020 00:44:10 -0700
Subject: [PATCH] Language teaching tweaks: 1. Schoolteachers with bad accents
 are worse at teaching language. 2. Devoted Schoolteachers with bad accents
 will try to get better on their own. 3. Decorating a Schoolroom in a
 Revivalist theme will help teach the Revivalist language.

---
 src/endWeek/saTakeClasses.js                  | 16 +++++++++-
 src/endWeek/schoolroomReport.js               | 17 ++++++++++-
 .../schoolroom/schoolroomFramework.js         | 29 +++++++++++++++----
 3 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/src/endWeek/saTakeClasses.js b/src/endWeek/saTakeClasses.js
index 49b307ab266..15f9f3b588a 100644
--- a/src/endWeek/saTakeClasses.js
+++ b/src/endWeek/saTakeClasses.js
@@ -445,8 +445,22 @@ App.SlaveAssignment.takeClasses = (function() {
 	 *
 	 */
 	function speechLessons(slave) {
+		let teacherBonus = 0;
+		if (slave.assignment === Job.SCHOOL) {
+			if (S.Schoolteacher.accent >= 2) { // really === 2, because accent > 2 can't teach at all
+				teacherBonus -= 5; // penalty for bad example
+			}
+			teacherBonus += (S.Schoolteacher.intelligence + S.Schoolteacher.intelligenceImplant) / 20; // -7 to 7
+			if (V.schoolroomUpgradeLanguage) {
+				teacherBonus = Math.max(teacherBonus, 1); // automated teaching counterbalances terrible teachers
+			}
+			if (App.Entity.facilities.schoolroom.revivalistLanguageDecorationBonus()) {
+				teacherBonus += 5;
+			}
+		}
+
 		if (slave.intelligenceImplant >= 15 || slave.intelligenceImplant < 0) {
-			if (slave.intelligence > jsRandom(-110, 110)) {
+			if (slave.intelligence + teacherBonus > jsRandom(-110, 110)) {
 				if (slave.accent > 3) {
 					const langWeekThreshold = (V.schoolroomUpgradeLanguage === 0) ? 24 : 16;
 					if (V.week - slave.weekAcquired > langWeekThreshold) {
diff --git a/src/endWeek/schoolroomReport.js b/src/endWeek/schoolroomReport.js
index ea0b28a34e6..ce81af86e82 100644
--- a/src/endWeek/schoolroomReport.js
+++ b/src/endWeek/schoolroomReport.js
@@ -45,7 +45,7 @@ App.EndWeek.schoolroomReport = function() {
 				}
 			}
 
-			const {He, he, His, his, him, wife} = getPronouns(S.Schoolteacher);
+			const {He, he, His, his, him, himself, wife} = getPronouns(S.Schoolteacher);
 			r.push(`${S.Schoolteacher.slaveName} is serving as your Schoolteacher.`);
 			if (S.Schoolteacher.relationship === -3 && S.Schoolteacher.devotion > 50) {
 				r.push(`As your loving ${wife}, ${he} tries ${his} best to teach ${his} pupils how to please you.`);
@@ -85,6 +85,18 @@ App.EndWeek.schoolroomReport = function() {
 				r.push(`${His} students want to be just like their beautiful teacher.`);
 				idleBonus++;
 			}
+			if (S.Schoolteacher.accent >= 2) { // really accent === 2, because accent > 2 can't teach anyway
+				r.push(`${He}'s been tasked with teaching ${V.language}, but ${he}'s barely understandable ${himself}.`);
+				r.push(`This <span class="warning">slows ${his} students' progress</span> with the language.`);
+				if (S.Schoolteacher.devotion > 50) {
+					r.push(`${He} wants to do better, and devotes any extra time ${he} can find to improving ${his} own competency in ${V.language}.`);
+					idleBonus--;
+					if (S.Schoolteacher.intelligence + S.Schoolteacher.intelligenceImplant > random(-110, 110)) { // similar chances to saTakeClasses.speechLessons
+						r.push(`This week, ${he} makes a breakthrough, <span class="improvement">reducing ${his} accent</span> to a clear, pleasant, exoticism.`);
+						S.Schoolteacher.accent--;
+					}
+				}
+			}
 
 			for (const slave of slaves) {
 				const {he2} = getPronouns(slave).appendSuffix('2');
@@ -241,6 +253,9 @@ App.EndWeek.schoolroomReport = function() {
 	if (V.schoolroomDecoration !== "standard") {
 		const decorationEffects = App.UI.DOM.appendNewElement("p", frag, '', "indent");
 		$(decorationEffects).append(`${V.schoolroomNameCaps}'s ${V.schoolroomDecoration} atmosphere <span class="hotpink">has a minor impact on the students.</span>`);
+		if (App.Entity.facilities.schoolroom.revivalistLanguageDecorationBonus()) {
+			$(decorationEffects).append(` They also <span class="positive">learn ${V.language} more quickly</span> in this environment.`);
+		}
 	}
 
 	return frag;
diff --git a/src/facilities/schoolroom/schoolroomFramework.js b/src/facilities/schoolroom/schoolroomFramework.js
index 31059cd5e28..9f2b6511143 100644
--- a/src/facilities/schoolroom/schoolroomFramework.js
+++ b/src/facilities/schoolroom/schoolroomFramework.js
@@ -64,9 +64,28 @@ App.Entity.Facilities.SchoolroomStudentJob = class extends App.Entity.Facilities
 	}
 };
 
-App.Entity.facilities.schoolroom = new App.Entity.Facilities.SingleJobFacility(
-	App.Data.Facilities.schoolroom,
-	{
-		student: new App.Entity.Facilities.SchoolroomStudentJob()
+App.Entity.Facilities.Schoolroom = class extends App.Entity.Facilities.SingleJobFacility {
+	constructor() {
+		super(App.Data.Facilities.schoolroom, {
+			student: new App.Entity.Facilities.SchoolroomStudentJob()
+		});
 	}
-);
+
+	/** Does the schoolroom decoration impart a language-learning bonus?
+	 * @returns {boolean}
+	 */
+	revivalistLanguageDecorationBonus() {
+		const decorationBonus = {
+			"Latin": "Roman Revivalist",
+			"Nahuatl": "Aztec Revivalist",
+			"Ancient Egyptian": "Egyptian Revivalist",
+			"Japanese": "Edo Revivalist",
+			"Arabic": "Arabian Revivalist",
+			"Chinese": "Chinese Revivalist"
+		};
+		const bonusDeco = decorationBonus[V.language];
+		return bonusDeco && V.schoolroomDecoration === bonusDeco;
+	}
+};
+
+App.Entity.facilities.schoolroom = new App.Entity.Facilities.Schoolroom();
-- 
GitLab