code:
:: securityReport [nobr]

/* init */
<<if $ACitizens > $oldACitizens>>
	<<set _immigration = $ACitizens - $oldACitizens, _emigration = 0>>
<<else>>
	<<set _emigration = $oldACitizens - $ACitizens, _immigration = 0>> /*takes into account citizens leaving and those getting enslaved*/
<</if>>
<<set _secGrowth = 0>>
<<set _secRest = 0>>
<<set _restGrowth = 0>>
<<set _newSec = 0>>
<<set _crimeGrowth = 0>>
<<set _crimeCap = 0>>
<<set _newCrime = 0>>
<<set _recruits = 0>>
<<set _recruitsMultiplier = 1>>
<<set _newMercs = 0>>

<<if $useTabs == 0>>
__Security__<</if>>

Security:
<<if $terrain === "oceanic">>
	Due to the @@.green;massive economic and logistical challenges@@ of attacking an oceanic arcology, your security force(s)
<<else>>
	The @@.red;easily manageable economic and logistical challenges@@ of attacking an $terrain arcology ensure that your security force(s) do not
<</if>>
 have the luxury of focusing exclusively on internal matters.

<<if $secMenials > 0>>
	<<print num($secMenials)>> slaves work to improve the security of your arcology,
	<<if $mercenaries >= 1 && $arcologyUpgrade.drones == 1>>
		while your mercenaries and security drones tirelessly patrol the streets to keep them safe.
	<<elseif $arcologyUpgrade.drones == 1>>
		while your security drones tirelessly patrol the arcology to keep it safe.
	<<else>>
		while your loyal subordinates try to keep the arcology safe to the best of their abilities.
	<</if>>
<<else>>
	<<if $mercenaries >= 1 && $arcologyUpgrade.drones == 1>>
		Your mercenaries and security drones tirelessly patrol the streets to keep them safe.
	<<elseif $arcologyUpgrade.drones == 1>>
		Your security drones tirelessly patrol the arcology to keep it safe.
	<<else>>
		Your loyal subordinates try to keep the arcology safe to the best of their abilities.
	<</if>>
<</if>>

/* security modifiers */
<<if $PC.career == "mercenary">>
	Your past life as a mercenary makes it easier to manage the security of the arcology.
	<<set _secGrowth += 1>>
<</if>>
<<if $smilingManFate == 0>>
	The ex-criminal known to the world as The Smiling Man puts her impressive skills to work, dramatically increasing the efficiency of your security measures.
	<<set _secGrowth += 2>>
<</if>>
<<if $ACitizens + $ASlaves <= 5000>>
	The small number of residents makes their job easier.
	<<set _secGrowth += 2>>
<<elseif $ACitizens + $ASlaves <= 7500>>
	The fairly low number of residents makes their job a little easier.
	<<set _secGrowth += 1>>
<<elseif $ACitizens + $ASlaves <= 10000>>
	The fairly high number of residents makes their job a little harder.
	<<set _secGrowth -= -0.5>>
<<elseif $ACitizens + $ASlaves <= 15000>>
	The high number of residents makes their job harder.
	<<set _secGrowth -= 1>>
<<else>>
	The extremely high number of residents makes their job a lot harder.
	<<set _secGrowth -= 2>>
<</if>>
<<if _immigration >= 0 && _emigration == 0>>
	<<if _immigration < 50>>
		The limited number of immigrants that reached the arcology this week does not have any serious impact on the efficiency of current security measures.
		<<set _secGrowth += 0.5>>
	<<elseif _immigration < 150>>
		The number of immigrants that reached the arcology this week is high enough to complicate security protocols.
		<<set _secGrowth -= 0.2>>
	<<elseif _immigration < 300>>
		The high number of immigrants that reached the arcology this week complicates security protocols.
		<<set _secGrowth -= 0.5>>
	<<elseif _immigration < 500>>
		The high number of immigrants that reached the arcology this week severely complicates security protocols.
		<<set _secGrowth -= 1>>
	<<else>>
		The extremely high number of immigrants that reached the arcology this week severely complicates security protocols.
		<<set _secGrowth -= 2>>
	<</if>>
<</if>>
<<if $visitors < 300>>
	The limited number of visitors coming and going did not have any serious impact on the efficiency of current security measures.
	<<set _secGrowth += 0.5>>
<<elseif _immigration < 750>>
	The number of visitors coming and going somewhat complicates security protocols.
	<<set _secGrowth -= 0.2>>
<<elseif _immigration < 1500>>
	The high number of visitors coming and going complicates security protocols.
	<<set _secGrowth -= 0.5>>
<<elseif _immigration < 2500>>
	The high number of visitors coming and going greatly complicates security protocols.
	<<set _secGrowth -= 1>>
<<else>>
	The extremely high number of visitors coming and going severely complicates security protocols.
	<<set _secGrowth -= 2>>
<</if>>
<<if _emigration != 0 && _immigration == 0>>
	<<if _emigration < 100>>
		The limited reduction in citizens this week does not have any serious impact on the efficiency of current security measures.
		<<set _secGrowth += 0.5>>
	<<elseif _emigration < 300>>
		The reduction in citizens this week is high enough to complicate security protocols.
		<<set _secGrowth -= 0.2>>
	<<elseif _emigration < 600>>
		The large reduction in citizens this week complicates security protocols.
		<<set _secGrowth -= 0.5>>
	<<elseif _emigration < 1000>>
		The huge reduction in citizens this week severely complicates security protocols.
		<<set _secGrowth -= 1>>
	<<else>>
		The extreme reduction in citizens this week severely complicates security protocols.
		<<set _secGrowth -= 2>>
	<</if>>
<</if>>
<<if $crime < 20>>
	Crime is a distant problem in the arcology, which makes improving security easier.
	<<set _secGrowth += 1>>
<<elseif $crime < 40>>
	Crime is a minor problem in the arcology, not serious enough to disrupt security efforts.
<<elseif $crime < 60>>
	Crime is an issue in the arcology, which makes improving security harder.
	<<set _secGrowth -= 0.5>>
<<elseif $crime < 80>>
	Crime is an overbearing problem in the arcology, which makes improving security a lot harder.
	<<set _secGrowth -= 1>>
<<else>>
	Crime is sovereign in the arcology, which makes improving security extremely difficult.
	<<set _secGrowth -= 2>>
<</if>>
<<if $authority < 5000>>
	The low authority you hold on the arcology hampers the efforts of your security department.
	<<set _secGrowth -= 1>>
<<elseif $authority < 7500>>
	The limited authority you hold on the arcology hampers the efforts of your security department.
	<<set _secGrowth -= 0.5>>
<<elseif $authority < 10000>>
	The authority you hold on the arcology does not significantly impact the efforts of your security department.
<<elseif $authority < 15000>>
	The high authority you hold on the arcology facilitates the security department's work.
	<<set _secGrowth += 0.5>>
<<else>>
	The absolute authority you hold on the arcology makes the security department's work a lot easier.
	<<set _secGrowth += 1>>
<</if>>
<<if $activeUnits >= 6>>
	Your military is the size of a small army. Security is easier to maintain with such forces at your disposal.
	<<set _secGrowth += 0.5>>
<</if>>
<<if $lastAttackWeeks < 3 && $hasFoughtOnce == 1>>
	The recent attack has a negative effect on the security of the arcology.
	<<set _secGrowth -= 1>>
<<elseif $lastAttackWeeks < 5 && $hasFoughtOnce == 1>>
	While some time has passed, the last attack still has a negative effect on the security of the arcology.
	<<set _secGrowth -= 0.5>>
<<elseif $hasFoughtOnce == 1>>
	The arcology has not been attacked in a while, which has a positive effect on security.
	<<set _secGrowth += 0.5>>
<</if>>

<<if $transportHub == 1>>
	<<if $terrain != "oceanic" && $terrain != "marine">>
		<<set _secGrowth -= ($airport + $railway - $hubSecurity * 3) / 2>>
	<<else>>
		<<set _secGrowth -= ($airport + $docks - $hubSecurity * 3) / 2>>
	<</if>>
	The transport hub, for all its usefulness, is a hotspot of malicious
	<<if $airport + $docks > $hubSecurity * 3>>
		activity and hub security forces are not sufficient to keep up with all threats.
	<<else>>
		activity, but the hub security forces are up to the task.
	<</if>>
<</if>>

<<if $blackOps == 1>>
	Your black ops team proves to be a formidable tool against anyone threatening the security of your arcology.
	<<set _secGrowth += 0.5 * random(1,2)>>
<</if>>

<<if $garrison.assistantTime > 0>>
	With the central CPU core of the assistant down, managing security is a much harder task. Inevitably some little but important details will slip past your agents.
	It will still take <<if $garrison.assistantTime> 1>>$garrison.assistantTime weeks<<else>>a week<</if>> to finish repair works.
	<<set _secGrowth-->>
	<<set _crimeGrowth++>>
	<<set $garrison.assistantTime--, IncreasePCSkills('engineering', 0.1)>>
<</if>>

<<if $SF.Toggle && $SF.Active >= 1>>
	<<if $SFSupportLevel >= 3>>
		The two squads of $SF.Lower assigned to the Security HQ provide an essential help to the security department.
	<</if>>
	<<if $SFSupportLevel >= 2>>
		The training officers of $SF.Lower assigned to the Security HQ improve its effectiveness.
	<</if>>
	<<if $SFSupportLevel >= 1>>
		Providing your Security Department with equipment from $SF.Lower slightly boosts the security of your arcology.
	<</if>>
<</if>>

/* resting point */
<<set _secRest = $secRestPoint * (Math.clamp($secMenials,0,$reqMenials) / $reqMenials)>>
<<if _secRest < 0>>
	<<set _secRest = 20>>
<</if>>
<<if _secRest < $secRestPoint && $secHQ == 1>>
	The limited staff assigned to the HQ hampered the improvements to security achieved this week.
<<elseif _secRest < $secRestPoint>>
	The limited infrastructure available slowly erodes away the security level of the arcology.
<</if>>

The security level of the arcology is
<<if $security > (_secRest + 5)>>
	 over its effective resting point, limiting the achievable growth this week.
	<<set _secGrowth *= 0.5>>
<<elseif $security < (_secRest - 5)>>
	under its effective resting point, speeding up its growth.
	<<set _secGrowth *= 1.5>>
<<elseif $security == _secRest>>
	at its effective resting point, this severely limits the influence of external factors on the change achievable this week.
	<<set _secGrowth *= 0.3>>
<<else>>
	near its effective resting point, this severely limits the influence of external factors on the change achievable this week.
	<<if _secGrowth < 0>>
		<<set _secGrowth *= 0.3>>
	<</if>>
<</if>>
<<set _restGrowth = (_secRest - $security) * 0.2>>
<<set _newSec = Math.trunc($security + _secGrowth + _restGrowth)>>
<<if _newSec < $security>>
	This week @@.red;security decreased.@@
<<elseif _newSec == $security>>
	This week @@.yellow;security did not change.@@
<<else>>
	This week @@.green;security improved.@@
<</if>>
<<set $security = Math.clamp(_newSec, 0, 100)>>

Crime:
/* crime modifiers */
Due to the deterioration of the old world countries, organized crime focuses more and more on the prosperous free cities, yours included. This has a
<<if $week < 30>>
	small
	<<set _crimeGrowth += 0.5>>
<<elseif $week < 60>>
	noticeable
	<<set _crimeGrowth += 1>>
<<elseif $week < 90>>
	moderate
	<<set _crimeGrowth += 1.5>>
