:: Next Week

<<silently>>

<<if $rivalOwner != 0>>
	<<set _SL = $arcologies.length>>
	<<for _i = 0; _i < _SL; _i++>>
	<<if $arcologies[_i].rival == 1>>
		<<set $rivalOwner = $arcologies[_i].prosperity>>
	<</if>>
	<</for>>
<</if>>

<<if $playerAging != 0>>
	<<set $PC.birthWeek += 1>>
	<<if $PC.physicalAge >= 55 && ($PC.preg == -1 || $PC.preg == 0)>>
		<<set $PC.preg = -2>>
	<</if>>
	<<if $PC.birthWeek >= 52>>
		<<set $PC.birthWeek to 0>>
		<<if $playerAging == 2>>
			<<set $PC.physicalAge += 1>>
			<<set $PC.actualAge += 1>>
			<<set $PC.visualAge += 1>>
		<</if>>
	<</if>>
<</if>>

<<set $averageTrust to 0>>
<<set $averageDevotion to 0>>
<<set _slavesContributing = 0>>
<<set _OldHG = -1, _NewHG = -1, _SL = $slaves.length>>
<<for _i = 0; _i < _SL; _i++>>
	<<if $seeAge != 0>>
	<<set $slaves[_i].birthWeek += 1>>
		<<if $slaves[_i].birthWeek >= 52>>
		<<set $slaves[_i].birthWeek to 0>>
		<<if $seeAge == 1>>
			<<set $slaves[_i].physicalAge += 1>>
			<<set $slaves[_i].actualAge += 1>>
			<<set $slaves[_i].visualAge += 1>>
			<<if $slaves[_i].physicalAge lte 18 && $loliGrow == 1>>
				<<include "Physical Development">>
			<</if>>
		<</if>>
		<</if>>
	<</if>>
	<<if $slaves[_i].indenture > 0>>
		<<set $slaves[_i].indenture -= 1>>
	<</if>>
	<<set $slaves[_i].trust = Number($slaves[_i].trust.toFixed(1)), $slaves[_i].devotion = Number($slaves[_i].devotion.toFixed(1))>>
	<<set $slaves[_i].oldDevotion = $slaves[_i].devotion, $slaves[_i].oldTrust = $slaves[_i].trust, $slaves[_i].tired = 0, $slaves[_i].minorInjury = 0>>
	<<if $slaves[_i].sentence > 1>>
		<<set $slaves[_i].sentence -= 1>>
	<<elseif $slaves[_i].sentence == 1>>
		<<set $slaves[_i].sentence = 0, $slaves[_i].assignment to "rest", $slaves[_i].assignmentVisible = 1>>
	<</if>>
	<<if $slaves[_i].weekAcquired == 0>>
		<<set $slaves[_i].weekAcquired = $week>>
	<</if>>
	<<if $slaves[_i].relation == 0>>
		<<set $slaves[_i].relationTarget = 0>>
	<</if>>
	<<if $slaves[_i].relationship == 0>>
		<<set $slaves[_i].relationshipTarget = 0>>
	<</if>>
	<<if $slaves[_i].rivalry == 0>>
		<<set $slaves[_i].rivalryTarget = 0>>
	<</if>>
	/% Fix some possible floating point rounding errors, and bring precision to one decimal place. %/
	<<set $slaves[_i].energy = Math.clamp(Number($slaves[_i].energy.toFixed(1)), 0, 100)>>
	<<if $slaves[_i].fetishStrength > 95>>
		<<set $slaves[_i].fetishStrength = 100>>
	<<else>>
		<<set $slaves[_i].fetishStrength = Math.clamp(Number($slaves[_i].fetishStrength.toFixed(1)), 0, 100)>>
	<</if>>
	<<set $slaves[_i].weight = Math.clamp(Number($slaves[_i].weight.toFixed(1)), -100, 100)>>
	<<set $slaves[_i].health = Number($slaves[_i].health.toFixed(1))>>
	<<set $slaves[_i].butt = Number($slaves[_i].butt.toFixed(1))>>
	<<set $slaves[_i].muscles = Math.clamp(Number($slaves[_i].muscles.toFixed(1)), -100, 100)>>
	<<set $slaves[_i].lips = Math.clamp(Number($slaves[_i].lips.toFixed(1)), 0, 100)>>
	<<set $slaves[_i].oralSkill = Math.clamp(Number($slaves[_i].oralSkill.toFixed(1)), 0, 100)>>
	<<set $slaves[_i].vaginalSkill = Math.clamp(Number($slaves[_i].vaginalSkill.toFixed(1)), 0, 100)>>
	<<set $slaves[_i].analSkill = Math.clamp(Number($slaves[_i].analSkill.toFixed(1)), 0, 100)>>
	<<set $slaves[_i].whoreSkill = Math.clamp(Number($slaves[_i].whoreSkill.toFixed(1)), 0, 100)>>
	<<set $slaves[_i].entertainSkill = Math.clamp(Number($slaves[_i].entertainSkill.toFixed(1)), 0, 100)>>
	<<set $slaves[_i].lactationAdaptation = Math.clamp(Number($slaves[_i].lactationAdaptation.toFixed(1)), 0, 100)>>
	<<set $slaves[_i].intelligenceImplant = Number($slaves[_i].intelligenceImplant.toFixed(1))>>
	<<if ($HGSuiteEquality == 1) && ($HeadGirl != 0) && ($slaves[_i].devotion > 50)>>
		<<if ($slaves[_i].assignment == "live with your Head Girl")>>
			<<set _NewHG = _i>>
		<<elseif ($slaves[_i].ID == $HeadGirl.ID)>>
			<<set _OldHG = _i>>
		<</if>>
	<</if>>
	/* AVERAGE VALUES UPDATE */
	<<if $slaves[$i].assignmentVisible == 1>>
		<<set $averageTrust += $slaves[$i].trust, $averageDevotion += $slaves[$i].devotion, _slavesContributing += 1>>
	<<else>>
		<<if $slaves[$i].assignment != "be confined in the cellblock">>
		<<if $slaves[$i].assignment != "be confined in the arcade">>
		<<if $slaves[$i].assignment != "labor in the production line">>
		<<if ($slaves[$i].assignment != "work in the dairy") || ($dairyRestraintsSetting < 2)>>
			<<set $averageTrust += $slaves[$i].trust*0.5, $averageDevotion += $slaves[$i].devotion*0.5, _slavesContributing += 0.5>>
		<</if>>
		<</if>>
		<</if>>
		<</if>>
	<</if>>
