From b27007f7655d62d94cdc228d1a434db41ed8b7b2 Mon Sep 17 00:00:00 2001
From: klorpa <30924131+klorpa@users.noreply.github.com>
Date: Tue, 11 Dec 2018 20:26:03 -0600
Subject: [PATCH] Working Now

---
 devNotes/twine JS.txt                      | 38 +++++++++++-----------
 src/SecExp/attackGenerator.tw              |  2 +-
 src/js/generateNewSlaveJS.tw               | 34 ++++++-------------
 src/js/slaveGenerationJS.tw                |  4 ++-
 src/uncategorized/seCustomSlaveDelivery.tw | 24 +++++---------
 5 files changed, 42 insertions(+), 60 deletions(-)

diff --git a/devNotes/twine JS.txt b/devNotes/twine JS.txt
index 62bad777d75..8a2419f8b4f 100644
--- a/devNotes/twine JS.txt	
+++ b/devNotes/twine JS.txt	
@@ -1570,7 +1570,7 @@ window.setPregType = function(actor) {
 
 	if(actor.broodmother < 1) { // Broodmothers should be not processed here. Necessary now.
 		if(typeof actor.readyOva == "number" && actor.readyOva != 0) {
-			ovum = actor.readyOva; //just single override; for delayed impregnation cases 
+			ovum = actor.readyOva; //just single override; for delayed impregnation cases
 		} else if(actor.ID == -1) {
 			if(actor.geneticQuirks.fertility == 2 && actor.geneticQuirks.hyperFertility == 2) { // Do not mix with sperm
 				if(actor.fertDrugs == 1) {
@@ -8891,7 +8891,7 @@ window.DegradingName = function DegradingName(slave) {
 		if (slave.fetishKnown === 1) {
 			if (slave.fetish === "buttslut") {
 				names.push("Anal", "Sodomy");
-			} 
+			}
 			if (slave.fetish === "cumslut") {
 				names.push("Cum", "Dicksuck", "Sucker");
 			}
@@ -10954,7 +10954,7 @@ window.generateChild = function(mother, ova, destination) {
 /*:: wombJS [script]*/
 
 /*
-This is womb processor/simulator script. It's take care about calculation of belly sizes based on individual fetus sizes, 
+This is womb processor/simulator script. It's take care about calculation of belly sizes based on individual fetus sizes,
 with full support of broodmothers implant random turning on and off possibility. Also this can be expanded to store more parents data in each individual fetus in future.
 Design limitations:
 - Mother can't gestate children with different speeds at same time. All speed changes apply to all fetuses.
@@ -10969,7 +10969,7 @@ WombImpregnate($slave, $fetus_count, $fatherID, $initial_age) - should be added
 
 WombProgress($slave, $time_to_add_to_fetuses) - after code that update $slave.preg, time to add should be the same.
 
-$isReady = WombBirthReady($slave, $birth_ready_age) - how many children ready to be birthed if their time to be ready is $birth_ready_age (40 is for normal length pregnancy). Return int - count of ready to birth children, or 0 if no ready exists. 
+$isReady = WombBirthReady($slave, $birth_ready_age) - how many children ready to be birthed if their time to be ready is $birth_ready_age (40 is for normal length pregnancy). Return int - count of ready to birth children, or 0 if no ready exists.
 
 $children = WombBirth($slave, $birth_ready_age) - for actual birth. Return array with fetuses objects that birthed (can be used in future) and remove them from womb array of $slave. Should be called at actual birth code in sugarcube. fetuses that not ready remained in womb (array).
 
@@ -11287,7 +11287,7 @@ window.WombGetVolume = function(actor) { //most legacy code from pregJS.tw with
     }
 
 
-    
+
     function getVolByWeight(actor)
     {
         var targetData;
@@ -11333,7 +11333,7 @@ window.WombGetVolume = function(actor) { //most legacy code from pregJS.tw with
 		data.size = csize;
 		data.rate = rate;
 
-		return data; //csize * rate; 
+		return data; //csize * rate;
 		//maybe not very effective code, but simple and easy to debug. May be optimized more in future.
 	}
 
@@ -11351,7 +11351,7 @@ window.WombGetVolume = function(actor) { //most legacy code from pregJS.tw with
 				/* legacy block for debug only
 				let gestastionWeek = ft.age;
 				let oldLen;
-				let oldVol; 
+				let oldVol;
 				if (gestastionWeek <= 32) {
 					oldLen = (0.00006396 * Math.pow(gestastionWeek, 4)) -
 						(0.005501 * Math.pow(gestastionWeek, 3)) +
@@ -11377,7 +11377,7 @@ window.WombGetVolume = function(actor) { //most legacy code from pregJS.tw with
 				ft.volume = ((4 / 3) * (Math.PI) * (phi / 2) * (Math.pow((targetLen / 2), 3)));
 				wombSize += ft.volume;
 
-				//oldVol = ((4 / 3) * (Math.PI) * (phi / 2) * (Math.pow((oldLen / 2), 3))); //for debug 
+				//oldVol = ((4 / 3) * (Math.PI) * (phi / 2) * (Math.pow((oldLen / 2), 3))); //for debug
 
 				//console.log("fetus.age:" + ft.age + "  oldLen:"+oldLen+"  targetLen:"+targetLen+"  ft.volume:"+ft.volume+ "  old volume:"+oldVol );
 				/*
@@ -11451,7 +11451,7 @@ window.WombUpdatePregVars = function(actor) {
 
 window.WombMinPreg = function(actor) {
 	WombSort(actor);
-	if (actor.womb.length > 0) 
+	if (actor.womb.length > 0)
 		return actor.womb[actor.womb.length-1].age;
 	else
 		return 0;
@@ -11459,7 +11459,7 @@ window.WombMinPreg = function(actor) {
 
 window.WombMaxPreg = function(actor) {
 	WombSort(actor);
-	if (actor.womb.length > 0) 
+	if (actor.womb.length > 0)
 		return actor.womb[0].age;
 	else
 		return 0;
@@ -11471,20 +11471,20 @@ window.WombNormalizePreg = function(actor)
 	WombInit(actor);
 
 	// this is broodmother on hold.
-	if (actor.womb.length == 0 && actor.broodmother >= 1) { 
-		actor.pregType = 0; 
+	if (actor.womb.length == 0 && actor.broodmother >= 1) {
+		actor.pregType = 0;
 		actor.pregKnown = 0;
 
 		// to avoid legacy code conflicts - broodmother on hold
 		// can't be impregnated, but she not on normal contraceptives.
 		// So we set this for special case.
 		if (actor.preg >= 0)
-			actor.preg = 0.1; 
+			actor.preg = 0.1;
 
 		if (actor.pregSource > 0)
 			actor.pregSource = 0;
 
-		if (actor.pregWeek > 0) 
+		if (actor.pregWeek > 0)
 			actor.pregWeek = 0;
 
 		actor.broodmotherCountDown = 0;
@@ -11522,7 +11522,7 @@ window.WombNormalizePreg = function(actor)
 
 		// We can't properly set postpartum here,
 		// but can normalize obvious error with forgotten property.
-		if (actor.pregWeek > 0) 
+		if (actor.pregWeek > 0)
 			actor.pregWeek = 0;
 	}
 	actor.bellyPreg = WombGetVolume(actor);
@@ -11604,7 +11604,7 @@ window.WombGetFetus = function(actor, fetusNum)
 	WombInit(actor);
 	if (actor.womb.length >= fetusNum)
 		return actor.womb[fetusNum];
-	else 
+	else
 		return null;
 }
 
@@ -11676,7 +11676,7 @@ window.WombCleanYYFetuses = function(actor)
 	return reserved;
 }
 
-window.FetusGlobalReserveCount = function(reserveType) 
+window.FetusGlobalReserveCount = function(reserveType)
 {
 	var cnt = 0;
 	var SV = State.variables;
@@ -11827,7 +11827,7 @@ window.BCReserveInit = function()
 			if (typeof ft.reserve != 'string')
 				ft.reserve = "";
 				if (typeof ft.motherID != 'number') //setting missing biological mother ID for fetus.
-					ft.motherID = slave.ID; 
+					ft.motherID = slave.ID;
 
 				if (ft.ID == undefined)
 					ft.ID = generateNewID();
@@ -11849,7 +11849,7 @@ window.BCReserveInit = function()
 	SV.PC.womb.forEach(function(ft){
 		if (typeof ft.reserve != 'string')
 			ft.reserve = "";
-			ft.motherID = SV.PC.ID; 
+			ft.motherID = SV.PC.ID;
 		});
 
 }
diff --git a/src/SecExp/attackGenerator.tw b/src/SecExp/attackGenerator.tw
index ff6782f2905..4a0a2fefabf 100644
--- a/src/SecExp/attackGenerator.tw
+++ b/src/SecExp/attackGenerator.tw
@@ -40,7 +40,7 @@
 	<<set $lastAttackWeeks = 0>>
 	<<set $leadingTroops = "assistant">>
 	<<set $deployableUnits = 2 * $readiness>>
-	<<set $chosenTactic = either("Bait and Bleed", "Guerrilla", "Choke Points", "Interior Lines", "Pincer Maneuver", "Defense In Depth", "Blitzkrieg", "Human Wave")>>
+	<<set $chosenTactic = either("Bait and Bleed", "Blitzkrieg", "Choke Points", "Defense In Depth", "Guerrilla", "Human Wave", "Interior Lines", "Pincer Maneuver")>>
 	/* _type is the chance out of 100 of an attack of that type happening */
 	<<set _raider = 25>>
 	<<set _oldWorld = 25>>
diff --git a/src/js/generateNewSlaveJS.tw b/src/js/generateNewSlaveJS.tw
index 88842387052..a01d64cbffa 100644
--- a/src/js/generateNewSlaveJS.tw
+++ b/src/js/generateNewSlaveJS.tw
@@ -1140,32 +1140,18 @@ window.GenerateNewSlave = (function(){
 				V.fixedNationality = 0;
 			}
 			nationalityToRace(slave);
-
-			if (passage() == "Corporate Market" && (V.captureUpgradeRace != "unselected") && (V.captureUpgradeRace != "none")) {
-				if (V.captureUpgradeRace == "mixed race") {
-					slave.race = "mixed race";
-				} else {
-					const capUpgradeCheck = setup[V.captureUpgradeRace.toLowerCase().replace(/[ -]/g, '')+'Nationalities'];
-					const keys = Object.keys(capUpgradeCheck);
-					var capUpgradeNationalities = {};
-					for (var i = 0; i < keys.length; i++) {
-						if (keys[i] in V.nationalities) {
-							capUpgradeNationalities[keys[i]] = capUpgradeCheck[keys[i]];
-						}
-					}
-					if (Object.keys(capUpgradeNationalities).length > 0) {
-						slave.nationality = hashChoice(capUpgradeNationalities);
-					} else {
-						slave.nationality = hashChoice(capUpgradeCheck);
-					}
-					slave.race = V.captureUpgradeRace;
-				}
+		} else {
+			if (V.fixedNationality == 0) {
+				slave.race = V.fixedRace;
+				V.fixedRace = 0;
+				raceToNationality(slave);
+			} else {
+				slave.race = V.fixedRace;
+				slave.nationality = V.fixedNationality;
+				V.fixedNationality = 0;
+				V.fixedRace = 0;
 			}
 
-		} else {
-			slave.race = V.fixedRace;
-			V.fixedRace = 0;
-			raceToNationality(slave);
 		}
 	};
 
diff --git a/src/js/slaveGenerationJS.tw b/src/js/slaveGenerationJS.tw
index be4a9256396..72a100761d6 100644
--- a/src/js/slaveGenerationJS.tw
+++ b/src/js/slaveGenerationJS.tw
@@ -5,9 +5,11 @@ window.nationalityToRace = function nationalityToRace(slave) {
 };
 
 window.raceToNationality = function raceToNationality(slave) {
+	const V = State.variables;
+	slave.nationality = hashChoice(V.nationalities);
 	/* Maximum of 100 attempts */
 	for (var i = 0; setup.raceSelector[slave.nationality] && !(slave.race in setup.raceSelector[slave.nationality]) && i < 100; i++) {
-		slave.nationality = hashChoice($nationalities);
+		slave.nationality = hashChoice(V.nationalities);
 	}
 	/* No success after 100 attempts, so just randomize according to race */
 	if (setup.raceSelector[slave.nationality] && !(slave.race in setup.raceSelector[slave.nationality]) && i == 100) {
diff --git a/src/uncategorized/seCustomSlaveDelivery.tw b/src/uncategorized/seCustomSlaveDelivery.tw
index 958ad192cb5..1d052890d38 100644
--- a/src/uncategorized/seCustomSlaveDelivery.tw
+++ b/src/uncategorized/seCustomSlaveDelivery.tw
@@ -104,8 +104,12 @@
 <</if>>
 <<set $ageAdjustOverride = 1>>
 <<set $one_time_age_overrides_pedo_mode = 1>>
-<<set $fixedNationality = $customSlave.nationality>>
-<<set $fixedRace = $customSlave.race>>
+<<if $customSlave.nationality != "Nationality is unimportant">>
+	<<set $fixedNationality = $customSlave.nationality>>
+<</if>>
+<<if $customSlave.race != "ethnicity is unimportant">>
+	<<set $fixedRace = $customSlave.race>>
+<</if>>
 <<if $customSlave.sex == 2>>
 	<<include "Generate XY Slave">>
 	<<set $activeSlave.dick = $customSlave.dick>>
@@ -133,7 +137,6 @@
 		<<set $activeSlave.clit = $customSlave.clit>>
 	<</if>>
 <</if>>
-<<set $fixedNationality = 0>>
 
 /* I have no clue what I'm doing here */
 <<if $customSlave.heightMod == "greatly below average">>
@@ -178,8 +181,9 @@
 <<set $activeSlave.weight = $customSlave.weight>>
 <<set $activeSlave.face = $customSlave.face>>
 <<set $activeSlave.lips = $customSlave.lips>>
-<<set $activeSlave.race = $customSlave.race>>
-<<set $activeSlave.skin = $customSlave.skin>>
+<<if $customSlave.skin != "left natural">>
+	<<set $activeSlave.skin = $customSlave.skin>>
+<</if>>
 <<set $activeSlave.boobs = $customSlave.boobs>>
 <<set $activeSlave.butt = $customSlave.butt>>
 <<set $activeSlave.analSkill = $customSlave.skills>>
@@ -198,16 +202,6 @@
 <<set $activeSlave.devotion = random(-10,10)>>
 <<set $activeSlave.trust = random(-10,10)>>
 
-<<if $activeSlave.nationality == "Nationality is unimportant" && $activeSlave.race == "ethnicity is unimportant">>
-	<<set $activeSlave.nationality = hashChoice($nationalities)>>
-	<<run nationalityToRace($activeSlave)>>
-<<elseif $activeSlave.nationality == "Nationality is unimportant">>
-	<<run raceToNationality($activeSlave)>>
-<<elseif $activeSlave.race == "ethnicity is unimportant">>
-	<<run nationalityToRace($activeSlave)>>
-<<else>>
-<</if>>
-
 <<if $activeSlave.race == "black">>
 	<<if $activeSlave.skin == "left natural">><<set $activeSlave.skin = either("black", "brown", "dark brown")>><</if>>
 	<<set $activeSlave.hColor = either("black", "black", "black", "brown")>>
-- 
GitLab