<<elseif $week < 120>>
	big
	<<set _crimeGrowth += 2>>
<<else>>
	huge
	<<set _crimeGrowth += 2.5>>
<</if>>
 impact on the growth of criminal activities in your arcology.

<<if $arcologies[0].prosperity < 50>>
	The low prosperity of the arcology facilitates criminal recruitment and organization.
	<<set _crimeGrowth += 1>>
<<elseif $arcologies[0].prosperity < 80>>
	The fairly low prosperity of the arcology facilitates criminal recruitment and organization.
	<<set _crimeGrowth += 0.5>>
<<elseif $arcologies[0].prosperity < 120>>
	The prosperity of the arcology is not high or low enough to have significant effects on criminal recruitment and organization.
<<elseif $arcologies[0].prosperity < 160>>
	The prosperity of the arcology is high enough to provide its citizens a decent life, hampering criminal recruitment and organization.
	<<set _crimeGrowth -= 0.5>>
<<elseif $arcologies[0].prosperity < 180>>
	The prosperity of the arcology is high enough to provide its citizens a decent life, significantly hampering criminal recruitment and organization.
	<<set _crimeGrowth -= 1>>
<<else>>
	The prosperity of the arcology is high enough to provide its citizens a very good life, significantly hampering criminal recruitment and organization.
	<<set _crimeGrowth -= 2>>
<</if>>
<<if $ASlaves < 1000>>
	The low number of slaves in the arcology does not hinder the activity of law enforcement, limiting crime growth.
	<<set _crimeGrowth -= 1>>
<<elseif $ASlaves < 2000>>
	The fairly low number of slaves in the arcology does not hinder significantly the activity of law enforcement, limiting crime growth.
	<<set _crimeGrowth -= 0.5>>
<<elseif $ASlaves < 3000>>
	The number of slaves in the arcology is becoming an impediment for law enforcement, facilitating crime growth.
	<<set _crimeGrowth += 1>>
<<else>>
	The number of slaves in the arcology is becoming a big issue for law enforcement, facilitating crime growth.
	<<set _crimeGrowth += 1.5>>
<</if>>
<<if $security <= 20>>
	The security measures in place are severely limited, allowing crime to grow uncontested.
<<elseif $security <= 50>>
	The security measures in place are of limited effect and use, giving only mixed results in their fight against crime.
	<<set _crimeGrowth -= 1.5>>
<<elseif $security <= 75>>
	The security measures in place are well developed and effective, making a serious dent in the profitability of criminal activity in your arcology.
	<<set _crimeGrowth -= 3>>
<<else>>
	The security measures in place are extremely well developed and very effective, posing a serious threat even to the most powerful criminal organizations in existence.
	<<set _crimeGrowth -= 5.5>>
<</if>>
<<if $authority < 5000>>
	Your low authority allows crime to grow undisturbed.
	<<set _crimeGrowth += 1>>
<<elseif $authority < 7500>>
	Your relatively low authority facilitates criminal activities.
	<<set _crimeGrowth += 0.5>>
<<elseif $authority < 10000>>
	Your authority is not high enough to discourage criminal activity.
<<elseif $authority < 15000>>
	Your high authority is an effective tool against crime.
	<<set _crimeGrowth -= 1>>
<<else>>
	Your absolute authority is an extremely effective tool against crime.
	<<set _crimeGrowth -= 2>>
<</if>>
<<if $cash >= 100000>>
	Your great wealth acts as a beacon for the greediest criminals, calling them to your arcology as moths to a flame.
	<<set _crimeGrowth += 0.5>>
<</if>>
<<if $marketInfiltration == 1>>
	<<set _crimeGrowth += 0.5 * random(1,2)>>
<</if>>

/* crime cap */
<<set _crimeCap = Math.trunc(Math.clamp($crimeCap + ($crimeCap - $crimeCap * ($secMenials / $reqMenials)),0,100))>>
<<if _crimeCap > $crimeCap && $secHQ == 1>>
	The limited staff assigned to the HQ allows more space for criminals to act.
<</if>>
<<set _newCrime = Math.trunc(Math.clamp($crime + _crimeGrowth,0,_crimeCap))>>
<<if _newCrime > $crime>>
	This week @@.red;crime increased.@@
<<elseif _newCrime == $crime>>
	This week @@.yellow;crime did not change.@@
<<else>>
	This week @@.green;crime decreased.@@
<</if>>
<<set $crime = Math.clamp(_newCrime,0,100)>>

<<if $militiaFounded == 1 || $activeUnits >= 1>>

	 Military: /* militia */
	<<if $SF.Toggle && $SF.Active >= 1 && $SF.Size > 10>>
		Having a powerful special force attracts a lot of citizens, hopeful that they may be able to fight along side it.
	<<set _recruitsMultiplier *= 1 + (random(1, (Math.round($SF.Size / 10))) / 20)>> /* not sure how high $SF.Size goes, so I hope this makes sense */
	<</if>>
	<<if $propCampaign >= 1 && $propFocus == "recruitment">>
		<<if $RecuriterOffice == 0 || $Recruiter == 0>>
			<<if $propCampaignBoost == 1>>
				<<set _recruitsMultiplier *= 1.1>>
			<<else>>
				<<set _recruitsMultiplier *= 1.05>>
			<</if>>
		<<else>>
			<<setLocalPronouns $Recruiter>>
			''__@@.pink;<<= SlaveFullName($Recruiter)>>@@__'' is able to further boost your militia recruitment campaign from $his PR hub office.
			<<if $propCampaignBoost == 1>>
				<<set _recruitsMultiplier *= 1.2+Math.floor(($Recruiter.intelligence+$Recruiter.intelligenceImplant)/650)>>
			<<else>>
				<<set _recruitsMultiplier *= 1.15+Math.floor(($Recruiter.intelligence+$Recruiter.intelligenceImplant)/650)>>
			<</if>>
		<</if>>
	<</if>>
	<<if $recruitVolunteers == 1>>
		Your militia accepts only volunteering citizens, ready to defend their arcology.
		<<set _recruitLimit = 0.02>>
		<<if $rep >= 10000>>
			Many citizens volunteer just to fight for someone of your renown.
			<<set _recruitLimit += 0.0025>>
		<</if>>
		<<if $authority >= 10000>>
			Many citizens feel it is their duty to fight for you, boosting volunteer enrollment.
			<<set _recruitLimit += 0.0025>>
		<</if>>
		<<if $lowerRquirements == 1>>
			Your lax physical requirements to enter the militia allows for a greater number of citizens to join.
			<<set _recruitLimit += 0.0025>>
		<</if>>
	<<elseif $conscription == 1>>
		Adult citizens are required to join the militia for a period of time.
		<<set _recruitLimit = 0.05>>
		<<if $militaryExemption == 1>>
			Some citizens prefer to contribute to the arcology's defense through financial support rather than military service, making you @@.yellowgreen;a small sum.@@
			<<set _recruitLimit -= 0.005>>
			<<run cashX(250, "securityExpansion")>>
		<</if>>
		<<if $lowerRquirements == 1>>
			Your lax physical requirements to enter the militia allows for a greater number of citizens to join.
			<<set _recruitLimit += 0.005>>
		<</if>>
		<<if $noSubhumansInArmy == 1>>
			Guaranteeing the purity of your armed forces comes with a small loss of potential recruits.
			<<set _recruitLimit -= 0.005>>
		<</if>>
		<<if $pregExemption == 1>>
			Many pregnant citizens prefer to avoid military service not to endanger themselves and their children.
			<<set _recruitLimit -= 0.005>>
		<</if>>
	<<elseif $militaryService == 1>>
		Adult citizens are required to register and serve in the militia whenever necessary.
		<<set _recruitLimit = 0.1>>
		<<if $militaryExemption == 1>>
			Some citizens prefer to contribute to the arcology's defense through financial support rather than military service, making you @@.yellowgreen;a small sum.@@
			<<set _recruitLimit -= 0.01>>
			<<run cashX(250, "securityExpansion")>>
		<</if>>
		<<if $lowerRquirements == 1>>
			Your lax physical requirements to enter the militia allows for a greater number of citizens to join.
			<<set _recruitLimit += 0.01>>
		<</if>>
		<<if $noSubhumansInArmy == 1>>
			Guaranteeing the purity of your armed forces comes with a small loss of potential recruits.
			<<set _recruitLimit -= 0.01>>
		<</if>>
		<<if $pregExemption == 1>>
			Many pregnant citizens prefer to avoid military service not to endanger themselves and their children.
			<<set _recruitLimit -= 0.01>>
		<</if>>
	<<elseif $militarizedSociety == 1>>
		Every citizen is required to train and participate in the military activities of the arcology.
		<<set _recruitLimit = 0.2>>
		<<if $militaryExemption == 1>>
			Some citizens prefer to contribute to the arcology's defense through financial support rather than military service, making you @@.yellowgreen;a small sum.@@
			<<set _recruitLimit -= 0.02>>
			<<run cashX(250, "securityExpansion")>>
		<</if>>
		<<if $lowerRquirements == 1>>
			Your lax physical requirements to enter the militia allows for a greater number of citizens to join.
			<<set _recruitLimit += 0.02>>
		<</if>>
		<<if $noSubhumansInArmy == 1>>
			Guaranteeing the purity of your armed forces comes with a small loss of potential recruits.
			<<set _recruitLimit -= 0.02>>
		<</if>>
		<<if $pregExemption == 1>>
			Many pregnant citizens prefer to avoid military service not to endanger themselves and their children.
			<<set _recruitLimit -= 0.02>>
		<</if>>
	<</if>>
	<<if $militiaFounded == 1>>
		<<set _recruits = Math.trunc((_recruitLimit * $ACitizens - ($militiaTotalManpower - $militiaTotalCasualties)) / 20 * _recruitsMultiplier)>>
		<<if _recruits > 0>>
			<<set $militiaTotalManpower += _recruits>>
			<<set $militiaFreeManpower += _recruits>>
			This week <<print _recruits>> citizens joined the militia.
		<<elseif $militarizedSociety == 1>>
			No citizens joined your militia this week because your society is as militarized as it can get.
		<<elseif $recruitVolunteers == 1>>
			There are no more citizens willing to join the arcology armed forces. You'll need to enact higher recruitment edicts if you need more manpower.
		<<else>>
			No more citizens could be drafted into your militia. You'll need to enact higher recruitment edicts if you need more manpower.
		<</if>>

	<</if>>

	/* mercs */
	<<if $mercenaries >= 1>>
		<<set _newMercs = random(0,3)>>
		<<if $rep < 6000>>
			Your low reputation turns some mercenaries away, hoping to find contracts that would bring them more renown.
			<<set _newMercs -= 1>>
		<<elseif $rep < 12000>>
			Your reputation is not high enough to attract many mercenaries to your free city.
		<<else>>
			Your reputation attracts many guns for hire who would be proud to have such distinct character on their resume.
			<<set _newMercs += 1>>
		<</if>>
		<<if $arcologies[0].prosperity < 50>>
			The low prosperity of the arcology discourages new guns for hire from coming to your arcology.
			<<set _newMercs -= 1>>
		<<elseif $arcologies[0].prosperity < 80>>
			The fairly low prosperity of the arcology discourages new guns for hire from coming to your arcology.
			<<set _newMercs += 1>>
		<<elseif $arcologies[0].prosperity < 120>>
			The prosperity of the arcology attracts a few mercenaries, hopeful to find lucrative contracts within its walls.
			<<set _newMercs += random(1,2)>>
		<<elseif $arcologies[0].prosperity < 160>>
			The fairly high prosperity of the arcology attracts some mercenaries, hopeful to find lucrative contracts within its walls.
			<<set _newMercs += random(2,3)>>
		<<elseif $arcologies[0].prosperity < 180>>
			The high prosperity of the arcology is attracts some mercenaries, hopeful to find lucrative contracts within its walls.
			<<set _newMercs += random(2,4)>>
		<<else>>
			The very high prosperity of the arcology attracts a lot of mercenaries, hopeful to find lucrative contracts within its walls.
			<<set _newMercs += random(3,5)>>
		<</if>>
		<<if $crime > 60>>
			The powerful crime organizations that nested themselves in the arcology have an unending need for cheap guns for hire, many mercenaries flock to your free city in search of employment.
			<<set _newMercs += random(1,2)>>
		<</if>>
		<<if $SF.Toggle && $SF.Active >= 1 && $SF.Size > 10>>
			Having a powerful special force attracts a lot of mercenaries, hopeful that they may be able to fight along side it.
			<<set _newMercs += random(1,Math.round($SF.Size/10))>>
		<</if>>
		<<if $discountMercenaries > 0>>
			More mercenaries are attracted to your arcology as a result of the reduced rent.
			<<set _newMercs += random(2,4)>>
		<</if>>
		<<set _newMercs = Math.trunc(_newMercs / 2)>>
		<<if _newMercs > 0>>
			<<set $mercTotalManpower += _newMercs>>
			<<set $mercFreeManpower += _newMercs>>
			This week <<print _newMercs>> mercenaries reached the arcology.
		<<else>>
			This week no new mercenaries reached the arcology.
		<</if>>
		<<if $mercFreeManpower > 2000>>
			<<set $mercTotalManpower -= $mercFreeManpower - 2000>>
			<<set $mercFreeManpower = 2000>>
		<</if>>

	<</if>>

	<<if $activeUnits > 0>>
		/* loyalty and training */
		<<set _sL = $slaveUnits.length>>
		<<for _i = 0; _i < _sL; _i++>>
			<<set _loyaltyChange = 0>>

 $slaveUnits[_i].platoonName:
			<<if $secBarracksUpgrades.loyaltyMod >= 1>>
				<<set _loyaltyChange += 2 * $secBarracksUpgrades.loyaltyMod>>
				is periodically sent to the indoctrination facility in the barracks for thought correction therapy.
			<</if>>
			<<if $slaveUnits[_i].commissars >= 1>>
				The commissars attached to the unit carefully monitor the officers and grunts for signs of insubordination.
				<<set _loyaltyChange += 2 * $slaveUnits[_i].commissars>>
			<</if>>
			<<if $soldierWages == 2>>
				The slaves greatly appreciate the generous wage given to them for their service as soldiers. Occasions to earn money for a slave are scarce after all.
				<<set _loyaltyChange += random(5,10)>>
			<<elseif $soldierWages == 1>>
				The slaves appreciate the wage given to them for their service as soldiers, despite it being just adequate. Occasions to earn money for a slave are scarce after all.
				<<set _loyaltyChange += random(-5,5)>>
			<<else>>
				The slaves do not appreciate the low wage given to them for their service as soldiers, but occasions to earn money for a slave are scarce, so they're not too affected by it.
				<<set _loyaltyChange -= random(5,10)>>
			<</if>>
			<<if $slaveSoldierPrivilege == 1>>
				Allowing them to hold material possessions earns you their devotion and loyalty.
				<<set _loyaltyChange += random(1,2)>>
			<</if>>
			<<if _loyaltyChange > 0>>
				The loyalty of this unit @@.green;increased@@ this week.
			<<elseif _loyaltyChange == 0>>
				The loyalty of this unit @@.yellow;did not change@@ this week.
			<<else>>
				The loyalty of this unit @@.red;decreased@@ this week.
			<</if>>
			<<set $slaveUnits[_i].loyalty = Math.clamp($slaveUnits[_i].loyalty + _loyaltyChange,0,100)>>
			<<if $slaveUnits[_i].training < 100 && $secBarracksUpgrades.training >= 1>>