<</for>>
<<set $averageTrust = $averageTrust/_slavesContributing>>
<<set $averageDevotion = $averageDevotion/_slavesContributing>>
<<set $enduringTrust = ($averageTrust+($enduringTrust*3))/4>>
<<set $enduringDevotion = ($averageDevotion+($enduringDevotion*3))/4>>

<<if (_OldHG != -1) && (_NewHG != -1)>>
	<<set $slaves[_OldHG].assignment = "live with your Head Girl", $slaves[_OldHG].assignmentVisible = 0>>
	<<if $slaves[_OldHG].ID == $personalAttention>>
		<<if $PC.career == "escort">>
		<<set $personalAttention to "whoring">>
		<<elseif $PC.career == "servant">>
		<<set $personalAttention to "upkeep">>
		<<else>>
		<<set $personalAttention to "business">>
		<</if>>
	<</if>>
	<<set $slaves[_NewHG].assignment = "be your Head Girl", $slaves[_NewHG].assignmentVisible = 1, $HeadGirl = $slaves[_NewHG], $slaves[_NewHG].diet = "healthy">>
<</if>>

<<if $PC.preg >= 40 && random(1,100) > 50>>
	<<set $PC.labor = 1>>
<<elseif $PC.preg >= 44>>
	<<set $PC.labor = 1>>
<</if>>

<<if $week is $oldWeek>>
	<<set $week += 1, $day += 7>>
	<<switch $month>>
	<<case "January">>
	<<if $day > 31>>
		<<set $day -= 31, $month to "February">>
	<</if>>
	<<case "February">>
	<<if $day > 28>>
		<<set $day -= 28, $month to "March">>
	<</if>>
	<<case "March">>
	<<if $day > 31>>
		<<set $day -= 31, $month to "April">>
	<</if>>
	<<case "April">>
	<<if $day > 30>>
		<<set $day -= 30, $month to "May">>
	<</if>>
	<<case "May">>
	<<if $day > 31>>
		<<set $day -= 31, $month to "June">>
	<</if>>
	<<case "June">>
	<<if $day > 30>>
		<<set $day -= 30, $month to "July">>
	<</if>>
	<<case "July">>
	<<if $day > 31>>
		<<set $day -= 31, $month to "August">>
	<</if>>
	<<case "August">>
	<<if $day > 31>>
		<<set $day -= 31, $month to "September">>
	<</if>>
	<<case "September">>
	<<if $day > 30>>
		<<set $day -= 30, $month to "October">>
	<</if>>
	<<case "October">>
	<<if $day > 31>>
		<<set $day -= 31, $month to "November">>
	<</if>>
	<<case "November">>
	<<if $day > 30>>
		<<set $day -= 30, $month to "December">>
	<</if>>
	<<default>>
	<<if $day > 31>>
		<<set $day -= 31, $month to "January", $year += 1>>
	<</if>>
	<</switch>>
<</if>>

<<set _seed to random(1,10)>>
<<if $week < 25>>
	<<if _seed > 4>>
		<<set $weatherToday = $niceWeather.random()>>
	<<else>>
		<<set $weatherToday = $lightWeather.random()>>
	<</if>>