The unit is able to make use of the training facilities to better prepare its soldiers, slowly increasing their experience level.
				<<set $slaveUnits[_i].training += random(2,4) * 1.5 * $secBarracksUpgrades.training>>
			<</if>>
		<</for>>
		<<set _mL = $militiaUnits.length>>
		<<for _i = 0; _i < _mL; _i++>>

$militiaUnits[_i].platoonName:
			<<set _loyaltyChange = 0>>
			<<if $secBarracksUpgrades.loyaltyMod >= 1>>
				<<set _loyaltyChange += 2 * $secBarracksUpgrades.loyaltyMod>>
				is periodically sent to the indoctrination facility in the barracks for thought correction therapy.
			<</if>>
			<<if $militiaUnits[_i].commissars >= 1>>
				The commissars attached to the unit carefully monitor the officers and grunts for signs of insubordination.
				<<set _loyaltyChange += 2 * $militiaUnits[_i].commissars>>
			<</if>>
			<<if $soldierWages == 2>>
				The soldiers greatly appreciate the generous wage given to them for their service. They are proud to defend their homes while making a small fortune out of it.
				<<set _loyaltyChange += random(5,10)>>
			<<elseif $soldierWages == 1>>
				The soldiers appreciate the wage given to them for their service, despite it being just adequate. They are proud to defend their homes, though at the cost of possible financial gains.
				<<set _loyaltyChange += random(-5,5)>>
			<<else>>
				The soldiers do not appreciate the low wage given to them for their service. Their sense of duty keeps them proud of their role as defenders of the arcology, but many do feel its financial weight.
				<<set _loyaltyChange -= random(5,10)>>
			<</if>>
			<<if $militiaSoldierPrivilege == 1>>
				Allowing them to avoid rent payment for their military service earns you their happiness and loyalty.
				<<set _loyaltyChange += random(1,2)>>
			<</if>>
			<<if _loyaltyChange > 0>>
				The loyalty of this unit @@.green;increased@@ this week.
			<<elseif _loyaltyChange == 0>>
				The loyalty of this unit @@.yellow;did not change@@ this week.
			<<else>>
				The loyalty of this unit @@.red;decreased@@ this week.
			<</if>>
			<<set $militiaUnits[_i].loyalty = Math.clamp($militiaUnits[_i].loyalty + _loyaltyChange,0,100)>>
			<<if $militiaUnits[_i].training < 100 && $secBarracksUpgrades.training >= 1>>

The unit is able to make use of the training facilities to better prepare its soldiers, slowly increasing their experience level.
				<<set $militiaUnits[_i].training += random(2,4) * 1.5 * $secBarracksUpgrades.training>>
			<</if>>
		<</for>>
		<<set _meL = $mercUnits.length>>
		<<for _i = 0; _i < _meL; _i++>>

$mercUnits[_i].platoonName:
			<<set _loyaltyChange = 0, _loyaltyTotal = 0>>
			<<if $secBarracksUpgrades.loyaltyMod >= 1>>
				<<set _loyaltyChange += 2 * $secBarracksUpgrades.loyaltyMod>>
				is periodically sent to the indoctrination facility in the barracks for thought correction therapy.
			<</if>>
			<<if $mercUnits[_i].commissars >= 1>>
				The commissars attached to the unit carefully monitor the officers and grunts for signs of insubordination.
				<<set _loyaltyChange += 2 * $mercUnits[_i].commissars>>
			<</if>>
			<<if $soldierWages == 2>>
				The mercenaries greatly appreciate the generous wage given to them for their service. After all coin is the fastest way to reach their hearts.
				<<set _loyaltyChange += random(5,10)>>
			<<elseif $soldierWages == 1>>
				The mercenaries do not appreciate the barely adequate wage given to them for their service. Still their professionalism keeps them determined to finish their contract.
				<<set _loyaltyChange += random(-5,5)>>
			<<else>>
				The mercenaries do not appreciate the low wage given to them for their service.Their skill would be better served by a better contract and this world does not lack demand for guns for hire.
				<<set _loyaltyChange -= random(5,10)>>
			<</if>>
			<<if $mercSoldierPrivilege == 1>>
				Allowing them to keep part of the loot gained from your enemies earns you their trust and loyalty.
				<<set _loyaltyChange += random(1,2)>>
			<</if>>
			<<if _loyaltyChange > 0>>
				The loyalty of this unit @@.green;increased@@ this week.
			<<elseif _loyaltyChange == 0>>
				The loyalty of this unit @@.yellow;did not change@@ this week.
			<<else>>
				The loyalty of this unit @@.red;decreased@@ this week.
			<</if>>
			<<set $mercUnits[_i].loyalty = Math.clamp($mercUnits[_i].loyalty + _loyaltyChange,0,100)>>
			<<set _loyaltyTotal += $mercUnits[_i].loyalty>>
			<<if $mercUnits[_i].training < 100 && $secBarracksUpgrades.training >= 1>>

The unit is able to make use of the training facilities to better prepare its soldiers, slowly increasing their experience level.
				<<set $mercUnits[_i].training += random(2,4) * 1.5 * $secBarracksUpgrades.training>>
			<</if>>
		<</for>>
		<<if _meL > 0>>
			<<set $mercLoyalty = (_loyaltyTotal/_meL)>>
		<</if>>
	<</if>>
<</if>>

<<if $brainImplantProject > 0 && $brainImplant < 106>>

	<<set $brainImplant += $brainImplantProject>>
	<<if 100 - $brainImplant <= 0>>
		The project has been completed!
		<<set $brainImplant = 106>>
		<<set $riotUpkeep -= 5000 * $brainImplantProject>>
	<<else>>
		The great brain implant project is proceeding steadily. This week we made
		<<if $brainImplantProject <= 2>>
			some small
		<<elseif $brainImplantProject <= 4>>
			some
		<<else>>
			good
		<</if>>
		progress.
	<</if>>
<</if>>

<<if $currentUpgrade.time > 0>>

	In the research lab, <<print $currentUpgrade.name>>
	<<switch $currentUpgrade.name>>
	<<case "adaptive armored frames" "advanced synthetic alloys" "ceramo-metallic alloys" "rapid action stimulants" "universal cyber enhancements" "remote neural links" "combined training regimens with the special force">>
		are
	<<default>>
		is
	<</switch>>
	being developed, with the objective to enhance
	<<if $currentUpgrade.type == "attack">>
		attack power
	<<elseif $currentUpgrade.type == "defense">>
		defense capabilities
	<<elseif $currentUpgrade.type == "hp">>
		survivability
	<<elseif $currentUpgrade.type == "morale">>
		standing power
	<<elseif $currentUpgrade.type == "attackAndDefense">>
		offensive and defensive effectiveness
	<<elseif $currentUpgrade.type == "hpAndMorale">>
		morale and survivability
	<<elseif $currentUpgrade.type == "all">>
		offensive,defensive effectiveness in addition to morale and survivability
	<</if>>
	for <<if $currentUpgrade.unit == 0>> the security drones<<else>> our human troops<</if>>.

	<<set $currentUpgrade.time-->>
	<<if $currentUpgrade.time <= 0>>
		Reports indicate it is ready for deployment and will be issued to
		<<if $currentUpgrade.unit == 0>>
			the security drones
			<<if $currentUpgrade.type == "attack">>
				<<set $droneUpgrades.attack++>>
			<<elseif $currentUpgrade.type == "defense">>
				<<set $droneUpgrades.defense++>>
			<<elseif $currentUpgrade.type == "hp">>
				<<set $droneUpgrades.hp++>>
			<</if>>
		<<else>>
			all human troops
			<<if $currentUpgrade.type == "attack">>
				<<set $humanUpgrade.attack++>>
			<<elseif $currentUpgrade.type == "defense">>
				<<set $humanUpgrade.defense++>>
			<<elseif $currentUpgrade.type == "hp">>
				<<set $humanUpgrade.hp++>>
			<<elseif $currentUpgrade.type == "morale">>
				<<set $humanUpgrade.morale += 10>>
			<<elseif $currentUpgrade.type == "attackAndDefense">>
				<<set $humanUpgrade.attack++>>
				<<set $humanUpgrade.defense++>>
			<<elseif $currentUpgrade.type == "hpAndMorale">>
				<<set $humanUpgrade.hp++>>
				<<set $humanUpgrade.morale += 10>>
			<<elseif $currentUpgrade.type == "all">>
				<<set $humanUpgrade.attack++>>
				<<set $humanUpgrade.defense++>>
				<<set $humanUpgrade.hp++>>
				<<set $humanUpgrade.morale += 10>>
			<</if>>
		<</if>>
		<<set $currentUpgrade.name = " ">>
		<<set $currentUpgrade.type = " ">>
		<<set $currentUpgrade.unit = -1>>
		<<set $currentUpgrade.time = 0>>
		in the following days.
		<<recalcBaseStats>>
		<<set $completedUpgrades.push($currentUpgrade.ID)>>
	<<else>>
		It will be finished in <<if $currentUpgrade.time == 1>> one week.<<else>><<print $currentUpgrade.time>> weeks.<</if>>
	<</if>>
<</if>>


code:
:: seeUnit [nobr]

<<if $attackThisWeek == 1>>
	<<set $nextButton = "Back", $nextLink = "attackOptions", $returnTo = "secBarracks">>
<<else>>
	<<set $nextButton = "Back", $nextLink = "secBarracks", $returnTo = "secBarracks">>
<</if>>

<<if $targetUnit == "secBots">>
	<<secBotsDescription>>
	<<if $secBots.maxTroops > $secBots.troops>>

		<<link "Replenish the unit" "seeUnit">>
			<<run cashX(forceNeg(($secBots.maxTroops - $secBots.troops) * $secBotsCost), "securityExpansion")>>
			<<set $secBots.troops = $secBots.maxTroops>>
		<</link>>
	<</if>>

	<<if $secBots.maxTroops < 80>>

		<<link "Improve the digital control matrix" "seeUnit">>
			<<set $secBots.maxTroops += 10>>
			<<run cashX(-5000, "securityExpansion")>>
		<</link>>
		Invest in the development of more refined controls for your drones to increase the maximum number of drones in the unit.

//Costs <<print cashFormat(5000)>> per upgrade and each will increase the max by 10//
	<<elseif $SF.Toggle && $SF.Active >= 1 && $secBots.maxTroops < 100 && $SFSupportLevel >= 1>>

		<<link "Refine the drone network with $SF.Lower assistance" "seeUnit">>
		<<set $secBots.maxTroops += 10>>
			<<run cashX(forceNeg(5000 + 10 * $secBotsUpgradeCost * $secBots.equip), "securityExpansion")>>
		<</link>>
		Utilize the technological developments made by $SF.Lower to further improve the control matrix of the security drones.

//Costs <<print cashFormat(5000 + 10 * $secBotsUpgradeCost * $secBots.equip)>> and will increase the max by 10//
	<<elseif $SF.Toggle && $SF.Active >= 1 && $SFSupportLevel < 1>>
		There's little left to improve in the matrix. However support from $SF.Lower might give some more room from improvement.
	<<else>>
		There's little left to improve in the matrix. Your control systems are at top capacity and won't be able to handle a bigger drone unit.
	<</if>>
	<<if $secBots.equip < 3>>

		<<link "Improve drone weaponry and armor" "seeUnit">>
			<<set $secBots.equip += 1>>
			<<run cashX(forceNeg(($secBotsUpgradeCost * $secBots.maxTroops) + 1000), "securityExpansion")>>
		<</link>>
		Invest in better equipment for your drones to increase their battle effectiveness.

//Costs <<print cashFormat(($secBotsUpgradeCost * $secBots.maxTroops) + 1000)>> and will increase attack and defense value of the unit by 15% for every upgrade.//
	<<else>>

		Your drones are equipped with top tier weaponry and armor.
	<</if>>
	<<if $showBattleStatistics == 1>>

Security drones base attack: $secBotsBaseAttack <<if $droneUpgrades.attack > 0>> + 1 <</if>>(<<print Math.round($secBotsBaseAttack + $secBotsBaseAttack * $secBots.equip * 0.15)>>)

Security drones base defense: $secBotsBaseDefense <<if $droneUpgrades.defense > 0>> + 1 <</if>>(<<print Math.round($secBotsBaseDefense + $secBotsBaseDefense * $secBots.equip * 0.15)>>)

Equipment bonus: + <<print $secBots.equip * 15>>%

Security drones base hp: $secBotsBaseHp <<if $droneUpgrades.hp > 0>> + 1 <</if>>

Security drones base morale: $secBotsMorale
	<</if>>
<<elseif $targetUnit == "militiaUnits">>
	<<militiaUnitsDescription $militiaUnits[$targetIndex]>>

	Rename unit <<textbox "$militiaUnits[$targetIndex].platoonName" $militiaUnits[$targetIndex].platoonName "seeUnit">>
	<<if $militiaUnits[$targetIndex].maxTroops > $militiaUnits[$targetIndex].troops && $militiaFreeManpower > 0>>

		<<link "Replenish unit" "seeUnit">>
			<<if $militiaFreeManpower >= $militiaUnits[$targetIndex].maxTroops - $militiaUnits[$targetIndex].troops>>
				<<set $militiaFreeManpower -= $militiaUnits[$targetIndex].maxTroops - $militiaUnits[$targetIndex].troops>>
				<<set $militiaEmployedManpower += $militiaUnits[$targetIndex].maxTroops - $militiaUnits[$targetIndex].troops>>
				<<set _expLoss = ($militiaUnits[$targetIndex].maxTroops - $militiaUnits[$targetIndex].troops) / $militiaUnits[$targetIndex].troops>>
				<<set $militiaUnits[$targetIndex].training -= $militiaUnits[$targetIndex].training * _expLoss>>
				<<set $militiaUnits[$targetIndex].troops = $militiaUnits[$targetIndex].maxTroops>>
			<<else>>
				<<set $militiaEmployedManpower += $militiaFreeManpower>>
				<<set _expLoss = $militiaFreeManpower / $militiaUnits[$targetIndex].troops>>
				<<set $militiaUnits[$targetIndex].training -= $militiaUnits[$targetIndex].training * _expLoss>>
				<<set $militiaUnits[$targetIndex].troops += $militiaFreeManpower>>
				<<set $militiaFreeManpower = 0>>
			<</if>>
		<</link>>
	<</if>>

	<<if $militiaUnits[$targetIndex].maxTroops < 50>>

		<<link "Intensive officers training" "seeUnit">>
			<<set $militiaUnits[$targetIndex].maxTroops += 10>>
			<<run cashX(forceNeg(5000 + 10 * $equipUpgradeCost * ($militiaUnits[$targetIndex].equip + $militiaUnits[$targetIndex].commissars + $militiaUnits[$targetIndex].cyber + $militiaUnits[$targetIndex].SF)), "securityExpansion")>>
		<</link>>
		Invest in the training of your officers to increase the maximum number of soldiers in the unit.

//Costs <<print cashFormat(5000 + 10 * $equipUpgradeCost * ($militiaUnits[$targetIndex].equip + $militiaUnits[$targetIndex].commissars + $militiaUnits[$targetIndex].cyber + $militiaUnits[$targetIndex].SF))>> and will increase the max by 10//
	<<else>>

		Your officers reached their peak. Further training will have little impact on the number of troops they can effectively lead.
	<</if>>
	<<if $militiaUnits[$targetIndex].equip < 3>>

		<<link "Improve weaponry and equipment" "seeUnit">>
			<<set $militiaUnits[$targetIndex].equip += 1>>
			<<run cashX(forceNeg(($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 1000), "securityExpansion")>>
		<</link>>
		Invest in better equipment for your soldiers to increase their battle effectiveness.

//Costs <<print cashFormat(($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 1000)>> and will increase attack and defense value of the unit by 15% for every upgrade.//
	<<else>>

		The unit is equipped with state of the art weaponry and equipment.
	<</if>>
	<<if $militiaUnits[$targetIndex].commissars == 0>>

		<<link "Attach commissars to the unit" "seeUnit">>
			<<set $militiaUnits[$targetIndex].commissars = 1>>
			<<run cashX(forceNeg($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops + 1000), "specialForces")>>
		<</link>>
		Attach a small squad of commissars to the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 1000)>> and will slowly increase the loyalty of the unit.//
	<<elseif $militiaUnits[$targetIndex].commissars < 2>>

		<<link "Intensive loyalty training" "seeUnit">>
			<<set $militiaUnits[$targetIndex].commissars += 1>>
			<<run cashX(forceNeg($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops + 1000), "specialForces")>>
		<</link>>
		Provide special training for the officers and the commissars of the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 1000)>> and will increase the loyalty of the unit faster.//
	<<elseif $militiaUnits[$targetIndex].commissars == 1>>

The unit has a commissar detachment, keeping under control the ambitions of the unit's officers.
	<<else>>

The unit has a perfectly trained and loyal commissar detachment, keeping under control the ambitions of the unit's officers.
	<</if>>
	<<if $prostheticsUpgrade >= 2 || $researchLab.advCombatPLimb == 1>>
		<<if $militiaUnits[$targetIndex].cyber == 0>>

			<<link "Provide enhanced cybernetic enhancements" "seeUnit">>
				<<set $militiaUnits[$targetIndex].cyber += 1>>
				<<run cashX(forceNeg($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops + 2000), "specialForces")>>
			<</link>>
			Will augment all soldiers of the unit with high tech cyber enhancements.

//Costs <<print cashFormat(($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 2000)>> and will increase attack, defense and base hp values of the unit.//
		<<else>>

The unit is equipped with advanced cybernetic enhancements.
		<</if>>
	<</if>>
	<<if $militiaUnits[$targetIndex].medics == 0>>

		<<link "Attach trained medics to the unit" "seeUnit">>
			<<set $militiaUnits[$targetIndex].medics = 1>>
			<<run cashX(forceNeg($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops + 1000), "specialForces")>>
		<</link>>
		Attach a small squad of trained medics to the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 1000)>> and will decrease the number of casualties suffered during battle.//
	<<else>>

The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers.
	<</if>>
	<<if $SF.Toggle && $SF.Active >= 1>>
		<<if $militiaUnits[$targetIndex].SF == 0>>

			<<link "Attach Special Force advisors" "seeUnit">>
				<<set $militiaUnits[$targetIndex].SF = 1>>
				<<run cashX(forceNeg(($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 5000), "securityExpansion")>>
			<</link>>
			Attach $SF.Lower advisors to the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $militiaUnits[$targetIndex].maxTroops) + 5000)>> and will slightly increase the base stats of the unit.//
		<<else>>