<<elseif $week < 50>>
	<<if _seed > 4>>
		<<set $weatherToday = $niceWeather.random()>>
	<<elseif _seed > 2>>
		<<set $weatherToday = $lightWeather.random()>>
	<<else>>
		<<set $weatherToday = $heavyWeather.random()>>
	<</if>>
<<elseif $week < 75>>
	<<if _seed > 6>>
		<<set $weatherToday = $niceWeather.random()>>
	<<elseif _seed > 3>>
		<<set $weatherToday = $lightWeather.random()>>
	<<else>>
		<<set $weatherToday = $heavyWeather.random()>>
	<</if>>
<<else>>
	<<if _seed > 8>>
		<<set $weatherToday = $niceWeather.random()>>
	<<elseif _seed > 6>>
		<<set $weatherToday = $lightWeather.random()>>
	<<elseif _seed > 2>>
		<<set $weatherToday = $heavyWeather.random()>>
	<<else>>
		<<set $weatherToday = $extremeWeather.random()>>
	<</if>>
<</if>>

<<set $coursed = 0, $eventDescription = 0, $manuallyRetired = 0, $pitFought = 0, $preOwnedViewed = 0, $prestigeAuctioned = 0, $repGain = 0, $shelterSlave = 0, $shelterSlaveBought = 0, $slaveMarketLimit = 10 + ($rep / 1000), $slavesSeen = 0>>

/% These are variables that either should be made into _temp vars or should be Zeroed out once done with them instead of here. This can also interfere with debugging or hide NaN's as zeroing things out would clear a NaN. Also could stop from NaN's getting worse? %/
/% Integer and float variables. No real need to zero them out but doesn't hurt to have them in a known state, though this might mask variables NaN'ing out. Takes up the least amount of Memory besides a "" string. %/
<<set $averageProsperity = 0, $beauty = 0, $beautyMultiplier = 0, $boobsID = -1, $boobsInterestTargetID = -1, $brideSlave = -1, $buttslutID = -1, $buttslutInterestTargetID = -1, $costs = 0, $cumslutID = -1, $FResult = 0, $groomSlave = -1, $humiliationID = -1, $humiliationInterestTargetID = -1, $i = 0, $I = 0, $individualCosts = 0, $influenceBonus = 0, $j = 0, $learning = 0, $m = 0, $masochistID = -1, $masochistInterestTargetID = -1, $opinion = 0, $r = 0, $subID = -1, $submissiveInterestTargetID = -1, $weddingSlaveID = -1, $x = 0, $y = 0, $relationID = 0, $tempMF = 0, $relationType = 0>>

/% Other arrays %/
<<set $events = [], $FSAcquisitionEvents = [], $FSNonconformistEvents = [], $nurseMolestationSubIDs = [], $PESSevent = [], $PETSevent = [], $qualifiedNicknames = [], $REAnalCowgirlSubIDs = [], $REButtholeCheckinIDs = [], $RECIevent = [], $recruit = [], $RETasteTestSubIDs = [], $qualifiedFS to [], $recruitedType to []>>

/% Slave Objects using 0 instead of null. Second most memory eaten up. %/
<<set $activeSlave = 0, $displaySlave = 0, $domSlave = 0, $eventSlave = 0, $REBoobCollisionSub = 0, $REIfYouEnjoyItSub = 0, $RERelationshipSlave = 0, $RESadisticDescriptionSub = 0, $REShowerForceSub = 0, $secondSlave = 0, $slaveWithoutBonuses = 0, $subSlave = 0, $milkTap = 0, $relation = 0>>

/% Slave Objects that never get zeroed so null them here. Second most memory eaten up. %/
<<set $alphaTwin = null, $assayedSlave = null, $beforeGingering = null, $betaTwin = null, $mother = null, $olderSister = null, $recruiterMother = null, $recruiterSisterOlder = null, $recruiterSisterYoung = null, $recruiterTwin = null, $sibling = null, $tempLover = null, $tempRival = null, $tempSub = null>>

/% Slave Object Arrays. These can take up the most memory. %/
<<set $eligibleSlaves = [], $slavesInLine = []>>

/% Strings Memory varies. %/
<<set $analSkinDesc = "", $applyDesc = "", $bellyAccessory = "", $buyer = "", $desc = "", $event = "", $goto = "", $malefactor = "", $nickname = "", $notApplyDesc = "", $oldName = "", $situationDesc = "", $skinDesc = "", $k = "", $l = "", $j = "", $y = "", $relationType = "">>
/% Done with zeroing out, what should be for the most part Temps %/

/*HACKY EVENT WORKAROUNDS*/
<<if $eventID != -1>>
	<<set $slaves[$eventID].devotion -= 50, $eventID to -1>>
<</if>>

<<if $autosave != 0>>
	<<script>>Save.autosave.save("Week Start Autosave")<</script>>
<</if>>

<<goto "Main">>

<</silently>>
src/uncategorized/nextWeek.tw