The unit has attached advisors from $SF.Lower that will help the squad remain tactically aware and active.
		<</if>>
	<</if>>

	<<if $showBattleStatistics == 1>>
		<<if $militiaUnits[$targetIndex].training <= 10>>
			<<set _expBonus = 0>>
		<<elseif $militiaUnits[$targetIndex].training <= 33>>
			<<set _expBonus = 10>>
		<<elseif $militiaUnits[$targetIndex].training <= 66>>
			<<set _expBonus = 25>>
		<<else>>
			<<set _expBonus = 50>>
		<</if>>
		<<if $militiaUnits[$targetIndex].loyalty <= 10>>
			<<set _loyaltyBonus = 0>>
		<<elseif $militiaUnits[$targetIndex].loyalty <= 33>>
			<<set _loyaltyBonus = 10>>
		<<elseif $militiaUnits[$targetIndex].loyalty <= 66>>
			<<set _loyaltyBonus = 20>>
		<<else>>
			<<set _loyaltyBonus = 30>>
		<</if>>

Militia base attack: $militiaBaseAttack <<if $humanUpgrade.attack > 0>> + $humanUpgrade.attack <</if>>(<<print Math.round($militiaBaseAttack + $militiaUnits[$targetIndex].cyber + $militiaBaseAttack * $militiaUnits[$targetIndex].equip * $equipMod + $militiaBaseAttack * _expBonus * 0.01 + $militiaBaseAttack * _loyaltyBonus * 0.01 + $militiaBaseAttack * $militiaUnits[$targetIndex].SF * 0.20)>>)

Militia base defense: $militiaBaseDefense <<if $humanUpgrade.defense > 0>> + $humanUpgrade.defense <</if>>(<<print Math.round($militiaBaseDefense + $militiaUnits[$targetIndex].cyber + $militiaBaseDefense * $militiaUnits[$targetIndex].equip * $equipMod + $militiaBaseDefense * _expBonus * 0.01 + $militiaBaseDefense * _loyaltyBonus * 0.01 + $militiaBaseDefense * $militiaUnits[$targetIndex].SF * 0.20)>>)
		<<if $militiaUnits[$targetIndex].equip > 0>>

Equipment bonus: + <<print $militiaUnits[$targetIndex].equip * 15>>%
		<</if>>
		<<if $militiaUnits[$targetIndex].cyber > 0>>

Cyber enhancements bonus: + 1
		<</if>>
		<<if _expBonus > 0>>

Experience bonus: +<<print _expBonus>>%
		<</if>>
		<<if _loyaltyBonus > 0>>

Loyalty bonus: +<<print _loyaltyBonus>>%
		<</if>>
		<<if $militiaUnits[$targetIndex].SF > 0>>

Special Force advisors bonus: +20%
		<</if>>

Militia base morale: $militiaBaseMorale <<if $humanUpgrade.morale > 0>> + $humanUpgrade.morale <</if>>(<<print Math.round($militiaBaseMorale + $militiaBaseMorale * $secBarracksUpgrades.luxury * 0.05)>>)
		<<if $secBarracksUpgrades.luxury > 0>>

Barracks bonus: + <<print $secBarracksUpgrades.luxury * 5>>%
		<</if>>

Militia base hp: $militiaBaseHp <<if $humanUpgrade.hp > 0>> + $humanUpgrade.hp <</if>>(<<print Math.round($militiaBaseHp + $militiaUnits[$targetIndex].cyber + $militiaBaseHp * $militiaUnits[$targetIndex].medics * 0.25)>>)
		<<if $militiaUnits[$targetIndex].medics > 0>>

Medics detachment bonus: +25%
		<</if>>
	<</if>>
<<elseif $targetUnit == "slaveUnits">>
	<<slaveUnitsDescription $slaveUnits[$targetIndex]>>

	Rename unit <<textbox "$slaveUnits[$targetIndex].platoonName" $slaveUnits[$targetIndex].platoonName "seeUnit">>
	<<if $slaveUnits[$targetIndex].maxTroops > $slaveUnits[$targetIndex].troops && $menials > 0>>

		<<link "Replenish unit" "seeUnit">>
			<<if $menials >= $slaveUnits[$targetIndex].maxTroops - $slaveUnits[$targetIndex].troops>>
				<<set $menials -= $slaveUnits[$targetIndex].maxTroops - $slaveUnits[$targetIndex].troops>>
				<<set $slavesEmployedManpower += $slaveUnits[$targetIndex].maxTroops - $slaveUnits[$targetIndex].troops>>
				<<set _expLoss = ($slaveUnits[$targetIndex].maxTroops - $slaveUnits[$targetIndex].troops) / $slaveUnits[$targetIndex].troops>>
				<<set $slaveUnits[$targetIndex].training -= $slaveUnits[$targetIndex].training * _expLoss>>
				<<set $slaveUnits[$targetIndex].troops = $slaveUnits[$targetIndex].maxTroops>>
			<<else>>
				<<set $slavesEmployedManpower += $menials>>
				<<set _expLoss = $menials / $slaveUnits[$targetIndex].troops>>
				<<set $slaveUnits[$targetIndex].training -= $slaveUnits[$targetIndex].training * _expLoss>>
				<<set $slaveUnits[$targetIndex].troops += $menials>>
				<<set $menials = 0>>
			<</if>>
		<</link>>
	<</if>>

	<<if $slaveUnits[$targetIndex].maxTroops < 50>>

		<<link "Intensive officers training" "seeUnit">>
			<<set $slaveUnits[$targetIndex].maxTroops += 10>>
			<<run cashX(forceNeg(5000 + 10 * $equipUpgradeCost * ($slaveUnits[$targetIndex].equip + $slaveUnits[$targetIndex].commissars + $slaveUnits[$targetIndex].cyber + $slaveUnits[$targetIndex].SF)), "securityExpansion")>>
		<</link>>
		Invest in the training of your officers to increase the maximum number of soldiers in the unit.

//Costs <<print cashFormat(5000 + 10 * $equipUpgradeCost * ($slaveUnits[$targetIndex].equip + $slaveUnits[$targetIndex].commissars + $slaveUnits[$targetIndex].cyber + $slaveUnits[$targetIndex].SF))>> and will increase the max by 10//
	<<else>>

Your officers reached their peak. Further training will have little impact on the number of troops they can effectively lead.
	<</if>>
	<<if $slaveUnits[$targetIndex].equip < 3>>

		<<link "Improve weaponry and equipment">>
			<<set $slaveUnits[$targetIndex].equip += 1>>
			<<run cashX(forceNeg($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops + 1000), "securityExpansion")>>
			<<goto "seeUnit">>
		<</link>>
		Invest in better equipment for your soldiers to increase their battle effectiveness.

//Costs <<print cashFormat(($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 1000)>> and will increase attack and defense value of the unit by 15% for every upgrade.//
	<<else>>

The unit is equipped with state of the art weaponry and equipment.
	<</if>>
	<<if $slaveUnits[$targetIndex].commissars == 0>>

		<<link "Attach commissars to the unit" "seeUnit">>
			<<set $slaveUnits[$targetIndex].commissars = 1>>
			<<run cashX(forceNeg($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops + 1000), "specialForces")>>
		<</link>>
		Attach a small squad of commissars to the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 1000)>> and will slowly increase the loyalty of the unit.//
	<<elseif $slaveUnits[$targetIndex].commissars < 2>>

		<<link "Intensive loyalty training" "seeUnit">>
			<<set $slaveUnits[$targetIndex].commissars += 1>>
			<<run cashX(forceNeg($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops + 1000), "specialForces")>>
		<</link>>
		Provide special training for the officers and the commissars of the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 1000)>> and will increase the loyalty of the unit faster.//
	<<elseif $slaveUnits[$targetIndex].commissars == 1>>

The unit has a commissar detachment, keeping under control the ambitions of the unit's officers.
	<<else>>

The unit has a perfectly trained and loyal commissar detachment, keeping under control the ambitions of the unit's officers.
	<</if>>
	<<if $prostheticsUpgrade >= 2 || $researchLab.advCombatPLimb == 1>>
		<<if $slaveUnits[$targetIndex].cyber == 0>>

			<<link "Provide enhanced cybernetic enhancements" "seeUnit">>
				<<set $slaveUnits[$targetIndex].cyber += 1>>
				<<run cashX(forceNeg($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops + 2000), "specialForces")>>
			<</link>>
			Will augment all soldiers of the unit with high tech cyber enhancements.

//Costs <<print cashFormat(($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 2000)>> and will increase attack, defense and base hp values of the unit.//
		<<else>>

The unit is equipped with advanced cybernetic enhancements.
		<</if>>
	<</if>>
	<<if $slaveUnits[$targetIndex].medics == 0>>

		<<link "Attach trained medics to the unit" "seeUnit">>
			<<set $slaveUnits[$targetIndex].medics = 1>>
			<<run cashX(forceNeg($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops + 1000), "specialForces")>>
		<</link>>
		Attach a small squad of trained medics to the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 1000)>> and will decrease the number of casualties suffered during battle.//
	<<else>>

The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers.
	<</if>>
	<<if $SF.Toggle && $SF.Active >= 1>>
		<<if $slaveUnits[$targetIndex].SF == 0>>

			<<link "Attach Special Force advisors" "seeUnit">>
				<<set $slaveUnits[$targetIndex].SF = 1>>
				<<run cashX(forceNeg(($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 5000), "specialForces")>>
			<</link>>
			Attach $SF.Lower advisors to the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $slaveUnits[$targetIndex].maxTroops) + 5000)>> and will slightly increase the base stats of the unit.//
		<<else>>

The unit has attached advisors from $SF.Lower that will help the squad remain tactically aware and active.
		<</if>>
	<</if>>
	<<if $showBattleStatistics == 1>>
		<<if $slaveUnits[$targetIndex].training <= 10>>
			<<set _expBonus = 0>>
		<<elseif $slaveUnits[$targetIndex].training <= 33>>
			<<set _expBonus = 10>>
		<<elseif $slaveUnits[$targetIndex].training <= 66>>
			<<set _expBonus = 25>>
		<<else>>
			<<set _expBonus = 50>>
		<</if>>
		<<if $slaveUnits[$targetIndex].loyalty <= 10>>
			<<set _loyaltyBonus = 0>>
		<<elseif $slaveUnits[$targetIndex].loyalty <= 33>>
			<<set _loyaltyBonus = 10>>
		<<elseif $slaveUnits[$targetIndex].loyalty <= 66>>
			<<set _loyaltyBonus = 20>>
		<<else>>
			<<set _loyaltyBonus = 30>>
		<</if>>

Slaves base attack: $slaveBaseAttack <<if $humanUpgrade.attack > 0>> + $humanUpgrade.attack <</if>>(<<print Math.round($slaveBaseAttack + $slaveUnits[$targetIndex].cyber + $slaveBaseAttack * $slaveUnits[$targetIndex].equip * $equipMod + $slaveBaseAttack * _expBonus * 0.01 + $slaveBaseAttack * _loyaltyBonus * 0.01 + $slaveBaseAttack * $slaveUnits[$targetIndex].SF * 0.20)>>)

Slaves base defense: $slaveBaseDefense <<if $humanUpgrade.defense > 0>> + $humanUpgrade.defense <</if>>(<<print Math.round($slaveBaseDefense + $slaveUnits[$targetIndex].cyber + $slaveBaseDefense * $slaveUnits[$targetIndex].equip * $equipMod + $slaveBaseDefense * _expBonus * 0.01 + $slaveBaseDefense * _loyaltyBonus * 0.01 + $slaveBaseDefense * $slaveUnits[$targetIndex].SF * 0.20)>>)
		<<if $slaveUnits[$targetIndex].equip > 0>>

Equipment bonus: + <<print $slaveUnits[$targetIndex].equip * 15>>%
		<</if>>
		<<if $slaveUnits[$targetIndex].cyber > 0>>

Cyber enhancements bonus: + 1
		<</if>>
		<<if _expBonus > 0>>

Experience bonus: +<<print _expBonus>>%
		<</if>>
		<<if _loyaltyBonus > 0>>

Loyalty bonus: +<<print _loyaltyBonus>>%
		<</if>>
		<<if $slaveUnits[$targetIndex].SF > 0>>

Special Force advisors bonus: +20%
		<</if>>

Slaves base morale: $slaveBaseMorale <<if $humanUpgrade.morale > 0>> + $humanUpgrade.morale <</if>>(<<print Math.round($slaveBaseMorale + $slaveBaseMorale * $secBarracksUpgrades.luxury * 0.05)>>)
		<<if $secBarracksUpgrades.luxury > 0>>

Barracks bonus: + <<print $secBarracksUpgrades.luxury * 5>>%
		<</if>>

Slaves base hp: $slaveBaseHp <<if $humanUpgrade.hp > 0>> + $humanUpgrade.hp <</if>>(<<print Math.round($slaveBaseHp + $slaveUnits[$targetIndex].cyber + $slaveBaseHp * $slaveUnits[$targetIndex].medics * 0.25)>>)
		<<if $slaveUnits[$targetIndex].medics > 0>>

Medics detachment bonus: +25%
		<</if>>
	<</if>>
<<elseif $targetUnit == "mercUnits">>
	<<mercUnitsDescription $mercUnits[$targetIndex]>>

	Rename unit <<textbox "$mercUnits[$targetIndex].platoonName" $mercUnits[$targetIndex].platoonName "seeUnit">>
	<<if $mercUnits[$targetIndex].troops < $mercUnits[$targetIndex].maxTroops && $mercFreeManpower > 0>>

		<<link "Replenish unit" "seeUnit">>
			<<if $mercFreeManpower >= $mercUnits[$targetIndex].maxTroops - $mercUnits[$targetIndex].troops>>
				<<set $mercFreeManpower -= $mercUnits[$targetIndex].maxTroops - $mercUnits[$targetIndex].troops>>
				<<set $mercEmployedManpower += $mercUnits[$targetIndex].maxTroops - $mercUnits[$targetIndex].troops>>
				<<set _expLoss = ($mercUnits[$targetIndex].maxTroops - $mercUnits[$targetIndex].troops) / $mercUnits[$targetIndex].troops>>
				<<set $mercUnits[$targetIndex].training -= $mercUnits[$targetIndex].training * _expLoss>>
				<<set $mercUnits[$targetIndex].troops = $mercUnits[$targetIndex].maxTroops>>
			<<else>>
				<<set $mercEmployedManpower += $mercFreeManpower>>
				<<set _expLoss = $mercFreeManpower / $mercUnits[$targetIndex].troops>>
				<<set $mercUnits[$targetIndex].training -= $mercUnits[$targetIndex].training * _expLoss>>
				<<set $mercUnits[$targetIndex].troops += $mercFreeManpower>>
				<<set $mercFreeManpower = 0>>
			<</if>>
		<</link>>
	<</if>>

	<<if $mercUnits[$targetIndex].maxTroops < 50>>

		<<link "Intensive officers training" "seeUnit">>
			<<set $mercUnits[$targetIndex].maxTroops += 10>>
			<<run cashX(forceNeg(5000 + 10 * $equipUpgradeCost * ($mercUnits[$targetIndex].equip + $mercUnits[$targetIndex].commissars + $mercUnits[$targetIndex].cyber + $mercUnits[$targetIndex].SF)), "securityExpansion")>>
		<</link>>
		Invest in the training of your officers to increase the maximum number of soldiers in the unit.

//Costs <<print cashFormat(5000 + 10 * $equipUpgradeCost * ($mercUnits[$targetIndex].equip + $mercUnits[$targetIndex].commissars + $mercUnits[$targetIndex].cyber + $mercUnits[$targetIndex].SF))>> and will increase the max by 10//
	<<else>>

Your officers reached their peak. Further training will have little impact on the number of troops they can effectively lead.
	<</if>>
	<<if $mercUnits[$targetIndex].equip < 3>>

		<<link "Improve weaponry and equipment" "seeUnit">>
			<<set $mercUnits[$targetIndex].equip += 1>>
			<<run cashX(forceNeg(($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 1000), "securityExpansion")>>
		<</link>>
		Invest in better equipment for your soldiers to increase their battle effectiveness.

//Costs <<print cashFormat(($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 1000)>> and will increase attack and defense value of the unit by 15% for every upgrade.//
	<<else>>

The unit is equipped with state of the art weaponry and equipment.
	<</if>>
	<<if $mercUnits[$targetIndex].commissars == 0>>

		<<link "Attach commissars to the unit" "seeUnit">>
			<<set $mercUnits[$targetIndex].commissars = 1>>
			<<run cashX(forceNeg($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops + 1000), "specialForces")>>
		<</link>>
		Attach a small squad of commissars to the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 1000)>> and will slowly increase the loyalty of the unit.//
	<<elseif $mercUnits[$targetIndex].commissars < 2>>

		<<link "Intensive loyalty training" "seeUnit">>
			<<set $mercUnits[$targetIndex].commissars += 1>>
			<<run cashX(forceNeg($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops + 1000), "specialForces")>>
		<</link>>
		Provide special training for the officers and the commissars of the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 1000)>> and will increase the loyalty of the unit faster.//
	<<elseif $mercUnits[$targetIndex].commissars == 1>>

The unit has a commissar detachment, keeping under control the ambitions of the unit's officers.
	<<else>>

The unit has a perfectly trained and loyal commissar detachment, keeping under control the ambitions of the unit's officers.
	<</if>>
	<<if $prostheticsUpgrade >= 2 || $researchLab.advCombatPLimb == 1>>
		<<if $mercUnits[$targetIndex].cyber == 0>>

			<<link "Provide enhanced cybernetic enhancements" "seeUnit">>
				<<set $mercUnits[$targetIndex].cyber += 1>>
				<<run cashX(forceNeg($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops + 2000), "specialForces")>>
			<</link>>Will augment all soldiers of the unit with high tech cyber enhancements.

//Costs <<print cashFormat(($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 2000)>> and will increase attack, defense and base hp values of the unit.//
		<<else>>

The unit is equipped with advanced cybernetic enhancements.
		<</if>>
	<</if>>
	<<if $mercUnits[$targetIndex].medics == 0>>

		<<link "Attach trained medics to the unit" "seeUnit">>
			<<set $mercUnits[$targetIndex].medics = 1>>
			<<run cashX(forceNeg(($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 5000), "securityExpansion")>>
		<</link>>
		Attach a small squad of trained medics to the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 5000)>> and will decrease the number of casualties suffered during battle.//
	<<else>>

The unit has a medic detachment following it into battle, decreasing the number of casualties the unit suffers.
	<</if>>
	<<if $SF.Toggle && $SF.Active >= 1>>
		<<if $mercUnits[$targetIndex].SF == 0>>

			<<link "Attach Special Force advisors" "seeUnit">>
				<<set $mercUnits[$targetIndex].SF = 1>>
				<<run cashX(forceNeg(($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 5000), "securityExpansion")>>
			<</link>>
			Attach $SF.Lower advisors to the unit.

//Costs <<print cashFormat(($equipUpgradeCost * $mercUnits[$targetIndex].maxTroops) + 5000)>> and will slightly increase the base stats of the unit.//
		<<else>>

The unit has attached advisors from $SF.Lower that will help the squad remain tactically aware and active.
		<</if>>
	<</if>>
	<<if $showBattleStatistics == 1>>
		<<if $mercUnits[$targetIndex].training <= 10>>
			<<set _expBonus = 0>>
		<<elseif $mercUnits[$targetIndex].training <= 33>>
			<<set _expBonus = 10>>
		<<elseif $mercUnits[$targetIndex].training <= 66>>
			<<set _expBonus = 25>>
		<<else>>
			<<set _expBonus = 50>>
		<</if>>
		<<if $mercUnits[$targetIndex].loyalty <= 10>>
			<<set _loyaltyBonus = 0>>
		<<elseif $mercUnits[$targetIndex].loyalty <= 33>>
			<<set _loyaltyBonus = 10>>
		<<elseif $mercUnits[$targetIndex].loyalty <= 66>>
			<<set _loyaltyBonus = 20>>
		<<else>>
			<<set _loyaltyBonus = 30>>
		<</if>>

Mercenaries base attack: $mercBaseAttack <<if $humanUpgrade.attack > 0>> + $humanUpgrade.attack <</if>>(<<print Math.round($mercBaseAttack + $mercBaseAttack * $mercUnits[$targetIndex].equip * $equipMod + $mercBaseAttack * _expBonus * 0.01 + $mercBaseAttack * _loyaltyBonus * 0.01 + $mercBaseAttack * $mercUnits[$targetIndex].SF * 0.20 + $mercUnits[$targetIndex].cyber)>>)

Mercenaries base defense: $mercBaseDefense <<if $humanUpgrade.defense > 0>> + $humanUpgrade.defense <</if>>(<<print Math.round($mercBaseDefense + $mercBaseDefense * $mercUnits[$targetIndex].equip * $equipMod + $mercBaseDefense * _expBonus * 0.01 + $mercBaseDefense * _loyaltyBonus * 0.01 + $mercBaseDefense * $mercUnits[$targetIndex].SF * 0.20 + $mercUnits[$targetIndex].cyber)>>)
		<<if $mercUnits[$targetIndex].equip > 0>>

Equipment bonus: + <<print $mercUnits[$targetIndex].equip * 15>>%
		<</if>>
		<<if $mercUnits[$targetIndex].cyber > 0>>

Cyber enhancements bonus: + 1
		<</if>>
		<<if _expBonus > 0>>

Experience bonus: +<<print _expBonus>>%
		<</if>>
		<<if _loyaltyBonus > 0>>

Loyalty bonus: +<<print _loyaltyBonus>>%
		<</if>>
		<<if $mercUnits[$targetIndex].SF > 0>>

Special Force advisors bonus: +20%
		<</if>>

Mercenaries base morale: $mercBaseMorale <<if $humanUpgrade.morale > 0>> + $humanUpgrade.morale <</if>>(<<print Math.round($mercBaseMorale + $mercBaseMorale * $secBarracksUpgrades.luxury * 0.05)>>)
		<<if $secBarracksUpgrades.luxury > 0>>

Barracks bonus: + <<print $secBarracksUpgrades.luxury * 5>>%
		<</if>>

Mercenaries base hp: $mercBaseHp <<if $humanUpgrade.hp > 0>> + $humanUpgrade.hp <</if>>(<<print Math.round($mercBaseHp + $mercBaseHp * $mercUnits[$targetIndex].medics * 0.25 + $mercUnits[$targetIndex].cyber)>>)
		<<if $mercUnits[$targetIndex].medics > 0>>

Medics detachment bonus: +25%
		<</if>>
	<</if>>
<</if>>

repo_name: AmbrosiaCheesecake/fc


code:
:: 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>>
<<if $lastAttackWeeks < 2 && $hasFoughtOnce == 1>>
	The recent attack has a negative effect on the trade of the arcology.
	<<set _tradeChange -= 1>>
<<elseif $lastAttackWeeks < 4 && $hasFoughtOnce == 1>>
	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 $lastRebellionWeeks < 2 && $hasRebelledOnce == 1>>
	The recent rebellion has a negative effect on the trade of the arcology.
	<<set _tradeChange -= 1>>
<<elseif $lastRebellionWeeks < 4 && $hasRebelledOnce == 1>>
	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 $assistantPower == 1>>
	Thanks to the computing power available to _himA, $assistantName is able to guide the commercial development of the arcology to greater levels.
	<<set _tradeChange++>>
<<elseif $assistantPower == 2>>
	Thanks to the incredible computing power available to _himA, $assistantName is able to guide the commercial development of the arcology to greater levels.
	<<set _tradeChange += 2>>
<</if>>

<<if $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 $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 $weapManu == 1>>
	The weapons manufacturing facility of the arcology attracts a significant amount of trade.
	<<set _tradeChange += 0.5 * ($weapProductivity + $weapLab)>>
<</if>>
<<if $transportHub == 1>>
	<<if $airport == 1>>
		The airport, while small, helps facilitate the commercial development of the arcology.
		<<set _tradeChange += 1>>
	<<elseif $airport == 2>>
		The airport, while fairly small, helps facilitate the commercial development of the arcology.
		<<set _tradeChange += 1.5>>
	<<elseif $airport == 3>>
		The airport helps facilitate the commercial development of the arcology.
		<<set _tradeChange += 2>>
	<<elseif $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 $railway == 1>>
			The railway network's age and limited extension limit commercial activity.
		<<elseif $railway == 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 $railway == 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 $docks == 1>>
			The docks' age and limited size limit commercial activity.
		<<elseif $docks == 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 $docks == 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>>

<<if $SF.Toggle && $SF.Active >= 1 && $SF.Size > 10>>
	Having a powerful special force, increases trade security.
	<<set _tradeChange += $SF.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 $trade <= 20>>
	The almost non-existent trade crossing the arcology @@.yellow;does little to promote growth.@@
<<elseif $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 $trade <= 60>>
	With trade at positive levels, the @@.green;prosperity of the arcology grows more powerful.@@
	<<set _AWeekGrowth += 2.5>>
<<elseif $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 $trade = Math.clamp($trade + _tradeChange,0,100)>>


code:
:: transportHub [nobr]

<<set $nextButton = "Back", $nextLink = "Main">>

The Transport Hub

You quickly reach the transport hub, where a constant stream of vehicles, people and goods greets you. Part of the structure is dedicated to air travel and the other is mainly occupied by <<if $terrain != "oceanic" && $terrain != "marine">>the rail station.<<else>> the docks.<</if>>

<<if $limitImmigration == 1 || $AntiImmigrationRep == 1>>
	Due to your strict policies concerning immigration, very few new citizens arrive in the transport hub.
<<elseif $openBorders == 1 || $ProImmigrationCash == 1>>
	Due to your liberal policies concerning immigration, the transport hub is filled with a flow of new citizens.
<</if>>

<<if $airport == 1>>
	The arcology's airport is relatively small and poorly equipped. It can handle some traffic, but nothing noteworthy.
<<elseif $airport == 2>>
	The arcology's airport is relatively small, but well equipped. It can handle some traffic, but nothing too serious.
<<elseif $airport == 3>>
	The arcology's airport is good sized and well equipped. It can handle a good amount of traffic.
<<elseif $airport == 4>>
	The arcology's airport is good sized and very well equipped. It can handle a lot of traffic.
<<else>>
	The arcology's airport is huge and very well equipped. It can handle an impressive amount of traffic.
<</if>>

<<if $terrain != "oceanic" && $terrain != "marine">>
	<<if $railway == 1>>
		The railway network is old and limited. It can handle some traffic, but not sustain commercial activity.
	<<elseif $railway == 2>>
		The railway network is modern and efficient, but limited in reach. It can handle some traffic, but not sustain commercial activity of any significant size.
	<<elseif $railway == 3>>
		The railway network is modern, efficient and expansive. It can handle a significant amount of traffic.
	<<else>>
		The railway network is high tech and very far reaching. It can handle an enormous amount of traffic.
	<</if>>
<<else>>
	<<if $docks == 1>>
		The docks are old and small. They can handle some traffic, but not sustain commercial activity.
	<<elseif $docks == 2>>
		The docks are modern and efficient, but limited in size. They can handle some traffic, but not sustain commercial activity of significant size.
	<<elseif $docks == 3>>
		The docks are modern, efficient and expansive. They can handle a significant amount of traffic.
	<<else>>
		The docks are huge in size and high tech. They can handle an enormous amount of traffic.
	<</if>>
<</if>>

<<if $hubSecurity == 1>>
	The security of the hub is limited to a few cameras and the occasional guard.
<<elseif $hubSecurity == 2>>
	The security of the hub is guaranteed by a powerful camera surveillance system.
<<elseif $hubSecurity == 3>>
	The security of the hub is guaranteed by a powerful camera surveillance system and a rapid response team constantly patrolling the structure.
<<else>>
	The security of the hub is guaranteed by a powerful camera surveillance system, a rapid response team constantly patrolling the building and additional security drones making the rounds around the exterior.
<</if>>

<<if $trade <= 20>>
	Trade is @@.red;almost non-existent.@@ Outside the supplies for the arcology's domestic consumption little else crosses the territory of the free city.
<<elseif $trade <= 40>>
	Trade is @@.orange;low.@@ There's some but limited commercial activity crossing the territory of the free city.
<<elseif $trade <= 60>>
	Trade is at @@.yellow;positive levels.@@ There's a good amount commercial activity outside the supplies for the arcology's domestic consumption.
<<elseif $trade <= 80>>
	Trade is at @@.limegreen;high levels.@@ There's a lot of commercial activity outside the supplies for the arcology's domestic consumption.
<<else>>
	Trade is at @@.green;extremely high levels.@@ There's a constant stream of commercial activity crossing the arcology.
<</if>>

/* airport */
<<if $airport == 1>>
	<<link "Modernize the airport">>
		<<run cashX(forceNeg(5000*$upgradeMultiplierArcology), "capEx")>>
		<<set $airport++>>
		<<goto "transportHub">>
	<</link>> //Will cost <<print cashFormat(5000*$upgradeMultiplierArcology)>> and will increase trade, but will affect security//
<<elseif $airport == 2>>
	<<link "Enlarge the airport">>
		<<run cashX(forceNeg(15000*$upgradeMultiplierArcology), "capEx")>>
		<<set $airport++>>
		<<goto "transportHub">>
	<</link>> //Will cost <<print cashFormat(15000*$upgradeMultiplierArcology)>> and will increase trade, but will affect security//
<<elseif $airport == 3>>
	<<link "Further modernize the airport">>
		<<run cashX(forceNeg(45000*$upgradeMultiplierArcology), "capEx")>>
		<<set $airport++>>
		<<goto "transportHub">>
	<</link>> //Will cost <<print cashFormat(45000*$upgradeMultiplierArcology)>> and will increase trade, but will affect security//
<<elseif $airport == 4>>
	<<link "Further enlarge the airport">>
		<<run cashX(forceNeg(85000*$upgradeMultiplierArcology), "capEx")>>
		<<set $airport++>>
		<<goto "transportHub">>
	<</link>> //Will cost <<print cashFormat(85000*$upgradeMultiplierArcology)>> and will increase trade, but will affect security//
<<else>>
	The airport is fully upgraded.
<</if>>

/* trainyard/dockyard */
<<if $terrain != "oceanic" && $terrain != "marine">>
	<<if $railway == 1>>
		<<link "Modernize the railway">>
			<<run cashX(forceNeg(10000*$upgradeMultiplierArcology), "capEx")>>
			<<set $railway++>>
			<<goto "transportHub">>
		<</link>> //Will cost <<print cashFormat(10000*$upgradeMultiplierArcology)>>, will increase trade and slightly lower arcology's upkeep, but will affect security//
	<<elseif $railway == 2>>
		<<link "Enlarge the railway">>
			<<run cashX(forceNeg(25000*$upgradeMultiplierArcology), "capEx")>>
			<<set $railway++>>
			<<goto "transportHub">>
		<</link>> //Will cost <<print cashFormat(25000*$upgradeMultiplierArcology)>>, will increase trade and slightly lower arcology's upkeep, but will affect security//
	<<elseif $railway == 3>>
		<<link "Further modernize and enlarge the railway">>
			<<run cashX(forceNeg(65000*$upgradeMultiplierArcology), "capEx")>>
			<<set $railway++>>
			<<goto "transportHub">>
		<</link>> //Will cost <<print cashFormat(65000*$upgradeMultiplierArcology)>>, will increase trade and slightly lower arcology's upkeep, but will affect security//
	<<else>>
		The railway is fully upgraded.
	<</if>>
<<else>>
	<<if $docks == 1>>
		<<link "Modernize the docks">>
			<<run cashX(forceNeg(10000*$upgradeMultiplierArcology), "capEx")>>
			<<set $docks++>>
			<<goto "transportHub">>
		<</link>> //Will cost <<print cashFormat(10000*$upgradeMultiplierArcology)>>, will increase trade and slightly lower arcology's upkeep, but will affect security//
	<<elseif $docks == 2>>
		<<link "Enlarge the docks">>
			<<run cashX(forceNeg(25000*$upgradeMultiplierArcology), "capEx")>>
			<<set $docks++>>
			<<goto "transportHub">>
		<</link>> //Will cost <<print cashFormat(25000*$upgradeMultiplierArcology)>>, will increase trade and slightly lower arcology's upkeep, but will affect security//
	<<elseif $docks == 3>>
		<<link "Further modernize and enlarge the docks">>
			<<run cashX(forceNeg(65000*$upgradeMultiplierArcology), "capEx")>>
			<<set $docks++>>
			<<goto "transportHub">>
		<</link>> //Will cost <<print cashFormat(65000*$upgradeMultiplierArcology)>>, will increase trade and slightly lower arcology's upkeep, but will affect security//
	<<else>>
		The docks are fully upgraded.
	<</if>>
<</if>>

/* security */
<<if $hubSecurity == 1>>
	<<link "Expand and modernize the surveillance system">>
		<<run cashX(forceNeg(15000*$upgradeMultiplierArcology), "capEx")>>
		<<set $hubSecurity++>>
		<<goto "transportHub">>
	<</link>> //Will cost <<print cashFormat(15000*$upgradeMultiplierArcology)>> and lower the transport hub security modifiers//
<<elseif $hubSecurity == 2>>
	<<link "Establish a rapid response team">>
		<<run cashX(forceNeg(35000*$upgradeMultiplierArcology), "capEx")>>
		<<set $hubSecurity++>>
		<<goto "transportHub">>
	<</link>> //Will cost <<print cashFormat(35000*$upgradeMultiplierArcology)>> and further lower the transport hub security modifiers//
<<elseif $hubSecurity == 3>>
	<<link "Add additional security drones to the structure">>
		<<run cashX(forceNeg(55000*$upgradeMultiplierArcology), "capEx")>>
		<<set $hubSecurity++>>
		<<goto "transportHub">>
	<</link>> //Will cost <<print cashFormat(55000*$upgradeMultiplierArcology)>> and further lower the transport hub security modifiers//
<<else>>
	The hub security is fully upgraded
<</if>>

[[Return this sector to standard markets|Main][cashX(forceNeg(Math.trunc(10000*$upgradeMultiplierArcology)), "capEx"), $sectors[$AS].type = "Markets", $transportHub = 0, $hubSecurity = 1]] //Costs <<print cashFormat(Math.trunc(10000*$upgradeMultiplierArcology))>>//


code:
:: unitsBattleReport [nobr]

<<if $losses == 0>>
	<<if $deployingBots == 1>>

		Security Drones: no casualties.
	<</if>>
	<<if $SF.Toggle && $SF.Active >= 1 && $SFIntervention>>

		<<print num($SF.Squad.Troops)>> soldiers from $SF.Lower joined the battle: no casualties suffered.
	<</if>>
	<<if $deployingMilitia == 1>>
		<<for _j = 0; _j < $militiaUnits.length; _j++>>
			<<if $militiaUnits[_j].isDeployed == 1>>

				$militiaUnits[_j].platoonName: no casualties.
				<<if $militiaUnits[_j].training < 100>>
					<<if random(1,100) > 60>>
						Experience has increased.
						<<set $militiaUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>>
					<</if>>
				<</if>>
			<</if>>
		<</for>>
	<</if>>
	<<if $deployingSlaves == 1>>
		<<for _j = 0; _j < $slaveUnits.length; _j++>>
			<<if $slaveUnits[_j].isDeployed == 1>>

				$slaveUnits[_j].platoonName: no casualties.
				<<if $slaveUnits[_j].training < 100>>
					<<if random(1,100) > 60>>
						Experience has increased.
						<<set $slaveUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>>
					<</if>>
				<</if>>
			<</if>>
		<</for>>
	<</if>>
	<<if $deployingMercs == 1>>
		<<for _j = 0; _j < $mercUnits.length; _j++>>
			<<if $mercUnits[_j].isDeployed == 1>>

				$mercUnits[_j].platoonName: no casualties.
				<<if $mercUnits[_j].training < 100>>
					<<if random(1,100) > 60>>
						Experience has increased.
						<<set $mercUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>>
					<</if>>
				<</if>>
			<</if>>
		<</for>>
	<</if>>

<<elseif $losses > 0>>
	/* if the losses are more than zero */
	/* generates a list of randomized losses, from which each unit picks one at random */
	<<set _losses = $losses>>
	<<if $SF.Toggle && $SF.Active >= 1 && $SFIntervention>>
		<<set $deployedUnits++>>
	<</if>>
	<<set _averageLosses = Math.trunc(_losses / $deployedUnits)>>
	<<set _lossesList = []>>
	<<set _validityCount = 0>>
	<<for _i = 0; _i < $deployedUnits; _i++>>
		<<set _assignedLosses = Math.trunc(Math.clamp(_averageLosses + random(-5,5), 0, 100))>>
		<<if _assignedLosses > _losses>>
			<<set _assignedLosses = _losses>>
			<<set _losses = 0>>
		<<else>>
			<<set _losses -= _assignedLosses>>
		<</if>>
		<<set _lossesList.push(_assignedLosses)>>
		<<set _validityCount += _assignedLosses>>
	<</for>>
	<<if _losses > 0>>
		<<set _lossesList[random(_lossesList.length - 1)] += _losses>>
	<</if>>
	<<set _lossesList.shuffle()>>

	/* sanity check for losses */
	<<set _count = 0>>
	<<for _i = 0; _i < _lossesList.length; _i++>>
		<<if !Number.isInteger(_lossesList[_i])>>
			<<set _lossesList[_i] = 0>>
		<</if>>
		<<set _count += _lossesList[_i]>>
	<</for>>
	<<if _count < $losses>>
		<<set _rand = random(_lossesList.length - 1)>>
		<<set _lossesList[_rand] += $losses - _count>>
	<<elseif _count > $losses>>
		<<set _diff = _count - $losses>>
		<<set _rand = random(_lossesList.length - 1)>>
		<<set _lossesList[_rand] = Math.trunc(_lossesList[_rand]-_diff,0,100)>>
	<</if>>

	/* assigns the losses and notify the player */
	<<if $deployingBots == 1>>

		<<set _loss = _lossesList.pluck()>>
		<<set _loss = Math.clamp(_loss,0,$secBots.troops)>>
		<<set $secBots.troops -= _loss>>
		Security drones:
		<<if _loss <= 0>>
			no casualties
		<<elseif _loss <= $secBots.troops * 0.2>>
			light casualties
		<<elseif _loss <= $secBots.troops * 0.4>>
			moderate casualties
		<<elseif _loss <= $secBots.troops * 0.6>>
			heavy casualties
		<<else>>
			catastrophic casualties
		<</if>>
		suffered.
		<<if $secBots.troops <= 5>>
			<<set $secBots.active = 0>>
			Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. It will take quite the investment to rebuild them.
		<<elseif $secBots.troops <= 10>>
			The unit has very few operatives left, it risks complete annihilation if deployed again.
		<</if>>

	<</if>>
	<<if $SF.Toggle && $SF.Active >= 1 && $SFIntervention>>

		<<set _loss = _lossesList.pluck()>>
		<<set _loss = Math.clamp(_loss,0,$SF.Squad.Troops)>>
		<<print num($SF.Squad.Troops)>> soldiers from $SF.Lower joined the battle:
		<<if _loss <= 0>>
			no casualties
		<<elseif _loss <= 10>>
			light casualties
		<<elseif _loss <= 30>>
			moderate casualties
		<<elseif _loss <= 60>>
			heavy casualties
		<<else>>
			catastrophic casualties
		<</if>>
		suffered.
		<<set $SF.Squad.Troops -= _loss>>

	<</if>>
	<<if $deployingMilitia == 1>>
		<<for _j = 0; _j < $militiaUnits.length; _j++>>
			<<if $militiaUnits[_j].isDeployed == 1>>

				<<set $militiaUnits[_j].battlesFought++>>
				<<set _loss = _lossesList.pluck()>>
				<<set _loss = Math.clamp(_loss,0,$militiaUnits[_j].troops)>>
				$militiaUnits[_j].platoonName:
				<<if _loss <= 0>>
					no casualties
				<<elseif _loss <= $militiaUnits[_j].troops * 0.2>>
					light casualties
				<<elseif _loss <= $militiaUnits[_j].troops * 0.4>>
					moderate casualties
				<<elseif _loss <= $militiaUnits[_j].troops * 0.6>>
					heavy casualties
				<<else>>
					catastrophic casualties
				<</if>>
				suffered.
				<<set _med = Math.round(Math.clamp(_loss * $militiaUnits[_j].medics * 0.25,1,_loss))>>
				<<if $militiaUnits[_j].medics == 1 && _loss > 0>>
					Some men were saved by their medics.
				<</if>>
				<<set $militiaUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$militiaUnits[_j].maxTroops))>>
				<<set $militiaEmployedManpower -= Math.trunc(_loss - _med)>>
				<<set $militiaTotalCasualties += Math.trunc(_loss - _med)>>
				<<set $militiaTotalManpower -= Math.trunc(_loss - _med)>>
				<<if $militiaUnits[_j].training < 100>>
					<<if random(1,100) > 60>>
						Experience has increased.
						<<set $militiaUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>>
					<</if>>
				<</if>>
				<<if $militiaUnits[_j].troops <= 5>>
					<<set $militiaUnits[_j].active = 0>>

Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The remnants will be sent home honored as veterans or reorganized in a new unit.
				<<elseif $militiaUnits[_j].troops <= 10>>

The unit has very few operatives left, it risks complete annihilation if deployed again.
				<</if>>
			<</if>>
		<</for>>
	<</if>>
	<<if $deployingSlaves == 1>>
		<<for _j = 0; _j < $slaveUnits.length; _j++>>
			<<if $slaveUnits[_j].isDeployed == 1>>

				<<set $slaveUnits[_j].battlesFought++>>
				<<set _loss = _lossesList.pluck()>>
				<<set _loss = Math.clamp(_loss,0,$slaveUnits[_j].troops)>>
				$slaveUnits[_j].platoonName:
				<<if _loss <= 0>>
					no casualties
				<<elseif _loss <= $slaveUnits[_j].troops * 0.2>>
					light casualties
				<<elseif _loss <= $slaveUnits[_j].troops * 0.4>>
					moderate casualties
				<<elseif _loss <= $slaveUnits[_j].troops * 0.6>>
					heavy casualties
				<<else>>
					catastrophic casualties
				<</if>>
				suffered.
				<<set _med = Math.round(Math.clamp(_loss * $slaveUnits[_j].medics * 0.25,1,_loss))>>
				<<if $slaveUnits[_j].medics == 1 && _loss > 0>>
					Some men were saved by their medics.
				<</if>>
				<<set $slaveUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$slaveUnits[_j].maxTroops))>>
				<<set $slavesEmployedManpower -= Math.trunc(_loss - _med)>>
				<<set $slavesTotalCasualties += Math.trunc(_loss - _med)>>
				<<set $menials -= Math.trunc(_loss - _med)>>
				<<if $slaveUnits[_j].training < 100>>
					<<if random(1,100) > 60>>
						Experience has increased.
						<<set $slaveUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>>
					<</if>>
				<</if>>
				<<if $slaveUnits[_j].troops <= 5>>
					<<set $slaveUnits[_j].active = 0>>

Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The survivors will be sent home honored as veterans or reorganized in a new unit.
				<<elseif $slaveUnits[_j].troops <= 10>>

The unit has very few operatives left, it risks complete annihilation if deployed again.
				<</if>>
			<</if>>
		<</for>>
	<</if>>
	<<if $deployingMercs == 1>>
		<<for _j = 0; _j < $mercUnits.length; _j++>>
			<<if $mercUnits[_j].isDeployed == 1>>

				<<set $mercUnits[_j].battlesFought++>>
				<<set _loss = _lossesList.pluck()>>
				<<set _loss = Math.clamp(_loss,0,$mercUnits[_j].troops)>>
				$mercUnits[_j].platoonName:
				<<if _loss <= 0>>
					no casualties
				<<elseif _loss <= $mercUnits[_j].troops * 0.2>>
					light casualties
				<<elseif _loss <= $mercUnits[_j].troops * 0.4>>
					moderate casualties
				<<elseif _loss <= $mercUnits[_j].troops * 0.6>>
					heavy casualties
				<<else>>
					catastrophic casualties
				<</if>>
				suffered.
				<<set _med = Math.round(Math.clamp(_loss * $mercUnits[_j].medics * 0.25,1,_loss))>>
				<<if $mercUnits[_j].medics == 1 && _loss > 0>>
					Some men were saved by their medics.
				<</if>>
				<<set $mercUnits[_j].troops -= Math.trunc(Math.clamp(_loss - _med,0,$mercUnits[_j].maxTroops))>>
				<<set $mercEmployedManpower -= Math.trunc(_loss - _med)>>
				<<set $mercTotalCasualties += Math.trunc(_loss - _med)>>
				<<set $mercTotalManpower -= Math.trunc(_loss - _med)>>
				<<if $mercUnits[_j].training < 100>>
					<<if random(1,100) > 60>>
						Experience has increased.
						<<set $mercUnits[_j].training += random(5,15) + $majorBattle * random(5,15)>>
					<</if>>
				<</if>>
				<<if $mercUnits[_j].troops <= 5>>
					<<set $mercUnits[_j].active = 0>>

Unfortunately the losses they took were simply too great, their effective combatants are in so small number you can no longer call them a deployable unit. The remnants will be sent home honored as veterans or reorganized in a new unit.
				<<elseif $mercUnits[_j].troops <= 10>>

The unit has very few operatives left, it risks complete annihilation if deployed again.
				<</if>>
			<</if>>
		<</for>>
	<</if>>
<<else>>

@@.red;Error: losses are a negative number or NaN@@
<</if>> /* closes check for more than zero casualties */